]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/src/controls2.i
fixes for GetReturnCode/SetReturnCode
[wxWidgets.git] / utils / wxPython / src / controls2.i
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 %{
39 extern wxValidator wxPyDefaultValidator;
40 %}
41
42 //----------------------------------------------------------------------
43
44 enum {
45 wxLIST_MASK_TEXT,
46 wxLIST_MASK_IMAGE,
47 wxLIST_MASK_DATA,
48 wxLIST_MASK_WIDTH,
49 wxLIST_MASK_FORMAT,
50 wxLIST_STATE_DONTCARE,
51 wxLIST_STATE_DROPHILITED,
52 wxLIST_STATE_FOCUSED,
53 wxLIST_STATE_SELECTED,
54 wxLIST_STATE_CUT,
55 wxLIST_HITTEST_ABOVE,
56 wxLIST_HITTEST_BELOW,
57 wxLIST_HITTEST_NOWHERE,
58 wxLIST_HITTEST_ONITEMICON,
59 wxLIST_HITTEST_ONITEMLABEL,
60 wxLIST_HITTEST_ONITEMRIGHT,
61 wxLIST_HITTEST_ONITEMSTATEICON,
62 wxLIST_HITTEST_TOLEFT,
63 wxLIST_HITTEST_TORIGHT,
64 wxLIST_HITTEST_ONITEM,
65 wxLIST_NEXT_ABOVE,
66 wxLIST_NEXT_ALL,
67 wxLIST_NEXT_BELOW,
68 wxLIST_NEXT_LEFT,
69 wxLIST_NEXT_RIGHT,
70 wxLIST_ALIGN_DEFAULT,
71 wxLIST_ALIGN_LEFT,
72 wxLIST_ALIGN_TOP,
73 wxLIST_ALIGN_SNAP_TO_GRID,
74 wxLIST_FORMAT_LEFT,
75 wxLIST_FORMAT_RIGHT,
76 wxLIST_FORMAT_CENTRE,
77 wxLIST_FORMAT_CENTER,
78 wxLIST_AUTOSIZE,
79 wxLIST_AUTOSIZE_USEHEADER,
80 wxLIST_RECT_BOUNDS,
81 wxLIST_RECT_ICON,
82 wxLIST_RECT_LABEL,
83 wxLIST_FIND_UP,
84 wxLIST_FIND_DOWN,
85 wxLIST_FIND_LEFT,
86 wxLIST_FIND_RIGHT,
87 };
88
89
90 class wxListItem {
91 public:
92 long m_mask; // Indicates what fields are valid
93 long m_itemId; // The zero-based item position
94 int m_col; // Zero-based column, if in report mode
95 long m_state; // The state of the item
96 long m_stateMask; // Which flags of m_state are valid (uses same flags)
97 wxString m_text; // The label/header text
98 int m_image; // The zero-based index into an image list
99 long m_data; // App-defined data
100 // wxColour *m_colour; // only wxGLC, not supported by Windows ;->
101
102 // For columns only
103 int m_format; // left, right, centre
104 int m_width; // width of column
105
106 wxListItem();
107 ~wxListItem();
108 };
109
110 class wxListEvent: public wxCommandEvent {
111 public:
112 int m_code;
113 long m_itemIndex;
114 long m_oldItemIndex;
115 int m_col;
116 bool m_cancelled;
117 wxPoint m_pointDrag;
118 wxListItem m_item;
119 };
120
121
122
123
124 class wxListCtrl : public wxControl {
125 public:
126 wxListCtrl(wxWindow* parent, wxWindowID id,
127 const wxPoint& pos = wxPyDefaultPosition,
128 const wxSize& size = wxPyDefaultSize,
129 long style = wxLC_ICON,
130 const wxValidator& validator = wxPyDefaultValidator,
131 char* name = "listCtrl");
132
133 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
134
135 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
136 bool DeleteItem(long item);
137 bool DeleteAllItems();
138 bool DeleteColumn(int col);
139 bool DeleteAllColumns(void);
140 void ClearAll(void);
141 #ifdef __WXMSW__
142 wxTextCtrl* EditLabel(long item);
143 bool EndEditLabel(bool cancel);
144 wxTextCtrl* GetEditControl();
145 #endif
146 bool EnsureVisible(long item);
147 long FindItem(long start, const wxString& str, bool partial = FALSE);
148 %name(FindItemData)long FindItem(long start, long data);
149 %name(FindItemAtPos)long FindItem(long start, const wxPoint& pt,
150 int direction);
151 bool GetColumn(int col, wxListItem& item);
152 int GetColumnWidth(int col);
153 int GetCountPerPage();
154 wxImageList* GetImageList(int which);
155 long GetItemData(long item);
156
157 %addmethods {
158 %new wxListItem* GetItem(long itemId) {
159 wxListItem* info = new wxListItem;
160 info->m_itemId = itemId;
161 self->GetItem(*info);
162 return info;
163 }
164 %new wxPoint* GetItemPosition(long item) {
165 wxPoint* pos = new wxPoint;
166 self->GetItemPosition(item, *pos);
167 return pos;
168 }
169 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
170 wxRect* rect= new wxRect;
171 self->GetItemRect(item, *rect, code);
172 return rect;
173 }
174 }
175
176 int GetItemState(long item, long stateMask);
177 int GetItemCount();
178 int GetItemSpacing(bool isSmall);
179 wxString GetItemText(long item);
180 long GetNextItem(long item,
181 int geometry = wxLIST_NEXT_ALL,
182 int state = wxLIST_STATE_DONTCARE);
183 int GetSelectedItemCount();
184 #ifdef __WXMSW__
185 wxColour GetTextColour();
186 void SetTextColour(const wxColour& col);
187 #endif
188 long GetTopItem();
189 long HitTest(const wxPoint& point, int& OUTPUT);
190 %name(InsertColumnWith)long InsertColumn(long col, wxListItem& info);
191 long InsertColumn(long col, const wxString& heading,
192 int format = wxLIST_FORMAT_LEFT,
193 int width = -1);
194
195 long InsertItem(wxListItem& info);
196 %name(InsertStringItem) long InsertItem(long index, const wxString& label);
197 %name(InsertImageItem) long InsertItem(long index, int imageIndex);
198 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label,
199 int imageIndex);
200
201 bool ScrollList(int dx, int dy);
202 void SetBackgroundColour(const wxColour& col);
203 bool SetColumn(int col, wxListItem& item);
204 bool SetColumnWidth(int col, int width);
205 void SetImageList(wxImageList* imageList, int which);
206
207 bool SetItem(wxListItem& info);
208 %name(SetStringItem)long SetItem(long index, int col, const wxString& label,
209 int imageId = -1);
210
211 bool SetItemData(long item, long data);
212 bool SetItemImage(long item, int image, int selImage);
213 bool SetItemPosition(long item, const wxPoint& pos);
214 bool SetItemState(long item, long state, long stateMask);
215 void SetItemText(long item, const wxString& text);
216 void SetSingleStyle(long style, bool add = TRUE);
217 void SetWindowStyleFlag(long style);
218 // TODO: bool SortItems(wxListCtrlCompare fn, long data);
219 };
220
221
222
223 //----------------------------------------------------------------------
224
225
226 class wxTreeItemId {
227 public:
228 wxTreeItemId();
229 ~wxTreeItemId();
230 bool IsOk() const { return m_itemId != 0; }
231
232 };
233
234
235
236 %{
237 class wxPyTreeItemData : public wxTreeItemData {
238 public:
239 wxPyTreeItemData(PyObject* obj = NULL) {
240 if (obj == NULL)
241 obj = Py_None;
242 Py_INCREF(obj);
243 m_obj = obj;
244 }
245
246 ~wxPyTreeItemData() {
247 Py_DECREF(m_obj);
248 }
249
250 PyObject* GetData() {
251 Py_INCREF(m_obj);
252 return m_obj;
253 }
254
255 void SetData(PyObject* obj) {
256 Py_DECREF(m_obj);
257 m_obj = obj;
258 Py_INCREF(obj);
259 }
260
261 PyObject* m_obj;
262 };
263 %}
264
265
266
267 %name(wxTreeItemData) class wxPyTreeItemData {
268 public:
269 wxPyTreeItemData(PyObject* obj = NULL);
270
271 PyObject* GetData();
272 void SetData(PyObject* obj);
273
274 const wxTreeItemId& GetId();
275 void SetId(const wxTreeItemId& id);
276 };
277
278
279
280 class wxTreeEvent : public wxCommandEvent {
281 public:
282 wxTreeItemId GetItem();
283 wxTreeItemId GetOldItem();
284 wxPoint GetPoint();
285 int GetCode();
286 void Veto();
287 };
288
289
290 // These are for the GetFirstChild/GetNextChild methods below
291 %typemap(python, in) long& INOUT = long* INOUT;
292 %typemap(python, argout) long& INOUT = long* INOUT;
293
294
295 class wxTreeCtrl : public wxControl {
296 public:
297 wxTreeCtrl(wxWindow *parent, wxWindowID id = -1,
298 const wxPoint& pos = wxPyDefaultPosition,
299 const wxSize& size = wxPyDefaultSize,
300 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
301 const wxValidator& validator = wxPyDefaultValidator,
302 char* name = "wxTreeCtrl");
303
304 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
305
306 size_t GetCount();
307 unsigned int GetIndent();
308 void SetIndent(unsigned int indent);
309 wxImageList *GetImageList();
310 wxImageList *GetStateImageList();
311 void SetImageList(wxImageList *imageList);
312 void SetStateImageList(wxImageList *imageList);
313
314 wxString GetItemText(const wxTreeItemId& item);
315 int GetItemImage(const wxTreeItemId& item);
316 int GetItemSelectedImage(const wxTreeItemId& item);
317
318 void SetItemText(const wxTreeItemId& item, const wxString& text);
319 void SetItemImage(const wxTreeItemId& item, int image);
320 void SetItemSelectedImage(const wxTreeItemId& item, int image);
321 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
322
323 %addmethods {
324 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
325 // if needed.
326 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
327 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
328 if (data == NULL) {
329 data = new wxPyTreeItemData();
330 self->SetItemData(item, data);
331 }
332 return data;
333 }
334
335 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
336 self->SetItemData(item, data);
337 }
338
339 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
340 // automatically creating data classes.
341 PyObject* GetPyData(const wxTreeItemId& item) {
342 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
343 if (data == NULL) {
344 data = new wxPyTreeItemData();
345 self->SetItemData(item, data);
346 }
347 return data->GetData();
348 }
349
350 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
351 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
352 if (data == NULL) {
353 data = new wxPyTreeItemData(obj);
354 self->SetItemData(item, data);
355 } else
356 data->SetData(obj);
357 }
358 }
359
360
361 bool IsVisible(const wxTreeItemId& item);
362 bool ItemHasChildren(const wxTreeItemId& item);
363 bool IsExpanded(const wxTreeItemId& item);
364 bool IsSelected(const wxTreeItemId& item);
365
366 wxTreeItemId GetRootItem();
367 wxTreeItemId GetSelection();
368 wxTreeItemId GetParent(const wxTreeItemId& item);
369
370 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
371 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
372 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
373 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
374 wxTreeItemId GetFirstVisibleItem();
375 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
376 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
377
378
379 wxTreeItemId AddRoot(const wxString& text,
380 int image = -1, int selectedImage = -1,
381 wxPyTreeItemData *data = NULL);
382 wxTreeItemId PrependItem(const wxTreeItemId& parent,
383 const wxString& text,
384 int image = -1, int selectedImage = -1,
385 wxPyTreeItemData *data = NULL);
386 wxTreeItemId InsertItem(const wxTreeItemId& parent,
387 const wxTreeItemId& idPrevious,
388 const wxString& text,
389 int image = -1, int selectedImage = -1,
390 wxPyTreeItemData *data = NULL);
391 wxTreeItemId AppendItem(const wxTreeItemId& parent,
392 const wxString& text,
393 int image = -1, int selectedImage = -1,
394 wxPyTreeItemData *data = NULL);
395
396 void Delete(const wxTreeItemId& item);
397 void DeleteChildren(const wxTreeItemId& item);
398 void DeleteAllItems();
399
400 void Expand(const wxTreeItemId& item);
401 void Collapse(const wxTreeItemId& item);
402 void CollapseAndReset(const wxTreeItemId& item);
403 void Toggle(const wxTreeItemId& item);
404
405 void Unselect();
406 void SelectItem(const wxTreeItemId& item);
407 void EnsureVisible(const wxTreeItemId& item);
408 void ScrollTo(const wxTreeItemId& item);
409
410 wxTextCtrl* EditLabel(const wxTreeItemId& item);
411 // **** figure out how to do this
412 // wxClassInfo* textCtrlClass = CLASSINFO(wxTextCtrl));
413 wxTextCtrl* GetEditControl();
414 void EndEditLabel(const wxTreeItemId& item, bool discardChanges = FALSE);
415
416 // void SortChildren(const wxTreeItemId& item);
417 // **** And this too
418 // wxTreeItemCmpFunc *cmpFunction = NULL);
419
420 void SetItemBold(const wxTreeItemId& item, bool bold = TRUE);
421 bool IsBold(const wxTreeItemId& item) const;
422 wxTreeItemId HitTest(const wxPoint& point);
423
424 %pragma(python) addtoclass = "
425 # Redefine a couple methods that SWIG gets a bit confused on...
426 def GetFirstChild(self,arg0,arg1):
427 val1, val2 = controls2c.wxTreeCtrl_GetFirstChild(self.this,arg0.this,arg1)
428 val1 = wxTreeItemIdPtr(val1)
429 val1.thisown = 1
430 return (val1,val2)
431 def GetNextChild(self,arg0,arg1):
432 val1, val2 = controls2c.wxTreeCtrl_GetFirstChild(self.this,arg0.this,arg1)
433 val1 = wxTreeItemIdPtr(val1)
434 val1.thisown = 1
435 return (val1,val2)
436 "
437 };
438
439
440 //----------------------------------------------------------------------
441
442 #ifdef SKIPTHIS
443 #ifdef __WXMSW__
444 class wxTabEvent : public wxCommandEvent {
445 public:
446 };
447
448
449
450 class wxTabCtrl : public wxControl {
451 public:
452 wxTabCtrl(wxWindow* parent, wxWindowID id,
453 const wxPoint& pos = wxPyDefaultPosition,
454 const wxSize& size = wxPyDefaultSize,
455 long style = 0,
456 char* name = "tabCtrl");
457
458 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
459
460 bool DeleteAllItems();
461 bool DeleteItem(int item);
462 wxImageList* GetImageList();
463 int GetItemCount();
464 // TODO: void* GetItemData();
465 int GetItemImage(int item);
466
467 %addmethods {
468 %new wxRect* GetItemRect(int item) {
469 wxRect* rect = new wxRect;
470 self->GetItemRect(item, *rect);
471 return rect;
472 }
473 }
474
475 wxString GetItemText(int item);
476 bool GetRowCount();
477 int GetSelection();
478 int HitTest(const wxPoint& pt, long& OUTPUT);
479 void InsertItem(int item, const wxString& text,
480 int imageId = -1, void* clientData = NULL);
481 // TODO: bool SetItemData(int item, void* data);
482 bool SetItemImage(int item, int image);
483 void SetImageList(wxImageList* imageList);
484 void SetItemSize(const wxSize& size);
485 bool SetItemText(int item, const wxString& text);
486 void SetPadding(const wxSize& padding);
487 int SetSelection(int item);
488
489 };
490
491 #endif
492 #endif
493
494 //----------------------------------------------------------------------
495
496
497 /////////////////////////////////////////////////////////////////////////////
498 //
499 // $Log$
500 // Revision 1.18 1999/05/02 02:06:15 RD
501 // More for wxPython 2.0b9 (hopefully the last...)
502 //
503 // Revision 1.17 1999/04/30 03:29:18 RD
504 //
505 // wxPython 2.0b9, first phase (win32)
506 // Added gobs of stuff, see wxPython/README.txt for details
507 //
508 // Revision 1.16 1999/02/25 07:08:32 RD
509 //
510 // wxPython version 2.0b5
511 //
512 // Revision 1.15 1999/02/20 09:02:56 RD
513 // Added wxWindow_FromHWND(hWnd) for wxMSW to construct a wxWindow from a
514 // window handle. If you can get the window handle into the python code,
515 // it should just work... More news on this later.
516 //
517 // Added wxImageList, wxToolTip.
518 //
519 // Re-enabled wxConfig.DeleteAll() since it is reportedly fixed for the
520 // wxRegConfig class.
521 //
522 // As usual, some bug fixes, tweaks, etc.
523 //
524 // Revision 1.14 1999/01/30 07:30:10 RD
525 //
526 // Added wxSashWindow, wxSashEvent, wxLayoutAlgorithm, etc.
527 //
528 // Various cleanup, tweaks, minor additions, etc. to maintain
529 // compatibility with the current wxWindows.
530 //
531 // Revision 1.13 1998/12/17 14:07:34 RR
532 //
533 // Removed minor differences between wxMSW and wxGTK
534 //
535 // Revision 1.12 1998/12/16 22:10:52 RD
536 //
537 // Tweaks needed to be able to build wxPython with wxGTK.
538 //
539 // Revision 1.11 1998/12/15 20:41:16 RD
540 // Changed the import semantics from "from wxPython import *" to "from
541 // wxPython.wx import *" This is for people who are worried about
542 // namespace pollution, they can use "from wxPython import wx" and then
543 // prefix all the wxPython identifiers with "wx."
544 //
545 // Added wxTaskbarIcon for wxMSW.
546 //
547 // Made the events work for wxGrid.
548 //
549 // Added wxConfig.
550 //
551 // Added wxMiniFrame for wxGTK, (untested.)
552 //
553 // Changed many of the args and return values that were pointers to gdi
554 // objects to references to reflect changes in the wxWindows API.
555 //
556 // Other assorted fixes and additions.
557 //
558 // Revision 1.10 1998/11/25 08:45:23 RD
559 //
560 // Added wxPalette, wxRegion, wxRegionIterator, wxTaskbarIcon
561 // Added events for wxGrid
562 // Other various fixes and additions
563 //
564 // Revision 1.9 1998/11/16 00:00:54 RD
565 // Generic treectrl for wxPython/GTK compiles...
566 //
567 // Revision 1.8 1998/11/11 04:40:20 RD
568 // wxTreeCtrl now works (sort of) for wxPython-GTK. This is the new
569 // TreeCtrl in src/gtk/treectrl.cpp not the old generic one.
570 //
571 // Revision 1.7 1998/11/11 03:12:25 RD
572 //
573 // Additions for wxTreeCtrl
574 //
575 // Revision 1.6 1998/10/20 06:43:55 RD
576 // New wxTreeCtrl wrappers (untested)
577 // some changes in helpers
578 // etc.
579 //
580 // Revision 1.5 1998/10/07 07:34:33 RD
581 // Version 0.4.1 for wxGTK
582 //
583 // Revision 1.4 1998/10/02 06:40:36 RD
584 //
585 // Version 0.4 of wxPython for MSW.
586 //
587 // Revision 1.3 1998/08/18 19:48:15 RD
588 // more wxGTK compatibility things.
589 //
590 // It builds now but there are serious runtime problems...
591 //
592 // Revision 1.2 1998/08/15 07:36:30 RD
593 // - Moved the header in the .i files out of the code that gets put into
594 // the .cpp files. It caused CVS conflicts because of the RCS ID being
595 // different each time.
596 //
597 // - A few minor fixes.
598 //
599 // Revision 1.1 1998/08/09 08:25:49 RD
600 // Initial version
601 //
602 //