44#include <wx/popupwin.h>
45#include <wx/renderer.h>
47#include <wx/dcclient.h>
48#include <wx/settings.h>
68 const std::vector<const TOOL_ACTION*>& aActions )
79 wxASSERT_MSG( aActions.size() > 0, wxS(
"Action groups must have at least one action" ) );
98 return aAction->GetId() == aDefault.GetId();
101 wxASSERT_MSG( valid, wxS(
"Action must be present in a group to be the default" ) );
107#define PALETTE_BORDER FromDIP( 4 )
108#define BUTTON_BORDER FromDIP( 1 )
112 wxPopupTransientWindow( aParent, wxBORDER_NONE ),
119 m_panel =
new wxPanel(
this, wxID_ANY );
120 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
123 m_buttonSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
126 m_mainSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
139 int paddingDip = ( ToDIP(
m_buttonSize.GetWidth() ) - iconSize ) / 2;
167 it->second->Enable( aEnable );
176 it->second->Check( aCheck );
183 SetClientSize(
m_panel->GetSize() );
193 wxPopupTransientWindow::Popup( aFocus );
200 if( aEvent.GetKeyCode() == WXK_ESCAPE )
208bool ACTION_TOOLBAR_PALETTE::MSWHandleMessage( WXLRESULT* aResult, WXUINT aMessage,
209 WXWPARAM aWParam, WXLPARAM aLParam )
218 if( aMessage == WM_ACTIVATE && LOWORD( aWParam ) == WA_INACTIVE )
220 BOOL tracking = FALSE;
222 if( ::SystemParametersInfo( SPI_GETACTIVEWINDOWTRACKING, 0, &tracking, 0 ) && tracking )
224 HWND activated =
reinterpret_cast<HWND
>( aLParam );
225 wxWindow* owner = MSWGetOwner();
227 if( activated && owner && ::GetAncestor( activated, GA_ROOT ) == owner->GetHWND() )
228 return wxPopupTransientWindowBase::MSWHandleMessage( aResult, aMessage, aWParam,
233 return wxPopupTransientWindow::MSWHandleMessage( aResult, aMessage, aWParam, aLParam );
240 wxAuiToolBar( parent, id, pos, size, style ),
260 [&]( wxSizeEvent& aEvent )
265 SetOverflowVisible( !GetToolBarFits() );
273 Bind( wxEVT_DPI_CHANGED,
274 [&]( wxDPIChangedEvent& aEvent )
279 SetToolPacking( FromDIP( 2 ) );
280 SetToolBorderPadding( FromDIP( 3 ) );
282 wxSize margin_lt = FromDIP( wxSize( 5, 5 ) );
283 wxSize margin_rb = FromDIP( wxSize( 2, 2 ) );
284 SetMargins( margin_lt.x, margin_lt.y, margin_rb.x, margin_rb.y );
289 if( GetToolCount() > 0 )
292 InvalidateBestSize();
328 std::list<ACTION_TOOLBAR_CONTROL*> controls;
332 if( control->SupportedFor( aContext ) )
333 controls.push_back( control );
342 wxASSERT( GetParent() );
353 for(
auto& item : items )
355 switch( item.m_Type )
362 AddSpacer( item.m_Size );
368 std::string groupName = item.m_GroupName.ToStdString();
369 std::vector<const TOOL_ACTION*>
tools;
374 switch( groupItem.
m_Type )
380 wxFAIL_MSG( wxT(
"Unsupported group item type" ) );
388 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find group tool %s" ), groupItem.
m_ActionName ) );
392 tools.push_back( grpAction );
394 if( currentGroupItems[groupName] == groupItem.
m_ActionName )
395 defaultTool = grpAction;
403 std::unique_ptr<ACTION_GROUP>
group = std::make_unique<ACTION_GROUP>( groupName,
tools );
406 group->SetDefaultAction( *defaultTool );
431 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find control factory for %s" ), item.m_ControlName ) );
446 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find toolbar tool %s" ), item.m_ActionName ) );
473 tip.Replace(
"\t",
" " );
475 wxAuiToolBar::DoSetToolTipText( tip );
482 wxString::Format(
"Attempting to add hidden action %s to the toolbar", aAction.
GetName() ) );
487 Add( aAction, isToggleEntry, isCancellable );
493 wxASSERT( GetParent() );
494 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ),
495 wxS(
"aIsCancellable requires aIsToggleEntry" ) );
497 int toolId = aAction.
GetUIId();
500 AddTool( toolId, wxEmptyString,
503 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
514 int toolId = aAction.
GetUIId();
517 AddTool( toolId, wxEmptyString,
532 AddSpacer( 16 * (
scale - 4 ) / 4 );
537 AddSpacer( 16 * (
scale - 4 ) / 4 );
543 wxASSERT( aControl );
545 AddControl( aControl, aLabel );
551 int toolId = aAction.
GetUIId();
559 int groupId = aGroup->GetUIId();
560 const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction();
563 wxASSERT( GetParent() );
564 wxASSERT( defaultAction );
567 bool isToggleEntry =
false;
569 for(
const auto& act : aGroup->GetActions() )
577 AddTool( groupId, wxEmptyString,
580 isToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL, wxEmptyString, wxEmptyString,
nullptr );
593 return aAction.GetId() == action2->GetId();
608 bool inGroup = std::any_of(
group->m_actions.begin(),
group->m_actions.end(),
611 return aAction.GetId() == action2->GetId();
625 wxASSERT( GetParent() );
627 int groupId = aGroup->
GetUIId();
629 wxAuiToolBarItem* item = FindTool( groupId );
644 m_toolManager->GetToolHolder()->UnregisterUIUpdateHandler( groupId );
651 m_toolManager->GetToolHolder()->RegisterUIUpdateHandler( groupId, *cond );
677 wxAuiToolBarItem* item = FindTool( aID );
678 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
681 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
682 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
685 control->InvalidateBestSize();
686 wxSize bestSize = control->GetBestSize();
687 item->SetMinSize( bestSize );
693 if( wxSizerItem* szrItem = item->GetSizerItem() )
694 szrItem->SetMinSize( bestSize );
702 m_sizer->SetItemMinSize( control, bestSize );
721 m_parent->ClearToolbarControl(
id );
734 int toolId = aAction.
GetUIId();
737 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
742 wxBitmap bm = aBitmap.GetBitmapFor(
this );
744 tb_item->SetBitmap( aBitmap );
751 int toolId = aAction.
GetUIId();
754 ToggleTool( toolId, aState );
756 EnableTool( toolId, aState );
762 int toolId = aAction.
GetUIId();
764 EnableTool( toolId, aEnabled );
765 ToggleTool( toolId, aEnabled && aChecked );
771 int id = aEvent.GetId();
772 wxEventType type = aEvent.GetEventType();
775 bool handled =
false;
784 bool isCancellable = ( cancelIt !=
m_toolCancellable.end() ) ? cancelIt->second :
false;
788 if( isCancellable && !GetToolToggled(
id ) )
795 && std::none_of( groupIt->second->GetActions().begin(),
796 groupIt->second->GetActions().end(),
799 return a->IsActivation();
806 const std::vector<const TOOL_ACTION*>& actions =
group->GetActions();
811 for(
size_t i = 0; i < actions.size(); ++i )
813 if( actions[i]->GetId() == current->
GetId() )
815 next = actions[( i + 1 ) % actions.size()];
820 evt =
next->MakeEvent();
821 evt->SetHasPosition(
false );
831 evt = actionIt->second->MakeEvent();
832 evt->SetHasPosition(
false );
847 int toolId = aEvent.GetToolId();
862 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
882 aToolId = actionIt->second->GetUIId();
891 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
898 condMenu->Evaluate( dummySel );
905 SetHoverItem(
nullptr );
910#define PALETTE_OPEN_DELAY 500
915 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
932 if( aEvent.LeftUp() )
943 int toolId = aEvent.GetToolId();
947 wxAuiToolBarItem* item = FindTool( toolId );
967 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
988 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
991 return aAction->GetUIId() == aEvent.GetId();
994 if( actionIt !=
group->GetActions().end() )
1019 wxWindow* toolParent =
dynamic_cast<wxWindow*
>(
m_toolManager->GetToolHolder() );
1034 wxRect toolRect = GetToolRect( aItem->GetId() );
1037 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
1040 bool dir = pane.dock_direction != wxAUI_DOCK_LEFT && pane.dock_direction != wxAUI_DOCK_RIGHT;
1051 wxUpdateUIEvent evt( action->
GetUIId() );
1053 toolParent->ProcessWindowEvent( evt );
1057 if( evt.GetSetEnabled() )
1058 m_palette->EnableAction( *action, evt.GetEnabled() );
1061 wxSize paletteSize =
m_palette->GetFittedSize();
1064 switch( pane.dock_direction )
1066 case wxAUI_DOCK_TOP:
1068 pos = ClientToScreen( toolRect.GetBottomLeft() );
1073 case wxAUI_DOCK_BOTTOM:
1076 pos = ClientToScreen( toolRect.GetTopLeft() );
1079 -( paletteSize.GetHeight() + m_topPadding ) );
1082 case wxAUI_DOCK_LEFT:
1085 pos = ClientToScreen( toolRect.GetTopRight() );
1089 case wxAUI_DOCK_RIGHT:
1092 pos = ClientToScreen( toolRect.GetTopLeft() );
1096 pos += wxPoint( -( paletteSize.GetWidth() + m_leftPadding +
PALETTE_BORDER ), 0 );
1110 RefreshOverflowState();
1111 SetHoverItem(
nullptr );
1112 SetPressedItem(
nullptr );
1115 m_tipItem =
nullptr;
1116 m_actionPos = wxPoint( -1, -1 );
1117 m_actionItem =
nullptr;
1131 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
1132 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
1134 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
1137 aDc.SetPen( wxPen( clr ) );
1138 aDc.SetBrush( wxBrush( clr ) );
1141 int sideLength =
KiROUND( aRect.height / 5.0 );
1145 wxPoint btmRight = aRect.GetBottomRight();
1146 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
1147 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
1150 points.Append( &btmRight );
1151 points.Append( &topCorner );
1152 points.Append( &btmCorner );
1154 aDc.DrawPolygon( &points );
1160#if wxCHECK_VERSION( 3, 3, 0 )
1163 wxClientDC dc(
this );
1174 if( m_orientation == wxHORIZONTAL )
1176 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
1178 m_vertHintSize = GetSize();
1179 retval = RealizeHelper( dc,
false );
1182 if( retval && RealizeHelper( dc,
true ) )
1183 m_horzHintSize = GetSize();
1189 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
1191 m_horzHintSize = GetSize();
1192 retval = RealizeHelper( dc,
true );
1195 if( retval && RealizeHelper( dc,
false ) )
1196 m_vertHintSize = GetSize();
1220 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
1222 wxAuiToolBarItem* tool = FindTool( pair.first );
1235 _(
"Grid selector" ),
1236 _(
"Grid Selection box" ),
1248 _(
"Zoom selector" ),
1249 _(
"Zoom Selection box" ),
1261 _(
"IPC/Scripting plugins" ),
1262 _(
"Region to hold the IPC/Scripting action buttons" ),
1267 _(
"Layer selector" ),
1268 _(
"Control to select the layer" ),
1275 _(
"Symbol unit selector" ),
1276 _(
"Displays the current unit" ),
1281 _(
"Symbol body style selector" ),
1282 _(
"Displays the current body style" ),
1287 _(
"Override locks" ),
1288 _(
"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)
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.