1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: More control (widget) classes for wxPython
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
20 #include <wx/listctrl.h>
21 #include <wx/treectrl.h>
24 //----------------------------------------------------------------------
27 %include my_typemaps.i
29 // Import some definitions of other classes, etc.
37 %pragma(python) code = "import wx"
39 //----------------------------------------------------------------------
42 extern wxValidator wxPyDefaultValidator;
45 //----------------------------------------------------------------------
54 wxLIST_STATE_DONTCARE,
55 wxLIST_STATE_DROPHILITED,
57 wxLIST_STATE_SELECTED,
61 wxLIST_HITTEST_NOWHERE,
62 wxLIST_HITTEST_ONITEMICON,
63 wxLIST_HITTEST_ONITEMLABEL,
64 wxLIST_HITTEST_ONITEMRIGHT,
65 wxLIST_HITTEST_ONITEMSTATEICON,
66 wxLIST_HITTEST_TOLEFT,
67 wxLIST_HITTEST_TORIGHT,
68 wxLIST_HITTEST_ONITEM,
77 wxLIST_ALIGN_SNAP_TO_GRID,
79 wxLIST_AUTOSIZE_USEHEADER,
90 enum wxListColumnFormat
95 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
104 //wxListItemAttr(const wxColour& colText,
105 // const wxColour& colBack,
106 // const wxFont& font)
107 // : m_colText(colText), m_colBack(colBack), m_font(font) { }
110 void SetTextColour(const wxColour& colText);
111 void SetBackgroundColour(const wxColour& colBack);
112 void SetFont(const wxFont& font);
115 bool HasTextColour();
116 bool HasBackgroundColour();
119 const wxColour& GetTextColour();
120 const wxColour& GetBackgroundColour();
121 const wxFont& GetFont();
132 void ClearAttributes();
135 void SetMask(long mask);
137 void SetColumn(int col);
138 void SetState(long state);
139 void SetStateMask(long stateMask);
140 void SetText(const wxString& text);
141 void SetImage(int image);
142 void SetData(long data);
144 void SetWidth(int width);
145 void SetAlign(wxListColumnFormat align);
147 void SetTextColour(const wxColour& colText);
148 void SetBackgroundColour(const wxColour& colBack);
149 void SetFont(const wxFont& font);
156 const wxString& GetText();
161 wxListColumnFormat GetAlign();
163 wxListItemAttr *GetAttributes();
164 bool HasAttributes();
166 wxColour GetTextColour() const;
167 wxColour GetBackgroundColour() const;
168 wxFont GetFont() const;
170 // these members are public for compatibility
171 long m_mask; // Indicates what fields are valid
172 long m_itemId; // The zero-based item position
173 int m_col; // Zero-based column, if in report mode
174 long m_state; // The state of the item
175 long m_stateMask;// Which flags of m_state are valid (uses same flags)
176 wxString m_text; // The label/header text
177 int m_image; // The zero-based index into an image list
178 long m_data; // App-defined data
181 int m_format; // left, right, centre
182 int m_width; // width of column
187 class wxListEvent: public wxNotifyEvent {
204 const wxString& GetLabel();
205 const wxString& GetText();
209 const wxListItem& GetItem();
214 class wxListCtrl : public wxControl {
216 wxListCtrl(wxWindow* parent, wxWindowID id,
217 const wxPoint& pos = wxPyDefaultPosition,
218 const wxSize& size = wxPyDefaultSize,
219 long style = wxLC_ICON,
220 const wxValidator& validator = wxPyDefaultValidator,
221 char* name = "listCtrl");
223 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
225 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
226 bool DeleteItem(long item);
227 bool DeleteAllItems();
228 bool DeleteColumn(int col);
229 bool DeleteAllColumns(void);
232 wxTextCtrl* EditLabel(long item);
233 bool EndEditLabel(bool cancel);
234 wxTextCtrl* GetEditControl();
236 void EditLabel(long item);
238 bool EnsureVisible(long item);
239 long FindItem(long start, const wxString& str, bool partial = FALSE);
240 %name(FindItemData)long FindItem(long start, long data);
241 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt,
243 bool GetColumn(int col, wxListItem& item);
244 int GetColumnWidth(int col);
245 int GetCountPerPage();
246 wxImageList* GetImageList(int which);
247 long GetItemData(long item);
250 %new wxListItem* GetItem(long itemId, int col=0) {
251 wxListItem* info = new wxListItem;
252 info->m_itemId = itemId;
254 info->m_mask = 0xFFFF;
255 self->GetItem(*info);
258 %new wxPoint* GetItemPosition(long item) {
259 wxPoint* pos = new wxPoint;
260 self->GetItemPosition(item, *pos);
263 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
264 wxRect* rect= new wxRect;
265 self->GetItemRect(item, *rect, code);
270 int GetItemState(long item, long stateMask);
272 int GetItemSpacing(bool isSmall);
273 wxString GetItemText(long item);
274 long GetNextItem(long item,
275 int geometry = wxLIST_NEXT_ALL,
276 int state = wxLIST_STATE_DONTCARE);
277 int GetSelectedItemCount();
279 wxColour GetTextColour();
280 void SetTextColour(const wxColour& col);
283 long HitTest(const wxPoint& point, int& OUTPUT);
284 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
285 long InsertColumn(long col, const wxString& heading,
286 int format = wxLIST_FORMAT_LEFT,
289 long InsertItem(wxListItem& info);
290 %name(InsertStringItem) long InsertItem(long index, const wxString& label);
291 %name(InsertImageItem) long InsertItem(long index, int imageIndex);
292 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label,
295 bool ScrollList(int dx, int dy);
296 void SetBackgroundColour(const wxColour& col);
297 bool SetColumn(int col, wxListItem& item);
298 bool SetColumnWidth(int col, int width);
299 void SetImageList(wxImageList* imageList, int which);
301 bool SetItem(wxListItem& info);
302 %name(SetStringItem)long SetItem(long index, int col, const wxString& label,
305 bool SetItemData(long item, long data);
306 bool SetItemImage(long item, int image, int selImage);
307 bool SetItemPosition(long item, const wxPoint& pos);
308 bool SetItemState(long item, long state, long stateMask);
309 void SetItemText(long item, const wxString& text);
310 void SetSingleStyle(long style, bool add = TRUE);
311 void SetWindowStyleFlag(long style);
313 // bool SortItems(wxListCtrlCompare fn, long data);
315 bool SortItems(PyObject* func) {
316 if (!PyCallable_Check(func))
319 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
325 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
327 PyObject* func = (PyObject*)funcPtr;
328 bool doSave = wxPyRestoreThread();
330 PyObject* args = Py_BuildValue("(ii)", item1, item2);
331 PyObject* result = PyEval_CallObject(func, args);
334 retval = PyInt_AsLong(result);
338 wxPySaveThread(doSave);
344 //----------------------------------------------------------------------
348 wxTreeItemIcon_Normal, // not selected, not expanded
349 wxTreeItemIcon_Selected, // selected, not expanded
350 wxTreeItemIcon_Expanded, // not selected, expanded
351 wxTreeItemIcon_SelectedExpanded, // selected, expanded
356 // constants for HitTest
358 wxTREE_HITTEST_ABOVE,
359 wxTREE_HITTEST_BELOW,
360 wxTREE_HITTEST_NOWHERE,
361 wxTREE_HITTEST_ONITEMBUTTON,
362 wxTREE_HITTEST_ONITEMICON,
363 wxTREE_HITTEST_ONITEMINDENT,
364 wxTREE_HITTEST_ONITEMLABEL,
365 wxTREE_HITTEST_ONITEMRIGHT,
366 wxTREE_HITTEST_ONITEMSTATEICON,
367 wxTREE_HITTEST_TOLEFT,
368 wxTREE_HITTEST_TORIGHT,
369 wxTREE_HITTEST_ONITEMUPPERPART,
370 wxTREE_HITTEST_ONITEMLOWERPART,
371 wxTREE_HITTEST_ONITEM
382 int __cmp__(wxTreeItemId* other) {
383 if (! other) return -1;
384 return *self != *other;
392 class wxPyTreeItemData : public wxTreeItemData {
394 wxPyTreeItemData(PyObject* obj = NULL) {
401 ~wxPyTreeItemData() {
402 bool doSave = wxPyRestoreThread();
404 wxPySaveThread(doSave);
407 PyObject* GetData() {
412 void SetData(PyObject* obj) {
413 bool doSave = wxPyRestoreThread();
415 wxPySaveThread(doSave);
426 %name(wxTreeItemData) class wxPyTreeItemData {
428 wxPyTreeItemData(PyObject* obj = NULL);
431 void SetData(PyObject* obj);
433 const wxTreeItemId& GetId();
434 void SetId(const wxTreeItemId& id);
439 class wxTreeEvent : public wxNotifyEvent {
441 wxTreeItemId GetItem();
442 wxTreeItemId GetOldItem();
445 const wxString& GetLabel();
451 class wxPyTreeCtrl : public wxTreeCtrl {
453 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
457 const wxValidator& validator,
459 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
462 int OnCompareItems(const wxTreeItemId& item1,
463 const wxTreeItemId& item2) {
465 bool doSave = wxPyRestoreThread();
466 if (m_myInst.findCallback("OnCompareItems"))
467 rval = m_myInst.callCallback(Py_BuildValue(
469 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
470 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
472 rval = wxTreeCtrl::OnCompareItems(item1, item2);
473 wxPySaveThread(doSave);
481 // These are for the GetFirstChild/GetNextChild methods below
482 %typemap(python, in) long& INOUT = long* INOUT;
483 %typemap(python, argout) long& INOUT = long* INOUT;
486 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
488 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
489 const wxPoint& pos = wxPyDefaultPosition,
490 const wxSize& size = wxPyDefaultSize,
491 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
492 const wxValidator& validator = wxPyDefaultValidator,
493 char* name = "wxTreeCtrl");
495 void _setSelf(PyObject* self, PyObject* _class);
496 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
497 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxTreeCtrl)"
500 unsigned int GetIndent();
501 void SetIndent(unsigned int indent);
502 wxImageList *GetImageList();
503 wxImageList *GetStateImageList();
504 void SetImageList(wxImageList *imageList/*, int which = wxIMAGE_LIST_NORMAL*/);
505 void SetStateImageList(wxImageList *imageList);
507 unsigned int GetSpacing();
508 void SetSpacing(unsigned int spacing);
510 wxString GetItemText(const wxTreeItemId& item);
511 int GetItemImage(const wxTreeItemId& item,
512 wxTreeItemIcon which = wxTreeItemIcon_Normal);
513 int GetItemSelectedImage(const wxTreeItemId& item);
515 void SetItemText(const wxTreeItemId& item, const wxString& text);
516 void SetItemImage(const wxTreeItemId& item, int image,
517 wxTreeItemIcon which = wxTreeItemIcon_Normal);
518 void SetItemSelectedImage(const wxTreeItemId& item, int image);
519 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
522 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
524 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
525 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
527 data = new wxPyTreeItemData();
528 data->SetId(item); // set the id
529 self->SetItemData(item, data);
534 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
535 data->SetId(item); // set the id
536 self->SetItemData(item, data);
539 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
540 // automatically creating data classes.
541 PyObject* GetPyData(const wxTreeItemId& item) {
542 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
544 data = new wxPyTreeItemData();
545 data->SetId(item); // set the id
546 self->SetItemData(item, data);
548 return data->GetData();
551 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
552 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
554 data = new wxPyTreeItemData(obj);
555 data->SetId(item); // set the id
556 self->SetItemData(item, data);
563 bool IsVisible(const wxTreeItemId& item);
564 bool ItemHasChildren(const wxTreeItemId& item);
565 bool IsExpanded(const wxTreeItemId& item);
566 bool IsSelected(const wxTreeItemId& item);
568 wxTreeItemId GetRootItem();
569 wxTreeItemId GetSelection();
570 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
571 //size_t GetSelections(wxArrayTreeItemIds& selection);
573 PyObject* GetSelections() {
574 bool doSave = wxPyRestoreThread();
575 PyObject* rval = PyList_New(0);
576 wxArrayTreeItemIds array;
578 num = self->GetSelections(array);
579 for (x=0; x < num; x++) {
580 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
581 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
582 PyList_Append(rval, item);
584 wxPySaveThread(doSave);
591 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
593 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
594 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
595 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
596 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
597 wxTreeItemId GetFirstVisibleItem();
598 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
599 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
600 wxTreeItemId GetLastChild(const wxTreeItemId& item);
604 wxTreeItemId AddRoot(const wxString& text,
605 int image = -1, int selectedImage = -1,
606 wxPyTreeItemData *data = NULL);
607 wxTreeItemId PrependItem(const wxTreeItemId& parent,
608 const wxString& text,
609 int image = -1, int selectedImage = -1,
610 wxPyTreeItemData *data = NULL);
611 wxTreeItemId InsertItem(const wxTreeItemId& parent,
612 const wxTreeItemId& idPrevious,
613 const wxString& text,
614 int image = -1, int selectedImage = -1,
615 wxPyTreeItemData *data = NULL);
616 %name(InsertItemBefore)
617 wxTreeItemId InsertItem(const wxTreeItemId& parent,
619 const wxString& text,
620 int image = -1, int selectedImage = -1,
621 wxTreeItemData *data = NULL);
622 wxTreeItemId AppendItem(const wxTreeItemId& parent,
623 const wxString& text,
624 int image = -1, int selectedImage = -1,
625 wxPyTreeItemData *data = NULL);
627 void Delete(const wxTreeItemId& item);
628 void DeleteChildren(const wxTreeItemId& item);
629 void DeleteAllItems();
631 void Expand(const wxTreeItemId& item);
632 void Collapse(const wxTreeItemId& item);
633 void CollapseAndReset(const wxTreeItemId& item);
634 void Toggle(const wxTreeItemId& item);
638 void SelectItem(const wxTreeItemId& item);
639 void EnsureVisible(const wxTreeItemId& item);
640 void ScrollTo(const wxTreeItemId& item);
642 wxTextCtrl* EditLabel(const wxTreeItemId& item);
643 wxTextCtrl* GetEditControl();
644 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
646 void EditLabel(const wxTreeItemId& item);
649 void SortChildren(const wxTreeItemId& item);
651 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
652 bool IsBold(const wxTreeItemId& item) const;
653 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
657 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
658 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
659 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
662 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
664 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
666 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
668 if (self->GetBoundingRect(item, rect, textOnly)) {
669 bool doSave = wxPyRestoreThread();
670 wxRect* r = new wxRect(rect);
671 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
672 wxPySaveThread(doSave);
683 %pragma(python) addtoclass = "
684 # Redefine some methods that SWIG gets a bit confused on...
685 def GetFirstChild(self, *_args, **_kwargs):
686 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
687 val1 = wxTreeItemIdPtr(val1)
690 def GetNextChild(self, *_args, **_kwargs):
691 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
692 val1 = wxTreeItemIdPtr(val1)
695 def HitTest(self, *_args, **_kwargs):
696 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
697 val1 = wxTreeItemIdPtr(val1)
704 //----------------------------------------------------------------------
708 class wxTabEvent : public wxCommandEvent {
714 class wxTabCtrl : public wxControl {
716 wxTabCtrl(wxWindow* parent, wxWindowID id,
717 const wxPoint& pos = wxPyDefaultPosition,
718 const wxSize& size = wxPyDefaultSize,
720 char* name = "tabCtrl");
722 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
724 bool DeleteAllItems();
725 bool DeleteItem(int item);
726 wxImageList* GetImageList();
728 // TODO: void* GetItemData();
729 int GetItemImage(int item);
732 %new wxRect* GetItemRect(int item) {
733 wxRect* rect = new wxRect;
734 self->GetItemRect(item, *rect);
739 wxString GetItemText(int item);
742 int HitTest(const wxPoint& pt, long& OUTPUT);
743 void InsertItem(int item, const wxString& text,
744 int imageId = -1, void* clientData = NULL);
745 // TODO: bool SetItemData(int item, void* data);
746 bool SetItemImage(int item, int image);
747 void SetImageList(wxImageList* imageList);
748 void SetItemSize(const wxSize& size);
749 bool SetItemText(int item, const wxString& text);
750 void SetPadding(const wxSize& padding);
751 int SetSelection(int item);
758 //----------------------------------------------------------------------