KiCad PCB EDA Suite
action_menu.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013-2019 CERN
5  * Copyright (C) 2013-2019 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #include <eda_base_frame.h>
28 #include <functional>
29 #include <id.h>
30 #include <menus_helpers.h>
31 #include <tool/action_menu.h>
32 #include <tool/actions.h>
33 #include <tool/tool_event.h>
34 #include <tool/tool_interactive.h>
35 #include <tool/tool_manager.h>
36 #include <trace_helpers.h>
37 #include <wx/log.h>
38 #include <wx/stc/stc.h>
39 #include <textentry_tricks.h>
40 #include <wx/listctrl.h>
41 
42 using namespace std::placeholders;
43 
44 
45 ACTION_MENU::ACTION_MENU( bool isContextMenu ) :
46  m_dirty( true ),
47  m_titleDisplayed( false ),
48  m_isContextMenu( isContextMenu ),
49  m_icon( nullptr ),
50  m_selected( -1 ),
51  m_tool( nullptr )
52 {
53  setupEvents();
54 }
55 
56 
58 {
59  // Set parent to NULL to prevent submenus from unregistering from a notexisting object
60  for( auto menu : m_submenus )
61  menu->SetParent( nullptr );
62 
63  ACTION_MENU* parent = dynamic_cast<ACTION_MENU*>( GetParent() );
64 
65  if( parent )
66  parent->m_submenus.remove( this );
67 }
68 
69 
70 void ACTION_MENU::SetIcon( const BITMAP_OPAQUE* aIcon )
71 {
72  m_icon = aIcon;
73 }
74 
75 
77 {
78 // See wxWidgets hack in TOOL_DISPATCHER::DispatchWxEvent().
79 // Connect( wxEVT_MENU_OPEN, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
80 // Connect( wxEVT_MENU_HIGHLIGHT, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
81 // Connect( wxEVT_MENU_CLOSE, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
82 
83  Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( ACTION_MENU::OnMenuEvent ), NULL, this );
84  Connect( wxEVT_IDLE, wxIdleEventHandler( ACTION_MENU::OnIdle ), NULL, this );
85 }
86 
87 
88 void ACTION_MENU::SetTitle( const wxString& aTitle )
89 {
90  // Unfortunately wxMenu::SetTitle() does not work very well, so this is an alternative version
91  m_title = aTitle;
92 
93  // Update the menu title
94  if( m_titleDisplayed )
95  DisplayTitle( true );
96 }
97 
98 
99 void ACTION_MENU::DisplayTitle( bool aDisplay )
100 {
101  if( ( !aDisplay || m_title.IsEmpty() ) && m_titleDisplayed )
102  {
103  // Destroy the menu entry keeping the title..
104  wxMenuItem* item = FindItemByPosition( 0 );
105  wxASSERT( item->GetItemLabelText() == GetTitle() );
106  Destroy( item );
107  // ..and separator
108  item = FindItemByPosition( 0 );
109  wxASSERT( item->IsSeparator() );
110  Destroy( item );
111  m_titleDisplayed = false;
112  }
113 
114  else if( aDisplay && !m_title.IsEmpty() )
115  {
116  if( m_titleDisplayed )
117  {
118  // Simply update the title
119  FindItemByPosition( 0 )->SetItemLabel( m_title );
120  }
121  else
122  {
123  // Add a separator and a menu entry to display the title
124  InsertSeparator( 0 );
125  Insert( 0, new wxMenuItem( this, wxID_NONE, m_title, wxEmptyString, wxITEM_NORMAL ) );
126 
127  if( m_icon )
128  AddBitmapToMenuItem( FindItemByPosition( 0 ), KiBitmap( m_icon ) );
129 
130  m_titleDisplayed = true;
131  }
132  }
133 }
134 
135 
136 wxMenuItem* ACTION_MENU::Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon )
137 {
138  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
139 
140  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
141 
142  if( aIcon )
143  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
144 
145  return Append( item );
146 }
147 
148 
149 wxMenuItem* ACTION_MENU::Add( const wxString& aLabel, const wxString& aTooltip, int aId,
150  const BITMAP_OPAQUE* aIcon )
151 {
152  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
153 
154  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, aTooltip, wxITEM_NORMAL );
155 
156  if( aIcon )
157  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
158 
159  return Append( item );
160 }
161 
162 
163 wxMenuItem* ACTION_MENU::Add( const TOOL_ACTION& aAction, bool aIsCheckmarkEntry )
164 {
166  const BITMAP_OPAQUE* icon = aAction.GetIcon();
167 
168  wxMenuItem* item = new wxMenuItem( this, getMenuId( aAction ), aAction.GetMenuItem(),
169  aAction.GetDescription(),
170  aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
171 
172  if( icon )
173  AddBitmapToMenuItem( item, KiBitmap( icon ) );
174 
175  m_toolActions[getMenuId( aAction )] = &aAction;
176 
177  return Append( item );
178 }
179 
180 
181 wxMenuItem* ACTION_MENU::Add( ACTION_MENU* aMenu )
182 {
183  ACTION_MENU* menuCopy = aMenu->Clone();
184  m_submenus.push_back( menuCopy );
185 
186  wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), "Set a title for ACTION_MENU using SetTitle()" );
187 
188  if( aMenu->m_icon )
189  {
190  wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->m_title );
191  AddBitmapToMenuItem( newItem, KiBitmap( aMenu->m_icon ) );
192  newItem->SetSubMenu( menuCopy );
193  return Append( newItem );
194  }
195  else
196  {
197  return AppendSubMenu( menuCopy, menuCopy->m_title );
198  }
199 }
200 
201 
203 {
204  m_titleDisplayed = false;
205 
206  for( int i = GetMenuItemCount() - 1; i >= 0; --i )
207  Destroy( FindItemByPosition( i ) );
208 
209  m_toolActions.clear();
210  m_submenus.clear();
211 
212  wxASSERT( GetMenuItemCount() == 0 );
213 }
214 
215 
217 {
218  bool hasEnabled = false;
219 
220  auto& items = GetMenuItems();
221 
222  for( auto item : items )
223  {
224  if( item->IsEnabled() && !item->IsSeparator() )
225  {
226  hasEnabled = true;
227  break;
228  }
229  }
230 
231  return hasEnabled;
232 }
233 
234 
236 {
237  try
238  {
239  update();
240  }
241  catch( std::exception& e )
242  {
243  wxLogDebug( wxString::Format( "ACTION_MENU update handler exception: %s", e.what() ) );
244  }
245 
246  if( m_tool )
247  updateHotKeys();
248 
249  runOnSubmenus( std::bind( &ACTION_MENU::UpdateAll, _1 ) );
250 }
251 
252 
254 {
255  m_dirty = false;
256  runOnSubmenus( std::bind( &ACTION_MENU::ClearDirty, _1 ) );
257 }
258 
259 
261 {
262  m_dirty = true;
263  runOnSubmenus( std::bind( &ACTION_MENU::SetDirty, _1 ) );
264 }
265 
266 
268 {
269  m_tool = aTool;
270  runOnSubmenus( std::bind( &ACTION_MENU::SetTool, _1, aTool ) );
271 }
272 
273 
275 {
276  ACTION_MENU* clone = create();
277  clone->Clear();
278  clone->copyFrom( *this );
279  return clone;
280 }
281 
282 
284 {
285  ACTION_MENU* menu = new ACTION_MENU( false );
286 
287  wxASSERT_MSG( typeid( *this ) == typeid( *menu ),
288  wxString::Format( "You need to override create() method for class %s", typeid(*this).name() ) );
289 
290  return menu;
291 }
292 
293 
295 {
296  wxASSERT( m_tool );
297  return m_tool ? m_tool->GetManager() : nullptr;
298 }
299 
300 
302 {
303  TOOL_MANAGER* toolMgr = getToolManager();
304 
305  for( auto& ii : m_toolActions )
306  {
307  int id = ii.first;
308  const TOOL_ACTION& action = *ii.second;
309  int key = toolMgr->GetHotKey( action ) & ~MD_MODIFIER_MASK;
310 
311  if( key )
312  {
313  int mod = toolMgr->GetHotKey( action ) & MD_MODIFIER_MASK;
314  int flags = 0;
315  wxMenuItem* item = FindChildItem( id );
316 
317  if( item )
318  {
319  flags |= ( mod & MD_ALT ) ? wxACCEL_ALT : 0;
320  flags |= ( mod & MD_CTRL ) ? wxACCEL_CTRL : 0;
321  flags |= ( mod & MD_SHIFT ) ? wxACCEL_SHIFT : 0;
322 
323  if( !flags )
324  flags = wxACCEL_NORMAL;
325 
326  wxAcceleratorEntry accel( flags, key, id, item );
327  item->SetAccel( &accel );
328  }
329  }
330  }
331 }
332 
333 
334 // wxWidgets doesn't tell us when a menu command was generated from a hotkey or from
335 // a menu selection. It's important to us because a hotkey can be an immediate action
336 // while the menu selection can not (as it has no associated position).
337 //
338 // We get around this by storing the last highlighted menuId. If it matches the command
339 // id then we know this is a menu selection. (You might think we could use the menuOpen
340 // menuClose events, but these are actually generated for hotkeys as well.)
341 
343 
344 // We need to store the position of the mouse when the menu was opened so it can be passed
345 // to the command event generated when the menu item is selected.
347 
348 
349 void ACTION_MENU::OnIdle( wxIdleEvent& event )
350 {
352  g_menu_open_position.x = 0.0;
353  g_menu_open_position.y = 0.0;
354 }
355 
356 
357 void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent )
358 {
359  OPT_TOOL_EVENT evt;
360  wxString menuText;
361  wxEventType type = aEvent.GetEventType();
362  wxWindow* focus = wxWindow::FindFocus();
363 
364  if( type == wxEVT_MENU_OPEN )
365  {
366  if( m_dirty && m_tool )
367  getToolManager()->RunAction( ACTIONS::updateMenu, true, this );
368 
369  wxMenu* parent = dynamic_cast<wxMenu*>( GetParent() );
370 
371  // Don't update the position if this menu has a parent
372  if( !parent && m_tool )
374 
376  }
377  else if( type == wxEVT_MENU_HIGHLIGHT )
378  {
379  if( aEvent.GetId() > 0 )
380  g_last_menu_highlighted_id = aEvent.GetId();
381 
382  evt = TOOL_EVENT( TC_COMMAND, TA_CHOICE_MENU_UPDATE, aEvent.GetId() );
383  }
384  else if( type == wxEVT_COMMAND_MENU_SELECTED )
385  {
386  // Despite our attempts to catch the theft of text editor CHAR_HOOK and CHAR events
387  // in TOOL_DISPATCHER::DispatchWxEvent, wxWidgets sometimes converts those it knows
388  // about into menu commands without ever generating the appropriate CHAR_HOOK and CHAR
389  // events first.
390  if( dynamic_cast<wxTextEntry*>( focus )
391  || dynamic_cast<wxStyledTextCtrl*>( focus )
392  || dynamic_cast<wxListView*>( focus ) )
393  {
394  // Original key event has been lost, so we have to re-create it from the menu's
395  // wxAcceleratorEntry.
396  wxMenuItem* menuItem = FindItem( aEvent.GetId() );
397  wxAcceleratorEntry* acceleratorKey = menuItem ? menuItem->GetAccel() : nullptr;
398 
399  if( acceleratorKey )
400  {
401  wxKeyEvent keyEvent( wxEVT_CHAR_HOOK );
402  keyEvent.m_keyCode = acceleratorKey->GetKeyCode();
403  keyEvent.m_controlDown = ( acceleratorKey->GetFlags() & wxMOD_CONTROL ) > 0;
404  keyEvent.m_shiftDown = ( acceleratorKey->GetFlags() & wxMOD_SHIFT ) > 0;
405  keyEvent.m_altDown = ( acceleratorKey->GetFlags() & wxMOD_ALT ) > 0;
406 
407  if( auto ctrl = dynamic_cast<wxTextEntry*>( focus ) )
408  TEXTENTRY_TRICKS::OnCharHook( ctrl, keyEvent );
409  else
410  focus->HandleWindowEvent( keyEvent );
411 
412  if( keyEvent.GetSkipped() )
413  {
414  keyEvent.SetEventType( wxEVT_CHAR );
415  focus->HandleWindowEvent( keyEvent );
416  }
417 
418  // If the event was used as KEY event (not skipped) by the focused window,
419  // just finish.
420  // Otherwise this is actually a wxEVT_COMMAND_MENU_SELECTED, or the
421  // focused window is read only
422  if( !keyEvent.GetSkipped() )
423  return;
424  }
425  }
426 
427  // Store the selected position, so it can be checked by the tools
428  m_selected = aEvent.GetId();
429 
430  ACTION_MENU* parent = dynamic_cast<ACTION_MENU*>( GetParent() );
431 
432  while( parent )
433  {
434  parent->m_selected = m_selected;
435  parent = dynamic_cast<ACTION_MENU*>( parent->GetParent() );
436  }
437 
438  // Check if there is a TOOL_ACTION for the given ID
439  if( m_selected >= ACTION_ID )
440  evt = findToolAction( m_selected );
441 
442  if( !evt )
443  {
444 #ifdef __WINDOWS__
445  if( !evt )
446  {
447  // Try to find the submenu which holds the selected item
448  wxMenu* menu = nullptr;
449  FindItem( m_selected, &menu );
450 
451  // This conditional compilation is probably not needed.
452  // It will be removed later, for the Kicad V 6.x version.
453  // But in "old" 3.0 version, the "&& menu != this" contition was added to avoid hang
454  // This hang is no longer encountered in wxWidgets 3.0.4 version, and this condition is no longer needed.
455  // And in 3.1.2, we have to remove it, as "menu != this" never happens
456  // ("menu != this" always happens in 3.1.1 and older!).
457  #if wxCHECK_VERSION(3, 1, 2)
458  if( menu )
459  #else
460  if( menu && menu != this )
461  #endif
462  {
463  ACTION_MENU* cxmenu = static_cast<ACTION_MENU*>( menu );
464  evt = cxmenu->eventHandler( aEvent );
465  }
466  }
467 #else
468  if( !evt )
469  runEventHandlers( aEvent, evt );
470 #endif
471 
472  // Handling non-action menu entries (e.g. items in clarification list)
473  // in some context menus, that have IDs explicitly chosen between
474  // ID_POPUP_MENU_START and ID_POPUP_MENU_END
475  // Note also items in clarification list have an id >= 0 and < wxID_LOWEST
476  // in fact 0 to n-1 for n items in clarification list)
477  // id < 0 are automatically created for menuitems created with wxID_ANY
478  #define ID_CONTEXT_MENU_ID_MAX wxID_LOWEST /* = 100 should be enough and better */
479 
480  if( !evt &&
481  ( ( m_selected >= 0 && m_selected < ID_CONTEXT_MENU_ID_MAX ) ||
483  {
484  menuText = GetLabelText( aEvent.GetId() );
486  &menuText );
487  }
488  }
489  }
490 
491  // forward the action/update event to the TOOL_MANAGER
492  // clients that don't supply a tool will have to check GetSelected() themselves
493  if( evt && m_tool )
494  {
495  wxLogTrace( kicadTraceToolStack, "ACTION_MENU::OnMenuEvent %s", evt->Format() );
496 
497  // Pass the position the menu was opened from into the generated event if it is a select event
498  if( type == wxEVT_COMMAND_MENU_SELECTED )
499  evt->SetMousePosition( g_menu_open_position );
500  else
501  evt->SetMousePosition( getToolManager()->GetMousePosition() );
502 
503  if( g_last_menu_highlighted_id == aEvent.GetId() && !m_isContextMenu )
504  evt->SetHasPosition( false );
505 
506  if( m_tool->GetManager() )
507  m_tool->GetManager()->ProcessEvent( *evt );
508  }
509  else
510  {
511  aEvent.Skip();
512  }
513 }
514 
515 
516 void ACTION_MENU::runEventHandlers( const wxMenuEvent& aMenuEvent, OPT_TOOL_EVENT& aToolEvent )
517 {
518  aToolEvent = eventHandler( aMenuEvent );
519 
520  if( !aToolEvent )
521  runOnSubmenus( std::bind( &ACTION_MENU::runEventHandlers, _1, aMenuEvent, aToolEvent ) );
522 }
523 
524 
525 void ACTION_MENU::runOnSubmenus( std::function<void(ACTION_MENU*)> aFunction )
526 {
527  try
528  {
529  std::for_each( m_submenus.begin(), m_submenus.end(), [&]( ACTION_MENU* m ) {
530  aFunction( m );
531  m->runOnSubmenus( aFunction );
532  } );
533  }
534  catch( std::exception& e )
535  {
536  wxLogDebug( wxString::Format( "ACTION_MENU runOnSubmenus exception: %s", e.what() ) );
537  }
538 }
539 
540 
542 {
543  OPT_TOOL_EVENT evt;
544 
545  auto findFunc = [&]( ACTION_MENU* m ) {
546  if( evt )
547  return;
548 
549  const auto it = m->m_toolActions.find( aId );
550 
551  if( it != m->m_toolActions.end() )
552  evt = it->second->MakeEvent();
553  };
554 
555  findFunc( this );
556 
557  if( !evt )
558  runOnSubmenus( findFunc );
559 
560  return evt;
561 }
562 
563 
564 void ACTION_MENU::copyFrom( const ACTION_MENU& aMenu )
565 {
566  m_icon = aMenu.m_icon;
567  m_title = aMenu.m_title;
569  m_selected = -1; // aMenu.m_selected;
570  m_tool = aMenu.m_tool;
572 
573  // Copy all menu entries
574  for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
575  {
576  wxMenuItem* item = aMenu.FindItemByPosition( i );
577  appendCopy( item );
578  }
579 }
580 
581 
582 wxMenuItem* ACTION_MENU::appendCopy( const wxMenuItem* aSource )
583 {
584  wxMenuItem* newItem = new wxMenuItem( this, aSource->GetId(), aSource->GetItemLabel(),
585  aSource->GetHelp(), aSource->GetKind() );
586 
587  // Add the source bitmap if it is not the wxNullBitmap
588  // On Windows, for Checkable Menu items, adding a null bitmap adds also
589  // our predefined checked alternate bitmap
590  const wxBitmap& src_bitmap = aSource->GetBitmap();
591 
592  if( src_bitmap.IsOk() && src_bitmap.GetHeight() > 1 ) // a null bitmap has a 0 size
593  AddBitmapToMenuItem( newItem, src_bitmap );
594 
595  if( aSource->IsSubMenu() )
596  {
597  ACTION_MENU* menu = dynamic_cast<ACTION_MENU*>( aSource->GetSubMenu() );
598  wxASSERT_MSG( menu, "Submenus are expected to be a ACTION_MENU" );
599 
600  if( menu )
601  {
602  ACTION_MENU* menuCopy = menu->Clone();
603  newItem->SetSubMenu( menuCopy );
604  m_submenus.push_back( menuCopy );
605  }
606  }
607 
608  // wxMenuItem has to be added before enabling/disabling or checking
609  Append( newItem );
610 
611  if( aSource->IsCheckable() )
612  newItem->Check( aSource->IsChecked() );
613 
614  newItem->Enable( aSource->IsEnabled() );
615 
616  return newItem;
617 }
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Function Add() Adds a wxWidgets-style entry to the menu.
virtual void update()
Update menu state stub.
Definition: action_menu.h:171
bool m_titleDisplayed
Definition: action_menu.h:218
OPT_TOOL_EVENT findToolAction(int aId)
Checks if any of submenus contains a TOOL_ACTION with a specific ID.
int GetHotKey(const TOOL_ACTION &aAction)
PNG memory record (file in memory).
Definition: bitmap_def.h:29
static int g_last_menu_highlighted_id
static int getMenuId(const TOOL_ACTION &aAction)
Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.
Definition: action_menu.h:162
ACTION_MENU.
Definition: action_menu.h:44
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: action_menu.h:225
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
void runEventHandlers(const wxMenuEvent &aMenuEvent, OPT_TOOL_EVENT &aToolEvent)
Traverses the submenus tree looking for a submenu capable of handling a particular menu event.
void ClearDirty()
Function ClearDirty() Clears the dirty flag on the menu and all descendants.
void UpdateAll()
Function UpdateAll() Runs update handlers for the menu and its submenus.
virtual ACTION_MENU * create() const
Returns an instance of this class. It has to be overridden in inheriting classes.
const BITMAP_OPAQUE * GetIcon() const
Returns an icon associated with the action.
Definition: tool_action.h:149
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
TOOL_MANAGER * GetManager() const
Function GetManager() Returns 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:179
wxString GetDescription() const
Definition: tool_action.cpp:83
TOOL_MANAGER.
Definition: tool_manager.h:51
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
#define ID_CONTEXT_MENU_ID_MAX
void copyFrom(const ACTION_MENU &aMenu)
Copies another menus data to this instance.
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:205
#define NULL
bool m_isContextMenu
Definition: action_menu.h:219
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
wxString m_title
Menu title
Definition: action_menu.h:222
std::list< ACTION_MENU * > m_submenus
List of submenus.
Definition: action_menu.h:240
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:70
TOOL_EVENT.
Definition: tool_event.h:171
static VECTOR2D g_menu_open_position
Base window classes and related definitions.
int m_selected
Stores the id number of selected item.
Definition: action_menu.h:228
wxLogTrace helper definitions.
ACTION_MENU * Clone() const
Creates a deep, recursive copy of this ACTION_MENU.
static const int ACTION_ID
Menu items with ID higher than that are considered TOOL_ACTIONs
Definition: action_menu.h:234
static TOOL_ACTION updateMenu
Definition: actions.h:163
All active tools
Definition: tool_event.h:147
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: action_menu.h:231
wxMenuItem * appendCopy(const wxMenuItem *aSource)
Function appendCopy Appends a copy of wxMenuItem.
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Runs a function on the menu and all its submenus.
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:237
void OnMenuEvent(wxMenuEvent &aEvent)
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:88
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static void OnCharHook(wxTextEntry *aTextEntry, wxKeyEvent &aEvent)
TOOL_MANAGER * getToolManager() const
Returns an instance of TOOL_MANAGER class.
TOOL_ACTION.
Definition: tool_action.h:46
void setupEvents()
Initializes handlers for events.
Definition: action_menu.cpp:76
void Clear()
Function Clear() Removes all the entries from the menu (as well as its title).
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
bool HasEnabledItems() const
Function HasEnabledItems();.
void OnIdle(wxIdleEvent &event)
ACTION_MENU(bool isContextMenu)
Default constructor
Definition: action_menu.cpp:45
VECTOR2D GetMousePosition()
void updateHotKeys()
Updates hot key settings for TOOL_ACTIONs in this menu.
wxString GetMenuItem() const
Definition: tool_action.cpp:75
~ACTION_MENU() override
Definition: action_menu.cpp:57
void SetDirty()
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:556
void DisplayTitle(bool aDisplay=true)
Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.
Definition: action_menu.cpp:99