KiCad PCB EDA Suite
ZOOM_MENU Class Reference

#include <zoom_menu.h>

Inheritance diagram for ZOOM_MENU:
ACTION_MENU

Public Member Functions

 ZOOM_MENU (EDA_DRAW_FRAME *aParent)
 
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

TOOL_MANAGERgetToolManager () const
 
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
 

Private Member Functions

ACTION_MENUcreate () const override
 < Return an instance of this class. It has to be overridden in inheriting classes. More...
 
OPT_TOOL_EVENT eventHandler (const wxMenuEvent &aEvent) override
 Event handler stub. More...
 
void update () override
 Update menu state stub. More...
 

Private Attributes

EDA_DRAW_FRAMEm_parent
 

Detailed Description

Definition at line 32 of file zoom_menu.h.

Constructor & Destructor Documentation

◆ ZOOM_MENU()

ZOOM_MENU::ZOOM_MENU ( EDA_DRAW_FRAME aParent)

Definition at line 39 of file zoom_menu.cpp.

39  :
40  ACTION_MENU( true ),
41  m_parent( aParent )
42 {
43  SetTitle( _( "Zoom" ) );
45 
46  int i = ID_POPUP_ZOOM_LEVEL_START + 1; // 0 reserved for menus which support auto-zoom
47 
48  for( double factor : m_parent->config()->m_Window.zoom_factors )
49  Append( i++, wxString::Format( _( "Zoom: %.2f" ), factor ), wxEmptyString, wxITEM_CHECK );
50 }
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:72
std::vector< double > zoom_factors
Definition: app_settings.h:86
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
WINDOW_SETTINGS m_Window
Definition: app_settings.h:181
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:90
ACTION_MENU(bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr)
< Default constructor
Definition: action_menu.cpp:47
#define _(s)
Definition: 3d_actions.cpp:33
EDA_DRAW_FRAME * m_parent
Definition: zoom_menu.h:46

References _, EDA_BASE_FRAME::config(), Format(), ID_POPUP_ZOOM_LEVEL_START, m_parent, APP_SETTINGS_BASE::m_Window, ACTION_MENU::SetIcon(), ACTION_MENU::SetTitle(), WINDOW_SETTINGS::zoom_factors, and zoom_selection.

Referenced by create().

Member Function Documentation

◆ Add() [1/4]

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

Add a wxWidgets-style entry to the menu.

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

Definition at line 138 of file action_menu.cpp.

139 {
140  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
141 
142  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
143 
144  if( !!aIcon )
145  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
146 
147  return Append( item );
148 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:231
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:104

References AddBitmapToMenuItem(), and KiBitmap().

Referenced by ACTION_MENU::AddClose(), AddMenuLanguageList(), ACTION_MENU::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(), SCH_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), CVPCB_MAINFRAME::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 
)
inherited

Definition at line 151 of file action_menu.cpp.

153 {
154  wxASSERT_MSG( FindItem( aId ) == nullptr, "Duplicate menu IDs!" );
155 
156  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, aTooltip,
157  aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
158 
159  if( !!aIcon )
160  AddBitmapToMenuItem( item, KiBitmap( aIcon ) );
161 
162  return Append( item );
163 }
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:231
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:104

References AddBitmapToMenuItem(), and KiBitmap().

◆ Add() [3/4]

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

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

168 {
170  BITMAPS icon = aAction.GetIcon();
171 
172  // Allow the label to be overridden at point of use
173  wxString menuLabel = aOverrideLabel.IsEmpty() ? aAction.GetMenuItem() : aOverrideLabel;
174 
175  wxMenuItem* item = new wxMenuItem( this, aAction.GetUIId(), menuLabel,
176  aAction.GetDescription(),
177  aIsCheckmarkEntry ? wxITEM_CHECK : wxITEM_NORMAL );
178  if( !!icon )
179  AddBitmapToMenuItem( item, KiBitmap( icon ) );
180 
181  m_toolActions[aAction.GetUIId()] = &aAction;
182 
183  return Append( item );
184 }
int GetUIId() const
Definition: tool_action.h:112
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:231
const BITMAPS GetIcon() const
Return an icon associated with the action.
Definition: tool_action.h:169
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:104
wxString GetDescription(bool aIncludeHotkey=true) const
Definition: tool_action.cpp:84
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:262
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
wxString GetMenuItem() const
Definition: tool_action.cpp:76

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

◆ Add() [4/4]

wxMenuItem * ACTION_MENU::Add ( ACTION_MENU aMenu)
inherited

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

188 {
189  ACTION_MENU* menuCopy = aMenu->Clone();
190  m_submenus.push_back( menuCopy );
191 
192  wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), "Set a title for ACTION_MENU using SetTitle()" );
193 
194  if( !!aMenu->m_icon )
195  {
196  wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->m_title );
197  AddBitmapToMenuItem( newItem, KiBitmap( aMenu->m_icon ) );
198  newItem->SetSubMenu( menuCopy );
199  return Append( newItem );
200  }
201  else
202  {
203  return AppendSubMenu( menuCopy, menuCopy->m_title );
204  }
205 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:47
BITMAPS m_icon
Stores the id number of selected item.
Definition: action_menu.h:253
void AddBitmapToMenuItem(wxMenuItem *aMenu, const wxBitmap &aImage)
Add a bitmap to a menuitem.
Definition: bitmap.cpp:231
wxString m_title
Optional icon.
Definition: action_menu.h:250
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:265
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:104

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

◆ AddClose()

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

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

209 {
210  Add( _( "Close" ) + "\tCtrl+W",
211  wxString::Format( _( "Close %s" ), aAppname ),
212  wxID_CLOSE,
213  BITMAPS::exit );
214 }
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
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.

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

Referenced by ACTION_MENU::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 = "" 
)
inherited

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

218 {
219  if( !aKiface || aKiface->IsSingle() ) // not when under a project mgr
220  {
221  // Don't use ACTIONS::quit; wxWidgets moves this on OSX and expects to find it via
222  // wxID_EXIT
223  Add( _( "Quit" ),
224  wxString::Format( _( "Quit %s" ), aAppname ),
225  wxID_EXIT,
226  BITMAPS::exit );
227  }
228  else
229  {
230  AddClose( aAppname );
231  }
232 }
bool IsSingle() const
Is this KIFACE_I running under single_top?
Definition: kiface_i.h:104
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
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 _, ACTION_MENU::Add(), ACTION_MENU::AddClose(), exit, Format(), and KIFACE_I::IsSingle().

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

◆ appendCopy()

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

Append a copy of wxMenuItem.

Initialize handlers for events.

Definition at line 631 of file action_menu.cpp.

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

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

Referenced by ACTION_MENU::copyFrom().

◆ Clear()

void ACTION_MENU::Clear ( )
inherited

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

It leaves the menu in the initial state.

Definition at line 235 of file action_menu.cpp.

236 {
237  m_titleDisplayed = false;
238 
239  for( int i = GetMenuItemCount() - 1; i >= 0; --i )
240  Destroy( FindItemByPosition( i ) );
241 
242  m_toolActions.clear();
243  m_submenus.clear();
244 
245  wxASSERT( GetMenuItemCount() == 0 );
246 }
bool m_titleDisplayed
Definition: action_menu.h:246
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:265
std::map< int, const TOOL_ACTION * > m_toolActions
List of submenus.
Definition: action_menu.h:262

References ACTION_MENU::m_submenus, ACTION_MENU::m_titleDisplayed, and ACTION_MENU::m_toolActions.

Referenced by ACTION_MENU::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 ( )
inherited

Clear the dirty flag on the menu and all descendants.

Definition at line 285 of file action_menu.cpp.

286 {
287  m_dirty = false;
288  runOnSubmenus( std::bind( &ACTION_MENU::ClearDirty, _1 ) );
289 }
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 ACTION_MENU::m_dirty, and ACTION_MENU::runOnSubmenus().

Referenced by TOOL_MENU::ShowContextMenu().

◆ Clone()

ACTION_MENU * ACTION_MENU::Clone ( ) const
inherited

Create a deep, recursive copy of this ACTION_MENU.

Definition at line 306 of file action_menu.cpp.

307 {
308  ACTION_MENU* clone = create();
309  clone->Clear();
310  clone->copyFrom( *this );
311  return clone;
312 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:47
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 ACTION_MENU::Clear(), ACTION_MENU::copyFrom(), and ACTION_MENU::create().

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

◆ copyFrom()

void ACTION_MENU::copyFrom ( const ACTION_MENU aMenu)
protectedinherited

Copy another menus data to this instance.

Old entries are preserved and ones form aMenu are copied.

Definition at line 613 of file action_menu.cpp.

614 {
615  m_icon = aMenu.m_icon;
616  m_title = aMenu.m_title;
618  m_selected = -1; // aMenu.m_selected;
619  m_tool = aMenu.m_tool;
621 
622  // Copy all menu entries
623  for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
624  {
625  wxMenuItem* item = aMenu.FindItemByPosition( i );
626  appendCopy( item );
627  }
628 }
bool m_titleDisplayed
Definition: action_menu.h:246
BITMAPS m_icon
Stores the id number of selected item.
Definition: action_menu.h:253
wxString m_title
Optional icon.
Definition: action_menu.h:250
int m_selected
Creator of the menu.
Definition: action_menu.h:256
TOOL_INTERACTIVE * m_tool
Associates tool actions with menu item IDs. Non-owning.
Definition: action_menu.h:259
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:262

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

Referenced by ACTION_MENU::Clone().

◆ create()

ACTION_MENU* ZOOM_MENU::create ( ) const
inlineoverrideprivatevirtual

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

Returns an instance of TOOL_MANAGER class.

Reimplemented from ACTION_MENU.

Definition at line 38 of file zoom_menu.h.

39  {
40  return new ZOOM_MENU( m_parent );
41  }
ZOOM_MENU(EDA_DRAW_FRAME *aParent)
Definition: zoom_menu.cpp:39
EDA_DRAW_FRAME * m_parent
Definition: zoom_menu.h:46

References m_parent, and ZOOM_MENU().

◆ DisplayTitle()

void ACTION_MENU::DisplayTitle ( bool  aDisplay = true)
inherited

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

Definition at line 101 of file action_menu.cpp.

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

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

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

◆ eventHandler()

OPT_TOOL_EVENT ZOOM_MENU::eventHandler ( const wxMenuEvent &  )
overrideprivatevirtual

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 from ACTION_MENU.

Definition at line 53 of file zoom_menu.cpp.

54 {
55  OPT_TOOL_EVENT event( ACTIONS::zoomPreset.MakeEvent() );
56  event->SetParameter( (intptr_t) aEvent.GetId() - ID_POPUP_ZOOM_LEVEL_START );
57  return event;
58 }
static TOOL_ACTION zoomPreset
Definition: actions.h:101
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:569

References ID_POPUP_ZOOM_LEVEL_START, and ACTIONS::zoomPreset.

◆ findToolAction()

OPT_TOOL_EVENT ACTION_MENU::findToolAction ( int  aId)
protectedinherited

Definition at line 590 of file action_menu.cpp.

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

Referenced by ACTION_MENU::OnMenuEvent().

◆ GetSelected()

int ACTION_MENU::GetSelected ( ) const
inlineinherited

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

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

References ACTION_MENU::m_selected.

◆ getToolManager()

TOOL_MANAGER * ACTION_MENU::getToolManager ( ) const
protectedinherited

Definition at line 326 of file action_menu.cpp.

327 {
328  wxASSERT( m_tool );
329  return m_tool ? m_tool->GetManager() : nullptr;
330 }
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:259

References TOOL_BASE::GetManager(), and ACTION_MENU::m_tool.

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

◆ HasEnabledItems()

bool ACTION_MENU::HasEnabledItems ( ) const
inherited

Returns true if the menu has any enabled items.

Definition at line 249 of file action_menu.cpp.

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

◆ OnIdle()

void ACTION_MENU::OnIdle ( wxIdleEvent &  event)
inherited

Definition at line 381 of file action_menu.cpp.

382 {
384  g_menu_open_position.x = 0.0;
385  g_menu_open_position.y = 0.0;
386 }
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 ACTION_MENU::setupEvents().

◆ OnMenuEvent()

void ACTION_MENU::OnMenuEvent ( wxMenuEvent &  aEvent)
inherited

Definition at line 389 of file action_menu.cpp.

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

References AS_GLOBAL, ACTION_MENU::eventHandler(), ACTION_MENU::findToolAction(), g_last_menu_highlighted_id, g_menu_open_position, TOOL_ACTION::GetBaseUIId(), TOOL_BASE::GetManager(), TOOL_MANAGER::GetMousePosition(), ACTION_MENU::getToolManager(), ID_CONTEXT_MENU_ID_MAX, ID_POPUP_MENU_END, ID_POPUP_MENU_START, kicadTraceToolStack, ACTION_MENU::m_dirty, ACTION_MENU::m_isContextMenu, ACTION_MENU::m_selected, ACTION_MENU::m_tool, TEXTENTRY_TRICKS::OnCharHook(), ACTION_MENU::PassHelpTextToHandler(), TOOL_MANAGER::ProcessEvent(), TOOL_MANAGER::RunAction(), ACTION_MENU::runEventHandlers(), TA_CHOICE_MENU_CHOICE, TA_CHOICE_MENU_UPDATE, TC_COMMAND, and ACTIONS::updateMenu.

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

◆ PassHelpTextToHandler()

virtual bool ACTION_MENU::PassHelpTextToHandler ( )
inlinevirtualinherited

Reimplemented in BUS_UNFOLD_MENU.

Definition at line 179 of file action_menu.h.

179 { return false; }

Referenced by ACTION_MENU::OnMenuEvent().

◆ runEventHandlers()

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

Run a function on the menu and all its submenus.

Definition at line 566 of file action_menu.cpp.

567 {
568  aToolEvent = eventHandler( aMenuEvent );
569 
570  if( !aToolEvent )
571  runOnSubmenus( std::bind( &ACTION_MENU::runEventHandlers, _1, aMenuEvent, aToolEvent ) );
572 }
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:207
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.

References ACTION_MENU::eventHandler(), and ACTION_MENU::runOnSubmenus().

Referenced by ACTION_MENU::OnMenuEvent().

◆ runOnSubmenus()

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

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

Definition at line 575 of file action_menu.cpp.

576 {
577  try
578  {
579  std::for_each( m_submenus.begin(), m_submenus.end(), [&]( ACTION_MENU* m ) {
580  aFunction( m );
581  m->runOnSubmenus( aFunction );
582  } );
583  }
584  catch( std::exception& )
585  {
586  }
587 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:47
std::list< ACTION_MENU * > m_submenus
Definition: action_menu.h:265

References ACTION_MENU::m_submenus.

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

◆ SetDirty()

void ACTION_MENU::SetDirty ( )
inherited

Definition at line 292 of file action_menu.cpp.

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

References ACTION_MENU::m_dirty, and ACTION_MENU::runOnSubmenus().

Referenced by TOOL_MENU::ShowContextMenu().

◆ SetIcon()

◆ SetTitle()

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

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

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

References ACTION_MENU::DisplayTitle(), ACTION_MENU::m_title, and ACTION_MENU::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(), SCH_EDIT_FRAME::ReCreateMenuBar(), PL_EDITOR_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().

◆ SetTool()

void ACTION_MENU::SetTool ( TOOL_INTERACTIVE aTool)
inherited

Set a tool that is the creator of the menu.

Parameters
aToolis the tool that created the menu.

Definition at line 299 of file action_menu.cpp.

300 {
301  m_tool = aTool;
302  runOnSubmenus( std::bind( &ACTION_MENU::SetTool, _1, aTool ) );
303 }
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:259
void runOnSubmenus(std::function< void(ACTION_MENU *)> aFunction)
Check if any of submenus contains a TOOL_ACTION with a specific ID.

References ACTION_MENU::m_tool, and ACTION_MENU::runOnSubmenus().

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

◆ setupEvents()

void ACTION_MENU::setupEvents ( )
protectedinherited

Update hot key settings for TOOL_ACTIONs in this menu.

Definition at line 78 of file action_menu.cpp.

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

References NULL, ACTION_MENU::OnIdle(), and ACTION_MENU::OnMenuEvent().

Referenced by ACTION_MENU::ACTION_MENU().

◆ update()

void ZOOM_MENU::update ( )
overrideprivatevirtual

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 from ACTION_MENU.

Definition at line 61 of file zoom_menu.cpp.

62 {
63  double zoom = m_parent->GetCanvas()->GetGAL()->GetZoomFactor();
64 
65  const std::vector<double>& zoomList = m_parent->config()->m_Window.zoom_factors;
66 
67  for( size_t i = 0; i < zoomList.size(); ++i )
68  {
69  // Search for a value near the current zoom setting:
70  double rel_error = std::fabs( zoomList[i] - zoom ) / zoom;
71  // IDs start with 1 (leaving 0 for auto-zoom)
72  Check( ID_POPUP_ZOOM_LEVEL_START + i + 1, rel_error < 0.1 );
73  }
74 }
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
std::vector< double > zoom_factors
Definition: app_settings.h:86
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
double GetZoomFactor() const
Get the zoom factor.
WINDOW_SETTINGS m_Window
Definition: app_settings.h:181
EDA_DRAW_FRAME * m_parent
Definition: zoom_menu.h:46

References EDA_BASE_FRAME::config(), EDA_DRAW_FRAME::GetCanvas(), EDA_DRAW_PANEL_GAL::GetGAL(), KIGFX::GAL::GetZoomFactor(), ID_POPUP_ZOOM_LEVEL_START, m_parent, APP_SETTINGS_BASE::m_Window, zoom, and WINDOW_SETTINGS::zoom_factors.

◆ UpdateAll()

void ACTION_MENU::UpdateAll ( )
inherited

Run update handlers for the menu and its submenus.

Definition at line 268 of file action_menu.cpp.

269 {
270  try
271  {
272  update();
273  }
274  catch( std::exception& )
275  {
276  }
277 
278  if( m_tool )
279  updateHotKeys();
280 
281  runOnSubmenus( std::bind( &ACTION_MENU::UpdateAll, _1 ) );
282 }
virtual void update()
Update menu state stub.
Definition: action_menu.h:197
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:259
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 ACTION_MENU::m_tool, ACTION_MENU::runOnSubmenus(), ACTION_MENU::update(), and ACTION_MENU::updateHotKeys().

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

◆ updateHotKeys()

void ACTION_MENU::updateHotKeys ( )
protectedinherited

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

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

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

Referenced by ACTION_MENU::UpdateAll().

Member Data Documentation

◆ CHECK

◆ m_dirty

bool ACTION_MENU::m_dirty
protectedinherited

◆ m_forcedPosition

wxPoint ACTION_MENU::m_forcedPosition
protectedinherited

Definition at line 242 of file action_menu.h.

◆ m_icon

BITMAPS ACTION_MENU::m_icon
protectedinherited

Stores the id number of selected item.

Definition at line 253 of file action_menu.h.

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

◆ m_isContextMenu

bool ACTION_MENU::m_isContextMenu
protectedinherited

Menu title.

Definition at line 247 of file action_menu.h.

Referenced by ACTION_MENU::OnMenuEvent().

◆ m_isForcedPosition

bool ACTION_MENU::m_isForcedPosition
protectedinherited

Definition at line 241 of file action_menu.h.

◆ m_parent

EDA_DRAW_FRAME* ZOOM_MENU::m_parent
private

Definition at line 46 of file zoom_menu.h.

Referenced by create(), update(), and ZOOM_MENU().

◆ m_selected

int ACTION_MENU::m_selected
protectedinherited

Creator of the menu.

Definition at line 256 of file action_menu.h.

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

◆ m_submenus

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

◆ m_title

wxString ACTION_MENU::m_title
protectedinherited

Optional icon.

Definition at line 250 of file action_menu.h.

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

◆ m_titleDisplayed

bool ACTION_MENU::m_titleDisplayed
protectedinherited

◆ m_tool

TOOL_INTERACTIVE* ACTION_MENU::m_tool
protectedinherited

◆ m_toolActions

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

List of submenus.

Definition at line 262 of file action_menu.h.

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

◆ NORMAL

constexpr bool ACTION_MENU::NORMAL = false
staticinherited

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