1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2004-2021 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, 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 #ifndef  HOTKEYS_BASIC_H
25 #define  HOTKEYS_BASIC_H
26 
27 #include <wx/string.h>
28 #include <map>
29 
30 #define EESCHEMA_HOTKEY_NAME wxT( "Eeschema" )
31 #define PCBNEW_HOTKEY_NAME wxT( "PcbNew" )
32 
33 // A define to allow translation of Hot Key message Info in hotkey help menu
34 // We do not want to use the _( x ) usual macro from wxWidgets, which calls wxGetTranslation(),
35 // because the English string is used in key file configuration
36 // The translated string is used only when displaying the help window.
37 // Therefore translation tools have to use the "_" and the "_HKI" prefix to extract
38 // strings to translate
39 #include <i18n_utility.h>       // _HKI definition
40 
41 class TOOL_ACTION;
42 class TOOL_MANAGER;
43 class EDA_BASE_FRAME;
44 
45 
46 /*
47  * Keep these out of the ASCII range, and out of the WXK range
48  */
49 #define PSEUDO_WXK_CLICK    400
50 #define PSEUDO_WXK_DBLCLICK 401
51 #define PSEUDO_WXK_WHEEL    402
52 
53 /**
54  * Return the key code from its user-friendly key name (ie: "Ctrl+M").
55  */
56 int KeyCodeFromKeyName( const wxString& keyname );
57 
58 /**
59  * Return the user friendly key name (ie: "Ctrl+M") from the key code.
60  *
61  * @param aKeycode key code (ASCII value, or wxWidgets value for function keys).
62  * @param aIsFound a pointer to a bool to return true if found, or false.
63  */
64 wxString KeyNameFromKeyCode( int aKeycode, bool* aIsFound = nullptr );
65 
66 /**
67  * In menus we can add a hot key, or an accelerator, or sometimes just a comment.   Hot keys
68  * can perform actions using the current mouse cursor position and accelerators perform the
69  * same action as the associated menu.
70  *
71  * A comment is used in tool tips for some tools (zoom ..) to show the hot key that performs
72  * this action
73  */
74 enum HOTKEY_ACTION_TYPE
75 {
76     IS_HOTKEY,
77     IS_COMMENT
78 };
79 
80 /**
81  * @param aText the base text on which to append the hotkey.
82  * @param aHotKey the hotkey keycode.
83  * @param aStyle #IS_HOTKEY to add <tab><keyname> (shortcuts in menus, same as hotkeys).
84  *               #IS_COMMENT to add <spaces><(keyname)> mainly in tool tips.
85  */
86 wxString AddHotkeyName(  const wxString& aText, int aHotKey,
87                          HOTKEY_ACTION_TYPE aStyle = IS_HOTKEY);
88 
89 /**
90  * Display the current hotkey list.
91  *
92  * @param aFrame current active frame.
93  * @param aToolMgr the tool manager holding the registered actions from which the hotkeys
94  *                 will be harvested.
95  */
96 void DisplayHotkeyList( EDA_BASE_FRAME* aFrame, TOOL_MANAGER* aToolMgr );
97 
98 /**
99  * Reads a hotkey config file into a map.
100  *
101  * If \a aFileName is empty it will read in the default hotkeys file.
102  */
103 void ReadHotKeyConfig( const wxString& aFileName, std::map<std::string, int>& aHotKeys );
104 
105 /**
106  * Update the hotkeys config file with the hotkeys from the given actions map.
107  */
108 int WriteHotKeyConfig( const std::map<std::string, TOOL_ACTION*>& aActionMap );
109 
110 /**
111  * Read hotkey configuration for a given app.
112  *
113  * @param aFilename the filename to save the hotkeys as.
114  * @param aMap The list of keycodes mapped by legacy property names.
115  * @return 1 on success, 0 on failure.
116 */
117 int ReadLegacyHotkeyConfigFile( const wxString& aFilename, std::map<std::string, int>& aMap );
118 
119 /**
120  * Read configuration data and fill the current hotkey list with hotkeys.
121  *
122  * @param aAppname the value of the app's m_FrameName.
123  * @param aMap The list of keycodes mapped by legacy property names.
124  */
125 int ReadLegacyHotkeyConfig( const wxString& aAppname, std::map<std::string, int>& aMap );
126 
127 #endif // HOTKEYS_BASIC_H
128