]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/controls2.i
Probably only whitespace changes
[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 void SetItemTextColour( long item, const wxColour& col);
671 wxColour GetItemTextColour( long item ) const;
672 void SetItemBackgroundColour( long item, const wxColour &col);
673 wxColour GetItemBackgroundColour( long item ) const;
674
675
676 %pragma(python) addtoclass = "
677 # Some helpers...
678
679 def Select(self, idx, on=1):
680 '''[de]select an item'''
681 if on: state = wxLIST_STATE_SELECTED
682 else: state = 0
683 self.SetItemState(idx, state, wxLIST_STATE_SELECTED)
684
685 def Focus(self, idx):
686 '''Focus and show the given item'''
687 self.SetItemState(idx, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED)
688 self.EnsureVisible(idx)
689
690 def GetFocusedItem(self):
691 '''get the currently focused item or -1 if none'''
692 return self.GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED)
693
694 def IsSelected(self, idx):
695 '''return TRUE if the item is selected'''
696 return self.GetItemState(idx, wxLIST_STATE_SELECTED) != 0
697
698 def SetColumnImage(self, col, image):
699 item = wxListItem()
700 item.SetMask(wxLIST_MASK_IMAGE)
701 item.SetImage(image)
702 self.SetColumn(col, item)
703
704 def ClearColumnImage(self, col):
705 self.SetColumnImage(col, -1)
706
707 def Append(self, entry):
708 '''Append an item to the list control. The entry parameter should be a
709 sequence with an item for each column'''
710 if len(entry):
711 pos = self.GetItemCount()
712 self.InsertStringItem(pos, str(entry[0]))
713 for i in range(1, len(entry)):
714 self.SetStringItem(pos, i, str(entry[i]))
715 return pos
716 "
717
718
719 // bool SortItems(wxListCtrlCompare fn, long data);
720 %addmethods {
721 // Sort items.
722 // func is a function which takes 2 long arguments: item1, item2.
723 // item1 is the long data associated with a first item (NOT the index).
724 // item2 is the long data associated with a second item (NOT the index).
725 // The return value is a negative number if the first item should precede the second
726 // item, a positive number of the second item should precede the first,
727 // or zero if the two items are equivalent.
728 bool SortItems(PyObject* func) {
729 if (!PyCallable_Check(func))
730 return FALSE;
731 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
732 }
733 }
734 };
735
736
737
738 %{ // Python aware sorting function for wxPyListCtrl
739 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
740 int retval = 0;
741 PyObject* func = (PyObject*)funcPtr;
742 wxPyBeginBlockThreads();
743
744 PyObject* args = Py_BuildValue("(ii)", item1, item2);
745 PyObject* result = PyEval_CallObject(func, args);
746 Py_DECREF(args);
747 if (result) {
748 retval = PyInt_AsLong(result);
749 Py_DECREF(result);
750 }
751
752 wxPyEndBlockThreads();
753 return retval;
754 }
755
756 %}
757
758 //----------------------------------------------------------------------
759
760 class wxListView : public wxPyListCtrl
761 {
762 public:
763 wxListView( wxWindow *parent,
764 wxWindowID id = -1,
765 const wxPoint& pos = wxDefaultPosition,
766 const wxSize& size = wxDefaultSize,
767 long style = wxLC_REPORT,
768 const wxValidator& validator = wxDefaultValidator,
769 const wxString& name = wxPyListCtrlNameStr);
770 %name(wxPreListView)wxListView();
771
772 bool Create( wxWindow *parent,
773 wxWindowID id = -1,
774 const wxPoint& pos = wxDefaultPosition,
775 const wxSize& size = wxDefaultSize,
776 long style = wxLC_REPORT,
777 const wxValidator& validator = wxDefaultValidator,
778 const wxString& name = wxPyListCtrlNameStr);
779
780 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
781 %pragma(python) addtomethod = "wxPreListView:val._setOORInfo(val)"
782
783 // [de]select an item
784 void Select(long n, bool on = TRUE);
785
786 // focus and show the given item
787 void Focus(long index);
788
789 // get the currently focused item or -1 if none
790 long GetFocusedItem() const;
791
792 // get first and subsequent selected items, return -1 when no more
793 long GetNextSelected(long item) const;
794 long GetFirstSelected() const;
795
796 // return TRUE if the item is selected
797 bool IsSelected(long index);
798
799 void SetColumnImage(int col, int image);
800 void ClearColumnImage(int col);
801 };
802
803
804 //----------------------------------------------------------------------
805
806 // wxTreeCtrl flags
807 enum {
808 wxTR_NO_BUTTONS,
809 wxTR_HAS_BUTTONS,
810 wxTR_TWIST_BUTTONS,
811 wxTR_NO_LINES,
812 wxTR_MAC_BUTTONS,
813 wxTR_AQUA_BUTTONS,
814
815 wxTR_SINGLE,
816 wxTR_MULTIPLE,
817 wxTR_EXTENDED,
818 wxTR_FULL_ROW_HIGHLIGHT,
819
820 wxTR_EDIT_LABELS,
821 wxTR_LINES_AT_ROOT,
822 wxTR_HIDE_ROOT,
823 wxTR_ROW_LINES,
824 wxTR_HAS_VARIABLE_ROW_HEIGHT,
825
826 wxTR_DEFAULT_STYLE,
827 };
828
829 enum wxTreeItemIcon
830 {
831 wxTreeItemIcon_Normal, // not selected, not expanded
832 wxTreeItemIcon_Selected, // selected, not expanded
833 wxTreeItemIcon_Expanded, // not selected, expanded
834 wxTreeItemIcon_SelectedExpanded, // selected, expanded
835 wxTreeItemIcon_Max
836 };
837
838
839 // constants for HitTest
840 enum {
841 wxTREE_HITTEST_ABOVE,
842 wxTREE_HITTEST_BELOW,
843 wxTREE_HITTEST_NOWHERE,
844 wxTREE_HITTEST_ONITEMBUTTON,
845 wxTREE_HITTEST_ONITEMICON,
846 wxTREE_HITTEST_ONITEMINDENT,
847 wxTREE_HITTEST_ONITEMLABEL,
848 wxTREE_HITTEST_ONITEMRIGHT,
849 wxTREE_HITTEST_ONITEMSTATEICON,
850 wxTREE_HITTEST_TOLEFT,
851 wxTREE_HITTEST_TORIGHT,
852 wxTREE_HITTEST_ONITEMUPPERPART,
853 wxTREE_HITTEST_ONITEMLOWERPART,
854 wxTREE_HITTEST_ONITEM
855 };
856
857
858 enum {
859 /* Tree control event types */
860 wxEVT_COMMAND_TREE_BEGIN_DRAG,
861 wxEVT_COMMAND_TREE_BEGIN_RDRAG,
862 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT,
863 wxEVT_COMMAND_TREE_END_LABEL_EDIT,
864 wxEVT_COMMAND_TREE_DELETE_ITEM,
865 wxEVT_COMMAND_TREE_GET_INFO,
866 wxEVT_COMMAND_TREE_SET_INFO,
867 wxEVT_COMMAND_TREE_ITEM_EXPANDED,
868 wxEVT_COMMAND_TREE_ITEM_EXPANDING,
869 wxEVT_COMMAND_TREE_ITEM_COLLAPSED,
870 wxEVT_COMMAND_TREE_ITEM_COLLAPSING,
871 wxEVT_COMMAND_TREE_SEL_CHANGED,
872 wxEVT_COMMAND_TREE_SEL_CHANGING,
873 wxEVT_COMMAND_TREE_KEY_DOWN,
874 wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
875 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,
876 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK,
877 wxEVT_COMMAND_TREE_END_DRAG,
878 };
879
880
881 %pragma(python) code = "
882 # wxTreeCtrl events
883 def EVT_TREE_BEGIN_DRAG(win, id, func):
884 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func)
885
886 def EVT_TREE_BEGIN_RDRAG(win, id, func):
887 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func)
888
889 def EVT_TREE_END_DRAG(win, id, func):
890 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func)
891
892 def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func):
893 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func)
894
895 def EVT_TREE_END_LABEL_EDIT(win, id, func):
896 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func)
897
898 def EVT_TREE_GET_INFO(win, id, func):
899 win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func)
900
901 def EVT_TREE_SET_INFO(win, id, func):
902 win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func)
903
904 def EVT_TREE_ITEM_EXPANDED(win, id, func):
905 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func)
906
907 def EVT_TREE_ITEM_EXPANDING(win, id, func):
908 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func)
909
910 def EVT_TREE_ITEM_COLLAPSED(win, id, func):
911 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func)
912
913 def EVT_TREE_ITEM_COLLAPSING(win, id, func):
914 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func)
915
916 def EVT_TREE_SEL_CHANGED(win, id, func):
917 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func)
918
919 def EVT_TREE_SEL_CHANGING(win, id, func):
920 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func)
921
922 def EVT_TREE_KEY_DOWN(win, id, func):
923 win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func)
924
925 def EVT_TREE_DELETE_ITEM(win, id, func):
926 win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
927
928 def EVT_TREE_ITEM_ACTIVATED(win, id, func):
929 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
930
931 def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
932 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
933
934 def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
935 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
936 "
937
938
939 class wxTreeItemAttr
940 {
941 public:
942 // ctors
943 //wxTreeItemAttr() { }
944 wxTreeItemAttr(const wxColour& colText = wxNullColour,
945 const wxColour& colBack = wxNullColour,
946 const wxFont& font = wxNullFont);
947
948 // setters
949 void SetTextColour(const wxColour& colText);
950 void SetBackgroundColour(const wxColour& colBack);
951 void SetFont(const wxFont& font);
952
953 // accessors
954 bool HasTextColour();
955 bool HasBackgroundColour();
956 bool HasFont();
957
958 wxColour GetTextColour();
959 wxColour GetBackgroundColour();
960 wxFont GetFont();
961 };
962
963
964 class wxTreeItemId {
965 public:
966 wxTreeItemId();
967 ~wxTreeItemId();
968 bool IsOk();
969 %pragma(python) addtoclass = "Ok = IsOk"
970
971 %addmethods {
972 int __cmp__(wxTreeItemId* other) {
973 if (! other) return -1;
974 return *self != *other;
975 }
976 }
977 };
978
979
980
981 %{
982 class wxPyTreeItemData : public wxTreeItemData {
983 public:
984 wxPyTreeItemData(PyObject* obj = NULL) {
985 if (obj == NULL)
986 obj = Py_None;
987 Py_INCREF(obj);
988 m_obj = obj;
989 }
990
991 ~wxPyTreeItemData() {
992 wxPyBeginBlockThreads();
993 Py_DECREF(m_obj);
994 wxPyEndBlockThreads();
995 }
996
997 PyObject* GetData() {
998 Py_INCREF(m_obj);
999 return m_obj;
1000 }
1001
1002 void SetData(PyObject* obj) {
1003 wxPyBeginBlockThreads();
1004 Py_DECREF(m_obj);
1005 wxPyEndBlockThreads();
1006 m_obj = obj;
1007 Py_INCREF(obj);
1008 }
1009
1010 PyObject* m_obj;
1011 };
1012 %}
1013
1014
1015
1016 %name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
1017 public:
1018 wxPyTreeItemData(PyObject* obj = NULL);
1019
1020 PyObject* GetData();
1021 void SetData(PyObject* obj);
1022
1023 const wxTreeItemId& GetId();
1024 void SetId(const wxTreeItemId& id);
1025 };
1026
1027
1028
1029 class wxTreeEvent : public wxNotifyEvent {
1030 public:
1031 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
1032
1033 wxTreeItemId GetItem();
1034 wxTreeItemId GetOldItem();
1035 wxPoint GetPoint();
1036 const wxKeyEvent& GetKeyEvent();
1037 int GetCode();
1038 const wxString& GetLabel();
1039 };
1040
1041
1042
1043 %{ // C++ version of Python aware wxTreeCtrl
1044 class wxPyTreeCtrl : public wxTreeCtrl {
1045 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
1046 public:
1047 wxPyTreeCtrl() : wxTreeCtrl() {}
1048 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
1049 const wxPoint& pos,
1050 const wxSize& size,
1051 long style,
1052 const wxValidator& validator,
1053 const wxString& name) :
1054 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
1055
1056 bool Create(wxWindow *parent, wxWindowID id,
1057 const wxPoint& pos,
1058 const wxSize& size,
1059 long style,
1060 const wxValidator& validator,
1061 const wxString& name) {
1062 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
1063 }
1064
1065
1066 int OnCompareItems(const wxTreeItemId& item1,
1067 const wxTreeItemId& item2) {
1068 int rval = 0;
1069 bool found;
1070 wxPyBeginBlockThreads();
1071 if ((found = m_myInst.findCallback("OnCompareItems")))
1072 rval = m_myInst.callCallback(Py_BuildValue(
1073 "(OO)",
1074 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
1075 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
1076 wxPyEndBlockThreads();
1077 if (! found)
1078 rval = wxTreeCtrl::OnCompareItems(item1, item2);
1079 return rval;
1080 }
1081 PYPRIVATE;
1082 };
1083
1084 IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
1085
1086 %}
1087
1088 // These are for the GetFirstChild/GetNextChild methods below
1089 %typemap(python, in) long& INOUT = long* INOUT;
1090 %typemap(python, argout) long& INOUT = long* INOUT;
1091
1092
1093 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
1094 public:
1095 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
1096 const wxPoint& pos = wxDefaultPosition,
1097 const wxSize& size = wxDefaultSize,
1098 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1099 const wxValidator& validator = wxDefaultValidator,
1100 const wxString& name = wxPy_TreeCtrlNameStr);
1101 %name(wxPreTreeCtrl)wxPyTreeCtrl();
1102
1103 bool Create(wxWindow *parent, wxWindowID id = -1,
1104 const wxPoint& pos = wxDefaultPosition,
1105 const wxSize& size = wxDefaultSize,
1106 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
1107 const wxValidator& validator = wxDefaultValidator,
1108 const wxString& name = wxPy_TreeCtrlNameStr);
1109
1110 void _setCallbackInfo(PyObject* self, PyObject* _class);
1111 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeCtrl)"
1112
1113 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1114 %pragma(python) addtomethod = "wxPreTreeCtrl:val._setOORInfo(val)"
1115
1116 size_t GetCount();
1117 unsigned int GetIndent();
1118 void SetIndent(unsigned int indent);
1119 wxImageList *GetImageList();
1120 wxImageList *GetStateImageList();
1121 void SetImageList(wxImageList *imageList);
1122 void SetStateImageList(wxImageList *imageList);
1123 void AssignImageList(wxImageList* imageList);
1124 %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0"
1125 void AssignStateImageList(wxImageList* imageList);
1126 %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0"
1127
1128 unsigned int GetSpacing();
1129 void SetSpacing(unsigned int spacing);
1130
1131 wxString GetItemText(const wxTreeItemId& item);
1132 int GetItemImage(const wxTreeItemId& item,
1133 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1134 int GetItemSelectedImage(const wxTreeItemId& item);
1135
1136 void SetItemText(const wxTreeItemId& item, const wxString& text);
1137 void SetItemImage(const wxTreeItemId& item, int image,
1138 wxTreeItemIcon which = wxTreeItemIcon_Normal);
1139 void SetItemSelectedImage(const wxTreeItemId& item, int image);
1140 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
1141
1142 %addmethods {
1143 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
1144 // if needed.
1145 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
1146 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1147 if (data == NULL) {
1148 data = new wxPyTreeItemData();
1149 data->SetId(item); // set the id
1150 self->SetItemData(item, data);
1151 }
1152 return data;
1153 }
1154
1155 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
1156 data->SetId(item); // set the id
1157 self->SetItemData(item, data);
1158 }
1159
1160 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1161 // automatically creating data classes.
1162 PyObject* GetPyData(const wxTreeItemId& item) {
1163 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1164 if (data == NULL) {
1165 data = new wxPyTreeItemData();
1166 data->SetId(item); // set the id
1167 self->SetItemData(item, data);
1168 }
1169 return data->GetData();
1170 }
1171
1172 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
1173 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1174 if (data == NULL) {
1175 data = new wxPyTreeItemData(obj);
1176 data->SetId(item); // set the id
1177 self->SetItemData(item, data);
1178 } else
1179 data->SetData(obj);
1180 }
1181 }
1182
1183
1184 bool IsVisible(const wxTreeItemId& item);
1185 bool ItemHasChildren(const wxTreeItemId& item);
1186 bool IsExpanded(const wxTreeItemId& item);
1187 bool IsSelected(const wxTreeItemId& item);
1188
1189 wxTreeItemId GetRootItem();
1190 wxTreeItemId GetSelection();
1191 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
1192 //size_t GetSelections(wxArrayTreeItemIds& selection);
1193 %addmethods {
1194 PyObject* GetSelections() {
1195 wxPyBeginBlockThreads();
1196 PyObject* rval = PyList_New(0);
1197 wxArrayTreeItemIds array;
1198 size_t num, x;
1199 num = self->GetSelections(array);
1200 for (x=0; x < num; x++) {
1201 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1202 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
1203 PyList_Append(rval, item);
1204 }
1205 wxPyEndBlockThreads();
1206 return rval;
1207 }
1208 }
1209
1210
1211
1212 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1213
1214 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
1215 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
1216 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
1217 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
1218 wxTreeItemId GetFirstVisibleItem();
1219 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
1220 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
1221 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1222
1223
1224
1225 wxTreeItemId AddRoot(const wxString& text,
1226 int image = -1, int selectedImage = -1,
1227 wxPyTreeItemData *data = NULL);
1228 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1229 const wxString& text,
1230 int image = -1, int selectedImage = -1,
1231 wxPyTreeItemData *data = NULL);
1232 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1233 const wxTreeItemId& idPrevious,
1234 const wxString& text,
1235 int image = -1, int selectedImage = -1,
1236 wxPyTreeItemData *data = NULL);
1237 %name(InsertItemBefore)
1238 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1239 size_t before,
1240 const wxString& text,
1241 int image = -1, int selectedImage = -1,
1242 wxPyTreeItemData *data = NULL);
1243 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1244 const wxString& text,
1245 int image = -1, int selectedImage = -1,
1246 wxPyTreeItemData *data = NULL);
1247
1248 void Delete(const wxTreeItemId& item);
1249 void DeleteChildren(const wxTreeItemId& item);
1250 void DeleteAllItems();
1251
1252 void Expand(const wxTreeItemId& item);
1253 void Collapse(const wxTreeItemId& item);
1254 void CollapseAndReset(const wxTreeItemId& item);
1255 void Toggle(const wxTreeItemId& item);
1256
1257 void Unselect();
1258 void UnselectAll();
1259 void SelectItem(const wxTreeItemId& item);
1260 void EnsureVisible(const wxTreeItemId& item);
1261 void ScrollTo(const wxTreeItemId& item);
1262 #ifdef __WXMSW__
1263 wxTextCtrl* EditLabel(const wxTreeItemId& item);
1264 wxTextCtrl* GetEditControl();
1265 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
1266 #else
1267 void EditLabel(const wxTreeItemId& item);
1268 #endif
1269
1270 void SortChildren(const wxTreeItemId& item);
1271
1272 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
1273 bool IsBold(const wxTreeItemId& item) const;
1274 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
1275
1276
1277
1278 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
1279 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
1280 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
1281
1282 #ifdef __WXMSW__
1283 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
1284 #endif
1285
1286 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
1287 %addmethods {
1288 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
1289 wxRect rect;
1290 if (self->GetBoundingRect(item, rect, textOnly)) {
1291 wxPyBeginBlockThreads();
1292 wxRect* r = new wxRect(rect);
1293 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
1294 wxPyEndBlockThreads();
1295 return val;
1296 }
1297 else {
1298 Py_INCREF(Py_None);
1299 return Py_None;
1300 }
1301 }
1302 }
1303
1304
1305 %pragma(python) addtoclass = "
1306 # Redefine some methods that SWIG gets a bit confused on...
1307 def GetFirstChild(self, *_args, **_kwargs):
1308 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
1309 val1 = wxTreeItemIdPtr(val1)
1310 val1.thisown = 1
1311 return (val1,val2)
1312 def GetNextChild(self, *_args, **_kwargs):
1313 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
1314 val1 = wxTreeItemIdPtr(val1)
1315 val1.thisown = 1
1316 return (val1,val2)
1317 def HitTest(self, *_args, **_kwargs):
1318 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
1319 val1 = wxTreeItemIdPtr(val1)
1320 val1.thisown = 1
1321 return (val1,val2)
1322 "
1323
1324 };
1325
1326
1327 //----------------------------------------------------------------------
1328
1329
1330 enum {
1331 wxDIRCTRL_DIR_ONLY,
1332 wxDIRCTRL_SELECT_FIRST,
1333 wxDIRCTRL_SHOW_FILTERS,
1334 wxDIRCTRL_3D_INTERNAL,
1335 wxDIRCTRL_EDIT_LABELS,
1336
1337 wxID_TREECTRL,
1338 wxID_FILTERLISTCTRL,
1339 };
1340
1341
1342 class wxDirItemData : public wxObject // wxTreeItemData
1343 {
1344 public:
1345 wxDirItemData(const wxString& path, const wxString& name, bool isDir);
1346 // ~wxDirItemDataEx();
1347 void SetNewDirName( wxString path );
1348 wxString m_path, m_name;
1349 bool m_isHidden;
1350 bool m_isExpanded;
1351 bool m_isDir;
1352 };
1353
1354
1355 class wxGenericDirCtrl: public wxControl
1356 {
1357 public:
1358 wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1,
1359 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1360 const wxPoint& pos = wxDefaultPosition,
1361 const wxSize& size = wxDefaultSize,
1362 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1363 const wxString& filter = wxPyEmptyString,
1364 int defaultFilter = 0,
1365 const wxString& name = wxPy_TreeCtrlNameStr);
1366 %name(wxPreGenericDirCtrl)wxGenericDirCtrl();
1367
1368 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1369 %pragma(python) addtomethod = "wxPreGenericDirCtrl:val._setOORInfo(val)"
1370
1371 bool Create(wxWindow *parent, const wxWindowID id = -1,
1372 const wxString& dir = wxPyDirDialogDefaultFolderStr,
1373 const wxPoint& pos = wxDefaultPosition,
1374 const wxSize& size = wxDefaultSize,
1375 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
1376 const wxString& filter = wxPyEmptyString,
1377 int defaultFilter = 0,
1378 const wxString& name = wxPy_TreeCtrlNameStr);
1379
1380
1381 // Try to expand as much of the given path as possible.
1382 bool ExpandPath(const wxString& path);
1383
1384 // Accessors
1385
1386 inline wxString GetDefaultPath() const;
1387 void SetDefaultPath(const wxString& path);
1388
1389 // Get dir or filename
1390 wxString GetPath() const ;
1391
1392 // Get selected filename path only (else empty string).
1393 // I.e. don't count a directory as a selection
1394 wxString GetFilePath() const ;
1395 void SetPath(const wxString& path) ;
1396
1397 void ShowHidden( bool show );
1398 bool GetShowHidden();
1399
1400 wxString GetFilter() const;
1401 void SetFilter(const wxString& filter);
1402
1403 int GetFilterIndex() const;
1404 void SetFilterIndex(int n) ;
1405
1406 wxTreeItemId GetRootId();
1407
1408 wxTreeCtrl* GetTreeCtrl() const;
1409 wxDirFilterListCtrl* GetFilterListCtrl() const;
1410
1411 // //// Helpers
1412 // void SetupSections();
1413 // // Parse the filter into an array of filters and an array of descriptions
1414 // int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions);
1415 // // Find the child that matches the first part of 'path'.
1416 // // E.g. if a child path is "/usr" and 'path' is "/usr/include"
1417 // // then the child for /usr is returned.
1418 // // If the path string has been used (we're at the leaf), done is set to TRUE
1419 // wxTreeItemId FindChild(wxTreeItemId parentId, const wxString& path, bool& done);
1420 };
1421
1422
1423 class wxDirFilterListCtrl: public wxChoice
1424 {
1425 public:
1426 wxDirFilterListCtrl(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1427 const wxPoint& pos = wxDefaultPosition,
1428 const wxSize& size = wxDefaultSize,
1429 long style = 0);
1430 %name(wxPreDirFilterListCtrl)wxDirFilterListCtrl();
1431
1432 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
1433 %pragma(python) addtomethod = "wxPreDirFilterListCtrl:val._setOORInfo(val)"
1434
1435 bool Create(wxGenericDirCtrl* parent, const wxWindowID id = -1,
1436 const wxPoint& pos = wxDefaultPosition,
1437 const wxSize& size = wxDefaultSize,
1438 long style = 0);
1439
1440 //// Operations
1441 void FillFilterList(const wxString& filter, int defaultFilter);
1442 };
1443
1444
1445 //----------------------------------------------------------------------
1446 //----------------------------------------------------------------------
1447
1448 %init %{
1449 // Map renamed classes back to their common name for OOR
1450 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1451 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
1452 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
1453 %}
1454
1455 //----------------------------------------------------------------------
1456
1457