Merge branch 'stattext-no-resize'

Avoid unexpected changes to wxStaticText size with wxST_NO_AUTORESIZE.

See https://github.com/wxWidgets/wxWidgets/pull/675
This commit is contained in:
Vadim Zeitlin
2018-01-23 15:49:03 +01:00
5 changed files with 26 additions and 42 deletions

View File

@@ -205,13 +205,22 @@ void wxStaticTextBase::Wrap(int width)
void wxStaticTextBase::AutoResizeIfNecessary() void wxStaticTextBase::AutoResizeIfNecessary()
{ {
// adjust the size of the window to fit to the label unless autoresizing is // This flag is specifically used to prevent the control from resizing even
// disabled // when its label changes.
if ( !HasFlag(wxST_NO_AUTORESIZE) ) if ( HasFlag(wxST_NO_AUTORESIZE) )
{ return;
DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord,
wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT); // This method is only called if either the label or the font changed, i.e.
} // if the label extent changed, so the best size is not the same neither
// any more.
//
// Note that we don't invalidate it when wxST_NO_AUTORESIZE is on because
// this would result in the control being effectively resized during the
// next Layout() and this style is used expressly to prevent this from
// happening.
InvalidateBestSize();
SetSize(GetBestSize());
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -102,10 +102,7 @@ void wxGenericStaticText::SetLabel(const wxString& label)
wxControl::SetLabel(label); wxControl::SetLabel(label);
DoSetLabel(GetEllipsizedLabel()); DoSetLabel(GetEllipsizedLabel());
InvalidateBestSize(); AutoResizeIfNecessary();
if ( !IsEllipsized() )
AutoResizeIfNecessary();
#if wxUSE_MARKUP #if wxUSE_MARKUP
if ( m_markupText ) if ( m_markupText )

View File

@@ -138,14 +138,9 @@ void wxStaticText::GTKDoSetLabel(GTKLabelSetter setter, const wxString& label)
{ {
wxCHECK_RET( m_widget != NULL, wxT("invalid static text") ); wxCHECK_RET( m_widget != NULL, wxT("invalid static text") );
InvalidateBestSize();
(this->*setter)(GTK_LABEL(m_widget), label); (this->*setter)(GTK_LABEL(m_widget), label);
// adjust the label size to the new label unless disabled AutoResizeIfNecessary();
if ( !HasFlag(wxST_NO_AUTORESIZE) &&
!IsEllipsized() ) // if ellipsization is ON, then we don't want to get resized!
SetSize( GetBestSize() );
} }
void wxStaticText::SetLabel(const wxString& label) void wxStaticText::SetLabel(const wxString& label)
@@ -180,7 +175,8 @@ bool wxStaticText::SetFont( const wxFont &font )
const bool wasUnderlined = GetFont().GetUnderlined(); const bool wasUnderlined = GetFont().GetUnderlined();
const bool wasStrickenThrough = GetFont().GetStrikethrough(); const bool wasStrickenThrough = GetFont().GetStrikethrough();
bool ret = wxControl::SetFont(font); if ( !wxControl::SetFont(font) )
return false;
const bool isUnderlined = GetFont().GetUnderlined(); const bool isUnderlined = GetFont().GetUnderlined();
const bool isStrickenThrough = GetFont().GetStrikethrough(); const bool isStrickenThrough = GetFont().GetStrikethrough();
@@ -222,12 +218,9 @@ bool wxStaticText::SetFont( const wxFont &font )
gtk_label_set_use_underline(GTK_LABEL(m_widget), !isUnderlined); gtk_label_set_use_underline(GTK_LABEL(m_widget), !isUnderlined);
} }
// adjust the label size to the new label unless disabled AutoResizeIfNecessary();
if (!HasFlag(wxST_NO_AUTORESIZE))
{ return true;
SetSize( GetBestSize() );
}
return ret;
} }
wxSize wxStaticText::DoGetBestSize() const wxSize wxStaticText::DoGetBestSize() const

View File

@@ -184,12 +184,7 @@ void wxStaticText::SetLabel(const wxString& label)
#endif // SS_ENDELLIPSIS #endif // SS_ENDELLIPSIS
DoSetLabel(GetEllipsizedLabel()); DoSetLabel(GetEllipsizedLabel());
InvalidateBestSize(); AutoResizeIfNecessary();
if ( !IsEllipsized() ) // if ellipsize is ON, then we don't want to get resized!
{
AutoResizeIfNecessary();
}
} }
bool wxStaticText::SetFont(const wxFont& font) bool wxStaticText::SetFont(const wxFont& font)

View File

@@ -78,13 +78,7 @@ void wxStaticText::SetLabel(const wxString& label)
DoSetLabel(GetEllipsizedLabel()); DoSetLabel(GetEllipsizedLabel());
} }
InvalidateBestSize(); AutoResizeIfNecessary();
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) &&
!IsEllipsized() ) // don't resize if we adjust to current size
{
SetSize( GetBestSize() );
}
Refresh(); Refresh();
@@ -98,11 +92,7 @@ bool wxStaticText::SetFont(const wxFont& font)
if ( ret ) if ( ret )
{ {
if ( !(GetWindowStyle() & wxST_NO_AUTORESIZE) ) AutoResizeIfNecessary();
{
InvalidateBestSize();
SetSize( GetBestSize() );
}
} }
return ret; return ret;