1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ribbon/buttonbar.h
3 // Purpose: Ribbon control similar to a tool bar
4 // Author: Peter Cawley
8 // Copyright: (C) Peter Cawley
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_RIBBON_BUTTON_BAR_H_
12 #define _WX_RIBBON_BUTTON_BAR_H_
18 #include "wx/ribbon/art.h"
19 #include "wx/ribbon/control.h"
20 #include "wx/dynarray.h"
22 class wxRibbonButtonBarButtonBase
;
23 class wxRibbonButtonBarLayout
;
24 class wxRibbonButtonBarButtonInstance
;
26 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxRibbonButtonBarLayout
*, wxArrayRibbonButtonBarLayout
, class WXDLLIMPEXP_RIBBON
);
27 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxRibbonButtonBarButtonBase
*, wxArrayRibbonButtonBarButtonBase
, class WXDLLIMPEXP_RIBBON
);
29 class WXDLLIMPEXP_RIBBON wxRibbonButtonBar
: public wxRibbonControl
34 wxRibbonButtonBar(wxWindow
* parent
,
35 wxWindowID id
= wxID_ANY
,
36 const wxPoint
& pos
= wxDefaultPosition
,
37 const wxSize
& size
= wxDefaultSize
,
40 virtual ~wxRibbonButtonBar();
42 bool Create(wxWindow
* parent
,
43 wxWindowID id
= wxID_ANY
,
44 const wxPoint
& pos
= wxDefaultPosition
,
45 const wxSize
& size
= wxDefaultSize
,
48 virtual wxRibbonButtonBarButtonBase
* AddButton(
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
58 virtual wxRibbonButtonBarButtonBase
* AddDropdownButton(
60 const wxString
& label
,
61 const wxBitmap
& bitmap
,
62 const wxString
& help_string
= wxEmptyString
);
64 virtual wxRibbonButtonBarButtonBase
* AddHybridButton(
66 const wxString
& label
,
67 const wxBitmap
& bitmap
,
68 const wxString
& help_string
= wxEmptyString
);
70 virtual wxRibbonButtonBarButtonBase
* AddToggleButton(
72 const wxString
& label
,
73 const wxBitmap
& bitmap
,
74 const wxString
& help_string
= wxEmptyString
);
76 virtual wxRibbonButtonBarButtonBase
* AddButton(
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
);
87 virtual wxRibbonButtonBarButtonBase
* InsertButton(
90 const wxString
& label
,
91 const wxBitmap
& bitmap
,
92 const wxString
& help_string
,
93 wxRibbonButtonKind kind
= wxRIBBON_BUTTON_NORMAL
);
95 virtual wxRibbonButtonBarButtonBase
* InsertDropdownButton(
98 const wxString
& label
,
99 const wxBitmap
& bitmap
,
100 const wxString
& help_string
= wxEmptyString
);
102 virtual wxRibbonButtonBarButtonBase
* InsertHybridButton(
105 const wxString
& label
,
106 const wxBitmap
& bitmap
,
107 const wxString
& help_string
= wxEmptyString
);
109 virtual wxRibbonButtonBarButtonBase
* InsertToggleButton(
112 const wxString
& label
,
113 const wxBitmap
& bitmap
,
114 const wxString
& help_string
= wxEmptyString
);
116 virtual wxRibbonButtonBarButtonBase
* InsertButton(
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
);
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;
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
);
140 virtual wxRibbonButtonBarButtonBase
*GetActiveItem() const;
141 virtual wxRibbonButtonBarButtonBase
*GetHoveredItem() const;
143 virtual void SetArtProvider(wxRibbonArtProvider
* art
);
144 virtual bool IsSizingContinuous() const;
146 virtual wxSize
GetMinSize() const;
148 friend class wxRibbonButtonBarEvent
;
149 virtual wxSize
DoGetBestSize() const;
150 wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
152 void OnEraseBackground(wxEraseEvent
& evt
);
153 void OnPaint(wxPaintEvent
& evt
);
154 void OnSize(wxSizeEvent
& evt
);
155 void OnMouseMove(wxMouseEvent
& evt
);
156 void OnMouseEnter(wxMouseEvent
& evt
);
157 void OnMouseLeave(wxMouseEvent
& evt
);
158 void OnMouseDown(wxMouseEvent
& evt
);
159 void OnMouseUp(wxMouseEvent
& evt
);
161 virtual wxSize
DoGetNextSmallerSize(wxOrientation direction
,
162 wxSize relative_to
) const;
163 virtual wxSize
DoGetNextLargerSize(wxOrientation direction
,
164 wxSize relative_to
) const;
166 void CommonInit(long style
);
168 bool TryCollapseLayout(wxRibbonButtonBarLayout
* original
, size_t first_btn
, size_t* last_button
);
169 static wxBitmap
MakeResizedBitmap(const wxBitmap
& original
, wxSize size
);
170 static wxBitmap
MakeDisabledBitmap(const wxBitmap
& original
);
171 void FetchButtonSizeInfo(wxRibbonButtonBarButtonBase
* button
,
172 wxRibbonButtonBarButtonState size
, wxDC
& dc
);
173 virtual void UpdateWindowUI(long flags
);
175 wxArrayRibbonButtonBarLayout m_layouts
;
176 wxArrayRibbonButtonBarButtonBase m_buttons
;
177 wxRibbonButtonBarButtonInstance
* m_hovered_button
;
178 wxRibbonButtonBarButtonInstance
* m_active_button
;
180 wxPoint m_layout_offset
;
181 wxSize m_bitmap_size_large
;
182 wxSize m_bitmap_size_small
;
183 int m_current_layout
;
184 bool m_layouts_valid
;
185 bool m_lock_active_state
;
188 DECLARE_CLASS(wxRibbonButtonBar
)
189 DECLARE_EVENT_TABLE()
193 class WXDLLIMPEXP_RIBBON wxRibbonButtonBarEvent
: public wxCommandEvent
196 wxRibbonButtonBarEvent(wxEventType command_type
= wxEVT_NULL
,
198 wxRibbonButtonBar
* bar
= NULL
,
199 wxRibbonButtonBarButtonBase
* button
= NULL
)
200 : wxCommandEvent(command_type
, win_id
)
201 , m_bar(bar
), m_button(button
)
205 wxRibbonButtonBarEvent(const wxRibbonButtonBarEvent
& e
) : wxCommandEvent(e
)
208 m_button
= e
.m_button
;
211 wxEvent
*Clone() const { return new wxRibbonButtonBarEvent(*this); }
213 wxRibbonButtonBar
* GetBar() {return m_bar
;}
214 wxRibbonButtonBarButtonBase
*GetButton() { return m_button
; }
215 void SetBar(wxRibbonButtonBar
* bar
) {m_bar
= bar
;}
216 void SetButton(wxRibbonButtonBarButtonBase
* button
) { m_button
= button
; }
217 bool PopupMenu(wxMenu
* menu
);
220 wxRibbonButtonBar
* m_bar
;
221 wxRibbonButtonBarButtonBase
*m_button
;
225 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonButtonBarEvent
)
231 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_COMMAND_RIBBONBUTTON_CLICKED
, wxRibbonButtonBarEvent
);
232 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED
, wxRibbonButtonBarEvent
);
234 typedef void (wxEvtHandler::*wxRibbonButtonBarEventFunction
)(wxRibbonButtonBarEvent
&);
236 #define wxRibbonButtonBarEventHandler(func) \
237 wxEVENT_HANDLER_CAST(wxRibbonButtonBarEventFunction, func)
239 #define EVT_RIBBONBUTTONBAR_CLICKED(winid, fn) \
240 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBUTTON_CLICKED, winid, wxRibbonButtonBarEventHandler(fn))
241 #define EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED(winid, fn) \
242 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED, winid, wxRibbonButtonBarEventHandler(fn))
245 // wxpython/swig event work
246 %constant wxEventType wxEVT_COMMAND_RIBBONBUTTON_CLICKED
;
247 %constant wxEventType wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED
;
250 EVT_RIBBONBUTTONBAR_CLICKED
= wx
.PyEventBinder( wxEVT_COMMAND_RIBBONBUTTON_CLICKED
, 1 )
251 EVT_RIBBONBUTTONBAR_DROPDOWN_CLICKED
= wx
.PyEventBinder( wxEVT_COMMAND_RIBBONBUTTON_DROPDOWN_CLICKED
, 1 )
255 #endif // wxUSE_RIBBON
257 #endif // _WX_RIBBON_BUTTON_BAR_H_