gallery.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/ribbon/gallery.h
  3. // Purpose: Ribbon control which displays a gallery of items to choose from
  4. // Author: Peter Cawley
  5. // Modified by:
  6. // Created: 2009-07-22
  7. // Copyright: (C) Peter Cawley
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_RIBBON_GALLERY_H_
  11. #define _WX_RIBBON_GALLERY_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_RIBBON
  14. #include "wx/ribbon/art.h"
  15. #include "wx/ribbon/control.h"
  16. class wxRibbonGalleryItem;
  17. WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxRibbonGalleryItem*, wxArrayRibbonGalleryItem, class WXDLLIMPEXP_RIBBON);
  18. class WXDLLIMPEXP_RIBBON wxRibbonGallery : public wxRibbonControl
  19. {
  20. public:
  21. wxRibbonGallery();
  22. wxRibbonGallery(wxWindow* parent,
  23. wxWindowID id = wxID_ANY,
  24. const wxPoint& pos = wxDefaultPosition,
  25. const wxSize& size = wxDefaultSize,
  26. long style = 0);
  27. virtual ~wxRibbonGallery();
  28. bool Create(wxWindow* parent,
  29. wxWindowID id = wxID_ANY,
  30. const wxPoint& pos = wxDefaultPosition,
  31. const wxSize& size = wxDefaultSize,
  32. long style = 0);
  33. void Clear();
  34. bool IsEmpty() const;
  35. unsigned int GetCount() const;
  36. wxRibbonGalleryItem* GetItem(unsigned int n);
  37. wxRibbonGalleryItem* Append(const wxBitmap& bitmap, int id);
  38. wxRibbonGalleryItem* Append(const wxBitmap& bitmap, int id, void* clientData);
  39. wxRibbonGalleryItem* Append(const wxBitmap& bitmap, int id, wxClientData* clientData);
  40. void SetItemClientObject(wxRibbonGalleryItem* item, wxClientData* data);
  41. wxClientData* GetItemClientObject(const wxRibbonGalleryItem* item) const;
  42. void SetItemClientData(wxRibbonGalleryItem* item, void* data);
  43. void* GetItemClientData(const wxRibbonGalleryItem* item) const;
  44. void SetSelection(wxRibbonGalleryItem* item);
  45. wxRibbonGalleryItem* GetSelection() const;
  46. wxRibbonGalleryItem* GetHoveredItem() const;
  47. wxRibbonGalleryItem* GetActiveItem() const;
  48. wxRibbonGalleryButtonState GetUpButtonState() const;
  49. wxRibbonGalleryButtonState GetDownButtonState() const;
  50. wxRibbonGalleryButtonState GetExtensionButtonState() const;
  51. bool IsHovered() const;
  52. virtual bool IsSizingContinuous() const;
  53. virtual bool Realize();
  54. virtual bool Layout();
  55. virtual bool ScrollLines(int lines);
  56. bool ScrollPixels(int pixels);
  57. void EnsureVisible(const wxRibbonGalleryItem* item);
  58. protected:
  59. wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
  60. void CommonInit(long style);
  61. void CalculateMinSize();
  62. bool TestButtonHover(const wxRect& rect, wxPoint pos,
  63. wxRibbonGalleryButtonState* state);
  64. void OnEraseBackground(wxEraseEvent& evt);
  65. void OnMouseEnter(wxMouseEvent& evt);
  66. void OnMouseMove(wxMouseEvent& evt);
  67. void OnMouseLeave(wxMouseEvent& evt);
  68. void OnMouseDown(wxMouseEvent& evt);
  69. void OnMouseUp(wxMouseEvent& evt);
  70. void OnMouseDClick(wxMouseEvent& evt);
  71. void OnPaint(wxPaintEvent& evt);
  72. void OnSize(wxSizeEvent& evt);
  73. int GetScrollLineSize() const;
  74. virtual wxSize DoGetBestSize() const;
  75. virtual wxSize DoGetNextSmallerSize(wxOrientation direction,
  76. wxSize relative_to) const;
  77. virtual wxSize DoGetNextLargerSize(wxOrientation direction,
  78. wxSize relative_to) const;
  79. wxArrayRibbonGalleryItem m_items;
  80. wxRibbonGalleryItem* m_selected_item;
  81. wxRibbonGalleryItem* m_hovered_item;
  82. wxRibbonGalleryItem* m_active_item;
  83. wxSize m_bitmap_size;
  84. wxSize m_bitmap_padded_size;
  85. wxSize m_best_size;
  86. wxRect m_client_rect;
  87. wxRect m_scroll_up_button_rect;
  88. wxRect m_scroll_down_button_rect;
  89. wxRect m_extension_button_rect;
  90. const wxRect* m_mouse_active_rect;
  91. int m_item_separation_x;
  92. int m_item_separation_y;
  93. int m_scroll_amount;
  94. int m_scroll_limit;
  95. wxRibbonGalleryButtonState m_up_button_state;
  96. wxRibbonGalleryButtonState m_down_button_state;
  97. wxRibbonGalleryButtonState m_extension_button_state;
  98. bool m_hovered;
  99. #ifndef SWIG
  100. DECLARE_CLASS(wxRibbonGallery)
  101. DECLARE_EVENT_TABLE()
  102. #endif
  103. };
  104. class WXDLLIMPEXP_RIBBON wxRibbonGalleryEvent : public wxCommandEvent
  105. {
  106. public:
  107. wxRibbonGalleryEvent(wxEventType command_type = wxEVT_NULL,
  108. int win_id = 0,
  109. wxRibbonGallery* gallery = NULL,
  110. wxRibbonGalleryItem* item = NULL)
  111. : wxCommandEvent(command_type, win_id)
  112. , m_gallery(gallery), m_item(item)
  113. {
  114. }
  115. #ifndef SWIG
  116. wxRibbonGalleryEvent(const wxRibbonGalleryEvent& e) : wxCommandEvent(e)
  117. {
  118. m_gallery = e.m_gallery;
  119. m_item = e.m_item;
  120. }
  121. #endif
  122. wxEvent *Clone() const { return new wxRibbonGalleryEvent(*this); }
  123. wxRibbonGallery* GetGallery() {return m_gallery;}
  124. wxRibbonGalleryItem* GetGalleryItem() {return m_item;}
  125. void SetGallery(wxRibbonGallery* gallery) {m_gallery = gallery;}
  126. void SetGalleryItem(wxRibbonGalleryItem* item) {m_item = item;}
  127. protected:
  128. wxRibbonGallery* m_gallery;
  129. wxRibbonGalleryItem* m_item;
  130. #ifndef SWIG
  131. private:
  132. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonGalleryEvent)
  133. #endif
  134. };
  135. #ifndef SWIG
  136. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_RIBBONGALLERY_HOVER_CHANGED, wxRibbonGalleryEvent);
  137. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_RIBBONGALLERY_SELECTED, wxRibbonGalleryEvent);
  138. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_RIBBONGALLERY_CLICKED, wxRibbonGalleryEvent);
  139. typedef void (wxEvtHandler::*wxRibbonGalleryEventFunction)(wxRibbonGalleryEvent&);
  140. #define wxRibbonGalleryEventHandler(func) \
  141. wxEVENT_HANDLER_CAST(wxRibbonGalleryEventFunction, func)
  142. #define EVT_RIBBONGALLERY_HOVER_CHANGED(winid, fn) \
  143. wx__DECLARE_EVT1(wxEVT_RIBBONGALLERY_HOVER_CHANGED, winid, wxRibbonGalleryEventHandler(fn))
  144. #define EVT_RIBBONGALLERY_SELECTED(winid, fn) \
  145. wx__DECLARE_EVT1(wxEVT_RIBBONGALLERY_SELECTED, winid, wxRibbonGalleryEventHandler(fn))
  146. #define EVT_RIBBONGALLERY_CLICKED(winid, fn) \
  147. wx__DECLARE_EVT1(wxEVT_RIBBONGALLERY_CLICKED, winid, wxRibbonGalleryEventHandler(fn))
  148. #else
  149. // wxpython/swig event work
  150. %constant wxEventType wxEVT_RIBBONGALLERY_HOVER_CHANGED;
  151. %constant wxEventType wxEVT_RIBBONGALLERY_SELECTED;
  152. %pythoncode {
  153. EVT_RIBBONGALLERY_HOVER_CHANGED = wx.PyEventBinder( wxEVT_RIBBONGALLERY_HOVER_CHANGED, 1 )
  154. EVT_RIBBONGALLERY_SELECTED = wx.PyEventBinder( wxEVT_RIBBONGALLERY_SELECTED, 1 )
  155. }
  156. #endif // SWIG
  157. // old wxEVT_COMMAND_* constants
  158. #define wxEVT_COMMAND_RIBBONGALLERY_HOVER_CHANGED wxEVT_RIBBONGALLERY_HOVER_CHANGED
  159. #define wxEVT_COMMAND_RIBBONGALLERY_SELECTED wxEVT_RIBBONGALLERY_SELECTED
  160. #define wxEVT_COMMAND_RIBBONGALLERY_CLICKED wxEVT_RIBBONGALLERY_CLICKED
  161. #endif // wxUSE_RIBBON
  162. #endif // _WX_RIBBON_GALLERY_H_