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