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