artprov.h 14 KB

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