49#include <wx/popupwin.h>
50#include <wx/renderer.h>
52#include <wx/dcclient.h>
53#include <wx/settings.h>
57#include <python_scripting.h>
70 const std::vector<const TOOL_ACTION*>& aActions )
81 wxASSERT_MSG( aActions.size() > 0, wxS(
"Action groups must have at least one action" ) );
100 return aAction->GetId() == aDefault.GetId();
103 wxASSERT_MSG( valid, wxS(
"Action must be present in a group to be the default" ) );
109#define PALETTE_BORDER 4
110#define BUTTON_BORDER 1
114 wxPopupTransientWindow( aParent, wxBORDER_NONE ),
121 m_panel =
new wxPanel(
this, wxID_ANY );
122 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
125 m_buttonSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
128 m_mainSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
142 int bmpWidth = normalBmp.GetPreferredBitmapSizeFor(
this ).GetWidth();
143 int padding = (
m_buttonSize.GetWidth() - bmpWidth ) / 2;
171 it->second->Enable( aEnable );
180 it->second->Check( aCheck );
187 SetClientSize(
m_panel->GetSize() );
189 wxPopupTransientWindow::Popup( aFocus );
196 if( aEvent.GetKeyCode() == WXK_ESCAPE )
205 wxAuiToolBar( parent, id, pos, size, style ),
225 Bind( wxEVT_DPI_CHANGED,
226 [&]( wxDPIChangedEvent& aEvent )
231 m_toolPacking = FromDIP( 2 );
232 m_toolBorderPadding = FromDIP( 3 );
234 wxSize margin_lt = FromDIP( wxSize( 5, 5 ) );
235 wxSize margin_rb = FromDIP( wxSize( 2, 2 ) );
236 SetMargins( margin_lt.x, margin_lt.y, margin_rb.x, margin_rb.y );
269 std::list<ACTION_TOOLBAR_CONTROL*> controls;
273 if( control->SupportedFor( aContext ) )
274 controls.push_back( control );
283 wxASSERT( GetParent() );
285 std::map<std::string, std::string> currentGroupItems;
299 for(
auto& item : items )
301 switch( item.m_Type )
308 AddSpacer( item.m_Size );
314 std::string groupName = item.m_GroupName.ToStdString();
315 std::vector<const TOOL_ACTION*>
tools;
320 switch( groupItem.
m_Type )
326 wxFAIL_MSG( wxT(
"Unsupported group item type" ) );
334 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find group tool %s" ), groupItem.
m_ActionName ) );
338 tools.push_back( grpAction );
340 if( currentGroupItems[groupName] == groupItem.
m_ActionName )
341 defaultTool = grpAction;
345 std::unique_ptr<ACTION_GROUP>
group = std::make_unique<ACTION_GROUP>( groupName,
tools );
348 group->SetDefaultAction( *defaultTool );
373 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find control factory for %s" ), item.m_ControlName ) );
388 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find toolbar tool %s" ), item.m_ActionName ) );
413 wxString::Format(
"Attempting to add hidden action %s to the toolbar", aAction.
GetName() ) );
418 Add( aAction, isToggleEntry, isCancellable );
424 wxASSERT( GetParent() );
425 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ),
426 wxS(
"aIsCancellable requires aIsToggleEntry" ) );
428 int toolId = aAction.
GetUIId();
431 AddTool( toolId, wxEmptyString,
434 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
445 int toolId = aAction.
GetUIId();
448 AddTool( toolId, wxEmptyString,
463 AddSpacer( 16 * (
scale - 4 ) / 4 );
468 AddSpacer( 16 * (
scale - 4 ) / 4 );
474 wxASSERT( aControl );
476 AddControl( aControl, aLabel );
482 int toolId = aAction.
GetUIId();
490 int groupId = aGroup->GetUIId();
491 const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction();
494 wxASSERT( GetParent() );
495 wxASSERT( defaultAction );
498 bool isToggleEntry =
false;
500 for(
const auto& act : aGroup->GetActions() )
509 AddTool( groupId, wxEmptyString,
512 isToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL, wxEmptyString, wxEmptyString,
nullptr );
525 return aAction.GetId() == action2->GetId();
540 bool inGroup = std::any_of(
group->m_actions.begin(),
group->m_actions.end(),
543 return aAction.GetId() == action2->GetId();
557 wxASSERT( GetParent() );
559 int groupId = aGroup->
GetUIId();
561 wxAuiToolBarItem* item = FindTool( groupId );
576 m_toolManager->GetToolHolder()->UnregisterUIUpdateHandler( groupId );
583 m_toolManager->GetToolHolder()->RegisterUIUpdateHandler( groupId, *cond );
608 wxAuiToolBarItem* item = FindTool( aID );
609 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
612 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
613 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
616 control->InvalidateBestSize();
617 wxSize bestSize = control->GetBestSize();
618 item->SetMinSize( bestSize );
624 if( wxSizerItem* szrItem = item->GetSizerItem() )
625 szrItem->SetMinSize( bestSize );
633 m_sizer->SetItemMinSize( control, bestSize );
652 m_parent->ClearToolbarControl(
id );
665 int toolId = aAction.
GetUIId();
668 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
673 wxBitmap bm = aBitmap.GetBitmapFor(
this );
675 tb_item->SetBitmap( aBitmap );
682 int toolId = aAction.
GetUIId();
685 ToggleTool( toolId, aState );
687 EnableTool( toolId, aState );
693 int toolId = aAction.
GetUIId();
695 EnableTool( toolId, aEnabled );
696 ToggleTool( toolId, aEnabled && aChecked );
702 int id = aEvent.GetId();
703 wxEventType type = aEvent.GetEventType();
706 bool handled =
false;
723 evt = actionIt->second->MakeEvent();
724 evt->SetHasPosition(
false );
739 int toolId = aEvent.GetToolId();
750 toolId = actionIt->second->GetUIId();
759 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
766 condMenu->Evaluate( dummySel );
773 SetHoverItem(
nullptr );
778#define PALETTE_OPEN_DELAY 500
783 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
800 if( aEvent.LeftUp() )
811 int toolId = aEvent.GetToolId();
815 wxAuiToolBarItem* item = FindTool( toolId );
835 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
851 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
854 return aAction->GetUIId() == aEvent.GetId();
857 if( actionIt !=
group->GetActions().end() )
883 wxWindow* toolParent =
dynamic_cast<wxWindow*
>(
m_toolManager->GetToolHolder() );
898 wxRect toolRect = GetToolRect( aItem->GetId() );
901 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
905 size_t numActions =
group->m_actions.size();
911 + ( numActions * toolRect.GetHeight() );
914 switch( pane.dock_direction )
919 pos = ClientToScreen( toolRect.GetBottomLeft() );
924 case wxAUI_DOCK_BOTTOM:
928 pos = ClientToScreen( toolRect.GetTopLeft() );
931 -( paletteLongDim + m_topPadding ) );
934 case wxAUI_DOCK_LEFT:
937 pos = ClientToScreen( toolRect.GetTopRight() );
938 pos += wxPoint( m_rightPadding,
942 case wxAUI_DOCK_RIGHT:
946 pos = ClientToScreen( toolRect.GetTopLeft() );
949 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
966 wxUpdateUIEvent evt( action->
GetUIId() );
968 toolParent->ProcessWindowEvent( evt );
972 if( evt.GetSetEnabled() )
973 m_palette->EnableAction( *action, evt.GetEnabled() );
985 RefreshOverflowState();
986 SetHoverItem(
nullptr );
987 SetPressedItem(
nullptr );
991 m_actionPos = wxPoint( -1, -1 );
992 m_actionItem =
nullptr;
1006 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
1007 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
1009 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
1012 aDc.SetPen( wxPen( clr ) );
1013 aDc.SetBrush( wxBrush( clr ) );
1016 int sideLength =
KiROUND( aRect.height / 5.0 );
1020 wxPoint btmRight = aRect.GetBottomRight();
1021 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
1022 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
1025 points.Append( &btmRight );
1026 points.Append( &topCorner );
1027 points.Append( &btmCorner );
1029 aDc.DrawPolygon( &points );
1035#if wxCHECK_VERSION( 3, 3, 0 )
1038 wxClientDC dc(
this );
1049 if( m_orientation == wxHORIZONTAL )
1051 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
1053 m_vertHintSize = GetSize();
1054 retval = RealizeHelper( dc,
false );
1057 if( retval && RealizeHelper( dc,
true ) )
1058 m_horzHintSize = GetSize();
1064 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
1066 m_horzHintSize = GetSize();
1067 retval = RealizeHelper( dc,
true );
1070 if( retval && RealizeHelper( dc,
false ) )
1071 m_vertHintSize = GetSize();
1095 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
1097 wxAuiToolBarItem* tool = FindTool( pair.first );
1110 _(
"Grid selector" ),
1111 _(
"Grid Selection box" ),
1123 _(
"Zoom selector" ),
1124 _(
"Zoom Selection box" ),
1136 _(
"IPC/Scripting plugins" ),
1137 _(
"Region to hold the IPC/Scripting action buttons" ),
1142 _(
"Layer selector" ),
1143 _(
"Control to select the layer" ),
1150 _(
"Symbol unit selector" ),
1151 _(
"Displays the current unit" ),
1156 _(
"Symbol body style selector" ),
1157 _(
"Displays the current body style" ),
1162 _(
"Override locks" ),
1163 _(
"Allow moving of locked items with the mouse" ),
wxBitmapBundle KiBitmapBundleDef(BITMAPS aBitmap, int aDefHeight)
Constructs and returns a bitmap bundle for the given icon ID, with the default bitmap size being aDef...
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
BITMAP_STORE * GetBitmapStore()
KICOMMON_API wxBitmapBundle KiDisabledBitmapBundleDef(BITMAPS aBitmap, int aDefHeight)
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. Non-owning.
std::string m_name
The default action to display on the toolbar item.
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
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
@ FRAME_SCH_SYMBOL_EDITOR
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.