44#include <wx/popupwin.h>
45#include <wx/renderer.h>
47#include <wx/dcclient.h>
48#include <wx/settings.h>
52 const std::vector<const TOOL_ACTION*>& aActions )
54 wxASSERT_MSG( aActions.size() > 0, wxS(
"Action groups must have at least one action" ) );
77 return aAction->GetId() == aDefault.GetId();
80 wxASSERT_MSG( valid, wxS(
"Action must be present in a group to be the default" ) );
86#define PALETTE_BORDER 4
87#define BUTTON_BORDER 1
91 wxPopupTransientWindow( aParent, wxBORDER_NONE ),
93 m_isVertical( aVertical ),
95 m_mainSizer( nullptr ),
96 m_buttonSizer( nullptr )
98 m_panel =
new wxPanel(
this, wxID_ANY );
99 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
102 m_buttonSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
105 m_mainSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
119 int bmpWidth = normalBmp.GetPreferredBitmapSizeFor(
this ).GetWidth();
120 int padding = (
m_buttonSize.GetWidth() - bmpWidth ) / 2;
122 wxSize bmSize( size, size );
152 it->second->Enable( aEnable );
161 it->second->Check( aCheck );
168 SetClientSize(
m_panel->GetSize() );
170 wxPopupTransientWindow::Popup( aFocus );
177 if( aEvent.GetKeyCode() == WXK_ESCAPE )
185 const wxSize& size,
long style ) :
186 wxAuiToolBar( parent, id, pos, size, style ),
187 m_paletteTimer( nullptr ),
188 m_auiManager( nullptr ),
189 m_toolManager( parent->GetToolManager() ),
198 Connect( wxEVT_AUITOOLBAR_RIGHT_CLICK,
208 Bind( wxEVT_SYS_COLOUR_CHANGED,
217 Disconnect( wxEVT_AUITOOLBAR_RIGHT_CLICK,
227 Unbind( wxEVT_SYS_COLOUR_CHANGED,
243 wxASSERT( GetParent() );
244 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ), wxS(
"aIsCancellable requires aIsToggleEntry" ) );
246 int toolId = aAction.
GetUIId();
250 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
261 int toolId = aAction.
GetUIId();
277 AddSpacer( 16 * (
scale - 4 ) / 4 );
282 AddSpacer( 16 * (
scale - 4 ) / 4 );
287 std::unique_ptr<ACTION_MENU> aMenu )
289 int toolId = aAction.
GetUIId();
297 int groupId = aGroup->
GetUIId();
300 wxASSERT( GetParent() );
301 wxASSERT( defaultAction );
310 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
311 wxEmptyString, wxEmptyString,
nullptr );
324 return aAction.GetId() == action2->GetId();
334 wxASSERT( GetParent() );
336 int groupId = aGroup->
GetUIId();
338 wxAuiToolBarItem* item = FindTool( groupId );
353 wxASSERT_MSG( cond, wxString::Format(
"Missing UI condition for action %s",
369 wxAuiToolBarItem* item = FindTool( aID );
370 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
373 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
374 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
377 control->InvalidateBestSize();
378 wxSize bestSize = control->GetBestSize();
379 item->SetMinSize( bestSize );
385 if( wxSizerItem* szrItem = item->GetSizerItem() )
386 szrItem->SetMinSize( bestSize );
394 m_sizer->SetItemMinSize( control, bestSize );
418 int toolId = aAction.
GetUIId();
419 wxAuiToolBar::SetToolBitmap( toolId, aBitmap );
422 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
426 tb_item->SetDisabledBitmap(
434 int toolId = aAction.
GetUIId();
437 ToggleTool( toolId, aState );
439 EnableTool( toolId, aState );
445 int toolId = aAction.
GetUIId();
447 EnableTool( toolId, aEnabled );
448 ToggleTool( toolId, aEnabled && aChecked );
454 int id = aEvent.GetId();
455 wxEventType type = aEvent.GetEventType();
458 bool handled =
false;
475 evt = actionIt->second->MakeEvent();
476 evt->SetHasPosition(
false );
491 int toolId = aEvent.GetToolId();
503 toolId = actionIt->second->GetUIId();
512 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
519 condMenu->Evaluate( dummySel );
526 SetHoverItem(
nullptr );
530#define PALETTE_OPEN_DELAY 500
535 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
552 if( aEvent.LeftUp() )
563 int toolId = aEvent.GetToolId();
567 wxAuiToolBarItem* item = FindTool( toolId );
587 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
603 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
606 return aAction->GetUIId() == aEvent.GetId();
609 if( actionIt !=
group->GetActions().end() )
637 wxASSERT( GetParent() );
639 wxASSERT( toolParent );
652 wxRect toolRect = GetToolRect( aItem->GetId() );
655 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
659 size_t numActions =
group->m_actions.size();
665 + ( numActions * toolRect.GetHeight() );
668 switch( pane.dock_direction )
673 pos = ClientToScreen( toolRect.GetBottomLeft() );
678 case wxAUI_DOCK_BOTTOM:
682 pos = ClientToScreen( toolRect.GetTopLeft() );
685 -( paletteLongDim + m_topPadding ) );
688 case wxAUI_DOCK_LEFT:
691 pos = ClientToScreen( toolRect.GetTopRight() );
692 pos += wxPoint( m_rightPadding,
696 case wxAUI_DOCK_RIGHT:
700 pos = ClientToScreen( toolRect.GetTopLeft() );
703 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
721 wxUpdateUIEvent evt( action->
GetUIId() );
723 toolParent->ProcessWindowEvent( evt );
727 if( evt.GetSetEnabled() )
740 RefreshOverflowState();
741 SetHoverItem(
nullptr );
742 SetPressedItem(
nullptr );
746 m_actionPos = wxPoint( -1, -1 );
747 m_actionItem =
nullptr;
761 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
762 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
764 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
767 aDc.SetPen( wxPen( clr ) );
768 aDc.SetBrush( wxBrush( clr ) );
771 int sideLength =
KiROUND( aRect.height / 5.0 );
775 wxPoint btmRight = aRect.GetBottomRight();
776 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
777 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
780 points.Append( &btmRight );
781 points.Append( &topCorner );
782 points.Append( &btmCorner );
784 aDc.DrawPolygon( &points );
790#if wxCHECK_VERSION( 3, 3, 0 )
793 wxClientDC dc(
this );
804 if( m_orientation == wxHORIZONTAL )
806 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
808 m_vertHintSize = GetSize();
809 retval = RealizeHelper( dc,
false );
812 if( retval && RealizeHelper( dc,
true ) )
814 m_horzHintSize = GetSize();
823 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
825 m_horzHintSize = GetSize();
826 retval = RealizeHelper( dc,
true );
829 if( retval && RealizeHelper( dc,
false ) )
831 m_vertHintSize = GetSize();
856 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
858 wxAuiToolBarItem* tool = FindTool( pair.first );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
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)
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.
std::vector< const TOOL_ACTION * > m_actions
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.
const TOOL_ACTION * GetDefaultAction() const
Get the default action to use when first creating this group's toolbar palette icon.
std::string m_name
The default action to display on the toolbar item.
ACTION_GROUP(const std::string &aName, const std::vector< const TOOL_ACTION * > &aActions)
const ACTION_CONDITIONS * GetCondition(const TOOL_ACTION &aAction) const
Get the conditions to use for a specific tool action.
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.
virtual COMMON_SETTINGS * GetCommonSettings() const
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 ...