From 6528a7f14507ed235ab087d63e3a0be68ea9b1b8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 23 May 2009 11:26:58 +0000 Subject: [PATCH] make wxWindow::SetAutoLayout() now works for all windows, not just panels git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60722 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/generic/panelg.h | 3 --- include/wx/window.h | 5 +++++ interface/wx/window.h | 21 ++++++++++--------- src/common/wincmn.cpp | 9 ++++++++ src/generic/panelg.cpp | 41 ------------------------------------- src/html/htmlwin.cpp | 3 ++- 7 files changed, 28 insertions(+), 55 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 9ffd122ebf..2772b26810 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -333,6 +333,7 @@ All: All (GUI): +- wxWindow::SetAutoLayout() now works for all windows, not just panels. - Support loading wxListCtrl items and image lists from XRC (Kinaou Hervé). - wxGrid: add possibility to prevent resizing of individual rows/columns. - wxHTML: add support for table borders width (Laurent Humbertclaude). diff --git a/include/wx/generic/panelg.h b/include/wx/generic/panelg.h index 8d5475a46d..5824c0efc4 100644 --- a/include/wx/generic/panelg.h +++ b/include/wx/generic/panelg.h @@ -70,9 +70,6 @@ public: // implementation from now on // -------------------------- - // calls layout for layout constraints and sizers - void OnSize(wxSizeEvent& event); - virtual void InitDialog(); #ifdef __WXUNIVERSAL__ diff --git a/include/wx/window.h b/include/wx/window.h index c9243e7027..7e2470214a 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -1694,6 +1694,11 @@ private: int DoGetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y); #endif // wxUSE_MENUS + // layout the window children when its size changes unless this was + // explicitly disabled with SetAutoLayout(false) + void InternalOnSize(wxSizeEvent& event); + + // the stack of windows which have captured the mouse static struct WXDLLIMPEXP_FWD_CORE wxWindowNext *ms_winCaptureNext; diff --git a/interface/wx/window.h b/interface/wx/window.h index 6eb30c66bb..4835c550b8 100644 --- a/interface/wx/window.h +++ b/interface/wx/window.h @@ -2600,19 +2600,23 @@ public: /** Sets the window to have the given layout sizer. + The window will then own the object, and will take care of its deletion. If an existing layout constraints object is already owned by the - window, it will be deleted if the deleteOld parameter is @true. + window, it will be deleted if the @a deleteOld parameter is @true. Note that this function will also call SetAutoLayout() implicitly with @true - parameter if the @a sizer is non-@NULL and @false otherwise. + parameter if the @a sizer is non-@NULL and @false otherwise so that the + sizer will be effectively used to layout the window children whenever + it is resized. @param sizer The sizer to set. Pass @NULL to disassociate and conditionally delete the window's sizer. See below. @param deleteOld If @true (the default), this will delete any pre-existing sizer. - Pass @false if you wish to handle deleting the old sizer yourself. + Pass @false if you wish to handle deleting the old sizer yourself + but remember to do it yourself in this case to avoid memory leaks. @remarks SetSizer enables and disables Layout automatically. */ @@ -2665,20 +2669,17 @@ public: /** Determines whether the Layout() function will be called automatically - when the window is resized. Please note that this only happens for the - windows usually used to contain children, namely wxPanel and wxTopLevelWindow - (and the classes deriving from them). + when the window is resized. This method is called implicitly by SetSizer() but if you use SetConstraints() you should call it manually or otherwise the window layout won't be correctly updated when its size changes. @param autoLayout - Set this to @true if you wish the Layout() function to be - called automatically when the window is resized - (really happens only if you derive from wxPanel or wxTopLevelWindow). + Set this to @true if you wish the Layout() function to be called + automatically when the window is resized. - @see SetConstraints() + @see SetSizer(), SetConstraints() */ void SetAutoLayout(bool autoLayout); diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index cd95242587..8d3fa0af2c 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -102,6 +102,7 @@ BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler) EVT_HELP(wxID_ANY, wxWindowBase::OnHelp) #endif // wxUSE_HELP + EVT_SIZE(wxWindowBase::InternalOnSize) END_EVENT_TABLE() // ============================================================================ @@ -2095,6 +2096,14 @@ bool wxWindowBase::Layout() return true; } +void wxWindowBase::InternalOnSize(wxSizeEvent& event) +{ + if ( GetAutoLayout() ) + Layout(); + + event.Skip(); +} + #if wxUSE_CONSTRAINTS // first phase of the constraints evaluation: set our own constraints diff --git a/src/generic/panelg.cpp b/src/generic/panelg.cpp index d714bce3c0..3bff49d8d7 100644 --- a/src/generic/panelg.cpp +++ b/src/generic/panelg.cpp @@ -88,8 +88,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxPanel, wxWindow) #endif BEGIN_EVENT_TABLE(wxPanel, wxWindow) - EVT_SIZE(wxPanel::OnSize) - WX_EVENT_TABLE_CONTROL_CONTAINER(wxPanel) END_EVENT_TABLE() @@ -139,42 +137,3 @@ void wxPanel::InitDialog() GetEventHandler()->ProcessEvent(event); } -// ---------------------------------------------------------------------------- -// event handlers -// ---------------------------------------------------------------------------- - -void wxPanel::OnSize(wxSizeEvent& event) -{ - if (GetAutoLayout()) - Layout(); -#if wxUSE_CONSTRAINTS -#if defined(__WXPM__) && 0 - else - { - // Need to properly move child windows under OS/2 - - PSWP pWinSwp = GetSwp(); - - if (pWinSwp->cx == 0 && pWinSwp->cy == 0 && pWinSwp->fl == 0) - { - // Uninitialized - - ::WinQueryWindowPos(GetHWND(), pWinSwp); - } - else - { - SWP vSwp; - int nYDiff; - - ::WinQueryWindowPos(GetHWND(), &vSwp); - nYDiff = pWinSwp->cy - vSwp.cy; - MoveChildren(nYDiff); - pWinSwp->cx = vSwp.cx; - pWinSwp->cy = vSwp.cy; - } - } -#endif -#endif // wxUSE_CONSTRAINTS - - event.Skip(); -} diff --git a/src/html/htmlwin.cpp b/src/html/htmlwin.cpp index 56c6f5d7b7..82f7c10557 100644 --- a/src/html/htmlwin.cpp +++ b/src/html/htmlwin.cpp @@ -1103,9 +1103,10 @@ void wxHtmlWindow::OnPaint(wxPaintEvent& WXUNUSED(event)) void wxHtmlWindow::OnSize(wxSizeEvent& event) { + event.Skip(); + wxDELETE(m_backBuffer); - wxScrolledWindow::OnSize(event); CreateLayout(); // Recompute selection if necessary: -- 2.45.2