]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_listctrl.i
new port constants
[wxWidgets.git] / wxPython / src / _listctrl.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _listctrl.i
3// Purpose: SWIG interface file for wxListCtrl and related classes
4//
5// Author: Robin Dunn
6//
7// Created: 10-June-1998
8// RCS-ID: $Id$
9// Copyright: (c) 2002 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17
18%{
19#include <wx/listctrl.h>
d14a1e28 20%}
ab1f7d2a 21
aeee37c3 22MAKE_CONST_WXSTRING(ListCtrlNameStr);
d14a1e28
RD
23
24//---------------------------------------------------------------------------
25%newgroup
26
27enum {
28 // style flags
29 wxLC_VRULES,
30 wxLC_HRULES,
31
32 wxLC_ICON,
33 wxLC_SMALL_ICON,
34 wxLC_LIST,
35 wxLC_REPORT,
36
37 wxLC_ALIGN_TOP,
38 wxLC_ALIGN_LEFT,
39 wxLC_AUTOARRANGE,
40 wxLC_VIRTUAL,
41 wxLC_EDIT_LABELS,
42 wxLC_NO_HEADER,
43 wxLC_NO_SORT_HEADER,
44 wxLC_SINGLE_SEL,
45 wxLC_SORT_ASCENDING,
46 wxLC_SORT_DESCENDING,
47
48 wxLC_MASK_TYPE,
49 wxLC_MASK_ALIGN,
50 wxLC_MASK_SORT
51};
52
53
54enum {
55 // Mask flags to tell app/GUI what fields of wxListItem are valid
56 wxLIST_MASK_STATE,
57 wxLIST_MASK_TEXT,
58 wxLIST_MASK_IMAGE,
59 wxLIST_MASK_DATA,
60 wxLIST_SET_ITEM,
61 wxLIST_MASK_WIDTH,
62 wxLIST_MASK_FORMAT,
63
64// State flags for indicating the state of an item
65 wxLIST_STATE_DONTCARE,
66 wxLIST_STATE_DROPHILITED,
67 wxLIST_STATE_FOCUSED,
68 wxLIST_STATE_SELECTED,
69 wxLIST_STATE_CUT,
70 wxLIST_STATE_DISABLED,
71 wxLIST_STATE_FILTERED,
72 wxLIST_STATE_INUSE,
73 wxLIST_STATE_PICKED,
74 wxLIST_STATE_SOURCE,
75
76// Hit test flags, used in HitTest
77 wxLIST_HITTEST_ABOVE,
78 wxLIST_HITTEST_BELOW,
79 wxLIST_HITTEST_NOWHERE,
80 wxLIST_HITTEST_ONITEMICON,
81 wxLIST_HITTEST_ONITEMLABEL,
82 wxLIST_HITTEST_ONITEMRIGHT,
83 wxLIST_HITTEST_ONITEMSTATEICON,
84 wxLIST_HITTEST_TOLEFT,
85 wxLIST_HITTEST_TORIGHT,
86 wxLIST_HITTEST_ONITEM,
d0e2ede0
RD
87
88// GetSubItemRect constants
89 wxLIST_GETSUBITEMRECT_WHOLEITEM,
d14a1e28
RD
90};
91
92
93// Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
94enum
95{
96 wxLIST_NEXT_ABOVE, // Searches for an item above the specified item
97 wxLIST_NEXT_ALL, // Searches for subsequent item by index
98 wxLIST_NEXT_BELOW, // Searches for an item below the specified item
99 wxLIST_NEXT_LEFT, // Searches for an item to the left of the specified item
100 wxLIST_NEXT_RIGHT // Searches for an item to the right of the specified item
101};
102
103// Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
104enum
105{
106 wxLIST_ALIGN_DEFAULT,
107 wxLIST_ALIGN_LEFT,
108 wxLIST_ALIGN_TOP,
109 wxLIST_ALIGN_SNAP_TO_GRID
110};
111
112// Column format (MSW only except wxLIST_FORMAT_LEFT)
113enum wxListColumnFormat
114{
115 wxLIST_FORMAT_LEFT,
116 wxLIST_FORMAT_RIGHT,
117 wxLIST_FORMAT_CENTRE,
118 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
119};
120
121// Autosize values for SetColumnWidth
122enum
123{
124 wxLIST_AUTOSIZE = -1,
125 wxLIST_AUTOSIZE_USEHEADER = -2 // partly supported by generic version
126};
127
128// Flag values for GetItemRect
129enum
130{
131 wxLIST_RECT_BOUNDS,
132 wxLIST_RECT_ICON,
133 wxLIST_RECT_LABEL
134};
135
136// Flag values for FindItem (MSW only)
137enum
138{
139 wxLIST_FIND_UP,
140 wxLIST_FIND_DOWN,
141 wxLIST_FIND_LEFT,
142 wxLIST_FIND_RIGHT
143};
144
145
146
147//---------------------------------------------------------------------------
148%newgroup
149
150// wxListItemAttr: a structure containing the visual attributes of an item
151class wxListItemAttr
152{
153public:
154 // ctors
155 //wxListItemAttr();
156 wxListItemAttr(const wxColour& colText = wxNullColour,
157 const wxColour& colBack = wxNullColour,
158 const wxFont& font = wxNullFont);
214c4fbe 159 ~wxListItemAttr();
d14a1e28
RD
160
161 // setters
162 void SetTextColour(const wxColour& colText);
163 void SetBackgroundColour(const wxColour& colBack);
164 void SetFont(const wxFont& font);
165
166 // accessors
167 bool HasTextColour();
168 bool HasBackgroundColour();
169 bool HasFont();
170
171 wxColour GetTextColour();
172 wxColour GetBackgroundColour();
173 wxFont GetFont();
174
214c4fbe
RD
175 void AssignFrom(const wxListItemAttr& source);
176
177 %pythonAppend Destroy "args[0].thisown = 0"
d14a1e28
RD
178 %extend { void Destroy() { delete self; } }
179};
180
181
182
183
184//---------------------------------------------------------------------------
185%newgroup
186
dd9f7fea 187
d14a1e28
RD
188// wxListItem: the item or column info, used to exchange data with wxListCtrl
189class wxListItem : public wxObject {
190public:
191 wxListItem();
192 ~wxListItem();
193
194 // resetting
195 void Clear();
196 void ClearAttributes();
197
198 // setters
199 void SetMask(long mask);
200 void SetId(long id);
201 void SetColumn(int col);
202 void SetState(long state);
203 void SetStateMask(long stateMask);
204 void SetText(const wxString& text);
205 void SetImage(int image);
206 void SetData(long data);
207
208 void SetWidth(int width);
209 void SetAlign(wxListColumnFormat align);
210
211 void SetTextColour(const wxColour& colText);
212 void SetBackgroundColour(const wxColour& colBack);
213 void SetFont(const wxFont& font);
214
215 // accessors
216 long GetMask();
217 long GetId();
218 int GetColumn();
219 long GetState();
220 const wxString& GetText();
221 int GetImage();
222 long GetData();
223
224 int GetWidth();
225 wxListColumnFormat GetAlign();
226
227 wxListItemAttr *GetAttributes();
228 bool HasAttributes();
229
230 wxColour GetTextColour() const;
231 wxColour GetBackgroundColour() const;
232 wxFont GetFont() const;
233
234 // these members are public for compatibility
235 long m_mask; // Indicates what fields are valid
236 long m_itemId; // The zero-based item position
237 int m_col; // Zero-based column, if in report mode
238 long m_state; // The state of the item
239 long m_stateMask;// Which flags of m_state are valid (uses same flags)
240 wxString m_text; // The label/header text
241 int m_image; // The zero-based index into an image list
242 long m_data; // App-defined data
243
244 // For columns only
245 int m_format; // left, right, centre
246 int m_width; // width of column
247
248};
249
250
251//---------------------------------------------------------------------------
252%newgroup
253
254
255// wxListEvent - the event class for the wxListCtrl notifications
256class wxListEvent: public wxNotifyEvent {
257public:
258 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
259
260 int m_code;
261 long m_oldItemIndex;
262 long m_itemIndex;
263 int m_col;
264 wxPoint m_pointDrag;
265 %immutable;
266 wxListItem m_item;
267 %mutable;
268
269 int GetKeyCode();
270 %pythoncode { GetCode = GetKeyCode }
271 long GetIndex();
272 int GetColumn();
273 wxPoint GetPoint();
bdcf3ef5 274 %pythoncode { GetPosition = GetPoint }
d14a1e28
RD
275 const wxString& GetLabel();
276 const wxString& GetText();
277 int GetImage();
278 long GetData();
279 long GetMask();
280 const wxListItem& GetItem();
281
282 long GetCacheFrom();
283 long GetCacheTo();
284
285 // was label editing canceled? (for wxEVT_COMMAND_LIST_END_LABEL_EDIT only)
286 bool IsEditCancelled() const;
287 void SetEditCanceled(bool editCancelled);
288};
289
290/* List control event types */
291%constant wxEventType wxEVT_COMMAND_LIST_BEGIN_DRAG;
292%constant wxEventType wxEVT_COMMAND_LIST_BEGIN_RDRAG;
293%constant wxEventType wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
294%constant wxEventType wxEVT_COMMAND_LIST_END_LABEL_EDIT;
295%constant wxEventType wxEVT_COMMAND_LIST_DELETE_ITEM;
296%constant wxEventType wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
d14a1e28
RD
297%constant wxEventType wxEVT_COMMAND_LIST_ITEM_SELECTED;
298%constant wxEventType wxEVT_COMMAND_LIST_ITEM_DESELECTED;
299%constant wxEventType wxEVT_COMMAND_LIST_KEY_DOWN;
300%constant wxEventType wxEVT_COMMAND_LIST_INSERT_ITEM;
301%constant wxEventType wxEVT_COMMAND_LIST_COL_CLICK;
302%constant wxEventType wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK;
303%constant wxEventType wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK;
304%constant wxEventType wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
305%constant wxEventType wxEVT_COMMAND_LIST_CACHE_HINT;
306%constant wxEventType wxEVT_COMMAND_LIST_COL_RIGHT_CLICK;
307%constant wxEventType wxEVT_COMMAND_LIST_COL_BEGIN_DRAG;
308%constant wxEventType wxEVT_COMMAND_LIST_COL_DRAGGING;
309%constant wxEventType wxEVT_COMMAND_LIST_COL_END_DRAG;
310%constant wxEventType wxEVT_COMMAND_LIST_ITEM_FOCUSED;
311
aeee37c3 312// WXWIN_COMPATIBILITY_2_4
2f91e3df 313#if 0
aeee37c3
RD
314%constant wxEventType wxEVT_COMMAND_LIST_GET_INFO;
315%constant wxEventType wxEVT_COMMAND_LIST_SET_INFO;
2f91e3df 316#endif
d14a1e28
RD
317
318%pythoncode {
319
320EVT_LIST_BEGIN_DRAG = wx.PyEventBinder(wxEVT_COMMAND_LIST_BEGIN_DRAG , 1)
321EVT_LIST_BEGIN_RDRAG = wx.PyEventBinder(wxEVT_COMMAND_LIST_BEGIN_RDRAG , 1)
322EVT_LIST_BEGIN_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT , 1)
323EVT_LIST_END_LABEL_EDIT = wx.PyEventBinder(wxEVT_COMMAND_LIST_END_LABEL_EDIT , 1)
324EVT_LIST_DELETE_ITEM = wx.PyEventBinder(wxEVT_COMMAND_LIST_DELETE_ITEM , 1)
325EVT_LIST_DELETE_ALL_ITEMS = wx.PyEventBinder(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS , 1)
2f91e3df
KO
326#WXWIN_COMPATIBILITY_2_4
327#EVT_LIST_GET_INFO = wx.PyEventBinder(wxEVT_COMMAND_LIST_GET_INFO , 1)
328#EVT_LIST_SET_INFO = wx.PyEventBinder(wxEVT_COMMAND_LIST_SET_INFO , 1)
329#END WXWIN_COMPATIBILITY_2_4
d14a1e28
RD
330EVT_LIST_ITEM_SELECTED = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_SELECTED , 1)
331EVT_LIST_ITEM_DESELECTED = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_DESELECTED , 1)
332EVT_LIST_KEY_DOWN = wx.PyEventBinder(wxEVT_COMMAND_LIST_KEY_DOWN , 1)
333EVT_LIST_INSERT_ITEM = wx.PyEventBinder(wxEVT_COMMAND_LIST_INSERT_ITEM , 1)
334EVT_LIST_COL_CLICK = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_CLICK , 1)
335EVT_LIST_ITEM_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK , 1)
336EVT_LIST_ITEM_MIDDLE_CLICK = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, 1)
337EVT_LIST_ITEM_ACTIVATED = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_ACTIVATED , 1)
338EVT_LIST_CACHE_HINT = wx.PyEventBinder(wxEVT_COMMAND_LIST_CACHE_HINT , 1)
339EVT_LIST_COL_RIGHT_CLICK = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK , 1)
340EVT_LIST_COL_BEGIN_DRAG = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG , 1)
341EVT_LIST_COL_DRAGGING = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_DRAGGING , 1)
342EVT_LIST_COL_END_DRAG = wx.PyEventBinder(wxEVT_COMMAND_LIST_COL_END_DRAG , 1)
343EVT_LIST_ITEM_FOCUSED = wx.PyEventBinder(wxEVT_COMMAND_LIST_ITEM_FOCUSED , 1)
5f24651b 344
2f91e3df
KO
345#WXWIN_COMPATIBILITY_2_4
346#EVT_LIST_GET_INFO = wx._deprecated(EVT_LIST_GET_INFO)
347#EVT_LIST_SET_INFO = wx._deprecated(EVT_LIST_SET_INFO)
d14a1e28
RD
348}
349
350//---------------------------------------------------------------------------
351%newgroup
352
353
354%{ // Python aware sorting function for wxPyListCtrl
355 static int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
356 int retval = 0;
357 PyObject* func = (PyObject*)funcPtr;
6e6b3557 358 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
359
360 PyObject* args = Py_BuildValue("(ii)", item1, item2);
361 PyObject* result = PyEval_CallObject(func, args);
362 Py_DECREF(args);
363 if (result) {
364 retval = PyInt_AsLong(result);
365 Py_DECREF(result);
366 }
367
da32eb53 368 wxPyEndBlockThreads(blocked);
d14a1e28
RD
369 return retval;
370 }
371%}
372
373
374
375%{ // C++ Version of a Python aware class
376class wxPyListCtrl : public wxListCtrl {
4617be08 377 DECLARE_ABSTRACT_CLASS(wxPyListCtrl)
d14a1e28
RD
378public:
379 wxPyListCtrl() : wxListCtrl() {}
380 wxPyListCtrl(wxWindow* parent, wxWindowID id,
381 const wxPoint& pos,
382 const wxSize& size,
383 long style,
384 const wxValidator& validator,
385 const wxString& name) :
386 wxListCtrl(parent, id, pos, size, style, validator, name) {}
387
388 bool Create(wxWindow* parent, wxWindowID id,
389 const wxPoint& pos,
390 const wxSize& size,
391 long style,
392 const wxValidator& validator,
393 const wxString& name) {
394 return wxListCtrl::Create(parent, id, pos, size, style, validator, name);
395 }
396
397 DEC_PYCALLBACK_STRING_LONGLONG(OnGetItemText);
d14a1e28
RD
398 DEC_PYCALLBACK_LISTATTR_LONG(OnGetItemAttr);
399
f5bd42d1
RD
400 // use the virtual version to avoid a confusing assert in the base class
401 DEC_PYCALLBACK_INT_LONG_virtual(OnGetItemImage);
e280c9ca 402 DEC_PYCALLBACK_INT_LONGLONG(OnGetItemColumnImage);
f5bd42d1 403
d14a1e28
RD
404 PYPRIVATE;
405};
406
407IMPLEMENT_ABSTRACT_CLASS(wxPyListCtrl, wxListCtrl);
408
409IMP_PYCALLBACK_STRING_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemText);
d14a1e28 410IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
f5bd42d1 411IMP_PYCALLBACK_INT_LONG_virtual(wxPyListCtrl, wxListCtrl, OnGetItemImage);
e280c9ca
RD
412IMP_PYCALLBACK_INT_LONGLONG(wxPyListCtrl, wxListCtrl, OnGetItemColumnImage);
413
d14a1e28
RD
414%}
415
416
417
418
419
ab1f7d2a
RD
420MustHaveApp(wxPyListCtrl);
421
1b8c7ba6
RD
422%rename(ListCtrl) wxPyListCtrl;
423class wxPyListCtrl : public wxControl {
d14a1e28
RD
424public:
425
2b9048c5
RD
426 %pythonAppend wxPyListCtrl "self._setOORInfo(self);self._setCallbackInfo(self, ListCtrl)"
427 %pythonAppend wxPyListCtrl() ""
f5bd42d1 428
d14a1e28
RD
429 wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
430 const wxPoint& pos = wxDefaultPosition,
431 const wxSize& size = wxDefaultSize,
432 long style = wxLC_ICON,
433 const wxValidator& validator = wxDefaultValidator,
434 const wxString& name = wxPyListCtrlNameStr);
1b8c7ba6 435 %RenameCtor(PreListCtrl, wxPyListCtrl());
d14a1e28
RD
436
437 bool Create(wxWindow* parent, wxWindowID id = -1,
438 const wxPoint& pos = wxDefaultPosition,
439 const wxSize& size = wxDefaultSize,
440 long style = wxLC_ICON,
441 const wxValidator& validator = wxDefaultValidator,
442 const wxString& name = wxPyListCtrlNameStr);
443
444 void _setCallbackInfo(PyObject* self, PyObject* _class);
445
f5bd42d1 446
d14a1e28
RD
447 // Set the control colours
448 bool SetForegroundColour(const wxColour& col);
449 bool SetBackgroundColour(const wxColour& col);
450
451 // Gets information about this column
2b9048c5 452 %pythonAppend GetColumn "if val is not None: val.thisown = 1"; // %newobject doesn't work with OOR typemap
d14a1e28
RD
453 %extend {
454 wxListItem* GetColumn(int col) {
455 wxListItem item;
456 item.SetMask( wxLIST_MASK_STATE |
457 wxLIST_MASK_TEXT |
458 wxLIST_MASK_IMAGE |
459 wxLIST_MASK_DATA |
460 wxLIST_SET_ITEM |
461 wxLIST_MASK_WIDTH |
462 wxLIST_MASK_FORMAT
463 );
464 if (self->GetColumn(col, item))
465 return new wxListItem(item);
466 else
467 return NULL;
468 }
469 }
470
471 // Sets information about this column
472 bool SetColumn(int col, wxListItem& item) ;
473
474 // Gets the column width
475 int GetColumnWidth(int col) const;
476
477 // Sets the column width
478 bool SetColumnWidth(int col, int width) ;
479
480 // Gets the number of items that can fit vertically in the
481 // visible area of the list control (list or report view)
482 // or the total number of items in the list control (icon
483 // or small icon view)
484 int GetCountPerPage() const;
485
486 // return the total area occupied by all the items (icon/small icon only)
487 wxRect GetViewRect() const;
f5bd42d1 488
d14a1e28
RD
489 // Gets the edit control for editing labels.
490 wxTextCtrl* GetEditControl() const;
d14a1e28
RD
491
492 // Gets information about the item
2b9048c5 493 %pythonAppend GetItem "if val is not None: val.thisown = 1"; // %newobject doesn't work with OOR typemap
d14a1e28
RD
494 %extend {
495 wxListItem* GetItem(long itemId, int col=0) {
496 wxListItem* info = new wxListItem;
497 info->m_itemId = itemId;
498 info->m_col = col;
499 info->m_mask = 0xFFFF;
500 self->GetItem(*info);
501 return info;
502 }
503 }
504
505 // Sets information about the item
506 bool SetItem(wxListItem& info) ;
507
508 // Sets a string field at a particular column
1b8c7ba6 509 %Rename(SetStringItem, long, SetItem(long index, int col, const wxString& label, int imageId = -1));
d14a1e28
RD
510
511 // Gets the item state
512 int GetItemState(long item, long stateMask) const ;
513
514 // Sets the item state
515 bool SetItemState(long item, long state, long stateMask) ;
516
517 // Sets the item image
5f24651b 518 bool SetItemImage(long item, int image, int selImage=-1) ;
06db67bc 519 bool SetItemColumnImage( long item, long column, int image );
d14a1e28
RD
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 ;
536
537 // Gets the item position
538 %extend {
539 wxPoint GetItemPosition(long item) {
540 wxPoint pos;
541 self->GetItemPosition(item, pos);
542 return pos;
543 }
544 // Gets the item rectangle
545 wxRect GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
546 wxRect rect;
547 self->GetItemRect(item, rect, code);
548 return rect;
549 }
d0e2ede0
RD
550
551// MSW only so far...
552// wxRect GetSubItemRect(long item, long subItem, int code = wxLIST_RECT_BOUNDS) {
553// wxRect rect;
554// self->GetSubItemRect(item, subItem, rect, code);
555// return rect;
556// }
d14a1e28
RD
557 }
558
559
560 // Sets the item position
561 bool SetItemPosition(long item, const wxPoint& pos) ;
562
563 // Gets the number of items in the list control
564 int GetItemCount() const;
565
566 // Gets the number of columns in the list control
567 int GetColumnCount() const;
568
569 // get the horizontal and vertical components of the item spacing
570 wxSize GetItemSpacing() const;
15648073 571 %pythoncode { GetItemSpacing = wx._deprecated(GetItemSpacing) }
d14a1e28
RD
572
573#ifndef __WXMSW__
a72f4631 574 void SetItemSpacing( int spacing, bool isSmall = false );
15648073 575 %pythoncode { SetItemSpacing = wx._deprecated(SetItemSpacing) }
d14a1e28
RD
576#endif
577
578 // Gets the number of selected items in the list control
579 int GetSelectedItemCount() const;
580
581 // Gets the text colour of the listview
582 wxColour GetTextColour() const;
583
584 // Sets the text colour of the listview
585 void SetTextColour(const wxColour& col);
586
587 // Gets the index of the topmost visible item when in
588 // list or report view
589 long GetTopItem() const ;
590
591 // Add or remove a single window style
a72f4631 592 void SetSingleStyle(long style, bool add = true) ;
d14a1e28
RD
593
594 // Set the whole window style
595 void SetWindowStyleFlag(long style) ;
596
597 // Searches for an item, starting from 'item'.
598 // item can be -1 to find the first item that matches the
599 // specified flags.
600 // Returns the item or -1 if unsuccessful.
601 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
602
603 // Gets one of the three image lists
604 wxImageList *GetImageList(int which) const ;
605
606 // Sets the image list
607 void SetImageList(wxImageList *imageList, int which);
608
214c4fbe 609 %disownarg( wxImageList *imageList );
d14a1e28 610 void AssignImageList(wxImageList *imageList, int which);
214c4fbe 611 %cleardisown( wxImageList *imageList );
f5bd42d1 612
6e7db3c8
RD
613 // are we in report mode?
614 bool InReportView() const;
f5bd42d1 615
dd9f7fea 616 // returns True if it is a virtual list control
d14a1e28
RD
617 bool IsVirtual() const;
618
619 // refresh items selectively (only useful for virtual list controls)
620 void RefreshItem(long item);
621 void RefreshItems(long itemFrom, long itemTo);
622
623 // Arranges the items
624 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
625
626 // Deletes an item
627 bool DeleteItem(long item);
628
629 // Deletes all items
630 bool DeleteAllItems() ;
631
632 // Deletes a column
633 bool DeleteColumn(int col);
634
635 // Deletes all columns
636 bool DeleteAllColumns();
637
638 // Clears items, and columns if there are any.
639 void ClearAll();
640
641#ifdef __WXMSW__
642 // Edit the label
643 wxTextCtrl* EditLabel(long item /*, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)*/);
644
645 // End label editing, optionally cancelling the edit
646 bool EndEditLabel(bool cancel);
647#else
648 void EditLabel(long item);
649#endif
650
651 // Ensures this item is visible
652 bool EnsureVisible(long item) ;
653
654 // Find an item whose label matches this string, starting from the item after 'start'
655 // or the beginning if 'start' is -1.
a72f4631 656 long FindItem(long start, const wxString& str, bool partial = false);
d14a1e28
RD
657
658 // Find an item whose data matches this data, starting from the item after 'start'
659 // or the beginning if 'start' is -1.
1b8c7ba6 660 %Rename(FindItemData, long, FindItem(long start, long data));
d14a1e28
RD
661
662 // Find an item nearest this position in the specified direction, starting from
663 // the item after 'start' or the beginning if 'start' is -1.
1b8c7ba6 664 %Rename(FindItemAtPos, long, FindItem(long start, const wxPoint& pt, int direction));
d14a1e28 665
322913ce
RD
666
667 DocDeclAStr(
668 long, HitTest(const wxPoint& point, int& OUTPUT),
669 "HitTest(Point point) -> (item, where)",
d07d2bc9 670 "Determines which item (if any) is at the specified point, giving
7c1f6b54 671details in the second return value (see wx.LIST_HITTEST flags.)", "");
d14a1e28 672
d0e2ede0
RD
673 DocDeclAStrName(
674 long, HitTest(const wxPoint& point, int& OUTPUT, long* OUTPUT),
675 "HitTestSubItem(Point point) -> (item, where, subItem)",
676 "Determines which item (if any) is at the specified point, giving details in
677the second return value (see wx.LIST_HITTEST flags) and also the subItem, if
678any.", "",
679 HitTestSubItem);
680
681
d14a1e28
RD
682 // Inserts an item, returning the index of the new item if successful,
683 // -1 otherwise.
684 long InsertItem(wxListItem& info);
685
686 // Insert a string item
4617be08
RD
687 %Rename(InsertStringItem,
688 long, InsertItem(long index, const wxString& label, int imageIndex=-1));
d14a1e28
RD
689
690 // Insert an image item
4617be08
RD
691 %Rename(InsertImageItem,
692 long, InsertItem(long index, int imageIndex));
d14a1e28
RD
693
694 // Insert an image/string item
4617be08
RD
695 %Rename(InsertImageStringItem,
696 long, InsertItem(long index, const wxString& label, int imageIndex));
d14a1e28
RD
697
698 // For list view mode (only), inserts a column.
54ab2b20
RD
699 %Rename(InsertColumnItem, long, InsertColumn(long col, wxListItem& info));
700 %pythoncode { InsertColumnInfo = InsertColumnItem }
d14a1e28
RD
701
702 long InsertColumn(long col,
703 const wxString& heading,
704 int format = wxLIST_FORMAT_LEFT,
705 int width = -1);
706
707 // set the number of items in a virtual list control
708 void SetItemCount(long count);
709
710 // Scrolls the list control. If in icon, small icon or report view mode,
711 // x specifies the number of pixels to scroll. If in list view mode, x
712 // specifies the number of columns to scroll.
713 // If in icon, small icon or list view mode, y specifies the number of pixels
714 // to scroll. If in report view mode, y specifies the number of lines to scroll.
715 bool ScrollList(int dx, int dy);
716
717 void SetItemTextColour( long item, const wxColour& col);
718 wxColour GetItemTextColour( long item ) const;
719 void SetItemBackgroundColour( long item, const wxColour &col);
720 wxColour GetItemBackgroundColour( long item ) const;
721
02b800ce
RD
722 // Font of an item.
723 void SetItemFont( long item, const wxFont &f);
724 wxFont GetItemFont( long item ) const;
d14a1e28
RD
725
726 %pythoncode {
727 %#
728 %# Some helpers...
729 def Select(self, idx, on=1):
730 '''[de]select an item'''
dd9f7fea 731 if on: state = wx.LIST_STATE_SELECTED
d14a1e28 732 else: state = 0
dd9f7fea 733 self.SetItemState(idx, state, wx.LIST_STATE_SELECTED)
d14a1e28
RD
734
735 def Focus(self, idx):
736 '''Focus and show the given item'''
dd9f7fea 737 self.SetItemState(idx, wx.LIST_STATE_FOCUSED, wx.LIST_STATE_FOCUSED)
d14a1e28
RD
738 self.EnsureVisible(idx)
739
740 def GetFocusedItem(self):
741 '''get the currently focused item or -1 if none'''
dd9f7fea 742 return self.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_FOCUSED)
d14a1e28
RD
743
744 def GetFirstSelected(self, *args):
745 '''return first selected item, or -1 when none'''
746 return self.GetNextSelected(-1)
747
748 def GetNextSelected(self, item):
749 '''return subsequent selected items, or -1 when no more'''
dd9f7fea 750 return self.GetNextItem(item, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
d14a1e28
RD
751
752 def IsSelected(self, idx):
dd9f7fea 753 '''return True if the item is selected'''
08e2c570 754 return (self.GetItemState(idx, wx.LIST_STATE_SELECTED) & wx.LIST_STATE_SELECTED) != 0
d14a1e28
RD
755
756 def SetColumnImage(self, col, image):
757 item = self.GetColumn(col)
dd9f7fea
RD
758 %# preserve all other attributes too
759 item.SetMask( wx.LIST_MASK_STATE |
760 wx.LIST_MASK_TEXT |
761 wx.LIST_MASK_IMAGE |
762 wx.LIST_MASK_DATA |
763 wx.LIST_SET_ITEM |
764 wx.LIST_MASK_WIDTH |
765 wx.LIST_MASK_FORMAT )
d14a1e28
RD
766 item.SetImage(image)
767 self.SetColumn(col, item)
768
769 def ClearColumnImage(self, col):
770 self.SetColumnImage(col, -1)
771
772 def Append(self, entry):
773 '''Append an item to the list control. The entry parameter should be a
774 sequence with an item for each column'''
775 if len(entry):
dd9f7fea 776 if wx.USE_UNICODE:
d14a1e28
RD
777 cvtfunc = unicode
778 else:
779 cvtfunc = str
780 pos = self.GetItemCount()
781 self.InsertStringItem(pos, cvtfunc(entry[0]))
782 for i in range(1, len(entry)):
783 self.SetStringItem(pos, i, cvtfunc(entry[i]))
784 return pos
785 }
786
787
788 // bool SortItems(wxListCtrlCompare fn, long data);
789 %extend {
790 // Sort items.
791 // func is a function which takes 2 long arguments: item1, item2.
792 // item1 is the long data associated with a first item (NOT the index).
793 // item2 is the long data associated with a second item (NOT the index).
794 // The return value is a negative number if the first item should precede the second
795 // item, a positive number of the second item should precede the first,
796 // or zero if the two items are equivalent.
797 bool SortItems(PyObject* func) {
798 if (!PyCallable_Check(func))
a72f4631 799 return false;
d14a1e28
RD
800 return self->SortItems((wxListCtrlCompare)wxPyListCtrl_SortItems, (long)func);
801 }
802 }
803
804
805 %extend {
806 wxWindow* GetMainWindow() {
807 #ifdef __WXMSW__
808 return self;
809 #else
810 return (wxWindow*)self->m_mainWin;
811 #endif
812 }
813 }
174051f6
RD
814
815 static wxVisualAttributes
816 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
d14a1e28
RD
817};
818
819
820
821//---------------------------------------------------------------------------
822%newgroup
823
824
ab1f7d2a
RD
825MustHaveApp(wxListView);
826
d14a1e28
RD
827// wxListView: a class which provides a little better API for list control
828class wxListView : public wxPyListCtrl
829{
830public:
2b9048c5
RD
831 %pythonAppend wxListView "self._setOORInfo(self)"
832 %pythonAppend wxListView() ""
d14a1e28
RD
833
834 wxListView( wxWindow *parent,
835 wxWindowID id = -1,
836 const wxPoint& pos = wxDefaultPosition,
837 const wxSize& size = wxDefaultSize,
838 long style = wxLC_REPORT,
839 const wxValidator& validator = wxDefaultValidator,
840 const wxString& name = wxPyListCtrlNameStr);
1b8c7ba6 841 %RenameCtor(PreListView, wxListView());
d14a1e28
RD
842
843 bool Create( wxWindow *parent,
844 wxWindowID id = -1,
845 const wxPoint& pos = wxDefaultPosition,
846 const wxSize& size = wxDefaultSize,
847 long style = wxLC_REPORT,
848 const wxValidator& validator = wxDefaultValidator,
849 const wxString& name = wxPyListCtrlNameStr);
850
851 // [de]select an item
a72f4631 852 void Select(long n, bool on = true);
d14a1e28
RD
853
854 // focus and show the given item
855 void Focus(long index);
856
857 // get the currently focused item or -1 if none
858 long GetFocusedItem() const;
859
860 // get first and subsequent selected items, return -1 when no more
861 long GetNextSelected(long item) const;
862 long GetFirstSelected() const;
863
dd9f7fea 864 // return True if the item is selected
d14a1e28
RD
865 bool IsSelected(long index);
866
867 void SetColumnImage(int col, int image);
868 void ClearColumnImage(int col);
869};
870
871
872
873//---------------------------------------------------------------------------
874
875%init %{
876 // Map renamed classes back to their common name for OOR
877 wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
878%}
879
880//---------------------------------------------------------------------------