32#include <magic_enum.hpp>
33#include <wx/listctrl.h>
67 wxASSERT( aType == TOOLBAR_ITEM_TYPE::SPACER );
74 wxASSERT( aType == TOOLBAR_ITEM_TYPE::CONTROL
75 || aType == TOOLBAR_ITEM_TYPE::TB_GROUP );
82 wxASSERT( aType == TOOLBAR_ITEM_TYPE::TOOL );
113 std::vector<TOOL_ACTION*> aTools,
114 std::vector<ACTION_TOOLBAR_CONTROL*> aControls ) :
116 m_actionImageList( nullptr ),
117 m_appSettings( aCfg ),
118 m_appTbSettings( aTbSettings )
121 for(
auto& tool : aTools )
124 for(
auto& control : aControls )
165 for(
auto& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
170 if( tbConfig.has_value() )
177 auto firstTb = magic_enum::enum_cast<TOOLBAR_LOC>( 0 );
179 if( firstTb.has_value() )
189 wxArrayString tbChoices;
192 for(
auto& tb : magic_enum::enum_values<TOOLBAR_LOC>() )
197 if( tbConfig.has_value() )
204 wxString::Format(
"Unknown toolbar: %s", magic_enum::enum_name( tb ) ) );
206 tbChoices.Add( tbName->second );
217 auto firstTb = magic_enum::enum_cast<TOOLBAR_LOC>( 0 );
219 if( firstTb.has_value() )
239 if( currentTb.has_value() )
256 wxTreeItemIdValue mainCookie;
263 while( mainId.IsOk() )
265 wxTreeItemData* treeData =
m_toolbarTree->GetItemData( mainId );
273 case TOOLBAR_ITEM_TYPE::SPACER:
277 case TOOLBAR_ITEM_TYPE::SEPARATOR:
281 case TOOLBAR_ITEM_TYPE::CONTROL:
285 case TOOLBAR_ITEM_TYPE::TOOL:
289 case TOOLBAR_ITEM_TYPE::TB_GROUP:
294 wxTreeItemIdValue childCookie;
295 wxTreeItemId childId =
m_toolbarTree->GetFirstChild( mainId, childCookie );
297 while( childId.IsOk() )
299 wxTreeItemData* childTreeData =
m_toolbarTree->GetItemData( childId );
303 wxASSERT( childTbData );
305 switch( childTbData->
GetType() )
307 case TOOLBAR_ITEM_TYPE::TB_GROUP:
308 case TOOLBAR_ITEM_TYPE::SPACER:
309 case TOOLBAR_ITEM_TYPE::SEPARATOR:
310 case TOOLBAR_ITEM_TYPE::CONTROL:
311 wxASSERT_MSG(
false,
"Invalid entry in a group" );
314 case TOOLBAR_ITEM_TYPE::TOOL:
319 childId =
m_toolbarTree->GetNextChild( mainId, childCookie );
323 config.AppendGroup( grpConfig );
356 switch( item.m_Type )
358 case TOOLBAR_ITEM_TYPE::SEPARATOR:
362 m_toolbarTree->AppendItem( root,
"Separator", -1, -1, sepTreeItem );
366 case TOOLBAR_ITEM_TYPE::SPACER:
370 spacerTreeItem->
SetSize( item.m_Size );
371 m_toolbarTree->AppendItem( root, wxString::Format(
"Spacer: %i", item.m_Size ), -1, -1,
376 case TOOLBAR_ITEM_TYPE::CONTROL:
380 controlTreeItem->
SetName( item.m_ControlName );
386 case TOOLBAR_ITEM_TYPE::TOOL:
393 wxASSERT_MSG(
false, wxString::Format(
"Unable to find tool %s", item.m_ActionName ) );
398 toolTreeItem->
SetAction( toolMap->second );
404 imgIdx = imgMap->second;
406 m_toolbarTree->AppendItem( root, toolMap->second->GetFriendlyName(),
407 imgIdx, -1, toolTreeItem );
411 case TOOLBAR_ITEM_TYPE::TB_GROUP:
415 groupTreeItem->
SetName( item.m_GroupName );
417 wxTreeItemId groupId =
m_toolbarTree->AppendItem( root, item.m_GroupName, -1, -1,
421 for(
auto& groupItem : item.m_GroupItems )
427 wxASSERT_MSG(
false, wxString::Format(
"Unable to find group tool %s", groupItem.m_ActionName ) );
432 toolTreeItem->
SetAction( toolMap->second );
438 imgIdx = imgMap->second;
440 m_toolbarTree->AppendItem( groupId, toolMap->second->GetFriendlyName(),
441 imgIdx, -1, toolTreeItem );
450 wxTreeItemIdValue temp;
451 wxTreeItemId firstItem =
m_toolbarTree->GetFirstChild( root, temp );
453 if( firstItem.IsOk() )
471 m_actionsList->InsertColumn( 0,
"", wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE );
474 int logicSize = 24 * GetDPIScaleFactor() / GetContentScaleFactor();
475 int physSize = ToPhys( logicSize );
479 else if( physSize >= 48 )
481 else if( physSize >= 32 )
486 logicSize = std::min( logicSize, physSize );
487 int bmpsf = std::max( 1, physSize / logicSize );
489 logicSize = physSize / bmpsf;
491 auto toBitmap = [&](
BITMAPS aBmps )
493 wxBitmap bmp =
KiBitmap( aBmps, physSize );
494 bmp.SetScaleFactor( bmpsf );
495 wxASSERT(bmp.IsOk());
507 if( tool->CheckToolbarState( TOOLBAR_STATE::HIDDEN ) )
511 item.SetText( tool->GetFriendlyName() );
512 item.SetData(
static_cast<void*
>( tool ) );
513 item.SetId( itemIdx++ );
515 if( tool->GetIcon() != BITMAPS::INVALID_BITMAP )
526 item.SetImage( idx );
545 wxTreeItemId newItem;
551 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
555 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
557 if( secondParent.IsOk() )
585 wxString label = wxString::Format(
"Spacer: %i", treeItem->
GetSize() );
587 wxTreeItemId newItem;
593 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
598 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
600 if( secondParent.IsOk() )
607 newItem =
m_toolbarTree->InsertItem( parent, selItem, label, -1, -1, treeItem );
624 wxTreeItemId newItem;
630 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
635 wxTreeItemId secondParent =
m_toolbarTree->GetItemParent( parent );
637 if( secondParent.IsOk() )
644 newItem =
m_toolbarTree->InsertItem( parent, selItem,
"Separator", -1, -1, treeItem );
703 if( !item.IsOk() && prev.IsOk() )
726 long actionIdx =
m_actionsList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
744 imgIdx = imgMap->second;
749 wxTreeItemId newItem;
757 if( data && data->
GetType() == TOOLBAR_ITEM_TYPE::TB_GROUP )
760 newItem =
m_toolbarTree->AppendItem( selItem, label, imgIdx, -1, toolTreeItem );
765 wxTreeItemId parent =
m_toolbarTree->GetItemParent( selItem );
766 newItem =
m_toolbarTree->InsertItem( parent, selItem, label, imgIdx, -1, toolTreeItem );
782 if( ++actionIdx < m_actionsList->GetItemCount() )
783 m_actionsList->SetItemState( actionIdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
790 wxTreeItemId
id =
event.GetItem();
799 case TOOLBAR_ITEM_TYPE::TOOL:
800 case TOOLBAR_ITEM_TYPE::CONTROL:
801 case TOOLBAR_ITEM_TYPE::SEPARATOR:
806 case TOOLBAR_ITEM_TYPE::TB_GROUP:
807 case TOOLBAR_ITEM_TYPE::SPACER:
826 if( currentTb.has_value() )
830 auto newTb = magic_enum::enum_cast<TOOLBAR_LOC>( event.GetInt() );
832 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.