X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1d13cc5da47cd44765e0751b1a3a9d3ecfccd8bb..75e275af320f70d9bb57dd30494f6cc2c100dc25:/src/msw/choice.cpp diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 2a83571ecb..b643d1d1cb 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: choice.cpp +// Name: src/msw/choice.cpp // Purpose: wxChoice // Author: Julian Smart // Modified by: Vadim Zeitlin to derive from wxChoiceBase @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "choice.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -236,6 +232,7 @@ int wxChoice::DoAppend(const wxString& item) UpdateVisibleHeight(); } + InvalidateBestSize(); return n; } @@ -255,6 +252,7 @@ int wxChoice::DoInsert(const wxString& item, int pos) UpdateVisibleHeight(); } + InvalidateBestSize(); return n; } @@ -271,6 +269,8 @@ void wxChoice::Delete(int n) if ( !IsFrozen() ) UpdateVisibleHeight(); + + InvalidateBestSize(); } void wxChoice::Clear() @@ -281,6 +281,8 @@ void wxChoice::Clear() if ( !IsFrozen() ) UpdateVisibleHeight(); + + InvalidateBestSize(); } void wxChoice::Free() @@ -300,6 +302,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); } @@ -318,7 +331,7 @@ int wxChoice::GetCount() const return (int)SendMessage(GetHwnd(), CB_GETCOUNT, 0, 0); } -int wxChoice::FindString(const wxString& s) const +int wxChoice::FindString(const wxString& s, bool bCase) const { #if defined(__WATCOMC__) && defined(__WIN386__) // For some reason, Watcom in WIN386 mode crashes in the CB_FINDSTRINGEXACT message. @@ -327,7 +340,7 @@ 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, bCase) ) return i; } @@ -337,21 +350,26 @@ int wxChoice::FindString(const wxString& s) const //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; + int count = GetCount(); + for ( int i = 0; i < count; i++ ) + { + if ( GetString(i).empty() ) + return i; + } + + return wxNOT_FOUND; + } + else if (bCase) + { + // back to base class search for not native search type + return wxItemContainerImmutable::FindString( s, bCase ); } else { - int pos = (int)SendMessage(GetHwnd(), CB_FINDSTRINGEXACT, - (WPARAM)-1, (LPARAM)s.c_str()); + int pos = (int)SendMessage(GetHwnd(), CB_FINDSTRINGEXACT, + (WPARAM)-1, (LPARAM)s.c_str()); - return pos == LB_ERR ? wxNOT_FOUND : pos; + return pos == LB_ERR ? wxNOT_FOUND : pos; } #endif // Watcom/!Watcom } @@ -383,6 +401,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 @@ -613,27 +633,42 @@ 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, WXHWND hWnd) @@ -645,4 +680,3 @@ WXHBRUSH wxChoice::MSWControlColor(WXHDC hDC, WXHWND hWnd) } #endif // wxUSE_CHOICE && !(__SMARTPHONE__ && __WXWINCE__) -