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