]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_toolbar.i
revert last change
[wxWidgets.git] / wxPython / src / _toolbar.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _toolbar.i
3 // Purpose: SWIG interface defs for wxStatusBar
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 24-Aug-1998
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 MAKE_CONST_WXSTRING_NOSWIG(ToolBarNameStr);
19
20
21 //---------------------------------------------------------------------------
22 %newgroup;
23
24
25 class wxToolBarBase;
26
27 enum wxToolBarToolStyle
28 {
29 wxTOOL_STYLE_BUTTON = 1,
30 wxTOOL_STYLE_SEPARATOR = 2,
31 wxTOOL_STYLE_CONTROL
32 };
33
34 enum {
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,
46 wxTB_NO_TOOLTIPS,
47 };
48
49
50
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.
59 class wxToolBarToolBase : public wxObject {
60 public:
61 // wxToolBarToolBase(wxToolBarBase *tbar = (wxToolBarBase *)NULL,
62 // int id = wxID_SEPARATOR,
63 // const wxString& label = wxPyEmptyString,
64 // const wxBitmap& bmpNormal = wxNullBitmap,
65 // const wxBitmap& bmpDisabled = wxNullBitmap,
66 // wxItemKind kind = wxITEM_NORMAL,
67 // wxObject *clientData = (wxObject *) NULL,
68 // const wxString& shortHelpString = wxPyEmptyString,
69 // const wxString& longHelpString = wxPyEmptyString)
70 // ~wxToolBarToolBase();
71
72 int GetId();
73 wxControl *GetControl();
74 wxToolBarBase *GetToolBar();
75 int IsButton();
76 int IsControl();
77 int IsSeparator();
78 int GetStyle();
79 wxItemKind GetKind();
80 bool IsEnabled();
81 bool IsToggled();
82 bool CanBeToggled();
83 const wxBitmap& GetNormalBitmap();
84 const wxBitmap& GetDisabledBitmap();
85 wxBitmap GetBitmap();
86 wxString GetLabel();
87 wxString GetShortHelp();
88 wxString GetLongHelp();
89 bool Enable(bool enable);
90 void Toggle();
91 bool SetToggle(bool toggle);
92 bool SetShortHelp(const wxString& help);
93 bool SetLongHelp(const wxString& help);
94 void SetNormalBitmap(const wxBitmap& bmp);
95 void SetDisabledBitmap(const wxBitmap& bmp);
96 void SetLabel(const wxString& label);
97 void Detach();
98 void Attach(wxToolBarBase *tbar);
99
100 //wxObject *GetClientData();
101 %extend {
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 }
118
119 %pythoncode {
120 GetBitmap1 = GetNormalBitmap
121 GetBitmap2 = GetDisabledBitmap
122 SetBitmap1 = SetNormalBitmap
123 SetBitmap2 = SetDisabledBitmap
124 }
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`");
138 };
139
140
141
142
143 class wxToolBarBase : public wxControl {
144 public:
145
146 // This is an Abstract Base Class
147
148 %extend {
149
150 // The full AddTool() function. Call it DoAddTool in wxPython and
151 // implement the other Add methods by calling it.
152 //
153 // If bmpDisabled is wxNullBitmap, a shadowed version of the normal bitmap
154 // is created and used as the disabled image.
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)
163 {
164 wxPyUserData* udata = NULL;
165 if (clientData && clientData != Py_None)
166 udata = new wxPyUserData(clientData);
167 return self->AddTool(id, label, bitmap, bmpDisabled, kind,
168 shortHelp, longHelp, udata);
169 }
170
171
172 // Insert the new tool at the given position, if pos == GetToolsCount(), it
173 // is equivalent to DoAddTool()
174 wxToolBarToolBase *DoInsertTool(size_t pos,
175 int id,
176 const wxString& label,
177 const wxBitmap& bitmap,
178 const wxBitmap& bmpDisabled = wxNullBitmap,
179 wxItemKind kind = wxITEM_NORMAL,
180 const wxString& shortHelp = wxPyEmptyString,
181 const wxString& longHelp = wxPyEmptyString,
182 PyObject *clientData = NULL)
183 {
184 wxPyUserData* udata = NULL;
185 if (clientData && clientData != Py_None)
186 udata = new wxPyUserData(clientData);
187 return self->InsertTool(pos, id, label, bitmap, bmpDisabled, kind,
188 shortHelp, longHelp, udata);
189 }
190
191 }
192
193
194 %pythoncode {
195 %# These match the original Add methods for this class, kept for
196 %# backwards compatibility with versions < 2.3.3.
197
198
199 def AddTool(self, id, bitmap,
200 pushedBitmap = wx.NullBitmap,
201 isToggle = 0,
202 clientData = None,
203 shortHelpString = '',
204 longHelpString = '') :
205 '''Old style method to add a tool to the toolbar.'''
206 kind = wx.ITEM_NORMAL
207 if isToggle: kind = wx.ITEM_CHECK
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.'''
216 kind = wx.ITEM_NORMAL
217 if isToggle: kind = wx.ITEM_CHECK
218 return self.DoAddTool(id, '', bitmap, wx.NullBitmap, kind,
219 shortHelpString, longHelpString, None)
220
221 def InsertTool(self, pos, id, bitmap,
222 pushedBitmap = wx.NullBitmap,
223 isToggle = 0,
224 clientData = None,
225 shortHelpString = '',
226 longHelpString = ''):
227 '''Old style method to insert a tool in the toolbar.'''
228 kind = wx.ITEM_NORMAL
229 if isToggle: kind = wx.ITEM_CHECK
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.'''
238 kind = wx.ITEM_NORMAL
239 if isToggle: kind = wx.ITEM_CHECK
240 return self.DoInsertTool(pos, id, '', bitmap, wx.NullBitmap, kind,
241 shortHelpString, longHelpString, None)
242
243
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...
249
250 def AddLabelTool(self, id, label, bitmap,
251 bmpDisabled = wx.NullBitmap,
252 kind = wx.ITEM_NORMAL,
253 shortHelp = '', longHelp = '',
254 clientData = None):
255 '''
256 The full AddTool() function.
257
258 If bmpDisabled is wx.NullBitmap, a shadowed version of the normal bitmap
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,
266 bmpDisabled = wx.NullBitmap,
267 kind = wx.ITEM_NORMAL,
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,
278 bmpDisabled = wx.NullBitmap,
279 shortHelp = '', longHelp = '',
280 clientData = None):
281 '''Add a check tool, i.e. a tool which can be toggled'''
282 return self.DoAddTool(id, label, bitmap, bmpDisabled, wx.ITEM_CHECK,
283 shortHelp, longHelp, clientData)
284
285 def AddRadioLabelTool(self, id, label, bitmap,
286 bmpDisabled = wx.NullBitmap,
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 '''
293 return self.DoAddTool(id, label, bitmap, bmpDisabled, wx.ITEM_RADIO,
294 shortHelp, longHelp, clientData)
295
296
297 %# For consistency with the backwards compatible methods above, here are
298 %# some non-'Label' versions of the Check and Radio methods
299
300 def AddCheckTool(self, id, bitmap,
301 bmpDisabled = wx.NullBitmap,
302 shortHelp = '', longHelp = '',
303 clientData = None):
304 '''Add a check tool, i.e. a tool which can be toggled'''
305 return self.DoAddTool(id, '', bitmap, bmpDisabled, wx.ITEM_CHECK,
306 shortHelp, longHelp, clientData)
307
308 def AddRadioTool(self, id, bitmap,
309 bmpDisabled = wx.NullBitmap,
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 '''
316 return self.DoAddTool(id, '', bitmap, bmpDisabled, wx.ITEM_RADIO,
317 shortHelp, longHelp, clientData)
318 }
319
320 %Rename(AddToolItem, wxToolBarToolBase*, AddTool (wxToolBarToolBase *tool));
321 %Rename(InsertToolItem, wxToolBarToolBase*, InsertTool (size_t pos, wxToolBarToolBase *tool));
322
323 wxToolBarToolBase *AddControl(wxControl *control);
324 wxToolBarToolBase *InsertControl(size_t pos, wxControl *control);
325 wxControl *FindControl( int id );
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
342 %extend {
343 // convert the ClientData back to a PyObject
344 PyObject* GetToolClientData(int id) {
345 wxPyUserData* udata = (wxPyUserData*)self->GetToolClientData(id);
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
355 void SetToolClientData(int id, PyObject* clientData) {
356 self->SetToolClientData(id, new wxPyUserData(clientData));
357 }
358 }
359
360 // returns tool pos, or wxNOT_FOUND if tool isn't found
361 int GetToolPos(int id) const;
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
370 %Rename(SetMarginsXY, void, SetMargins(int x, int y));
371 void SetMargins(const wxSize& size);
372 void SetToolPacking(int packing);
373 void SetToolSeparation(int separation);
374 wxSize GetToolMargins();
375 wxSize GetMargins();
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
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
392 // find the tool by id
393 wxToolBarToolBase *FindById(int toolid) const;
394
395 // return True if this is a vertical toolbar, otherwise False
396 bool IsVertical();
397
398 size_t GetToolsCount() const;
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`");
409 };
410
411
412
413
414 MustHaveApp(wxToolBar);
415
416 class wxToolBar : public wxToolBarBase {
417 public:
418 %pythonAppend wxToolBar "self._setOORInfo(self)"
419 %pythonAppend wxToolBar() ""
420 %typemap(out) wxToolBar*; // turn off this typemap
421
422 wxToolBar(wxWindow *parent,
423 wxWindowID id=-1,
424 const wxPoint& pos = wxDefaultPosition,
425 const wxSize& size = wxDefaultSize,
426 long style = wxNO_BORDER | wxTB_HORIZONTAL,
427 const wxString& name = wxPyToolBarNameStr);
428 %RenameCtor(PreToolBar, wxToolBar());
429
430 // Turn it back on again
431 %typemap(out) wxToolBar* { $result = wxPyMake_wxObject($1, $owner); }
432
433 bool Create(wxWindow *parent,
434 wxWindowID id=-1,
435 const wxPoint& pos = wxDefaultPosition,
436 const wxSize& size = wxDefaultSize,
437 long style = wxNO_BORDER | wxTB_HORIZONTAL,
438 const wxString& name = wxPyToolBarNameStr);
439
440 static wxVisualAttributes
441 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
442 };
443
444 //---------------------------------------------------------------------------
445
446 #if 0
447 %{
448 #include <wx/generic/buttonbar.h>
449 %}
450
451 MustHaveApp(wxToolBar);
452 class wxButtonToolBar : public wxToolBarBase
453 {
454 public:
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 //---------------------------------------------------------------------------