KiCad PCB EDA Suite
ACTION_TOOLBAR Class Reference

Define the structure of a toolbar with buttons that invoke ACTIONs. 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 SetAuiManager (wxAuiManager *aManager)
 Set the AUI manager that this toolbar belongs to. More...
 
void Add (const TOOL_ACTION &aAction, bool aIsToggleEntry=false, bool aIsCancellable=false)
 Add a TOOL_ACTION-based button to the toolbar. More...
 
void AddButton (const TOOL_ACTION &aAction)
 Add 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, std::unique_ptr< ACTION_MENU > aMenu)
 Add a context menu to a specific tool item on the toolbar. More...
 
void AddGroup (ACTION_GROUP *aGroup, bool aIsToggleEntry=false)
 Add a set of actions to a toolbar as a group. More...
 
void SelectAction (ACTION_GROUP *aGroup, const TOOL_ACTION &aAction)
 Select an action inside a group. More...
 
void UpdateControlWidth (int aID)
 Update the toolbar item width of a control using its best size. More...
 
void ClearToolbar ()
 Clear the toolbar and remove all associated menus. More...
 
void SetToolBitmap (const TOOL_ACTION &aAction, const wxBitmap &aBitmap)
 Updates the bitmap of a particular tool. More...
 
void Toggle (const TOOL_ACTION &aAction, bool aState)
 Apply the default toggle action. More...
 
void Toggle (const TOOL_ACTION &aAction, bool aEnabled, bool aChecked)
 
bool KiRealize ()
 Use this over Realize() to avoid a rendering glitch with fixed orientation toolbars. More...
 
void RefreshBitmaps ()
 Reload all the bitmaps for the tools (e.g. More...
 

Static Public Attributes

static constexpr bool TOGGLE = true
 
static constexpr bool CANCEL = true
 

Protected Member Functions

void doSelectAction (ACTION_GROUP *aGroup, const TOOL_ACTION &aAction)
 Update a group toolbar item to look like a specific action. More...
 
void popupPalette (wxAuiToolBarItem *aItem)
 Popup the ACTION_TOOLBAR_PALETTE associated with the ACTION_GROUP of the given toolbar item. More...
 
void onMouseClick (wxMouseEvent &aEvent)
 Handler for when a drag event occurs on an item. More...
 
void onItemDrag (wxAuiToolBarEvent &aEvent)
 The default tool event handler. More...
 
void onToolEvent (wxAuiToolBarEvent &aEvent)
 Handle a right-click on a menu item. More...
 
void onToolRightClick (wxAuiToolBarEvent &aEvent)
 Handle the button select inside the palette. More...
 
void onPaletteEvent (wxCommandEvent &aEvent)
 Handle the palette timer triggering. More...
 
void onTimerDone (wxTimerEvent &aEvent)
 Render the triangle in the lower-right corner that represents that an action palette is available for an item. More...
 
void OnCustomRender (wxDC &aDc, const wxAuiToolBarItem &aItem, const wxRect &aRect) override
 

Protected Attributes

wxTimer * m_paletteTimer
 
wxAuiManager * m_auiManager
 
TOOL_MANAGERm_toolManager
 
ACTION_TOOLBAR_PALETTEm_palette
 
std::map< int, bool > m_toolKinds
 
std::map< int, bool > m_toolCancellable
 
std::map< int, const TOOL_ACTION * > m_toolActions
 
std::map< int, ACTION_GROUP * > m_actionGroups
 
std::map< int, std::unique_ptr< ACTION_MENU > > m_toolMenus
 

Detailed Description

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

Definition at line 184 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 165 of file action_toolbar.cpp.

166  :
167  wxAuiToolBar( parent, id, pos, size, style ),
168  m_paletteTimer( nullptr ),
169  m_auiManager( nullptr ),
170  m_toolManager( parent->GetToolManager() ),
171  m_palette( nullptr )
172 {
173  m_paletteTimer = new wxTimer( this );
174 
175 #if !wxCHECK_VERSION( 3, 1, 0 )
176  // Custom art provider makes dark mode work on wx < 3.1
177  if( ADVANCED_CFG::GetCfg().m_AllowDarkMode )
178  {
179  WX_AUI_TOOLBAR_ART* newArt = new WX_AUI_TOOLBAR_ART();
180  SetArtProvider( newArt );
181  }
182 #endif
183 
184  Connect( wxEVT_COMMAND_TOOL_CLICKED, wxAuiToolBarEventHandler( ACTION_TOOLBAR::onToolEvent ),
185  NULL, this );
186  Connect( wxEVT_AUITOOLBAR_RIGHT_CLICK, wxAuiToolBarEventHandler( ACTION_TOOLBAR::onToolRightClick ),
187  NULL, this );
188  Connect( wxEVT_AUITOOLBAR_BEGIN_DRAG, wxAuiToolBarEventHandler( ACTION_TOOLBAR::onItemDrag ),
189  NULL, this );
190  Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( ACTION_TOOLBAR::onMouseClick ),
191  NULL, this );
192  Connect( wxEVT_LEFT_UP, wxMouseEventHandler( ACTION_TOOLBAR::onMouseClick ),
193  NULL, this );
194  Connect( m_paletteTimer->GetId(), wxEVT_TIMER, wxTimerEventHandler( ACTION_TOOLBAR::onTimerDone ),
195  NULL, this );
196 }
void onItemDrag(wxAuiToolBarEvent &aEvent)
The default tool event handler.
void onToolRightClick(wxAuiToolBarEvent &aEvent)
Handle the button select inside the palette.
void onTimerDone(wxTimerEvent &aEvent)
Render the triangle in the lower-right corner that represents that an action palette is available for...
void onToolEvent(wxAuiToolBarEvent &aEvent)
Handle a right-click on a menu item.
void onMouseClick(wxMouseEvent &aEvent)
Handler for when a drag event occurs on an item.
wxWidgets 3.1 has support for dark mode detection, but 3.0 doesn't.
#define NULL
ACTION_TOOLBAR_PALETTE * m_palette
wxAuiManager * m_auiManager
TOOL_MANAGER * m_toolManager
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
wxTimer * m_paletteTimer

References ADVANCED_CFG::GetCfg(), m_paletteTimer, NULL, onItemDrag(), onMouseClick(), onTimerDone(), onToolEvent(), and onToolRightClick().

◆ ~ACTION_TOOLBAR()

ACTION_TOOLBAR::~ACTION_TOOLBAR ( )
virtual

Definition at line 199 of file action_toolbar.cpp.

200 {
201  delete m_paletteTimer;
202 
203  // Clear all the maps keeping track of our items on the toolbar
204  m_toolMenus.clear();
205  m_actionGroups.clear();
206  m_toolCancellable.clear();
207  m_toolKinds.clear();
208  m_toolActions.clear();
209 }
std::map< int, const TOOL_ACTION * > m_toolActions
std::map< int, bool > m_toolCancellable
std::map< int, std::unique_ptr< ACTION_MENU > > m_toolMenus
std::map< int, ACTION_GROUP * > m_actionGroups
std::map< int, bool > m_toolKinds
wxTimer * m_paletteTimer

References m_actionGroups, m_paletteTimer, m_toolActions, m_toolCancellable, m_toolKinds, and m_toolMenus.

Member Function Documentation

◆ Add()

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

Add a TOOL_ACTION-based button to the toolbar.

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

Parameters
aActionis the action to add.
aIsToggleEntrymakes the toolbar item a toggle entry when true.
aIsCancellablewhen true, cancels the tool if clicked when tool is active.

Definition at line 212 of file action_toolbar.cpp.

213 {
214  wxASSERT( GetParent() );
215  wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ), "aIsCancellable requires aIsToggleEntry" );
216 
217  int toolId = aAction.GetUIId();
218 
219  AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), GetParent() ),
220  aAction.GetDescription(), aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL );
221 
222  m_toolKinds[ toolId ] = aIsToggleEntry;
223  m_toolActions[ toolId ] = &aAction;
224  m_toolCancellable[ toolId ] = aIsCancellable;
225 }
int GetUIId() const
Definition: tool_action.h:112
std::map< int, const TOOL_ACTION * > m_toolActions
std::map< int, bool > m_toolCancellable
const BITMAPS GetIcon() const
Return an icon associated with the action.
Definition: tool_action.h:169
wxString GetDescription(bool aIncludeHotkey=true) const
Definition: tool_action.cpp:84
std::map< int, bool > m_toolKinds
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:147

References TOOL_ACTION::GetDescription(), TOOL_ACTION::GetIcon(), TOOL_ACTION::GetUIId(), KiScaledBitmap(), m_toolActions, m_toolCancellable, and m_toolKinds.

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

◆ AddButton()

void ACTION_TOOLBAR::AddButton ( const TOOL_ACTION aAction)

Add a large button such as used in the KiCad Manager Frame's launch bar.

Parameters
aAction

Definition at line 228 of file action_toolbar.cpp.

229 {
230  int toolId = aAction.GetUIId();
231 
232  AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), GetParent() ),
233  aAction.GetName(), wxITEM_NORMAL );
234 
235  m_toolKinds[ toolId ] = false;
236  m_toolActions[ toolId ] = &aAction;
237 }
int GetUIId() const
Definition: tool_action.h:112
std::map< int, const TOOL_ACTION * > m_toolActions
const BITMAPS GetIcon() const
Return an icon associated with the action.
Definition: tool_action.h:169
std::map< int, bool > m_toolKinds
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:147
const std::string & GetName() const
Return name of the action.
Definition: tool_action.h:83

References TOOL_ACTION::GetIcon(), TOOL_ACTION::GetName(), TOOL_ACTION::GetUIId(), KiScaledBitmap(), m_toolActions, and m_toolKinds.

◆ AddGroup()

void ACTION_TOOLBAR::AddGroup ( ACTION_GROUP aGroup,
bool  aIsToggleEntry = false 
)

Add a set of actions to a toolbar as a group.

One action from the group will be displayed at a time.

Parameters
aGroupis the group to add. The first action in the group will be the first shown on the toolbar.
aIsToggleEntrymakes the toolbar item a toggle entry when true

Definition at line 266 of file action_toolbar.cpp.

267 {
268  int groupId = aGroup->GetUIId();
269  const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction();
270 
271  wxASSERT( GetParent() );
272  wxASSERT( defaultAction );
273 
274  m_toolKinds[ groupId ] = aIsToggleEntry;
275  m_toolActions[ groupId ] = defaultAction;
276  m_actionGroups[ groupId ] = aGroup;
277 
278  // Add the main toolbar item representing the group
279  AddTool( groupId, wxEmptyString, KiScaledBitmap( defaultAction->GetIcon(), GetParent() ),
280  wxEmptyString, aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL );
281 
282  // Select the default action
283  doSelectAction( aGroup, *defaultAction );
284 }
std::map< int, const TOOL_ACTION * > m_toolActions
void doSelectAction(ACTION_GROUP *aGroup, const TOOL_ACTION &aAction)
Update a group toolbar item to look like a specific action.
const BITMAPS GetIcon() const
Return an icon associated with the action.
Definition: tool_action.h:169
const TOOL_ACTION * GetDefaultAction() const
Get the default action to use when first creating this group's toolbar palette icon.
std::map< int, ACTION_GROUP * > m_actionGroups
Represent a single user action.
Definition: tool_action.h:49
int GetUIId() const
Get the ID used in the UI to reference this group.
std::map< int, bool > m_toolKinds
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:147

References doSelectAction(), ACTION_GROUP::GetDefaultAction(), TOOL_ACTION::GetIcon(), ACTION_GROUP::GetUIId(), KiScaledBitmap(), m_actionGroups, m_toolActions, and m_toolKinds.

Referenced by PCB_EDIT_FRAME::ReCreateVToolbar().

◆ 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 240 of file action_toolbar.cpp.

241 {
242  int scale = Pgm().GetCommonSettings()->m_Appearance.icon_scale;
243 
244  if( scale == 0 )
245  scale = KiIconScale( aWindow );
246 
247  if( scale > 4 )
248  AddSpacer( 16 * ( scale - 4 ) / 4 );
249 
250  AddSeparator();
251 
252  if( scale > 4 )
253  AddSpacer( 16 * ( scale - 4 ) / 4 );
254 }
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
Definition: bitmap.cpp:121
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
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(), GERBVIEW_FRAME::ReCreateHToolbar(), SYMBOL_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), SCH_EDIT_FRAME::ReCreateHToolbar(), FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar(), SYMBOL_EDIT_FRAME::ReCreateHToolbar(), CVPCB_MAINFRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateHToolbar(), EDA_3D_VIEWER::ReCreateMainToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateOptToolbar(), GERBVIEW_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateVToolbar(), SCH_EDIT_FRAME::ReCreateVToolbar(), PL_EDITOR_FRAME::ReCreateVToolbar(), SYMBOL_EDIT_FRAME::ReCreateVToolbar(), and PCB_EDIT_FRAME::ReCreateVToolbar().

◆ AddToolContextMenu()

void ACTION_TOOLBAR::AddToolContextMenu ( const TOOL_ACTION aAction,
std::unique_ptr< ACTION_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 257 of file action_toolbar.cpp.

259 {
260  int toolId = aAction.GetUIId();
261 
262  m_toolMenus[toolId] = std::move( aMenu );
263 }
int GetUIId() const
Definition: tool_action.h:112
std::map< int, std::unique_ptr< ACTION_MENU > > m_toolMenus

References TOOL_ACTION::GetUIId(), and m_toolMenus.

Referenced by FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar(), SCH_EDIT_FRAME::ReCreateOptToolbar(), SYMBOL_EDIT_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateOptToolbar(), and PCB_EDIT_FRAME::ReCreateVToolbar().

◆ ClearToolbar()

void ACTION_TOOLBAR::ClearToolbar ( )

Clear the toolbar and remove all associated menus.

Definition at line 370 of file action_toolbar.cpp.

371 {
372  // Clear all the maps keeping track of our items on the toolbar
373  m_toolMenus.clear();
374  m_actionGroups.clear();
375  m_toolCancellable.clear();
376  m_toolKinds.clear();
377  m_toolActions.clear();
378 
379  // Remove the actual tools from the toolbar
380  Clear();
381 }
std::map< int, const TOOL_ACTION * > m_toolActions
std::map< int, bool > m_toolCancellable
std::map< int, std::unique_ptr< ACTION_MENU > > m_toolMenus
std::map< int, ACTION_GROUP * > m_actionGroups
std::map< int, bool > m_toolKinds

References m_actionGroups, m_toolActions, m_toolCancellable, m_toolKinds, and m_toolMenus.

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

◆ doSelectAction()

void ACTION_TOOLBAR::doSelectAction ( ACTION_GROUP aGroup,
const TOOL_ACTION aAction 
)
protected

Update a group toolbar item to look like a specific action.

Note: This function does not verify that the action is inside the group.

Definition at line 301 of file action_toolbar.cpp.

302 {
303  wxASSERT( GetParent() );
304 
305  int groupId = aGroup->GetUIId();
306 
307  wxAuiToolBarItem* item = FindTool( groupId );
308 
309  if( !item )
310  return;
311 
312  // Update the item information
313  item->SetShortHelp( aAction.GetDescription() );
314  item->SetBitmap( KiScaledBitmap( aAction.GetIcon(), GetParent() ) );
315  item->SetDisabledBitmap( item->GetBitmap().ConvertToDisabled() );
316 
317  // Register a new handler with the new UI conditions
318  if( m_toolManager )
319  {
320  const ACTION_CONDITIONS* cond = m_toolManager->GetActionManager()->GetCondition( aAction );
321 
322  wxASSERT_MSG( cond, wxString::Format( "Missing UI condition for action %s",
323  aAction.GetName() ) );
324 
327  }
328 
329  // Update the currently selected action
330  m_toolActions[ groupId ] = &aAction;
331 
332  Refresh();
333 }
virtual void UnregisterUIUpdateHandler(const TOOL_ACTION &aAction)
Unregister a UI handler for an action that was registered using RegisterUIUpdateHandler.
Definition: tools_holder.h:84
std::map< int, const TOOL_ACTION * > m_toolActions
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
const BITMAPS GetIcon() const
Return an icon associated with the action.
Definition: tool_action.h:169
wxString GetDescription(bool aIncludeHotkey=true) const
Definition: tool_action.cpp:84
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
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:300
TOOL_MANAGER * m_toolManager
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
int GetUIId() const
Get the ID used in the UI to reference this group.
ACTION_MANAGER * GetActionManager() const
Definition: tool_manager.h:197
const ACTION_CONDITIONS * GetCondition(const TOOL_ACTION &aAction) const
Get the conditions to use for a specific tool action.
virtual void RegisterUIUpdateHandler(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Register an action's update conditions with the UI layer to allow the UI to appropriately display the...
Definition: tools_holder.h:64
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:147
const std::string & GetName() const
Return name of the action.
Definition: tool_action.h:83

References Format(), TOOL_MANAGER::GetActionManager(), ACTION_MANAGER::GetCondition(), TOOL_ACTION::GetDescription(), TOOL_ACTION::GetIcon(), TOOL_ACTION::GetName(), TOOL_MANAGER::GetToolHolder(), ACTION_GROUP::GetUIId(), KiScaledBitmap(), m_toolActions, m_toolManager, Refresh(), TOOLS_HOLDER::RegisterUIUpdateHandler(), and TOOLS_HOLDER::UnregisterUIUpdateHandler().

Referenced by AddGroup(), onPaletteEvent(), and SelectAction().

◆ KiRealize()

bool ACTION_TOOLBAR::KiRealize ( )

Use this over Realize() to avoid a rendering glitch with fixed orientation toolbars.

The standard Realize() draws both horizontal and vertical to determine sizing However with many icons, potato PCs, etc, you can actually see that double draw This custom function avoids the double draw if the HORIZONTAL or VERTICAL toolbar properties are set.

Definition at line 748 of file action_toolbar.cpp.

749 {
750  wxClientDC dc( this );
751  if( !dc.IsOk() )
752  return false;
753 
754  // calculate hint sizes for both horizontal and vertical
755  // in the order that leaves toolbar in correct final state
756 
757  // however, skip calculating alternate orientations if we dont need them due to window style
758  bool retval = true;
759  if( m_orientation == wxHORIZONTAL )
760  {
761  if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
762  {
763  m_vertHintSize = GetSize();
764  retval = RealizeHelper( dc, false );
765  }
766 
767  if( retval && RealizeHelper( dc, true ) )
768  {
769  m_horzHintSize = GetSize();
770  }
771  else
772  {
773  retval = false;
774  }
775  }
776  else
777  {
778  if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
779  {
780  m_horzHintSize = GetSize();
781  retval = RealizeHelper( dc, true );
782  }
783 
784  if( retval && RealizeHelper( dc, false ) )
785  {
786  m_vertHintSize = GetSize();
787  }
788  else
789  {
790  retval = false;
791  }
792  }
793 
794  Refresh( false );
795  return retval;
796 }
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...

References Refresh().

Referenced by GERBVIEW_FRAME::ReCreateAuxiliaryToolbar(), PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar(), GERBVIEW_FRAME::ReCreateHToolbar(), SYMBOL_VIEWER_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), SCH_EDIT_FRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateHToolbar(), EDA_3D_VIEWER::ReCreateMainToolbar(), GERBVIEW_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_VIEWER_FRAME::ReCreateOptToolbar(), SCH_EDIT_FRAME::ReCreateOptToolbar(), PL_EDITOR_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateVToolbar(), SCH_EDIT_FRAME::ReCreateVToolbar(), PL_EDITOR_FRAME::ReCreateVToolbar(), and PCB_EDIT_FRAME::ReCreateVToolbar().

◆ OnCustomRender()

void ACTION_TOOLBAR::OnCustomRender ( wxDC &  aDc,
const wxAuiToolBarItem &  aItem,
const wxRect &  aRect 
)
overrideprotected

Definition at line 710 of file action_toolbar.cpp.

712 {
713  auto it = m_actionGroups.find( aItem.GetId() );
714 
715  if( it == m_actionGroups.end() )
716  return;
717 
718  // Choose the color to draw the triangle
719  wxColour clr;
720 
721  if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
722  clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
723  else
724  clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
725 
726  // Must set both the pen (for the outline) and the brush (for the polygon fill)
727  aDc.SetPen( wxPen( clr ) );
728  aDc.SetBrush( wxBrush( clr ) );
729 
730  // Make the side length of the triangle approximately 1/5th of the bitmap
731  int sideLength = KiROUND( aRect.height / 5.0 );
732 
733  // This will create a triangle with its point at the bottom right corner,
734  // and its other two corners along the right and bottom sides
735  wxPoint btmRight = aRect.GetBottomRight();
736  wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
737  wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
738 
739  wxPointList points;
740  points.Append( &btmRight );
741  points.Append( &topCorner );
742  points.Append( &btmCorner );
743 
744  aDc.DrawPolygon( &points );
745 }
std::map< int, ACTION_GROUP * > m_actionGroups
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68

References KiROUND(), and m_actionGroups.

◆ onItemDrag()

void ACTION_TOOLBAR::onItemDrag ( wxAuiToolBarEvent &  aEvent)
protected

The default tool event handler.

Definition at line 526 of file action_toolbar.cpp.

527 {
528  int toolId = aEvent.GetToolId();
529 
530  if( m_actionGroups.find( toolId ) != m_actionGroups.end() )
531  {
532  wxAuiToolBarItem* item = FindTool( toolId );
533 
534  // Use call after because opening the palette from a mouse handler
535  // creates a weird mouse state that causes problems on OSX.
536  CallAfter( &ACTION_TOOLBAR::popupPalette, item );
537 
538  // Don't skip this event since we are handling it
539  return;
540  }
541 
542  // Skip since we don't care about it
543  aEvent.Skip();
544 }
void popupPalette(wxAuiToolBarItem *aItem)
Popup the ACTION_TOOLBAR_PALETTE associated with the ACTION_GROUP of the given toolbar item.
std::map< int, ACTION_GROUP * > m_actionGroups

References m_actionGroups, and popupPalette().

Referenced by ACTION_TOOLBAR().

◆ onMouseClick()

void ACTION_TOOLBAR::onMouseClick ( wxMouseEvent &  aEvent)
protected

Handler for when a drag event occurs on an item.

Definition at line 498 of file action_toolbar.cpp.

499 {
500  wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
501 
502  if( item )
503  {
504  // Ensure there is no active palette
505  if( m_palette )
506  {
507  m_palette->Hide();
508  m_palette->Destroy();
509  m_palette = nullptr;
510  }
511 
512  // Start the popup conditions if it is a left mouse click and the tool clicked is a group
513  if( aEvent.LeftDown() && ( m_actionGroups.find( item->GetId() ) != m_actionGroups.end() ) )
514  m_paletteTimer->StartOnce( PALETTE_OPEN_DELAY );
515 
516  // Clear the popup conditions if it is a left up, because that implies a click happened
517  if( aEvent.LeftUp() )
518  m_paletteTimer->Stop();
519  }
520 
521  // Skip the event so wx can continue processing the mouse event
522  aEvent.Skip();
523 }
#define PALETTE_OPEN_DELAY
ACTION_TOOLBAR_PALETTE * m_palette
std::map< int, ACTION_GROUP * > m_actionGroups
wxTimer * m_paletteTimer

References m_actionGroups, m_palette, m_paletteTimer, and PALETTE_OPEN_DELAY.

Referenced by ACTION_TOOLBAR().

◆ onPaletteEvent()

void ACTION_TOOLBAR::onPaletteEvent ( wxCommandEvent &  aEvent)
protected

Handle the palette timer triggering.

Definition at line 559 of file action_toolbar.cpp.

560 {
561  if( !m_palette )
562  return;
563 
564  OPT_TOOL_EVENT evt;
566 
567  // Find the action corresponding to the button press
568  auto actionIt = std::find_if( group->GetActions().begin(), group->GetActions().end(),
569  [=]( const TOOL_ACTION* aAction )
570  {
571  return aAction->GetUIId() == aEvent.GetId();
572  } );
573 
574  if( actionIt != group->GetActions().end() )
575  {
576  const TOOL_ACTION* action = *actionIt;
577 
578  // Dispatch a tool event
579  evt = action->MakeEvent();
580  evt->SetHasPosition( false );
581  m_toolManager->ProcessEvent( *evt );
582 
583  // Update the main toolbar item with the selected action
584  doSelectAction( group, *action );
585  }
586 
587  // Hide the palette
588  m_palette->Hide();
589  m_palette->Destroy();
590  m_palette = nullptr;
591 }
ACTION_GROUP * GetGroup()
A group of actions that will be displayed together on a toolbar palette.
void doSelectAction(ACTION_GROUP *aGroup, const TOOL_ACTION &aAction)
Update a group toolbar item to look like a specific action.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
ACTION_TOOLBAR_PALETTE * m_palette
TOOL_MANAGER * m_toolManager
Represent a single user action.
Definition: tool_action.h:49
TOOL_EVENT MakeEvent() const
Return the event associated with the action (i.e.
Definition: tool_action.h:123
void SetHasPosition(bool aHasPosition)
Returns if the action associated with this event should be treated as immediate regardless of the cur...
Definition: tool_event.h:262
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:569

References doSelectAction(), ACTION_TOOLBAR_PALETTE::GetGroup(), group, m_palette, m_toolManager, TOOL_ACTION::MakeEvent(), TOOL_MANAGER::ProcessEvent(), and TOOL_EVENT::SetHasPosition().

Referenced by popupPalette().

◆ onTimerDone()

void ACTION_TOOLBAR::onTimerDone ( wxTimerEvent &  aEvent)
protected

Render the triangle in the lower-right corner that represents that an action palette is available for an item.

Definition at line 547 of file action_toolbar.cpp.

548 {
549  // We need to search for the tool using the client coordinates
550  wxPoint mousePos = ScreenToClient( wxGetMousePosition() );
551 
552  wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
553 
554  if( item )
555  popupPalette( item );
556 }
void popupPalette(wxAuiToolBarItem *aItem)
Popup the ACTION_TOOLBAR_PALETTE associated with the ACTION_GROUP of the given toolbar item.

References popupPalette().

Referenced by ACTION_TOOLBAR().

◆ onToolEvent()

void ACTION_TOOLBAR::onToolEvent ( wxAuiToolBarEvent &  aEvent)
protected

Handle a right-click on a menu item.

Definition at line 418 of file action_toolbar.cpp.

419 {
420  int id = aEvent.GetId();
421  wxEventType type = aEvent.GetEventType();
422  OPT_TOOL_EVENT evt;
423 
424  bool handled = false;
425 
426  if( m_toolManager && type == wxEVT_COMMAND_TOOL_CLICKED && id >= TOOL_ACTION::GetBaseUIId() )
427  {
428  const auto actionIt = m_toolActions.find( id );
429 
430  // The toolbar item is toggled before the event is sent, so we check for it not being
431  // toggled to see if it was toggled originally
432  if( m_toolCancellable[id] && !GetToolToggled( id ) )
433  {
434  // Send a cancel event
436  handled = true;
437  }
438  else if( actionIt != m_toolActions.end() )
439  {
440  // Dispatch a tool event
441  evt = actionIt->second->MakeEvent();
442  evt->SetHasPosition( false );
443  m_toolManager->ProcessEvent( *evt );
444  handled = true;
445  }
446  }
447 
448  // Skip the event if we don't handle it
449  if( !handled )
450  aEvent.Skip();
451 }
std::map< int, const TOOL_ACTION * > m_toolActions
static int GetBaseUIId()
Definition: tool_action.h:117
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
std::map< int, bool > m_toolCancellable
TOOL_MANAGER * m_toolManager
void CancelTool()
Send a cancel event to the tool currently at the top of the tool stack.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:569

References TOOL_MANAGER::CancelTool(), TOOL_ACTION::GetBaseUIId(), m_toolActions, m_toolCancellable, m_toolManager, and TOOL_MANAGER::ProcessEvent().

Referenced by ACTION_TOOLBAR().

◆ onToolRightClick()

void ACTION_TOOLBAR::onToolRightClick ( wxAuiToolBarEvent &  aEvent)
protected

Handle the button select inside the palette.

Definition at line 454 of file action_toolbar.cpp.

455 {
456  int toolId = aEvent.GetToolId();
457 
458  // This means the event was not on a button
459  if( toolId == -1 )
460  return;
461 
462  // Ensure that the ID used maps to a proper tool ID.
463  // If right-clicked on a group item, this is needed to get the ID of the currently selected
464  // action, since the event's ID is that of the group.
465  const auto actionIt = m_toolActions.find( toolId );
466 
467  if( actionIt != m_toolActions.end() )
468  toolId = actionIt->second->GetUIId();
469 
470  // Find the menu for the action
471  const auto menuIt = m_toolMenus.find( toolId );
472 
473  if( menuIt == m_toolMenus.end() )
474  return;
475 
476  // Update and show the menu
477  std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
478 
479  // Get the actual menu pointer to show it
480  ACTION_MENU* menu = owningMenu.get();
481  SELECTION dummySel;
482 
483  if( CONDITIONAL_MENU* condMenu = dynamic_cast<CONDITIONAL_MENU*>( menu ) )
484  condMenu->Evaluate( dummySel );
485 
486  menu->UpdateAll();
487  PopupMenu( menu );
488 
489  // Remove hovered item when the menu closes, otherwise it remains hovered even if the
490  // mouse is not on the toolbar
491  SetHoverItem( nullptr );
492 }
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:47
void UpdateAll()
Run update handlers for the menu and its submenus.
std::map< int, const TOOL_ACTION * > m_toolActions
std::map< int, std::unique_ptr< ACTION_MENU > > m_toolMenus

References m_toolActions, m_toolMenus, and ACTION_MENU::UpdateAll().

Referenced by ACTION_TOOLBAR().

◆ popupPalette()

void ACTION_TOOLBAR::popupPalette ( wxAuiToolBarItem *  aItem)
protected

Popup the ACTION_TOOLBAR_PALETTE associated with the ACTION_GROUP of the given toolbar item.

Handler for a mouse up/down event

Definition at line 594 of file action_toolbar.cpp.

595 {
596  // Clear all popup conditions
597  m_paletteTimer->Stop();
598 
599  wxWindow* toolParent = dynamic_cast<wxWindow*>( m_toolManager->GetToolHolder() );
600 
601  wxASSERT( GetParent() );
602  wxASSERT( m_auiManager );
603  wxASSERT( toolParent );
604 
605  // Ensure the item we are using for the palette has a group associated with it.
606  const auto it = m_actionGroups.find( aItem->GetId() );
607 
608  if( it == m_actionGroups.end() )
609  return;
610 
611  ACTION_GROUP* group = it->second;
612 
613  wxAuiPaneInfo& pane = m_auiManager->GetPane( this );
614 
615  // We use the size of the toolbar items for our palette buttons
616  wxRect toolRect = GetToolRect( aItem->GetId() );
617 
618  // The position for the palette window must be in screen coordinates
619  wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
620 
621  // True for vertical buttons, false for horizontal
622  bool dir = true;
623  size_t numActions = group->m_actions.size();
624 
625  // The size of the palette in the long dimension
626  int paletteLongDim = ( 2 * PALETTE_BORDER ) // The border on all sides of the buttons
627  + ( BUTTON_BORDER ) // The border on the start of the buttons
628  + ( numActions * BUTTON_BORDER ) // The other button borders
629  + ( numActions * toolRect.GetHeight() ); // The size of the buttons
630 
631  // Determine the position of the top left corner of the palette window
632  switch( pane.dock_direction )
633  {
634  case wxAUI_DOCK_TOP:
635  // Top toolbars need to shift the palette window down by the toolbar padding
636  dir = true; // Buttons are vertical in the palette
637  pos = ClientToScreen( toolRect.GetBottomLeft() );
638  pos += wxPoint( -PALETTE_BORDER, // Shift left to align the button edges
639  m_bottomPadding ); // Shift down to move away from the toolbar
640  break;
641 
642  case wxAUI_DOCK_BOTTOM:
643  // Bottom toolbars need to shift the palette window up by its height (all buttons + border + toolbar padding)
644  dir = true; // Buttons are vertical in the palette
645  pos = ClientToScreen( toolRect.GetTopLeft() );
646  pos += wxPoint( -PALETTE_BORDER, // Shift left to align the button
647  -( paletteLongDim + m_topPadding ) ); // Shift up by the entire length of the palette
648  break;
649 
650  case wxAUI_DOCK_LEFT:
651  // Left toolbars need to shift the palette window up by the toolbar padding
652  dir = false; // Buttons are horizontal in the palette
653  pos = ClientToScreen( toolRect.GetTopRight() );
654  pos += wxPoint( m_rightPadding, // Shift right to move away from the toolbar
655  -( PALETTE_BORDER ) ); // Shift up to align the button tops
656  break;
657 
658  case wxAUI_DOCK_RIGHT:
659  // Right toolbars need to shift the palette window left by its width (all buttons + border + toolbar padding)
660  dir = false; // Buttons are horizontal in the palette
661  pos = ClientToScreen( toolRect.GetTopLeft() );
662  pos += wxPoint( -( paletteLongDim + m_leftPadding ), // Shift left by the entire length of the palette
663  -( PALETTE_BORDER ) ); // Shift up to align the button
664  break;
665  }
666 
667  m_palette = new ACTION_TOOLBAR_PALETTE( GetParent(), dir );
668 
669  // We handle the button events in the toolbar class, so connect the right handler
671  m_palette->SetButtonSize( toolRect );
672  m_palette->Connect( wxEVT_BUTTON, wxCommandEventHandler( ACTION_TOOLBAR::onPaletteEvent ),
673  NULL, this );
674 
675 
676  // Add the actions in the group to the palette and update their enabled state
677  // We purposely don't check items in the palette
678  for( const TOOL_ACTION* action : group->m_actions )
679  {
680  wxUpdateUIEvent evt( action->GetUIId() );
681 
682  toolParent->ProcessWindowEvent( evt );
683 
684  m_palette->AddAction( *action );
685 
686  if( evt.GetSetEnabled() )
687  m_palette->EnableAction( *action, evt.GetEnabled() );
688  }
689 
690  // Release the mouse to ensure the first click will be recognized in the palette
691  ReleaseMouse();
692 
693  m_palette->SetPosition( pos );
694  m_palette->Popup();
695 
696  // Clear the mouse state on the toolbar because otherwise wxWidgets gets confused
697  // and won't properly display any highlighted items after the palette is closed.
698  // (This is the equivalent of calling the DoResetMouseState() private function)
699  RefreshOverflowState();
700  SetHoverItem( nullptr );
701  SetPressedItem( nullptr );
702 
703  m_dragging = false;
704  m_tipItem = nullptr;
705  m_actionPos = wxPoint( -1, -1 );
706  m_actionItem = nullptr;
707 }
int GetUIId() const
Definition: tool_action.h:112
void SetButtonSize(wxRect &aSize)
Set the size all the buttons on this palette should be.
A group of actions that will be displayed together on a toolbar palette.
void AddAction(const TOOL_ACTION &aAction)
Add an action to the palette.
#define NULL
void SetGroup(ACTION_GROUP *aGroup)
Set the action group that this palette contains the actions for.
ACTION_TOOLBAR_PALETTE * m_palette
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:300
wxAuiManager * m_auiManager
TOOL_MANAGER * m_toolManager
std::map< int, ACTION_GROUP * > m_actionGroups
Represent a single user action.
Definition: tool_action.h:49
#define PALETTE_BORDER
void Popup(wxWindow *aFocus=nullptr) override
Popup this window.
#define BUTTON_BORDER
void EnableAction(const TOOL_ACTION &aAction, bool aEnable=true)
Enable the button for an action on the palette.
wxTimer * m_paletteTimer
A popup window that contains a row of toolbar-like buttons for the user to choose from.
void onPaletteEvent(wxCommandEvent &aEvent)
Handle the palette timer triggering.

References ACTION_TOOLBAR_PALETTE::AddAction(), BUTTON_BORDER, ACTION_TOOLBAR_PALETTE::EnableAction(), TOOL_MANAGER::GetToolHolder(), TOOL_ACTION::GetUIId(), group, m_actionGroups, m_auiManager, m_palette, m_paletteTimer, m_toolManager, NULL, onPaletteEvent(), PALETTE_BORDER, ACTION_TOOLBAR_PALETTE::Popup(), ACTION_TOOLBAR_PALETTE::SetButtonSize(), and ACTION_TOOLBAR_PALETTE::SetGroup().

Referenced by onItemDrag(), and onTimerDone().

◆ RefreshBitmaps()

void ACTION_TOOLBAR::RefreshBitmaps ( )

Reload all the bitmaps for the tools (e.g.

when switching icon themes)

Definition at line 799 of file action_toolbar.cpp.

800 {
801  for( const std::pair<int, const TOOL_ACTION*> pair : m_toolActions )
802  {
803  wxAuiToolBarItem* tool = FindTool( pair.first );
804 
805  wxBitmap bmp = KiScaledBitmap( pair.second->GetIcon(), GetParent() );
806 
807  tool->SetBitmap( bmp );
808  tool->SetDisabledBitmap( bmp.ConvertToDisabled() );
809  }
810 
811  Refresh();
812 }
std::map< int, const TOOL_ACTION * > m_toolActions
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:147

References KiScaledBitmap(), m_toolActions, and Refresh().

◆ SelectAction()

void ACTION_TOOLBAR::SelectAction ( ACTION_GROUP aGroup,
const TOOL_ACTION aAction 
)

Select an action inside a group.

Parameters
aGroupis the group that contains the action
aActionis the action inside the group

Definition at line 287 of file action_toolbar.cpp.

288 {
289  bool valid = std::any_of( aGroup->m_actions.begin(), aGroup->m_actions.end(),
290  [&]( const TOOL_ACTION* action2 ) -> bool
291  {
292  // For some reason, we can't compare the actions directly
293  return aAction.GetId() == action2->GetId();
294  } );
295 
296  if( valid )
297  doSelectAction( aGroup, aAction );
298 }
void doSelectAction(ACTION_GROUP *aGroup, const TOOL_ACTION &aAction)
Update a group toolbar item to look like a specific action.
std::vector< const TOOL_ACTION * > m_actions
int GetId() const
Return the unique id of the TOOL_ACTION object.
Definition: tool_action.h:103
Represent a single user action.
Definition: tool_action.h:49

References doSelectAction(), TOOL_ACTION::GetId(), and ACTION_GROUP::m_actions.

◆ SetAuiManager()

void ACTION_TOOLBAR::SetAuiManager ( wxAuiManager *  aManager)
inline

◆ SetToolBitmap()

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

Updates the bitmap of a particular tool.

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

Definition at line 384 of file action_toolbar.cpp.

385 {
386  int toolId = aAction.GetUIId();
387  wxAuiToolBar::SetToolBitmap( toolId, aBitmap );
388 
389  // Set the disabled bitmap: we use the disabled bitmap version
390  // of aBitmap.
391  wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
392 
393  if( tb_item )
394  tb_item->SetDisabledBitmap( aBitmap.ConvertToDisabled() );
395 }
int GetUIId() const
Definition: tool_action.h:112

References TOOL_ACTION::GetUIId().

Referenced by PCB_EDIT_FRAME::PrepareLayerIndicator().

◆ Toggle() [1/2]

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

Apply the default toggle action.

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

Definition at line 398 of file action_toolbar.cpp.

399 {
400  int toolId = aAction.GetUIId();
401 
402  if( m_toolKinds[ toolId ] )
403  ToggleTool( toolId, aState );
404  else
405  EnableTool( toolId, aState );
406 }
int GetUIId() const
Definition: tool_action.h:112
std::map< int, bool > m_toolKinds

References TOOL_ACTION::GetUIId(), and m_toolKinds.

◆ Toggle() [2/2]

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

Definition at line 409 of file action_toolbar.cpp.

410 {
411  int toolId = aAction.GetUIId();
412 
413  EnableTool( toolId, aEnabled );
414  ToggleTool( toolId, aEnabled && aChecked );
415 }
int GetUIId() const
Definition: tool_action.h:112

References TOOL_ACTION::GetUIId().

◆ UpdateControlWidth()

void ACTION_TOOLBAR::UpdateControlWidth ( int  aID)

Update the toolbar item width of a control using its best size.

Parameters
aIDis the ID of the toolbar item to update the width for

Definition at line 336 of file action_toolbar.cpp.

337 {
338  wxAuiToolBarItem* item = FindTool( aID );
339  wxASSERT_MSG( item, wxString::Format( "No toolbar item found for ID %d", aID ) );
340 
341  // The control on the toolbar is stored inside the window field of the item
342  wxControl* control = dynamic_cast<wxControl*>( item->GetWindow() );
343  wxASSERT_MSG( control, wxString::Format( "No control located in toolbar item with ID %d", aID ) );
344 
345  // Update the size the item has stored using the best size of the control
346  wxSize bestSize = control->GetBestSize();
347  item->SetMinSize( bestSize );
348 
349  // Update the sizer item sizes
350  // This is a bit convoluted because there are actually 2 sizers that need to be updated:
351  // 1. The main sizer that is used for the entire toolbar (this sizer item can be found in the
352  // toolbar item)
353  if( wxSizerItem* szrItem = item->GetSizerItem() )
354  szrItem->SetMinSize( bestSize );
355 
356  // 2. The controls have a second sizer that allows for padding above/below the control with stretch
357  // space, so we also need to update the sizer item for the control in that sizer with the new size.
358  // We let wx do the search for us, since SetItemMinSize is recursive and will locate the control
359  // on that sizer.
360  if( m_sizer )
361  {
362  m_sizer->SetItemMinSize( control, bestSize );
363 
364  // Now actually update the toolbar with the new sizes
365  m_sizer->Layout();
366  }
367 }
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

References Format().

Referenced by GERBVIEW_FRAME::ReCreateAuxiliaryToolbar(), PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar(), DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar(), GERBVIEW_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), PL_EDITOR_FRAME::ReCreateHToolbar(), PCB_EDIT_FRAME::ReCreateHToolbar(), DISPLAY_FOOTPRINTS_FRAME::UpdateToolbarControlSizes(), GERBVIEW_FRAME::UpdateToolbarControlSizes(), FOOTPRINT_EDIT_FRAME::UpdateToolbarControlSizes(), PL_EDITOR_FRAME::UpdateToolbarControlSizes(), and PCB_EDIT_FRAME::UpdateToolbarControlSizes().

Member Data Documentation

◆ CANCEL

◆ m_actionGroups

std::map<int, ACTION_GROUP*> ACTION_TOOLBAR::m_actionGroups
protected

◆ m_auiManager

wxAuiManager* ACTION_TOOLBAR::m_auiManager
protected

Definition at line 342 of file action_toolbar.h.

Referenced by popupPalette(), and SetAuiManager().

◆ m_palette

ACTION_TOOLBAR_PALETTE* ACTION_TOOLBAR::m_palette
protected

Definition at line 344 of file action_toolbar.h.

Referenced by onMouseClick(), onPaletteEvent(), and popupPalette().

◆ m_paletteTimer

wxTimer* ACTION_TOOLBAR::m_paletteTimer
protected

Definition at line 340 of file action_toolbar.h.

Referenced by ACTION_TOOLBAR(), onMouseClick(), popupPalette(), and ~ACTION_TOOLBAR().

◆ m_toolActions

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

◆ m_toolCancellable

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

Definition at line 347 of file action_toolbar.h.

Referenced by Add(), ClearToolbar(), onToolEvent(), and ~ACTION_TOOLBAR().

◆ m_toolKinds

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

Definition at line 346 of file action_toolbar.h.

Referenced by Add(), AddButton(), AddGroup(), ClearToolbar(), Toggle(), and ~ACTION_TOOLBAR().

◆ m_toolManager

TOOL_MANAGER* ACTION_TOOLBAR::m_toolManager
protected

Definition at line 343 of file action_toolbar.h.

Referenced by doSelectAction(), onPaletteEvent(), onToolEvent(), and popupPalette().

◆ m_toolMenus

std::map<int, std::unique_ptr<ACTION_MENU> > ACTION_TOOLBAR::m_toolMenus
protected

◆ TOGGLE


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