44#include <wx/popupwin.h>
45#include <wx/renderer.h>
47#include <wx/dcclient.h>
48#include <wx/settings.h>
52 const std::vector<const TOOL_ACTION*>& aActions )
54 wxASSERT_MSG( aActions.size() > 0, wxS(
"Action groups must have at least one action" ) );
77 return aAction->GetId() == aDefault.GetId();
80 wxASSERT_MSG( valid, wxS(
"Action must be present in a group to be the default" ) );
86#define PALETTE_BORDER 4
87#define BUTTON_BORDER 1
91 wxPopupTransientWindow( aParent, wxBORDER_NONE ),
93 m_isVertical( aVertical ),
95 m_mainSizer( nullptr ),
96 m_buttonSizer( nullptr )
98 m_panel =
new wxPanel(
this, wxID_ANY );
99 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
102 m_buttonSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
105 m_mainSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
120 int bmpWidth = normalBmp.GetPreferredBitmapSizeFor(
this ).GetWidth();
121 int padding = (
m_buttonSize.GetWidth() - bmpWidth ) / 2;
122 wxSize bmSize( size, size );
151 it->second->Enable( aEnable );
160 it->second->Check( aCheck );
167 SetClientSize(
m_panel->GetSize() );
169 wxPopupTransientWindow::Popup( aFocus );
176 if( aEvent.GetKeyCode() == WXK_ESCAPE )
184 const wxSize& size,
long style ) :
185 wxAuiToolBar( parent, id, pos, size, style ),
186 m_paletteTimer( nullptr ),
187 m_auiManager( nullptr ),
188 m_toolManager( parent->GetToolManager() ),
197 Connect( wxEVT_AUITOOLBAR_RIGHT_CLICK,
207 Bind( wxEVT_SYS_COLOUR_CHANGED,
216 Disconnect( wxEVT_AUITOOLBAR_RIGHT_CLICK,
226 Unbind( wxEVT_SYS_COLOUR_CHANGED,
242 wxASSERT( GetParent() );
243 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ),
244 wxS(
"aIsCancellable requires aIsToggleEntry" ) );
246 int toolId = aAction.
GetUIId();
248 AddTool( toolId, wxEmptyString,
250 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ),
252 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
263 int toolId = aAction.
GetUIId();
265 AddTool( toolId, wxEmptyString,
267 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ),
281 AddSpacer( 16 * (
scale - 4 ) / 4 );
286 AddSpacer( 16 * (
scale - 4 ) / 4 );
291 std::unique_ptr<ACTION_MENU> aMenu )
293 int toolId = aAction.
GetUIId();
301 int groupId = aGroup->
GetUIId();
304 wxASSERT( GetParent() );
305 wxASSERT( defaultAction );
312 AddTool( groupId, wxEmptyString,
314 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ),
316 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
317 wxEmptyString, wxEmptyString,
nullptr );
330 return aAction.GetId() == action2->GetId();
340 wxASSERT( GetParent() );
342 int groupId = aGroup->
GetUIId();
344 wxAuiToolBarItem* item = FindTool( groupId );
352 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ) );
360 wxASSERT_MSG( cond, wxString::Format(
"Missing UI condition for action %s",
376 wxAuiToolBarItem* item = FindTool( aID );
377 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
380 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
381 wxASSERT_MSG( control,
382 wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
385 control->InvalidateBestSize();
386 wxSize bestSize = control->GetBestSize();
387 item->SetMinSize( bestSize );
393 if( wxSizerItem* szrItem = item->GetSizerItem() )
394 szrItem->SetMinSize( bestSize );
402 m_sizer->SetItemMinSize( control, bestSize );
426 int toolId = aAction.
GetUIId();
427 wxAuiToolBar::SetToolBitmap( toolId, aBitmap );
430 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
434 tb_item->SetDisabledBitmap(
442 int toolId = aAction.
GetUIId();
445 ToggleTool( toolId, aState );
447 EnableTool( toolId, aState );
453 int toolId = aAction.
GetUIId();
455 EnableTool( toolId, aEnabled );
456 ToggleTool( toolId, aEnabled && aChecked );
462 int id = aEvent.GetId();
463 wxEventType type = aEvent.GetEventType();
466 bool handled =
false;
483 evt = actionIt->second->MakeEvent();
484 evt->SetHasPosition(
false );
499 int toolId = aEvent.GetToolId();
511 toolId = actionIt->second->GetUIId();
520 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
527 condMenu->Evaluate( dummySel );
534 SetHoverItem(
nullptr );
539#define PALETTE_OPEN_DELAY 500
544 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
561 if( aEvent.LeftUp() )
572 int toolId = aEvent.GetToolId();
576 wxAuiToolBarItem* item = FindTool( toolId );
596 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
612 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
615 return aAction->GetUIId() == aEvent.GetId();
618 if( actionIt !=
group->GetActions().end() )
646 wxASSERT( GetParent() );
648 wxASSERT( toolParent );
661 wxRect toolRect = GetToolRect( aItem->GetId() );
664 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
668 size_t numActions =
group->m_actions.size();
674 + ( numActions * toolRect.GetHeight() );
677 switch( pane.dock_direction )
682 pos = ClientToScreen( toolRect.GetBottomLeft() );
687 case wxAUI_DOCK_BOTTOM:
691 pos = ClientToScreen( toolRect.GetTopLeft() );
694 -( paletteLongDim + m_topPadding ) );
697 case wxAUI_DOCK_LEFT:
700 pos = ClientToScreen( toolRect.GetTopRight() );
701 pos += wxPoint( m_rightPadding,
705 case wxAUI_DOCK_RIGHT:
709 pos = ClientToScreen( toolRect.GetTopLeft() );
712 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
730 wxUpdateUIEvent evt( action->
GetUIId() );
732 toolParent->ProcessWindowEvent( evt );
736 if( evt.GetSetEnabled() )
749 RefreshOverflowState();
750 SetHoverItem(
nullptr );
751 SetPressedItem(
nullptr );
755 m_actionPos = wxPoint( -1, -1 );
756 m_actionItem =
nullptr;
770 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
771 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
773 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
776 aDc.SetPen( wxPen( clr ) );
777 aDc.SetBrush( wxBrush( clr ) );
780 int sideLength =
KiROUND( aRect.height / 5.0 );
784 wxPoint btmRight = aRect.GetBottomRight();
785 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
786 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
789 points.Append( &btmRight );
790 points.Append( &topCorner );
791 points.Append( &btmCorner );
793 aDc.DrawPolygon( &points );
799#if wxCHECK_VERSION( 3, 3, 0 )
802 wxClientDC dc(
this );
813 if( m_orientation == wxHORIZONTAL )
815 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
817 m_vertHintSize = GetSize();
818 retval = RealizeHelper( dc,
false );
821 if( retval && RealizeHelper( dc,
true ) )
823 m_horzHintSize = GetSize();
832 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
834 m_horzHintSize = GetSize();
835 retval = RealizeHelper( dc,
true );
838 if( retval && RealizeHelper( dc,
false ) )
840 m_vertHintSize = GetSize();
865 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
867 wxAuiToolBarItem* tool = FindTool( pair.first );
871 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ) );
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
BITMAP_STORE * GetBitmapStore()
wxBitmapBundle KiDisabledBitmapBundle(BITMAPS aBitmap)
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
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.
std::vector< const TOOL_ACTION * > m_actions
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.
ACTION_GROUP(const std::string &aName, const std::vector< const TOOL_ACTION * > &aActions)
const ACTION_CONDITIONS * GetCondition(const TOOL_ACTION &aAction) const
Get the conditions to use for a specific tool action.
static int MakeActionId(const std::string &aActionName)
Generate an unique ID from for an action with given name.
void ThemeChanged()
Notifies the store that the icon theme has been changed by the user, so caches must be invalidated.
The base frame for deriving all KiCad main window classes.
virtual COMMON_SETTINGS * GetCommonSettings() const
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
PGM_BASE & Pgm()
The global program "get" accessor.
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...