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
This commit is contained in:
Vadim Zeitlin
2014-10-24 21:54:31 +00:00
parent 4936366716
commit f0aea4098c
3 changed files with 22 additions and 17 deletions

View File

@@ -78,6 +78,10 @@ protected: // functions required for wxST_ELLIPSIZE_* support
// but may contain the mnemonic characters. // but may contain the mnemonic characters.
virtual void DoSetLabel(const wxString& WXUNUSED(str)) { } 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: private:
wxDECLARE_NO_COPY_CLASS(wxStaticTextBase); wxDECLARE_NO_COPY_CLASS(wxStaticTextBase);
}; };

View File

@@ -194,6 +194,18 @@ void wxStaticTextBase::Wrap(int width)
wrapper.WrapLabel(this, 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 // wxStaticTextBase - generic implementation for wxST_ELLIPSIZE_* support
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -186,31 +186,20 @@ void wxStaticText::SetLabel(const wxString& label)
#endif // SS_ENDELLIPSIS #endif // SS_ENDELLIPSIS
DoSetLabel(GetEllipsizedLabel()); DoSetLabel(GetEllipsizedLabel());
// adjust the size of the window to fit to the label unless autoresizing is if ( !IsEllipsized() ) // if ellipsize is ON, then we don't want to get resized!
// disabled
if ( !HasFlag(wxST_NO_AUTORESIZE) &&
!IsEllipsized() ) // if ellipsize is ON, then we don't want to get resized!
{ {
InvalidateBestSize(); AutoResizeIfNecessary();
DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord,
wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
} }
} }
bool wxStaticText::SetFont(const wxFont& font) 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 AutoResizeIfNecessary();
// disabled
if ( !HasFlag(wxST_NO_AUTORESIZE) )
{
InvalidateBestSize();
DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord,
wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
}
return ret; return true;
} }
// for wxST_ELLIPSIZE_* support: // for wxST_ELLIPSIZE_* support: