]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/controls2.i
compilation error fix (trailing comma in an enum)
[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 item.SetMask(0xFFFF);
448 if (self->GetColumn(col, item))
449 return new wxListItem(item);
450 else
451 return NULL;
452 }
453 } // The OOR typemaps don't know what to do with the %new, so fix it up.
454 %pragma(python) addtoclass = "
455 def GetColumn(self, *_args, **_kwargs):
456 val = apply(controls2c.wxListCtrl_GetColumn,(self,) + _args, _kwargs)
457 if val is not None: val.thisown = 1
458 return val
459 "
460
461 // Sets information about this column
462 bool SetColumn(int col, wxListItem& item) ;
463
464 // Gets the column width
465 int GetColumnWidth(int col) const;
466
467 // Sets the column width
468 bool SetColumnWidth(int col, int width) ;
469
470 // Gets the number of items that can fit vertically in the
471 // visible area of the list control (list or report view)
472 // or the total number of items in the list control (icon
473 // or small icon view)
474 int GetCountPerPage() const;
475
476 #ifdef __WXMSW__
477 // Gets the edit control for editing labels.
478 wxTextCtrl* GetEditControl() const;
479 #endif
480
481 //bool GetItem(wxListItem& info) const ;
482 %addmethods {
483 // Gets information about the item
484 %new wxListItem* GetItem(long itemId, int col=0) {
485 wxListItem* info = new wxListItem;
486 info->m_itemId = itemId;
487 info->m_col = col;
488 info->m_mask = 0xFFFF;
489 self->GetItem(*info);
490 return info;
491 }
492 } // The OOR typemaps don't know what to do with the %new, so fix it up.
493 %pragma(python) addtoclass = "
494 def GetItem(self, *_args, **_kwargs):
495 val = apply(controls2c.wxListCtrl_GetItem,(self,) + _args, _kwargs)
496 if val is not None: val.thisown = 1
497 return val
498 "
499
500
501 // Sets information about the item
502 bool SetItem(wxListItem& info) ;
503
504 // Sets a string field at a particular column
505 %name(SetStringItem)long SetItem(long index, int col, const wxString& label, int imageId = -1);
506
507 // Gets the item state
508 int GetItemState(long item, long stateMask) const ;
509
510 // Sets the item state
511 bool SetItemState(long item, long state, long stateMask) ;
512
513 // Sets the item image
514 bool SetItemImage(long item, int image, int selImage) ;
515
516 // Gets the item text
517 wxString GetItemText(long item) const ;
518
519 // Sets the item text
520 void SetItemText(long item, const wxString& str) ;
521
522 // Gets the item data
523 long GetItemData(long item) const ;
524
525 // Sets the item data
526 bool SetItemData(long item, long data) ;
527
528
529 //bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
530 //bool GetItemPosition(long item, wxPoint& pos) const ;
531
532 // Gets the item position
533 %addmethods {
534 %new wxPoint* GetItemPosition(long item) {
535 wxPoint* pos = new wxPoint;
536 self->GetItemPosition(item, *pos);
537 return pos;
538 }
539 // Gets the item rectangle
540 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
541 wxRect* rect= new wxRect;
542 self->GetItemRect(item, *rect, code);
543 return rect;
544 }
545 }
546
547
548 // Sets the item position
549 bool SetItemPosition(long item, const wxPoint& pos) ;
550
551 // Gets the number of items in the list control
552 int GetItemCount() const;
553
554 // Gets the number of columns in the list control
555 int GetColumnCount() const;
556
557 // Retrieves the spacing between icons in pixels.
558 // If small is TRUE, gets the spacing for the small icon
559 // view, otherwise the large icon view.
560 int GetItemSpacing(bool isSmall) const;
561
562 // Gets the number of selected items in the list control
563 int GetSelectedItemCount() const;
564
565 // Gets the text colour of the listview
566 wxColour GetTextColour() const;
567
568 // Sets the text colour of the listview
569 void SetTextColour(const wxColour& col);
570
571 // Gets the index of the topmost visible item when in
572 // list or report view
573 long GetTopItem() const ;
574
575 // Add or remove a single window style
576 void SetSingleStyle(long style, bool add = TRUE) ;
577
578 // Set the whole window style
579 void SetWindowStyleFlag(long style) ;
580
581 // Searches for an item, starting from 'item'.
582 // item can be -1 to find the first item that matches the
583 // specified flags.
584 // Returns the item or -1 if unsuccessful.
585 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
586
587 // Gets one of the three image lists
588 wxImageList *GetImageList(int which) const ;
589
590 // Sets the image list
591 void SetImageList(wxImageList *imageList, int which) ;
592 void AssignImageList(wxImageList *imageList, int which) ;
593 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
594
595 // returns true if it is a virtual list control
596 bool IsVirtual() const;
597
598 // refresh items selectively (only useful for virtual list controls)
599 void RefreshItem(long item);
600 void RefreshItems(long itemFrom, long itemTo);
601
602 // Arranges the items
603 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
604
605 // Deletes an item
606 bool DeleteItem(long item);
607
608 // Deletes all items
609 bool DeleteAllItems() ;
610
611 // Deletes a column
612 bool DeleteColumn(int col);
613
614 // Deletes all columns
615 bool DeleteAllColumns();
616
617 // Clears items, and columns if there are any.
618 void ClearAll();
619
620 #ifdef __WXMSW__
621 // Edit the label
622 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
623
624 // End label editing, optionally cancelling the edit
625 bool EndEditLabel(bool cancel);
626 #endif
627
628 // Ensures this item is visible
629 bool EnsureVisible(long item) ;
630
631 // Find an item whose label matches this string, starting from the item after 'start'
632 // or the beginning if 'start' is -1.
633 long FindItem(long start, const wxString& str, bool partial = FALSE);
634
635 // Find an item whose data matches this data, starting from the item after 'start'
636 // or the beginning if 'start' is -1.
637 %name(FindItemData)long FindItem(long start, long data);
638
639 // Find an item nearest this position in the specified direction, starting from
640 // the item after 'start' or the beginning if 'start' is -1.
641 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt, int direction);
642
643 // Determines which item (if any) is at the specified point,
644 // giving details in the second return value (see wxLIST_HITTEST_... flags above)
645 long HitTest(const wxPoint& point, int& OUTPUT);
646
647 // Inserts an item, returning the index of the new item if successful,
648 // -1 otherwise.
649 long InsertItem(wxListItem& info);
650
651 // Insert a string item
652 %name(InsertStringItem)long InsertItem(long index, const wxString& label);
653
654 // Insert an image item
655 %name(InsertImageItem)long InsertItem(long index, int imageIndex);
656
657 // Insert an image/string item
658 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label, int imageIndex);
659
660 // For list view mode (only), inserts a column.
661 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
662
663 long InsertColumn(long col,
664 const wxString& heading,
665 int format = wxLIST_FORMAT_LEFT,
666 int width = -1);
667
668 // set the number of items in a virtual list control
669 void SetItemCount(long count);
670
671 // Scrolls the list control. If in icon, small icon or report view mode,
672 // x specifies the number of pixels to scroll. If in list view mode, x
673 // specifies the number of columns to scroll.
674 // If in icon, small icon or list view mode, y specifies the number of pixels
675 // to scroll. If in report view mode, y specifies the number of lines to scroll.
676 bool ScrollList(int dx, int dy);
677
678 void SetItemTextColour( long item, const wxColour& col);
679 wxColour GetItemTextColour( long item ) const;
680 void SetItemBackgroundColour( long item, const wxColour &col);
681 wxColour GetItemBackgroundColour( long item ) const;
682
683
684 %pragma(python) addtoclass = "
685 # Some helpers...
686
687 def Select(self, idx, on=1):
688 '''[de]select an item'''
689 if on: state = wxLIST_STATE_SELECTED
690 else: state = 0
691 self.SetItemState(idx, state, wxLIST_STATE_SELECTED)
692
693 def Focus(self, idx):
694 '''Focus and show the given item'''
695 self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED)
696 self.EnsureVisible(idx)
697
698 def GetFocusedItem(self):
699 '''get the currently focused item or -1 if none'''
700 return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
701
702 def IsSelected(self, idx):
703 '''return TRUE if the item is selected'''
704 return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
705
706 def SetColumnImage(self, col, image):
707 item = wxListItem()
708 item.SetMask(wxLIST_MASK_IMAGE)
709 item.SetImage(image)
710 self.SetColumn(col, item)
711
712 def ClearColumnImage(self, col):
713 self.SetColumnImage(col, -1)
714
715 def Append(self, entry):
716 '''Append an item to the list control. The entry parameter should be a
717 sequence with an item for each column'''
718 if len(entry):
719 pos = self.GetItemCount()
720 self.InsertStringItem(pos, str(entry[0]))
721 for i in range(1, len(entry)):
722 self.SetStringItem(pos, i, str(entry[i]))
723 return pos
724 "
725
726
727 // bool SortItems(wxListCtrlCompare fn, long data);
728 %addmethods {
729 // Sort items.
730 // func is a function which takes 2 long arguments: item1, item2.
731 // item1 is the long data associated with a first item (NOT the index).
732 // item2 is the long data associated with a second item (NOT the index).
733 // The return value is a negative number if the first item should precede the second
734 // item, a positive number of the second item should precede the first,
735 // or zero if the two items are equivalent.
736 bool SortItems(PyObject* func) {
737 if (!PyCallable_Check(func))
738 return FALSE;
739 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
740 }
741 }
742 };
743
744
745
746 %{ // Python aware sorting function for wxPyListCtrl
747 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
748 int retval = 0;
749 PyObject* func = (PyObject*)funcPtr;
750 wxPyBeginBlockThreads();
751
752 PyObject* args = Py_BuildValue("(ii)", item1, item2);
753 PyObject* result = PyEval_CallObject(func, args);
754 Py_DECREF(args);
755 if (result) {
756 retval = PyInt_AsLong(result);
757 Py_DECREF(result);
758 }
759
760 wxPyEndBlockThreads();
761 return retval;
762 }
763
764 %}
765
766 //----------------------------------------------------------------------
767
768 class wxListView : public wxPyListCtrl
769 {
770 public:
771 wxListView( wxWindow *parent,
772 wxWindowID id = -1,
773 const wxPoint& pos = wxDefaultPosition,
774 const wxSize& size = wxDefaultSize,
775 long style = wxLC_REPORT,
776 const wxValidator& validator = wxDefaultValidator,
777 const wxString& name = wxPyListCtrlNameStr);
778 %name(wxPreListView)wxListView();
779
780 bool Create( wxWindow *parent,
781 wxWindowID id = -1,
782 const wxPoint& pos = wxDefaultPosition,
783 const wxSize& size = wxDefaultSize,
784 long style = wxLC_REPORT,
785 const wxValidator& validator = wxDefaultValidator,
786 const wxString& name = wxPyListCtrlNameStr);
787
788 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
789 %pragma(python) addtomethod = "wxPreListView:val._setOORInfo(val)"
790
791 // [de]select an item
792 void Select(long n, bool on = TRUE);
793
794 // focus and show the given item
795 void Focus(long index);
796
797 // get the currently focused item or -1 if none
798 long GetFocusedItem() const;
799
800 // get first and subsequent selected items, return -1 when no more
801 long GetNextSelected(long item) const;
802 long GetFirstSelected() const;
803
804 // return TRUE if the item is selected
805 bool IsSelected(long index);
806
807 void SetColumnImage(int col, int image);
808 void ClearColumnImage(int col);
809 };
810
811
812 //----------------------------------------------------------------------
813
814 // wxTreeCtrl flags
815 enum {
816 wxTR_NO_BUTTONS,
817 wxTR_HAS_BUTTONS,
818 wxTR_TWIST_BUTTONS,
819 wxTR_NO_LINES,
820 wxTR_MAC_BUTTONS,
821 wxTR_AQUA_BUTTONS,
822
823 wxTR_SINGLE,
824 wxTR_MULTIPLE,
825 wxTR_EXTENDED,
826 wxTR_FULL_ROW_HIGHLIGHT,
827
828 wxTR_EDIT_LABELS,
829 wxTR_LINES_AT_ROOT,
830 wxTR_HIDE_ROOT,
831 wxTR_ROW_LINES,
832 wxTR_HAS_VARIABLE_ROW_HEIGHT,
833
834 wxTR_DEFAULT_STYLE,
835 };
836
837 enum wxTreeItemIcon
838 {
839 wxTreeItemIcon_Normal, // not selected, not expanded
840 wxTreeItemIcon_Selected, // selected, not expanded
841 wxTreeItemIcon_Expanded, // not selected, expanded
842 wxTreeItemIcon_SelectedExpanded, // selected, expanded
843 wxTreeItemIcon_Max
844 };
845
846
847 // constants for HitTest
848 enum {
849 wxTREE_HITTEST_ABOVE,
850 wxTREE_HITTEST_BELOW,
851 wxTREE_HITTEST_NOWHERE,
852 wxTREE_HITTEST_ONITEMBUTTON,
853 wxTREE_HITTEST_ONITEMICON,
854 wxTREE_HITTEST_ONITEMINDENT,
855 wxTREE_HITTEST_ONITEMLABEL,
856 wxTREE_HITTEST_ONITEMRIGHT,
857 wxTREE_HITTEST_ONITEMSTATEICON,
858 wxTREE_HITTEST_TOLEFT,
859 wxTREE_HITTEST_TORIGHT,
860 wxTREE_HITTEST_ONITEMUPPERPART,
861 wxTREE_HITTEST_ONITEMLOWERPART,
862 wxTREE_HITTEST_ONITEM
863 };
864
865
866 enum {
867 /* Tree control event types */
868 wxEVT_COMMAND_TREE_BEGIN_DRAG,
869 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
870 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
871 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
872 wxEVT_COMMAND_TREE_DELETE_ITEM,
873 wxEVT_COMMAND_TREE_GET_INFO,
874 wxEVT_COMMAND_TREE_SET_INFO,
875 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
876 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
877 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
878 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
879 wxEVT_COMMAND_TREE_SEL_CHANGED,
880 wxEVT_COMMAND_TREE_SEL_CHANGING,
881 wxEVT_COMMAND_TREE_KEY_DOWN,
882 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
883 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
884 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
885 wxEVT_COMMAND_TREE_END_DRAG,
886 };
887
888
889 %pragma(python) code = "
890 # wxTreeCtrl events
891 def EVT_TREE_BEGIN_DRAG(win, id, func):
892 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func)
893
894 def EVT_TREE_BEGIN_RDRAG(win, id, func):
895 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func)
896
897 def EVT_TREE_END_DRAG(win, id, func):
898 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func)
899
900 def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func):
901 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func)
902
903 def EVT_TREE_END_LABEL_EDIT(win, id, func):
904 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func)
905
906 def EVT_TREE_GET_INFO(win, id, func):
907 win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func)
908
909 def EVT_TREE_SET_INFO(win, id, func):
910 win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func)
911
912 def EVT_TREE_ITEM_EXPANDED(win, id, func):
913 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func)
914
915 def EVT_TREE_ITEM_EXPANDING(win, id, func):
916 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func)
917
918 def EVT_TREE_ITEM_COLLAPSED(win, id, func):
919 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func)
920
921 def EVT_TREE_ITEM_COLLAPSING(win, id, func):
922 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func)
923
924 def EVT_TREE_SEL_CHANGED(win, id, func):
925 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func)
926
927 def EVT_TREE_SEL_CHANGING(win, id, func):
928 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func)
929
930 def EVT_TREE_KEY_DOWN(win, id, func):
931 win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func)
932
933 def EVT_TREE_DELETE_ITEM(win, id, func):
934 win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
935
936 def EVT_TREE_ITEM_ACTIVATED(win, id, func):
937 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
938
939 def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
940 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
941
942 def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
943 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
944 "
945
946
947 class wxTreeItemAttr
948 {
949 public:
950 // ctors
951 //wxTreeItemAttr() { }
952 wxTreeItemAttr(const wxColour& colText = wxNullColour,
953 const wxColour& colBack = wxNullColour,
954 const wxFont& font = wxNullFont);
955
956 // setters
957 void SetTextColour(const wxColour& colText);
958 void SetBackgroundColour(const wxColour& colBack);
959 void SetFont(const wxFont& font);
960
961 // accessors
962 bool HasTextColour();
963 bool HasBackgroundColour();
964 bool HasFont();
965
966 wxColour GetTextColour();
967 wxColour GetBackgroundColour();
968 wxFont GetFont();
969 };
970
971
972 class wxTreeItemId {
973 public:
974 wxTreeItemId();
975 ~wxTreeItemId();
976 bool IsOk();
977 %pragma(python) addtoclass = "Ok = IsOk"
978
979 %addmethods {
980 int __cmp__(wxTreeItemId* other) {
981 if (! other) return -1;
982 return *self != *other;
983 }
984 }
985 };
986
987
988
989 %{
990 class wxPyTreeItemData : public wxTreeItemData {
991 public:
992 wxPyTreeItemData(PyObject* obj = NULL) {
993 if (obj == NULL)
994 obj = Py_None;
995 Py_INCREF(obj);
996 m_obj = obj;
997 }
998
999 ~wxPyTreeItemData() {
1000 wxPyBeginBlockThreads();
1001 Py_DECREF(m_obj);
1002 wxPyEndBlockThreads();
1003 }
1004
1005 PyObject* GetData() {
1006 Py_INCREF(m_obj);
1007 return m_obj;
1008 }
1009
1010 void SetData(PyObject* obj) {
1011 wxPyBeginBlockThreads();
1012 Py_DECREF(m_obj);
1013 wxPyEndBlockThreads();
1014 m_obj = obj;
1015 Py_INCREF(obj);
1016 }
1017
1018 PyObject* m_obj;
1019 };
1020 %}
1021
1022
1023
1024 %name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
1025 public:
1026 wxPyTreeItemData(PyObject* obj = NULL);
1027
1028 PyObject* GetData();
1029 void SetData(PyObject* obj);
1030
1031 const wxTreeItemId& GetId();
1032 void SetId(const wxTreeItemId& id);
1033 };
1034
1035
1036
1037 class wxTreeEvent : public wxNotifyEvent {
1038 public:
1039 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
1040
1041 wxTreeItemId GetItem();
1042 wxTreeItemId GetOldItem();
1043 wxPoint GetPoint();
1044 const wxKeyEvent& GetKeyEvent();
1045 int GetCode();
1046 const wxString& GetLabel();
1047 };
1048
1049
1050
1051 %{ // C++ version of Python aware wxTreeCtrl
1052 class wxPyTreeCtrl : public wxTreeCtrl {
1053 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
1054 public:
1055 wxPyTreeCtrl() : wxTreeCtrl() {}
1056 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
1057 const wxPoint& pos,
1058 const wxSize& size,
1059 long style,
1060 const wxValidator& validator,
1061 const wxString& name) :
1062 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
1063
1064 bool Create(wxWindow *parent, wxWindowID id,
1065 const wxPoint& pos,
1066 const wxSize& size,
1067 long style,
1068 const wxValidator& validator,
1069 const wxString& name) {
1070 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
1071 }
1072
1073
1074 int OnCompareItems(const wxTreeItemId& item1,
1075 const wxTreeItemId& item2) {
1076 int rval = 0;
1077 bool found;
1078 wxPyBeginBlockThreads();
1079 if ((found = m_myInst.findCallback("OnCompareItems"))) {
1080 PyObject *o1 = wxPyConstructObject((void*)&item1, "wxTreeItemId");
1081 PyObject *o2 = wxPyConstructObject((void*)&item2, "wxTreeItemId");
1082 rval = m_myInst.callCallback(Py_BuildValue("(OO)",o1,o2));
1083 Py_DECREF(o1);
1084 Py_DECREF(o2);
1085 }
1086 wxPyEndBlockThreads();
1087 if (! found)
1088 rval = wxTreeCtrl::OnCompareItems(item1, item2);
1089 return rval;
1090 }
1091 PYPRIVATE;
1092 };
1093
1094 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
1095
1096 %}
1097
1098 // These are for the GetFirstChild/GetNextChild methods below
1099 %typemap(python, in) long& INOUT = long* INOUT;
1100 %typemap(python, argout) long& INOUT = long* INOUT;
1101
1102
1103 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
1104 public:
1105 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
1106 const wxPoint& pos = wxDefaultPosition,
1107 const wxSize& size = wxDefaultSize,
1108 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1109 const wxValidator& validator = wxDefaultValidator,
1110 const wxString& name = wxPy_TreeCtrlNameStr);
1111 %name(wxPreTreeCtrl)wxPyTreeCtrl();
1112
1113 bool Create(wxWindow *parent, wxWindowID id = -1,
1114 const wxPoint& pos = wxDefaultPosition,
1115 const wxSize& size = wxDefaultSize,
1116 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1117 const wxValidator& validator = wxDefaultValidator,
1118 const wxString& name = wxPy_TreeCtrlNameStr);
1119
1120 void _setCallbackInfo(PyObject* self, PyObject* _class);
1121 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeCtrl)"
1122
1123 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1124 %pragma(python) addtomethod = "wxPreTreeCtrl:val._setOORInfo(val)"
1125
1126 size_t GetCount();
1127 unsigned int GetIndent();
1128 void SetIndent(unsigned int indent);
1129 wxImageList *GetImageList();
1130 wxImageList *GetStateImageList();
1131 void SetImageList(wxImageList *imageList);
1132 void SetStateImageList(wxImageList *imageList);
1133 void AssignImageList(wxImageList* imageList);
1134 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
1135 void AssignStateImageList(wxImageList* imageList);
1136 %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0"
1137
1138 unsigned int GetSpacing();
1139 void SetSpacing(unsigned int spacing);
1140
1141 wxString GetItemText(const wxTreeItemId& item);
1142 int GetItemImage(const wxTreeItemId& item,
1143 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1144 int GetItemSelectedImage(const wxTreeItemId& item);
1145
1146 void SetItemText(const wxTreeItemId& item, const wxString& text);
1147 void SetItemImage(const wxTreeItemId& item, int image,
1148 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1149 void SetItemSelectedImage(const wxTreeItemId& item, int image);
1150 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
1151
1152 %addmethods {
1153 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
1154 // if needed.
1155 wxPyTreeItemData* GetItemData(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;
1163 }
1164
1165 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
1166 data->SetId(item); // set the id
1167 self->SetItemData(item, data);
1168 }
1169
1170 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1171 // automatically creating data classes.
1172 PyObject* GetPyData(const wxTreeItemId& item) {
1173 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1174 if (data == NULL) {
1175 data = new wxPyTreeItemData();
1176 data->SetId(item); // set the id
1177 self->SetItemData(item, data);
1178 }
1179 return data->GetData();
1180 }
1181
1182 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
1183 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1184 if (data == NULL) {
1185 data = new wxPyTreeItemData(obj);
1186 data->SetId(item); // set the id
1187 self->SetItemData(item, data);
1188 } else
1189 data->SetData(obj);
1190 }
1191 }
1192
1193
1194 bool IsVisible(const wxTreeItemId& item);
1195 bool ItemHasChildren(const wxTreeItemId& item);
1196 bool IsExpanded(const wxTreeItemId& item);
1197 bool IsSelected(const wxTreeItemId& item);
1198
1199 wxTreeItemId GetRootItem();
1200 wxTreeItemId GetSelection();
1201 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
1202 //size_t GetSelections(wxArrayTreeItemIds& selection);
1203 %addmethods {
1204 PyObject* GetSelections() {
1205 wxPyBeginBlockThreads();
1206 PyObject* rval = PyList_New(0);
1207 wxArrayTreeItemIds array;
1208 size_t num, x;
1209 num = self->GetSelections(array);
1210 for (x=0; x < num; x++) {
1211 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1212 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
1213 PyList_Append(rval, item);
1214 }
1215 wxPyEndBlockThreads();
1216 return rval;
1217 }
1218 }
1219
1220
1221
1222 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1223
1224 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT = longzero);
1225 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
1226 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
1227 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
1228 wxTreeItemId GetFirstVisibleItem();
1229 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
1230 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
1231 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1232
1233
1234
1235 wxTreeItemId AddRoot(const wxString& text,
1236 int image = -1, int selectedImage = -1,
1237 wxPyTreeItemData *data = NULL);
1238 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1239 const wxString& text,
1240 int image = -1, int selectedImage = -1,
1241 wxPyTreeItemData *data = NULL);
1242 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1243 const wxTreeItemId& idPrevious,
1244 const wxString& text,
1245 int image = -1, int selectedImage = -1,
1246 wxPyTreeItemData *data = NULL);
1247 %name(InsertItemBefore)
1248 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1249 size_t before,
1250 const wxString& text,
1251 int image = -1, int selectedImage = -1,
1252 wxPyTreeItemData *data = NULL);
1253 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1254 const wxString& text,
1255 int image = -1, int selectedImage = -1,
1256 wxPyTreeItemData *data = NULL);
1257
1258 void Delete(const wxTreeItemId& item);
1259 void DeleteChildren(const wxTreeItemId& item);
1260 void DeleteAllItems();
1261
1262 void Expand(const wxTreeItemId& item);
1263 void Collapse(const wxTreeItemId& item);
1264 void CollapseAndReset(const wxTreeItemId& item);
1265 void Toggle(const wxTreeItemId& item);
1266
1267 void Unselect();
1268 void UnselectAll();
1269 void SelectItem(const wxTreeItemId& item);
1270 void EnsureVisible(const wxTreeItemId& item);
1271 void ScrollTo(const wxTreeItemId& item);
1272 #ifdef __WXMSW__
1273 wxTextCtrl* EditLabel(const wxTreeItemId& item);
1274 wxTextCtrl* GetEditControl();
1275 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
1276 #else
1277 void EditLabel(const wxTreeItemId& item);
1278 #endif
1279
1280 void SortChildren(const wxTreeItemId& item);
1281
1282 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
1283 bool IsBold(const wxTreeItemId& item) const;
1284 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
1285
1286
1287
1288 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
1289 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
1290 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
1291
1292 #ifdef __WXMSW__
1293 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
1294 #endif
1295
1296 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
1297 %addmethods {
1298 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
1299 wxRect rect;
1300 if (self->GetBoundingRect(item, rect, textOnly)) {
1301 wxPyBeginBlockThreads();
1302 wxRect* r = new wxRect(rect);
1303 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
1304 wxPyEndBlockThreads();
1305 return val;
1306 }
1307 else {
1308 Py_INCREF(Py_None);
1309 return Py_None;
1310 }
1311 }
1312 }
1313
1314
1315 %pragma(python) addtoclass = "
1316 # Redefine some methods that SWIG gets a bit confused on...
1317 def GetFirstChild(self, *_args, **_kwargs):
1318 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
1319 val1 = wxTreeItemIdPtr(val1)
1320 val1.thisown = 1
1321 return (val1,val2)
1322 def GetNextChild(self, *_args, **_kwargs):
1323 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
1324 val1 = wxTreeItemIdPtr(val1)
1325 val1.thisown = 1
1326 return (val1,val2)
1327 def HitTest(self, *_args, **_kwargs):
1328 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
1329 val1 = wxTreeItemIdPtr(val1)
1330 val1.thisown = 1
1331 return (val1,val2)
1332 "
1333
1334 };
1335
1336
1337 //----------------------------------------------------------------------
1338
1339
1340 enum {
1341 wxDIRCTRL_DIR_ONLY,
1342 wxDIRCTRL_SELECT_FIRST,
1343 wxDIRCTRL_SHOW_FILTERS,
1344 wxDIRCTRL_3D_INTERNAL,
1345 wxDIRCTRL_EDIT_LABELS,
1346
1347 wxID_TREECTRL,
1348 wxID_FILTERLISTCTRL,
1349 };
1350
1351
1352 class wxDirItemData : public wxObject // wxTreeItemData
1353 {
1354 public:
1355 wxDirItemData(const wxString& path, const wxString& name, bool isDir);
1356 // ~wxDirItemDataEx();
1357 void SetNewDirName( wxString path );
1358 wxString m_path, m_name;
1359 bool m_isHidden;
1360 bool m_isExpanded;
1361 bool m_isDir;
1362 };
1363
1364
1365 class wxGenericDirCtrl: public wxControl
1366 {
1367 public:
1368 wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1,
1369 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1370 const wxPoint& pos = wxDefaultPosition,
1371 const wxSize& size = wxDefaultSize,
1372 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1373 const wxString& filter = wxPyEmptyString,
1374 int defaultFilter = 0,
1375 const wxString& name = wxPy_TreeCtrlNameStr);
1376 %name(wxPreGenericDirCtrl)wxGenericDirCtrl();
1377
1378 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1379 %pragma(python) addtomethod = "wxPreGenericDirCtrl:val._setOORInfo(val)"
1380
1381 bool Create(wxWindow *parent, const wxWindowID id = -1,
1382 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1383 const wxPoint& pos = wxDefaultPosition,
1384 const wxSize& size = wxDefaultSize,
1385 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1386 const wxString& filter = wxPyEmptyString,
1387 int defaultFilter = 0,
1388 const wxString& name = wxPy_TreeCtrlNameStr);
1389
1390
1391 // Try to expand as much of the given path as possible.
1392 bool ExpandPath(const wxString& path);
1393
1394 // Accessors
1395
1396 inline wxString GetDefaultPath() const;
1397 void SetDefaultPath(const wxString& path);
1398
1399 // Get dir or filename
1400 wxString GetPath() const ;
1401
1402 // Get selected filename path only (else empty string).
1403 // I.e. don't count a directory as a selection
1404 wxString GetFilePath() const ;
1405 void SetPath(const wxString& path) ;
1406
1407 void ShowHidden( bool show );
1408 bool GetShowHidden();
1409
1410 wxString GetFilter() const;
1411 void SetFilter(const wxString& filter);
1412
1413 int GetFilterIndex() const;
1414 void SetFilterIndex(int n) ;
1415
1416 wxTreeItemId GetRootId();
1417
1418 wxTreeCtrl* GetTreeCtrl() const;
1419 wxDirFilterListCtrl* GetFilterListCtrl() const;
1420
1421 // //// Helpers
1422 // void SetupSections();
1423 // // Parse the filter into an array of filters and an array of descriptions
1424 // int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
1425 // // Find the child that matches the first part of 'path'.
1426 // // E.g. if a child path is "/usr" and 'path' is "/usr/include"
1427 // // then the child for /usr is returned.
1428 // // If the path string has been used (we're at the leaf), done is set to TRUE
1429 // wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
1430 };
1431
1432
1433 class wxDirFilterListCtrl: public wxChoice
1434 {
1435 public:
1436 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1437 const wxPoint& pos = wxDefaultPosition,
1438 const wxSize& size = wxDefaultSize,
1439 long style = 0);
1440 %name(wxPreDirFilterListCtrl)wxDirFilterListCtrl();
1441
1442 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1443 %pragma(python) addtomethod = "wxPreDirFilterListCtrl:val._setOORInfo(val)"
1444
1445 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1446 const wxPoint& pos = wxDefaultPosition,
1447 const wxSize& size = wxDefaultSize,
1448 long style = 0);
1449
1450 //// Operations
1451 void FillFilterList(const wxString& filter, int defaultFilter);
1452 };
1453
1454
1455 //----------------------------------------------------------------------
1456 //----------------------------------------------------------------------
1457
1458 %init %{
1459 // Map renamed classes back to their common name for OOR
1460 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1461 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1462 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
1463 %}
1464
1465 //----------------------------------------------------------------------
1466
1467