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