49#include <wx/popupwin.h>
50#include <wx/renderer.h>
52#include <wx/dcclient.h>
53#include <wx/settings.h>
69 const std::vector<const TOOL_ACTION*>& aActions )
80 wxASSERT_MSG( aActions.size() > 0, wxS(
"Action groups must have at least one action" ) );
99 return aAction->GetId() == aDefault.GetId();
102 wxASSERT_MSG( valid, wxS(
"Action must be present in a group to be the default" ) );
108#define PALETTE_BORDER FromDIP( 4 )
109#define BUTTON_BORDER FromDIP( 1 )
113 wxPopupTransientWindow( aParent, wxBORDER_NONE ),
120 m_panel =
new wxPanel(
this, wxID_ANY );
121 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
124 m_buttonSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
127 m_mainSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
140 int paddingDip = ( ToDIP(
m_buttonSize.GetWidth() ) - iconSize ) / 2;
168 it->second->Enable( aEnable );
177 it->second->Check( aCheck );
184 SetClientSize(
m_panel->GetSize() );
186 wxPopupTransientWindow::Popup( aFocus );
193 if( aEvent.GetKeyCode() == WXK_ESCAPE )
202 wxAuiToolBar( parent, id, pos, size, style ),
221 [&]( wxSizeEvent& aEvent )
226 SetOverflowVisible( !GetToolBarFits() );
234 Bind( wxEVT_DPI_CHANGED,
235 [&]( wxDPIChangedEvent& aEvent )
240 m_toolPacking = FromDIP( 2 );
241 m_toolBorderPadding = FromDIP( 3 );
243 wxSize margin_lt = FromDIP( wxSize( 5, 5 ) );
244 wxSize margin_rb = FromDIP( wxSize( 2, 2 ) );
245 SetMargins( margin_lt.x, margin_lt.y, margin_rb.x, margin_rb.y );
278 std::list<ACTION_TOOLBAR_CONTROL*> controls;
282 if( control->SupportedFor( aContext ) )
283 controls.push_back( control );
292 wxASSERT( GetParent() );
303 for(
auto& item : items )
305 switch( item.m_Type )
312 AddSpacer( item.m_Size );
318 std::string groupName = item.m_GroupName.ToStdString();
319 std::vector<const TOOL_ACTION*>
tools;
324 switch( groupItem.
m_Type )
330 wxFAIL_MSG( wxT(
"Unsupported group item type" ) );
338 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find group tool %s" ), groupItem.
m_ActionName ) );
342 tools.push_back( grpAction );
344 if( currentGroupItems[groupName] == groupItem.
m_ActionName )
345 defaultTool = grpAction;
353 std::unique_ptr<ACTION_GROUP>
group = std::make_unique<ACTION_GROUP>( groupName,
tools );
356 group->SetDefaultAction( *defaultTool );
381 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find control factory for %s" ), item.m_ControlName ) );
396 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find toolbar tool %s" ), item.m_ActionName ) );
423 tip.Replace(
"\t",
" " );
425 wxAuiToolBar::DoSetToolTipText( tip );
432 wxString::Format(
"Attempting to add hidden action %s to the toolbar", aAction.
GetName() ) );
437 Add( aAction, isToggleEntry, isCancellable );
443 wxASSERT( GetParent() );
444 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ),
445 wxS(
"aIsCancellable requires aIsToggleEntry" ) );
447 int toolId = aAction.
GetUIId();
450 AddTool( toolId, wxEmptyString,
453 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
464 int toolId = aAction.
GetUIId();
467 AddTool( toolId, wxEmptyString,
482 AddSpacer( 16 * (
scale - 4 ) / 4 );
487 AddSpacer( 16 * (
scale - 4 ) / 4 );
493 wxASSERT( aControl );
495 AddControl( aControl, aLabel );
501 int toolId = aAction.
GetUIId();
509 int groupId = aGroup->GetUIId();
510 const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction();
513 wxASSERT( GetParent() );
514 wxASSERT( defaultAction );
517 bool isToggleEntry =
false;
519 for(
const auto& act : aGroup->GetActions() )
527 AddTool( groupId, wxEmptyString,
530 isToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL, wxEmptyString, wxEmptyString,
nullptr );
543 return aAction.GetId() == action2->GetId();
558 bool inGroup = std::any_of(
group->m_actions.begin(),
group->m_actions.end(),
561 return aAction.GetId() == action2->GetId();
575 wxASSERT( GetParent() );
577 int groupId = aGroup->
GetUIId();
579 wxAuiToolBarItem* item = FindTool( groupId );
594 m_toolManager->GetToolHolder()->UnregisterUIUpdateHandler( groupId );
601 m_toolManager->GetToolHolder()->RegisterUIUpdateHandler( groupId, *cond );
627 wxAuiToolBarItem* item = FindTool( aID );
628 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
631 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
632 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
635 control->InvalidateBestSize();
636 wxSize bestSize = control->GetBestSize();
637 item->SetMinSize( bestSize );
643 if( wxSizerItem* szrItem = item->GetSizerItem() )
644 szrItem->SetMinSize( bestSize );
652 m_sizer->SetItemMinSize( control, bestSize );
671 m_parent->ClearToolbarControl(
id );
684 int toolId = aAction.
GetUIId();
687 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
692 wxBitmap bm = aBitmap.GetBitmapFor(
this );
694 tb_item->SetBitmap( aBitmap );
701 int toolId = aAction.
GetUIId();
704 ToggleTool( toolId, aState );
706 EnableTool( toolId, aState );
712 int toolId = aAction.
GetUIId();
714 EnableTool( toolId, aEnabled );
715 ToggleTool( toolId, aEnabled && aChecked );
721 int id = aEvent.GetId();
722 wxEventType type = aEvent.GetEventType();
725 bool handled =
false;
734 bool isCancellable = ( cancelIt !=
m_toolCancellable.end() ) ? cancelIt->second :
false;
739 bool selectionSpecialCase =
false;
743 selectionSpecialCase =
m_parent->ToolStackIsEmpty()
750 if( isCancellable && !GetToolToggled(
id ) )
757 && ( selectionSpecialCase
758 || std::none_of( groupIt->second->GetActions().begin(),
759 groupIt->second->GetActions().end(),
762 return a->IsActivation();
769 const std::vector<const TOOL_ACTION*>& actions =
group->GetActions();
774 for(
size_t i = 0; i < actions.size(); ++i )
776 if( actions[i]->GetId() == current->
GetId() )
778 next = actions[( i + 1 ) % actions.size()];
783 evt =
next->MakeEvent();
784 evt->SetHasPosition(
false );
794 evt = actionIt->second->MakeEvent();
795 evt->SetHasPosition(
false );
810 int toolId = aEvent.GetToolId();
821 toolId = actionIt->second->GetUIId();
830 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
837 condMenu->Evaluate( dummySel );
844 SetHoverItem(
nullptr );
849#define PALETTE_OPEN_DELAY 500
854 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
871 if( aEvent.LeftUp() )
882 int toolId = aEvent.GetToolId();
886 wxAuiToolBarItem* item = FindTool( toolId );
906 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
927 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
930 return aAction->GetUIId() == aEvent.GetId();
933 if( actionIt !=
group->GetActions().end() )
958 wxWindow* toolParent =
dynamic_cast<wxWindow*
>(
m_toolManager->GetToolHolder() );
973 wxRect toolRect = GetToolRect( aItem->GetId() );
976 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
980 size_t numActions =
group->m_actions.size();
986 + ( numActions * toolRect.GetHeight() );
989 switch( pane.dock_direction )
994 pos = ClientToScreen( toolRect.GetBottomLeft() );
999 case wxAUI_DOCK_BOTTOM:
1003 pos = ClientToScreen( toolRect.GetTopLeft() );
1006 -( paletteLongDim + m_topPadding ) );
1009 case wxAUI_DOCK_LEFT:
1012 pos = ClientToScreen( toolRect.GetTopRight() );
1013 pos += wxPoint( m_rightPadding,
1017 case wxAUI_DOCK_RIGHT:
1021 pos = ClientToScreen( toolRect.GetTopLeft() );
1024 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
1041 wxUpdateUIEvent evt( action->
GetUIId() );
1043 toolParent->ProcessWindowEvent( evt );
1047 if( evt.GetSetEnabled() )
1048 m_palette->EnableAction( *action, evt.GetEnabled() );
1061 RefreshOverflowState();
1062 SetHoverItem(
nullptr );
1063 SetPressedItem(
nullptr );
1066 m_tipItem =
nullptr;
1067 m_actionPos = wxPoint( -1, -1 );
1068 m_actionItem =
nullptr;
1082 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
1083 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
1085 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
1088 aDc.SetPen( wxPen( clr ) );
1089 aDc.SetBrush( wxBrush( clr ) );
1092 int sideLength =
KiROUND( aRect.height / 5.0 );
1096 wxPoint btmRight = aRect.GetBottomRight();
1097 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
1098 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
1101 points.Append( &btmRight );
1102 points.Append( &topCorner );
1103 points.Append( &btmCorner );
1105 aDc.DrawPolygon( &points );
1111#if wxCHECK_VERSION( 3, 3, 0 )
1114 wxClientDC dc(
this );
1125 if( m_orientation == wxHORIZONTAL )
1127 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
1129 m_vertHintSize = GetSize();
1130 retval = RealizeHelper( dc,
false );
1133 if( retval && RealizeHelper( dc,
true ) )
1134 m_horzHintSize = GetSize();
1140 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
1142 m_horzHintSize = GetSize();
1143 retval = RealizeHelper( dc,
true );
1146 if( retval && RealizeHelper( dc,
false ) )
1147 m_vertHintSize = GetSize();
1171 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
1173 wxAuiToolBarItem* tool = FindTool( pair.first );
1186 _(
"Grid selector" ),
1187 _(
"Grid Selection box" ),
1199 _(
"Zoom selector" ),
1200 _(
"Zoom Selection box" ),
1212 _(
"IPC/Scripting plugins" ),
1213 _(
"Region to hold the IPC/Scripting action buttons" ),
1218 _(
"Layer selector" ),
1219 _(
"Control to select the layer" ),
1226 _(
"Symbol unit selector" ),
1227 _(
"Displays the current unit" ),
1232 _(
"Symbol body style selector" ),
1233 _(
"Displays the current body style" ),
1238 _(
"Override locks" ),
1239 _(
"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)
static TOOL_ACTION selectSetLasso
static TOOL_ACTION selectSetRect
Set lasso selection mode.
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.
std::string GetName() const
Get the name of the group.
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.
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.