From: Paarvai Naai on
Hi,

I noticed something very strange with when hooking the wxEVT_SIZE
event in one of my custom controls. Specifically, for every discrete
window resize, I find that the wxEVT_SIZE seems to be issued 4(!)
times, thereby calling my event handler 4 times. This seems very
inefficient. In an effort to simplify things, I decided to test the
wxEVT_SIZE event on a simple wxApp.

I created a wxApp that instantiates a wxFrame which in turn creates a
wxPanel. The wxEVT_SIZE event is hooked as follows:

panel->Connect(ID_PANEL, wxEVT_SIZE,
wxSizeEventHandler(SizeTestFrame::OnSize), NULL, this);

The OnSize function is written as:

void SizeTestFrame::OnSize( wxSizeEvent& event )
{
static int count = 0;
printf("OnSize: %p %d\n", event.GetEventObject(), count++);
//event.Skip();
}

Now when I launch the app, I get 3 OnSize calls upon the initial
showing of the main frame. All show the same value from
event.GetEventObject() (presumably the panel's pointer). I am using
wxGTK 2.8.9. To resize the window, I right click on the titlebar and
select the resize option. This way I can use discrete events on my
keyboard to resize the window. Each resize results in 3 more calls to
OnSize.

Is this is a known issue? Is there some way I can squelch these extra
wxEVT_SIZE events?

Thanks,
Paarvai
From: Vadim Zeitlin on
On Fri, 5 Dec 2008 11:18:01 -0800 Paarvai Naai <opensource3141(a)gmail.com> wrote:

PN> Is this is a known issue? Is there some way I can squelch these extra
PN> wxEVT_SIZE events?

I don't have time to test this right now myself unfortunately but it would
help to see from where each of these events is generated (i.e. the stack
trace from gdb when it stops on the breakpoint at your size event handler).
This would allow to see if it's GTK+ or wxGTK which generates duplicated
events.

Also, are they really exactly the same? I.e. do they all carry the same
size?

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
From: Paarvai Naai on
Hi,

Was the information I provided below useful? I'd like to do as much a
I can to assist in figuring out why OnSize is called so many times
with wxGTK. Please let me know if there is any more information I can
quickly collect that might be useful.

Thanks again,
Paarvai

On Fri, Dec 5, 2008 at 1:57 PM, Paarvai Naai <opensource3141(a)gmail.com> wrote:
> Looking into this a little more, I realized I didn't paste enough of
> the calls to be as useful. Here are each of the calls again, along
> with some theories on what is happening.
>
> Call #1:
> #0 SizeTestFrame::OnSize (this=0x8d748c8, event=(a)0xbf87a590)
> at sizetestframe.cpp:168
> #1 0x00c73765 in wxAppConsole::HandleEvent ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #2 0x00d203af in wxEvtHandler::ProcessEventIfMatches ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #3 0x00d20584 in wxEvtHandler::SearchDynamicEventTable ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #4 0x00d20643 in wxEvtHandler::ProcessEvent ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #5 0x006f7ad7 in wxWindow::DoSetSize ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #6 0x0081508c in wxTopLevelWindowBase::DoLayout ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #7 0x00815c4d in wxTopLevelWindowBase::OnSize ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #8 0x00c73765 in wxAppConsole::HandleEvent ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #9 0x00d203af in wxEvtHandler::ProcessEventIfMatches ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #10 0x00d204fd in wxEventHashTable::HandleEvent ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #11 0x00d20666 in wxEvtHandler::ProcessEvent ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #12 0x00752545 in wxFrame::GtkOnSize () from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #13 0x006ed7ab in wxTopLevelWindowGTK::OnInternalIdle ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #14 0x007bff4d in wxFrameBase::OnInternalIdle ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #15 0x00751b9e in wxFrame::OnInternalIdle ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #16 0x00786635 in wxAppBase::SendIdleEvents ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #17 0x0078699b in wxAppBase::ProcessIdle ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #18 0x006c7886 in ?? () from /usr/lib/libwx_gtk2u_core-2.8.so.0
>
> It appears that the app is resized and the frame gets notification
> through the idle loop. Then the frame resizes its child panel since
> the panel is the only child and the frame wants to fill its entire
> client region with the panel. The call to DoSetSize on the panel
> generates a wxEVT_SIZE event.
>
> Next, Call #2 happens:
> #0 SizeTestFrame::OnSize (this=0x8d748c8, event=(a)0xbf878670)
> at sizetestframe.cpp:168
> #1 0x00c73765 in wxAppConsole::HandleEvent ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #2 0x00d203af in wxEvtHandler::ProcessEventIfMatches ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #3 0x00d20584 in wxEvtHandler::SearchDynamicEventTable ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #4 0x00d20643 in wxEvtHandler::ProcessEvent ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #5 0x006f41ab in wxWindow::GTKProcessEvent ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #6 0x006f80bf in ?? () from /usr/lib/libwx_gtk2u_core-2.8.so.0
>
> This call seems to be generated by GTK for the panel itself because
> the panel's size was changed due to Call #1.
>
> Finally, we have Call #3:
> #0 SizeTestFrame::OnSize (this=0x8d748c8, event=(a)0xbf879080)
> at sizetestframe.cpp:168
> #1 0x00c73765 in wxAppConsole::HandleEvent ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #2 0x00d203af in wxEvtHandler::ProcessEventIfMatches ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #3 0x00d20584 in wxEvtHandler::SearchDynamicEventTable ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #4 0x00d20643 in wxEvtHandler::ProcessEvent ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #5 0x006f7ad7 in wxWindow::DoSetSize ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #6 0x0081508c in wxTopLevelWindowBase::DoLayout ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #7 0x00815c4d in wxTopLevelWindowBase::OnSize ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #8 0x00c73765 in wxAppConsole::HandleEvent ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #9 0x00d203af in wxEvtHandler::ProcessEventIfMatches ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #10 0x00d204fd in wxEventHashTable::HandleEvent ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #11 0x00d20666 in wxEvtHandler::ProcessEvent ()
> from /usr/lib/libwx_baseu-2.8.so.0
> #12 0x006f41ab in wxWindow::GTKProcessEvent ()
> from /usr/lib/libwx_gtk2u_core-2.8.so.0
> #13 0x006f80bf in ?? () from /usr/lib/libwx_gtk2u_core-2.8.so.0
>
> I'm not entirely sure, but it seems that this call is generated by GTK
> because the frame has changed size (during the course of Call #1).
> This again causes the DoSetSize to be called on the panel via
> DoLayout. The DoSetSize then causes another wxEVT_SIZE to be emitted.
> My guess is that the only thing that saves us from going into an
> infinite loop is that the DoSetSize on the panel during Call #3 does
> not generate a subsequent internal event by GTK for the panel since
> the panel's size is simply set to the same size as was set in Call #1.
>
> Please confirm my logic above. On face, it seems that there is a
> problem here and it should somehow be fixed.
>
> Thanks,
> Paarvai
>