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 m_toolPacking = FromDIP( 2 );
273 m_toolBorderPadding = 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 );
311 std::list<ACTION_TOOLBAR_CONTROL*> controls;
315 if( control->SupportedFor( aContext ) )
316 controls.push_back( control );
325 wxASSERT( GetParent() );
336 for(
auto& item : items )
338 switch( item.m_Type )
345 AddSpacer( item.m_Size );
351 std::string groupName = item.m_GroupName.ToStdString();
352 std::vector<const TOOL_ACTION*>
tools;
357 switch( groupItem.
m_Type )
363 wxFAIL_MSG( wxT(
"Unsupported group item type" ) );
371 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find group tool %s" ), groupItem.
m_ActionName ) );
375 tools.push_back( grpAction );
377 if( currentGroupItems[groupName] == groupItem.
m_ActionName )
378 defaultTool = grpAction;
386 std::unique_ptr<ACTION_GROUP>
group = std::make_unique<ACTION_GROUP>( groupName,
tools );
389 group->SetDefaultAction( *defaultTool );
414 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find control factory for %s" ), item.m_ControlName ) );
429 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find toolbar tool %s" ), item.m_ActionName ) );
456 tip.Replace(
"\t",
" " );
458 wxAuiToolBar::DoSetToolTipText( tip );
465 wxString::Format(
"Attempting to add hidden action %s to the toolbar", aAction.
GetName() ) );
470 Add( aAction, isToggleEntry, isCancellable );
476 wxASSERT( GetParent() );
477 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ),
478 wxS(
"aIsCancellable requires aIsToggleEntry" ) );
480 int toolId = aAction.
GetUIId();
483 AddTool( toolId, wxEmptyString,
486 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
497 int toolId = aAction.
GetUIId();
500 AddTool( toolId, wxEmptyString,
515 AddSpacer( 16 * (
scale - 4 ) / 4 );
520 AddSpacer( 16 * (
scale - 4 ) / 4 );
526 wxASSERT( aControl );
528 AddControl( aControl, aLabel );
534 int toolId = aAction.
GetUIId();
542 int groupId = aGroup->GetUIId();
543 const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction();
546 wxASSERT( GetParent() );
547 wxASSERT( defaultAction );
550 bool isToggleEntry =
false;
552 for(
const auto& act : aGroup->GetActions() )
560 AddTool( groupId, wxEmptyString,
563 isToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL, wxEmptyString, wxEmptyString,
nullptr );
576 return aAction.GetId() == action2->GetId();
591 bool inGroup = std::any_of(
group->m_actions.begin(),
group->m_actions.end(),
594 return aAction.GetId() == action2->GetId();
608 wxASSERT( GetParent() );
610 int groupId = aGroup->
GetUIId();
612 wxAuiToolBarItem* item = FindTool( groupId );
627 m_toolManager->GetToolHolder()->UnregisterUIUpdateHandler( groupId );
634 m_toolManager->GetToolHolder()->RegisterUIUpdateHandler( groupId, *cond );
660 wxAuiToolBarItem* item = FindTool( aID );
661 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
664 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
665 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
668 control->InvalidateBestSize();
669 wxSize bestSize = control->GetBestSize();
670 item->SetMinSize( bestSize );
676 if( wxSizerItem* szrItem = item->GetSizerItem() )
677 szrItem->SetMinSize( bestSize );
685 m_sizer->SetItemMinSize( control, bestSize );
704 m_parent->ClearToolbarControl(
id );
717 int toolId = aAction.
GetUIId();
720 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
725 wxBitmap bm = aBitmap.GetBitmapFor(
this );
727 tb_item->SetBitmap( aBitmap );
734 int toolId = aAction.
GetUIId();
737 ToggleTool( toolId, aState );
739 EnableTool( toolId, aState );
745 int toolId = aAction.
GetUIId();
747 EnableTool( toolId, aEnabled );
748 ToggleTool( toolId, aEnabled && aChecked );
754 int id = aEvent.GetId();
755 wxEventType type = aEvent.GetEventType();
758 bool handled =
false;
767 bool isCancellable = ( cancelIt !=
m_toolCancellable.end() ) ? cancelIt->second :
false;
772 bool selectionSpecialCase =
false;
776 selectionSpecialCase =
m_parent->ToolStackIsEmpty()
783 if( isCancellable && !GetToolToggled(
id ) )
790 && ( selectionSpecialCase
791 || std::none_of( groupIt->second->GetActions().begin(),
792 groupIt->second->GetActions().end(),
795 return a->IsActivation();
802 const std::vector<const TOOL_ACTION*>& actions =
group->GetActions();
807 for(
size_t i = 0; i < actions.size(); ++i )
809 if( actions[i]->GetId() == current->
GetId() )
811 next = actions[( i + 1 ) % actions.size()];
816 evt =
next->MakeEvent();
817 evt->SetHasPosition(
false );
827 evt = actionIt->second->MakeEvent();
828 evt->SetHasPosition(
false );
843 int toolId = aEvent.GetToolId();
858 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
878 aToolId = actionIt->second->GetUIId();
887 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
894 condMenu->Evaluate( dummySel );
901 SetHoverItem(
nullptr );
906#define PALETTE_OPEN_DELAY 500
911 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
928 if( aEvent.LeftUp() )
939 int toolId = aEvent.GetToolId();
943 wxAuiToolBarItem* item = FindTool( toolId );
963 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
984 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
987 return aAction->GetUIId() == aEvent.GetId();
990 if( actionIt !=
group->GetActions().end() )
1015 wxWindow* toolParent =
dynamic_cast<wxWindow*
>(
m_toolManager->GetToolHolder() );
1030 wxRect toolRect = GetToolRect( aItem->GetId() );
1033 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
1037 size_t numActions =
group->m_actions.size();
1043 + ( numActions * toolRect.GetHeight() );
1046 switch( pane.dock_direction )
1048 case wxAUI_DOCK_TOP:
1051 pos = ClientToScreen( toolRect.GetBottomLeft() );
1056 case wxAUI_DOCK_BOTTOM:
1060 pos = ClientToScreen( toolRect.GetTopLeft() );
1063 -( paletteLongDim + m_topPadding ) );
1066 case wxAUI_DOCK_LEFT:
1069 pos = ClientToScreen( toolRect.GetTopRight() );
1070 pos += wxPoint( m_rightPadding,
1074 case wxAUI_DOCK_RIGHT:
1078 pos = ClientToScreen( toolRect.GetTopLeft() );
1081 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
1098 wxUpdateUIEvent evt( action->
GetUIId() );
1100 toolParent->ProcessWindowEvent( evt );
1104 if( evt.GetSetEnabled() )
1105 m_palette->EnableAction( *action, evt.GetEnabled() );
1118 RefreshOverflowState();
1119 SetHoverItem(
nullptr );
1120 SetPressedItem(
nullptr );
1123 m_tipItem =
nullptr;
1124 m_actionPos = wxPoint( -1, -1 );
1125 m_actionItem =
nullptr;
1139 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
1140 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
1142 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
1145 aDc.SetPen( wxPen( clr ) );
1146 aDc.SetBrush( wxBrush( clr ) );
1149 int sideLength =
KiROUND( aRect.height / 5.0 );
1153 wxPoint btmRight = aRect.GetBottomRight();
1154 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
1155 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
1158 points.Append( &btmRight );
1159 points.Append( &topCorner );
1160 points.Append( &btmCorner );
1162 aDc.DrawPolygon( &points );
1168#if wxCHECK_VERSION( 3, 3, 0 )
1171 wxClientDC dc(
this );
1182 if( m_orientation == wxHORIZONTAL )
1184 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
1186 m_vertHintSize = GetSize();
1187 retval = RealizeHelper( dc,
false );
1190 if( retval && RealizeHelper( dc,
true ) )
1191 m_horzHintSize = GetSize();
1197 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
1199 m_horzHintSize = GetSize();
1200 retval = RealizeHelper( dc,
true );
1203 if( retval && RealizeHelper( dc,
false ) )
1204 m_vertHintSize = GetSize();
1228 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
1230 wxAuiToolBarItem* tool = FindTool( pair.first );
1243 _(
"Grid selector" ),
1244 _(
"Grid Selection box" ),
1256 _(
"Zoom selector" ),
1257 _(
"Zoom Selection box" ),
1269 _(
"IPC/Scripting plugins" ),
1270 _(
"Region to hold the IPC/Scripting action buttons" ),
1275 _(
"Layer selector" ),
1276 _(
"Control to select the layer" ),
1283 _(
"Symbol unit selector" ),
1284 _(
"Displays the current unit" ),
1289 _(
"Symbol body style selector" ),
1290 _(
"Displays the current body style" ),
1295 _(
"Override locks" ),
1296 _(
"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.