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