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 FromDIP( 4 )
110#define BUTTON_BORDER FromDIP( 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 );
141 int paddingDip = ( ToDIP(
m_buttonSize.GetWidth() ) - iconSize ) / 2;
169 it->second->Enable( aEnable );
178 it->second->Check( aCheck );
185 SetClientSize(
m_panel->GetSize() );
187 wxPopupTransientWindow::Popup( aFocus );
194 if( aEvent.GetKeyCode() == WXK_ESCAPE )
203 wxAuiToolBar( parent, id, pos, size, style ),
222 [&]( wxSizeEvent& aEvent )
227 SetOverflowVisible( !GetToolBarFits() );
235 Bind( wxEVT_DPI_CHANGED,
236 [&]( wxDPIChangedEvent& aEvent )
241 m_toolPacking = FromDIP( 2 );
242 m_toolBorderPadding = FromDIP( 3 );
244 wxSize margin_lt = FromDIP( wxSize( 5, 5 ) );
245 wxSize margin_rb = FromDIP( wxSize( 2, 2 ) );
246 SetMargins( margin_lt.x, margin_lt.y, margin_rb.x, margin_rb.y );
279 std::list<ACTION_TOOLBAR_CONTROL*> controls;
283 if( control->SupportedFor( aContext ) )
284 controls.push_back( control );
293 wxASSERT( GetParent() );
295 std::map<std::string, std::string> currentGroupItems;
309 for(
auto& item : items )
311 switch( item.m_Type )
318 AddSpacer( item.m_Size );
324 std::string groupName = item.m_GroupName.ToStdString();
325 std::vector<const TOOL_ACTION*>
tools;
330 switch( groupItem.
m_Type )
336 wxFAIL_MSG( wxT(
"Unsupported group item type" ) );
344 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find group tool %s" ), groupItem.
m_ActionName ) );
348 tools.push_back( grpAction );
350 if( currentGroupItems[groupName] == groupItem.
m_ActionName )
351 defaultTool = grpAction;
355 std::unique_ptr<ACTION_GROUP>
group = std::make_unique<ACTION_GROUP>( groupName,
tools );
358 group->SetDefaultAction( *defaultTool );
383 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find control factory for %s" ), item.m_ControlName ) );
398 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find toolbar tool %s" ), item.m_ActionName ) );
425 tip.Replace(
"\t",
" " );
427 wxAuiToolBar::DoSetToolTipText( tip );
434 wxString::Format(
"Attempting to add hidden action %s to the toolbar", aAction.
GetName() ) );
439 Add( aAction, isToggleEntry, isCancellable );
445 wxASSERT( GetParent() );
446 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ),
447 wxS(
"aIsCancellable requires aIsToggleEntry" ) );
449 int toolId = aAction.
GetUIId();
452 AddTool( toolId, wxEmptyString,
455 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
466 int toolId = aAction.
GetUIId();
469 AddTool( toolId, wxEmptyString,
484 AddSpacer( 16 * (
scale - 4 ) / 4 );
489 AddSpacer( 16 * (
scale - 4 ) / 4 );
495 wxASSERT( aControl );
497 AddControl( aControl, aLabel );
503 int toolId = aAction.
GetUIId();
511 int groupId = aGroup->GetUIId();
512 const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction();
515 wxASSERT( GetParent() );
516 wxASSERT( defaultAction );
519 bool isToggleEntry =
false;
521 for(
const auto& act : aGroup->GetActions() )
530 AddTool( groupId, wxEmptyString,
533 isToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL, wxEmptyString, wxEmptyString,
nullptr );
546 return aAction.GetId() == action2->GetId();
561 bool inGroup = std::any_of(
group->m_actions.begin(),
group->m_actions.end(),
564 return aAction.GetId() == action2->GetId();
578 wxASSERT( GetParent() );
580 int groupId = aGroup->
GetUIId();
582 wxAuiToolBarItem* item = FindTool( groupId );
597 m_toolManager->GetToolHolder()->UnregisterUIUpdateHandler( groupId );
604 m_toolManager->GetToolHolder()->RegisterUIUpdateHandler( groupId, *cond );
629 wxAuiToolBarItem* item = FindTool( aID );
630 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
633 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
634 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
637 control->InvalidateBestSize();
638 wxSize bestSize = control->GetBestSize();
639 item->SetMinSize( bestSize );
645 if( wxSizerItem* szrItem = item->GetSizerItem() )
646 szrItem->SetMinSize( bestSize );
654 m_sizer->SetItemMinSize( control, bestSize );
673 m_parent->ClearToolbarControl(
id );
686 int toolId = aAction.
GetUIId();
689 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
694 wxBitmap bm = aBitmap.GetBitmapFor(
this );
696 tb_item->SetBitmap( aBitmap );
703 int toolId = aAction.
GetUIId();
706 ToggleTool( toolId, aState );
708 EnableTool( toolId, aState );
714 int toolId = aAction.
GetUIId();
716 EnableTool( toolId, aEnabled );
717 ToggleTool( toolId, aEnabled && aChecked );
723 int id = aEvent.GetId();
724 wxEventType type = aEvent.GetEventType();
727 bool handled =
false;
744 evt = actionIt->second->MakeEvent();
745 evt->SetHasPosition(
false );
760 int toolId = aEvent.GetToolId();
771 toolId = actionIt->second->GetUIId();
780 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
787 condMenu->Evaluate( dummySel );
794 SetHoverItem(
nullptr );
799#define PALETTE_OPEN_DELAY 500
804 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
821 if( aEvent.LeftUp() )
832 int toolId = aEvent.GetToolId();
836 wxAuiToolBarItem* item = FindTool( toolId );
856 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
872 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
875 return aAction->GetUIId() == aEvent.GetId();
878 if( actionIt !=
group->GetActions().end() )
904 wxWindow* toolParent =
dynamic_cast<wxWindow*
>(
m_toolManager->GetToolHolder() );
919 wxRect toolRect = GetToolRect( aItem->GetId() );
922 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
926 size_t numActions =
group->m_actions.size();
932 + ( numActions * toolRect.GetHeight() );
935 switch( pane.dock_direction )
940 pos = ClientToScreen( toolRect.GetBottomLeft() );
945 case wxAUI_DOCK_BOTTOM:
949 pos = ClientToScreen( toolRect.GetTopLeft() );
952 -( paletteLongDim + m_topPadding ) );
955 case wxAUI_DOCK_LEFT:
958 pos = ClientToScreen( toolRect.GetTopRight() );
959 pos += wxPoint( m_rightPadding,
963 case wxAUI_DOCK_RIGHT:
967 pos = ClientToScreen( toolRect.GetTopLeft() );
970 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
987 wxUpdateUIEvent evt( action->
GetUIId() );
989 toolParent->ProcessWindowEvent( evt );
993 if( evt.GetSetEnabled() )
994 m_palette->EnableAction( *action, evt.GetEnabled() );
1006 RefreshOverflowState();
1007 SetHoverItem(
nullptr );
1008 SetPressedItem(
nullptr );
1011 m_tipItem =
nullptr;
1012 m_actionPos = wxPoint( -1, -1 );
1013 m_actionItem =
nullptr;
1027 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
1028 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
1030 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
1033 aDc.SetPen( wxPen( clr ) );
1034 aDc.SetBrush( wxBrush( clr ) );
1037 int sideLength =
KiROUND( aRect.height / 5.0 );
1041 wxPoint btmRight = aRect.GetBottomRight();
1042 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
1043 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
1046 points.Append( &btmRight );
1047 points.Append( &topCorner );
1048 points.Append( &btmCorner );
1050 aDc.DrawPolygon( &points );
1056#if wxCHECK_VERSION( 3, 3, 0 )
1059 wxClientDC dc(
this );
1070 if( m_orientation == wxHORIZONTAL )
1072 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
1074 m_vertHintSize = GetSize();
1075 retval = RealizeHelper( dc,
false );
1078 if( retval && RealizeHelper( dc,
true ) )
1079 m_horzHintSize = GetSize();
1085 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
1087 m_horzHintSize = GetSize();
1088 retval = RealizeHelper( dc,
true );
1091 if( retval && RealizeHelper( dc,
false ) )
1092 m_vertHintSize = GetSize();
1116 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
1118 wxAuiToolBarItem* tool = FindTool( pair.first );
1131 _(
"Grid selector" ),
1132 _(
"Grid Selection box" ),
1144 _(
"Zoom selector" ),
1145 _(
"Zoom Selection box" ),
1157 _(
"IPC/Scripting plugins" ),
1158 _(
"Region to hold the IPC/Scripting action buttons" ),
1163 _(
"Layer selector" ),
1164 _(
"Control to select the layer" ),
1171 _(
"Symbol unit selector" ),
1172 _(
"Displays the current unit" ),
1177 _(
"Symbol body style selector" ),
1178 _(
"Displays the current body style" ),
1183 _(
"Override locks" ),
1184 _(
"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.