X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3180bc0e63fc0feea1fcdb756752b700c27b9773..48d597ed967da2ff414b9580f499c6e43e0159d6:/src/msw/choice.cpp diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 0848b22251..95632e7057 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -333,10 +333,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.size() == 0 ) + { + int count = GetCount(); + for ( int i = 0; i < count; i++ ) + { + if ( GetString(i).size() == 0 ) + 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 } @@ -489,8 +505,24 @@ void wxChoice::DoSetSize(int x, int y, 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) + { + ::SendMessage(GetHwnd(), CB_SETEDITSEL, (WPARAM) 0, (LPARAM) MAKELPARAM(oldSelStart, oldSelEnd)); + } + // 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 @@ -562,13 +594,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); + if ( hbr ) + return (WXLRESULT)hbr; + //else: fall through to default window proc } } @@ -600,24 +633,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) { - HDC hdc = (HDC)pDC; - wxColour colBack = GetBackgroundColour(); - - if (!IsEnabled()) - colBack = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); - - ::SetBkColor(hdc, wxColourToRGB(colBack)); - ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour())); + if ( !IsEnabled() ) + return MSWControlColorDisabled(hDC); - wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID); - - return (WXHBRUSH)brush->GetResourceHandle(); + return wxChoiceBase::MSWControlColorSolid(hDC); } #endif // wxUSE_CHOICE && !(__SMARTPHONE__ && __WXWINCE__) +