44#include <wx/popupwin.h>
45#include <wx/renderer.h>
47#include <wx/dcclient.h>
48#include <wx/settings.h>
58 const std::vector<const TOOL_ACTION*>& aActions )
60 wxASSERT_MSG( aActions.size() > 0, wxS(
"Action groups must have at least one action" ) );
83 return aAction->GetId() == aDefault.GetId();
86 wxASSERT_MSG( valid, wxS(
"Action must be present in a group to be the default" ) );
92#define PALETTE_BORDER 4
93#define BUTTON_BORDER 1
97 wxPopupTransientWindow( aParent, wxBORDER_NONE ),
99 m_isVertical( aVertical ),
101 m_mainSizer( nullptr ),
102 m_buttonSizer( nullptr )
104 m_panel =
new wxPanel(
this, wxID_ANY );
105 m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
108 m_buttonSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
111 m_mainSizer =
new wxBoxSizer( aVertical ? wxVERTICAL : wxHORIZONTAL );
126 int padding = (
m_buttonSize.GetWidth() - normalBmp.GetWidth() ) / 2;
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() ),
194#if !wxCHECK_VERSION( 3, 1, 0 )
197 SetArtProvider( newArt );
202 Connect( wxEVT_AUITOOLBAR_RIGHT_CLICK,
212 Bind( wxEVT_SYS_COLOUR_CHANGED,
232 wxASSERT( GetParent() );
233 wxASSERT_MSG( !( aIsCancellable && !aIsToggleEntry ), wxS(
"aIsCancellable requires aIsToggleEntry" ) );
235 int toolId = aAction.
GetUIId();
239 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
250 int toolId = aAction.
GetUIId();
254 wxITEM_NORMAL, aAction.
GetDescription(), wxEmptyString,
nullptr );
263 int scale =
Pgm().GetCommonSettings()->m_Appearance.icon_scale;
269 AddSpacer( 16 * (
scale - 4 ) / 4 );
274 AddSpacer( 16 * (
scale - 4 ) / 4 );
279 std::unique_ptr<ACTION_MENU> aMenu )
281 int toolId = aAction.
GetUIId();
289 int groupId = aGroup->
GetUIId();
293 wxASSERT( GetParent() );
294 wxASSERT( defaultAction );
302 aIsToggleEntry ? wxITEM_CHECK : wxITEM_NORMAL,
303 wxEmptyString, wxEmptyString,
nullptr );
316 return aAction.GetId() == action2->GetId();
326 wxASSERT( GetParent() );
328 int groupId = aGroup->
GetUIId();
330 wxAuiToolBarItem* item = FindTool( groupId );
338#if wxCHECK_VERSION( 3, 1, 6 )
339 item->SetDisabledBitmap(
350 wxASSERT_MSG( cond, wxString::Format(
"Missing UI condition for action %s",
366 wxAuiToolBarItem* item = FindTool( aID );
367 wxASSERT_MSG( item, wxString::Format(
"No toolbar item found for ID %d", aID ) );
370 wxControl* control =
dynamic_cast<wxControl*
>( item->GetWindow() );
371 wxASSERT_MSG( control, wxString::Format(
"No control located in toolbar item with ID %d", aID ) );
374 wxSize bestSize = control->GetBestSize();
375 item->SetMinSize( bestSize );
381 if( wxSizerItem* szrItem = item->GetSizerItem() )
382 szrItem->SetMinSize( bestSize );
390 m_sizer->SetItemMinSize( control, bestSize );
414 int toolId = aAction.
GetUIId();
415 wxAuiToolBar::SetToolBitmap( toolId, aBitmap );
418 wxAuiToolBarItem* tb_item = wxAuiToolBar::FindTool( toolId );
427 int toolId = aAction.
GetUIId();
430 ToggleTool( toolId, aState );
432 EnableTool( toolId, aState );
438 int toolId = aAction.
GetUIId();
440 EnableTool( toolId, aEnabled );
441 ToggleTool( toolId, aEnabled && aChecked );
447 int id = aEvent.GetId();
448 wxEventType type = aEvent.GetEventType();
451 bool handled =
false;
468 evt = actionIt->second->MakeEvent();
469 evt->SetHasPosition(
false );
484 int toolId = aEvent.GetToolId();
496 toolId = actionIt->second->GetUIId();
505 std::unique_ptr<ACTION_MENU>& owningMenu = menuIt->second;
512 condMenu->Evaluate( dummySel );
519 SetHoverItem(
nullptr );
523#define PALETTE_OPEN_DELAY 500
528 wxAuiToolBarItem* item = FindToolByPosition( aEvent.GetX(), aEvent.GetY() );
545 if( aEvent.LeftUp() )
556 int toolId = aEvent.GetToolId();
560 wxAuiToolBarItem* item = FindTool( toolId );
578 wxPoint mousePos = ScreenToClient( wxGetMousePosition() );
580 wxAuiToolBarItem* item = FindToolByPosition( mousePos.x, mousePos.y );
596 auto actionIt = std::find_if(
group->GetActions().begin(),
group->GetActions().end(),
599 return aAction->GetUIId() == aEvent.GetId();
602 if( actionIt !=
group->GetActions().end() )
630 wxASSERT( GetParent() );
632 wxASSERT( toolParent );
645 wxRect toolRect = GetToolRect( aItem->GetId() );
648 wxPoint pos( ClientToScreen( toolRect.GetPosition() ) );
652 size_t numActions =
group->m_actions.size();
658 + ( numActions * toolRect.GetHeight() );
661 switch( pane.dock_direction )
666 pos = ClientToScreen( toolRect.GetBottomLeft() );
671 case wxAUI_DOCK_BOTTOM:
675 pos = ClientToScreen( toolRect.GetTopLeft() );
678 -( paletteLongDim + m_topPadding ) );
681 case wxAUI_DOCK_LEFT:
684 pos = ClientToScreen( toolRect.GetTopRight() );
685 pos += wxPoint( m_rightPadding,
689 case wxAUI_DOCK_RIGHT:
693 pos = ClientToScreen( toolRect.GetTopLeft() );
696 pos += wxPoint( -( paletteLongDim + m_leftPadding ),
714 wxUpdateUIEvent evt( action->
GetUIId() );
716 toolParent->ProcessWindowEvent( evt );
720 if( evt.GetSetEnabled() )
733 RefreshOverflowState();
734 SetHoverItem(
nullptr );
735 SetPressedItem(
nullptr );
739 m_actionPos = wxPoint( -1, -1 );
740 m_actionItem =
nullptr;
754 if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
755 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
757 clr = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
760 aDc.SetPen( wxPen( clr ) );
761 aDc.SetBrush( wxBrush( clr ) );
764 int sideLength =
KiROUND( aRect.height / 5.0 );
768 wxPoint btmRight = aRect.GetBottomRight();
769 wxPoint topCorner( btmRight.x, btmRight.y - sideLength );
770 wxPoint btmCorner( btmRight.x - sideLength, btmRight.y );
773 points.Append( &btmRight );
774 points.Append( &topCorner );
775 points.Append( &btmCorner );
777 aDc.DrawPolygon( &points );
783 wxClientDC dc(
this );
794 if( m_orientation == wxHORIZONTAL )
796 if( !( GetWindowStyle() & wxAUI_TB_HORIZONTAL ) )
798 m_vertHintSize = GetSize();
799 retval = RealizeHelper( dc,
false );
802 if( retval && RealizeHelper( dc,
true ) )
804 m_horzHintSize = GetSize();
813 if( !( GetWindowStyle() & wxAUI_TB_VERTICAL ) )
815 m_horzHintSize = GetSize();
816 retval = RealizeHelper( dc,
true );
819 if( retval && RealizeHelper( dc,
false ) )
821 m_vertHintSize = GetSize();
845 for(
const std::pair<int, const TOOL_ACTION*> pair :
m_toolActions )
847 wxAuiToolBarItem* tool = FindTool( pair.first );
849 wxBitmap bmp =
KiScaledBitmap( pair.second->GetIcon(), GetParent() );
851 tool->SetBitmap( bmp );
int KiIconScale(wxWindow *aWindow)
Return the automatic scale factor that would be used for a given window by KiScaledBitmap and KiScale...
BITMAP_STORE * GetBitmapStore()
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight, bool aQuantized)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
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".