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