1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ribbon/buttonbar.h
3 // Purpose: Ribbon control similar to a tool bar
4 // Author: Peter Cawley
7 // Copyright: (C) Peter Cawley
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_RIBBON_BUTTON_BAR_H_
11 #define _WX_RIBBON_BUTTON_BAR_H_
17 #include "wx/ribbon/art.h"
18 #include "wx/ribbon/control.h"
19 #include "wx/dynarray.h"
21 class wxRibbonButtonBarButtonBase
;
22 class wxRibbonButtonBarLayout
;
23 class wxRibbonButtonBarButtonInstance
;
25 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxRibbonButtonBarLayout
*, wxArrayRibbonButtonBarLayout
, class WXDLLIMPEXP_RIBBON
);
26 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxRibbonButtonBarButtonBase
*, wxArrayRibbonButtonBarButtonBase
, class WXDLLIMPEXP_RIBBON
);
28 class WXDLLIMPEXP_RIBBON wxRibbonButtonBar
: public wxRibbonControl
33 wxRibbonButtonBar(wxWindow
* parent
,
34 wxWindowID id
= wxID_ANY
,
35 const wxPoint
& pos
= wxDefaultPosition
,
36 const wxSize
& size
= wxDefaultSize
,
39 virtual ~wxRibbonButtonBar();
41 bool Create(wxWindow
* parent
,
42 wxWindowID id
= wxID_ANY
,
43 const wxPoint
& pos
= wxDefaultPosition
,
44 const wxSize
& size
= wxDefaultSize
,
47 virtual wxRibbonButtonBarButtonBase
* AddButton(
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
57 virtual wxRibbonButtonBarButtonBase
* AddDropdownButton(
59 const wxString
& label
,
60 const wxBitmap
& bitmap
,
61 const wxString
& help_string
= wxEmptyString
);
63 virtual wxRibbonButtonBarButtonBase
* AddHybridButton(
65 const wxString
& label
,
66 const wxBitmap
& bitmap
,
67 const wxString
& help_string
= wxEmptyString
);
69 virtual wxRibbonButtonBarButtonBase
* AddToggleButton(
71 const wxString
& label
,
72 const wxBitmap
& bitmap
,
73 const wxString
& help_string
= wxEmptyString
);
75 virtual wxRibbonButtonBarButtonBase
* AddButton(
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
,
83 const wxString
& help_string
= wxEmptyString
);
85 virtual wxRibbonButtonBarButtonBase
* InsertButton(
88 const wxString
& label
,
89 const wxBitmap
& bitmap
,
90 const wxString
& help_string
,
91 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
);
93 virtual wxRibbonButtonBarButtonBase
* InsertDropdownButton(
96 const wxString
& label
,
97 const wxBitmap
& bitmap
,
98 const wxString
& help_string
= wxEmptyString
);
100 virtual wxRibbonButtonBarButtonBase
* InsertHybridButton(
103 const wxString
& label
,
104 const wxBitmap
& bitmap
,
105 const wxString
& help_string
= wxEmptyString
);
107 virtual wxRibbonButtonBarButtonBase
* InsertToggleButton(
110 const wxString
& label
,
111 const wxBitmap
& bitmap
,
112 const wxString
& help_string
= wxEmptyString
);
114 virtual wxRibbonButtonBarButtonBase
* InsertButton(
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
,
123 const wxString
& help_string
= wxEmptyString
);
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;
130 virtual size_t GetButtonCount() const;
131 virtual wxRibbonButtonBarButtonBase
*GetItem(size_t n
) const;
132 virtual wxRibbonButtonBarButtonBase
*GetItemById(int id
) const;
133 virtual int GetItemId(wxRibbonButtonBarButtonBase
*button
) const;
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);
140 virtual void ToggleButton(int button_id
, bool checked
);
142 virtual wxRibbonButtonBarButtonBase
*GetActiveItem() const;
143 virtual wxRibbonButtonBarButtonBase
*GetHoveredItem() const;
145 virtual void SetArtProvider(wxRibbonArtProvider
* art
);
146 virtual bool IsSizingContinuous() const;
148 virtual wxSize
GetMinSize() const;
150 void SetShowToolTipsForDisabled(bool show
);
151 bool GetShowToolTipsForDisabled() const;
154 friend class wxRibbonButtonBarEvent
;
155 virtual wxSize
DoGetBestSize() const;
156 wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
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
);
167 virtual wxSize
DoGetNextSmallerSize(wxOrientation direction
,
168 wxSize relative_to
) const;
169 virtual wxSize
DoGetNextLargerSize(wxOrientation direction
,
170 wxSize relative_to
) const;
172 void CommonInit(long style
);
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
);
179 virtual void UpdateWindowUI(long flags
);
181 wxArrayRibbonButtonBarLayout m_layouts
;
182 wxArrayRibbonButtonBarButtonBase m_buttons
;
183 wxRibbonButtonBarButtonInstance
* m_hovered_button
;
184 wxRibbonButtonBarButtonInstance
* m_active_button
;
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
;
192 bool m_show_tooltips_for_disabled
;
195 DECLARE_CLASS(wxRibbonButtonBar
)
196 DECLARE_EVENT_TABLE()
200 class WXDLLIMPEXP_RIBBON wxRibbonButtonBarEvent
: public wxCommandEvent
203 wxRibbonButtonBarEvent(wxEventType command_type
= wxEVT_NULL
,
205 wxRibbonButtonBar
* bar
= NULL
,
206 wxRibbonButtonBarButtonBase
* button
= NULL
)
207 : wxCommandEvent(command_type
, win_id
)
208 , m_bar(bar
), m_button(button
)
212 wxRibbonButtonBarEvent(const wxRibbonButtonBarEvent
& e
) : wxCommandEvent(e
)
215 m_button
= e
.m_button
;
218 wxEvent
*Clone() const { return new wxRibbonButtonBarEvent(*this); }
220 wxRibbonButtonBar
* GetBar() {return m_bar
;}
221 wxRibbonButtonBarButtonBase
*GetButton() { return m_button
; }
222 void SetBar(wxRibbonButtonBar
* bar
) {m_bar
= bar
;}
223 void SetButton(wxRibbonButtonBarButtonBase
* button
) { m_button
= button
; }
224 bool PopupMenu(wxMenu
* menu
);
227 wxRibbonButtonBar
* m_bar
;
228 wxRibbonButtonBarButtonBase
*m_button
;
232 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonButtonBarEvent
)
238 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONBUTTONBAR_CLICKED
, wxRibbonButtonBarEvent
);
239 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED
, wxRibbonButtonBarEvent
);
241 typedef void (wxEvtHandler::*wxRibbonButtonBarEventFunction
)(wxRibbonButtonBarEvent
&);
243 #define wxRibbonButtonBarEventHandler(func) \
244 wxEVENT_HANDLER_CAST(wxRibbonButtonBarEventFunction, func)
246 #define EVT_RIBBONBUTTONBAR_CLICKED(winid, fn) \
247 wx__DECLARE_EVT1(wxEVT_RIBBONBUTTONBAR_CLICKED, winid, wxRibbonButtonBarEventHandler(fn))
248 #define EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(winid, fn) \
249 wx__DECLARE_EVT1(wxEVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED, winid, wxRibbonButtonBarEventHandler(fn))
252 // wxpython/swig event work
253 %constant wxEventType wxEVT_RIBBONBUTTONBAR_CLICKED
;
254 %constant wxEventType wxEVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED
;
257 EVT_RIBBONBUTTONBAR_CLICKED
= wx
.PyEventBinder( wxEVT_RIBBONBUTTONBAR_CLICKED
, 1 )
258 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED
= wx
.PyEventBinder( wxEVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED
, 1 )
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
266 #endif // wxUSE_RIBBON
268 #endif // _WX_RIBBON_BUTTON_BAR_H_