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 102 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 96 of file action_toolbar.cpp.

96  :
97  wxPopupTransientWindow( aParent, wxBORDER_NONE ),
98  m_group( nullptr ),
99  m_isVertical( aVertical ),
100  m_panel( nullptr ),
101  m_mainSizer( nullptr ),
102  m_buttonSizer( nullptr )
103 {
104  m_panel = new wxPanel( this, wxID_ANY );
105  m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
106 
107  // This sizer holds the buttons for the actions
108  m_buttonSizer = new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
109 
110  // This sizer holds the other sizer, so that a consistent border is present on all sides
111  m_mainSizer = new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
112  m_mainSizer->Add( m_buttonSizer, wxSizerFlags().Border( wxALL, PALETTE_BORDER ) );
113 
114  m_panel->SetSizer( m_mainSizer );
115 
116  Connect( wxEVT_CHAR_HOOK, wxCharEventHandler( ACTION_TOOLBAR_PALETTE::onCharHook ),
117  nullptr, this );
118 }
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, 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 121 of file action_toolbar.cpp.

122 {
123  wxBitmap normalBmp = KiScaledBitmap( aAction.GetIcon(), this );
124  wxBitmap disabledBmp = MakeDisabledBitmap( normalBmp );
125 
126  int padding = ( m_buttonSize.GetWidth() - normalBmp.GetWidth() ) / 2;
127 
128  BITMAP_BUTTON* button = new BITMAP_BUTTON( m_panel, aAction.GetUIId() );
129 
130  button->SetBitmap( normalBmp );
131  button->SetDisabledBitmap( disabledBmp );
132  button->SetPadding( padding );
133  button->SetToolTip( aAction.GetDescription() );
134  button->AcceptDragInAsClick();
135 
136  m_buttons[aAction.GetUIId()] = button;
137 
138  if( m_isVertical )
139  m_buttonSizer->Add( button, wxSizerFlags().Border( wxTOP | wxBOTTOM, BUTTON_BORDER ) );
140  else
141  m_buttonSizer->Add( button, wxSizerFlags().Border( wxLEFT | wxRIGHT, BUTTON_BORDER ) );
142 
143  m_buttonSizer->Layout();
144 }
wxBitmap MakeDisabledBitmap(const wxBitmap &aSource)
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:130
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:179
wxString GetDescription(bool aIncludeHotkey=true) const
Definition: tool_action.cpp:97
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight, bool aQuantized)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:148
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 AcceptDragInAsClick(bool aAcceptDragIn=true)
Accept mouse-up as click even if mouse-down happened outside of the control.
void SetDisabledBitmap(const wxBitmap &aBmp)
Set the bitmap shown when the button is disabled.
#define BUTTON_BORDER

References BITMAP_BUTTON::AcceptDragInAsClick(), BUTTON_BORDER, TOOL_ACTION::GetDescription(), TOOL_ACTION::GetIcon(), TOOL_ACTION::GetUIId(), KiScaledBitmap(), m_buttons, m_buttonSize, m_buttonSizer, m_isVertical, m_panel, MakeDisabledBitmap(), 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 156 of file action_toolbar.cpp.

157 {
158  auto it = m_buttons.find( aAction.GetUIId() );
159 
160  if( it != m_buttons.end() )
161  it->second->Check( aCheck );
162 }
int GetUIId() const
Definition: tool_action.h:130
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 147 of file action_toolbar.cpp.

148 {
149  auto it = m_buttons.find( aAction.GetUIId() );
150 
151  if( it != m_buttons.end() )
152  it->second->Enable( aEnable );
153 }
int GetUIId() const
Definition: tool_action.h:130
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 157 of file action_toolbar.h.

157 { 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 174 of file action_toolbar.cpp.

175 {
176  // Allow the escape key to dismiss this popup
177  if( aEvent.GetKeyCode() == WXK_ESCAPE )
178  Dismiss();
179  else
180  aEvent.Skip();
181 }

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

166 {
167  m_mainSizer->Fit( m_panel );
168  SetClientSize( m_panel->GetSize() );
169 
170  wxPopupTransientWindow::Popup( aFocus );
171 }

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 144 of file action_toolbar.h.

144 { 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 156 of file action_toolbar.h.

156 { 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 176 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 166 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 173 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 163 of file action_toolbar.h.

Referenced by GetGroup(), and SetGroup().

◆ m_isVertical

bool ACTION_TOOLBAR_PALETTE::m_isVertical
protected

Definition at line 169 of file action_toolbar.h.

Referenced by AddAction().

◆ m_mainSizer

wxBoxSizer* ACTION_TOOLBAR_PALETTE::m_mainSizer
protected

Definition at line 172 of file action_toolbar.h.

Referenced by ACTION_TOOLBAR_PALETTE(), and Popup().

◆ m_panel

wxPanel* ACTION_TOOLBAR_PALETTE::m_panel
protected

Definition at line 171 of file action_toolbar.h.

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


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