Add wxControl::GetSizeFromTextSize() to size the control to its text.
This function can be used to size a, say, wxTextCtrl to be exactly of the size needed to enter the given amount of text in it. This patch adds wxGTK implementation for wxTextCtrl, wxChoice and wxCombobox; changes to the samples and the documentation. Closes #14812. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72935 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1820,13 +1820,55 @@ void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
|
||||
|
||||
wxSize wxTextCtrl::DoGetBestSize() const
|
||||
{
|
||||
// FIXME should be different for multi-line controls...
|
||||
wxSize ret( wxControl::DoGetBestSize() );
|
||||
wxSize best(80, ret.y);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
return DoGetSizeFromTextSize(80);
|
||||
}
|
||||
|
||||
wxSize wxTextCtrl::DoGetSizeFromTextSize(int xlen, int ylen) const
|
||||
{
|
||||
wxASSERT_MSG( m_widget, wxS("GetSizeFromTextSize called before creation") );
|
||||
|
||||
wxSize tsize(xlen, 0);
|
||||
int cHeight = GetCharHeight();
|
||||
|
||||
if ( IsSingleLine() )
|
||||
{
|
||||
// default height
|
||||
tsize.y = GTKGetPreferredSize(m_widget).y;
|
||||
// Add the margins we have previously set, but only the horizontal border
|
||||
// as vertical one has been taken account at GTKGetPreferredSize().
|
||||
// Also get other GTK+ margins.
|
||||
tsize.IncBy( GTKGetEntryMargins(GetEntry()).x, 0);
|
||||
}
|
||||
|
||||
//multiline
|
||||
else
|
||||
{
|
||||
// add space for vertical scrollbar
|
||||
if ( m_scrollBar[1] && !(m_windowStyle & wxTE_NO_VSCROLL) )
|
||||
tsize.IncBy(GTKGetPreferredSize(GTK_WIDGET(m_scrollBar[1])).x + 3, 0);
|
||||
|
||||
// height
|
||||
tsize.y = cHeight;
|
||||
if ( ylen <= 0 )
|
||||
{
|
||||
tsize.y = cHeight * wxMax(wxMin(GetNumberOfLines(), 10), 2);
|
||||
// add space for horizontal scrollbar
|
||||
if ( m_scrollBar[0] && (m_windowStyle & wxHSCROLL) )
|
||||
tsize.IncBy(0, GTKGetPreferredSize(GTK_WIDGET(m_scrollBar[0])).y + 3);
|
||||
}
|
||||
|
||||
// hardcode borders, margins, etc
|
||||
tsize.IncBy(5, 5);
|
||||
}
|
||||
|
||||
// Perhaps the user wants something different from CharHeight
|
||||
if ( ylen > 0 )
|
||||
tsize.IncBy(0, ylen - cHeight);
|
||||
|
||||
return tsize;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// freeze/thaw
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user