From 0dba08dd3987303ff116bf77d5fb877b6d8f32d0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 29 Jul 2008 12:32:47 +0000 Subject: [PATCH] move SendSizeEvent() down to wxWindow from wxFrame; added SendSizeEventToParent() helper git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54803 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/frame.h | 3 --- include/wx/motif/frame.h | 3 +-- include/wx/msw/frame.h | 3 +-- include/wx/os2/frame.h | 2 -- include/wx/univ/frame.h | 3 --- include/wx/window.h | 21 +++++++++++++++++++-- interface/wx/frame.h | 11 ----------- interface/wx/window.h | 23 +++++++++++++++++++++++ src/common/framecmn.cpp | 9 --------- src/common/wincmn.cpp | 14 ++++++++++++++ src/motif/frame.cpp | 7 ------- src/msw/statusbar.cpp | 12 ++---------- src/msw/toolbar.cpp | 10 ++-------- src/os2/frame.cpp | 17 ----------------- src/univ/framuniv.cpp | 7 ------- src/univ/toolbar.cpp | 8 +------- 16 files changed, 63 insertions(+), 90 deletions(-) diff --git a/include/wx/frame.h b/include/wx/frame.h index 3816a57b3e..fe6694fbc7 100644 --- a/include/wx/frame.h +++ b/include/wx/frame.h @@ -72,9 +72,6 @@ public: // if the frame has a toolbar) in client coordinates virtual wxPoint GetClientAreaOrigin() const; - // sends a size event to the window using its current size -- this has an - // effect of refreshing the window layout - virtual void SendSizeEvent(); // menu bar functions // ------------------ diff --git a/include/wx/motif/frame.h b/include/wx/motif/frame.h index 9aa7129aa3..64f808bbad 100644 --- a/include/wx/motif/frame.h +++ b/include/wx/motif/frame.h @@ -87,10 +87,9 @@ public: bool PreResize(); - void SendSizeEvent(); - // for generic/mdig.h virtual void DoGetClientSize(int *width, int *height) const; + private: // common part of all ctors void Init(); diff --git a/include/wx/msw/frame.h b/include/wx/msw/frame.h index 11e881d5a8..50f8f16064 100644 --- a/include/wx/msw/frame.h +++ b/include/wx/msw/frame.h @@ -91,8 +91,7 @@ public: void SetToolTipCtrl(WXHWND hwndTT) { m_hwndToolTip = hwndTT; } #endif // tooltips - // a MSW only function which sends a size event to the window using its - // current size - this has an effect of refreshing the window layout + // override the base class function to handle iconized/maximized frames virtual void SendSizeEvent(); virtual wxPoint GetClientAreaOrigin() const; diff --git a/include/wx/os2/frame.h b/include/wx/os2/frame.h index b6e2c09e29..b8ad5deaef 100644 --- a/include/wx/os2/frame.h +++ b/include/wx/os2/frame.h @@ -125,8 +125,6 @@ public: void SetToolTipCtrl(WXHWND hHwndTT) { m_hWndToolTip = hHwndTT; } #endif // tooltips - virtual void SendSizeEvent(void); - void SetClient(WXHWND c_Hwnd); void SetClient(wxWindow* c_Window); wxWindow *GetClient(); diff --git a/include/wx/univ/frame.h b/include/wx/univ/frame.h index 924ea90a96..cd75831ca0 100644 --- a/include/wx/univ/frame.h +++ b/include/wx/univ/frame.h @@ -58,9 +58,6 @@ public: virtual wxSize GetMinSize() const; - // sends wxSizeEvent to itself (used after attaching xxxBar) - virtual void SendSizeEvent(); - protected: void OnSize(wxSizeEvent& event); void OnSysColourChanged(wxSysColourChangedEvent& event); diff --git a/include/wx/window.h b/include/wx/window.h index fc3f46dbc0..52712b7d22 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -528,8 +528,25 @@ public: // stretch over several lines). Parameter availableOtherDir // tells the item how much more space there is available in the opposite // direction (-1 if unknown). - virtual bool InformFirstDirection( int WXUNUSED(direction), int WXUNUSED(size), int WXUNUSED(availableOtherDir) ) - { return false; } + virtual bool + InformFirstDirection(int WXUNUSED(direction), + int WXUNUSED(size), + int WXUNUSED(availableOtherDir)) + { + return false; + } + + // sends a size event to the window using its current size -- this has an + // effect of refreshing the window layout + virtual void SendSizeEvent(); + + // 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(); + // window state // ------------ diff --git a/interface/wx/frame.h b/interface/wx/frame.h index aad65984d5..fd6c78c878 100644 --- a/interface/wx/frame.h +++ b/interface/wx/frame.h @@ -328,17 +328,6 @@ public: */ void ProcessCommand(int id); - /** - This function sends a dummy @ref overview_wxsizeevent "size event" to the frame - forcing it to reevaluate its children positions. It is sometimes useful to call - this function after adding or deleting a children after the frame creation or - if a child size changes. - Note that 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. - */ - void SendSizeEvent(); - /** Tells the frame to show the given menu bar. diff --git a/interface/wx/window.h b/interface/wx/window.h index c1106244e9..01c7fa6065 100644 --- a/interface/wx/window.h +++ b/interface/wx/window.h @@ -1784,6 +1784,29 @@ public: virtual void ScrollWindow(int dx, int dy, const wxRect* rect = NULL); + /** + This function sends a dummy @ref overview_wxsizeevent "size event" to + the window allowing it to re-layout its children positions. + + It is sometimes useful to call this function after adding or deleting a + children after the frame creation or if a child size changes. Note that + 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. + */ + void SendSizeEvent(); + + /** + Safe wrapper for GetParent()->SendSizeEvent(). + + This function simply checks that the window has a valid parent which is + not in process of being deleted and calls SendSizeEvent() on it. It is + 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). + */ + void SendSizeEventToParent(); + /** Sets the accelerator table for this window. See wxAcceleratorTable. */ diff --git a/src/common/framecmn.cpp b/src/common/framecmn.cpp index f09e2c67cc..61efbb6cf6 100644 --- a/src/common/framecmn.cpp +++ b/src/common/framecmn.cpp @@ -170,15 +170,6 @@ wxPoint wxFrameBase::GetClientAreaOrigin() const return pt; } - -void wxFrameBase::SendSizeEvent() -{ - wxSizeEvent event( GetSize(), GetId() ); - event.SetEventObject( this ); - GetEventHandler()->AddPendingEvent( event ); -} - - // ---------------------------------------------------------------------------- // misc // ---------------------------------------------------------------------------- diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 6ccc05323e..bf4f7da301 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -841,6 +841,20 @@ void wxWindowBase::DoGetScreenPosition(int *x, int *y) const ClientToScreen(x, y); } +void wxWindowBase::SendSizeEvent() +{ + wxSizeEvent event(GetSize(), GetId()); + event.SetEventObject(this); + HandleWindowEvent(event); +} + +void wxWindowBase::SendSizeEventToParent() +{ + wxWindow * const parent = GetParent(); + if ( parent && !parent->IsBeingDeleted() ) + parent->SendSizeEvent(); +} + // ---------------------------------------------------------------------------- // show/hide/enable/disable the window // ---------------------------------------------------------------------------- diff --git a/src/motif/frame.cpp b/src/motif/frame.cpp index 355b54f48a..184daa28e0 100644 --- a/src/motif/frame.cpp +++ b/src/motif/frame.cpp @@ -557,13 +557,6 @@ void wxFrame::OnActivate(wxActivateEvent& event) } } -void wxFrame::SendSizeEvent() -{ - wxSizeEvent event(GetSize(), GetId()); - event.SetEventObject(this); - GetEventHandler()->AddPendingEvent(event); -} - #if wxUSE_TOOLBAR wxToolBar* wxFrame::CreateToolBar(long style, diff --git a/src/msw/statusbar.cpp b/src/msw/statusbar.cpp index aef8e5c567..69826207de 100644 --- a/src/msw/statusbar.cpp +++ b/src/msw/statusbar.cpp @@ -125,11 +125,7 @@ bool wxStatusBar::Create(wxWindow *parent, // we must refresh the frame size when the statusbar is created, because // its client area might change - wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); - if ( frame ) - { - frame->SendSizeEvent(); - } + SendSizeEventToParent(); return true; } @@ -139,11 +135,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 - wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); - if ( frame && !frame->IsBeingDeleted() ) - { - frame->SendSizeEvent(); - } + SendSizeEventToParent(); } void wxStatusBar::SetFieldsCount(int nFields, const int *widths) diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index e8c47e5ed3..33c4950b30 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -397,9 +397,7 @@ wxToolBar::~wxToolBar() { // we must refresh the frame size when the toolbar is deleted but the frame // is not - otherwise toolbar leaves a hole in the place it used to occupy - wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); - if ( frame && !frame->IsBeingDeleted() ) - frame->SendSizeEvent(); + SendSizeEventToParent(); if ( m_hBitmap ) ::DeleteObject((HBITMAP) m_hBitmap); @@ -1422,11 +1420,7 @@ void wxToolBar::UpdateSize() // toolbar to full width again, but only if the parent is a frame and the // toolbar is managed by the frame. Otherwise assume that some other // layout mechanism is controlling the toolbar size and leave it alone. - wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); - if ( frame && frame->GetToolBar() == this ) - { - frame->SendSizeEvent(); - } + SendSizeEventToParent(); } // ---------------------------------------------------------------------------- diff --git a/src/os2/frame.cpp b/src/os2/frame.cpp index 567fa20eb6..98dbc1ba94 100644 --- a/src/os2/frame.cpp +++ b/src/os2/frame.cpp @@ -1379,20 +1379,3 @@ wxWindow* wxFrame::GetClient() return wxFindWinFromHandle((WXHWND)::WinWindowFromID(m_hFrame, FID_CLIENT)); } -void wxFrame::SendSizeEvent() -{ - if (!m_bIconized) - { - RECTL vRect = wxGetWindowRect(GetHwnd()); - - ::WinPostMsg( GetHwnd() - ,WM_SIZE - ,MPFROM2SHORT( vRect.xRight - vRect.xLeft - ,vRect.xRight - vRect.xLeft - ) - ,MPFROM2SHORT( vRect.yTop - vRect.yBottom - ,vRect.yTop - vRect.yBottom - ) - ); - } -} diff --git a/src/univ/framuniv.cpp b/src/univ/framuniv.cpp index 91c5a9d7eb..cb7aa42d0b 100644 --- a/src/univ/framuniv.cpp +++ b/src/univ/framuniv.cpp @@ -92,13 +92,6 @@ void wxFrame::OnSize(wxSizeEvent& event) event.Skip(); } -void wxFrame::SendSizeEvent() -{ - wxSizeEvent event(GetSize(), GetId()); - event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); -} - #if wxUSE_MENUS void wxFrame::PositionMenuBar() diff --git a/src/univ/toolbar.cpp b/src/univ/toolbar.cpp index 41dc5d2281..9b36cc74ac 100644 --- a/src/univ/toolbar.cpp +++ b/src/univ/toolbar.cpp @@ -587,13 +587,7 @@ void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags) // otherwise the toolbar can be shown incorrectly if ( old_width != width || old_height != height ) { - // But before we send the size event check it - // we have a frame that is not being deleted. - wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); - if ( frame && !frame->IsBeingDeleted() ) - { - frame->SendSizeEvent(); - } + SendSizeEventToParent(); } } -- 2.45.2