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.
This commit is contained in:
fuscated 2018-12-27 17:54:37 +02:00 committed by Stefan Csomor
parent 6cdf22b5dd
commit 491c131886
2 changed files with 41 additions and 0 deletions

View File

@ -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_

View File

@ -18,6 +18,12 @@
#ifndef WX_PRECOMP
#endif
typedef wxWindowWithItems<wxControl, wxComboBoxBase> 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