]>
git.saurik.com Git - wxWidgets.git/blob - interface/artprov.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxArtProvider
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 wxArtProvider class is used to customize the look of wxWidgets application.
15 When wxWidgets needs to display an icon or a bitmap (e.g. in the standard file
16 dialog), it does not use a hard-coded resource but asks wxArtProvider for it
17 instead. This way users can plug in their own wxArtProvider class and easily
18 replace standard art with their own version.
20 All that is needed is to derive a class from wxArtProvider, override either its
21 wxArtProvider::CreateBitmap and/or its wxArtProvider::CreateIconBundle methods
22 and register the provider with wxArtProvider::Push:
25 class MyProvider : public wxArtProvider
28 wxBitmap CreateBitmap(const wxArtID& id,
29 const wxArtClient& client,
32 // optionally override this one as well
33 wxIconBundle CreateIconBundle(const wxArtID& id,
34 const wxArtClient& client)
38 wxArtProvider::Push(new MyProvider);
41 If you need bitmap images (of the same artwork) that should be displayed at
42 different sizes you should probably consider overriding wxArtProvider::CreateIconBundle
43 and supplying icon bundles that contain different bitmap sizes.
45 There's another way of taking advantage of this class: you can use it in your
46 code and use platform native icons as provided by wxArtProvider::GetBitmap or
47 wxArtProvider::GetIcon.
49 @todo IS THIS NB TRUE?
50 (NB: this is not yet really possible as of wxWidgets 2.3.3, the set of wxArtProvider
51 bitmaps is too small).
53 @section wxartprovider_identify Identifying art resources
55 Every bitmap and icon bundle are known to wxArtProvider under an unique ID that
56 is used when requesting a resource from it. The ID is represented by wxArtID type
57 and can have one of these predefined values (you can see bitmaps represented by these
58 constants in the @ref page_utils_samples_artprovider):
66 @li wxART_ADD_BOOKMARK
67 @li wxART_DEL_BOOKMARK
68 @li wxART_HELP_SIDE_PANEL
69 @li wxART_HELP_SETTINGS
78 @li wxART_GO_TO_PARENT
89 @li wxART_EXECUTABLE_FILE
94 @li wxART_MISSING_IMAGE
98 @li wxART_FILE_SAVE_AS
107 @li wxART_FIND_AND_REPLACE
115 Additionally, any string recognized by custom art providers registered using
116 wxArtProvider::Push may be used.
119 When running under GTK+ 2, GTK+ stock item IDs (e.g. @c "gtk-cdrom") may be used
120 as well. Additionally, if wxGTK was compiled against GTK+ >= 2.4, then it is also
121 possible to load icons from current icon theme by specifying their name (without
122 extension and directory components).
123 Icon themes recognized by GTK+ follow the freedesktop.org Icon Themes specification
124 (see http://freedesktop.org/Standards/icon-theme-spec).
125 Note that themes are not guaranteed to contain all icons, so wxArtProvider may
126 return ::wxNullBitmap or ::wxNullIcon.
127 The default theme is typically installed in @c /usr/share/icons/hicolor.
130 @section wxartprovider_clients Clients
132 Client is the entity that calls wxArtProvider's GetBitmap or GetIcon function.
133 It is represented by wxClientID type and can have one of these values:
140 @li wxART_HELP_BROWSER
141 @li wxART_MESSAGE_BOX
142 @li wxART_OTHER (used for all requests that don't fit into any of the
145 Client ID servers as a hint to wxArtProvider that is supposed to help it to
146 choose the best looking bitmap. For example it is often desirable to use
147 slightly different icons in menus and toolbars even though they represent
148 the same action (e.g. wxART_FILE_OPEN). Remember that this is really only a
149 hint for wxArtProvider -- it is common that wxArtProvider::GetBitmap returns
150 identical bitmap for different client values!
155 @see the @ref page_utils_samples_artprovider for an example of wxArtProvider usage.
157 class wxArtProvider
: public wxObject
161 The destructor automatically removes the provider from the provider stack used
167 Derived art provider classes must override this method to create requested art
168 resource. Note that returned bitmaps are cached by wxArtProvider and it is
169 therefore not necessary to optimize CreateBitmap() for speed (e.g. you may
170 create wxBitmap objects from XPMs here).
173 wxArtID unique identifier of the bitmap.
175 wxArtClient identifier of the client (i.e. who is asking for the bitmap).
176 This only servers as a hint.
178 Preferred size of the bitmap. The function may return a bitmap of different
179 dimensions, it will be automatically rescaled to meet client's request.
182 This is not part of wxArtProvider's public API, use wxArtProvider::GetBitmap
183 or wxArtProvider::GetIconBundle or wxArtProvider::GetIcon to query wxArtProvider
186 @see CreateIconBundle()
188 wxBitmap
CreateBitmap(const wxArtID
& id
,
189 const wxArtClient
& client
,
193 This method is similar to CreateBitmap() but can be used when a bitmap
194 (or an icon) exists in several sizes.
196 wxIconBundle
CreateIconBundle(const wxArtID
& id
,
197 const wxArtClient
& client
);
200 Delete the given @e provider.
202 static bool Delete(wxArtProvider
* provider
);
205 Query registered providers for bitmap with given ID.
208 wxArtID unique identifier of the bitmap.
210 wxArtClient identifier of the client (i.e. who is asking for the bitmap).
212 Size of the returned bitmap or wxDefaultSize if size doesn't matter.
214 @returns The bitmap if one of registered providers recognizes the ID or
215 wxNullBitmap otherwise.
217 static wxBitmap
GetBitmap(const wxArtID
& id
,
218 const wxArtClient
& client
= wxART_OTHER
,
219 const wxSize
& size
= wxDefaultSize
);
222 Same as wxArtProvider::GetBitmap, but return a wxIcon object
223 (or ::wxNullIcon on failure).
225 static wxIcon
GetIcon(const wxArtID
& id
,
226 const wxArtClient
& client
= wxART_OTHER
,
227 const wxSize
& size
= wxDefaultSize
);
230 Returns a suitable size hint for the given @e wxArtClient. If
231 @a platform_default is @true, return a size based on the current platform,
232 otherwise return the size from the topmost wxArtProvider. @e wxDefaultSize may
233 be returned if the client doesn't have a specified size, like wxART_OTHER for
236 static wxSize
GetSizeHint(const wxArtClient
& client
,
237 bool platform_default
= false);
240 Query registered providers for icon bundle with given ID.
243 wxArtID unique identifier of the icon bundle.
245 wxArtClient identifier of the client (i.e. who is asking for the icon
248 @returns The icon bundle if one of registered providers recognizes the ID
249 or wxNullIconBundle otherwise.
251 static wxIconBundle
GetIconBundle(const wxArtID
& id
,
252 const wxArtClient
& client
= wxART_OTHER
);
255 Register new art provider and add it to the bottom of providers stack
256 (i.e. it will be queried as the last one).
260 static void Insert(wxArtProvider
* provider
);
263 Remove latest added provider and delete it.
268 Register new art provider and add it to the top of providers stack
269 (i.e. it will be queried as the first provider).
273 static void Push(wxArtProvider
* provider
);
276 Remove a provider from the stack if it is on it. The provider is not
277 deleted, unlike when using Delete().
279 static bool Remove(wxArtProvider
* provider
);