]>
Commit | Line | Data |
---|---|---|
10b959e3 | 1 | ///////////////////////////////////////////////////////////////////////////// |
6d167489 | 2 | // Name: wx/tbarbase.h |
10b959e3 JS |
3 | // Purpose: Base class for toolbar classes |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
371a5b4e | 8 | // Copyright: (c) Julian Smart |
1c383dba | 9 | // Licence: wxWindows licence |
10b959e3 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_TBARBASE_H_ |
13 | #define _WX_TBARBASE_H_ | |
10b959e3 | 14 | |
1c383dba VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
12028905 | 19 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
1c383dba | 20 | #pragma interface "tbarbase.h" |
10b959e3 JS |
21 | #endif |
22 | ||
23 | #include "wx/defs.h" | |
24 | ||
1e6feb95 VZ |
25 | #if wxUSE_TOOLBAR |
26 | ||
10b959e3 JS |
27 | #include "wx/bitmap.h" |
28 | #include "wx/list.h" | |
29 | #include "wx/control.h" | |
30 | ||
8a0681f9 VZ |
31 | class WXDLLEXPORT wxToolBarBase; |
32 | class WXDLLEXPORT wxToolBarToolBase; | |
c229e50d | 33 | class WXDLLEXPORT wxImage; |
1c383dba VZ |
34 | |
35 | // ---------------------------------------------------------------------------- | |
36 | // constants | |
37 | // ---------------------------------------------------------------------------- | |
38 | ||
f39f9220 | 39 | WXDLLEXPORT_DATA(extern const wxChar*) wxToolBarNameStr; |
10b959e3 JS |
40 | WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize; |
41 | WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition; | |
42 | ||
8a0681f9 | 43 | enum wxToolBarToolStyle |
1c383dba VZ |
44 | { |
45 | wxTOOL_STYLE_BUTTON = 1, | |
46 | wxTOOL_STYLE_SEPARATOR = 2, | |
47 | wxTOOL_STYLE_CONTROL | |
48 | }; | |
10b959e3 | 49 | |
1c383dba | 50 | // ---------------------------------------------------------------------------- |
8a0681f9 VZ |
51 | // wxToolBarTool is a toolbar element. |
52 | // | |
53 | // It has a unique id (except for the separators which always have id -1), the | |
54 | // style (telling whether it is a normal button, separator or a control), the | |
55 | // state (toggled or not, enabled or not) and short and long help strings. The | |
56 | // default implementations use the short help string for the tooltip text which | |
57 | // is popped up when the mouse pointer enters the tool and the long help string | |
58 | // for the applications status bar. | |
1c383dba | 59 | // ---------------------------------------------------------------------------- |
4fcd73bd | 60 | |
8a0681f9 | 61 | class WXDLLEXPORT wxToolBarToolBase : public wxObject |
10b959e3 | 62 | { |
1c383dba VZ |
63 | public: |
64 | // ctors & dtor | |
65 | // ------------ | |
66 | ||
8a0681f9 | 67 | wxToolBarToolBase(wxToolBarBase *tbar = (wxToolBarBase *)NULL, |
d9e2e4c2 | 68 | int toolid = wxID_SEPARATOR, |
e76c0b5f VZ |
69 | const wxString& label = wxEmptyString, |
70 | const wxBitmap& bmpNormal = wxNullBitmap, | |
71 | const wxBitmap& bmpDisabled = wxNullBitmap, | |
72 | wxItemKind kind = wxITEM_NORMAL, | |
8a0681f9 VZ |
73 | wxObject *clientData = (wxObject *) NULL, |
74 | const wxString& shortHelpString = wxEmptyString, | |
75 | const wxString& longHelpString = wxEmptyString) | |
e76c0b5f VZ |
76 | : m_label(label), |
77 | m_shortHelpString(shortHelpString), | |
8a0681f9 VZ |
78 | m_longHelpString(longHelpString) |
79 | { | |
80 | m_tbar = tbar; | |
d9e2e4c2 | 81 | m_id = toolid; |
8a0681f9 VZ |
82 | m_clientData = clientData; |
83 | ||
e76c0b5f VZ |
84 | m_bmpNormal = bmpNormal; |
85 | m_bmpDisabled = bmpDisabled; | |
86 | ||
87 | m_kind = kind; | |
8a0681f9 | 88 | |
8a0681f9 VZ |
89 | m_enabled = TRUE; |
90 | m_toggled = FALSE; | |
91 | ||
d9e2e4c2 | 92 | m_toolStyle = toolid == wxID_SEPARATOR ? wxTOOL_STYLE_SEPARATOR |
8a0681f9 VZ |
93 | : wxTOOL_STYLE_BUTTON; |
94 | } | |
95 | ||
96 | wxToolBarToolBase(wxToolBarBase *tbar, wxControl *control) | |
97 | { | |
98 | m_tbar = tbar; | |
99 | m_control = control; | |
100 | m_id = control->GetId(); | |
101 | ||
e76c0b5f VZ |
102 | m_kind = wxITEM_MAX; // invalid value |
103 | ||
8a0681f9 VZ |
104 | m_enabled = TRUE; |
105 | m_toggled = FALSE; | |
106 | ||
107 | m_toolStyle = wxTOOL_STYLE_CONTROL; | |
108 | } | |
109 | ||
110 | ~wxToolBarToolBase(); | |
1c383dba VZ |
111 | |
112 | // accessors | |
113 | // --------- | |
114 | ||
8a0681f9 VZ |
115 | // general |
116 | int GetId() const { return m_id; } | |
1c383dba VZ |
117 | |
118 | wxControl *GetControl() const | |
119 | { | |
8a0681f9 | 120 | wxASSERT_MSG( IsControl(), _T("this toolbar tool is not a control") ); |
1c383dba VZ |
121 | |
122 | return m_control; | |
123 | } | |
10b959e3 | 124 | |
8a0681f9 VZ |
125 | wxToolBarBase *GetToolBar() const { return m_tbar; } |
126 | ||
127 | // style | |
42d6e136 VZ |
128 | bool IsButton() const { return m_toolStyle == wxTOOL_STYLE_BUTTON; } |
129 | bool IsControl() const { return m_toolStyle == wxTOOL_STYLE_CONTROL; } | |
130 | bool IsSeparator() const { return m_toolStyle == wxTOOL_STYLE_SEPARATOR; } | |
8a0681f9 | 131 | int GetStyle() const { return m_toolStyle; } |
e76c0b5f VZ |
132 | wxItemKind GetKind() const |
133 | { | |
134 | wxASSERT_MSG( IsButton(), _T("only makes sense for buttons") ); | |
135 | ||
136 | return m_kind; | |
137 | } | |
8a0681f9 VZ |
138 | |
139 | // state | |
140 | bool IsEnabled() const { return m_enabled; } | |
141 | bool IsToggled() const { return m_toggled; } | |
e76c0b5f VZ |
142 | bool CanBeToggled() const |
143 | { return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; } | |
8a0681f9 VZ |
144 | |
145 | // attributes | |
e76c0b5f VZ |
146 | const wxBitmap& GetNormalBitmap() const { return m_bmpNormal; } |
147 | const wxBitmap& GetDisabledBitmap() const { return m_bmpDisabled; } | |
8a0681f9 VZ |
148 | |
149 | const wxBitmap& GetBitmap() const | |
3216dbf5 VZ |
150 | { return IsEnabled() ? GetNormalBitmap() : GetDisabledBitmap(); } |
151 | ||
152 | wxString GetLabel() const { return m_label; } | |
8a0681f9 VZ |
153 | |
154 | wxString GetShortHelp() const { return m_shortHelpString; } | |
155 | wxString GetLongHelp() const { return m_longHelpString; } | |
156 | ||
157 | wxObject *GetClientData() const | |
158 | { | |
6fd5fa4f VZ |
159 | if ( m_toolStyle == wxTOOL_STYLE_CONTROL ) |
160 | { | |
2063a4a0 | 161 | return (wxObject*)m_control->GetClientData(); |
6fd5fa4f VZ |
162 | } |
163 | else | |
164 | { | |
165 | return m_clientData; | |
166 | } | |
8a0681f9 VZ |
167 | } |
168 | ||
169 | // modifiers: return TRUE if the state really changed | |
170 | bool Enable(bool enable); | |
171 | bool Toggle(bool toggle); | |
172 | bool SetToggle(bool toggle); | |
173 | bool SetShortHelp(const wxString& help); | |
174 | bool SetLongHelp(const wxString& help); | |
175 | ||
176 | void Toggle() { Toggle(!IsToggled()); } | |
177 | ||
e76c0b5f VZ |
178 | void SetNormalBitmap(const wxBitmap& bmp) { m_bmpNormal = bmp; } |
179 | void SetDisabledBitmap(const wxBitmap& bmp) { m_bmpDisabled = bmp; } | |
3216dbf5 | 180 | |
c631abda | 181 | virtual void SetLabel(const wxString& label) { m_label = label; } |
8a0681f9 | 182 | |
6fd5fa4f VZ |
183 | void SetClientData(wxObject *clientData) |
184 | { | |
185 | if ( m_toolStyle == wxTOOL_STYLE_CONTROL ) | |
186 | { | |
187 | m_control->SetClientData(clientData); | |
188 | } | |
189 | else | |
190 | { | |
191 | m_clientData = clientData; | |
192 | } | |
193 | } | |
194 | ||
8a0681f9 VZ |
195 | // add tool to/remove it from a toolbar |
196 | virtual void Detach() { m_tbar = (wxToolBarBase *)NULL; } | |
197 | virtual void Attach(wxToolBarBase *tbar) { m_tbar = tbar; } | |
198 | ||
3216dbf5 VZ |
199 | // compatibility only, don't use |
200 | #if WXWIN_COMPATIBILITY_2_2 | |
201 | const wxBitmap& GetBitmap1() const { return GetNormalBitmap(); } | |
202 | const wxBitmap& GetBitmap2() const { return GetDisabledBitmap(); } | |
203 | ||
204 | void SetBitmap1(const wxBitmap& bmp) { SetNormalBitmap(bmp); } | |
205 | void SetBitmap2(const wxBitmap& bmp) { SetDisabledBitmap(bmp); } | |
206 | #endif // WXWIN_COMPATIBILITY_2_2 | |
207 | ||
8a0681f9 VZ |
208 | protected: |
209 | wxToolBarBase *m_tbar; // the toolbar to which we belong (may be NULL) | |
210 | ||
e76c0b5f VZ |
211 | // tool parameters |
212 | int m_toolStyle; // see enum wxToolBarToolStyle | |
213 | int m_id; // the tool id, wxID_SEPARATOR for separator | |
214 | wxItemKind m_kind; // for normal buttons may be wxITEM_NORMAL/CHECK/RADIO | |
1c383dba VZ |
215 | |
216 | // as controls have their own client data, no need to waste memory | |
217 | union | |
218 | { | |
219 | wxObject *m_clientData; | |
220 | wxControl *m_control; | |
221 | }; | |
222 | ||
8a0681f9 VZ |
223 | // tool state |
224 | bool m_toggled; | |
8a0681f9 | 225 | bool m_enabled; |
1c383dba | 226 | |
e76c0b5f VZ |
227 | // normal and disabled bitmaps for the tool, both can be invalid |
228 | wxBitmap m_bmpNormal; | |
229 | wxBitmap m_bmpDisabled; | |
1c383dba | 230 | |
3216dbf5 VZ |
231 | // the button label |
232 | wxString m_label; | |
233 | ||
8a0681f9 VZ |
234 | // short and long help strings |
235 | wxString m_shortHelpString; | |
236 | wxString m_longHelpString; | |
22f3361e | 237 | |
d6071228 | 238 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxToolBarToolBase) |
10b959e3 JS |
239 | }; |
240 | ||
8a0681f9 | 241 | // a list of toolbar tools |
f6bcfd97 | 242 | WX_DECLARE_EXPORTED_LIST(wxToolBarToolBase, wxToolBarToolsList); |
8a0681f9 | 243 | |
1c383dba VZ |
244 | // ---------------------------------------------------------------------------- |
245 | // the base class for all toolbars | |
246 | // ---------------------------------------------------------------------------- | |
247 | ||
10b959e3 JS |
248 | class WXDLLEXPORT wxToolBarBase : public wxControl |
249 | { | |
1c383dba VZ |
250 | public: |
251 | wxToolBarBase(); | |
8a0681f9 | 252 | virtual ~wxToolBarBase(); |
10b959e3 | 253 | |
1c383dba VZ |
254 | // toolbar construction |
255 | // -------------------- | |
10b959e3 | 256 | |
e76c0b5f VZ |
257 | // the full AddTool() function |
258 | // | |
259 | // If bmpDisabled is wxNullBitmap, a shadowed version of the normal bitmap | |
260 | // is created and used as the disabled image. | |
d9e2e4c2 | 261 | wxToolBarToolBase *AddTool(int toolid, |
e76c0b5f | 262 | const wxString& label, |
3ca6a5f0 | 263 | const wxBitmap& bitmap, |
e76c0b5f VZ |
264 | const wxBitmap& bmpDisabled, |
265 | wxItemKind kind = wxITEM_NORMAL, | |
266 | const wxString& shortHelp = wxEmptyString, | |
267 | const wxString& longHelp = wxEmptyString, | |
268 | wxObject *data = NULL) | |
3ca6a5f0 | 269 | { |
d9e2e4c2 | 270 | return DoAddTool(toolid, label, bitmap, bmpDisabled, kind, |
e76c0b5f | 271 | shortHelp, longHelp, data); |
3ca6a5f0 BP |
272 | } |
273 | ||
e76c0b5f | 274 | // the most common AddTool() version |
d9e2e4c2 | 275 | wxToolBarToolBase *AddTool(int toolid, |
e76c0b5f | 276 | const wxString& label, |
8a0681f9 | 277 | const wxBitmap& bitmap, |
e76c0b5f VZ |
278 | const wxString& shortHelp = wxEmptyString, |
279 | wxItemKind kind = wxITEM_NORMAL) | |
8a0681f9 | 280 | { |
d9e2e4c2 | 281 | return AddTool(toolid, label, bitmap, wxNullBitmap, kind, shortHelp); |
e76c0b5f VZ |
282 | } |
283 | ||
284 | // add a check tool, i.e. a tool which can be toggled | |
d9e2e4c2 | 285 | wxToolBarToolBase *AddCheckTool(int toolid, |
e76c0b5f VZ |
286 | const wxString& label, |
287 | const wxBitmap& bitmap, | |
288 | const wxBitmap& bmpDisabled = wxNullBitmap, | |
289 | const wxString& shortHelp = wxEmptyString, | |
290 | const wxString& longHelp = wxEmptyString, | |
291 | wxObject *data = NULL) | |
292 | { | |
d9e2e4c2 | 293 | return AddTool(toolid, label, bitmap, bmpDisabled, wxITEM_CHECK, |
e76c0b5f VZ |
294 | shortHelp, longHelp, data); |
295 | } | |
296 | ||
297 | // add a radio tool, i.e. a tool which can be toggled and releases any | |
298 | // other toggled radio tools in the same group when it happens | |
d9e2e4c2 | 299 | wxToolBarToolBase *AddRadioTool(int toolid, |
e76c0b5f VZ |
300 | const wxString& label, |
301 | const wxBitmap& bitmap, | |
302 | const wxBitmap& bmpDisabled = wxNullBitmap, | |
303 | const wxString& shortHelp = wxEmptyString, | |
304 | const wxString& longHelp = wxEmptyString, | |
305 | wxObject *data = NULL) | |
306 | { | |
d9e2e4c2 | 307 | return AddTool(toolid, label, bitmap, bmpDisabled, wxITEM_RADIO, |
e76c0b5f | 308 | shortHelp, longHelp, data); |
8a0681f9 VZ |
309 | } |
310 | ||
8a0681f9 VZ |
311 | |
312 | // insert the new tool at the given position, if pos == GetToolsCount(), it | |
313 | // is equivalent to AddTool() | |
314 | virtual wxToolBarToolBase *InsertTool | |
315 | ( | |
316 | size_t pos, | |
d9e2e4c2 | 317 | int toolid, |
e76c0b5f | 318 | const wxString& label, |
8a0681f9 | 319 | const wxBitmap& bitmap, |
e76c0b5f VZ |
320 | const wxBitmap& bmpDisabled = wxNullBitmap, |
321 | wxItemKind kind = wxITEM_NORMAL, | |
322 | const wxString& shortHelp = wxEmptyString, | |
323 | const wxString& longHelp = wxEmptyString, | |
324 | wxObject *clientData = NULL | |
8a0681f9 VZ |
325 | ); |
326 | ||
dd91da4e VZ |
327 | virtual wxToolBarToolBase *AddTool (wxToolBarToolBase *tool); |
328 | virtual wxToolBarToolBase *InsertTool (size_t pos, wxToolBarToolBase *tool); | |
329 | ||
8a0681f9 VZ |
330 | // add an arbitrary control to the toolbar, return TRUE if ok (notice that |
331 | // the control will be deleted by the toolbar and that it will also adjust | |
332 | // its position/size) | |
1c383dba VZ |
333 | // |
334 | // NB: the control should have toolbar as its parent | |
8a0681f9 VZ |
335 | virtual wxToolBarToolBase *AddControl(wxControl *control); |
336 | virtual wxToolBarToolBase *InsertControl(size_t pos, wxControl *control); | |
fba2d5e6 RR |
337 | |
338 | // get the control with the given id or return NULL | |
d9e2e4c2 | 339 | virtual wxControl *FindControl( int toolid ); |
10b959e3 | 340 | |
8a0681f9 VZ |
341 | // add a separator to the toolbar |
342 | virtual wxToolBarToolBase *AddSeparator(); | |
343 | virtual wxToolBarToolBase *InsertSeparator(size_t pos); | |
344 | ||
345 | // remove the tool from the toolbar: the caller is responsible for actually | |
346 | // deleting the pointer | |
d9e2e4c2 | 347 | virtual wxToolBarToolBase *RemoveTool(int toolid); |
8a0681f9 VZ |
348 | |
349 | // delete tool either by index or by position | |
350 | virtual bool DeleteToolByPos(size_t pos); | |
d9e2e4c2 | 351 | virtual bool DeleteTool(int toolid); |
8a0681f9 VZ |
352 | |
353 | // delete all tools | |
1c383dba | 354 | virtual void ClearTools(); |
10b959e3 | 355 | |
1c383dba VZ |
356 | // must be called after all buttons have been created to finish toolbar |
357 | // initialisation | |
8a0681f9 | 358 | virtual bool Realize(); |
10b959e3 | 359 | |
1c383dba VZ |
360 | // tools state |
361 | // ----------- | |
10b959e3 | 362 | |
d9e2e4c2 DE |
363 | virtual void EnableTool(int toolid, bool enable); |
364 | virtual void ToggleTool(int toolid, bool toggle); | |
b02da6b1 | 365 | |
1c383dba | 366 | // Set this to be togglable (or not) |
d9e2e4c2 | 367 | virtual void SetToggle(int toolid, bool toggle); |
8a0681f9 | 368 | |
6fd5fa4f | 369 | // set/get tools client data (not for controls) |
d9e2e4c2 DE |
370 | virtual wxObject *GetToolClientData(int toolid) const; |
371 | virtual void SetToolClientData(int toolid, wxObject *clientData); | |
10b959e3 | 372 | |
e6c96a7c JS |
373 | // returns tool pos, or wxNOT_FOUND if tool isn't found |
374 | virtual int GetToolPos(int id) const; | |
375 | ||
8a0681f9 | 376 | // return TRUE if the tool is toggled |
d9e2e4c2 | 377 | virtual bool GetToolState(int toolid) const; |
8a0681f9 | 378 | |
d9e2e4c2 | 379 | virtual bool GetToolEnabled(int toolid) const; |
81d66cf3 | 380 | |
d9e2e4c2 DE |
381 | virtual void SetToolShortHelp(int toolid, const wxString& helpString); |
382 | virtual wxString GetToolShortHelp(int toolid) const; | |
383 | virtual void SetToolLongHelp(int toolid, const wxString& helpString); | |
384 | virtual wxString GetToolLongHelp(int toolid) const; | |
10b959e3 | 385 | |
1c383dba VZ |
386 | // margins/packing/separation |
387 | // -------------------------- | |
10b959e3 | 388 | |
1c383dba VZ |
389 | virtual void SetMargins(int x, int y); |
390 | void SetMargins(const wxSize& size) | |
391 | { SetMargins((int) size.x, (int) size.y); } | |
8a0681f9 VZ |
392 | virtual void SetToolPacking(int packing) |
393 | { m_toolPacking = packing; } | |
394 | virtual void SetToolSeparation(int separation) | |
395 | { m_toolSeparation = separation; } | |
10b959e3 | 396 | |
e76c0b5f VZ |
397 | virtual wxSize GetToolMargins() const { return wxSize(m_xMargin, m_yMargin); } |
398 | virtual int GetToolPacking() const { return m_toolPacking; } | |
399 | virtual int GetToolSeparation() const { return m_toolSeparation; } | |
ef7eaedd | 400 | |
8a0681f9 VZ |
401 | // toolbar geometry |
402 | // ---------------- | |
403 | ||
404 | // set the number of toolbar rows | |
405 | virtual void SetRows(int nRows); | |
406 | ||
407 | // the toolbar can wrap - limit the number of columns or rows it may take | |
1c383dba VZ |
408 | void SetMaxRowsCols(int rows, int cols) |
409 | { m_maxRows = rows; m_maxCols = cols; } | |
410 | int GetMaxRows() const { return m_maxRows; } | |
411 | int GetMaxCols() const { return m_maxCols; } | |
10b959e3 | 412 | |
8a0681f9 VZ |
413 | // get/set the size of the bitmaps used by the toolbar: should be called |
414 | // before adding any tools to the toolbar | |
1c383dba VZ |
415 | virtual void SetToolBitmapSize(const wxSize& size) |
416 | { m_defaultWidth = size.x; m_defaultHeight = size.y; }; | |
417 | virtual wxSize GetToolBitmapSize() const | |
418 | { return wxSize(m_defaultWidth, m_defaultHeight); } | |
10b959e3 | 419 | |
8a0681f9 VZ |
420 | // the button size in some implementations is bigger than the bitmap size: |
421 | // get the total button size (by default the same as bitmap size) | |
1c383dba | 422 | virtual wxSize GetToolSize() const |
8a0681f9 | 423 | { return GetToolBitmapSize(); } ; |
10b959e3 | 424 | |
8a0681f9 VZ |
425 | // returns a (non separator) tool containing the point (x, y) or NULL if |
426 | // there is no tool at this point (corrdinates are client) | |
427 | virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, | |
428 | wxCoord y) const = 0; | |
429 | ||
d6071228 RD |
430 | // find the tool by id |
431 | wxToolBarToolBase *FindById(int toolid) const; | |
432 | ||
3216dbf5 VZ |
433 | // return TRUE if this is a vertical toolbar, otherwise FALSE |
434 | bool IsVertical() const { return HasFlag(wxTB_VERTICAL); } | |
435 | ||
e76c0b5f VZ |
436 | |
437 | // the old versions of the various methods kept for compatibility | |
438 | // don't use in the new code! | |
439 | // -------------------------------------------------------------- | |
440 | ||
d9e2e4c2 | 441 | wxToolBarToolBase *AddTool(int toolid, |
e76c0b5f VZ |
442 | const wxBitmap& bitmap, |
443 | const wxBitmap& bmpDisabled, | |
444 | bool toggle = FALSE, | |
445 | wxObject *clientData = NULL, | |
446 | const wxString& shortHelpString = wxEmptyString, | |
447 | const wxString& longHelpString = wxEmptyString) | |
448 | { | |
d9e2e4c2 | 449 | return AddTool(toolid, wxEmptyString, |
e76c0b5f VZ |
450 | bitmap, bmpDisabled, |
451 | toggle ? wxITEM_CHECK : wxITEM_NORMAL, | |
452 | shortHelpString, longHelpString, clientData); | |
453 | } | |
454 | ||
d9e2e4c2 | 455 | wxToolBarToolBase *AddTool(int toolid, |
e76c0b5f VZ |
456 | const wxBitmap& bitmap, |
457 | const wxString& shortHelpString = wxEmptyString, | |
458 | const wxString& longHelpString = wxEmptyString) | |
459 | { | |
d9e2e4c2 | 460 | return AddTool(toolid, wxEmptyString, |
e76c0b5f VZ |
461 | bitmap, wxNullBitmap, wxITEM_NORMAL, |
462 | shortHelpString, longHelpString, NULL); | |
463 | } | |
464 | ||
d9e2e4c2 | 465 | wxToolBarToolBase *AddTool(int toolid, |
e76c0b5f VZ |
466 | const wxBitmap& bitmap, |
467 | const wxBitmap& bmpDisabled, | |
468 | bool toggle, | |
469 | wxCoord xPos, | |
470 | wxCoord yPos = -1, | |
471 | wxObject *clientData = NULL, | |
472 | const wxString& shortHelp = wxEmptyString, | |
473 | const wxString& longHelp = wxEmptyString) | |
474 | { | |
d9e2e4c2 | 475 | return DoAddTool(toolid, wxEmptyString, bitmap, bmpDisabled, |
e76c0b5f VZ |
476 | toggle ? wxITEM_CHECK : wxITEM_NORMAL, |
477 | shortHelp, longHelp, clientData, xPos, yPos); | |
478 | } | |
479 | ||
480 | wxToolBarToolBase *InsertTool(size_t pos, | |
d9e2e4c2 | 481 | int toolid, |
e76c0b5f VZ |
482 | const wxBitmap& bitmap, |
483 | const wxBitmap& bmpDisabled = wxNullBitmap, | |
484 | bool toggle = FALSE, | |
485 | wxObject *clientData = NULL, | |
486 | const wxString& shortHelp = wxEmptyString, | |
487 | const wxString& longHelp = wxEmptyString) | |
488 | { | |
d9e2e4c2 | 489 | return InsertTool(pos, toolid, wxEmptyString, bitmap, bmpDisabled, |
e76c0b5f VZ |
490 | toggle ? wxITEM_CHECK : wxITEM_NORMAL, |
491 | shortHelp, longHelp, clientData); | |
492 | } | |
493 | ||
8a0681f9 VZ |
494 | // event handlers |
495 | // -------------- | |
10b959e3 | 496 | |
1c383dba | 497 | // NB: these functions are deprecated, use EVT_TOOL_XXX() instead! |
10b959e3 | 498 | |
1c383dba | 499 | // Only allow toggle if returns TRUE. Call when left button up. |
d9e2e4c2 | 500 | virtual bool OnLeftClick(int toolid, bool toggleDown); |
b02da6b1 | 501 | |
1c383dba | 502 | // Call when right button down. |
d9e2e4c2 | 503 | virtual void OnRightClick(int toolid, long x, long y); |
10b959e3 | 504 | |
1c383dba VZ |
505 | // Called when the mouse cursor enters a tool bitmap. |
506 | // Argument is -1 if mouse is exiting the toolbar. | |
d9e2e4c2 | 507 | virtual void OnMouseEnter(int toolid); |
1c383dba VZ |
508 | |
509 | // more deprecated functions | |
510 | // ------------------------- | |
511 | ||
e76c0b5f VZ |
512 | // use GetToolMargins() instead |
513 | wxSize GetMargins() const { return GetToolMargins(); } | |
514 | ||
1c383dba VZ |
515 | // implementation only from now on |
516 | // ------------------------------- | |
517 | ||
8a0681f9 | 518 | size_t GetToolsCount() const { return m_tools.GetCount(); } |
1c383dba | 519 | |
8a0681f9 | 520 | // Do the toolbar button updates (check for EVT_UPDATE_UI handlers) |
e39af974 | 521 | virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE) ; |
b02da6b1 | 522 | |
33b12a3a VZ |
523 | // don't want toolbars to accept the focus |
524 | virtual bool AcceptsFocus() const { return FALSE; } | |
4f430439 | 525 | |
8a0681f9 VZ |
526 | protected: |
527 | // to implement in derived classes | |
528 | // ------------------------------- | |
1c383dba | 529 | |
e76c0b5f VZ |
530 | // create a new toolbar tool and add it to the toolbar, this is typically |
531 | // implemented by just calling InsertTool() | |
532 | virtual wxToolBarToolBase *DoAddTool | |
533 | ( | |
d9e2e4c2 | 534 | int toolid, |
e76c0b5f VZ |
535 | const wxString& label, |
536 | const wxBitmap& bitmap, | |
537 | const wxBitmap& bmpDisabled, | |
538 | wxItemKind kind, | |
539 | const wxString& shortHelp = wxEmptyString, | |
540 | const wxString& longHelp = wxEmptyString, | |
541 | wxObject *clientData = NULL, | |
542 | wxCoord xPos = -1, | |
543 | wxCoord yPos = -1 | |
544 | ); | |
545 | ||
8a0681f9 VZ |
546 | // the tool is not yet inserted into m_tools list when this function is |
547 | // called and will only be added to it if this function succeeds | |
548 | virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool) = 0; | |
1c383dba | 549 | |
8a0681f9 VZ |
550 | // the tool is still in m_tools list when this function is called, it will |
551 | // only be deleted from it if it succeeds | |
552 | virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool) = 0; | |
1c383dba | 553 | |
8a0681f9 VZ |
554 | // called when the tools enabled flag changes |
555 | virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable) = 0; | |
1c383dba | 556 | |
8a0681f9 VZ |
557 | // called when the tool is toggled |
558 | virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle) = 0; | |
1c383dba | 559 | |
8a0681f9 VZ |
560 | // called when the tools "can be toggled" flag changes |
561 | virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle) = 0; | |
10b959e3 | 562 | |
8a0681f9 | 563 | // the functions to create toolbar tools |
d9e2e4c2 | 564 | virtual wxToolBarToolBase *CreateTool(int toolid, |
e76c0b5f VZ |
565 | const wxString& label, |
566 | const wxBitmap& bmpNormal, | |
567 | const wxBitmap& bmpDisabled, | |
568 | wxItemKind kind, | |
8a0681f9 | 569 | wxObject *clientData, |
e76c0b5f VZ |
570 | const wxString& shortHelp, |
571 | const wxString& longHelp) = 0; | |
572 | ||
8a0681f9 | 573 | virtual wxToolBarToolBase *CreateTool(wxControl *control) = 0; |
1c383dba | 574 | |
8a0681f9 VZ |
575 | // helper functions |
576 | // ---------------- | |
1c383dba | 577 | |
6bb7cee4 VZ |
578 | // un-toggle all buttons in the same radio group |
579 | void UnToggleRadioGroup(wxToolBarToolBase *tool); | |
580 | ||
8a0681f9 VZ |
581 | // the list of all our tools |
582 | wxToolBarToolsList m_tools; | |
1c383dba | 583 | |
8a0681f9 VZ |
584 | // the offset of the first tool |
585 | int m_xMargin; | |
586 | int m_yMargin; | |
10b959e3 | 587 | |
8a0681f9 VZ |
588 | // the maximum number of toolbar rows/columns |
589 | int m_maxRows; | |
590 | int m_maxCols; | |
1c383dba | 591 | |
8a0681f9 VZ |
592 | // the tool packing and separation |
593 | int m_toolPacking, | |
594 | m_toolSeparation; | |
1c383dba | 595 | |
8a0681f9 VZ |
596 | // the size of the toolbar bitmaps |
597 | wxCoord m_defaultWidth, m_defaultHeight; | |
1c383dba VZ |
598 | |
599 | private: | |
10b959e3 | 600 | DECLARE_EVENT_TABLE() |
fc7a2a60 | 601 | DECLARE_NO_COPY_CLASS(wxToolBarBase) |
10b959e3 JS |
602 | }; |
603 | ||
c229e50d JS |
604 | // Helper function for creating the image for disabled buttons |
605 | bool wxCreateGreyedImage(const wxImage& in, wxImage& out) ; | |
606 | ||
1e6feb95 VZ |
607 | #endif // wxUSE_TOOLBAR |
608 | ||
10b959e3 | 609 | #endif |
34138703 | 610 | // _WX_TBARBASE_H_ |
10b959e3 | 611 |