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();
494 bool inGroup = std::any_of(
group->m_actions.begin(),
group->m_actions.end(),
497 return aAction.GetId() == action2->GetId();
511 wxASSERT( GetParent() );
513 int groupId = aGroup->
GetUIId();
515 wxAuiToolBarItem* item = FindTool( groupId );
523 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ) );
529 m_toolManager->GetToolHolder()->UnregisterUIUpdateHandler( groupId );
536 m_toolManager->GetToolHolder()->RegisterUIUpdateHandler( groupId, *cond );
561 wxAuiToolBarItem* item = FindTool( aID );
562 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
565 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
566 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
569 control->InvalidateBestSize();
570 wxSize bestSize = control->GetBestSize();
571 item->SetMinSize( bestSize );
577 if( wxSizerItem* szrItem = item->GetSizerItem() )
578 szrItem->SetMinSize( bestSize );
586 m_sizer->SetItemMinSize( control, bestSize );
610 int toolId = aAction.
GetUIId();
611 wxAuiToolBar::SetToolBitmap( toolId, aBitmap );
614 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
623 int toolId = aAction.
GetUIId();
626 ToggleTool( toolId, aState );
628 EnableTool( toolId, aState );
634 int toolId = aAction.
GetUIId();
636 EnableTool( toolId, aEnabled );
637 ToggleTool( toolId, aEnabled && aChecked );
643 int id = aEvent.GetId();
644 wxEventType type = aEvent.GetEventType();
647 bool handled =
false;
664 evt = actionIt->second->MakeEvent();
665 evt->SetHasPosition(
false );
680 int toolId = aEvent.GetToolId();
691 toolId = actionIt->second->GetUIId();
700 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
707 condMenu->Evaluate( dummySel );
714 SetHoverItem(
nullptr );
719#define PALETTE_OPEN_DELAY 500
724 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
741 if( aEvent.LeftUp() )
752 int toolId = aEvent.GetToolId();
756 wxAuiToolBarItem* item = FindTool( toolId );
776 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
792 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
795 return aAction->GetUIId() == aEvent.GetId();
798 if( actionIt !=
group->GetActions().end() )
824 wxWindow* toolParent =
dynamic_cast<wxWindow*
>(
m_toolManager->GetToolHolder() );
839 wxRect toolRect = GetToolRect( aItem->GetId() );
842 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
846 size_t numActions =
group->m_actions.size();
852 + ( numActions * toolRect.GetHeight() );
855 switch( pane.dock_direction )
860 pos = ClientToScreen( toolRect.GetBottomLeft() );
865 case wxAUI_DOCK_BOTTOM:
869 pos = ClientToScreen( toolRect.GetTopLeft() );
872 -( paletteLongDim + m_topPadding ) );
875 case wxAUI_DOCK_LEFT:
878 pos = ClientToScreen( toolRect.GetTopRight() );
879 pos += wxPoint( m_rightPadding,
883 case wxAUI_DOCK_RIGHT:
887 pos = ClientToScreen( toolRect.GetTopLeft() );
890 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
907 wxUpdateUIEvent evt( action->
GetUIId() );
909 toolParent->ProcessWindowEvent( evt );
913 if( evt.GetSetEnabled() )
914 m_palette->EnableAction( *action, evt.GetEnabled() );
926 RefreshOverflowState();
927 SetHoverItem(
nullptr );
928 SetPressedItem(
nullptr );
932 m_actionPos = wxPoint( -1, -1 );
933 m_actionItem =
nullptr;
947 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
948 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
950 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
953 aDc.SetPen( wxPen( clr ) );
954 aDc.SetBrush( wxBrush( clr ) );
957 int sideLength =
KiROUND( aRect.height / 5.0 );
961 wxPoint btmRight = aRect.GetBottomRight();
962 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
963 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
966 points.Append( &btmRight );
967 points.Append( &topCorner );
968 points.Append( &btmCorner );
970 aDc.DrawPolygon( &points );
976#if wxCHECK_VERSION( 3, 3, 0 )
979 wxClientDC dc(
this );
990 if( m_orientation == wxHORIZONTAL )
992 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
994 m_vertHintSize = GetSize();
995 retval = RealizeHelper( dc,
false );
998 if( retval && RealizeHelper( dc,
true ) )
999 m_horzHintSize = GetSize();
1005 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
1007 m_horzHintSize = GetSize();
1008 retval = RealizeHelper( dc,
true );
1011 if( retval && RealizeHelper( dc,
false ) )
1012 m_vertHintSize = GetSize();
1034 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
1036 wxAuiToolBarItem* tool = FindTool( pair.first );
1039 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ) );
1050 _(
"Grid Selection box" ) );
1053 _(
"Zoom Selection box" ) );
1056 _(
"Region to hold the IPC/Scripting action buttons" ) );
1059 _(
"Control to select the layer" ) );
1062 _(
"Displays the current unit" ) );
1065 _(
"Symbol body style selector" ),
1066 _(
"Displays the current body style" ) );
1069 _(
"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.