1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ribbon/bar.h
3 // Purpose: Top-level component of the ribbon-bar-style interface
4 // Author: Peter Cawley
7 // Copyright: (C) Peter Cawley
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_RIBBON_BAR_H_
12 #define _WX_RIBBON_BAR_H_
18 #include "wx/ribbon/control.h"
19 #include "wx/ribbon/page.h"
21 enum wxRibbonBarOption
23 wxRIBBON_BAR_SHOW_PAGE_LABELS
= 1 << 0,
24 wxRIBBON_BAR_SHOW_PAGE_ICONS
= 1 << 1,
25 wxRIBBON_BAR_FLOW_HORIZONTAL
= 0,
26 wxRIBBON_BAR_FLOW_VERTICAL
= 1 << 2,
27 wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS
= 1 << 3,
28 wxRIBBON_BAR_SHOW_PANEL_MINIMISE_BUTTONS
= 1 << 4,
29 wxRIBBON_BAR_ALWAYS_SHOW_TABS
= 1 << 5,
30 wxRIBBON_BAR_SHOW_TOGGLE_BUTTON
= 1 << 6,
31 wxRIBBON_BAR_SHOW_HELP_BUTTON
= 1 << 7,
33 wxRIBBON_BAR_DEFAULT_STYLE
= wxRIBBON_BAR_FLOW_HORIZONTAL
34 | wxRIBBON_BAR_SHOW_PAGE_LABELS
35 | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS
36 | wxRIBBON_BAR_SHOW_TOGGLE_BUTTON
37 | wxRIBBON_BAR_SHOW_HELP_BUTTON
,
39 wxRIBBON_BAR_FOLDBAR_STYLE
= wxRIBBON_BAR_FLOW_VERTICAL
40 | wxRIBBON_BAR_SHOW_PAGE_ICONS
41 | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS
42 | wxRIBBON_BAR_SHOW_PANEL_MINIMISE_BUTTONS
45 enum wxRibbonDisplayMode
48 wxRIBBON_BAR_MINIMIZED
,
52 class WXDLLIMPEXP_RIBBON wxRibbonBarEvent
: public wxNotifyEvent
55 wxRibbonBarEvent(wxEventType command_type
= wxEVT_NULL
,
57 wxRibbonPage
* page
= NULL
)
58 : wxNotifyEvent(command_type
, win_id
)
63 wxRibbonBarEvent(const wxRibbonBarEvent
& c
) : wxNotifyEvent(c
)
68 wxEvent
*Clone() const { return new wxRibbonBarEvent(*this); }
70 wxRibbonPage
* GetPage() {return m_page
;}
71 void SetPage(wxRibbonPage
* page
) {m_page
= page
;}
78 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonBarEvent
)
82 class WXDLLIMPEXP_RIBBON wxRibbonPageTabInfo
88 int small_begin_need_separator_width
;
89 int small_must_have_separator_width
;
98 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxRibbonPageTabInfo
, wxRibbonPageTabInfoArray
, WXDLLIMPEXP_RIBBON
);
101 class WXDLLIMPEXP_RIBBON wxRibbonBar
: public wxRibbonControl
106 wxRibbonBar(wxWindow
* parent
,
107 wxWindowID id
= wxID_ANY
,
108 const wxPoint
& pos
= wxDefaultPosition
,
109 const wxSize
& size
= wxDefaultSize
,
110 long style
= wxRIBBON_BAR_DEFAULT_STYLE
);
112 virtual ~wxRibbonBar();
114 bool Create(wxWindow
* parent
,
115 wxWindowID id
= wxID_ANY
,
116 const wxPoint
& pos
= wxDefaultPosition
,
117 const wxSize
& size
= wxDefaultSize
,
118 long style
= wxRIBBON_BAR_DEFAULT_STYLE
);
120 void SetTabCtrlMargins(int left
, int right
);
122 void SetArtProvider(wxRibbonArtProvider
* art
);
124 bool SetActivePage(size_t page
);
125 bool SetActivePage(wxRibbonPage
* page
);
126 int GetActivePage() const;
127 wxRibbonPage
* GetPage(int n
);
128 size_t GetPageCount() const;
129 bool DismissExpandedPanel();
130 int GetPageNumber(wxRibbonPage
* page
) const;
132 void DeletePage(size_t n
);
135 bool IsPageShown(size_t page
) const;
136 void ShowPage(size_t page
, bool show
= true);
137 void HidePage(size_t page
) { ShowPage(page
, false); }
139 bool IsPageHighlighted(size_t page
) const;
140 void AddPageHighlight(size_t page
, bool highlight
= true);
141 void RemovePageHighlight(size_t page
) { AddPageHighlight(page
, false); }
143 void ShowPanels(bool show
= true);
144 void HidePanels() { ShowPanels(false); }
145 bool ArePanelsShown() const { return m_arePanelsShown
; }
147 virtual bool HasMultiplePages() const { return true; }
149 void SetWindowStyleFlag(long style
);
150 long GetWindowStyleFlag() const;
151 virtual bool Realize();
153 // Implementation only.
154 bool IsToggleButtonHovered() const { return m_toggle_button_hovered
; }
155 bool IsHelpButtonHovered() const { return m_help_button_hovered
; }
157 void HideIfExpanded();
160 friend class wxRibbonPage
;
162 virtual wxSize
DoGetBestSize() const;
163 wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
164 wxRibbonPageTabInfo
* HitTestTabs(wxPoint position
, int* index
= NULL
);
165 void HitTestRibbonButton(const wxRect
& rect
, const wxPoint
& position
, bool &hover_flag
);
167 void CommonInit(long style
);
168 void AddPage(wxRibbonPage
*page
);
169 void RecalculateTabSizes();
170 void RecalculateMinSize();
171 void ScrollTabBar(int npixels
);
172 void RefreshTabBar();
173 void RepositionPage(wxRibbonPage
*page
);
175 void OnPaint(wxPaintEvent
& evt
);
176 void OnEraseBackground(wxEraseEvent
& evt
);
177 void DoEraseBackground(wxDC
& dc
);
178 void OnSize(wxSizeEvent
& evt
);
179 void OnMouseLeftDown(wxMouseEvent
& evt
);
180 void OnMouseLeftUp(wxMouseEvent
& evt
);
181 void OnMouseMiddleDown(wxMouseEvent
& evt
);
182 void OnMouseMiddleUp(wxMouseEvent
& evt
);
183 void OnMouseRightDown(wxMouseEvent
& evt
);
184 void OnMouseRightUp(wxMouseEvent
& evt
);
185 void OnMouseMove(wxMouseEvent
& evt
);
186 void OnMouseLeave(wxMouseEvent
& evt
);
187 void OnMouseDoubleClick(wxMouseEvent
& evt
);
188 void DoMouseButtonCommon(wxMouseEvent
& evt
, wxEventType tab_event_type
);
189 void OnKillFocus(wxFocusEvent
& evt
);
191 wxRibbonPageTabInfoArray m_pages
;
192 wxRect m_tab_scroll_left_button_rect
;
193 wxRect m_tab_scroll_right_button_rect
;
194 wxRect m_toggle_button_rect
;
195 wxRect m_help_button_rect
;
197 int m_tabs_total_width_ideal
;
198 int m_tabs_total_width_minimum
;
199 int m_tab_margin_left
;
200 int m_tab_margin_right
;
202 int m_tab_scroll_amount
;
204 int m_current_hovered_page
;
205 int m_tab_scroll_left_button_state
;
206 int m_tab_scroll_right_button_state
;
207 bool m_tab_scroll_buttons_shown
;
208 bool m_arePanelsShown
;
210 bool m_toggle_button_hovered
;
211 bool m_help_button_hovered
;
213 wxRibbonDisplayMode m_ribbon_state
;
216 DECLARE_CLASS(wxRibbonBar
)
217 DECLARE_EVENT_TABLE()
223 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONBAR_PAGE_CHANGED
, wxRibbonBarEvent
);
224 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONBAR_PAGE_CHANGING
, wxRibbonBarEvent
);
225 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONBAR_TAB_MIDDLE_DOWN
, wxRibbonBarEvent
);
226 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONBAR_TAB_MIDDLE_UP
, wxRibbonBarEvent
);
227 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONBAR_TAB_RIGHT_DOWN
, wxRibbonBarEvent
);
228 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONBAR_TAB_RIGHT_UP
, wxRibbonBarEvent
);
229 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONBAR_TAB_LEFT_DCLICK
, wxRibbonBarEvent
);
230 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONBAR_TOGGLED
, wxRibbonBarEvent
);
231 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_RIBBONBAR_HELP_CLICK
, wxRibbonBarEvent
);
233 typedef void (wxEvtHandler::*wxRibbonBarEventFunction
)(wxRibbonBarEvent
&);
235 #define wxRibbonBarEventHandler(func) \
236 wxEVENT_HANDLER_CAST(wxRibbonBarEventFunction, func)
238 #define EVT_RIBBONBAR_PAGE_CHANGED(winid, fn) \
239 wx__DECLARE_EVT1(wxEVT_RIBBONBAR_PAGE_CHANGED, winid, wxRibbonBarEventHandler(fn))
240 #define EVT_RIBBONBAR_PAGE_CHANGING(winid, fn) \
241 wx__DECLARE_EVT1(wxEVT_RIBBONBAR_PAGE_CHANGING, winid, wxRibbonBarEventHandler(fn))
242 #define EVT_RIBBONBAR_TAB_MIDDLE_DOWN(winid, fn) \
243 wx__DECLARE_EVT1(wxEVT_RIBBONBAR_TAB_MIDDLE_DOWN, winid, wxRibbonBarEventHandler(fn))
244 #define EVT_RIBBONBAR_TAB_MIDDLE_UP(winid, fn) \
245 wx__DECLARE_EVT1(wxEVT_RIBBONBAR_TAB_MIDDLE_UP, winid, wxRibbonBarEventHandler(fn))
246 #define EVT_RIBBONBAR_TAB_RIGHT_DOWN(winid, fn) \
247 wx__DECLARE_EVT1(wxEVT_RIBBONBAR_TAB_RIGHT_DOWN, winid, wxRibbonBarEventHandler(fn))
248 #define EVT_RIBBONBAR_TAB_RIGHT_UP(winid, fn) \
249 wx__DECLARE_EVT1(wxEVT_RIBBONBAR_TAB_RIGHT_UP, winid, wxRibbonBarEventHandler(fn))
250 #define EVT_RIBBONBAR_TAB_LEFT_DCLICK(winid, fn) \
251 wx__DECLARE_EVT1(wxEVT_RIBBONBAR_TAB_LEFT_DCLICK, winid, wxRibbonBarEventHandler(fn))
252 #define EVT_RIBBONBAR_TOGGLED(winid, fn) \
253 wx__DECLARE_EVT1(wxEVT_RIBBONBAR_TOGGLED, winid, wxRibbonBarEventHandler(fn))
254 #define EVT_RIBBONBAR_HELP_CLICK(winid, fn) \
255 wx__DECLARE_EVT1(wxEVT_RIBBONBAR_HELP_CLICK, winid, wxRibbonBarEventHandler(fn))
258 // wxpython/swig event work
259 %constant wxEventType wxEVT_RIBBONBAR_PAGE_CHANGED
;
260 %constant wxEventType wxEVT_RIBBONBAR_PAGE_CHANGING
;
261 %constant wxEventType wxEVT_RIBBONBAR_TAB_MIDDLE_DOWN
;
262 %constant wxEventType wxEVT_RIBBONBAR_TAB_MIDDLE_UP
;
263 %constant wxEventType wxEVT_RIBBONBAR_TAB_RIGHT_DOWN
;
264 %constant wxEventType wxEVT_RIBBONBAR_TAB_RIGHT_UP
;
265 %constant wxEventType wxEVT_RIBBONBAR_TAB_LEFT_DCLICK
;
266 %constant wxEventType wxEVT_RIBBONBAR_TOGGLED
;
267 %constant wxEventType wxEVT_RIBBONBAR_HELP_CLICK
;
270 EVT_RIBBONBAR_PAGE_CHANGED
= wx
.PyEventBinder( wxEVT_RIBBONBAR_PAGE_CHANGED
, 1 )
271 EVT_RIBBONBAR_PAGE_CHANGING
= wx
.PyEventBinder( wxEVT_RIBBONBAR_PAGE_CHANGING
, 1 )
272 EVT_RIBBONBAR_TAB_MIDDLE_DOWN
= wx
.PyEventBinder( wxEVT_RIBBONBAR_TAB_MIDDLE_DOWN
, 1 )
273 EVT_RIBBONBAR_TAB_MIDDLE_UP
= wx
.PyEventBinder( wxEVT_RIBBONBAR_TAB_MIDDLE_UP
, 1 )
274 EVT_RIBBONBAR_TAB_RIGHT_DOWN
= wx
.PyEventBinder( wxEVT_RIBBONBAR_TAB_RIGHT_DOWN
, 1 )
275 EVT_RIBBONBAR_TAB_RIGHT_UP
= wx
.PyEventBinder( wxEVT_RIBBONBAR_TAB_RIGHT_UP
, 1 )
276 EVT_RIBBONBAR_TAB_LEFT_DCLICK
= wx
.PyEventBinder( wxEVT_RIBBONBAR_TAB_LEFT_DCLICK
, 1 )
277 EVT_RIBBONBAR_TOGGLED
= wx
.PyEventBinder( wxEVT_RIBBONBAR_TOGGLED
, 1 )
278 EVT_RIBBONBAR_HELP_CLICK
= wx
.PyEventBinder( wxEVT_RIBBONBAR_HELP_CLICK
, 1 )
282 // old wxEVT_COMMAND_* constants
283 #define wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGED wxEVT_RIBBONBAR_PAGE_CHANGED
284 #define wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGING wxEVT_RIBBONBAR_PAGE_CHANGING
285 #define wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_DOWN wxEVT_RIBBONBAR_TAB_MIDDLE_DOWN
286 #define wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_UP wxEVT_RIBBONBAR_TAB_MIDDLE_UP
287 #define wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_DOWN wxEVT_RIBBONBAR_TAB_RIGHT_DOWN
288 #define wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP wxEVT_RIBBONBAR_TAB_RIGHT_UP
289 #define wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK wxEVT_RIBBONBAR_TAB_LEFT_DCLICK
290 #define wxEVT_COMMAND_RIBBONBAR_TOGGLED wxEVT_RIBBONBAR_TOGGLED
291 #define wxEVT_COMMAND_RIBBONBAR_HELP_CLICKED wxEVT_RIBBONBAR_HELP_CLICK
293 #endif // wxUSE_RIBBON
295 #endif // _WX_RIBBON_BAR_H_