virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO);
+ virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
// Show or hide the popup part of the control.
void MSWDoPopupOrDismiss(bool show);
virtual void DoSetToolTip(wxToolTip *tip);
#endif
+ virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
+
// this is the implementation of GetEditHWND() which can also be used when
// we don't have the edit control, it simply returns NULL then
//
bool SendUpdateEvent();
virtual wxSize DoGetBestSize() const;
+ virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
#if wxUSE_RICHEDIT
// Apply the character-related parts of wxTextAttr to the given selection
@endcode
Currently this method is only implemented for wxTextCtrl, wxComboBox
- and wxChoice in wxGTK.
+ and wxChoice in wxMSW and wxGTK.
@param xlen The horizontal extent of the area to leave for text, in
pixels.
wxSize wxChoice::DoGetBestSize() const
{
// The base version returns the size of the largest string
- wxSize best( wxChoiceBase::DoGetBestSize() );
-
- // We just need to adjust it to account for the arrow width.
- best.x += 5*GetCharWidth();
-
- // set height on our own
- if( HasFlag( wxCB_SIMPLE ) )
- best.y = SetHeightSimpleComboBox(GetCount());
- else
- best.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(GetCharHeight());
-
- return best;
+ return GetSizeFromTextSize(wxChoiceBase::DoGetBestSize().x);
}
int wxChoice::SetHeightSimpleComboBox(int nItems) const
return EDIT_HEIGHT_FROM_CHAR_HEIGHT( cy ) * wxMin( wxMax( nItems, 3 ), 6 ) + hItem - 1;
}
+wxSize wxChoice::DoGetSizeFromTextSize(int xlen, int ylen) const
+{
+ int cHeight = GetCharHeight();
+
+ // We are interested in the difference of sizes between the whole control
+ // and its child part. I.e. arrow, separators, etc.
+ wxSize tsize(xlen, 0);
+
+ WinStruct<COMBOBOXINFO> info;
+ if ( MSWGetComboBoxInfo(&info) )
+ {
+ tsize.x += info.rcItem.left + info.rcButton.right - info.rcItem.right
+ + info.rcItem.left + 3; // right and extra margins
+ }
+ else // Just use some rough approximation.
+ {
+ tsize.x += 4*cHeight;
+ }
+
+ // set height on our own
+ if( HasFlag( wxCB_SIMPLE ) )
+ tsize.y = SetHeightSimpleComboBox(GetCount());
+ else
+ tsize.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cHeight);
+
+ // Perhaps the user wants something different from CharHeight
+ if ( ylen > 0 )
+ tsize.IncBy(0, ylen - cHeight);
+
+ return tsize;
+}
+
// ----------------------------------------------------------------------------
// Popup operations
// ----------------------------------------------------------------------------
#endif // wxUSE_UXTHEME
+wxSize wxComboBox::DoGetSizeFromTextSize(int xlen, int ylen) const
+{
+ wxSize tsize( wxChoice::DoGetSizeFromTextSize(xlen, ylen) );
+
+ if ( !HasFlag(wxCB_READONLY) )
+ {
+ // Add the margins we have previously set
+ wxPoint marg( GetMargins() );
+ marg.x = wxMax(0, marg.x);
+ marg.y = wxMax(0, marg.y);
+ tsize.IncBy( marg );
+ }
+
+ return tsize;
+}
+
#endif // wxUSE_COMBOBOX
}
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
// 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);
}