From f0aea4098c3f65a1af27aa36142cd9060d11f077 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 24 Oct 2014 21:54:31 +0000 Subject: [PATCH] Refactor: extra wxStaticText auto-resizing code from wxMSW to common. This will allow its reuse in wxGenericStaticText and maybe other ports that need it in the future. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78061 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/stattext.h | 4 ++++ src/common/stattextcmn.cpp | 12 ++++++++++++ src/msw/stattext.cpp | 23 ++++++----------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/include/wx/stattext.h b/include/wx/stattext.h index 5b85b6c8f1..810a26167d 100644 --- a/include/wx/stattext.h +++ b/include/wx/stattext.h @@ -78,6 +78,10 @@ protected: // functions required for wxST_ELLIPSIZE_* support // but may contain the mnemonic characters. virtual void DoSetLabel(const wxString& WXUNUSED(str)) { } + // Update the current size to match the best size unless wxST_NO_AUTORESIZE + // style is explicitly used. + void AutoResizeIfNecessary(); + private: wxDECLARE_NO_COPY_CLASS(wxStaticTextBase); }; diff --git a/src/common/stattextcmn.cpp b/src/common/stattextcmn.cpp index b59869d4eb..78e1793c7c 100644 --- a/src/common/stattextcmn.cpp +++ b/src/common/stattextcmn.cpp @@ -194,6 +194,18 @@ void wxStaticTextBase::Wrap(int width) wrapper.WrapLabel(this, width); } +void wxStaticTextBase::AutoResizeIfNecessary() +{ + // adjust the size of the window to fit to the label unless autoresizing is + // disabled + if ( !HasFlag(wxST_NO_AUTORESIZE) ) + { + InvalidateBestSize(); + DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, + wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); + } +} + // ---------------------------------------------------------------------------- // wxStaticTextBase - generic implementation for wxST_ELLIPSIZE_* support // ---------------------------------------------------------------------------- diff --git a/src/msw/stattext.cpp b/src/msw/stattext.cpp index 1eb8b24acd..846d3d2a7c 100644 --- a/src/msw/stattext.cpp +++ b/src/msw/stattext.cpp @@ -186,31 +186,20 @@ void wxStaticText::SetLabel(const wxString& label) #endif // SS_ENDELLIPSIS DoSetLabel(GetEllipsizedLabel()); - // adjust the size of the window to fit to the label unless autoresizing is - // disabled - if ( !HasFlag(wxST_NO_AUTORESIZE) && - !IsEllipsized() ) // if ellipsize is ON, then we don't want to get resized! + if ( !IsEllipsized() ) // if ellipsize is ON, then we don't want to get resized! { - InvalidateBestSize(); - DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, - wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); + AutoResizeIfNecessary(); } } bool wxStaticText::SetFont(const wxFont& font) { - bool ret = wxControl::SetFont(font); + if ( !wxControl::SetFont(font) ) + return false; - // adjust the size of the window to fit to the label unless autoresizing is - // disabled - if ( !HasFlag(wxST_NO_AUTORESIZE) ) - { - InvalidateBestSize(); - DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, - wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); - } + AutoResizeIfNecessary(); - return ret; + return true; } // for wxST_ELLIPSIZE_* support: