]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_toolbar.i
fixed crash in <sub/sup> handling (bug #1545152)
[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 }
9b3d3bc4
RD
125};
126
127
128
d14a1e28 129
9b3d3bc4
RD
130class wxToolBarBase : public wxControl {
131public:
132
133 // This is an Abstract Base Class
134
d14a1e28 135 %extend {
b96c7a38 136
15030c51
RD
137 // The full AddTool() function. Call it DoAddTool in wxPython and
138 // implement the other Add methods by calling it.
b96c7a38
RD
139 //
140 // If bmpDisabled is wxNullBitmap, a shadowed version of the normal bitmap
141 // is created and used as the disabled image.
15030c51
RD
142 wxToolBarToolBase *DoAddTool(int id,
143 const wxString& label,
144 const wxBitmap& bitmap,
145 const wxBitmap& bmpDisabled = wxNullBitmap,
146 wxItemKind kind = wxITEM_NORMAL,
147 const wxString& shortHelp = wxPyEmptyString,
148 const wxString& longHelp = wxPyEmptyString,
149 PyObject *clientData = NULL)
b96c7a38 150 {
9b3d3bc4 151 wxPyUserData* udata = NULL;
15030c51 152 if (clientData && clientData != Py_None)
9b3d3bc4 153 udata = new wxPyUserData(clientData);
b96c7a38
RD
154 return self->AddTool(id, label, bitmap, bmpDisabled, kind,
155 shortHelp, longHelp, udata);
9b3d3bc4
RD
156 }
157
9b3d3bc4 158
15030c51
RD
159 // Insert the new tool at the given position, if pos == GetToolsCount(), it
160 // is equivalent to DoAddTool()
1e4a197e 161 wxToolBarToolBase *DoInsertTool(size_t pos,
9b3d3bc4 162 int id,
b96c7a38 163 const wxString& label,
9b3d3bc4 164 const wxBitmap& bitmap,
b96c7a38
RD
165 const wxBitmap& bmpDisabled = wxNullBitmap,
166 wxItemKind kind = wxITEM_NORMAL,
c12de7f8
RD
167 const wxString& shortHelp = wxPyEmptyString,
168 const wxString& longHelp = wxPyEmptyString,
b96c7a38
RD
169 PyObject *clientData = NULL)
170 {
9b3d3bc4 171 wxPyUserData* udata = NULL;
15030c51 172 if (clientData && clientData != Py_None)
9b3d3bc4 173 udata = new wxPyUserData(clientData);
b96c7a38
RD
174 return self->InsertTool(pos, id, label, bitmap, bmpDisabled, kind,
175 shortHelp, longHelp, udata);
9b3d3bc4
RD
176 }
177
9b3d3bc4
RD
178 }
179
180
d14a1e28
RD
181 %pythoncode {
182 %# These match the original Add methods for this class, kept for
183 %# backwards compatibility with versions < 2.3.3.
15030c51
RD
184
185
186 def AddTool(self, id, bitmap,
d14a1e28 187 pushedBitmap = wx.NullBitmap,
15030c51
RD
188 isToggle = 0,
189 clientData = None,
190 shortHelpString = '',
191 longHelpString = '') :
192 '''Old style method to add a tool to the toolbar.'''
d14a1e28
RD
193 kind = wx.ITEM_NORMAL
194 if isToggle: kind = wx.ITEM_CHECK
15030c51
RD
195 return self.DoAddTool(id, '', bitmap, pushedBitmap, kind,
196 shortHelpString, longHelpString, clientData)
197
198 def AddSimpleTool(self, id, bitmap,
199 shortHelpString = '',
200 longHelpString = '',
201 isToggle = 0):
202 '''Old style method to add a tool to the toolbar.'''
d14a1e28
RD
203 kind = wx.ITEM_NORMAL
204 if isToggle: kind = wx.ITEM_CHECK
205 return self.DoAddTool(id, '', bitmap, wx.NullBitmap, kind,
15030c51
RD
206 shortHelpString, longHelpString, None)
207
208 def InsertTool(self, pos, id, bitmap,
d14a1e28 209 pushedBitmap = wx.NullBitmap,
15030c51
RD
210 isToggle = 0,
211 clientData = None,
212 shortHelpString = '',
213 longHelpString = ''):
214 '''Old style method to insert a tool in the toolbar.'''
d14a1e28
RD
215 kind = wx.ITEM_NORMAL
216 if isToggle: kind = wx.ITEM_CHECK
15030c51
RD
217 return self.DoInsertTool(pos, id, '', bitmap, pushedBitmap, kind,
218 shortHelpString, longHelpString, clientData)
219
220 def InsertSimpleTool(self, pos, id, bitmap,
221 shortHelpString = '',
222 longHelpString = '',
223 isToggle = 0):
224 '''Old style method to insert a tool in the toolbar.'''
d14a1e28
RD
225 kind = wx.ITEM_NORMAL
226 if isToggle: kind = wx.ITEM_CHECK
227 return self.DoInsertTool(pos, id, '', bitmap, wx.NullBitmap, kind,
15030c51
RD
228 shortHelpString, longHelpString, None)
229
230
d14a1e28
RD
231 %# The following are the new toolbar Add methods starting with
232 %# 2.3.3. They are renamed to have 'Label' in the name so as to be
233 %# able to keep backwards compatibility with using the above
234 %# methods. Eventually these should migrate to be the methods used
235 %# primarily and lose the 'Label' in the name...
15030c51
RD
236
237 def AddLabelTool(self, id, label, bitmap,
d14a1e28
RD
238 bmpDisabled = wx.NullBitmap,
239 kind = wx.ITEM_NORMAL,
15030c51
RD
240 shortHelp = '', longHelp = '',
241 clientData = None):
242 '''
243 The full AddTool() function.
244
d14a1e28 245 If bmpDisabled is wx.NullBitmap, a shadowed version of the normal bitmap
15030c51
RD
246 is created and used as the disabled image.
247 '''
248 return self.DoAddTool(id, label, bitmap, bmpDisabled, kind,
249 shortHelp, longHelp, clientData)
250
251
252 def InsertLabelTool(self, pos, id, label, bitmap,
d14a1e28
RD
253 bmpDisabled = wx.NullBitmap,
254 kind = wx.ITEM_NORMAL,
15030c51
RD
255 shortHelp = '', longHelp = '',
256 clientData = None):
257 '''
258 Insert the new tool at the given position, if pos == GetToolsCount(), it
259 is equivalent to AddTool()
260 '''
261 return self.DoInsertTool(pos, id, label, bitmap, bmpDisabled, kind,
262 shortHelp, longHelp, clientData)
263
264 def AddCheckLabelTool(self, id, label, bitmap,
d14a1e28 265 bmpDisabled = wx.NullBitmap,
15030c51
RD
266 shortHelp = '', longHelp = '',
267 clientData = None):
268 '''Add a check tool, i.e. a tool which can be toggled'''
d14a1e28 269 return self.DoAddTool(id, label, bitmap, bmpDisabled, wx.ITEM_CHECK,
15030c51
RD
270 shortHelp, longHelp, clientData)
271
272 def AddRadioLabelTool(self, id, label, bitmap,
d14a1e28 273 bmpDisabled = wx.NullBitmap,
15030c51
RD
274 shortHelp = '', longHelp = '',
275 clientData = None):
276 '''
277 Add a radio tool, i.e. a tool which can be toggled and releases any
278 other toggled radio tools in the same group when it happens
279 '''
d14a1e28 280 return self.DoAddTool(id, label, bitmap, bmpDisabled, wx.ITEM_RADIO,
15030c51
RD
281 shortHelp, longHelp, clientData)
282
283
d14a1e28
RD
284 %# For consistency with the backwards compatible methods above, here are
285 %# some non-'Label' versions of the Check and Radio methods
d5573410 286
15030c51 287 def AddCheckTool(self, id, 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, '', bitmap, bmpDisabled, wx.ITEM_CHECK,
15030c51
RD
293 shortHelp, longHelp, clientData)
294
295 def AddRadioTool(self, id, 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, '', bitmap, bmpDisabled, wx.ITEM_RADIO,
15030c51 304 shortHelp, longHelp, clientData)
d14a1e28 305 }
15030c51 306
1b8c7ba6
RD
307 %Rename(AddToolItem, wxToolBarToolBase*, AddTool (wxToolBarToolBase *tool));
308 %Rename(InsertToolItem, wxToolBarToolBase*, InsertTool (size_t pos, wxToolBarToolBase *tool));
15030c51 309
9b3d3bc4
RD
310 wxToolBarToolBase *AddControl(wxControl *control);
311 wxToolBarToolBase *InsertControl(size_t pos, wxControl *control);
fe953afb 312 wxControl *FindControl( int id );
9b3d3bc4
RD
313
314 wxToolBarToolBase *AddSeparator();
315 wxToolBarToolBase *InsertSeparator(size_t pos);
316
317 wxToolBarToolBase *RemoveTool(int id);
318
319 bool DeleteToolByPos(size_t pos);
320 bool DeleteTool(int id);
321 void ClearTools();
322 bool Realize();
323
324 void EnableTool(int id, bool enable);
325 void ToggleTool(int id, bool toggle);
326 void SetToggle(int id, bool toggle);
327
328
d14a1e28 329 %extend {
9b3d3bc4 330 // convert the ClientData back to a PyObject
c6ebc32a
RD
331 PyObject* GetToolClientData(int id) {
332 wxPyUserData* udata = (wxPyUserData*)self->GetToolClientData(id);
9b3d3bc4
RD
333 if (udata) {
334 Py_INCREF(udata->m_obj);
335 return udata->m_obj;
336 } else {
337 Py_INCREF(Py_None);
338 return Py_None;
339 }
340 }
341
c6ebc32a
RD
342 void SetToolClientData(int id, PyObject* clientData) {
343 self->SetToolClientData(id, new wxPyUserData(clientData));
9b3d3bc4
RD
344 }
345 }
346
3ef86e32
RD
347 // returns tool pos, or wxNOT_FOUND if tool isn't found
348 int GetToolPos(int id) const;
9b3d3bc4
RD
349
350 bool GetToolState(int id);
351 bool GetToolEnabled(int id);
352 void SetToolShortHelp(int id, const wxString& helpString);
353 wxString GetToolShortHelp(int id);
354 void SetToolLongHelp(int id, const wxString& helpString);
355 wxString GetToolLongHelp(int id);
356
1b8c7ba6 357 %Rename(SetMarginsXY, void, SetMargins(int x, int y));
9b3d3bc4
RD
358 void SetMargins(const wxSize& size);
359 void SetToolPacking(int packing);
360 void SetToolSeparation(int separation);
361 wxSize GetToolMargins();
83b18bab 362 wxSize GetMargins();
9b3d3bc4
RD
363 int GetToolPacking();
364 int GetToolSeparation();
365
366 void SetRows(int nRows);
367 void SetMaxRowsCols(int rows, int cols);
368 int GetMaxRows();
369 int GetMaxCols();
370
371 void SetToolBitmapSize(const wxSize& size);
372 wxSize GetToolBitmapSize();
373 wxSize GetToolSize();
374
c6ebc32a
RD
375 // returns a (non separator) tool containing the point (x, y) or NULL if
376 // there is no tool at this point (corrdinates are client)
377 wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y);
378
a6d2f5bb
RD
379 // find the tool by id
380 wxToolBarToolBase *FindById(int toolid) const;
381
dd9f7fea 382 // return True if this is a vertical toolbar, otherwise False
c6ebc32a 383 bool IsVertical();
06336f51
RD
384
385 size_t GetToolsCount() const;
9b3d3bc4
RD
386};
387
388
389
390
ab1f7d2a
RD
391MustHaveApp(wxToolBar);
392
9b3d3bc4
RD
393class wxToolBar : public wxToolBarBase {
394public:
2b9048c5
RD
395 %pythonAppend wxToolBar "self._setOORInfo(self)"
396 %pythonAppend wxToolBar() ""
b39c3fa0
RD
397 %typemap(out) wxToolBar*; // turn off this typemap
398
9b3d3bc4 399 wxToolBar(wxWindow *parent,
d5573410 400 wxWindowID id=-1,
b68dc582
RD
401 const wxPoint& pos = wxDefaultPosition,
402 const wxSize& size = wxDefaultSize,
9b3d3bc4 403 long style = wxNO_BORDER | wxTB_HORIZONTAL,
137b5242 404 const wxString& name = wxPyToolBarNameStr);
1b8c7ba6 405 %RenameCtor(PreToolBar, wxToolBar());
09f3d4e6 406
b39c3fa0
RD
407 // Turn it back on again
408 %typemap(out) wxToolBar* { $result = wxPyMake_wxObject($1, $owner); }
409
09f3d4e6 410 bool Create(wxWindow *parent,
d5573410 411 wxWindowID id=-1,
09f3d4e6
RD
412 const wxPoint& pos = wxDefaultPosition,
413 const wxSize& size = wxDefaultSize,
414 long style = wxNO_BORDER | wxTB_HORIZONTAL,
137b5242 415 const wxString& name = wxPyToolBarNameStr);
9b3d3bc4 416
880715c9
RD
417 static wxVisualAttributes
418 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
9b3d3bc4
RD
419};
420
9c039d08 421//---------------------------------------------------------------------------
de871c91
RD
422
423#if 0
424%{
425#include <wx/generic/buttonbar.h>
426%}
427
428MustHaveApp(wxToolBar);
429class wxButtonToolBar : public wxToolBarBase
430{
431public:
432 %pythonAppend wxButtonToolBar "self._setOORInfo(self)"
433 %pythonAppend wxButtonToolBar() ""
434
435 wxButtonToolBar(wxWindow *parent,
436 wxWindowID id=-1,
437 const wxPoint& pos = wxDefaultPosition,
438 const wxSize& size = wxDefaultSize,
439 long style = 0,
440 const wxString& name = wxPyToolBarNameStr);
441 %RenameCtor(PreButtonToolBar, wxButtonToolBar());
442
443
444 bool Create(wxWindow *parent,
445 wxWindowID id=-1,
446 const wxPoint& pos = wxDefaultPosition,
447 const wxSize& size = wxDefaultSize,
448 long style = 0,
449 const wxString& name = wxPyToolBarNameStr);
450};
451
452#endif
453//---------------------------------------------------------------------------