KiCad PCB EDA Suite
ACTION_TOOLBAR Class Reference

ACTION_TOOLBAR. More...

#include <action_toolbar.h>

Inheritance diagram for ACTION_TOOLBAR:

Public Member Functions

 ACTION_TOOLBAR (EDA_BASE_FRAME *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxAUI_TB_DEFAULT_STYLE)
 
virtual ~ACTION_TOOLBAR ()
 
void Add (const TOOL_ACTION &aAction, bool aIsToggleEntry=false)
 Function Add() Adds a TOOL_ACTION-based button to the toolbar. More...
 
void AddButton (const TOOL_ACTION &aAction)
 Function AddButton() Adds a large button such as used in the Kicad Manager Frame's launch bar. More...
 
void AddScaledSeparator (wxWindow *aWindow)
 Add a separator that introduces space on either side to not squash the tools when scaled. More...
 
void AddToolContextMenu (const TOOL_ACTION &aAction, CONDITIONAL_MENU *aMenu)
 Add a context menu to a specific tool item on the toolbar. More...
 
void ClearToolbar ()
 Clear the toolbar and remove all associated menus. More...
 
void SetToolBitmap (const TOOL_ACTION &aAction, const wxBitmap &aBitmap)
 Function SetToolBitmap() Updates the bitmap of a particular tool. More...
 
void Toggle (const TOOL_ACTION &aAction, bool aState)
 Applies the default toggle action. More...
 
void Toggle (const TOOL_ACTION &aAction, bool aEnabled, bool aChecked)
 

Static Public Attributes

static const bool TOGGLE = true
 

Protected Member Functions

void onToolEvent (wxAuiToolBarEvent &aEvent)
 

The default tool event handler.

More...
 
void onToolRightClick (wxAuiToolBarEvent &aEvent)
 

Handle a right-click on a menu item

More...
 

Protected Attributes

TOOL_MANAGERm_toolManager
 
std::map< int, bool > m_toolKinds
 
std::map< int, const TOOL_ACTION * > m_toolActions
 
std::map< int, CONDITIONAL_MENU * > m_toolMenus
 

Static Protected Attributes

static const int ACTION_ID = 10000
 

Tool items with ID higher than that are considered TOOL_ACTIONs

More...
 

Detailed Description

ACTION_TOOLBAR.

Defines the structure of a toolbar with buttons that invoke ACTIONs.

Definition at line 42 of file action_toolbar.h.

Constructor & Destructor Documentation

◆ ACTION_TOOLBAR()

ACTION_TOOLBAR::ACTION_TOOLBAR ( EDA_BASE_FRAME parent,
wxWindowID  id = wxID_ANY,
const wxPoint pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = wxAUI_TB_DEFAULT_STYLE 
)

Definition at line 38 of file action_toolbar.cpp.

39  :
40  wxAuiToolBar( parent, id, pos, size, style ),
41  m_toolManager( parent->GetToolManager() )
42 {
43  Connect( wxEVT_COMMAND_TOOL_CLICKED, wxAuiToolBarEventHandler( ACTION_TOOLBAR::onToolEvent ),
44  NULL, this );
45  Connect( wxEVT_AUITOOLBAR_RIGHT_CLICK, wxAuiToolBarEventHandler( ACTION_TOOLBAR::onToolRightClick ),
46  NULL, this );
47 }
void onToolRightClick(wxAuiToolBarEvent &aEvent)
Handle a right-click on a menu item
void onToolEvent(wxAuiToolBarEvent &aEvent)
The default tool event handler.
#define NULL
TOOL_MANAGER * m_toolManager
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:74

References NULL, onToolEvent(), and onToolRightClick().

◆ ~ACTION_TOOLBAR()

ACTION_TOOLBAR::~ACTION_TOOLBAR ( )
virtual

Definition at line 50 of file action_toolbar.cpp.

51 {
52  // Delete all the menus
53  for( auto it = m_toolMenus.begin(); it != m_toolMenus.end(); it++ )
54  delete it->second;
55 
56  m_toolMenus.clear();
57 }
std::map< int, CONDITIONAL_MENU * > m_toolMenus

References m_toolMenus.

Member Function Documentation

◆ Add()

void ACTION_TOOLBAR::Add ( const TOOL_ACTION aAction,
bool  aIsToggleEntry = false 
)

Function Add() Adds a TOOL_ACTION-based button to the toolbar.

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

Definition at line 60 of file action_toolbar.cpp.

61 {
62  wxWindow* parent = dynamic_cast<wxWindow*>( m_toolManager->GetToolHolder() );
63  int toolId = aAction.GetId() + ACTION_ID;
64 
65  AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), parent ),
66  aAction.GetDescription(), aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL );
67 
68  m_toolKinds[ toolId ] = aIsToggleEntry;
69  m_toolActions[ toolId ] = &aAction;
70 }
std::map< int, const TOOL_ACTION * > m_toolActions
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, wxWindow *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
const BITMAP_OPAQUE * GetIcon() const
Returns an icon associated with the action.
Definition: tool_action.h:149
wxString GetDescription() const
Definition: tool_action.cpp:83
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:295
TOOL_MANAGER * m_toolManager
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs
std::map< int, bool > m_toolKinds

References ACTION_ID, TOOL_ACTION::GetDescription(), TOOL_ACTION::GetIcon(), TOOL_ACTION::GetId(), TOOL_MANAGER::GetToolHolder(), KiScaledBitmap(), m_toolActions, m_toolKinds, and m_toolManager.

Referenced by KICAD_MANAGER_FRAME::RecreateBaseHToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar(), LIB_VIEW_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar(), CVPCB_MAINFRAME::ReCreateHToolbar(), GERBVIEW_FRAME::ReCreateHToolbar(), LIB_EDIT_FRAME::ReCreateHToolbar(), SCH_EDIT_FRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateHToolbar(), KICAD_MANAGER_FRAME::RecreateLauncher(), EDA_3D_VIEWER::ReCreateMainToolbar(), PCB_EDIT_FRAME::ReCreateMicrowaveVToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateOptToolbar(), LIB_EDIT_FRAME::ReCreateOptToolbar(), GERBVIEW_FRAME::ReCreateOptToolbar(), SCH_EDIT_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateVToolbar(), PL_EDITOR_FRAME::ReCreateVToolbar(), LIB_EDIT_FRAME::ReCreateVToolbar(), SCH_EDIT_FRAME::ReCreateVToolbar(), and PCB_EDIT_FRAME::ReCreateVToolbar().

◆ AddButton()

void ACTION_TOOLBAR::AddButton ( const TOOL_ACTION aAction)

Function AddButton() Adds a large button such as used in the Kicad Manager Frame's launch bar.

Parameters
aAction

Definition at line 73 of file action_toolbar.cpp.

74 {
75  wxWindow* parent = dynamic_cast<wxWindow*>( m_toolManager->GetToolHolder() );
76  int toolId = aAction.GetId() + ACTION_ID;
77 
78  AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), parent ),
79  aAction.GetName(), wxITEM_NORMAL );
80 
81  m_toolKinds[ toolId ] = false;
82  m_toolActions[ toolId ] = &aAction;
83 }
std::map< int, const TOOL_ACTION * > m_toolActions
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, wxWindow *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
const BITMAP_OPAQUE * GetIcon() const
Returns an icon associated with the action.
Definition: tool_action.h:149
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:295
TOOL_MANAGER * m_toolManager
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs
std::map< int, bool > m_toolKinds
const std::string & GetName() const
Function GetName() Returns name of the action.
Definition: tool_action.h:78

References ACTION_ID, TOOL_ACTION::GetIcon(), TOOL_ACTION::GetId(), TOOL_ACTION::GetName(), TOOL_MANAGER::GetToolHolder(), KiScaledBitmap(), m_toolActions, m_toolKinds, and m_toolManager.

◆ AddScaledSeparator()

void ACTION_TOOLBAR::AddScaledSeparator ( wxWindow *  aWindow)

Add a separator that introduces space on either side to not squash the tools when scaled.

Parameters
aWindowis the window to get the scaling factor of

Definition at line 86 of file action_toolbar.cpp.

87 {
88  int scale = Pgm().GetCommonSettings()->m_Appearance.icon_scale;
89 
90  if( scale == 0 )
91  scale = KiIconScale( aWindow );
92 
93  if( scale > 4 )
94  AddSpacer( 16 * ( scale - 4 ) / 4 );
95 
96  AddSeparator();
97 
98  if( scale > 4 )
99  AddSpacer( 16 * ( scale - 4 ) / 4 );
100 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
Definition: bitmap.cpp:90
const int scale

References KiIconScale(), Pgm(), and scale.

Referenced by GERBVIEW_FRAME::ReCreateAuxiliaryToolbar(), PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar(), KICAD_MANAGER_FRAME::RecreateBaseHToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar(), LIB_VIEW_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar(), CVPCB_MAINFRAME::ReCreateHToolbar(), GERBVIEW_FRAME::ReCreateHToolbar(), LIB_EDIT_FRAME::ReCreateHToolbar(), SCH_EDIT_FRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateHToolbar(), KICAD_MANAGER_FRAME::RecreateLauncher(), EDA_3D_VIEWER::ReCreateMainToolbar(), PCB_EDIT_FRAME::ReCreateMicrowaveVToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateOptToolbar(), GERBVIEW_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateVToolbar(), PL_EDITOR_FRAME::ReCreateVToolbar(), LIB_EDIT_FRAME::ReCreateVToolbar(), SCH_EDIT_FRAME::ReCreateVToolbar(), and PCB_EDIT_FRAME::ReCreateVToolbar().

◆ AddToolContextMenu()

void ACTION_TOOLBAR::AddToolContextMenu ( const TOOL_ACTION aAction,
CONDITIONAL_MENU aMenu 
)

Add a context menu to a specific tool item on the toolbar.

This toolbar gets ownership of the menu object, and will delete it when the ClearToolbar() function is called.

Parameters
aActionis the action to get the menu
aMenuis the context menu

Definition at line 103 of file action_toolbar.cpp.

104 {
105  int toolId = aAction.GetId() + ACTION_ID;
106 
107  // If this is replacing an existing menu, delete the existing menu before adding the new one
108  const auto it = m_toolMenus.find( toolId );
109 
110  if( it != m_toolMenus.end() )
111  {
112  // Don't delete it if it is the same menu, just ignore this call
113  if( it->second == aMenu )
114  return;
115 
116  delete it->second;
117  }
118 
119  m_toolMenus[toolId] = aMenu;
120 }
std::map< int, CONDITIONAL_MENU * > m_toolMenus
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs

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

Referenced by PCB_EDIT_FRAME::ReCreateVToolbar().

◆ ClearToolbar()

void ACTION_TOOLBAR::ClearToolbar ( )

Clear the toolbar and remove all associated menus.

Definition at line 123 of file action_toolbar.cpp.

124 {
125  // Delete all the menus
126  for( auto it = m_toolMenus.begin(); it != m_toolMenus.end(); it++ )
127  delete it->second;
128 
129  // Clear the menu items and the actual toolbar
130  m_toolMenus.clear();
131  Clear();
132 }
std::map< int, CONDITIONAL_MENU * > m_toolMenus

References m_toolMenus.

Referenced by GERBVIEW_FRAME::ReCreateAuxiliaryToolbar(), KICAD_MANAGER_FRAME::RecreateBaseHToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar(), LIB_VIEW_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar(), CVPCB_MAINFRAME::ReCreateHToolbar(), GERBVIEW_FRAME::ReCreateHToolbar(), LIB_EDIT_FRAME::ReCreateHToolbar(), SCH_EDIT_FRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateHToolbar(), EDA_3D_VIEWER::ReCreateMainToolbar(), PCB_EDIT_FRAME::ReCreateMicrowaveVToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateOptToolbar(), LIB_EDIT_FRAME::ReCreateOptToolbar(), GERBVIEW_FRAME::ReCreateOptToolbar(), SCH_EDIT_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateVToolbar(), PL_EDITOR_FRAME::ReCreateVToolbar(), LIB_EDIT_FRAME::ReCreateVToolbar(), SCH_EDIT_FRAME::ReCreateVToolbar(), and PCB_EDIT_FRAME::ReCreateVToolbar().

◆ onToolEvent()

void ACTION_TOOLBAR::onToolEvent ( wxAuiToolBarEvent &  aEvent)
protected

The default tool event handler.

Definition at line 169 of file action_toolbar.cpp.

170 {
171  OPT_TOOL_EVENT evt;
172  wxString menuText;
173 
174  wxEventType type = aEvent.GetEventType();
175 
176  if( type == wxEVT_COMMAND_TOOL_CLICKED && aEvent.GetId() >= ACTION_ID )
177  {
178  const auto it = m_toolActions.find( aEvent.GetId() );
179 
180  if( it != m_toolActions.end() )
181  evt = it->second->MakeEvent();
182  }
183 
184  // forward the action/update event to the TOOL_MANAGER
185  if( evt && m_toolManager )
186  {
187  evt->SetHasPosition( false );
188  m_toolManager->ProcessEvent( *evt );
189  }
190  else
191  {
192  aEvent.Skip();
193  }
194 }
std::map< int, const TOOL_ACTION * > m_toolActions
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
TOOL_MANAGER * m_toolManager
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:556

References ACTION_ID, m_toolActions, m_toolManager, and TOOL_MANAGER::ProcessEvent().

Referenced by ACTION_TOOLBAR().

◆ onToolRightClick()

void ACTION_TOOLBAR::onToolRightClick ( wxAuiToolBarEvent &  aEvent)
protected

Handle a right-click on a menu item

Definition at line 197 of file action_toolbar.cpp.

198 {
199  int toolId = aEvent.GetToolId();
200 
201  // This means the event was not on a button
202  if( toolId == -1 )
203  return;
204 
205  const auto it = m_toolMenus.find( aEvent.GetId() );
206 
207  if( it == m_toolMenus.end() )
208  return;
209 
210  // Update and show the menu
211  CONDITIONAL_MENU* menu = it->second;
212  SELECTION dummySel;
213 
214  menu->Evaluate( dummySel );
215  menu->UpdateAll();
216  PopupMenu( menu );
217 
218  // Remove hovered item when the menu closes, otherwise it remains hovered even if the
219  // mouse is not on the toolbar
220  SetHoverItem( nullptr );
221 }
std::map< int, CONDITIONAL_MENU * > m_toolMenus
void UpdateAll()
Function UpdateAll() Runs update handlers for the menu and its submenus.
void Evaluate(SELECTION &aSelection)
Function Evaluate()

References CONDITIONAL_MENU::Evaluate(), m_toolMenus, and ACTION_MENU::UpdateAll().

Referenced by ACTION_TOOLBAR().

◆ SetToolBitmap()

void ACTION_TOOLBAR::SetToolBitmap ( const TOOL_ACTION aAction,
const wxBitmap &  aBitmap 
)

Function SetToolBitmap() Updates the bitmap of a particular tool.

Not icon-based because we use it for the custom-drawn layer pair bitmap.

Definition at line 135 of file action_toolbar.cpp.

136 {
137  int toolId = aAction.GetId() + ACTION_ID;
138  wxAuiToolBar::SetToolBitmap( toolId, aBitmap );
139 
140  // Set the disabled bitmap: we use the disabled bitmap version
141  // of aBitmap.
142  wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
143 
144  if( tb_item )
145  tb_item->SetDisabledBitmap( aBitmap.ConvertToDisabled() );
146 }
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs

References ACTION_ID, and TOOL_ACTION::GetId().

Referenced by PCB_EDIT_FRAME::PrepareLayerIndicator(), and KICAD_MANAGER_FRAME::RecreateLauncher().

◆ Toggle() [1/2]

void ACTION_TOOLBAR::Toggle ( const TOOL_ACTION aAction,
bool  aState 
)

Applies the default toggle action.

For checked items this is check/uncheck; for non-checked items it's enable/disable.

Definition at line 149 of file action_toolbar.cpp.

150 {
151  int toolId = aAction.GetId() + ACTION_ID;
152 
153  if( m_toolKinds[ toolId ] )
154  ToggleTool( toolId, aState );
155  else
156  EnableTool( toolId, aState );
157 }
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs
std::map< int, bool > m_toolKinds

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

Referenced by DISPLAY_FOOTPRINTS_FRAME::SyncToolbars(), FOOTPRINT_VIEWER_FRAME::SyncToolbars(), LIB_VIEW_FRAME::SyncToolbars(), KICAD_MANAGER_FRAME::SyncToolbars(), PL_EDITOR_FRAME::SyncToolbars(), EDA_3D_VIEWER::SyncToolbars(), FOOTPRINT_EDIT_FRAME::SyncToolbars(), CVPCB_MAINFRAME::SyncToolbars(), LIB_EDIT_FRAME::SyncToolbars(), GERBVIEW_FRAME::SyncToolbars(), PCB_EDIT_FRAME::SyncToolbars(), and SCH_EDIT_FRAME::SyncToolbars().

◆ Toggle() [2/2]

void ACTION_TOOLBAR::Toggle ( const TOOL_ACTION aAction,
bool  aEnabled,
bool  aChecked 
)

Definition at line 160 of file action_toolbar.cpp.

161 {
162  int toolId = aAction.GetId() + ACTION_ID;
163 
164  EnableTool( toolId, aEnabled );
165  ToggleTool( toolId, aEnabled && aChecked );
166 }
int GetId() const
Function GetId() Returns the unique id of the TOOL_ACTION object.
Definition: tool_action.h:100
static const int ACTION_ID
Tool items with ID higher than that are considered TOOL_ACTIONs

References ACTION_ID, and TOOL_ACTION::GetId().

Member Data Documentation

◆ ACTION_ID

const int ACTION_TOOLBAR::ACTION_ID = 10000
staticprotected

Tool items with ID higher than that are considered TOOL_ACTIONs

Definition at line 114 of file action_toolbar.h.

Referenced by Add(), AddButton(), AddToolContextMenu(), onToolEvent(), SetToolBitmap(), and Toggle().

◆ m_toolActions

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

Definition at line 118 of file action_toolbar.h.

Referenced by Add(), AddButton(), and onToolEvent().

◆ m_toolKinds

std::map<int, bool> ACTION_TOOLBAR::m_toolKinds
protected

Definition at line 117 of file action_toolbar.h.

Referenced by Add(), AddButton(), and Toggle().

◆ m_toolManager

TOOL_MANAGER* ACTION_TOOLBAR::m_toolManager
protected

Definition at line 116 of file action_toolbar.h.

Referenced by Add(), AddButton(), and onToolEvent().

◆ m_toolMenus

std::map<int, CONDITIONAL_MENU*> ACTION_TOOLBAR::m_toolMenus
protected

◆ TOGGLE


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