Add wxRibbonButtonBar::GetItem(), GetItemById() and GetItemId().
[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 wxObject* client_data = NULL);
86
87 virtual wxRibbonButtonBarButtonBase* InsertButton(
88 size_t pos,
89 int button_id,
90 const wxString& label,
91 const wxBitmap& bitmap,
92 const wxString& help_string,
93 wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL);
94
95 virtual wxRibbonButtonBarButtonBase* InsertDropdownButton(
96 size_t pos,
97 int button_id,
98 const wxString& label,
99 const wxBitmap& bitmap,
100 const wxString& help_string = wxEmptyString);
101
102 virtual wxRibbonButtonBarButtonBase* InsertHybridButton(
103 size_t pos,
104 int button_id,
105 const wxString& label,
106 const wxBitmap& bitmap,
107 const wxString& help_string = wxEmptyString);
108
109 virtual wxRibbonButtonBarButtonBase* InsertToggleButton(
110 size_t pos,
111 int button_id,
112 const wxString& label,
113 const wxBitmap& bitmap,
114 const wxString& help_string = wxEmptyString);
115
116 virtual wxRibbonButtonBarButtonBase* InsertButton(
117 size_t pos,
118 int button_id,
119 const wxString& label,
120 const wxBitmap& bitmap,
121 const wxBitmap& bitmap_small = wxNullBitmap,
122 const wxBitmap& bitmap_disabled = wxNullBitmap,
123 const wxBitmap& bitmap_small_disabled = wxNullBitmap,
124 wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL,
125 const wxString& help_string = wxEmptyString,
126 wxObject* client_data = NULL);
127
128 virtual size_t GetButtonCount() const;
129 virtual wxRibbonButtonBarButtonBase *GetItem(size_t n) const;
130 virtual wxRibbonButtonBarButtonBase *GetItemById(int id) const;
131 virtual int GetItemId(wxRibbonButtonBarButtonBase *button) const;
132
133
134 virtual bool Realize();
135 virtual void ClearButtons();
136 virtual bool DeleteButton(int button_id);
137 virtual void EnableButton(int button_id, bool enable = true);
138 virtual void ToggleButton(int button_id, bool checked);
139
140 virtual void SetArtProvider(wxRibbonArtProvider* art);
141 virtual bool IsSizingContinuous() const;
142
143 virtual wxSize GetMinSize() const;
144 protected:
145 friend class wxRibbonButtonBarEvent;
146 virtual wxSize DoGetBestSize() const;
147 wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
148
149 void OnEraseBackground(wxEraseEvent& evt);
150 void OnPaint(wxPaintEvent& evt);
151 void OnSize(wxSizeEvent& evt);
152 void OnMouseMove(wxMouseEvent& evt);
153 void OnMouseEnter(wxMouseEvent& evt);
154 void OnMouseLeave(wxMouseEvent& evt);
155 void OnMouseDown(wxMouseEvent& evt);
156 void OnMouseUp(wxMouseEvent& evt);
157
158 virtual wxSize DoGetNextSmallerSize(wxOrientation direction,
159 wxSize relative_to) const;
160 virtual wxSize DoGetNextLargerSize(wxOrientation direction,
161 wxSize relative_to) const;
162
163 void CommonInit(long style);
164 void MakeLayouts();
165 bool TryCollapseLayout(wxRibbonButtonBarLayout* original, size_t first_btn, size_t* last_button);
166 static wxBitmap MakeResizedBitmap(const wxBitmap& original, wxSize size);
167 static wxBitmap MakeDisabledBitmap(const wxBitmap& original);
168 void FetchButtonSizeInfo(wxRibbonButtonBarButtonBase* button,
169 wxRibbonButtonBarButtonState size, wxDC& dc);
170 virtual void UpdateWindowUI(long flags);
171
172 wxArrayRibbonButtonBarLayout m_layouts;
173 wxArrayRibbonButtonBarButtonBase m_buttons;
174 wxRibbonButtonBarButtonInstance* m_hovered_button;
175 wxRibbonButtonBarButtonInstance* m_active_button;
176
177 wxPoint m_layout_offset;
178 wxSize m_bitmap_size_large;
179 wxSize m_bitmap_size_small;
180 int m_current_layout;
181 bool m_layouts_valid;
182 bool m_lock_active_state;
183
184 #ifndef SWIG
185 DECLARE_CLASS(wxRibbonButtonBar)
186 DECLARE_EVENT_TABLE()
187 #endif
188 };
189
190 class WXDLLIMPEXP_RIBBON wxRibbonButtonBarEvent : public wxCommandEvent
191 {
192 public:
193 wxRibbonButtonBarEvent(wxEventType command_type = wxEVT_NULL,
194 int win_id = 0,
195 wxRibbonButtonBar* bar = NULL)
196 : wxCommandEvent(command_type, win_id)
197 , m_bar(bar)
198 {
199 }
200 #ifndef SWIG
201 wxRibbonButtonBarEvent(const wxRibbonButtonBarEvent& e) : wxCommandEvent(e)
202 {
203 m_bar = e.m_bar;
204 }
205 #endif
206 wxEvent *Clone() const { return new wxRibbonButtonBarEvent(*this); }
207
208 wxRibbonButtonBar* GetBar() {return m_bar;}
209 void SetBar(wxRibbonButtonBar* bar) {m_bar = bar;}
210 bool PopupMenu(wxMenu* menu);
211
212 protected:
213 wxRibbonButtonBar* m_bar;
214
215 #ifndef SWIG
216 private:
217 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonButtonBarEvent)
218 #endif
219 };
220
221 #ifndef SWIG
222
223 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_COMMAND_RIBBONBUTTON_CLICKED, wxRibbonButtonBarEvent);
224 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED, wxRibbonButtonBarEvent);
225
226 typedef void (wxEvtHandler::*wxRibbonButtonBarEventFunction)(wxRibbonButtonBarEvent&);
227
228 #define wxRibbonButtonBarEventHandler(func) \
229 wxEVENT_HANDLER_CAST(wxRibbonButtonBarEventFunction, func)
230
231 #define EVT_RIBBONBUTTONBAR_CLICKED(winid, fn) \
232 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBUTTON_CLICKED, winid, wxRibbonButtonBarEventHandler(fn))
233 #define EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(winid, fn) \
234 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED, winid, wxRibbonButtonBarEventHandler(fn))
235 #else
236
237 // wxpython/swig event work
238 %constant wxEventType wxEVT_COMMAND_RIBBONBUTTON_CLICKED;
239 %constant wxEventType wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED;
240
241 %pythoncode {
242 EVT_RIBBONBUTTONBAR_CLICKED = wx.PyEventBinder( wxEVT_COMMAND_RIBBONBUTTON_CLICKED, 1 )
243 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED = wx.PyEventBinder( wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED, 1 )
244 }
245 #endif
246
247 #endif // wxUSE_RIBBON
248
249 #endif // _WX_RIBBON_BUTTON_BAR_H_