gallery.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: ribbon/gallery.h
  3. // Purpose: interface of wxRibbonGallery
  4. // Author: Peter Cawley
  5. // Licence: wxWindows licence
  6. ///////////////////////////////////////////////////////////////////////////////
  7. enum wxRibbonGalleryButtonState
  8. {
  9. wxRIBBON_GALLERY_BUTTON_NORMAL,
  10. wxRIBBON_GALLERY_BUTTON_HOVERED,
  11. wxRIBBON_GALLERY_BUTTON_ACTIVE,
  12. wxRIBBON_GALLERY_BUTTON_DISABLED,
  13. };
  14. /**
  15. @class wxRibbonGallery
  16. A ribbon gallery is like a wxListBox, but for bitmaps rather than strings.
  17. It displays a collection of bitmaps arranged in a grid and allows the user
  18. to choose one. As there are typically more bitmaps in a gallery than can
  19. be displayed in the space used for a ribbon, a gallery always has scroll
  20. buttons to allow the user to navigate through the entire gallery. It also
  21. has an "extension" button, the behaviour of which is outside the scope of
  22. the gallery control itself, though it typically displays some kind of
  23. dialog related to the gallery.
  24. @beginEventEmissionTable{wxRibbonGalleryEvent}
  25. @event{EVT_RIBBONGALLERY_SELECTED(id, func)}
  26. Triggered when the user selects an item from the gallery. Note that the
  27. ID is that of the gallery, not of the item.
  28. @event{EVT_RIBBONGALLERY_CLICKED(id, func)}
  29. Similar to EVT_RIBBONGALLERY_SELECTED but triggered every time a
  30. gallery item is clicked, even if it is already selected. Note that the
  31. ID of the event is that of the gallery, not of the item, just as above.
  32. This event is available since wxWidgets 2.9.2.
  33. @event{EVT_RIBBONGALLERY_HOVER_CHANGED(id, func)}
  34. Triggered when the item being hovered over by the user changes. The
  35. item in the event will be the new item being hovered, or NULL if there
  36. is no longer an item being hovered. Note that the ID is that of the
  37. gallery, not of the item.
  38. @endEventTable
  39. @beginEventEmissionTable{wxCommandEvent}
  40. @event{EVT_BUTTON(id, func)}
  41. Triggered when the "extension" button of the gallery is pressed.
  42. @endEventTable
  43. @library{wxribbon}
  44. @category{ribbon}
  45. */
  46. class wxRibbonGallery : public wxRibbonControl
  47. {
  48. public:
  49. /**
  50. Default constructor.
  51. With this constructor, Create() should be called in order to create
  52. the gallery.
  53. */
  54. wxRibbonGallery();
  55. /**
  56. Construct a ribbon gallery with the given parameters.
  57. @param parent
  58. Parent window for the gallery (typically a wxRibbonPanel).
  59. @param id
  60. An identifier for the gallery. @c wxID_ANY is taken to mean a default.
  61. @param pos
  62. Initial position of the gallery.
  63. @param size
  64. Initial size of the gallery.
  65. @param style
  66. Gallery style, currently unused.
  67. */
  68. wxRibbonGallery(wxWindow* parent,
  69. wxWindowID id = wxID_ANY,
  70. const wxPoint& pos = wxDefaultPosition,
  71. const wxSize& size = wxDefaultSize,
  72. long style = 0);
  73. /**
  74. Destructor.
  75. */
  76. virtual ~wxRibbonGallery();
  77. /**
  78. Create a gallery in two-step gallery construction.
  79. Should only be called when the default constructor is used, and
  80. arguments have the same meaning as in the full constructor.
  81. */
  82. bool Create(wxWindow* parent,
  83. wxWindowID id = wxID_ANY,
  84. const wxPoint& pos = wxDefaultPosition,
  85. const wxSize& size = wxDefaultSize,
  86. long style = 0);
  87. /**
  88. Remove all items from the gallery.
  89. */
  90. void Clear();
  91. /**
  92. Query if the gallery has no items in it.
  93. */
  94. bool IsEmpty() const;
  95. /**
  96. Get the number of items in the gallery.
  97. */
  98. unsigned int GetCount() const;
  99. /**
  100. Get an item by index.
  101. */
  102. wxRibbonGalleryItem* GetItem(unsigned int n);
  103. /**
  104. Add an item to the gallery (with no client data).
  105. @param bitmap
  106. The bitmap to display for the item. Note that all items must
  107. have equally sized bitmaps.
  108. @param id
  109. ID number to associate with the item. Not currently used for
  110. anything important.
  111. */
  112. wxRibbonGalleryItem* Append(const wxBitmap& bitmap, int id);
  113. /**
  114. Add an item to the gallery (with simple client data).
  115. @param bitmap
  116. The bitmap to display for the item. Note that all items must
  117. have equally sized bitmaps.
  118. @param id
  119. ID number to associate with the item. Not currently used for
  120. anything important.
  121. @param clientData
  122. An opaque pointer to associate with the item.
  123. */
  124. wxRibbonGalleryItem* Append(const wxBitmap& bitmap, int id, void* clientData);
  125. /**
  126. Add an item to the gallery (with complex client data)
  127. @param bitmap
  128. The bitmap to display for the item. Note that all items must
  129. have equally sized bitmaps.
  130. @param id
  131. ID number to associate with the item. Not currently used for
  132. anything important.
  133. @param clientData
  134. An object which contains data to associate with the item. The item
  135. takes ownership of this pointer, and will delete it when the item
  136. client data is changed to something else, or when the item is
  137. destroyed.
  138. */
  139. wxRibbonGalleryItem* Append(const wxBitmap& bitmap, int id, wxClientData* clientData);
  140. /**
  141. Set the client object associated with a gallery item.
  142. */
  143. void SetItemClientObject(wxRibbonGalleryItem* item, wxClientData* data);
  144. /**
  145. Get the client object associated with a gallery item.
  146. */
  147. wxClientData* GetItemClientObject(const wxRibbonGalleryItem* item) const;
  148. /**
  149. Set the client data associated with a gallery item.
  150. */
  151. void SetItemClientData(wxRibbonGalleryItem* item, void* data);
  152. /**
  153. Get the client data associated with a gallery item.
  154. */
  155. void* GetItemClientData(const wxRibbonGalleryItem* item) const;
  156. /**
  157. Set the selection to the given item, or removes the selection if
  158. @a item == NULL.
  159. Note that this not cause any events to be emitted.
  160. */
  161. void SetSelection(wxRibbonGalleryItem* item);
  162. /**
  163. Get the currently selected item, or NULL if there is none.
  164. The selected item is set by SetSelection(), or by the user clicking on
  165. an item.
  166. */
  167. wxRibbonGalleryItem* GetSelection() const;
  168. /**
  169. Get the currently hovered item, or NULL if there is none.
  170. The hovered item is the item underneath the mouse cursor.
  171. */
  172. wxRibbonGalleryItem* GetHoveredItem() const;
  173. /**
  174. Get the currently active item, or NULL if there is none.
  175. The active item is the item being pressed by the user, and will thus
  176. become the selected item if the user releases the mouse button.
  177. */
  178. wxRibbonGalleryItem* GetActiveItem() const;
  179. /**
  180. Get the state of the scroll up button.
  181. */
  182. wxRibbonGalleryButtonState GetUpButtonState() const;
  183. /**
  184. Get the state of the scroll down button.
  185. */
  186. wxRibbonGalleryButtonState GetDownButtonState() const;
  187. /**
  188. Get the state of the "extension" button.
  189. */
  190. wxRibbonGalleryButtonState GetExtensionButtonState() const;
  191. /**
  192. Query is the mouse is currently hovered over the gallery.
  193. @return @true if the cursor is within the bounds of the gallery (not
  194. just hovering over an item), @false otherwise.
  195. */
  196. bool IsHovered() const;
  197. /**
  198. Scroll the gallery contents by some amount.
  199. @param lines
  200. Positive values scroll toward the end of the gallery, while negative
  201. values scroll toward the start.
  202. @return @true if the gallery scrolled at least one pixel in the given
  203. direction, @false if it did not scroll.
  204. */
  205. virtual bool ScrollLines(int lines);
  206. /**
  207. Scroll the gallery contents by some fine-grained amount.
  208. @param pixels
  209. Positive values scroll toward the end of the gallery, while negative
  210. values scroll toward the start.
  211. @return @true if the gallery scrolled at least one pixel in the given
  212. direction, @false if it did not scroll.
  213. */
  214. bool ScrollPixels(int pixels);
  215. /**
  216. Scroll the gallery to ensure that the given item is visible.
  217. */
  218. void EnsureVisible(const wxRibbonGalleryItem* item);
  219. };
  220. /**
  221. @class wxRibbonGalleryEvent
  222. @library{wxribbon}
  223. @category{events,ribbon}
  224. @see wxRibbonBar
  225. */
  226. class wxRibbonGalleryEvent : public wxCommandEvent
  227. {
  228. public:
  229. /**
  230. Constructor.
  231. */
  232. wxRibbonGalleryEvent(wxEventType command_type = wxEVT_NULL,
  233. int win_id = 0,
  234. wxRibbonGallery* gallery = NULL,
  235. wxRibbonGalleryItem* item = NULL);
  236. /**
  237. Returns the gallery which the event relates to.
  238. */
  239. wxRibbonGallery* GetGallery();
  240. /**
  241. Returns the gallery item which the event relates to, or NULL if it does
  242. not relate to an item.
  243. */
  244. wxRibbonGalleryItem* GetGalleryItem();
  245. /**
  246. Sets the gallery relating to this event.
  247. */
  248. void SetGallery(wxRibbonGallery* gallery);
  249. /**
  250. Sets the gallery item relating to this event.
  251. */
  252. void SetGalleryItem(wxRibbonGalleryItem* item);
  253. };