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 //----------------------------------------------------------------------
49 wxLIST_STATE_DONTCARE,
50 wxLIST_STATE_DROPHILITED,
52 wxLIST_STATE_SELECTED,
56 wxLIST_HITTEST_NOWHERE,
57 wxLIST_HITTEST_ONITEMICON,
58 wxLIST_HITTEST_ONITEMLABEL,
59 wxLIST_HITTEST_ONITEMRIGHT,
60 wxLIST_HITTEST_ONITEMSTATEICON,
61 wxLIST_HITTEST_TOLEFT,
62 wxLIST_HITTEST_TORIGHT,
63 wxLIST_HITTEST_ONITEM,
72 wxLIST_ALIGN_SNAP_TO_GRID,
74 wxLIST_AUTOSIZE_USEHEADER,
85 enum wxListColumnFormat
90 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
99 //wxListItemAttr(const wxColour& colText,
100 // const wxColour& colBack,
101 // const wxFont& font)
102 // : m_colText(colText), m_colBack(colBack), m_font(font) { }
105 void SetTextColour(const wxColour& colText);
106 void SetBackgroundColour(const wxColour& colBack);
107 void SetFont(const wxFont& font);
110 bool HasTextColour();
111 bool HasBackgroundColour();
114 const wxColour& GetTextColour();
115 const wxColour& GetBackgroundColour();
116 const wxFont& GetFont();
127 void ClearAttributes();
130 void SetMask(long mask);
132 void SetColumn(int col);
133 void SetState(long state);
134 void SetStateMask(long stateMask);
135 void SetText(const wxString& text);
136 void SetImage(int image);
137 void SetData(long data);
139 void SetWidth(int width);
140 void SetAlign(wxListColumnFormat align);
142 void SetTextColour(const wxColour& colText);
143 void SetBackgroundColour(const wxColour& colBack);
144 void SetFont(const wxFont& font);
151 const wxString& GetText();
156 wxListColumnFormat GetAlign();
158 wxListItemAttr *GetAttributes();
159 bool HasAttributes();
161 wxColour GetTextColour() const;
162 wxColour GetBackgroundColour() const;
163 wxFont GetFont() const;
165 // these members are public for compatibility
166 long m_mask; // Indicates what fields are valid
167 long m_itemId; // The zero-based item position
168 int m_col; // Zero-based column, if in report mode
169 long m_state; // The state of the item
170 long m_stateMask;// Which flags of m_state are valid (uses same flags)
171 wxString m_text; // The label/header text
172 int m_image; // The zero-based index into an image list
173 long m_data; // App-defined data
176 int m_format; // left, right, centre
177 int m_width; // width of column
182 class wxListEvent: public wxNotifyEvent {
199 const wxString& GetLabel();
200 const wxString& GetText();
204 const wxListItem& GetItem();
209 class wxListCtrl : public wxControl {
211 wxListCtrl(wxWindow* parent, wxWindowID id,
212 const wxPoint& pos = wxDefaultPosition,
213 const wxSize& size = wxDefaultSize,
214 long style = wxLC_ICON,
215 const wxValidator& validator = wxDefaultValidator,
216 char* name = "listCtrl");
218 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
220 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
221 bool DeleteItem(long item);
222 bool DeleteAllItems();
223 bool DeleteColumn(int col);
224 bool DeleteAllColumns(void);
227 wxTextCtrl* EditLabel(long item);
228 bool EndEditLabel(bool cancel);
229 wxTextCtrl* GetEditControl();
231 void EditLabel(long item);
233 bool EnsureVisible(long item);
234 long FindItem(long start, const wxString& str, bool partial = FALSE);
235 %name(FindItemData)long FindItem(long start, long data);
236 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt,
238 bool GetColumn(int col, wxListItem& item);
239 int GetColumnWidth(int col);
240 int GetCountPerPage();
241 wxImageList* GetImageList(int which);
242 long GetItemData(long item);
245 %new wxListItem* GetItem(long itemId, int col=0) {
246 wxListItem* info = new wxListItem;
247 info->m_itemId = itemId;
249 info->m_mask = 0xFFFF;
250 self->GetItem(*info);
253 %new wxPoint* GetItemPosition(long item) {
254 wxPoint* pos = new wxPoint;
255 self->GetItemPosition(item, *pos);
258 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
259 wxRect* rect= new wxRect;
260 self->GetItemRect(item, *rect, code);
265 int GetItemState(long item, long stateMask);
267 int GetItemSpacing(bool isSmall);
268 wxString GetItemText(long item);
269 long GetNextItem(long item,
270 int geometry = wxLIST_NEXT_ALL,
271 int state = wxLIST_STATE_DONTCARE);
272 int GetSelectedItemCount();
274 wxColour GetTextColour();
275 void SetTextColour(const wxColour& col);
278 long HitTest(const wxPoint& point, int& OUTPUT);
279 %name(InsertColumnInfo)long InsertColumn(long col, wxListItem& info);
280 long InsertColumn(long col, const wxString& heading,
281 int format = wxLIST_FORMAT_LEFT,
284 long InsertItem(wxListItem& info);
285 %name(InsertStringItem) long InsertItem(long index, const wxString& label);
286 %name(InsertImageItem) long InsertItem(long index, int imageIndex);
287 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label,
290 bool ScrollList(int dx, int dy);
291 void SetBackgroundColour(const wxColour& col);
292 bool SetColumn(int col, wxListItem& item);
293 bool SetColumnWidth(int col, int width);
294 void SetImageList(wxImageList* imageList, int which);
296 bool SetItem(wxListItem& info);
297 %name(SetStringItem)long SetItem(long index, int col, const wxString& label,
300 bool SetItemData(long item, long data);
301 bool SetItemImage(long item, int image, int selImage);
302 bool SetItemPosition(long item, const wxPoint& pos);
303 bool SetItemState(long item, long state, long stateMask);
304 void SetItemText(long item, const wxString& text);
305 void SetSingleStyle(long style, bool add = TRUE);
306 void SetWindowStyleFlag(long style);
308 // bool SortItems(wxListCtrlCompare fn, long data);
310 bool SortItems(PyObject* func) {
311 if (!PyCallable_Check(func))
314 return self->SortItems(wxPyListCtrl_SortItems, (long)func);
320 int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
322 PyObject* func = (PyObject*)funcPtr;
323 bool doSave = wxPyRestoreThread();
325 PyObject* args = Py_BuildValue("(ii)", item1, item2);
326 PyObject* result = PyEval_CallObject(func, args);
329 retval = PyInt_AsLong(result);
333 wxPySaveThread(doSave);
339 //----------------------------------------------------------------------
343 wxTreeItemIcon_Normal, // not selected, not expanded
344 wxTreeItemIcon_Selected, // selected, not expanded
345 wxTreeItemIcon_Expanded, // not selected, expanded
346 wxTreeItemIcon_SelectedExpanded, // selected, expanded
351 // constants for HitTest
353 wxTREE_HITTEST_ABOVE,
354 wxTREE_HITTEST_BELOW,
355 wxTREE_HITTEST_NOWHERE,
356 wxTREE_HITTEST_ONITEMBUTTON,
357 wxTREE_HITTEST_ONITEMICON,
358 wxTREE_HITTEST_ONITEMINDENT,
359 wxTREE_HITTEST_ONITEMLABEL,
360 wxTREE_HITTEST_ONITEMRIGHT,
361 wxTREE_HITTEST_ONITEMSTATEICON,
362 wxTREE_HITTEST_TOLEFT,
363 wxTREE_HITTEST_TORIGHT,
364 wxTREE_HITTEST_ONITEMUPPERPART,
365 wxTREE_HITTEST_ONITEMLOWERPART,
366 wxTREE_HITTEST_ONITEM
377 int __cmp__(wxTreeItemId* other) {
378 if (! other) return -1;
379 return *self != *other;
387 class wxPyTreeItemData : public wxTreeItemData {
389 wxPyTreeItemData(PyObject* obj = NULL) {
396 ~wxPyTreeItemData() {
397 bool doSave = wxPyRestoreThread();
399 wxPySaveThread(doSave);
402 PyObject* GetData() {
407 void SetData(PyObject* obj) {
408 bool doSave = wxPyRestoreThread();
410 wxPySaveThread(doSave);
421 %name(wxTreeItemData) class wxPyTreeItemData {
423 wxPyTreeItemData(PyObject* obj = NULL);
426 void SetData(PyObject* obj);
428 const wxTreeItemId& GetId();
429 void SetId(const wxTreeItemId& id);
434 class wxTreeEvent : public wxNotifyEvent {
436 wxTreeItemId GetItem();
437 wxTreeItemId GetOldItem();
440 const wxString& GetLabel();
446 class wxPyTreeCtrl : public wxTreeCtrl {
448 wxPyTreeCtrl(wxWindow *parent, wxWindowID id,
452 const wxValidator& validator,
454 wxTreeCtrl(parent, id, pos, size, style, validator, name) {}
457 int OnCompareItems(const wxTreeItemId& item1,
458 const wxTreeItemId& item2) {
460 bool doSave = wxPyRestoreThread();
461 if (m_myInst.findCallback("OnCompareItems"))
462 rval = m_myInst.callCallback(Py_BuildValue(
464 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
465 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
467 rval = wxTreeCtrl::OnCompareItems(item1, item2);
468 wxPySaveThread(doSave);
476 // These are for the GetFirstChild/GetNextChild methods below
477 %typemap(python, in) long& INOUT = long* INOUT;
478 %typemap(python, argout) long& INOUT = long* INOUT;
481 %name(wxTreeCtrl)class wxPyTreeCtrl : public wxControl {
483 wxPyTreeCtrl(wxWindow *parent, wxWindowID id = -1,
484 const wxPoint& pos = wxDefaultPosition,
485 const wxSize& size = wxDefaultSize,
486 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
487 const wxValidator& validator = wxDefaultValidator,
488 char* name = "wxTreeCtrl");
490 void _setSelf(PyObject* self, PyObject* _class);
491 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
492 %pragma(python) addtomethod = "__init__:self._setSelf(self, wxTreeCtrl)"
495 unsigned int GetIndent();
496 void SetIndent(unsigned int indent);
497 wxImageList *GetImageList();
498 wxImageList *GetStateImageList();
499 void SetImageList(wxImageList *imageList/*, int which = wxIMAGE_LIST_NORMAL*/);
500 void SetStateImageList(wxImageList *imageList);
502 unsigned int GetSpacing();
503 void SetSpacing(unsigned int spacing);
505 wxString GetItemText(const wxTreeItemId& item);
506 int GetItemImage(const wxTreeItemId& item,
507 wxTreeItemIcon which = wxTreeItemIcon_Normal);
508 int GetItemSelectedImage(const wxTreeItemId& item);
510 void SetItemText(const wxTreeItemId& item, const wxString& text);
511 void SetItemImage(const wxTreeItemId& item, int image,
512 wxTreeItemIcon which = wxTreeItemIcon_Normal);
513 void SetItemSelectedImage(const wxTreeItemId& item, int image);
514 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
517 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
519 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
520 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
522 data = new wxPyTreeItemData();
523 data->SetId(item); // set the id
524 self->SetItemData(item, data);
529 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
530 data->SetId(item); // set the id
531 self->SetItemData(item, data);
534 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
535 // automatically creating data classes.
536 PyObject* GetPyData(const wxTreeItemId& item) {
537 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
539 data = new wxPyTreeItemData();
540 data->SetId(item); // set the id
541 self->SetItemData(item, data);
543 return data->GetData();
546 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
547 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
549 data = new wxPyTreeItemData(obj);
550 data->SetId(item); // set the id
551 self->SetItemData(item, data);
558 bool IsVisible(const wxTreeItemId& item);
559 bool ItemHasChildren(const wxTreeItemId& item);
560 bool IsExpanded(const wxTreeItemId& item);
561 bool IsSelected(const wxTreeItemId& item);
563 wxTreeItemId GetRootItem();
564 wxTreeItemId GetSelection();
565 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
566 //size_t GetSelections(wxArrayTreeItemIds& selection);
568 PyObject* GetSelections() {
569 bool doSave = wxPyRestoreThread();
570 PyObject* rval = PyList_New(0);
571 wxArrayTreeItemIds array;
573 num = self->GetSelections(array);
574 for (x=0; x < num; x++) {
575 wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
576 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
577 PyList_Append(rval, item);
579 wxPySaveThread(doSave);
586 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
588 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
589 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
590 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
591 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
592 wxTreeItemId GetFirstVisibleItem();
593 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
594 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
595 wxTreeItemId GetLastChild(const wxTreeItemId& item);
599 wxTreeItemId AddRoot(const wxString& text,
600 int image = -1, int selectedImage = -1,
601 wxPyTreeItemData *data = NULL);
602 wxTreeItemId PrependItem(const wxTreeItemId& parent,
603 const wxString& text,
604 int image = -1, int selectedImage = -1,
605 wxPyTreeItemData *data = NULL);
606 wxTreeItemId InsertItem(const wxTreeItemId& parent,
607 const wxTreeItemId& idPrevious,
608 const wxString& text,
609 int image = -1, int selectedImage = -1,
610 wxPyTreeItemData *data = NULL);
611 %name(InsertItemBefore)
612 wxTreeItemId InsertItem(const wxTreeItemId& parent,
614 const wxString& text,
615 int image = -1, int selectedImage = -1,
616 wxTreeItemData *data = NULL);
617 wxTreeItemId AppendItem(const wxTreeItemId& parent,
618 const wxString& text,
619 int image = -1, int selectedImage = -1,
620 wxPyTreeItemData *data = NULL);
622 void Delete(const wxTreeItemId& item);
623 void DeleteChildren(const wxTreeItemId& item);
624 void DeleteAllItems();
626 void Expand(const wxTreeItemId& item);
627 void Collapse(const wxTreeItemId& item);
628 void CollapseAndReset(const wxTreeItemId& item);
629 void Toggle(const wxTreeItemId& item);
633 void SelectItem(const wxTreeItemId& item);
634 void EnsureVisible(const wxTreeItemId& item);
635 void ScrollTo(const wxTreeItemId& item);
637 wxTextCtrl* EditLabel(const wxTreeItemId& item);
638 wxTextCtrl* GetEditControl();
639 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
641 void EditLabel(const wxTreeItemId& item);
644 void SortChildren(const wxTreeItemId& item);
646 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
647 bool IsBold(const wxTreeItemId& item) const;
648 wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT);
652 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
653 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
654 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
657 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
659 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
661 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
663 if (self->GetBoundingRect(item, rect, textOnly)) {
664 bool doSave = wxPyRestoreThread();
665 wxRect* r = new wxRect(rect);
666 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
667 wxPySaveThread(doSave);
678 %pragma(python) addtoclass = "
679 # Redefine some methods that SWIG gets a bit confused on...
680 def GetFirstChild(self, *_args, **_kwargs):
681 val1,val2 = apply(controls2c.wxTreeCtrl_GetFirstChild,(self,) + _args, _kwargs)
682 val1 = wxTreeItemIdPtr(val1)
685 def GetNextChild(self, *_args, **_kwargs):
686 val1,val2 = apply(controls2c.wxTreeCtrl_GetNextChild,(self,) + _args, _kwargs)
687 val1 = wxTreeItemIdPtr(val1)
690 def HitTest(self, *_args, **_kwargs):
691 val1, val2 = apply(controls2c.wxTreeCtrl_HitTest,(self,) + _args, _kwargs)
692 val1 = wxTreeItemIdPtr(val1)
699 //----------------------------------------------------------------------
703 class wxTabEvent : public wxCommandEvent {
709 class wxTabCtrl : public wxControl {
711 wxTabCtrl(wxWindow* parent, wxWindowID id,
712 const wxPoint& pos = wxDefaultPosition,
713 const wxSize& size = wxDefaultSize,
715 char* name = "tabCtrl");
717 %pragma(python) addtomethod = "__init__:#wx._StdWindowCallbacks(self)"
719 bool DeleteAllItems();
720 bool DeleteItem(int item);
721 wxImageList* GetImageList();
723 // TODO: void* GetItemData();
724 int GetItemImage(int item);
727 %new wxRect* GetItemRect(int item) {
728 wxRect* rect = new wxRect;
729 self->GetItemRect(item, *rect);
734 wxString GetItemText(int item);
737 int HitTest(const wxPoint& pt, long& OUTPUT);
738 void InsertItem(int item, const wxString& text,
739 int imageId = -1, void* clientData = NULL);
740 // TODO: bool SetItemData(int item, void* data);
741 bool SetItemImage(int item, int image);
742 void SetImageList(wxImageList* imageList);
743 void SetItemSize(const wxSize& size);
744 bool SetItemText(int item, const wxString& text);
745 void SetPadding(const wxSize& padding);
746 int SetSelection(int item);
753 //----------------------------------------------------------------------