Use SetImages/SetStateImages in project tree on wx 3.3.

This commit is contained in:
Alex Shvartzkop
2026-01-02 08:27:23 +05:00
parent b2766a60ef
commit 13f2d4f6ab
2 changed files with 57 additions and 123 deletions
+57 -122
View File
@@ -46,7 +46,6 @@ PROJECT_TREE::PROJECT_TREE( PROJECT_TREE_PANE* parent ) :
wxTreeCtrl( parent, ID_PROJECT_TREE, wxDefaultPosition, wxDefaultSize,
PLATFORM_STYLE | wxTR_HAS_BUTTONS | wxTR_MULTIPLE, wxDefaultValidator,
wxT( "EDATreeCtrl" ) ),
m_imageList( nullptr ),
m_statusImageList( nullptr )
{
m_projectTreePane = parent;
@@ -62,145 +61,81 @@ PROJECT_TREE::PROJECT_TREE( PROJECT_TREE_PANE* parent ) :
PROJECT_TREE::~PROJECT_TREE()
{
// We pass ownership of these to wxWidgets in SetImageList() and SetStateImageList()
//delete m_imageList;
//delete m_statusImageList;
}
void PROJECT_TREE::LoadIcons()
{
// KiCad for macOS currently has backported high-DPI support for this control
// that is not in a released version of wxWidgets 3.2 yet. This can become the
// main codepath once wxWidgets 3.4 is released.
#ifdef __WXMAC__
const int c_fileDefSize = 24;
const int c_gitDefSize = 16;
wxVector<wxBitmapBundle> images;
images.push_back( KiBitmapBundle( BITMAPS::project ) ); // TREE_LEGACY_PROJECT
images.push_back( KiBitmapBundle( BITMAPS::project_kicad ) ); // TREE_JSON_PROJECT
images.push_back( KiBitmapBundle( BITMAPS::icon_eeschema_24 ) ); // TREE_LEGACY_SCHEMATIC
images.push_back( KiBitmapBundle( BITMAPS::icon_eeschema_24 ) ); // TREE_SEXPR_SCHEMATIC
images.push_back( KiBitmapBundle( BITMAPS::icon_pcbnew_24 ) ); // TREE_LEGACY_PCB
images.push_back( KiBitmapBundle( BITMAPS::icon_pcbnew_24 ) ); // TREE_SEXPR_PCB
images.push_back( KiBitmapBundle( BITMAPS::icon_gerbview_24 ) ); // TREE_GERBER
images.push_back( KiBitmapBundle( BITMAPS::file_gerber_job ) ); // TREE_GERBER_JOB_FILE (.gbrjob)
images.push_back( KiBitmapBundle( BITMAPS::file_html ) ); // TREE_HTML
images.push_back( KiBitmapBundle( BITMAPS::file_pdf ) ); // TREE_PDF
images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // TREE_TXT
images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // TREE_MD
images.push_back( KiBitmapBundle( BITMAPS::netlist ) ); // TREE_NET
images.push_back( KiBitmapBundle( BITMAPS::file_cir ) ); // TREE_NET_SPICE
images.push_back( KiBitmapBundle( BITMAPS::unknown ) ); // TREE_UNKNOWN
images.push_back( KiBitmapBundle( BITMAPS::directory ) ); // TREE_DIRECTORY
images.push_back( KiBitmapBundle( BITMAPS::icon_cvpcb_24 ) ); // TREE_CMP_LINK
images.push_back( KiBitmapBundle( BITMAPS::tools ) ); // TREE_REPORT
images.push_back( KiBitmapBundle( BITMAPS::file_pos ) ); // TREE_POS
images.push_back( KiBitmapBundle( BITMAPS::file_drl ) ); // TREE_DRILL
images.push_back( KiBitmapBundle( BITMAPS::file_drl ) ); // TREE_DRILL_NC (similar TREE_DRILL)
images.push_back( KiBitmapBundle( BITMAPS::file_drl ) ); // TREE_DRILL_XNC (similar TREE_DRILL)
images.push_back( KiBitmapBundle( BITMAPS::file_svg ) ); // TREE_SVG
images.push_back( KiBitmapBundle( BITMAPS::icon_pagelayout_editor_24 ) ); // TREE_PAGE_LAYOUT_DESCR
images.push_back( KiBitmapBundle( BITMAPS::module ) ); // TREE_FOOTPRINT_FILE
images.push_back( KiBitmapBundle( BITMAPS::library ) ); // TREE_SCHEMATIC_LIBFILE
images.push_back( KiBitmapBundle( BITMAPS::library ) ); // TREE_SEXPR_SYMBOL_LIB_FILE
images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // DESIGN_RULES
images.push_back( KiBitmapBundle( BITMAPS::zip ) ); // ZIP_ARCHIVE
images.push_back( KiBitmapBundle( BITMAPS::editor ) ); // JOBSET_FILE
images.push_back( KiBitmapBundleDef( BITMAPS::project, c_fileDefSize ) ); // TREE_LEGACY_PROJECT
images.push_back( KiBitmapBundleDef( BITMAPS::project_kicad, c_fileDefSize ) ); // TREE_JSON_PROJECT
images.push_back( KiBitmapBundleDef( BITMAPS::icon_eeschema_24, c_fileDefSize ) ); // TREE_LEGACY_SCHEMATIC
images.push_back( KiBitmapBundleDef( BITMAPS::icon_eeschema_24, c_fileDefSize ) ); // TREE_SEXPR_SCHEMATIC
images.push_back( KiBitmapBundleDef( BITMAPS::icon_pcbnew_24, c_fileDefSize ) ); // TREE_LEGACY_PCB
images.push_back( KiBitmapBundleDef( BITMAPS::icon_pcbnew_24, c_fileDefSize ) ); // TREE_SEXPR_PCB
images.push_back( KiBitmapBundleDef( BITMAPS::icon_gerbview_24, c_fileDefSize ) ); // TREE_GERBER
images.push_back( KiBitmapBundleDef( BITMAPS::file_gerber_job, c_fileDefSize ) ); // TREE_GERBER_JOB_FILE (.gbrjob)
images.push_back( KiBitmapBundleDef( BITMAPS::file_html, c_fileDefSize ) ); // TREE_HTML
images.push_back( KiBitmapBundleDef( BITMAPS::file_pdf, c_fileDefSize ) ); // TREE_PDF
images.push_back( KiBitmapBundleDef( BITMAPS::editor, c_fileDefSize ) ); // TREE_TXT
images.push_back( KiBitmapBundleDef( BITMAPS::editor, c_fileDefSize ) ); // TREE_MD
images.push_back( KiBitmapBundleDef( BITMAPS::netlist, c_fileDefSize ) ); // TREE_NET
images.push_back( KiBitmapBundleDef( BITMAPS::file_cir, c_fileDefSize ) ); // TREE_NET_SPICE
images.push_back( KiBitmapBundleDef( BITMAPS::unknown, c_fileDefSize ) ); // TREE_UNKNOWN
images.push_back( KiBitmapBundleDef( BITMAPS::directory, c_fileDefSize ) ); // TREE_DIRECTORY
images.push_back( KiBitmapBundleDef( BITMAPS::icon_cvpcb_24, c_fileDefSize ) ); // TREE_CMP_LINK
images.push_back( KiBitmapBundleDef( BITMAPS::tools, c_fileDefSize ) ); // TREE_REPORT
images.push_back( KiBitmapBundleDef( BITMAPS::file_pos, c_fileDefSize ) ); // TREE_POS
images.push_back( KiBitmapBundleDef( BITMAPS::file_drl, c_fileDefSize ) ); // TREE_DRILL
images.push_back( KiBitmapBundleDef( BITMAPS::file_drl, c_fileDefSize ) ); // TREE_DRILL_NC (similar TREE_DRILL)
images.push_back( KiBitmapBundleDef( BITMAPS::file_drl, c_fileDefSize ) ); // TREE_DRILL_XNC (similar TREE_DRILL)
images.push_back( KiBitmapBundleDef( BITMAPS::file_svg, c_fileDefSize ) ); // TREE_SVG
images.push_back( KiBitmapBundleDef( BITMAPS::icon_pagelayout_editor_24, c_fileDefSize ) ); // TREE_PAGE_LAYOUT_DESCR
images.push_back( KiBitmapBundleDef( BITMAPS::module, c_fileDefSize ) ); // TREE_FOOTPRINT_FILE
images.push_back( KiBitmapBundleDef( BITMAPS::library, c_fileDefSize ) ); // TREE_SCHEMATIC_LIBFILE
images.push_back( KiBitmapBundleDef( BITMAPS::library, c_fileDefSize ) ); // TREE_SEXPR_SYMBOL_LIB_FILE
images.push_back( KiBitmapBundleDef( BITMAPS::editor, c_fileDefSize ) ); // DESIGN_RULES
images.push_back( KiBitmapBundleDef( BITMAPS::zip, c_fileDefSize ) ); // ZIP_ARCHIVE
images.push_back( KiBitmapBundleDef( BITMAPS::editor, c_fileDefSize ) ); // JOBSET_FILE
SetImages( images );
// KiCad for macOS currently has backported SetStateImages for this control
// that is otherwise available since wxWidgets 3.3 on other platforms.
#if wxCHECK_VERSION( 3, 3, 0 ) || defined( __WXMAC__ )
wxVector<wxBitmapBundle> stateImages;
stateImages.push_back( wxBitmapBundle( wxBitmap( 16, 16 ) ) ); // GIT_STATUS_UNTRACKED
stateImages.push_back( KiBitmapBundle( BITMAPS::git_good_check ) ); // GIT_STATUS_CURRENT
stateImages.push_back( KiBitmapBundle( BITMAPS::git_modified ) ); // GIT_STATUS_MODIFIED
stateImages.push_back( KiBitmapBundle( BITMAPS::git_add ) ); // GIT_STATUS_ADDED
stateImages.push_back( KiBitmapBundle( BITMAPS::git_delete ) ); // GIT_STATUS_DELETED
stateImages.push_back( KiBitmapBundle( BITMAPS::git_out_of_date ) ); // GIT_STATUS_BEHIND
stateImages.push_back( KiBitmapBundle( BITMAPS::git_changed_ahead ) ); // GIT_STATUS_AHEAD
stateImages.push_back( KiBitmapBundle( BITMAPS::git_conflict ) ); // GIT_STATUS_CONFLICTED
stateImages.push_back( wxBitmapBundle( wxBitmap( 16, 16 ) ) ); // GIT_STATUS_IGNORED
stateImages.push_back( wxBitmapBundle( wxBitmap( c_gitDefSize, c_gitDefSize ) ) ); // GIT_STATUS_UNTRACKED
stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_good_check, c_gitDefSize ) ); // GIT_STATUS_CURRENT
stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_modified, c_gitDefSize ) ); // GIT_STATUS_MODIFIED
stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_add, c_gitDefSize ) ); // GIT_STATUS_ADDED
stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_delete, c_gitDefSize ) ); // GIT_STATUS_DELETED
stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_out_of_date, c_gitDefSize ) ); // GIT_STATUS_BEHIND
stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_changed_ahead, c_gitDefSize ) ); // GIT_STATUS_AHEAD
stateImages.push_back( KiBitmapBundleDef( BITMAPS::git_conflict, c_gitDefSize ) ); // GIT_STATUS_CONFLICTED
stateImages.push_back( wxBitmapBundle( wxBitmap( c_gitDefSize, c_gitDefSize ) ) ); // GIT_STATUS_IGNORED
SetStateImages( stateImages );
#else
delete m_imageList;
// Make an image list containing small icons
int logicSize = 24 * GetDPIScaleFactor() / GetContentScaleFactor(); // Cross-platform way
int physSize = ToPhys( logicSize ); // aka *GetContentScaleFactor()
if( physSize >= 64 )
physSize = 64;
else if( physSize >= 48 )
physSize = 48;
else if( physSize >= 32 )
physSize = 32;
else
physSize = 24;
logicSize = std::min( logicSize, physSize );
int bmpsf = std::max( 1, physSize / logicSize );
logicSize = physSize / bmpsf;
auto toBitmap = [&]( BITMAPS aBmps )
{
wxBitmap bmp = KiBitmap( aBmps, physSize );
bmp.SetScaleFactor( bmpsf );
wxASSERT(bmp.IsOk());
return bmp;
};
m_imageList = new wxImageList( logicSize, logicSize, true,
static_cast<int>( TREE_FILE_TYPE::MAX ) );
m_imageList->Add( toBitmap( BITMAPS::project ) ); // TREE_LEGACY_PROJECT
m_imageList->Add( toBitmap( BITMAPS::project_kicad ) ); // TREE_JSON_PROJECT
m_imageList->Add( toBitmap( BITMAPS::icon_eeschema_24 ) ); // TREE_LEGACY_SCHEMATIC
m_imageList->Add( toBitmap( BITMAPS::icon_eeschema_24 ) ); // TREE_SEXPR_SCHEMATIC
m_imageList->Add( toBitmap( BITMAPS::icon_pcbnew_24 ) ); // TREE_LEGACY_PCB
m_imageList->Add( toBitmap( BITMAPS::icon_pcbnew_24 ) ); // TREE_SEXPR_PCB
m_imageList->Add( toBitmap( BITMAPS::icon_gerbview_24 ) ); // TREE_GERBER
m_imageList->Add( toBitmap( BITMAPS::file_gerber_job ) ); // TREE_GERBER_JOB_FILE (.gbrjob)
m_imageList->Add( toBitmap( BITMAPS::file_html ) ); // TREE_HTML
m_imageList->Add( toBitmap( BITMAPS::file_pdf ) ); // TREE_PDF
m_imageList->Add( toBitmap( BITMAPS::editor ) ); // TREE_TXT
m_imageList->Add( toBitmap( BITMAPS::editor ) ); // TREE_MD
m_imageList->Add( toBitmap( BITMAPS::netlist ) ); // TREE_NET
m_imageList->Add( toBitmap( BITMAPS::file_cir ) ); // TREE_NET_SPICE
m_imageList->Add( toBitmap( BITMAPS::unknown ) ); // TREE_UNKNOWN
m_imageList->Add( toBitmap( BITMAPS::directory ) ); // TREE_DIRECTORY
m_imageList->Add( toBitmap( BITMAPS::icon_cvpcb_24 ) ); // TREE_CMP_LINK
m_imageList->Add( toBitmap( BITMAPS::tools ) ); // TREE_REPORT
m_imageList->Add( toBitmap( BITMAPS::file_pos ) ); // TREE_POS
m_imageList->Add( toBitmap( BITMAPS::file_drl ) ); // TREE_DRILL
m_imageList->Add( toBitmap( BITMAPS::file_drl ) ); // TREE_DRILL_NC (similar TREE_DRILL)
m_imageList->Add( toBitmap( BITMAPS::file_drl ) ); // TREE_DRILL_XNC (similar TREE_DRILL)
m_imageList->Add( toBitmap( BITMAPS::file_svg ) ); // TREE_SVG
m_imageList->Add( toBitmap( BITMAPS::icon_pagelayout_editor_24 ) ); // TREE_PAGE_LAYOUT_DESCR
m_imageList->Add( toBitmap( BITMAPS::module ) ); // TREE_FOOTPRINT_FILE
m_imageList->Add( toBitmap( BITMAPS::library ) ); // TREE_SCHEMATIC_LIBFILE
m_imageList->Add( toBitmap( BITMAPS::library ) ); // TREE_SEXPR_SYMBOL_LIB_FILE
m_imageList->Add( toBitmap( BITMAPS::editor ) ); // DESIGN_RULES
m_imageList->Add( toBitmap( BITMAPS::zip ) ); // ZIP_ARCHIVE
m_imageList->Add( toBitmap( BITMAPS::editor ) ); // JOBSET_FILE
SetImageList( m_imageList );
// Make an image list containing small icons
int size = 16;
wxBitmap blank_bitmap( size, size );
wxBitmap blank_bitmap( c_gitDefSize, c_gitDefSize );
delete m_statusImageList;
m_statusImageList = new wxImageList( size, size, true,
m_statusImageList = new wxImageList( c_gitDefSize, c_gitDefSize, true,
static_cast<int>( KIGIT_COMMON::GIT_STATUS::GIT_STATUS_LAST ) );
m_statusImageList->Add( blank_bitmap ); // GIT_STATUS_UNTRACKED
m_statusImageList->Add( KiBitmap( BITMAPS::git_good_check, size ) ); // GIT_STATUS_CURRENT
m_statusImageList->Add( KiBitmap( BITMAPS::git_modified, size ) ); // GIT_STATUS_MODIFIED
m_statusImageList->Add( KiBitmap( BITMAPS::git_add, size ) ); // GIT_STATUS_ADDED
m_statusImageList->Add( KiBitmap( BITMAPS::git_delete, size ) ); // GIT_STATUS_DELETED
m_statusImageList->Add( KiBitmap( BITMAPS::git_out_of_date, size ) ); // GIT_STATUS_BEHIND
m_statusImageList->Add( KiBitmap( BITMAPS::git_changed_ahead, size ) ); // GIT_STATUS_AHEAD
m_statusImageList->Add( KiBitmap( BITMAPS::git_conflict, size ) ); // GIT_STATUS_CONFLICTED
m_statusImageList->Add( blank_bitmap ); // GIT_STATUS_IGNORED
m_statusImageList->Add( blank_bitmap ); // GIT_STATUS_UNTRACKED
m_statusImageList->Add( KiBitmap( BITMAPS::git_good_check, c_gitDefSize ) ); // GIT_STATUS_CURRENT
m_statusImageList->Add( KiBitmap( BITMAPS::git_modified, c_gitDefSize ) ); // GIT_STATUS_MODIFIED
m_statusImageList->Add( KiBitmap( BITMAPS::git_add, c_gitDefSize ) ); // GIT_STATUS_ADDED
m_statusImageList->Add( KiBitmap( BITMAPS::git_delete, c_gitDefSize ) ); // GIT_STATUS_DELETED
m_statusImageList->Add( KiBitmap( BITMAPS::git_out_of_date, c_gitDefSize ) ); // GIT_STATUS_BEHIND
m_statusImageList->Add( KiBitmap( BITMAPS::git_changed_ahead, c_gitDefSize ) ); // GIT_STATUS_AHEAD
m_statusImageList->Add( KiBitmap( BITMAPS::git_conflict, c_gitDefSize ) ); // GIT_STATUS_CONFLICTED
m_statusImageList->Add( blank_bitmap ); // GIT_STATUS_IGNORED
SetStateImageList( m_statusImageList );
#endif
-1
View File
@@ -45,7 +45,6 @@ class PROJECT_TREE : public wxTreeCtrl
private:
PROJECT_TREE_PANE* m_projectTreePane;
wxImageList* m_imageList;
wxImageList* m_statusImageList;
std::unique_ptr<KIGIT_COMMON> m_gitCommon;