]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_toolbar.i
fixed wxString iterators linked list corruption
[wxWidgets.git] / wxPython / src / _toolbar.i
CommitLineData
9c039d08 1/////////////////////////////////////////////////////////////////////////////
d14a1e28
RD
2// Name: _toolbar.i
3// Purpose: SWIG interface defs for wxStatusBar
9c039d08
RD
4//
5// Author: Robin Dunn
6//
d14a1e28 7// Created: 24-Aug-1998
9c039d08 8// RCS-ID: $Id$
d14a1e28 9// Copyright: (c) 2003 by Total Control Software
9c039d08
RD
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
d14a1e28 13// Not a %module
9c039d08 14
9c039d08 15
d14a1e28 16//---------------------------------------------------------------------------
137b5242 17
b2dc1044
RD
18MAKE_CONST_WXSTRING_NOSWIG(ToolBarNameStr);
19
137b5242 20
9c039d08 21//---------------------------------------------------------------------------
d14a1e28 22%newgroup;
9c039d08 23
9c039d08 24
9b3d3bc4
RD
25class wxToolBarBase;
26
27enum wxToolBarToolStyle
28{
29 wxTOOL_STYLE_BUTTON = 1,
30 wxTOOL_STYLE_SEPARATOR = 2,
31 wxTOOL_STYLE_CONTROL
32};
33
3ef86e32
RD
34enum {
35 wxTB_HORIZONTAL,
36 wxTB_VERTICAL,
8f514ab4
RD
37 wxTB_TOP,
38 wxTB_LEFT,
39 wxTB_BOTTOM,
40 wxTB_RIGHT,
41
3ef86e32
RD
42 wxTB_3DBUTTONS,
43 wxTB_FLAT,
44 wxTB_DOCKABLE,
45 wxTB_NOICONS,
46 wxTB_TEXT,
47 wxTB_NODIVIDER,
48 wxTB_NOALIGN,
49 wxTB_HORZ_LAYOUT,
50 wxTB_HORZ_TEXT,
8f514ab4 51 wxTB_NO_TOOLTIPS
3ef86e32
RD
52};
53
9b3d3bc4
RD
54
55
d14a1e28
RD
56// wxToolBarTool is a toolbar element.
57//
58// It has a unique id (except for the separators which always have id -1), the
59// style (telling whether it is a normal button, separator or a control), the
60// state (toggled or not, enabled or not) and short and long help strings. The
61// default implementations use the short help string for the tooltip text which
62// is popped up when the mouse pointer enters the tool and the long help string
63// for the applications status bar.
9416aa89 64class wxToolBarToolBase : public wxObject {
9b3d3bc4
RD
65public:
66// wxToolBarToolBase(wxToolBarBase *tbar = (wxToolBarBase *)NULL,
67// int id = wxID_SEPARATOR,
b2dc1044 68// const wxString& label = wxPyEmptyString,
b96c7a38
RD
69// const wxBitmap& bmpNormal = wxNullBitmap,
70// const wxBitmap& bmpDisabled = wxNullBitmap,
71// wxItemKind kind = wxITEM_NORMAL,
9b3d3bc4 72// wxObject *clientData = (wxObject *) NULL,
b2dc1044
RD
73// const wxString& shortHelpString = wxPyEmptyString,
74// const wxString& longHelpString = wxPyEmptyString)
9b3d3bc4
RD
75// ~wxToolBarToolBase();
76
9b3d3bc4
RD
77 int GetId();
78 wxControl *GetControl();
79 wxToolBarBase *GetToolBar();
80 int IsButton();
81 int IsControl();
82 int IsSeparator();
83 int GetStyle();
b96c7a38 84 wxItemKind GetKind();
9b3d3bc4
RD
85 bool IsEnabled();
86 bool IsToggled();
87 bool CanBeToggled();
c6ebc32a
RD
88 const wxBitmap& GetNormalBitmap();
89 const wxBitmap& GetDisabledBitmap();
c5943253 90 wxBitmap GetBitmap();
c6ebc32a 91 wxString GetLabel();
9b3d3bc4
RD
92 wxString GetShortHelp();
93 wxString GetLongHelp();
94 bool Enable(bool enable);
c6ebc32a 95 void Toggle();
9b3d3bc4
RD
96 bool SetToggle(bool toggle);
97 bool SetShortHelp(const wxString& help);
98 bool SetLongHelp(const wxString& help);
c6ebc32a
RD
99 void SetNormalBitmap(const wxBitmap& bmp);
100 void SetDisabledBitmap(const wxBitmap& bmp);
101 void SetLabel(const wxString& label);
9b3d3bc4
RD
102 void Detach();
103 void Attach(wxToolBarBase *tbar);
104
0b0849b5
RD
105 // these methods are only for tools of wxITEM_DROPDOWN kind (but even such
106 // tools can have a NULL associated menu)
107 void SetDropdownMenu(wxMenu *menu);
108 wxMenu *GetDropdownMenu() const;
109
9b3d3bc4 110 //wxObject *GetClientData();
d14a1e28 111 %extend {
9b3d3bc4
RD
112 // convert the ClientData back to a PyObject
113 PyObject* GetClientData() {
114 wxPyUserData* udata = (wxPyUserData*)self->GetClientData();
115 if (udata) {
116 Py_INCREF(udata->m_obj);
117 return udata->m_obj;
118 } else {
119 Py_INCREF(Py_None);
120 return Py_None;
121 }
122 }
123
124 void SetClientData(PyObject* clientData) {
125 self->SetClientData(new wxPyUserData(clientData));
126 }
127 }
c6ebc32a 128
d14a1e28 129 %pythoncode {
c6ebc32a
RD
130 GetBitmap1 = GetNormalBitmap
131 GetBitmap2 = GetDisabledBitmap
132 SetBitmap1 = SetNormalBitmap
133 SetBitmap2 = SetDisabledBitmap
d14a1e28 134 }
994453b8
RD
135
136 %property(Bitmap, GetBitmap, doc="See `GetBitmap`");
137 %property(ClientData, GetClientData, SetClientData, doc="See `GetClientData` and `SetClientData`");
138 %property(Control, GetControl, doc="See `GetControl`");
139 %property(DisabledBitmap, GetDisabledBitmap, SetDisabledBitmap, doc="See `GetDisabledBitmap` and `SetDisabledBitmap`");
140 %property(Id, GetId, doc="See `GetId`");
141 %property(Kind, GetKind, doc="See `GetKind`");
142 %property(Label, GetLabel, SetLabel, doc="See `GetLabel` and `SetLabel`");
143 %property(LongHelp, GetLongHelp, SetLongHelp, doc="See `GetLongHelp` and `SetLongHelp`");
144 %property(NormalBitmap, GetNormalBitmap, SetNormalBitmap, doc="See `GetNormalBitmap` and `SetNormalBitmap`");
145 %property(ShortHelp, GetShortHelp, SetShortHelp, doc="See `GetShortHelp` and `SetShortHelp`");
146 %property(Style, GetStyle, doc="See `GetStyle`");
147 %property(ToolBar, GetToolBar, doc="See `GetToolBar`");
9b3d3bc4
RD
148};
149
150
151
d14a1e28 152
9b3d3bc4
RD
153class wxToolBarBase : public wxControl {
154public:
155
156 // This is an Abstract Base Class
157
d14a1e28 158 %extend {
b96c7a38 159
15030c51
RD
160 // The full AddTool() function. Call it DoAddTool in wxPython and
161 // implement the other Add methods by calling it.
b96c7a38
RD
162 //
163 // If bmpDisabled is wxNullBitmap, a shadowed version of the normal bitmap
164 // is created and used as the disabled image.
15030c51
RD
165 wxToolBarToolBase *DoAddTool(int id,
166 const wxString& label,
167 const wxBitmap& bitmap,
168 const wxBitmap& bmpDisabled = wxNullBitmap,
169 wxItemKind kind = wxITEM_NORMAL,
170 const wxString& shortHelp = wxPyEmptyString,
171 const wxString& longHelp = wxPyEmptyString,
172 PyObject *clientData = NULL)
b96c7a38 173 {
9b3d3bc4 174 wxPyUserData* udata = NULL;
15030c51 175 if (clientData && clientData != Py_None)
9b3d3bc4 176 udata = new wxPyUserData(clientData);
b96c7a38
RD
177 return self->AddTool(id, label, bitmap, bmpDisabled, kind,
178 shortHelp, longHelp, udata);
9b3d3bc4
RD
179 }
180
9b3d3bc4 181
15030c51
RD
182 // Insert the new tool at the given position, if pos == GetToolsCount(), it
183 // is equivalent to DoAddTool()
1e4a197e 184 wxToolBarToolBase *DoInsertTool(size_t pos,
9b3d3bc4 185 int id,
b96c7a38 186 const wxString& label,
9b3d3bc4 187 const wxBitmap& bitmap,
b96c7a38
RD
188 const wxBitmap& bmpDisabled = wxNullBitmap,
189 wxItemKind kind = wxITEM_NORMAL,
c12de7f8
RD
190 const wxString& shortHelp = wxPyEmptyString,
191 const wxString& longHelp = wxPyEmptyString,
b96c7a38
RD
192 PyObject *clientData = NULL)
193 {
9b3d3bc4 194 wxPyUserData* udata = NULL;
15030c51 195 if (clientData && clientData != Py_None)
9b3d3bc4 196 udata = new wxPyUserData(clientData);
b96c7a38
RD
197 return self->InsertTool(pos, id, label, bitmap, bmpDisabled, kind,
198 shortHelp, longHelp, udata);
9b3d3bc4
RD
199 }
200
9b3d3bc4
RD
201 }
202
203
d14a1e28
RD
204 %pythoncode {
205 %# These match the original Add methods for this class, kept for
206 %# backwards compatibility with versions < 2.3.3.
15030c51
RD
207
208
209 def AddTool(self, id, bitmap,
d14a1e28 210 pushedBitmap = wx.NullBitmap,
15030c51
RD
211 isToggle = 0,
212 clientData = None,
213 shortHelpString = '',
214 longHelpString = '') :
215 '''Old style method to add a tool to the toolbar.'''
d14a1e28
RD
216 kind = wx.ITEM_NORMAL
217 if isToggle: kind = wx.ITEM_CHECK
15030c51
RD
218 return self.DoAddTool(id, '', bitmap, pushedBitmap, kind,
219 shortHelpString, longHelpString, clientData)
220
221 def AddSimpleTool(self, id, bitmap,
222 shortHelpString = '',
223 longHelpString = '',
224 isToggle = 0):
225 '''Old style method to add a tool to the toolbar.'''
d14a1e28
RD
226 kind = wx.ITEM_NORMAL
227 if isToggle: kind = wx.ITEM_CHECK
228 return self.DoAddTool(id, '', bitmap, wx.NullBitmap, kind,
15030c51
RD
229 shortHelpString, longHelpString, None)
230
231 def InsertTool(self, pos, id, bitmap,
d14a1e28 232 pushedBitmap = wx.NullBitmap,
15030c51
RD
233 isToggle = 0,
234 clientData = None,
235 shortHelpString = '',
236 longHelpString = ''):
237 '''Old style method to insert a tool in the toolbar.'''
d14a1e28
RD
238 kind = wx.ITEM_NORMAL
239 if isToggle: kind = wx.ITEM_CHECK
15030c51
RD
240 return self.DoInsertTool(pos, id, '', bitmap, pushedBitmap, kind,
241 shortHelpString, longHelpString, clientData)
242
243 def InsertSimpleTool(self, pos, id, bitmap,
244 shortHelpString = '',
245 longHelpString = '',
246 isToggle = 0):
247 '''Old style method to insert a tool in the toolbar.'''
d14a1e28
RD
248 kind = wx.ITEM_NORMAL
249 if isToggle: kind = wx.ITEM_CHECK
250 return self.DoInsertTool(pos, id, '', bitmap, wx.NullBitmap, kind,
15030c51
RD
251 shortHelpString, longHelpString, None)
252
253
d14a1e28
RD
254 %# The following are the new toolbar Add methods starting with
255 %# 2.3.3. They are renamed to have 'Label' in the name so as to be
256 %# able to keep backwards compatibility with using the above
257 %# methods. Eventually these should migrate to be the methods used
258 %# primarily and lose the 'Label' in the name...
15030c51
RD
259
260 def AddLabelTool(self, id, label, bitmap,
d14a1e28
RD
261 bmpDisabled = wx.NullBitmap,
262 kind = wx.ITEM_NORMAL,
15030c51
RD
263 shortHelp = '', longHelp = '',
264 clientData = None):
265 '''
266 The full AddTool() function.
267
d14a1e28 268 If bmpDisabled is wx.NullBitmap, a shadowed version of the normal bitmap
15030c51
RD
269 is created and used as the disabled image.
270 '''
271 return self.DoAddTool(id, label, bitmap, bmpDisabled, kind,
272 shortHelp, longHelp, clientData)
273
274
275 def InsertLabelTool(self, pos, id, label, bitmap,
d14a1e28
RD
276 bmpDisabled = wx.NullBitmap,
277 kind = wx.ITEM_NORMAL,
15030c51
RD
278 shortHelp = '', longHelp = '',
279 clientData = None):
280 '''
281 Insert the new tool at the given position, if pos == GetToolsCount(), it
282 is equivalent to AddTool()
283 '''
284 return self.DoInsertTool(pos, id, label, bitmap, bmpDisabled, kind,
285 shortHelp, longHelp, clientData)
286
287 def AddCheckLabelTool(self, id, label, bitmap,
d14a1e28 288 bmpDisabled = wx.NullBitmap,
15030c51
RD
289 shortHelp = '', longHelp = '',
290 clientData = None):
291 '''Add a check tool, i.e. a tool which can be toggled'''
d14a1e28 292 return self.DoAddTool(id, label, bitmap, bmpDisabled, wx.ITEM_CHECK,
15030c51
RD
293 shortHelp, longHelp, clientData)
294
295 def AddRadioLabelTool(self, id, label, bitmap,
d14a1e28 296 bmpDisabled = wx.NullBitmap,
15030c51
RD
297 shortHelp = '', longHelp = '',
298 clientData = None):
299 '''
300 Add a radio tool, i.e. a tool which can be toggled and releases any
301 other toggled radio tools in the same group when it happens
302 '''
d14a1e28 303 return self.DoAddTool(id, label, bitmap, bmpDisabled, wx.ITEM_RADIO,
15030c51
RD
304 shortHelp, longHelp, clientData)
305
306
d14a1e28
RD
307 %# For consistency with the backwards compatible methods above, here are
308 %# some non-'Label' versions of the Check and Radio methods
d5573410 309
15030c51 310 def AddCheckTool(self, id, bitmap,
d14a1e28 311 bmpDisabled = wx.NullBitmap,
15030c51
RD
312 shortHelp = '', longHelp = '',
313 clientData = None):
314 '''Add a check tool, i.e. a tool which can be toggled'''
d14a1e28 315 return self.DoAddTool(id, '', bitmap, bmpDisabled, wx.ITEM_CHECK,
15030c51
RD
316 shortHelp, longHelp, clientData)
317
318 def AddRadioTool(self, id, bitmap,
d14a1e28 319 bmpDisabled = wx.NullBitmap,
15030c51
RD
320 shortHelp = '', longHelp = '',
321 clientData = None):
322 '''
323 Add a radio tool, i.e. a tool which can be toggled and releases any
324 other toggled radio tools in the same group when it happens
325 '''
d14a1e28 326 return self.DoAddTool(id, '', bitmap, bmpDisabled, wx.ITEM_RADIO,
15030c51 327 shortHelp, longHelp, clientData)
d14a1e28 328 }
15030c51 329
1b8c7ba6
RD
330 %Rename(AddToolItem, wxToolBarToolBase*, AddTool (wxToolBarToolBase *tool));
331 %Rename(InsertToolItem, wxToolBarToolBase*, InsertTool (size_t pos, wxToolBarToolBase *tool));
15030c51 332
cbfc9df6
RD
333 wxToolBarToolBase *AddControl(wxControl *control,
334 const wxString& label = wxEmptyString);
335 wxToolBarToolBase *InsertControl(size_t pos, wxControl *control,
336 const wxString& label = wxEmptyString);
fe953afb 337 wxControl *FindControl( int id );
9b3d3bc4
RD
338
339 wxToolBarToolBase *AddSeparator();
340 wxToolBarToolBase *InsertSeparator(size_t pos);
341
342 wxToolBarToolBase *RemoveTool(int id);
343
344 bool DeleteToolByPos(size_t pos);
345 bool DeleteTool(int id);
346 void ClearTools();
347 bool Realize();
348
349 void EnableTool(int id, bool enable);
350 void ToggleTool(int id, bool toggle);
351 void SetToggle(int id, bool toggle);
352
353
d14a1e28 354 %extend {
9b3d3bc4 355 // convert the ClientData back to a PyObject
c6ebc32a
RD
356 PyObject* GetToolClientData(int id) {
357 wxPyUserData* udata = (wxPyUserData*)self->GetToolClientData(id);
9b3d3bc4
RD
358 if (udata) {
359 Py_INCREF(udata->m_obj);
360 return udata->m_obj;
361 } else {
362 Py_INCREF(Py_None);
363 return Py_None;
364 }
365 }
366
c6ebc32a
RD
367 void SetToolClientData(int id, PyObject* clientData) {
368 self->SetToolClientData(id, new wxPyUserData(clientData));
9b3d3bc4
RD
369 }
370 }
371
3ef86e32
RD
372 // returns tool pos, or wxNOT_FOUND if tool isn't found
373 int GetToolPos(int id) const;
9b3d3bc4
RD
374
375 bool GetToolState(int id);
376 bool GetToolEnabled(int id);
377 void SetToolShortHelp(int id, const wxString& helpString);
378 wxString GetToolShortHelp(int id);
379 void SetToolLongHelp(int id, const wxString& helpString);
380 wxString GetToolLongHelp(int id);
381
1b8c7ba6 382 %Rename(SetMarginsXY, void, SetMargins(int x, int y));
9b3d3bc4
RD
383 void SetMargins(const wxSize& size);
384 void SetToolPacking(int packing);
385 void SetToolSeparation(int separation);
386 wxSize GetToolMargins();
83b18bab 387 wxSize GetMargins();
9b3d3bc4
RD
388 int GetToolPacking();
389 int GetToolSeparation();
390
391 void SetRows(int nRows);
392 void SetMaxRowsCols(int rows, int cols);
393 int GetMaxRows();
394 int GetMaxCols();
395
396 void SetToolBitmapSize(const wxSize& size);
397 wxSize GetToolBitmapSize();
398 wxSize GetToolSize();
399
c6ebc32a
RD
400 // returns a (non separator) tool containing the point (x, y) or NULL if
401 // there is no tool at this point (corrdinates are client)
402 wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y);
403
a6d2f5bb
RD
404 // find the tool by id
405 wxToolBarToolBase *FindById(int toolid) const;
406
dd9f7fea 407 // return True if this is a vertical toolbar, otherwise False
c6ebc32a 408 bool IsVertical();
06336f51
RD
409
410 size_t GetToolsCount() const;
994453b8 411
0b0849b5
RD
412 // Set dropdown menu
413 bool SetDropdownMenu(int toolid, wxMenu *menu);
414
415
994453b8
RD
416 %property(Margins, GetMargins, SetMargins, doc="See `GetMargins` and `SetMargins`");
417 %property(MaxCols, GetMaxCols, doc="See `GetMaxCols`");
418 %property(MaxRows, GetMaxRows, doc="See `GetMaxRows`");
419 %property(ToolBitmapSize, GetToolBitmapSize, SetToolBitmapSize, doc="See `GetToolBitmapSize` and `SetToolBitmapSize`");
420 %property(ToolMargins, GetToolMargins, doc="See `GetToolMargins`");
421 %property(ToolPacking, GetToolPacking, SetToolPacking, doc="See `GetToolPacking` and `SetToolPacking`");
422 %property(ToolSeparation, GetToolSeparation, SetToolSeparation, doc="See `GetToolSeparation` and `SetToolSeparation`");
423 %property(ToolSize, GetToolSize, doc="See `GetToolSize`");
424 %property(ToolsCount, GetToolsCount, doc="See `GetToolsCount`");
9b3d3bc4
RD
425};
426
427
428
429
ab1f7d2a
RD
430MustHaveApp(wxToolBar);
431
9b3d3bc4
RD
432class wxToolBar : public wxToolBarBase {
433public:
2b9048c5
RD
434 %pythonAppend wxToolBar "self._setOORInfo(self)"
435 %pythonAppend wxToolBar() ""
b39c3fa0
RD
436 %typemap(out) wxToolBar*; // turn off this typemap
437
9b3d3bc4 438 wxToolBar(wxWindow *parent,
d5573410 439 wxWindowID id=-1,
b68dc582
RD
440 const wxPoint& pos = wxDefaultPosition,
441 const wxSize& size = wxDefaultSize,
9b3d3bc4 442 long style = wxNO_BORDER | wxTB_HORIZONTAL,
137b5242 443 const wxString& name = wxPyToolBarNameStr);
1b8c7ba6 444 %RenameCtor(PreToolBar, wxToolBar());
09f3d4e6 445
b39c3fa0
RD
446 // Turn it back on again
447 %typemap(out) wxToolBar* { $result = wxPyMake_wxObject($1, $owner); }
448
09f3d4e6 449 bool Create(wxWindow *parent,
d5573410 450 wxWindowID id=-1,
09f3d4e6
RD
451 const wxPoint& pos = wxDefaultPosition,
452 const wxSize& size = wxDefaultSize,
453 long style = wxNO_BORDER | wxTB_HORIZONTAL,
137b5242 454 const wxString& name = wxPyToolBarNameStr);
9b3d3bc4 455
3c69a2ec
RD
456 // TODO: In 2.9 move these to the base class...
457 void SetToolNormalBitmap(int id, const wxBitmap& bitmap);
458 void SetToolDisabledBitmap(int id, const wxBitmap& bitmap);
459
880715c9
RD
460 static wxVisualAttributes
461 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
9b3d3bc4
RD
462};
463
9c039d08 464//---------------------------------------------------------------------------
de871c91
RD
465
466#if 0
467%{
468#include <wx/generic/buttonbar.h>
469%}
470
471MustHaveApp(wxToolBar);
472class wxButtonToolBar : public wxToolBarBase
473{
474public:
475 %pythonAppend wxButtonToolBar "self._setOORInfo(self)"
476 %pythonAppend wxButtonToolBar() ""
477
478 wxButtonToolBar(wxWindow *parent,
479 wxWindowID id=-1,
480 const wxPoint& pos = wxDefaultPosition,
481 const wxSize& size = wxDefaultSize,
482 long style = 0,
483 const wxString& name = wxPyToolBarNameStr);
484 %RenameCtor(PreButtonToolBar, wxButtonToolBar());
485
486
487 bool Create(wxWindow *parent,
488 wxWindowID id=-1,
489 const wxPoint& pos = wxDefaultPosition,
490 const wxSize& size = wxDefaultSize,
491 long style = 0,
492 const wxString& name = wxPyToolBarNameStr);
493};
494
495#endif
496//---------------------------------------------------------------------------