~brian-sidebotham/wxwidgets-cmake/wxpython-2.9.4

« back to all changes in this revision

Viewing changes to wxPython/src/_toolbar.i

  • Committer: Brian Sidebotham
  • Date: 2013-08-03 14:30:08 UTC
  • Revision ID: brian.sidebotham@gmail.com-20130803143008-c7806tkych1tp6fc
Initial import into Bazaar

Show diffs side-by-side

added added

removed removed

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