From: Vadim Zeitlin Date: Mon, 31 Jul 2006 22:06:24 +0000 (+0000) Subject: TLW default item changes have changed Enter key processing: it was now handled as... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/90c6edd706882b8fd06b6d5359d9682ac0ee858c TLW default item changes have changed Enter key processing: it was now handled as TAB even for controls such as wxTree/ListCtrl which need it themselves; fix this by checking for VK_RETURN in these classes MSWShouldPreProcessMessage() implementation; also removed specific test for wxTextCtrl in wxWindowMSW::MSWProcessMessage() and simplified its code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40405 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index fea8942770..4bb1855f5e 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -346,6 +346,7 @@ public: // IMPLEMENTATION virtual bool MSWCommand(WXUINT param, WXWORD id); virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); + virtual bool MSWShouldPreProcessMessage(WXMSG* msg); // bring the control in sync with current m_windowStyle value void UpdateStyle(); diff --git a/include/wx/msw/treectrl.h b/include/wx/msw/treectrl.h index d154a48042..5729f58904 100644 --- a/include/wx/msw/treectrl.h +++ b/include/wx/msw/treectrl.h @@ -224,6 +224,7 @@ public: virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); virtual bool MSWCommand(WXUINT param, WXWORD id); virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); + virtual bool MSWShouldPreProcessMessage(WXMSG* msg); // override some base class virtuals virtual bool SetBackgroundColour(const wxColour &colour); diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 6e8eba40b5..6bb6ef1527 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1763,6 +1763,20 @@ bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data) // message processing // ---------------------------------------------------------------------------- +bool wxListCtrl::MSWShouldPreProcessMessage(WXMSG* msg) +{ + if ( msg->message == WM_KEYDOWN ) + { + if ( msg->wParam == VK_RETURN ) + { + // we need VK_RETURN to generate wxEVT_COMMAND_LIST_ITEM_ACTIVATED + return false; + } + } + + return wxControl::MSWShouldPreProcessMessage(msg); +} + bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id) { if (cmd == EN_UPDATE) diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 15311c9683..ab2e41b7a8 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -1784,18 +1784,17 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) // kbd input processing // ---------------------------------------------------------------------------- -bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* pMsg) +bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* msg) { - MSG *msg = (MSG *)pMsg; - // check for our special keys here: if we don't do it and the parent frame // uses them as accelerators, they wouldn't work at all, so we disable // usual preprocessing for them if ( msg->message == WM_KEYDOWN ) { - WORD vkey = (WORD) msg->wParam; - if ( (HIWORD(msg->lParam) & KF_ALTDOWN) == KF_ALTDOWN ) + const WPARAM vkey = msg->wParam; + if ( HIWORD(msg->lParam) & KF_ALTDOWN ) { + // Alt-Backspace is accelerator for "Undo" if ( vkey == VK_BACK ) return false; } @@ -1813,6 +1812,9 @@ bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* pMsg) // fall through case 0: + if ( vkey == VK_RETURN ) + return false; + // fall through case 2: break; @@ -1841,7 +1843,7 @@ bool wxTextCtrl::MSWShouldPreProcessMessage(WXMSG* pMsg) } } - return wxControl::MSWShouldPreProcessMessage(pMsg); + return wxControl::MSWShouldPreProcessMessage(msg); } void wxTextCtrl::OnChar(wxKeyEvent& event) diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index ef013be6f7..08f8e0779f 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -1985,6 +1985,20 @@ void wxTreeCtrl::SortChildren(const wxTreeItemId& item) // implementation // ---------------------------------------------------------------------------- +bool wxTreeCtrl::MSWShouldPreProcessMessage(WXMSG* msg) +{ + if ( msg->message == WM_KEYDOWN ) + { + if ( msg->wParam == VK_RETURN ) + { + // we need VK_RETURN to generate wxEVT_COMMAND_TREE_ITEM_ACTIVATED + return false; + } + } + + return wxTreeCtrlBase::MSWShouldPreProcessMessage(msg); +} + bool wxTreeCtrl::MSWCommand(WXUINT cmd, WXWORD id) { if ( cmd == EN_UPDATE ) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 22b2626855..2c7a71a8a3 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -2119,13 +2119,15 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg) if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown ) { // control wants to process Enter itself, don't - // call IsDialogMessage() which would interpret - // it + // call IsDialogMessage() which would consume it return false; } +#if wxUSE_BUTTON // currently active button should get enter press even - // if there is a default button elsewhere + // if there is a default button elsewhere so check if + // this window is a button first + wxWindow *btn = NULL; if ( lDlgCode & DLGC_DEFPUSHBUTTON ) { // let IsDialogMessage() handle this for all @@ -2135,59 +2137,38 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg) if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW ) { // emulate the button click - wxWindow * - btn = wxFindWinFromHandle((WXHWND)msg->hwnd); - if ( btn ) - btn->MSWCommand(BN_CLICKED, 0 /* unused */); + btn = wxFindWinFromHandle((WXHWND)msg->hwnd); } bProcess = false; } - else // not a button itself + else // not a button itself, do we have default button? { -#if wxUSE_BUTTON - wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); + wxTopLevelWindow * + tlw = wxDynamicCast(wxGetTopLevelParent(this), + wxTopLevelWindow); if ( tlw ) { - wxButton *btn = wxDynamicCast(tlw->GetDefaultItem(), wxButton); - if ( btn && btn->IsEnabled() ) - { - // if we do have a default button, do press it - btn->MSWCommand(BN_CLICKED, 0 /* unused */); - - return true; - } + btn = wxDynamicCast(tlw->GetDefaultItem(), + wxButton); } - else // no default button + } + + if ( btn && btn->IsEnabled() ) + { + btn->MSWCommand(BN_CLICKED, 0 /* unused */); + return true; + } + #endif // wxUSE_BUTTON - { + #ifdef __WXWINCE__ - wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN); - event.SetEventObject(this); - if(GetEventHandler()->ProcessEvent(event)) - return true; -#endif - // this is a quick and dirty test for a text - // control - if ( !(lDlgCode & DLGC_HASSETSEL) ) - { - // don't process Enter, the control might - // need it for itself and don't let - // ::IsDialogMessage() have it as it can - // eat the Enter events sometimes - return false; - } - else if (!IsTopLevel()) - { - // if not a top level window, let parent - // handle it - return false; - } - //else: treat Enter as TAB: pass to the next - // control as this is the best thing to do - // if the text doesn't handle Enter itself - } - } + // map Enter presses into button presses on PDAs + wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN); + event.SetEventObject(this); + if ( GetEventHandler()->ProcessEvent(event) ) + return true; +#endif // __WXWINCE__ } break;