Contents Up Previous Next

wxArtProvider

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 its CreateBitmap method and register the provider with wxArtProvider::Push:

  class MyProvider : public wxArtProvider
  {
  protected:
    wxBitmap CreateBitmap(const wxArtID& id, 
                          const wxArtClient& client,
                          const wxSize size)
    { ... }
  };
  ...
  wxArtProvider::Push(new MyProvider);
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 (NB: this is not yet really possible as of wxWidgets 2.3.3, the set of wxArtProvider bitmaps is too small).

Identifying art resources
Clients
wxArtProvider::~wxArtProvider
wxArtProvider::CreateBitmap
wxArtProvider::Delete
wxArtProvider::GetBitmap
wxArtProvider::GetIcon
wxArtProvider::Insert
wxArtProvider::Pop
wxArtProvider::Push
wxArtProvider::Remove


Identifying art resources

Every bitmap is known to wxArtProvider under an unique ID that is used by when requesting a resource from it. The ID is represented by wxArtID type and can have one of these predefined values (you can see bitmaps represented by these constants in the artprov sample):

Additionally, any string recognized by custom art providers registered using Push may be used.

GTK+ Note

When running under GTK+ 2, GTK+ stock item IDs (e.g. "gtk-cdrom") may be used as well. Additionally, if wxGTK was compiled against GTK+ >= 2.4, then it is also possible to load icons from 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. Default theme is typically installed in /usr/share/icons/hicolor.


Clients

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:

Client ID servers 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. wx_ART_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!

See also

See the artprov sample for an example of wxArtProvider usage.

Derived from

wxObject

Include files

<wx/artprov.h>

Members


wxArtProvider::~wxArtProvider

~wxArtProvider()

The destructor automatically removes the provider from the provider stack used by GetBitmap.


wxArtProvider::CreateBitmap

wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size)

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).

Parameters

id

client

size

Note

This is not part of wxArtProvider's public API, use wxArtProvider::GetBitmap or wxArtProvider::GetIcon to query wxArtProvider for a resource.


wxArtProvider::Delete

static bool Delete(wxArtProvider* provider)

Delete the given provider.


wxArtProvider::GetBitmap

static wxBitmap GetBitmap(const wxArtID& id, const wxArtClient& client = wxART_OTHER, const wxSize& size = wxDefaultSize)

Query registered providers for bitmap with given ID.

Parameters

id

client

size

Return value

The bitmap if one of registered providers recognizes the ID or wxNullBitmap otherwise.


wxArtProvider::GetIcon

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 GetSizeHint(const wxArtClient& client, bool platform_default = false)

Returns a suitable size hint for the given wxArtClient. If platform_default is true, return a size based on the current platform, 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.


wxArtProvider::Insert

static void Insert(wxArtProvider* provider)

Register new art provider and add it to the bottom of providers stack (i.e. it will be queried as the last one).

See also

Push


wxArtProvider::Pop

static bool Pop()

Remove latest added provider and delete it.


wxArtProvider::Push

static void Push(wxArtProvider* provider)

Register new art provider and add it to the top of providers stack (i.e. it will be queried as the first provider).

See also

Insert


wxArtProvider::Remove

static bool Remove(wxArtProvider* provider)

Remove a provider from the stack if it is on it. The provider is not deleted, unlike when using Delete().