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