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;
121 int size =
Pgm().GetCommonSettings()->m_Appearance.toolbar_icon_size;
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,
236 aAction.
GetTooltip(), wxEmptyString,
nullptr );
246 int toolId = aAction.
GetUIId();
250 wxITEM_NORMAL, aAction.
GetTooltip(), wxEmptyString,
nullptr );
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 wxSize bestSize = control->GetBestSize();
363 item->SetMinSize( bestSize );
369 if( wxSizerItem* szrItem = item->GetSizerItem() )
370 szrItem->SetMinSize( bestSize );
378 m_sizer->SetItemMinSize( control, bestSize );
402 int toolId = aAction.
GetUIId();
403 wxAuiToolBar::SetToolBitmap( toolId, aBitmap );
406 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
410 tb_item->SetDisabledBitmap(
418 int toolId = aAction.
GetUIId();
421 ToggleTool( toolId, aState );
423 EnableTool( toolId, aState );
429 int toolId = aAction.
GetUIId();
431 EnableTool( toolId, aEnabled );
432 ToggleTool( toolId, aEnabled && aChecked );
438 int id = aEvent.GetId();
439 wxEventType type = aEvent.GetEventType();
442 bool handled =
false;
459 evt = actionIt->second->MakeEvent();
460 evt->SetHasPosition(
false );
475 int toolId = aEvent.GetToolId();
487 toolId = actionIt->second->GetUIId();
496 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
503 condMenu->Evaluate( dummySel );
510 SetHoverItem(
nullptr );
514#define PALETTE_OPEN_DELAY 500
519 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
536 if( aEvent.LeftUp() )
547 int toolId = aEvent.GetToolId();
551 wxAuiToolBarItem* item = FindTool( toolId );
571 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
587 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
590 return aAction->GetUIId() == aEvent.GetId();
593 if( actionIt !=
group->GetActions().end() )
621 wxASSERT( GetParent() );
623 wxASSERT( toolParent );
636 wxRect toolRect = GetToolRect( aItem->GetId() );
639 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
643 size_t numActions =
group->m_actions.size();
649 + ( numActions * toolRect.GetHeight() );
652 switch( pane.dock_direction )
657 pos = ClientToScreen( toolRect.GetBottomLeft() );
662 case wxAUI_DOCK_BOTTOM:
666 pos = ClientToScreen( toolRect.GetTopLeft() );
669 -( paletteLongDim + m_topPadding ) );
672 case wxAUI_DOCK_LEFT:
675 pos = ClientToScreen( toolRect.GetTopRight() );
676 pos += wxPoint( m_rightPadding,
680 case wxAUI_DOCK_RIGHT:
684 pos = ClientToScreen( toolRect.GetTopLeft() );
687 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
705 wxUpdateUIEvent evt( action->
GetUIId() );
707 toolParent->ProcessWindowEvent( evt );
711 if( evt.GetSetEnabled() )
724 RefreshOverflowState();
725 SetHoverItem(
nullptr );
726 SetPressedItem(
nullptr );
730 m_actionPos = wxPoint( -1, -1 );
731 m_actionItem =
nullptr;
745 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
746 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
748 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
751 aDc.SetPen( wxPen( clr ) );
752 aDc.SetBrush( wxBrush( clr ) );
755 int sideLength =
KiROUND( aRect.height / 5.0 );
759 wxPoint btmRight = aRect.GetBottomRight();
760 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
761 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
764 points.Append( &btmRight );
765 points.Append( &topCorner );
766 points.Append( &btmCorner );
768 aDc.DrawPolygon( &points );
774 wxClientDC dc(
this );
785 if( m_orientation == wxHORIZONTAL )
787 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
789 m_vertHintSize = GetSize();
790 retval = RealizeHelper( dc,
false );
793 if( retval && RealizeHelper( dc,
true ) )
795 m_horzHintSize = GetSize();
804 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
806 m_horzHintSize = GetSize();
807 retval = RealizeHelper( dc,
true );
810 if( retval && RealizeHelper( dc,
false ) )
812 m_vertHintSize = GetSize();
836 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
838 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.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
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".