From d4445d24d33828580f8bf2a1215ef906f70adb51 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 30 Mar 2006 09:21:11 +0000 Subject: [PATCH] Reverted wxChoice size fix due to problems in W2K and below git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38442 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 +- src/msw/choice.cpp | 60 ++++++++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 17bbe621a3..7a22272a8c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -155,7 +155,7 @@ wxMSW: - wxDisplay doesn't require multimon.h now and is enabled by default (Olly Betts). - Fixed wxChoice/wxComboBox slow appending and infinite recursion if its size is set within a paint handler (for example when embedded in a - wxHtmlWindow). + wxHtmlWindow). [Now reverted due to problems in W2K and below.] wxGTK: diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 6319f4ae2e..1441653418 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -504,8 +504,46 @@ void wxChoice::DoSetSize(int x, int y, int width, int height, int sizeFlags) { - 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); + } + else + { + // We cannot pass wxDefaultCoord as height to wxControl. wxControl uses + // wxGetWindowRect() to determine the current height of the combobox, + // and then again sets the combobox's height to that value. Unfortunately, + // wxGetWindowRect doesn't include the dropdown list's height (at least + // on Win2K), so this would result in a combobox with dropdown height of + // 1 pixel. We have to determine the default height ourselves and call + // wxControl with that value instead. + int w, h; + RECT r; + DoGetSize(&w, &h); + if (::SendMessage(GetHwnd(), CB_GETDROPPEDCONTROLRECT, 0, (LPARAM) &r) != 0) + { + height = h + r.bottom - r.top; + } + } + + wxControl::DoSetSize(x, y, width, height, sizeFlags); + + // This solution works on XP, but causes choice/combobox lists to be + // too short on W2K and earlier. +#if 0 int widthCurrent, heightCurrent; DoGetSize(&widthCurrent, &heightCurrent); @@ -568,26 +606,6 @@ void wxChoice::DoSetSize(int x, int y, } wxControl::DoSetSize(x, y, width, height, sizeFlags); - - // I'm commenting this out since the code appears to make choices - // and comboxes too high when they have associated sizers. I'm sure this - // is not the end of the story, which is why I'm leaving it #if'ed out for - // now. JACS. -#if 0 - // if the height specified for the visible part of the control is - // different from the current one, we need to change it separately - // as it is not affected by normal WM_SETSIZE - if ( height != wxDefaultCoord ) - { - const int delta = heightOrig - GetSize().y; - if ( delta ) - { - int h = ::SendMessage(GetHwnd(), CB_GETITEMHEIGHT, (WPARAM)-1, 0); - SendMessage(GetHwnd(), CB_SETITEMHEIGHT, (WPARAM)-1, h + delta); - } - } -#else - wxUnusedVar(heightOrig); #endif } -- 2.45.2