From ecdc118383f458bd7e684ab631f6e5d23cc6d251 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 29 Jul 2008 23:07:24 +0000 Subject: [PATCH] add PostSizeEvent() and use it in wxMSW status bar code (#9795) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54837 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/frame.h | 2 +- include/wx/os2/toplevel.h | 2 +- include/wx/window.h | 20 ++++++++++++++++++-- interface/wx/window.h | 32 ++++++++++++++++++++++++++++++-- src/common/wincmn.cpp | 11 +++++++---- src/msw/frame.cpp | 17 +++++++++++++---- src/msw/statusbar.cpp | 8 ++++++-- src/os2/toplevel.cpp | 23 +++++++++++++++++------ 8 files changed, 93 insertions(+), 22 deletions(-) diff --git a/include/wx/msw/frame.h b/include/wx/msw/frame.h index 50f8f16064..0677d943e9 100644 --- a/include/wx/msw/frame.h +++ b/include/wx/msw/frame.h @@ -92,7 +92,7 @@ public: #endif // tooltips // override the base class function to handle iconized/maximized frames - virtual void SendSizeEvent(); + virtual void SendSizeEvent(int flags = 0); virtual wxPoint GetClientAreaOrigin() const; diff --git a/include/wx/os2/toplevel.h b/include/wx/os2/toplevel.h index 1f775dc01d..01c5e7dc86 100644 --- a/include/wx/os2/toplevel.h +++ b/include/wx/os2/toplevel.h @@ -66,7 +66,7 @@ public: virtual bool IsMaximized(void) const; virtual void Maximize(bool bMaximize = true); virtual void Restore(void); - virtual void SendSizeEvent(void); + virtual void SendSizeEvent(int flags = 0); virtual void SetIcons(const wxIconBundle& rIcons); virtual bool Show(bool bShow = true); diff --git a/include/wx/window.h b/include/wx/window.h index 52712b7d22..73411b2167 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -131,6 +131,12 @@ enum wxShowEffect wxSHOW_EFFECT_MAX }; +// flags for SendSizeEvent() +enum +{ + wxSEND_EVENT_POST = 1 +}; + // ---------------------------------------------------------------------------- // (pseudo)template list classes // ---------------------------------------------------------------------------- @@ -538,14 +544,24 @@ public: // sends a size event to the window using its current size -- this has an // effect of refreshing the window layout - virtual void SendSizeEvent(); + // + // by default the event is sent, i.e. processed immediately, but if flags + // value includes wxSEND_EVENT_POST then it's posted, i.e. only schedule + // for later processing + virtual void SendSizeEvent(int flags = 0); // this is a safe wrapper for GetParent()->SendSizeEvent(): it checks that // we have a parent window and it's not in process of being deleted // // this is used by controls such as tool/status bars changes to which must // also result in parent re-layout - void SendSizeEventToParent(); + void SendSizeEventToParent(int flags = 0); + + // this is a more readable synonym for SendSizeEvent(wxSEND_EVENT_POST) + void PostSizeEvent() { SendSizeEvent(wxSEND_EVENT_POST); } + + // this is the same as SendSizeEventToParent() but using PostSizeEvent() + void PostSizeEventToParent() { SendSizeEventToParent(wxSEND_EVENT_POST); } // window state diff --git a/interface/wx/window.h b/interface/wx/window.h index 01c7fa6065..b1fe0fa9e7 100644 --- a/interface/wx/window.h +++ b/interface/wx/window.h @@ -1588,6 +1588,21 @@ public: bool PopupMenu(wxMenu* menu, int x, int y); //@} + /** + Posts a size event to the window. + + This is the same as SendSizeEvent() with @c wxSEND_EVENT_POST argument. + */ + void PostSizeEvent(); + + /** + Posts a size event to the parent of this window. + + This is the same as SendSizeEventToParent() with @c wxSEND_EVENT_POST + argument. + */ + void PostSizeEventToParent(); + /** Pushes this event handler onto the event stack for the window. @@ -1793,8 +1808,16 @@ public: if the frame is using either sizers or constraints for the children layout, it is enough to call wxWindow::Layout() directly and this function should not be used in this case. + + If @a flags includes @c wxSEND_EVENT_POST value, this function posts + the event, i.e. schedules it for later processing, instead of + dispatching it directly. You can also use PostSizeEvent() as a more + readable equivalent of calling this function with this flag. + + @param flags + May include @c wxSEND_EVENT_POST. Default value is 0. */ - void SendSizeEvent(); + void SendSizeEvent(int flags = 0); /** Safe wrapper for GetParent()->SendSizeEvent(). @@ -1804,8 +1827,13 @@ public: used internally by windows such as toolbars changes to whose state should result in parent re-layout (e.g. when a toolbar is added to the top of the window, all the other windows must be shifted down). + + @see PostSizeEventToParent() + + @param flags + See description of this parameter in SendSizeEvent() documentation. */ - void SendSizeEventToParent(); + void SendSizeEventToParent(int flags = 0); /** Sets the accelerator table for this window. See wxAcceleratorTable. diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index bf4f7da301..b9942fa0a8 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -841,18 +841,21 @@ void wxWindowBase::DoGetScreenPosition(int *x, int *y) const ClientToScreen(x, y); } -void wxWindowBase::SendSizeEvent() +void wxWindowBase::SendSizeEvent(int flags) { wxSizeEvent event(GetSize(), GetId()); event.SetEventObject(this); - HandleWindowEvent(event); + if ( flags & wxSEND_EVENT_POST ) + wxPostEvent(this, event); + else + HandleWindowEvent(event); } -void wxWindowBase::SendSizeEventToParent() +void wxWindowBase::SendSizeEventToParent(int flags) { wxWindow * const parent = GetParent(); if ( parent && !parent->IsBeingDeleted() ) - parent->SendSizeEvent(); + parent->SendSizeEvent(flags); } // ---------------------------------------------------------------------------- diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index 3e4ff854b7..76615b04fa 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -310,15 +310,24 @@ void wxFrame::Raise() } // generate an artificial resize event -void wxFrame::SendSizeEvent() +void wxFrame::SendSizeEvent(int flags) { if ( !m_iconized ) { RECT r = wxGetWindowRect(GetHwnd()); - (void)::SendMessage(GetHwnd(), WM_SIZE, - IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, - MAKELPARAM(r.right - r.left, r.bottom - r.top)); + if ( flags & wxSEND_EVENT_POST ) + { + ::PostMessage(GetHwnd(), WM_SIZE, + IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, + MAKELPARAM(r.right - r.left, r.bottom - r.top)); + } + else // send it + { + ::SendMessage(GetHwnd(), WM_SIZE, + IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, + MAKELPARAM(r.right - r.left, r.bottom - r.top)); + } } } diff --git a/src/msw/statusbar.cpp b/src/msw/statusbar.cpp index 69826207de..4baebc470b 100644 --- a/src/msw/statusbar.cpp +++ b/src/msw/statusbar.cpp @@ -125,7 +125,11 @@ bool wxStatusBar::Create(wxWindow *parent, // we must refresh the frame size when the statusbar is created, because // its client area might change - SendSizeEventToParent(); + // + // notice that we must post the event, not send it, as the frame doesn't + // know that we're its status bar yet so laying it out right now wouldn't + // work correctly, we need to wait until we return to the main loop + PostSizeEventToParent(); return true; } @@ -135,7 +139,7 @@ wxStatusBar::~wxStatusBar() // we must refresh the frame size when the statusbar is deleted but the // frame is not - otherwise statusbar leaves a hole in the place it used to // occupy - SendSizeEventToParent(); + PostSizeEventToParent(); } void wxStatusBar::SetFieldsCount(int nFields, const int *widths) diff --git a/src/os2/toplevel.cpp b/src/os2/toplevel.cpp index fde6f06b6f..ff1c6d70e9 100644 --- a/src/os2/toplevel.cpp +++ b/src/os2/toplevel.cpp @@ -872,17 +872,28 @@ void wxTopLevelWindowOS2::Restore() } // end of wxTopLevelWindowOS2::Restore // generate an artificial resize event -void wxTopLevelWindowOS2::SendSizeEvent() +void wxTopLevelWindowOS2::SendSizeEvent(int flags) { if (!m_bIconized) { RECTL vRect = wxGetWindowRect(GetHwnd()); - (void)::WinPostMsg( m_hFrame - ,WM_SIZE - ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom) - ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom) - ); + if ( flags & wxSEND_EVENT_POST ) + { + (void)::WinPostMsg( m_hFrame + ,WM_SIZE + ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom) + ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom) + ); + } + else // send it + { + (void)::WinSendMsg( m_hFrame + ,WM_SIZE + ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom) + ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom) + ); + } } } // end of wxTopLevelWindowOS2::SendSizeEvent -- 2.45.2