]> git.saurik.com Git - wxWidgets.git/blob - include/wx/ribbon/bar.h
Add wxActivateEvent::GetActivationReason().
[wxWidgets.git] / include / wx / ribbon / bar.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ribbon/bar.h
3 // Purpose: Top-level component of the ribbon-bar-style interface
4 // Author: Peter Cawley
5 // Modified by:
6 // Created: 2009-05-23
7 // Copyright: (C) Peter Cawley
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_RIBBON_BAR_H_
12 #define _WX_RIBBON_BAR_H_
13
14 #include "wx/defs.h"
15
16 #if wxUSE_RIBBON
17
18 #include "wx/ribbon/control.h"
19 #include "wx/ribbon/page.h"
20
21 enum wxRibbonBarOption
22 {
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,
32
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,
38
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
43 };
44
45 enum wxRibbonDisplayMode
46 {
47 wxRIBBON_BAR_PINNED,
48 wxRIBBON_BAR_MINIMIZED,
49 wxRIBBON_BAR_EXPANDED
50 };
51
52 class WXDLLIMPEXP_RIBBON wxRibbonBarEvent : public wxNotifyEvent
53 {
54 public:
55 wxRibbonBarEvent(wxEventType command_type = wxEVT_NULL,
56 int win_id = 0,
57 wxRibbonPage* page = NULL)
58 : wxNotifyEvent(command_type, win_id)
59 , m_page(page)
60 {
61 }
62 #ifndef SWIG
63 wxRibbonBarEvent(const wxRibbonBarEvent& c) : wxNotifyEvent(c)
64 {
65 m_page = c.m_page;
66 }
67 #endif
68 wxEvent *Clone() const { return new wxRibbonBarEvent(*this); }
69
70 wxRibbonPage* GetPage() {return m_page;}
71 void SetPage(wxRibbonPage* page) {m_page = page;}
72
73 protected:
74 wxRibbonPage* m_page;
75
76 #ifndef SWIG
77 private:
78 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonBarEvent)
79 #endif
80 };
81
82 class WXDLLIMPEXP_RIBBON wxRibbonPageTabInfo
83 {
84 public:
85 wxRect rect;
86 wxRibbonPage *page;
87 int ideal_width;
88 int small_begin_need_separator_width;
89 int small_must_have_separator_width;
90 int minimum_width;
91 bool active;
92 bool hovered;
93 bool highlight;
94 bool shown;
95 };
96
97 #ifndef SWIG
98 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxRibbonPageTabInfo, wxRibbonPageTabInfoArray, WXDLLIMPEXP_RIBBON);
99 #endif
100
101 class WXDLLIMPEXP_RIBBON wxRibbonBar : public wxRibbonControl
102 {
103 public:
104 wxRibbonBar();
105
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);
111
112 virtual ~wxRibbonBar();
113
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);
119
120 void SetTabCtrlMargins(int left, int right);
121
122 void SetArtProvider(wxRibbonArtProvider* art);
123
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;
131
132 void DeletePage(size_t n);
133 void ClearPages();
134
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); }
138
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); }
142
143 void ShowPanels(bool show = true);
144 void HidePanels() { ShowPanels(false); }
145 bool ArePanelsShown() const { return m_arePanelsShown; }
146
147 virtual bool HasMultiplePages() const { return true; }
148
149 void SetWindowStyleFlag(long style);
150 long GetWindowStyleFlag() const;
151 virtual bool Realize();
152
153 // Implementation only.
154 bool IsToggleButtonHovered() const { return m_toggle_button_hovered; }
155 bool IsHelpButtonHovered() const { return m_help_button_hovered; }
156
157 void HideIfExpanded();
158
159 protected:
160 friend class wxRibbonPage;
161
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);
166
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);
174
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);
190
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;
196 long m_flags;
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;
201 int m_tab_height;
202 int m_tab_scroll_amount;
203 int m_current_page;
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;
209 bool m_bar_hovered;
210 bool m_toggle_button_hovered;
211 bool m_help_button_hovered;
212
213 wxRibbonDisplayMode m_ribbon_state;
214
215 #ifndef SWIG
216 DECLARE_CLASS(wxRibbonBar)
217 DECLARE_EVENT_TABLE()
218 #endif
219 };
220
221 #ifndef SWIG
222
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);
232
233 typedef void (wxEvtHandler::*wxRibbonBarEventFunction)(wxRibbonBarEvent&);
234
235 #define wxRibbonBarEventHandler(func) \
236 wxEVENT_HANDLER_CAST(wxRibbonBarEventFunction, func)
237
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))
256 #else
257
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;
268
269 %pythoncode {
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 )
279 }
280 #endif
281
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
292
293 #endif // wxUSE_RIBBON
294
295 #endif // _WX_RIBBON_BAR_H_
296