KiCad PCB EDA Suite
textentry_tricks.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 KiCad Developers, see change_log.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 
25 #include <fctsys.h>
26 #include <textentry_tricks.h>
27 #include <dialog_shim.h>
28 
29 
30 void TEXTENTRY_TRICKS::OnCharHook( wxTextEntry* aTextEntry, wxKeyEvent& aEvent )
31 {
32  if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'X' )
33  {
34  aTextEntry->Cut();
35  }
36  else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'C' )
37  {
38  aTextEntry->Copy();
39  }
40  else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'V' )
41  {
42  aTextEntry->Paste();
43  }
44  else if( aEvent.GetKeyCode() == WXK_BACK )
45  {
46  long start, end;
47  aTextEntry->GetSelection( &start, &end );
48 
49  if( end > start )
50  {
51  aTextEntry->Remove( start, end );
52  aTextEntry->SetInsertionPoint( start );
53  }
54  else if ( start == end && start > 0 )
55  {
56  aTextEntry->Remove( start-1, start );
57  aTextEntry->SetInsertionPoint( start-1 );
58  }
59  }
60  else if( aEvent.GetKeyCode() == WXK_DELETE )
61  {
62  long start, end;
63  aTextEntry->GetSelection( &start, &end );
64 
65  if( end > start )
66  {
67  aTextEntry->Remove( start, end );
68  aTextEntry->SetInsertionPoint( start );
69  }
70  else if( start == end && start < aTextEntry->GetLastPosition() )
71  {
72  aTextEntry->Remove( start, start+1 );
73  }
74  }
75  else
76  {
77  aEvent.Skip();
78  }
79 }
80 
81 
static void OnCharHook(wxTextEntry *aTextEntry, wxKeyEvent &aEvent)