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:
Stefan Csomor 2010-01-31 11:01:53 +00:00
parent 96e790a567
commit 5aa6ea933f
2 changed files with 31 additions and 31 deletions

View File

@ -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);

View File

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