How to properly create a wxIconBundle under Linux?

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
a little bit
In need of some credit
In need of some credit
Posts: 6
Joined: Sat Apr 10, 2021 11:46 am

How to properly create a wxIconBundle under Linux?

Post by a little bit »

I would like to create a wxIconBundle under Linux for a given file type (e.g., "pdf") with different icon sizes. Currently, I have the following code for my wxArtProvider-derived art_provider:

Code: Select all

wxIconBundle
art_provider::CreateIconBundle(
	wxArtID const& art_id,
	wxArtClient const& WXUNUSED(art_client)
) {
    wxIconBundle icon_bundle;

    if (auto const file_type = get_file_type(art_id); !file_type)
        ;

    else {
        create_icon_bundle(icon_bundle, *file_type);
        delete file_type;
    }

    return icon_bundle;
}
with

Code: Select all

static wxFileType*
get_file_type(
	wxString const& key
) {
    if (auto const file_type = wxTheMimeTypesManager->GetFileTypeFromMimeType(key))
        return file_type;
        
    if (auto const file_type = wxTheMimeTypesManager->GetFileTypeFromExtension(key))
        return file_type;
        
    return nullptr;
}

static void
create_icon_bundle(
	wxIconBundle& icon_bundle,
	wxFileType const& file_type
) {
    if (wxIconLocation icon_loc; file_type.GetIcon(&icon_loc)) {
        /*
         * icon_loc denotes the path name of an icon with one *particular*
         * size; we now need to collect all other sizes of that icon as well
         * in order to build our icon bundle
         */
         
         // ???
    }
}
In section "???" I do some nasty heuristic function calls to find all the files containing the same icon but with a different size. For instance, the icons might be distributed in directories /usr/share/icons/gnome/MxM/mimetypes/ with M = 16, 32, 48, 128, ... with icon_loc then containing one particular icon file from those directories. Hence, in that case, I check the other existing directories for the respective icon file. That feels messy. Is there a better and more portable way to create the icon bundle under Linux using a wxWidgets call sequence?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to properly create a wxIconBundle under Linux?

Post by ONEEYEMAN »

Hi,
Why do you need an icon bundle?

Just use XPM on Linux, png on Windows and pack the 2 icons inside the Application Bundle on Mac.

Thank you.
thoray
Knows some wx things
Knows some wx things
Posts: 48
Joined: Sun Oct 18, 2015 9:31 am

Re: How to properly create a wxIconBundle under Linux?

Post by thoray »

Here's my code for all three platforms. Using an icon bundle looks good with hidpi.

Code: Select all

wxIconBundle icons;

#ifdef __WXMSW__
icons.AddIcon("resname_icon",0); // add icons from windows resource file
#else
// TODO find out how to load __WXOSX__ .icns file here

// Repeat the next line for different icon sizes
icons.AddIcon(myicon_png);
#endif

// optionally call in frame's constructor
SetIcons(icons);
Post Reply