KiCad PCB EDA Suite
LOCK_CONTEXT_MENU Class Reference
Inheritance diagram for LOCK_CONTEXT_MENU:
CONTEXT_MENU

Public Member Functions

 LOCK_CONTEXT_MENU ()
 
CONTEXT_MENUcreate () const override
 

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

More...
 
void SetTitle (const wxString &aTitle) override
 Function SetTitle() Sets title for the context menu. More...
 
void DisplayTitle (bool aDisplay=true)
 Function DisplayTitle() Decides whether a title for a pop up menu should be displayed. More...
 
void SetIcon (const BITMAP_OPAQUE *aIcon)
 Function SetIcon() Assigns an icon for the entry. More...
 
wxMenuItem * Add (const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon=NULL)
 Function Add() Adds an entry to the menu. More...
 
wxMenuItem * Add (const TOOL_ACTION &aAction)
 Function Add() Adds an entry to the menu, basing on the TOOL_ACTION object. More...
 
std::list< wxMenuItem * > Add (CONTEXT_MENU *aMenu, bool aExpand=false)
 Function Add() Adds a context menu as a submenu. More...
 
void Clear ()
 Function Clear() Removes all the entries from the menu (as well as its title). More...
 
bool HasEnabledItems () const
 Function HasEnabledItems();. More...
 
int GetSelected () const
 Function GetSelected() Returns the position of selected item. More...
 
void UpdateAll ()
 Function UpdateAll() Runs update handlers for the menu and its submenus. More...
 
void SetTool (TOOL_INTERACTIVE *aTool)
 Function SetTool() Sets a tool that is the creator of the menu. More...
 
CONTEXT_MENUClone () const
 Creates a deep, recursive copy of this CONTEXT_MENU. More...
 

Protected Member Functions

TOOL_MANAGERgetToolManager ()
 

Returns an instance of TOOL_MANAGER class.

More...
 
virtual void update ()
 Update menu state stub. More...
 
virtual OPT_TOOL_EVENT eventHandler (const wxMenuEvent &)
 Event handler stub. More...
 
void copyFrom (const CONTEXT_MENU &aMenu)
 Copies another menus data to this instance. More...
 

Static Protected Member Functions

static int getMenuId (const TOOL_ACTION &aAction)
 

Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.

More...
 

Detailed Description

Definition at line 211 of file pcb_editor_control.cpp.

Constructor & Destructor Documentation

LOCK_CONTEXT_MENU::LOCK_CONTEXT_MENU ( )
inline

Definition at line 214 of file pcb_editor_control.cpp.

References PCB_ACTIONS::lock, PCB_ACTIONS::toggleLock, and PCB_ACTIONS::unlock.

215  {
216  SetIcon( locked_xpm );
217  SetTitle( _( "Locking" ) );
218 
222  }
static TOOL_ACTION toggleLock
Definition: pcb_actions.h:340
static TOOL_ACTION unlock
Definition: pcb_actions.h:342
static TOOL_ACTION lock
Definition: pcb_actions.h:341
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon=NULL)
Function Add() Adds an entry to the menu.
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: context_menu.h:74
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the context menu.

Member Function Documentation

wxMenuItem * CONTEXT_MENU::Add ( const wxString &  aLabel,
int  aId,
const BITMAP_OPAQUE aIcon = NULL 
)
inherited

Function Add() Adds an entry to the menu.

After highlighting/selecting the entry, a TOOL_EVENT command is sent that contains ID of the entry.

Parameters
aLabelis the text label show in the menu.
aIdis the ID that is sent in the TOOL_EVENT. It should be unique for every entry.
aIconis an optional icon.

Definition at line 107 of file context_menu.cpp.

References KiBitmap().

Referenced by SELECTION_TOOL::disambiguationMenu(), CONDITIONAL_MENU::Generate(), PLACEMENT_TOOL::Init(), PAD_CONTEXT_MENU::PAD_CONTEXT_MENU(), ROUTER_TOOL_MENU::ROUTER_TOOL_MENU(), and TUNER_TOOL_MENU::TUNER_TOOL_MENU().

108 {
109 #ifdef DEBUG
110  if( FindItem( aId ) != NULL )
111  wxLogWarning( wxT( "Adding more than one menu entry with the same ID may result in"
112  "undefined behaviour" ) );
113 #endif
114 
115  wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
116 
117  if( aIcon )
118  item->SetBitmap( KiBitmap( aIcon ) );
119 
120  return Append( item );
121 }
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
wxMenuItem * CONTEXT_MENU::Add ( const TOOL_ACTION aAction)
inherited

Function Add() Adds an entry to the menu, basing on the TOOL_ACTION object.

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

Parameters
aActionis the action to be added to menu entry.

ID numbers for tool actions need to have a value higher than ACTION_ID

Definition at line 124 of file context_menu.cpp.

References TOOL_ACTION::GetDescription(), TOOL_ACTION::GetIcon(), CONTEXT_MENU::getMenuId(), TOOL_ACTION::GetMenuItem(), KiBitmap(), and CONTEXT_MENU::m_toolActions.

125 {
127  const BITMAP_OPAQUE* icon = aAction.GetIcon();
128 
129  wxMenuItem* item = new wxMenuItem( this, getMenuId( aAction ), aAction.GetMenuItem(),
130  aAction.GetDescription(), wxITEM_NORMAL );
131 
132  if( icon )
133  item->SetBitmap( KiBitmap( icon ) );
134 
135  m_toolActions[getMenuId( aAction )] = &aAction;
136 
137  wxMenuItem* i = Append( item );
138  return i;
139 }
PNG memory record (file in memory).
Definition: bitmap_types.h:38
const wxString & GetDescription() const
Definition: tool_action.h:124
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: context_menu.h:228
const wxString & GetMenuItem() const
Definition: tool_action.h:114
static int getMenuId(const TOOL_ACTION &aAction)
Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.
Definition: context_menu.h:158
const BITMAP_OPAQUE * GetIcon() const
Returns an icon associated with the action.
Definition: tool_action.h:165
std::list< wxMenuItem * > CONTEXT_MENU::Add ( CONTEXT_MENU aMenu,
bool  aExpand = false 
)
inherited

Function Add() Adds a context 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.
aExpandallows to add all entries from the menu as individual entries rather than add everything as a submenu.

Definition at line 142 of file context_menu.cpp.

References CONTEXT_MENU::appendCopy(), CONTEXT_MENU::Clone(), KiBitmap(), CONTEXT_MENU::m_icon, CONTEXT_MENU::m_submenus, and CONTEXT_MENU::m_title.

143 {
144  std::list<wxMenuItem*> items;
145  CONTEXT_MENU* menuCopy = aMenu->Clone();
146  m_submenus.push_back( menuCopy );
147 
148  if( aExpand )
149  {
150  for( int i = 0; i < (int) aMenu->GetMenuItemCount(); ++i )
151  {
152  wxMenuItem* item = aMenu->FindItemByPosition( i );
153  items.push_back( appendCopy( item ) );
154  }
155  }
156  else
157  {
158  wxASSERT_MSG( !menuCopy->m_title.IsEmpty(), "Set a title for CONTEXT_MENU using SetTitle()" );
159 
160  if( aMenu->m_icon )
161  {
162  wxMenuItem* newItem = new wxMenuItem( this, -1, menuCopy->m_title );
163  newItem->SetBitmap( KiBitmap( aMenu->m_icon ) );
164  newItem->SetSubMenu( menuCopy );
165  items.push_back( Append( newItem ) );
166  }
167  else
168  {
169  items.push_back( AppendSubMenu( menuCopy, menuCopy->m_title ) );
170  }
171  }
172 
173  return items;
174 }
Class CONTEXT_MENU.
Definition: context_menu.h:44
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: context_menu.h:234
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
CONTEXT_MENU * Clone() const
Creates a deep, recursive copy of this CONTEXT_MENU.
std::list< CONTEXT_MENU * > m_submenus
List of submenus.
Definition: context_menu.h:231
wxMenuItem * appendCopy(const wxMenuItem *aSource)
Function appendCopy Appends a copy of wxMenuItem.
wxString m_title
Menu title
Definition: context_menu.h:216
void CONTEXT_MENU::Clear ( )
inherited

Function Clear() Removes all the entries from the menu (as well as its title).

It leaves the menu in the initial state.

Definition at line 177 of file context_menu.cpp.

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

Referenced by CONTEXT_MENU::Clone(), and TRACK_WIDTH_MENU::SetBoard().

178 {
179  m_titleDisplayed = false;
180 
181  for( int i = GetMenuItemCount() - 1; i >= 0; --i )
182  Destroy( FindItemByPosition( i ) );
183 
184  m_toolActions.clear();
185  m_submenus.clear();
186 
187  wxASSERT( GetMenuItemCount() == 0 );
188 }
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: context_menu.h:228
std::list< CONTEXT_MENU * > m_submenus
List of submenus.
Definition: context_menu.h:231
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: context_menu.h:213
CONTEXT_MENU * CONTEXT_MENU::Clone ( ) const
inherited

Creates a deep, recursive copy of this CONTEXT_MENU.

Definition at line 235 of file context_menu.cpp.

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

Referenced by CONTEXT_MENU::Add(), CONTEXT_MENU::appendCopy(), and TOOL_MANAGER::dispatchContextMenu().

236 {
237  CONTEXT_MENU* clone = create();
238  clone->Clear();
239  clone->copyFrom( *this );
240  return clone;
241 }
Class CONTEXT_MENU.
Definition: context_menu.h:44
void copyFrom(const CONTEXT_MENU &aMenu)
Copies another menus data to this instance.
void Clear()
Function Clear() Removes all the entries from the menu (as well as its title).
virtual CONTEXT_MENU * create() const
Returns an instance of this class. It has to be overridden in inheriting classes. ...
void CONTEXT_MENU::copyFrom ( const CONTEXT_MENU aMenu)
protectedinherited

Copies another menus data to this instance.

Old entries are preserved, and ones form aMenu are copied.

Definition at line 403 of file context_menu.cpp.

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

Referenced by CONTEXT_MENU::Clone().

404 {
405  m_icon = aMenu.m_icon;
406  m_title = aMenu.m_title;
408  m_selected = -1; // aMenu.m_selected;
409  m_tool = aMenu.m_tool;
411 
412  // Copy all menu entries
413  for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
414  {
415  wxMenuItem* item = aMenu.FindItemByPosition( i );
416  appendCopy( item );
417  }
418 }
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: context_menu.h:222
int m_selected
Stores the id number of selected item.
Definition: context_menu.h:219
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: context_menu.h:234
std::map< int, const TOOL_ACTION * > m_toolActions
Associates tool actions with menu item IDs. Non-owning.
Definition: context_menu.h:228
wxMenuItem * appendCopy(const wxMenuItem *aSource)
Function appendCopy Appends a copy of wxMenuItem.
wxString m_title
Menu title
Definition: context_menu.h:216
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: context_menu.h:213
CONTEXT_MENU* LOCK_CONTEXT_MENU::create ( ) const
inlineoverridevirtual

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

Reimplemented from CONTEXT_MENU.

Definition at line 224 of file pcb_editor_control.cpp.

225  {
226  return new LOCK_CONTEXT_MENU();
227  }
void CONTEXT_MENU::DisplayTitle ( bool  aDisplay = true)
inherited

Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.

Definition at line 74 of file context_menu.cpp.

References CONTEXT_MENU::m_title, and CONTEXT_MENU::m_titleDisplayed.

Referenced by SELECTION_TOOL::disambiguationMenu(), CONTEXT_MENU::SetTitle(), and TUNER_TOOL_MENU::TUNER_TOOL_MENU().

75 {
76  if( ( !aDisplay || m_title.IsEmpty() ) && m_titleDisplayed )
77  {
78  // Destroy the menu entry keeping the title..
79  wxMenuItem* item = FindItemByPosition( 0 );
80  wxASSERT( item->GetItemLabelText() == GetTitle() );
81  Destroy( item );
82  // ..and separator
83  item = FindItemByPosition( 0 );
84  wxASSERT( item->IsSeparator() );
85  Destroy( item );
86  m_titleDisplayed = false;
87  }
88 
89  else if( aDisplay && !m_title.IsEmpty() )
90  {
91  if( m_titleDisplayed )
92  {
93  // Simply update the title
94  FindItemByPosition( 0 )->SetItemLabel( m_title );
95  }
96  else
97  {
98  // Add a separator and a menu entry to display the title
99  InsertSeparator( 0 );
100  Insert( 0, new wxMenuItem( this, wxID_NONE, m_title, wxEmptyString, wxITEM_NORMAL ) );
101  m_titleDisplayed = true;
102  }
103  }
104 }
wxString m_title
Menu title
Definition: context_menu.h:216
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: context_menu.h:213
virtual OPT_TOOL_EVENT CONTEXT_MENU::eventHandler ( const wxMenuEvent &  )
inlineprotectedvirtualinherited

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 TRACK_WIDTH_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 175 of file context_menu.h.

Referenced by CONTEXT_MENU::onMenuEvent(), and CONTEXT_MENU::runEventHandlers().

176  {
177  return OPT_TOOL_EVENT();
178  }
boost::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:460
static int CONTEXT_MENU::getMenuId ( const TOOL_ACTION aAction)
inlinestaticprotectedinherited

Returns the corresponding wxMenuItem identifier for a TOOL_ACTION object.

Definition at line 158 of file context_menu.h.

References CONTEXT_MENU::ACTION_ID, and TOOL_ACTION::GetId().

Referenced by CONTEXT_MENU::Add(), and PAD_CONTEXT_MENU::update().

159  {
160  return aAction.GetId() + ACTION_ID;
161  }
static const int ACTION_ID
Menu items with ID higher than that are considered TOOL_ACTIONs
Definition: context_menu.h:225
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:85
int CONTEXT_MENU::GetSelected ( ) const
inlineinherited

Function GetSelected() Returns 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 context menu.

Definition at line 127 of file context_menu.h.

References CONTEXT_MENU::m_selected.

128  {
129  return m_selected;
130  }
int m_selected
Stores the id number of selected item.
Definition: context_menu.h:219
TOOL_MANAGER * CONTEXT_MENU::getToolManager ( )
protectedinherited

Returns an instance of TOOL_MANAGER class.

Definition at line 255 of file context_menu.cpp.

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

Referenced by PAD_CONTEXT_MENU::update(), and CONTEXT_MENU::updateHotKeys().

256 {
257  wxASSERT( m_tool );
258  return m_tool ? m_tool->GetManager() : nullptr;
259 }
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: context_menu.h:222
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool...
Definition: tool_base.h:144
bool CONTEXT_MENU::HasEnabledItems ( ) const
inherited

Function HasEnabledItems();.

Returns true if the menu has any enabled items

Definition at line 191 of file context_menu.cpp.

192 {
193  bool hasEnabled = false;
194 
195  auto& items = GetMenuItems();
196 
197  for( auto item : items )
198  {
199  if( item->IsEnabled() && !item->IsSeparator() )
200  {
201  hasEnabled = true;
202  break;
203  }
204  }
205 
206  return hasEnabled;
207 }
void CONTEXT_MENU::SetIcon ( const BITMAP_OPAQUE aIcon)
inlineinherited

Function SetIcon() Assigns an icon for the entry.

Parameters
aIconis the icon to be assigned. NULL is used to remove icon.

Definition at line 74 of file context_menu.h.

References CONTEXT_MENU::m_icon.

Referenced by GRID_MENU::GRID_MENU(), PLACEMENT_TOOL::Init(), PAD_CONTEXT_MENU::PAD_CONTEXT_MENU(), TRACK_VIA_SIZE_MENU::TRACK_VIA_SIZE_MENU(), and ZOOM_MENU::ZOOM_MENU().

75  {
76  m_icon = aIcon;
77  }
const BITMAP_OPAQUE * m_icon
Optional icon
Definition: context_menu.h:234
void CONTEXT_MENU::SetTitle ( const wxString &  aTitle)
overrideinherited

Function SetTitle() Sets title for the context menu.

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

Parameters
aTitleis the new title.

Definition at line 63 of file context_menu.cpp.

References CONTEXT_MENU::DisplayTitle(), CONTEXT_MENU::m_title, and CONTEXT_MENU::m_titleDisplayed.

Referenced by SELECTION_TOOL::disambiguationMenu(), GRID_MENU::GRID_MENU(), PLACEMENT_TOOL::Init(), PAD_CONTEXT_MENU::PAD_CONTEXT_MENU(), ROUTER_TOOL_MENU::ROUTER_TOOL_MENU(), TRACK_WIDTH_MENU::TRACK_WIDTH_MENU(), TUNER_TOOL_MENU::TUNER_TOOL_MENU(), and ZOOM_MENU::ZOOM_MENU().

64 {
65  // Unfortunately wxMenu::SetTitle() does not work very well, so this is an alternative version
66  m_title = aTitle;
67 
68  // Update the menu title
69  if( m_titleDisplayed )
70  DisplayTitle( true );
71 }
void DisplayTitle(bool aDisplay=true)
Function DisplayTitle() Decides whether a title for a pop up menu should be displayed.
wxString m_title
Menu title
Definition: context_menu.h:216
bool m_titleDisplayed
Flag indicating that the menu title was set up.
Definition: context_menu.h:213
void CONTEXT_MENU::SetTool ( TOOL_INTERACTIVE aTool)
inherited

Function SetTool() Sets a tool that is the creator of the menu.

Parameters
aToolis the tool that created the menu.

Definition at line 228 of file context_menu.cpp.

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

Referenced by CONDITIONAL_MENU::Generate(), and TOOL_INTERACTIVE::SetContextMenu().

229 {
230  m_tool = aTool;
231  runOnSubmenus( std::bind( &CONTEXT_MENU::SetTool, _1, aTool ) );
232 }
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: context_menu.h:222
void runOnSubmenus(std::function< void(CONTEXT_MENU *)> aFunction)
Runs a function on the menu and all its submenus.
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
virtual void CONTEXT_MENU::update ( )
inlineprotectedvirtualinherited

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 ZONE_CONTEXT_MENU, SELECT_MENU, PAD_CONTEXT_MENU, GRID_MENU, and ZOOM_MENU.

Definition at line 167 of file context_menu.h.

Referenced by CONTEXT_MENU::UpdateAll().

168  {
169  }
void CONTEXT_MENU::UpdateAll ( )
inherited

Function UpdateAll() Runs update handlers for the menu and its submenus.

Definition at line 210 of file context_menu.cpp.

References Format(), CONTEXT_MENU::m_tool, CONTEXT_MENU::runOnSubmenus(), CONTEXT_MENU::update(), and CONTEXT_MENU::updateHotKeys().

211 {
212  try
213  {
214  update();
215  }
216  catch( std::exception& e )
217  {
218  wxLogDebug( wxString::Format( "CONTEXT_MENU update handler exception: %s", e.what() ) );
219  }
220 
221  if( m_tool )
222  updateHotKeys();
223 
224  runOnSubmenus( std::bind( &CONTEXT_MENU::UpdateAll, _1 ) );
225 }
TOOL_INTERACTIVE * m_tool
Creator of the menu
Definition: context_menu.h:222
void updateHotKeys()
Updates hot key settings for TOOL_ACTIONs in this menu.
virtual void update()
Update menu state stub.
Definition: context_menu.h:167
void runOnSubmenus(std::function< void(CONTEXT_MENU *)> aFunction)
Runs a function on the menu and all its submenus.
void UpdateAll()
Function UpdateAll() Runs update handlers for the menu and its submenus.
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

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