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

« back to all changes in this revision

Viewing changes to wxPython/src/_treectrl.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:        _treectrl.i
 
3
// Purpose:     SWIG interface file for wxTreeCtrl and related classes
 
4
//
 
5
// Author:      Robin Dunn
 
6
//
 
7
// Created:     10-June-1998
 
8
// RCS-ID:      $Id: _treectrl.i 71592 2012-05-30 03:10:49Z RD $
 
9
// Copyright:   (c) 2002 by Total Control Software
 
10
// Licence:     wxWindows license
 
11
/////////////////////////////////////////////////////////////////////////////
 
12
 
 
13
// Not a %module
 
14
 
 
15
 
 
16
//---------------------------------------------------------------------------
 
17
 
 
18
%{
 
19
#include <wx/treectrl.h>
 
20
#include "wx/wxPython/pytree.h"
 
21
%}
 
22
    
 
23
MAKE_CONST_WXSTRING2(TreeCtrlNameStr, _T("wxTreeCtrl"));
 
24
 
 
25
//---------------------------------------------------------------------------
 
26
%newgroup
 
27
 
 
28
 
 
29
// wxTreeCtrl flags
 
30
enum {
 
31
    wxTR_NO_BUTTONS,
 
32
    wxTR_HAS_BUTTONS,
 
33
    wxTR_NO_LINES,
 
34
    wxTR_LINES_AT_ROOT,
 
35
 
 
36
    wxTR_SINGLE,
 
37
    wxTR_MULTIPLE,
 
38
    wxTR_EXTENDED,
 
39
    wxTR_HAS_VARIABLE_ROW_HEIGHT,
 
40
 
 
41
    wxTR_EDIT_LABELS,
 
42
    wxTR_HIDE_ROOT,
 
43
    wxTR_ROW_LINES,
 
44
 
 
45
    wxTR_FULL_ROW_HIGHLIGHT,
 
46
    wxTR_DEFAULT_STYLE,
 
47
 
 
48
    wxTR_TWIST_BUTTONS,
 
49
};
 
50
 
 
51
%pythoncode {
 
52
    %# obsolete
 
53
    TR_MAC_BUTTONS = 0
 
54
    wxTR_AQUA_BUTTONS = 0
 
55
}
 
56
 
 
57
enum wxTreeItemIcon
 
58
{
 
59
    wxTreeItemIcon_Normal,              // not selected, not expanded
 
60
    wxTreeItemIcon_Selected,            //     selected, not expanded
 
61
    wxTreeItemIcon_Expanded,            // not selected,     expanded
 
62
    wxTreeItemIcon_SelectedExpanded,    //     selected,     expanded
 
63
    wxTreeItemIcon_Max
 
64
};
 
65
 
 
66
enum {
 
67
    wxTREE_ITEMSTATE_NONE,    // not state (no display state image)
 
68
    wxTREE_ITEMSTATE_NEXT,    // cycle to the next state
 
69
    wxTREE_ITEMSTATE_PREV     // cycle to the previous state
 
70
};
 
71
 
 
72
// constants for HitTest
 
73
enum {
 
74
    wxTREE_HITTEST_ABOVE,
 
75
    wxTREE_HITTEST_BELOW,
 
76
    wxTREE_HITTEST_NOWHERE,
 
77
    wxTREE_HITTEST_ONITEMBUTTON,
 
78
    wxTREE_HITTEST_ONITEMICON,
 
79
    wxTREE_HITTEST_ONITEMINDENT,
 
80
    wxTREE_HITTEST_ONITEMLABEL,
 
81
    wxTREE_HITTEST_ONITEMRIGHT,
 
82
    wxTREE_HITTEST_ONITEMSTATEICON,
 
83
    wxTREE_HITTEST_TOLEFT,
 
84
    wxTREE_HITTEST_TORIGHT,
 
85
    wxTREE_HITTEST_ONITEMUPPERPART,
 
86
    wxTREE_HITTEST_ONITEMLOWERPART,
 
87
    wxTREE_HITTEST_ONITEM
 
88
};
 
89
 
 
90
//---------------------------------------------------------------------------
 
91
%newgroup
 
92
 
 
93
 
 
94
// wxTreeItemId identifies an element of the tree. In this implementation, it's
 
95
// just a trivial wrapper around Win32 HTREEITEM or a pointer to some private
 
96
// data structure in the generic version. It's opaque for the application and
 
97
// the only method which can be used by user code is IsOk().
 
98
class wxTreeItemId {
 
99
public:
 
100
    wxTreeItemId();
 
101
    ~wxTreeItemId(); 
 
102
 
 
103
    // is this a valid tree item?
 
104
    bool IsOk() const;
 
105
 
 
106
    %extend {
 
107
        bool __eq__(const wxTreeItemId* other) { return other ? (*self == *other) : false; }
 
108
        bool __ne__(const wxTreeItemId* other) { return other ? (*self != *other) : true;  }
 
109
    }
 
110
 
 
111
    void*  m_pItem;
 
112
 
 
113
 
 
114
    %pythoncode {
 
115
        Ok = IsOk
 
116
        def __nonzero__(self): return self.IsOk() }
 
117
};
 
118
 
 
119
 
 
120
 
 
121
 
 
122
// wxTreeItemData is some (arbitrary) user data associated with some tree
 
123
// item.  The Python version is just a simple wrapper around a Python object
 
124
// that knows how to handle references properly.  Using this class directly in
 
125
// Python code should rarely be neccessary.  Just use the GetItemPyData and
 
126
// SetItemPyData tree methods instead of the GetItemData and SetItemData
 
127
// methods.
 
128
%rename(TreeItemData) wxPyTreeItemData;
 
129
class wxPyTreeItemData {
 
130
public:
 
131
    wxPyTreeItemData(PyObject* obj = NULL);
 
132
    ~wxPyTreeItemData();
 
133
    
 
134
    PyObject* GetData();
 
135
    void      SetData(PyObject* obj);
 
136
 
 
137
    const wxTreeItemId& GetId();
 
138
    void                SetId(const wxTreeItemId& id);
 
139
 
 
140
    %pythonPrepend Destroy "args[0].this.own(False)"
 
141
    %extend { void Destroy() { delete self; } }
 
142
 
 
143
    %property(Data, GetData, SetData, doc="See `GetData` and `SetData`");
 
144
    %property(Id, GetId, SetId, doc="See `GetId` and `SetId`");
 
145
};
 
146
 
 
147
 
 
148
 
 
149
#if 0  // it's not currently used anywhere...
 
150
 
 
151
// wxTreeItemAttr: a structure containing the visual attributes of an item
 
152
class wxTreeItemAttr
 
153
{
 
154
public:
 
155
    // ctors
 
156
    //wxTreeItemAttr() { }
 
157
    wxTreeItemAttr(const wxColour& colText = wxNullColour,
 
158
                   const wxColour& colBack = wxNullColour,
 
159
                   const wxFont& font = wxNullFont);
 
160
    ~wxTreeItemAttr();
 
161
    
 
162
    // setters
 
163
    void SetTextColour(const wxColour& colText);
 
164
    void SetBackgroundColour(const wxColour& colBack);
 
165
    void SetFont(const wxFont& font);
 
166
 
 
167
    // accessors
 
168
    bool HasTextColour();
 
169
    bool HasBackgroundColour();
 
170
    bool HasFont();
 
171
 
 
172
    wxColour GetTextColour();
 
173
    wxColour GetBackgroundColour();
 
174
    wxFont GetFont();
 
175
 
 
176
    %pythonAppend Destroy "args[0].thisown = 0"
 
177
    %extend { void Destroy() { delete self; } }
 
178
};
 
179
 
 
180
#endif
 
181
 
 
182
 
 
183
//---------------------------------------------------------------------------
 
184
%newgroup
 
185
 
 
186
/* Tree control event types */
 
187
%constant wxEventType wxEVT_COMMAND_TREE_BEGIN_DRAG;
 
188
%constant wxEventType wxEVT_COMMAND_TREE_BEGIN_RDRAG;
 
189
%constant wxEventType wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT;
 
190
%constant wxEventType wxEVT_COMMAND_TREE_END_LABEL_EDIT;
 
191
%constant wxEventType wxEVT_COMMAND_TREE_DELETE_ITEM;
 
192
%constant wxEventType wxEVT_COMMAND_TREE_GET_INFO;
 
193
%constant wxEventType wxEVT_COMMAND_TREE_SET_INFO;
 
194
%constant wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDED;
 
195
%constant wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDING;
 
196
%constant wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSED;
 
197
%constant wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSING;
 
198
%constant wxEventType wxEVT_COMMAND_TREE_SEL_CHANGED;
 
199
%constant wxEventType wxEVT_COMMAND_TREE_SEL_CHANGING;
 
200
%constant wxEventType wxEVT_COMMAND_TREE_KEY_DOWN;
 
201
%constant wxEventType wxEVT_COMMAND_TREE_ITEM_ACTIVATED;
 
202
%constant wxEventType wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK;
 
203
%constant wxEventType wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK;
 
204
%constant wxEventType wxEVT_COMMAND_TREE_END_DRAG;
 
205
%constant wxEventType wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK;
 
206
%constant wxEventType wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP;
 
207
%constant wxEventType wxEVT_COMMAND_TREE_ITEM_MENU;
 
208
 
 
209
%pythoncode {
 
210
EVT_TREE_BEGIN_DRAG        = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_DRAG       , 1)
 
211
EVT_TREE_BEGIN_RDRAG       = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_RDRAG      , 1)
 
212
EVT_TREE_BEGIN_LABEL_EDIT  = wx.PyEventBinder(wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT , 1)
 
213
EVT_TREE_END_LABEL_EDIT    = wx.PyEventBinder(wxEVT_COMMAND_TREE_END_LABEL_EDIT   , 1)
 
214
EVT_TREE_DELETE_ITEM       = wx.PyEventBinder(wxEVT_COMMAND_TREE_DELETE_ITEM      , 1)
 
215
EVT_TREE_GET_INFO          = wx.PyEventBinder(wxEVT_COMMAND_TREE_GET_INFO         , 1)
 
216
EVT_TREE_SET_INFO          = wx.PyEventBinder(wxEVT_COMMAND_TREE_SET_INFO         , 1)
 
217
EVT_TREE_ITEM_EXPANDED     = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_EXPANDED    , 1)
 
218
EVT_TREE_ITEM_EXPANDING    = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_EXPANDING   , 1)
 
219
EVT_TREE_ITEM_COLLAPSED    = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_COLLAPSED   , 1)
 
220
EVT_TREE_ITEM_COLLAPSING   = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_COLLAPSING  , 1)
 
221
EVT_TREE_SEL_CHANGED       = wx.PyEventBinder(wxEVT_COMMAND_TREE_SEL_CHANGED      , 1)
 
222
EVT_TREE_SEL_CHANGING      = wx.PyEventBinder(wxEVT_COMMAND_TREE_SEL_CHANGING     , 1)
 
223
EVT_TREE_KEY_DOWN          = wx.PyEventBinder(wxEVT_COMMAND_TREE_KEY_DOWN         , 1)
 
224
EVT_TREE_ITEM_ACTIVATED    = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_ACTIVATED   , 1)
 
225
EVT_TREE_ITEM_RIGHT_CLICK  = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK , 1)
 
226
EVT_TREE_ITEM_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, 1)
 
227
EVT_TREE_END_DRAG          = wx.PyEventBinder(wxEVT_COMMAND_TREE_END_DRAG         , 1)
 
228
EVT_TREE_STATE_IMAGE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, 1)
 
229
EVT_TREE_ITEM_GETTOOLTIP   = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP,   1)
 
230
EVT_TREE_ITEM_MENU         = wx.PyEventBinder(wxEVT_COMMAND_TREE_ITEM_MENU,         1)
 
231
}
 
232
 
 
233
 
 
234
%{
 
235
    static wxTreeItemId wxNullTreeItemId;
 
236
%}
 
237
wxTreeItemId wxNullTreeItemId;
 
238
 
 
239
 
 
240
// wxTreeEvent is a special class for all events associated with tree controls
 
241
//
 
242
// NB: note that not all accessors make sense for all events, see the event
 
243
//     descriptions below
 
244
class wxTreeEvent : public wxNotifyEvent {
 
245
public:
 
246
    %nokwargs wxTreeEvent;
 
247
    wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
 
248
    wxTreeEvent(wxEventType   commandType,
 
249
                wxPyTreeCtrl* tree,
 
250
                wxTreeItemId& item = wxNullTreeItemId);
 
251
 
 
252
        // get the item on which the operation was performed or the newly
 
253
        // selected item for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events
 
254
    wxTreeItemId GetItem() const;
 
255
    void SetItem(const wxTreeItemId& item);
 
256
 
 
257
        // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously
 
258
        // selected item
 
259
    wxTreeItemId GetOldItem() const;
 
260
    void SetOldItem(const wxTreeItemId& item);
 
261
 
 
262
        // the point where the mouse was when the drag operation started (for
 
263
        // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only) or click position
 
264
    wxPoint GetPoint() const;
 
265
    void SetPoint(const wxPoint& pt);
 
266
 
 
267
        // keyboard data (for wxEVT_COMMAND_TREE_KEY_DOWN only)
 
268
    const wxKeyEvent& GetKeyEvent() const;
 
269
    int GetKeyCode() const;
 
270
    void SetKeyEvent(const wxKeyEvent& evt);
 
271
 
 
272
        // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
 
273
    const wxString& GetLabel() const;
 
274
    void SetLabel(const wxString& label);
 
275
 
 
276
        // edit cancel flag (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
 
277
    bool IsEditCancelled() const;
 
278
    void SetEditCanceled(bool editCancelled);
 
279
 
 
280
        // Set the tooltip for the item (for EVT_TREE_ITEM_GETTOOLTIP events)
 
281
    void SetToolTip(const wxString& toolTip);
 
282
    wxString GetToolTip();
 
283
 
 
284
    %property(Item, GetItem, SetItem, doc="See `GetItem` and `SetItem`");
 
285
    %property(KeyCode, GetKeyCode, doc="See `GetKeyCode`");
 
286
    %property(KeyEvent, GetKeyEvent, SetKeyEvent, doc="See `GetKeyEvent` and `SetKeyEvent`");
 
287
    %property(Label, GetLabel, SetLabel, doc="See `GetLabel` and `SetLabel`");
 
288
    %property(OldItem, GetOldItem, SetOldItem, doc="See `GetOldItem` and `SetOldItem`");
 
289
    %property(Point, GetPoint, SetPoint, doc="See `GetPoint` and `SetPoint`");
 
290
    %property(ToolTip, GetToolTip, SetToolTip, doc="See `GetToolTip` and `SetToolTip`");
 
291
    %property(EditCancelled, IsEditCancelled, SetEditCanceled, doc="See `IsEditCancelled` and `SetEditCanceled`");
 
292
};
 
293
 
 
294
//---------------------------------------------------------------------------
 
295
%newgroup
 
296
 
 
297
%{ // C++ version of Python aware wxTreeCtrl
 
298
class wxPyTreeCtrl : public wxTreeCtrl {
 
299
    DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl)
 
300
public:
 
301
    wxPyTreeCtrl() : wxTreeCtrl() {}
 
302
    wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
 
303
                 const wxPoint& pos,
 
304
                 const wxSize& size,
 
305
                 long style,
 
306
                 const wxValidator& validator,
 
307
                 const wxString& name) :
 
308
        wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
 
309
 
 
310
    bool Create(wxWindow *parent, wxWindowID id,
 
311
                const wxPoint& pos,
 
312
                const wxSize& size,
 
313
                long style,
 
314
                const wxValidator& validator,
 
315
                const wxString& name) {
 
316
        return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
 
317
    }
 
318
 
 
319
 
 
320
    int OnCompareItems(const wxTreeItemId& item1,
 
321
                       const wxTreeItemId& item2) {
 
322
        int rval = 0;
 
323
        bool found;
 
324
        wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
325
        if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) {
 
326
            PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), false);
 
327
            PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), false);
 
328
            rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2));
 
329
            Py_DECREF(o1);
 
330
            Py_DECREF(o2);
 
331
        }
 
332
        wxPyEndBlockThreads(blocked);
 
333
        if (! found)
 
334
            rval = wxTreeCtrl::OnCompareItems(item1, item2);
 
335
        return rval;
 
336
    }
 
337
    PYPRIVATE;
 
338
};
 
339
 
 
340
IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
 
341
 
 
342
%}
 
343
 
 
344
 
 
345
 
 
346
 
 
347
MustHaveApp(wxPyTreeCtrl);
 
348
 
 
349
%rename(TreeCtrl) wxPyTreeCtrl;
 
350
class wxPyTreeCtrl : public wxControl {
 
351
public:
 
352
    %pythonAppend wxPyTreeCtrl         "self._setOORInfo(self);" setCallbackInfo(TreeCtrl)
 
353
    %pythonAppend wxPyTreeCtrl()       ""
 
354
    %typemap(out) wxPyTreeCtrl*;    // turn off this typemap
 
355
   
 
356
    wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
 
357
                 const wxPoint& pos = wxDefaultPosition,
 
358
                 const wxSize& size = wxDefaultSize,
 
359
                 long style = wxTR_DEFAULT_STYLE,
 
360
                 const wxValidator& validator = wxDefaultValidator,
 
361
                 const wxString& name = wxPyTreeCtrlNameStr);
 
362
    %RenameCtor(PreTreeCtrl, wxPyTreeCtrl());
 
363
 
 
364
    // Turn it back on again
 
365
    %typemap(out) wxPyTreeCtrl* { $result = wxPyMake_wxObject($1, $owner); }
 
366
 
 
367
    bool Create(wxWindow *parent, wxWindowID id = -1,
 
368
                const wxPoint& pos = wxDefaultPosition,
 
369
                const wxSize& size = wxDefaultSize,
 
370
                long style = wxTR_DEFAULT_STYLE,
 
371
                const wxValidator& validator = wxDefaultValidator,
 
372
                const wxString& name = wxPyTreeCtrlNameStr);
 
373
 
 
374
    void _setCallbackInfo(PyObject* self, PyObject* _class);
 
375
 
 
376
    
 
377
    // get the total number of items in the control
 
378
    unsigned int GetCount() const;
 
379
 
 
380
    // indent is the number of pixels the children are indented relative to
 
381
    // the parents position. SetIndent() also redraws the control
 
382
    // immediately.
 
383
    unsigned int GetIndent() const;
 
384
    void SetIndent(unsigned int indent);
 
385
 
 
386
    // spacing is the number of pixels between the start and the Text
 
387
    // not implemented under wxMSW
 
388
    unsigned int GetSpacing() const;
 
389
    void SetSpacing(unsigned int spacing);
 
390
 
 
391
 
 
392
    // image list: these functions allow to associate an image list with
 
393
    // the control and retrieve it. Note that the control does _not_ delete
 
394
    // the associated image list when it's deleted in order to allow image
 
395
    // lists to be shared between different controls.
 
396
    //
 
397
    // The normal image list is for the icons which correspond to the
 
398
    // normal tree item state (whether it is selected or not).
 
399
    // Additionally, the application might choose to show a state icon
 
400
    // which corresponds to an app-defined item state (for example,
 
401
    // checked/unchecked) which are taken from the state image list.
 
402
    wxImageList *GetImageList() const;
 
403
    wxImageList *GetStateImageList() const;
 
404
 
 
405
    void SetImageList(wxImageList *imageList);
 
406
    void SetStateImageList(wxImageList *imageList);
 
407
 
 
408
    %disownarg( wxImageList *imageList );
 
409
    void AssignImageList(wxImageList *imageList);
 
410
    void AssignStateImageList(wxImageList *imageList);
 
411
    %cleardisown( wxImageList *imageList );
 
412
    
 
413
 
 
414
    // retrieve items label
 
415
    wxString GetItemText(const wxTreeItemId& item) const;
 
416
    
 
417
    // get one of the images associated with the item (normal by default)
 
418
    int GetItemImage(const wxTreeItemId& item,
 
419
                     wxTreeItemIcon which = wxTreeItemIcon_Normal) const;
 
420
 
 
421
    %extend {
 
422
        // get the wxPyTreeItemData associated with the tree item
 
423
        wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
 
424
            wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
 
425
            return data;
 
426
        }
 
427
        // Get the Python object associated with the tree item
 
428
        PyObject* GetItemPyData(const wxTreeItemId& item) {
 
429
            wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
 
430
            return wxPyTreeItemData::SafeGetData(data);
 
431
        }
 
432
    }
 
433
    %pythoncode { GetPyData = GetItemPyData }
 
434
        
 
435
 
 
436
    // get the item's text colour
 
437
    wxColour GetItemTextColour(const wxTreeItemId& item) const;
 
438
 
 
439
    // get the item's background colour
 
440
    wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
 
441
 
 
442
    // get the item's font
 
443
    wxFont GetItemFont(const wxTreeItemId& item) const;
 
444
 
 
445
    int GetItemState(const wxTreeItemId& item) const;
 
446
 
 
447
    // set items label
 
448
    void SetItemText(const wxTreeItemId& item, const wxString& text);
 
449
 
 
450
    // get one of the images associated with the item (normal by default)
 
451
    void SetItemImage(const wxTreeItemId& item, int image,
 
452
                      wxTreeItemIcon which = wxTreeItemIcon_Normal);
 
453
 
 
454
    %extend {
 
455
        // associate a wxPyTreeItemData with the tree item
 
456
        %disownarg( wxPyTreeItemData* data );
 
457
        void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
 
458
            self->SetItemData(item, data);
 
459
        }
 
460
        %cleardisown( wxPyTreeItemData* data );
 
461
 
 
462
        // associate a Python object with the tree item
 
463
        void SetItemPyData(const wxTreeItemId& item, PyObject* obj) {
 
464
            wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
 
465
            if (data == NULL) {
 
466
                data = new wxPyTreeItemData(obj);
 
467
                self->SetItemData(item, data);
 
468
            } else {
 
469
                data->SetData(obj);
 
470
            }
 
471
        }
 
472
    }
 
473
    %pythoncode { SetPyData = SetItemPyData }
 
474
 
 
475
 
 
476
    // force appearance of [+] button near the item. This is useful to
 
477
    // allow the user to expand the items which don't have any children now
 
478
    // - but instead add them only when needed, thus minimizing memory
 
479
    // usage and loading time.
 
480
    void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
 
481
 
 
482
    // the item will be shown in bold
 
483
    void SetItemBold(const wxTreeItemId& item, bool bold = true);
 
484
 
 
485
    // the item will be shown with a drop highlight
 
486
    void SetItemDropHighlight(const wxTreeItemId& item, bool highlight = true);
 
487
    
 
488
    // set the items text colour
 
489
    void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
 
490
 
 
491
    // set the items background colour
 
492
    void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
 
493
 
 
494
    // set the items font (should be of the same height for all items)
 
495
    void SetItemFont(const wxTreeItemId& item, const wxFont& font);
 
496
 
 
497
    void SetItemState(const wxTreeItemId& item, int state);
 
498
 
 
499
    // is the item visible (it might be outside the view or not expanded)?
 
500
    bool IsVisible(const wxTreeItemId& item) const;
 
501
 
 
502
    // does the item has any children?
 
503
    bool ItemHasChildren(const wxTreeItemId& item) const;
 
504
 
 
505
    // is the item expanded (only makes sense if HasChildren())?
 
506
    bool IsExpanded(const wxTreeItemId& item) const;
 
507
 
 
508
    // is this item currently selected (the same as has focus)?
 
509
    bool IsSelected(const wxTreeItemId& item) const;
 
510
 
 
511
    // is item text in bold font?
 
512
    bool IsBold(const wxTreeItemId& item) const;
 
513
 
 
514
    // is the control empty?
 
515
    bool IsEmpty() const;
 
516
    
 
517
 
 
518
    // if 'recursively' is False, only immediate children count, otherwise
 
519
    // the returned number is the number of all items in this branch
 
520
    size_t GetChildrenCount(const wxTreeItemId& item,
 
521
                            bool recursively = true) /*const*/;
 
522
 
 
523
 
 
524
 
 
525
    // get the root tree item
 
526
    // wxTreeItemId.IsOk() will return False if there is no such item
 
527
    wxTreeItemId GetRootItem() const;
 
528
 
 
529
    // get the item currently selected 
 
530
    // wxTreeItemId.IsOk() will return False if there is no such item
 
531
    wxTreeItemId GetSelection() const;
 
532
 
 
533
    %extend {
 
534
        // get the items currently selected, return the number of such item
 
535
        //
 
536
        // NB: this operation is expensive and can take a long time for a
 
537
        //     control with a lot of items (~ O(number of items)).
 
538
        PyObject* GetSelections() {
 
539
            wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
540
            PyObject*           rval = PyList_New(0);
 
541
            wxArrayTreeItemIds  array;
 
542
            size_t              num, x;
 
543
            num = self->GetSelections(array);
 
544
            for (x=0; x < num; x++) {
 
545
                wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
 
546
                PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), true);
 
547
                PyList_Append(rval, item);
 
548
                Py_DECREF(item);
 
549
            }
 
550
            wxPyEndBlockThreads(blocked);
 
551
            return rval;
 
552
        }
 
553
    }
 
554
 
 
555
    virtual wxTreeItemId GetFocusedItem() const;
 
556
    virtual void ClearFocusedItem();
 
557
    virtual void SetFocusedItem(const wxTreeItemId& item);
 
558
 
 
559
    // get the parent of this item
 
560
    // wxTreeItemId.IsOk() will return False if there is no such item
 
561
    wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
 
562
 
 
563
 
 
564
    // NOTE: These are a copy of the same methods in gizmos.i, be sure to
 
565
    // update both at the same time.  (Or find a good way to refactor!)
 
566
    %extend {
 
567
        // Get the first child of this item.  Returns a wxTreeItemId and an
 
568
        // opaque "cookie" value that should be passed to GetNextChild in
 
569
        // order to continue the search.
 
570
        PyObject* GetFirstChild(const wxTreeItemId& item) {
 
571
            void* cookie = 0;
 
572
            wxTreeItemId* ritem = new wxTreeItemId(self->GetFirstChild(item, cookie));
 
573
            wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
574
            PyObject* tup = PyTuple_New(2);
 
575
            PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true));
 
576
            PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void")));
 
577
            wxPyEndBlockThreads(blocked);
 
578
            return tup;
 
579
        }
 
580
 
 
581
 
 
582
        // Get the next child of this item.  The cookie parameter is the 2nd
 
583
        // value returned from GetFirstChild or the previous GetNextChild.
 
584
        // Returns a wxTreeItemId and an opaque "cookie" value that should be
 
585
        // passed to GetNextChild in order to continue the search.
 
586
        PyObject* GetNextChild(const wxTreeItemId& item, void* cookie) {
 
587
            wxTreeItemId* ritem = new wxTreeItemId(self->GetNextChild(item, cookie));
 
588
            wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
589
            PyObject* tup = PyTuple_New(2);
 
590
            PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true));
 
591
            PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void")));
 
592
            wxPyEndBlockThreads(blocked);
 
593
            return tup;
 
594
        }            
 
595
    }
 
596
    
 
597
    // get the last child of this item
 
598
    wxTreeItemId GetLastChild(const wxTreeItemId& item) const;
 
599
 
 
600
    // get the next sibling of this item
 
601
    wxTreeItemId GetNextSibling(const wxTreeItemId& item) const;
 
602
 
 
603
    // get the previous sibling
 
604
    wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const;
 
605
 
 
606
    // get first visible item
 
607
    wxTreeItemId GetFirstVisibleItem() const;
 
608
 
 
609
    // get the next visible item: item must be visible itself!
 
610
    // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem()
 
611
    wxTreeItemId GetNextVisible(const wxTreeItemId& item) const;
 
612
 
 
613
    // get the previous visible item: item must be visible itself!
 
614
    wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const;
 
615
 
 
616
    
 
617
    %disownarg( wxPyTreeItemData* data );
 
618
    
 
619
    // add the root node to the tree
 
620
    wxTreeItemId AddRoot(const wxString& text,
 
621
                         int image = -1, int selectedImage = -1,
 
622
                         wxPyTreeItemData *data = NULL);
 
623
 
 
624
    // insert a new item in as the first child of the parent
 
625
    wxTreeItemId PrependItem(const wxTreeItemId& parent,
 
626
                             const wxString& text,
 
627
                             int image = -1, int selectedImage = -1,
 
628
                             wxPyTreeItemData *data = NULL);
 
629
 
 
630
    // insert a new item after a given one
 
631
    wxTreeItemId InsertItem(const wxTreeItemId& parent,
 
632
                            const wxTreeItemId& idPrevious,
 
633
                            const wxString& text,
 
634
                            int image = -1, int selectedImage = -1,
 
635
                            wxPyTreeItemData *data = NULL);
 
636
 
 
637
    // insert a new item before the one with the given index
 
638
    %Rename(InsertItemBefore, 
 
639
    wxTreeItemId, InsertItem(const wxTreeItemId& parent,
 
640
                            size_t index,
 
641
                            const wxString& text,
 
642
                            int image = -1, int selectedImage = -1,
 
643
                            wxPyTreeItemData *data = NULL));
 
644
 
 
645
        // insert a new item in as the last child of the parent
 
646
    wxTreeItemId AppendItem(const wxTreeItemId& parent,
 
647
                            const wxString& text,
 
648
                            int image = -1, int selectedImage = -1,
 
649
                            wxPyTreeItemData *data = NULL);
 
650
 
 
651
 
 
652
    %cleardisown( wxPyTreeItemData* data );
 
653
    
 
654
    // delete this item and associated data if any
 
655
    void Delete(const wxTreeItemId& item);
 
656
 
 
657
    // delete all children (but don't delete the item itself)
 
658
    // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
 
659
    void DeleteChildren(const wxTreeItemId& item);
 
660
 
 
661
    // delete all items from the tree
 
662
    // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events
 
663
    void DeleteAllItems();
 
664
 
 
665
 
 
666
    // expand this item
 
667
    void Expand(const wxTreeItemId& item);
 
668
 
 
669
    // expand the item and all its childs and thats childs
 
670
    void ExpandAllChildren(const wxTreeItemId& item);
 
671
 
 
672
    // expand all items
 
673
    void ExpandAll();
 
674
   
 
675
    // collapse the item without removing its children
 
676
    void Collapse(const wxTreeItemId& item);
 
677
 
 
678
    // collapse the item and all its childs and thats childs
 
679
    void CollapseAllChildren(const wxTreeItemId& item);
 
680
 
 
681
    // collapse all items
 
682
    void CollapseAll();
 
683
    
 
684
    // collapse the item and remove all children
 
685
    void CollapseAndReset(const wxTreeItemId& item);
 
686
 
 
687
    // toggles the current state
 
688
    void Toggle(const wxTreeItemId& item);
 
689
 
 
690
 
 
691
    // remove the selection from currently selected item (if any)
 
692
    void Unselect();
 
693
 
 
694
    // remove the selection from the given one (multiselect mode only)
 
695
    void UnselectItem(const wxTreeItemId& item);
 
696
    
 
697
    // unselect all items (only makes sense for multiple selection control)
 
698
    void UnselectAll();
 
699
 
 
700
    // select this item
 
701
    void SelectItem(const wxTreeItemId& item, bool select = true);
 
702
    void SelectChildren(const wxTreeItemId& parent);
 
703
 
 
704
    // toggle the item selection
 
705
    void ToggleItemSelection(const wxTreeItemId& item);
 
706
 
 
707
    
 
708
    // make sure this item is visible (expanding the parent item and/or
 
709
    // scrolling to this item if necessary)
 
710
    void EnsureVisible(const wxTreeItemId& item);
 
711
 
 
712
    // scroll to this item (but don't expand its parent)
 
713
    void ScrollTo(const wxTreeItemId& item);
 
714
 
 
715
 
 
716
 
 
717
    // start editing the item label: this (temporarily) replaces the item
 
718
    // with a one line edit control. The item will be selected if it hadn't
 
719
    // been before.
 
720
    /**wxTextCtrl* */ void  EditLabel(const wxTreeItemId& item);
 
721
    
 
722
    // returns the same pointer as StartEdit() if the item is being edited,
 
723
    // NULL otherwise (it's assumed that no more than one item may be
 
724
    // edited simultaneously)
 
725
    wxTextCtrl* GetEditControl() const;
 
726
 
 
727
#ifdef __WXMSW__
 
728
    // end editing and accept or discard the changes to item label
 
729
    void EndEditLabel(const wxTreeItemId& item, bool discardChanges = false);
 
730
#endif
 
731
 
 
732
 
 
733
    // Sort the children of this item using OnCompareItems, a member function
 
734
    // that is called to compare 2 items and should return -1, 0 or +1 if the
 
735
    // first item is less than, equal to or greater than the second one. The
 
736
    // base class version performs alphabetic comparaison of item labels
 
737
    // (GetText)
 
738
    void SortChildren(const wxTreeItemId& item);
 
739
 
 
740
 
 
741
 
 
742
    DocDeclAStr(
 
743
        wxTreeItemId, HitTest(const wxPoint& point, int& OUTPUT),
 
744
        "HitTest(Point point) -> (item, where)",
 
745
        "Determine which item (if any) belongs the given point.  The coordinates
 
746
specified are relative to the client area of tree ctrl and the where return
 
747
value is set to a bitmask of wxTREE_HITTEST_xxx constants.
 
748
", "");
 
749
    
 
750
 
 
751
    %extend {
 
752
        // get the bounding rectangle of the item (or of its label only)
 
753
        PyObject* GetBoundingRect(const wxTreeItemId& item,  bool textOnly = false) {
 
754
             wxRect rect;
 
755
            if (self->GetBoundingRect(item, rect, textOnly)) {
 
756
                wxPyBlock_t blocked = wxPyBeginBlockThreads();
 
757
                wxRect* r = new wxRect(rect);
 
758
                PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), true);
 
759
                wxPyEndBlockThreads(blocked);
 
760
                return val;
 
761
            }
 
762
            else
 
763
                RETURN_NONE();
 
764
        }
 
765
    }
 
766
 
 
767
    static wxVisualAttributes
 
768
    GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
 
769
 
 
770
    void SetQuickBestSize(bool q);
 
771
    bool GetQuickBestSize() const;
 
772
 
 
773
    %property(Count, GetCount, doc="See `GetCount`");
 
774
    %property(EditControl, GetEditControl, doc="See `GetEditControl`");
 
775
    %property(FirstVisibleItem, GetFirstVisibleItem, doc="See `GetFirstVisibleItem`");
 
776
    %property(ImageList, GetImageList, SetImageList, doc="See `GetImageList` and `SetImageList`");
 
777
    %property(Indent, GetIndent, SetIndent, doc="See `GetIndent` and `SetIndent`");
 
778
    %property(QuickBestSize, GetQuickBestSize, SetQuickBestSize, doc="See `GetQuickBestSize` and `SetQuickBestSize`");
 
779
    %property(RootItem, GetRootItem, doc="See `GetRootItem`");
 
780
    %property(Selection, GetSelection, doc="See `GetSelection`");
 
781
    %property(Selections, GetSelections, doc="See `GetSelections`");
 
782
    %property(Spacing, GetSpacing, SetSpacing, doc="See `GetSpacing` and `SetSpacing`");
 
783
    %property(StateImageList, GetStateImageList, SetStateImageList, doc="See `GetStateImageList` and `SetStateImageList`");
 
784
};
 
785
 
 
786
 
 
787
//---------------------------------------------------------------------------
 
788
%init %{
 
789
    // Map renamed classes back to their common name for OOR
 
790
    wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
 
791
    wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
 
792
%}
 
793
//---------------------------------------------------------------------------