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,
83 wxLIST_AUTOSIZE_USEHEADER,
96 long m_mask; // Indicates what fields are valid
97 long m_itemId; // The zero-based item position
98 int m_col; // Zero-based column, if in report mode
99 long m_state; // The state of the item
100 long m_stateMask; // Which flags of m_state are valid (uses same flags)
101 wxString m_text; // The label/header text
102 int m_image; // The zero-based index into an image list
103 long m_data; // App-defined data
104 // wxColour *m_colour; // only wxGLC, not supported by Windows ;->
107 int m_format; // left, right, centre
108 int m_width; // width of column
114 class wxListEvent: public wxCommandEvent {
128 class wxListCtrl : public wxControl {
130 wxListCtrl(wxWindow* parent, wxWindowID id,
131 const wxPoint& pos = wxPyDefaultPosition,
132 const wxSize& size = wxPyDefaultSize,
133 long style = wxLC_ICON,
134 const wxValidator& validator = wxPyDefaultValidator,
135 char* name = "listCtrl");
137 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
139 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
140 bool DeleteItem(long item);
141 bool DeleteAllItems();
142 bool DeleteColumn(int col);
143 bool DeleteAllColumns(void);
146 wxTextCtrl* EditLabel(long item);
147 bool EndEditLabel(bool cancel);
148 wxTextCtrl* GetEditControl();
150 void EditLabel(long item);
152 bool EnsureVisible(long item);
153 long FindItem(long start, const wxString& str, bool partial = FALSE);
154 %name(FindItemData)long FindItem(long start, long data);
155 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt,
157 bool GetColumn(int col, wxListItem& item);
158 int GetColumnWidth(int col);
159 int GetCountPerPage();
160 wxImageList* GetImageList(int which);
161 long GetItemData(long item);
164 %new wxListItem* GetItem(long itemId, int col=0) {
165 wxListItem* info = new wxListItem;
166 info->m_itemId = itemId;
168 info->m_mask = 0xFFFF;
169 self->GetItem(*info);
172 %new wxPoint* GetItemPosition(long item) {
173 wxPoint* pos = new wxPoint;
174 self->GetItemPosition(item, *pos);
177 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
178 wxRect* rect= new wxRect;
179 self->GetItemRect(item, *rect, code);
184 int GetItemState(long item, long stateMask);
186 int GetItemSpacing(bool isSmall);
187 wxString GetItemText(long item);
188 long GetNextItem(long item,
189 int geometry = wxLIST_NEXT_ALL,
190 int state = wxLIST_STATE_DONTCARE);
191 int GetSelectedItemCount();
193 wxColour GetTextColour();
194 void SetTextColour(const wxColour& col);
197 long HitTest(const wxPoint& point, int& OUTPUT);
198 %name(InsertColumnWith)long InsertColumn(long col, wxListItem& info);
199 long InsertColumn(long col, const wxString& heading,
200 int format = wxLIST_FORMAT_LEFT,
203 long InsertItem(wxListItem& info);
204 %name(InsertStringItem) long InsertItem(long index, const wxString& label);
205 %name(InsertImageItem) long InsertItem(long index, int imageIndex);
206 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label,
209 bool ScrollList(int dx, int dy);
210 void SetBackgroundColour(const wxColour& col);
211 bool SetColumn(int col, wxListItem& item);
212 bool SetColumnWidth(int col, int width);
213 void SetImageList(wxImageList* imageList, int which);
215 bool SetItem(wxListItem& info);
216 %name(SetStringItem)long SetItem(long index, int col, const wxString& label,
219 bool SetItemData(long item, long data);
220 bool SetItemImage(long item, int image, int selImage);
221 bool SetItemPosition(long item, const wxPoint& pos);
222 bool SetItemState(long item, long state, long stateMask);
223 void SetItemText(long item, const wxString& text);
224 void SetSingleStyle(long style, bool add = TRUE);
225 void SetWindowStyleFlag(long style);
226 // TODO: bool SortItems(wxListCtrlCompare fn, long data);
231 //----------------------------------------------------------------------
235 wxTreeItemIcon_Normal, // not selected, not expanded
236 wxTreeItemIcon_Selected, // selected, not expanded
237 wxTreeItemIcon_Expanded, // not selected, expanded
238 wxTreeItemIcon_SelectedExpanded, // selected, expanded
254 class wxPyTreeItemData : public wxTreeItemData {
256 wxPyTreeItemData(PyObject* obj = NULL) {
263 ~wxPyTreeItemData() {
264 bool doSave = wxPyRestoreThread();
266 wxPySaveThread(doSave);
269 PyObject* GetData() {
274 void SetData(PyObject* obj) {
286 %name(wxTreeItemData) class wxPyTreeItemData {
288 wxPyTreeItemData(PyObject* obj = NULL);
291 void SetData(PyObject* obj);
293 const wxTreeItemId& GetId();
294 void SetId(const wxTreeItemId& id);
299 class wxTreeEvent : public wxNotifyEvent {
301 wxTreeItemId GetItem();
302 wxTreeItemId GetOldItem();
305 const wxString& GetLabel();
309 // These are for the GetFirstChild/GetNextChild methods below
310 %typemap(python, in) long& INOUT = long* INOUT;
311 %typemap(python, argout) long& INOUT = long* INOUT;
314 class wxTreeCtrl : public wxControl {
316 wxTreeCtrl(wxWindow *parent, wxWindowID id = -1,
317 const wxPoint& pos = wxPyDefaultPosition,
318 const wxSize& size = wxPyDefaultSize,
319 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
320 const wxValidator& validator = wxPyDefaultValidator,
321 char* name = "wxTreeCtrl");
323 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
326 unsigned int GetIndent();
327 void SetIndent(unsigned int indent);
328 wxImageList *GetImageList();
329 wxImageList *GetStateImageList();
330 void SetImageList(wxImageList *imageList/*, int which = wxIMAGE_LIST_NORMAL*/);
331 void SetStateImageList(wxImageList *imageList);
333 unsigned int GetSpacing();
334 void SetSpacing(unsigned int spacing);
336 wxString GetItemText(const wxTreeItemId& item);
337 int GetItemImage(const wxTreeItemId& item,
338 wxTreeItemIcon which = wxTreeItemIcon_Normal);
339 int GetItemSelectedImage(const wxTreeItemId& item);
341 void SetItemText(const wxTreeItemId& item, const wxString& text);
342 void SetItemImage(const wxTreeItemId& item, int image,
343 wxTreeItemIcon which = wxTreeItemIcon_Normal);
344 void SetItemSelectedImage(const wxTreeItemId& item, int image);
345 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
348 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
350 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
351 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
353 data = new wxPyTreeItemData();
354 self->SetItemData(item, data);
359 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
360 self->SetItemData(item, data);
363 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
364 // automatically creating data classes.
365 PyObject* GetPyData(const wxTreeItemId& item) {
366 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
368 data = new wxPyTreeItemData();
369 self->SetItemData(item, data);
371 return data->GetData();
374 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
375 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
377 data = new wxPyTreeItemData(obj);
378 self->SetItemData(item, data);
385 bool IsVisible(const wxTreeItemId& item);
386 bool ItemHasChildren(const wxTreeItemId& item);
387 bool IsExpanded(const wxTreeItemId& item);
388 bool IsSelected(const wxTreeItemId& item);
390 wxTreeItemId GetRootItem();
391 wxTreeItemId GetSelection();
392 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
393 //size_t GetSelections(wxArrayTreeItemIds& selection);
395 PyObject* GetSelections() {
396 PyObject* rval = PyList_New(0);
397 wxArrayTreeItemIds array;
399 num = self->GetSelections(array);
400 for (x=0; x < num; x++) {
401 PyObject* item = wxPyConstructObject((void*)&array.Item(x),
403 PyList_Append(rval, item);
411 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
413 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
414 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
415 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
416 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
417 wxTreeItemId GetFirstVisibleItem();
418 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
419 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
420 wxTreeItemId GetLastChild(const wxTreeItemId& item);
424 wxTreeItemId AddRoot(const wxString& text,
425 int image = -1, int selectedImage = -1,
426 wxPyTreeItemData *data = NULL);
427 wxTreeItemId PrependItem(const wxTreeItemId& parent,
428 const wxString& text,
429 int image = -1, int selectedImage = -1,
430 wxPyTreeItemData *data = NULL);
431 wxTreeItemId InsertItem(const wxTreeItemId& parent,
432 const wxTreeItemId& idPrevious,
433 const wxString& text,
434 int image = -1, int selectedImage = -1,
435 wxPyTreeItemData *data = NULL);
436 wxTreeItemId AppendItem(const wxTreeItemId& parent,
437 const wxString& text,
438 int image = -1, int selectedImage = -1,
439 wxPyTreeItemData *data = NULL);
441 void Delete(const wxTreeItemId& item);
442 void DeleteChildren(const wxTreeItemId& item);
443 void DeleteAllItems();
445 void Expand(const wxTreeItemId& item);
446 void Collapse(const wxTreeItemId& item);
447 void CollapseAndReset(const wxTreeItemId& item);
448 void Toggle(const wxTreeItemId& item);
452 void SelectItem(const wxTreeItemId& item);
453 void EnsureVisible(const wxTreeItemId& item);
454 void ScrollTo(const wxTreeItemId& item);
456 wxTextCtrl* EditLabel(const wxTreeItemId& item);
457 wxTextCtrl* GetEditControl();
458 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
460 void EditLabel(const wxTreeItemId& item);
463 void SortChildren(const wxTreeItemId& item);
465 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
466 bool IsBold(const wxTreeItemId& item) const;
467 wxTreeItemId HitTest(const wxPoint& point);
470 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
472 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
474 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
476 if (self->GetBoundingRect(item, rect, textOnly))
477 return wxPyConstructObject((void*)&rect, "wxRect");
486 %pragma(python) addtoclass = "
487 # Redefine a couple methods that SWIG gets a bit confused on...
488 def GetFirstChild(self,arg0,arg1):
489 val1, val2 = controls2c.wxTreeCtrl_GetFirstChild(self.this,arg0.this,arg1)
490 val1 = wxTreeItemIdPtr(val1)
493 def GetNextChild(self,arg0,arg1):
494 val1, val2 = controls2c.wxTreeCtrl_GetNextChild(self.this,arg0.this,arg1)
495 val1 = wxTreeItemIdPtr(val1)
502 //----------------------------------------------------------------------
506 class wxTabEvent : public wxCommandEvent {
512 class wxTabCtrl : public wxControl {
514 wxTabCtrl(wxWindow* parent, wxWindowID id,
515 const wxPoint& pos = wxPyDefaultPosition,
516 const wxSize& size = wxPyDefaultSize,
518 char* name = "tabCtrl");
520 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
522 bool DeleteAllItems();
523 bool DeleteItem(int item);
524 wxImageList* GetImageList();
526 // TODO: void* GetItemData();
527 int GetItemImage(int item);
530 %new wxRect* GetItemRect(int item) {
531 wxRect* rect = new wxRect;
532 self->GetItemRect(item, *rect);
537 wxString GetItemText(int item);
540 int HitTest(const wxPoint& pt, long& OUTPUT);
541 void InsertItem(int item, const wxString& text,
542 int imageId = -1, void* clientData = NULL);
543 // TODO: bool SetItemData(int item, void* data);
544 bool SetItemImage(int item, int image);
545 void SetImageList(wxImageList* imageList);
546 void SetItemSize(const wxSize& size);
547 bool SetItemText(int item, const wxString& text);
548 void SetPadding(const wxSize& padding);
549 int SetSelection(int item);
556 //----------------------------------------------------------------------