X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cb8289465de165d669fca6a97a4a60cfcc9e03b1..40786029bdd143adcf213118a6a53ecdc7832270:/src/msw/choice.cpp diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 9abbe7e00f..859e700b71 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -28,7 +28,7 @@ #pragma hdrstop #endif -#if wxUSE_CHOICE +#if wxUSE_CHOICE && !(defined(__SMARTPHONE__) && defined(__WXWINCE__)) #ifndef WX_PRECOMP #include "wx/choice.h" @@ -138,11 +138,11 @@ bool wxChoice::CreateAndInit(wxWindow *parent, { // initialize wxControl if ( !CreateControl(parent, id, pos, size, style, validator, name) ) - return FALSE; + return false; // now create the real HWND - if ( !MSWCreateControl(wxT("COMBOBOX"), _T(""), pos, size) ) - return FALSE; + if ( !MSWCreateControl(wxT("COMBOBOX"), wxEmptyString, pos, size) ) + return false; // choice/combobox normally has "white" (depends on colour scheme, of @@ -158,7 +158,7 @@ bool wxChoice::CreateAndInit(wxWindow *parent, // and now we may finally size the control properly (if needed) SetBestSize(size); - return TRUE; + return true; } bool wxChoice::Create(wxWindow *parent, @@ -232,9 +232,11 @@ int wxChoice::DoAppend(const wxString& item) { // we need to refresh our size in order to have enough space for the // newly added items - UpdateVisibleHeight(); + if ( !IsFrozen() ) + UpdateVisibleHeight(); } + InvalidateBestSize(); return n; } @@ -250,9 +252,11 @@ int wxChoice::DoInsert(const wxString& item, int pos) } else // ok { - UpdateVisibleHeight(); + if ( !IsFrozen() ) + UpdateVisibleHeight(); } + InvalidateBestSize(); return n; } @@ -267,7 +271,10 @@ void wxChoice::Delete(int n) SendMessage(GetHwnd(), CB_DELETESTRING, n, 0); - UpdateVisibleHeight(); + if ( !IsFrozen() ) + UpdateVisibleHeight(); + + InvalidateBestSize(); } void wxChoice::Clear() @@ -276,7 +283,10 @@ void wxChoice::Clear() SendMessage(GetHwnd(), CB_RESETCONTENT, 0, 0); - UpdateVisibleHeight(); + if ( !IsFrozen() ) + UpdateVisibleHeight(); + + InvalidateBestSize(); } void wxChoice::Free() @@ -323,16 +333,32 @@ int wxChoice::FindString(const wxString& s) const for ( int i = 0; i < count; i++ ) { // as CB_FINDSTRINGEXACT is case insensitive, be case insensitive too - if ( GetString(i).IsSameAs(s, FALSE) ) + if ( GetString(i).IsSameAs(s, false) ) return i; } 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 } @@ -363,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 @@ -431,7 +459,7 @@ wxClientData* wxChoice::DoGetItemClientObject( int n ) const void wxChoice::UpdateVisibleHeight() { // be careful to not change the width here - DoSetSize(-1, -1, -1, GetSize().y, wxSIZE_USE_EXISTING); + DoSetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, GetSize().y, wxSIZE_USE_EXISTING); } void wxChoice::DoMoveWindow(int x, int y, int width, int height) @@ -458,7 +486,7 @@ void wxChoice::DoGetSize(int *w, int *h) const // total height of the control including the drop down list -- but only // sometimes, and normally it isn't... I have no idea about what to do with // this - wxControl::DoGetSize(w, h); + wxControl::DoGetSize(w, h); } void wxChoice::DoSetSize(int x, int y, @@ -470,7 +498,7 @@ void wxChoice::DoSetSize(int x, int y, // 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 != -1 ) + 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 @@ -484,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); @@ -495,7 +540,7 @@ void wxChoice::DoSetSize(int x, int y, // 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 != -1 ) + if ( height != wxDefaultCoord ) { const int delta = heightOrig - GetSize().y; if ( delta ) @@ -530,23 +575,45 @@ 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) { - if ( nMsg == WM_LBUTTONUP ) + switch ( nMsg ) { - int x = (int)LOWORD(lParam); - int y = (int)HIWORD(lParam); - - // Ok, this is truly weird, but if a panel with a wxChoice loses the - // focus, then you get a *fake* WM_LBUTTONUP message with x = 65535 and - // y = 65535. Filter out this nonsense. - // - // VZ: I'd like to know how to reproduce this please... - if ( x == 65535 && y == 65535 ) - return 0; + case WM_LBUTTONUP: + { + int x = (int)LOWORD(lParam); + int y = (int)HIWORD(lParam); + + // Ok, this is truly weird, but if a panel with a wxChoice + // loses the focus, then you get a *fake* WM_LBUTTONUP message + // with x = 65535 and y = 65535. Filter out this nonsense. + // + // VZ: I'd like to know how to reproduce this please... + if ( x == 65535 && y == 65535 ) + return 0; + } + break; + + // we have to handle both: one for the normal case and the other + // for readonly + case WM_CTLCOLOREDIT: + case WM_CTLCOLORLISTBOX: + case WM_CTLCOLORSTATIC: + { + WXHDC hdc; + WXHWND hwnd; + UnpackCtlColor(wParam, lParam, &hdc, &hwnd); + + WXHBRUSH hbr = MSWControlColor((WXHDC)hdc, hwnd); + if ( hbr ) + return (WXLRESULT)hbr; + //else: fall through to default window proc + } } return wxWindow::MSWWindowProc(nMsg, wParam, lParam); @@ -557,7 +624,7 @@ bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) if ( param != CBN_SELCHANGE) { // "selection changed" is the only event we're after - return FALSE; + return false; } int n = GetSelection(); @@ -574,27 +641,16 @@ bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) ProcessCommand(event); } - return TRUE; + 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() ) + return MSWControlColorDisabled(hDC); - if (!IsEnabled()) - colBack = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); - - ::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 +#endif // wxUSE_CHOICE && !(__SMARTPHONE__ && __WXWINCE__) +