Applied #10025 (Patch to allow proper sizing of simple combo box)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62058 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2009-09-24 09:07:13 +00:00
parent fe56156fb5
commit da89830af4
2 changed files with 31 additions and 6 deletions

View File

@ -135,6 +135,9 @@ protected:
// free all memory we have (used by Clear() and dtor) // free all memory we have (used by Clear() and dtor)
void Free(); void Free();
// set the height for simple combo box
int SetHeightSimpleComboBox(int nItems) const;
#if wxUSE_DEFERRED_SIZING #if wxUSE_DEFERRED_SIZING
virtual void MSWEndDeferWindowPos(); virtual void MSWEndDeferWindowPos();
#endif // wxUSE_DEFERRED_SIZING #endif // wxUSE_DEFERRED_SIZING

View File

@ -552,13 +552,20 @@ void wxChoice::DoSetSize(int x, int y,
// don't make the drop down list too tall, arbitrarily limit it to 30 // don't make the drop down list too tall, arbitrarily limit it to 30
// items max and also don't make it too small if it's currently empty // items max and also don't make it too small if it's currently empty
size_t nItems = GetCount(); size_t nItems = GetCount();
if ( !nItems ) if (!HasFlag(wxCB_SIMPLE))
nItems = 9; {
else if ( nItems > 30 ) if ( !nItems )
nItems = 30; nItems = 9;
else if ( nItems > 30 )
nItems = 30;
}
const int hItem = SendMessage(GetHwnd(), CB_GETITEMHEIGHT, 0, 0); const int hItem = SendMessage(GetHwnd(), CB_GETITEMHEIGHT, 0, 0);
const int heightWithItems = height + hItem*nItems; int heightWithItems = 0;
if (!HasFlag(wxCB_SIMPLE))
heightWithItems = height + hItem*nItems;
else
heightWithItems = SetHeightSimpleComboBox(nItems);
// do resize the native control // do resize the native control
@ -592,6 +599,7 @@ wxSize wxChoice::DoGetBestSize() const
{ {
// find the widest string // find the widest string
int wChoice = 0; int wChoice = 0;
int hChoice;
const unsigned int nItems = GetCount(); const unsigned int nItems = GetCount();
for ( unsigned int i = 0; i < nItems; i++ ) for ( unsigned int i = 0; i < nItems; i++ )
{ {
@ -608,12 +616,26 @@ wxSize wxChoice::DoGetBestSize() const
// the combobox should be slightly larger than the widest string // the combobox should be slightly larger than the widest string
wChoice += 5*GetCharWidth(); wChoice += 5*GetCharWidth();
if( HasFlag( wxCB_SIMPLE ) )
{
hChoice = SetHeightSimpleComboBox( nItems );
}
else
hChoice = EDIT_HEIGHT_FROM_CHAR_HEIGHT(GetCharHeight());
wxSize best(wChoice, EDIT_HEIGHT_FROM_CHAR_HEIGHT(GetCharHeight())); wxSize best(wChoice, hChoice);
CacheBestSize(best); CacheBestSize(best);
return best; return best;
} }
int wxChoice::SetHeightSimpleComboBox(int nItems) const
{
int cx, cy;
wxGetCharSize( GetHWND(), &cx, &cy, GetFont() );
int hItem = SendMessage(GetHwnd(), CB_GETITEMHEIGHT, -1, 0);
return EDIT_HEIGHT_FROM_CHAR_HEIGHT( cy ) * wxMin( wxMax( nItems, 3 ), 6 ) + hItem - 1;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// MSW message handlers // MSW message handlers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------