X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3a7d5f7cc3892d15ee8de373b8ab52d4bc1eabf8..373a5fb355f4023f96b14bbf8161cbd1de5b846e:/src/msw/combobox.cpp diff --git a/src/msw/combobox.cpp b/src/msw/combobox.cpp index 4c07746705..5cd1e71bed 100644 --- a/src/msw/combobox.cpp +++ b/src/msw/combobox.cpp @@ -65,7 +65,7 @@ wxBEGIN_FLAGS( wxComboBoxStyle ) wxFLAGS_MEMBER(wxBORDER_RAISED) wxFLAGS_MEMBER(wxBORDER_STATIC) wxFLAGS_MEMBER(wxBORDER_NONE) - + // old style border flags wxFLAGS_MEMBER(wxSIMPLE_BORDER) wxFLAGS_MEMBER(wxSUNKEN_BORDER) @@ -94,15 +94,15 @@ wxEND_FLAGS( wxComboBoxStyle ) IMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox, wxControl,"wx/combobox.h") wxBEGIN_PROPERTIES_TABLE(wxComboBox) - wxEVENT_PROPERTY( Select , wxEVT_COMMAND_COMBOBOX_SELECTED , wxCommandEvent ) + wxEVENT_PROPERTY( Select , wxEVT_COMMAND_COMBOBOX_SELECTED , wxCommandEvent ) wxEVENT_PROPERTY( TextEnter , wxEVT_COMMAND_TEXT_ENTER , wxCommandEvent ) // TODO DELEGATES - wxPROPERTY( Font , wxFont , SetFont , GetFont , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) + wxPROPERTY( Font , wxFont , SetFont , GetFont , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) wxPROPERTY_COLLECTION( Choices , wxArrayString , wxString , AppendString , GetStrings , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) - wxPROPERTY( Value ,wxString, SetValue, GetValue, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) - wxPROPERTY( Selection ,int, SetSelection, GetSelection, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) - wxPROPERTY_FLAGS( WindowStyle , wxComboBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style + wxPROPERTY( Value ,wxString, SetValue, GetValue, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) + wxPROPERTY( Selection ,int, SetSelection, GetSelection, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) + wxPROPERTY_FLAGS( WindowStyle , wxComboBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style wxEND_PROPERTIES_TABLE() wxBEGIN_HANDLERS_TABLE(wxComboBox) @@ -127,7 +127,7 @@ LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd, // --------------------------------------------------------------------------- // the pointer to standard radio button wnd proc -static WXFARPROC gs_wndprocEdit = (WXFARPROC)NULL; +static WNDPROC gs_wndprocEdit = (WNDPROC)NULL; // ============================================================================ // implementation @@ -238,7 +238,7 @@ WXHBRUSH wxComboBox::OnCtlColor(WXHDC pDC, // wxComboBox callbacks // ---------------------------------------------------------------------------- -long wxComboBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) +WXLRESULT wxComboBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { // handle WM_CTLCOLOR messages from our EDIT control to be able to set its // colour correctly (to be the same as our own one) @@ -253,7 +253,7 @@ long wxComboBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) WXHWND hwnd; UnpackCtlColor(wParam, lParam, &nCtlColor, &hdc, &hwnd); - return OnCtlColor(hdc, hwnd, nCtlColor, nMsg, wParam, lParam); + return (WXLRESULT)OnCtlColor(hdc, hwnd, nCtlColor, nMsg, wParam, lParam); } return wxChoice::MSWWindowProc(nMsg, wParam, lParam); @@ -275,7 +275,7 @@ bool wxComboBox::MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam) ProcessCommand(event); } - return HandleChar(wParam, lParam, TRUE /* isASCII */); + return HandleChar(wParam, lParam, true /* isASCII */); case WM_KEYDOWN: return HandleKeyDown(wParam, lParam); @@ -290,7 +290,7 @@ bool wxComboBox::MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam) return HandleKillFocus((WXHWND)wParam); } - return FALSE; + return false; } bool wxComboBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) @@ -301,18 +301,30 @@ bool wxComboBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) { case CBN_SELCHANGE: sel = GetSelection(); - if ( sel > -1 ) + + // somehow we get 2 CBN_SELCHANGE events with the same index when + // the user selects an item in the combobox -- ignore duplicates + if ( sel > -1 && sel != m_selectionOld ) { - value = GetString(sel); + m_selectionOld = sel; + + // GetValue() would still return the old value from here but + // according to the docs we should return the new value if the + // user calls it in his event handler, so update internal + // m_value + m_value = GetString(sel); wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, GetId()); event.SetInt(sel); event.SetEventObject(this); - event.SetString(value); + event.SetString(m_value); ProcessCommand(event); } - else + else // no valid selection { + m_selectionOld = sel; + + // hence no EVT_TEXT neither break; } @@ -329,25 +341,21 @@ bool wxComboBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) // want the new one) if ( sel == -1 ) { - value = GetValue(); + m_value = wxGetWindowText(GetHwnd()); } else // we're synthesizing text updated event from sel change { - // We need to retrieve the current selection because the user - // may have changed it in the previous handler (for CBN_SELCHANGE - // above). + // We need to retrieve the current selection because the + // user may have changed it in the previous handler (for + // CBN_SELCHANGE above). sel = GetSelection(); if ( sel > -1 ) { - value = GetString(sel); + m_value = GetString(sel); } - // we need to do this because the user code expects - // wxComboBox::GetValue() to return the new value from - // "text updated" handler but it hadn't been updated yet - SetValue(value); } - event.SetString(value); + event.SetString(m_value); event.SetEventObject(this); ProcessCommand(event); } @@ -355,8 +363,8 @@ bool wxComboBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) } // there is no return value for the CBN_ notifications, so always return - // FALSE from here to pass the message to DefWindowProc() - return FALSE; + // false from here to pass the message to DefWindowProc() + return false; } WXHWND wxComboBox::GetEditHWND() const @@ -393,31 +401,31 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, // pretend that wxComboBox is hidden while it is positioned and resized and // show it only right before leaving this method because otherwise there is // some noticeable flicker while the control rearranges itself - m_isShown = FALSE; + m_isShown = false; if ( !CreateAndInit(parent, id, pos, size, n, choices, style, validator, name) ) - return FALSE; + return false; - SetValue(value); + // we shouldn't call SetValue() for an empty string because this would + // (correctly) result in an assert with a read only combobox and is useless + // for the other ones anyhow + if ( !value.empty() ) + SetValue(value); // a (not read only) combobox is, in fact, 2 controls: the combobox itself // and an edit control inside it and if we want to catch events from this // edit control, we must subclass it as well if ( !(style & wxCB_READONLY) ) { - gs_wndprocEdit = (WXFARPROC)::SetWindowLong - ( - (HWND)GetEditHWND(), - GWL_WNDPROC, - (LPARAM)wxComboEditWndProc - ); + gs_wndprocEdit = wxSetWindowProc((HWND)GetEditHWND(), + wxComboEditWndProc); } // and finally, show the control - Show(TRUE); + Show(true); - return TRUE; + return true; } bool wxComboBox::Create(wxWindow *parent, wxWindowID id, @@ -472,6 +480,9 @@ void wxComboBox::SetValue(const wxString& value) SetStringSelection(value); else SetWindowText(GetHwnd(), value.c_str()); + + m_value = value; + m_selectionOld = GetSelection(); } // Clipboard operations @@ -573,7 +584,7 @@ void wxComboBox::SetSelection(long from, long to) long fromChar = from; long toChar = to; // if from and to are both -1, it means - // (in wxWindows) that all text should be selected. + // (in wxWidgets) that all text should be selected. // This translates into Windows convention if ((from == -1) && (to == -1)) { @@ -581,13 +592,7 @@ void wxComboBox::SetSelection(long from, long to) toChar = -1; } - if ( -#ifdef __WIN32__ - SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar)) -#else // Win16 - SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)fromChar, (LPARAM)toChar) -#endif - == CB_ERR ) + if ( SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar)) == CB_ERR ) { wxLogDebug(_T("CB_SETEDITSEL failed")); }