X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c3732409acc7a1e0b3cdb1f0a5dec7cc49a4b28b..3dc786e02e0165169287cc6abe7a193b19c32b3e:/src/msw/choice.cpp diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index bf0739540f..31b0b5f46c 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -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() @@ -300,6 +306,17 @@ void wxChoice::Free() // ---------------------------------------------------------------------------- int wxChoice::GetSelection() const +{ + // if m_lastAcceptedSelection is set, it means that the dropdown is + // currently shown and that we want to use the last "permanent" selection + // instead of whatever is under the mouse pointer currently + // + // otherwise, get the selection from the control + return m_lastAcceptedSelection == wxID_NONE ? GetCurrentSelection() + : m_lastAcceptedSelection; +} + +int wxChoice::GetCurrentSelection() const { return (int)SendMessage(GetHwnd(), CB_GETCURSEL, 0, 0); } @@ -383,6 +400,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 @@ -567,7 +586,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) @@ -599,7 +620,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 @@ -611,35 +632,50 @@ WXLRESULT wxChoice::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) { - if ( param != CBN_SELCHANGE) + switch ( param ) { - // "selection changed" is the only event we're after - return false; - } + case CBN_DROPDOWN: + // we don't want to track selection using CB_GETCURSEL while the + // dropdown is opened + m_lastAcceptedSelection = GetCurrentSelection(); + break; - int n = GetSelection(); - if (n > -1) - { - wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId); - event.SetInt(n); - event.SetEventObject(this); - event.SetString(GetStringSelection()); - if ( HasClientObjectData() ) - event.SetClientObject( GetClientObject(n) ); - else if ( HasClientUntypedData() ) - event.SetClientData( GetClientData(n) ); - ProcessCommand(event); + case CBN_CLOSEUP: + // it should be safe to use CB_GETCURSEL again + m_lastAcceptedSelection = wxID_NONE; + break; + + case CBN_SELCHANGE: + { + const int n = GetSelection(); + + wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId); + event.SetInt(n); + event.SetEventObject(this); + + if ( n > -1 ) + { + event.SetString(GetStringSelection()); + if ( HasClientObjectData() ) + event.SetClientObject( GetClientObject(n) ); + else if ( HasClientUntypedData() ) + event.SetClientData( GetClientData(n) ); + } + + ProcessCommand(event); + } + return true; } - return true; + return false; } -WXHBRUSH wxChoice::MSWControlColor(WXHDC hDC) +WXHBRUSH wxChoice::MSWControlColor(WXHDC hDC, WXHWND hWnd) { if ( !IsEnabled() ) return MSWControlColorDisabled(hDC); - return wxChoiceBase::MSWControlColor(hDC); + return wxChoiceBase::MSWControlColor(hDC, hWnd); } #endif // wxUSE_CHOICE && !(__SMARTPHONE__ && __WXWINCE__)