- // Ignore height parameter because height doesn't mean 'initially
- // displayed' height, it refers to the drop-down menu as well. The
- // wxWindows interpretation is different; also, getting the size returns
- // the _displayed_ size (NOT the drop down menu size) so
- // setting-getting-setting size would not work.
+ int heightOrig = height;
+
+ // the height which we must pass to Windows should be the total height of
+ // the control including the drop down list while the height given to us
+ // is, of course, just the height of the permanently visible part of it
+ if ( height != wxDefaultCoord )
+ {
+ // don't make the drop down list too tall, arbitrarily limit it to 40
+ // items max and also don't leave it empty
+ size_t nItems = GetCount();
+ if ( !nItems )
+ nItems = 9;
+ else if ( nItems > 24 )
+ nItems = 24;
+
+ // add space for the drop down list
+ const int hItem = SendMessage(GetHwnd(), CB_GETITEMHEIGHT, 0, 0);
+ height += hItem*(nItems + 1);
+ }
+
+ // To work around a Windows bug (see "Bug in Windows Combobox" thread in Google Groups)
+ // we have to reset the selection if it was accidentally selected in the size.
+ DWORD oldSelStart = 0;
+ DWORD oldSelEnd = 0;
+ DWORD newSelStart = 0;
+ DWORD newSelEnd = 0;
+
+ ::SendMessage(GetHwnd(), CB_GETEDITSEL, (WPARAM) & oldSelStart, (LPARAM) & oldSelEnd);
+
+ wxControl::DoSetSize(x, y, width, height, sizeFlags);