KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The KiCad Developers, see AUTHORS.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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <wx/event.h>
21#include <wx/gdicmn.h>
22#include <textentry_tricks.h>
23#include <dialog_shim.h>
24
25
26void TEXTENTRY_TRICKS::OnCharHook( wxTextEntry* aTextEntry, wxKeyEvent& aEvent )
27{
28 if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'X' )
29 {
30 aTextEntry->Cut();
31 }
32 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'C' )
33 {
34 aTextEntry->Copy();
35 }
36 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'V' )
37 {
38 aTextEntry->Paste();
39 }
40 else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'A' )
41 {
42 aTextEntry->SelectAll();
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)
VECTOR2I end