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 ),
115 m_isVertical( aVertical ),
117 m_mainSizer( nullptr ),
118 m_buttonSizer( nullptr )
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 )
206 const wxSize& size,
long style ) :
207 wxAuiToolBar( parent, id, pos, size, style ),
208 m_paletteTimer( nullptr ),
209 m_auiManager( nullptr ),
210 m_toolManager( parent->GetToolManager() ),
219 Connect( wxEVT_AUITOOLBAR_RIGHT_CLICK,
229 Bind( wxEVT_SYS_COLOUR_CHANGED,
238 Disconnect( wxEVT_AUITOOLBAR_RIGHT_CLICK,
248 Unbind( wxEVT_SYS_COLOUR_CHANGED,
264 wxASSERT( GetParent() );
266 std::map<std::string, std::string> currentGroupItems;
280 for(
auto& item : items )
282 switch( item.m_Type )
284 case TOOLBAR_ITEM_TYPE::SEPARATOR:
288 case TOOLBAR_ITEM_TYPE::SPACER:
289 AddSpacer( item.m_Size );
292 case TOOLBAR_ITEM_TYPE::TB_GROUP:
295 std::string groupName = item.m_GroupName.ToStdString();
296 std::vector<const TOOL_ACTION*>
tools;
301 switch( groupItem.
m_Type )
303 case TOOLBAR_ITEM_TYPE::SEPARATOR:
304 case TOOLBAR_ITEM_TYPE::SPACER:
305 case TOOLBAR_ITEM_TYPE::TB_GROUP:
306 case TOOLBAR_ITEM_TYPE::CONTROL:
307 wxFAIL_MSG( wxT(
"Unsupported group item type" ) );
310 case TOOLBAR_ITEM_TYPE::TOOL:
315 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find group tool %s" ), groupItem.
m_ActionName ) );
319 tools.push_back( grpAction );
321 if( currentGroupItems[groupName] == groupItem.
m_ActionName )
322 defaultTool = grpAction;
326 std::unique_ptr<ACTION_GROUP>
group = std::make_unique<ACTION_GROUP>( groupName,
tools );
329 group->SetDefaultAction( *defaultTool );
335 case TOOLBAR_ITEM_TYPE::CONTROL:
343 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find control factory for %s" ), item.m_ControlName ) );
352 case TOOLBAR_ITEM_TYPE::TOOL:
358 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find toolbar tool %s" ), item.m_ActionName ) );
376 wxString::Format(
"Attempting to add hidden action %s to the toolbar", aAction.
GetName() ) );
381 Add( aAction, isToggleEntry, isCancellable );
387 wxASSERT( GetParent() );
388 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ),
389 wxS(
"aIsCancellable requires aIsToggleEntry" ) );
391 int toolId = aAction.
GetUIId();
393 AddTool( toolId, wxEmptyString,
395 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ),
397 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
408 int toolId = aAction.
GetUIId();
410 AddTool( toolId, wxEmptyString,
412 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ),
426 AddSpacer( 16 * (
scale - 4 ) / 4 );
431 AddSpacer( 16 * (
scale - 4 ) / 4 );
437 wxASSERT( aControl );
439 AddControl( aControl, aLabel );
444 std::unique_ptr<ACTION_MENU> aMenu )
446 int toolId = aAction.
GetUIId();
454 int groupId = aGroup->GetUIId();
455 const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction();
457 wxASSERT( GetParent() );
458 wxASSERT( defaultAction );
461 bool isToggleEntry =
false;
463 for(
const auto& act : aGroup->GetActions() )
464 isToggleEntry |= act->CheckToolbarState( TOOLBAR_STATE::TOGGLE );
472 AddTool( groupId, wxEmptyString,
474 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ),
476 isToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
477 wxEmptyString, wxEmptyString,
nullptr );
490 return aAction.GetId() == action2->GetId();
500 wxASSERT( GetParent() );
502 int groupId = aGroup->
GetUIId();
504 wxAuiToolBarItem* item = FindTool( groupId );
512 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ) );
550 wxAuiToolBarItem* item = FindTool( aID );
551 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
554 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
555 wxASSERT_MSG( control,
556 wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
559 control->InvalidateBestSize();
560 wxSize bestSize = control->GetBestSize();
561 item->SetMinSize( bestSize );
567 if( wxSizerItem* szrItem = item->GetSizerItem() )
568 szrItem->SetMinSize( bestSize );
576 m_sizer->SetItemMinSize( control, bestSize );
600 int toolId = aAction.
GetUIId();
601 wxAuiToolBar::SetToolBitmap( toolId, aBitmap );
604 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
608 tb_item->SetDisabledBitmap(
616 int toolId = aAction.
GetUIId();
619 ToggleTool( toolId, aState );
621 EnableTool( toolId, aState );
627 int toolId = aAction.
GetUIId();
629 EnableTool( toolId, aEnabled );
630 ToggleTool( toolId, aEnabled && aChecked );
636 int id = aEvent.GetId();
637 wxEventType type = aEvent.GetEventType();
640 bool handled =
false;
657 evt = actionIt->second->MakeEvent();
658 evt->SetHasPosition(
false );
673 int toolId = aEvent.GetToolId();
685 toolId = actionIt->second->GetUIId();
694 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
701 condMenu->Evaluate( dummySel );
708 SetHoverItem(
nullptr );
713#define PALETTE_OPEN_DELAY 500
718 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
735 if( aEvent.LeftUp() )
746 int toolId = aEvent.GetToolId();
750 wxAuiToolBarItem* item = FindTool( toolId );
770 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
786 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
789 return aAction->GetUIId() == aEvent.GetId();
792 if( actionIt !=
group->GetActions().end() )
833 wxRect toolRect = GetToolRect( aItem->GetId() );
836 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
840 size_t numActions =
group->m_actions.size();
846 + ( numActions * toolRect.GetHeight() );
849 switch( pane.dock_direction )
854 pos = ClientToScreen( toolRect.GetBottomLeft() );
859 case wxAUI_DOCK_BOTTOM:
863 pos = ClientToScreen( toolRect.GetTopLeft() );
866 -( paletteLongDim + m_topPadding ) );
869 case wxAUI_DOCK_LEFT:
872 pos = ClientToScreen( toolRect.GetTopRight() );
873 pos += wxPoint( m_rightPadding,
877 case wxAUI_DOCK_RIGHT:
881 pos = ClientToScreen( toolRect.GetTopLeft() );
884 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
902 wxUpdateUIEvent evt( action->
GetUIId() );
904 toolParent->ProcessWindowEvent( evt );
908 if( evt.GetSetEnabled() )
921 RefreshOverflowState();
922 SetHoverItem(
nullptr );
923 SetPressedItem(
nullptr );
927 m_actionPos = wxPoint( -1, -1 );
928 m_actionItem =
nullptr;
942 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
943 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
945 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
948 aDc.SetPen( wxPen( clr ) );
949 aDc.SetBrush( wxBrush( clr ) );
952 int sideLength =
KiROUND( aRect.height / 5.0 );
956 wxPoint btmRight = aRect.GetBottomRight();
957 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
958 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
961 points.Append( &btmRight );
962 points.Append( &topCorner );
963 points.Append( &btmCorner );
965 aDc.DrawPolygon( &points );
971#if wxCHECK_VERSION( 3, 3, 0 )
974 wxClientDC dc(
this );
985 if( m_orientation == wxHORIZONTAL )
987 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
989 m_vertHintSize = GetSize();
990 retval = RealizeHelper( dc,
false );
993 if( retval && RealizeHelper( dc,
true ) )
995 m_horzHintSize = GetSize();
1004 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
1006 m_horzHintSize = GetSize();
1007 retval = RealizeHelper( dc,
true );
1010 if( retval && RealizeHelper( dc,
false ) )
1012 m_vertHintSize = GetSize();
1037 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
1039 wxAuiToolBarItem* tool = FindTool( pair.first );
1043 Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size ) );
1054 _(
"Grid Selection box" ) );
1057 _(
"Zoom Selection box" ) );
1060 _(
"Region to hold the IPC/Scripting action buttons" ) );
1063 _(
"Control to select the layer" ) );
1066 _(
"Displays the current unit" ) );
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.
std::string m_name
The default action to display on the toolbar item.
const ACTION_CONDITIONS * GetCondition(const TOOL_ACTION &aAction) const
Get the conditions to use for a specific tool action.
TOOL_ACTION * FindAction(const std::string &aActionName) const
Find an action with a given name (if there is one available).
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.