]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/controls2.i
merged wxRegConf rename fix from 2.2
[wxWidgets.git] / wxPython / src / controls2.i
CommitLineData
7bf85405
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: controls2.i
3// Purpose: More control (widget) classes for wxPython
4//
5// Author: Robin Dunn
6//
7// Created: 6/10/98
8// RCS-ID: $Id$
9// Copyright: (c) 1998 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
03e9bead 13%module controls2
7bf85405 14
03e9bead 15%{
7bf85405 16#include "helpers.h"
2f90df85
RD
17#ifdef __WXMSW__
18#include <windows.h>
19#endif
7bf85405
RD
20#include <wx/listctrl.h>
21#include <wx/treectrl.h>
9416aa89 22#include <wx/imaglist.h>
7bf85405
RD
23%}
24
25//----------------------------------------------------------------------
26
27%include typemaps.i
28%include my_typemaps.i
29
30// Import some definitions of other classes, etc.
31%import _defs.i
32%import misc.i
33%import windows.i
34%import gdi.i
35%import events.i
36%import controls.i
37
b8b8dda7 38%pragma(python) code = "import wx"
9c039d08 39
7bf85405
RD
40//----------------------------------------------------------------------
41
7bf85405 42
af309447
RD
43enum {
44 wxLIST_MASK_TEXT,
45 wxLIST_MASK_IMAGE,
46 wxLIST_MASK_DATA,
47 wxLIST_MASK_WIDTH,
48 wxLIST_MASK_FORMAT,
bb0054cd 49 wxLIST_MASK_STATE,
af309447
RD
50 wxLIST_STATE_DONTCARE,
51 wxLIST_STATE_DROPHILITED,
52 wxLIST_STATE_FOCUSED,
53 wxLIST_STATE_SELECTED,
54 wxLIST_STATE_CUT,
55 wxLIST_HITTEST_ABOVE,
56 wxLIST_HITTEST_BELOW,
57 wxLIST_HITTEST_NOWHERE,
58 wxLIST_HITTEST_ONITEMICON,
59 wxLIST_HITTEST_ONITEMLABEL,
60 wxLIST_HITTEST_ONITEMRIGHT,
61 wxLIST_HITTEST_ONITEMSTATEICON,
62 wxLIST_HITTEST_TOLEFT,
63 wxLIST_HITTEST_TORIGHT,
64 wxLIST_HITTEST_ONITEM,
65 wxLIST_NEXT_ABOVE,
66 wxLIST_NEXT_ALL,
67 wxLIST_NEXT_BELOW,
68 wxLIST_NEXT_LEFT,
69 wxLIST_NEXT_RIGHT,
70 wxLIST_ALIGN_DEFAULT,
71 wxLIST_ALIGN_LEFT,
72 wxLIST_ALIGN_TOP,
73 wxLIST_ALIGN_SNAP_TO_GRID,
af309447
RD
74 wxLIST_AUTOSIZE,
75 wxLIST_AUTOSIZE_USEHEADER,
76 wxLIST_RECT_BOUNDS,
77 wxLIST_RECT_ICON,
78 wxLIST_RECT_LABEL,
79 wxLIST_FIND_UP,
80 wxLIST_FIND_DOWN,
81 wxLIST_FIND_LEFT,
82 wxLIST_FIND_RIGHT,
83};
84
85
f6bcfd97
BP
86enum wxListColumnFormat
87{
88 wxLIST_FORMAT_LEFT,
89 wxLIST_FORMAT_RIGHT,
90 wxLIST_FORMAT_CENTRE,
91 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
92};
93
94
1b62f00d
RD
95enum {
96 /* List control event types */
97 wxEVT_COMMAND_LIST_BEGIN_DRAG,
98 wxEVT_COMMAND_LIST_BEGIN_RDRAG,
99 wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT,
100 wxEVT_COMMAND_LIST_END_LABEL_EDIT,
101 wxEVT_COMMAND_LIST_DELETE_ITEM,
102 wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS,
103 wxEVT_COMMAND_LIST_GET_INFO,
104 wxEVT_COMMAND_LIST_SET_INFO,
105 wxEVT_COMMAND_LIST_ITEM_SELECTED,
106 wxEVT_COMMAND_LIST_ITEM_DESELECTED,
107 wxEVT_COMMAND_LIST_KEY_DOWN,
108 wxEVT_COMMAND_LIST_INSERT_ITEM,
109 wxEVT_COMMAND_LIST_COL_CLICK,
110 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
111 wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
112 wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK,
113};
114
115
116
f6bcfd97
BP
117class wxListItemAttr
118{
119public:
120 // ctors
121 wxListItemAttr();
122 //wxListItemAttr(const wxColour& colText,
123 // const wxColour& colBack,
124 // const wxFont& font)
125 // : m_colText(colText), m_colBack(colBack), m_font(font) { }
126
127 // setters
128 void SetTextColour(const wxColour& colText);
129 void SetBackgroundColour(const wxColour& colBack);
130 void SetFont(const wxFont& font);
131
132 // accessors
133 bool HasTextColour();
134 bool HasBackgroundColour();
135 bool HasFont();
136
137 const wxColour& GetTextColour();
138 const wxColour& GetBackgroundColour();
139 const wxFont& GetFont();
140};
141
142
9416aa89 143class wxListItem : public wxObject {
7bf85405 144public:
f6bcfd97
BP
145 wxListItem();
146 ~wxListItem();
147
148 // resetting
149 void Clear();
150 void ClearAttributes();
151
152 // setters
153 void SetMask(long mask);
154 void SetId(long id);
155 void SetColumn(int col);
156 void SetState(long state);
157 void SetStateMask(long stateMask);
158 void SetText(const wxString& text);
159 void SetImage(int image);
160 void SetData(long data);
161
162 void SetWidth(int width);
163 void SetAlign(wxListColumnFormat align);
164
165 void SetTextColour(const wxColour& colText);
166 void SetBackgroundColour(const wxColour& colBack);
167 void SetFont(const wxFont& font);
168
169 // accessors
170 long GetMask();
171 long GetId();
172 int GetColumn();
173 long GetState();
174 const wxString& GetText();
175 int GetImage();
176 long GetData();
177
178 int GetWidth();
179 wxListColumnFormat GetAlign();
180
181 wxListItemAttr *GetAttributes();
182 bool HasAttributes();
183
184 wxColour GetTextColour() const;
185 wxColour GetBackgroundColour() const;
186 wxFont GetFont() const;
187
188 // these members are public for compatibility
7bf85405
RD
189 long m_mask; // Indicates what fields are valid
190 long m_itemId; // The zero-based item position
191 int m_col; // Zero-based column, if in report mode
192 long m_state; // The state of the item
f6bcfd97 193 long m_stateMask;// Which flags of m_state are valid (uses same flags)
7bf85405
RD
194 wxString m_text; // The label/header text
195 int m_image; // The zero-based index into an image list
196 long m_data; // App-defined data
7bf85405
RD
197
198 // For columns only
199 int m_format; // left, right, centre
200 int m_width; // width of column
201
7bf85405
RD
202};
203
f6bcfd97 204
c368d904 205class wxListEvent: public wxNotifyEvent {
7bf85405
RD
206public:
207 int m_code;
208 long m_itemIndex;
209 long m_oldItemIndex;
210 int m_col;
211 bool m_cancelled;
212 wxPoint m_pointDrag;
213 wxListItem m_item;
7bf85405 214
f6bcfd97
BP
215 int GetCode();
216 long GetIndex();
217 long GetOldIndex();
218 long GetOldItem();
219 int GetColumn();
220 bool Cancelled();
221 wxPoint GetPoint();
222 const wxString& GetLabel();
223 const wxString& GetText();
224 int GetImage();
225 long GetData();
226 long GetMask();
227 const wxListItem& GetItem();
228};
7bf85405
RD
229
230
231
232class wxListCtrl : public wxControl {
233public:
234 wxListCtrl(wxWindow* parent, wxWindowID id,
b68dc582
RD
235 const wxPoint& pos = wxDefaultPosition,
236 const wxSize& size = wxDefaultSize,
7bf85405 237 long style = wxLC_ICON,
b68dc582 238 const wxValidator& validator = wxDefaultValidator,
7bf85405
RD
239 char* name = "listCtrl");
240
f6bcfd97 241 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
9c039d08 242
7bf85405 243 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
1b62f00d 244 void AssignImageList(wxImageList* imageList, int which);
9416aa89 245 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
7bf85405
RD
246 bool DeleteItem(long item);
247 bool DeleteAllItems();
248 bool DeleteColumn(int col);
249 bool DeleteAllColumns(void);
250 void ClearAll(void);
4f22cf8d 251#ifdef __WXMSW__
7bf85405
RD
252 wxTextCtrl* EditLabel(long item);
253 bool EndEditLabel(bool cancel);
4f22cf8d 254 wxTextCtrl* GetEditControl();
8bf5d46e
RD
255#else
256 void EditLabel(long item);
fb5e0af0 257#endif
7bf85405
RD
258 bool EnsureVisible(long item);
259 long FindItem(long start, const wxString& str, bool partial = FALSE);
260 %name(FindItemData)long FindItem(long start, long data);
261 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt,
262 int direction);
263 bool GetColumn(int col, wxListItem& item);
264 int GetColumnWidth(int col);
265 int GetCountPerPage();
7bf85405
RD
266 wxImageList* GetImageList(int which);
267 long GetItemData(long item);
268
269 %addmethods {
e166644c 270 %new wxListItem* GetItem(long itemId, int col=0) {
7bf85405 271 wxListItem* info = new wxListItem;
0699c864 272 info->m_itemId = itemId;
e166644c 273 info->m_col = col;
f17fee68 274 info->m_mask = 0xFFFF;
7bf85405
RD
275 self->GetItem(*info);
276 return info;
277 }
278 %new wxPoint* GetItemPosition(long item) {
279 wxPoint* pos = new wxPoint;
280 self->GetItemPosition(item, *pos);
281 return pos;
282 }
283 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
284 wxRect* rect= new wxRect;
285 self->GetItemRect(item, *rect, code);
286 return rect;
287 }
288 }
289
290 int GetItemState(long item, long stateMask);
291 int GetItemCount();
292 int GetItemSpacing(bool isSmall);
293 wxString GetItemText(long item);
294 long GetNextItem(long item,
295 int geometry = wxLIST_NEXT_ALL,
296 int state = wxLIST_STATE_DONTCARE);
297 int GetSelectedItemCount();
fb5e0af0 298#ifdef __WXMSW__
7bf85405 299 wxColour GetTextColour();
4f22cf8d 300 void SetTextColour(const wxColour& col);
fb5e0af0 301#endif
7bf85405
RD
302 long GetTopItem();
303 long HitTest(const wxPoint& point, int& OUTPUT);
c368d904 304 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
7bf85405
RD
305 long InsertColumn(long col, const wxString& heading,
306 int format = wxLIST_FORMAT_LEFT,
307 int width = -1);
308
309 long InsertItem(wxListItem& info);
310 %name(InsertStringItem) long InsertItem(long index, const wxString& label);
311 %name(InsertImageItem) long InsertItem(long index, int imageIndex);
312 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label,
313 int imageIndex);
314
315 bool ScrollList(int dx, int dy);
316 void SetBackgroundColour(const wxColour& col);
317 bool SetColumn(int col, wxListItem& item);
318 bool SetColumnWidth(int col, int width);
319 void SetImageList(wxImageList* imageList, int which);
af309447 320
7bf85405 321 bool SetItem(wxListItem& info);
af309447 322 %name(SetStringItem)long SetItem(long index, int col, const wxString& label,
7bf85405 323 int imageId = -1);
af309447 324
7bf85405
RD
325 bool SetItemData(long item, long data);
326 bool SetItemImage(long item, int image, int selImage);
327 bool SetItemPosition(long item, const wxPoint& pos);
328 bool SetItemState(long item, long state, long stateMask);
329 void SetItemText(long item, const wxString& text);
330 void SetSingleStyle(long style, bool add = TRUE);
7bf85405 331 void SetWindowStyleFlag(long style);
dcd38683
RD
332
333 // bool SortItems(wxListCtrlCompare fn, long data);
334 %addmethods {
335 bool SortItems(PyObject* func) {
336 if (!PyCallable_Check(func))
337 return FALSE;
338
f6bcfd97 339 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
dcd38683
RD
340 }
341 }
7bf85405
RD
342};
343
dcd38683 344%{
f6bcfd97 345 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
dcd38683
RD
346 int retval = 0;
347 PyObject* func = (PyObject*)funcPtr;
348 bool doSave = wxPyRestoreThread();
7bf85405 349
dcd38683
RD
350 PyObject* args = Py_BuildValue("(ii)", item1, item2);
351 PyObject* result = PyEval_CallObject(func, args);
352 Py_DECREF(args);
353 if (result) {
354 retval = PyInt_AsLong(result);
355 Py_DECREF(result);
356 }
357
358 wxPySaveThread(doSave);
359 return retval;
360 }
361
362%}
7bf85405
RD
363
364//----------------------------------------------------------------------
365
694759cf
RD
366enum wxTreeItemIcon
367{
368 wxTreeItemIcon_Normal, // not selected, not expanded
369 wxTreeItemIcon_Selected, // selected, not expanded
370 wxTreeItemIcon_Expanded, // not selected, expanded
371 wxTreeItemIcon_SelectedExpanded, // selected, expanded
372 wxTreeItemIcon_Max
373};
374
7bf85405 375
164b735b
RD
376// constants for HitTest
377enum {
378 wxTREE_HITTEST_ABOVE,
379 wxTREE_HITTEST_BELOW,
380 wxTREE_HITTEST_NOWHERE,
381 wxTREE_HITTEST_ONITEMBUTTON,
382 wxTREE_HITTEST_ONITEMICON,
383 wxTREE_HITTEST_ONITEMINDENT,
384 wxTREE_HITTEST_ONITEMLABEL,
385 wxTREE_HITTEST_ONITEMRIGHT,
386 wxTREE_HITTEST_ONITEMSTATEICON,
387 wxTREE_HITTEST_TOLEFT,
388 wxTREE_HITTEST_TORIGHT,
389 wxTREE_HITTEST_ONITEMUPPERPART,
390 wxTREE_HITTEST_ONITEMLOWERPART,
391 wxTREE_HITTEST_ONITEM
392};
393
394
1b62f00d
RD
395enum {
396 /* Tree control event types */
397 wxEVT_COMMAND_TREE_BEGIN_DRAG,
398 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
399 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
400 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
401 wxEVT_COMMAND_TREE_DELETE_ITEM,
402 wxEVT_COMMAND_TREE_GET_INFO,
403 wxEVT_COMMAND_TREE_SET_INFO,
404 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
405 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
406 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
407 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
408 wxEVT_COMMAND_TREE_SEL_CHANGED,
409 wxEVT_COMMAND_TREE_SEL_CHANGING,
410 wxEVT_COMMAND_TREE_KEY_DOWN,
411 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
412 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
413 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
d1679124 414 wxEVT_COMMAND_TREE_END_DRAG,
1b62f00d
RD
415};
416
417
d5c9047a
RD
418class wxTreeItemId {
419public:
420 wxTreeItemId();
421 ~wxTreeItemId();
bb0054cd 422 bool IsOk();
d5c9047a 423
f6bcfd97
BP
424 %addmethods {
425 int __cmp__(wxTreeItemId* other) {
c368d904 426 if (! other) return -1;
f6bcfd97
BP
427 return *self != *other;
428 }
429 }
d5c9047a
RD
430};
431
432
433
cf694132
RD
434%{
435class wxPyTreeItemData : public wxTreeItemData {
d5c9047a 436public:
cf694132 437 wxPyTreeItemData(PyObject* obj = NULL) {
c368d904 438 if (obj == NULL)
cf694132 439 obj = Py_None;
c368d904
RD
440 Py_INCREF(obj);
441 m_obj = obj;
cf694132 442 }
d5c9047a 443
cf694132 444 ~wxPyTreeItemData() {
1afc06c2 445 bool doSave = wxPyRestoreThread();
c368d904 446 Py_DECREF(m_obj);
1afc06c2 447 wxPySaveThread(doSave);
cf694132
RD
448 }
449
450 PyObject* GetData() {
451 Py_INCREF(m_obj);
452 return m_obj;
453 }
454
455 void SetData(PyObject* obj) {
c368d904 456 bool doSave = wxPyRestoreThread();
cf694132 457 Py_DECREF(m_obj);
c368d904 458 wxPySaveThread(doSave);
cf694132
RD
459 m_obj = obj;
460 Py_INCREF(obj);
461 }
462
463 PyObject* m_obj;
d5c9047a 464};
cf694132 465%}
d5c9047a
RD
466
467
468
9416aa89 469%name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
cf694132
RD
470public:
471 wxPyTreeItemData(PyObject* obj = NULL);
472
473 PyObject* GetData();
474 void SetData(PyObject* obj);
475
476 const wxTreeItemId& GetId();
477 void SetId(const wxTreeItemId& id);
478};
479
480
d5c9047a 481
8bf5d46e 482class wxTreeEvent : public wxNotifyEvent {
d5c9047a
RD
483public:
484 wxTreeItemId GetItem();
485 wxTreeItemId GetOldItem();
486 wxPoint GetPoint();
487 int GetCode();
8bf5d46e 488 const wxString& GetLabel();
d5c9047a
RD
489};
490
491
f6bcfd97
BP
492
493%{
494class wxPyTreeCtrl : public wxTreeCtrl {
3b36695d 495 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
f6bcfd97
BP
496public:
497 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
498 const wxPoint& pos,
499 const wxSize& size,
500 long style,
501 const wxValidator& validator,
502 char* name) :
503 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
504
f6bcfd97
BP
505 int OnCompareItems(const wxTreeItemId& item1,
506 const wxTreeItemId& item2) {
507 int rval = 0;
508 bool doSave = wxPyRestoreThread();
509 if (m_myInst.findCallback("OnCompareItems"))
510 rval = m_myInst.callCallback(Py_BuildValue(
511 "(OO)",
512 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
513 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
514 else
515 rval = wxTreeCtrl::OnCompareItems(item1, item2);
516 wxPySaveThread(doSave);
517 return rval;
518 }
519 PYPRIVATE;
520};
521
3b36695d
RD
522IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
523
f6bcfd97
BP
524%}
525
d5c9047a
RD
526// These are for the GetFirstChild/GetNextChild methods below
527%typemap(python, in) long& INOUT = long* INOUT;
528%typemap(python, argout) long& INOUT = long* INOUT;
529
530
f6bcfd97 531%name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
d5c9047a 532public:
f6bcfd97 533 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
b68dc582
RD
534 const wxPoint& pos = wxDefaultPosition,
535 const wxSize& size = wxDefaultSize,
d5c9047a 536 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
b68dc582 537 const wxValidator& validator = wxDefaultValidator,
d5c9047a
RD
538 char* name = "wxTreeCtrl");
539
f6bcfd97
BP
540 void _setSelf(PyObject* self, PyObject* _class);
541 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
542 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxTreeCtrl)"
d5c9047a 543
1b62f00d 544 void AssignImageList(wxImageList* imageList);
9416aa89 545 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
d5c9047a
RD
546 size_t GetCount();
547 unsigned int GetIndent();
548 void SetIndent(unsigned int indent);
549 wxImageList *GetImageList();
550 wxImageList *GetStateImageList();
1b62f00d 551 void SetImageList(wxImageList *imageList);
d5c9047a
RD
552 void SetStateImageList(wxImageList *imageList);
553
b1462dfa
RD
554 unsigned int GetSpacing();
555 void SetSpacing(unsigned int spacing);
556
d5c9047a 557 wxString GetItemText(const wxTreeItemId& item);
694759cf
RD
558 int GetItemImage(const wxTreeItemId& item,
559 wxTreeItemIcon which = wxTreeItemIcon_Normal);
d5c9047a 560 int GetItemSelectedImage(const wxTreeItemId& item);
d5c9047a
RD
561
562 void SetItemText(const wxTreeItemId& item, const wxString& text);
694759cf
RD
563 void SetItemImage(const wxTreeItemId& item, int image,
564 wxTreeItemIcon which = wxTreeItemIcon_Normal);
d5c9047a 565 void SetItemSelectedImage(const wxTreeItemId& item, int image);
08127323 566 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
d5c9047a 567
cf694132 568 %addmethods {
c368d904
RD
569 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
570 // if needed.
cf694132
RD
571 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
572 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
573 if (data == NULL) {
574 data = new wxPyTreeItemData();
f6bcfd97 575 data->SetId(item); // set the id
cf694132
RD
576 self->SetItemData(item, data);
577 }
578 return data;
579 }
580
581 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
f6bcfd97
BP
582 data->SetId(item); // set the id
583 self->SetItemData(item, data);
c368d904 584 }
cf694132 585
c368d904
RD
586 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
587 // automatically creating data classes.
588 PyObject* GetPyData(const wxTreeItemId& item) {
cf694132
RD
589 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
590 if (data == NULL) {
591 data = new wxPyTreeItemData();
f6bcfd97 592 data->SetId(item); // set the id
cf694132
RD
593 self->SetItemData(item, data);
594 }
595 return data->GetData();
c368d904 596 }
cf694132
RD
597
598 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
599 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
600 if (data == NULL) {
601 data = new wxPyTreeItemData(obj);
f6bcfd97 602 data->SetId(item); // set the id
cf694132
RD
603 self->SetItemData(item, data);
604 } else
605 data->SetData(obj);
c368d904 606 }
cf694132
RD
607 }
608
609
d5c9047a
RD
610 bool IsVisible(const wxTreeItemId& item);
611 bool ItemHasChildren(const wxTreeItemId& item);
612 bool IsExpanded(const wxTreeItemId& item);
613 bool IsSelected(const wxTreeItemId& item);
614
615 wxTreeItemId GetRootItem();
616 wxTreeItemId GetSelection();
eb715945 617 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
d426c97e
RD
618 //size_t GetSelections(wxArrayTreeItemIds& selection);
619 %addmethods {
620 PyObject* GetSelections() {
26b9cf27 621 bool doSave = wxPyRestoreThread();
d426c97e
RD
622 PyObject* rval = PyList_New(0);
623 wxArrayTreeItemIds array;
624 size_t num, x;
625 num = self->GetSelections(array);
626 for (x=0; x < num; x++) {
c368d904
RD
627 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
628 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
d426c97e
RD
629 PyList_Append(rval, item);
630 }
26b9cf27 631 wxPySaveThread(doSave);
d426c97e
RD
632 return rval;
633 }
634 }
635
636
d5c9047a 637
bb0054cd
RD
638 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
639
d5c9047a
RD
640 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
641 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
642 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
643 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
644 wxTreeItemId GetFirstVisibleItem();
645 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
646 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
d426c97e
RD
647 wxTreeItemId GetLastChild(const wxTreeItemId& item);
648
d5c9047a
RD
649
650
651 wxTreeItemId AddRoot(const wxString& text,
652 int image = -1, int selectedImage = -1,
cf694132 653 wxPyTreeItemData *data = NULL);
d5c9047a
RD
654 wxTreeItemId PrependItem(const wxTreeItemId& parent,
655 const wxString& text,
656 int image = -1, int selectedImage = -1,
cf694132 657 wxPyTreeItemData *data = NULL);
d5c9047a
RD
658 wxTreeItemId InsertItem(const wxTreeItemId& parent,
659 const wxTreeItemId& idPrevious,
660 const wxString& text,
661 int image = -1, int selectedImage = -1,
cf694132 662 wxPyTreeItemData *data = NULL);
f6bcfd97
BP
663 %name(InsertItemBefore)
664 wxTreeItemId InsertItem(const wxTreeItemId& parent,
665 size_t before,
666 const wxString& text,
667 int image = -1, int selectedImage = -1,
668 wxTreeItemData *data = NULL);
d5c9047a
RD
669 wxTreeItemId AppendItem(const wxTreeItemId& parent,
670 const wxString& text,
671 int image = -1, int selectedImage = -1,
cf694132 672 wxPyTreeItemData *data = NULL);
d5c9047a
RD
673
674 void Delete(const wxTreeItemId& item);
08127323 675 void DeleteChildren(const wxTreeItemId& item);
d5c9047a
RD
676 void DeleteAllItems();
677
678 void Expand(const wxTreeItemId& item);
679 void Collapse(const wxTreeItemId& item);
680 void CollapseAndReset(const wxTreeItemId& item);
681 void Toggle(const wxTreeItemId& item);
682
683 void Unselect();
8bf5d46e 684 void UnselectAll();
d5c9047a
RD
685 void SelectItem(const wxTreeItemId& item);
686 void EnsureVisible(const wxTreeItemId& item);
687 void ScrollTo(const wxTreeItemId& item);
8bf5d46e 688#ifdef __WXMSW__
d5c9047a 689 wxTextCtrl* EditLabel(const wxTreeItemId& item);
d5c9047a 690 wxTextCtrl* GetEditControl();
b1462dfa 691 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
8bf5d46e
RD
692#else
693 void EditLabel(const wxTreeItemId& item);
694#endif
d5c9047a 695
d426c97e 696 void SortChildren(const wxTreeItemId& item);
d5c9047a 697
b1462dfa 698 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
b8b8dda7 699 bool IsBold(const wxTreeItemId& item) const;
164b735b 700 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
c127177f 701
f6bcfd97
BP
702
703
b7e72427
RD
704 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
705 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
706 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
707
4120ef2b 708#ifdef __WXMSW__
b1462dfa
RD
709 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
710
d426c97e
RD
711 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
712 %addmethods {
713 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
714 wxRect rect;
164b735b
RD
715 if (self->GetBoundingRect(item, rect, textOnly)) {
716 bool doSave = wxPyRestoreThread();
717 wxRect* r = new wxRect(rect);
718 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
719 wxPySaveThread(doSave);
720 return val;
721 }
d426c97e
RD
722 else {
723 Py_INCREF(Py_None);
724 return Py_None;
725 }
726 }
727 }
761a9d2b 728#endif
d426c97e 729
c127177f 730%pragma(python) addtoclass = "
f6bcfd97
BP
731 # Redefine some methods that SWIG gets a bit confused on...
732 def GetFirstChild(self, *_args, **_kwargs):
733 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
734 val1 = wxTreeItemIdPtr(val1)
735 val1.thisown = 1
736 return (val1,val2)
737 def GetNextChild(self, *_args, **_kwargs):
738 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
c127177f
RD
739 val1 = wxTreeItemIdPtr(val1)
740 val1.thisown = 1
741 return (val1,val2)
f6bcfd97
BP
742 def HitTest(self, *_args, **_kwargs):
743 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
c127177f
RD
744 val1 = wxTreeItemIdPtr(val1)
745 val1.thisown = 1
746 return (val1,val2)
747"
d5c9047a
RD
748};
749
d5c9047a 750
7bf85405
RD
751//----------------------------------------------------------------------
752
9c039d08 753#ifdef SKIPTHIS
fb5e0af0 754#ifdef __WXMSW__
1b62f00d
RD
755
756
757enum {
758 /* tab control event types */
759 wxEVT_COMMAND_TAB_SEL_CHANGED,
760 wxEVT_COMMAND_TAB_SEL_CHANGING,
761};
762
763
7bf85405
RD
764class wxTabEvent : public wxCommandEvent {
765public:
766};
767
768
769
770class wxTabCtrl : public wxControl {
771public:
772 wxTabCtrl(wxWindow* parent, wxWindowID id,
b68dc582
RD
773 const wxPoint& pos = wxDefaultPosition,
774 const wxSize& size = wxDefaultSize,
7bf85405
RD
775 long style = 0,
776 char* name = "tabCtrl");
777
f6bcfd97 778 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
9c039d08 779
7bf85405
RD
780 bool DeleteAllItems();
781 bool DeleteItem(int item);
782 wxImageList* GetImageList();
783 int GetItemCount();
784 // TODO: void* GetItemData();
785 int GetItemImage(int item);
786
787 %addmethods {
788 %new wxRect* GetItemRect(int item) {
789 wxRect* rect = new wxRect;
790 self->GetItemRect(item, *rect);
791 return rect;
792 }
793 }
794
795 wxString GetItemText(int item);
796 bool GetRowCount();
797 int GetSelection();
798 int HitTest(const wxPoint& pt, long& OUTPUT);
799 void InsertItem(int item, const wxString& text,
800 int imageId = -1, void* clientData = NULL);
801 // TODO: bool SetItemData(int item, void* data);
802 bool SetItemImage(int item, int image);
803 void SetImageList(wxImageList* imageList);
804 void SetItemSize(const wxSize& size);
805 bool SetItemText(int item, const wxString& text);
806 void SetPadding(const wxSize& padding);
807 int SetSelection(int item);
808
809};
810
9c039d08 811#endif
fb5e0af0
RD
812#endif
813
7bf85405
RD
814//----------------------------------------------------------------------
815
9416aa89
RD
816%init %{
817 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
818 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
819%}
820
821//----------------------------------------------------------------------
822
7bf85405 823