imaglist.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: imaglist.h
  3. // Purpose: interface of wxImageList
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Flag values for Set/GetImageList
  9. */
  10. enum
  11. {
  12. wxIMAGE_LIST_NORMAL, // Normal icons
  13. wxIMAGE_LIST_SMALL, // Small icons
  14. wxIMAGE_LIST_STATE // State icons: unimplemented (see WIN32 documentation)
  15. };
  16. /**
  17. Flags for Draw
  18. */
  19. #define wxIMAGELIST_DRAW_NORMAL 0x0001
  20. #define wxIMAGELIST_DRAW_TRANSPARENT 0x0002
  21. #define wxIMAGELIST_DRAW_SELECTED 0x0004
  22. #define wxIMAGELIST_DRAW_FOCUSED 0x0008
  23. /**
  24. @class wxImageList
  25. A wxImageList contains a list of images, which are stored in an unspecified
  26. form. Images can have masks for transparent drawing, and can be made from a
  27. variety of sources including bitmaps and icons.
  28. wxImageList is used principally in conjunction with wxTreeCtrl and
  29. wxListCtrl classes.
  30. @library{wxcore}
  31. @category{gdi}
  32. @see wxTreeCtrl, wxListCtrl
  33. */
  34. class wxImageList : public wxObject
  35. {
  36. public:
  37. /**
  38. Default ctor.
  39. */
  40. wxImageList();
  41. /**
  42. Constructor specifying the image size, whether image masks should be created,
  43. and the initial size of the list.
  44. @param width
  45. Width of the images in the list.
  46. @param height
  47. Height of the images in the list.
  48. @param mask
  49. @true if masks should be created for all images.
  50. @param initialCount
  51. The initial size of the list.
  52. @see Create()
  53. */
  54. wxImageList(int width, int height, bool mask = true,
  55. int initialCount = 1);
  56. /**
  57. Adds a new image or images using a bitmap and optional mask bitmap.
  58. @param bitmap
  59. Bitmap representing the opaque areas of the image.
  60. @param mask
  61. Monochrome mask bitmap, representing the transparent areas of the image.
  62. @return The new zero-based image index.
  63. @remarks The original bitmap or icon is not affected by the Add()
  64. operation, and can be deleted afterwards.
  65. If the bitmap is wider than the images in the list, then the
  66. bitmap will automatically be split into smaller images, each
  67. matching the dimensions of the image list.
  68. This does not apply when adding icons.
  69. */
  70. int Add(const wxBitmap& bitmap,
  71. const wxBitmap& mask = wxNullBitmap);
  72. /**
  73. Adds a new image or images using a bitmap and mask colour.
  74. @param bitmap
  75. Bitmap representing the opaque areas of the image.
  76. @param maskColour
  77. Colour indicating which parts of the image are transparent.
  78. @return The new zero-based image index.
  79. @remarks The original bitmap or icon is not affected by the Add()
  80. operation, and can be deleted afterwards.
  81. If the bitmap is wider than the images in the list, then the
  82. bitmap will automatically be split into smaller images, each
  83. matching the dimensions of the image list.
  84. This does not apply when adding icons.
  85. */
  86. int Add(const wxBitmap& bitmap, const wxColour& maskColour);
  87. /**
  88. Adds a new image using an icon.
  89. @param icon
  90. Icon to use as the image.
  91. @return The new zero-based image index.
  92. @remarks The original bitmap or icon is not affected by the Add()
  93. operation, and can be deleted afterwards.
  94. If the bitmap is wider than the images in the list, then the
  95. bitmap will automatically be split into smaller images, each
  96. matching the dimensions of the image list.
  97. This does not apply when adding icons.
  98. @onlyfor{wxmsw,wxosx}
  99. */
  100. int Add(const wxIcon& icon);
  101. /**
  102. Initializes the list. See wxImageList() for details.
  103. */
  104. bool Create(int width, int height, bool mask = true,
  105. int initialCount = 1);
  106. /**
  107. Draws a specified image onto a device context.
  108. @param index
  109. Image index, starting from zero.
  110. @param dc
  111. Device context to draw on.
  112. @param x
  113. X position on the device context.
  114. @param y
  115. Y position on the device context.
  116. @param flags
  117. How to draw the image. A bitlist of a selection of the following:
  118. - wxIMAGELIST_DRAW_NORMAL: Draw the image normally.
  119. - wxIMAGELIST_DRAW_TRANSPARENT: Draw the image with transparency.
  120. - wxIMAGELIST_DRAW_SELECTED: Draw the image in selected state.
  121. - wxIMAGELIST_DRAW_FOCUSED: Draw the image in a focused state.
  122. @param solidBackground
  123. For optimisation - drawing can be faster if the function is told
  124. that the background is solid.
  125. */
  126. virtual bool Draw(int index, wxDC& dc, int x, int y,
  127. int flags = wxIMAGELIST_DRAW_NORMAL,
  128. bool solidBackground = false);
  129. /**
  130. Returns the bitmap corresponding to the given index.
  131. */
  132. wxBitmap GetBitmap(int index) const;
  133. /**
  134. Returns the icon corresponding to the given index.
  135. */
  136. wxIcon GetIcon(int index) const;
  137. /**
  138. Returns the number of images in the list.
  139. */
  140. virtual int GetImageCount() const;
  141. /**
  142. Retrieves the size of the images in the list. Currently, the @a index
  143. parameter is ignored as all images in the list have the same size.
  144. @param index
  145. currently unused, should be 0
  146. @param width
  147. receives the width of the images in the list
  148. @param height
  149. receives the height of the images in the list
  150. @return @true if the function succeeded, @false if it failed
  151. (for example, if the image list was not yet initialized).
  152. */
  153. virtual bool GetSize(int index, int& width, int& height) const;
  154. /**
  155. Removes the image at the given position.
  156. */
  157. bool Remove(int index);
  158. /**
  159. Removes all the images in the list.
  160. */
  161. bool RemoveAll();
  162. /**
  163. Replaces the existing image with the new image.
  164. Windows only.
  165. @param index
  166. The index of the bitmap to be replaced.
  167. @param bitmap
  168. Bitmap representing the opaque areas of the image.
  169. @param mask
  170. Monochrome mask bitmap, representing the transparent areas of the image.
  171. @return @true if the replacement was successful, @false otherwise.
  172. @remarks The original bitmap or icon is not affected by the Replace()
  173. operation, and can be deleted afterwards.
  174. */
  175. bool Replace(int index, const wxBitmap& bitmap,
  176. const wxBitmap& mask = wxNullBitmap);
  177. /**
  178. Replaces the existing image with the new image.
  179. @param index
  180. The index of the bitmap to be replaced.
  181. @param icon
  182. Icon to use as the image.
  183. @return @true if the replacement was successful, @false otherwise.
  184. @remarks The original bitmap or icon is not affected by the Replace()
  185. operation, and can be deleted afterwards.
  186. @onlyfor{wxmsw,wxosx}
  187. */
  188. bool Replace(int index, const wxIcon& icon);
  189. };