From 01d2bf4def3a1687b47a85fe250bed006db72d65 Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= <abx@abx.art.pl> Date: Sun, 13 Mar 2005 15:32:30 +0000 Subject: [PATCH] Correct sending of wxW event from wxChoice on MS Smartphone. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32794 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/wince/choicece.h | 5 ++++ src/msw/wince/choicece.cpp | 43 +++++++++++++++++++++++++++++++++ src/msw/window.cpp | 13 ++++++++-- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/include/wx/msw/wince/choicece.h b/include/wx/msw/wince/choicece.h index 75aedb775f..64e9905801 100644 --- a/include/wx/msw/wince/choicece.h +++ b/include/wx/msw/wince/choicece.h @@ -98,6 +98,11 @@ public: // get the subclassed window proc of the buddy list of choices WXFARPROC GetBuddyWndProc() const { return m_wndProcBuddy; } + // return the choice object whose buddy is the given window or NULL + static wxChoice *GetChoiceForListBox(WXHWND hwndBuddy); + + virtual bool MSWCommand(WXUINT param, WXWORD id); + protected: virtual void DoSetItemClientData( int n, void* clientData ); virtual void* DoGetItemClientData( int n ) const; diff --git a/src/msw/wince/choicece.cpp b/src/msw/wince/choicece.cpp index 231b96e90f..397ba4ec14 100644 --- a/src/msw/wince/choicece.cpp +++ b/src/msw/wince/choicece.cpp @@ -109,6 +109,22 @@ LRESULT APIENTRY _EXPORT wxBuddyChoiceWndProc(HWND hwnd, hwnd, message, wParam, lParam); } +wxChoice *wxChoice::GetChoiceForListBox(WXHWND hwndBuddy) +{ + wxChoice *choice = (wxChoice *)wxGetWindowUserData((HWND)hwndBuddy); + + int i = ms_allChoiceSpins.Index(choice); + + if ( i == wxNOT_FOUND ) + return NULL; + + // sanity check + wxASSERT_MSG( choice->m_hwndBuddy == hwndBuddy, + _T("wxChoice has incorrect buddy HWND!") ); + + return choice; +} + // ---------------------------------------------------------------------------- // creation // ---------------------------------------------------------------------------- @@ -284,9 +300,36 @@ WXDWORD wxChoice::MSWGetStyle(long style, WXDWORD *exstyle) const if ( style & wxCB_SORT ) msStyle |= LBS_SORT; + msStyle |= LBS_NOTIFY; + return msStyle; } +bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) +{ + if ( param != LBN_SELCHANGE) + { + // "selection changed" is the only event we're after + return false; + } + + 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); + } + + return true; +} + wxChoice::~wxChoice() { Free(); diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 10c5aaef5d..0e04fab578 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4269,18 +4269,27 @@ bool wxWindowMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) return GetEventHandler()->ProcessEvent(event); } -#if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__) else { +#if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__) // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND // notifications to its parent which we want to reflect back to // wxSpinCtrl wxSpinCtrl *spin = wxSpinCtrl::GetSpinForTextCtrl(control); if ( spin && spin->ProcessTextCommand(cmd, id) ) return true; - } #endif // wxUSE_SPINCTRL +#if wxUSE_CHOICE && defined(__SMARTPHONE__) + // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND + // notifications to its parent which we want to reflect back to + // wxChoice + wxChoice *choice = wxChoice::GetChoiceForListBox(control); + if ( choice && choice->MSWCommand(cmd, id) ) + return true; +#endif + } + return false; } -- 2.47.2