1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: More control (widget) classes for wxPython
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
17 #include <wx/listctrl.h>
18 #include <wx/treectrl.h>
21 //----------------------------------------------------------------------
24 %include my_typemaps.i
26 // Import some definitions of other classes, etc.
34 %pragma(python) code = "import wx"
36 //----------------------------------------------------------------------
39 extern wxValidator wxPyDefaultValidator;
42 //----------------------------------------------------------------------
51 wxLIST_STATE_DONTCARE,
52 wxLIST_STATE_DROPHILITED,
54 wxLIST_STATE_SELECTED,
58 wxLIST_HITTEST_NOWHERE,
59 wxLIST_HITTEST_ONITEMICON,
60 wxLIST_HITTEST_ONITEMLABEL,
61 wxLIST_HITTEST_ONITEMRIGHT,
62 wxLIST_HITTEST_ONITEMSTATEICON,
63 wxLIST_HITTEST_TOLEFT,
64 wxLIST_HITTEST_TORIGHT,
65 wxLIST_HITTEST_ONITEM,
74 wxLIST_ALIGN_SNAP_TO_GRID,
80 wxLIST_AUTOSIZE_USEHEADER,
93 long m_mask; // Indicates what fields are valid
94 long m_itemId; // The zero-based item position
95 int m_col; // Zero-based column, if in report mode
96 long m_state; // The state of the item
97 long m_stateMask; // Which flags of m_state are valid (uses same flags)
98 wxString m_text; // The label/header text
99 int m_image; // The zero-based index into an image list
100 long m_data; // App-defined data
101 // wxColour *m_colour; // only wxGLC, not supported by Windows ;->
104 int m_format; // left, right, centre
105 int m_width; // width of column
111 class wxListEvent: public wxCommandEvent {
125 class wxListCtrl : public wxControl {
127 wxListCtrl(wxWindow* parent, wxWindowID id,
128 const wxPoint& pos = wxPyDefaultPosition,
129 const wxSize& size = wxPyDefaultSize,
130 long style = wxLC_ICON,
131 const wxValidator& validator = wxPyDefaultValidator,
132 char* name = "listCtrl");
134 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
136 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
137 bool DeleteItem(long item);
138 bool DeleteAllItems();
139 bool DeleteColumn(int col);
140 bool DeleteAllColumns(void);
143 wxTextCtrl* EditLabel(long item);
144 bool EndEditLabel(bool cancel);
145 wxTextCtrl* GetEditControl();
147 void EditLabel(long item);
149 bool EnsureVisible(long item);
150 long FindItem(long start, const wxString& str, bool partial = FALSE);
151 %name(FindItemData)long FindItem(long start, long data);
152 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt,
154 bool GetColumn(int col, wxListItem& item);
155 int GetColumnWidth(int col);
156 int GetCountPerPage();
157 wxImageList* GetImageList(int which);
158 long GetItemData(long item);
161 %new wxListItem* GetItem(long itemId) {
162 wxListItem* info = new wxListItem;
163 info->m_itemId = itemId;
164 self->GetItem(*info);
167 %new wxPoint* GetItemPosition(long item) {
168 wxPoint* pos = new wxPoint;
169 self->GetItemPosition(item, *pos);
172 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
173 wxRect* rect= new wxRect;
174 self->GetItemRect(item, *rect, code);
179 int GetItemState(long item, long stateMask);
181 int GetItemSpacing(bool isSmall);
182 wxString GetItemText(long item);
183 long GetNextItem(long item,
184 int geometry = wxLIST_NEXT_ALL,
185 int state = wxLIST_STATE_DONTCARE);
186 int GetSelectedItemCount();
188 wxColour GetTextColour();
189 void SetTextColour(const wxColour& col);
192 long HitTest(const wxPoint& point, int& OUTPUT);
193 %name(InsertColumnWith)long InsertColumn(long col, wxListItem& info);
194 long InsertColumn(long col, const wxString& heading,
195 int format = wxLIST_FORMAT_LEFT,
198 long InsertItem(wxListItem& info);
199 %name(InsertStringItem) long InsertItem(long index, const wxString& label);
200 %name(InsertImageItem) long InsertItem(long index, int imageIndex);
201 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label,
204 bool ScrollList(int dx, int dy);
205 void SetBackgroundColour(const wxColour& col);
206 bool SetColumn(int col, wxListItem& item);
207 bool SetColumnWidth(int col, int width);
208 void SetImageList(wxImageList* imageList, int which);
210 bool SetItem(wxListItem& info);
211 %name(SetStringItem)long SetItem(long index, int col, const wxString& label,
214 bool SetItemData(long item, long data);
215 bool SetItemImage(long item, int image, int selImage);
216 bool SetItemPosition(long item, const wxPoint& pos);
217 bool SetItemState(long item, long state, long stateMask);
218 void SetItemText(long item, const wxString& text);
219 void SetSingleStyle(long style, bool add = TRUE);
220 void SetWindowStyleFlag(long style);
221 // TODO: bool SortItems(wxListCtrlCompare fn, long data);
226 //----------------------------------------------------------------------
240 class wxPyTreeItemData : public wxTreeItemData {
242 wxPyTreeItemData(PyObject* obj = NULL) {
249 ~wxPyTreeItemData() {
250 bool doSave = wxPyRestoreThread();
252 wxPySaveThread(doSave);
255 PyObject* GetData() {
260 void SetData(PyObject* obj) {
272 %name(wxTreeItemData) class wxPyTreeItemData {
274 wxPyTreeItemData(PyObject* obj = NULL);
277 void SetData(PyObject* obj);
279 const wxTreeItemId& GetId();
280 void SetId(const wxTreeItemId& id);
285 class wxTreeEvent : public wxNotifyEvent {
287 wxTreeItemId GetItem();
288 wxTreeItemId GetOldItem();
291 const wxString& GetLabel();
295 // These are for the GetFirstChild/GetNextChild methods below
296 %typemap(python, in) long& INOUT = long* INOUT;
297 %typemap(python, argout) long& INOUT = long* INOUT;
300 class wxTreeCtrl : public wxControl {
302 wxTreeCtrl(wxWindow *parent, wxWindowID id = -1,
303 const wxPoint& pos = wxPyDefaultPosition,
304 const wxSize& size = wxPyDefaultSize,
305 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
306 const wxValidator& validator = wxPyDefaultValidator,
307 char* name = "wxTreeCtrl");
309 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
312 unsigned int GetIndent();
313 void SetIndent(unsigned int indent);
314 wxImageList *GetImageList();
315 wxImageList *GetStateImageList();
316 void SetImageList(wxImageList *imageList);
317 void SetStateImageList(wxImageList *imageList);
319 wxString GetItemText(const wxTreeItemId& item);
320 int GetItemImage(const wxTreeItemId& item);
321 int GetItemSelectedImage(const wxTreeItemId& item);
323 void SetItemText(const wxTreeItemId& item, const wxString& text);
324 void SetItemImage(const wxTreeItemId& item, int image);
325 void SetItemSelectedImage(const wxTreeItemId& item, int image);
326 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
329 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
331 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
332 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
334 data = new wxPyTreeItemData();
335 self->SetItemData(item, data);
340 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
341 self->SetItemData(item, data);
344 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
345 // automatically creating data classes.
346 PyObject* GetPyData(const wxTreeItemId& item) {
347 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
349 data = new wxPyTreeItemData();
350 self->SetItemData(item, data);
352 return data->GetData();
355 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
356 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
358 data = new wxPyTreeItemData(obj);
359 self->SetItemData(item, data);
366 bool IsVisible(const wxTreeItemId& item);
367 bool ItemHasChildren(const wxTreeItemId& item);
368 bool IsExpanded(const wxTreeItemId& item);
369 bool IsSelected(const wxTreeItemId& item);
371 wxTreeItemId GetRootItem();
372 wxTreeItemId GetSelection();
373 wxTreeItemId GetParent(const wxTreeItemId& item);
375 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
377 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
378 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
379 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
380 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
381 wxTreeItemId GetFirstVisibleItem();
382 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
383 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
386 wxTreeItemId AddRoot(const wxString& text,
387 int image = -1, int selectedImage = -1,
388 wxPyTreeItemData *data = NULL);
389 wxTreeItemId PrependItem(const wxTreeItemId& parent,
390 const wxString& text,
391 int image = -1, int selectedImage = -1,
392 wxPyTreeItemData *data = NULL);
393 wxTreeItemId InsertItem(const wxTreeItemId& parent,
394 const wxTreeItemId& idPrevious,
395 const wxString& text,
396 int image = -1, int selectedImage = -1,
397 wxPyTreeItemData *data = NULL);
398 wxTreeItemId AppendItem(const wxTreeItemId& parent,
399 const wxString& text,
400 int image = -1, int selectedImage = -1,
401 wxPyTreeItemData *data = NULL);
403 void Delete(const wxTreeItemId& item);
404 void DeleteChildren(const wxTreeItemId& item);
405 void DeleteAllItems();
407 void Expand(const wxTreeItemId& item);
408 void Collapse(const wxTreeItemId& item);
409 void CollapseAndReset(const wxTreeItemId& item);
410 void Toggle(const wxTreeItemId& item);
414 void SelectItem(const wxTreeItemId& item);
415 void EnsureVisible(const wxTreeItemId& item);
416 void ScrollTo(const wxTreeItemId& item);
418 wxTextCtrl* EditLabel(const wxTreeItemId& item);
419 wxTextCtrl* GetEditControl();
420 void EndEditLabel(const wxTreeItemId& item, bool discardChanges = FALSE);
422 void EditLabel(const wxTreeItemId& item);
425 // void SortChildren(const wxTreeItemId& item);
427 // wxTreeItemCmpFunc *cmpFunction = NULL);
429 void SetItemBold(const wxTreeItemId& item, bool bold = TRUE);
430 bool IsBold(const wxTreeItemId& item) const;
431 wxTreeItemId HitTest(const wxPoint& point);
433 %pragma(python) addtoclass = "
434 # Redefine a couple methods that SWIG gets a bit confused on...
435 def GetFirstChild(self,arg0,arg1):
436 val1, val2 = controls2c.wxTreeCtrl_GetFirstChild(self.this,arg0.this,arg1)
437 val1 = wxTreeItemIdPtr(val1)
440 def GetNextChild(self,arg0,arg1):
441 val1, val2 = controls2c.wxTreeCtrl_GetNextChild(self.this,arg0.this,arg1)
442 val1 = wxTreeItemIdPtr(val1)
449 //----------------------------------------------------------------------
453 class wxTabEvent : public wxCommandEvent {
459 class wxTabCtrl : public wxControl {
461 wxTabCtrl(wxWindow* parent, wxWindowID id,
462 const wxPoint& pos = wxPyDefaultPosition,
463 const wxSize& size = wxPyDefaultSize,
465 char* name = "tabCtrl");
467 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
469 bool DeleteAllItems();
470 bool DeleteItem(int item);
471 wxImageList* GetImageList();
473 // TODO: void* GetItemData();
474 int GetItemImage(int item);
477 %new wxRect* GetItemRect(int item) {
478 wxRect* rect = new wxRect;
479 self->GetItemRect(item, *rect);
484 wxString GetItemText(int item);
487 int HitTest(const wxPoint& pt, long& OUTPUT);
488 void InsertItem(int item, const wxString& text,
489 int imageId = -1, void* clientData = NULL);
490 // TODO: bool SetItemData(int item, void* data);
491 bool SetItemImage(int item, int image);
492 void SetImageList(wxImageList* imageList);
493 void SetItemSize(const wxSize& size);
494 bool SetItemText(int item, const wxString& text);
495 void SetPadding(const wxSize& padding);
496 int SetSelection(int item);
503 //----------------------------------------------------------------------