KiCad PCB EDA Suite
Loading...
Searching...
No Matches
action_toolbar.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef ACTION_TOOLBAR_H
25#define ACTION_TOOLBAR_H
26
27#include <map>
28#include <memory>
29#include <vector>
30#include <wx/bitmap.h> // Needed for the auibar include
31#include <wx/aui/auibar.h>
32#include <wx/aui/framemanager.h>
33#include <wx/popupwin.h>
34#include <wx/panel.h>
35#include <tool/action_manager.h>
36
37class ACTION_MENU;
38class BITMAP_BUTTON;
39class EDA_BASE_FRAME;
40class TOOL_ACTION;
41class TOOL_MANAGER;
43
48{
49public:
50 // Make the toolbar a friend so it can easily access everything inside here
51 friend class ACTION_TOOLBAR;
52
53 ACTION_GROUP(const std::string_view& aName );
54
55 ACTION_GROUP( const std::string_view& aName, const std::vector<const TOOL_ACTION*>& aActions );
56
65 void SetDefaultAction( const TOOL_ACTION& aDefault );
66
70 const TOOL_ACTION* GetDefaultAction() const { return m_defaultAction; }
71
75 std::string GetName() const { return m_name; }
76
80 int GetUIId() const;
81
89 void SetActions( const std::vector<const TOOL_ACTION*>& aActions );
90
94 const std::vector<const TOOL_ACTION*>& GetActions() const { return m_actions; }
95
96protected:
98 int m_id;
99
101 std::string m_name;
102
105
107 std::vector<const TOOL_ACTION*> m_actions;
108};
109
110
114class ACTION_TOOLBAR_PALETTE : public wxPopupTransientWindow
115{
116public:
124 ACTION_TOOLBAR_PALETTE( wxWindow* aParent, bool aVertical );
125
131 void AddAction( const TOOL_ACTION& aAction );
132
139 void EnableAction( const TOOL_ACTION& aAction, bool aEnable = true );
140
147 void CheckAction( const TOOL_ACTION& aAction, bool aCheck = true );
148
156 void SetButtonSize( wxRect& aSize ) { m_buttonSize = aSize; }
157
163 void Popup( wxWindow* aFocus = nullptr ) override;
164
168 void SetGroup( ACTION_GROUP* aGroup ) { m_group = aGroup; }
170
171protected:
172 void onCharHook( wxKeyEvent& aEvent );
173
174 // The group that the buttons in the palette are part of
176
179
182
183 wxPanel* m_panel;
184 wxBoxSizer* m_mainSizer;
185 wxBoxSizer* m_buttonSizer;
186
188 std::map<int, BITMAP_BUTTON*> m_buttons;
189};
190
191// Forward declare this because the toolbar wants it
193
197class ACTION_TOOLBAR : public wxAuiToolBar
198{
199public:
200 ACTION_TOOLBAR( EDA_BASE_FRAME* parent, wxWindowID id = wxID_ANY,
201 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
202 long style = wxAUI_TB_DEFAULT_STYLE );
203
204 virtual ~ACTION_TOOLBAR();
205
211 void SetAuiManager( wxAuiManager* aManager ) { m_auiManager = aManager; }
212
213 void SetToolManager( TOOL_MANAGER* aManager ) { m_toolManager = aManager; }
214
224 void Add( const TOOL_ACTION& aAction );
225
235 void Add( const TOOL_ACTION& aAction, bool aIsToggleEntry,
236 bool aIsCancellable = false );
237
243 void AddButton( const TOOL_ACTION& aAction );
244
251 void AddScaledSeparator( wxWindow* aWindow );
252
256 void Add( wxControl* aControl, const wxString& aLabel = wxEmptyString );
257
267 void AddToolContextMenu( const TOOL_ACTION& aAction, std::unique_ptr<ACTION_MENU> aMenu );
268
279 void AddGroup( std::unique_ptr<ACTION_GROUP> aGroup );
280
287 void SelectAction( ACTION_GROUP* aGroup, const TOOL_ACTION& aAction );
288
295 void ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig );
296
300 void UpdateControlWidths();
301
307 void UpdateControlWidth( int aID );
308
312 void ClearToolbar();
313
319 void SetToolBitmap( const TOOL_ACTION& aAction, const wxBitmap& aBitmap );
320
326 void Toggle( const TOOL_ACTION& aAction, bool aState );
327
328 void Toggle( const TOOL_ACTION& aAction, bool aEnabled, bool aChecked );
329
338 bool KiRealize();
339
343 void RefreshBitmaps();
344
348 static std::list<ACTION_TOOLBAR_CONTROL*>& GetCustomControlList()
349 {
350 static std::list<ACTION_TOOLBAR_CONTROL*> m_controls;
351 return m_controls;
352 }
353
354 static constexpr bool TOGGLE = true;
355 static constexpr bool CANCEL = true;
356
357protected:
363 void doSelectAction( ACTION_GROUP* aGroup, const TOOL_ACTION& aAction );
364
369 void popupPalette( wxAuiToolBarItem* aItem );
370
372 void onMouseClick( wxMouseEvent& aEvent );
373
375 void onItemDrag( wxAuiToolBarEvent& aEvent );
376
378 void onToolEvent( wxAuiToolBarEvent& aEvent );
379
381 void onToolRightClick( wxAuiToolBarEvent& aEvent );
382
384 void onPaletteEvent( wxCommandEvent& aEvent );
385
387 void onTimerDone( wxTimerEvent& aEvent );
388
389 void onThemeChanged( wxSysColourChangedEvent &aEvent );
390
393 void OnCustomRender( wxDC& aDc, const wxAuiToolBarItem& aItem, const wxRect& aRect ) override;
394
395protected:
396 // Timer used to determine when the palette should be opened after a group item is pressed
398
399 wxAuiManager* m_auiManager;
402
403 std::map<int, bool> m_toolKinds;
404 std::map<int, bool> m_toolCancellable;
405 std::map<int, const TOOL_ACTION*> m_toolActions;
406
408 std::vector<int> m_controlIDs;
409
410 std::map<int, std::unique_ptr<ACTION_GROUP>> m_actionGroups;
411 std::map<int, std::unique_ptr<ACTION_MENU>> m_toolMenus;
412};
413
421typedef std::function<void ( ACTION_TOOLBAR* )> ACTION_TOOLBAR_CONTROL_FACTORY;
422
423
428{
429public:
430 ACTION_TOOLBAR_CONTROL( std::string aName, wxString aUiName, wxString aDescription ) :
431 m_name( aName ),
432 m_uiname( aUiName ),
433 m_description( aDescription )
434 {
435 wxASSERT_MSG( aName.starts_with( "control" ),
436 wxString::Format( "Control name \"%s\" must start with \"control\"", aName ) );
437
438 ACTION_TOOLBAR::GetCustomControlList().push_back( this );
439 }
440
441 const std::string& GetName() const { return m_name; }
442 const wxString& GetUiName() const { return m_uiname; }
443 const wxString& GetDescription() const { return m_description; }
444
445protected:
449 std::string m_name;
450
454 wxString m_uiname;
455
460};
461
463{
464public:
470};
471
472#endif
std::function< void(ACTION_TOOLBAR *)> ACTION_TOOLBAR_CONTROL_FACTORY
Type for the function signature that is used to add custom controls to the toolbar.
A group of actions that will be displayed together on a toolbar palette.
void SetDefaultAction(const TOOL_ACTION &aDefault)
Set the default action to use when first creating the toolbar palette icon.
const std::vector< const TOOL_ACTION * > & GetActions() const
Get a vector of all the actions contained inside this group.
std::vector< const TOOL_ACTION * > m_actions
void SetActions(const std::vector< const TOOL_ACTION * > &aActions)
Set the actions contained in this group.
int GetUIId() const
Get the ID used in the UI to reference this group.
int m_id
< The action ID for this action group
const TOOL_ACTION * m_defaultAction
The actions that compose the group.
const TOOL_ACTION * GetDefaultAction() const
Get the default action to use when first creating this group's toolbar palette icon.
std::string m_name
The default action to display on the toolbar item.
std::string GetName() const
Get the name of the group.
Define the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
static ACTION_TOOLBAR_CONTROL gridSelect
static ACTION_TOOLBAR_CONTROL layerSelector
static ACTION_TOOLBAR_CONTROL zoomSelect
static ACTION_TOOLBAR_CONTROL unitSelector
static ACTION_TOOLBAR_CONTROL ipcScripting
Class to hold basic information about controls that can be added to the toolbars.
wxString m_uiname
Short description to show for the control.
std::string m_name
Name of the control - must start with "control.".
const wxString & GetDescription() const
const wxString & GetUiName() const
ACTION_TOOLBAR_CONTROL(std::string aName, wxString aUiName, wxString aDescription)
const std::string & GetName() const
wxString m_description
User-visible tooltip for the control.
A popup window that contains a row of toolbar-like buttons for the user to choose from.
void CheckAction(const TOOL_ACTION &aAction, bool aCheck=true)
Check/Toggle the button for an action on the palette.
void onCharHook(wxKeyEvent &aEvent)
wxBoxSizer * m_buttonSizer
The buttons that act as the toolbar on the palette.
void AddAction(const TOOL_ACTION &aAction)
Add an action to the palette.
void SetButtonSize(wxRect &aSize)
Set the size all the buttons on this palette should be.
void SetGroup(ACTION_GROUP *aGroup)
Set the action group that this palette contains the actions for.
wxRect m_buttonSize
True if the palette uses vertical buttons, false for horizontal buttons.
void EnableAction(const TOOL_ACTION &aAction, bool aEnable=true)
Enable the button for an action on the palette.
ACTION_GROUP * m_group
The size each button on the toolbar should be.
std::map< int, BITMAP_BUTTON * > m_buttons
ACTION_GROUP * GetGroup()
void Popup(wxWindow *aFocus=nullptr) override
Popup this window.
Define the structure of a toolbar with buttons that invoke ACTIONs.
void RefreshBitmaps()
Reload all the bitmaps for the tools (e.g.
void OnCustomRender(wxDC &aDc, const wxAuiToolBarItem &aItem, const wxRect &aRect) override
static constexpr bool TOGGLE
void onTimerDone(wxTimerEvent &aEvent)
void doSelectAction(ACTION_GROUP *aGroup, const TOOL_ACTION &aAction)
Update a group toolbar item to look like a specific action.
static constexpr bool CANCEL
void SetAuiManager(wxAuiManager *aManager)
Set the AUI manager that this toolbar belongs to.
void onMouseClick(wxMouseEvent &aEvent)
Handler for when a drag event occurs on an item.
void onToolRightClick(wxAuiToolBarEvent &aEvent)
Handle the button select inside the palette.
void AddButton(const TOOL_ACTION &aAction)
Add a large button such as used in the KiCad Manager Frame's launch bar.
wxAuiManager * m_auiManager
void UpdateControlWidth(int aID)
Update the toolbar item width of a control using its best size.
void Toggle(const TOOL_ACTION &aAction, bool aState)
Apply the default toggle action.
void SelectAction(ACTION_GROUP *aGroup, const TOOL_ACTION &aAction)
Select an action inside a group.
void Add(const TOOL_ACTION &aAction)
Add a TOOL_ACTION-based button to the toolbar.
void onPaletteEvent(wxCommandEvent &aEvent)
Handle the palette timer triggering.
wxTimer * m_paletteTimer
std::map< int, std::unique_ptr< ACTION_MENU > > m_toolMenus
void onToolEvent(wxAuiToolBarEvent &aEvent)
Handle a right-click on a menu item.
void onItemDrag(wxAuiToolBarEvent &aEvent)
The default tool event handler.
std::map< int, bool > m_toolKinds
std::map< int, std::unique_ptr< ACTION_GROUP > > m_actionGroups
void AddGroup(std::unique_ptr< ACTION_GROUP > aGroup)
Add a set of actions to a toolbar as a group.
void AddToolContextMenu(const TOOL_ACTION &aAction, std::unique_ptr< ACTION_MENU > aMenu)
Add a context menu to a specific tool item on the toolbar.
std::map< int, bool > m_toolCancellable
void AddScaledSeparator(wxWindow *aWindow)
Add a separator that introduces space on either side to not squash the tools when scaled.
bool KiRealize()
Use this over Realize() to avoid a rendering glitch with fixed orientation toolbars.
void popupPalette(wxAuiToolBarItem *aItem)
Popup the ACTION_TOOLBAR_PALETTE associated with the ACTION_GROUP of the given toolbar item.
virtual ~ACTION_TOOLBAR()
ACTION_TOOLBAR_PALETTE * m_palette
std::vector< int > m_controlIDs
IDs for all the control items in this toolbar.
void onThemeChanged(wxSysColourChangedEvent &aEvent)
Render the triangle in the lower-right corner that represents that an action palette is available for...
void SetToolManager(TOOL_MANAGER *aManager)
std::map< int, const TOOL_ACTION * > m_toolActions
void ClearToolbar()
Clear the toolbar and remove all associated menus.
void SetToolBitmap(const TOOL_ACTION &aAction, const wxBitmap &aBitmap)
Updates the bitmap of a particular tool.
static std::list< ACTION_TOOLBAR_CONTROL * > & GetCustomControlList()
Get the list of custom controls that could be used on toolbars.
void UpdateControlWidths()
Update the width of all wxControl tools on thsi toolbar.
void ApplyConfiguration(const TOOLBAR_CONFIGURATION &aConfig)
Replace the contents of this toolbar with the configuration given in aConfig.
TOOL_MANAGER * m_toolManager
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:42
The base frame for deriving all KiCad main window classes.
Represent a single user action.
Definition: tool_action.h:304
Master controller class:
Definition: tool_manager.h:62