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,
228 wxASSERT( GetParent() );
229 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ), wxS(
"aIsCancellable requires aIsToggleEntry" ) );
231 int toolId = aAction.
GetUIId();
235 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
246 int toolId = aAction.
GetUIId();
262 AddSpacer( 16 * (
scale - 4 ) / 4 );
267 AddSpacer( 16 * (
scale - 4 ) / 4 );
272 std::unique_ptr<ACTION_MENU> aMenu )
274 int toolId = aAction.
GetUIId();
282 int groupId = aGroup->
GetUIId();
285 wxASSERT( GetParent() );
286 wxASSERT( defaultAction );
295 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
296 wxEmptyString, wxEmptyString,
nullptr );
309 return aAction.GetId() == action2->GetId();
319 wxASSERT( GetParent() );
321 int groupId = aGroup->
GetUIId();
323 wxAuiToolBarItem* item = FindTool( groupId );
338 wxASSERT_MSG( cond, wxString::Format(
"Missing UI condition for action %s",
354 wxAuiToolBarItem* item = FindTool( aID );
355 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
358 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
359 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
362 control->InvalidateBestSize();
363 wxSize bestSize = control->GetBestSize();
364 item->SetMinSize( bestSize );
370 if( wxSizerItem* szrItem = item->GetSizerItem() )
371 szrItem->SetMinSize( bestSize );
379 m_sizer->SetItemMinSize( control, bestSize );
403 int toolId = aAction.
GetUIId();
404 wxAuiToolBar::SetToolBitmap( toolId, aBitmap );
407 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
411 tb_item->SetDisabledBitmap(
419 int toolId = aAction.
GetUIId();
422 ToggleTool( toolId, aState );
424 EnableTool( toolId, aState );
430 int toolId = aAction.
GetUIId();
432 EnableTool( toolId, aEnabled );
433 ToggleTool( toolId, aEnabled && aChecked );
439 int id = aEvent.GetId();
440 wxEventType type = aEvent.GetEventType();
443 bool handled =
false;
460 evt = actionIt->second->MakeEvent();
461 evt->SetHasPosition(
false );
476 int toolId = aEvent.GetToolId();
488 toolId = actionIt->second->GetUIId();
497 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
504 condMenu->Evaluate( dummySel );
511 SetHoverItem(
nullptr );
515#define PALETTE_OPEN_DELAY 500
520 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
537 if( aEvent.LeftUp() )
548 int toolId = aEvent.GetToolId();
552 wxAuiToolBarItem* item = FindTool( toolId );
572 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
588 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
591 return aAction->GetUIId() == aEvent.GetId();
594 if( actionIt !=
group->GetActions().end() )
622 wxASSERT( GetParent() );
624 wxASSERT( toolParent );
637 wxRect toolRect = GetToolRect( aItem->GetId() );
640 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
644 size_t numActions =
group->m_actions.size();
650 + ( numActions * toolRect.GetHeight() );
653 switch( pane.dock_direction )
658 pos = ClientToScreen( toolRect.GetBottomLeft() );
663 case wxAUI_DOCK_BOTTOM:
667 pos = ClientToScreen( toolRect.GetTopLeft() );
670 -( paletteLongDim + m_topPadding ) );
673 case wxAUI_DOCK_LEFT:
676 pos = ClientToScreen( toolRect.GetTopRight() );
677 pos += wxPoint( m_rightPadding,
681 case wxAUI_DOCK_RIGHT:
685 pos = ClientToScreen( toolRect.GetTopLeft() );
688 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
706 wxUpdateUIEvent evt( action->
GetUIId() );
708 toolParent->ProcessWindowEvent( evt );
712 if( evt.GetSetEnabled() )
725 RefreshOverflowState();
726 SetHoverItem(
nullptr );
727 SetPressedItem(
nullptr );
731 m_actionPos = wxPoint( -1, -1 );
732 m_actionItem =
nullptr;
746 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
747 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
749 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
752 aDc.SetPen( wxPen( clr ) );
753 aDc.SetBrush( wxBrush( clr ) );
756 int sideLength =
KiROUND( aRect.height / 5.0 );
760 wxPoint btmRight = aRect.GetBottomRight();
761 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
762 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
765 points.Append( &btmRight );
766 points.Append( &topCorner );
767 points.Append( &btmCorner );
769 aDc.DrawPolygon( &points );
775#if wxCHECK_VERSION( 3, 3, 0 )
778 wxClientDC dc(
this );
789 if( m_orientation == wxHORIZONTAL )
791 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
793 m_vertHintSize = GetSize();
794 retval = RealizeHelper( dc,
false );
797 if( retval && RealizeHelper( dc,
true ) )
799 m_horzHintSize = GetSize();
808 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
810 m_horzHintSize = GetSize();
811 retval = RealizeHelper( dc,
true );
814 if( retval && RealizeHelper( dc,
false ) )
816 m_vertHintSize = GetSize();
841 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
843 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)
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 ...
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".