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, see <https://www.gnu.org/licenses/>.
22
*/
23
24
#pragma once
25
26
#include <map>
27
#include <list>
28
#include <functional>
29
30
#include <wx/menu.h>
31
#include <
tool/tool_event.h
>
32
33
class
KIFACE_BASE
;
34
class
TOOL_INTERACTIVE
;
35
class
TOOL_MANAGER
;
36
37
enum class
BITMAPS
:
unsigned
int;
38
42
class
ACTION_MENU
:
public
wxMenu
43
{
44
public
:
46
ACTION_MENU
(
bool
isContextMenu,
TOOL_INTERACTIVE
* aTool =
nullptr
);
47
48
~ACTION_MENU
()
override
;
49
50
ACTION_MENU
(
const
ACTION_MENU
& aMenu ) =
delete
;
51
ACTION_MENU
&
operator=
(
const
ACTION_MENU
& aMenu ) =
delete
;
52
59
void
SetTitle
(
const
wxString& aTitle )
override
;
60
void
SetUntranslatedTitle
(
const
wxString& aTitle ) {
m_untranslatedTitle
= aTitle; }
61
62
// Yes, it hides a non-virtual method in the parent class.
63
wxString
GetTitle
()
const
{
return
m_title
; }
64
68
void
DisplayTitle
(
bool
aDisplay =
true
);
69
75
void
SetIcon
(
BITMAPS
aIcon );
76
82
wxMenuItem*
Add
(
const
wxString& aLabel,
int
aId,
BITMAPS
aIcon );
83
wxMenuItem*
Add
(
const
wxString& aLabel,
const
wxString& aToolTip,
int
aId,
84
BITMAPS
aIcon,
bool
aIsCheckmarkEntry =
false
);
85
96
wxMenuItem*
Add
(
const
TOOL_ACTION
& aAction,
bool
aIsCheckmarkEntry =
false
,
97
const
wxString& aOverrideLabel = wxEmptyString );
98
108
wxMenuItem*
Add
(
ACTION_MENU
* aMenu );
109
117
void
AddClose
(
const
wxString& aAppname =
""
);
118
127
void
AddQuitOrClose
(
KIFACE_BASE
* aKiface, wxString aAppname =
""
);
128
136
void
AddQuit
(
const
wxString& aAppname =
""
);
137
143
void
Clear
();
144
148
bool
HasEnabledItems
()
const
;
149
157
inline
int
GetSelected
()
const
158
{
159
return
m_selected
;
160
}
161
165
void
UpdateAll
();
166
170
virtual
void
UpdateTitle
()
171
{
172
if
( !
m_untranslatedTitle
.IsEmpty() )
173
m_title
= wxGetTranslation(
m_untranslatedTitle
);
174
}
175
179
void
ClearDirty
();
180
void
SetDirty
();
181
187
void
SetTool
(
TOOL_INTERACTIVE
* aTool );
188
192
ACTION_MENU
*
Clone
()
const
;
193
194
void
OnMenuEvent
( wxMenuEvent& aEvent );
195
void
OnIdle
( wxIdleEvent& event );
196
197
virtual
bool
PassHelpTextToHandler
() {
return
false
; }
198
199
static
constexpr
bool
NORMAL
=
false
;
200
static
constexpr
bool
CHECK
=
true
;
201
202
protected
:
204
virtual
ACTION_MENU
*
create
()
const
;
205
207
TOOL_MANAGER
*
getToolManager
()
const
;
208
215
virtual
void
update
()
216
{
217
}
218
225
virtual
OPT_TOOL_EVENT
eventHandler
(
const
wxMenuEvent& )
226
{
227
return
OPT_TOOL_EVENT
();
228
}
229
235
void
copyFrom
(
const
ACTION_MENU
& aMenu );
236
237
protected
:
241
wxMenuItem*
appendCopy
(
const
wxMenuItem* aSource );
242
244
void
setupEvents
();
245
247
void
updateHotKeys
();
248
251
void
runEventHandlers
(
const
wxMenuEvent& aMenuEvent,
OPT_TOOL_EVENT
& aToolEvent );
252
254
void
runOnSubmenus
( std::function<
void
(
ACTION_MENU
*)> aFunction );
255
257
OPT_TOOL_EVENT
findToolAction
(
int
aId );
258
259
bool
m_isForcedPosition
;
260
wxPoint
m_forcedPosition
;
261
262
bool
m_dirty
;
// Menu requires update before display
263
264
bool
m_titleDisplayed
;
265
bool
m_isContextMenu
;
266
268
wxString
m_title
;
269
wxString
m_untranslatedTitle
;
270
272
BITMAPS
m_icon
;
273
275
int
m_selected
;
276
278
TOOL_INTERACTIVE
*
m_tool
;
279
281
std::map<int, const TOOL_ACTION*>
m_toolActions
;
282
284
std::list<ACTION_MENU*>
m_submenus
;
285
286
friend
class
TOOL_INTERACTIVE
;
287
};
BITMAPS
BITMAPS
A list of all bitmap identifiers.
Definition
bitmaps_list.h:29
ACTION_MENU
Define the structure of a menu based on ACTIONs.
Definition
action_menu.h:43
ACTION_MENU::updateHotKeys
void updateHotKeys()
Update hot key settings for TOOL_ACTIONs in this menu.
Definition
action_menu.cpp:351
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:47
ACTION_MENU::m_forcedPosition
wxPoint m_forcedPosition
Definition
action_menu.h:260
ACTION_MENU::SetDirty
void SetDirty()
Definition
action_menu.cpp:311
ACTION_MENU::getToolManager
TOOL_MANAGER * getToolManager() const
Return an instance of TOOL_MANAGER class.
Definition
action_menu.cpp:345
ACTION_MENU::setupEvents
void setupEvents()
Initialize handlers for events.
Definition
action_menu.cpp:91
ACTION_MENU::m_title
wxString m_title
Menu title.
Definition
action_menu.h:268
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:334
ACTION_MENU::update
virtual void update()
Update menu state stub.
Definition
action_menu.h:215
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:232
ACTION_MENU::ClearDirty
void ClearDirty()
Clear the dirty flag on the menu and all descendants.
Definition
action_menu.cpp:304
ACTION_MENU::m_isForcedPosition
bool m_isForcedPosition
Definition
action_menu.h:259
ACTION_MENU::appendCopy
wxMenuItem * appendCopy(const wxMenuItem *aSource)
Append a copy of wxMenuItem.
Definition
action_menu.cpp:672
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:629
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:603
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:281
ACTION_MENU::m_isContextMenu
bool m_isContextMenu
Definition
action_menu.h:265
ACTION_MENU::eventHandler
virtual OPT_TOOL_EVENT eventHandler(const wxMenuEvent &)
Event handler stub.
Definition
action_menu.h:225
ACTION_MENU::CHECK
static constexpr bool CHECK
Definition
action_menu.h:200
ACTION_MENU::m_dirty
bool m_dirty
Definition
action_menu.h:262
ACTION_MENU::OnMenuEvent
void OnMenuEvent(wxMenuEvent &aEvent)
Definition
action_menu.cpp:410
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:216
ACTION_MENU::DisplayTitle
void DisplayTitle(bool aDisplay=true)
Decide whether a title for a pop up menu should be displayed.
Definition
action_menu.cpp:109
ACTION_MENU::AddQuit
void AddQuit(const wxString &aAppname="")
Add a standard Quit item to the menu.
Definition
action_menu.cpp:250
ACTION_MENU::SetUntranslatedTitle
void SetUntranslatedTitle(const wxString &aTitle)
Definition
action_menu.h:60
ACTION_MENU::m_untranslatedTitle
wxString m_untranslatedTitle
Definition
action_menu.h:269
ACTION_MENU::Clone
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.
Definition
action_menu.cpp:325
ACTION_MENU::Clear
void Clear()
Remove all the entries from the menu (as well as its title).
Definition
action_menu.cpp:261
ACTION_MENU::UpdateAll
void UpdateAll()
Run update handlers for the menu and its submenus.
Definition
action_menu.cpp:287
ACTION_MENU::SetTitle
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition
action_menu.cpp:98
ACTION_MENU::NORMAL
static constexpr bool NORMAL
Definition
action_menu.h:199
ACTION_MENU::SetTool
void SetTool(TOOL_INTERACTIVE *aTool)
Set a tool that is the creator of the menu.
Definition
action_menu.cpp:318
ACTION_MENU::OnIdle
void OnIdle(wxIdleEvent &event)
Definition
action_menu.cpp:402
ACTION_MENU::m_submenus
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition
action_menu.h:284
ACTION_MENU::SetIcon
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition
action_menu.cpp:85
ACTION_MENU::~ACTION_MENU
~ACTION_MENU() override
Definition
action_menu.cpp:60
ACTION_MENU::UpdateTitle
virtual void UpdateTitle()
Used by some menus to just-in-time translate their titles.
Definition
action_menu.h:170
ACTION_MENU::GetTitle
wxString GetTitle() const
Definition
action_menu.h:63
ACTION_MENU::Add
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
Definition
action_menu.cpp:148
ACTION_MENU::m_titleDisplayed
bool m_titleDisplayed
Definition
action_menu.h:264
ACTION_MENU::GetSelected
int GetSelected() const
Return the position of selected item.
Definition
action_menu.h:157
ACTION_MENU::TOOL_INTERACTIVE
friend class TOOL_INTERACTIVE
Definition
action_menu.h:286
ACTION_MENU::m_selected
int m_selected
Store the id number of selected item.
Definition
action_menu.h:275
ACTION_MENU::m_icon
BITMAPS m_icon
Optional icon.
Definition
action_menu.h:272
ACTION_MENU::HasEnabledItems
bool HasEnabledItems() const
Return true if the menu has any enabled items.
Definition
action_menu.cpp:275
ACTION_MENU::m_tool
TOOL_INTERACTIVE * m_tool
Creator of the menu.
Definition
action_menu.h:278
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:612
ACTION_MENU::PassHelpTextToHandler
virtual bool PassHelpTextToHandler()
Definition
action_menu.h:197
ACTION_MENU::copyFrom
void copyFrom(const ACTION_MENU &aMenu)
Copy another menus data to this instance.
Definition
action_menu.cpp:654
KIFACE_BASE
A KIFACE implementation.
Definition
kiface_base.h:35
TOOL_ACTION
Represent a single user action.
Definition
tool_action.h:300
TOOL_INTERACTIVE
Definition
tool_interactive.h:53
TOOL_MANAGER
Master controller class:
Definition
tool_manager.h:58
tool_event.h
OPT_TOOL_EVENT
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition
tool_event.h:637
src
include
tool
action_menu.h
Generated on Fri Jun 26 2026 00:05:37 for KiCad PCB EDA Suite by
1.13.2