]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/src/controls2.i
it is now possible to add custom buttons into wxHtmlHelpFrame's toolbar
[wxWidgets.git] / utils / wxPython / src / controls2.i
CommitLineData
7bf85405
RD
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
03e9bead 13%module controls2
7bf85405 14
03e9bead 15%{
7bf85405 16#include "helpers.h"
2f90df85
RD
17#ifdef __WXMSW__
18#include <windows.h>
19#endif
7bf85405
RD
20#include <wx/listctrl.h>
21#include <wx/treectrl.h>
7bf85405
RD
22%}
23
24//----------------------------------------------------------------------
25
26%include typemaps.i
27%include my_typemaps.i
28
29// Import some definitions of other classes, etc.
30%import _defs.i
31%import misc.i
32%import windows.i
33%import gdi.i
34%import events.i
35%import controls.i
36
b8b8dda7 37%pragma(python) code = "import wx"
9c039d08 38
7bf85405
RD
39//----------------------------------------------------------------------
40
41%{
42extern wxValidator wxPyDefaultValidator;
43%}
44
45//----------------------------------------------------------------------
46
af309447
RD
47enum {
48 wxLIST_MASK_TEXT,
49 wxLIST_MASK_IMAGE,
50 wxLIST_MASK_DATA,
51 wxLIST_MASK_WIDTH,
52 wxLIST_MASK_FORMAT,
bb0054cd 53 wxLIST_MASK_STATE,
af309447
RD
54 wxLIST_STATE_DONTCARE,
55 wxLIST_STATE_DROPHILITED,
56 wxLIST_STATE_FOCUSED,
57 wxLIST_STATE_SELECTED,
58 wxLIST_STATE_CUT,
59 wxLIST_HITTEST_ABOVE,
60 wxLIST_HITTEST_BELOW,
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,
69 wxLIST_NEXT_ABOVE,
70 wxLIST_NEXT_ALL,
71 wxLIST_NEXT_BELOW,
72 wxLIST_NEXT_LEFT,
73 wxLIST_NEXT_RIGHT,
74 wxLIST_ALIGN_DEFAULT,
75 wxLIST_ALIGN_LEFT,
76 wxLIST_ALIGN_TOP,
77 wxLIST_ALIGN_SNAP_TO_GRID,
78 wxLIST_FORMAT_LEFT,
79 wxLIST_FORMAT_RIGHT,
80 wxLIST_FORMAT_CENTRE,
81 wxLIST_FORMAT_CENTER,
82 wxLIST_AUTOSIZE,
83 wxLIST_AUTOSIZE_USEHEADER,
84 wxLIST_RECT_BOUNDS,
85 wxLIST_RECT_ICON,
86 wxLIST_RECT_LABEL,
87 wxLIST_FIND_UP,
88 wxLIST_FIND_DOWN,
89 wxLIST_FIND_LEFT,
90 wxLIST_FIND_RIGHT,
91};
92
93
7bf85405
RD
94class wxListItem {
95public:
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 ;->
105
106 // For columns only
107 int m_format; // left, right, centre
108 int m_width; // width of column
109
110 wxListItem();
111 ~wxListItem();
112};
113
114class wxListEvent: public wxCommandEvent {
115public:
116 int m_code;
117 long m_itemIndex;
118 long m_oldItemIndex;
119 int m_col;
120 bool m_cancelled;
121 wxPoint m_pointDrag;
122 wxListItem m_item;
123};
124
125
126
127
128class wxListCtrl : public wxControl {
129public:
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");
136
b8b8dda7 137 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
9c039d08 138
7bf85405
RD
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);
144 void ClearAll(void);
4f22cf8d 145#ifdef __WXMSW__
7bf85405
RD
146 wxTextCtrl* EditLabel(long item);
147 bool EndEditLabel(bool cancel);
4f22cf8d 148 wxTextCtrl* GetEditControl();
8bf5d46e
RD
149#else
150 void EditLabel(long item);
fb5e0af0 151#endif
7bf85405
RD
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,
156 int direction);
157 bool GetColumn(int col, wxListItem& item);
158 int GetColumnWidth(int col);
159 int GetCountPerPage();
7bf85405
RD
160 wxImageList* GetImageList(int which);
161 long GetItemData(long item);
162
163 %addmethods {
e166644c 164 %new wxListItem* GetItem(long itemId, int col=0) {
7bf85405 165 wxListItem* info = new wxListItem;
0699c864 166 info->m_itemId = itemId;
e166644c 167 info->m_col = col;
f17fee68 168 info->m_mask = 0xFFFF;
7bf85405
RD
169 self->GetItem(*info);
170 return info;
171 }
172 %new wxPoint* GetItemPosition(long item) {
173 wxPoint* pos = new wxPoint;
174 self->GetItemPosition(item, *pos);
175 return pos;
176 }
177 %new wxRect* GetItemRect(long item, int code = wxLIST_RECT_BOUNDS) {
178 wxRect* rect= new wxRect;
179 self->GetItemRect(item, *rect, code);
180 return rect;
181 }
182 }
183
184 int GetItemState(long item, long stateMask);
185 int GetItemCount();
186 int GetItemSpacing(bool isSmall);
187 wxString GetItemText(long item);
188 long GetNextItem(long item,
189 int geometry = wxLIST_NEXT_ALL,
190 int state = wxLIST_STATE_DONTCARE);
191 int GetSelectedItemCount();
fb5e0af0 192#ifdef __WXMSW__
7bf85405 193 wxColour GetTextColour();
4f22cf8d 194 void SetTextColour(const wxColour& col);
fb5e0af0 195#endif
7bf85405
RD
196 long GetTopItem();
197 long HitTest(const wxPoint& point, int& OUTPUT);
0699c864 198 %name(InsertColumnWith)long InsertColumn(long col, wxListItem& info);
7bf85405
RD
199 long InsertColumn(long col, const wxString& heading,
200 int format = wxLIST_FORMAT_LEFT,
201 int width = -1);
202
203 long InsertItem(wxListItem& info);
204 %name(InsertStringItem) long InsertItem(long index, const wxString& label);
205 %name(InsertImageItem) long InsertItem(long index, int imageIndex);
206 %name(InsertImageStringItem)long InsertItem(long index, const wxString& label,
207 int imageIndex);
208
209 bool ScrollList(int dx, int dy);
210 void SetBackgroundColour(const wxColour& col);
211 bool SetColumn(int col, wxListItem& item);
212 bool SetColumnWidth(int col, int width);
213 void SetImageList(wxImageList* imageList, int which);
af309447 214
7bf85405 215 bool SetItem(wxListItem& info);
af309447 216 %name(SetStringItem)long SetItem(long index, int col, const wxString& label,
7bf85405 217 int imageId = -1);
af309447 218
7bf85405
RD
219 bool SetItemData(long item, long data);
220 bool SetItemImage(long item, int image, int selImage);
221 bool SetItemPosition(long item, const wxPoint& pos);
222 bool SetItemState(long item, long state, long stateMask);
223 void SetItemText(long item, const wxString& text);
224 void SetSingleStyle(long style, bool add = TRUE);
7bf85405
RD
225 void SetWindowStyleFlag(long style);
226 // TODO: bool SortItems(wxListCtrlCompare fn, long data);
227};
228
229
230
231//----------------------------------------------------------------------
232
694759cf
RD
233enum wxTreeItemIcon
234{
235 wxTreeItemIcon_Normal, // not selected, not expanded
236 wxTreeItemIcon_Selected, // selected, not expanded
237 wxTreeItemIcon_Expanded, // not selected, expanded
238 wxTreeItemIcon_SelectedExpanded, // selected, expanded
239 wxTreeItemIcon_Max
240};
241
7bf85405 242
d5c9047a
RD
243class wxTreeItemId {
244public:
245 wxTreeItemId();
246 ~wxTreeItemId();
bb0054cd 247 bool IsOk();
d5c9047a 248
d5c9047a
RD
249};
250
251
252
cf694132
RD
253%{
254class wxPyTreeItemData : public wxTreeItemData {
d5c9047a 255public:
cf694132
RD
256 wxPyTreeItemData(PyObject* obj = NULL) {
257 if (obj == NULL)
258 obj = Py_None;
259 Py_INCREF(obj);
260 m_obj = obj;
261 }
d5c9047a 262
cf694132 263 ~wxPyTreeItemData() {
1afc06c2 264 bool doSave = wxPyRestoreThread();
cf694132 265 Py_DECREF(m_obj);
1afc06c2 266 wxPySaveThread(doSave);
cf694132
RD
267 }
268
269 PyObject* GetData() {
270 Py_INCREF(m_obj);
271 return m_obj;
272 }
273
274 void SetData(PyObject* obj) {
275 Py_DECREF(m_obj);
276 m_obj = obj;
277 Py_INCREF(obj);
278 }
279
280 PyObject* m_obj;
d5c9047a 281};
cf694132 282%}
d5c9047a
RD
283
284
285
cf694132
RD
286%name(wxTreeItemData) class wxPyTreeItemData {
287public:
288 wxPyTreeItemData(PyObject* obj = NULL);
289
290 PyObject* GetData();
291 void SetData(PyObject* obj);
292
293 const wxTreeItemId& GetId();
294 void SetId(const wxTreeItemId& id);
295};
296
297
d5c9047a 298
8bf5d46e 299class wxTreeEvent : public wxNotifyEvent {
d5c9047a
RD
300public:
301 wxTreeItemId GetItem();
302 wxTreeItemId GetOldItem();
303 wxPoint GetPoint();
304 int GetCode();
8bf5d46e 305 const wxString& GetLabel();
d5c9047a
RD
306};
307
308
309// These are for the GetFirstChild/GetNextChild methods below
310%typemap(python, in) long& INOUT = long* INOUT;
311%typemap(python, argout) long& INOUT = long* INOUT;
312
313
314class wxTreeCtrl : public wxControl {
315public:
316 wxTreeCtrl(wxWindow *parent, wxWindowID id = -1,
317 const wxPoint& pos = wxPyDefaultPosition,
318 const wxSize& size = wxPyDefaultSize,
319 long style = wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT,
320 const wxValidator& validator = wxPyDefaultValidator,
321 char* name = "wxTreeCtrl");
322
b8b8dda7 323 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
d5c9047a
RD
324
325 size_t GetCount();
326 unsigned int GetIndent();
327 void SetIndent(unsigned int indent);
328 wxImageList *GetImageList();
329 wxImageList *GetStateImageList();
694759cf 330 void SetImageList(wxImageList *imageList/*, int which = wxIMAGE_LIST_NORMAL*/);
d5c9047a
RD
331 void SetStateImageList(wxImageList *imageList);
332
b1462dfa
RD
333 unsigned int GetSpacing();
334 void SetSpacing(unsigned int spacing);
335
d5c9047a 336 wxString GetItemText(const wxTreeItemId& item);
694759cf
RD
337 int GetItemImage(const wxTreeItemId& item,
338 wxTreeItemIcon which = wxTreeItemIcon_Normal);
d5c9047a 339 int GetItemSelectedImage(const wxTreeItemId& item);
d5c9047a
RD
340
341 void SetItemText(const wxTreeItemId& item, const wxString& text);
694759cf
RD
342 void SetItemImage(const wxTreeItemId& item, int image,
343 wxTreeItemIcon which = wxTreeItemIcon_Normal);
d5c9047a 344 void SetItemSelectedImage(const wxTreeItemId& item, int image);
08127323 345 void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE);
d5c9047a 346
cf694132
RD
347 %addmethods {
348 // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData
349 // if needed.
350 wxPyTreeItemData* GetItemData(const wxTreeItemId& item) {
351 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
352 if (data == NULL) {
353 data = new wxPyTreeItemData();
354 self->SetItemData(item, data);
355 }
356 return data;
357 }
358
359 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
360 self->SetItemData(item, data);
361 }
362
363 // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by
364 // automatically creating data classes.
365 PyObject* GetPyData(const wxTreeItemId& item) {
366 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
367 if (data == NULL) {
368 data = new wxPyTreeItemData();
369 self->SetItemData(item, data);
370 }
371 return data->GetData();
372 }
373
374 void SetPyData(const wxTreeItemId& item, PyObject* obj) {
375 wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
376 if (data == NULL) {
377 data = new wxPyTreeItemData(obj);
378 self->SetItemData(item, data);
379 } else
380 data->SetData(obj);
381 }
382 }
383
384
d5c9047a
RD
385 bool IsVisible(const wxTreeItemId& item);
386 bool ItemHasChildren(const wxTreeItemId& item);
387 bool IsExpanded(const wxTreeItemId& item);
388 bool IsSelected(const wxTreeItemId& item);
389
390 wxTreeItemId GetRootItem();
391 wxTreeItemId GetSelection();
eb715945 392 %name(GetItemParent) wxTreeItemId GetParent(const wxTreeItemId& item);
d426c97e
RD
393 //size_t GetSelections(wxArrayTreeItemIds& selection);
394 %addmethods {
395 PyObject* GetSelections() {
396 PyObject* rval = PyList_New(0);
397 wxArrayTreeItemIds array;
398 size_t num, x;
399 num = self->GetSelections(array);
400 for (x=0; x < num; x++) {
401 PyObject* item = wxPyConstructObject((void*)&array.Item(x),
402 "wxTreeItemId");
403 PyList_Append(rval, item);
404 }
405 return rval;
406 }
407 }
408
409
d5c9047a 410
bb0054cd
RD
411 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE);
412
d5c9047a
RD
413 wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT);
414 wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT);
415 wxTreeItemId GetNextSibling(const wxTreeItemId& item);
416 wxTreeItemId GetPrevSibling(const wxTreeItemId& item);
417 wxTreeItemId GetFirstVisibleItem();
418 wxTreeItemId GetNextVisible(const wxTreeItemId& item);
419 wxTreeItemId GetPrevVisible(const wxTreeItemId& item);
d426c97e
RD
420 wxTreeItemId GetLastChild(const wxTreeItemId& item);
421
d5c9047a
RD
422
423
424 wxTreeItemId AddRoot(const wxString& text,
425 int image = -1, int selectedImage = -1,
cf694132 426 wxPyTreeItemData *data = NULL);
d5c9047a
RD
427 wxTreeItemId PrependItem(const wxTreeItemId& parent,
428 const wxString& text,
429 int image = -1, int selectedImage = -1,
cf694132 430 wxPyTreeItemData *data = NULL);
d5c9047a
RD
431 wxTreeItemId InsertItem(const wxTreeItemId& parent,
432 const wxTreeItemId& idPrevious,
433 const wxString& text,
434 int image = -1, int selectedImage = -1,
cf694132 435 wxPyTreeItemData *data = NULL);
d5c9047a
RD
436 wxTreeItemId AppendItem(const wxTreeItemId& parent,
437 const wxString& text,
438 int image = -1, int selectedImage = -1,
cf694132 439 wxPyTreeItemData *data = NULL);
d5c9047a
RD
440
441 void Delete(const wxTreeItemId& item);
08127323 442 void DeleteChildren(const wxTreeItemId& item);
d5c9047a
RD
443 void DeleteAllItems();
444
445 void Expand(const wxTreeItemId& item);
446 void Collapse(const wxTreeItemId& item);
447 void CollapseAndReset(const wxTreeItemId& item);
448 void Toggle(const wxTreeItemId& item);
449
450 void Unselect();
8bf5d46e 451 void UnselectAll();
d5c9047a
RD
452 void SelectItem(const wxTreeItemId& item);
453 void EnsureVisible(const wxTreeItemId& item);
454 void ScrollTo(const wxTreeItemId& item);
8bf5d46e 455#ifdef __WXMSW__
d5c9047a 456 wxTextCtrl* EditLabel(const wxTreeItemId& item);
d5c9047a 457 wxTextCtrl* GetEditControl();
b1462dfa 458 void EndEditLabel(const wxTreeItemId& item, int discardChanges = FALSE);
8bf5d46e
RD
459#else
460 void EditLabel(const wxTreeItemId& item);
461#endif
d5c9047a 462
d426c97e 463 void SortChildren(const wxTreeItemId& item);
d5c9047a 464
b1462dfa 465 void SetItemBold(const wxTreeItemId& item, int bold = TRUE);
b8b8dda7
RD
466 bool IsBold(const wxTreeItemId& item) const;
467 wxTreeItemId HitTest(const wxPoint& point);
c127177f 468
b7e72427
RD
469 void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
470 void SetItemBackgroundColour(const wxTreeItemId& item, const wxColour& col);
471 void SetItemFont(const wxTreeItemId& item, const wxFont& font);
472
4120ef2b 473#ifdef __WXMSW__
b1462dfa
RD
474 void SetItemDropHighlight(const wxTreeItemId& item, int highlight = TRUE);
475
d426c97e
RD
476 //bool GetBoundingRect(const wxTreeItemId& item, wxRect& rect, int textOnly = FALSE)
477 %addmethods {
478 PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
479 wxRect rect;
480 if (self->GetBoundingRect(item, rect, textOnly))
481 return wxPyConstructObject((void*)&rect, "wxRect");
482 else {
483 Py_INCREF(Py_None);
484 return Py_None;
485 }
486 }
487 }
761a9d2b 488#endif
d426c97e 489
c127177f
RD
490%pragma(python) addtoclass = "
491 # Redefine a couple methods that SWIG gets a bit confused on...
492 def GetFirstChild(self,arg0,arg1):
493 val1, val2 = controls2c.wxTreeCtrl_GetFirstChild(self.this,arg0.this,arg1)
494 val1 = wxTreeItemIdPtr(val1)
495 val1.thisown = 1
496 return (val1,val2)
497 def GetNextChild(self,arg0,arg1):
bb0054cd 498 val1, val2 = controls2c.wxTreeCtrl_GetNextChild(self.this,arg0.this,arg1)
c127177f
RD
499 val1 = wxTreeItemIdPtr(val1)
500 val1.thisown = 1
501 return (val1,val2)
502"
d5c9047a
RD
503};
504
d5c9047a 505
7bf85405
RD
506//----------------------------------------------------------------------
507
9c039d08 508#ifdef SKIPTHIS
fb5e0af0 509#ifdef __WXMSW__
7bf85405
RD
510class wxTabEvent : public wxCommandEvent {
511public:
512};
513
514
515
516class wxTabCtrl : public wxControl {
517public:
518 wxTabCtrl(wxWindow* parent, wxWindowID id,
519 const wxPoint& pos = wxPyDefaultPosition,
520 const wxSize& size = wxPyDefaultSize,
521 long style = 0,
522 char* name = "tabCtrl");
523
b8b8dda7 524 %pragma(python) addtomethod = "__init__:wx._StdWindowCallbacks(self)"
9c039d08 525
7bf85405
RD
526 bool DeleteAllItems();
527 bool DeleteItem(int item);
528 wxImageList* GetImageList();
529 int GetItemCount();
530 // TODO: void* GetItemData();
531 int GetItemImage(int item);
532
533 %addmethods {
534 %new wxRect* GetItemRect(int item) {
535 wxRect* rect = new wxRect;
536 self->GetItemRect(item, *rect);
537 return rect;
538 }
539 }
540
541 wxString GetItemText(int item);
542 bool GetRowCount();
543 int GetSelection();
544 int HitTest(const wxPoint& pt, long& OUTPUT);
545 void InsertItem(int item, const wxString& text,
546 int imageId = -1, void* clientData = NULL);
547 // TODO: bool SetItemData(int item, void* data);
548 bool SetItemImage(int item, int image);
549 void SetImageList(wxImageList* imageList);
550 void SetItemSize(const wxSize& size);
551 bool SetItemText(int item, const wxString& text);
552 void SetPadding(const wxSize& padding);
553 int SetSelection(int item);
554
555};
556
9c039d08 557#endif
fb5e0af0
RD
558#endif
559
7bf85405
RD
560//----------------------------------------------------------------------
561
562