]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/controls2.i
Corrected typo in wxStringHashTable::Delete
[wxWidgets.git] / wxPython / src / controls2.i
CommitLineData
7bf85405
RD
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
03e9bead 13%module controls2
7bf85405 14
03e9bead 15%{
7bf85405 16#include "helpers.h"
2f90df85
RD
17#ifdef __WXMSW__
18#include <windows.h>
19#endif
7bf85405
RD
20#include <wx/listctrl.h>
21#include <wx/treectrl.h>
9416aa89 22#include <wx/imaglist.h>
68320e40 23#include <wx/dirctrl.h>
7bf85405
RD
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
b8b8dda7 39%pragma(python) code = "import wx"
9c039d08 40
c7e7022c
RD
41
42//----------------------------------------------------------------------
137b5242
RD
43%{
44 // Put some wx default wxChar* values into wxStrings.
45 const wxChar* wxListCtrlNameStr = _T("wxListCtrl");
46 DECLARE_DEF_STRING(ListCtrlNameStr);
47
9a74fcaf 48 const wxChar* wx_TreeCtrlNameStr = _T("wxTreeCtrl");
137b5242
RD
49 DECLARE_DEF_STRING(_TreeCtrlNameStr);
50 DECLARE_DEF_STRING(DirDialogDefaultFolderStr);
51
52 static const wxString wxPyEmptyString(wxT(""));
53%}
54
7bf85405
RD
55//----------------------------------------------------------------------
56
c7e7022c
RD
57enum {
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,
6d19860f
RD
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,
d8200036 80 wxEVT_COMMAND_LIST_ITEM_FOCUSED,
c7e7022c
RD
81};
82
83
84%pragma(python) code = "
85def EVT_LIST_BEGIN_DRAG(win, id, func):
86 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_DRAG, func)
87
88def EVT_LIST_BEGIN_RDRAG(win, id, func):
89 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_RDRAG, func)
90
91def EVT_LIST_BEGIN_LABEL_EDIT(win, id, func):
92 win.Connect(id, -1, wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, func)
93
94def EVT_LIST_END_LABEL_EDIT(win, id, func):
95 win.Connect(id, -1, wxEVT_COMMAND_LIST_END_LABEL_EDIT, func)
96
97def EVT_LIST_DELETE_ITEM(win, id, func):
98 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ITEM, func)
99
100def EVT_LIST_DELETE_ALL_ITEMS(win, id, func):
101 win.Connect(id, -1, wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, func)
102
103def EVT_LIST_GET_INFO(win, id, func):
104 win.Connect(id, -1, wxEVT_COMMAND_LIST_GET_INFO, func)
105
106def EVT_LIST_SET_INFO(win, id, func):
107 win.Connect(id, -1, wxEVT_COMMAND_LIST_SET_INFO, func)
108
109def EVT_LIST_ITEM_SELECTED(win, id, func):
110 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_SELECTED, func)
111
112def EVT_LIST_ITEM_DESELECTED(win, id, func):
113 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_DESELECTED, func)
114
115def EVT_LIST_KEY_DOWN(win, id, func):
116 win.Connect(id, -1, wxEVT_COMMAND_LIST_KEY_DOWN, func)
117
118def EVT_LIST_INSERT_ITEM(win, id, func):
119 win.Connect(id, -1, wxEVT_COMMAND_LIST_INSERT_ITEM, func)
120
121def EVT_LIST_COL_CLICK(win, id, func):
122 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_CLICK, func)
123
6d19860f
RD
124def EVT_LIST_COL_RIGHT_CLICK(win, id, func):
125 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, func)
126
127def EVT_LIST_COL_BEGIN_DRAG(win, id, func):
128 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, func)
129
130def EVT_LIST_COL_DRAGGING(win, id, func):
131 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_DRAGGING, func)
132
133def EVT_LIST_COL_END_DRAG(win, id, func):
134 win.Connect(id, -1, wxEVT_COMMAND_LIST_COL_END_DRAG, func)
135
c7e7022c
RD
136def EVT_LIST_ITEM_RIGHT_CLICK(win, id, func):
137 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, func)
138
139def EVT_LIST_ITEM_MIDDLE_CLICK(win, id, func):
140 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, func)
141
142def EVT_LIST_ITEM_ACTIVATED(win, id, func):
143 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_ACTIVATED, func)
144
145def EVT_LIST_CACHE_HINT(win, id, func):
146 win.Connect(id, -1, wxEVT_COMMAND_LIST_CACHE_HINT, func)
d8200036
RD
147
148def EVT_LIST_ITEM_FOCUSED(win, id, func):
149 win.Connect(id, -1, wxEVT_COMMAND_LIST_ITEM_FOCUSED, func)
c7e7022c
RD
150"
151
7bf85405 152
af309447 153enum {
c7e7022c
RD
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
6d19860f 178 wxLC_USER_TEXT,
c7e7022c
RD
179};
180
181
182enum {
183 // Mask flags
184 wxLIST_MASK_STATE,
af309447
RD
185 wxLIST_MASK_TEXT,
186 wxLIST_MASK_IMAGE,
187 wxLIST_MASK_DATA,
c7e7022c 188 wxLIST_SET_ITEM,
af309447
RD
189 wxLIST_MASK_WIDTH,
190 wxLIST_MASK_FORMAT,
c7e7022c
RD
191
192 // State flags
af309447
RD
193 wxLIST_STATE_DONTCARE,
194 wxLIST_STATE_DROPHILITED,
195 wxLIST_STATE_FOCUSED,
196 wxLIST_STATE_SELECTED,
197 wxLIST_STATE_CUT,
c7e7022c
RD
198
199 // Hit test flags
af309447
RD
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,
c7e7022c
RD
210
211 // Flags for GetNextItem
af309447
RD
212 wxLIST_NEXT_ABOVE,
213 wxLIST_NEXT_ALL,
214 wxLIST_NEXT_BELOW,
215 wxLIST_NEXT_LEFT,
216 wxLIST_NEXT_RIGHT,
c7e7022c
RD
217
218 // Alignment flags
af309447
RD
219 wxLIST_ALIGN_DEFAULT,
220 wxLIST_ALIGN_LEFT,
221 wxLIST_ALIGN_TOP,
222 wxLIST_ALIGN_SNAP_TO_GRID,
c7e7022c
RD
223
224 // Autosize values for SetColumnWidth
225 wxLIST_AUTOSIZE = -1,
226 wxLIST_AUTOSIZE_USEHEADER = -2,
227
228 // Flag values for GetItemRect
af309447
RD
229 wxLIST_RECT_BOUNDS,
230 wxLIST_RECT_ICON,
231 wxLIST_RECT_LABEL,
c7e7022c
RD
232
233 // Flag values for FindItem (MSW only)
af309447
RD
234 wxLIST_FIND_UP,
235 wxLIST_FIND_DOWN,
236 wxLIST_FIND_LEFT,
237 wxLIST_FIND_RIGHT,
c7e7022c
RD
238
239
af309447
RD
240};
241
242
c7e7022c 243
f6bcfd97
BP
244enum wxListColumnFormat
245{
246 wxLIST_FORMAT_LEFT,
247 wxLIST_FORMAT_RIGHT,
248 wxLIST_FORMAT_CENTRE,
249 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
250};
251
252
1b62f00d
RD
253
254
f6bcfd97
BP
255class wxListItemAttr
256{
257public:
258 // ctors
c7e7022c
RD
259 //wxListItemAttr();
260 wxListItemAttr(const wxColour& colText = wxNullColour,
261 const wxColour& colBack = wxNullColour,
262 const wxFont& font = wxNullFont);
263
f6bcfd97
BP
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
c5943253
RD
275 wxColour GetTextColour();
276 wxColour GetBackgroundColour();
277 wxFont GetFont();
f6bcfd97
BP
278};
279
280
9416aa89 281class wxListItem : public wxObject {
7bf85405 282public:
f6bcfd97
BP
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
7bf85405
RD
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
f6bcfd97 331 long m_stateMask;// Which flags of m_state are valid (uses same flags)
7bf85405
RD
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
7bf85405
RD
335
336 // For columns only
337 int m_format; // left, right, centre
338 int m_width; // width of column
339
7bf85405
RD
340};
341
f6bcfd97 342
c368d904 343class wxListEvent: public wxNotifyEvent {
7bf85405 344public:
6d19860f
RD
345 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
346
b7fc54be 347%readonly
7bf85405 348 int m_code;
ebf4302c 349 long m_oldItemIndex;
7bf85405 350 long m_itemIndex;
7bf85405 351 int m_col;
7bf85405
RD
352 wxPoint m_pointDrag;
353 wxListItem m_item;
b7fc54be 354%readwrite
7bf85405 355
f6bcfd97
BP
356 int GetCode();
357 long GetIndex();
f6bcfd97 358 int GetColumn();
f6bcfd97
BP
359 wxPoint GetPoint();
360 const wxString& GetLabel();
361 const wxString& GetText();
362 int GetImage();
363 long GetData();
364 long GetMask();
365 const wxListItem& GetItem();
6d19860f
RD
366
367 long GetCacheFrom();
368 long GetCacheTo();
f6bcfd97 369};
7bf85405
RD
370
371
09f3d4e6 372%{ // C++ Version of a Python aware class
c7e7022c
RD
373class wxPyListCtrl : public wxListCtrl {
374 DECLARE_ABSTRACT_CLASS(wxPyListCtrl);
7bf85405 375public:
09f3d4e6 376 wxPyListCtrl() : wxListCtrl() {}
c7e7022c
RD
377 wxPyListCtrl(wxWindow* parent, wxWindowID id,
378 const wxPoint& pos,
379 const wxSize& size,
380 long style,
381 const wxValidator& validator,
137b5242 382 const wxString& name) :
c7e7022c
RD
383 wxListCtrl(parent, id, pos, size, style, validator, name) {}
384
09f3d4e6
RD
385 bool Create(wxWindow* parent, wxWindowID id,
386 const wxPoint& pos,
387 const wxSize& size,
388 long style,
389 const wxValidator& validator,
137b5242 390 const wxString& name) {
09f3d4e6
RD
391 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
392 }
393
c7e7022c
RD
394 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
395 DEC_PYCALLBACK_INT_LONG(OnGetItemImage);
396 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
397
398 PYPRIVATE;
399};
400
401IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
7bf85405 402
c7e7022c
RD
403IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
404IMP_PYCALLBACK_INT_LONG(wxPyListCtrl, wxListCtrl, OnGetItemImage);
405IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
406%}
407
408
cdf14688 409
c7e7022c
RD
410%name(wxListCtrl)class wxPyListCtrl : public wxControl {
411public:
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,
137b5242 417 const wxString& name = wxPyListCtrlNameStr);
09f3d4e6
RD
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,
137b5242 425 const wxString& name = wxPyListCtrlNameStr);
c7e7022c 426
0122b7e3
RD
427 void _setCallbackInfo(PyObject* self, PyObject* _class);
428 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxListCtrl)"
9c039d08 429
0122b7e3 430 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
17c0e08c 431 %pragma(python) addtomethod = "wxPreListCtrl:val._setOORInfo(val)"
7bf85405 432
c7e7022c
RD
433 // Set the control colours
434 bool SetForegroundColour(const wxColour& col);
435 bool SetBackgroundColour(const wxColour& col);
436
437 // Gets information about this column
14afa2cb
RD
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 "
c7e7022c
RD
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
cd096152 470#ifdef __WXMSW__
c7e7022c
RD
471 // Gets the edit control for editing labels.
472 wxTextCtrl* GetEditControl() const;
cd096152 473#endif
c7e7022c
RD
474
475 //bool GetItem(wxListItem& info) const ;
7bf85405 476 %addmethods {
c7e7022c 477 // Gets information about the item
e166644c 478 %new wxListItem* GetItem(long itemId, int col=0) {
7bf85405 479 wxListItem* info = new wxListItem;
0699c864 480 info->m_itemId = itemId;
e166644c 481 info->m_col = col;
f17fee68 482 info->m_mask = 0xFFFF;
7bf85405
RD
483 self->GetItem(*info);
484 return info;
485 }
5597b61e
RD
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
c7e7022c
RD
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 ;
00b6c4e3
RD
525
526 // Gets the item position
5597b61e 527 %addmethods {
7bf85405
RD
528 %new wxPoint* GetItemPosition(long item) {
529 wxPoint* pos = new wxPoint;
530 self->GetItemPosition(item, *pos);
531 return pos;
532 }
c7e7022c 533 // Gets the item rectangle
7bf85405
RD
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
c7e7022c
RD
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
9d37f964 549 int GetColumnCount() const;
c7e7022c
RD
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
4f22cf8d 563 void SetTextColour(const wxColour& col);
c7e7022c
RD
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
c7e7022c
RD
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
cd096152 614#ifdef __WXMSW__
c7e7022c
RD
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);
cd096152 620#endif
c7e7022c
RD
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)
7bf85405 639 long HitTest(const wxPoint& point, int& OUTPUT);
c7e7022c
RD
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.
c368d904 655 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
c7e7022c
RD
656
657 long InsertColumn(long col,
658 const wxString& heading,
7bf85405
RD
659 int format = wxLIST_FORMAT_LEFT,
660 int width = -1);
661
c7e7022c
RD
662 // set the number of items in a virtual list control
663 void SetItemCount(long count);
7bf85405 664
c7e7022c
RD
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.
7bf85405 670 bool ScrollList(int dx, int dy);
dcd38683 671
3bd1e033
RD
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
c7e7022c 677
6d19860f
RD
678 %pragma(python) addtoclass = "
679 # Some helpers...
680
43097598 681 def Select(self, idx, on=1):
6d19860f
RD
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)
44536514
RD
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
6d19860f 718 "
3bd1e033
RD
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 }
7bf85405
RD
736};
737
c7e7022c
RD
738
739
6d19860f 740%{ // Python aware sorting function for wxPyListCtrl
f6bcfd97 741 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
dcd38683
RD
742 int retval = 0;
743 PyObject* func = (PyObject*)funcPtr;
4268f798 744 wxPyBeginBlockThreads();
7bf85405 745
dcd38683
RD
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
4268f798 754 wxPyEndBlockThreads();
dcd38683
RD
755 return retval;
756 }
757
758%}
7bf85405 759
6d19860f
RD
760//----------------------------------------------------------------------
761
762class wxListView : public wxPyListCtrl
763{
764public:
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,
137b5242 771 const wxString& name = wxPyListCtrlNameStr);
6d19860f
RD
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,
137b5242 780 const wxString& name = wxPyListCtrlNameStr);
6d19860f 781
0122b7e3 782 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
17c0e08c 783 %pragma(python) addtomethod = "wxPreListView:val._setOORInfo(val)"
6d19860f
RD
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
7bf85405
RD
806//----------------------------------------------------------------------
807
00b6c4e3
RD
808// wxTreeCtrl flags
809enum {
810 wxTR_NO_BUTTONS,
811 wxTR_HAS_BUTTONS,
812 wxTR_TWIST_BUTTONS,
813 wxTR_NO_LINES,
814 wxTR_MAC_BUTTONS,
b5a5d647 815 wxTR_AQUA_BUTTONS,
00b6c4e3
RD
816
817 wxTR_SINGLE,
818 wxTR_MULTIPLE,
819 wxTR_EXTENDED,
b5a5d647 820 wxTR_FULL_ROW_HIGHLIGHT,
00b6c4e3
RD
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
694759cf
RD
831enum 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
7bf85405 840
164b735b
RD
841// constants for HitTest
842enum {
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
1b62f00d
RD
860enum {
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,
d1679124 879 wxEVT_COMMAND_TREE_END_DRAG,
1b62f00d
RD
880};
881
882
00b6c4e3
RD
883%pragma(python) code = "
884# wxTreeCtrl events
885def EVT_TREE_BEGIN_DRAG(win, id, func):
886 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_DRAG, func)
887
888def EVT_TREE_BEGIN_RDRAG(win, id, func):
889 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_RDRAG, func)
890
891def EVT_TREE_END_DRAG(win, id, func):
892 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_DRAG, func)
893
894def EVT_TREE_BEGIN_LABEL_EDIT(win, id, func):
895 win.Connect(id, -1, wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, func)
896
897def EVT_TREE_END_LABEL_EDIT(win, id, func):
898 win.Connect(id, -1, wxEVT_COMMAND_TREE_END_LABEL_EDIT, func)
899
900def EVT_TREE_GET_INFO(win, id, func):
901 win.Connect(id, -1, wxEVT_COMMAND_TREE_GET_INFO, func)
902
903def EVT_TREE_SET_INFO(win, id, func):
904 win.Connect(id, -1, wxEVT_COMMAND_TREE_SET_INFO, func)
905
906def EVT_TREE_ITEM_EXPANDED(win, id, func):
907 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDED, func)
908
909def EVT_TREE_ITEM_EXPANDING(win, id, func):
910 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_EXPANDING, func)
911
912def EVT_TREE_ITEM_COLLAPSED(win, id, func):
913 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSED, func)
914
915def EVT_TREE_ITEM_COLLAPSING(win, id, func):
916 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_COLLAPSING, func)
917
918def EVT_TREE_SEL_CHANGED(win, id, func):
919 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGED, func)
920
921def EVT_TREE_SEL_CHANGING(win, id, func):
922 win.Connect(id, -1, wxEVT_COMMAND_TREE_SEL_CHANGING, func)
923
924def EVT_TREE_KEY_DOWN(win, id, func):
925 win.Connect(id, -1, wxEVT_COMMAND_TREE_KEY_DOWN, func)
926
927def EVT_TREE_DELETE_ITEM(win, id, func):
928 win.Connect(id, -1, wxEVT_COMMAND_TREE_DELETE_ITEM, func)
929
930def EVT_TREE_ITEM_ACTIVATED(win, id, func):
931 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_ACTIVATED, func)
932
933def EVT_TREE_ITEM_RIGHT_CLICK(win, id, func):
934 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, func)
935
936def EVT_TREE_ITEM_MIDDLE_CLICK(win, id, func):
937 win.Connect(id, -1, wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK, func)
938"
939
940
941class wxTreeItemAttr
942{
943public:
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
c5943253
RD
960 wxColour GetTextColour();
961 wxColour GetBackgroundColour();
962 wxFont GetFont();
00b6c4e3
RD
963};
964
965
d5c9047a
RD
966class wxTreeItemId {
967public:
968 wxTreeItemId();
969 ~wxTreeItemId();
bb0054cd 970 bool IsOk();
78e8819c 971 %pragma(python) addtoclass = "Ok = IsOk"
d5c9047a 972
f6bcfd97
BP
973 %addmethods {
974 int __cmp__(wxTreeItemId* other) {
c368d904 975 if (! other) return -1;
f6bcfd97
BP
976 return *self != *other;
977 }
978 }
d5c9047a
RD
979};
980
981
982
cf694132
RD
983%{
984class wxPyTreeItemData : public wxTreeItemData {
d5c9047a 985public:
cf694132 986 wxPyTreeItemData(PyObject* obj = NULL) {
c368d904 987 if (obj == NULL)
cf694132 988 obj = Py_None;
c368d904
RD
989 Py_INCREF(obj);
990 m_obj = obj;
cf694132 991 }
d5c9047a 992
cf694132 993 ~wxPyTreeItemData() {
4268f798 994 wxPyBeginBlockThreads();
c368d904 995 Py_DECREF(m_obj);
4268f798 996 wxPyEndBlockThreads();
cf694132
RD
997 }
998
999 PyObject* GetData() {
1000 Py_INCREF(m_obj);
1001 return m_obj;
1002 }
1003
1004 void SetData(PyObject* obj) {
4268f798 1005 wxPyBeginBlockThreads();
cf694132 1006 Py_DECREF(m_obj);
4268f798 1007 wxPyEndBlockThreads();
cf694132
RD
1008 m_obj = obj;
1009 Py_INCREF(obj);
1010 }
1011
1012 PyObject* m_obj;
d5c9047a 1013};
cf694132 1014%}
d5c9047a
RD
1015
1016
1017
9416aa89 1018%name(wxTreeItemData) class wxPyTreeItemData : public wxObject {
cf694132
RD
1019public:
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
d5c9047a 1030
8bf5d46e 1031class wxTreeEvent : public wxNotifyEvent {
d5c9047a 1032public:
00b6c4e3
RD
1033 wxTreeEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
1034
d5c9047a
RD
1035 wxTreeItemId GetItem();
1036 wxTreeItemId GetOldItem();
1037 wxPoint GetPoint();
ecc08ead 1038 const wxKeyEvent& GetKeyEvent();
d5c9047a 1039 int GetCode();
8bf5d46e 1040 const wxString& GetLabel();
d5c9047a
RD
1041};
1042
1043
f6bcfd97 1044
09f3d4e6 1045%{ // C++ version of Python aware wxTreeCtrl
f6bcfd97 1046class wxPyTreeCtrl : public wxTreeCtrl {
3b36695d 1047 DECLARE_ABSTRACT_CLASS(wxPyTreeCtrl);
f6bcfd97 1048public:
09f3d4e6 1049 wxPyTreeCtrl() : wxTreeCtrl() {}
f6bcfd97
BP
1050 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
1051 const wxPoint& pos,
1052 const wxSize& size,
1053 long style,
1054 const wxValidator& validator,
137b5242 1055 const wxString& name) :
f6bcfd97
BP
1056 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
1057
09f3d4e6
RD
1058 bool Create(wxWindow *parent, wxWindowID id,
1059 const wxPoint& pos,
1060 const wxSize& size,
1061 long style,
1062 const wxValidator& validator,
137b5242 1063 const wxString& name) {
09f3d4e6
RD
1064 return wxTreeCtrl::Create(parent, id, pos, size, style, validator, name);
1065 }
1066
1067
f6bcfd97
BP
1068 int OnCompareItems(const wxTreeItemId& item1,
1069 const wxTreeItemId& item2) {
1070 int rval = 0;
19a97bd6 1071 bool found;
4268f798 1072 wxPyBeginBlockThreads();
19a97bd6 1073 if ((found = m_myInst.findCallback("OnCompareItems")))
f6bcfd97
BP
1074 rval = m_myInst.callCallback(Py_BuildValue(
1075 "(OO)",
1076 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
1077 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
4268f798 1078 wxPyEndBlockThreads();
19a97bd6 1079 if (! found)
f6bcfd97 1080 rval = wxTreeCtrl::OnCompareItems(item1, item2);
f6bcfd97
BP
1081 return rval;
1082 }
1083 PYPRIVATE;
1084};
1085
3b36695d
RD
1086IMPLEMENT_ABSTRACT_CLASS(wxPyTreeCtrl, wxTreeCtrl);
1087
f6bcfd97
BP
1088%}
1089
d5c9047a
RD
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
f6bcfd97 1095%name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
d5c9047a 1096public:
f6bcfd97 1097 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
b68dc582
RD
1098 const wxPoint& pos = wxDefaultPosition,
1099 const wxSize& size = wxDefaultSize,
d5c9047a 1100 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
b68dc582 1101 const wxValidator& validator = wxDefaultValidator,
137b5242 1102 const wxString& name = wxPy_TreeCtrlNameStr);
09f3d4e6
RD
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,
137b5242 1110 const wxString& name = wxPy_TreeCtrlNameStr);
d5c9047a 1111
0122b7e3
RD
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)"
17c0e08c 1116 %pragma(python) addtomethod = "wxPreTreeCtrl:val._setOORInfo(val)"
d5c9047a
RD
1117
1118 size_t GetCount();
1119 unsigned int GetIndent();
1120 void SetIndent(unsigned int indent);
1121 wxImageList *GetImageList();
1122 wxImageList *GetStateImageList();
1b62f00d 1123 void SetImageList(wxImageList *imageList);
d5c9047a 1124 void SetStateImageList(wxImageList *imageList);
00b6c4e3
RD
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"
d5c9047a 1129
b1462dfa
RD
1130 unsigned int GetSpacing();
1131 void SetSpacing(unsigned int spacing);
1132
d5c9047a 1133 wxString GetItemText(const wxTreeItemId& item);
694759cf
RD
1134 int GetItemImage(const wxTreeItemId& item,
1135 wxTreeItemIcon which = wxTreeItemIcon_Normal);
d5c9047a 1136 int GetItemSelectedImage(const wxTreeItemId& item);
d5c9047a
RD
1137
1138 void SetItemText(const wxTreeItemId& item, const wxString& text);
694759cf
RD
1139 void SetItemImage(const wxTreeItemId& item, int image,
1140 wxTreeItemIcon which = wxTreeItemIcon_Normal);
d5c9047a 1141 void SetItemSelectedImage(const wxTreeItemId& item, int image);
08127323 1142 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
d5c9047a 1143
cf694132 1144 %addmethods {
c368d904
RD
1145 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
1146 // if needed.
cf694132
RD
1147 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
1148 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1149 if (data == NULL) {
1150 data = new wxPyTreeItemData();
f6bcfd97 1151 data->SetId(item); // set the id
cf694132
RD
1152 self->SetItemData(item, data);
1153 }
1154 return data;
1155 }
1156
1157 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
f6bcfd97
BP
1158 data->SetId(item); // set the id
1159 self->SetItemData(item, data);
c368d904 1160 }
cf694132 1161
c368d904
RD
1162 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
1163 // automatically creating data classes.
1164 PyObject* GetPyData(const wxTreeItemId& item) {
cf694132
RD
1165 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
1166 if (data == NULL) {
1167 data = new wxPyTreeItemData();
f6bcfd97 1168 data->SetId(item); // set the id
cf694132
RD
1169 self->SetItemData(item, data);
1170 }
1171 return data->GetData();
c368d904 1172 }
cf694132
RD
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);
f6bcfd97 1178 data->SetId(item); // set the id
cf694132
RD
1179 self->SetItemData(item, data);
1180 } else
1181 data->SetData(obj);
c368d904 1182 }
cf694132
RD
1183 }
1184
1185
d5c9047a
RD
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();
eb715945 1193 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
d426c97e
RD
1194 //size_t GetSelections(wxArrayTreeItemIds& selection);
1195 %addmethods {
1196 PyObject* GetSelections() {
4268f798 1197 wxPyBeginBlockThreads();
d426c97e
RD
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++) {
c368d904
RD
1203 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
1204 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
d426c97e
RD
1205 PyList_Append(rval, item);
1206 }
4268f798 1207 wxPyEndBlockThreads();
d426c97e
RD
1208 return rval;
1209 }
1210 }
1211
1212
d5c9047a 1213
bb0054cd
RD
1214 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
1215
d5c9047a
RD
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);
d426c97e
RD
1223 wxTreeItemId GetLastChild(const wxTreeItemId& item);
1224
d5c9047a
RD
1225
1226
1227 wxTreeItemId AddRoot(const wxString& text,
1228 int image = -1, int selectedImage = -1,
cf694132 1229 wxPyTreeItemData *data = NULL);
d5c9047a
RD
1230 wxTreeItemId PrependItem(const wxTreeItemId& parent,
1231 const wxString& text,
1232 int image = -1, int selectedImage = -1,
cf694132 1233 wxPyTreeItemData *data = NULL);
d5c9047a
RD
1234 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1235 const wxTreeItemId& idPrevious,
1236 const wxString& text,
1237 int image = -1, int selectedImage = -1,
cf694132 1238 wxPyTreeItemData *data = NULL);
f6bcfd97
BP
1239 %name(InsertItemBefore)
1240 wxTreeItemId InsertItem(const wxTreeItemId& parent,
1241 size_t before,
1242 const wxString& text,
1243 int image = -1, int selectedImage = -1,
3999941a 1244 wxPyTreeItemData *data = NULL);
d5c9047a
RD
1245 wxTreeItemId AppendItem(const wxTreeItemId& parent,
1246 const wxString& text,
1247 int image = -1, int selectedImage = -1,
cf694132 1248 wxPyTreeItemData *data = NULL);
d5c9047a
RD
1249
1250 void Delete(const wxTreeItemId& item);
08127323 1251 void DeleteChildren(const wxTreeItemId& item);
d5c9047a
RD
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();
8bf5d46e 1260 void UnselectAll();
d5c9047a
RD
1261 void SelectItem(const wxTreeItemId& item);
1262 void EnsureVisible(const wxTreeItemId& item);
1263 void ScrollTo(const wxTreeItemId& item);
8bf5d46e 1264#ifdef __WXMSW__
d5c9047a 1265 wxTextCtrl* EditLabel(const wxTreeItemId& item);
d5c9047a 1266 wxTextCtrl* GetEditControl();
b1462dfa 1267 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
8bf5d46e
RD
1268#else
1269 void EditLabel(const wxTreeItemId& item);
1270#endif
d5c9047a 1271
d426c97e 1272 void SortChildren(const wxTreeItemId& item);
d5c9047a 1273
b1462dfa 1274 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
b8b8dda7 1275 bool IsBold(const wxTreeItemId& item) const;
164b735b 1276 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
c127177f 1277
f6bcfd97
BP
1278
1279
b7e72427
RD
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
4120ef2b 1284#ifdef __WXMSW__
b1462dfa 1285 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
74bcba0e 1286#endif
b1462dfa 1287
d426c97e
RD
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;
164b735b 1292 if (self->GetBoundingRect(item, rect, textOnly)) {
4268f798 1293 wxPyBeginBlockThreads();
164b735b
RD
1294 wxRect* r = new wxRect(rect);
1295 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
4268f798 1296 wxPyEndBlockThreads();
164b735b
RD
1297 return val;
1298 }
d426c97e
RD
1299 else {
1300 Py_INCREF(Py_None);
1301 return Py_None;
1302 }
1303 }
1304 }
74bcba0e 1305
d426c97e 1306
c127177f 1307%pragma(python) addtoclass = "
f6bcfd97
BP
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)
c127177f
RD
1316 val1 = wxTreeItemIdPtr(val1)
1317 val1.thisown = 1
1318 return (val1,val2)
f6bcfd97
BP
1319 def HitTest(self, *_args, **_kwargs):
1320 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
c127177f
RD
1321 val1 = wxTreeItemIdPtr(val1)
1322 val1.thisown = 1
1323 return (val1,val2)
1324"
74bcba0e 1325
d5c9047a
RD
1326};
1327
d5c9047a 1328
7bf85405
RD
1329//----------------------------------------------------------------------
1330
68320e40
RD
1331
1332enum {
1333 wxDIRCTRL_DIR_ONLY,
1334 wxDIRCTRL_SELECT_FIRST,
1335 wxDIRCTRL_SHOW_FILTERS,
1336 wxDIRCTRL_3D_INTERNAL,
7cdaed0b 1337 wxDIRCTRL_EDIT_LABELS,
db0ff83e
RD
1338
1339 wxID_TREECTRL,
1340 wxID_FILTERLISTCTRL,
68320e40
RD
1341};
1342
1343
1344class wxDirItemData : public wxObject // wxTreeItemData
1345{
1346public:
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
1357class wxGenericDirCtrl: public wxControl
1358{
1359public:
1360 wxGenericDirCtrl(wxWindow *parent, const wxWindowID id = -1,
137b5242 1361 const wxString& dir = wxPyDirDialogDefaultFolderStr,
68320e40
RD
1362 const wxPoint& pos = wxDefaultPosition,
1363 const wxSize& size = wxDefaultSize,
1364 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
137b5242 1365 const wxString& filter = wxPyEmptyString,
68320e40 1366 int defaultFilter = 0,
137b5242 1367 const wxString& name = wxPy_TreeCtrlNameStr);
68320e40
RD
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,
137b5242 1374 const wxString& dir = wxPyDirDialogDefaultFolderStr,
68320e40
RD
1375 const wxPoint& pos = wxDefaultPosition,
1376 const wxSize& size = wxDefaultSize,
1377 long style = wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
137b5242 1378 const wxString& filter = wxPyEmptyString,
68320e40 1379 int defaultFilter = 0,
137b5242 1380 const wxString& name = wxPy_TreeCtrlNameStr);
68320e40
RD
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
1425class wxDirFilterListCtrl: public wxChoice
1426{
1427public:
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
9416aa89 1450%init %{
a3fbed81 1451 // Map renamed classes back to their common name for OOR
9416aa89
RD
1452 wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
1453 wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
a3fbed81 1454 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
9416aa89
RD
1455%}
1456
1457//----------------------------------------------------------------------
1458
7bf85405 1459