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