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() );
194 wxPopupTransientWindow::Popup( aFocus );
201 if( aEvent.GetKeyCode() == WXK_ESCAPE )
209bool ACTION_TOOLBAR_PALETTE::MSWHandleMessage( WXLRESULT* aResult, WXUINT aMessage,
210 WXWPARAM aWParam, WXLPARAM aLParam )
219 if( aMessage == WM_ACTIVATE && LOWORD( aWParam ) == WA_INACTIVE )
221 BOOL tracking = FALSE;
223 if( ::SystemParametersInfo( SPI_GETACTIVEWINDOWTRACKING, 0, &tracking, 0 ) && tracking )
225 HWND activated =
reinterpret_cast<HWND
>( aLParam );
226 wxWindow* owner = MSWGetOwner();
228 if( activated && owner && ::GetAncestor( activated, GA_ROOT ) == owner->GetHWND() )
229 return wxPopupTransientWindowBase::MSWHandleMessage( aResult, aMessage, aWParam,
234 return wxPopupTransientWindow::MSWHandleMessage( aResult, aMessage, aWParam, aLParam );
241 wxAuiToolBar( parent, id, pos, size, style ),
261 [&]( wxSizeEvent& aEvent )
266 SetOverflowVisible( !GetToolBarFits() );
274 Bind( wxEVT_DPI_CHANGED,
275 [&]( wxDPIChangedEvent& aEvent )
280 SetToolPacking( FromDIP( 2 ) );
281 SetToolBorderPadding( FromDIP( 3 ) );
283 wxSize margin_lt = FromDIP( wxSize( 5, 5 ) );
284 wxSize margin_rb = FromDIP( wxSize( 2, 2 ) );
285 SetMargins( margin_lt.x, margin_lt.y, margin_rb.x, margin_rb.y );
290 if( GetToolCount() > 0 )
293 InvalidateBestSize();
329 std::list<ACTION_TOOLBAR_CONTROL*> controls;
333 if( control->SupportedFor( aContext ) )
334 controls.push_back( control );
343 wxASSERT( GetParent() );
354 for(
auto& item : items )
356 switch( item.m_Type )
363 AddSpacer( item.m_Size );
369 std::string groupName = item.m_GroupName.ToStdString();
370 std::vector<const TOOL_ACTION*>
tools;
375 switch( groupItem.
m_Type )
381 wxFAIL_MSG( wxT(
"Unsupported group item type" ) );
389 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find group tool %s" ), groupItem.
m_ActionName ) );
393 tools.push_back( grpAction );
395 if( currentGroupItems[groupName] == groupItem.
m_ActionName )
396 defaultTool = grpAction;
404 std::unique_ptr<ACTION_GROUP>
group = std::make_unique<ACTION_GROUP>( groupName,
tools );
407 group->SetDefaultAction( *defaultTool );
432 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find control factory for %s" ), item.m_ControlName ) );
447 wxFAIL_MSG( wxString::Format( wxT(
"Unable to find toolbar tool %s" ), item.m_ActionName ) );
474 tip.Replace(
"\t",
" " );
476 wxAuiToolBar::DoSetToolTipText( tip );
483 wxString::Format(
"Attempting to add hidden action %s to the toolbar", aAction.
GetName() ) );
488 Add( aAction, isToggleEntry, isCancellable );
494 wxASSERT( GetParent() );
495 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ),
496 wxS(
"aIsCancellable requires aIsToggleEntry" ) );
498 int toolId = aAction.
GetUIId();
501 AddTool( toolId, wxEmptyString,
504 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
515 int toolId = aAction.
GetUIId();
518 AddTool( toolId, wxEmptyString,
533 AddSpacer( 16 * (
scale - 4 ) / 4 );
538 AddSpacer( 16 * (
scale - 4 ) / 4 );
544 wxASSERT( aControl );
546 AddControl( aControl, aLabel );
552 int toolId = aAction.
GetUIId();
560 int groupId = aGroup->GetUIId();
561 const TOOL_ACTION* defaultAction = aGroup->GetDefaultAction();
564 wxASSERT( GetParent() );
565 wxASSERT( defaultAction );
568 bool isToggleEntry =
false;
570 for(
const auto& act : aGroup->GetActions() )
578 AddTool( groupId, wxEmptyString,
581 isToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL, wxEmptyString, wxEmptyString,
nullptr );
594 return aAction.GetId() == action2->GetId();
609 bool inGroup = std::any_of(
group->m_actions.begin(),
group->m_actions.end(),
612 return aAction.GetId() == action2->GetId();
626 wxASSERT( GetParent() );
628 int groupId = aGroup->
GetUIId();
630 wxAuiToolBarItem* item = FindTool( groupId );
645 m_toolManager->GetToolHolder()->UnregisterUIUpdateHandler( groupId );
652 m_toolManager->GetToolHolder()->RegisterUIUpdateHandler( groupId, *cond );
678 wxAuiToolBarItem* item = FindTool( aID );
679 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
682 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
683 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
686 control->InvalidateBestSize();
687 wxSize bestSize = control->GetBestSize();
688 item->SetMinSize( bestSize );
694 if( wxSizerItem* szrItem = item->GetSizerItem() )
695 szrItem->SetMinSize( bestSize );
703 m_sizer->SetItemMinSize( control, bestSize );
722 m_parent->ClearToolbarControl(
id );
735 int toolId = aAction.
GetUIId();
738 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
743 wxBitmap bm = aBitmap.GetBitmapFor(
this );
745 tb_item->SetBitmap( aBitmap );
752 int toolId = aAction.
GetUIId();
755 ToggleTool( toolId, aState );
757 EnableTool( toolId, aState );
763 int toolId = aAction.
GetUIId();
765 EnableTool( toolId, aEnabled );
766 ToggleTool( toolId, aEnabled && aChecked );
772 int id = aEvent.GetId();
773 wxEventType type = aEvent.GetEventType();
776 bool handled =
false;
785 bool isCancellable = ( cancelIt !=
m_toolCancellable.end() ) ? cancelIt->second :
false;
790 bool selectionSpecialCase =
false;
794 selectionSpecialCase =
m_parent->ToolStackIsEmpty()
801 if( isCancellable && !GetToolToggled(
id ) )
808 && ( selectionSpecialCase
809 || std::none_of( groupIt->second->GetActions().begin(),
810 groupIt->second->GetActions().end(),
813 return a->IsActivation();
820 const std::vector<const TOOL_ACTION*>& actions =
group->GetActions();
825 for(
size_t i = 0; i < actions.size(); ++i )
827 if( actions[i]->GetId() == current->
GetId() )
829 next = actions[( i + 1 ) % actions.size()];
834 evt =
next->MakeEvent();
835 evt->SetHasPosition(
false );
845 evt = actionIt->second->MakeEvent();
846 evt->SetHasPosition(
false );
861 int toolId = aEvent.GetToolId();
876 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
896 aToolId = actionIt->second->GetUIId();
905 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
912 condMenu->Evaluate( dummySel );
919 SetHoverItem(
nullptr );
924#define PALETTE_OPEN_DELAY 500
929 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
946 if( aEvent.LeftUp() )
957 int toolId = aEvent.GetToolId();
961 wxAuiToolBarItem* item = FindTool( toolId );
981 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
1002 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
1005 return aAction->GetUIId() == aEvent.GetId();
1008 if( actionIt !=
group->GetActions().end() )
1033 wxWindow* toolParent =
dynamic_cast<wxWindow*
>(
m_toolManager->GetToolHolder() );
1048 wxRect toolRect = GetToolRect( aItem->GetId() );
1051 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
1054 bool dir = pane.dock_direction != wxAUI_DOCK_LEFT && pane.dock_direction != wxAUI_DOCK_RIGHT;
1065 wxUpdateUIEvent evt( action->
GetUIId() );
1067 toolParent->ProcessWindowEvent( evt );
1071 if( evt.GetSetEnabled() )
1072 m_palette->EnableAction( *action, evt.GetEnabled() );
1075 wxSize paletteSize =
m_palette->GetFittedSize();
1078 switch( pane.dock_direction )
1080 case wxAUI_DOCK_TOP:
1082 pos = ClientToScreen( toolRect.GetBottomLeft() );
1087 case wxAUI_DOCK_BOTTOM:
1090 pos = ClientToScreen( toolRect.GetTopLeft() );
1093 -( paletteSize.GetHeight() + m_topPadding ) );
1096 case wxAUI_DOCK_LEFT:
1099 pos = ClientToScreen( toolRect.GetTopRight() );
1103 case wxAUI_DOCK_RIGHT:
1106 pos = ClientToScreen( toolRect.GetTopLeft() );
1110 pos += wxPoint( -( paletteSize.GetWidth() + m_leftPadding +
PALETTE_BORDER ), 0 );
1124 RefreshOverflowState();
1125 SetHoverItem(
nullptr );
1126 SetPressedItem(
nullptr );
1129 m_tipItem =
nullptr;
1130 m_actionPos = wxPoint( -1, -1 );
1131 m_actionItem =
nullptr;
1145 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
1146 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
1148 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
1151 aDc.SetPen( wxPen( clr ) );
1152 aDc.SetBrush( wxBrush( clr ) );
1155 int sideLength =
KiROUND( aRect.height / 5.0 );
1159 wxPoint btmRight = aRect.GetBottomRight();
1160 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
1161 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
1164 points.Append( &btmRight );
1165 points.Append( &topCorner );
1166 points.Append( &btmCorner );
1168 aDc.DrawPolygon( &points );
1174#if wxCHECK_VERSION( 3, 3, 0 )
1177 wxClientDC dc(
this );
1188 if( m_orientation == wxHORIZONTAL )
1190 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
1192 m_vertHintSize = GetSize();
1193 retval = RealizeHelper( dc,
false );
1196 if( retval && RealizeHelper( dc,
true ) )
1197 m_horzHintSize = GetSize();
1203 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
1205 m_horzHintSize = GetSize();
1206 retval = RealizeHelper( dc,
true );
1209 if( retval && RealizeHelper( dc,
false ) )
1210 m_vertHintSize = GetSize();
1234 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
1236 wxAuiToolBarItem* tool = FindTool( pair.first );
1249 _(
"Grid selector" ),
1250 _(
"Grid Selection box" ),
1262 _(
"Zoom selector" ),
1263 _(
"Zoom Selection box" ),
1275 _(
"IPC/Scripting plugins" ),
1276 _(
"Region to hold the IPC/Scripting action buttons" ),
1281 _(
"Layer selector" ),
1282 _(
"Control to select the layer" ),
1289 _(
"Symbol unit selector" ),
1290 _(
"Displays the current unit" ),
1295 _(
"Symbol body style selector" ),
1296 _(
"Displays the current body style" ),
1301 _(
"Override locks" ),
1302 _(
"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.