]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/artprov.h
Add a link to Microsoft guidelines from wxICON_QUESTION documentation.
[wxWidgets.git] / interface / wx / artprov.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: artprov.h
e54c96f1 3// Purpose: interface of wxArtProvider
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
878770b8
FM
9/**
10 This type identifies the client of the art objects requested to wxArtProvider.
11*/
adf8418e 12typedef class wxString wxArtClient;
878770b8
FM
13
14/**
15 This type identifies a specific art object which can be requested to wxArtProvider.
16*/
adf8418e 17typedef class wxString wxArtID;
878770b8
FM
18
19
23324ae1
FM
20/**
21 @class wxArtProvider
7c913512 22
23324ae1 23 wxArtProvider class is used to customize the look of wxWidgets application.
39fb8056 24
23324ae1
FM
25 When wxWidgets needs to display an icon or a bitmap (e.g. in the standard file
26 dialog), it does not use a hard-coded resource but asks wxArtProvider for it
27 instead. This way users can plug in their own wxArtProvider class and easily
39fb8056
FM
28 replace standard art with their own version.
29
30 All that is needed is to derive a class from wxArtProvider, override either its
cc6e1a74
FM
31 wxArtProvider::CreateBitmap() and/or its wxArtProvider::CreateIconBundle() methods
32 and register the provider with wxArtProvider::Push():
7c913512 33
23324ae1 34 @code
39fb8056 35 class MyProvider : public wxArtProvider
23324ae1
FM
36 {
37 protected:
7c913512 38 wxBitmap CreateBitmap(const wxArtID& id,
23324ae1
FM
39 const wxArtClient& client,
40 const wxSize size)
7c913512 41
23324ae1
FM
42 // optionally override this one as well
43 wxIconBundle CreateIconBundle(const wxArtID& id,
44 const wxArtClient& client)
45 { ... }
46 };
47 ...
48 wxArtProvider::Push(new MyProvider);
49 @endcode
7c913512 50
23324ae1 51 If you need bitmap images (of the same artwork) that should be displayed at
39fb8056 52 different sizes you should probably consider overriding wxArtProvider::CreateIconBundle
23324ae1 53 and supplying icon bundles that contain different bitmap sizes.
7c913512 54
23324ae1 55 There's another way of taking advantage of this class: you can use it in your
39fb8056
FM
56 code and use platform native icons as provided by wxArtProvider::GetBitmap or
57 wxArtProvider::GetIcon.
7c913512 58
3a74a290 59 @section artprovider_identify Identifying art resources
7c913512 60
23324ae1 61 Every bitmap and icon bundle are known to wxArtProvider under an unique ID that
4b37c1bf 62 is used when requesting a resource from it. The ID is represented by the ::wxArtID type
39fb8056 63 and can have one of these predefined values (you can see bitmaps represented by these
c0e97a5e 64 constants in the @ref page_samples_artprov):
7c913512 65
39fb8056
FM
66 <table>
67 <tr><td>
68 @li wxART_ERROR
69 @li wxART_QUESTION
70 @li wxART_WARNING
71 @li wxART_INFORMATION
72 @li wxART_ADD_BOOKMARK
73 @li wxART_DEL_BOOKMARK
74 @li wxART_HELP_SIDE_PANEL
75 @li wxART_HELP_SETTINGS
76 @li wxART_HELP_BOOK
77 @li wxART_HELP_FOLDER
78 @li wxART_HELP_PAGE
79 @li wxART_GO_BACK
80 @li wxART_GO_FORWARD
81 @li wxART_GO_UP
82 </td><td>
83 @li wxART_GO_DOWN
84 @li wxART_GO_TO_PARENT
85 @li wxART_GO_HOME
86 @li wxART_PRINT
87 @li wxART_HELP
88 @li wxART_TIP
89 @li wxART_REPORT_VIEW
90 @li wxART_LIST_VIEW
91 @li wxART_NEW_DIR
92 @li wxART_FOLDER
93 @li wxART_FOLDER_OPEN
94 @li wxART_GO_DIR_UP
95 @li wxART_EXECUTABLE_FILE
96 @li wxART_NORMAL_FILE
97 @li wxART_TICK_MARK
98 @li wxART_CROSS_MARK
99 </td><td>
100 @li wxART_MISSING_IMAGE
101 @li wxART_NEW
102 @li wxART_FILE_OPEN
103 @li wxART_FILE_SAVE
104 @li wxART_FILE_SAVE_AS
105 @li wxART_DELETE
106 @li wxART_COPY
107 @li wxART_CUT
108 @li wxART_PASTE
109 @li wxART_UNDO
110 @li wxART_REDO
b9727751 111 @li wxART_CLOSE
39fb8056
FM
112 @li wxART_QUIT
113 @li wxART_FIND
114 @li wxART_FIND_AND_REPLACE
115 @li wxART_HARDDISK
116 @li wxART_FLOPPY
117 @li wxART_CDROM
118 @li wxART_REMOVABLE
119 </td></tr>
120 </table>
7c913512
FM
121
122 Additionally, any string recognized by custom art providers registered using
23324ae1 123 wxArtProvider::Push may be used.
7c913512 124
39fb8056
FM
125 @note
126 When running under GTK+ 2, GTK+ stock item IDs (e.g. @c "gtk-cdrom") may be used
878770b8
FM
127 as well:
128 @code
4b37c1bf 129 #ifdef __WXGTK__
878770b8 130 wxBitmap bmp = wxArtProvider::GetBitmap("gtk-cdrom", wxART_MENU);
4b37c1bf 131 #endif
878770b8 132 @endcode
232fdc63
VZ
133 For a list of the GTK+ stock items please refer to the
134 <a href="http://library.gnome.org/devel/gtk/stable/gtk-Stock-Items.html">GTK+ documentation
135 page</a>.
4b37c1bf
FM
136 It is also possible to load icons from the current icon theme by specifying their name
137 (without extension and directory components).
232fdc63
VZ
138 Icon themes recognized by GTK+ follow the freedesktop.org
139 <a href="http://freedesktop.org/Standards/icon-theme-spec">Icon Themes specification</a>.
39fb8056
FM
140 Note that themes are not guaranteed to contain all icons, so wxArtProvider may
141 return ::wxNullBitmap or ::wxNullIcon.
142 The default theme is typically installed in @c /usr/share/icons/hicolor.
143
144
3a74a290 145 @section artprovider_clients Clients
39fb8056 146
878770b8 147 The @e client is the entity that calls wxArtProvider's GetBitmap() or GetIcon() function.
39fb8056
FM
148 It is represented by wxClientID type and can have one of these values:
149
3c4f71cc
VS
150 @li wxART_TOOLBAR
151 @li wxART_MENU
152 @li wxART_BUTTON
153 @li wxART_FRAME_ICON
154 @li wxART_CMN_DIALOG
155 @li wxART_HELP_BROWSER
156 @li wxART_MESSAGE_BOX
157 @li wxART_OTHER (used for all requests that don't fit into any of the
39fb8056
FM
158 categories above)
159
878770b8 160 Client ID serve as a hint to wxArtProvider that is supposed to help it to
39fb8056
FM
161 choose the best looking bitmap. For example it is often desirable to use
162 slightly different icons in menus and toolbars even though they represent
163 the same action (e.g. wxART_FILE_OPEN). Remember that this is really only a
164 hint for wxArtProvider -- it is common that wxArtProvider::GetBitmap returns
165 identical bitmap for different client values!
166
23324ae1 167 @library{wxcore}
3c99e2fd 168 @category{misc}
7c913512 169
c0e97a5e 170 @see the @ref page_samples_artprov for an example of wxArtProvider usage.
23324ae1
FM
171*/
172class wxArtProvider : public wxObject
173{
174public:
175 /**
176 The destructor automatically removes the provider from the provider stack used
177 by GetBitmap().
178 */
8d483c9b 179 virtual ~wxArtProvider();
23324ae1 180
23324ae1 181 /**
71f8a117 182 Delete the given @a provider.
23324ae1
FM
183 */
184 static bool Delete(wxArtProvider* provider);
185
186 /**
187 Query registered providers for bitmap with given ID.
3c4f71cc 188
7c913512 189 @param id
4cc4bfaf 190 wxArtID unique identifier of the bitmap.
7c913512 191 @param client
4cc4bfaf 192 wxArtClient identifier of the client (i.e. who is asking for the bitmap).
7c913512 193 @param size
4cc4bfaf 194 Size of the returned bitmap or wxDefaultSize if size doesn't matter.
3c4f71cc 195
d29a9a8a
BP
196 @return The bitmap if one of registered providers recognizes the ID or
197 wxNullBitmap otherwise.
23324ae1
FM
198 */
199 static wxBitmap GetBitmap(const wxArtID& id,
200 const wxArtClient& client = wxART_OTHER,
201 const wxSize& size = wxDefaultSize);
202
39fb8056
FM
203 /**
204 Same as wxArtProvider::GetBitmap, but return a wxIcon object
205 (or ::wxNullIcon on failure).
206 */
207 static wxIcon GetIcon(const wxArtID& id,
208 const wxArtClient& client = wxART_OTHER,
209 const wxSize& size = wxDefaultSize);
210
23324ae1 211 /**
a158acac
VS
212 Returns native icon size for use specified by @a client hint.
213
214 If the platform has no commonly used default for this use or if
215 @a client is not recognized, returns wxDefaultSize.
216
217 @note In some cases, a platform may have @em several appropriate
218 native sizes (for example, wxART_FRAME_ICON for frame icons).
219 In that case, this method returns only one of them, picked
220 reasonably.
221
222 @since 2.9.0
223 */
224 static wxSize GetNativeSizeHint(const wxArtClient& client);
225
226 /**
227 Returns a suitable size hint for the given @e wxArtClient.
228
229 If @a platform_default is @true, return a size based on the current
230 platform using GetNativeSizeHint(), otherwise return the size from the
231 topmost wxArtProvider. @e wxDefaultSize may be returned if the client
232 doesn't have a specified size, like wxART_OTHER for example.
233
234 @see GetNativeSizeHint()
23324ae1 235 */
7c913512 236 static wxSize GetSizeHint(const wxArtClient& client,
4cc4bfaf 237 bool platform_default = false);
23324ae1
FM
238
239 /**
240 Query registered providers for icon bundle with given ID.
3c4f71cc 241
7c913512 242 @param id
4cc4bfaf 243 wxArtID unique identifier of the icon bundle.
7c913512 244 @param client
4cc4bfaf 245 wxArtClient identifier of the client (i.e. who is asking for the icon
39fb8056 246 bundle).
3c4f71cc 247
d29a9a8a
BP
248 @return The icon bundle if one of registered providers recognizes the ID
249 or wxNullIconBundle otherwise.
23324ae1
FM
250 */
251 static wxIconBundle GetIconBundle(const wxArtID& id,
252 const wxArtClient& client = wxART_OTHER);
253
254 /**
14440cc6
VS
255 Returns true if the platform uses native icons provider that should
256 take precedence over any customizations.
3c4f71cc 257
14440cc6
VS
258 This is true for any platform that has user-customizable icon themes,
259 currently only wxGTK.
260
261 A typical use for this method is to decide whether a custom art provider
262 should be plugged in using Push() or PushBack().
263
264 @since 2.9.0
265 */
266 static bool HasNativeProvider();
267
268 /**
269 @deprecated Use PushBack() instead.
23324ae1
FM
270 */
271 static void Insert(wxArtProvider* provider);
272
273 /**
274 Remove latest added provider and delete it.
275 */
4cc4bfaf 276 static bool Pop();
23324ae1
FM
277
278 /**
39fb8056
FM
279 Register new art provider and add it to the top of providers stack
280 (i.e. it will be queried as the first provider).
3c4f71cc 281
14440cc6 282 @see PushBack()
23324ae1
FM
283 */
284 static void Push(wxArtProvider* provider);
285
14440cc6
VS
286 /**
287 Register new art provider and add it to the bottom of providers stack.
288 In other words, it will be queried as the last one, after all others,
289 including the default provider.
290
291 @see Push()
292
293 @since 2.9.0
294 */
295 static void PushBack(wxArtProvider* provider);
296
23324ae1 297 /**
7c913512 298 Remove a provider from the stack if it is on it. The provider is not
23324ae1
FM
299 deleted, unlike when using Delete().
300 */
301 static bool Remove(wxArtProvider* provider);
e4f1d811
FM
302
303protected:
304
305 /**
306 Derived art provider classes must override this method to create requested art
307 resource. Note that returned bitmaps are cached by wxArtProvider and it is
308 therefore not necessary to optimize CreateBitmap() for speed (e.g. you may
309 create wxBitmap objects from XPMs here).
310
311 @param id
312 wxArtID unique identifier of the bitmap.
313 @param client
314 wxArtClient identifier of the client (i.e. who is asking for the bitmap).
315 This only servers as a hint.
316 @param size
317 Preferred size of the bitmap. The function may return a bitmap of different
318 dimensions, it will be automatically rescaled to meet client's request.
319
320 @note
321 This is not part of wxArtProvider's public API, use wxArtProvider::GetBitmap
322 or wxArtProvider::GetIconBundle or wxArtProvider::GetIcon to query wxArtProvider
323 for a resource.
324
325 @see CreateIconBundle()
326 */
327 virtual wxBitmap CreateBitmap(const wxArtID& id,
328 const wxArtClient& client,
329 const wxSize& size);
330
331 /**
332 This method is similar to CreateBitmap() but can be used when a bitmap
333 (or an icon) exists in several sizes.
334 */
335 virtual wxIconBundle CreateIconBundle(const wxArtID& id,
336 const wxArtClient& client);
23324ae1 337};
e54c96f1 338