2019-05-14 19:21:10 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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>
|
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>
|
|
|
|
#include <tool/tool_event.h>
|
|
|
|
|
2020-08-13 23:09:17 +00:00
|
|
|
class ACTION_MENU;
|
2020-03-24 01:01:23 +00:00
|
|
|
class EDA_BASE_FRAME;
|
2019-05-14 19:21:10 +00:00
|
|
|
class TOOL_MANAGER;
|
|
|
|
class TOOL_ACTION;
|
|
|
|
|
|
|
|
/**
|
2020-01-10 14:31:00 +00:00
|
|
|
* ACTION_TOOLBAR
|
2019-05-14 19:21:10 +00:00
|
|
|
*
|
|
|
|
* Defines the structure of a toolbar with buttons that invoke ACTIONs.
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a TOOL_ACTION-based button to the toolbar. After selecting the entry,
|
|
|
|
* a TOOL_EVENT command containing name of the action is sent.
|
2020-09-05 00:48:22 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
* Adds 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.
|
|
|
|
* 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-08-13 23:09:17 +00:00
|
|
|
void AddToolContextMenu( const TOOL_ACTION& aAction, ACTION_MENU* aMenu );
|
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
|
|
|
/**
|
|
|
|
* Updates the bitmap of a particular tool. Not icon-based because we use it
|
|
|
|
* for the custom-drawn layer pair bitmap.
|
|
|
|
*/
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Applies the default toggle action. For checked items this is check/uncheck; for
|
|
|
|
* non-checked items it's enable/disable.
|
|
|
|
*/
|
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-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:
|
|
|
|
///> The default tool event handler.
|
|
|
|
void onToolEvent( wxAuiToolBarEvent& aEvent );
|
|
|
|
|
2020-06-23 10:42:23 +00:00
|
|
|
///> Handle a right-click on a menu item
|
|
|
|
void onToolRightClick( wxAuiToolBarEvent& aEvent );
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
protected:
|
|
|
|
TOOL_MANAGER* m_toolManager;
|
2019-05-15 22:49:48 +00:00
|
|
|
std::map<int, bool> m_toolKinds;
|
2020-09-05 00:48:22 +00:00
|
|
|
std::map<int, bool> m_toolCancellable;
|
2019-05-14 19:21:10 +00:00
|
|
|
std::map<int, const TOOL_ACTION*> m_toolActions;
|
2020-08-13 23:09:17 +00:00
|
|
|
std::map<int, ACTION_MENU*> m_toolMenus;
|
2019-05-14 19:21:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|