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() );
294 std::map<std::string, std::string> currentGroupItems;
308 for(
auto& item : items )
310 switch( item.m_Type )
317 AddSpacer( item.m_Size );
323 std::string groupName = item.m_GroupName.ToStdString();
324 std::vector<const TOOL_ACTION*>
tools;
329 switch( groupItem.
m_Type )
335 wxFAIL_MSG( wxT(
"Unsupported group item type" ) );
343 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find group tool %s" ), groupItem.
m_ActionName ) );
347 tools.push_back( grpAction );
349 if( currentGroupItems[groupName] == groupItem.
m_ActionName )
350 defaultTool = grpAction;
354 std::unique_ptr<ACTION_GROUP>
group = std::make_unique<ACTION_GROUP>( groupName,
tools );
357 group->SetDefaultAction( *defaultTool );
382 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find control factory for %s" ), item.m_ControlName ) );
397 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find toolbar tool %s" ), item.m_ActionName ) );
424 tip.Replace(
"\t",
" " );
426 wxAuiToolBar::DoSetToolTipText( tip );
433 wxString::Format(
"Attempting to add hidden action %s to the toolbar", aAction.
GetName() ) );
438 Add( aAction, isToggleEntry, isCancellable );
444 wxASSERT( GetParent() );
445 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ),
446 wxS(
"aIsCancellable requires aIsToggleEntry" ) );
448 int toolId = aAction.
GetUIId();
451 AddTool( toolId, wxEmptyString,
454 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
465 int toolId = aAction.
GetUIId();
468 AddTool( toolId, wxEmptyString,
483 AddSpacer( 16 * (
scale - 4 ) / 4 );
488 AddSpacer( 16 * (
scale - 4 ) / 4 );
494 wxASSERT( aControl );
496 AddControl( aControl, aLabel );
502 int toolId = aAction.
GetUIId();
510 int groupId = aGroup->GetUIId();
511 const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction();
514 wxASSERT( GetParent() );
515 wxASSERT( defaultAction );
518 bool isToggleEntry =
false;
520 for(
const auto& act : aGroup->GetActions() )
528 AddTool( groupId, wxEmptyString,
531 isToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL, wxEmptyString, wxEmptyString,
nullptr );
544 return aAction.GetId() == action2->GetId();
559 bool inGroup = std::any_of(
group->m_actions.begin(),
group->m_actions.end(),
562 return aAction.GetId() == action2->GetId();
576 wxASSERT( GetParent() );
578 int groupId = aGroup->
GetUIId();
580 wxAuiToolBarItem* item = FindTool( groupId );
595 m_toolManager->GetToolHolder()->UnregisterUIUpdateHandler( groupId );
602 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.
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.