45#include <wx/popupwin.h>
46#include <wx/renderer.h>
48#include <wx/dcclient.h>
49#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 )
201bool ACTION_TOOLBAR_PALETTE::MSWHandleMessage( WXLRESULT* aResult, WXUINT aMessage,
202 WXWPARAM aWParam, WXLPARAM aLParam )
211 if( aMessage == WM_ACTIVATE && LOWORD( aWParam ) == WA_INACTIVE )
213 BOOL tracking = FALSE;
215 if( ::SystemParametersInfo( SPI_GETACTIVEWINDOWTRACKING, 0, &tracking, 0 ) && tracking )
217 HWND activated =
reinterpret_cast<HWND
>( aLParam );
218 wxWindow* owner = MSWGetOwner();
220 if( activated && owner && ::GetAncestor( activated, GA_ROOT ) == owner->GetHWND() )
221 return wxPopupTransientWindowBase::MSWHandleMessage( aResult, aMessage, aWParam,
226 return wxPopupTransientWindow::MSWHandleMessage( aResult, aMessage, aWParam, aLParam );
233 wxAuiToolBar( parent, id, pos, size, style ),
253 [&]( wxSizeEvent& aEvent )
258 SetOverflowVisible( !GetToolBarFits() );
266 Bind( wxEVT_DPI_CHANGED,
267 [&]( wxDPIChangedEvent& aEvent )
272 SetToolPacking( FromDIP( 2 ) );
273 SetToolBorderPadding( FromDIP( 3 ) );
275 wxSize margin_lt = FromDIP( wxSize( 5, 5 ) );
276 wxSize margin_rb = FromDIP( wxSize( 2, 2 ) );
277 SetMargins( margin_lt.x, margin_lt.y, margin_rb.x, margin_rb.y );
282 if( GetToolCount() > 0 )
285 InvalidateBestSize();
321 std::list<ACTION_TOOLBAR_CONTROL*> controls;
325 if( control->SupportedFor( aContext ) )
326 controls.push_back( control );
335 wxASSERT( GetParent() );
346 for(
auto& item : items )
348 switch( item.m_Type )
355 AddSpacer( item.m_Size );
361 std::string groupName = item.m_GroupName.ToStdString();
362 std::vector<const TOOL_ACTION*>
tools;
367 switch( groupItem.
m_Type )
373 wxFAIL_MSG( wxT(
"Unsupported group item type" ) );
381 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find group tool %s" ), groupItem.
m_ActionName ) );
385 tools.push_back( grpAction );
387 if( currentGroupItems[groupName] == groupItem.
m_ActionName )
388 defaultTool = grpAction;
396 std::unique_ptr<ACTION_GROUP>
group = std::make_unique<ACTION_GROUP>( groupName,
tools );
399 group->SetDefaultAction( *defaultTool );
424 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find control factory for %s" ), item.m_ControlName ) );
439 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find toolbar tool %s" ), item.m_ActionName ) );
466 tip.Replace(
"\t",
" " );
468 wxAuiToolBar::DoSetToolTipText( tip );
475 wxString::Format(
"Attempting to add hidden action %s to the toolbar", aAction.
GetName() ) );
480 Add( aAction, isToggleEntry, isCancellable );
486 wxASSERT( GetParent() );
487 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ),
488 wxS(
"aIsCancellable requires aIsToggleEntry" ) );
490 int toolId = aAction.
GetUIId();
493 AddTool( toolId, wxEmptyString,
496 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
507 int toolId = aAction.
GetUIId();
510 AddTool( toolId, wxEmptyString,
525 AddSpacer( 16 * (
scale - 4 ) / 4 );
530 AddSpacer( 16 * (
scale - 4 ) / 4 );
536 wxASSERT( aControl );
538 AddControl( aControl, aLabel );
544 int toolId = aAction.
GetUIId();
552 int groupId = aGroup->GetUIId();
553 const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction();
556 wxASSERT( GetParent() );
557 wxASSERT( defaultAction );
560 bool isToggleEntry =
false;
562 for(
const auto& act : aGroup->GetActions() )
570 AddTool( groupId, wxEmptyString,
573 isToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL, wxEmptyString, wxEmptyString,
nullptr );
586 return aAction.GetId() == action2->GetId();
601 bool inGroup = std::any_of(
group->m_actions.begin(),
group->m_actions.end(),
604 return aAction.GetId() == action2->GetId();
618 wxASSERT( GetParent() );
620 int groupId = aGroup->
GetUIId();
622 wxAuiToolBarItem* item = FindTool( groupId );
637 m_toolManager->GetToolHolder()->UnregisterUIUpdateHandler( groupId );
644 m_toolManager->GetToolHolder()->RegisterUIUpdateHandler( groupId, *cond );
670 wxAuiToolBarItem* item = FindTool( aID );
671 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
674 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
675 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
678 control->InvalidateBestSize();
679 wxSize bestSize = control->GetBestSize();
680 item->SetMinSize( bestSize );
686 if( wxSizerItem* szrItem = item->GetSizerItem() )
687 szrItem->SetMinSize( bestSize );
695 m_sizer->SetItemMinSize( control, bestSize );
714 m_parent->ClearToolbarControl(
id );
727 int toolId = aAction.
GetUIId();
730 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
735 wxBitmap bm = aBitmap.GetBitmapFor(
this );
737 tb_item->SetBitmap( aBitmap );
744 int toolId = aAction.
GetUIId();
747 ToggleTool( toolId, aState );
749 EnableTool( toolId, aState );
755 int toolId = aAction.
GetUIId();
757 EnableTool( toolId, aEnabled );
758 ToggleTool( toolId, aEnabled && aChecked );
764 int id = aEvent.GetId();
765 wxEventType type = aEvent.GetEventType();
768 bool handled =
false;
777 bool isCancellable = ( cancelIt !=
m_toolCancellable.end() ) ? cancelIt->second :
false;
782 bool selectionSpecialCase =
false;
786 selectionSpecialCase =
m_parent->ToolStackIsEmpty()
793 if( isCancellable && !GetToolToggled(
id ) )
800 && ( selectionSpecialCase
801 || std::none_of( groupIt->second->GetActions().begin(),
802 groupIt->second->GetActions().end(),
805 return a->IsActivation();
812 const std::vector<const TOOL_ACTION*>& actions =
group->GetActions();
817 for(
size_t i = 0; i < actions.size(); ++i )
819 if( actions[i]->GetId() == current->
GetId() )
821 next = actions[( i + 1 ) % actions.size()];
826 evt =
next->MakeEvent();
827 evt->SetHasPosition(
false );
837 evt = actionIt->second->MakeEvent();
838 evt->SetHasPosition(
false );
853 int toolId = aEvent.GetToolId();
868 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
888 aToolId = actionIt->second->GetUIId();
897 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
904 condMenu->Evaluate( dummySel );
911 SetHoverItem(
nullptr );
916#define PALETTE_OPEN_DELAY 500
921 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
938 if( aEvent.LeftUp() )
949 int toolId = aEvent.GetToolId();
953 wxAuiToolBarItem* item = FindTool( toolId );
973 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
994 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
997 return aAction->GetUIId() == aEvent.GetId();
1000 if( actionIt !=
group->GetActions().end() )
1025 wxWindow* toolParent =
dynamic_cast<wxWindow*
>(
m_toolManager->GetToolHolder() );
1040 wxRect toolRect = GetToolRect( aItem->GetId() );
1043 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
1047 size_t numActions =
group->m_actions.size();
1053 + ( numActions * toolRect.GetHeight() );
1056 switch( pane.dock_direction )
1058 case wxAUI_DOCK_TOP:
1061 pos = ClientToScreen( toolRect.GetBottomLeft() );
1066 case wxAUI_DOCK_BOTTOM:
1070 pos = ClientToScreen( toolRect.GetTopLeft() );
1073 -( paletteLongDim + m_topPadding ) );
1076 case wxAUI_DOCK_LEFT:
1079 pos = ClientToScreen( toolRect.GetTopRight() );
1080 pos += wxPoint( m_rightPadding,
1084 case wxAUI_DOCK_RIGHT:
1088 pos = ClientToScreen( toolRect.GetTopLeft() );
1091 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
1108 wxUpdateUIEvent evt( action->
GetUIId() );
1110 toolParent->ProcessWindowEvent( evt );
1114 if( evt.GetSetEnabled() )
1115 m_palette->EnableAction( *action, evt.GetEnabled() );
1128 RefreshOverflowState();
1129 SetHoverItem(
nullptr );
1130 SetPressedItem(
nullptr );
1133 m_tipItem =
nullptr;
1134 m_actionPos = wxPoint( -1, -1 );
1135 m_actionItem =
nullptr;
1149 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
1150 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
1152 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
1155 aDc.SetPen( wxPen( clr ) );
1156 aDc.SetBrush( wxBrush( clr ) );
1159 int sideLength =
KiROUND( aRect.height / 5.0 );
1163 wxPoint btmRight = aRect.GetBottomRight();
1164 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
1165 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
1168 points.Append( &btmRight );
1169 points.Append( &topCorner );
1170 points.Append( &btmCorner );
1172 aDc.DrawPolygon( &points );
1178#if wxCHECK_VERSION( 3, 3, 0 )
1181 wxClientDC dc(
this );
1192 if( m_orientation == wxHORIZONTAL )
1194 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
1196 m_vertHintSize = GetSize();
1197 retval = RealizeHelper( dc,
false );
1200 if( retval && RealizeHelper( dc,
true ) )
1201 m_horzHintSize = GetSize();
1207 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
1209 m_horzHintSize = GetSize();
1210 retval = RealizeHelper( dc,
true );
1213 if( retval && RealizeHelper( dc,
false ) )
1214 m_vertHintSize = GetSize();
1238 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
1240 wxAuiToolBarItem* tool = FindTool( pair.first );
1253 _(
"Grid selector" ),
1254 _(
"Grid Selection box" ),
1266 _(
"Zoom selector" ),
1267 _(
"Zoom Selection box" ),
1279 _(
"IPC/Scripting plugins" ),
1280 _(
"Region to hold the IPC/Scripting action buttons" ),
1285 _(
"Layer selector" ),
1286 _(
"Control to select the layer" ),
1293 _(
"Symbol unit selector" ),
1294 _(
"Displays the current unit" ),
1299 _(
"Symbol body style selector" ),
1300 _(
"Displays the current body style" ),
1305 _(
"Override locks" ),
1306 _(
"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.