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() )
529 AddTool( groupId, wxEmptyString,
532 isToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL, wxEmptyString, wxEmptyString,
nullptr );
545 return aAction.GetId() == action2->GetId();
560 bool inGroup = std::any_of(
group->m_actions.begin(),
group->m_actions.end(),
563 return aAction.GetId() == action2->GetId();
577 wxASSERT( GetParent() );
579 int groupId = aGroup->
GetUIId();
581 wxAuiToolBarItem* item = FindTool( groupId );
596 m_toolManager->GetToolHolder()->UnregisterUIUpdateHandler( groupId );
603 m_toolManager->GetToolHolder()->RegisterUIUpdateHandler( groupId, *cond );
628 wxAuiToolBarItem* item = FindTool( aID );
629 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
632 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
633 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
636 control->InvalidateBestSize();
637 wxSize bestSize = control->GetBestSize();
638 item->SetMinSize( bestSize );
644 if( wxSizerItem* szrItem = item->GetSizerItem() )
645 szrItem->SetMinSize( bestSize );
653 m_sizer->SetItemMinSize( control, bestSize );
672 m_parent->ClearToolbarControl(
id );
685 int toolId = aAction.
GetUIId();
688 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
693 wxBitmap bm = aBitmap.GetBitmapFor(
this );
695 tb_item->SetBitmap( aBitmap );
702 int toolId = aAction.
GetUIId();
705 ToggleTool( toolId, aState );
707 EnableTool( toolId, aState );
713 int toolId = aAction.
GetUIId();
715 EnableTool( toolId, aEnabled );
716 ToggleTool( toolId, aEnabled && aChecked );
722 int id = aEvent.GetId();
723 wxEventType type = aEvent.GetEventType();
726 bool handled =
false;
735 bool isCancellable = ( cancelIt !=
m_toolCancellable.end() ) ? cancelIt->second :
false;
739 if( isCancellable && !GetToolToggled(
id ) )
746 && std::none_of( groupIt->second->GetActions().begin(),
747 groupIt->second->GetActions().end(),
750 return a->IsActivation();
757 const std::vector<const TOOL_ACTION*>& actions =
group->GetActions();
762 for(
size_t i = 0; i < actions.size(); ++i )
764 if( actions[i]->GetId() == current->
GetId() )
766 next = actions[( i + 1 ) % actions.size()];
771 evt =
next->MakeEvent();
772 evt->SetHasPosition(
false );
782 evt = actionIt->second->MakeEvent();
783 evt->SetHasPosition(
false );
798 int toolId = aEvent.GetToolId();
809 toolId = actionIt->second->GetUIId();
818 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
825 condMenu->Evaluate( dummySel );
832 SetHoverItem(
nullptr );
837#define PALETTE_OPEN_DELAY 500
842 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
859 if( aEvent.LeftUp() )
870 int toolId = aEvent.GetToolId();
874 wxAuiToolBarItem* item = FindTool( toolId );
894 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
910 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
913 return aAction->GetUIId() == aEvent.GetId();
916 if( actionIt !=
group->GetActions().end() )
942 wxWindow* toolParent =
dynamic_cast<wxWindow*
>(
m_toolManager->GetToolHolder() );
957 wxRect toolRect = GetToolRect( aItem->GetId() );
960 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
964 size_t numActions =
group->m_actions.size();
970 + ( numActions * toolRect.GetHeight() );
973 switch( pane.dock_direction )
978 pos = ClientToScreen( toolRect.GetBottomLeft() );
983 case wxAUI_DOCK_BOTTOM:
987 pos = ClientToScreen( toolRect.GetTopLeft() );
990 -( paletteLongDim + m_topPadding ) );
993 case wxAUI_DOCK_LEFT:
996 pos = ClientToScreen( toolRect.GetTopRight() );
997 pos += wxPoint( m_rightPadding,
1001 case wxAUI_DOCK_RIGHT:
1005 pos = ClientToScreen( toolRect.GetTopLeft() );
1008 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
1025 wxUpdateUIEvent evt( action->
GetUIId() );
1027 toolParent->ProcessWindowEvent( evt );
1031 if( evt.GetSetEnabled() )
1032 m_palette->EnableAction( *action, evt.GetEnabled() );
1045 RefreshOverflowState();
1046 SetHoverItem(
nullptr );
1047 SetPressedItem(
nullptr );
1050 m_tipItem =
nullptr;
1051 m_actionPos = wxPoint( -1, -1 );
1052 m_actionItem =
nullptr;
1066 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
1067 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
1069 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
1072 aDc.SetPen( wxPen( clr ) );
1073 aDc.SetBrush( wxBrush( clr ) );
1076 int sideLength =
KiROUND( aRect.height / 5.0 );
1080 wxPoint btmRight = aRect.GetBottomRight();
1081 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
1082 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
1085 points.Append( &btmRight );
1086 points.Append( &topCorner );
1087 points.Append( &btmCorner );
1089 aDc.DrawPolygon( &points );
1095#if wxCHECK_VERSION( 3, 3, 0 )
1098 wxClientDC dc(
this );
1109 if( m_orientation == wxHORIZONTAL )
1111 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
1113 m_vertHintSize = GetSize();
1114 retval = RealizeHelper( dc,
false );
1117 if( retval && RealizeHelper( dc,
true ) )
1118 m_horzHintSize = GetSize();
1124 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
1126 m_horzHintSize = GetSize();
1127 retval = RealizeHelper( dc,
true );
1130 if( retval && RealizeHelper( dc,
false ) )
1131 m_vertHintSize = GetSize();
1155 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
1157 wxAuiToolBarItem* tool = FindTool( pair.first );
1170 _(
"Grid selector" ),
1171 _(
"Grid Selection box" ),
1183 _(
"Zoom selector" ),
1184 _(
"Zoom Selection box" ),
1196 _(
"IPC/Scripting plugins" ),
1197 _(
"Region to hold the IPC/Scripting action buttons" ),
1202 _(
"Layer selector" ),
1203 _(
"Control to select the layer" ),
1210 _(
"Symbol unit selector" ),
1211 _(
"Displays the current unit" ),
1216 _(
"Symbol body style selector" ),
1217 _(
"Displays the current body style" ),
1222 _(
"Override locks" ),
1223 _(
"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.