Added ogl to the module list
[wxWidgets.git] / utils / wxPython / src / controls2.i
0 / 535 (  0%)
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: controls2.i
3// Purpose: More control (widget) classes for wxPython
4//
5// Author: Robin Dunn
6//
7// Created: 6/10/98
8// RCS-ID: $Id$
9// Copyright: (c) 1998 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13%module controls2
14
15%{
16#include "helpers.h"
17#include <wx/listctrl.h>
18#include <wx/treectrl.h>
19%}
20
21//----------------------------------------------------------------------
22
23%include typemaps.i
24%include my_typemaps.i
25
26// Import some definitions of other classes, etc.
27%import _defs.i
28%import misc.i
29%import windows.i
30%import gdi.i
31%import events.i
32%import controls.i
33
34%pragma(python) code = "import wx"
35
36//----------------------------------------------------------------------
37
38%{
39extern wxValidator wxPyDefaultValidator;
40%}
41
42//----------------------------------------------------------------------
43
44enum {
45 wxLIST_MASK_TEXT,
46 wxLIST_MASK_IMAGE,
47 wxLIST_MASK_DATA,
48 wxLIST_MASK_WIDTH,
49 wxLIST_MASK_FORMAT,
50 wxLIST_MASK_STATE,
51 wxLIST_STATE_DONTCARE,
52 wxLIST_STATE_DROPHILITED,
53 wxLIST_STATE_FOCUSED,
54 wxLIST_STATE_SELECTED,
55 wxLIST_STATE_CUT,
56 wxLIST_HITTEST_ABOVE,
57 wxLIST_HITTEST_BELOW,
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,
66 wxLIST_NEXT_ABOVE,
67 wxLIST_NEXT_ALL,
68 wxLIST_NEXT_BELOW,
69 wxLIST_NEXT_LEFT,
70 wxLIST_NEXT_RIGHT,
71 wxLIST_ALIGN_DEFAULT,
72 wxLIST_ALIGN_LEFT,
73 wxLIST_ALIGN_TOP,
74 wxLIST_ALIGN_SNAP_TO_GRID,
75 wxLIST_FORMAT_LEFT,
76 wxLIST_FORMAT_RIGHT,
77 wxLIST_FORMAT_CENTRE,
78 wxLIST_FORMAT_CENTER,
79 wxLIST_AUTOSIZE,
80 wxLIST_AUTOSIZE_USEHEADER,
81 wxLIST_RECT_BOUNDS,
82 wxLIST_RECT_ICON,
83 wxLIST_RECT_LABEL,
84 wxLIST_FIND_UP,
85 wxLIST_FIND_DOWN,
86 wxLIST_FIND_LEFT,
87 wxLIST_FIND_RIGHT,
88};
89
90
91class wxListItem {
92public:
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 ;->
102
103 // For columns only
104 int m_format; // left, right, centre
105 int m_width; // width of column
106
107 wxListItem();
108 ~wxListItem();
109};
110
111class wxListEvent: public wxCommandEvent {
112public:
113 int m_code;
114 long m_itemIndex;
115 long m_oldItemIndex;
116 int m_col;
117 bool m_cancelled;
118 wxPoint m_pointDrag;
119 wxListItem m_item;
120};
121
122
123
124
125class wxListCtrl : public wxControl {
126public:
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");
133
134 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
135
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);
141 void ClearAll(void);
142#ifdef __WXMSW__
143 wxTextCtrl* EditLabel(long item);
144 bool EndEditLabel(bool cancel);
145 wxTextCtrl* GetEditControl();
146#else
147 void EditLabel(long item);
148#endif
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,
153 int direction);
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);
159
160 %addmethods {
161 %new wxListItem* GetItem(long itemId) {
162 wxListItem* info = new wxListItem;
163 info->m_itemId = itemId;
164 self->GetItem(*info);
165 return info;
166 }
167 %new wxPoint* GetItemPosition(long item) {
168 wxPoint* pos = new wxPoint;
169 self->GetItemPosition(item, *pos);
170 return pos;
171 }
172 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
173 wxRect* rect= new wxRect;
174 self->GetItemRect(item, *rect, code);
175 return rect;
176 }
177 }
178
179 int GetItemState(long item, long stateMask);
180 int GetItemCount();
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();
187#ifdef __WXMSW__
188 wxColour GetTextColour();
189 void SetTextColour(const wxColour& col);
190#endif
191 long GetTopItem();
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,
196 int width = -1);
197
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,
202 int imageIndex);
203
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);
209
210 bool SetItem(wxListItem& info);
211 %name(SetStringItem)long SetItem(long index, int col, const wxString& label,
212 int imageId = -1);
213
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);
222};
223
224
225
226//----------------------------------------------------------------------
227
228
229class wxTreeItemId {
230public:
231 wxTreeItemId();
232 ~wxTreeItemId();
233 bool IsOk();
234
235};
236
237
238
239%{
240class wxPyTreeItemData : public wxTreeItemData {
241public:
242 wxPyTreeItemData(PyObject* obj = NULL) {
243 if (obj == NULL)
244 obj = Py_None;
245 Py_INCREF(obj);
246 m_obj = obj;
247 }
248
249 ~wxPyTreeItemData() {
250 bool doSave = wxPyRestoreThread();
251 Py_DECREF(m_obj);
252 wxPySaveThread(doSave);
253 }
254
255 PyObject* GetData() {
256 Py_INCREF(m_obj);
257 return m_obj;
258 }
259
260 void SetData(PyObject* obj) {
261 Py_DECREF(m_obj);
262 m_obj = obj;
263 Py_INCREF(obj);
264 }
265
266 PyObject* m_obj;
267};
268%}
269
270
271
272%name(wxTreeItemData) class wxPyTreeItemData {
273public:
274 wxPyTreeItemData(PyObject* obj = NULL);
275
276 PyObject* GetData();
277 void SetData(PyObject* obj);
278
279 const wxTreeItemId& GetId();
280 void SetId(const wxTreeItemId& id);
281};
282
283
284
285class wxTreeEvent : public wxNotifyEvent {
286public:
287 wxTreeItemId GetItem();
288 wxTreeItemId GetOldItem();
289 wxPoint GetPoint();
290 int GetCode();
291 const wxString& GetLabel();
292};
293
294
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;
298
299
300class wxTreeCtrl : public wxControl {
301public:
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");
308
309 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
310
311 size_t GetCount();
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);
318
319 wxString GetItemText(const wxTreeItemId& item);
320 int GetItemImage(const wxTreeItemId& item);
321 int GetItemSelectedImage(const wxTreeItemId& item);
322
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);
327
328 %addmethods {
329 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
330 // if needed.
331 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
332 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
333 if (data == NULL) {
334 data = new wxPyTreeItemData();
335 self->SetItemData(item, data);
336 }
337 return data;
338 }
339
340 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
341 self->SetItemData(item, data);
342 }
343
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);
348 if (data == NULL) {
349 data = new wxPyTreeItemData();
350 self->SetItemData(item, data);
351 }
352 return data->GetData();
353 }
354
355 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
356 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
357 if (data == NULL) {
358 data = new wxPyTreeItemData(obj);
359 self->SetItemData(item, data);
360 } else
361 data->SetData(obj);
362 }
363 }
364
365
366 bool IsVisible(const wxTreeItemId& item);
367 bool ItemHasChildren(const wxTreeItemId& item);
368 bool IsExpanded(const wxTreeItemId& item);
369 bool IsSelected(const wxTreeItemId& item);
370
371 wxTreeItemId GetRootItem();
372 wxTreeItemId GetSelection();
373 wxTreeItemId GetParent(const wxTreeItemId& item);
374 //size_t GetSelections(wxArrayTreeItemIds& selection);
375 %addmethods {
376 PyObject* GetSelections() {
377 PyObject* rval = PyList_New(0);
378 wxArrayTreeItemIds array;
379 size_t num, x;
380 num = self->GetSelections(array);
381 for (x=0; x < num; x++) {
382 PyObject* item = wxPyConstructObject((void*)&array.Item(x),
383 "wxTreeItemId");
384 PyList_Append(rval, item);
385 }
386 return rval;
387 }
388 }
389
390
391
392 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
393
394 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
395 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
396 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
397 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
398 wxTreeItemId GetFirstVisibleItem();
399 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
400 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
401 wxTreeItemId GetLastChild(const wxTreeItemId& item);
402
403
404
405 wxTreeItemId AddRoot(const wxString& text,
406 int image = -1, int selectedImage = -1,
407 wxPyTreeItemData *data = NULL);
408 wxTreeItemId PrependItem(const wxTreeItemId& parent,
409 const wxString& text,
410 int image = -1, int selectedImage = -1,
411 wxPyTreeItemData *data = NULL);
412 wxTreeItemId InsertItem(const wxTreeItemId& parent,
413 const wxTreeItemId& idPrevious,
414 const wxString& text,
415 int image = -1, int selectedImage = -1,
416 wxPyTreeItemData *data = NULL);
417 wxTreeItemId AppendItem(const wxTreeItemId& parent,
418 const wxString& text,
419 int image = -1, int selectedImage = -1,
420 wxPyTreeItemData *data = NULL);
421
422 void Delete(const wxTreeItemId& item);
423 void DeleteChildren(const wxTreeItemId& item);
424 void DeleteAllItems();
425
426 void Expand(const wxTreeItemId& item);
427 void Collapse(const wxTreeItemId& item);
428 void CollapseAndReset(const wxTreeItemId& item);
429 void Toggle(const wxTreeItemId& item);
430
431 void Unselect();
432 void UnselectAll();
433 void SelectItem(const wxTreeItemId& item);
434 void EnsureVisible(const wxTreeItemId& item);
435 void ScrollTo(const wxTreeItemId& item);
436#ifdef __WXMSW__
437 wxTextCtrl* EditLabel(const wxTreeItemId& item);
438 wxTextCtrl* GetEditControl();
439 void EndEditLabel(const wxTreeItemId& item, bool discardChanges = FALSE);
440#else
441 void EditLabel(const wxTreeItemId& item);
442#endif
443
444 void SortChildren(const wxTreeItemId& item);
445
446 void SetItemBold(const wxTreeItemId& item, bool bold = TRUE);
447 bool IsBold(const wxTreeItemId& item) const;
448 wxTreeItemId HitTest(const wxPoint& point);
449
450 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
451 %addmethods {
452 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
453 wxRect rect;
454 if (self->GetBoundingRect(item, rect, textOnly))
455 return wxPyConstructObject((void*)&rect, "wxRect");
456 else {
457 Py_INCREF(Py_None);
458 return Py_None;
459 }
460 }
461 }
462
463%pragma(python) addtoclass = "
464 # Redefine a couple methods that SWIG gets a bit confused on...
465 def GetFirstChild(self,arg0,arg1):
466 val1, val2 = controls2c.wxTreeCtrl_GetFirstChild(self.this,arg0.this,arg1)
467 val1 = wxTreeItemIdPtr(val1)
468 val1.thisown = 1
469 return (val1,val2)
470 def GetNextChild(self,arg0,arg1):
471 val1, val2 = controls2c.wxTreeCtrl_GetNextChild(self.this,arg0.this,arg1)
472 val1 = wxTreeItemIdPtr(val1)
473 val1.thisown = 1
474 return (val1,val2)
475"
476};
477
478
479//----------------------------------------------------------------------
480
481#ifdef SKIPTHIS
482#ifdef __WXMSW__
483class wxTabEvent : public wxCommandEvent {
484public:
485};
486
487
488
489class wxTabCtrl : public wxControl {
490public:
491 wxTabCtrl(wxWindow* parent, wxWindowID id,
492 const wxPoint& pos = wxPyDefaultPosition,
493 const wxSize& size = wxPyDefaultSize,
494 long style = 0,
495 char* name = "tabCtrl");
496
497 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
498
499 bool DeleteAllItems();
500 bool DeleteItem(int item);
501 wxImageList* GetImageList();
502 int GetItemCount();
503 // TODO: void* GetItemData();
504 int GetItemImage(int item);
505
506 %addmethods {
507 %new wxRect* GetItemRect(int item) {
508 wxRect* rect = new wxRect;
509 self->GetItemRect(item, *rect);
510 return rect;
511 }
512 }
513
514 wxString GetItemText(int item);
515 bool GetRowCount();
516 int GetSelection();
517 int HitTest(const wxPoint& pt, long& OUTPUT);
518 void InsertItem(int item, const wxString& text,
519 int imageId = -1, void* clientData = NULL);
520 // TODO: bool SetItemData(int item, void* data);
521 bool SetItemImage(int item, int image);
522 void SetImageList(wxImageList* imageList);
523 void SetItemSize(const wxSize& size);
524 bool SetItemText(int item, const wxString& text);
525 void SetPadding(const wxSize& padding);
526 int SetSelection(int item);
527
528};
529
530#endif
531#endif
532
533//----------------------------------------------------------------------
534
535