From 5aa6ea933f515a1afa9b97b23e353f2eae54764c Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 31 Jan 2010 11:01:53 +0000 Subject: [PATCH] supporting clipboard command shortcuts on osx_cocoa as well, simplifying code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63332 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/textctrl.h | 1 + src/osx/textctrl_osx.cpp | 61 +++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/include/wx/osx/textctrl.h b/include/wx/osx/textctrl.h index 3bd9c978a2..762bf34a18 100644 --- a/include/wx/osx/textctrl.h +++ b/include/wx/osx/textctrl.h @@ -115,6 +115,7 @@ public: // callbacks void OnDropFiles(wxDropFilesEvent& event); void OnChar(wxKeyEvent& event); // Process 'enter' if required + void OnKeyDown(wxKeyEvent& event); // Process clipboard shortcuts void OnCut(wxCommandEvent& event); void OnCopy(wxCommandEvent& event); diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index 5d243607e0..af08390bfa 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -53,6 +53,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) EVT_DROP_FILES(wxTextCtrl::OnDropFiles) EVT_CHAR(wxTextCtrl::OnChar) + EVT_KEY_DOWN(wxTextCtrl::OnKeyDown) EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) @@ -341,27 +342,41 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) LoadFile( event.GetFiles()[0] ); } +void wxTextCtrl::OnKeyDown(wxKeyEvent& event) +{ + if ( event.MetaDown() ) + { + switch( event.GetKeyCode() ) + { + case 'A': + SelectAll(); + return; + case 'C': + if ( CanCopy() ) + Copy() ; + return; + case 'V': + if ( CanPaste() ) + Paste() ; + return; + case 'X': + if ( CanCut() ) + Cut() ; + return; + default: + break; + } + } + // no, we didn't process it + event.Skip(); +} + void wxTextCtrl::OnChar(wxKeyEvent& event) { int key = event.GetKeyCode() ; bool eat_key = false ; long from, to; - if ( key == 'a' && event.MetaDown() ) - { - SelectAll() ; - - return ; - } - - if ( key == 'c' && event.MetaDown() ) - { - if ( CanCopy() ) - Copy() ; - - return ; - } - if ( !IsEditable() && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB) && !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END @@ -388,22 +403,6 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) // assume that any key not processed yet is going to modify the control m_dirty = true; - if ( key == 'v' && event.MetaDown() ) - { - if ( CanPaste() ) - Paste() ; - - return ; - } - - if ( key == 'x' && event.MetaDown() ) - { - if ( CanCut() ) - Cut() ; - - return ; - } - switch ( key ) { case WXK_RETURN: