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 self->GetItem(*info);
171 %new wxPoint* GetItemPosition(long item) {
172 wxPoint* pos = new wxPoint;
173 self->GetItemPosition(item, *pos);
176 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
177 wxRect* rect= new wxRect;
178 self->GetItemRect(item, *rect, code);
183 int GetItemState(long item, long stateMask);
185 int GetItemSpacing(bool isSmall);
186 wxString GetItemText(long item);
187 long GetNextItem(long item,
188 int geometry = wxLIST_NEXT_ALL,
189 int state = wxLIST_STATE_DONTCARE);
190 int GetSelectedItemCount();
192 wxColour GetTextColour();
193 void SetTextColour(const wxColour& col);
196 long HitTest(const wxPoint& point, int& OUTPUT);
197 %name(InsertColumnWith)long InsertColumn(long col, wxListItem& info);
198 long InsertColumn(long col, const wxString& heading,
199 int format = wxLIST_FORMAT_LEFT,
202 long InsertItem(wxListItem& info);
203 %name(InsertStringItem) long InsertItem(long index, const wxString& label);
204 %name(InsertImageItem) long InsertItem(long index, int imageIndex);
205 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label,
208 bool ScrollList(int dx, int dy);
209 void SetBackgroundColour(const wxColour& col);
210 bool SetColumn(int col, wxListItem& item);
211 bool SetColumnWidth(int col, int width);
212 void SetImageList(wxImageList* imageList, int which);
214 bool SetItem(wxListItem& info);
215 %name(SetStringItem)long SetItem(long index, int col, const wxString& label,
218 bool SetItemData(long item, long data);
219 bool SetItemImage(long item, int image, int selImage);
220 bool SetItemPosition(long item, const wxPoint& pos);
221 bool SetItemState(long item, long state, long stateMask);
222 void SetItemText(long item, const wxString& text);
223 void SetSingleStyle(long style, bool add = TRUE);
224 void SetWindowStyleFlag(long style);
225 // TODO: bool SortItems(wxListCtrlCompare fn, long data);
230 //----------------------------------------------------------------------
234 wxTreeItemIcon_Normal, // not selected, not expanded
235 wxTreeItemIcon_Selected, // selected, not expanded
236 wxTreeItemIcon_Expanded, // not selected, expanded
237 wxTreeItemIcon_SelectedExpanded, // selected, expanded
253 class wxPyTreeItemData : public wxTreeItemData {
255 wxPyTreeItemData(PyObject* obj = NULL) {
262 ~wxPyTreeItemData() {
263 bool doSave = wxPyRestoreThread();
265 wxPySaveThread(doSave);
268 PyObject* GetData() {
273 void SetData(PyObject* obj) {
285 %name(wxTreeItemData) class wxPyTreeItemData {
287 wxPyTreeItemData(PyObject* obj = NULL);
290 void SetData(PyObject* obj);
292 const wxTreeItemId& GetId();
293 void SetId(const wxTreeItemId& id);
298 class wxTreeEvent : public wxNotifyEvent {
300 wxTreeItemId GetItem();
301 wxTreeItemId GetOldItem();
304 const wxString& GetLabel();
308 // These are for the GetFirstChild/GetNextChild methods below
309 %typemap(python, in) long& INOUT = long* INOUT;
310 %typemap(python, argout) long& INOUT = long* INOUT;
313 class wxTreeCtrl : public wxControl {
315 wxTreeCtrl(wxWindow *parent, wxWindowID id = -1,
316 const wxPoint& pos = wxPyDefaultPosition,
317 const wxSize& size = wxPyDefaultSize,
318 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
319 const wxValidator& validator = wxPyDefaultValidator,
320 char* name = "wxTreeCtrl");
322 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
325 unsigned int GetIndent();
326 void SetIndent(unsigned int indent);
327 wxImageList *GetImageList();
328 wxImageList *GetStateImageList();
329 void SetImageList(wxImageList *imageList/*, int which = wxIMAGE_LIST_NORMAL*/);
330 void SetStateImageList(wxImageList *imageList);
332 unsigned int GetSpacing();
333 void SetSpacing(unsigned int spacing);
335 wxString GetItemText(const wxTreeItemId& item);
336 int GetItemImage(const wxTreeItemId& item,
337 wxTreeItemIcon which = wxTreeItemIcon_Normal);
338 int GetItemSelectedImage(const wxTreeItemId& item);
340 void SetItemText(const wxTreeItemId& item, const wxString& text);
341 void SetItemImage(const wxTreeItemId& item, int image,
342 wxTreeItemIcon which = wxTreeItemIcon_Normal);
343 void SetItemSelectedImage(const wxTreeItemId& item, int image);
344 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
347 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
349 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
350 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
352 data = new wxPyTreeItemData();
353 self->SetItemData(item, data);
358 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
359 self->SetItemData(item, data);
362 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
363 // automatically creating data classes.
364 PyObject* GetPyData(const wxTreeItemId& item) {
365 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
367 data = new wxPyTreeItemData();
368 self->SetItemData(item, data);
370 return data->GetData();
373 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
374 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
376 data = new wxPyTreeItemData(obj);
377 self->SetItemData(item, data);
384 bool IsVisible(const wxTreeItemId& item);
385 bool ItemHasChildren(const wxTreeItemId& item);
386 bool IsExpanded(const wxTreeItemId& item);
387 bool IsSelected(const wxTreeItemId& item);
389 wxTreeItemId GetRootItem();
390 wxTreeItemId GetSelection();
391 wxTreeItemId GetParent(const wxTreeItemId& item);
392 //size_t GetSelections(wxArrayTreeItemIds& selection);
394 PyObject* GetSelections() {
395 PyObject* rval = PyList_New(0);
396 wxArrayTreeItemIds array;
398 num = self->GetSelections(array);
399 for (x=0; x < num; x++) {
400 PyObject* item = wxPyConstructObject((void*)&array.Item(x),
402 PyList_Append(rval, item);
410 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
412 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
413 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
414 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
415 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
416 wxTreeItemId GetFirstVisibleItem();
417 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
418 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
419 wxTreeItemId GetLastChild(const wxTreeItemId& item);
423 wxTreeItemId AddRoot(const wxString& text,
424 int image = -1, int selectedImage = -1,
425 wxPyTreeItemData *data = NULL);
426 wxTreeItemId PrependItem(const wxTreeItemId& parent,
427 const wxString& text,
428 int image = -1, int selectedImage = -1,
429 wxPyTreeItemData *data = NULL);
430 wxTreeItemId InsertItem(const wxTreeItemId& parent,
431 const wxTreeItemId& idPrevious,
432 const wxString& text,
433 int image = -1, int selectedImage = -1,
434 wxPyTreeItemData *data = NULL);
435 wxTreeItemId AppendItem(const wxTreeItemId& parent,
436 const wxString& text,
437 int image = -1, int selectedImage = -1,
438 wxPyTreeItemData *data = NULL);
440 void Delete(const wxTreeItemId& item);
441 void DeleteChildren(const wxTreeItemId& item);
442 void DeleteAllItems();
444 void Expand(const wxTreeItemId& item);
445 void Collapse(const wxTreeItemId& item);
446 void CollapseAndReset(const wxTreeItemId& item);
447 void Toggle(const wxTreeItemId& item);
451 void SelectItem(const wxTreeItemId& item);
452 void EnsureVisible(const wxTreeItemId& item);
453 void ScrollTo(const wxTreeItemId& item);
455 wxTextCtrl* EditLabel(const wxTreeItemId& item);
456 wxTextCtrl* GetEditControl();
457 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
459 void EditLabel(const wxTreeItemId& item);
462 void SortChildren(const wxTreeItemId& item);
464 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
465 bool IsBold(const wxTreeItemId& item) const;
466 wxTreeItemId HitTest(const wxPoint& point);
469 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
471 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
473 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
475 if (self->GetBoundingRect(item, rect, textOnly))
476 return wxPyConstructObject((void*)&rect, "wxRect");
485 %pragma(python) addtoclass = "
486 # Redefine a couple methods that SWIG gets a bit confused on...
487 def GetFirstChild(self,arg0,arg1):
488 val1, val2 = controls2c.wxTreeCtrl_GetFirstChild(self.this,arg0.this,arg1)
489 val1 = wxTreeItemIdPtr(val1)
492 def GetNextChild(self,arg0,arg1):
493 val1, val2 = controls2c.wxTreeCtrl_GetNextChild(self.this,arg0.this,arg1)
494 val1 = wxTreeItemIdPtr(val1)
501 //----------------------------------------------------------------------
505 class wxTabEvent : public wxCommandEvent {
511 class wxTabCtrl : public wxControl {
513 wxTabCtrl(wxWindow* parent, wxWindowID id,
514 const wxPoint& pos = wxPyDefaultPosition,
515 const wxSize& size = wxPyDefaultSize,
517 char* name = "tabCtrl");
519 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
521 bool DeleteAllItems();
522 bool DeleteItem(int item);
523 wxImageList* GetImageList();
525 // TODO: void* GetItemData();
526 int GetItemImage(int item);
529 %new wxRect* GetItemRect(int item) {
530 wxRect* rect = new wxRect;
531 self->GetItemRect(item, *rect);
536 wxString GetItemText(int item);
539 int HitTest(const wxPoint& pt, long& OUTPUT);
540 void InsertItem(int item, const wxString& text,
541 int imageId = -1, void* clientData = NULL);
542 // TODO: bool SetItemData(int item, void* data);
543 bool SetItemImage(int item, int image);
544 void SetImageList(wxImageList* imageList);
545 void SetItemSize(const wxSize& size);
546 bool SetItemText(int item, const wxString& text);
547 void SetPadding(const wxSize& padding);
548 int SetSelection(int item);
555 //----------------------------------------------------------------------