KiCad PCB EDA Suite
Loading...
Searching...
No Matches
action_menu.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) 2013-2017 CERN
5
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6
*
7
* @author Tomasz Wlostowski <
[email protected]
>
8
* @author Maciej Suminski <
[email protected]
>
9
*
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU General Public License
12
* as published by the Free Software Foundation; either version 2
13
* of the License, or (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, you may find one here:
22
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23
* or you may search the http://www.gnu.org website for the version 2 license,
24
* or you may write to the Free Software Foundation, Inc.,
25
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26
*/
27
28
#pragma once
29
30
#include <map>
31
#include <list>
32
#include <functional>
33
34
#include <wx/menu.h>
35
#include <
tool/tool_event.h
>
36
37
class
KIFACE_BASE
;
38
class
TOOL_INTERACTIVE
;
39
class
TOOL_MANAGER
;
40
41
enum class
BITMAPS
:
unsigned
int;
42
46
class
ACTION_MENU
:
public
wxMenu
47
{
48
public
:
50
ACTION_MENU
(
bool
isContextMenu,
TOOL_INTERACTIVE
* aTool =
nullptr
);
51
52
~ACTION_MENU
()
override
;
53
54
ACTION_MENU
(
const
ACTION_MENU
& aMenu ) =
delete
;
55
ACTION_MENU
&
operator=
(
const
ACTION_MENU
& aMenu ) =
delete
;
56
63
void
SetTitle
(
const
wxString& aTitle )
override
;
64
void
SetUntranslatedTitle
(
const
wxString& aTitle ) {
m_untranslatedTitle
= aTitle; }
65
66
// Yes, it hides a non-virtual method in the parent class.
67
wxString
GetTitle
()
const
{
return
m_title
; }
68
72
void
DisplayTitle
(
bool
aDisplay =
true
);
73
79
void
SetIcon
(
BITMAPS
aIcon );
80
86
wxMenuItem*
Add
(
const
wxString& aLabel,
int
aId,
BITMAPS
aIcon );
87
wxMenuItem*
Add
(
const
wxString& aLabel,
const
wxString& aToolTip,
int
aId,
88
BITMAPS
aIcon,
bool
aIsCheckmarkEntry =
false
);
89
100
wxMenuItem*
Add
(
const
TOOL_ACTION
& aAction,
bool
aIsCheckmarkEntry =
false
,
101
const
wxString& aOverrideLabel = wxEmptyString );
102
112
wxMenuItem*
Add
(
ACTION_MENU
* aMenu );
113
121
void
AddClose
(
const
wxString& aAppname =
""
);
122
131
void
AddQuitOrClose
(
KIFACE_BASE
* aKiface, wxString aAppname =
""
);
132
140
void
AddQuit
(
const
wxString& aAppname =
""
);
141
147
void
Clear
();
148
152
bool
HasEnabledItems
()
const
;
153
161
inline
int
GetSelected
()
const
162
{
163
return
m_selected
;
164
}
165
169
void
UpdateAll
();
170
174
virtual
void
UpdateTitle
()
175
{
176
if
( !
m_untranslatedTitle
.IsEmpty() )
177
m_title
= wxGetTranslation(
m_untranslatedTitle
);
178
}
179
183
void
ClearDirty
();
184
void
SetDirty
();
185
191
void
SetTool
(
TOOL_INTERACTIVE
* aTool );
192
196
ACTION_MENU
*
Clone
()
const
;
197
198
void
OnMenuEvent
( wxMenuEvent& aEvent );
199
void
OnIdle
( wxIdleEvent& event );
200
201
virtual
bool
PassHelpTextToHandler
() {
return
false
; }
202
203
static
constexpr
bool
NORMAL
=
false
;
204
static
constexpr
bool
CHECK
=
true
;
205
206
protected
:
208
virtual
ACTION_MENU
*
create
()
const
;
209
211
TOOL_MANAGER
*
getToolManager
()
const
;
212
219
virtual
void
update
()
220
{
221
}
222
229
virtual
OPT_TOOL_EVENT
eventHandler
(
const
wxMenuEvent& )
230
{
231
return
OPT_TOOL_EVENT
();
232
}
233
239
void
copyFrom
(
const
ACTION_MENU
& aMenu );
240
241
protected
:
245
wxMenuItem*
appendCopy
(
const
wxMenuItem* aSource );
246
248
void
setupEvents
();
249
251
void
updateHotKeys
();
252
255
void
runEventHandlers
(
const
wxMenuEvent& aMenuEvent,
OPT_TOOL_EVENT
& aToolEvent );
256
258
void
runOnSubmenus
( std::function<
void
(
ACTION_MENU
*)> aFunction );
259
261
OPT_TOOL_EVENT
findToolAction
(
int
aId );
262
263
bool
m_isForcedPosition
;
264
wxPoint
m_forcedPosition
;
265
266
bool
m_dirty
;
// Menu requires update before display
267
268
bool
m_titleDisplayed
;
269
bool
m_isContextMenu
;
270
272
wxString
m_title
;
273
wxString
m_untranslatedTitle
;
274
276
BITMAPS
m_icon
;
277
279
int
m_selected
;
280
282
TOOL_INTERACTIVE
*
m_tool
;
283
285
std::map<int, const TOOL_ACTION*>
m_toolActions
;
286
288
std::list<ACTION_MENU*>
m_submenus
;
289
290
friend
class
TOOL_INTERACTIVE
;
291
};
BITMAPS
BITMAPS
A list of all bitmap identifiers.
Definition
bitmaps_list.h:33
ACTION_MENU
Define the structure of a menu based on ACTIONs.
Definition
action_menu.h:47
ACTION_MENU::updateHotKeys
void updateHotKeys()
Update hot key settings for TOOL_ACTIONs in this menu.
Definition
action_menu.cpp:355
ACTION_MENU::ACTION_MENU
ACTION_MENU(const ACTION_MENU &aMenu)=delete
ACTION_MENU::ACTION_MENU
ACTION_MENU(bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr)
Default constructor.
Definition
action_menu.cpp:51
ACTION_MENU::m_forcedPosition
wxPoint m_forcedPosition
Definition
action_menu.h:264
ACTION_MENU::SetDirty
void SetDirty()
Definition
action_menu.cpp:315
ACTION_MENU::getToolManager
TOOL_MANAGER * getToolManager() const
Return an instance of TOOL_MANAGER class.
Definition
action_menu.cpp:349
ACTION_MENU::setupEvents
void setupEvents()
Initialize handlers for events.
Definition
action_menu.cpp:95
ACTION_MENU::m_title
wxString m_title
Menu title.
Definition
action_menu.h:272
ACTION_MENU::create
virtual ACTION_MENU * create() const
Return an instance of this class. It has to be overridden in inheriting classes.
Definition
action_menu.cpp:338
ACTION_MENU::update
virtual void update()
Update menu state stub.
Definition
action_menu.h:219
ACTION_MENU::AddQuitOrClose
void AddQuitOrClose(KIFACE_BASE *aKiface, wxString aAppname="")
Add either a standard Quit or Close item to the menu.
Definition
action_menu.cpp:236
ACTION_MENU::ClearDirty
void ClearDirty()
Clear the dirty flag on the menu and all descendants.
Definition
action_menu.cpp:308
ACTION_MENU::m_isForcedPosition
bool m_isForcedPosition
Definition
action_menu.h:263
ACTION_MENU::appendCopy
wxMenuItem * appendCopy(const wxMenuItem *aSource)
Append a copy of wxMenuItem.
Definition
action_menu.cpp:656
ACTION_MENU::findToolAction
OPT_TOOL_EVENT findToolAction(int aId)
Check if any of submenus contains a TOOL_ACTION with a specific ID.
Definition
action_menu.cpp:613
ACTION_MENU::operator=
ACTION_MENU & operator=(const ACTION_MENU &aMenu)=delete
ACTION_MENU::runEventHandlers
void runEventHandlers(const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
Traverse the submenus tree looking for a submenu capable of handling a particular menu event.
Definition
action_menu.cpp:587
ACTION_MENU::m_toolActions
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition
action_menu.h:285
ACTION_MENU::m_isContextMenu
bool m_isContextMenu
Definition
action_menu.h:269
ACTION_MENU::eventHandler
virtual OPT_TOOL_EVENT eventHandler(const wxMenuEvent &)
Event handler stub.
Definition
action_menu.h:229
ACTION_MENU::CHECK
static constexpr bool CHECK
Definition
action_menu.h:204
ACTION_MENU::m_dirty
bool m_dirty
Definition
action_menu.h:266
ACTION_MENU::OnMenuEvent
void OnMenuEvent(wxMenuEvent &aEvent)
Definition
action_menu.cpp:414
ACTION_MENU::AddClose
void AddClose(const wxString &aAppname="")
Add a standard close item to the menu with the accelerator key CTRL-W.
Definition
action_menu.cpp:220
ACTION_MENU::DisplayTitle
void DisplayTitle(bool aDisplay=true)
Decide whether a title for a pop up menu should be displayed.
Definition
action_menu.cpp:113
ACTION_MENU::AddQuit
void AddQuit(const wxString &aAppname="")
Add a standard Quit item to the menu.
Definition
action_menu.cpp:254
ACTION_MENU::SetUntranslatedTitle
void SetUntranslatedTitle(const wxString &aTitle)
Definition
action_menu.h:64
ACTION_MENU::m_untranslatedTitle
wxString m_untranslatedTitle
Definition
action_menu.h:273
ACTION_MENU::Clone
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.
Definition
action_menu.cpp:329
ACTION_MENU::Clear
void Clear()
Remove all the entries from the menu (as well as its title).
Definition
action_menu.cpp:265
ACTION_MENU::UpdateAll
void UpdateAll()
Run update handlers for the menu and its submenus.
Definition
action_menu.cpp:291
ACTION_MENU::SetTitle
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition
action_menu.cpp:102
ACTION_MENU::NORMAL
static constexpr bool NORMAL
Definition
action_menu.h:203
ACTION_MENU::SetTool
void SetTool(TOOL_INTERACTIVE *aTool)
Set a tool that is the creator of the menu.
Definition
action_menu.cpp:322
ACTION_MENU::OnIdle
void OnIdle(wxIdleEvent &event)
Definition
action_menu.cpp:406
ACTION_MENU::m_submenus
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition
action_menu.h:288
ACTION_MENU::SetIcon
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition
action_menu.cpp:89
ACTION_MENU::~ACTION_MENU
~ACTION_MENU() override
Definition
action_menu.cpp:64
ACTION_MENU::UpdateTitle
virtual void UpdateTitle()
Used by some menus to just-in-time translate their titles.
Definition
action_menu.h:174
ACTION_MENU::GetTitle
wxString GetTitle() const
Definition
action_menu.h:67
ACTION_MENU::Add
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
Definition
action_menu.cpp:152
ACTION_MENU::m_titleDisplayed
bool m_titleDisplayed
Definition
action_menu.h:268
ACTION_MENU::GetSelected
int GetSelected() const
Return the position of selected item.
Definition
action_menu.h:161
ACTION_MENU::TOOL_INTERACTIVE
friend class TOOL_INTERACTIVE
Definition
action_menu.h:290
ACTION_MENU::m_selected
int m_selected
Store the id number of selected item.
Definition
action_menu.h:279
ACTION_MENU::m_icon
BITMAPS m_icon
Optional icon.
Definition
action_menu.h:276
ACTION_MENU::HasEnabledItems
bool HasEnabledItems() const
Return true if the menu has any enabled items.
Definition
action_menu.cpp:279
ACTION_MENU::m_tool
TOOL_INTERACTIVE * m_tool
Creator of the menu.
Definition
action_menu.h:282
ACTION_MENU::runOnSubmenus
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Run a function on the menu and all its submenus.
Definition
action_menu.cpp:596
ACTION_MENU::PassHelpTextToHandler
virtual bool PassHelpTextToHandler()
Definition
action_menu.h:201
ACTION_MENU::copyFrom
void copyFrom(const ACTION_MENU &aMenu)
Copy another menus data to this instance.
Definition
action_menu.cpp:638
KIFACE_BASE
A KIFACE implementation.
Definition
kiface_base.h:39
TOOL_ACTION
Represent a single user action.
Definition
tool_action.h:304
TOOL_INTERACTIVE
Definition
tool_interactive.h:57
TOOL_MANAGER
Master controller class:
Definition
tool_manager.h:62
tool_event.h
OPT_TOOL_EVENT
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition
tool_event.h:641
src
include
tool
action_menu.h
Generated on Mon Oct 13 2025 00:06:20 for KiCad PCB EDA Suite by
1.13.2