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