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