KiCad PCB EDA Suite
ACTION_TOOLBAR_PALETTE Class Reference

A popup window that contains a row of toolbar-like buttons for the user to choose from. More...

#include <action_toolbar.h>

Inheritance diagram for ACTION_TOOLBAR_PALETTE:

Public Member Functions

 ACTION_TOOLBAR_PALETTE (wxWindow *aParent, bool aVertical)
 Create the palette. More...
 
void AddAction (const TOOL_ACTION &aAction)
 Add an action to the palette. More...
 
void EnableAction (const TOOL_ACTION &aAction, bool aEnable=true)
 Enable the button for an action on the palette. More...
 
void CheckAction (const TOOL_ACTION &aAction, bool aCheck=true)
 Check/Toggle the button for an action on the palette. More...
 
void SetButtonSize (wxRect &aSize)
 Set the size all the buttons on this palette should be. More...
 
void Popup (wxWindow *aFocus=nullptr) override
 Popup this window. More...
 
void SetGroup (ACTION_GROUP *aGroup)
 Set the action group that this palette contains the actions for. More...
 
ACTION_GROUPGetGroup ()
 

Protected Member Functions

void onCharHook (wxKeyEvent &aEvent)
 

Protected Attributes

ACTION_GROUPm_group
 The size each button on the toolbar should be. More...
 
wxRect m_buttonSize
 True if the palette uses vertical buttons, false for horizontal buttons. More...
 
bool m_isVertical
 
wxPanel * m_panel
 
wxBoxSizer * m_mainSizer
 
wxBoxSizer * m_buttonSizer
 The buttons that act as the toolbar on the palette. More...
 
std::map< int, BITMAP_BUTTON * > m_buttons
 

Detailed Description

A popup window that contains a row of toolbar-like buttons for the user to choose from.

Definition at line 103 of file action_toolbar.h.

Constructor & Destructor Documentation

◆ ACTION_TOOLBAR_PALETTE()

ACTION_TOOLBAR_PALETTE::ACTION_TOOLBAR_PALETTE ( wxWindow *  aParent,
bool  aVertical 
)

Create the palette.

Parameters
aParentis the parent window
aVerticalis true if the palette should make the buttons a vertical line, false for a horizontal line.

Definition at line 78 of file action_toolbar.cpp.

78  :
79  wxPopupTransientWindow( aParent, wxBORDER_NONE ),
80  m_group( nullptr ),
81  m_isVertical( aVertical ),
82  m_panel( nullptr ),
83  m_mainSizer( nullptr ),
84  m_buttonSizer( nullptr )
85 {
86  m_panel = new wxPanel( this, wxID_ANY );
87  m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
88 
89  // This sizer holds the buttons for the actions
90  m_buttonSizer = new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
91 
92  // This sizer holds the other sizer, so that a consistent border is present on all sides
93  m_mainSizer = new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
94  m_mainSizer->Add( m_buttonSizer, wxSizerFlags().Border( wxALL, PALETTE_BORDER ) );
95 
96  m_panel->SetSizer( m_mainSizer );
97 
98  Connect( wxEVT_CHAR_HOOK, wxCharEventHandler( ACTION_TOOLBAR_PALETTE::onCharHook ),
99  NULL, this );
100 }
#define NULL
ACTION_GROUP * m_group
The size each button on the toolbar should be.
#define PALETTE_BORDER
wxBoxSizer * m_buttonSizer
The buttons that act as the toolbar on the palette.
void onCharHook(wxKeyEvent &aEvent)

References m_buttonSizer, m_mainSizer, m_panel, NULL, onCharHook(), and PALETTE_BORDER.

Member Function Documentation

◆ AddAction()

void ACTION_TOOLBAR_PALETTE::AddAction ( const TOOL_ACTION aAction)

Add an action to the palette.

Parameters
aActionis the action to add

Definition at line 103 of file action_toolbar.cpp.

104 {
105  wxBitmap normalBmp = KiScaledBitmap( aAction.GetIcon(), this );
106  wxBitmap disabledBmp = normalBmp.ConvertToDisabled();
107 
108  int padding = ( m_buttonSize.GetWidth() - normalBmp.GetWidth() ) / 2;
109 
110  BITMAP_BUTTON* button = new BITMAP_BUTTON( m_panel, aAction.GetUIId() );
111 
112  button->SetBitmap( normalBmp );
113  button->SetDisabledBitmap( disabledBmp );
114  button->SetPadding( padding );
115  button->SetToolTip( aAction.GetDescription() );
116 
117  m_buttons[aAction.GetUIId()] = button;
118 
119  if( m_isVertical )
120  m_buttonSizer->Add( button, wxSizerFlags().Border( wxTOP | wxBOTTOM, BUTTON_BORDER ) );
121  else
122  m_buttonSizer->Add( button, wxSizerFlags().Border( wxLEFT | wxRIGHT, BUTTON_BORDER ) );
123 
124  m_buttonSizer->Layout();
125 }
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:39
int GetUIId() const
Definition: tool_action.h:112
void SetPadding(int aPadding)
Set the amount of padding present on each side of the bitmap.
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
wxRect m_buttonSize
True if the palette uses vertical buttons, false for horizontal buttons.
void SetBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is enabled.
std::map< int, BITMAP_BUTTON * > m_buttons
wxBoxSizer * m_buttonSizer
The buttons that act as the toolbar on the palette.
void SetDisabledBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is disabled.
#define BUTTON_BORDER
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 BUTTON_BORDER, TOOL_ACTION::GetDescription(), TOOL_ACTION::GetIcon(), TOOL_ACTION::GetUIId(), KiScaledBitmap(), m_buttons, m_buttonSize, m_buttonSizer, m_isVertical, m_panel, BITMAP_BUTTON::SetBitmap(), BITMAP_BUTTON::SetDisabledBitmap(), and BITMAP_BUTTON::SetPadding().

Referenced by ACTION_TOOLBAR::popupPalette().

◆ CheckAction()

void ACTION_TOOLBAR_PALETTE::CheckAction ( const TOOL_ACTION aAction,
bool  aCheck = true 
)

Check/Toggle the button for an action on the palette.

Parameters
aActionis the action who's button should be checked
aCheckis true to check the button, false to uncheck

Definition at line 137 of file action_toolbar.cpp.

138 {
139  auto it = m_buttons.find( aAction.GetUIId() );
140 
141  if( it != m_buttons.end() )
142  it->second->Check( aCheck );
143 }
int GetUIId() const
Definition: tool_action.h:112
std::map< int, BITMAP_BUTTON * > m_buttons

References TOOL_ACTION::GetUIId(), and m_buttons.

◆ EnableAction()

void ACTION_TOOLBAR_PALETTE::EnableAction ( const TOOL_ACTION aAction,
bool  aEnable = true 
)

Enable the button for an action on the palette.

Parameters
aActionis the action who's button should be enabled
aEnableis true to enable the button, false to disable

Definition at line 128 of file action_toolbar.cpp.

129 {
130  auto it = m_buttons.find( aAction.GetUIId() );
131 
132  if( it != m_buttons.end() )
133  it->second->Enable( aEnable );
134 }
int GetUIId() const
Definition: tool_action.h:112
std::map< int, BITMAP_BUTTON * > m_buttons

References TOOL_ACTION::GetUIId(), and m_buttons.

Referenced by ACTION_TOOLBAR::popupPalette().

◆ GetGroup()

ACTION_GROUP* ACTION_TOOLBAR_PALETTE::GetGroup ( )
inline

Definition at line 158 of file action_toolbar.h.

158 { return m_group; }
ACTION_GROUP * m_group
The size each button on the toolbar should be.

References m_group.

Referenced by ACTION_TOOLBAR::onPaletteEvent().

◆ onCharHook()

void ACTION_TOOLBAR_PALETTE::onCharHook ( wxKeyEvent &  aEvent)
protected

Definition at line 155 of file action_toolbar.cpp.

156 {
157  // Allow the escape key to dismiss this popup
158  if( aEvent.GetKeyCode() == WXK_ESCAPE )
159  Dismiss();
160  else
161  aEvent.Skip();
162 }

Referenced by ACTION_TOOLBAR_PALETTE().

◆ Popup()

void ACTION_TOOLBAR_PALETTE::Popup ( wxWindow *  aFocus = nullptr)
override

Popup this window.

Parameters
aFocusis the window to keep focus on (if supported)

Definition at line 146 of file action_toolbar.cpp.

147 {
148  m_mainSizer->Fit( m_panel );
149  SetClientSize( m_panel->GetSize() );
150 
151  wxPopupTransientWindow::Popup( aFocus );
152 }

References m_mainSizer, and m_panel.

Referenced by ACTION_TOOLBAR::popupPalette().

◆ SetButtonSize()

void ACTION_TOOLBAR_PALETTE::SetButtonSize ( wxRect &  aSize)
inline

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.

Parameters
aSizeis the requested size of the buttons

Definition at line 145 of file action_toolbar.h.

145 { m_buttonSize = aSize; }
wxRect m_buttonSize
True if the palette uses vertical buttons, false for horizontal buttons.

References m_buttonSize.

Referenced by ACTION_TOOLBAR::popupPalette().

◆ SetGroup()

void ACTION_TOOLBAR_PALETTE::SetGroup ( ACTION_GROUP aGroup)
inline

Set the action group that this palette contains the actions for.

Definition at line 157 of file action_toolbar.h.

157 { m_group = aGroup; }
ACTION_GROUP * m_group
The size each button on the toolbar should be.

References m_group.

Referenced by ACTION_TOOLBAR::popupPalette().

Member Data Documentation

◆ m_buttons

std::map<int, BITMAP_BUTTON*> ACTION_TOOLBAR_PALETTE::m_buttons
protected

Definition at line 177 of file action_toolbar.h.

Referenced by AddAction(), CheckAction(), and EnableAction().

◆ m_buttonSize

wxRect ACTION_TOOLBAR_PALETTE::m_buttonSize
protected

True if the palette uses vertical buttons, false for horizontal buttons.

Definition at line 167 of file action_toolbar.h.

Referenced by AddAction(), and SetButtonSize().

◆ m_buttonSizer

wxBoxSizer* ACTION_TOOLBAR_PALETTE::m_buttonSizer
protected

The buttons that act as the toolbar on the palette.

Definition at line 174 of file action_toolbar.h.

Referenced by ACTION_TOOLBAR_PALETTE(), and AddAction().

◆ m_group

ACTION_GROUP* ACTION_TOOLBAR_PALETTE::m_group
protected

The size each button on the toolbar should be.

Definition at line 164 of file action_toolbar.h.

Referenced by GetGroup(), and SetGroup().

◆ m_isVertical

bool ACTION_TOOLBAR_PALETTE::m_isVertical
protected

Definition at line 170 of file action_toolbar.h.

Referenced by AddAction().

◆ m_mainSizer

wxBoxSizer* ACTION_TOOLBAR_PALETTE::m_mainSizer
protected

Definition at line 173 of file action_toolbar.h.

Referenced by ACTION_TOOLBAR_PALETTE(), and Popup().

◆ m_panel

wxPanel* ACTION_TOOLBAR_PALETTE::m_panel
protected

Definition at line 172 of file action_toolbar.h.

Referenced by ACTION_TOOLBAR_PALETTE(), AddAction(), and Popup().


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