]> git.saurik.com Git - wxWidgets.git/blame - include/wx/tbarbase.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / tbarbase.h
CommitLineData
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
371a5b4e 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
10b959e3
JS
9/////////////////////////////////////////////////////////////////////////////
10
34138703
JS
11#ifndef _WX_TBARBASE_H_
12#define _WX_TBARBASE_H_
10b959e3 13
1c383dba
VZ
14// ----------------------------------------------------------------------------
15// headers
16// ----------------------------------------------------------------------------
17
10b959e3
JS
18#include "wx/defs.h"
19
1e6feb95
VZ
20#if wxUSE_TOOLBAR
21
10b959e3
JS
22#include "wx/bitmap.h"
23#include "wx/list.h"
24#include "wx/control.h"
25
b5dbe15d
VS
26class WXDLLIMPEXP_FWD_CORE wxToolBarBase;
27class WXDLLIMPEXP_FWD_CORE wxToolBarToolBase;
28class WXDLLIMPEXP_FWD_CORE wxImage;
1c383dba
VZ
29
30// ----------------------------------------------------------------------------
31// constants
32// ----------------------------------------------------------------------------
33
53a2db12
FM
34extern WXDLLIMPEXP_DATA_CORE(const char) wxToolBarNameStr[];
35extern WXDLLIMPEXP_DATA_CORE(const wxSize) wxDefaultSize;
36extern WXDLLIMPEXP_DATA_CORE(const wxPoint) wxDefaultPosition;
10b959e3 37
8a0681f9 38enum wxToolBarToolStyle
1c383dba
VZ
39{
40 wxTOOL_STYLE_BUTTON = 1,
41 wxTOOL_STYLE_SEPARATOR = 2,
42 wxTOOL_STYLE_CONTROL
43};
10b959e3 44
1c383dba 45// ----------------------------------------------------------------------------
8a0681f9
VZ
46// wxToolBarTool is a toolbar element.
47//
cb719f2e 48// It has a unique id (except for the separators which always have id wxID_ANY), the
8a0681f9
VZ
49// style (telling whether it is a normal button, separator or a control), the
50// state (toggled or not, enabled or not) and short and long help strings. The
51// default implementations use the short help string for the tooltip text which
52// is popped up when the mouse pointer enters the tool and the long help string
53// for the applications status bar.
1c383dba 54// ----------------------------------------------------------------------------
4fcd73bd 55
53a2db12 56class WXDLLIMPEXP_CORE wxToolBarToolBase : public wxObject
10b959e3 57{
1c383dba
VZ
58public:
59 // ctors & dtor
60 // ------------
61
a7daf7ea 62 // generic ctor for any kind of tool
d3b9f782 63 wxToolBarToolBase(wxToolBarBase *tbar = NULL,
d9e2e4c2 64 int toolid = wxID_SEPARATOR,
e76c0b5f
VZ
65 const wxString& label = wxEmptyString,
66 const wxBitmap& bmpNormal = wxNullBitmap,
67 const wxBitmap& bmpDisabled = wxNullBitmap,
68 wxItemKind kind = wxITEM_NORMAL,
d3b9f782 69 wxObject *clientData = NULL,
8a0681f9
VZ
70 const wxString& shortHelpString = wxEmptyString,
71 const wxString& longHelpString = wxEmptyString)
e76c0b5f
VZ
72 : m_label(label),
73 m_shortHelpString(shortHelpString),
a7daf7ea 74 m_longHelpString(longHelpString)
8a0681f9 75 {
a7daf7ea
VZ
76 Init
77 (
78 tbar,
79 toolid == wxID_SEPARATOR ? wxTOOL_STYLE_SEPARATOR
80 : wxTOOL_STYLE_BUTTON,
81 toolid == wxID_ANY ? wxWindow::NewControlId()
82 : toolid,
83 kind
84 );
85
8a0681f9
VZ
86 m_clientData = clientData;
87
e76c0b5f
VZ
88 m_bmpNormal = bmpNormal;
89 m_bmpDisabled = bmpDisabled;
8a0681f9
VZ
90 }
91
a7daf7ea 92 // ctor for controls only
cdb11cb9
VZ
93 wxToolBarToolBase(wxToolBarBase *tbar,
94 wxControl *control,
95 const wxString& label)
96 : m_label(label)
8a0681f9 97 {
a7daf7ea 98 Init(tbar, wxTOOL_STYLE_CONTROL, control->GetId(), wxITEM_MAX);
8a0681f9 99
a7daf7ea
VZ
100 m_control = control;
101 }
8a0681f9 102
a9a0ceca 103 virtual ~wxToolBarToolBase();
1c383dba
VZ
104
105 // accessors
106 // ---------
107
8a0681f9
VZ
108 // general
109 int GetId() const { return m_id; }
1c383dba
VZ
110
111 wxControl *GetControl() const
112 {
9a83f860 113 wxASSERT_MSG( IsControl(), wxT("this toolbar tool is not a control") );
1c383dba
VZ
114
115 return m_control;
116 }
10b959e3 117
8a0681f9
VZ
118 wxToolBarBase *GetToolBar() const { return m_tbar; }
119
cc260109
VZ
120 // style/kind
121 bool IsStretchable() const { return m_stretchable; }
42d6e136
VZ
122 bool IsButton() const { return m_toolStyle == wxTOOL_STYLE_BUTTON; }
123 bool IsControl() const { return m_toolStyle == wxTOOL_STYLE_CONTROL; }
124 bool IsSeparator() const { return m_toolStyle == wxTOOL_STYLE_SEPARATOR; }
cc260109 125 bool IsStretchableSpace() const { return IsSeparator() && IsStretchable(); }
8a0681f9 126 int GetStyle() const { return m_toolStyle; }
e76c0b5f
VZ
127 wxItemKind GetKind() const
128 {
9a83f860 129 wxASSERT_MSG( IsButton(), wxT("only makes sense for buttons") );
e76c0b5f
VZ
130
131 return m_kind;
132 }
8a0681f9 133
cc260109
VZ
134 void MakeStretchable()
135 {
136 wxASSERT_MSG( IsSeparator(), "only separators can be stretchable" );
137
138 m_stretchable = true;
139 }
140
8a0681f9
VZ
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
27e09084 154 const wxString& GetLabel() const { return m_label; }
8a0681f9 155
27e09084
VZ
156 const wxString& GetShortHelp() const { return m_shortHelpString; }
157 const wxString& GetLongHelp() const { return m_longHelpString; }
8a0681f9
VZ
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
cb719f2e 171 // modifiers: return true if the state really changed
fe21801d
SC
172 virtual bool Enable(bool enable);
173 virtual bool Toggle(bool toggle);
174 virtual bool SetToggle(bool toggle);
175 virtual bool SetShortHelp(const wxString& help);
176 virtual bool SetLongHelp(const wxString& help);
8a0681f9
VZ
177
178 void Toggle() { Toggle(!IsToggled()); }
179
fe21801d
SC
180 virtual void SetNormalBitmap(const wxBitmap& bmp) { m_bmpNormal = bmp; }
181 virtual 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 197 // add tool to/remove it from a toolbar
d3b9f782 198 virtual void Detach() { m_tbar = NULL; }
8a0681f9
VZ
199 virtual void Attach(wxToolBarBase *tbar) { m_tbar = tbar; }
200
4e8d90a7 201#if wxUSE_MENUS
a9a0ceca
VZ
202 // these methods are only for tools of wxITEM_DROPDOWN kind (but even such
203 // tools can have a NULL associated menu)
fe21801d 204 virtual void SetDropdownMenu(wxMenu *menu);
a9a0ceca 205 wxMenu *GetDropdownMenu() const { return m_dropdownMenu; }
4e8d90a7 206#endif
a9a0ceca 207
8a0681f9 208protected:
a7daf7ea
VZ
209 // common part of all ctors
210 void Init(wxToolBarBase *tbar,
211 wxToolBarToolStyle style,
212 int toolid,
213 wxItemKind kind)
214 {
215 m_tbar = tbar;
216 m_toolStyle = style;
217 m_id = toolid;
218 m_kind = kind;
219
220 m_clientData = NULL;
221
cc260109 222 m_stretchable = false;
a7daf7ea
VZ
223 m_toggled = false;
224 m_enabled = true;
225
4e8d90a7 226#if wxUSE_MENUS
a7daf7ea 227 m_dropdownMenu = NULL;
4e8d90a7
JS
228#endif
229
a7daf7ea
VZ
230 }
231
8a0681f9
VZ
232 wxToolBarBase *m_tbar; // the toolbar to which we belong (may be NULL)
233
e76c0b5f 234 // tool parameters
cc260109 235 wxToolBarToolStyle m_toolStyle;
cf2810aa 236 wxWindowIDRef m_id; // the tool id, wxID_SEPARATOR for separator
e76c0b5f 237 wxItemKind m_kind; // for normal buttons may be wxITEM_NORMAL/CHECK/RADIO
1c383dba
VZ
238
239 // as controls have their own client data, no need to waste memory
240 union
241 {
242 wxObject *m_clientData;
243 wxControl *m_control;
244 };
245
cc260109
VZ
246 // true if this tool is stretchable: currently is only value for separators
247 bool m_stretchable;
248
8a0681f9
VZ
249 // tool state
250 bool m_toggled;
8a0681f9 251 bool m_enabled;
1c383dba 252
e76c0b5f
VZ
253 // normal and disabled bitmaps for the tool, both can be invalid
254 wxBitmap m_bmpNormal;
255 wxBitmap m_bmpDisabled;
1c383dba 256
3216dbf5
VZ
257 // the button label
258 wxString m_label;
259
8a0681f9
VZ
260 // short and long help strings
261 wxString m_shortHelpString;
262 wxString m_longHelpString;
22f3361e 263
4e8d90a7 264#if wxUSE_MENUS
a9a0ceca 265 wxMenu *m_dropdownMenu;
4e8d90a7 266#endif
a9a0ceca 267
d6071228 268 DECLARE_DYNAMIC_CLASS_NO_COPY(wxToolBarToolBase)
10b959e3
JS
269};
270
8a0681f9 271// a list of toolbar tools
f6bcfd97 272WX_DECLARE_EXPORTED_LIST(wxToolBarToolBase, wxToolBarToolsList);
8a0681f9 273
1c383dba
VZ
274// ----------------------------------------------------------------------------
275// the base class for all toolbars
276// ----------------------------------------------------------------------------
277
53a2db12 278class WXDLLIMPEXP_CORE wxToolBarBase : public wxControl
10b959e3 279{
1c383dba
VZ
280public:
281 wxToolBarBase();
8a0681f9 282 virtual ~wxToolBarBase();
10b959e3 283
1c383dba
VZ
284 // toolbar construction
285 // --------------------
10b959e3 286
e76c0b5f
VZ
287 // the full AddTool() function
288 //
289 // If bmpDisabled is wxNullBitmap, a shadowed version of the normal bitmap
290 // is created and used as the disabled image.
d9e2e4c2 291 wxToolBarToolBase *AddTool(int toolid,
e76c0b5f 292 const wxString& label,
3ca6a5f0 293 const wxBitmap& bitmap,
e76c0b5f
VZ
294 const wxBitmap& bmpDisabled,
295 wxItemKind kind = wxITEM_NORMAL,
296 const wxString& shortHelp = wxEmptyString,
297 const wxString& longHelp = wxEmptyString,
298 wxObject *data = NULL)
3ca6a5f0 299 {
d9e2e4c2 300 return DoAddTool(toolid, label, bitmap, bmpDisabled, kind,
e76c0b5f 301 shortHelp, longHelp, data);
3ca6a5f0
BP
302 }
303
e76c0b5f 304 // the most common AddTool() version
d9e2e4c2 305 wxToolBarToolBase *AddTool(int toolid,
e76c0b5f 306 const wxString& label,
8a0681f9 307 const wxBitmap& bitmap,
e76c0b5f
VZ
308 const wxString& shortHelp = wxEmptyString,
309 wxItemKind kind = wxITEM_NORMAL)
8a0681f9 310 {
d9e2e4c2 311 return AddTool(toolid, label, bitmap, wxNullBitmap, kind, shortHelp);
e76c0b5f
VZ
312 }
313
314 // add a check tool, i.e. a tool which can be toggled
d9e2e4c2 315 wxToolBarToolBase *AddCheckTool(int toolid,
e76c0b5f
VZ
316 const wxString& label,
317 const wxBitmap& bitmap,
318 const wxBitmap& bmpDisabled = wxNullBitmap,
319 const wxString& shortHelp = wxEmptyString,
320 const wxString& longHelp = wxEmptyString,
321 wxObject *data = NULL)
322 {
d9e2e4c2 323 return AddTool(toolid, label, bitmap, bmpDisabled, wxITEM_CHECK,
e76c0b5f
VZ
324 shortHelp, longHelp, data);
325 }
326
327 // add a radio tool, i.e. a tool which can be toggled and releases any
328 // other toggled radio tools in the same group when it happens
d9e2e4c2 329 wxToolBarToolBase *AddRadioTool(int toolid,
e76c0b5f
VZ
330 const wxString& label,
331 const wxBitmap& bitmap,
332 const wxBitmap& bmpDisabled = wxNullBitmap,
333 const wxString& shortHelp = wxEmptyString,
334 const wxString& longHelp = wxEmptyString,
335 wxObject *data = NULL)
336 {
d9e2e4c2 337 return AddTool(toolid, label, bitmap, bmpDisabled, wxITEM_RADIO,
e76c0b5f 338 shortHelp, longHelp, data);
8a0681f9
VZ
339 }
340
8a0681f9
VZ
341
342 // insert the new tool at the given position, if pos == GetToolsCount(), it
343 // is equivalent to AddTool()
344 virtual wxToolBarToolBase *InsertTool
345 (
346 size_t pos,
d9e2e4c2 347 int toolid,
e76c0b5f 348 const wxString& label,
8a0681f9 349 const wxBitmap& bitmap,
e76c0b5f
VZ
350 const wxBitmap& bmpDisabled = wxNullBitmap,
351 wxItemKind kind = wxITEM_NORMAL,
352 const wxString& shortHelp = wxEmptyString,
353 const wxString& longHelp = wxEmptyString,
354 wxObject *clientData = NULL
8a0681f9
VZ
355 );
356
dd91da4e
VZ
357 virtual wxToolBarToolBase *AddTool (wxToolBarToolBase *tool);
358 virtual wxToolBarToolBase *InsertTool (size_t pos, wxToolBarToolBase *tool);
359
cdb11cb9
VZ
360 // add an arbitrary control to the toolbar (notice that the control will be
361 // deleted by the toolbar and that it will also adjust its position/size)
1c383dba 362 //
cdb11cb9 363 // the label is optional and, if specified, will be shown near the control
1c383dba 364 // NB: the control should have toolbar as its parent
cdb11cb9
VZ
365 virtual wxToolBarToolBase *
366 AddControl(wxControl *control, const wxString& label = wxEmptyString);
367
368 virtual wxToolBarToolBase *
369 InsertControl(size_t pos, wxControl *control,
370 const wxString& label = wxEmptyString);
cb719f2e 371
fba2d5e6 372 // get the control with the given id or return NULL
d9e2e4c2 373 virtual wxControl *FindControl( int toolid );
10b959e3 374
8a0681f9
VZ
375 // add a separator to the toolbar
376 virtual wxToolBarToolBase *AddSeparator();
377 virtual wxToolBarToolBase *InsertSeparator(size_t pos);
378
cc260109
VZ
379 // add a stretchable space to the toolbar: this is similar to a separator
380 // except that it's always blank and that all the extra space the toolbar
381 // has is [equally] distributed among the stretchable spaces in it
382 virtual wxToolBarToolBase *AddStretchableSpace();
383 virtual wxToolBarToolBase *InsertStretchableSpace(size_t pos);
384
8a0681f9
VZ
385 // remove the tool from the toolbar: the caller is responsible for actually
386 // deleting the pointer
d9e2e4c2 387 virtual wxToolBarToolBase *RemoveTool(int toolid);
8a0681f9
VZ
388
389 // delete tool either by index or by position
390 virtual bool DeleteToolByPos(size_t pos);
d9e2e4c2 391 virtual bool DeleteTool(int toolid);
8a0681f9
VZ
392
393 // delete all tools
1c383dba 394 virtual void ClearTools();
10b959e3 395
1c383dba
VZ
396 // must be called after all buttons have been created to finish toolbar
397 // initialisation
bb2212e6
VZ
398 //
399 // derived class versions should call the base one first, before doing
400 // platform-specific stuff
8a0681f9 401 virtual bool Realize();
10b959e3 402
1c383dba
VZ
403 // tools state
404 // -----------
10b959e3 405
d9e2e4c2
DE
406 virtual void EnableTool(int toolid, bool enable);
407 virtual void ToggleTool(int toolid, bool toggle);
b02da6b1 408
1c383dba 409 // Set this to be togglable (or not)
d9e2e4c2 410 virtual void SetToggle(int toolid, bool toggle);
8a0681f9 411
6fd5fa4f 412 // set/get tools client data (not for controls)
d9e2e4c2
DE
413 virtual wxObject *GetToolClientData(int toolid) const;
414 virtual void SetToolClientData(int toolid, wxObject *clientData);
10b959e3 415
e6c96a7c
JS
416 // returns tool pos, or wxNOT_FOUND if tool isn't found
417 virtual int GetToolPos(int id) const;
418
cb719f2e 419 // return true if the tool is toggled
d9e2e4c2 420 virtual bool GetToolState(int toolid) const;
8a0681f9 421
d9e2e4c2 422 virtual bool GetToolEnabled(int toolid) const;
81d66cf3 423
d9e2e4c2
DE
424 virtual void SetToolShortHelp(int toolid, const wxString& helpString);
425 virtual wxString GetToolShortHelp(int toolid) const;
426 virtual void SetToolLongHelp(int toolid, const wxString& helpString);
427 virtual wxString GetToolLongHelp(int toolid) const;
10b959e3 428
6cd67472
RD
429 virtual void SetToolNormalBitmap(int WXUNUSED(id),
430 const wxBitmap& WXUNUSED(bitmap)) {}
431 virtual void SetToolDisabledBitmap(int WXUNUSED(id),
432 const wxBitmap& WXUNUSED(bitmap)) {}
bbd321ff 433
25af884d 434
1c383dba
VZ
435 // margins/packing/separation
436 // --------------------------
10b959e3 437
1c383dba
VZ
438 virtual void SetMargins(int x, int y);
439 void SetMargins(const wxSize& size)
440 { SetMargins((int) size.x, (int) size.y); }
8a0681f9
VZ
441 virtual void SetToolPacking(int packing)
442 { m_toolPacking = packing; }
443 virtual void SetToolSeparation(int separation)
444 { m_toolSeparation = separation; }
10b959e3 445
e76c0b5f
VZ
446 virtual wxSize GetToolMargins() const { return wxSize(m_xMargin, m_yMargin); }
447 virtual int GetToolPacking() const { return m_toolPacking; }
448 virtual int GetToolSeparation() const { return m_toolSeparation; }
ef7eaedd 449
8a0681f9
VZ
450 // toolbar geometry
451 // ----------------
452
453 // set the number of toolbar rows
454 virtual void SetRows(int nRows);
455
456 // the toolbar can wrap - limit the number of columns or rows it may take
1c383dba
VZ
457 void SetMaxRowsCols(int rows, int cols)
458 { m_maxRows = rows; m_maxCols = cols; }
459 int GetMaxRows() const { return m_maxRows; }
460 int GetMaxCols() const { return m_maxCols; }
10b959e3 461
8a0681f9
VZ
462 // get/set the size of the bitmaps used by the toolbar: should be called
463 // before adding any tools to the toolbar
1c383dba 464 virtual void SetToolBitmapSize(const wxSize& size)
47b378bd 465 { m_defaultWidth = size.x; m_defaultHeight = size.y; }
1c383dba
VZ
466 virtual wxSize GetToolBitmapSize() const
467 { return wxSize(m_defaultWidth, m_defaultHeight); }
10b959e3 468
8a0681f9
VZ
469 // the button size in some implementations is bigger than the bitmap size:
470 // get the total button size (by default the same as bitmap size)
1c383dba 471 virtual wxSize GetToolSize() const
47b378bd 472 { return GetToolBitmapSize(); }
10b959e3 473
8a0681f9 474 // returns a (non separator) tool containing the point (x, y) or NULL if
d9384bfb 475 // there is no tool at this point (coordinates are client)
8a0681f9
VZ
476 virtual wxToolBarToolBase *FindToolForPosition(wxCoord x,
477 wxCoord y) const = 0;
478
d6071228
RD
479 // find the tool by id
480 wxToolBarToolBase *FindById(int toolid) const;
481
cb719f2e 482 // return true if this is a vertical toolbar, otherwise false
25af884d 483 bool IsVertical() const;
3216dbf5 484
e79f02bd
VZ
485 // these methods allow to access tools by their index in the toolbar
486 size_t GetToolsCount() const { return m_tools.GetCount(); }
487 const wxToolBarToolBase *GetToolByPos(int pos) const { return m_tools[pos]; }
488
bbe28fbb 489#if WXWIN_COMPATIBILITY_2_8
e76c0b5f
VZ
490 // the old versions of the various methods kept for compatibility
491 // don't use in the new code!
492 // --------------------------------------------------------------
bbe28fbb 493 wxDEPRECATED_INLINE(
d9e2e4c2 494 wxToolBarToolBase *AddTool(int toolid,
e76c0b5f
VZ
495 const wxBitmap& bitmap,
496 const wxBitmap& bmpDisabled,
cb719f2e 497 bool toggle = false,
e76c0b5f
VZ
498 wxObject *clientData = NULL,
499 const wxString& shortHelpString = wxEmptyString,
500 const wxString& longHelpString = wxEmptyString)
bbe28fbb 501 ,
d9e2e4c2 502 return AddTool(toolid, wxEmptyString,
e76c0b5f
VZ
503 bitmap, bmpDisabled,
504 toggle ? wxITEM_CHECK : wxITEM_NORMAL,
505 shortHelpString, longHelpString, clientData);
bbe28fbb
PC
506 )
507 wxDEPRECATED_INLINE(
d9e2e4c2 508 wxToolBarToolBase *AddTool(int toolid,
e76c0b5f
VZ
509 const wxBitmap& bitmap,
510 const wxString& shortHelpString = wxEmptyString,
511 const wxString& longHelpString = wxEmptyString)
bbe28fbb 512 ,
d9e2e4c2 513 return AddTool(toolid, wxEmptyString,
e76c0b5f
VZ
514 bitmap, wxNullBitmap, wxITEM_NORMAL,
515 shortHelpString, longHelpString, NULL);
bbe28fbb
PC
516 )
517 wxDEPRECATED_INLINE(
d9e2e4c2 518 wxToolBarToolBase *AddTool(int toolid,
e76c0b5f
VZ
519 const wxBitmap& bitmap,
520 const wxBitmap& bmpDisabled,
521 bool toggle,
522 wxCoord xPos,
cb719f2e 523 wxCoord yPos = wxDefaultCoord,
e76c0b5f
VZ
524 wxObject *clientData = NULL,
525 const wxString& shortHelp = wxEmptyString,
526 const wxString& longHelp = wxEmptyString)
bbe28fbb 527 ,
d9e2e4c2 528 return DoAddTool(toolid, wxEmptyString, bitmap, bmpDisabled,
e76c0b5f
VZ
529 toggle ? wxITEM_CHECK : wxITEM_NORMAL,
530 shortHelp, longHelp, clientData, xPos, yPos);
bbe28fbb
PC
531 )
532 wxDEPRECATED_INLINE(
e76c0b5f 533 wxToolBarToolBase *InsertTool(size_t pos,
d9e2e4c2 534 int toolid,
e76c0b5f
VZ
535 const wxBitmap& bitmap,
536 const wxBitmap& bmpDisabled = wxNullBitmap,
cb719f2e 537 bool toggle = false,
e76c0b5f
VZ
538 wxObject *clientData = NULL,
539 const wxString& shortHelp = wxEmptyString,
540 const wxString& longHelp = wxEmptyString)
bbe28fbb 541 ,
d9e2e4c2 542 return InsertTool(pos, toolid, wxEmptyString, bitmap, bmpDisabled,
e76c0b5f
VZ
543 toggle ? wxITEM_CHECK : wxITEM_NORMAL,
544 shortHelp, longHelp, clientData);
bbe28fbb
PC
545 )
546#endif // WXWIN_COMPATIBILITY_2_8
e76c0b5f 547
8a0681f9
VZ
548 // event handlers
549 // --------------
10b959e3 550
1c383dba 551 // NB: these functions are deprecated, use EVT_TOOL_XXX() instead!
10b959e3 552
cb719f2e 553 // Only allow toggle if returns true. Call when left button up.
d9e2e4c2 554 virtual bool OnLeftClick(int toolid, bool toggleDown);
b02da6b1 555
1c383dba 556 // Call when right button down.
d9e2e4c2 557 virtual void OnRightClick(int toolid, long x, long y);
10b959e3 558
1c383dba 559 // Called when the mouse cursor enters a tool bitmap.
cb719f2e 560 // Argument is wxID_ANY if mouse is exiting the toolbar.
d9e2e4c2 561 virtual void OnMouseEnter(int toolid);
1c383dba
VZ
562
563 // more deprecated functions
564 // -------------------------
565
e76c0b5f
VZ
566 // use GetToolMargins() instead
567 wxSize GetMargins() const { return GetToolMargins(); }
568
f2b6dd8c
RD
569 // Tool factories,
570 // helper functions to create toolbar tools
571 // -------------------------
572 virtual wxToolBarToolBase *CreateTool(int toolid,
573 const wxString& label,
574 const wxBitmap& bmpNormal,
575 const wxBitmap& bmpDisabled = wxNullBitmap,
576 wxItemKind kind = wxITEM_NORMAL,
577 wxObject *clientData = NULL,
578 const wxString& shortHelp = wxEmptyString,
579 const wxString& longHelp = wxEmptyString) = 0;
580
581 virtual wxToolBarToolBase *CreateTool(wxControl *control,
582 const wxString& label) = 0;
583
584 // this one is not virtual but just a simple helper/wrapper around
585 // CreateTool() for separators
586 wxToolBarToolBase *CreateSeparator()
587 {
588 return CreateTool(wxID_SEPARATOR,
589 wxEmptyString,
590 wxNullBitmap, wxNullBitmap,
591 wxITEM_SEPARATOR, NULL,
592 wxEmptyString, wxEmptyString);
593 }
594
595
1c383dba
VZ
596 // implementation only from now on
597 // -------------------------------
598
8a0681f9 599 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
e39af974 600 virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE) ;
b02da6b1 601
33b12a3a 602 // don't want toolbars to accept the focus
cb719f2e 603 virtual bool AcceptsFocus() const { return false; }
4f430439 604
4e8d90a7 605#if wxUSE_MENUS
a9a0ceca
VZ
606 // Set dropdown menu
607 bool SetDropdownMenu(int toolid, wxMenu *menu);
4e8d90a7 608#endif
a9a0ceca 609
8a0681f9 610protected:
f75b1bd3
VZ
611 // choose the default border for this window
612 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
613
8a0681f9
VZ
614 // to implement in derived classes
615 // -------------------------------
1c383dba 616
e76c0b5f
VZ
617 // create a new toolbar tool and add it to the toolbar, this is typically
618 // implemented by just calling InsertTool()
619 virtual wxToolBarToolBase *DoAddTool
620 (
d9e2e4c2 621 int toolid,
e76c0b5f
VZ
622 const wxString& label,
623 const wxBitmap& bitmap,
624 const wxBitmap& bmpDisabled,
625 wxItemKind kind,
626 const wxString& shortHelp = wxEmptyString,
627 const wxString& longHelp = wxEmptyString,
628 wxObject *clientData = NULL,
cb719f2e
WS
629 wxCoord xPos = wxDefaultCoord,
630 wxCoord yPos = wxDefaultCoord
e76c0b5f
VZ
631 );
632
8a0681f9
VZ
633 // the tool is not yet inserted into m_tools list when this function is
634 // called and will only be added to it if this function succeeds
635 virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool) = 0;
1c383dba 636
8a0681f9
VZ
637 // the tool is still in m_tools list when this function is called, it will
638 // only be deleted from it if it succeeds
639 virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool) = 0;
1c383dba 640
8a0681f9
VZ
641 // called when the tools enabled flag changes
642 virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable) = 0;
1c383dba 643
8a0681f9
VZ
644 // called when the tool is toggled
645 virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle) = 0;
1c383dba 646
8a0681f9
VZ
647 // called when the tools "can be toggled" flag changes
648 virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle) = 0;
10b959e3 649
cc260109 650
8a0681f9
VZ
651 // helper functions
652 // ----------------
1c383dba 653
d408730c
VZ
654 // call this from derived class ctor/Create() to ensure that we have either
655 // wxTB_HORIZONTAL or wxTB_VERTICAL style, there is a lot of existing code
656 // which randomly checks either one or the other of them and gets confused
657 // if neither is set (and making one of them 0 is not an option neither as
658 // then the existing tests would break down)
659 void FixupStyle();
660
6bb7cee4
VZ
661 // un-toggle all buttons in the same radio group
662 void UnToggleRadioGroup(wxToolBarToolBase *tool);
663
bb2212e6
VZ
664 // make the size of the buttons big enough to fit the largest bitmap size
665 void AdjustToolBitmapSize();
666
26007761
VZ
667 // calls InsertTool() and deletes the tool if inserting it failed
668 wxToolBarToolBase *DoInsertNewTool(size_t pos, wxToolBarToolBase *tool)
669 {
670 if ( !InsertTool(pos, tool) )
671 {
672 delete tool;
673 return NULL;
674 }
675
676 return tool;
677 }
bb2212e6 678
8a0681f9
VZ
679 // the list of all our tools
680 wxToolBarToolsList m_tools;
1c383dba 681
8a0681f9
VZ
682 // the offset of the first tool
683 int m_xMargin;
684 int m_yMargin;
10b959e3 685
8a0681f9
VZ
686 // the maximum number of toolbar rows/columns
687 int m_maxRows;
688 int m_maxCols;
1c383dba 689
8a0681f9
VZ
690 // the tool packing and separation
691 int m_toolPacking,
692 m_toolSeparation;
1c383dba 693
8a0681f9
VZ
694 // the size of the toolbar bitmaps
695 wxCoord m_defaultWidth, m_defaultHeight;
1c383dba
VZ
696
697private:
10b959e3 698 DECLARE_EVENT_TABLE()
c0c133e1 699 wxDECLARE_NO_COPY_CLASS(wxToolBarBase);
10b959e3
JS
700};
701
9ac43913
VZ
702// deprecated function for creating the image for disabled buttons, use
703// wxImage::ConvertToGreyscale() instead
704#if WXWIN_COMPATIBILITY_2_8
705
706wxDEPRECATED( bool wxCreateGreyedImage(const wxImage& in, wxImage& out) );
707
708#endif // WXWIN_COMPATIBILITY_2_8
709
c229e50d 710
1e6feb95
VZ
711#endif // wxUSE_TOOLBAR
712
10b959e3 713#endif
34138703 714 // _WX_TBARBASE_H_
10b959e3 715