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
This commit is contained in:
@@ -115,6 +115,7 @@ public:
|
|||||||
// callbacks
|
// callbacks
|
||||||
void OnDropFiles(wxDropFilesEvent& event);
|
void OnDropFiles(wxDropFilesEvent& event);
|
||||||
void OnChar(wxKeyEvent& event); // Process 'enter' if required
|
void OnChar(wxKeyEvent& event); // Process 'enter' if required
|
||||||
|
void OnKeyDown(wxKeyEvent& event); // Process clipboard shortcuts
|
||||||
|
|
||||||
void OnCut(wxCommandEvent& event);
|
void OnCut(wxCommandEvent& event);
|
||||||
void OnCopy(wxCommandEvent& event);
|
void OnCopy(wxCommandEvent& event);
|
||||||
|
@@ -53,6 +53,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase)
|
|||||||
BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase)
|
BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase)
|
||||||
EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
|
EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
|
||||||
EVT_CHAR(wxTextCtrl::OnChar)
|
EVT_CHAR(wxTextCtrl::OnChar)
|
||||||
|
EVT_KEY_DOWN(wxTextCtrl::OnKeyDown)
|
||||||
EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
|
EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
|
||||||
EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
|
EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
|
||||||
EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
|
EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
|
||||||
@@ -341,27 +342,41 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
|
|||||||
LoadFile( event.GetFiles()[0] );
|
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)
|
void wxTextCtrl::OnChar(wxKeyEvent& event)
|
||||||
{
|
{
|
||||||
int key = event.GetKeyCode() ;
|
int key = event.GetKeyCode() ;
|
||||||
bool eat_key = false ;
|
bool eat_key = false ;
|
||||||
long from, to;
|
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) &&
|
if ( !IsEditable() && !event.IsKeyInCategory(WXK_CATEGORY_ARROW | WXK_CATEGORY_TAB) &&
|
||||||
!( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) )
|
!( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) )
|
||||||
// && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END
|
// && 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
|
// assume that any key not processed yet is going to modify the control
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
|
|
||||||
if ( key == 'v' && event.MetaDown() )
|
|
||||||
{
|
|
||||||
if ( CanPaste() )
|
|
||||||
Paste() ;
|
|
||||||
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( key == 'x' && event.MetaDown() )
|
|
||||||
{
|
|
||||||
if ( CanCut() )
|
|
||||||
Cut() ;
|
|
||||||
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ( key )
|
switch ( key )
|
||||||
{
|
{
|
||||||
case WXK_RETURN:
|
case WXK_RETURN:
|
||||||
|
Reference in New Issue
Block a user