![]() |
KiCad PCB EDA Suite
|
Class ACTION_MENU. More...
#include <action_menu.h>
Public Member Functions | |
ACTION_MENU (bool isContextMenu) | |
More... | |
~ACTION_MENU () override | |
ACTION_MENU (const ACTION_MENU &aMenu)=delete | |
ACTION_MENU & | operator= (const ACTION_MENU &aMenu)=delete |
void | SetTitle (const wxString &aTitle) override |
Function SetTitle() Sets title for the menu. More... | |
void | DisplayTitle (bool aDisplay=true) |
Function DisplayTitle() Decides whether a title for a pop up menu should be displayed. More... | |
void | SetIcon (const BITMAP_OPAQUE *aIcon) |
Function SetIcon() Assigns an icon for the entry. More... | |
wxMenuItem * | Add (const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon) |
Function Add() Adds a wxWidgets-style entry to the menu. More... | |
wxMenuItem * | Add (const wxString &aLabel, const wxString &aToolTip, int aId, const BITMAP_OPAQUE *aIcon) |
wxMenuItem * | Add (const TOOL_ACTION &aAction, bool aIsCheckmarkEntry=false) |
Function Add() Adds an entry to the menu, basing on the TOOL_ACTION object. More... | |
wxMenuItem * | Add (ACTION_MENU *aMenu) |
Function Add() Adds an action menu as a submenu. More... | |
void | Clear () |
Function Clear() Removes all the entries from the menu (as well as its title). More... | |
bool | HasEnabledItems () const |
Function HasEnabledItems();. More... | |
int | GetSelected () const |
Function GetSelected() Returns the position of selected item. More... | |
void | UpdateAll () |
Function UpdateAll() Runs update handlers for the menu and its submenus. More... | |
void | ClearDirty () |
Function ClearDirty() Clears the dirty flag on the menu and all descendants. More... | |
void | SetDirty () |
void | SetTool (TOOL_INTERACTIVE *aTool) |
Function SetTool() Sets a tool that is the creator of the menu. More... | |
ACTION_MENU * | Clone () const |
Creates a deep, recursive copy of this ACTION_MENU. More... | |
void | OnMenuEvent (wxMenuEvent &aEvent) |
void | OnIdle (wxIdleEvent &event) |
Protected Member Functions | |
virtual ACTION_MENU * | create () const |
More... | |
TOOL_MANAGER * | getToolManager () const |
More... | |
virtual void | update () |
Update menu state stub. More... | |
virtual OPT_TOOL_EVENT | eventHandler (const wxMenuEvent &) |
Event handler stub. More... | |
void | copyFrom (const ACTION_MENU &aMenu) |
Copies another menus data to this instance. More... | |
wxMenuItem * | appendCopy (const wxMenuItem *aSource) |
Function appendCopy Appends a copy of wxMenuItem. More... | |
void | setupEvents () |
More... | |
void | updateHotKeys () |
More... | |
void | runEventHandlers (const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent) |
More... | |
void | runOnSubmenus (std::function< void(ACTION_MENU *)> aFunction) |
More... | |
OPT_TOOL_EVENT | findToolAction (int aId) |
More... | |
Static Protected Member Functions | |
static int | getMenuId (const TOOL_ACTION &aAction) |
More... | |
Protected Attributes | |
bool | m_dirty |
bool | m_titleDisplayed |
bool | m_isContextMenu |
wxString | m_title |
More... | |
const BITMAP_OPAQUE * | m_icon |
More... | |
int | m_selected |
More... | |
TOOL_INTERACTIVE * | m_tool |
More... | |
std::map< int, const TOOL_ACTION * > | m_toolActions |
More... | |
std::list< ACTION_MENU * > | m_submenus |
More... | |
Static Protected Attributes | |
static const int | ACTION_ID = 20000 |
More... | |
Friends | |
class | TOOL_INTERACTIVE |
Class ACTION_MENU.
Defines the structure of a menu based on ACTIONs.
Definition at line 43 of file action_menu.h.
ACTION_MENU::ACTION_MENU | ( | bool | isContextMenu | ) |
Default constructor
Definition at line 43 of file action_menu.cpp.
References setupEvents().
Referenced by create(), and BUS_UNFOLD_MENU::update().
|
override |
Definition at line 55 of file action_menu.cpp.
References m_submenus.
|
delete |
wxMenuItem * ACTION_MENU::Add | ( | const wxString & | aLabel, |
int | aId, | ||
const BITMAP_OPAQUE * | aIcon | ||
) |
Function Add() Adds a wxWidgets-style entry to the menu.
After highlighting/selecting the entry, a wxWidgets event is generated.
Definition at line 134 of file action_menu.cpp.
References AddBitmapToMenuItem(), and KiBitmap().
Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), CONDITIONAL_MENU::Evaluate(), ALIGN_DISTRIBUTE_TOOL::Init(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), ROUTER_TOOL_MENU::ROUTER_TOOL_MENU(), CVPCB_MAINFRAME::setupTools(), and TUNER_TOOL_MENU::TUNER_TOOL_MENU().
wxMenuItem * ACTION_MENU::Add | ( | const wxString & | aLabel, |
const wxString & | aToolTip, | ||
int | aId, | ||
const BITMAP_OPAQUE * | aIcon | ||
) |
Definition at line 147 of file action_menu.cpp.
References AddBitmapToMenuItem(), and KiBitmap().
wxMenuItem * ACTION_MENU::Add | ( | const TOOL_ACTION & | aAction, |
bool | aIsCheckmarkEntry = false |
||
) |
Function Add() Adds an entry to the menu, basing on the TOOL_ACTION object.
After selecting the entry, a TOOL_EVENT command containing name of the action is sent.
aAction | is the action to be added to menu entry. |
ID numbers for tool actions need to have a value higher than ACTION_ID
Definition at line 161 of file action_menu.cpp.
References AddBitmapToMenuItem(), TOOL_ACTION::GetDescription(), TOOL_ACTION::GetIcon(), getMenuId(), TOOL_ACTION::GetMenuItem(), KiBitmap(), and m_toolActions.
wxMenuItem * ACTION_MENU::Add | ( | ACTION_MENU * | aMenu | ) |
Function Add() Adds an action menu as a submenu.
The difference between this function and wxMenu::AppendSubMenu() is the capability to handle icons.
aMenu | is the submenu to be added. |
Definition at line 179 of file action_menu.cpp.
References AddBitmapToMenuItem(), Clone(), KiBitmap(), m_icon, m_submenus, and m_title.
|
protected |
Function appendCopy Appends a copy of wxMenuItem.
Definition at line 551 of file action_menu.cpp.
References AddBitmapToMenuItem(), Clone(), and m_submenus.
Referenced by copyFrom().
void ACTION_MENU::Clear | ( | ) |
Function Clear() Removes all the entries from the menu (as well as its title).
It leaves the menu in the initial state.
Definition at line 200 of file action_menu.cpp.
References i, m_submenus, m_titleDisplayed, and m_toolActions.
Referenced by Clone(), CONDITIONAL_MENU::Evaluate(), BUS_UNFOLD_MENU::update(), SYMBOL_UNIT_MENU::update(), TRACK_WIDTH_MENU::update(), and DIFF_PAIR_MENU::update().
void ACTION_MENU::ClearDirty | ( | ) |
Function ClearDirty() Clears the dirty flag on the menu and all descendants.
Definition at line 251 of file action_menu.cpp.
References m_dirty, and runOnSubmenus().
Referenced by TOOL_MENU::ShowContextMenu().
ACTION_MENU * ACTION_MENU::Clone | ( | ) | const |
Creates a deep, recursive copy of this ACTION_MENU.
Definition at line 272 of file action_menu.cpp.
References Clear(), copyFrom(), and create().
Referenced by Add(), appendCopy(), and TOOL_MANAGER::DispatchContextMenu().
|
protected |
Copies another menus data to this instance.
Old entries are preserved, and ones form aMenu are copied.
Definition at line 533 of file action_menu.cpp.
References appendCopy(), i, m_icon, m_selected, m_title, m_titleDisplayed, m_tool, and m_toolActions.
Referenced by Clone().
|
protectedvirtual |
Returns an instance of this class. It has to be overridden in inheriting classes.
Reimplemented in ROUTER_TOOL_MENU, DIFF_PAIR_MENU, TRACK_WIDTH_MENU, LOCK_CONTEXT_MENU, TUNER_TOOL_MENU, HIGHLIGHT_MENU, SELECT_MENU, ZONE_CONTEXT_MENU, SYMBOL_UNIT_MENU, BUS_UNFOLD_MENU, CONDITIONAL_MENU, GRID_MENU, and ZOOM_MENU.
Definition at line 281 of file action_menu.cpp.
References ACTION_MENU(), and Format().
Referenced by Clone().
void ACTION_MENU::DisplayTitle | ( | bool | aDisplay = true | ) |
Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.
Definition at line 97 of file action_menu.cpp.
References AddBitmapToMenuItem(), KiBitmap(), m_icon, m_title, and m_titleDisplayed.
Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), SetTitle(), and TUNER_TOOL_MENU::TUNER_TOOL_MENU().
|
inlineprotectedvirtual |
Event handler stub.
It should be used if you want to generate a TOOL_EVENT from a wxMenuEvent. It will be called when a menu entry is clicked.
Reimplemented in DIFF_PAIR_MENU, TRACK_WIDTH_MENU, GRID_MENU, and ZOOM_MENU.
Definition at line 178 of file action_menu.h.
Referenced by OnMenuEvent(), and runEventHandlers().
|
protected |
Checks if any of submenus contains a TOOL_ACTION with a specific ID.
Definition at line 510 of file action_menu.cpp.
References runOnSubmenus().
Referenced by OnMenuEvent().
|
inlinestaticprotected |
Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.
Definition at line 161 of file action_menu.h.
References ACTION_ID, and TOOL_ACTION::GetId().
Referenced by Add().
|
inline |
Function GetSelected() Returns the position of selected item.
If the returned value is negative, that means that menu was dismissed.
Definition at line 120 of file action_menu.h.
References m_selected.
Referenced by EE_INSPECTION_TOOL::ShowDatasheet().
|
protected |
Returns an instance of TOOL_MANAGER class.
Definition at line 292 of file action_menu.cpp.
References TOOL_BASE::GetManager(), and m_tool.
Referenced by OnMenuEvent(), BUS_UNFOLD_MENU::update(), SYMBOL_UNIT_MENU::update(), and updateHotKeys().
bool ACTION_MENU::HasEnabledItems | ( | ) | const |
Function HasEnabledItems();.
Returns true if the menu has any enabled items
Definition at line 214 of file action_menu.cpp.
void ACTION_MENU::OnIdle | ( | wxIdleEvent & | event | ) |
Definition at line 347 of file action_menu.cpp.
References g_last_menu_highlighted_id, g_menu_open_position, VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by setupEvents().
void ACTION_MENU::OnMenuEvent | ( | wxMenuEvent & | aEvent | ) |
Definition at line 355 of file action_menu.cpp.
References ACTION_ID, AS_GLOBAL, eventHandler(), findToolAction(), g_last_menu_highlighted_id, g_menu_open_position, TOOL_BASE::GetManager(), TOOL_MANAGER::GetMousePosition(), getToolManager(), ID_CONTEXT_MENU_ID_MAX, ID_POPUP_MENU_END, ID_POPUP_MENU_START, kicadTraceToolStack, m_dirty, m_isContextMenu, m_selected, m_tool, TOOL_MANAGER::ProcessEvent(), TOOL_MANAGER::RunAction(), runEventHandlers(), TA_CHOICE_MENU_CHOICE, TA_CHOICE_MENU_UPDATE, TC_COMMAND, and ACTIONS::updateMenu.
Referenced by EDA_BASE_FRAME::OnMenuOpen(), and setupEvents().
|
delete |
|
protected |
Traverses the submenus tree looking for a submenu capable of handling a particular menu event.
In case it is handled, it is returned the aToolEvent parameter.
Definition at line 485 of file action_menu.cpp.
References eventHandler(), and runOnSubmenus().
Referenced by OnMenuEvent().
|
protected |
Runs a function on the menu and all its submenus.
Definition at line 494 of file action_menu.cpp.
References Format(), and m_submenus.
Referenced by ClearDirty(), CONDITIONAL_MENU::Evaluate(), findToolAction(), CONDITIONAL_MENU::Resolve(), runEventHandlers(), SetDirty(), SetTool(), and UpdateAll().
void ACTION_MENU::SetDirty | ( | ) |
Definition at line 258 of file action_menu.cpp.
References m_dirty, and runOnSubmenus().
Referenced by TOOL_MENU::ShowContextMenu().
void ACTION_MENU::SetIcon | ( | const BITMAP_OPAQUE * | aIcon | ) |
Function SetIcon() Assigns an icon for the entry.
aIcon | is the icon to be assigned. NULL is used to remove icon. |
Definition at line 68 of file action_menu.cpp.
References m_icon.
Referenced by AddMenuLanguageList(), BUS_UNFOLD_MENU::BUS_UNFOLD_MENU(), EDA_3D_VIEWER::CreateMenuBar(), DIFF_PAIR_MENU::DIFF_PAIR_MENU(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), GRID_MENU::GRID_MENU(), ALIGN_DISTRIBUTE_TOOL::Init(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), SYMBOL_UNIT_MENU::SYMBOL_UNIT_MENU(), TRACK_WIDTH_MENU::TRACK_WIDTH_MENU(), TUNER_TOOL_MENU::TUNER_TOOL_MENU(), and ZOOM_MENU::ZOOM_MENU().
|
override |
Function SetTitle() Sets title for the menu.
The title is shown as a text label shown on the top of the menu.
aTitle | is the new title. |
Definition at line 86 of file action_menu.cpp.
References DisplayTitle(), m_title, and m_titleDisplayed.
Referenced by AddMenuLanguageList(), BUS_UNFOLD_MENU::BUS_UNFOLD_MENU(), EDA_3D_VIEWER::CreateMenuBar(), DIFF_PAIR_MENU::DIFF_PAIR_MENU(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), GRID_MENU::GRID_MENU(), ALIGN_DISTRIBUTE_TOOL::Init(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), ROUTER_TOOL_MENU::ROUTER_TOOL_MENU(), SYMBOL_UNIT_MENU::SYMBOL_UNIT_MENU(), TRACK_WIDTH_MENU::TRACK_WIDTH_MENU(), TUNER_TOOL_MENU::TUNER_TOOL_MENU(), and ZOOM_MENU::ZOOM_MENU().
void ACTION_MENU::SetTool | ( | TOOL_INTERACTIVE * | aTool | ) |
Function SetTool() Sets a tool that is the creator of the menu.
aTool | is the tool that created the menu. |
Definition at line 265 of file action_menu.cpp.
References m_tool, and runOnSubmenus().
Referenced by ALIGN_DISTRIBUTE_TOOL::Init(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), LIB_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), TOOL_INTERACTIVE::SetContextMenu(), CVPCB_MAINFRAME::setupTools(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().
|
protected |
Initializes handlers for events.
Definition at line 74 of file action_menu.cpp.
References OnIdle(), and OnMenuEvent().
Referenced by ACTION_MENU().
|
inlineprotectedvirtual |
Update menu state stub.
It is called before a menu is shown, in order to update its state. Here you can tick current settings, enable/disable entries, etc.
Reimplemented in DIFF_PAIR_MENU, TRACK_WIDTH_MENU, ZONE_CONTEXT_MENU, SELECT_MENU, SYMBOL_UNIT_MENU, BUS_UNFOLD_MENU, HIGHLIGHT_MENU, GRID_MENU, and ZOOM_MENU.
Definition at line 170 of file action_menu.h.
Referenced by UpdateAll().
void ACTION_MENU::UpdateAll | ( | ) |
Function UpdateAll() Runs update handlers for the menu and its submenus.
Definition at line 233 of file action_menu.cpp.
References Format(), m_tool, runOnSubmenus(), update(), and updateHotKeys().
Referenced by CONDITIONAL_MENU::Resolve(), TOOL_MENU::ShowContextMenu(), KICAD_MANAGER_CONTROL::UpdateMenu(), GERBVIEW_SELECTION_TOOL::UpdateMenu(), PL_SELECTION_TOOL::UpdateMenu(), EE_SELECTION_TOOL::UpdateMenu(), CVPCB_CONTROL::UpdateMenu(), and SELECTION_TOOL::UpdateMenu().
|
protected |
Updates hot key settings for TOOL_ACTIONs in this menu.
Definition at line 299 of file action_menu.cpp.
References TOOL_MANAGER::GetHotKey(), getToolManager(), m_toolActions, MD_ALT, MD_CTRL, MD_MODIFIER_MASK, MD_SHIFT, and mod.
Referenced by UpdateAll().
|
friend |
Definition at line 238 of file action_menu.h.
|
staticprotected |
Menu items with ID higher than that are considered TOOL_ACTIONs
Definition at line 230 of file action_menu.h.
Referenced by getMenuId(), and OnMenuEvent().
|
protected |
Definition at line 212 of file action_menu.h.
Referenced by ClearDirty(), OnMenuEvent(), and SetDirty().
|
protected |
Optional icon
Definition at line 221 of file action_menu.h.
Referenced by Add(), copyFrom(), DisplayTitle(), and SetIcon().
|
protected |
Definition at line 215 of file action_menu.h.
Referenced by CONDITIONAL_MENU::create(), CONDITIONAL_MENU::Evaluate(), and OnMenuEvent().
|
protected |
Stores the id number of selected item.
Definition at line 224 of file action_menu.h.
Referenced by copyFrom(), GetSelected(), and OnMenuEvent().
|
protected |
List of submenus.
Definition at line 236 of file action_menu.h.
Referenced by Add(), appendCopy(), Clear(), runOnSubmenus(), and ~ACTION_MENU().
|
protected |
Menu title
Definition at line 218 of file action_menu.h.
Referenced by Add(), copyFrom(), DisplayTitle(), and SetTitle().
|
protected |
Definition at line 214 of file action_menu.h.
Referenced by Clear(), copyFrom(), DisplayTitle(), and SetTitle().
|
protected |
Creator of the menu
Definition at line 227 of file action_menu.h.
Referenced by CONDITIONAL_MENU::CONDITIONAL_MENU(), copyFrom(), CONDITIONAL_MENU::create(), getToolManager(), OnMenuEvent(), SetTool(), and UpdateAll().
|
protected |
Associates tool actions with menu item IDs. Non-owning.
Definition at line 233 of file action_menu.h.
Referenced by Add(), Clear(), copyFrom(), and updateHotKeys().