buttonbar.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/ribbon/buttonbar.h
  3. // Purpose: Ribbon control similar to a tool bar
  4. // Author: Peter Cawley
  5. // Modified by:
  6. // Created: 2009-07-01
  7. // Copyright: (C) Peter Cawley
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_RIBBON_BUTTON_BAR_H_
  11. #define _WX_RIBBON_BUTTON_BAR_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_RIBBON
  14. #include "wx/ribbon/art.h"
  15. #include "wx/ribbon/control.h"
  16. #include "wx/dynarray.h"
  17. class wxRibbonButtonBarButtonBase;
  18. class wxRibbonButtonBarLayout;
  19. class wxRibbonButtonBarButtonInstance;
  20. WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxRibbonButtonBarLayout*, wxArrayRibbonButtonBarLayout, class WXDLLIMPEXP_RIBBON);
  21. WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxRibbonButtonBarButtonBase*, wxArrayRibbonButtonBarButtonBase, class WXDLLIMPEXP_RIBBON);
  22. class WXDLLIMPEXP_RIBBON wxRibbonButtonBar : public wxRibbonControl
  23. {
  24. public:
  25. wxRibbonButtonBar();
  26. wxRibbonButtonBar(wxWindow* parent,
  27. wxWindowID id = wxID_ANY,
  28. const wxPoint& pos = wxDefaultPosition,
  29. const wxSize& size = wxDefaultSize,
  30. long style = 0);
  31. virtual ~wxRibbonButtonBar();
  32. bool Create(wxWindow* parent,
  33. wxWindowID id = wxID_ANY,
  34. const wxPoint& pos = wxDefaultPosition,
  35. const wxSize& size = wxDefaultSize,
  36. long style = 0);
  37. virtual wxRibbonButtonBarButtonBase* AddButton(
  38. int button_id,
  39. const wxString& label,
  40. const wxBitmap& bitmap,
  41. const wxString& help_string,
  42. wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL);
  43. // NB: help_string cannot be optional as that would cause the signature
  44. // to be identical to the full version of AddButton when 3 arguments are
  45. // given.
  46. virtual wxRibbonButtonBarButtonBase* AddDropdownButton(
  47. int button_id,
  48. const wxString& label,
  49. const wxBitmap& bitmap,
  50. const wxString& help_string = wxEmptyString);
  51. virtual wxRibbonButtonBarButtonBase* AddHybridButton(
  52. int button_id,
  53. const wxString& label,
  54. const wxBitmap& bitmap,
  55. const wxString& help_string = wxEmptyString);
  56. virtual wxRibbonButtonBarButtonBase* AddToggleButton(
  57. int button_id,
  58. const wxString& label,
  59. const wxBitmap& bitmap,
  60. const wxString& help_string = wxEmptyString);
  61. virtual wxRibbonButtonBarButtonBase* AddButton(
  62. int button_id,
  63. const wxString& label,
  64. const wxBitmap& bitmap,
  65. const wxBitmap& bitmap_small = wxNullBitmap,
  66. const wxBitmap& bitmap_disabled = wxNullBitmap,
  67. const wxBitmap& bitmap_small_disabled = wxNullBitmap,
  68. wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL,
  69. const wxString& help_string = wxEmptyString);
  70. virtual wxRibbonButtonBarButtonBase* InsertButton(
  71. size_t pos,
  72. int button_id,
  73. const wxString& label,
  74. const wxBitmap& bitmap,
  75. const wxString& help_string,
  76. wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL);
  77. virtual wxRibbonButtonBarButtonBase* InsertDropdownButton(
  78. size_t pos,
  79. int button_id,
  80. const wxString& label,
  81. const wxBitmap& bitmap,
  82. const wxString& help_string = wxEmptyString);
  83. virtual wxRibbonButtonBarButtonBase* InsertHybridButton(
  84. size_t pos,
  85. int button_id,
  86. const wxString& label,
  87. const wxBitmap& bitmap,
  88. const wxString& help_string = wxEmptyString);
  89. virtual wxRibbonButtonBarButtonBase* InsertToggleButton(
  90. size_t pos,
  91. int button_id,
  92. const wxString& label,
  93. const wxBitmap& bitmap,
  94. const wxString& help_string = wxEmptyString);
  95. virtual wxRibbonButtonBarButtonBase* InsertButton(
  96. size_t pos,
  97. int button_id,
  98. const wxString& label,
  99. const wxBitmap& bitmap,
  100. const wxBitmap& bitmap_small = wxNullBitmap,
  101. const wxBitmap& bitmap_disabled = wxNullBitmap,
  102. const wxBitmap& bitmap_small_disabled = wxNullBitmap,
  103. wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL,
  104. const wxString& help_string = wxEmptyString);
  105. void SetItemClientObject(wxRibbonButtonBarButtonBase* item, wxClientData* data);
  106. wxClientData* GetItemClientObject(const wxRibbonButtonBarButtonBase* item) const;
  107. void SetItemClientData(wxRibbonButtonBarButtonBase* item, void* data);
  108. void* GetItemClientData(const wxRibbonButtonBarButtonBase* item) const;
  109. virtual size_t GetButtonCount() const;
  110. virtual wxRibbonButtonBarButtonBase *GetItem(size_t n) const;
  111. virtual wxRibbonButtonBarButtonBase *GetItemById(int id) const;
  112. virtual int GetItemId(wxRibbonButtonBarButtonBase *button) const;
  113. virtual bool Realize();
  114. virtual void ClearButtons();
  115. virtual bool DeleteButton(int button_id);
  116. virtual void EnableButton(int button_id, bool enable = true);
  117. virtual void ToggleButton(int button_id, bool checked);
  118. virtual wxRibbonButtonBarButtonBase *GetActiveItem() const;
  119. virtual wxRibbonButtonBarButtonBase *GetHoveredItem() const;
  120. virtual void SetArtProvider(wxRibbonArtProvider* art);
  121. virtual bool IsSizingContinuous() const;
  122. virtual wxSize GetMinSize() const;
  123. void SetShowToolTipsForDisabled(bool show);
  124. bool GetShowToolTipsForDisabled() const;
  125. protected:
  126. friend class wxRibbonButtonBarEvent;
  127. virtual wxSize DoGetBestSize() const;
  128. wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
  129. void OnEraseBackground(wxEraseEvent& evt);
  130. void OnPaint(wxPaintEvent& evt);
  131. void OnSize(wxSizeEvent& evt);
  132. void OnMouseMove(wxMouseEvent& evt);
  133. void OnMouseEnter(wxMouseEvent& evt);
  134. void OnMouseLeave(wxMouseEvent& evt);
  135. void OnMouseDown(wxMouseEvent& evt);
  136. void OnMouseUp(wxMouseEvent& evt);
  137. virtual wxSize DoGetNextSmallerSize(wxOrientation direction,
  138. wxSize relative_to) const;
  139. virtual wxSize DoGetNextLargerSize(wxOrientation direction,
  140. wxSize relative_to) const;
  141. void CommonInit(long style);
  142. void MakeLayouts();
  143. bool TryCollapseLayout(wxRibbonButtonBarLayout* original, size_t first_btn, size_t* last_button);
  144. static wxBitmap MakeResizedBitmap(const wxBitmap& original, wxSize size);
  145. static wxBitmap MakeDisabledBitmap(const wxBitmap& original);
  146. void FetchButtonSizeInfo(wxRibbonButtonBarButtonBase* button,
  147. wxRibbonButtonBarButtonState size, wxDC& dc);
  148. virtual void UpdateWindowUI(long flags);
  149. wxArrayRibbonButtonBarLayout m_layouts;
  150. wxArrayRibbonButtonBarButtonBase m_buttons;
  151. wxRibbonButtonBarButtonInstance* m_hovered_button;
  152. wxRibbonButtonBarButtonInstance* m_active_button;
  153. wxPoint m_layout_offset;
  154. wxSize m_bitmap_size_large;
  155. wxSize m_bitmap_size_small;
  156. int m_current_layout;
  157. bool m_layouts_valid;
  158. bool m_lock_active_state;
  159. bool m_show_tooltips_for_disabled;
  160. #ifndef SWIG
  161. DECLARE_CLASS(wxRibbonButtonBar)
  162. DECLARE_EVENT_TABLE()
  163. #endif
  164. };
  165. class WXDLLIMPEXP_RIBBON wxRibbonButtonBarEvent : public wxCommandEvent
  166. {
  167. public:
  168. wxRibbonButtonBarEvent(wxEventType command_type = wxEVT_NULL,
  169. int win_id = 0,
  170. wxRibbonButtonBar* bar = NULL,
  171. wxRibbonButtonBarButtonBase* button = NULL)
  172. : wxCommandEvent(command_type, win_id)
  173. , m_bar(bar), m_button(button)
  174. {
  175. }
  176. #ifndef SWIG
  177. wxRibbonButtonBarEvent(const wxRibbonButtonBarEvent& e) : wxCommandEvent(e)
  178. {
  179. m_bar = e.m_bar;
  180. m_button = e.m_button;
  181. }
  182. #endif
  183. wxEvent *Clone() const { return new wxRibbonButtonBarEvent(*this); }
  184. wxRibbonButtonBar* GetBar() {return m_bar;}
  185. wxRibbonButtonBarButtonBase *GetButton() { return m_button; }
  186. void SetBar(wxRibbonButtonBar* bar) {m_bar = bar;}
  187. void SetButton(wxRibbonButtonBarButtonBase* button) { m_button = button; }
  188. bool PopupMenu(wxMenu* menu);
  189. protected:
  190. wxRibbonButtonBar* m_bar;
  191. wxRibbonButtonBarButtonBase *m_button;
  192. #ifndef SWIG
  193. private:
  194. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonButtonBarEvent)
  195. #endif
  196. };
  197. #ifndef SWIG
  198. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_RIBBONBUTTONBAR_CLICKED, wxRibbonButtonBarEvent);
  199. wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED, wxRibbonButtonBarEvent);
  200. typedef void (wxEvtHandler::*wxRibbonButtonBarEventFunction)(wxRibbonButtonBarEvent&);
  201. #define wxRibbonButtonBarEventHandler(func) \
  202. wxEVENT_HANDLER_CAST(wxRibbonButtonBarEventFunction, func)
  203. #define EVT_RIBBONBUTTONBAR_CLICKED(winid, fn) \
  204. wx__DECLARE_EVT1(wxEVT_RIBBONBUTTONBAR_CLICKED, winid, wxRibbonButtonBarEventHandler(fn))
  205. #define EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(winid, fn) \
  206. wx__DECLARE_EVT1(wxEVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED, winid, wxRibbonButtonBarEventHandler(fn))
  207. #else
  208. // wxpython/swig event work
  209. %constant wxEventType wxEVT_RIBBONBUTTONBAR_CLICKED;
  210. %constant wxEventType wxEVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED;
  211. %pythoncode {
  212. EVT_RIBBONBUTTONBAR_CLICKED = wx.PyEventBinder( wxEVT_RIBBONBUTTONBAR_CLICKED, 1 )
  213. EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED = wx.PyEventBinder( wxEVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED, 1 )
  214. }
  215. #endif
  216. // old wxEVT_COMMAND_* constants
  217. #define wxEVT_COMMAND_RIBBONBUTTON_CLICKED wxEVT_RIBBONBUTTONBAR_CLICKED
  218. #define wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED wxEVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED
  219. #endif // wxUSE_RIBBON
  220. #endif // _WX_RIBBON_BUTTON_BAR_H_