32#include <magic_enum.hpp>
33#include <wx/listctrl.h>
73 wxASSERT( aType == TOOLBAR_ITEM_TYPE::SPACER );
82 wxASSERT( aType == TOOLBAR_ITEM_TYPE::CONTROL
83 || aType == TOOLBAR_ITEM_TYPE::TB_GROUP );
91 wxASSERT( aType == TOOLBAR_ITEM_TYPE::TOOL );
122 const std::vector<TOOL_ACTION*>& aTools,
123 const std::vector<ACTION_TOOLBAR_CONTROL*>& aControls ) :
125 m_actionImageList( nullptr ),
126 m_appSettings( aCfg ),
127 m_appTbSettings( aTbSettings ),
131 for(
auto& tool : aTools )
134 for(
auto& control : aControls )
175 for(
auto& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
180 if( tbConfig.has_value() )
187 auto firstTb = magic_enum::enum_cast<TOOLBAR_LOC>( 0 );
189 if( firstTb.has_value() )
199 wxArrayString tbChoices;
202 for(
auto& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
207 if( tbConfig.has_value() )
214 wxString::Format(
"Unknown toolbar: %s", magic_enum::enum_name( tb ) ) );
216 tbChoices.Add( tbName->second );
227 auto firstTb = magic_enum::enum_cast<TOOLBAR_LOC>( 0 );
229 if( firstTb.has_value() )
249 if( currentTb.has_value() )
266 wxTreeItemIdValue mainCookie;
273 while( mainId.IsOk() )
275 wxTreeItemData* treeData =
m_toolbarTree->GetItemData( mainId );
283 case TOOLBAR_ITEM_TYPE::SPACER:
287 case TOOLBAR_ITEM_TYPE::SEPARATOR:
291 case TOOLBAR_ITEM_TYPE::CONTROL:
295 case TOOLBAR_ITEM_TYPE::TOOL:
299 case TOOLBAR_ITEM_TYPE::TB_GROUP:
304 wxTreeItemIdValue childCookie;
305 wxTreeItemId childId =
m_toolbarTree->GetFirstChild( mainId, childCookie );
307 while( childId.IsOk() )
309 wxTreeItemData* childTreeData =
m_toolbarTree->GetItemData( childId );
313 wxASSERT( childTbData );
315 switch( childTbData->
GetType() )
317 case TOOLBAR_ITEM_TYPE::TB_GROUP:
318 case TOOLBAR_ITEM_TYPE::SPACER:
319 case TOOLBAR_ITEM_TYPE::SEPARATOR:
320 case TOOLBAR_ITEM_TYPE::CONTROL:
321 wxASSERT_MSG(
false,
"Invalid entry in a group" );
324 case TOOLBAR_ITEM_TYPE::TOOL:
329 childId =
m_toolbarTree->GetNextChild( mainId, childCookie );
333 config.AppendGroup( grpConfig );
366 switch( item.m_Type )
368 case TOOLBAR_ITEM_TYPE::SEPARATOR:
372 m_toolbarTree->AppendItem( root,
"Separator", -1, -1, sepTreeItem );
376 case TOOLBAR_ITEM_TYPE::SPACER:
380 spacerTreeItem->
SetSize( item.m_Size );
381 m_toolbarTree->AppendItem( root, wxString::Format(
"Spacer: %i", item.m_Size ), -1, -1,
386 case TOOLBAR_ITEM_TYPE::CONTROL:
390 controlTreeItem->
SetName( item.m_ControlName );
391 m_toolbarTree->AppendItem( root, item.m_ControlName, -1, -1, controlTreeItem );
395 case TOOLBAR_ITEM_TYPE::TOOL:
402 wxASSERT_MSG(
false, wxString::Format(
"Unable to find tool %s", item.m_ActionName ) );
407 toolTreeItem->
SetAction( toolMap->second );
413 imgIdx = imgMap->second;
415 m_toolbarTree->AppendItem( root, toolMap->second->GetFriendlyName(), imgIdx, -1, toolTreeItem );
419 case TOOLBAR_ITEM_TYPE::TB_GROUP:
423 groupTreeItem->
SetName( item.m_GroupName );
425 wxTreeItemId groupId =
m_toolbarTree->AppendItem( root, item.m_GroupName, -1, -1,
435 wxASSERT_MSG(
false, wxString::Format(
"Unable to find group tool %s", groupItem.
m_ActionName ) );
440 toolTreeItem->
SetAction( toolMap->second );
446 imgIdx = imgMap->second;
448 m_toolbarTree->AppendItem( groupId, toolMap->second->GetFriendlyName(),
449 imgIdx, -1, toolTreeItem );
459 wxTreeItemIdValue temp;
460 wxTreeItemId firstItem =
m_toolbarTree->GetFirstChild( root, temp );
462 if( firstItem.IsOk() )
480 m_actionsList->InsertColumn( 0,
"", wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE );
483 int logicSize = 24 * GetDPIScaleFactor() / GetContentScaleFactor();
484 int physSize = ToPhys( logicSize );
488 else if( physSize >= 48 )
490 else if( physSize >= 32 )
495 logicSize = std::min( logicSize, physSize );
496 int bmpsf = std::max( 1, physSize / logicSize );
498 logicSize = physSize / bmpsf;
500 auto toBitmap = [&](
BITMAPS aBmps )
502 wxBitmap bmp =
KiBitmap( aBmps, physSize );
503 bmp.SetScaleFactor( bmpsf );
504 wxASSERT(bmp.IsOk());
516 if( tool->CheckToolbarState( TOOLBAR_STATE::HIDDEN ) )
520 item.SetText( tool->GetFriendlyName() );
521 item.SetData(
static_cast<void*
>( tool ) );
522 item.SetId( itemIdx++ );
524 if( tool->GetIcon() != BITMAPS::INVALID_BITMAP )
535 item.SetImage( idx );
554 wxTreeItemId newItem;
560 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
564 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
566 if( secondParent.IsOk() )
594 wxString label = wxString::Format(
"Spacer: %i", treeItem->
GetSize() );
596 wxTreeItemId newItem;
602 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
607 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
609 if( secondParent.IsOk() )
616 newItem =
m_toolbarTree->InsertItem( parent, selItem, label, -1, -1, treeItem );
633 wxTreeItemId newItem;
639 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
644 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
646 if( secondParent.IsOk() )
653 newItem =
m_toolbarTree->InsertItem( parent, selItem,
"Separator", -1, -1, treeItem );
712 if( !item.IsOk() && prev.IsOk() )
735 long actionIdx =
m_actionsList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
753 imgIdx = imgMap->second;
758 wxTreeItemId newItem;
765 if( data && data->
GetType() == TOOLBAR_ITEM_TYPE::TB_GROUP )
768 newItem =
m_toolbarTree->AppendItem( selItem, label, imgIdx, -1, toolTreeItem );
773 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
774 newItem =
m_toolbarTree->InsertItem( parent, selItem, label, imgIdx, -1, toolTreeItem );
790 if( ++actionIdx < m_actionsList->GetItemCount() )
791 m_actionsList->SetItemState( actionIdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
798 wxTreeItemId
id =
event.GetItem();
806 switch( tbData->GetType() )
808 case TOOLBAR_ITEM_TYPE::TOOL:
809 case TOOLBAR_ITEM_TYPE::CONTROL:
810 case TOOLBAR_ITEM_TYPE::SEPARATOR:
815 case TOOLBAR_ITEM_TYPE::TB_GROUP:
816 case TOOLBAR_ITEM_TYPE::SPACER:
836 if( currentTb.has_value() )
840 auto newTb = magic_enum::enum_cast<TOOLBAR_LOC>( event.GetInt() );
842 if( newTb.has_value() )
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
BITMAPS
A list of all bitmap identifiers.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
bool m_CustomToolbars
Use custom toolbars.