PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/sources/plug_wx/interface/wx/artprov.h

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