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 );
716 m_toolManager->GetToolHolder()->UnregisterUIUpdateHandler( groupId );
728 m_parent->ClearToolbarControl(
id );
741 int toolId = aAction.
GetUIId();
744 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
749 wxBitmap bm = aBitmap.GetBitmapFor(
this );
751 tb_item->SetBitmap( aBitmap );
758 int toolId = aAction.
GetUIId();
761 ToggleTool( toolId, aState );
763 EnableTool( toolId, aState );
769 int toolId = aAction.
GetUIId();
771 EnableTool( toolId, aEnabled );
772 ToggleTool( toolId, aEnabled && aChecked );
778 int id = aEvent.GetId();
779 wxEventType type = aEvent.GetEventType();
782 bool handled =
false;
791 bool isCancellable = ( cancelIt !=
m_toolCancellable.end() ) ? cancelIt->second :
false;
795 if( isCancellable && !GetToolToggled(
id ) )
802 && std::none_of( groupIt->second->GetActions().begin(),
803 groupIt->second->GetActions().end(),
806 return a->IsActivation();
813 const std::vector<const TOOL_ACTION*>& actions =
group->GetActions();
818 for(
size_t i = 0; i < actions.size(); ++i )
820 if( actions[i]->GetId() == current->
GetId() )
822 next = actions[( i + 1 ) % actions.size()];
827 evt =
next->MakeEvent();
828 evt->SetHasPosition(
false );
838 evt = actionIt->second->MakeEvent();
839 evt->SetHasPosition(
false );
854 int toolId = aEvent.GetToolId();
869 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
871 if( !item || ( item->GetState() & wxAUI_BUTTON_STATE_DISABLED ) != 0 )
889 aToolId = actionIt->second->GetUIId();
898 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
905 condMenu->Evaluate( dummySel );
912 SetHoverItem(
nullptr );
917#define PALETTE_OPEN_DELAY 500
922 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
939 if( aEvent.LeftUp() )
950 int toolId = aEvent.GetToolId();
954 wxAuiToolBarItem* item = FindTool( toolId );
974 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
995 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
998 return aAction->GetUIId() == aEvent.GetId();
1001 const TOOL_ACTION* action = ( actionIt !=
group->GetActions().
end() ) ? *actionIt :
nullptr;
1028 wxWindow* toolParent =
dynamic_cast<wxWindow*
>(
m_toolManager->GetToolHolder() );
1043 wxRect toolRect = GetToolRect( aItem->GetId() );
1046 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
1049 bool dir = pane.dock_direction != wxAUI_DOCK_LEFT && pane.dock_direction != wxAUI_DOCK_RIGHT;
1060 wxUpdateUIEvent evt( action->
GetUIId() );
1062 toolParent->ProcessWindowEvent( evt );
1066 if( evt.GetSetEnabled() )
1067 m_palette->EnableAction( *action, evt.GetEnabled() );
1070 wxSize paletteSize =
m_palette->GetFittedSize();
1073 switch( pane.dock_direction )
1075 case wxAUI_DOCK_TOP:
1077 pos = ClientToScreen( toolRect.GetBottomLeft() );
1082 case wxAUI_DOCK_BOTTOM:
1085 pos = ClientToScreen( toolRect.GetTopLeft() );
1088 -( paletteSize.GetHeight() + m_topPadding ) );
1091 case wxAUI_DOCK_LEFT:
1094 pos = ClientToScreen( toolRect.GetTopRight() );
1098 case wxAUI_DOCK_RIGHT:
1101 pos = ClientToScreen( toolRect.GetTopLeft() );
1105 pos += wxPoint( -( paletteSize.GetWidth() + m_leftPadding +
PALETTE_BORDER ), 0 );
1119 RefreshOverflowState();
1120 SetHoverItem(
nullptr );
1121 SetPressedItem(
nullptr );
1124 m_tipItem =
nullptr;
1125 m_actionPos = wxPoint( -1, -1 );
1126 m_actionItem =
nullptr;
1140 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
1141 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
1143 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
1146 aDc.SetPen( wxPen( clr ) );
1147 aDc.SetBrush( wxBrush( clr ) );
1150 int sideLength =
KiROUND( aRect.height / 5.0 );
1154 wxPoint btmRight = aRect.GetBottomRight();
1155 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
1156 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
1159 points.Append( &btmRight );
1160 points.Append( &topCorner );
1161 points.Append( &btmCorner );
1163 aDc.DrawPolygon( &points );
1169#if wxCHECK_VERSION( 3, 3, 0 )
1172 wxClientDC
dc(
this );
1183 if( m_orientation == wxHORIZONTAL )
1185 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
1187 m_vertHintSize = GetSize();
1188 retval = RealizeHelper(
dc,
false );
1191 if( retval && RealizeHelper(
dc,
true ) )
1192 m_horzHintSize = GetSize();
1198 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
1200 m_horzHintSize = GetSize();
1201 retval = RealizeHelper(
dc,
true );
1204 if( retval && RealizeHelper(
dc,
false ) )
1205 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" ),
1277 _(
"Layer selector" ),
1278 _(
"Control to select the layer" ),
1285 _(
"Symbol unit selector" ),
1286 _(
"Displays the current unit" ),
1291 _(
"Symbol body style selector" ),
1292 _(
"Displays the current body style" ),
1297 _(
"Override locks" ),
1298 _(
"Allow moving of locked items with the mouse" ),
wxBitmapBundle KiBitmapBundleDef(BITMAPS aBitmap, int aDefHeight)
Construct and return a bitmap bundle for the given icon ID, with the default bitmap size being aDefHe...
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
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
The actions that compose the group. Non-owning.
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 default action to display on the toolbar item.
std::string m_name
The name of this action group.
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.
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 ...
DATABASE_CONNECTION dc(odbcBackend(cs))
wxLogTrace helper definitions.