]>
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 (@note 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_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_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
164 virtual ~wxArtProvider();
167 Delete the given @a provider.
169 static bool Delete(wxArtProvider
* provider
);
172 Query registered providers for bitmap with given ID.
175 wxArtID unique identifier of the bitmap.
177 wxArtClient identifier of the client (i.e. who is asking for the bitmap).
179 Size of the returned bitmap or wxDefaultSize if size doesn't matter.
181 @return The bitmap if one of registered providers recognizes the ID or
182 wxNullBitmap otherwise.
184 static wxBitmap
GetBitmap(const wxArtID
& id
,
185 const wxArtClient
& client
= wxART_OTHER
,
186 const wxSize
& size
= wxDefaultSize
);
189 Same as wxArtProvider::GetBitmap, but return a wxIcon object
190 (or ::wxNullIcon on failure).
192 static wxIcon
GetIcon(const wxArtID
& id
,
193 const wxArtClient
& client
= wxART_OTHER
,
194 const wxSize
& size
= wxDefaultSize
);
197 Returns a suitable size hint for the given @e wxArtClient. If
198 @a platform_default is @true, return a size based on the current platform,
199 otherwise return the size from the topmost wxArtProvider. @e wxDefaultSize may
200 be returned if the client doesn't have a specified size, like wxART_OTHER for
203 static wxSize
GetSizeHint(const wxArtClient
& client
,
204 bool platform_default
= false);
207 Query registered providers for icon bundle with given ID.
210 wxArtID unique identifier of the icon bundle.
212 wxArtClient identifier of the client (i.e. who is asking for the icon
215 @return The icon bundle if one of registered providers recognizes the ID
216 or wxNullIconBundle otherwise.
218 static wxIconBundle
GetIconBundle(const wxArtID
& id
,
219 const wxArtClient
& client
= wxART_OTHER
);
222 Register new art provider and add it to the bottom of providers stack
223 (i.e. it will be queried as the last one).
227 static void Insert(wxArtProvider
* provider
);
230 Remove latest added provider and delete it.
235 Register new art provider and add it to the top of providers stack
236 (i.e. it will be queried as the first provider).
240 static void Push(wxArtProvider
* provider
);
243 Remove a provider from the stack if it is on it. The provider is not
244 deleted, unlike when using Delete().
246 static bool Remove(wxArtProvider
* provider
);
251 Derived art provider classes must override this method to create requested art
252 resource. Note that returned bitmaps are cached by wxArtProvider and it is
253 therefore not necessary to optimize CreateBitmap() for speed (e.g. you may
254 create wxBitmap objects from XPMs here).
257 wxArtID unique identifier of the bitmap.
259 wxArtClient identifier of the client (i.e. who is asking for the bitmap).
260 This only servers as a hint.
262 Preferred size of the bitmap. The function may return a bitmap of different
263 dimensions, it will be automatically rescaled to meet client's request.
266 This is not part of wxArtProvider's public API, use wxArtProvider::GetBitmap
267 or wxArtProvider::GetIconBundle or wxArtProvider::GetIcon to query wxArtProvider
270 @see CreateIconBundle()
272 virtual wxBitmap
CreateBitmap(const wxArtID
& id
,
273 const wxArtClient
& client
,
277 This method is similar to CreateBitmap() but can be used when a bitmap
278 (or an icon) exists in several sizes.
280 virtual wxIconBundle
CreateIconBundle(const wxArtID
& id
,
281 const wxArtClient
& client
);