X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/55e0d33c979274c996a6e9369e2a3d151a7b23b9..1fef34b9eed0afe7f3d65f7c62bd85a679a5b6db:/src/msw/choice.cpp diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 95632e7057..c8681252f8 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -141,7 +141,7 @@ bool wxChoice::CreateAndInit(wxWindow *parent, return false; // now create the real HWND - if ( !MSWCreateControl(wxT("COMBOBOX"), _T(""), pos, size) ) + if ( !MSWCreateControl(wxT("COMBOBOX"), wxEmptyString, pos, size) ) return false; @@ -335,12 +335,12 @@ int wxChoice::FindString(const wxString& s) const #else // !Watcom //TODO: Evidently some MSW versions (all?) don't like empty strings //passed to SendMessage, so we have to do it ourselves in that case - if ( s.size() == 0 ) + if ( s.empty() ) { int count = GetCount(); for ( int i = 0; i < count; i++ ) { - if ( GetString(i).size() == 0 ) + if ( GetString(i).empty() ) return i; } @@ -350,7 +350,7 @@ int wxChoice::FindString(const wxString& s) const { int pos = (int)SendMessage(GetHwnd(), CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)s.c_str()); - + return pos == LB_ERR ? wxNOT_FOUND : pos; } #endif // Watcom/!Watcom @@ -504,25 +504,26 @@ void wxChoice::DoSetSize(int x, int y, 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); - - ::SendMessage(GetHwnd(), CB_GETEDITSEL, (WPARAM) & newSelStart, (LPARAM) & newSelEnd); - - if (oldSelStart != newSelStart || oldSelEnd != newSelEnd) + else { - ::SendMessage(GetHwnd(), CB_SETEDITSEL, (WPARAM) 0, (LPARAM) MAKELPARAM(oldSelStart, oldSelEnd)); + // 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); + // 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 @@ -598,7 +599,7 @@ WXLRESULT wxChoice::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) WXHWND hwnd; UnpackCtlColor(wParam, lParam, &hdc, &hwnd); - WXHBRUSH hbr = MSWControlColor((WXHDC)hdc); + WXHBRUSH hbr = MSWControlColor((WXHDC)hdc, hwnd); if ( hbr ) return (WXLRESULT)hbr; //else: fall through to default window proc @@ -633,12 +634,12 @@ bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) return true; } -WXHBRUSH wxChoice::MSWControlColor(WXHDC hDC) +WXHBRUSH wxChoice::MSWControlColor(WXHDC hDC, WXHWND hWnd) { if ( !IsEnabled() ) return MSWControlColorDisabled(hDC); - return wxChoiceBase::MSWControlColorSolid(hDC); + return wxChoiceBase::MSWControlColor(hDC, hWnd); } #endif // wxUSE_CHOICE && !(__SMARTPHONE__ && __WXWINCE__)