From 491c131886860cb4a790cfb61fd3aa3daf7fad6b Mon Sep 17 00:00:00 2001 From: fuscated Date: Thu, 27 Dec 2018 17:54:37 +0200 Subject: [PATCH] Add shortcuts for the combobox (select all, copy, cut, paste) * It is the same as the code in the implementation of the wxTextCtrl, I guess this could be extracted in a common function, but I don't know where to put it. --- include/wx/osx/combobox.h | 6 ++++++ src/osx/combobox_osx.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/wx/osx/combobox.h b/include/wx/osx/combobox.h index 35eb85a66c..65c7edd869 100644 --- a/include/wx/osx/combobox.h +++ b/include/wx/osx/combobox.h @@ -130,11 +130,17 @@ protected: virtual void EnableTextChangedEvents(bool enable) wxOVERRIDE; + // callbacks + void OnKeyDown(wxKeyEvent& event); // Process clipboard shortcuts + // the subcontrols wxComboBoxText* m_text; wxComboBoxChoice* m_choice; wxComboBoxDataArray m_datas; + +private: + wxDECLARE_EVENT_TABLE(); }; #endif // _WX_COMBOBOX_H_ diff --git a/src/osx/combobox_osx.cpp b/src/osx/combobox_osx.cpp index f529d019f9..fde159e927 100644 --- a/src/osx/combobox_osx.cpp +++ b/src/osx/combobox_osx.cpp @@ -18,6 +18,12 @@ #ifndef WX_PRECOMP #endif +typedef wxWindowWithItems RealwxComboBoxBase; + +wxBEGIN_EVENT_TABLE(wxComboBox, RealwxComboBoxBase) + EVT_KEY_DOWN(wxComboBox::OnKeyDown) +wxEND_EVENT_TABLE() + // work in progress wxComboBox::~wxComboBox() @@ -234,4 +240,33 @@ void wxComboBox::Dismiss() GetComboPeer()->Dismiss(); } +void wxComboBox::OnKeyDown(wxKeyEvent& event) +{ + if (event.GetModifiers() == wxMOD_CONTROL) + { + 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(); +} + #endif // wxUSE_COMBOBOX && wxOSX_USE_COCOA