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