From dda4f6c089cd8db779cd10904be3263c72d98700 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Tue, 10 Dec 2002 21:41:31 +0000 Subject: [PATCH] Applied patch [ 651640 ] Toolbar sizing fix This patch fixes the problem discussed on wx-dev mailing list. (Message title "wxUniversal: How is the parent notified when a child changes its size") In short: - This patch makes sure the toolbar notifies the parent of any size change, this will give the parent the opportunity to resize the frame client size and to make sure the toolbar is in the right place. Hans Van Leemputten git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18181 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/univ/frame.h | 6 +++--- include/wx/univ/toolbar.h | 3 +++ src/univ/toolbar.cpp | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/include/wx/univ/frame.h b/include/wx/univ/frame.h index a181bba996..4f13277f1e 100644 --- a/include/wx/univ/frame.h +++ b/include/wx/univ/frame.h @@ -64,12 +64,12 @@ public: virtual int GetMinWidth() const; virtual int GetMinHeight() const; + // sends wxSizeEvent to itself (used after attaching xxxBar) + virtual void SendSizeEvent(); + protected: void OnSize(wxSizeEvent& event); - // sends wxSizeEvent to itself (used after attaching xxxBar) - void SendSizeEvent(); - virtual void DoGetClientSize(int *width, int *height) const; virtual void DoSetClientSize(int width, int height); diff --git a/include/wx/univ/toolbar.h b/include/wx/univ/toolbar.h index 5ca1a31a68..5aa190b196 100644 --- a/include/wx/univ/toolbar.h +++ b/include/wx/univ/toolbar.h @@ -98,6 +98,9 @@ protected: long numArg = -1, const wxString& strArg = wxEmptyString); virtual wxSize DoGetBestClientSize() const; + virtual void DoSetSize(int x, int y, + int width, int height, + int sizeFlags = wxSIZE_AUTO); virtual void DoDraw(wxControlRenderer *renderer); // get the bounding rect for the given tool diff --git a/src/univ/toolbar.cpp b/src/univ/toolbar.cpp index 1745a900fd..8f77a0470e 100644 --- a/src/univ/toolbar.cpp +++ b/src/univ/toolbar.cpp @@ -156,6 +156,8 @@ bool wxToolBar::Create(wxWindow *parent, wxToolBar::~wxToolBar() { + // Make sure the toolbar is removed from the parent. + SetSize(0,0); } void wxToolBar::SetMargins(int x, int y) @@ -423,6 +425,39 @@ wxSize wxToolBar::DoGetBestClientSize() const return wxSize(m_maxWidth, m_maxHeight); } +void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags) +{ + int old_width, old_height; + GetSize(&old_width, &old_height); + + wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags); + + // Correct width and height if needed. + if ( width == -1 || height == -1 ) + { + int tmp_width, tmp_height; + GetSize(&tmp_width, &tmp_height); + + if ( width == -1 ) + width = tmp_width; + if ( height == -1 ) + height = tmp_height; + } + + // We must refresh the frame size when the toolbar changes size + // 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(); + } + } +} + // ---------------------------------------------------------------------------- // wxToolBar drawing // ---------------------------------------------------------------------------- -- 2.45.2