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 (const BITMAP_OPAQUE *aIcon)
 Assign an icon for the entry. More...
 
wxMenuItem * Add (const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
 Add a wxWidgets-style entry to the menu. More...
 
wxMenuItem * Add (const wxString &aLabel, const wxString &aToolTip, int aId, const BITMAP_OPAQUE *aIcon, bool aIsCheckmarkEntry=false)
 
wxMenuItem * Add (const TOOL_ACTION &aAction, bool aIsCheckmarkEntry=false)
 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 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...
 
const BITMAP_OPAQUEm_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 45 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 46 of file action_menu.cpp.

46  :
47  m_dirty( true ),
48  m_titleDisplayed( false ),
49  m_isContextMenu( isContextMenu ),
50  m_icon( nullptr ),
51  m_selected( -1 ),
52  m_tool( aTool )
53 {
54  setupEvents();
55 }
bool m_titleDisplayed
Definition: action_menu.h:239
const BITMAP_OPAQUE * m_icon
Stores the id number of selected item.
Definition: action_menu.h:246
bool m_isContextMenu
Menu title.
Definition: action_menu.h:240
int m_selected
Creator of the menu.
Definition: action_menu.h:249
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:252
void setupEvents()
Update hot key settings for TOOL_ACTIONs in this menu.
Definition: action_menu.cpp:77

References setupEvents().

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

◆ ~ACTION_MENU()

ACTION_MENU::~ACTION_MENU ( )
override

Definition at line 58 of file action_menu.cpp.

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

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,
const BITMAP_OPAQUE aIcon 
)

Add a wxWidgets-style entry to the menu.

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

Definition at line 137 of file action_menu.cpp.

138 {
139  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
140 
141  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
142 
143  if( aIcon )
144  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
145 
146  return Append( item );
147 }
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:207

References AddBitmapToMenuItem(), and KiBitmap().

Referenced by AddClose(), AddMenuLanguageList(), AddQuitOrClose(), EDA_3D_VIEWER::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,
const BITMAP_OPAQUE aIcon,
bool  aIsCheckmarkEntry = false 
)

Definition at line 150 of file action_menu.cpp.

152 {
153  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
154 
155  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, aTooltip,
156  aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
157 
158  if( aIcon )
159  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
160 
161  return Append( item );
162 }
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:207

References AddBitmapToMenuItem(), and KiBitmap().

◆ Add() [3/4]

wxMenuItem * ACTION_MENU::Add ( const TOOL_ACTION aAction,
bool  aIsCheckmarkEntry = false 
)

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.

ID numbers for tool actions are assigned above ACTION_BASE_UI_ID inside TOOL_EVENT

Definition at line 165 of file action_menu.cpp.

166 {
168  const BITMAP_OPAQUE* icon = aAction.GetIcon();
169 
170  wxMenuItem* item = new wxMenuItem( this, aAction.GetUIId(), aAction.GetMenuItem(),
171  aAction.GetDescription(),
172  aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
173  if( icon )
174  AddBitmapToMenuItem( item, KiBitmap( icon ) );
175 
176  m_toolActions[aAction.GetUIId()] = &aAction;
177 
178  return Append( item );
179 }
PNG memory record (file in memory).
Definition: bitmap_def.h:29
int GetUIId() const
Definition: tool_action.h:112
const BITMAP_OPAQUE * GetIcon() const
Return an icon associated with the action.
Definition: tool_action.h:169
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:207
wxString GetDescription(bool aIncludeHotkey=true) const
Definition: tool_action.cpp:83
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:255
wxString GetMenuItem() const
Definition: tool_action.cpp:75

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

183 {
184  ACTION_MENU* menuCopy = aMenu->Clone();
185  m_submenus.push_back( menuCopy );
186 
187  wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), "Set a title for ACTION_MENU using SetTitle()" );
188 
189  if( aMenu->m_icon )
190  {
191  wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->m_title );
192  AddBitmapToMenuItem( newItem, KiBitmap( aMenu->m_icon ) );
193  newItem->SetSubMenu( menuCopy );
194  return Append( newItem );
195  }
196  else
197  {
198  return AppendSubMenu( menuCopy, menuCopy->m_title );
199  }
200 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:45
const BITMAP_OPAQUE * m_icon
Stores the id number of selected item.
Definition: action_menu.h:246
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:207
wxString m_title
Optional icon.
Definition: action_menu.h:243
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:258
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.

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

204 {
205  Add( _( "Close" ) + "\tCtrl+W",
206  wxString::Format( _( "Close %s" ), aAppname ),
207  wxID_CLOSE,
208  exit_xpm );
209 }
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Add a wxWidgets-style entry to the menu.
const BITMAP_OPAQUE exit_xpm[1]
Definition: exit.cpp:50
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
#define _(s)
Definition: 3d_actions.cpp:33

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

Referenced by AddQuitOrClose(), EDA_3D_VIEWER::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 212 of file action_menu.cpp.

213 {
214  if( !aKiface || aKiface->IsSingle() ) // not when under a project mgr
215  {
216  // Don't use ACTIONS::quit; wxWidgets moves this on OSX and expects to find it via
217  // wxID_EXIT
218  Add( _( "Quit" ),
219  wxString::Format( _( "Quit %s" ), aAppname ),
220  wxID_EXIT,
221  exit_xpm );
222  }
223  else
224  {
225  AddClose( aAppname );
226  }
227 }
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Add a wxWidgets-style entry to the menu.
bool IsSingle() const
Is this KIFACE_I running under single_top?
Definition: kiface_i.h:104
const BITMAP_OPAQUE exit_xpm[1]
Definition: exit.cpp:50
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
#define _(s)
Definition: 3d_actions.cpp:33
void AddClose(wxString aAppname="")
Add a standard close item to the menu with the accelerator key CTRL-W.

References _, Add(), AddClose(), exit_xpm, 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 626 of file action_menu.cpp.

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

231 {
232  m_titleDisplayed = false;
233 
234  for( int i = GetMenuItemCount() - 1; i >= 0; --i )
235  Destroy( FindItemByPosition( i ) );
236 
237  m_toolActions.clear();
238  m_submenus.clear();
239 
240  wxASSERT( GetMenuItemCount() == 0 );
241 }
bool m_titleDisplayed
Definition: action_menu.h:239
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:258
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:255

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

281 {
282  m_dirty = false;
283  runOnSubmenus( std::bind( &ACTION_MENU::ClearDirty, _1 ) );
284 }
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 301 of file action_menu.cpp.

302 {
303  ACTION_MENU* clone = create();
304  clone->Clear();
305  clone->copyFrom( *this );
306  return clone;
307 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:45
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 608 of file action_menu.cpp.

609 {
610  m_icon = aMenu.m_icon;
611  m_title = aMenu.m_title;
613  m_selected = -1; // aMenu.m_selected;
614  m_tool = aMenu.m_tool;
616 
617  // Copy all menu entries
618  for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
619  {
620  wxMenuItem* item = aMenu.FindItemByPosition( i );
621  appendCopy( item );
622  }
623 }
bool m_titleDisplayed
Definition: action_menu.h:239
const BITMAP_OPAQUE * m_icon
Stores the id number of selected item.
Definition: action_menu.h:246
wxString m_title
Optional icon.
Definition: action_menu.h:243
int m_selected
Creator of the menu.
Definition: action_menu.h:249
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:252
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:255

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, NET_CONTEXT_MENU, VIA_SIZE_MENU, GROUP_CONTEXT_MENU, CONDITIONAL_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 310 of file action_menu.cpp.

311 {
312  ACTION_MENU* menu = new ACTION_MENU( false );
313 
314  wxASSERT_MSG( typeid( *this ) == typeid( *menu ),
315  wxString::Format( "You need to override create() method for class %s", typeid(*this).name() ) );
316 
317  return menu;
318 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:45
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:46

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

101 {
102  if( ( !aDisplay || m_title.IsEmpty() ) && m_titleDisplayed )
103  {
104  // Destroy the menu entry keeping the title..
105  wxMenuItem* item = FindItemByPosition( 0 );
106  wxASSERT( item->GetItemLabelText() == GetTitle() );
107  Destroy( item );
108  // ..and separator
109  item = FindItemByPosition( 0 );
110  wxASSERT( item->IsSeparator() );
111  Destroy( item );
112  m_titleDisplayed = false;
113  }
114 
115  else if( aDisplay && !m_title.IsEmpty() )
116  {
117  if( m_titleDisplayed )
118  {
119  // Simply update the title
120  FindItemByPosition( 0 )->SetItemLabel( m_title );
121  }
122  else
123  {
124  // Add a separator and a menu entry to display the title
125  InsertSeparator( 0 );
126  Insert( 0, new wxMenuItem( this, wxID_NONE, m_title, wxEmptyString, wxITEM_NORMAL ) );
127 
128  if( m_icon )
129  AddBitmapToMenuItem( FindItemByPosition( 0 ), KiBitmap( m_icon ) );
130 
131  m_titleDisplayed = true;
132  }
133  }
134 }
bool m_titleDisplayed
Definition: action_menu.h:239
const BITMAP_OPAQUE * m_icon
Stores the id number of selected item.
Definition: action_menu.h:246
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:207
wxString m_title
Optional icon.
Definition: action_menu.h:243

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 200 of file action_menu.h.

201  {
202  return OPT_TOOL_EVENT();
203  }
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:569

Referenced by OnMenuEvent(), and runEventHandlers().

◆ findToolAction()

OPT_TOOL_EVENT ACTION_MENU::findToolAction ( int  aId)
protected

Definition at line 585 of file action_menu.cpp.

586 {
587  OPT_TOOL_EVENT evt;
588 
589  auto findFunc = [&]( ACTION_MENU* m ) {
590  if( evt )
591  return;
592 
593  const auto it = m->m_toolActions.find( aId );
594 
595  if( it != m->m_toolActions.end() )
596  evt = it->second->MakeEvent();
597  };
598 
599  findFunc( this );
600 
601  if( !evt )
602  runOnSubmenus( findFunc );
603 
604  return evt;
605 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:45
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:569

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 142 of file action_menu.h.

143  {
144  return m_selected;
145  }
int m_selected
Creator of the menu.
Definition: action_menu.h:249

References m_selected.

◆ getToolManager()

TOOL_MANAGER * ACTION_MENU::getToolManager ( ) const
protected

Definition at line 321 of file action_menu.cpp.

322 {
323  wxASSERT( m_tool );
324  return m_tool ? m_tool->GetManager() : nullptr;
325 }
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:144
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:252

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

245 {
246  bool hasEnabled = false;
247 
248  auto& items = GetMenuItems();
249 
250  for( auto item : items )
251  {
252  if( item->IsEnabled() && !item->IsSeparator() )
253  {
254  hasEnabled = true;
255  break;
256  }
257  }
258 
259  return hasEnabled;
260 }

◆ OnIdle()

void ACTION_MENU::OnIdle ( wxIdleEvent &  event)

Definition at line 376 of file action_menu.cpp.

377 {
379  g_menu_open_position.x = 0.0;
380  g_menu_open_position.y = 0.0;
381 }
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 384 of file action_menu.cpp.

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

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 173 of file action_menu.h.

173 { 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 561 of file action_menu.cpp.

562 {
563  aToolEvent = eventHandler( aMenuEvent );
564 
565  if( !aToolEvent )
566  runOnSubmenus( std::bind( &ACTION_MENU::runEventHandlers, _1, aMenuEvent, aToolEvent ) );
567 }
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:200
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 570 of file action_menu.cpp.

571 {
572  try
573  {
574  std::for_each( m_submenus.begin(), m_submenus.end(), [&]( ACTION_MENU* m ) {
575  aFunction( m );
576  m->runOnSubmenus( aFunction );
577  } );
578  }
579  catch( std::exception& )
580  {
581  }
582 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:45
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:258

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

288 {
289  m_dirty = true;
290  runOnSubmenus( std::bind( &ACTION_MENU::SetDirty, _1 ) );
291 }
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 89 of file action_menu.cpp.

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

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(), 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 294 of file action_menu.cpp.

295 {
296  m_tool = aTool;
297  runOnSubmenus( std::bind( &ACTION_MENU::SetTool, _1, aTool ) );
298 }
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:252
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 ALIGN_DISTRIBUTE_TOOL::Init(), GERBVIEW_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), SYMBOL_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), TOOL_INTERACTIVE::SetContextMenu(), CVPCB_MAINFRAME::setupTools(), SCH_LINE_WIRE_BUS_TOOL::UnfoldBus(), and BUS_UNFOLD_MENU::update().

◆ setupEvents()

void ACTION_MENU::setupEvents ( )
protected

Update hot key settings for TOOL_ACTIONs in this menu.

Definition at line 77 of file action_menu.cpp.

78 {
79 // See wxWidgets hack in TOOL_DISPATCHER::DispatchWxEvent().
80 // Connect( wxEVT_MENU_OPEN, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
81 // Connect( wxEVT_MENU_HIGHLIGHT, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
82 // Connect( wxEVT_MENU_CLOSE, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
83 
84  Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
85  Connect( wxEVT_IDLE, wxIdleEventHandler( ACTION_MENU::OnIdle ), NULL, this );
86 }
#define NULL
void OnMenuEvent(wxMenuEvent &aEvent)
void OnIdle(wxIdleEvent &event)

References NULL, 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, HIGHLIGHT_MENU, GROUP_CONTEXT_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 190 of file action_menu.h.

191  {
192  }

Referenced by UpdateAll().

◆ UpdateAll()

void ACTION_MENU::UpdateAll ( )

Run update handlers for the menu and its submenus.

Definition at line 263 of file action_menu.cpp.

264 {
265  try
266  {
267  update();
268  }
269  catch( std::exception& )
270  {
271  }
272 
273  if( m_tool )
274  updateHotKeys();
275 
276  runOnSubmenus( std::bind( &ACTION_MENU::UpdateAll, _1 ) );
277 }
virtual void update()
Update menu state stub.
Definition: action_menu.h:190
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:252
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 328 of file action_menu.cpp.

329 {
330  TOOL_MANAGER* toolMgr = getToolManager();
331 
332  for( auto& ii : m_toolActions )
333  {
334  int id = ii.first;
335  const TOOL_ACTION& action = *ii.second;
336  int key = toolMgr->GetHotKey( action ) & ~MD_MODIFIER_MASK;
337 
338  if( key )
339  {
340  int mod = toolMgr->GetHotKey( action ) & MD_MODIFIER_MASK;
341  int flags = 0;
342  wxMenuItem* item = FindChildItem( id );
343 
344  if( item )
345  {
346  flags |= ( mod & MD_ALT ) ? wxACCEL_ALT : 0;
347  flags |= ( mod & MD_CTRL ) ? wxACCEL_CTRL : 0;
348  flags |= ( mod & MD_SHIFT ) ? wxACCEL_SHIFT : 0;
349 
350  if( !flags )
351  flags = wxACCEL_NORMAL;
352 
353  wxAcceleratorEntry accel( flags, key, id, item );
354  item->SetAccel( &accel );
355  }
356  }
357  }
358 }
int GetHotKey(const TOOL_ACTION &aAction)
Master controller class:
Definition: tool_manager.h:52
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:255
TOOL_MANAGER * getToolManager() const
Represent a single user action.
Definition: tool_action.h:49

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 260 of file action_menu.h.

Member Data Documentation

◆ CHECK

◆ m_dirty

bool ACTION_MENU::m_dirty
protected

Definition at line 237 of file action_menu.h.

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

◆ m_forcedPosition

wxPoint ACTION_MENU::m_forcedPosition
protected

Definition at line 235 of file action_menu.h.

◆ m_icon

const BITMAP_OPAQUE* ACTION_MENU::m_icon
protected

Stores the id number of selected item.

Definition at line 246 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 240 of file action_menu.h.

Referenced by OnMenuEvent().

◆ m_isForcedPosition

bool ACTION_MENU::m_isForcedPosition
protected

Definition at line 234 of file action_menu.h.

◆ m_selected

int ACTION_MENU::m_selected
protected

Creator of the menu.

Definition at line 249 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 258 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 243 of file action_menu.h.

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

◆ m_titleDisplayed

bool ACTION_MENU::m_titleDisplayed
protected

Definition at line 239 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 252 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 255 of file action_menu.h.

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


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