KiCad PCB EDA Suite
hotkeys_basic.h
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) 2004-2016 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 
29 #ifndef HOTKEYS_BASIC_H
30 #define HOTKEYS_BASIC_H
31 
32 #include <common.h>
33 
34 #define DEFAULT_HOTKEY_FILENAME_EXT wxT( "hotkeys" )
35 
36 // A define to allow translation of Hot Key message Info in hotkey help menu
37 // We do not want to use the _( x ) usual macro from wxWidgets, which calls wxGetTranslation(),
38 // because the English string is used in key file configuration
39 // The translated string is used only when displaying the help window.
40 // Therefore translation tools have to use the "_" and the "_HKI" prefix to extract
41 // strings to translate
42 #include <i18n_utility.h> // _HKI definition
43 
44 class EDA_BASE_FRAME;
45 
46 
47 /* Identifiers (tags) in key code configuration file (or section names)
48  * .m_SectionTag member of a EDA_HOTKEY_CONFIG
49  */
50 extern wxString g_CommonSectionTag;
51 
58 {
59 private:
60  int m_defaultKeyCode; // Key code assigned upon object construction, to be used as default value
61 
62 public:
63  int m_KeyCode; // Key code (ascii value for ascii keys or wxWidgets code for function key
64  wxString m_InfoMsg; // info message.
65  int m_Idcommand; // internal id for the corresponding command (see hotkey_id_commnand list)
66  int m_IdMenuEvent; // id to call the corresponding event (if any) (see id.h)
67 
68 public:
69  EDA_HOTKEY( const wxChar* infomsg, int idcommand, int keycode, int idmenuevent = 0 );
70  EDA_HOTKEY( const EDA_HOTKEY* base);
71  void ResetKeyCodeToDefault() { m_KeyCode = m_defaultKeyCode; }
72 };
73 
74 
88 {
89 public:
90  wxString* m_SectionTag; // The configuration file section name.
91  EDA_HOTKEY** m_HK_InfoList; // List of EDA_HOTKEY pointers
92  wxString* m_Title; // Title displayed in hotkey editor and used as comment in file
93 };
94 
95 
101 class EDA_HOTKEY_CLIENT_DATA : public wxClientData
102 {
103  //< Logical position of the mouse cursor when the hot key was pressed.
105 
106 public:
107  EDA_HOTKEY_CLIENT_DATA( const wxPoint& aPosition = wxDefaultPosition ) :
108  m_position( aPosition ) {}
109 
111 
112  void SetPosition( const wxPoint& aPosition ) { m_position = aPosition; }
113 
115 };
116 
117 
118 /* Functions:
119  */
120 void AddHotkeyConfigMenu( wxMenu* menu );
121 void HandleHotkeyConfigMenuSelection( EDA_BASE_FRAME* frame, int id );
122 
132 wxString KeyNameFromKeyCode( int aKeycode, bool * aIsFound = NULL );
133 
141 wxString KeyNameFromCommandId( EDA_HOTKEY** aList, int aCommandId );
142 
152 int KeyCodeFromKeyName( const wxString& keyname );
153 
163 {
167 };
168 
178 wxString AddHotkeyName( const wxString& aText, EDA_HOTKEY** aList, int aCommandId,
179  HOTKEY_ACTION_TYPE aShortCutType = IS_HOTKEY);
180 
190 wxString AddHotkeyName( const wxString& aText,
191  struct EDA_HOTKEY_CONFIG* aDescrList,
192  int aCommandId,
193  HOTKEY_ACTION_TYPE aShortCutType = IS_HOTKEY );
194 
201 void DisplayHotkeyList( EDA_BASE_FRAME* aFrame, struct EDA_HOTKEY_CONFIG* aList );
202 
210 EDA_HOTKEY* GetDescriptorFromHotkey( int aKey, EDA_HOTKEY** aList );
211 
219 EDA_HOTKEY* GetDescriptorFromCommand( int aCommand, EDA_HOTKEY** aList );
220 
228 void ReadHotkeyConfig( const wxString& Appname, struct EDA_HOTKEY_CONFIG* aDescList );
229 
230 void ParseHotkeyConfig( const wxString& data, struct EDA_HOTKEY_CONFIG* aDescList );
231 
232 
233 // common hotkeys event id
234 // these hotkey ID are used in many files, so they are define here only once.
250 };
251 
252 #endif // HOTKEYS_BASIC_H
void ParseHotkeyConfig(const wxString &data, struct EDA_HOTKEY_CONFIG *aDescList)
void ResetKeyCodeToDefault()
Definition: hotkeys_basic.h:71
Structure EDA_HOTKEY_CONFIG contains the information required to save hot key information to a config...
Definition: hotkeys_basic.h:87
EDA_HOTKEY ** m_HK_InfoList
Definition: hotkeys_basic.h:91
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound=NULL)
Function KeyNameFromKeyCode return the key name from the key code.
EDA_HOTKEY * GetDescriptorFromHotkey(int aKey, EDA_HOTKEY **aList)
Function GetDescriptorFromHotkey Returns a EDA_HOTKEY* pointer from a key code for OnHotKey() functio...
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType=IS_HOTKEY)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
common_hotkey_id_commnand
Class EDA_HOTKEY_CLIENT_DATA provides client data member for hotkeys to include in command events gen...
void HandleHotkeyConfigMenuSelection(EDA_BASE_FRAME *frame, int id)
EDA_HOTKEY * GetDescriptorFromCommand(int aCommand, EDA_HOTKEY **aList)
Function GetDescriptorFromCommand Returns a EDA_HOTKEY* pointer from a hot key identifier.
void ReadHotkeyConfig(const wxString &Appname, struct EDA_HOTKEY_CONFIG *aDescList)
Function ReadHotkeyConfig Read hotkey configuration for a given app, possibly before the frame for th...
void DisplayHotkeyList(EDA_BASE_FRAME *aFrame, struct EDA_HOTKEY_CONFIG *aList)
Function DisplayHotkeyList Displays the current hotkey list.
wxString * m_SectionTag
Definition: hotkeys_basic.h:90
EDA_HOTKEY(const wxChar *infomsg, int idcommand, int keycode, int idmenuevent=0)
Some functions to handle hotkeys in KiCad.
EDA_HOTKEY_CLIENT_DATA(const wxPoint &aPosition=wxDefaultPosition)
wxString m_InfoMsg
Definition: hotkeys_basic.h:64
int m_defaultKeyCode
Definition: hotkeys_basic.h:60
void SetPosition(const wxPoint &aPosition)
void AddHotkeyConfigMenu(wxMenu *menu)
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:57
int KeyCodeFromKeyName(const wxString &keyname)
Function KeyCodeFromKeyName return the key code from its key name Only some wxWidgets key values are ...
wxString * m_Title
Definition: hotkeys_basic.h:92
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
Definition: wxstruct.h:112
The common library.
wxString g_CommonSectionTag
HOTKEY_ACTION_TYPE
An helper enum for AddHotkeyName function In menus we can add a hot key, or an accelerator ...
wxString KeyNameFromCommandId(EDA_HOTKEY **aList, int aCommandId)
Function KeyNameFromCommandId return the key name from the Command id value ( m_Idcommand member valu...
int m_IdMenuEvent
Definition: hotkeys_basic.h:66