]> git.saurik.com Git - wxWidgets.git/blob - include/wx/ribbon/toolbar.h
Fix wxMac preprocessor check in wxWebView code.
[wxWidgets.git] / include / wx / ribbon / toolbar.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ribbon/toolbar.h
3 // Purpose: Ribbon-style tool bar
4 // Author: Peter Cawley
5 // Modified by:
6 // Created: 2009-07-06
7 // RCS-ID: $Id$
8 // Copyright: (C) Peter Cawley
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_RIBBON_TOOLBAR_H_
12 #define _WX_RIBBON_TOOLBAR_H_
13
14 #include "wx/defs.h"
15
16 #if wxUSE_RIBBON
17
18 #include "wx/ribbon/control.h"
19 #include "wx/ribbon/art.h"
20
21 class wxRibbonToolBarToolBase;
22 class wxRibbonToolBarToolGroup;
23 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxRibbonToolBarToolGroup*, wxArrayRibbonToolBarToolGroup, class WXDLLIMPEXP_RIBBON);
24
25 enum wxRibbonToolBarToolState
26 {
27 wxRIBBON_TOOLBAR_TOOL_FIRST = 1 << 0,
28 wxRIBBON_TOOLBAR_TOOL_LAST = 1 << 1,
29 wxRIBBON_TOOLBAR_TOOL_POSITION_MASK = wxRIBBON_TOOLBAR_TOOL_FIRST | wxRIBBON_TOOLBAR_TOOL_LAST,
30
31 wxRIBBON_TOOLBAR_TOOL_NORMAL_HOVERED = 1 << 3,
32 wxRIBBON_TOOLBAR_TOOL_DROPDOWN_HOVERED = 1 << 4,
33 wxRIBBON_TOOLBAR_TOOL_HOVER_MASK = wxRIBBON_TOOLBAR_TOOL_NORMAL_HOVERED | wxRIBBON_TOOLBAR_TOOL_DROPDOWN_HOVERED,
34 wxRIBBON_TOOLBAR_TOOL_NORMAL_ACTIVE = 1 << 5,
35 wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE = 1 << 6,
36 wxRIBBON_TOOLBAR_TOOL_ACTIVE_MASK = wxRIBBON_TOOLBAR_TOOL_NORMAL_ACTIVE | wxRIBBON_TOOLBAR_TOOL_DROPDOWN_ACTIVE,
37 wxRIBBON_TOOLBAR_TOOL_DISABLED = 1 << 7,
38 wxRIBBON_TOOLBAR_TOOL_TOGGLED = 1 << 8,
39 wxRIBBON_TOOLBAR_TOOL_STATE_MASK = 0x1F8
40 };
41
42
43 class WXDLLIMPEXP_RIBBON wxRibbonToolBar : public wxRibbonControl
44 {
45 public:
46 wxRibbonToolBar();
47
48 wxRibbonToolBar(wxWindow* parent,
49 wxWindowID id = wxID_ANY,
50 const wxPoint& pos = wxDefaultPosition,
51 const wxSize& size = wxDefaultSize,
52 long style = 0);
53
54 virtual ~wxRibbonToolBar();
55
56 bool Create(wxWindow* parent,
57 wxWindowID id = wxID_ANY,
58 const wxPoint& pos = wxDefaultPosition,
59 const wxSize& size = wxDefaultSize,
60 long style = 0);
61
62 virtual wxRibbonToolBarToolBase* AddTool(
63 int tool_id,
64 const wxBitmap& bitmap,
65 const wxString& help_string,
66 wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL);
67
68 virtual wxRibbonToolBarToolBase* AddDropdownTool(
69 int tool_id,
70 const wxBitmap& bitmap,
71 const wxString& help_string = wxEmptyString);
72
73 virtual wxRibbonToolBarToolBase* AddHybridTool(
74 int tool_id,
75 const wxBitmap& bitmap,
76 const wxString& help_string = wxEmptyString);
77
78 virtual wxRibbonToolBarToolBase* AddToggleTool(
79 int tool_id,
80 const wxBitmap& bitmap,
81 const wxString& help_string = wxEmptyString);
82
83 virtual wxRibbonToolBarToolBase* AddTool(
84 int tool_id,
85 const wxBitmap& bitmap,
86 const wxBitmap& bitmap_disabled = wxNullBitmap,
87 const wxString& help_string = wxEmptyString,
88 wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL,
89 wxObject* client_data = NULL);
90
91 virtual wxRibbonToolBarToolBase* AddSeparator();
92
93 virtual wxRibbonToolBarToolBase* InsertTool(
94 size_t pos,
95 int tool_id,
96 const wxBitmap& bitmap,
97 const wxString& help_string,
98 wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL);
99
100 virtual wxRibbonToolBarToolBase* InsertDropdownTool(
101 size_t pos,
102 int tool_id,
103 const wxBitmap& bitmap,
104 const wxString& help_string = wxEmptyString);
105
106 virtual wxRibbonToolBarToolBase* InsertHybridTool(
107 size_t pos,
108 int tool_id,
109 const wxBitmap& bitmap,
110 const wxString& help_string = wxEmptyString);
111
112 virtual wxRibbonToolBarToolBase* InsertToggleTool(
113 size_t pos,
114 int tool_id,
115 const wxBitmap& bitmap,
116 const wxString& help_string = wxEmptyString);
117
118 virtual wxRibbonToolBarToolBase* InsertTool(
119 size_t pos,
120 int tool_id,
121 const wxBitmap& bitmap,
122 const wxBitmap& bitmap_disabled = wxNullBitmap,
123 const wxString& help_string = wxEmptyString,
124 wxRibbonButtonKind kind = wxRIBBON_BUTTON_NORMAL,
125 wxObject* client_data = NULL);
126
127 virtual wxRibbonToolBarToolBase* InsertSeparator(size_t pos);
128
129 virtual void ClearTools();
130 virtual bool DeleteTool(int tool_id);
131 virtual bool DeleteToolByPos(size_t pos);
132
133 virtual wxRibbonToolBarToolBase* FindById(int tool_id)const;
134 virtual wxRibbonToolBarToolBase* GetToolByPos(size_t pos)const;
135 virtual size_t GetToolCount() const;
136 virtual int GetToolId(const wxRibbonToolBarToolBase* tool)const;
137
138 virtual wxObject* GetToolClientData(int tool_id)const;
139 virtual bool GetToolEnabled(int tool_id)const;
140 virtual wxString GetToolHelpString(int tool_id)const;
141 virtual wxRibbonButtonKind GetToolKind(int tool_id)const;
142 virtual int GetToolPos(int tool_id)const;
143 virtual bool GetToolState(int tool_id)const;
144
145 virtual bool Realize();
146 virtual void SetRows(int nMin, int nMax = -1);
147
148 virtual void SetToolClientData(int tool_id, wxObject* clientData);
149 virtual void SetToolDisabledBitmap(int tool_id, const wxBitmap &bitmap);
150 virtual void SetToolHelpString(int tool_id, const wxString& helpString);
151 virtual void SetToolNormalBitmap(int tool_id, const wxBitmap &bitmap);
152
153 virtual bool IsSizingContinuous() const;
154
155 virtual void EnableTool(int tool_id, bool enable = true);
156 virtual void ToggleTool(int tool_id, bool checked);
157
158 // Finds the best width and height given the parent's width and height
159 virtual wxSize GetBestSizeForParentSize(const wxSize& parentSize) const;
160
161 protected:
162 friend class wxRibbonToolBarEvent;
163 virtual wxSize DoGetBestSize() const;
164 wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
165
166 void OnEraseBackground(wxEraseEvent& evt);
167 void OnMouseDown(wxMouseEvent& evt);
168 void OnMouseEnter(wxMouseEvent& evt);
169 void OnMouseLeave(wxMouseEvent& evt);
170 void OnMouseMove(wxMouseEvent& evt);
171 void OnMouseUp(wxMouseEvent& evt);
172 void OnPaint(wxPaintEvent& evt);
173 void OnSize(wxSizeEvent& evt);
174
175 virtual wxSize DoGetNextSmallerSize(wxOrientation direction,
176 wxSize relative_to) const;
177 virtual wxSize DoGetNextLargerSize(wxOrientation direction,
178 wxSize relative_to) const;
179
180 void CommonInit(long style);
181 void AppendGroup();
182 wxRibbonToolBarToolGroup* InsertGroup(size_t pos);
183 virtual void UpdateWindowUI(long flags);
184
185 static wxBitmap MakeDisabledBitmap(const wxBitmap& original);
186
187 wxArrayRibbonToolBarToolGroup m_groups;
188 wxRibbonToolBarToolBase* m_hover_tool;
189 wxRibbonToolBarToolBase* m_active_tool;
190 wxSize* m_sizes;
191 int m_nrows_min;
192 int m_nrows_max;
193
194 #ifndef SWIG
195 DECLARE_CLASS(wxRibbonToolBar)
196 DECLARE_EVENT_TABLE()
197 #endif
198 };
199
200
201 class WXDLLIMPEXP_RIBBON wxRibbonToolBarEvent : public wxCommandEvent
202 {
203 public:
204 wxRibbonToolBarEvent(wxEventType command_type = wxEVT_NULL,
205 int win_id = 0,
206 wxRibbonToolBar* bar = NULL)
207 : wxCommandEvent(command_type, win_id)
208 , m_bar(bar)
209 {
210 }
211 #ifndef SWIG
212 wxRibbonToolBarEvent(const wxRibbonToolBarEvent& e) : wxCommandEvent(e)
213 {
214 m_bar = e.m_bar;
215 }
216 #endif
217 wxEvent *Clone() const { return new wxRibbonToolBarEvent(*this); }
218
219 wxRibbonToolBar* GetBar() {return m_bar;}
220 void SetBar(wxRibbonToolBar* bar) {m_bar = bar;}
221 bool PopupMenu(wxMenu* menu);
222
223 protected:
224 wxRibbonToolBar* m_bar;
225
226 #ifndef SWIG
227 private:
228 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRibbonToolBarEvent)
229 #endif
230 };
231
232 #ifndef SWIG
233
234 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_COMMAND_RIBBONTOOL_CLICKED, wxRibbonToolBarEvent);
235 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_RIBBON, wxEVT_COMMAND_RIBBONTOOL_DROPDOWN_CLICKED, wxRibbonToolBarEvent);
236
237 typedef void (wxEvtHandler::*wxRibbonToolBarEventFunction)(wxRibbonToolBarEvent&);
238
239 #define wxRibbonToolBarEventHandler(func) \
240 wxEVENT_HANDLER_CAST(wxRibbonToolBarEventFunction, func)
241
242 #define EVT_RIBBONTOOLBAR_CLICKED(winid, fn) \
243 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONTOOL_CLICKED, winid, wxRibbonToolBarEventHandler(fn))
244 #define EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED(winid, fn) \
245 wx__DECLARE_EVT1(wxEVT_COMMAND_RIBBONTOOL_DROPDOWN_CLICKED, winid, wxRibbonToolBarEventHandler(fn))
246 #else
247
248 // wxpython/swig event work
249 %constant wxEventType wxEVT_COMMAND_RIBBONTOOL_CLICKED;
250 %constant wxEventType wxEVT_COMMAND_RIBBONTOOL_DROPDOWN_CLICKED;
251
252 %pythoncode {
253 EVT_RIBBONTOOLBAR_CLICKED = wx.PyEventBinder( wxEVT_COMMAND_RIBBONTOOL_CLICKED, 1 )
254 EVT_RIBBONTOOLBAR_DROPDOWN_CLICKED = wx.PyEventBinder( wxEVT_COMMAND_RIBBONTOOL_DROPDOWN_CLICKED, 1 )
255 }
256 #endif
257
258 #endif // wxUSE_RIBBON
259
260 #endif // _WX_RIBBON_TOOLBAR_H_