]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/controls2.i
don't use deprecated symbols
[wxWidgets.git] / wxPython / src / controls2.i
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
13 %module controls2
14
15 %{
16 #include "helpers.h"
17 #ifdef __WXMSW__
18 #include <windows.h>
19 #endif
20 #include <wx/listctrl.h>
21 #include <wx/treectrl.h>
22 #include <wx/imaglist.h>
23 #include <wx/dirctrl.h>
24
25 #include "pytree.h"
26 %}
27
28 //----------------------------------------------------------------------
29
30 %include typemaps.i
31 %include my_typemaps.i
32
33 // Import some definitions of other classes, etc.
34 %import _defs.i
35 %import misc.i
36 %import windows.i
37 %import gdi.i
38 %import events.i
39 %import controls.i
40
41 %pragma(python) code = "import wx"
42
43
44 //----------------------------------------------------------------------
45 %{
46 // Put some wx default wxChar* values into wxStrings.
47 const wxChar* wxListCtrlNameStr = _T("wxListCtrl");
48 DECLARE_DEF_STRING(ListCtrlNameStr);
49
50 const wxChar* wx_TreeCtrlNameStr = _T("wxTreeCtrl");
51 DECLARE_DEF_STRING(_TreeCtrlNameStr);
52 DECLARE_DEF_STRING(DirDialogDefaultFolderStr);
53
54 static const wxString wxPyEmptyString(wxT(""));
55 %}
56
57
58 %{
59 static const long longzero = 0;
60 %}
61
62 //----------------------------------------------------------------------
63
64 enum {
65 /* List control event types */
66 wxEVT_COMMAND_LIST_BEGIN_DRAG,
67 wxEVT_COMMAND_LIST_BEGIN_RDRAG,
68 wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT,
69 wxEVT_COMMAND_LIST_END_LABEL_EDIT,
70 wxEVT_COMMAND_LIST_DELETE_ITEM,
71 wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS,
72 wxEVT_COMMAND_LIST_GET_INFO,
73 wxEVT_COMMAND_LIST_SET_INFO,
74 wxEVT_COMMAND_LIST_ITEM_SELECTED,
75 wxEVT_COMMAND_LIST_ITEM_DESELECTED,
76 wxEVT_COMMAND_LIST_KEY_DOWN,
77 wxEVT_COMMAND_LIST_INSERT_ITEM,
78 wxEVT_COMMAND_LIST_COL_CLICK,
79 wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK,
80 wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK,
81 wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
82 wxEVT_COMMAND_LIST_CACHE_HINT,
83 wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
84 wxEVT_COMMAND_LIST_COL_BEGIN_DRAG,
85 wxEVT_COMMAND_LIST_COL_DRAGGING,
86 wxEVT_COMMAND_LIST_COL_END_DRAG,
87 wxEVT_COMMAND_LIST_ITEM_FOCUSED,
88 };
89
90
91 %pragma(python) code = "
92 def EVT_LIST_BEGIN_DRAG(win, id, func):
93 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_DRAG, func)
94
95 def EVT_LIST_BEGIN_RDRAG(win, id, func):
96 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_RDRAG, func)
97
98 def EVT_LIST_BEGIN_LABEL_EDIT(win, id, func):
99 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, func)
100
101 def EVT_LIST_END_LABEL_EDIT(win, id, func):
102 win.Connect(id, -1, wxEVT_COMMAND_LIST_END_LABEL_EDIT, func)
103
104 def EVT_LIST_DELETE_ITEM(win, id, func):
105 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ITEM, func)
106
107 def EVT_LIST_DELETE_ALL_ITEMS(win, id, func):
108 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, func)
109
110 def EVT_LIST_GET_INFO(win, id, func):
111 win.Connect(id, -1, wxEVT_COMMAND_LIST_GET_INFO, func)
112
113 def EVT_LIST_SET_INFO(win, id, func):
114 win.Connect(id, -1, wxEVT_COMMAND_LIST_SET_INFO, func)
115
116 def EVT_LIST_ITEM_SELECTED(win, id, func):
117 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED, func)
118
119 def EVT_LIST_ITEM_DESELECTED(win, id, func):
120 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_DESELECTED, func)
121
122 def EVT_LIST_KEY_DOWN(win, id, func):
123 win.Connect(id, -1, wxEVT_COMMAND_LIST_KEY_DOWN, func)
124
125 def EVT_LIST_INSERT_ITEM(win, id, func):
126 win.Connect(id, -1, wxEVT_COMMAND_LIST_INSERT_ITEM, func)
127
128 def EVT_LIST_COL_CLICK(win, id, func):
129 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_CLICK, func)
130
131 def EVT_LIST_COL_RIGHT_CLICK(win, id, func):
132 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, func)
133
134 def EVT_LIST_COL_BEGIN_DRAG(win, id, func):
135 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, func)
136
137 def EVT_LIST_COL_DRAGGING(win, id, func):
138 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_DRAGGING, func)
139
140 def EVT_LIST_COL_END_DRAG(win, id, func):
141 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_END_DRAG, func)
142
143 def EVT_LIST_ITEM_RIGHT_CLICK(win, id, func):
144 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, func)
145
146 def EVT_LIST_ITEM_MIDDLE_CLICK(win, id, func):
147 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, func)
148
149 def EVT_LIST_ITEM_ACTIVATED(win, id, func):
150 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, func)
151
152 def EVT_LIST_CACHE_HINT(win, id, func):
153 win.Connect(id, -1, wxEVT_COMMAND_LIST_CACHE_HINT, func)
154
155 def EVT_LIST_ITEM_FOCUSED(win, id, func):
156 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_FOCUSED, func)
157 "
158
159
160 enum {
161 /* Style flags */
162 wxLC_VRULES,
163 wxLC_HRULES,
164
165 wxLC_ICON,
166 wxLC_SMALL_ICON,
167 wxLC_LIST,
168 wxLC_REPORT,
169
170 wxLC_ALIGN_TOP,
171 wxLC_ALIGN_LEFT,
172 wxLC_AUTOARRANGE,
173 wxLC_VIRTUAL,
174 wxLC_EDIT_LABELS,
175 wxLC_NO_HEADER,
176 wxLC_NO_SORT_HEADER,
177 wxLC_SINGLE_SEL,
178 wxLC_SORT_ASCENDING,
179 wxLC_SORT_DESCENDING,
180
181 wxLC_MASK_TYPE,
182 wxLC_MASK_ALIGN,
183 wxLC_MASK_SORT,
184
185 wxLC_USER_TEXT,
186 };
187
188
189 enum {
190 // Mask flags
191 wxLIST_MASK_STATE,
192 wxLIST_MASK_TEXT,
193 wxLIST_MASK_IMAGE,
194 wxLIST_MASK_DATA,
195 wxLIST_SET_ITEM,
196 wxLIST_MASK_WIDTH,
197 wxLIST_MASK_FORMAT,
198
199 // State flags
200 wxLIST_STATE_DONTCARE,
201 wxLIST_STATE_DROPHILITED,
202 wxLIST_STATE_FOCUSED,
203 wxLIST_STATE_SELECTED,
204 wxLIST_STATE_CUT,
205
206 // Hit test flags
207 wxLIST_HITTEST_ABOVE,
208 wxLIST_HITTEST_BELOW,
209 wxLIST_HITTEST_NOWHERE,
210 wxLIST_HITTEST_ONITEMICON,
211 wxLIST_HITTEST_ONITEMLABEL,
212 wxLIST_HITTEST_ONITEMRIGHT,
213 wxLIST_HITTEST_ONITEMSTATEICON,
214 wxLIST_HITTEST_TOLEFT,
215 wxLIST_HITTEST_TORIGHT,
216 wxLIST_HITTEST_ONITEM,
217
218 // Flags for GetNextItem
219 wxLIST_NEXT_ABOVE,
220 wxLIST_NEXT_ALL,
221 wxLIST_NEXT_BELOW,
222 wxLIST_NEXT_LEFT,
223 wxLIST_NEXT_RIGHT,
224
225 // Alignment flags
226 wxLIST_ALIGN_DEFAULT,
227 wxLIST_ALIGN_LEFT,
228 wxLIST_ALIGN_TOP,
229 wxLIST_ALIGN_SNAP_TO_GRID,
230
231 // Autosize values for SetColumnWidth
232 wxLIST_AUTOSIZE = -1,
233 wxLIST_AUTOSIZE_USEHEADER = -2,
234
235 // Flag values for GetItemRect
236 wxLIST_RECT_BOUNDS,
237 wxLIST_RECT_ICON,
238 wxLIST_RECT_LABEL,
239
240 // Flag values for FindItem (MSW only)
241 wxLIST_FIND_UP,
242 wxLIST_FIND_DOWN,
243 wxLIST_FIND_LEFT,
244 wxLIST_FIND_RIGHT,
245
246
247 };
248
249
250
251 enum wxListColumnFormat
252 {
253 wxLIST_FORMAT_LEFT,
254 wxLIST_FORMAT_RIGHT,
255 wxLIST_FORMAT_CENTRE,
256 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
257 };
258
259
260
261
262 class wxListItemAttr
263 {
264 public:
265 // ctors
266 //wxListItemAttr();
267 wxListItemAttr(const wxColour& colText = wxNullColour,
268 const wxColour& colBack = wxNullColour,
269 const wxFont& font = wxNullFont);
270
271
272 // setters
273 void SetTextColour(const wxColour& colText);
274 void SetBackgroundColour(const wxColour& colBack);
275 void SetFont(const wxFont& font);
276
277 // accessors
278 bool HasTextColour();
279 bool HasBackgroundColour();
280 bool HasFont();
281
282 wxColour GetTextColour();
283 wxColour GetBackgroundColour();
284 wxFont GetFont();
285 };
286
287
288 class wxListItem : public wxObject {
289 public:
290 wxListItem();
291 ~wxListItem();
292
293 // resetting
294 void Clear();
295 void ClearAttributes();
296
297 // setters
298 void SetMask(long mask);
299 void SetId(long id);
300 void SetColumn(int col);
301 void SetState(long state);
302 void SetStateMask(long stateMask);
303 void SetText(const wxString& text);
304 void SetImage(int image);
305 void SetData(long data);
306
307 void SetWidth(int width);
308 void SetAlign(wxListColumnFormat align);
309
310 void SetTextColour(const wxColour& colText);
311 void SetBackgroundColour(const wxColour& colBack);
312 void SetFont(const wxFont& font);
313
314 // accessors
315 long GetMask();
316 long GetId();
317 int GetColumn();
318 long GetState();
319 const wxString& GetText();
320 int GetImage();
321 long GetData();
322
323 int GetWidth();
324 wxListColumnFormat GetAlign();
325
326 wxListItemAttr *GetAttributes();
327 bool HasAttributes();
328
329 wxColour GetTextColour() const;
330 wxColour GetBackgroundColour() const;
331 wxFont GetFont() const;
332
333 // these members are public for compatibility
334 long m_mask; // Indicates what fields are valid
335 long m_itemId; // The zero-based item position
336 int m_col; // Zero-based column, if in report mode
337 long m_state; // The state of the item
338 long m_stateMask;// Which flags of m_state are valid (uses same flags)
339 wxString m_text; // The label/header text
340 int m_image; // The zero-based index into an image list
341 long m_data; // App-defined data
342
343 // For columns only
344 int m_format; // left, right, centre
345 int m_width; // width of column
346
347 };
348
349
350 class wxListEvent: public wxNotifyEvent {
351 public:
352 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
353
354 %readonly
355 int m_code;
356 long m_oldItemIndex;
357 long m_itemIndex;
358 int m_col;
359 wxPoint m_pointDrag;
360 wxListItem m_item;
361 %readwrite
362
363 int GetKeyCode();
364 %pragma(python) addtoclass = "GetCode = GetKeyCode"
365 long GetIndex();
366 int GetColumn();
367 wxPoint GetPoint();
368 const wxString& GetLabel();
369 const wxString& GetText();
370 int GetImage();
371 long GetData();
372 long GetMask();
373 const wxListItem& GetItem();
374
375 long GetCacheFrom();
376 long GetCacheTo();
377
378 // was label editing canceled? (for wxEVT_COMMAND_LIST_END_LABEL_EDIT only)
379 bool IsEditCancelled() const { return m_editCancelled; }
380 void SetEditCanceled(bool editCancelled) { m_editCancelled = editCancelled; }
381 };
382
383
384 %{ // C++ Version of a Python aware class
385 class wxPyListCtrl : public wxListCtrl {
386 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
387 public:
388 wxPyListCtrl() : wxListCtrl() {}
389 wxPyListCtrl(wxWindow* parent, wxWindowID id,
390 const wxPoint& pos,
391 const wxSize& size,
392 long style,
393 const wxValidator& validator,
394 const wxString& name) :
395 wxListCtrl(parent, id, pos, size, style, validator, name) {}
396
397 bool Create(wxWindow* parent, wxWindowID id,
398 const wxPoint& pos,
399 const wxSize& size,
400 long style,
401 const wxValidator& validator,
402 const wxString& name) {
403 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
404 }
405
406 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
407 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
408 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
409
410 PYPRIVATE;
411 };
412
413 IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
414
415 IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
416 IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
417 IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
418 %}
419
420
421
422 %name(wxListCtrl)class wxPyListCtrl : public wxControl {
423 public:
424 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
425 const wxPoint& pos = wxDefaultPosition,
426 const wxSize& size = wxDefaultSize,
427 long style = wxLC_ICON,
428 const wxValidator& validator = wxDefaultValidator,
429 const wxString& name = wxPyListCtrlNameStr);
430 %name(wxPreListCtrl)wxPyListCtrl();
431
432 bool Create(wxWindow* parent, wxWindowID id = -1,
433 const wxPoint& pos = wxDefaultPosition,
434 const wxSize& size = wxDefaultSize,
435 long style = wxLC_ICON,
436 const wxValidator& validator = wxDefaultValidator,
437 const wxString& name = wxPyListCtrlNameStr);
438
439 void _setCallbackInfo(PyObject* self, PyObject* _class);
440 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxListCtrl)"
441
442 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
443 %pragma(python) addtomethod = "wxPreListCtrl:val._setOORInfo(val)"
444
445 // Set the control colours
446 bool SetForegroundColour(const wxColour& col);
447 bool SetBackgroundColour(const wxColour& col);
448
449 // Gets information about this column
450 // bool GetColumn(int col, wxListItem& item) const;
451 %addmethods {
452 %new wxListItem* GetColumn(int col) {
453 wxListItem item;
454 item.SetMask(0xFFFF);
455 if (self->GetColumn(col, item))
456 return new wxListItem(item);
457 else
458 return NULL;
459 }
460 } // The OOR typemaps don't know what to do with the %new, so fix it up.
461 %pragma(python) addtoclass = "
462 def GetColumn(self, *_args, **_kwargs):
463 val = controls2c.wxListCtrl_GetColumn(self, *_args, **_kwargs)
464 if val is not None: val.thisown = 1
465 return val
466 "
467
468 // Sets information about this column
469 bool SetColumn(int col, wxListItem& item) ;
470
471 // Gets the column width
472 int GetColumnWidth(int col) const;
473
474 // Sets the column width
475 bool SetColumnWidth(int col, int width) ;
476
477 // Gets the number of items that can fit vertically in the
478 // visible area of the list control (list or report view)
479 // or the total number of items in the list control (icon
480 // or small icon view)
481 int GetCountPerPage() const;
482
483 // return the total area occupied by all the items (icon/small icon only)
484 wxRect GetViewRect() const;
485
486 #ifdef __WXMSW__
487 // Gets the edit control for editing labels.
488 wxTextCtrl* GetEditControl() const;
489 #endif
490
491 //bool GetItem(wxListItem& info) const ;
492 %addmethods {
493 // Gets information about the item
494 %new wxListItem* GetItem(long itemId, int col=0) {
495 wxListItem* info = new wxListItem;
496 info->m_itemId = itemId;
497 info->m_col = col;
498 info->m_mask = 0xFFFF;
499 self->GetItem(*info);
500 return info;
501 }
502 } // The OOR typemaps don't know what to do with the %new, so fix it up.
503 %pragma(python) addtoclass = "
504 def GetItem(self, *_args, **_kwargs):
505 val = controls2c.wxListCtrl_GetItem(self, *_args, **_kwargs)
506 if val is not None: val.thisown = 1
507 return val
508 "
509
510 // Sets information about the item
511 bool SetItem(wxListItem& info) ;
512
513 // Sets a string field at a particular column
514 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
515
516 // Gets the item state
517 int GetItemState(long item, long stateMask) const ;
518
519 // Sets the item state
520 bool SetItemState(long item, long state, long stateMask) ;
521
522 // Sets the item image
523 bool SetItemImage(long item, int image, int selImage) ;
524
525 // Gets the item text
526 wxString GetItemText(long item) const ;
527
528 // Sets the item text
529 void SetItemText(long item, const wxString& str) ;
530
531 // Gets the item data
532 long GetItemData(long item) const ;
533
534 // Sets the item data
535 bool SetItemData(long item, long data) ;
536
537
538 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
539 //bool GetItemPosition(long item, wxPoint& pos) const ;
540
541 // Gets the item position
542 %addmethods {
543 %new wxPoint* GetItemPosition(long item) {
544 wxPoint* pos = new wxPoint;
545 self->GetItemPosition(item, *pos);
546 return pos;
547 }
548 // Gets the item rectangle
549 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
550 wxRect* rect= new wxRect;
551 self->GetItemRect(item, *rect, code);
552 return rect;
553 }
554 }
555
556
557 // Sets the item position
558 bool SetItemPosition(long item, const wxPoint& pos) ;
559
560 // Gets the number of items in the list control
561 int GetItemCount() const;
562
563 // Gets the number of columns in the list control
564 int GetColumnCount() const;
565
566 // get the horizontal and vertical components of the item spacing
567 wxSize GetItemSpacing() const;
568
569 #ifndef __WXMSW__
570 void SetItemSpacing( int spacing, bool isSmall = FALSE );
571 #endif
572
573 // Gets the number of selected items in the list control
574 int GetSelectedItemCount() const;
575
576 // Gets the text colour of the listview
577 wxColour GetTextColour() const;
578
579 // Sets the text colour of the listview
580 void SetTextColour(const wxColour& col);
581
582 // Gets the index of the topmost visible item when in
583 // list or report view
584 long GetTopItem() const ;
585
586 // Add or remove a single window style
587 void SetSingleStyle(long style, bool add = TRUE) ;
588
589 // Set the whole window style
590 void SetWindowStyleFlag(long style) ;
591
592 // Searches for an item, starting from 'item'.
593 // item can be -1 to find the first item that matches the
594 // specified flags.
595 // Returns the item or -1 if unsuccessful.
596 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
597
598 // Gets one of the three image lists
599 wxImageList *GetImageList(int which) const ;
600
601 // Sets the image list
602 void SetImageList(wxImageList *imageList, int which) ;
603 void AssignImageList(wxImageList *imageList, int which) ;
604 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
605
606 // returns true if it is a virtual list control
607 bool IsVirtual() const;
608
609 // refresh items selectively (only useful for virtual list controls)
610 void RefreshItem(long item);
611 void RefreshItems(long itemFrom, long itemTo);
612
613 // Arranges the items
614 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
615
616 // Deletes an item
617 bool DeleteItem(long item);
618
619 // Deletes all items
620 bool DeleteAllItems() ;
621
622 // Deletes a column
623 bool DeleteColumn(int col);
624
625 // Deletes all columns
626 bool DeleteAllColumns();
627
628 // Clears items, and columns if there are any.
629 void ClearAll();
630
631 #ifdef __WXMSW__
632 // Edit the label
633 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
634
635 // End label editing, optionally cancelling the edit
636 bool EndEditLabel(bool cancel);
637 #else
638 void EditLabel(long item);
639 #endif
640
641 // Ensures this item is visible
642 bool EnsureVisible(long item) ;
643
644 // Find an item whose label matches this string, starting from the item after 'start'
645 // or the beginning if 'start' is -1.
646 long FindItem(long start, const wxString& str, bool partial = FALSE);
647
648 // Find an item whose data matches this data, starting from the item after 'start'
649 // or the beginning if 'start' is -1.
650 %name(FindItemData)long FindItem(long start, long data);
651
652 // Find an item nearest this position in the specified direction, starting from
653 // the item after 'start' or the beginning if 'start' is -1.
654 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction);
655
656 // Determines which item (if any) is at the specified point,
657 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
658 long HitTest(const wxPoint& point, int& OUTPUT);
659
660 // Inserts an item, returning the index of the new item if successful,
661 // -1 otherwise.
662 long InsertItem(wxListItem& info);
663
664 // Insert a string item
665 %name(InsertStringItem)long InsertItem(long index, const wxString& label);
666
667 // Insert an image item
668 %name(InsertImageItem)long InsertItem(long index, int imageIndex);
669
670 // Insert an image/string item
671 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex);
672
673 // For list view mode (only), inserts a column.
674 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
675
676 long InsertColumn(long col,
677 const wxString& heading,
678 int format = wxLIST_FORMAT_LEFT,
679 int width = -1);
680
681 // set the number of items in a virtual list control
682 void SetItemCount(long count);
683
684 // Scrolls the list control. If in icon, small icon or report view mode,
685 // x specifies the number of pixels to scroll. If in list view mode, x
686 // specifies the number of columns to scroll.
687 // If in icon, small icon or list view mode, y specifies the number of pixels
688 // to scroll. If in report view mode, y specifies the number of lines to scroll.
689 bool ScrollList(int dx, int dy);
690
691 void SetItemTextColour( long item, const wxColour& col);
692 wxColour GetItemTextColour( long item ) const;
693 void SetItemBackgroundColour( long item, const wxColour &col);
694 wxColour GetItemBackgroundColour( long item ) const;
695
696
697 %pragma(python) addtoclass = "
698 # Some helpers...
699
700 def Select(self, idx, on=1):
701 '''[de]select an item'''
702 if on: state = wxLIST_STATE_SELECTED
703 else: state = 0
704 self.SetItemState(idx, state, wxLIST_STATE_SELECTED)
705
706 def Focus(self, idx):
707 '''Focus and show the given item'''
708 self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED)
709 self.EnsureVisible(idx)
710
711 def GetFocusedItem(self):
712 '''get the currently focused item or -1 if none'''
713 return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
714
715 def GetFirstSelected(self, *args):
716 '''return first selected item, or -1 when none'''
717 return self.GetNextSelected(-1)
718
719 def GetNextSelected(self, item):
720 '''return subsequent selected items, or -1 when no more'''
721 return self.GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)
722
723 def IsSelected(self, idx):
724 '''return TRUE if the item is selected'''
725 return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
726
727 def SetColumnImage(self, col, image):
728 item = wxListItem()
729 item.SetMask(wxLIST_MASK_IMAGE)
730 item.SetImage(image)
731 self.SetColumn(col, item)
732
733 def ClearColumnImage(self, col):
734 self.SetColumnImage(col, -1)
735
736 def Append(self, entry):
737 '''Append an item to the list control. The entry parameter should be a
738 sequence with an item for each column'''
739 if len(entry):
740 if wx.wxUSE_UNICODE:
741 cvtfunc = unicode
742 else:
743 cvtfunc = str
744 pos = self.GetItemCount()
745 self.InsertStringItem(pos, cvtfunc(entry[0]))
746 for i in range(1, len(entry)):
747 self.SetStringItem(pos, i, cvtfunc(entry[i]))
748 return pos
749 "
750
751
752 // bool SortItems(wxListCtrlCompare fn, long data);
753 %addmethods {
754 // Sort items.
755 // func is a function which takes 2 long arguments: item1, item2.
756 // item1 is the long data associated with a first item (NOT the index).
757 // item2 is the long data associated with a second item (NOT the index).
758 // The return value is a negative number if the first item should precede the second
759 // item, a positive number of the second item should precede the first,
760 // or zero if the two items are equivalent.
761 bool SortItems(PyObject* func) {
762 if (!PyCallable_Check(func))
763 return FALSE;
764 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
765 }
766 }
767
768
769 %addmethods {
770 wxWindow* GetMainWindow() {
771 #ifdef __WXMSW__
772 return self;
773 #else
774 return (wxWindow*)self->m_mainWin;
775 #endif
776 }
777 }
778 };
779
780
781
782 %{ // Python aware sorting function for wxPyListCtrl
783 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
784 int retval = 0;
785 PyObject* func = (PyObject*)funcPtr;
786 wxPyBeginBlockThreads();
787
788 PyObject* args = Py_BuildValue("(ii)", item1, item2);
789 PyObject* result = PyEval_CallObject(func, args);
790 Py_DECREF(args);
791 if (result) {
792 retval = PyInt_AsLong(result);
793 Py_DECREF(result);
794 }
795
796 wxPyEndBlockThreads();
797 return retval;
798 }
799
800 %}
801
802 //----------------------------------------------------------------------
803
804 class wxListView : public wxPyListCtrl
805 {
806 public:
807 wxListView( wxWindow *parent,
808 wxWindowID id = -1,
809 const wxPoint& pos = wxDefaultPosition,
810 const wxSize& size = wxDefaultSize,
811 long style = wxLC_REPORT,
812 const wxValidator& validator = wxDefaultValidator,
813 const wxString& name = wxPyListCtrlNameStr);
814 %name(wxPreListView)wxListView();
815
816 bool Create( wxWindow *parent,
817 wxWindowID id = -1,
818 const wxPoint& pos = wxDefaultPosition,
819 const wxSize& size = wxDefaultSize,
820 long style = wxLC_REPORT,
821 const wxValidator& validator = wxDefaultValidator,
822 const wxString& name = wxPyListCtrlNameStr);
823
824 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
825 %pragma(python) addtomethod = "wxPreListView:val._setOORInfo(val)"
826
827 // [de]select an item
828 void Select(long n, bool on = TRUE);
829
830 // focus and show the given item
831 void Focus(long index);
832
833 // get the currently focused item or -1 if none
834 long GetFocusedItem() const;
835
836 // get first and subsequent selected items, return -1 when no more
837 long GetNextSelected(long item) const;
838 long GetFirstSelected() const;
839
840 // return TRUE if the item is selected
841 bool IsSelected(long index);
842
843 void SetColumnImage(int col, int image);
844 void ClearColumnImage(int col);
845 };
846
847
848 //--------------------------------------------------------------------------------
849 //--------------------------------------------------------------------------------
850
851 // wxTreeCtrl flags
852 enum {
853 wxTR_NO_BUTTONS,
854 wxTR_HAS_BUTTONS,
855 wxTR_NO_LINES,
856 wxTR_LINES_AT_ROOT,
857
858 wxTR_SINGLE,
859 wxTR_MULTIPLE,
860 wxTR_EXTENDED,
861 wxTR_HAS_VARIABLE_ROW_HEIGHT,
862
863 wxTR_EDIT_LABELS,
864 wxTR_HIDE_ROOT,
865 wxTR_ROW_LINES,
866
867 wxTR_FULL_ROW_HIGHLIGHT,
868 wxTR_DEFAULT_STYLE,
869
870 wxTR_TWIST_BUTTONS,
871 wxTR_MAC_BUTTONS,
872 wxTR_AQUA_BUTTONS,
873 };
874
875
876 enum wxTreeItemIcon
877 {
878 wxTreeItemIcon_Normal, // not selected, not expanded
879 wxTreeItemIcon_Selected, // selected, not expanded
880 wxTreeItemIcon_Expanded, // not selected, expanded
881 wxTreeItemIcon_SelectedExpanded, // selected, expanded
882 wxTreeItemIcon_Max
883 };
884
885
886 // constants for HitTest
887 enum {
888 wxTREE_HITTEST_ABOVE,
889 wxTREE_HITTEST_BELOW,
890 wxTREE_HITTEST_NOWHERE,
891 wxTREE_HITTEST_ONITEMBUTTON,
892 wxTREE_HITTEST_ONITEMICON,
893 wxTREE_HITTEST_ONITEMINDENT,
894 wxTREE_HITTEST_ONITEMLABEL,
895 wxTREE_HITTEST_ONITEMRIGHT,
896 wxTREE_HITTEST_ONITEMSTATEICON,
897 wxTREE_HITTEST_TOLEFT,
898 wxTREE_HITTEST_TORIGHT,
899 wxTREE_HITTEST_ONITEMUPPERPART,
900 wxTREE_HITTEST_ONITEMLOWERPART,
901 wxTREE_HITTEST_ONITEM
902 };
903
904
905 enum {
906 /* Tree control event types */
907 wxEVT_COMMAND_TREE_BEGIN_DRAG,
908 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
909 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
910 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
911 wxEVT_COMMAND_TREE_DELETE_ITEM,
912 wxEVT_COMMAND_TREE_GET_INFO,
913 wxEVT_COMMAND_TREE_SET_INFO,
914 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
915 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
916 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
917 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
918 wxEVT_COMMAND_TREE_SEL_CHANGED,
919 wxEVT_COMMAND_TREE_SEL_CHANGING,
920 wxEVT_COMMAND_TREE_KEY_DOWN,
921 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
922 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
923 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
924 wxEVT_COMMAND_TREE_END_DRAG,
925 wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK,
926 };
927
928
929 %pragma(python) code = "
930 # wxTreeCtrl events
931 def EVT_TREE_BEGIN_DRAG(win, id, func):
932 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func)
933
934 def EVT_TREE_BEGIN_RDRAG(win, id, func):
935 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func)
936
937 def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func):
938 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func)
939
940 def EVT_TREE_END_LABEL_EDIT(win, id, func):
941 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func)
942
943 def EVT_TREE_GET_INFO(win, id, func):
944 win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func)
945
946 def EVT_TREE_SET_INFO(win, id, func):
947 win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func)
948
949 def EVT_TREE_ITEM_EXPANDED(win, id, func):
950 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func)
951
952 def EVT_TREE_ITEM_EXPANDING(win, id, func):
953 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func)
954
955 def EVT_TREE_ITEM_COLLAPSED(win, id, func):
956 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func)
957
958 def EVT_TREE_ITEM_COLLAPSING(win, id, func):
959 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func)
960
961 def EVT_TREE_SEL_CHANGED(win, id, func):
962 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func)
963
964 def EVT_TREE_SEL_CHANGING(win, id, func):
965 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func)
966
967 def EVT_TREE_KEY_DOWN(win, id, func):
968 win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func)
969
970 def EVT_TREE_DELETE_ITEM(win, id, func):
971 win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
972
973 def EVT_TREE_ITEM_ACTIVATED(win, id, func):
974 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
975
976 def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
977 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
978
979 def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
980 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
981
982 def EVT_TREE_END_DRAG(win, id, func):
983 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func)
984
985 def EVT_TREE_STATE_IMAGE_CLICK(win, id, func):
986 win.Connect(id, -1, wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK, func)
987
988 "
989
990
991 typedef void *wxTreeItemIdValue;
992
993
994 class wxTreeItemAttr
995 {
996 public:
997 // ctors
998 //wxTreeItemAttr() { }
999 wxTreeItemAttr(const wxColour& colText = wxNullColour,
1000 const wxColour& colBack = wxNullColour,
1001 const wxFont& font = wxNullFont);
1002
1003 // setters
1004 void SetTextColour(const wxColour& colText);
1005 void SetBackgroundColour(const wxColour& colBack);
1006 void SetFont(const wxFont& font);
1007
1008 // accessors
1009 bool HasTextColour();
1010 bool HasBackgroundColour();
1011 bool HasFont();
1012
1013 wxColour GetTextColour();
1014 wxColour GetBackgroundColour();
1015 wxFont GetFont();
1016 };
1017
1018
1019 class wxTreeItemId {
1020 public:
1021 wxTreeItemId();
1022 ~wxTreeItemId();
1023 bool IsOk();
1024 %pragma(python) addtoclass = "
1025 Ok = IsOk
1026 def __nonzero__(self):
1027 return self.IsOk()
1028 "
1029
1030 %addmethods {
1031 int __cmp__(wxTreeItemId* other) {
1032 if (! other) return -1;
1033 return *self != *other;
1034 }
1035 }
1036 };
1037
1038
1039
1040
1041 %name(wxTreeItemData) class wxPyTreeItemData {
1042 public:
1043 wxPyTreeItemData(PyObject* obj = NULL);
1044
1045 PyObject* GetData();
1046 void SetData(PyObject* obj);
1047
1048 const wxTreeItemId& GetId();
1049 void SetId(const wxTreeItemId& id);
1050 };
1051
1052
1053
1054 class wxTreeEvent : public wxNotifyEvent {
1055 public:
1056 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
1057
1058 // get the item on which the operation was performed or the newly
1059 // selected item for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events
1060 wxTreeItemId GetItem() const;
1061 void SetItem(const wxTreeItemId& item);
1062
1063 // for wxEVT_COMMAND_TREE_SEL_CHANGED/ING events, get the previously
1064 // selected item
1065 wxTreeItemId GetOldItem() const;
1066 void SetOldItem(const wxTreeItemId& item);
1067
1068 // the point where the mouse was when the drag operation started (for
1069 // wxEVT_COMMAND_TREE_BEGIN_(R)DRAG events only) or click position
1070 wxPoint GetPoint() const;
1071 void SetPoint(const wxPoint& pt);
1072
1073 // keyboard data (for wxEVT_COMMAND_TREE_KEY_DOWN only)
1074 const wxKeyEvent& GetKeyEvent() const;
1075 int GetKeyCode() const;
1076 void SetKeyEvent(const wxKeyEvent& evt);
1077
1078 // label (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
1079 const wxString& GetLabel() const;
1080 void SetLabel(const wxString& label);
1081
1082 // edit cancel flag (for EVT_TREE_{BEGIN|END}_LABEL_EDIT only)
1083 bool IsEditCancelled() const;
1084 void SetEditCanceled(bool editCancelled);
1085
1086 };
1087
1088
1089
1090 %{ // C++ version of Python aware wxTreeCtrl
1091 class wxPyTreeCtrl : public wxTreeCtrl {
1092 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
1093 public:
1094 wxPyTreeCtrl() : wxTreeCtrl() {}
1095 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
1096 const wxPoint& pos,
1097 const wxSize& size,
1098 long style,
1099 const wxValidator& validator,
1100 const wxString& name) :
1101 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
1102
1103 bool Create(wxWindow *parent, wxWindowID id,
1104 const wxPoint& pos,
1105 const wxSize& size,
1106 long style,
1107 const wxValidator& validator,
1108 const wxString& name) {
1109 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
1110 }
1111
1112
1113 int OnCompareItems(const wxTreeItemId& item1,
1114 const wxTreeItemId& item2) {
1115 int rval = 0;
1116 bool found;
1117 wxPyBeginBlockThreads();
1118 if ((found = m_myInst.findCallback("OnCompareItems"))) {
1119 PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"));
1120 PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"));
1121 rval = m_myInst.callCallback(Py_BuildValue("(OO)",o1,o2));
1122 Py_DECREF(o1);
1123 Py_DECREF(o2);
1124 }
1125 wxPyEndBlockThreads();
1126 if (! found)
1127 rval = wxTreeCtrl::OnCompareItems(item1, item2);
1128 return rval;
1129 }
1130 PYPRIVATE;
1131 };
1132
1133 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
1134
1135 %}
1136
1137 // These are for the GetFirstChild/GetNextChild methods below
1138 %typemap(python, in) long& INOUT = long* INOUT;
1139 %typemap(python, argout) long& INOUT = long* INOUT;
1140
1141
1142 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
1143 public:
1144 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
1145 const wxPoint& pos = wxDefaultPosition,
1146 const wxSize& size = wxDefaultSize,
1147 long style = wxTR_DEFAULT_STYLE,
1148 const wxValidator& validator = wxDefaultValidator,
1149 const wxString& name = wxPy_TreeCtrlNameStr);
1150 %name(wxPreTreeCtrl)wxPyTreeCtrl();
1151
1152 bool Create(wxWindow *parent, wxWindowID id = -1,
1153 const wxPoint& pos = wxDefaultPosition,
1154 const wxSize& size = wxDefaultSize,
1155 long style = wxTR_DEFAULT_STYLE,
1156 const wxValidator& validator = wxDefaultValidator,
1157 const wxString& name = wxPy_TreeCtrlNameStr);
1158
1159 void _setCallbackInfo(PyObject* self, PyObject* _class);
1160 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeCtrl)"
1161
1162 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1163 %pragma(python) addtomethod = "wxPreTreeCtrl:val._setOORInfo(val)"
1164
1165 size_t GetCount();
1166 unsigned int GetIndent();
1167 void SetIndent(unsigned int indent);
1168 wxImageList *GetImageList();
1169 wxImageList *GetStateImageList();
1170 void SetImageList(wxImageList *imageList);
1171 void SetStateImageList(wxImageList *imageList);
1172 void AssignImageList(wxImageList* imageList);
1173 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
1174 void AssignStateImageList(wxImageList* imageList);
1175 %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0"
1176
1177 unsigned int GetSpacing();
1178 void SetSpacing(unsigned int spacing);
1179
1180 wxString GetItemText(const wxTreeItemId& item);
1181 int GetItemImage(const wxTreeItemId& item,
1182 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1183 int GetItemSelectedImage(const wxTreeItemId& item);
1184
1185 void SetItemText(const wxTreeItemId& item, const wxString& text);
1186 void SetItemImage(const wxTreeItemId& item, int image,
1187 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1188 void SetItemSelectedImage(const wxTreeItemId& item, int image);
1189 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
1190
1191 %addmethods {
1192 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
1193 // if needed.
1194 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
1195 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1196 if (data == NULL) {
1197 data = new wxPyTreeItemData();
1198 data->SetId(item); // set the id
1199 self->SetItemData(item, data);
1200 }
1201 return data;
1202 }
1203
1204 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
1205 data->SetId(item); // set the id
1206 self->SetItemData(item, data);
1207 }
1208
1209 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1210 // automatically creating data classes.
1211 PyObject* GetPyData(const wxTreeItemId& item) {
1212 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1213 if (data == NULL) {
1214 data = new wxPyTreeItemData();
1215 data->SetId(item); // set the id
1216 self->SetItemData(item, data);
1217 }
1218 return data->GetData();
1219 }
1220
1221 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
1222 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1223 if (data == NULL) {
1224 data = new wxPyTreeItemData(obj);
1225 data->SetId(item); // set the id
1226 self->SetItemData(item, data);
1227 } else
1228 data->SetData(obj);
1229 }
1230 }
1231
1232
1233 // get the item's text colour
1234 wxColour GetItemTextColour(const wxTreeItemId& item) const;
1235
1236 // get the item's background colour
1237 wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
1238
1239 // get the item's font
1240 wxFont GetItemFont(const wxTreeItemId& item) const;
1241
1242
1243 bool IsVisible(const wxTreeItemId& item);
1244 bool ItemHasChildren(const wxTreeItemId& item);
1245 bool IsExpanded(const wxTreeItemId& item);
1246 bool IsSelected(const wxTreeItemId& item);
1247
1248 wxTreeItemId GetRootItem();
1249 wxTreeItemId GetSelection();
1250 wxTreeItemId GetItemParent(const wxTreeItemId& item);
1251 //size_t GetSelections(wxArrayTreeItemIds& selection);
1252 %addmethods {
1253 PyObject* GetSelections() {
1254 wxPyBeginBlockThreads();
1255 PyObject* rval = PyList_New(0);
1256 wxArrayTreeItemIds array;
1257 size_t num, x;
1258 num = self->GetSelections(array);
1259 for (x=0; x < num; x++) {
1260 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1261 PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), TRUE);
1262 PyList_Append(rval, item);
1263 }
1264 wxPyEndBlockThreads();
1265 return rval;
1266 }
1267 }
1268
1269
1270
1271 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1272
1273 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT = longzero);
1274 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
1275 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
1276 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
1277 wxTreeItemId GetFirstVisibleItem();
1278 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
1279 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
1280 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1281
1282
1283
1284 wxTreeItemId AddRoot(const wxString& text,
1285 int image = -1, int selectedImage = -1,
1286 wxPyTreeItemData *data = NULL);
1287 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1288 const wxString& text,
1289 int image = -1, int selectedImage = -1,
1290 wxPyTreeItemData *data = NULL);
1291 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1292 const wxTreeItemId& idPrevious,
1293 const wxString& text,
1294 int image = -1, int selectedImage = -1,
1295 wxPyTreeItemData *data = NULL);
1296 %name(InsertItemBefore)
1297 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1298 size_t before,
1299 const wxString& text,
1300 int image = -1, int selectedImage = -1,
1301 wxPyTreeItemData *data = NULL);
1302 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1303 const wxString& text,
1304 int image = -1, int selectedImage = -1,
1305 wxPyTreeItemData *data = NULL);
1306
1307 void Delete(const wxTreeItemId& item);
1308 void DeleteChildren(const wxTreeItemId& item);
1309 void DeleteAllItems();
1310
1311 void Expand(const wxTreeItemId& item);
1312 void Collapse(const wxTreeItemId& item);
1313 void CollapseAndReset(const wxTreeItemId& item);
1314 void Toggle(const wxTreeItemId& item);
1315
1316 void Unselect();
1317 void UnselectAll();
1318 void SelectItem(const wxTreeItemId& item);
1319 void EnsureVisible(const wxTreeItemId& item);
1320 void ScrollTo(const wxTreeItemId& item);
1321
1322 wxTextCtrl* GetEditControl();
1323 void EditLabel(const wxTreeItemId& item);
1324 #ifdef __WXMSW__
1325 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
1326 #endif
1327
1328 void SortChildren(const wxTreeItemId& item);
1329
1330 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
1331 bool IsBold(const wxTreeItemId& item) const;
1332 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
1333
1334
1335
1336 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
1337 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
1338 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
1339
1340 #ifdef __WXMSW__
1341 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
1342 #endif
1343
1344 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
1345 %addmethods {
1346 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
1347 wxRect rect;
1348 if (self->GetBoundingRect(item, rect, textOnly)) {
1349 wxPyBeginBlockThreads();
1350 wxRect* r = new wxRect(rect);
1351 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), 1);
1352 wxPyEndBlockThreads();
1353 return val;
1354 }
1355 else {
1356 Py_INCREF(Py_None);
1357 return Py_None;
1358 }
1359 }
1360 }
1361
1362
1363 %pragma(python) addtoclass = "
1364 # Redefine some methods that SWIG gets a bit confused on...
1365 def GetFirstChild(self, *_args, **_kwargs):
1366 val1,val2 = controls2c.wxTreeCtrl_GetFirstChild(self, *_args, **_kwargs)
1367 val1 = wxTreeItemIdPtr(val1)
1368 val1.thisown = 1
1369 return (val1,val2)
1370 def GetNextChild(self, *_args, **_kwargs):
1371 val1,val2 = controls2c.wxTreeCtrl_GetNextChild(self, *_args, **_kwargs)
1372 val1 = wxTreeItemIdPtr(val1)
1373 val1.thisown = 1
1374 return (val1,val2)
1375 def HitTest(self, *_args, **_kwargs):
1376 val1, val2 = controls2c.wxTreeCtrl_HitTest(self, *_args, **_kwargs)
1377 val1 = wxTreeItemIdPtr(val1)
1378 val1.thisown = 1
1379 return (val1,val2)
1380 "
1381
1382 };
1383
1384
1385 //----------------------------------------------------------------------
1386
1387
1388 enum {
1389 wxDIRCTRL_DIR_ONLY,
1390 wxDIRCTRL_SELECT_FIRST,
1391 wxDIRCTRL_SHOW_FILTERS,
1392 wxDIRCTRL_3D_INTERNAL,
1393 wxDIRCTRL_EDIT_LABELS,
1394
1395 wxID_TREECTRL,
1396 wxID_FILTERLISTCTRL,
1397 };
1398
1399
1400 class wxDirItemData : public wxObject // wxTreeItemData
1401 {
1402 public:
1403 wxDirItemData(const wxString& path, const wxString& name, bool isDir);
1404 // ~wxDirItemDataEx();
1405 void SetNewDirName( wxString path );
1406 wxString m_path, m_name;
1407 bool m_isHidden;
1408 bool m_isExpanded;
1409 bool m_isDir;
1410 };
1411
1412
1413 class wxGenericDirCtrl: public wxControl
1414 {
1415 public:
1416 wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1,
1417 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1418 const wxPoint& pos = wxDefaultPosition,
1419 const wxSize& size = wxDefaultSize,
1420 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1421 const wxString& filter = wxPyEmptyString,
1422 int defaultFilter = 0,
1423 const wxString& name = wxPy_TreeCtrlNameStr);
1424 %name(wxPreGenericDirCtrl)wxGenericDirCtrl();
1425
1426 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1427 %pragma(python) addtomethod = "wxPreGenericDirCtrl:val._setOORInfo(val)"
1428
1429 bool Create(wxWindow *parent, const wxWindowID id = -1,
1430 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1431 const wxPoint& pos = wxDefaultPosition,
1432 const wxSize& size = wxDefaultSize,
1433 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1434 const wxString& filter = wxPyEmptyString,
1435 int defaultFilter = 0,
1436 const wxString& name = wxPy_TreeCtrlNameStr);
1437
1438
1439 // Try to expand as much of the given path as possible.
1440 bool ExpandPath(const wxString& path);
1441
1442 // Accessors
1443
1444 inline wxString GetDefaultPath() const;
1445 void SetDefaultPath(const wxString& path);
1446
1447 // Get dir or filename
1448 wxString GetPath() const ;
1449
1450 // Get selected filename path only (else empty string).
1451 // I.e. don't count a directory as a selection
1452 wxString GetFilePath() const ;
1453 void SetPath(const wxString& path) ;
1454
1455 void ShowHidden( bool show );
1456 bool GetShowHidden();
1457
1458 wxString GetFilter() const;
1459 void SetFilter(const wxString& filter);
1460
1461 int GetFilterIndex() const;
1462 void SetFilterIndex(int n) ;
1463
1464 wxTreeItemId GetRootId();
1465
1466 wxTreeCtrl* GetTreeCtrl() const;
1467 wxDirFilterListCtrl* GetFilterListCtrl() const;
1468
1469 // Collapse & expand the tree, thus re-creating it from scratch:
1470 void ReCreateTree();
1471
1472 // //// Helpers
1473 // void SetupSections();
1474 // // Parse the filter into an array of filters and an array of descriptions
1475 // int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
1476 // // Find the child that matches the first part of 'path'.
1477 // // E.g. if a child path is "/usr" and 'path' is "/usr/include"
1478 // // then the child for /usr is returned.
1479 // // If the path string has been used (we're at the leaf), done is set to TRUE
1480 // wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
1481 };
1482
1483
1484 class wxDirFilterListCtrl: public wxChoice
1485 {
1486 public:
1487 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1488 const wxPoint& pos = wxDefaultPosition,
1489 const wxSize& size = wxDefaultSize,
1490 long style = 0);
1491 %name(wxPreDirFilterListCtrl)wxDirFilterListCtrl();
1492
1493 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1494 %pragma(python) addtomethod = "wxPreDirFilterListCtrl:val._setOORInfo(val)"
1495
1496 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1497 const wxPoint& pos = wxDefaultPosition,
1498 const wxSize& size = wxDefaultSize,
1499 long style = 0);
1500
1501 //// Operations
1502 void FillFilterList(const wxString& filter, int defaultFilter);
1503 };
1504
1505
1506 class wxFileIconsTable
1507 {
1508 public:
1509 wxFileIconsTable();
1510 ~wxFileIconsTable();
1511
1512 enum iconId_Type
1513 {
1514 folder,
1515 folder_open,
1516 computer,
1517 drive,
1518 cdrom,
1519 floppy,
1520 removeable,
1521 file,
1522 executable
1523 };
1524
1525 int GetIconID(const wxString& extension, const wxString& mime = wxEmptyString);
1526 wxImageList *GetSmallImageList();
1527 };
1528
1529
1530 //----------------------------------------------------------------------
1531 //----------------------------------------------------------------------
1532
1533 %init %{
1534 // Map renamed classes back to their common name for OOR
1535 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1536 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1537 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
1538 %}
1539
1540 //----------------------------------------------------------------------
1541
1542