Generic way to intercept an event before processing ? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Generic way to intercept an event before processing ?

Post by TrV »

Hi,

I'm looking for a generic way to ignore/skip specific events, so i've got to intercept them before normal processing.

event.Skip() into associated event handler method does not skip the event.

My platform is Windows.

Thanks by advance ;)
DavidHart
Site Admin
Site Admin
Posts: 4254
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart »

Hi,

You can use wxApp::FilterEvent. See http://forums.wxwidgets.org/viewtopic.php?t=14858 for an example.
event.Skip() into associated event handler method does not skip the event.
No, it's a slightly misleading name. wxEvent::Skip doesn't ignore the event, it reactivates it; so it will continue to be processed by the event system. If you catch an event and don't Skip it, the event is considered to have been sufficiently processed, and so dies.

Regards,

David
TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV »

Waoh. As fast as light :) Thanks David Hart.
TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV »

Well, in fact, it does not work :(.
I can surely intercept any kind of event, but for the one i'm trying to manage (wxEVT_ICONIZE) the frame is iconized whatever the code i add.

Code: Select all

int MyApp::FilterEvent(wxEvent& event)
{
    int rtn = -1;

    if ( event.GetEventType() == wxEVT_ICONIZE && ((wxIconizeEvent&)event).Iconized() ) {
        rtn = false;
    }

    return rtn;
}
Any other idea ?
User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post by Disch »

My understanding is that FilterEvent does not prevent the iconize from happening, it just prevents it from sending an event to the window.

Can you just omit the wxMINIMIZE_BOX flag from the window style for your frame to prevent the user from attempting to iconize the window?
TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV »

Well, it's not a bad idea, Disch.
But, in fact, i want to do some processing before the frame is iconized, not just ignore the event.
Thanks anyway.
User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post by Disch »

Here's a hackish idea that seems to work on Windows:

Code: Select all

int MyApp::FilterEvent(wxEvent& evt)
{
	if( evt.GetEventType() == wxEVT_ICONIZE && ((wxIconizeEvent&)evt).Iconized() )
	{
		myframe->Iconize(false);
	}

	return -1;
}
If you experience flickering on other platforms you could try wrapping a freeze/thaw around the iconizing.

I noticed that if you attempt to iconize from a maximized window with this code, it will restore the window to normal size (ie: it won't be maximized). To avoid this you could check IsMaximized() and maximize the window to undo the iconize instead of calling Iconize(false).
TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV »

Well, i dont really like this workaround, but thanks.

It's ashame, in wxwidgets manual, it clearly says "This function is called before processing any event and allows the application to preempt the processing of some events".

But the frame is iconize before FilterEvent() catches it.
User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post by Disch »

TrV wrote:It's ashame, in wxwidgets manual, it clearly says "This function is called before processing any event and allows the application to preempt the processing of some events".

But the frame is iconize before FilterEvent() catches it.
This makes sense to me.

Remeber that the iconizing triggers the event, not the other way around. So blocking the event would not prevent the iconize from happening, since it already happened by the time the event was triggered.
TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV »

Ok, you must be right. So, no solution, i've to resigned i guess.
Post Reply