Implement DoGetSizeFromTextSize() for wxMSW wx{Choice,Combobox,TextCtrl}.
Refactor and improve the existing DoGetBestSize() implementations to use DoGetBestSize(). Closes #14816. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72954 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2106,18 +2106,42 @@ bool wxTextCtrl::AcceptsFocusFromKeyboard() const
|
||||
}
|
||||
|
||||
wxSize wxTextCtrl::DoGetBestSize() const
|
||||
{
|
||||
return DoGetSizeFromTextSize( DEFAULT_ITEM_WIDTH );
|
||||
}
|
||||
|
||||
wxSize wxTextCtrl::DoGetSizeFromTextSize(int xlen, int ylen) const
|
||||
{
|
||||
int cx, cy;
|
||||
wxGetCharSize(GetHWND(), &cx, &cy, GetFont());
|
||||
|
||||
int wText = DEFAULT_ITEM_WIDTH;
|
||||
DWORD wText = 1;
|
||||
::SystemParametersInfo(SPI_GETCARETWIDTH, 0, &wText, 0);
|
||||
wText += xlen;
|
||||
|
||||
int hText = cy;
|
||||
if ( m_windowStyle & wxTE_MULTILINE )
|
||||
{
|
||||
hText *= wxMax(wxMin(GetNumberOfLines(), 10), 2);
|
||||
// add space for vertical scrollbar
|
||||
if ( !(m_windowStyle & wxTE_NO_VSCROLL) )
|
||||
wText += ::GetSystemMetrics(SM_CXVSCROLL);
|
||||
|
||||
if ( ylen <= 0 )
|
||||
{
|
||||
hText *= wxMax(wxMin(GetNumberOfLines(), 10), 2);
|
||||
// add space for horizontal scrollbar
|
||||
if ( m_windowStyle & wxHSCROLL )
|
||||
hText += ::GetSystemMetrics(SM_CYHSCROLL);
|
||||
}
|
||||
}
|
||||
// for single line control cy (height + external leading) is ok
|
||||
else
|
||||
{
|
||||
// Add the margins we have previously set
|
||||
wxPoint marg( GetMargins() );
|
||||
wText += wxMax(0, marg.x);
|
||||
hText += wxMax(0, marg.y);
|
||||
}
|
||||
//else: for single line control everything is ok
|
||||
|
||||
// Text controls without border are special and have the same height as
|
||||
// static labels (they also have the same appearance when they're disable
|
||||
@@ -2126,11 +2150,18 @@ wxSize wxTextCtrl::DoGetBestSize() const
|
||||
// stand out).
|
||||
if ( !HasFlag(wxBORDER_NONE) )
|
||||
{
|
||||
wText += 9; // borders and inner margins
|
||||
|
||||
// we have to add the adjustments for the control height only once, not
|
||||
// once per line, so do it after multiplication above
|
||||
hText += EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) - cy;
|
||||
}
|
||||
|
||||
// Perhaps the user wants something different from CharHeight, or ylen
|
||||
// is used as the height of a multiline text.
|
||||
if ( ylen > 0 )
|
||||
hText += ylen - GetCharHeight();
|
||||
|
||||
return wxSize(wText, hText);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user