artprov.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/artprov.h
  3. // Purpose: wxArtProvider class
  4. // Author: Vaclav Slavik
  5. // Modified by:
  6. // Created: 18/03/2002
  7. // Copyright: (c) Vaclav Slavik
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_ARTPROV_H_
  11. #define _WX_ARTPROV_H_
  12. #include "wx/string.h"
  13. #include "wx/bitmap.h"
  14. #include "wx/icon.h"
  15. #include "wx/iconbndl.h"
  16. class WXDLLIMPEXP_FWD_CORE wxArtProvidersList;
  17. class WXDLLIMPEXP_FWD_CORE wxArtProviderCache;
  18. class wxArtProviderModule;
  19. // ----------------------------------------------------------------------------
  20. // Types
  21. // ----------------------------------------------------------------------------
  22. typedef wxString wxArtClient;
  23. typedef wxString wxArtID;
  24. #define wxART_MAKE_CLIENT_ID_FROM_STR(id) ((id) + "_C")
  25. #define wxART_MAKE_CLIENT_ID(id) (#id "_C")
  26. #define wxART_MAKE_ART_ID_FROM_STR(id) (id)
  27. #define wxART_MAKE_ART_ID(id) (#id)
  28. // ----------------------------------------------------------------------------
  29. // Art clients
  30. // ----------------------------------------------------------------------------
  31. #define wxART_TOOLBAR wxART_MAKE_CLIENT_ID(wxART_TOOLBAR)
  32. #define wxART_MENU wxART_MAKE_CLIENT_ID(wxART_MENU)
  33. #define wxART_FRAME_ICON wxART_MAKE_CLIENT_ID(wxART_FRAME_ICON)
  34. #define wxART_CMN_DIALOG wxART_MAKE_CLIENT_ID(wxART_CMN_DIALOG)
  35. #define wxART_HELP_BROWSER wxART_MAKE_CLIENT_ID(wxART_HELP_BROWSER)
  36. #define wxART_MESSAGE_BOX wxART_MAKE_CLIENT_ID(wxART_MESSAGE_BOX)
  37. #define wxART_BUTTON wxART_MAKE_CLIENT_ID(wxART_BUTTON)
  38. #define wxART_LIST wxART_MAKE_CLIENT_ID(wxART_LIST)
  39. #define wxART_OTHER wxART_MAKE_CLIENT_ID(wxART_OTHER)
  40. // ----------------------------------------------------------------------------
  41. // Art IDs
  42. // ----------------------------------------------------------------------------
  43. #define wxART_ADD_BOOKMARK wxART_MAKE_ART_ID(wxART_ADD_BOOKMARK)
  44. #define wxART_DEL_BOOKMARK wxART_MAKE_ART_ID(wxART_DEL_BOOKMARK)
  45. #define wxART_HELP_SIDE_PANEL wxART_MAKE_ART_ID(wxART_HELP_SIDE_PANEL)
  46. #define wxART_HELP_SETTINGS wxART_MAKE_ART_ID(wxART_HELP_SETTINGS)
  47. #define wxART_HELP_BOOK wxART_MAKE_ART_ID(wxART_HELP_BOOK)
  48. #define wxART_HELP_FOLDER wxART_MAKE_ART_ID(wxART_HELP_FOLDER)
  49. #define wxART_HELP_PAGE wxART_MAKE_ART_ID(wxART_HELP_PAGE)
  50. #define wxART_GO_BACK wxART_MAKE_ART_ID(wxART_GO_BACK)
  51. #define wxART_GO_FORWARD wxART_MAKE_ART_ID(wxART_GO_FORWARD)
  52. #define wxART_GO_UP wxART_MAKE_ART_ID(wxART_GO_UP)
  53. #define wxART_GO_DOWN wxART_MAKE_ART_ID(wxART_GO_DOWN)
  54. #define wxART_GO_TO_PARENT wxART_MAKE_ART_ID(wxART_GO_TO_PARENT)
  55. #define wxART_GO_HOME wxART_MAKE_ART_ID(wxART_GO_HOME)
  56. #define wxART_GOTO_FIRST wxART_MAKE_ART_ID(wxART_GOTO_FIRST)
  57. #define wxART_GOTO_LAST wxART_MAKE_ART_ID(wxART_GOTO_LAST)
  58. #define wxART_FILE_OPEN wxART_MAKE_ART_ID(wxART_FILE_OPEN)
  59. #define wxART_FILE_SAVE wxART_MAKE_ART_ID(wxART_FILE_SAVE)
  60. #define wxART_FILE_SAVE_AS wxART_MAKE_ART_ID(wxART_FILE_SAVE_AS)
  61. #define wxART_PRINT wxART_MAKE_ART_ID(wxART_PRINT)
  62. #define wxART_HELP wxART_MAKE_ART_ID(wxART_HELP)
  63. #define wxART_TIP wxART_MAKE_ART_ID(wxART_TIP)
  64. #define wxART_REPORT_VIEW wxART_MAKE_ART_ID(wxART_REPORT_VIEW)
  65. #define wxART_LIST_VIEW wxART_MAKE_ART_ID(wxART_LIST_VIEW)
  66. #define wxART_NEW_DIR wxART_MAKE_ART_ID(wxART_NEW_DIR)
  67. #define wxART_HARDDISK wxART_MAKE_ART_ID(wxART_HARDDISK)
  68. #define wxART_FLOPPY wxART_MAKE_ART_ID(wxART_FLOPPY)
  69. #define wxART_CDROM wxART_MAKE_ART_ID(wxART_CDROM)
  70. #define wxART_REMOVABLE wxART_MAKE_ART_ID(wxART_REMOVABLE)
  71. #define wxART_FOLDER wxART_MAKE_ART_ID(wxART_FOLDER)
  72. #define wxART_FOLDER_OPEN wxART_MAKE_ART_ID(wxART_FOLDER_OPEN)
  73. #define wxART_GO_DIR_UP wxART_MAKE_ART_ID(wxART_GO_DIR_UP)
  74. #define wxART_EXECUTABLE_FILE wxART_MAKE_ART_ID(wxART_EXECUTABLE_FILE)
  75. #define wxART_NORMAL_FILE wxART_MAKE_ART_ID(wxART_NORMAL_FILE)
  76. #define wxART_TICK_MARK wxART_MAKE_ART_ID(wxART_TICK_MARK)
  77. #define wxART_CROSS_MARK wxART_MAKE_ART_ID(wxART_CROSS_MARK)
  78. #define wxART_ERROR wxART_MAKE_ART_ID(wxART_ERROR)
  79. #define wxART_QUESTION wxART_MAKE_ART_ID(wxART_QUESTION)
  80. #define wxART_WARNING wxART_MAKE_ART_ID(wxART_WARNING)
  81. #define wxART_INFORMATION wxART_MAKE_ART_ID(wxART_INFORMATION)
  82. #define wxART_MISSING_IMAGE wxART_MAKE_ART_ID(wxART_MISSING_IMAGE)
  83. #define wxART_COPY wxART_MAKE_ART_ID(wxART_COPY)
  84. #define wxART_CUT wxART_MAKE_ART_ID(wxART_CUT)
  85. #define wxART_PASTE wxART_MAKE_ART_ID(wxART_PASTE)
  86. #define wxART_DELETE wxART_MAKE_ART_ID(wxART_DELETE)
  87. #define wxART_NEW wxART_MAKE_ART_ID(wxART_NEW)
  88. #define wxART_UNDO wxART_MAKE_ART_ID(wxART_UNDO)
  89. #define wxART_REDO wxART_MAKE_ART_ID(wxART_REDO)
  90. #define wxART_PLUS wxART_MAKE_ART_ID(wxART_PLUS)
  91. #define wxART_MINUS wxART_MAKE_ART_ID(wxART_MINUS)
  92. #define wxART_CLOSE wxART_MAKE_ART_ID(wxART_CLOSE)
  93. #define wxART_QUIT wxART_MAKE_ART_ID(wxART_QUIT)
  94. #define wxART_FIND wxART_MAKE_ART_ID(wxART_FIND)
  95. #define wxART_FIND_AND_REPLACE wxART_MAKE_ART_ID(wxART_FIND_AND_REPLACE)
  96. // ----------------------------------------------------------------------------
  97. // wxArtProvider class
  98. // ----------------------------------------------------------------------------
  99. class WXDLLIMPEXP_CORE wxArtProvider : public wxObject
  100. {
  101. public:
  102. // Dtor removes the provider from providers stack if it's still on it
  103. virtual ~wxArtProvider();
  104. // Does this platform implement native icons theme?
  105. static bool HasNativeProvider();
  106. // Add new provider to the top of providers stack (i.e. the provider will
  107. // be queried first of all).
  108. static void Push(wxArtProvider *provider);
  109. // Add new provider to the bottom of providers stack (i.e. the provider
  110. // will be queried as the last one).
  111. static void PushBack(wxArtProvider *provider);
  112. #if WXWIN_COMPATIBILITY_2_8
  113. // use PushBack(), it's the same thing
  114. static wxDEPRECATED( void Insert(wxArtProvider *provider) );
  115. #endif
  116. // Remove latest added provider and delete it.
  117. static bool Pop();
  118. // Remove provider from providers stack but don't delete it.
  119. static bool Remove(wxArtProvider *provider);
  120. // Delete the given provider and remove it from the providers stack.
  121. static bool Delete(wxArtProvider *provider);
  122. // Query the providers for bitmap with given ID and return it. Return
  123. // wxNullBitmap if no provider provides it.
  124. static wxBitmap GetBitmap(const wxArtID& id,
  125. const wxArtClient& client = wxART_OTHER,
  126. const wxSize& size = wxDefaultSize);
  127. // Query the providers for icon with given ID and return it. Return
  128. // wxNullIcon if no provider provides it.
  129. static wxIcon GetIcon(const wxArtID& id,
  130. const wxArtClient& client = wxART_OTHER,
  131. const wxSize& size = wxDefaultSize);
  132. // Helper used by GetMessageBoxIcon(): return the art id corresponding to
  133. // the standard wxICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one
  134. // can be set)
  135. static wxArtID GetMessageBoxIconId(int flags);
  136. // Helper used by several generic classes: return the icon corresponding to
  137. // the standard wxICON_INFORMATION/WARNING/ERROR/QUESTION flags (only one
  138. // can be set)
  139. static wxIcon GetMessageBoxIcon(int flags)
  140. {
  141. return GetIcon(GetMessageBoxIconId(flags), wxART_MESSAGE_BOX);
  142. }
  143. // Query the providers for iconbundle with given ID and return it. Return
  144. // wxNullIconBundle if no provider provides it.
  145. static wxIconBundle GetIconBundle(const wxArtID& id,
  146. const wxArtClient& client = wxART_OTHER);
  147. // Gets native size for given 'client' or wxDefaultSize if it doesn't
  148. // have native equivalent
  149. static wxSize GetNativeSizeHint(const wxArtClient& client);
  150. // Get the size hint of an icon from a specific wxArtClient, queries
  151. // the topmost provider if platform_dependent = false
  152. static wxSize GetSizeHint(const wxArtClient& client, bool platform_dependent = false);
  153. #if WXWIN_COMPATIBILITY_2_6
  154. // use the corresponding methods without redundant "Provider" suffix
  155. static wxDEPRECATED( void PushProvider(wxArtProvider *provider) );
  156. static wxDEPRECATED( void InsertProvider(wxArtProvider *provider) );
  157. static wxDEPRECATED( bool PopProvider() );
  158. // use Delete() if this is what you really need, or just delete the
  159. // provider pointer, do not use Remove() as it does not delete the pointer
  160. // unlike RemoveProvider() which does
  161. static wxDEPRECATED( bool RemoveProvider(wxArtProvider *provider) );
  162. #endif // WXWIN_COMPATIBILITY_2_6
  163. protected:
  164. friend class wxArtProviderModule;
  165. #if wxUSE_ARTPROVIDER_STD
  166. // Initializes default provider
  167. static void InitStdProvider();
  168. #endif // wxUSE_ARTPROVIDER_STD
  169. // Initializes Tango-based icon provider
  170. #if wxUSE_ARTPROVIDER_TANGO
  171. static void InitTangoProvider();
  172. #endif // wxUSE_ARTPROVIDER_TANGO
  173. // Initializes platform's native provider, if available (e.g. GTK2)
  174. static void InitNativeProvider();
  175. // Destroy caches & all providers
  176. static void CleanUpProviders();
  177. // Get the default size of an icon for a specific client
  178. virtual wxSize DoGetSizeHint(const wxArtClient& client)
  179. {
  180. return GetSizeHint(client, true);
  181. }
  182. // Derived classes must override CreateBitmap or CreateIconBundle
  183. // (or both) to create requested art resource. This method is called
  184. // only once per instance's lifetime for each requested wxArtID.
  185. virtual wxBitmap CreateBitmap(const wxArtID& WXUNUSED(id),
  186. const wxArtClient& WXUNUSED(client),
  187. const wxSize& WXUNUSED(size))
  188. {
  189. return wxNullBitmap;
  190. }
  191. virtual wxIconBundle CreateIconBundle(const wxArtID& WXUNUSED(id),
  192. const wxArtClient& WXUNUSED(client))
  193. {
  194. return wxNullIconBundle;
  195. }
  196. private:
  197. static void CommonAddingProvider();
  198. static wxIconBundle DoGetIconBundle(const wxArtID& id,
  199. const wxArtClient& client);
  200. private:
  201. // list of providers:
  202. static wxArtProvidersList *sm_providers;
  203. // art resources cache (so that CreateXXX is not called that often):
  204. static wxArtProviderCache *sm_cache;
  205. DECLARE_ABSTRACT_CLASS(wxArtProvider)
  206. };
  207. #if !defined(__WXUNIVERSAL__) && \
  208. ((defined(__WXGTK__) && defined(__WXGTK20__)) || defined(__WXMSW__) || \
  209. defined(__WXMAC__))
  210. // *some* (partial) native implementation of wxArtProvider exists; this is
  211. // not the same as wxArtProvider::HasNativeProvider()!
  212. #define wxHAS_NATIVE_ART_PROVIDER_IMPL
  213. #endif
  214. #endif // _WX_ARTPROV_H_