#include </home/zeitlin/src/wx/github/interface/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():
class MyProvider : public wxArtProvider { protected: wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, const wxSize size) // optionally override this one as well wxIconBundle CreateIconBundle(const wxArtID& id, const wxArtClient& client) { ... } }; ... wxArtProvider::Push(new MyProvider);
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::GetBitmap or wxArtProvider::GetIcon.
Every bitmap and icon bundle are known to wxArtProvider under an 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 Art Provider Sample):
|
|
|
Additionally, any string recognized by custom art providers registered using wxArtProvider::Push may be used.
"gtk-cdrom"
) may be used as well: #ifdef __WXGTK__ wxBitmap bmp = wxArtProvider::GetBitmap("gtk-cdrom", wxART_MENU); #endif
/usr/share/icons/hicolor
.The 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:
wxART_TOOLBAR
wxART_MENU
wxART_BUTTON
wxART_FRAME_ICON
wxART_CMN_DIALOG
wxART_HELP_BROWSER
wxART_MESSAGE_BOX
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!
Public Member Functions | |
virtual | ~wxArtProvider () |
The destructor automatically removes the provider from the provider stack used by GetBitmap(). | |
Static Public Member Functions | |
static bool | Delete (wxArtProvider *provider) |
Delete the given provider. | |
static wxBitmap | GetBitmap (const wxArtID &id, const wxArtClient &client=wxART_OTHER, const wxSize &size=wxDefaultSize) |
Query registered providers for bitmap with given ID. | |
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). | |
static wxSize | GetNativeSizeHint (const wxArtClient &client) |
Returns native icon size for use specified by client hint. | |
static wxSize | GetSizeHint (const wxArtClient &client, bool platform_default=false) |
Returns a suitable size hint for the given wxArtClient. | |
static wxIconBundle | GetIconBundle (const wxArtID &id, const wxArtClient &client=wxART_OTHER) |
Query registered providers for icon bundle with given ID. | |
static bool | HasNativeProvider () |
Returns true if the platform uses native icons provider that should take precedence over any customizations. | |
static void | Insert (wxArtProvider *provider) |
static bool | Pop () |
Remove latest added provider and delete it. | |
static void | Push (wxArtProvider *provider) |
Register new art provider and add it to the top of providers stack (i.e. | |
static void | PushBack (wxArtProvider *provider) |
Register new art provider and add it to the bottom of providers stack. | |
static bool | Remove (wxArtProvider *provider) |
Remove a provider from the stack if it is on it. | |
Protected Member Functions | |
virtual wxBitmap | CreateBitmap (const wxArtID &id, const wxArtClient &client, const wxSize &size) |
Derived art provider classes must override this method to create requested art resource. | |
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. |
virtual wxArtProvider::~wxArtProvider | ( | ) | [virtual] |
The destructor automatically removes the provider from the provider stack used by GetBitmap().
virtual wxBitmap wxArtProvider::CreateBitmap | ( | const wxArtID & | id, |
const wxArtClient & | client, | ||
const wxSize & | size | ||
) | [protected, virtual] |
Derived art provider classes must override this method to create requested art resource.
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 servers 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. |
virtual wxIconBundle wxArtProvider::CreateIconBundle | ( | const wxArtID & | id, |
const wxArtClient & | client | ||
) | [protected, virtual] |
This method is similar to CreateBitmap() but can be used when a bitmap (or an icon) exists in several sizes.
static bool wxArtProvider::Delete | ( | wxArtProvider * | provider | ) | [static] |
Delete the given provider.
static wxBitmap wxArtProvider::GetBitmap | ( | const wxArtID & | id, |
const wxArtClient & | client = wxART_OTHER , |
||
const wxSize & | size = wxDefaultSize |
||
) | [static] |
Query registered providers for bitmap 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 | Size of the returned bitmap or wxDefaultSize if size doesn't matter. |
static wxIcon wxArtProvider::GetIcon | ( | const wxArtID & | id, |
const wxArtClient & | client = wxART_OTHER , |
||
const wxSize & | size = wxDefaultSize |
||
) | [static] |
Same as wxArtProvider::GetBitmap, but return a wxIcon object (or wxNullIcon on failure).
static wxIconBundle wxArtProvider::GetIconBundle | ( | const wxArtID & | id, |
const wxArtClient & | client = wxART_OTHER |
||
) | [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 wxSize wxArtProvider::GetNativeSizeHint | ( | const wxArtClient & | client | ) | [static] |
Returns native icon size for use specified by client hint.
If the platform has no commonly used default for this use or if client is not recognized, returns wxDefaultSize.
static wxSize wxArtProvider::GetSizeHint | ( | const wxArtClient & | client, |
bool | platform_default = false |
||
) | [static] |
Returns a suitable size hint for the given wxArtClient.
If platform_default is true, return a size based on the current platform using GetNativeSizeHint(), otherwise return the size from the topmost wxArtProvider. wxDefaultSize may be returned if the client doesn't have a specified size, like wxART_OTHER for example.
static bool wxArtProvider::HasNativeProvider | ( | ) | [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 void wxArtProvider::Insert | ( | wxArtProvider * | provider | ) | [static] |
static bool wxArtProvider::Pop | ( | ) | [static] |
Remove latest added provider and delete it.
static void wxArtProvider::Push | ( | wxArtProvider * | provider | ) | [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 void wxArtProvider::PushBack | ( | wxArtProvider * | 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 bool wxArtProvider::Remove | ( | wxArtProvider * | provider | ) | [static] |
Remove a provider from the stack if it is on it.
The provider is not deleted, unlike when using Delete().