icon.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: icon.h
  3. // Purpose: interface of wxIcon
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. In wxIcon context this value means: "use the screen depth".
  9. */
  10. #define wxICON_SCREEN_DEPTH (-1)
  11. /**
  12. @class wxIcon
  13. An icon is a small rectangular bitmap usually used for denoting a minimized
  14. application.
  15. It differs from a wxBitmap in always having a mask associated with it for
  16. transparent drawing. On some platforms, icons and bitmaps are implemented
  17. identically, since there is no real distinction between a wxBitmap with a
  18. mask and an icon; and there is no specific icon format on some platforms
  19. (X-based applications usually standardize on XPMs for small bitmaps and icons).
  20. However, some platforms (such as Windows) make the distinction, so a
  21. separate class is provided.
  22. @remarks
  23. It is usually desirable to associate a pertinent icon with a frame.
  24. Icons can also be used for other purposes, for example with wxTreeCtrl and wxListCtrl.
  25. Icons have different formats on different platforms therefore separate icons
  26. will usually be created for the different environments.
  27. Platform-specific methods for creating a wxIcon structure are catered for,
  28. and this is an occasion where conditional compilation will probably be required.
  29. Note that a new icon must be created for every time the icon is to be used
  30. for a new window. In Windows, the icon will not be reloaded if it has already
  31. been used.
  32. An icon allocated to a frame will be deleted when the frame is deleted.
  33. For more information please see @ref overview_bitmap.
  34. @library{wxcore}
  35. @category{gdi}
  36. @stdobjects
  37. ::wxNullIcon
  38. @see @ref overview_bitmap, @ref overview_bitmap_supportedformats,
  39. wxDC::DrawIcon, wxCursor
  40. */
  41. class wxIcon : public wxGDIObject
  42. {
  43. public:
  44. /**
  45. Default ctor.
  46. Constructs an icon object with no data; an assignment or another member
  47. function such as LoadFile() must be called subsequently.
  48. */
  49. wxIcon();
  50. /**
  51. Copy ctor.
  52. */
  53. wxIcon(const wxIcon& icon);
  54. /*
  55. Creates an icon from the given data, which can be of arbitrary type.
  56. wxIcon(void* data, int type, int width, int height, int depth = -1);
  57. NOTE: this ctor is not implemented by all ports, is somewhat useless
  58. without further description of the "data" supported formats and
  59. uses 'int type' instead of wxBitmapType, so don't document it.
  60. */
  61. /**
  62. Creates an icon from an array of bits.
  63. You should only use this function for monochrome bitmaps (depth 1) in
  64. portable programs: in this case the bits parameter should contain an XBM image.
  65. For other bit depths, the behaviour is platform dependent: under Windows,
  66. the data is passed without any changes to the underlying CreateBitmap() API.
  67. Under other platforms, only monochrome bitmaps may be created using this
  68. constructor and wxImage should be used for creating colour bitmaps from
  69. static data.
  70. @param bits
  71. Specifies an array of pixel values.
  72. @param width
  73. The width of the image.
  74. @param height
  75. The height of the image.
  76. @beginWxPerlOnly
  77. In wxPerl use Wx::Icon->newBits(bits, width, height, depth = -1);
  78. @endWxPerlOnly
  79. @onlyfor{wxmsw,wxosx}
  80. */
  81. wxIcon(const char bits[], int width, int height);
  82. /**
  83. Creates a bitmap from XPM data.
  84. To use this constructor, you must first include an XPM file.
  85. For example, assuming that the file mybitmap.xpm contains an XPM array
  86. of character pointers called @e mybitmap:
  87. @code
  88. #include "mybitmap.xpm"
  89. ...
  90. wxIcon *icon = new wxIcon(mybitmap);
  91. @endcode
  92. A macro, wxICON, is available which creates an icon using an XPM on
  93. the appropriate platform, or an icon resource on Windows.
  94. @code
  95. wxIcon icon(wxICON(sample));
  96. // Equivalent to:
  97. #if defined(__WXGTK__) || defined(__WXMOTIF__)
  98. wxIcon icon(sample_xpm);
  99. #endif
  100. #if defined(__WXMSW__)
  101. wxIcon icon("sample");
  102. #endif
  103. @endcode
  104. @beginWxPerlOnly
  105. In wxPerl use Wx::Icon->newFromXPM(data).
  106. @endWxPerlOnly
  107. */
  108. wxIcon(const char* const* bits);
  109. /**
  110. Loads an icon from a file or resource.
  111. @param name
  112. This can refer to a resource name or a filename under MS Windows and X.
  113. Its meaning is determined by the @a type parameter.
  114. @param type
  115. May be one of the ::wxBitmapType values and indicates which type of
  116. bitmap should be loaded. See the note in the class detailed description.
  117. Note that the wxICON_DEFAULT_TYPE constant has different value under
  118. different wxWidgets ports. See the icon.h header for the value it takes
  119. for a specific port.
  120. @param desiredWidth
  121. Specifies the desired width of the icon. This parameter only has
  122. an effect in Windows where icon resources can contain several icons
  123. of different sizes.
  124. @param desiredHeight
  125. Specifies the desired height of the icon. This parameter only has
  126. an effect in Windows where icon resources can contain several icons
  127. of different sizes.
  128. @see LoadFile()
  129. */
  130. wxIcon(const wxString& name, wxBitmapType type = wxICON_DEFAULT_TYPE,
  131. int desiredWidth = -1, int desiredHeight = -1);
  132. /**
  133. Loads an icon from the specified location.
  134. */
  135. wxIcon(const wxIconLocation& loc);
  136. /**
  137. Destructor.
  138. See @ref overview_refcount_destruct for more info.
  139. If the application omits to delete the icon explicitly, the icon will be
  140. destroyed automatically by wxWidgets when the application exits.
  141. @warning
  142. Do not delete an icon that is selected into a memory device context.
  143. */
  144. virtual ~wxIcon();
  145. /**
  146. Attach a Windows icon handle.
  147. This wxMSW-specific method allows to assign a native Windows @c HICON
  148. (which must be castes to @c WXHICON opaque handle type) to wxIcon.
  149. Notice that this means that the @c HICON will be destroyed by wxIcon
  150. when it is destroyed.
  151. @return @true if successful.
  152. @onlyfor{wxmsw}
  153. @since 2.9.5
  154. */
  155. bool CreateFromHICON(WXHICON icon);
  156. /**
  157. Returns disabled (dimmed) version of the icon.
  158. This method is available in wxIcon only under wxMSW, other ports only
  159. have it in wxBitmap. You can always use wxImage::ConvertToDisabled()
  160. and create the icon from wxImage manually however.
  161. @onlyfor{wxmsw}
  162. @since 2.9.0
  163. */
  164. wxIcon ConvertToDisabled(unsigned char brightness = 255) const;
  165. /**
  166. Copies @a bmp bitmap to this icon.
  167. Under MS Windows the bitmap must have mask colour set.
  168. @see LoadFile()
  169. */
  170. void CopyFromBitmap(const wxBitmap& bmp);
  171. /**
  172. Gets the colour depth of the icon.
  173. A value of 1 indicates a monochrome icon.
  174. */
  175. int GetDepth() const;
  176. /**
  177. Gets the height of the icon in pixels.
  178. @see GetWidth()
  179. */
  180. int GetHeight() const;
  181. /**
  182. Gets the width of the icon in pixels.
  183. @see GetHeight()
  184. */
  185. int GetWidth() const;
  186. /**
  187. Returns @true if icon data is present.
  188. */
  189. virtual bool IsOk() const;
  190. /**
  191. Loads an icon from a file or resource.
  192. @param name
  193. Either a filename or a Windows resource name.
  194. The meaning of name is determined by the @a type parameter.
  195. @param type
  196. One of the ::wxBitmapType values; see the note in the class
  197. detailed description.
  198. Note that the wxICON_DEFAULT_TYPE constant has different value under
  199. different wxWidgets ports. See the icon.h header for the value it takes
  200. for a specific port.
  201. @param desiredWidth
  202. Specifies the desired width of the icon. This parameter only has
  203. an effect in Windows where icon resources can contain several icons
  204. of different sizes.
  205. @param desiredHeight
  206. Specifies the desired height of the icon. This parameter only has
  207. an effect in Windows where icon resources can contain several icons
  208. of different sizes.
  209. @return @true if the operation succeeded, @false otherwise.
  210. */
  211. bool LoadFile(const wxString& name, wxBitmapType type = wxICON_DEFAULT_TYPE,
  212. int desiredWidth = -1, int desiredHeight = -1);
  213. /**
  214. Sets the depth member (does not affect the icon data).
  215. @param depth
  216. Icon depth.
  217. */
  218. void SetDepth(int depth);
  219. /**
  220. Sets the height member (does not affect the icon data).
  221. @param height
  222. Icon height in pixels.
  223. */
  224. void SetHeight(int height);
  225. /**
  226. Sets the width member (does not affect the icon data).
  227. @param width
  228. Icon width in pixels.
  229. */
  230. void SetWidth(int width);
  231. /**
  232. Assignment operator, using @ref overview_refcount.
  233. @param icon
  234. Icon to assign.
  235. */
  236. wxIcon& operator=(const wxIcon& icon);
  237. };
  238. /**
  239. An empty wxIcon.
  240. */
  241. wxIcon wxNullIcon;