1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ribbon/bar.h
3 // Purpose: Top-level component of the ribbon-bar-style interface
4 // Author: Peter Cawley
8 // Copyright: (C) Peter Cawley
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_RIBBON_BAR_H_
13 #define _WX_RIBBON_BAR_H_
19 #include "wx/ribbon/control.h"
20 #include "wx/ribbon/page.h"
22 enum wxRibbonBarOption
24 wxRIBBON_BAR_SHOW_PAGE_LABELS
= 1 << 0,
25 wxRIBBON_BAR_SHOW_PAGE_ICONS
= 1 << 1,
26 wxRIBBON_BAR_FLOW_HORIZONTAL
= 0,
27 wxRIBBON_BAR_FLOW_VERTICAL
= 1 << 2,
28 wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS
= 1 << 3,
29 wxRIBBON_BAR_SHOW_PANEL_MINIMISE_BUTTONS
= 1 << 4,
30 wxRIBBON_BAR_ALWAYS_SHOW_TABS
= 1 << 5,
31 wxRIBBON_BAR_SHOW_TOGGLE_BUTTON
= 1 << 6,
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
,
38 wxRIBBON_BAR_FOLDBAR_STYLE
= wxRIBBON_BAR_FLOW_VERTICAL
39 | wxRIBBON_BAR_SHOW_PAGE_ICONS
40 | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS
41 | wxRIBBON_BAR_SHOW_PANEL_MINIMISE_BUTTONS
44 class WXDLLIMPEXP_RIBBON wxRibbonBarEvent
: public wxNotifyEvent
47 wxRibbonBarEvent(wxEventType command_type
= wxEVT_NULL
,
49 wxRibbonPage
* page
= NULL
)
50 : wxNotifyEvent(command_type
, win_id
)
55 wxRibbonBarEvent(const wxRibbonBarEvent
& c
) : wxNotifyEvent(c
)
60 wxEvent
*Clone() const { return new wxRibbonBarEvent(*this); }
62 wxRibbonPage
* GetPage() {return m_page
;}
63 void SetPage(wxRibbonPage
* page
) {m_page
= page
;}
70 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonBarEvent
)
74 class WXDLLIMPEXP_RIBBON wxRibbonPageTabInfo
80 int small_begin_need_separator_width
;
81 int small_must_have_separator_width
;
89 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxRibbonPageTabInfo
, wxRibbonPageTabInfoArray
, WXDLLIMPEXP_RIBBON
);
92 class WXDLLIMPEXP_RIBBON wxRibbonBar
: public wxRibbonControl
97 wxRibbonBar(wxWindow
* parent
,
98 wxWindowID id
= wxID_ANY
,
99 const wxPoint
& pos
= wxDefaultPosition
,
100 const wxSize
& size
= wxDefaultSize
,
101 long style
= wxRIBBON_BAR_DEFAULT_STYLE
);
103 virtual ~wxRibbonBar();
105 bool Create(wxWindow
* parent
,
106 wxWindowID id
= wxID_ANY
,
107 const wxPoint
& pos
= wxDefaultPosition
,
108 const wxSize
& size
= wxDefaultSize
,
109 long style
= wxRIBBON_BAR_DEFAULT_STYLE
);
111 void SetTabCtrlMargins(int left
, int right
);
113 void SetArtProvider(wxRibbonArtProvider
* art
);
115 bool SetActivePage(size_t page
);
116 bool SetActivePage(wxRibbonPage
* page
);
117 int GetActivePage() const;
118 wxRibbonPage
* GetPage(int n
);
119 size_t GetPageCount() const;
120 bool DismissExpandedPanel();
121 int GetPageNumber(wxRibbonPage
* page
) const;
123 void DeletePage(size_t n
);
126 bool IsPageShown(size_t page
) const;
127 void ShowPage(size_t page
, bool show
= true);
128 void HidePage(size_t page
) { ShowPage(page
, false); }
130 void ShowPanels(bool show
= true);
131 void HidePanels() { ShowPanels(false); }
132 bool ArePanelsShown() const { return m_arePanelsShown
; }
134 virtual bool HasMultiplePages() const { return true; }
136 void SetWindowStyleFlag(long style
);
137 long GetWindowStyleFlag() const;
138 virtual bool Realize();
140 // Implementation only.
141 bool IsToggleButtonHovered() const { return m_toggle_button_hovered
; }
144 friend class wxRibbonPage
;
146 virtual wxSize
DoGetBestSize() const;
147 wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
148 wxRibbonPageTabInfo
* HitTestTabs(wxPoint position
, int* index
= NULL
);
149 void HitTestToggleButton(wxPoint position
);
151 void CommonInit(long style
);
152 void AddPage(wxRibbonPage
*page
);
153 void RecalculateTabSizes();
154 void RecalculateMinSize();
155 void ScrollTabBar(int npixels
);
156 void RefreshTabBar();
157 void RepositionPage(wxRibbonPage
*page
);
159 void OnPaint(wxPaintEvent
& evt
);
160 void OnEraseBackground(wxEraseEvent
& evt
);
161 void DoEraseBackground(wxDC
& dc
);
162 void OnSize(wxSizeEvent
& evt
);
163 void OnMouseLeftDown(wxMouseEvent
& evt
);
164 void OnMouseLeftUp(wxMouseEvent
& evt
);
165 void OnMouseMiddleDown(wxMouseEvent
& evt
);
166 void OnMouseMiddleUp(wxMouseEvent
& evt
);
167 void OnMouseRightDown(wxMouseEvent
& evt
);
168 void OnMouseRightUp(wxMouseEvent
& evt
);
169 void OnMouseMove(wxMouseEvent
& evt
);
170 void OnMouseLeave(wxMouseEvent
& evt
);
171 void OnMouseDoubleClick(wxMouseEvent
& evt
);
172 void DoMouseButtonCommon(wxMouseEvent
& evt
, wxEventType tab_event_type
);
174 wxRibbonPageTabInfoArray m_pages
;
175 wxRect m_tab_scroll_left_button_rect
;
176 wxRect m_tab_scroll_right_button_rect
;
177 wxRect m_toggle_button_rect
;
179 int m_tabs_total_width_ideal
;
180 int m_tabs_total_width_minimum
;
181 int m_tab_margin_left
;
182 int m_tab_margin_right
;
184 int m_tab_scroll_amount
;
186 int m_current_hovered_page
;
187 int m_tab_scroll_left_button_state
;
188 int m_tab_scroll_right_button_state
;
189 bool m_tab_scroll_buttons_shown
;
190 bool m_arePanelsShown
;
192 bool m_toggle_button_hovered
;
195 DECLARE_CLASS(wxRibbonBar
)
196 DECLARE_EVENT_TABLE()
202 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGED
, wxRibbonBarEvent
);
203 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGING
, wxRibbonBarEvent
);
204 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_DOWN
, wxRibbonBarEvent
);
205 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_UP
, wxRibbonBarEvent
);
206 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_DOWN
, wxRibbonBarEvent
);
207 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP
, wxRibbonBarEvent
);
208 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK
, wxRibbonBarEvent
);
209 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON
, wxEVT_COMMAND_RIBBONBAR_TOGGLED
, wxRibbonBarEvent
);
211 typedef void (wxEvtHandler::*wxRibbonBarEventFunction
)(wxRibbonBarEvent
&);
213 #define wxRibbonBarEventHandler(func) \
214 wxEVENT_HANDLER_CAST(wxRibbonBarEventFunction, func)
216 #define EVT_RIBBONBAR_PAGE_CHANGED(winid, fn) \
217 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGED, winid, wxRibbonBarEventHandler(fn))
218 #define EVT_RIBBONBAR_PAGE_CHANGING(winid, fn) \
219 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGING, winid, wxRibbonBarEventHandler(fn))
220 #define EVT_RIBBONBAR_TAB_MIDDLE_DOWN(winid, fn) \
221 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_DOWN, winid, wxRibbonBarEventHandler(fn))
222 #define EVT_RIBBONBAR_TAB_MIDDLE_UP(winid, fn) \
223 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_UP, winid, wxRibbonBarEventHandler(fn))
224 #define EVT_RIBBONBAR_TAB_RIGHT_DOWN(winid, fn) \
225 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_DOWN, winid, wxRibbonBarEventHandler(fn))
226 #define EVT_RIBBONBAR_TAB_RIGHT_UP(winid, fn) \
227 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP, winid, wxRibbonBarEventHandler(fn))
228 #define EVT_RIBBONBAR_TAB_LEFT_DCLICK(winid, fn) \
229 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK, winid, wxRibbonBarEventHandler(fn))
230 #define EVT_RIBBONBAR_TOGGLED(winid, fn) \
231 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONBAR_TOGGLED, winid, wxRibbonBarEventHandler(fn))
234 // wxpython/swig event work
235 %constant wxEventType wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGED
;
236 %constant wxEventType wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGING
;
237 %constant wxEventType wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_DOWN
;
238 %constant wxEventType wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_UP
;
239 %constant wxEventType wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_DOWN
;
240 %constant wxEventType wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP
;
241 %constant wxEventType wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK
;
242 %constant wxEventType wxEVT_COMMAND_RIBBONBAR_TOGGLED
;
245 EVT_RIBBONBAR_PAGE_CHANGED
= wx
.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGED
, 1 )
246 EVT_RIBBONBAR_PAGE_CHANGING
= wx
.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_PAGE_CHANGING
, 1 )
247 EVT_RIBBONBAR_TAB_MIDDLE_DOWN
= wx
.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_DOWN
, 1 )
248 EVT_RIBBONBAR_TAB_MIDDLE_UP
= wx
.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_TAB_MIDDLE_UP
, 1 )
249 EVT_RIBBONBAR_TAB_RIGHT_DOWN
= wx
.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_DOWN
, 1 )
250 EVT_RIBBONBAR_TAB_RIGHT_UP
= wx
.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_TAB_RIGHT_UP
, 1 )
251 EVT_RIBBONBAR_TAB_LEFT_DCLICK
= wx
.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_TAB_LEFT_DCLICK
, 1 )
252 EVT_RIBBONBAR_TOGGLED
= wx
.PyEventBinder( wxEVT_COMMAND_RIBBONBAR_TOGGLED
, 1 )
256 #endif // wxUSE_RIBBON
258 #endif // _WX_RIBBON_BAR_H_