2019-05-14 19:21:10 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-06-08 14:09:24 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-14 19:21:10 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ACTION_TOOLBAR_H
|
|
|
|
#define ACTION_TOOLBAR_H
|
|
|
|
|
|
|
|
#include <map>
|
2020-10-01 21:55:17 +00:00
|
|
|
#include <memory>
|
2020-09-26 23:55:59 +00:00
|
|
|
#include <vector>
|
2019-08-09 21:05:16 +00:00
|
|
|
#include <wx/bitmap.h> // Needed for the auibar include
|
2019-05-14 19:21:10 +00:00
|
|
|
#include <wx/aui/auibar.h>
|
2020-09-26 23:55:59 +00:00
|
|
|
#include <wx/aui/framemanager.h>
|
|
|
|
#include <wx/popupwin.h>
|
2020-10-01 17:37:14 +00:00
|
|
|
#include <wx/panel.h>
|
2020-09-26 23:55:59 +00:00
|
|
|
#include <tool/action_manager.h>
|
2019-05-14 19:21:10 +00:00
|
|
|
|
2020-08-13 23:09:17 +00:00
|
|
|
class ACTION_MENU;
|
2020-09-26 23:55:59 +00:00
|
|
|
class BITMAP_BUTTON;
|
2020-03-24 01:01:23 +00:00
|
|
|
class EDA_BASE_FRAME;
|
2021-06-06 17:26:26 +00:00
|
|
|
class TOOL_ACTION;
|
2019-05-14 19:21:10 +00:00
|
|
|
class TOOL_MANAGER;
|
2020-09-26 23:55:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A group of actions that will be displayed together on a toolbar palette.
|
|
|
|
*/
|
|
|
|
class ACTION_GROUP
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Make the toolbar a friend so it can easily access everything inside here
|
|
|
|
friend class ACTION_TOOLBAR;
|
|
|
|
|
2021-06-08 14:09:24 +00:00
|
|
|
ACTION_GROUP( const std::string& aName, const std::vector<const TOOL_ACTION*>& aActions );
|
2020-09-26 23:55:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the default action to use when first creating the toolbar palette icon.
|
2020-12-27 00:41:04 +00:00
|
|
|
*
|
2020-09-26 23:55:59 +00:00
|
|
|
* If no default action is provided, the default will be the first action in the
|
|
|
|
* vector.
|
|
|
|
*
|
|
|
|
* @param aDefault is the default action.
|
|
|
|
*/
|
|
|
|
void SetDefaultAction( const TOOL_ACTION& aDefault );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the default action to use when first creating this group's toolbar palette icon.
|
|
|
|
*/
|
|
|
|
const TOOL_ACTION* GetDefaultAction() const { return m_defaultAction; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the name of the group.
|
|
|
|
*/
|
|
|
|
std::string GetName() const { return m_name; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the ID used in the UI to reference this group
|
|
|
|
*/
|
2021-06-06 17:26:26 +00:00
|
|
|
int GetUIId() const;
|
2020-09-26 23:55:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a vector of all the actions contained inside this group.
|
|
|
|
*/
|
2021-06-06 17:26:26 +00:00
|
|
|
const std::vector<const TOOL_ACTION*>& GetActions() const { return m_actions; }
|
2020-09-26 23:55:59 +00:00
|
|
|
|
|
|
|
protected:
|
2020-12-27 00:41:04 +00:00
|
|
|
///< The action ID for this action group
|
2020-09-26 23:55:59 +00:00
|
|
|
int m_id;
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< The name of this action group
|
2020-09-26 23:55:59 +00:00
|
|
|
std::string m_name;
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< The default action to display on the toolbar item
|
2020-09-26 23:55:59 +00:00
|
|
|
const TOOL_ACTION* m_defaultAction;
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< The actions that compose the group
|
2020-09-26 23:55:59 +00:00
|
|
|
std::vector<const TOOL_ACTION*> m_actions;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A popup window that contains a row of toolbar-like buttons for the user to choose from.
|
|
|
|
*/
|
|
|
|
class ACTION_TOOLBAR_PALETTE : public wxPopupTransientWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create the palette.
|
|
|
|
*
|
|
|
|
* @param aParent is the parent window
|
|
|
|
* @param aVertical is true if the palette should make the buttons a vertical line,
|
2020-12-27 00:41:04 +00:00
|
|
|
* false for a horizontal line.
|
2020-09-26 23:55:59 +00:00
|
|
|
*/
|
|
|
|
ACTION_TOOLBAR_PALETTE( wxWindow* aParent, bool aVertical );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an action to the palette.
|
|
|
|
*
|
|
|
|
* @param aAction is the action to add
|
|
|
|
*/
|
|
|
|
void AddAction( const TOOL_ACTION& aAction );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable the button for an action on the palette.
|
|
|
|
*
|
|
|
|
* @param aAction is the action who's button should be enabled
|
|
|
|
* @param aEnable is true to enable the button, false to disable
|
|
|
|
*/
|
|
|
|
void EnableAction( const TOOL_ACTION& aAction, bool aEnable = true );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check/Toggle the button for an action on the palette.
|
|
|
|
*
|
|
|
|
* @param aAction is the action who's button should be checked
|
|
|
|
* @param aCheck is true to check the button, false to uncheck
|
|
|
|
*/
|
|
|
|
void CheckAction( const TOOL_ACTION& aAction, bool aCheck = true );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the size all the buttons on this palette should be.
|
|
|
|
* This function will automatically pad all button bitmaps to ensure this
|
|
|
|
* size is met.
|
|
|
|
*
|
|
|
|
* @param aSize is the requested size of the buttons
|
|
|
|
*/
|
|
|
|
void SetButtonSize( wxRect& aSize ) { m_buttonSize = aSize; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Popup this window
|
|
|
|
*
|
|
|
|
* @param aFocus is the window to keep focus on (if supported)
|
|
|
|
*/
|
2020-09-28 02:31:34 +00:00
|
|
|
void Popup( wxWindow* aFocus = nullptr ) override;
|
2020-09-26 23:55:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the action group that this palette contains the actions for
|
|
|
|
*/
|
|
|
|
void SetGroup( ACTION_GROUP* aGroup ) { m_group = aGroup; }
|
|
|
|
ACTION_GROUP* GetGroup() { return m_group; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onCharHook( wxKeyEvent& aEvent );
|
|
|
|
|
|
|
|
// The group that the buttons in the palette are part of
|
|
|
|
ACTION_GROUP* m_group;
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< The size each button on the toolbar should be
|
2020-09-26 23:55:59 +00:00
|
|
|
wxRect m_buttonSize;
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< True if the palette uses vertical buttons, false for horizontal buttons
|
2020-09-26 23:55:59 +00:00
|
|
|
bool m_isVertical;
|
|
|
|
|
|
|
|
wxPanel* m_panel;
|
|
|
|
wxBoxSizer* m_mainSizer;
|
|
|
|
wxBoxSizer* m_buttonSizer;
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< The buttons that act as the toolbar on the palette
|
2020-09-26 23:55:59 +00:00
|
|
|
std::map<int, BITMAP_BUTTON*> m_buttons;
|
|
|
|
};
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Define the structure of a toolbar with buttons that invoke ACTIONs.
|
2019-05-14 19:21:10 +00:00
|
|
|
*/
|
|
|
|
class ACTION_TOOLBAR : public wxAuiToolBar
|
|
|
|
{
|
|
|
|
public:
|
2019-06-09 13:12:44 +00:00
|
|
|
ACTION_TOOLBAR( EDA_BASE_FRAME* parent, wxWindowID id = wxID_ANY,
|
2019-05-14 19:21:10 +00:00
|
|
|
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxAUI_TB_DEFAULT_STYLE );
|
|
|
|
|
2020-06-23 10:42:23 +00:00
|
|
|
virtual ~ACTION_TOOLBAR();
|
2019-05-14 19:21:10 +00:00
|
|
|
|
2020-09-26 23:55:59 +00:00
|
|
|
/**
|
|
|
|
* Set the AUI manager that this toolbar belongs to.
|
|
|
|
*
|
|
|
|
* @param aManager is the AUI manager
|
|
|
|
*/
|
|
|
|
void SetAuiManager( wxAuiManager* aManager ) { m_auiManager = aManager; }
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Add a TOOL_ACTION-based button to the toolbar.
|
2020-09-05 00:48:22 +00:00
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* After selecting the entry, a #TOOL_EVENT command containing name of the action is sent.
|
|
|
|
*
|
|
|
|
* @param aAction is the action to add.
|
|
|
|
* @param aIsToggleEntry makes the toolbar item a toggle entry when true.
|
|
|
|
* @param aIsCancellable when true, cancels the tool if clicked when tool is active.
|
2019-05-14 19:21:10 +00:00
|
|
|
*/
|
2020-09-05 00:48:22 +00:00
|
|
|
void Add( const TOOL_ACTION& aAction, bool aIsToggleEntry = false,
|
|
|
|
bool aIsCancellable = false );
|
2019-08-09 21:05:16 +00:00
|
|
|
|
2019-06-10 14:23:37 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Add a large button such as used in the KiCad Manager Frame's launch bar.
|
2020-07-23 23:47:19 +00:00
|
|
|
*
|
2019-08-09 21:05:16 +00:00
|
|
|
* @param aAction
|
2019-06-10 14:23:37 +00:00
|
|
|
*/
|
|
|
|
void AddButton( const TOOL_ACTION& aAction );
|
2019-05-14 19:21:10 +00:00
|
|
|
|
2020-06-17 11:03:25 +00:00
|
|
|
/**
|
|
|
|
* Add a separator that introduces space on either side to not squash the tools
|
|
|
|
* when scaled.
|
|
|
|
*
|
|
|
|
* @param aWindow is the window to get the scaling factor of
|
|
|
|
*/
|
|
|
|
void AddScaledSeparator( wxWindow* aWindow );
|
|
|
|
|
2020-06-23 10:42:23 +00:00
|
|
|
/**
|
|
|
|
* Add a context menu to a specific tool item on the toolbar.
|
2020-12-27 00:41:04 +00:00
|
|
|
*
|
2020-06-23 10:42:23 +00:00
|
|
|
* This toolbar gets ownership of the menu object, and will delete it when the
|
|
|
|
* ClearToolbar() function is called.
|
|
|
|
*
|
|
|
|
* @param aAction is the action to get the menu
|
|
|
|
* @param aMenu is the context menu
|
|
|
|
*/
|
2020-10-01 21:55:17 +00:00
|
|
|
void AddToolContextMenu( const TOOL_ACTION& aAction, std::unique_ptr<ACTION_MENU> aMenu );
|
2020-06-23 10:42:23 +00:00
|
|
|
|
2020-09-26 23:55:59 +00:00
|
|
|
/**
|
|
|
|
* Add a set of actions to a toolbar as a group. One action from the group will be displayed
|
|
|
|
* at a time.
|
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* @param aGroup is the group to add. The first action in the group will be the first shown
|
|
|
|
* on the toolbar.
|
2020-09-26 23:55:59 +00:00
|
|
|
* @param aIsToggleEntry makes the toolbar item a toggle entry when true
|
|
|
|
*/
|
|
|
|
void AddGroup( ACTION_GROUP* aGroup, bool aIsToggleEntry = false );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select an action inside a group
|
|
|
|
*
|
|
|
|
* @param aGroup is the group that contains the action
|
|
|
|
* @param aAction is the action inside the group
|
|
|
|
*/
|
|
|
|
void SelectAction( ACTION_GROUP* aGroup, const TOOL_ACTION& aAction );
|
|
|
|
|
2021-03-27 21:49:38 +00:00
|
|
|
/**
|
|
|
|
* Update the toolbar item width of a control using its best size.
|
|
|
|
*
|
|
|
|
* @param aID is the ID of the toolbar item to update the width for
|
|
|
|
*/
|
|
|
|
void UpdateControlWidth( int aID );
|
|
|
|
|
2020-06-23 10:42:23 +00:00
|
|
|
/**
|
|
|
|
* Clear the toolbar and remove all associated menus.
|
|
|
|
*/
|
|
|
|
void ClearToolbar();
|
|
|
|
|
2019-06-11 08:13:56 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Updates the bitmap of a particular tool.
|
|
|
|
*
|
|
|
|
* Not icon-based because we use it for the custom-drawn layer pair bitmap.
|
2019-06-11 08:13:56 +00:00
|
|
|
*/
|
|
|
|
void SetToolBitmap( const TOOL_ACTION& aAction, const wxBitmap& aBitmap );
|
2019-08-09 21:05:16 +00:00
|
|
|
|
2019-06-01 19:48:01 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Apply the default toggle action.
|
|
|
|
*
|
|
|
|
* For checked items this is check/uncheck; for non-checked items it's enable/disable.
|
2019-06-01 19:48:01 +00:00
|
|
|
*/
|
2019-05-14 19:21:10 +00:00
|
|
|
void Toggle( const TOOL_ACTION& aAction, bool aState );
|
|
|
|
|
2019-06-01 19:48:01 +00:00
|
|
|
void Toggle( const TOOL_ACTION& aAction, bool aEnabled, bool aChecked );
|
|
|
|
|
2020-11-06 01:56:02 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2020-12-27 00:41:04 +00:00
|
|
|
* This custom function avoids the double draw if the HORIZONTAL or VERTICAL toolbar
|
|
|
|
* properties are set.
|
2020-11-06 01:56:02 +00:00
|
|
|
*/
|
|
|
|
bool KiRealize();
|
|
|
|
|
2021-03-09 22:47:24 +00:00
|
|
|
/**
|
|
|
|
* Reload all the bitmaps for the tools (e.g. when switching icon themes)
|
|
|
|
*/
|
|
|
|
void RefreshBitmaps();
|
|
|
|
|
2020-07-27 22:42:23 +00:00
|
|
|
static constexpr bool TOGGLE = true;
|
2020-09-05 00:48:22 +00:00
|
|
|
static constexpr bool CANCEL = true;
|
2019-05-14 19:21:10 +00:00
|
|
|
|
|
|
|
protected:
|
2020-09-26 23:55:59 +00:00
|
|
|
/**
|
|
|
|
* Update a group toolbar item to look like a specific action.
|
|
|
|
*
|
|
|
|
* Note: This function does not verify that the action is inside the group.
|
|
|
|
*/
|
|
|
|
void doSelectAction( ACTION_GROUP* aGroup, const TOOL_ACTION& aAction );
|
|
|
|
|
2020-09-27 01:22:22 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Popup the #ACTION_TOOLBAR_PALETTE associated with the ACTION_GROUP of the
|
2020-09-27 01:22:22 +00:00
|
|
|
* given toolbar item.
|
|
|
|
*/
|
|
|
|
void popupPalette( wxAuiToolBarItem* aItem );
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< Handler for a mouse up/down event
|
2020-09-27 01:22:22 +00:00
|
|
|
void onMouseClick( wxMouseEvent& aEvent );
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< Handler for when a drag event occurs on an item
|
2020-09-27 21:26:12 +00:00
|
|
|
void onItemDrag( wxAuiToolBarEvent& aEvent );
|
2020-09-26 23:55:59 +00:00
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< The default tool event handler
|
2019-05-14 19:21:10 +00:00
|
|
|
void onToolEvent( wxAuiToolBarEvent& aEvent );
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< Handle a right-click on a menu item
|
2020-06-23 10:42:23 +00:00
|
|
|
void onToolRightClick( wxAuiToolBarEvent& aEvent );
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< Handle the button select inside the palette
|
2020-09-26 23:55:59 +00:00
|
|
|
void onPaletteEvent( wxCommandEvent& aEvent );
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< Handle the palette timer triggering
|
2020-09-26 23:55:59 +00:00
|
|
|
void onTimerDone( wxTimerEvent& aEvent );
|
|
|
|
|
2021-09-13 22:30:22 +00:00
|
|
|
void onThemeChanged( wxSysColourChangedEvent &aEvent );
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< Render the triangle in the lower-right corner that represents that an action palette
|
|
|
|
///< is available for an item
|
|
|
|
void OnCustomRender( wxDC& aDc, const wxAuiToolBarItem& aItem, const wxRect& aRect ) override;
|
2020-09-26 23:55:59 +00:00
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
protected:
|
2020-09-27 21:26:12 +00:00
|
|
|
// Timer used to determine when the palette should be opened after a group item is pressed
|
2020-09-27 01:22:22 +00:00
|
|
|
wxTimer* m_paletteTimer;
|
|
|
|
|
|
|
|
wxAuiManager* m_auiManager;
|
2020-09-26 23:55:59 +00:00
|
|
|
TOOL_MANAGER* m_toolManager;
|
|
|
|
ACTION_TOOLBAR_PALETTE* m_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;
|
2020-10-01 21:55:17 +00:00
|
|
|
|
|
|
|
std::map<int, std::unique_ptr<ACTION_MENU>> m_toolMenus;
|
2019-05-14 19:21:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|