X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3180bc0e63fc0feea1fcdb756752b700c27b9773..8af56e082726e68f3056722bbc2d9837393afa5d:/src/msw/choice.cpp diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 0848b22251..859e700b71 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; @@ -236,6 +236,7 @@ int wxChoice::DoAppend(const wxString& item) UpdateVisibleHeight(); } + InvalidateBestSize(); return n; } @@ -255,6 +256,7 @@ int wxChoice::DoInsert(const wxString& item, int pos) UpdateVisibleHeight(); } + InvalidateBestSize(); return n; } @@ -271,6 +273,8 @@ void wxChoice::Delete(int n) if ( !IsFrozen() ) UpdateVisibleHeight(); + + InvalidateBestSize(); } void wxChoice::Clear() @@ -281,6 +285,8 @@ void wxChoice::Clear() if ( !IsFrozen() ) UpdateVisibleHeight(); + + InvalidateBestSize(); } void wxChoice::Free() @@ -333,10 +339,26 @@ int wxChoice::FindString(const wxString& s) const return wxNOT_FOUND; #else // !Watcom - int pos = (int)SendMessage(GetHwnd(), CB_FINDSTRINGEXACT, - (WPARAM)-1, (LPARAM)s.c_str()); - - return pos == LB_ERR ? wxNOT_FOUND : pos; + //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.empty() ) + { + int count = GetCount(); + for ( int i = 0; i < count; i++ ) + { + if ( GetString(i).empty() ) + return i; + } + + return wxNOT_FOUND; + } + else + { + int pos = (int)SendMessage(GetHwnd(), CB_FINDSTRINGEXACT, + (WPARAM)-1, (LPARAM)s.c_str()); + + return pos == LB_ERR ? wxNOT_FOUND : pos; + } #endif // Watcom/!Watcom } @@ -367,6 +389,8 @@ void wxChoice::SetString(int n, const wxString& s) DoSetItemClientData(n, data); } //else: it's already NULL by default + + InvalidateBestSize(); } wxString wxChoice::GetString(int n) const @@ -488,6 +512,23 @@ void wxChoice::DoSetSize(int x, int y, 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); @@ -534,7 +575,9 @@ wxSize wxChoice::DoGetBestSize() const // the combobox should be slightly larger than the widest string wChoice += 5*GetCharWidth(); - return wxSize(wChoice, EDIT_HEIGHT_FROM_CHAR_HEIGHT(GetCharHeight())); + wxSize best(wChoice, EDIT_HEIGHT_FROM_CHAR_HEIGHT(GetCharHeight())); + CacheBestSize(best); + return best; } WXLRESULT wxChoice::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) @@ -562,13 +605,14 @@ WXLRESULT wxChoice::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) case WM_CTLCOLORLISTBOX: case WM_CTLCOLORSTATIC: { - WXWORD nCtlColor; WXHDC hdc; WXHWND hwnd; - UnpackCtlColor(wParam, lParam, &nCtlColor, &hdc, &hwnd); + UnpackCtlColor(wParam, lParam, &hdc, &hwnd); - return (WXLRESULT)OnCtlColor(hdc, hwnd, nCtlColor, - nMsg, wParam, lParam); + WXHBRUSH hbr = MSWControlColor((WXHDC)hdc, hwnd); + if ( hbr ) + return (WXLRESULT)hbr; + //else: fall through to default window proc } } @@ -600,24 +644,13 @@ bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) return true; } -WXHBRUSH wxChoice::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor), - WXUINT WXUNUSED(message), - WXWPARAM WXUNUSED(wParam), - WXLPARAM WXUNUSED(lParam) - ) +WXHBRUSH wxChoice::MSWControlColor(WXHDC hDC, WXHWND hWnd) { - HDC hdc = (HDC)pDC; - wxColour colBack = GetBackgroundColour(); - - if (!IsEnabled()) - colBack = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); + if ( !IsEnabled() ) + return MSWControlColorDisabled(hDC); - ::SetBkColor(hdc, wxColourToRGB(colBack)); - ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour())); - - wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID); - - return (WXHBRUSH)brush->GetResourceHandle(); + return wxChoiceBase::MSWControlColor(hDC, hWnd); } #endif // wxUSE_CHOICE && !(__SMARTPHONE__ && __WXWINCE__) +