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