Commit | Line | Data |
---|---|---|
ebf4302c RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: gizmos.i | |
3 | // Purpose: Wrappers for the "gizmo" classes in wx/contrib | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 23-Nov-2001 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2001 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | %module gizmos | |
14 | ||
15 | ||
16 | %{ | |
6e2129f9 | 17 | #include "wxPython.h" |
611dc22c RD |
18 | #include <wx/gizmos/dynamicsash.h> |
19 | #include <wx/gizmos/editlbox.h> | |
20 | #include <wx/gizmos/splittree.h> | |
950e7faf | 21 | #include <wx/gizmos/ledctrl.h> |
1fded56b | 22 | |
7c379a20 | 23 | #include <wx/listctrl.h> |
1fded56b RD |
24 | #include <wx/treectrl.h> |
25 | #include <wx/imaglist.h> | |
26 | #include "treelistctrl.h" | |
27 | #include "pytree.h" | |
ebf4302c RD |
28 | %} |
29 | ||
30 | //--------------------------------------------------------------------------- | |
31 | ||
32 | %include typemaps.i | |
33 | %include my_typemaps.i | |
34 | ||
35 | %extern wx.i | |
36 | %extern windows.i | |
37 | %extern _defs.i | |
38 | %extern events.i | |
39 | %extern controls.i | |
1fded56b RD |
40 | %extern controls2.i |
41 | %extern gdi.i | |
ebf4302c RD |
42 | |
43 | ||
44 | //---------------------------------------------------------------------- | |
45 | ||
137b5242 RD |
46 | %{ |
47 | // Put some wx default wxChar* values into wxStrings. | |
48 | static const wxString wxPyDynamicSashNameStr(wxT("dynamicSashWindow")); | |
49 | static const wxString wxPyEditableListBoxNameStr(wxT("editableListBox")); | |
1fded56b RD |
50 | static const wxString wxPyTreeListCtrlNameStr(wxT("treelistctrl")); |
51 | static const wxString wxPyEmptyString(wxT("")); | |
137b5242 RD |
52 | %} |
53 | ||
54 | ///---------------------------------------------------------------------- | |
55 | ||
ebf4302c RD |
56 | enum { |
57 | wxEVT_DYNAMIC_SASH_SPLIT, | |
58 | wxEVT_DYNAMIC_SASH_UNIFY, | |
59 | ||
60 | wxDS_MANAGE_SCROLLBARS, | |
61 | wxDS_DRAG_CORNER, | |
62 | }; | |
63 | ||
64 | ||
65 | /* | |
66 | wxDynamicSashSplitEvents are sent to your view by wxDynamicSashWindow | |
67 | whenever your view is being split by the user. It is your | |
68 | responsibility to handle this event by creating a new view window as | |
69 | a child of the wxDynamicSashWindow. wxDynamicSashWindow will | |
70 | automatically reparent it to the proper place in its window hierarchy. | |
71 | */ | |
72 | class wxDynamicSashSplitEvent : public wxCommandEvent { | |
73 | public: | |
74 | wxDynamicSashSplitEvent(wxObject *target); | |
75 | }; | |
76 | ||
77 | ||
78 | /* | |
79 | wxDynamicSashUnifyEvents are sent to your view by wxDynamicSashWindow | |
80 | whenever the sash which splits your view and its sibling is being | |
81 | reunified such that your view is expanding to replace its sibling. | |
82 | You needn't do anything with this event if you are allowing | |
83 | wxDynamicSashWindow to manage your view's scrollbars, but it is useful | |
84 | if you are managing the scrollbars yourself so that you can keep | |
85 | the scrollbars' event handlers connected to your view's event handler | |
86 | class. | |
87 | */ | |
88 | class wxDynamicSashUnifyEvent : public wxCommandEvent { | |
89 | public: | |
90 | wxDynamicSashUnifyEvent(wxObject *target); | |
91 | }; | |
92 | ||
93 | ||
94 | ||
95 | /* | |
96 | ||
97 | wxDynamicSashWindow | |
98 | ||
99 | wxDynamicSashWindow widgets manages the way other widgets are viewed. | |
100 | When a wxDynamicSashWindow is first shown, it will contain one child | |
101 | view, a viewport for that child, and a pair of scrollbars to allow the | |
102 | user to navigate the child view area. Next to each scrollbar is a small | |
103 | tab. By clicking on either tab and dragging to the appropriate spot, a | |
104 | user can split the view area into two smaller views separated by a | |
105 | draggable sash. Later, when the user wishes to reunify the two subviews, | |
106 | the user simply drags the sash to the side of the window. | |
107 | wxDynamicSashWindow will automatically reparent the appropriate child | |
108 | view back up the window hierarchy, and the wxDynamicSashWindow will have | |
109 | only one child view once again. | |
110 | ||
111 | As an application developer, you will simply create a wxDynamicSashWindow | |
112 | using either the Create() function or the more complex constructor | |
611dc22c | 113 | provided below, and then create a view window whose parent is the |
ebf4302c RD |
114 | wxDynamicSashWindow. The child should respond to |
115 | wxDynamicSashSplitEvents -- perhaps with an OnSplit() event handler -- by | |
116 | constructing a new view window whose parent is also the | |
117 | wxDynamicSashWindow. That's it! Now your users can dynamically split | |
118 | and reunify the view you provided. | |
119 | ||
120 | If you wish to handle the scrollbar events for your view, rather than | |
121 | allowing wxDynamicSashWindow to do it for you, things are a bit more | |
122 | complex. (You might want to handle scrollbar events yourself, if, | |
123 | for instance, you wish to scroll a subwindow of the view you add to | |
124 | your wxDynamicSashWindow object, rather than scrolling the whole view.) | |
611dc22c | 125 | In this case, you will need to construct your wxDynamicSashWindow without |
ebf4302c RD |
126 | the wxDS_MANAGE_SCROLLBARS style and you will need to use the |
127 | GetHScrollBar() and GetVScrollBar() methods to retrieve the scrollbar | |
128 | controls and call SetEventHanler() on them to redirect the scrolling | |
129 | events whenever your window is reparented by wxDyanmicSashWindow. | |
130 | You will need to set the scrollbars' event handler at three times: | |
131 | ||
132 | * When your view is created | |
133 | * When your view receives a wxDynamicSashSplitEvent | |
134 | * When your view receives a wxDynamicSashUnifyEvent | |
135 | ||
136 | See the dynsash_switch sample application for an example which does this. | |
137 | ||
138 | */ | |
139 | ||
140 | class wxDynamicSashWindow : public wxWindow { | |
141 | public: | |
142 | wxDynamicSashWindow(wxWindow *parent, wxWindowID id, | |
143 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, | |
144 | long style = wxCLIP_CHILDREN | wxDS_MANAGE_SCROLLBARS | wxDS_DRAG_CORNER, | |
137b5242 | 145 | const wxString& name = wxPyDynamicSashNameStr); |
ebf4302c RD |
146 | %name(wxPreDynamicSashWindow)wxDynamicSashWindow(); |
147 | ||
148 | bool Create(wxWindow *parent, wxWindowID id, | |
149 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, | |
150 | long style = wxCLIP_CHILDREN | wxDS_MANAGE_SCROLLBARS | wxDS_DRAG_CORNER, | |
137b5242 | 151 | const wxString& name = wxPyDynamicSashNameStr); |
ebf4302c RD |
152 | |
153 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" | |
154 | %pragma(python) addtomethod = "wxPreDynamicSashWindow:val._setOORInfo(val)" | |
155 | ||
156 | wxScrollBar *GetHScrollBar(const wxWindow *child) const; | |
157 | wxScrollBar *GetVScrollBar(const wxWindow *child) const; | |
158 | }; | |
159 | ||
160 | ||
161 | ||
162 | //---------------------------------------------------------------------- | |
163 | // Python functions to act like the event macros | |
164 | ||
165 | %pragma(python) code = " | |
166 | def EVT_DYNAMIC_SASH_SPLIT(win, id, func): | |
167 | win.Connect(id, -1, wxEVT_DYNAMIC_SASH_SPLIT, func) | |
168 | ||
169 | def EVT_DYNAMIC_SASH_UNIFY(win, id, func): | |
170 | win.Connect(id, -1, wxEVT_DYNAMIC_SASH_UNIFY, func) | |
171 | " | |
172 | ||
7b7ac0ab RD |
173 | //---------------------------------------------------------------------- |
174 | //---------------------------------------------------------------------- | |
175 | ||
6187ec8f RD |
176 | enum { |
177 | wxEL_ALLOW_NEW, | |
178 | wxEL_ALLOW_EDIT, | |
179 | wxEL_ALLOW_DELETE, | |
180 | }; | |
7b7ac0ab RD |
181 | |
182 | // This class provides a composite control that lets the | |
183 | // user easily enter list of strings | |
184 | class wxEditableListBox : public wxPanel | |
185 | { | |
186 | public: | |
187 | wxEditableListBox(wxWindow *parent, wxWindowID id, | |
188 | const wxString& label, | |
189 | const wxPoint& pos = wxDefaultPosition, | |
190 | const wxSize& size = wxDefaultSize, | |
6187ec8f | 191 | long style = wxEL_ALLOW_NEW | wxEL_ALLOW_EDIT | wxEL_ALLOW_DELETE, |
137b5242 | 192 | const wxString& name = wxPyEditableListBoxNameStr); |
7b7ac0ab | 193 | |
611dc22c RD |
194 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" |
195 | ||
7b7ac0ab RD |
196 | void SetStrings(const wxArrayString& strings); |
197 | ||
198 | //void GetStrings(wxArrayString& strings); | |
199 | %addmethods { | |
200 | PyObject* GetStrings() { | |
201 | wxArrayString strings; | |
202 | self->GetStrings(strings); | |
203 | return wxArrayString2PyList_helper(strings); | |
204 | } | |
205 | } | |
366d7bd6 RD |
206 | |
207 | wxListCtrl* GetListCtrl() { return m_listCtrl; } | |
208 | wxBitmapButton* GetDelButton() { return m_bDel; } | |
209 | wxBitmapButton* GetNewButton() { return m_bNew; } | |
210 | wxBitmapButton* GetUpButton() { return m_bUp; } | |
211 | wxBitmapButton* GetDownButton() { return m_bDown; } | |
212 | wxBitmapButton* GetEditButton() { return m_bEdit; } | |
7b7ac0ab RD |
213 | }; |
214 | ||
215 | ||
216 | ||
611dc22c RD |
217 | //---------------------------------------------------------------------- |
218 | ||
219 | ||
220 | /* | |
221 | * wxRemotelyScrolledTreeCtrl | |
222 | * | |
223 | * This tree control disables its vertical scrollbar and catches scroll | |
224 | * events passed by a scrolled window higher in the hierarchy. | |
225 | * It also updates the scrolled window vertical scrollbar as appropriate. | |
226 | */ | |
227 | ||
228 | %{ | |
229 | typedef wxTreeCtrl wxPyTreeCtrl; | |
230 | %} | |
231 | ||
232 | class wxRemotelyScrolledTreeCtrl: public wxPyTreeCtrl | |
233 | { | |
234 | public: | |
235 | wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id, | |
236 | const wxPoint& pos = wxDefaultPosition, | |
237 | const wxSize& size = wxDefaultSize, | |
238 | long style = wxTR_HAS_BUTTONS); | |
239 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" | |
240 | ||
241 | ||
242 | void HideVScrollbar(); | |
243 | ||
244 | // Adjust the containing wxScrolledWindow's scrollbars appropriately | |
245 | void AdjustRemoteScrollbars(); | |
246 | ||
247 | // Find the scrolled window that contains this control | |
248 | wxScrolledWindow* GetScrolledWindow() const; | |
249 | ||
250 | // Scroll to the given line (in scroll units where each unit is | |
251 | // the height of an item) | |
252 | void ScrollToLine(int posHoriz, int posVert); | |
253 | ||
254 | // The companion window is one which will get notified when certain | |
255 | // events happen such as node expansion | |
256 | void SetCompanionWindow(wxWindow* companion); | |
257 | wxWindow* GetCompanionWindow() const; | |
258 | }; | |
259 | ||
260 | ||
261 | ||
262 | /* | |
263 | * wxTreeCompanionWindow | |
264 | * | |
265 | * A window displaying values associated with tree control items. | |
266 | */ | |
267 | ||
268 | %{ | |
269 | class wxPyTreeCompanionWindow: public wxTreeCompanionWindow | |
270 | { | |
271 | public: | |
272 | wxPyTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1, | |
273 | const wxPoint& pos = wxDefaultPosition, | |
274 | const wxSize& size = wxDefaultSize, | |
275 | long style = 0) | |
276 | : wxTreeCompanionWindow(parent, id, pos, size, style) {} | |
277 | ||
278 | ||
279 | virtual void DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect) { | |
280 | bool found; | |
4268f798 | 281 | wxPyBeginBlockThreads(); |
611dc22c RD |
282 | if ((found = wxPyCBH_findCallback(m_myInst, "DrawItem"))) { |
283 | PyObject* dcobj = wxPyMake_wxObject(&dc); | |
1e4a197e RD |
284 | PyObject* idobj = wxPyConstructObject((void*)&id, wxT("wxTreeItemId"), FALSE); |
285 | PyObject* recobj= wxPyConstructObject((void*)&rect, wxT("wxRect"), FALSE); | |
611dc22c RD |
286 | wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", dcobj, idobj, recobj)); |
287 | Py_DECREF(dcobj); | |
288 | Py_DECREF(idobj); | |
289 | Py_DECREF(recobj); | |
290 | } | |
4268f798 | 291 | wxPyEndBlockThreads(); |
611dc22c RD |
292 | if (! found) |
293 | wxTreeCompanionWindow::DrawItem(dc, id, rect); | |
294 | } | |
295 | ||
296 | PYPRIVATE; | |
297 | }; | |
298 | %} | |
299 | ||
300 | ||
301 | %name(wxTreeCompanionWindow) class wxPyTreeCompanionWindow: public wxWindow | |
302 | { | |
303 | public: | |
304 | wxPyTreeCompanionWindow(wxWindow* parent, wxWindowID id = -1, | |
305 | const wxPoint& pos = wxDefaultPosition, | |
306 | const wxSize& size = wxDefaultSize, | |
307 | long style = 0); | |
308 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
309 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeCompanionWindow)" | |
310 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" | |
311 | ||
312 | wxRemotelyScrolledTreeCtrl* GetTreeCtrl() const; | |
313 | void SetTreeCtrl(wxRemotelyScrolledTreeCtrl* treeCtrl); | |
314 | }; | |
315 | ||
316 | ||
317 | ||
318 | /* | |
319 | * wxThinSplitterWindow | |
320 | * | |
321 | * Implements a splitter with a less obvious sash | |
322 | * than the usual one. | |
323 | */ | |
324 | ||
325 | class wxThinSplitterWindow: public wxSplitterWindow | |
326 | { | |
327 | public: | |
328 | wxThinSplitterWindow(wxWindow* parent, wxWindowID id = -1, | |
329 | const wxPoint& pos = wxDefaultPosition, | |
330 | const wxSize& size = wxDefaultSize, | |
331 | long style = wxSP_3D | wxCLIP_CHILDREN); | |
332 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" | |
333 | ||
334 | }; | |
335 | ||
336 | ||
337 | /* | |
338 | * wxSplitterScrolledWindow | |
339 | * | |
340 | * This scrolled window is aware of the fact that one of its | |
341 | * children is a splitter window. It passes on its scroll events | |
342 | * (after some processing) to both splitter children for them | |
343 | * scroll appropriately. | |
344 | */ | |
345 | ||
346 | class wxSplitterScrolledWindow: public wxScrolledWindow | |
347 | { | |
348 | public: | |
349 | wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id = -1, | |
350 | const wxPoint& pos = wxDefaultPosition, | |
351 | const wxSize& size = wxDefaultSize, | |
352 | long style = 0); | |
353 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" | |
354 | }; | |
355 | ||
356 | ||
950e7faf RD |
357 | //---------------------------------------------------------------------- |
358 | //---------------------------------------------------------------------- | |
359 | ||
360 | ||
361 | enum wxLEDValueAlign | |
362 | { | |
363 | wxLED_ALIGN_LEFT, | |
364 | wxLED_ALIGN_RIGHT, | |
365 | wxLED_ALIGN_CENTER, | |
366 | ||
367 | wxLED_ALIGN_MASK, | |
368 | ||
369 | wxLED_DRAW_FADED, | |
370 | }; | |
371 | ||
372 | ||
373 | class wxLEDNumberCtrl : public wxControl | |
374 | { | |
375 | public: | |
376 | // Constructors. | |
377 | wxLEDNumberCtrl(wxWindow *parent, wxWindowID id = -1, | |
378 | const wxPoint& pos = wxDefaultPosition, | |
379 | const wxSize& size = wxDefaultSize, | |
380 | long style = wxLED_ALIGN_LEFT | wxLED_DRAW_FADED); | |
381 | %name(wxPreLEDNumberCtrl) wxLEDNumberCtrl(); | |
382 | ||
383 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" | |
384 | %pragma(python) addtomethod = "wxPreLEDNumberCtrl:val._setOORInfo(val)" | |
385 | ||
386 | // Create functions. | |
387 | bool Create(wxWindow *parent, wxWindowID id = -1, | |
388 | const wxPoint& pos = wxDefaultPosition, | |
389 | const wxSize& size = wxDefaultSize, | |
390 | long style = wxLED_ALIGN_LEFT | wxLED_DRAW_FADED); | |
391 | ||
392 | wxLEDValueAlign GetAlignment() const { return m_Alignment; } | |
393 | bool GetDrawFaded() const { return m_DrawFaded; } | |
394 | const wxString &GetValue() const { return m_Value; } | |
395 | ||
396 | void SetAlignment(wxLEDValueAlign Alignment, bool Redraw = true); | |
397 | void SetDrawFaded(bool DrawFaded, bool Redraw = true); | |
398 | void SetValue(const wxString &Value, bool Redraw = true); | |
399 | ||
400 | }; | |
401 | ||
1fded56b RD |
402 | |
403 | ||
404 | //---------------------------------------------------------------------------- | |
405 | // wxTreeListCtrl - the multicolumn tree control | |
406 | //---------------------------------------------------------------------------- | |
407 | ||
408 | enum wxTreeListColumnAlign { | |
409 | wxTL_ALIGN_LEFT, | |
410 | wxTL_ALIGN_RIGHT, | |
411 | wxTL_ALIGN_CENTER | |
412 | }; | |
413 | ||
414 | ||
415 | ||
416 | enum { | |
417 | wxTREE_HITTEST_ONITEMCOLUMN | |
418 | }; | |
419 | ||
420 | ||
421 | ||
422 | ||
423 | class wxTreeListColumnInfo: public wxObject { | |
424 | public: | |
425 | wxTreeListColumnInfo(const wxString& text = wxPyEmptyString, | |
426 | int image = -1, | |
427 | size_t width = 100, | |
428 | wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT); | |
429 | ||
430 | wxTreeListColumnAlign GetAlignment() const; | |
431 | wxString GetText() const; | |
432 | int GetImage() const; | |
433 | int GetSelectedImage() const; | |
434 | size_t GetWidth() const; | |
435 | ||
436 | void SetAlignment(wxTreeListColumnAlign alignment); | |
437 | void SetText(const wxString& text); | |
438 | void SetImage(int image); | |
439 | void SetSelectedImage(int image); | |
440 | void SetWidth(size_t with); | |
441 | }; | |
442 | ||
443 | ||
444 | ||
445 | ||
446 | %{ // C++ version of Python aware control | |
447 | class wxPyTreeListCtrl : public wxTreeListCtrl { | |
448 | DECLARE_ABSTRACT_CLASS(wxPyTreeListCtrl); | |
449 | public: | |
450 | wxPyTreeListCtrl() : wxTreeListCtrl() {} | |
451 | wxPyTreeListCtrl(wxWindow *parent, wxWindowID id, | |
452 | const wxPoint& pos, | |
453 | const wxSize& size, | |
454 | long style, | |
455 | const wxValidator &validator, | |
456 | const wxString& name) : | |
457 | wxTreeListCtrl(parent, id, pos, size, style, validator, name) {} | |
458 | ||
459 | int OnCompareItems(const wxTreeItemId& item1, | |
460 | const wxTreeItemId& item2) { | |
461 | int rval = 0; | |
462 | bool found; | |
463 | wxPyBeginBlockThreads(); | |
464 | if ((found = wxPyCBH_findCallback(m_myInst, "OnCompareItems"))) { | |
465 | PyObject *o1 = wxPyConstructObject((void*)&item1, wxT("wxTreeItemId"), 0); | |
466 | PyObject *o2 = wxPyConstructObject((void*)&item2, wxT("wxTreeItemId"), 0); | |
467 | rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OO)",o1,o2)); | |
468 | Py_DECREF(o1); | |
469 | Py_DECREF(o2); | |
470 | } | |
471 | wxPyEndBlockThreads(); | |
472 | if (! found) | |
473 | rval = wxTreeListCtrl::OnCompareItems(item1, item2); | |
474 | return rval; | |
475 | } | |
476 | PYPRIVATE; | |
477 | }; | |
478 | ||
479 | IMPLEMENT_ABSTRACT_CLASS(wxPyTreeListCtrl, wxTreeListCtrl) | |
480 | ||
481 | %} | |
482 | ||
483 | ||
484 | ||
485 | ||
486 | // These are for the GetFirstChild/GetNextChild methods below | |
487 | %{ | |
488 | static const long longzero = 0; | |
489 | %} | |
490 | %typemap(python, in) long& INOUT = long* INOUT; | |
491 | %typemap(python, argout) long& INOUT = long* INOUT; | |
492 | ||
493 | ||
494 | %name(wxTreeListCtrl) class wxPyTreeListCtrl : public wxControl | |
495 | { | |
496 | public: | |
497 | wxPyTreeListCtrl(wxWindow *parent, wxWindowID id = -1, | |
498 | const wxPoint& pos = wxDefaultPosition, | |
499 | const wxSize& size = wxDefaultSize, | |
500 | long style = wxTR_DEFAULT_STYLE, | |
501 | const wxValidator &validator = wxDefaultValidator, | |
502 | const wxString& name = wxPyTreeListCtrlNameStr ); | |
503 | %name(wxPreTreeListCtrl)wxPyTreeListCtrl(); | |
504 | ||
505 | bool Create(wxWindow *parent, wxWindowID id = -1, | |
506 | const wxPoint& pos = wxDefaultPosition, | |
507 | const wxSize& size = wxDefaultSize, | |
508 | long style = wxTR_DEFAULT_STYLE, | |
509 | const wxValidator &validator = wxDefaultValidator, | |
510 | const wxString& name = wxPyTreeListCtrlNameStr ); | |
511 | ||
512 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
513 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxTreeListCtrl)" | |
514 | ||
515 | %pragma(python) addtomethod = "__init__:self._setOORInfo(self)" | |
516 | %pragma(python) addtomethod = "wxPreTreeListCtrl:val._setOORInfo(val)" | |
517 | ||
518 | ||
519 | ||
520 | // get the total number of items in the control | |
521 | size_t GetCount() const; | |
522 | ||
523 | // indent is the number of pixels the children are indented relative to | |
524 | // the parents position. SetIndent() also redraws the control | |
525 | // immediately. | |
526 | unsigned int GetIndent() const; | |
527 | void SetIndent(unsigned int indent); | |
528 | ||
529 | // spacing is the number of pixels between the start and the Text | |
530 | unsigned int GetSpacing() const; | |
531 | void SetSpacing(unsigned int spacing); | |
532 | ||
533 | // line spacing is the space above and below the text on each line | |
534 | unsigned int GetLineSpacing() const; | |
535 | void SetLineSpacing(unsigned int spacing); | |
536 | ||
537 | // image list: these functions allow to associate an image list with | |
538 | // the control and retrieve it. Note that when assigned with | |
539 | // SetImageList, the control does _not_ delete | |
540 | // the associated image list when it's deleted in order to allow image | |
541 | // lists to be shared between different controls. If you use | |
542 | // AssignImageList, the control _does_ delete the image list. | |
543 | // | |
544 | // The normal image list is for the icons which correspond to the | |
545 | // normal tree item state (whether it is selected or not). | |
546 | // Additionally, the application might choose to show a state icon | |
547 | // which corresponds to an app-defined item state (for example, | |
548 | // checked/unchecked) which are taken from the state image list. | |
549 | wxImageList *GetImageList() const; | |
550 | wxImageList *GetStateImageList() const; | |
551 | wxImageList *GetButtonsImageList() const; | |
552 | ||
553 | void SetImageList(wxImageList *imageList); | |
554 | void SetStateImageList(wxImageList *imageList); | |
555 | void SetButtonsImageList(wxImageList *imageList); | |
15d9a04c | 556 | |
1fded56b | 557 | void AssignImageList(wxImageList *imageList); |
15d9a04c RD |
558 | %pragma(python) addtomethod = "AssignImageList:_args[0].thisown = 0" |
559 | ||
1fded56b | 560 | void AssignStateImageList(wxImageList *imageList); |
15d9a04c RD |
561 | %pragma(python) addtomethod = "AssignStateImageList:_args[0].thisown = 0" |
562 | ||
1fded56b | 563 | void AssignButtonsImageList(wxImageList *imageList); |
15d9a04c | 564 | %pragma(python) addtomethod = "AssignButtonsImageList:_args[0].thisown = 0" |
1fded56b RD |
565 | |
566 | ||
567 | ||
568 | // adds a column | |
569 | void AddColumn(const wxString& text); | |
570 | %name(AddColumnInfo) void AddColumn(const wxTreeListColumnInfo& col); | |
571 | ||
572 | // inserts a column before the given one | |
573 | void InsertColumn(size_t before, const wxString& text); | |
574 | %name(InsertColumnInfo) void InsertColumn(size_t before, const wxTreeListColumnInfo& col); | |
575 | ||
576 | // deletes the given column - does not delete the corresponding column | |
577 | // of each item | |
578 | void RemoveColumn(size_t column); | |
579 | ||
580 | // returns the number of columns in the ctrl | |
581 | size_t GetColumnCount() const; | |
582 | ||
583 | void SetColumnWidth(size_t column, size_t width); | |
584 | int GetColumnWidth(size_t column) const; | |
585 | ||
586 | // tells which column is the "main" one, i.e. the "threaded" one | |
587 | void SetMainColumn(size_t column); | |
588 | size_t GetMainColumn() const; | |
589 | ||
590 | void SetColumnText(size_t column, const wxString& text); | |
591 | wxString GetColumnText(size_t column) const; | |
592 | ||
593 | void SetColumn(size_t column, const wxTreeListColumnInfo& info); | |
594 | wxTreeListColumnInfo& GetColumn(size_t column); | |
595 | ||
596 | // other column-related methods | |
597 | void SetColumnAlignment(size_t column, wxTreeListColumnAlign align); | |
598 | wxTreeListColumnAlign GetColumnAlignment(size_t column) const; | |
599 | ||
600 | void SetColumnImage(size_t column, int image); | |
601 | int GetColumnImage(size_t column) const; | |
602 | ||
603 | ||
604 | %addmethods { | |
605 | // retrieves item's label of the given column (main column by default) | |
606 | wxString GetItemText(const wxTreeItemId& item, int column = -1) { | |
607 | if (column < 0) column = self->GetMainColumn(); | |
608 | return self->GetItemText(item, column); | |
609 | } | |
610 | ||
611 | // get one of the images associated with the item (normal by default) | |
612 | int GetItemImage(const wxTreeItemId& item, int column = -1, | |
613 | wxTreeItemIcon which = wxTreeItemIcon_Normal) { | |
614 | if (column < 0) column = self->GetMainColumn(); | |
615 | return self->GetItemImage(item, column, which); | |
616 | } | |
617 | ||
618 | // set item's label (main column by default) | |
619 | void SetItemText(const wxTreeItemId& item, const wxString& text, int column = -1) { | |
620 | if (column < 0) column = self->GetMainColumn(); | |
621 | self->SetItemText(item, column, text); | |
622 | } | |
623 | ||
624 | // set one of the images associated with the item (normal by default) | |
625 | // the which parameter is ignored for all columns but the main one | |
626 | void SetItemImage(const wxTreeItemId& item, int image, int column = -1, | |
627 | wxTreeItemIcon which = wxTreeItemIcon_Normal) { | |
628 | if (column < 0) column = self->GetMainColumn(); | |
629 | self->SetItemImage(item, column, image, which); | |
630 | } | |
631 | ||
632 | ||
633 | // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData | |
634 | // if needed. | |
635 | wxPyTreeItemData* GetItemData(const wxTreeItemId& item) { | |
636 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
637 | if (data == NULL) { | |
638 | data = new wxPyTreeItemData(); | |
639 | data->SetId(item); // set the id | |
640 | self->SetItemData(item, data); | |
641 | } | |
642 | return data; | |
643 | } | |
644 | ||
645 | void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) { | |
646 | data->SetId(item); // set the id | |
647 | self->SetItemData(item, data); | |
648 | } | |
649 | ||
650 | // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by | |
651 | // automatically creating data classes. | |
652 | PyObject* GetPyData(const wxTreeItemId& item) { | |
653 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
654 | if (data == NULL) { | |
655 | data = new wxPyTreeItemData(); | |
656 | data->SetId(item); // set the id | |
657 | self->SetItemData(item, data); | |
658 | } | |
659 | return data->GetData(); | |
660 | } | |
661 | ||
662 | void SetPyData(const wxTreeItemId& item, PyObject* obj) { | |
663 | wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); | |
664 | if (data == NULL) { | |
665 | data = new wxPyTreeItemData(obj); | |
666 | data->SetId(item); // set the id | |
667 | self->SetItemData(item, data); | |
668 | } else | |
669 | data->SetData(obj); | |
670 | } | |
671 | } | |
672 | ||
673 | ||
674 | // force appearance of [+] button near the item. This is useful to | |
675 | // allow the user to expand the items which don't have any children now | |
676 | // - but instead add them only when needed, thus minimizing memory | |
677 | // usage and loading time. | |
678 | void SetItemHasChildren(const wxTreeItemId& item, bool has = TRUE); | |
679 | ||
680 | // the item will be shown in bold | |
681 | void SetItemBold(const wxTreeItemId& item, bool bold = TRUE); | |
682 | ||
683 | // set the item's text colour | |
684 | void SetItemTextColour(const wxTreeItemId& item, const wxColour& col); | |
685 | ||
686 | // set the item's background colour | |
687 | void SetItemBackgroundColour(const wxTreeItemId& item, | |
688 | const wxColour& col); | |
689 | ||
690 | // set the item's font (should be of the same height for all items) | |
691 | void SetItemFont(const wxTreeItemId& item, const wxFont& font); | |
692 | ||
693 | ||
694 | bool GetItemBold(const wxTreeItemId& item) const; | |
695 | wxColour GetItemTextColour(const wxTreeItemId& item) const; | |
696 | wxColour GetItemBackgroundColour(const wxTreeItemId& item) const; | |
697 | wxFont GetItemFont(const wxTreeItemId& item) const; | |
698 | ||
699 | // is the item visible (it might be outside the view or not expanded)? | |
700 | bool IsVisible(const wxTreeItemId& item) const; | |
701 | ||
702 | // does the item has any children? | |
703 | bool ItemHasChildren(const wxTreeItemId& item) const; | |
704 | ||
705 | // is the item expanded (only makes sense if HasChildren())? | |
706 | bool IsExpanded(const wxTreeItemId& item) const; | |
707 | ||
708 | // is this item currently selected (the same as has focus)? | |
709 | bool IsSelected(const wxTreeItemId& item) const; | |
710 | ||
711 | // is item text in bold font? | |
712 | bool IsBold(const wxTreeItemId& item) const; | |
713 | ||
714 | // if 'recursively' is FALSE, only immediate children count, otherwise | |
715 | // the returned number is the number of all items in this branch | |
716 | size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = TRUE); | |
717 | ||
718 | ||
719 | // wxTreeItemId.IsOk() will return FALSE if there is no such item | |
720 | ||
721 | // get the root tree item | |
722 | wxTreeItemId GetRootItem() const; | |
723 | ||
724 | // get the item currently selected (may return NULL if no selection) | |
725 | wxTreeItemId GetSelection() const; | |
726 | ||
727 | // get the items currently selected, return the number of such item | |
728 | //size_t GetSelections(wxArrayTreeItemIds&) const; | |
729 | %addmethods { | |
730 | PyObject* GetSelections() { | |
731 | wxPyBeginBlockThreads(); | |
732 | PyObject* rval = PyList_New(0); | |
733 | wxArrayTreeItemIds array; | |
734 | size_t num, x; | |
735 | num = self->GetSelections(array); | |
736 | for (x=0; x < num; x++) { | |
737 | wxTreeItemId *tii = new wxTreeItemId(array.Item(x)); | |
738 | PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), TRUE); | |
739 | PyList_Append(rval, item); | |
740 | } | |
741 | wxPyEndBlockThreads(); | |
742 | return rval; | |
743 | } | |
744 | } | |
745 | ||
746 | ||
747 | // get the parent of this item (may return NULL if root) | |
748 | %name(GetItemParent)wxTreeItemId GetParent(const wxTreeItemId& item) const; | |
749 | ||
750 | // for this enumeration function you must pass in a "cookie" parameter | |
751 | // which is opaque for the application but is necessary for the library | |
752 | // to make these functions reentrant (i.e. allow more than one | |
753 | // enumeration on one and the same object simultaneously). Of course, | |
754 | // the "cookie" passed to GetFirstChild() and GetNextChild() should be | |
755 | // the same! | |
756 | ||
757 | // get the first child of this item | |
758 | wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& INOUT = longzero) const; | |
759 | ||
760 | // get the next child | |
761 | wxTreeItemId GetNextChild(const wxTreeItemId& item, long& INOUT) const; | |
762 | ||
763 | // get the last child of this item - this method doesn't use cookies | |
764 | wxTreeItemId GetLastChild(const wxTreeItemId& item) const; | |
765 | ||
766 | // get the next sibling of this item | |
767 | wxTreeItemId GetNextSibling(const wxTreeItemId& item) const; | |
768 | ||
769 | // get the previous sibling | |
770 | wxTreeItemId GetPrevSibling(const wxTreeItemId& item) const; | |
771 | ||
772 | // get first visible item | |
773 | wxTreeItemId GetFirstVisibleItem() const; | |
774 | ||
775 | // get the next visible item: item must be visible itself! | |
776 | // see IsVisible() and wxTreeCtrl::GetFirstVisibleItem() | |
777 | wxTreeItemId GetNextVisible(const wxTreeItemId& item) const; | |
778 | ||
779 | // get the previous visible item: item must be visible itself! | |
780 | wxTreeItemId GetPrevVisible(const wxTreeItemId& item) const; | |
781 | ||
782 | // Only for internal use right now, but should probably be public | |
783 | wxTreeItemId GetNext(const wxTreeItemId& item) const; | |
784 | ||
785 | ||
786 | // add the root node to the tree | |
787 | wxTreeItemId AddRoot(const wxString& text, | |
788 | int image = -1, int selectedImage = -1, | |
789 | wxPyTreeItemData *data = NULL); | |
790 | ||
791 | // insert a new item in as the first child of the parent | |
792 | wxTreeItemId PrependItem(const wxTreeItemId& parent, | |
793 | const wxString& text, | |
794 | int image = -1, int selectedImage = -1, | |
795 | wxPyTreeItemData *data = NULL); | |
796 | ||
797 | // insert a new item after a given one | |
798 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
799 | const wxTreeItemId& idPrevious, | |
800 | const wxString& text, | |
801 | int image = -1, int selectedImage = -1, | |
802 | wxPyTreeItemData *data = NULL); | |
803 | ||
804 | // insert a new item before the one with the given index | |
805 | %name(InsertItemBefore) | |
806 | wxTreeItemId InsertItem(const wxTreeItemId& parent, | |
807 | size_t index, | |
808 | const wxString& text, | |
809 | int image = -1, int selectedImage = -1, | |
810 | wxPyTreeItemData *data = NULL); | |
811 | ||
812 | // insert a new item in as the last child of the parent | |
813 | wxTreeItemId AppendItem(const wxTreeItemId& parent, | |
814 | const wxString& text, | |
815 | int image = -1, int selectedImage = -1, | |
816 | wxPyTreeItemData *data = NULL); | |
817 | ||
818 | // delete this item and associated data if any | |
819 | void Delete(const wxTreeItemId& item); | |
820 | ||
821 | // delete all children (but don't delete the item itself) | |
822 | // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events | |
823 | void DeleteChildren(const wxTreeItemId& item); | |
824 | ||
825 | // delete all items from the tree | |
826 | // NB: this won't send wxEVT_COMMAND_TREE_ITEM_DELETED events | |
827 | void DeleteAllItems(); | |
828 | ||
829 | // expand this item | |
830 | void Expand(const wxTreeItemId& item); | |
831 | ||
832 | // expand this item and all subitems recursively | |
833 | void ExpandAll(const wxTreeItemId& item); | |
834 | ||
835 | // collapse the item without removing its children | |
836 | void Collapse(const wxTreeItemId& item); | |
837 | ||
838 | // collapse the item and remove all children | |
839 | void CollapseAndReset(const wxTreeItemId& item); | |
840 | ||
841 | // toggles the current state | |
842 | void Toggle(const wxTreeItemId& item); | |
843 | ||
844 | // remove the selection from currently selected item (if any) | |
845 | void Unselect(); | |
846 | void UnselectAll(); | |
847 | ||
848 | // select this item | |
849 | void SelectItem(const wxTreeItemId& item, bool unselect_others=TRUE, | |
850 | bool extended_select=FALSE); | |
851 | ||
852 | // make sure this item is visible (expanding the parent item and/or | |
853 | // scrolling to this item if necessary) | |
854 | void EnsureVisible(const wxTreeItemId& item); | |
855 | ||
856 | // scroll to this item (but don't expand its parent) | |
857 | void ScrollTo(const wxTreeItemId& item); | |
858 | ||
859 | // Returns wxTreeItemId, flags, and column | |
860 | wxTreeItemId HitTest(const wxPoint& point, int& OUTPUT, int& OUTPUT); | |
861 | ||
862 | %addmethods { | |
863 | // get the bounding rectangle of the item (or of its label only) | |
864 | PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = FALSE) { | |
865 | wxRect rect; | |
866 | if (self->GetBoundingRect(item, rect, textOnly)) { | |
867 | wxPyBeginBlockThreads(); | |
868 | wxRect* r = new wxRect(rect); | |
869 | PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), 1); | |
870 | wxPyEndBlockThreads(); | |
871 | return val; | |
872 | } | |
873 | else { | |
874 | Py_INCREF(Py_None); | |
875 | return Py_None; | |
876 | } | |
877 | } | |
878 | } | |
879 | ||
880 | ||
881 | // Start editing the item label: this (temporarily) replaces the item | |
882 | // with a one line edit control. The item will be selected if it hadn't | |
883 | // been before. | |
884 | void EditLabel( const wxTreeItemId& item ); | |
885 | void Edit( const wxTreeItemId& item ); | |
886 | ||
887 | // sort the children of this item using OnCompareItems | |
888 | void SortChildren(const wxTreeItemId& item); | |
889 | ||
890 | // get the selected item image | |
891 | int GetItemSelectedImage(const wxTreeItemId& item) const; | |
892 | ||
893 | // set the selected item image | |
894 | void SetItemSelectedImage(const wxTreeItemId& item, int image); | |
895 | ||
896 | ||
897 | wxWindow* GetHeaderWindow() const; | |
898 | wxWindow* GetMainWindow() const; | |
899 | ||
900 | %pragma(python) addtoclass = " | |
901 | # Redefine some methods that SWIG gets a bit confused on... | |
902 | def GetFirstChild(self, *_args, **_kwargs): | |
903 | val1,val2 = gizmosc.wxTreeListCtrl_GetFirstChild(self, *_args, **_kwargs) | |
904 | val1 = wxTreeItemIdPtr(val1) | |
905 | val1.thisown = 1 | |
906 | return (val1,val2) | |
907 | def GetNextChild(self, *_args, **_kwargs): | |
908 | val1,val2 = gizmosc.wxTreeListCtrl_GetNextChild(self, *_args, **_kwargs) | |
909 | val1 = wxTreeItemIdPtr(val1) | |
910 | val1.thisown = 1 | |
911 | return (val1,val2) | |
912 | def HitTest(self, *_args, **_kwargs): | |
913 | val1, val2, val3 = gizmosc.wxTreeListCtrl_HitTest(self, *_args, **_kwargs) | |
914 | val1 = wxTreeItemIdPtr(val1) | |
915 | val1.thisown = 1 | |
916 | return (val1, val2, val3) | |
917 | " | |
918 | }; | |
919 | ||
920 | ||
921 | ||
922 | ||
950e7faf | 923 | //---------------------------------------------------------------------- |
ebf4302c RD |
924 | //---------------------------------------------------------------------- |
925 | ||
926 | %init %{ | |
927 | ||
611dc22c | 928 | wxPyPtrTypeMap_Add("wxTreeCompanionWindow", "wxPyTreeCompanionWindow"); |
1fded56b | 929 | wxPyPtrTypeMap_Add("wxTreeListCtrl", "wxPyTreeListCtrl"); |
ebf4302c RD |
930 | %} |
931 | ||
932 | ||
ebf4302c RD |
933 | %pragma(python) include="_gizmoextras.py"; |
934 | ||
935 | //---------------------------------------------------------------------- | |
936 | //---------------------------------------------------------------------- | |
937 | ||
938 | ||
611dc22c RD |
939 | |
940 | ||
941 | ||
942 |