48#include <wx/popupwin.h>
49#include <wx/renderer.h>
51#include <wx/dcclient.h>
52#include <wx/settings.h>
56#include <python_scripting.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 4
109#define BUTTON_BORDER 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 );
142 int bmpWidth = normalBmp.GetPreferredBitmapSizeFor(
this ).GetWidth();
143 int padding = (
m_buttonSize.GetWidth() - bmpWidth ) / 2;
144 wxSize bmSize( size, size );
173 it->second->Enable( aEnable );
182 it->second->Check( aCheck );
189 SetClientSize(
m_panel->GetSize() );
191 wxPopupTransientWindow::Popup( aFocus );
198 if( aEvent.GetKeyCode() == WXK_ESCAPE )
207 wxAuiToolBar( parent, id, pos, size, style ),
253 wxASSERT( GetParent() );
255 std::map<std::string, std::string> currentGroupItems;
269 for(
auto& item : items )
271 switch( item.m_Type )
278 AddSpacer( item.m_Size );
284 std::string groupName = item.m_GroupName.ToStdString();
285 std::vector<const TOOL_ACTION*>
tools;
290 switch( groupItem.
m_Type )
296 wxFAIL_MSG( wxT(
"Unsupported group item type" ) );
304 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find group tool %s" ), groupItem.
m_ActionName ) );
308 tools.push_back( grpAction );
310 if( currentGroupItems[groupName] == groupItem.
m_ActionName )
311 defaultTool = grpAction;
315 std::unique_ptr<ACTION_GROUP>
group = std::make_unique<ACTION_GROUP>( groupName,
tools );
318 group->SetDefaultAction( *defaultTool );
332 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find control factory for %s" ), item.m_ControlName ) );
347 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find toolbar tool %s" ), item.m_ActionName ) );
365 wxString::Format(
"Attempting to add hidden action %s to the toolbar", aAction.
GetName() ) );
370 Add( aAction, isToggleEntry, isCancellable );
376 wxASSERT( GetParent() );
377 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ),
378 wxS(
"aIsCancellable requires aIsToggleEntry" ) );
380 int toolId = aAction.
GetUIId();
382 AddTool( toolId, wxEmptyString,
384 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ),
386 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
397 int toolId = aAction.
GetUIId();
399 AddTool( toolId, wxEmptyString,
401 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ),
415 AddSpacer( 16 * (
scale - 4 ) / 4 );
420 AddSpacer( 16 * (
scale - 4 ) / 4 );
426 wxASSERT( aControl );
428 AddControl( aControl, aLabel );
433 std::unique_ptr<ACTION_MENU> aMenu )
435 int toolId = aAction.
GetUIId();
443 int groupId = aGroup->GetUIId();
444 const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction();
446 wxASSERT( GetParent() );
447 wxASSERT( defaultAction );
450 bool isToggleEntry =
false;
452 for(
const auto& act : aGroup->GetActions() )
461 AddTool( groupId, wxEmptyString,
463 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ),
465 isToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
466 wxEmptyString, wxEmptyString,
nullptr );
479 return aAction.GetId() == action2->GetId();
489 wxASSERT( GetParent() );
491 int groupId = aGroup->
GetUIId();
493 wxAuiToolBarItem* item = FindTool( groupId );
501 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ) );
507 m_toolManager->GetToolHolder()->UnregisterUIUpdateHandler( groupId );
514 m_toolManager->GetToolHolder()->RegisterUIUpdateHandler( groupId, *cond );
539 wxAuiToolBarItem* item = FindTool( aID );
540 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
543 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
544 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
547 control->InvalidateBestSize();
548 wxSize bestSize = control->GetBestSize();
549 item->SetMinSize( bestSize );
555 if( wxSizerItem* szrItem = item->GetSizerItem() )
556 szrItem->SetMinSize( bestSize );
564 m_sizer->SetItemMinSize( control, bestSize );
588 int toolId = aAction.
GetUIId();
589 wxAuiToolBar::SetToolBitmap( toolId, aBitmap );
592 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
601 int toolId = aAction.
GetUIId();
604 ToggleTool( toolId, aState );
606 EnableTool( toolId, aState );
612 int toolId = aAction.
GetUIId();
614 EnableTool( toolId, aEnabled );
615 ToggleTool( toolId, aEnabled && aChecked );
621 int id = aEvent.GetId();
622 wxEventType type = aEvent.GetEventType();
625 bool handled =
false;
642 evt = actionIt->second->MakeEvent();
643 evt->SetHasPosition(
false );
658 int toolId = aEvent.GetToolId();
669 toolId = actionIt->second->GetUIId();
678 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
685 condMenu->Evaluate( dummySel );
692 SetHoverItem(
nullptr );
697#define PALETTE_OPEN_DELAY 500
702 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
719 if( aEvent.LeftUp() )
730 int toolId = aEvent.GetToolId();
734 wxAuiToolBarItem* item = FindTool( toolId );
754 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
770 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
773 return aAction->GetUIId() == aEvent.GetId();
776 if( actionIt !=
group->GetActions().end() )
802 wxWindow* toolParent =
dynamic_cast<wxWindow*
>(
m_toolManager->GetToolHolder() );
817 wxRect toolRect = GetToolRect( aItem->GetId() );
820 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
824 size_t numActions =
group->m_actions.size();
830 + ( numActions * toolRect.GetHeight() );
833 switch( pane.dock_direction )
838 pos = ClientToScreen( toolRect.GetBottomLeft() );
843 case wxAUI_DOCK_BOTTOM:
847 pos = ClientToScreen( toolRect.GetTopLeft() );
850 -( paletteLongDim + m_topPadding ) );
853 case wxAUI_DOCK_LEFT:
856 pos = ClientToScreen( toolRect.GetTopRight() );
857 pos += wxPoint( m_rightPadding,
861 case wxAUI_DOCK_RIGHT:
865 pos = ClientToScreen( toolRect.GetTopLeft() );
868 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
885 wxUpdateUIEvent evt( action->
GetUIId() );
887 toolParent->ProcessWindowEvent( evt );
891 if( evt.GetSetEnabled() )
892 m_palette->EnableAction( *action, evt.GetEnabled() );
904 RefreshOverflowState();
905 SetHoverItem(
nullptr );
906 SetPressedItem(
nullptr );
910 m_actionPos = wxPoint( -1, -1 );
911 m_actionItem =
nullptr;
925 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
926 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
928 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
931 aDc.SetPen( wxPen( clr ) );
932 aDc.SetBrush( wxBrush( clr ) );
935 int sideLength =
KiROUND( aRect.height / 5.0 );
939 wxPoint btmRight = aRect.GetBottomRight();
940 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
941 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
944 points.Append( &btmRight );
945 points.Append( &topCorner );
946 points.Append( &btmCorner );
948 aDc.DrawPolygon( &points );
954#if wxCHECK_VERSION( 3, 3, 0 )
957 wxClientDC dc(
this );
968 if( m_orientation == wxHORIZONTAL )
970 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
972 m_vertHintSize = GetSize();
973 retval = RealizeHelper( dc,
false );
976 if( retval && RealizeHelper( dc,
true ) )
977 m_horzHintSize = GetSize();
983 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
985 m_horzHintSize = GetSize();
986 retval = RealizeHelper( dc,
true );
989 if( retval && RealizeHelper( dc,
false ) )
990 m_vertHintSize = GetSize();
1012 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
1014 wxAuiToolBarItem* tool = FindTool( pair.first );
1017 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ) );
1028 _(
"Grid Selection box" ) );
1031 _(
"Zoom Selection box" ) );
1034 _(
"Region to hold the IPC/Scripting action buttons" ) );
1037 _(
"Control to select the layer" ) );
1040 _(
"Displays the current unit" ) );
1043 _(
"Symbol body style selector" ),
1044 _(
"Displays the current body style" ) );
1047 _(
"Allow moving of locked items with the mouse" ) );
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
BITMAP_STORE * GetBitmapStore()
wxBitmapBundle KiDisabledBitmapBundle(BITMAPS aBitmap)
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
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
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.