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