#include <wx/artprov.h>
wxArtProvider class is used to customize the look of wxWidgets application.
When wxWidgets needs to display an icon or a bitmap (e.g. in the standard file dialog), it does not use a hard-coded resource but asks wxArtProvider for it instead. This way users can plug in their own wxArtProvider class and easily replace standard art with their own version.
All that is needed is to derive a class from wxArtProvider, override either its wxArtProvider::CreateBitmap() and/or its wxArtProvider::CreateIconBundle() methods and register the provider with wxArtProvider::Push():
If you need bitmap images (of the same artwork) that should be displayed at different sizes you should probably consider overriding wxArtProvider::CreateIconBundle and supplying icon bundles that contain different bitmap sizes.
There's another way of taking advantage of this class: you can use it in your code and use platform native icons as provided by wxArtProvider::GetBitmapBundle or wxArtProvider::GetIcon.
Every bitmap and icon bundle are known to wxArtProvider under a unique ID that is used when requesting a resource from it. The ID is represented by the ::wxArtID type and can have one of these predefined values (you can see bitmaps represented by these constants in the @ref page_samples_artprov): <table> <tr><td> @li @c wxART_ERROR @li @c wxART_QUESTION @li @c wxART_WARNING @li @c wxART_INFORMATION @li @c wxART_ADD_BOOKMARK @li @c wxART_DEL_BOOKMARK @li @c wxART_HELP_SIDE_PANEL @li @c wxART_HELP_SETTINGS @li @c wxART_HELP_BOOK @li @c wxART_HELP_FOLDER @li @c wxART_HELP_PAGE @li @c wxART_GO_BACK @li @c wxART_GO_FORWARD @li @c wxART_GO_UP @li @c wxART_GO_DOWN @li @c wxART_GO_TO_PARENT @li @c wxART_GO_HOME @li @c wxART_GOTO_FIRST (since 2.9.2) </td><td> @li @c wxART_GOTO_LAST (since 2.9.2) @li @c wxART_PRINT @li @c wxART_HELP @li @c wxART_TIP @li @c wxART_REPORT_VIEW @li @c wxART_LIST_VIEW @li @c wxART_NEW_DIR @li @c wxART_FOLDER @li @c wxART_FOLDER_OPEN @li @c wxART_GO_DIR_UP @li @c wxART_EXECUTABLE_FILE @li @c wxART_NORMAL_FILE @li @c wxART_TICK_MARK @li @c wxART_CROSS_MARK @li @c wxART_MISSING_IMAGE @li @c wxART_NEW @li @c wxART_FILE_OPEN @li @c wxART_FILE_SAVE </td><td> @li @c wxART_FILE_SAVE_AS @li @c wxART_DELETE @li @c wxART_COPY @li @c wxART_CUT @li @c wxART_PASTE @li @c wxART_UNDO @li @c wxART_REDO @li @c wxART_PLUS (since 2.9.2) @li @c wxART_MINUS (since 2.9.2) @li @c wxART_CLOSE @li @c wxART_QUIT @li @c wxART_FIND @li @c wxART_FIND_AND_REPLACE @li @c wxART_FULL_SCREEN (since 3.1.0) @li @c wxART_EDIT (since 3.1.0) @li @c wxART_HARDDISK @li @c wxART_FLOPPY @li @c wxART_CDROM @li @c wxART_REMOVABLE @li @c wxART_WX_LOGO (since 3.1.6) </td></tr> </table> @note When building with @c wxNO_IMPLICIT_WXSTRING_ENCODING defined (see @ref overview_string for more details), you need to explicitly use wxASCII_STR() around these constants. Additionally, any string recognized by custom art providers registered using wxArtProvider::Push may be used. @note When running under GTK+ 2, GTK+ stock item IDs (e.g. @c "gtk-cdrom") may be used as well:
For a list of the GTK+ stock items please refer to the GTK+ documentation page. It is also possible to load icons from the current icon theme by specifying their name (without extension and directory components). Icon themes recognized by GTK+ follow the freedesktop.org Icon Themes specification. Note that themes are not guaranteed to contain all icons, so wxArtProvider may return wxNullBitmap or wxNullIcon. The default theme is typically installed in /usr/share/icons/hicolor
.
The @e client is the entity that calls wxArtProvider's GetBitmap() or GetIcon() function. It is represented by wxClientID type and can have one of these values: @li @c wxART_TOOLBAR @li @c wxART_MENU @li @c wxART_BUTTON @li @c wxART_FRAME_ICON @li @c wxART_CMN_DIALOG @li @c wxART_HELP_BROWSER @li @c wxART_MESSAGE_BOX @li @c wxART_OTHER (used for all requests that don't fit into any of the categories above) Client ID serve as a hint to wxArtProvider that is supposed to help it to choose the best looking bitmap. For example it is often desirable to use slightly different icons in menus and toolbars even though they represent the same action (e.g. wxART_FILE_OPEN). Remember that this is really only a hint for wxArtProvider -- it is common that wxArtProvider::GetBitmap returns identical bitmap for different client values! <h2></h2><div><span class='lib'>Library:</span> <span class='lib_text'>\ref page_libs_wxcore</span></div>
@see @ref page_samples_artprov for an example of wxArtProvider usage; @ref page_stockitems "stock ID list"
Public Member Functions | |
virtual | ~wxArtProvider () |
The destructor automatically removes the provider from the provider stack used by GetBitmap(). More... | |
![]() | |
wxObject () | |
Default ctor; initializes to NULL the internal reference data. More... | |
wxObject (const wxObject &other) | |
Copy ctor. More... | |
virtual | ~wxObject () |
Destructor. More... | |
virtual wxClassInfo * | GetClassInfo () const |
This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More... | |
wxObjectRefData * | GetRefData () const |
Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More... | |
bool | IsKindOf (const wxClassInfo *info) const |
Determines whether this class is a subclass of (or the same class as) the given class. More... | |
bool | IsSameAs (const wxObject &obj) const |
Returns true if this object has the same data pointer as obj. More... | |
void | Ref (const wxObject &clone) |
Makes this object refer to the data in clone. More... | |
void | SetRefData (wxObjectRefData *data) |
Sets the wxObject::m_refData pointer. More... | |
void | UnRef () |
Decrements the reference count in the associated data, and if it is zero, deletes the data. More... | |
void | UnShare () |
This is the same of AllocExclusive() but this method is public. More... | |
void | operator delete (void *buf) |
The delete operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More... | |
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0) |
The new operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More... | |
Static Public Member Functions | |
static bool | Delete (wxArtProvider *provider) |
Delete the given provider. More... | |
static wxBitmap | GetBitmap (const wxArtID &id, const wxArtClient &client=wxART_OTHER, const wxSize &size=wxDefaultSize) |
Query registered providers for bitmap with given ID. More... | |
static wxBitmapBundle | GetBitmapBundle (const wxArtID &id, const wxArtClient &client=wxART_OTHER, const wxSize &size=wxDefaultSize) |
Query registered providers for a bundle of bitmaps with given ID. More... | |
static wxIcon | GetIcon (const wxArtID &id, const wxArtClient &client=wxART_OTHER, const wxSize &size=wxDefaultSize) |
Same as wxArtProvider::GetBitmap, but return a wxIcon object (or wxNullIcon on failure). More... | |
static wxSize | GetNativeDIPSizeHint (const wxArtClient &client) |
Returns native icon size for use specified by client hint in DIPs. More... | |
static wxSize | GetNativeSizeHint (const wxArtClient &client, wxWindow *win=NULL) |
Returns native icon size for use specified by client hint. More... | |
static wxSize | GetDIPSizeHint (const wxArtClient &client) |
Returns a suitable size hint for the given wxArtClient in DIPs. More... | |
static wxSize | GetSizeHint (const wxArtClient &client, wxWindow *win=NULL) |
Returns a suitable size hint for the given wxArtClient. More... | |
static wxIconBundle | GetIconBundle (const wxArtID &id, const wxArtClient &client=wxART_OTHER) |
Query registered providers for icon bundle with given ID. More... | |
static bool | HasNativeProvider () |
Returns true if the platform uses native icons provider that should take precedence over any customizations. More... | |
static void | Insert (wxArtProvider *provider) |
static bool | Pop () |
Remove latest added provider and delete it. More... | |
static void | Push (wxArtProvider *provider) |
Register new art provider and add it to the top of providers stack (i.e. More... | |
static void | PushBack (wxArtProvider *provider) |
Register new art provider and add it to the bottom of providers stack. More... | |
static bool | Remove (wxArtProvider *provider) |
Remove a provider from the stack if it is on it. More... | |
static wxArtID | GetMessageBoxIconId (int flags) |
Helper used by GetMessageBoxIcon(): return the art id corresponding to the standard wxICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set) More... | |
static wxIcon | GetMessageBoxIcon (int flags) |
Helper used by several generic classes: return the icon corresponding to the standard wxICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set) More... | |
Protected Member Functions | |
virtual wxSize | DoGetSizeHint (const wxArtClient &client) |
Derived art provider classes may override this method to return the size of the images used by this provider. More... | |
virtual wxBitmap | CreateBitmap (const wxArtID &id, const wxArtClient &client, const wxSize &size) |
Derived art provider classes may override this method to create requested art resource. More... | |
virtual wxBitmapBundle | CreateBitmapBundle (const wxArtID &id, const wxArtClient &client, const wxSize &size) |
Override this method to create the requested art resources available in more than one size. More... | |
virtual wxIconBundle | CreateIconBundle (const wxArtID &id, const wxArtClient &client) |
This method is similar to CreateBitmap() but can be used when a bitmap (or an icon) exists in several sizes. More... | |
![]() | |
void | AllocExclusive () |
Ensure that this object's data is not shared with any other object. More... | |
virtual wxObjectRefData * | CreateRefData () const |
Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More... | |
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const |
Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More... | |
Additional Inherited Members | |
![]() | |
wxObjectRefData * | m_refData |
Pointer to an object which is the object's reference-counted data. More... | |
|
virtual |
The destructor automatically removes the provider from the provider stack used by GetBitmap().
|
protectedvirtual |
Derived art provider classes may override this method to create requested art resource.
For bitmaps available in more than one size, CreateBitmapBundle() should be overridden instead.
Note that returned bitmaps are cached by wxArtProvider and it is therefore not necessary to optimize CreateBitmap() for speed (e.g. you may create wxBitmap objects from XPMs here).
id | wxArtID unique identifier of the bitmap. |
client | wxArtClient identifier of the client (i.e. who is asking for the bitmap). This only serves as a hint. |
size | Preferred size of the bitmap. The function may return a bitmap of different dimensions, it will be automatically rescaled to meet client's request. |
|
protectedvirtual |
Override this method to create the requested art resources available in more than one size.
Unlike CreateBitmap(), this method can be overridden to return the same bitmap in several (or all, if wxBitmapBundle::FromSVG() is used) sizes at once, which will allow selecting the size best suited for the current display resolution automatically.
id | wxArtID unique identifier of the bitmap. |
client | wxArtClient identifier of the client (i.e. who is asking for the bitmap). This only serves as a hint. |
size | Default size of the bitmaps returned by the bundle. |
|
protectedvirtual |
This method is similar to CreateBitmap() but can be used when a bitmap (or an icon) exists in several sizes.
|
static |
Delete the given provider.
|
protectedvirtual |
Derived art provider classes may override this method to return the size of the images used by this provider.
Note that the returned size should be in DPI-independent pixels, i.e. DIPs. The default implementation returns the result of GetNativeDIPSizeHint().
|
static |
Query registered providers for bitmap with given ID.
Note that applications using wxWidgets 3.1.6 or later should prefer calling GetBitmapBundle().
id | wxArtID unique identifier of the bitmap. |
client | wxArtClient identifier of the client (i.e. who is asking for the bitmap). |
size | Size of the returned bitmap or wxDefaultSize if size doesn't matter. |
|
static |
Query registered providers for a bundle of bitmaps with given ID.
id | wxArtID unique identifier of the bitmap. |
client | wxArtClient identifier of the client (i.e. who is asking for the bitmap). |
size | Default size for the returned bundle, i.e. the size of the bitmap in normal DPI (this implies that wxWindow::FromDIP() must not be used with it). |
|
static |
Returns a suitable size hint for the given wxArtClient in DIPs.
Return the size used by the topmost wxArtProvider for the given client. wxDefaultSize may be returned if the client doesn't have a specified size, like wxART_OTHER for example.
|
static |
Same as wxArtProvider::GetBitmap, but return a wxIcon object (or wxNullIcon on failure).
|
static |
Query registered providers for icon bundle with given ID.
id | wxArtID unique identifier of the icon bundle. |
client | wxArtClient identifier of the client (i.e. who is asking for the icon bundle). |
|
static |
Helper used by several generic classes: return the icon corresponding to the standard wxICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set)
|
static |
Helper used by GetMessageBoxIcon(): return the art id corresponding to the standard wxICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one can be set)
|
static |
Returns native icon size for use specified by client hint in DIPs.
If the platform has no commonly used default for this use or if client is not recognized, returns wxDefaultSize.
|
static |
Returns native icon size for use specified by client hint.
This function does the same thing as GetNativeDIPSizeHint(), but uses win to convert the returned value to logical pixels. If win is NULL, default DPI scaling (i.e. that of the primary display) is used.
|
static |
Returns a suitable size hint for the given wxArtClient.
This function does the same thing as GetDIPSizeHint(), but uses win to convert the returned value to logical pixels. If win is NULL, default DPI scaling (i.e. that of the primary display) is used.
Note that win parameter is only available since wxWidgets 3.1.6.
|
static |
Returns true if the platform uses native icons provider that should take precedence over any customizations.
This is true for any platform that has user-customizable icon themes, currently only wxGTK.
A typical use for this method is to decide whether a custom art provider should be plugged in using Push() or PushBack().
|
static |
|
static |
Remove latest added provider and delete it.
|
static |
Register new art provider and add it to the top of providers stack (i.e.
it will be queried as the first provider).
|
static |
Register new art provider and add it to the bottom of providers stack.
In other words, it will be queried as the last one, after all others, including the default provider.
|
static |
Remove a provider from the stack if it is on it.
The provider is not deleted, unlike when using Delete().