48#include <wx/popupwin.h>
49#include <wx/renderer.h>
51#include <wx/dcclient.h>
52#include <wx/settings.h>
56#include <python_scripting.h>
68 const std::vector<const TOOL_ACTION*>& aActions )
79 wxASSERT_MSG( aActions.size() > 0, wxS(
"Action groups must have at least one action" ) );
98 return aAction->GetId() == aDefault.GetId();
101 wxASSERT_MSG( valid, wxS(
"Action must be present in a group to be the default" ) );
107#define PALETTE_BORDER 4
108#define BUTTON_BORDER 1
112 wxPopupTransientWindow( aParent, wxBORDER_NONE ),
114 m_isVertical( aVertical ),
116 m_mainSizer( nullptr ),
117 m_buttonSizer( nullptr )
119 m_panel =
new wxPanel(
this, wxID_ANY );
120 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
123 m_buttonSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
126 m_mainSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
141 int bmpWidth = normalBmp.GetPreferredBitmapSizeFor(
this ).GetWidth();
142 int padding = (
m_buttonSize.GetWidth() - bmpWidth ) / 2;
143 wxSize bmSize( size, size );
172 it->second->Enable( aEnable );
181 it->second->Check( aCheck );
188 SetClientSize(
m_panel->GetSize() );
190 wxPopupTransientWindow::Popup( aFocus );
197 if( aEvent.GetKeyCode() == WXK_ESCAPE )
205 const wxSize& size,
long style ) :
206 wxAuiToolBar( parent, id, pos, size, style ),
207 m_paletteTimer( nullptr ),
208 m_auiManager( nullptr ),
209 m_toolManager( parent->GetToolManager() ),
218 Connect( wxEVT_AUITOOLBAR_RIGHT_CLICK,
228 Bind( wxEVT_SYS_COLOUR_CHANGED,
237 Disconnect( wxEVT_AUITOOLBAR_RIGHT_CLICK,
247 Unbind( wxEVT_SYS_COLOUR_CHANGED,
263 wxASSERT( GetParent() );
271 for(
auto& item : items )
273 switch( item.m_Type )
275 case TOOLBAR_ITEM_TYPE::SEPARATOR:
279 case TOOLBAR_ITEM_TYPE::SPACER:
280 AddSpacer( item.m_Size );
283 case TOOLBAR_ITEM_TYPE::TB_GROUP:
286 std::vector<const TOOL_ACTION*>
tools;
288 for(
auto& groupItem : item.m_GroupItems )
290 switch( groupItem.m_Type )
292 case TOOLBAR_ITEM_TYPE::SEPARATOR:
293 case TOOLBAR_ITEM_TYPE::SPACER:
294 case TOOLBAR_ITEM_TYPE::TB_GROUP:
295 case TOOLBAR_ITEM_TYPE::CONTROL:
296 wxASSERT_MSG(
false,
"Unsupported group item type" );
299 case TOOLBAR_ITEM_TYPE::TOOL:
304 wxASSERT_MSG(
false, wxString::Format(
"Unable to find group tool %s", groupItem.m_ActionName ) );
308 tools.push_back( grpAction );
312 AddGroup( std::make_unique<ACTION_GROUP>( item.m_GroupName.ToStdString(),
tools ) );
316 case TOOLBAR_ITEM_TYPE::CONTROL:
324 wxASSERT_MSG(
false, wxString::Format(
"Unable to find control factory for %s", item.m_ControlName ) );
333 case TOOLBAR_ITEM_TYPE::TOOL:
339 wxASSERT_MSG(
false, wxString::Format(
"Unable to find toolbar tool %s", item.m_ActionName ) );
357 wxString::Format(
"Attempting to add hidden action %s to the toolbar", aAction.
GetName() ) );
362 Add( aAction, isToggleEntry, isCancellable );
368 wxASSERT( GetParent() );
369 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ),
370 wxS(
"aIsCancellable requires aIsToggleEntry" ) );
372 int toolId = aAction.
GetUIId();
374 AddTool( toolId, wxEmptyString,
376 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ),
378 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
389 int toolId = aAction.
GetUIId();
391 AddTool( toolId, wxEmptyString,
393 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ),
407 AddSpacer( 16 * (
scale - 4 ) / 4 );
412 AddSpacer( 16 * (
scale - 4 ) / 4 );
418 wxASSERT( aControl );
420 AddControl( aControl, aLabel );
425 std::unique_ptr<ACTION_MENU> aMenu )
427 int toolId = aAction.
GetUIId();
435 int groupId = aGroup->GetUIId();
436 const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction();
438 wxASSERT( GetParent() );
439 wxASSERT( defaultAction );
442 bool isToggleEntry =
false;
444 for(
const auto& act : aGroup->GetActions() )
445 isToggleEntry |= act->CheckToolbarState( TOOLBAR_STATE::TOGGLE );
453 AddTool( groupId, wxEmptyString,
455 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ),
457 isToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
458 wxEmptyString, wxEmptyString,
nullptr );
471 return aAction.GetId() == action2->GetId();
481 wxASSERT( GetParent() );
483 int groupId = aGroup->
GetUIId();
485 wxAuiToolBarItem* item = FindTool( groupId );
493 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ) );
531 wxAuiToolBarItem* item = FindTool( aID );
532 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
535 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
536 wxASSERT_MSG( control,
537 wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
540 control->InvalidateBestSize();
541 wxSize bestSize = control->GetBestSize();
542 item->SetMinSize( bestSize );
548 if( wxSizerItem* szrItem = item->GetSizerItem() )
549 szrItem->SetMinSize( bestSize );
557 m_sizer->SetItemMinSize( control, bestSize );
581 int toolId = aAction.
GetUIId();
582 wxAuiToolBar::SetToolBitmap( toolId, aBitmap );
585 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
589 tb_item->SetDisabledBitmap(
597 int toolId = aAction.
GetUIId();
600 ToggleTool( toolId, aState );
602 EnableTool( toolId, aState );
608 int toolId = aAction.
GetUIId();
610 EnableTool( toolId, aEnabled );
611 ToggleTool( toolId, aEnabled && aChecked );
617 int id = aEvent.GetId();
618 wxEventType type = aEvent.GetEventType();
621 bool handled =
false;
638 evt = actionIt->second->MakeEvent();
639 evt->SetHasPosition(
false );
654 int toolId = aEvent.GetToolId();
666 toolId = actionIt->second->GetUIId();
675 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
682 condMenu->Evaluate( dummySel );
689 SetHoverItem(
nullptr );
694#define PALETTE_OPEN_DELAY 500
699 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
716 if( aEvent.LeftUp() )
727 int toolId = aEvent.GetToolId();
731 wxAuiToolBarItem* item = FindTool( toolId );
751 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
767 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
770 return aAction->GetUIId() == aEvent.GetId();
773 if( actionIt !=
group->GetActions().end() )
801 wxASSERT( GetParent() );
803 wxASSERT( toolParent );
816 wxRect toolRect = GetToolRect( aItem->GetId() );
819 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
823 size_t numActions =
group->m_actions.size();
829 + ( numActions * toolRect.GetHeight() );
832 switch( pane.dock_direction )
837 pos = ClientToScreen( toolRect.GetBottomLeft() );
842 case wxAUI_DOCK_BOTTOM:
846 pos = ClientToScreen( toolRect.GetTopLeft() );
849 -( paletteLongDim + m_topPadding ) );
852 case wxAUI_DOCK_LEFT:
855 pos = ClientToScreen( toolRect.GetTopRight() );
856 pos += wxPoint( m_rightPadding,
860 case wxAUI_DOCK_RIGHT:
864 pos = ClientToScreen( toolRect.GetTopLeft() );
867 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
885 wxUpdateUIEvent evt( action->
GetUIId() );
887 toolParent->ProcessWindowEvent( evt );
891 if( evt.GetSetEnabled() )
904 RefreshOverflowState();
905 SetHoverItem(
nullptr );
906 SetPressedItem(
nullptr );
910 m_actionPos = wxPoint( -1, -1 );
911 m_actionItem =
nullptr;
925 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
926 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
928 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
931 aDc.SetPen( wxPen( clr ) );
932 aDc.SetBrush( wxBrush( clr ) );
935 int sideLength =
KiROUND( aRect.height / 5.0 );
939 wxPoint btmRight = aRect.GetBottomRight();
940 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
941 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
944 points.Append( &btmRight );
945 points.Append( &topCorner );
946 points.Append( &btmCorner );
948 aDc.DrawPolygon( &points );
954#if wxCHECK_VERSION( 3, 3, 0 )
957 wxClientDC dc(
this );
968 if( m_orientation == wxHORIZONTAL )
970 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
972 m_vertHintSize = GetSize();
973 retval = RealizeHelper( dc,
false );
976 if( retval && RealizeHelper( dc,
true ) )
978 m_horzHintSize = GetSize();
987 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
989 m_horzHintSize = GetSize();
990 retval = RealizeHelper( dc,
true );
993 if( retval && RealizeHelper( dc,
false ) )
995 m_vertHintSize = GetSize();
1020 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
1022 wxAuiToolBarItem* tool = FindTool( pair.first );
1026 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ) );
1037 _(
"Grid Selection box" ) );
1040 _(
"Zoom Selection box" ) );
1043 _(
"Region to hold the IPC/Scripting action buttons" ) );
1046 _(
"Control to select the layer" ) );
1049 _(
"Displays the current unit" ) );
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.
ACTION_GROUP(const std::string_view &aName)
std::vector< const TOOL_ACTION * > m_actions
void SetActions(const std::vector< const TOOL_ACTION * > &aActions)
Set the actions contained in this group.
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.
std::string m_name
The default action to display on the toolbar item.
const ACTION_CONDITIONS * GetCondition(const TOOL_ACTION &aAction) const
Get the conditions to use for a specific tool action.
TOOL_ACTION * FindAction(const std::string &aActionName) const
Find an action with a given name (if there is one available).
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.
ACTION_TOOLBAR_CONTROL_FACTORY * GetCustomToolbarControlFactory(const std::string &aName)
virtual COMMON_SETTINGS * GetCommonSettings() const
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
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 ...
wxLogTrace helper definitions.