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