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, int col=0) {
162 wxListItem* info = new wxListItem;
163 info->m_itemId = itemId;
165 self->GetItem(*info);
168 %new wxPoint* GetItemPosition(long item) {
169 wxPoint* pos = new wxPoint;
170 self->GetItemPosition(item, *pos);
173 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
174 wxRect* rect= new wxRect;
175 self->GetItemRect(item, *rect, code);
180 int GetItemState(long item, long stateMask);
182 int GetItemSpacing(bool isSmall);
183 wxString GetItemText(long item);
184 long GetNextItem(long item,
185 int geometry = wxLIST_NEXT_ALL,
186 int state = wxLIST_STATE_DONTCARE);
187 int GetSelectedItemCount();
189 wxColour GetTextColour();
190 void SetTextColour(const wxColour& col);
193 long HitTest(const wxPoint& point, int& OUTPUT);
194 %name(InsertColumnWith)long InsertColumn(long col, wxListItem& info);
195 long InsertColumn(long col, const wxString& heading,
196 int format = wxLIST_FORMAT_LEFT,
199 long InsertItem(wxListItem& info);
200 %name(InsertStringItem) long InsertItem(long index, const wxString& label);
201 %name(InsertImageItem) long InsertItem(long index, int imageIndex);
202 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label,
205 bool ScrollList(int dx, int dy);
206 void SetBackgroundColour(const wxColour& col);
207 bool SetColumn(int col, wxListItem& item);
208 bool SetColumnWidth(int col, int width);
209 void SetImageList(wxImageList* imageList, int which);
211 bool SetItem(wxListItem& info);
212 %name(SetStringItem)long SetItem(long index, int col, const wxString& label,
215 bool SetItemData(long item, long data);
216 bool SetItemImage(long item, int image, int selImage);
217 bool SetItemPosition(long item, const wxPoint& pos);
218 bool SetItemState(long item, long state, long stateMask);
219 void SetItemText(long item, const wxString& text);
220 void SetSingleStyle(long style, bool add = TRUE);
221 void SetWindowStyleFlag(long style);
222 // TODO: bool SortItems(wxListCtrlCompare fn, long data);
227 //----------------------------------------------------------------------
241 class wxPyTreeItemData : public wxTreeItemData {
243 wxPyTreeItemData(PyObject* obj = NULL) {
250 ~wxPyTreeItemData() {
251 bool doSave = wxPyRestoreThread();
253 wxPySaveThread(doSave);
256 PyObject* GetData() {
261 void SetData(PyObject* obj) {
273 %name(wxTreeItemData) class wxPyTreeItemData {
275 wxPyTreeItemData(PyObject* obj = NULL);
278 void SetData(PyObject* obj);
280 const wxTreeItemId& GetId();
281 void SetId(const wxTreeItemId& id);
286 class wxTreeEvent : public wxNotifyEvent {
288 wxTreeItemId GetItem();
289 wxTreeItemId GetOldItem();
292 const wxString& GetLabel();
296 // These are for the GetFirstChild/GetNextChild methods below
297 %typemap(python, in) long& INOUT = long* INOUT;
298 %typemap(python, argout) long& INOUT = long* INOUT;
301 class wxTreeCtrl : public wxControl {
303 wxTreeCtrl(wxWindow *parent, wxWindowID id = -1,
304 const wxPoint& pos = wxPyDefaultPosition,
305 const wxSize& size = wxPyDefaultSize,
306 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
307 const wxValidator& validator = wxPyDefaultValidator,
308 char* name = "wxTreeCtrl");
310 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
313 unsigned int GetIndent();
314 void SetIndent(unsigned int indent);
315 wxImageList *GetImageList();
316 wxImageList *GetStateImageList();
317 void SetImageList(wxImageList *imageList);
318 void SetStateImageList(wxImageList *imageList);
320 wxString GetItemText(const wxTreeItemId& item);
321 int GetItemImage(const wxTreeItemId& item);
322 int GetItemSelectedImage(const wxTreeItemId& item);
324 void SetItemText(const wxTreeItemId& item, const wxString& text);
325 void SetItemImage(const wxTreeItemId& item, int image);
326 void SetItemSelectedImage(const wxTreeItemId& item, int image);
327 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
330 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
332 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
333 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
335 data = new wxPyTreeItemData();
336 self->SetItemData(item, data);
341 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
342 self->SetItemData(item, data);
345 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
346 // automatically creating data classes.
347 PyObject* GetPyData(const wxTreeItemId& item) {
348 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
350 data = new wxPyTreeItemData();
351 self->SetItemData(item, data);
353 return data->GetData();
356 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
357 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
359 data = new wxPyTreeItemData(obj);
360 self->SetItemData(item, data);
367 bool IsVisible(const wxTreeItemId& item);
368 bool ItemHasChildren(const wxTreeItemId& item);
369 bool IsExpanded(const wxTreeItemId& item);
370 bool IsSelected(const wxTreeItemId& item);
372 wxTreeItemId GetRootItem();
373 wxTreeItemId GetSelection();
374 wxTreeItemId GetParent(const wxTreeItemId& item);
375 //size_t GetSelections(wxArrayTreeItemIds& selection);
377 PyObject* GetSelections() {
378 PyObject* rval = PyList_New(0);
379 wxArrayTreeItemIds array;
381 num = self->GetSelections(array);
382 for (x=0; x < num; x++) {
383 PyObject* item = wxPyConstructObject((void*)&array.Item(x),
385 PyList_Append(rval, item);
393 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
395 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
396 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
397 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
398 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
399 wxTreeItemId GetFirstVisibleItem();
400 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
401 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
402 wxTreeItemId GetLastChild(const wxTreeItemId& item);
406 wxTreeItemId AddRoot(const wxString& text,
407 int image = -1, int selectedImage = -1,
408 wxPyTreeItemData *data = NULL);
409 wxTreeItemId PrependItem(const wxTreeItemId& parent,
410 const wxString& text,
411 int image = -1, int selectedImage = -1,
412 wxPyTreeItemData *data = NULL);
413 wxTreeItemId InsertItem(const wxTreeItemId& parent,
414 const wxTreeItemId& idPrevious,
415 const wxString& text,
416 int image = -1, int selectedImage = -1,
417 wxPyTreeItemData *data = NULL);
418 wxTreeItemId AppendItem(const wxTreeItemId& parent,
419 const wxString& text,
420 int image = -1, int selectedImage = -1,
421 wxPyTreeItemData *data = NULL);
423 void Delete(const wxTreeItemId& item);
424 void DeleteChildren(const wxTreeItemId& item);
425 void DeleteAllItems();
427 void Expand(const wxTreeItemId& item);
428 void Collapse(const wxTreeItemId& item);
429 void CollapseAndReset(const wxTreeItemId& item);
430 void Toggle(const wxTreeItemId& item);
434 void SelectItem(const wxTreeItemId& item);
435 void EnsureVisible(const wxTreeItemId& item);
436 void ScrollTo(const wxTreeItemId& item);
438 wxTextCtrl* EditLabel(const wxTreeItemId& item);
439 wxTextCtrl* GetEditControl();
440 void EndEditLabel(const wxTreeItemId& item, bool discardChanges = FALSE);
442 void EditLabel(const wxTreeItemId& item);
445 void SortChildren(const wxTreeItemId& item);
447 void SetItemBold(const wxTreeItemId& item, bool bold = TRUE);
448 bool IsBold(const wxTreeItemId& item) const;
449 wxTreeItemId HitTest(const wxPoint& point);
452 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
454 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
456 if (self->GetBoundingRect(item, rect, textOnly))
457 return wxPyConstructObject((void*)&rect, "wxRect");
466 %pragma(python) addtoclass = "
467 # Redefine a couple methods that SWIG gets a bit confused on...
468 def GetFirstChild(self,arg0,arg1):
469 val1, val2 = controls2c.wxTreeCtrl_GetFirstChild(self.this,arg0.this,arg1)
470 val1 = wxTreeItemIdPtr(val1)
473 def GetNextChild(self,arg0,arg1):
474 val1, val2 = controls2c.wxTreeCtrl_GetNextChild(self.this,arg0.this,arg1)
475 val1 = wxTreeItemIdPtr(val1)
482 //----------------------------------------------------------------------
486 class wxTabEvent : public wxCommandEvent {
492 class wxTabCtrl : public wxControl {
494 wxTabCtrl(wxWindow* parent, wxWindowID id,
495 const wxPoint& pos = wxPyDefaultPosition,
496 const wxSize& size = wxPyDefaultSize,
498 char* name = "tabCtrl");
500 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
502 bool DeleteAllItems();
503 bool DeleteItem(int item);
504 wxImageList* GetImageList();
506 // TODO: void* GetItemData();
507 int GetItemImage(int item);
510 %new wxRect* GetItemRect(int item) {
511 wxRect* rect = new wxRect;
512 self->GetItemRect(item, *rect);
517 wxString GetItemText(int item);
520 int HitTest(const wxPoint& pt, long& OUTPUT);
521 void InsertItem(int item, const wxString& text,
522 int imageId = -1, void* clientData = NULL);
523 // TODO: bool SetItemData(int item, void* data);
524 bool SetItemImage(int item, int image);
525 void SetImageList(wxImageList* imageList);
526 void SetItemSize(const wxSize& size);
527 bool SetItemText(int item, const wxString& text);
528 void SetPadding(const wxSize& padding);
529 int SetSelection(int item);
536 //----------------------------------------------------------------------