]> git.saurik.com Git - wxWidgets.git/blame - include/wx/tbarbase.h
Correct check for MSVC version in wxUSE_GRAPHICS_CONTEXT definition.
[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
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
VZ
205 wxMenu *GetDropdownMenu() const { return m_dropdownMenu; }
206
8a0681f9 207protected:
a7daf7ea
VZ
208 // common part of all ctors
209 void Init(wxToolBarBase *tbar,
210 wxToolBarToolStyle style,
211 int toolid,
212 wxItemKind kind)
213 {
214 m_tbar = tbar;
215 m_toolStyle = style;
216 m_id = toolid;
217 m_kind = kind;
218
219 m_clientData = NULL;
220
cc260109 221 m_stretchable = false;
a7daf7ea
VZ
222 m_toggled = false;
223 m_enabled = true;
224
225 m_dropdownMenu = NULL;
226 }
227
8a0681f9
VZ
228 wxToolBarBase *m_tbar; // the toolbar to which we belong (may be NULL)
229
e76c0b5f 230 // tool parameters
cc260109 231 wxToolBarToolStyle m_toolStyle;
cf2810aa 232 wxWindowIDRef m_id; // the tool id, wxID_SEPARATOR for separator
e76c0b5f 233 wxItemKind m_kind; // for normal buttons may be wxITEM_NORMAL/CHECK/RADIO
1c383dba
VZ
234
235 // as controls have their own client data, no need to waste memory
236 union
237 {
238 wxObject *m_clientData;
239 wxControl *m_control;
240 };
241
cc260109
VZ
242 // true if this tool is stretchable: currently is only value for separators
243 bool m_stretchable;
244
8a0681f9
VZ
245 // tool state
246 bool m_toggled;
8a0681f9 247 bool m_enabled;
1c383dba 248
e76c0b5f
VZ
249 // normal and disabled bitmaps for the tool, both can be invalid
250 wxBitmap m_bmpNormal;
251 wxBitmap m_bmpDisabled;
1c383dba 252
3216dbf5
VZ
253 // the button label
254 wxString m_label;
255
8a0681f9
VZ
256 // short and long help strings
257 wxString m_shortHelpString;
258 wxString m_longHelpString;
22f3361e 259
a9a0ceca
VZ
260 wxMenu *m_dropdownMenu;
261
d6071228 262 DECLARE_DYNAMIC_CLASS_NO_COPY(wxToolBarToolBase)
10b959e3
JS
263};
264
8a0681f9 265// a list of toolbar tools
f6bcfd97 266WX_DECLARE_EXPORTED_LIST(wxToolBarToolBase, wxToolBarToolsList);
8a0681f9 267
1c383dba
VZ
268// ----------------------------------------------------------------------------
269// the base class for all toolbars
270// ----------------------------------------------------------------------------
271
53a2db12 272class WXDLLIMPEXP_CORE wxToolBarBase : public wxControl
10b959e3 273{
1c383dba
VZ
274public:
275 wxToolBarBase();
8a0681f9 276 virtual ~wxToolBarBase();
10b959e3 277
1c383dba
VZ
278 // toolbar construction
279 // --------------------
10b959e3 280
e76c0b5f
VZ
281 // the full AddTool() function
282 //
283 // If bmpDisabled is wxNullBitmap, a shadowed version of the normal bitmap
284 // is created and used as the disabled image.
d9e2e4c2 285 wxToolBarToolBase *AddTool(int toolid,
e76c0b5f 286 const wxString& label,
3ca6a5f0 287 const wxBitmap& bitmap,
e76c0b5f
VZ
288 const wxBitmap& bmpDisabled,
289 wxItemKind kind = wxITEM_NORMAL,
290 const wxString& shortHelp = wxEmptyString,
291 const wxString& longHelp = wxEmptyString,
292 wxObject *data = NULL)
3ca6a5f0 293 {
d9e2e4c2 294 return DoAddTool(toolid, label, bitmap, bmpDisabled, kind,
e76c0b5f 295 shortHelp, longHelp, data);
3ca6a5f0
BP
296 }
297
e76c0b5f 298 // the most common AddTool() version
d9e2e4c2 299 wxToolBarToolBase *AddTool(int toolid,
e76c0b5f 300 const wxString& label,
8a0681f9 301 const wxBitmap& bitmap,
e76c0b5f
VZ
302 const wxString& shortHelp = wxEmptyString,
303 wxItemKind kind = wxITEM_NORMAL)
8a0681f9 304 {
d9e2e4c2 305 return AddTool(toolid, label, bitmap, wxNullBitmap, kind, shortHelp);
e76c0b5f
VZ
306 }
307
308 // add a check tool, i.e. a tool which can be toggled
d9e2e4c2 309 wxToolBarToolBase *AddCheckTool(int toolid,
e76c0b5f
VZ
310 const wxString& label,
311 const wxBitmap& bitmap,
312 const wxBitmap& bmpDisabled = wxNullBitmap,
313 const wxString& shortHelp = wxEmptyString,
314 const wxString& longHelp = wxEmptyString,
315 wxObject *data = NULL)
316 {
d9e2e4c2 317 return AddTool(toolid, label, bitmap, bmpDisabled, wxITEM_CHECK,
e76c0b5f
VZ
318 shortHelp, longHelp, data);
319 }
320
321 // add a radio tool, i.e. a tool which can be toggled and releases any
322 // other toggled radio tools in the same group when it happens
d9e2e4c2 323 wxToolBarToolBase *AddRadioTool(int toolid,
e76c0b5f
VZ
324 const wxString& label,
325 const wxBitmap& bitmap,
326 const wxBitmap& bmpDisabled = wxNullBitmap,
327 const wxString& shortHelp = wxEmptyString,
328 const wxString& longHelp = wxEmptyString,
329 wxObject *data = NULL)
330 {
d9e2e4c2 331 return AddTool(toolid, label, bitmap, bmpDisabled, wxITEM_RADIO,
e76c0b5f 332 shortHelp, longHelp, data);
8a0681f9
VZ
333 }
334
8a0681f9
VZ
335
336 // insert the new tool at the given position, if pos == GetToolsCount(), it
337 // is equivalent to AddTool()
338 virtual wxToolBarToolBase *InsertTool
339 (
340 size_t pos,
d9e2e4c2 341 int toolid,
e76c0b5f 342 const wxString& label,
8a0681f9 343 const wxBitmap& bitmap,
e76c0b5f
VZ
344 const wxBitmap& bmpDisabled = wxNullBitmap,
345 wxItemKind kind = wxITEM_NORMAL,
346 const wxString& shortHelp = wxEmptyString,
347 const wxString& longHelp = wxEmptyString,
348 wxObject *clientData = NULL
8a0681f9
VZ
349 );
350
dd91da4e
VZ
351 virtual wxToolBarToolBase *AddTool (wxToolBarToolBase *tool);
352 virtual wxToolBarToolBase *InsertTool (size_t pos, wxToolBarToolBase *tool);
353
cdb11cb9
VZ
354 // add an arbitrary control to the toolbar (notice that the control will be
355 // deleted by the toolbar and that it will also adjust its position/size)
1c383dba 356 //
cdb11cb9 357 // the label is optional and, if specified, will be shown near the control
1c383dba 358 // NB: the control should have toolbar as its parent
cdb11cb9
VZ
359 virtual wxToolBarToolBase *
360 AddControl(wxControl *control, const wxString& label = wxEmptyString);
361
362 virtual wxToolBarToolBase *
363 InsertControl(size_t pos, wxControl *control,
364 const wxString& label = wxEmptyString);
cb719f2e 365
fba2d5e6 366 // get the control with the given id or return NULL
d9e2e4c2 367 virtual wxControl *FindControl( int toolid );
10b959e3 368
8a0681f9
VZ
369 // add a separator to the toolbar
370 virtual wxToolBarToolBase *AddSeparator();
371 virtual wxToolBarToolBase *InsertSeparator(size_t pos);
372
cc260109
VZ
373 // add a stretchable space to the toolbar: this is similar to a separator
374 // except that it's always blank and that all the extra space the toolbar
375 // has is [equally] distributed among the stretchable spaces in it
376 virtual wxToolBarToolBase *AddStretchableSpace();
377 virtual wxToolBarToolBase *InsertStretchableSpace(size_t pos);
378
8a0681f9
VZ
379 // remove the tool from the toolbar: the caller is responsible for actually
380 // deleting the pointer
d9e2e4c2 381 virtual wxToolBarToolBase *RemoveTool(int toolid);
8a0681f9
VZ
382
383 // delete tool either by index or by position
384 virtual bool DeleteToolByPos(size_t pos);
d9e2e4c2 385 virtual bool DeleteTool(int toolid);
8a0681f9
VZ
386
387 // delete all tools
1c383dba 388 virtual void ClearTools();
10b959e3 389
1c383dba
VZ
390 // must be called after all buttons have been created to finish toolbar
391 // initialisation
bb2212e6
VZ
392 //
393 // derived class versions should call the base one first, before doing
394 // platform-specific stuff
8a0681f9 395 virtual bool Realize();
10b959e3 396
1c383dba
VZ
397 // tools state
398 // -----------
10b959e3 399
d9e2e4c2
DE
400 virtual void EnableTool(int toolid, bool enable);
401 virtual void ToggleTool(int toolid, bool toggle);
b02da6b1 402
1c383dba 403 // Set this to be togglable (or not)
d9e2e4c2 404 virtual void SetToggle(int toolid, bool toggle);
8a0681f9 405
6fd5fa4f 406 // set/get tools client data (not for controls)
d9e2e4c2
DE
407 virtual wxObject *GetToolClientData(int toolid) const;
408 virtual void SetToolClientData(int toolid, wxObject *clientData);
10b959e3 409
e6c96a7c
JS
410 // returns tool pos, or wxNOT_FOUND if tool isn't found
411 virtual int GetToolPos(int id) const;
412
cb719f2e 413 // return true if the tool is toggled
d9e2e4c2 414 virtual bool GetToolState(int toolid) const;
8a0681f9 415
d9e2e4c2 416 virtual bool GetToolEnabled(int toolid) const;
81d66cf3 417
d9e2e4c2
DE
418 virtual void SetToolShortHelp(int toolid, const wxString& helpString);
419 virtual wxString GetToolShortHelp(int toolid) const;
420 virtual void SetToolLongHelp(int toolid, const wxString& helpString);
421 virtual wxString GetToolLongHelp(int toolid) const;
10b959e3 422
6cd67472
RD
423 virtual void SetToolNormalBitmap(int WXUNUSED(id),
424 const wxBitmap& WXUNUSED(bitmap)) {}
425 virtual void SetToolDisabledBitmap(int WXUNUSED(id),
426 const wxBitmap& WXUNUSED(bitmap)) {}
bbd321ff 427
25af884d 428
1c383dba
VZ
429 // margins/packing/separation
430 // --------------------------
10b959e3 431
1c383dba
VZ
432 virtual void SetMargins(int x, int y);
433 void SetMargins(const wxSize& size)
434 { SetMargins((int) size.x, (int) size.y); }
8a0681f9
VZ
435 virtual void SetToolPacking(int packing)
436 { m_toolPacking = packing; }
437 virtual void SetToolSeparation(int separation)
438 { m_toolSeparation = separation; }
10b959e3 439
e76c0b5f
VZ
440 virtual wxSize GetToolMargins() const { return wxSize(m_xMargin, m_yMargin); }
441 virtual int GetToolPacking() const { return m_toolPacking; }
442 virtual int GetToolSeparation() const { return m_toolSeparation; }
ef7eaedd 443
8a0681f9
VZ
444 // toolbar geometry
445 // ----------------
446
447 // set the number of toolbar rows
448 virtual void SetRows(int nRows);
449
450 // the toolbar can wrap - limit the number of columns or rows it may take
1c383dba
VZ
451 void SetMaxRowsCols(int rows, int cols)
452 { m_maxRows = rows; m_maxCols = cols; }
453 int GetMaxRows() const { return m_maxRows; }
454 int GetMaxCols() const { return m_maxCols; }
10b959e3 455
8a0681f9
VZ
456 // get/set the size of the bitmaps used by the toolbar: should be called
457 // before adding any tools to the toolbar
1c383dba 458 virtual void SetToolBitmapSize(const wxSize& size)
47b378bd 459 { m_defaultWidth = size.x; m_defaultHeight = size.y; }
1c383dba
VZ
460 virtual wxSize GetToolBitmapSize() const
461 { return wxSize(m_defaultWidth, m_defaultHeight); }
10b959e3 462
8a0681f9
VZ
463 // the button size in some implementations is bigger than the bitmap size:
464 // get the total button size (by default the same as bitmap size)
1c383dba 465 virtual wxSize GetToolSize() const
47b378bd 466 { return GetToolBitmapSize(); }
10b959e3 467
8a0681f9
VZ
468 // returns a (non separator) tool containing the point (x, y) or NULL if
469 // there is no tool at this point (corrdinates are client)
470 virtual wxToolBarToolBase *FindToolForPosition(wxCoord x,
471 wxCoord y) const = 0;
472
d6071228
RD
473 // find the tool by id
474 wxToolBarToolBase *FindById(int toolid) const;
475
cb719f2e 476 // return true if this is a vertical toolbar, otherwise false
25af884d 477 bool IsVertical() const;
3216dbf5 478
bbe28fbb 479#if WXWIN_COMPATIBILITY_2_8
e76c0b5f
VZ
480 // the old versions of the various methods kept for compatibility
481 // don't use in the new code!
482 // --------------------------------------------------------------
bbe28fbb 483 wxDEPRECATED_INLINE(
d9e2e4c2 484 wxToolBarToolBase *AddTool(int toolid,
e76c0b5f
VZ
485 const wxBitmap& bitmap,
486 const wxBitmap& bmpDisabled,
cb719f2e 487 bool toggle = false,
e76c0b5f
VZ
488 wxObject *clientData = NULL,
489 const wxString& shortHelpString = wxEmptyString,
490 const wxString& longHelpString = wxEmptyString)
bbe28fbb 491 ,
d9e2e4c2 492 return AddTool(toolid, wxEmptyString,
e76c0b5f
VZ
493 bitmap, bmpDisabled,
494 toggle ? wxITEM_CHECK : wxITEM_NORMAL,
495 shortHelpString, longHelpString, clientData);
bbe28fbb
PC
496 )
497 wxDEPRECATED_INLINE(
d9e2e4c2 498 wxToolBarToolBase *AddTool(int toolid,
e76c0b5f
VZ
499 const wxBitmap& bitmap,
500 const wxString& shortHelpString = wxEmptyString,
501 const wxString& longHelpString = wxEmptyString)
bbe28fbb 502 ,
d9e2e4c2 503 return AddTool(toolid, wxEmptyString,
e76c0b5f
VZ
504 bitmap, wxNullBitmap, wxITEM_NORMAL,
505 shortHelpString, longHelpString, NULL);
bbe28fbb
PC
506 )
507 wxDEPRECATED_INLINE(
d9e2e4c2 508 wxToolBarToolBase *AddTool(int toolid,
e76c0b5f
VZ
509 const wxBitmap& bitmap,
510 const wxBitmap& bmpDisabled,
511 bool toggle,
512 wxCoord xPos,
cb719f2e 513 wxCoord yPos = wxDefaultCoord,
e76c0b5f
VZ
514 wxObject *clientData = NULL,
515 const wxString& shortHelp = wxEmptyString,
516 const wxString& longHelp = wxEmptyString)
bbe28fbb 517 ,
d9e2e4c2 518 return DoAddTool(toolid, wxEmptyString, bitmap, bmpDisabled,
e76c0b5f
VZ
519 toggle ? wxITEM_CHECK : wxITEM_NORMAL,
520 shortHelp, longHelp, clientData, xPos, yPos);
bbe28fbb
PC
521 )
522 wxDEPRECATED_INLINE(
e76c0b5f 523 wxToolBarToolBase *InsertTool(size_t pos,
d9e2e4c2 524 int toolid,
e76c0b5f
VZ
525 const wxBitmap& bitmap,
526 const wxBitmap& bmpDisabled = wxNullBitmap,
cb719f2e 527 bool toggle = false,
e76c0b5f
VZ
528 wxObject *clientData = NULL,
529 const wxString& shortHelp = wxEmptyString,
530 const wxString& longHelp = wxEmptyString)
bbe28fbb 531 ,
d9e2e4c2 532 return InsertTool(pos, toolid, wxEmptyString, bitmap, bmpDisabled,
e76c0b5f
VZ
533 toggle ? wxITEM_CHECK : wxITEM_NORMAL,
534 shortHelp, longHelp, clientData);
bbe28fbb
PC
535 )
536#endif // WXWIN_COMPATIBILITY_2_8
e76c0b5f 537
8a0681f9
VZ
538 // event handlers
539 // --------------
10b959e3 540
1c383dba 541 // NB: these functions are deprecated, use EVT_TOOL_XXX() instead!
10b959e3 542
cb719f2e 543 // Only allow toggle if returns true. Call when left button up.
d9e2e4c2 544 virtual bool OnLeftClick(int toolid, bool toggleDown);
b02da6b1 545
1c383dba 546 // Call when right button down.
d9e2e4c2 547 virtual void OnRightClick(int toolid, long x, long y);
10b959e3 548
1c383dba 549 // Called when the mouse cursor enters a tool bitmap.
cb719f2e 550 // Argument is wxID_ANY if mouse is exiting the toolbar.
d9e2e4c2 551 virtual void OnMouseEnter(int toolid);
1c383dba
VZ
552
553 // more deprecated functions
554 // -------------------------
555
e76c0b5f
VZ
556 // use GetToolMargins() instead
557 wxSize GetMargins() const { return GetToolMargins(); }
558
1c383dba
VZ
559 // implementation only from now on
560 // -------------------------------
561
8a0681f9 562 size_t GetToolsCount() const { return m_tools.GetCount(); }
1c383dba 563
8a0681f9 564 // Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
e39af974 565 virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE) ;
b02da6b1 566
33b12a3a 567 // don't want toolbars to accept the focus
cb719f2e 568 virtual bool AcceptsFocus() const { return false; }
4f430439 569
a9a0ceca
VZ
570 // Set dropdown menu
571 bool SetDropdownMenu(int toolid, wxMenu *menu);
572
8a0681f9
VZ
573protected:
574 // to implement in derived classes
575 // -------------------------------
1c383dba 576
e76c0b5f
VZ
577 // create a new toolbar tool and add it to the toolbar, this is typically
578 // implemented by just calling InsertTool()
579 virtual wxToolBarToolBase *DoAddTool
580 (
d9e2e4c2 581 int toolid,
e76c0b5f
VZ
582 const wxString& label,
583 const wxBitmap& bitmap,
584 const wxBitmap& bmpDisabled,
585 wxItemKind kind,
586 const wxString& shortHelp = wxEmptyString,
587 const wxString& longHelp = wxEmptyString,
588 wxObject *clientData = NULL,
cb719f2e
WS
589 wxCoord xPos = wxDefaultCoord,
590 wxCoord yPos = wxDefaultCoord
e76c0b5f
VZ
591 );
592
8a0681f9
VZ
593 // the tool is not yet inserted into m_tools list when this function is
594 // called and will only be added to it if this function succeeds
595 virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool) = 0;
1c383dba 596
8a0681f9
VZ
597 // the tool is still in m_tools list when this function is called, it will
598 // only be deleted from it if it succeeds
599 virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool) = 0;
1c383dba 600
8a0681f9
VZ
601 // called when the tools enabled flag changes
602 virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable) = 0;
1c383dba 603
8a0681f9
VZ
604 // called when the tool is toggled
605 virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle) = 0;
1c383dba 606
8a0681f9
VZ
607 // called when the tools "can be toggled" flag changes
608 virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle) = 0;
10b959e3 609
8a0681f9 610 // the functions to create toolbar tools
d9e2e4c2 611 virtual wxToolBarToolBase *CreateTool(int toolid,
e76c0b5f
VZ
612 const wxString& label,
613 const wxBitmap& bmpNormal,
614 const wxBitmap& bmpDisabled,
615 wxItemKind kind,
8a0681f9 616 wxObject *clientData,
e76c0b5f
VZ
617 const wxString& shortHelp,
618 const wxString& longHelp) = 0;
619
cdb11cb9
VZ
620 virtual wxToolBarToolBase *CreateTool(wxControl *control,
621 const wxString& label) = 0;
1c383dba 622
cc260109
VZ
623 // this one is not virtual but just a simple helper/wrapper around
624 // CreateTool() for separators
625 wxToolBarToolBase *CreateSeparator()
626 {
627 return CreateTool(wxID_SEPARATOR,
628 wxEmptyString,
629 wxNullBitmap, wxNullBitmap,
630 wxITEM_SEPARATOR, NULL,
631 wxEmptyString, wxEmptyString);
632 }
633
8a0681f9
VZ
634 // helper functions
635 // ----------------
1c383dba 636
d408730c
VZ
637 // call this from derived class ctor/Create() to ensure that we have either
638 // wxTB_HORIZONTAL or wxTB_VERTICAL style, there is a lot of existing code
639 // which randomly checks either one or the other of them and gets confused
640 // if neither is set (and making one of them 0 is not an option neither as
641 // then the existing tests would break down)
642 void FixupStyle();
643
6bb7cee4
VZ
644 // un-toggle all buttons in the same radio group
645 void UnToggleRadioGroup(wxToolBarToolBase *tool);
646
bb2212e6
VZ
647 // make the size of the buttons big enough to fit the largest bitmap size
648 void AdjustToolBitmapSize();
649
26007761
VZ
650 // calls InsertTool() and deletes the tool if inserting it failed
651 wxToolBarToolBase *DoInsertNewTool(size_t pos, wxToolBarToolBase *tool)
652 {
653 if ( !InsertTool(pos, tool) )
654 {
655 delete tool;
656 return NULL;
657 }
658
659 return tool;
660 }
bb2212e6 661
8a0681f9
VZ
662 // the list of all our tools
663 wxToolBarToolsList m_tools;
1c383dba 664
8a0681f9
VZ
665 // the offset of the first tool
666 int m_xMargin;
667 int m_yMargin;
10b959e3 668
8a0681f9
VZ
669 // the maximum number of toolbar rows/columns
670 int m_maxRows;
671 int m_maxCols;
1c383dba 672
8a0681f9
VZ
673 // the tool packing and separation
674 int m_toolPacking,
675 m_toolSeparation;
1c383dba 676
8a0681f9
VZ
677 // the size of the toolbar bitmaps
678 wxCoord m_defaultWidth, m_defaultHeight;
1c383dba
VZ
679
680private:
10b959e3 681 DECLARE_EVENT_TABLE()
c0c133e1 682 wxDECLARE_NO_COPY_CLASS(wxToolBarBase);
10b959e3
JS
683};
684
9ac43913
VZ
685// deprecated function for creating the image for disabled buttons, use
686// wxImage::ConvertToGreyscale() instead
687#if WXWIN_COMPATIBILITY_2_8
688
689wxDEPRECATED( bool wxCreateGreyedImage(const wxImage& in, wxImage& out) );
690
691#endif // WXWIN_COMPATIBILITY_2_8
692
c229e50d 693
1e6feb95
VZ
694#endif // wxUSE_TOOLBAR
695
10b959e3 696#endif
34138703 697 // _WX_TBARBASE_H_
10b959e3 698