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
128
void
AddQuitOrClose
(
KIFACE_BASE
* aKiface, wxString aAppname =
""
);
129
137
void
AddQuit
(
const
wxString& aAppname =
""
);
138
144
void
Clear
();
145
149
bool
HasEnabledItems
()
const
;
150
158
inline
int
GetSelected
()
const
159
{
160
return
m_selected
;
161
}
162
166
void
UpdateAll
();
167
171
virtual
void
UpdateTitle
()
172
{
173
if
( !
m_untranslatedTitle
.IsEmpty() )
174
m_title
= wxGetTranslation(
m_untranslatedTitle
);
175
}
176
180
void
ClearDirty
();
181
void
SetDirty
();
182
188
void
SetTool
(
TOOL_INTERACTIVE
* aTool );
189
193
ACTION_MENU
*
Clone
()
const
;
194
195
void
OnMenuEvent
( wxMenuEvent& aEvent );
196
void
OnIdle
( wxIdleEvent& event );
197
198
virtual
bool
PassHelpTextToHandler
() {
return
false
; }
199
200
static
constexpr
bool
NORMAL
=
false
;
201
static
constexpr
bool
CHECK
=
true
;
202
203
protected
:
205
virtual
ACTION_MENU
*
create
()
const
;
206
208
TOOL_MANAGER
*
getToolManager
()
const
;
209
216
virtual
void
update
()
217
{
218
}
219
226
virtual
OPT_TOOL_EVENT
eventHandler
(
const
wxMenuEvent& )
227
{
228
return
OPT_TOOL_EVENT
();
229
}
230
236
void
copyFrom
(
const
ACTION_MENU
& aMenu );
237
238
protected
:
242
wxMenuItem*
appendCopy
(
const
wxMenuItem* aSource );
243
245
void
setupEvents
();
246
248
void
updateHotKeys
();
249
252
void
runEventHandlers
(
const
wxMenuEvent& aMenuEvent,
OPT_TOOL_EVENT
& aToolEvent );
253
255
void
runOnSubmenus
( std::function<
void
(
ACTION_MENU
*)> aFunction );
256
258
OPT_TOOL_EVENT
findToolAction
(
int
aId );
259
260
bool
m_isForcedPosition
;
261
wxPoint
m_forcedPosition
;
262
263
bool
m_dirty
;
// Menu requires update before display
264
265
bool
m_titleDisplayed
;
266
bool
m_isContextMenu
;
267
269
wxString
m_title
;
270
wxString
m_untranslatedTitle
;
271
273
BITMAPS
m_icon
;
274
276
int
m_selected
;
277
279
TOOL_INTERACTIVE
*
m_tool
;
280
282
std::map<int, const TOOL_ACTION*>
m_toolActions
;
283
285
std::list<ACTION_MENU*>
m_submenus
;
286
287
friend
class
TOOL_INTERACTIVE
;
288
};
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:261
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:269
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:216
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:260
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:282
ACTION_MENU::m_isContextMenu
bool m_isContextMenu
Definition
action_menu.h:266
ACTION_MENU::eventHandler
virtual OPT_TOOL_EVENT eventHandler(const wxMenuEvent &)
Event handler stub.
Definition
action_menu.h:226
ACTION_MENU::CHECK
static constexpr bool CHECK
Definition
action_menu.h:201
ACTION_MENU::m_dirty
bool m_dirty
Definition
action_menu.h:263
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:270
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:200
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:285
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:171
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:265
ACTION_MENU::GetSelected
int GetSelected() const
Return the position of selected item.
Definition
action_menu.h:158
ACTION_MENU::TOOL_INTERACTIVE
friend class TOOL_INTERACTIVE
Definition
action_menu.h:287
ACTION_MENU::m_selected
int m_selected
Store the id number of selected item.
Definition
action_menu.h:276
ACTION_MENU::m_icon
BITMAPS m_icon
Optional icon.
Definition
action_menu.h:273
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:279
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:198
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:652
src
include
tool
action_menu.h
Generated on Wed Oct 7 2026 00:05:59 for KiCad PCB EDA Suite by
1.13.2