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