KiCad PCB EDA Suite
widget_hotkey_list.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) 2016 Chris Pavlina <pavlina.chris@gmail.com>
5  * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef __widget_hotkey_list__
26 #define __widget_hotkey_list__
27 
28 #include <utility>
29 #include <vector>
30 
31 #include <wx/treelist.h>
32 #include <wx/dataview.h>
33 
34 #include <hotkeys_basic.h>
35 #include <hotkey_store.h>
36 
37 
39 
40 class WIDGET_HOTKEY_LIST : public wxTreeListCtrl
41 {
43  bool m_readOnly;
44 
45  wxTreeListItem m_context_menu_item;
46 
49 
50  static std::map<wxString, int> m_width_cache;
51 
56  WIDGET_HOTKEY_CLIENT_DATA* GetHKClientData( wxTreeListItem aItem );
57 
62  WIDGET_HOTKEY_CLIENT_DATA* getExpectedHkClientData( wxTreeListItem aItem );
63 
68  void UpdateFromClientData();
69 
77  void updateShownItems( const wxString& aFilterStr );
78 
88  void changeHotkey( HOTKEY& aHotkey, long aKey );
89 
90 protected:
95  void EditItem( wxTreeListItem aItem );
96 
101  void ResetItem( wxTreeListItem aItem, int aResetId );
102 
107  void OnActivated( wxTreeListEvent& aEvent );
108 
113  void OnContextMenu( wxTreeListEvent& aEvent );
114 
119  void OnMenu( wxCommandEvent& aEvent );
120 
125  void OnSize( wxSizeEvent& aEvent );
126 
131  int MemoWidthFor( const wxString& aStr );
132 
148  bool ResolveKeyConflicts( TOOL_ACTION* aAction, long aKey );
149 
150 public:
159  WIDGET_HOTKEY_LIST( wxWindow* aParent, HOTKEY_STORE& aHotkeyStore, bool aReadOnly );
160 
168  void ApplyFilterString( const wxString& aFilterStr );
169 
175  void ResetAllHotkeys( bool aResetToDefault );
176 
182  bool TransferDataToControl();
183 
190 
195  static long MapKeypressToKeycode( const wxKeyEvent& aEvent );
196 };
197 
198 #endif // __widget_hotkey_list__
void OnActivated(wxTreeListEvent &aEvent)
Method OnActivated Handle activation of a row.
static long MapKeypressToKeycode(const wxKeyEvent &aEvent)
Static method MapKeypressToKeycode Map a keypress event to the correct key code for use as a hotkey.
void changeHotkey(HOTKEY &aHotkey, long aKey)
Attempt to change the given hotkey to the given key code.
A class that contains a set of hotkeys, arranged into "sections" and provides some book-keeping funct...
Definition: hotkey_store.h:61
void OnMenu(wxCommandEvent &aEvent)
Method OnMenu Handle activation of a context menu item.
bool TransferDataToControl()
Method TransferDataToControl Load the hotkey data from the store into the control.
void OnSize(wxSizeEvent &aEvent)
Function OnSize Handle resizing of the control.
WIDGET_HOTKEY_CLIENT_DATA * getExpectedHkClientData(wxTreeListItem aItem)
Get the WIDGET_HOTKEY_CLIENT_DATA form an item and assert if it isn't found.
HOTKEY_STORE & m_hk_store
void UpdateFromClientData()
Method UpdateFromClientData Refresh the visible text on the widget from the rows' client data objects...
void updateShownItems(const wxString &aFilterStr)
Method updateShownItems.
wxTreeListItem m_context_menu_item
WIDGET_HOTKEY_CLIENT_DATA Stores the hotkey change data associated with each row.
bool ResolveKeyConflicts(TOOL_ACTION *aAction, long aKey)
Method ResolveKeyConflicts Check if we can set a hotkey, and prompt the user if there is a conflict b...
void ApplyFilterString(const wxString &aFilterStr)
Method ApplyFilterString Apply a filter string to the hotkey list, selecting which hotkeys to show.
WIDGET_HOTKEY_LIST(wxWindow *aParent, HOTKEY_STORE &aHotkeyStore, bool aReadOnly)
Constructor WIDGET_HOTKEY_LIST Create a WIDGET_HOTKEY_LIST.
void ResetItem(wxTreeListItem aItem, int aResetId)
Method ResetItem Reset the item to either the default, the value when the dialog was opened,...
TOOL_ACTION.
Definition: tool_action.h:46
WIDGET_HOTKEY_CLIENT_DATA * GetHKClientData(wxTreeListItem aItem)
Method GetHKClientData Return the WIDGET_HOTKEY_CLIENT_DATA for the given item, or NULL if the item i...
int MemoWidthFor(const wxString &aStr)
Memoized version of wxWidthFor(), which returns the width in pixels required to display a string.
void EditItem(wxTreeListItem aItem)
Method EditItem Prompt the user for a new hotkey given a list item.
static std::map< wxString, int > m_width_cache
void ResetAllHotkeys(bool aResetToDefault)
Set hotkeys in the control to default or original values.
void OnContextMenu(wxTreeListEvent &aEvent)
Method OnContextMenu Handle right-click on a row.
bool TransferDataFromControl()
Method TransferDataFromControl Save the hotkey data from the control.