KiCad PCB EDA Suite
ACTION_MENU Class Reference

Defines the structure of a menu based on ACTIONs. More...

#include <action_menu.h>

Inheritance diagram for ACTION_MENU:
BUS_UNFOLD_MENU CONDITIONAL_MENU DIFF_PAIR_MENU GRID_MENU GROUP_CONTEXT_MENU HIGHLIGHT_MENU LOCK_CONTEXT_MENU NET_CONTEXT_MENU SELECT_MENU SYMBOL_UNIT_MENU TRACK_WIDTH_MENU VIA_SIZE_MENU ZONE_CONTEXT_MENU ZOOM_MENU

Public Member Functions

 ACTION_MENU (bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr)
 < Default constructor More...
 
 ~ACTION_MENU () override
 
 ACTION_MENU (const ACTION_MENU &aMenu)=delete
 
ACTION_MENUoperator= (const ACTION_MENU &aMenu)=delete
 
void SetTitle (const wxString &aTitle) override
 Set title for the menu. More...
 
void DisplayTitle (bool aDisplay=true)
 Decide whether a title for a pop up menu should be displayed. More...
 
void SetIcon (BITMAPS aIcon)
 Assign an icon for the entry. More...
 
wxMenuItem * Add (const wxString &aLabel, int aId, BITMAPS aIcon)
 Add a wxWidgets-style entry to the menu. More...
 
wxMenuItem * Add (const wxString &aLabel, const wxString &aToolTip, int aId, BITMAPS aIcon, bool aIsCheckmarkEntry=false)
 
wxMenuItem * Add (const TOOL_ACTION &aAction, bool aIsCheckmarkEntry=false, const wxString &aOverrideLabel=wxEmptyString)
 Add an entry to the menu based on the TOOL_ACTION object. More...
 
wxMenuItem * Add (ACTION_MENU *aMenu)
 Add an action menu as a submenu. More...
 
void AddClose (wxString aAppname="")
 Add a standard close item to the menu with the accelerator key CTRL-W. More...
 
void AddQuitOrClose (KIFACE_I *aKiface, wxString aAppname="")
 Add either a standard Quit or Close item to the menu. More...
 
void Clear ()
 Remove all the entries from the menu (as well as its title). More...
 
bool HasEnabledItems () const
 Returns true if the menu has any enabled items. More...
 
int GetSelected () const
 Return the position of selected item. More...
 
void UpdateAll ()
 Run update handlers for the menu and its submenus. More...
 
void ClearDirty ()
 Clear the dirty flag on the menu and all descendants. More...
 
void SetDirty ()
 
void SetTool (TOOL_INTERACTIVE *aTool)
 Set a tool that is the creator of the menu. More...
 
ACTION_MENUClone () const
 Create a deep, recursive copy of this ACTION_MENU. More...
 
void OnMenuEvent (wxMenuEvent &aEvent)
 
void OnIdle (wxIdleEvent &event)
 
virtual bool PassHelpTextToHandler ()
 

Static Public Attributes

static constexpr bool NORMAL = false
 
static constexpr bool CHECK = true
 

Protected Member Functions

virtual ACTION_MENUcreate () const
 < Return an instance of this class. It has to be overridden in inheriting classes. More...
 
TOOL_MANAGERgetToolManager () const
 
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)
 Copy another menus data to this instance. More...
 
wxMenuItem * appendCopy (const wxMenuItem *aSource)
 Append a copy of wxMenuItem. More...
 
void setupEvents ()
 Update hot key settings for TOOL_ACTIONs in this menu. More...
 
void updateHotKeys ()
 Traverse the submenus tree looking for a submenu capable of handling a particular menu event. More...
 
void runEventHandlers (const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
 Run a function on the menu and all its submenus. More...
 
void runOnSubmenus (std::function< void(ACTION_MENU *)> aFunction)
 Check if any of submenus contains a TOOL_ACTION with a specific ID. More...
 
OPT_TOOL_EVENT findToolAction (int aId)
 

Protected Attributes

bool m_isForcedPosition
 
wxPoint m_forcedPosition
 
bool m_dirty
 
bool m_titleDisplayed
 
bool m_isContextMenu
 Menu title. More...
 
wxString m_title
 Optional icon. More...
 
BITMAPS m_icon
 Stores the id number of selected item. More...
 
int m_selected
 Creator of the menu. More...
 
TOOL_INTERACTIVEm_tool
 Associates tool actions with menu item IDs. Non-owning. More...
 
std::map< int, const TOOL_ACTION * > m_toolActions
 List of submenus. More...
 
std::list< ACTION_MENU * > m_submenus
 

Friends

class TOOL_INTERACTIVE
 

Detailed Description

Defines the structure of a menu based on ACTIONs.

Definition at line 48 of file action_menu.h.

Constructor & Destructor Documentation

◆ ACTION_MENU() [1/2]

ACTION_MENU::ACTION_MENU ( bool  isContextMenu,
TOOL_INTERACTIVE aTool = nullptr 
)

< Default constructor

Definition at line 47 of file action_menu.cpp.

47  :
48  m_isForcedPosition( false ),
49  m_dirty( true ),
50  m_titleDisplayed( false ),
51  m_isContextMenu( isContextMenu ),
53  m_selected( -1 ),
54  m_tool( aTool )
55 {
56  setupEvents();
57 }
bool m_titleDisplayed
Definition: action_menu.h:247
BITMAPS m_icon
Stores the id number of selected item.
Definition: action_menu.h:254
bool m_isContextMenu
Menu title.
Definition: action_menu.h:248
int m_selected
Creator of the menu.
Definition: action_menu.h:257
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:260
bool m_isForcedPosition
Definition: action_menu.h:242
void setupEvents()
Update hot key settings for TOOL_ACTIONs in this menu.
Definition: action_menu.cpp:79

References INVALID_BITMAP, and setupEvents().

Referenced by create(), and BUS_UNFOLD_MENU::update().

◆ ~ACTION_MENU()

ACTION_MENU::~ACTION_MENU ( )
override

Definition at line 60 of file action_menu.cpp.

61 {
62  // Set parent to NULL to prevent submenus from unregistering from a nonexistent object
63  for( auto menu : m_submenus )
64  menu->SetParent( nullptr );
65 
66  ACTION_MENU* parent = dynamic_cast<ACTION_MENU*>( GetParent() );
67 
68  if( parent )
69  parent->m_submenus.remove( this );
70 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:266

References m_submenus.

◆ ACTION_MENU() [2/2]

ACTION_MENU::ACTION_MENU ( const ACTION_MENU aMenu)
delete

Member Function Documentation

◆ Add() [1/4]

wxMenuItem * ACTION_MENU::Add ( const wxString &  aLabel,
int  aId,
BITMAPS  aIcon 
)

Add a wxWidgets-style entry to the menu.

After highlighting/selecting the entry, a wxWidgets event is generated.

Definition at line 135 of file action_menu.cpp.

136 {
137  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
138 
139  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
140 
141  if( !!aIcon )
142  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
143 
144  return Append( item );
145 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:240
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105

References AddBitmapToMenuItem(), and KiBitmap().

Referenced by AddClose(), AddMenuLanguageList(), AddQuitOrClose(), EDA_3D_VIEWER_FRAME::CreateMenuBar(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), CONDITIONAL_MENU::Evaluate(), GROUP_CONTEXT_MENU::GROUP_CONTEXT_MENU(), ALIGN_DISTRIBUTE_TOOL::Init(), NET_CONTEXT_MENU::NET_CONTEXT_MENU(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SYMBOL_VIEWER_FRAME::ReCreateMenuBar(), SYMBOL_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), CVPCB_MAINFRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), and CVPCB_MAINFRAME::setupTools().

◆ Add() [2/4]

wxMenuItem * ACTION_MENU::Add ( const wxString &  aLabel,
const wxString &  aToolTip,
int  aId,
BITMAPS  aIcon,
bool  aIsCheckmarkEntry = false 
)

Definition at line 148 of file action_menu.cpp.

150 {
151  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
152 
153  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, aTooltip,
154  aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
155 
156  if( !!aIcon )
157  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
158 
159  return Append( item );
160 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:240
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105

References AddBitmapToMenuItem(), and KiBitmap().

◆ Add() [3/4]

wxMenuItem * ACTION_MENU::Add ( const TOOL_ACTION aAction,
bool  aIsCheckmarkEntry = false,
const wxString &  aOverrideLabel = wxEmptyString 
)

Add an entry to the menu based on the TOOL_ACTION object.

After selecting the entry, a TOOL_EVENT command containing name of the action is sent.

Parameters
aActionis the action to be added to menu entry.
aIsCheckmarkEntryis true to indicate a check menu entry, false for normal menu entry
aOverrideLabelis the label to show in the menu (overriding the action's menu text) when non-empty

ID numbers for tool actions are assigned above ACTION_BASE_UI_ID inside TOOL_EVENT

Definition at line 163 of file action_menu.cpp.

165 {
167  BITMAPS icon = aAction.GetIcon();
168 
169  // Allow the label to be overridden at point of use
170  wxString menuLabel = aOverrideLabel.IsEmpty() ? aAction.GetMenuItem() : aOverrideLabel;
171 
172  wxMenuItem* item = new wxMenuItem( this, aAction.GetUIId(), menuLabel,
173  aAction.GetDescription(),
174  aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
175  if( !!icon )
176  AddBitmapToMenuItem( item, KiBitmap( icon ) );
177 
178  m_toolActions[aAction.GetUIId()] = &aAction;
179 
180  return Append( item );
181 }
int GetUIId() const
Definition: tool_action.h:130
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:240
const BITMAPS GetIcon() const
Return an icon associated with the action.
Definition: tool_action.h:179
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
wxString GetDescription(bool aIncludeHotkey=true) const
Definition: tool_action.cpp:97
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:263
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
wxString GetMenuItem() const
Definition: tool_action.cpp:89

References AddBitmapToMenuItem(), TOOL_ACTION::GetDescription(), TOOL_ACTION::GetIcon(), TOOL_ACTION::GetMenuItem(), TOOL_ACTION::GetUIId(), KiBitmap(), and m_toolActions.

◆ Add() [4/4]

wxMenuItem * ACTION_MENU::Add ( ACTION_MENU aMenu)

Add an action menu as a submenu.

The difference between this function and wxMenu::AppendSubMenu() is the capability to handle icons.

Parameters
aMenuis the submenu to be added.

Definition at line 184 of file action_menu.cpp.

185 {
186  ACTION_MENU* menuCopy = aMenu->Clone();
187  m_submenus.push_back( menuCopy );
188 
189  wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), "Set a title for ACTION_MENU using SetTitle()" );
190 
191  if( !!aMenu->m_icon )
192  {
193  wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->m_title );
194  AddBitmapToMenuItem( newItem, KiBitmap( aMenu->m_icon ) );
195  newItem->SetSubMenu( menuCopy );
196  return Append( newItem );
197  }
198  else
199  {
200  return AppendSubMenu( menuCopy, menuCopy->m_title );
201  }
202 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
BITMAPS m_icon
Stores the id number of selected item.
Definition: action_menu.h:254
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:240
wxString m_title
Optional icon.
Definition: action_menu.h:251
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:266
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105

References AddBitmapToMenuItem(), Clone(), KiBitmap(), m_icon, m_submenus, and m_title.

◆ AddClose()

void ACTION_MENU::AddClose ( wxString  aAppname = "")

Add a standard close item to the menu with the accelerator key CTRL-W.

Emits the wxID_CLOSE event.

Parameters
aAppnameis the application name to append to the tooltip.

Definition at line 205 of file action_menu.cpp.

206 {
207 #ifdef __WINDOWS__
208  Add( _( "Close" ),
209  wxString::Format( _( "Close %s" ), aAppname ),
210  wxID_CLOSE,
211  BITMAPS::exit );
212 #else
213  Add( _( "Close" ) + "\tCtrl+W",
214  wxString::Format( _( "Close %s" ), aAppname ),
215  wxID_CLOSE,
216  BITMAPS::exit );
217 #endif
218 }
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.

References _, Add(), exit, and Format().

Referenced by AddQuitOrClose(), EDA_3D_VIEWER_FRAME::CreateMenuBar(), SYMBOL_VIEWER_FRAME::ReCreateMenuBar(), SYMBOL_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), and CVPCB_MAINFRAME::ReCreateMenuBar().

◆ AddQuitOrClose()

void ACTION_MENU::AddQuitOrClose ( KIFACE_I aKiface,
wxString  aAppname = "" 
)

Add either a standard Quit or Close item to the menu.

If aKiface is NULL or in single-instance then quit (wxID_QUIT) is used, otherwise close (wxID_CLOSE) is used.

Parameters
aAppnameis the application name to append to the tooltip.

Definition at line 221 of file action_menu.cpp.

222 {
223  if( !aKiface || aKiface->IsSingle() ) // not when under a project mgr
224  {
225  // Don't use ACTIONS::quit; wxWidgets moves this on OSX and expects to find it via
226  // wxID_EXIT
227  Add( _( "Quit" ) + "\tCtrl+Q",
228  wxString::Format( _( "Quit %s" ), aAppname ),
229  wxID_EXIT,
230  BITMAPS::exit );
231  }
232  else
233  {
234  AddClose( aAppname );
235  }
236 }
bool IsSingle() const
Is this KIFACE_I running under single_top?
Definition: kiface_i.h:104
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
void AddClose(wxString aAppname="")
Add a standard close item to the menu with the accelerator key CTRL-W.

References _, Add(), AddClose(), exit, Format(), and KIFACE_I::IsSingle().

Referenced by KICAD_MANAGER_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), and PCB_EDIT_FRAME::ReCreateMenuBar().

◆ appendCopy()

wxMenuItem * ACTION_MENU::appendCopy ( const wxMenuItem *  aSource)
protected

Append a copy of wxMenuItem.

Initialize handlers for events.

Definition at line 637 of file action_menu.cpp.

638 {
639  wxMenuItem* newItem = new wxMenuItem( this, aSource->GetId(), aSource->GetItemLabel(),
640  aSource->GetHelp(), aSource->GetKind() );
641 
642  // Add the source bitmap if it is not the wxNullBitmap
643  // On Windows, for Checkable Menu items, adding a bitmap adds also
644  // our predefined checked alternate bitmap
645  // On other OS, wxITEM_CHECK and wxITEM_RADIO Menu items do not use custom bitmaps.
646 #if defined( _WIN32 )
647  // On Windows, AddBitmapToMenuItem() uses the unchecked bitmap for wxITEM_CHECK and
648  // wxITEM_RADIO menuitems and autoamtically adds a checked bitmap.
649  // For other menuitrms, use the "checked" bitmap.
650  bool use_checked_bm = ( aSource->GetKind() == wxITEM_CHECK ||
651  aSource->GetKind() == wxITEM_RADIO ) ? false : true;
652  const wxBitmap& src_bitmap = aSource->GetBitmap( use_checked_bm );
653 #else
654  const wxBitmap& src_bitmap = aSource->GetBitmap();
655 #endif
656 
657  if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 ) // a null bitmap has a 0 size
658  AddBitmapToMenuItem( newItem, src_bitmap );
659 
660  if( aSource->IsSubMenu() )
661  {
662  ACTION_MENU* menu = dynamic_cast<ACTION_MENU*>( aSource->GetSubMenu() );
663  wxASSERT_MSG( menu, "Submenus are expected to be a ACTION_MENU" );
664 
665  if( menu )
666  {
667  ACTION_MENU* menuCopy = menu->Clone();
668  newItem->SetSubMenu( menuCopy );
669  m_submenus.push_back( menuCopy );
670  }
671  }
672 
673  // wxMenuItem has to be added before enabling/disabling or checking
674  Append( newItem );
675 
676  if( aSource->IsCheckable() )
677  newItem->Check( aSource->IsChecked() );
678 
679  newItem->Enable( aSource->IsEnabled() );
680 
681  return newItem;
682 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:240
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:266
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.

References AddBitmapToMenuItem(), Clone(), and m_submenus.

Referenced by copyFrom().

◆ Clear()

void ACTION_MENU::Clear ( )

Remove all the entries from the menu (as well as its title).

It leaves the menu in the initial state.

Definition at line 239 of file action_menu.cpp.

240 {
241  m_titleDisplayed = false;
242 
243  for( int i = GetMenuItemCount() - 1; i >= 0; --i )
244  Destroy( FindItemByPosition( i ) );
245 
246  m_toolActions.clear();
247  m_submenus.clear();
248 
249  wxASSERT( GetMenuItemCount() == 0 );
250 }
bool m_titleDisplayed
Definition: action_menu.h:247
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:266
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:263

References m_submenus, m_titleDisplayed, and m_toolActions.

Referenced by Clone(), CONDITIONAL_MENU::Evaluate(), VIA_SIZE_MENU::update(), SYMBOL_UNIT_MENU::update(), BUS_UNFOLD_MENU::update(), TRACK_WIDTH_MENU::update(), and DIFF_PAIR_MENU::update().

◆ ClearDirty()

void ACTION_MENU::ClearDirty ( )

Clear the dirty flag on the menu and all descendants.

Definition at line 289 of file action_menu.cpp.

290 {
291  m_dirty = false;
292  runOnSubmenus( std::bind( &ACTION_MENU::ClearDirty, _1 ) );
293 }
void ClearDirty()
Clear the dirty flag on the menu and all descendants.
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.

References m_dirty, and runOnSubmenus().

Referenced by TOOL_MENU::ShowContextMenu().

◆ Clone()

ACTION_MENU * ACTION_MENU::Clone ( ) const

Create a deep, recursive copy of this ACTION_MENU.

Definition at line 310 of file action_menu.cpp.

311 {
312  ACTION_MENU* clone = create();
313  clone->Clear();
314  clone->copyFrom( *this );
315  return clone;
316 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
virtual ACTION_MENU * create() const
< Return an instance of this class. It has to be overridden in inheriting classes.
void copyFrom(const ACTION_MENU &aMenu)
Copy another menus data to this instance.
void Clear()
Remove all the entries from the menu (as well as its title).

References Clear(), copyFrom(), and create().

Referenced by Add(), appendCopy(), and TOOL_MANAGER::DispatchContextMenu().

◆ copyFrom()

void ACTION_MENU::copyFrom ( const ACTION_MENU aMenu)
protected

Copy another menus data to this instance.

Old entries are preserved and ones form aMenu are copied.

Definition at line 619 of file action_menu.cpp.

620 {
621  m_icon = aMenu.m_icon;
622  m_title = aMenu.m_title;
624  m_selected = -1; // aMenu.m_selected;
625  m_tool = aMenu.m_tool;
627 
628  // Copy all menu entries
629  for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
630  {
631  wxMenuItem* item = aMenu.FindItemByPosition( i );
632  appendCopy( item );
633  }
634 }
bool m_titleDisplayed
Definition: action_menu.h:247
BITMAPS m_icon
Stores the id number of selected item.
Definition: action_menu.h:254
wxString m_title
Optional icon.
Definition: action_menu.h:251
int m_selected
Creator of the menu.
Definition: action_menu.h:257
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:260
wxMenuItem * appendCopy(const wxMenuItem *aSource)
Append a copy of wxMenuItem.
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:263

References appendCopy(), m_icon, m_selected, m_title, m_titleDisplayed, m_tool, and m_toolActions.

Referenced by Clone().

◆ create()

ACTION_MENU * ACTION_MENU::create ( ) const
protectedvirtual

< Return an instance of this class. It has to be overridden in inheriting classes.

Returns an instance of TOOL_MANAGER class.

Reimplemented in DIFF_PAIR_MENU, TRACK_WIDTH_MENU, LOCK_CONTEXT_MENU, HIGHLIGHT_MENU, ZONE_CONTEXT_MENU, BUS_UNFOLD_MENU, SELECT_MENU, SYMBOL_UNIT_MENU, VIA_SIZE_MENU, NET_CONTEXT_MENU, GROUP_CONTEXT_MENU, CONDITIONAL_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 319 of file action_menu.cpp.

320 {
321  ACTION_MENU* menu = new ACTION_MENU( false );
322 
323  wxASSERT_MSG( typeid( *this ) == typeid( *menu ),
324  wxString::Format( "You need to override create() method for class %s",
325  typeid( *this ).name() ) );
326 
327  return menu;
328 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
ACTION_MENU(bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr)
< Default constructor
Definition: action_menu.cpp:47

References ACTION_MENU(), and Format().

Referenced by Clone().

◆ DisplayTitle()

void ACTION_MENU::DisplayTitle ( bool  aDisplay = true)

Decide whether a title for a pop up menu should be displayed.

Definition at line 98 of file action_menu.cpp.

99 {
100  if( ( !aDisplay || m_title.IsEmpty() ) && m_titleDisplayed )
101  {
102  // Destroy the menu entry keeping the title..
103  wxMenuItem* item = FindItemByPosition( 0 );
104  wxASSERT( item->GetItemLabelText() == GetTitle() );
105  Destroy( item );
106  // ..and separator
107  item = FindItemByPosition( 0 );
108  wxASSERT( item->IsSeparator() );
109  Destroy( item );
110  m_titleDisplayed = false;
111  }
112 
113  else if( aDisplay && !m_title.IsEmpty() )
114  {
115  if( m_titleDisplayed )
116  {
117  // Simply update the title
118  FindItemByPosition( 0 )->SetItemLabel( m_title );
119  }
120  else
121  {
122  // Add a separator and a menu entry to display the title
123  InsertSeparator( 0 );
124  Insert( 0, new wxMenuItem( this, wxID_NONE, m_title, wxEmptyString, wxITEM_NORMAL ) );
125 
126  if( !!m_icon )
127  AddBitmapToMenuItem( FindItemByPosition( 0 ), KiBitmap( m_icon ) );
128 
129  m_titleDisplayed = true;
130  }
131  }
132 }
bool m_titleDisplayed
Definition: action_menu.h:247
BITMAPS m_icon
Stores the id number of selected item.
Definition: action_menu.h:254
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:240
wxString m_title
Optional icon.
Definition: action_menu.h:251
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105

References AddBitmapToMenuItem(), KiBitmap(), m_icon, m_title, and m_titleDisplayed.

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), and SetTitle().

◆ eventHandler()

virtual OPT_TOOL_EVENT ACTION_MENU::eventHandler ( const wxMenuEvent &  )
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, VIA_SIZE_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 208 of file action_menu.h.

209  {
210  return OPT_TOOL_EVENT();
211  }
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:543

Referenced by OnMenuEvent(), and runEventHandlers().

◆ findToolAction()

OPT_TOOL_EVENT ACTION_MENU::findToolAction ( int  aId)
protected

Definition at line 596 of file action_menu.cpp.

597 {
598  OPT_TOOL_EVENT evt;
599 
600  auto findFunc = [&]( ACTION_MENU* m ) {
601  if( evt )
602  return;
603 
604  const auto it = m->m_toolActions.find( aId );
605 
606  if( it != m->m_toolActions.end() )
607  evt = it->second->MakeEvent();
608  };
609 
610  findFunc( this );
611 
612  if( !evt )
613  runOnSubmenus( findFunc );
614 
615  return evt;
616 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:543

References runOnSubmenus().

Referenced by OnMenuEvent().

◆ GetSelected()

int ACTION_MENU::GetSelected ( ) const
inline

Return the position of selected item.

If the returned value is negative, that means that menu was dismissed.

Returns
The position of selected item in the action menu.

Definition at line 149 of file action_menu.h.

150  {
151  return m_selected;
152  }
int m_selected
Creator of the menu.
Definition: action_menu.h:257

References m_selected.

◆ getToolManager()

TOOL_MANAGER * ACTION_MENU::getToolManager ( ) const
protected

Definition at line 331 of file action_menu.cpp.

332 {
333  wxASSERT( m_tool );
334  return m_tool ? m_tool->GetManager() : nullptr;
335 }
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:260

References TOOL_BASE::GetManager(), and m_tool.

Referenced by VIA_SIZE_MENU::eventHandler(), OnMenuEvent(), GROUP_CONTEXT_MENU::update(), VIA_SIZE_MENU::update(), SYMBOL_UNIT_MENU::update(), BUS_UNFOLD_MENU::update(), and updateHotKeys().

◆ HasEnabledItems()

bool ACTION_MENU::HasEnabledItems ( ) const

Returns true if the menu has any enabled items.

Definition at line 253 of file action_menu.cpp.

254 {
255  bool hasEnabled = false;
256 
257  auto& items = GetMenuItems();
258 
259  for( auto item : items )
260  {
261  if( item->IsEnabled() && !item->IsSeparator() )
262  {
263  hasEnabled = true;
264  break;
265  }
266  }
267 
268  return hasEnabled;
269 }

◆ OnIdle()

void ACTION_MENU::OnIdle ( wxIdleEvent &  event)

Definition at line 387 of file action_menu.cpp.

388 {
390  g_menu_open_position.x = 0.0;
391  g_menu_open_position.y = 0.0;
392 }
static int g_last_menu_highlighted_id
static VECTOR2D g_menu_open_position

References g_last_menu_highlighted_id, g_menu_open_position, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by setupEvents().

◆ OnMenuEvent()

void ACTION_MENU::OnMenuEvent ( wxMenuEvent &  aEvent)

Definition at line 395 of file action_menu.cpp.

396 {
397  OPT_TOOL_EVENT evt;
398  wxString menuText;
399  wxEventType type = aEvent.GetEventType();
400  wxWindow* focus = wxWindow::FindFocus();
401 
402  if( type == wxEVT_MENU_OPEN )
403  {
404  if( m_dirty && m_tool )
405  getToolManager()->RunAction( ACTIONS::updateMenu, true, this );
406 
407  wxMenu* parent = dynamic_cast<wxMenu*>( GetParent() );
408 
409  // Don't update the position if this menu has a parent
410  if( !parent && m_tool )
412 
414  }
415  else if( type == wxEVT_MENU_HIGHLIGHT )
416  {
417  if( aEvent.GetId() > 0 )
418  g_last_menu_highlighted_id = aEvent.GetId();
419 
420  evt = TOOL_EVENT( TC_COMMAND, TA_CHOICE_MENU_UPDATE, aEvent.GetId() );
421  }
422  else if( type == wxEVT_COMMAND_MENU_SELECTED )
423  {
424  // Despite our attempts to catch the theft of text editor CHAR_HOOK and CHAR events
425  // in TOOL_DISPATCHER::DispatchWxEvent, wxWidgets sometimes converts those it knows
426  // about into menu commands without ever generating the appropriate CHAR_HOOK and CHAR
427  // events first.
428  if( dynamic_cast<wxTextEntry*>( focus )
429  || dynamic_cast<wxStyledTextCtrl*>( focus )
430  || dynamic_cast<wxListView*>( focus ) )
431  {
432  // Original key event has been lost, so we have to re-create it from the menu's
433  // wxAcceleratorEntry.
434  wxMenuItem* menuItem = FindItem( aEvent.GetId() );
435  wxAcceleratorEntry* acceleratorKey = menuItem ? menuItem->GetAccel() : nullptr;
436 
437  if( acceleratorKey )
438  {
439  wxKeyEvent keyEvent( wxEVT_CHAR_HOOK );
440  keyEvent.m_keyCode = acceleratorKey->GetKeyCode();
441  keyEvent.m_controlDown = ( acceleratorKey->GetFlags() & wxMOD_CONTROL ) > 0;
442  keyEvent.m_shiftDown = ( acceleratorKey->GetFlags() & wxMOD_SHIFT ) > 0;
443  keyEvent.m_altDown = ( acceleratorKey->GetFlags() & wxMOD_ALT ) > 0;
444 
445  if( auto ctrl = dynamic_cast<wxTextEntry*>( focus ) )
446  TEXTENTRY_TRICKS::OnCharHook( ctrl, keyEvent );
447  else
448  focus->HandleWindowEvent( keyEvent );
449 
450  if( keyEvent.GetSkipped() )
451  {
452  keyEvent.SetEventType( wxEVT_CHAR );
453  focus->HandleWindowEvent( keyEvent );
454  }
455 
456  // If the event was used as KEY event (not skipped) by the focused window,
457  // just finish.
458  // Otherwise this is actually a wxEVT_COMMAND_MENU_SELECTED, or the
459  // focused window is read only
460  if( !keyEvent.GetSkipped() )
461  return;
462  }
463  }
464 
465  // Store the selected position, so it can be checked by the tools
466  m_selected = aEvent.GetId();
467 
468  ACTION_MENU* parent = dynamic_cast<ACTION_MENU*>( GetParent() );
469 
470  while( parent )
471  {
472  parent->m_selected = m_selected;
473  parent = dynamic_cast<ACTION_MENU*>( parent->GetParent() );
474  }
475 
476  // Check if there is a TOOL_ACTION for the given ID
478  evt = findToolAction( m_selected );
479 
480  if( !evt )
481  {
482 #ifdef __WINDOWS__
483  if( !evt )
484  {
485  // Try to find the submenu which holds the selected item
486  wxMenu* menu = nullptr;
487  FindItem( m_selected, &menu );
488 
489  // This conditional compilation is probably not needed.
490  // It will be removed later, for the Kicad V 6.x version.
491  // But in "old" 3.0 version, the "&& menu != this" contition was added to avoid
492  // hang. This hang is no longer encountered in wxWidgets 3.0.4 version, and this
493  // condition is no longer needed. And in 3.1.2, we have to remove it, as
494  // "menu != this" never happens ("menu != this" always happens in 3.1.1 and older!).
495 #if wxCHECK_VERSION( 3, 1, 2 )
496  if( menu )
497 #else
498  if( menu && menu != this )
499 #endif
500  {
501  ACTION_MENU* cxmenu = static_cast<ACTION_MENU*>( menu );
502  evt = cxmenu->eventHandler( aEvent );
503  }
504  }
505 #else
506  if( !evt )
507  runEventHandlers( aEvent, evt );
508 #endif
509 
510  // Handling non-ACTION menu entries. Two ranges of ids are supported:
511  // between 0 and ID_CONTEXT_MENU_ID_MAX
512  // between ID_POPUP_MENU_START and ID_POPUP_MENU_END
513 
514  #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST /* = 100 should be plenty */
515 
516  if( !evt &&
517  ( ( m_selected >= 0 && m_selected < ID_CONTEXT_MENU_ID_MAX ) ||
519  {
520  ACTION_MENU* actionMenu = dynamic_cast<ACTION_MENU*>( GetParent() );
521 
522  if( actionMenu && actionMenu->PassHelpTextToHandler() )
523  menuText = GetHelpString( aEvent.GetId() );
524  else
525  menuText = GetLabelText( aEvent.GetId() );
526 
528  &menuText );
529  }
530  }
531  }
532 
533  // forward the action/update event to the TOOL_MANAGER
534  // clients that don't supply a tool will have to check GetSelected() themselves
535  if( evt && m_tool )
536  {
537  wxLogTrace( kicadTraceToolStack, "ACTION_MENU::OnMenuEvent %s", evt->Format() );
538 
539  // WARNING: if you're squeamish, look away.
540  // What follows is a series of egregious hacks necessitated by a lack of information from
541  // wxWidgets on where context-menu-commands and command-key-events originated.
542 
543  // If it's a context menu then fetch the mouse position from our context-menu-position
544  // hack.
545  if( m_isContextMenu )
546  {
547  evt->SetMousePosition( g_menu_open_position );
548  }
549  // Otherwise, if g_last_menu_highlighted_id matches then it's a menubar menu event and has
550  // no position.
551  else if( g_last_menu_highlighted_id == aEvent.GetId() )
552  {
553  evt->SetHasPosition( false );
554  }
555  // Otherwise it's a command-key-event and we need to get the mouse position from the tool
556  // manager so that immediate actions work.
557  else
558  {
559  evt->SetMousePosition( getToolManager()->GetMousePosition() );
560  }
561 
562  if( m_tool->GetManager() )
563  m_tool->GetManager()->ProcessEvent( *evt );
564  }
565  else
566  {
567  aEvent.Skip();
568  }
569 }
OPT_TOOL_EVENT findToolAction(int aId)
static int g_last_menu_highlighted_id
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
VECTOR2D GetMousePosition() const
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
void runEventHandlers(const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
Run a function on the menu and all its submenus.
static int GetBaseUIId()
Definition: tool_action.h:135
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
virtual OPT_TOOL_EVENT eventHandler(const wxMenuEvent &)
Event handler stub.
Definition: action_menu.h:208
virtual bool PassHelpTextToHandler()
Definition: action_menu.h:180
#define ID_CONTEXT_MENU_ID_MAX
bool m_isContextMenu
Menu title.
Definition: action_menu.h:248
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
Generic, UI-independent tool event.
Definition: tool_event.h:152
static VECTOR2D g_menu_open_position
int m_selected
Creator of the menu.
Definition: action_menu.h:257
static TOOL_ACTION updateMenu
Definition: actions.h:167
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:260
Global action (toolbar/main menu event, global shortcut)
static void OnCharHook(wxTextEntry *aTextEntry, wxKeyEvent &aEvent)
TOOL_MANAGER * getToolManager() const
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:543

References AS_GLOBAL, eventHandler(), findToolAction(), g_last_menu_highlighted_id, g_menu_open_position, TOOL_ACTION::GetBaseUIId(), 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, TEXTENTRY_TRICKS::OnCharHook(), PassHelpTextToHandler(), TOOL_MANAGER::ProcessEvent(), TOOL_MANAGER::RunAction(), runEventHandlers(), TA_CHOICE_MENU_CHOICE, TA_CHOICE_MENU_UPDATE, TC_COMMAND, and ACTIONS::updateMenu.

Referenced by TOOL_DISPATCHER::DispatchWxEvent(), and setupEvents().

◆ operator=()

ACTION_MENU& ACTION_MENU::operator= ( const ACTION_MENU aMenu)
delete

◆ PassHelpTextToHandler()

virtual bool ACTION_MENU::PassHelpTextToHandler ( )
inlinevirtual

Reimplemented in BUS_UNFOLD_MENU.

Definition at line 180 of file action_menu.h.

180 { return false; }

Referenced by OnMenuEvent().

◆ runEventHandlers()

void ACTION_MENU::runEventHandlers ( const wxMenuEvent &  aMenuEvent,
OPT_TOOL_EVENT aToolEvent 
)
protected

Run a function on the menu and all its submenus.

Definition at line 572 of file action_menu.cpp.

573 {
574  aToolEvent = eventHandler( aMenuEvent );
575 
576  if( !aToolEvent )
577  runOnSubmenus( std::bind( &ACTION_MENU::runEventHandlers, _1, aMenuEvent, aToolEvent ) );
578 }
void runEventHandlers(const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
Run a function on the menu and all its submenus.
virtual OPT_TOOL_EVENT eventHandler(const wxMenuEvent &)
Event handler stub.
Definition: action_menu.h:208
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.

References eventHandler(), and runOnSubmenus().

Referenced by OnMenuEvent().

◆ runOnSubmenus()

void ACTION_MENU::runOnSubmenus ( std::function< void(ACTION_MENU *)>  aFunction)
protected

Check if any of submenus contains a TOOL_ACTION with a specific ID.

Definition at line 581 of file action_menu.cpp.

582 {
583  try
584  {
585  std::for_each( m_submenus.begin(), m_submenus.end(), [&]( ACTION_MENU* m ) {
586  aFunction( m );
587  m->runOnSubmenus( aFunction );
588  } );
589  }
590  catch( std::exception& )
591  {
592  }
593 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:266

References m_submenus.

Referenced by ClearDirty(), CONDITIONAL_MENU::Evaluate(), findToolAction(), CONDITIONAL_MENU::Resolve(), runEventHandlers(), SetDirty(), SetTool(), and UpdateAll().

◆ SetDirty()

void ACTION_MENU::SetDirty ( )

Definition at line 296 of file action_menu.cpp.

297 {
298  m_dirty = true;
299  runOnSubmenus( std::bind( &ACTION_MENU::SetDirty, _1 ) );
300 }
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.
void SetDirty()

References m_dirty, and runOnSubmenus().

Referenced by TOOL_MENU::ShowContextMenu().

◆ SetIcon()

◆ SetTitle()

void ACTION_MENU::SetTitle ( const wxString &  aTitle)
override

Set title for the menu.

The title is shown as a text label shown on the top of the menu.

Parameters
aTitleis the new title.

Definition at line 87 of file action_menu.cpp.

88 {
89  // Unfortunately wxMenu::SetTitle() does not work very well, so this is an alternative version
90  m_title = aTitle;
91 
92  // Update the menu title
93  if( m_titleDisplayed )
94  DisplayTitle( true );
95 }
bool m_titleDisplayed
Definition: action_menu.h:247
wxString m_title
Optional icon.
Definition: action_menu.h:251
void DisplayTitle(bool aDisplay=true)
Decide whether a title for a pop up menu should be displayed.
Definition: action_menu.cpp:98

References DisplayTitle(), m_title, and m_titleDisplayed.

Referenced by AddMenuLanguageList(), BUS_UNFOLD_MENU::BUS_UNFOLD_MENU(), EDA_3D_VIEWER_FRAME::CreateMenuBar(), DIFF_PAIR_MENU::DIFF_PAIR_MENU(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_SELECTION_TOOL::doSelectionMenu(), GRID_MENU::GRID_MENU(), GROUP_CONTEXT_MENU::GROUP_CONTEXT_MENU(), ROUTER_TOOL::Init(), LENGTH_TUNER_TOOL::Init(), CONVERT_TOOL::Init(), ALIGN_DISTRIBUTE_TOOL::Init(), NET_CONTEXT_MENU::NET_CONTEXT_MENU(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SYMBOL_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), SPECIAL_TOOLS_CONTEXT_MENU::SPECIAL_TOOLS_CONTEXT_MENU(), SYMBOL_UNIT_MENU::SYMBOL_UNIT_MENU(), TRACK_WIDTH_MENU::TRACK_WIDTH_MENU(), VIA_SIZE_MENU::VIA_SIZE_MENU(), and ZOOM_MENU::ZOOM_MENU().

◆ SetTool()

void ACTION_MENU::SetTool ( TOOL_INTERACTIVE aTool)

Set a tool that is the creator of the menu.

Parameters
aToolis the tool that created the menu.

Definition at line 303 of file action_menu.cpp.

304 {
305  m_tool = aTool;
306  runOnSubmenus( std::bind( &ACTION_MENU::SetTool, _1, aTool ) );
307 }
void SetTool(TOOL_INTERACTIVE *aTool)
Set a tool that is the creator of the menu.
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:260
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.

References m_tool, and runOnSubmenus().

Referenced by TOOL_INTERACTIVE::SetContextMenu(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ setupEvents()

void ACTION_MENU::setupEvents ( )
protected

Update hot key settings for TOOL_ACTIONs in this menu.

Definition at line 79 of file action_menu.cpp.

80 {
81  Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), nullptr,
82  this );
83  Connect( wxEVT_IDLE, wxIdleEventHandler( ACTION_MENU::OnIdle ), nullptr, this );
84 }
void OnMenuEvent(wxMenuEvent &aEvent)
void OnIdle(wxIdleEvent &event)

References OnIdle(), and OnMenuEvent().

Referenced by ACTION_MENU().

◆ update()

virtual void ACTION_MENU::update ( )
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, BUS_UNFOLD_MENU, SYMBOL_UNIT_MENU, VIA_SIZE_MENU, GROUP_CONTEXT_MENU, HIGHLIGHT_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 198 of file action_menu.h.

199  {
200  }

Referenced by UpdateAll().

◆ UpdateAll()

void ACTION_MENU::UpdateAll ( )

Run update handlers for the menu and its submenus.

Definition at line 272 of file action_menu.cpp.

273 {
274  try
275  {
276  update();
277  }
278  catch( std::exception& )
279  {
280  }
281 
282  if( m_tool )
283  updateHotKeys();
284 
285  runOnSubmenus( std::bind( &ACTION_MENU::UpdateAll, _1 ) );
286 }
virtual void update()
Update menu state stub.
Definition: action_menu.h:198
void UpdateAll()
Run update handlers for the menu and its submenus.
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:260
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.
void updateHotKeys()
Traverse the submenus tree looking for a submenu capable of handling a particular menu event.

References m_tool, runOnSubmenus(), update(), and updateHotKeys().

Referenced by ACTION_TOOLBAR::onToolRightClick(), CONDITIONAL_MENU::Resolve(), TOOL_MENU::ShowContextMenu(), KICAD_MANAGER_CONTROL::UpdateMenu(), PL_SELECTION_TOOL::UpdateMenu(), EDA_3D_CONTROLLER::UpdateMenu(), GERBVIEW_SELECTION_TOOL::UpdateMenu(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::UpdateMenu(), EE_SELECTION_TOOL::UpdateMenu(), CVPCB_CONTROL::UpdateMenu(), and PCB_SELECTION_TOOL::UpdateMenu().

◆ updateHotKeys()

void ACTION_MENU::updateHotKeys ( )
protected

Traverse 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 338 of file action_menu.cpp.

339 {
340  TOOL_MANAGER* toolMgr = getToolManager();
341 
342  for( auto& ii : m_toolActions )
343  {
344  int id = ii.first;
345  const TOOL_ACTION& action = *ii.second;
346  int key = toolMgr->GetHotKey( action ) & ~MD_MODIFIER_MASK;
347 
348  if( key )
349  {
350  int mod = toolMgr->GetHotKey( action ) & MD_MODIFIER_MASK;
351  int flags = 0;
352  wxMenuItem* item = FindChildItem( id );
353 
354  if( item )
355  {
356  flags |= ( mod & MD_ALT ) ? wxACCEL_ALT : 0;
357  flags |= ( mod & MD_CTRL ) ? wxACCEL_CTRL : 0;
358  flags |= ( mod & MD_SHIFT ) ? wxACCEL_SHIFT : 0;
359 
360  if( !flags )
361  flags = wxACCEL_NORMAL;
362 
363  wxAcceleratorEntry accel( flags, key, id, item );
364  item->SetAccel( &accel );
365  }
366  }
367  }
368 }
Master controller class:
Definition: tool_manager.h:54
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:263
TOOL_MANAGER * getToolManager() const
Represent a single user action.
Definition: tool_action.h:67
int GetHotKey(const TOOL_ACTION &aAction) const

References TOOL_MANAGER::GetHotKey(), getToolManager(), m_toolActions, MD_ALT, MD_CTRL, MD_MODIFIER_MASK, and MD_SHIFT.

Referenced by UpdateAll().

Friends And Related Function Documentation

◆ TOOL_INTERACTIVE

friend class TOOL_INTERACTIVE
friend

Definition at line 268 of file action_menu.h.

Member Data Documentation

◆ CHECK

◆ m_dirty

bool ACTION_MENU::m_dirty
protected

Definition at line 245 of file action_menu.h.

Referenced by ClearDirty(), OnMenuEvent(), and SetDirty().

◆ m_forcedPosition

wxPoint ACTION_MENU::m_forcedPosition
protected

Definition at line 243 of file action_menu.h.

◆ m_icon

BITMAPS ACTION_MENU::m_icon
protected

Stores the id number of selected item.

Definition at line 254 of file action_menu.h.

Referenced by Add(), copyFrom(), DisplayTitle(), and SetIcon().

◆ m_isContextMenu

bool ACTION_MENU::m_isContextMenu
protected

Menu title.

Definition at line 248 of file action_menu.h.

Referenced by OnMenuEvent().

◆ m_isForcedPosition

bool ACTION_MENU::m_isForcedPosition
protected

Definition at line 242 of file action_menu.h.

◆ m_selected

int ACTION_MENU::m_selected
protected

Creator of the menu.

Definition at line 257 of file action_menu.h.

Referenced by copyFrom(), GetSelected(), and OnMenuEvent().

◆ m_submenus

std::list<ACTION_MENU*> ACTION_MENU::m_submenus
protected

Definition at line 266 of file action_menu.h.

Referenced by Add(), appendCopy(), Clear(), runOnSubmenus(), and ~ACTION_MENU().

◆ m_title

wxString ACTION_MENU::m_title
protected

Optional icon.

Definition at line 251 of file action_menu.h.

Referenced by Add(), copyFrom(), DisplayTitle(), and SetTitle().

◆ m_titleDisplayed

bool ACTION_MENU::m_titleDisplayed
protected

Definition at line 247 of file action_menu.h.

Referenced by Clear(), copyFrom(), DisplayTitle(), and SetTitle().

◆ m_tool

TOOL_INTERACTIVE* ACTION_MENU::m_tool
protected

Associates tool actions with menu item IDs. Non-owning.

Definition at line 260 of file action_menu.h.

Referenced by copyFrom(), CONDITIONAL_MENU::create(), getToolManager(), OnMenuEvent(), SetTool(), BUS_UNFOLD_MENU::update(), and UpdateAll().

◆ m_toolActions

std::map<int, const TOOL_ACTION*> ACTION_MENU::m_toolActions
protected

List of submenus.

Definition at line 263 of file action_menu.h.

Referenced by Add(), Clear(), copyFrom(), and updateHotKeys().

◆ NORMAL

constexpr bool ACTION_MENU::NORMAL = false
static

The documentation for this class was generated from the following files: