]> git.saurik.com Git - wxWidgets.git/blame - wxPython/contrib/gizmos/gizmos.i
memory dc must have bitmap selected into it before it can be used for measuring
[wxWidgets.git] / wxPython / contrib / gizmos / gizmos.i
CommitLineData
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
c8fac2b6
RD
13%define DOCSTRING
14"Various *gizmo* classes: `DynamicSashWindow`, `EditableListBox`,
15`LEDNumberCtrl`, `TreeListCtrl`, etc."
16%enddef
17
b2eb030f 18%module(package="wx", docstring=DOCSTRING) gizmos
ebf4302c
RD
19
20
21%{
d14a1e28
RD
22#include "wx/wxPython/wxPython.h"
23#include "wx/wxPython/pyclasses.h"
28eab81f 24
611dc22c
RD
25#include <wx/gizmos/dynamicsash.h>
26#include <wx/gizmos/editlbox.h>
27#include <wx/gizmos/splittree.h>
950e7faf 28#include <wx/gizmos/ledctrl.h>
7e4b7f9a 29#include <wx/gizmos/statpict.h>
1fded56b 30
7c379a20 31#include <wx/listctrl.h>
1fded56b
RD
32#include <wx/treectrl.h>
33#include <wx/imaglist.h>
28eab81f
RD
34
35#include "wx/treelistctrl.h"
d14a1e28 36#include "wx/wxPython/pytree.h"
ebf4302c 37
137b5242
RD
38%}
39
d14a1e28
RD
40//---------------------------------------------------------------------------
41
42%import windows.i
43%import controls.i
648d396c
RD
44%pythoncode { import wx }
45%pythoncode { __docfilter__ = wx._core.__DocFilter(globals()) }
d14a1e28 46
b2dc1044 47
089142a5
RD
48MAKE_CONST_WXSTRING2(DynamicSashNameStr, wxT("dynamicSashWindow"));
49MAKE_CONST_WXSTRING2(EditableListBoxNameStr, wxT("editableListBox"));
50MAKE_CONST_WXSTRING2(TreeListCtrlNameStr, wxT("treelistctrl"));
d3397f6a 51MAKE_CONST_WXSTRING(StaticPictureNameStr);
7e4b7f9a 52
b2dc1044
RD
53MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
54
d14a1e28 55//---------------------------------------------------------------------------
137b5242 56
ebf4302c 57enum {
ebf4302c
RD
58 wxDS_MANAGE_SCROLLBARS,
59 wxDS_DRAG_CORNER,
60};
61
6c56259a
RD
62%constant wxEventType wxEVT_DYNAMIC_SASH_SPLIT;
63%constant wxEventType wxEVT_DYNAMIC_SASH_UNIFY;
64
ebf4302c
RD
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*/
73class wxDynamicSashSplitEvent : public wxCommandEvent {
74public:
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*/
89class wxDynamicSashUnifyEvent : public wxCommandEvent {
90public:
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
611dc22c 114 provided below, and then create a view window whose parent is the
ebf4302c
RD
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.)
611dc22c 126 In this case, you will need to construct your wxDynamicSashWindow without
ebf4302c
RD
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
ab1f7d2a
RD
141MustHaveApp(wxDynamicSashWindow);
142
ebf4302c
RD
143class wxDynamicSashWindow : public wxWindow {
144public:
2b9048c5
RD
145 %pythonAppend wxDynamicSashWindow "self._setOORInfo(self)"
146 %pythonAppend wxDynamicSashWindow() ""
d14a1e28 147
d5573410 148 wxDynamicSashWindow(wxWindow *parent, wxWindowID id=-1,
ebf4302c
RD
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);
1b8c7ba6 152 %RenameCtor(PreDynamicSashWindow, wxDynamicSashWindow());
ebf4302c 153
d5573410 154 bool Create(wxWindow *parent, wxWindowID id=-1,
ebf4302c
RD
155 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
156 long style = wxCLIP_CHILDREN | wxDS_MANAGE_SCROLLBARS | wxDS_DRAG_CORNER,
137b5242 157 const wxString& name = wxPyDynamicSashNameStr);
ebf4302c 158
ebf4302c
RD
159 wxScrollBar *GetHScrollBar(const wxWindow *child) const;
160 wxScrollBar *GetVScrollBar(const wxWindow *child) const;
161};
162
163
164
d14a1e28
RD
165%pythoncode {
166EVT_DYNAMIC_SASH_SPLIT = wx.PyEventBinder( wxEVT_DYNAMIC_SASH_SPLIT, 1 )
167EVT_DYNAMIC_SASH_UNIFY = wx.PyEventBinder( wxEVT_DYNAMIC_SASH_UNIFY, 1 )
168}
ebf4302c 169
d14a1e28
RD
170//---------------------------------------------------------------------------
171//---------------------------------------------------------------------------
7b7ac0ab 172
6187ec8f
RD
173enum {
174 wxEL_ALLOW_NEW,
175 wxEL_ALLOW_EDIT,
176 wxEL_ALLOW_DELETE,
177};
7b7ac0ab
RD
178
179// This class provides a composite control that lets the
180// user easily enter list of strings
ab1f7d2a 181MustHaveApp(wxEditableListBox);
7b7ac0ab
RD
182class wxEditableListBox : public wxPanel
183{
184public:
2b9048c5
RD
185 %pythonAppend wxEditableListBox "self._setOORInfo(self)"
186 %pythonAppend wxEditableListBox() ""
d14a1e28 187
d5573410
RD
188 wxEditableListBox(wxWindow *parent, wxWindowID id=-1,
189 const wxString& label = wxPyEmptyString,
7b7ac0ab
RD
190 const wxPoint& pos = wxDefaultPosition,
191 const wxSize& size = wxDefaultSize,
6187ec8f 192 long style = wxEL_ALLOW_NEW | wxEL_ALLOW_EDIT | wxEL_ALLOW_DELETE,
137b5242 193 const wxString& name = wxPyEditableListBoxNameStr);
7b7ac0ab 194
611dc22c 195
7b7ac0ab
RD
196 void SetStrings(const wxArrayString& strings);
197
198 //void GetStrings(wxArrayString& strings);
d14a1e28 199 %extend {
7b7ac0ab
RD
200 PyObject* GetStrings() {
201 wxArrayString strings;
202 self->GetStrings(strings);
203 return wxArrayString2PyList_helper(strings);
204 }
205 }
366d7bd6 206
15f80007 207 wxPyListCtrl* GetListCtrl();
d14a1e28
RD
208 wxBitmapButton* GetDelButton();
209 wxBitmapButton* GetNewButton();
210 wxBitmapButton* GetUpButton();
211 wxBitmapButton* GetDownButton();
212 wxBitmapButton* GetEditButton();
7b7ac0ab
RD
213};
214
215
216
d14a1e28 217//---------------------------------------------------------------------------
611dc22c
RD
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
ab1f7d2a
RD
232MustHaveApp(wxRemotelyScrolledTreeCtrl);
233
611dc22c
RD
234class wxRemotelyScrolledTreeCtrl: public wxPyTreeCtrl
235{
236public:
2b9048c5
RD
237 %pythonAppend wxRemotelyScrolledTreeCtrl "self._setOORInfo(self)"
238 %pythonAppend wxRemotelyScrolledTreeCtrl() ""
d14a1e28 239
611dc22c
RD
240 wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id,
241 const wxPoint& pos = wxDefaultPosition,
242 const wxSize& size = wxDefaultSize,
243 long style = wxTR_HAS_BUTTONS);
611dc22c
RD
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%{
273class wxPyTreeCompanionWindow: public wxTreeCompanionWindow
274{
275public:
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;
6e6b3557 285 wxPyBlock_t blocked = wxPyBeginBlockThreads();
611dc22c 286 if ((found = wxPyCBH_findCallback(m_myInst, "DrawItem"))) {
6d450e1a 287 PyObject* dcobj = wxPyMake_wxObject(&dc,false);
a72f4631
RD
288 PyObject* idobj = wxPyConstructObject((void*)&id, wxT("wxTreeItemId"), false);
289 PyObject* recobj= wxPyConstructObject((void*)&rect, wxT("wxRect"), false);
611dc22c
RD
290 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OOO)", dcobj, idobj, recobj));
291 Py_DECREF(dcobj);
292 Py_DECREF(idobj);
293 Py_DECREF(recobj);
294 }
da32eb53 295 wxPyEndBlockThreads(blocked);
611dc22c
RD
296 if (! found)
297 wxTreeCompanionWindow::DrawItem(dc, id, rect);
298 }
299
300 PYPRIVATE;
301};
302%}
303
304
ab1f7d2a
RD
305MustHaveApp(wxPyTreeCompanionWindow);
306
1b8c7ba6
RD
307%rename(TreeCompanionWindow) wxPyTreeCompanionWindow;
308class wxPyTreeCompanionWindow: public wxWindow
611dc22c
RD
309{
310public:
2b9048c5
RD
311 %pythonAppend wxPyTreeCompanionWindow "self._setOORInfo(self);self._setCallbackInfo(self, TreeCompanionWindow)"
312 %pythonAppend wxPyTreeCompanionWindow() ""
d14a1e28 313
611dc22c
RD
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);
611dc22c
RD
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
ab1f7d2a
RD
333MustHaveApp(wxThinSplitterWindow);
334
611dc22c
RD
335class wxThinSplitterWindow: public wxSplitterWindow
336{
337public:
2b9048c5
RD
338 %pythonAppend wxThinSplitterWindow "self._setOORInfo(self)"
339 %pythonAppend wxThinSplitterWindow() ""
d14a1e28 340
611dc22c
RD
341 wxThinSplitterWindow(wxWindow* parent, wxWindowID id = -1,
342 const wxPoint& pos = wxDefaultPosition,
343 const wxSize& size = wxDefaultSize,
344 long style = wxSP_3D | wxCLIP_CHILDREN);
611dc22c
RD
345};
346
347
d14a1e28 348
611dc22c
RD
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
ab1f7d2a
RD
358MustHaveApp(wxSplitterScrolledWindow);
359
611dc22c
RD
360class wxSplitterScrolledWindow: public wxScrolledWindow
361{
362public:
2b9048c5
RD
363 %pythonAppend wxSplitterScrolledWindow "self._setOORInfo(self)"
364 %pythonAppend wxSplitterScrolledWindow() ""
d14a1e28 365
611dc22c
RD
366 wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id = -1,
367 const wxPoint& pos = wxDefaultPosition,
368 const wxSize& size = wxDefaultSize,
369 long style = 0);
611dc22c
RD
370};
371
372
d14a1e28
RD
373//---------------------------------------------------------------------------
374//---------------------------------------------------------------------------
950e7faf
RD
375
376
377enum 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
ab1f7d2a
RD
389MustHaveApp(wxLEDNumberCtrl);
390
950e7faf
RD
391class wxLEDNumberCtrl : public wxControl
392{
393public:
2b9048c5
RD
394 %pythonAppend wxLEDNumberCtrl "self._setOORInfo(self)"
395 %pythonAppend wxLEDNumberCtrl() ""
d14a1e28 396
950e7faf
RD
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);
1b8c7ba6 401 %RenameCtor(PreLEDNumberCtrl, wxLEDNumberCtrl());
950e7faf 402
950e7faf
RD
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
d14a1e28
RD
408 wxLEDValueAlign GetAlignment() const;
409 bool GetDrawFaded() const;
410 const wxString &GetValue() const;
950e7faf
RD
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
1fded56b
RD
418
419
420//----------------------------------------------------------------------------
421// wxTreeListCtrl - the multicolumn tree control
422//----------------------------------------------------------------------------
423
424enum wxTreeListColumnAlign {
425 wxTL_ALIGN_LEFT,
426 wxTL_ALIGN_RIGHT,
427 wxTL_ALIGN_CENTER
428};
429
430
431
432enum {
433 wxTREE_HITTEST_ONITEMCOLUMN
434};
435
436
28eab81f
RD
437enum {
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
648d396c
RD
446enum {
447 // extra tree styles
448 wxTR_DONT_ADJUST_MAC
449};
450%pythoncode { wx.TR_DONT_ADJUST_MAC = TR_DONT_ADJUST_MAC }
1fded56b
RD
451
452
453class wxTreeListColumnInfo: public wxObject {
454public:
455 wxTreeListColumnInfo(const wxString& text = wxPyEmptyString,
456 int image = -1,
457 size_t width = 100,
a72f4631 458 bool shown = true,
1fded56b
RD
459 wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT);
460
7f80dd64
RD
461 ~wxTreeListColumnInfo();
462
28eab81f 463 bool GetShown() const;
1fded56b
RD
464 wxTreeListColumnAlign GetAlignment() const;
465 wxString GetText() const;
466 int GetImage() const;
467 int GetSelectedImage() const;
468 size_t GetWidth() const;
469
28eab81f
RD
470 // TODO: These all actually return wxTreeListColumnInfo&, any problem with doing it for Python too?
471 void SetShown(bool shown);
1fded56b
RD
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
483class wxPyTreeListCtrl : public wxTreeListCtrl {
484 DECLARE_ABSTRACT_CLASS(wxPyTreeListCtrl);
485public:
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;
6e6b3557 499 wxPyBlock_t blocked = wxPyBeginBlockThreads();
1fded56b
RD
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 }
da32eb53 507 wxPyEndBlockThreads(blocked);
1fded56b
RD
508 if (! found)
509 rval = wxTreeListCtrl::OnCompareItems(item1, item2);
510 return rval;
511 }
512 PYPRIVATE;
513};
514
515IMPLEMENT_ABSTRACT_CLASS(wxPyTreeListCtrl, wxTreeListCtrl)
516
517%}
518
519
520
521
1fded56b
RD
522
523
ab1f7d2a
RD
524MustHaveApp(wxPyTreeListCtrl);
525
1b8c7ba6
RD
526%rename(TreeListCtrl) wxPyTreeListCtrl;
527class wxPyTreeListCtrl : public wxControl
1fded56b
RD
528{
529public:
2b9048c5
RD
530 %pythonAppend wxPyTreeListCtrl "self._setOORInfo(self);self._setCallbackInfo(self, TreeListCtrl)"
531 %pythonAppend wxPyTreeListCtrl() ""
d14a1e28 532
1fded56b
RD
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 );
1b8c7ba6 539 %RenameCtor(PreTreeListCtrl, wxPyTreeListCtrl());
1fded56b
RD
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);
1fded56b 549
28eab81f 550
1fded56b
RD
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
1fded56b
RD
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);
15d9a04c 583
214c4fbe 584 %disownarg( wxImageList *imageList );
1fded56b
RD
585 void AssignImageList(wxImageList *imageList);
586 void AssignStateImageList(wxImageList *imageList);
587 void AssignButtonsImageList(wxImageList *imageList);
214c4fbe 588 %cleardisown( wxImageList *imageList );
1fded56b
RD
589
590
591 // adds a column
592 void AddColumn(const wxString& text);
28eab81f
RD
593// void AddColumn(const wxString& text,
594// size_t width,
595// wxTreeListColumnAlign alignment = wxTL_ALIGN_LEFT);
1b8c7ba6 596 %Rename(AddColumnInfo, void, AddColumn(const wxTreeListColumnInfo& col));
1fded56b
RD
597
598 // inserts a column before the given one
599 void InsertColumn(size_t before, const wxString& text);
1b8c7ba6 600 %Rename(InsertColumnInfo, void, InsertColumn(size_t before, const wxTreeListColumnInfo& col));
1fded56b
RD
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
28eab81f
RD
629 void ShowColumn(size_t column, bool shown);
630 bool IsColumnShown(size_t column) const;
1fded56b 631
d14a1e28 632 %extend {
1fded56b
RD
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
7f80dd64 673 %disownarg( wxPyTreeItemData* data );
1fded56b
RD
674 void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
675 data->SetId(item); // set the id
676 self->SetItemData(item, data);
677 }
7f80dd64 678 %cleardisown(wxPyTreeItemData* data );
1fded56b 679
d14a1e28 680 // [Get|Set]ItemPyData are short-cuts. Also made somewhat crash-proof by
1fded56b 681 // automatically creating data classes.
d14a1e28 682 PyObject* GetItemPyData(const wxTreeItemId& item) {
1fded56b
RD
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
d14a1e28 692 void SetItemPyData(const wxTreeItemId& item, PyObject* obj) {
1fded56b
RD
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 }
4e0b6696
RD
702 %pythoncode { GetPyData = GetItemPyData }
703 %pythoncode { SetPyData = SetItemPyData }
1fded56b
RD
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.
a72f4631 710 void SetItemHasChildren(const wxTreeItemId& item, bool has = true);
1fded56b
RD
711
712 // the item will be shown in bold
a72f4631 713 void SetItemBold(const wxTreeItemId& item, bool bold = true);
1fded56b
RD
714
715 // set the item's text colour
28eab81f 716 void SetItemTextColour(const wxTreeItemId& item, const wxColour& colour);
1fded56b
RD
717
718 // set the item's background colour
719 void SetItemBackgroundColour(const wxTreeItemId& item,
28eab81f 720 const wxColour& colour);
1fded56b
RD
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
dd9f7fea 746 // if 'recursively' is False, only immediate children count, otherwise
1fded56b 747 // the returned number is the number of all items in this branch
a72f4631 748 size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = true);
1fded56b
RD
749
750
dd9f7fea 751 // wxTreeItemId.IsOk() will return False if there is no such item
1fded56b
RD
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;
d14a1e28 761 %extend {
1fded56b 762 PyObject* GetSelections() {
6e6b3557 763 wxPyBlock_t blocked = wxPyBeginBlockThreads();
1fded56b
RD
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));
a72f4631 770 PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), true);
1fded56b 771 PyList_Append(rval, item);
faca2e45 772 Py_DECREF(item);
1fded56b 773 }
da32eb53 774 wxPyEndBlockThreads(blocked);
1fded56b
RD
775 return rval;
776 }
777 }
778
779
780 // get the parent of this item (may return NULL if root)
28eab81f 781 wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
1fded56b
RD
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
1fded56b 790
28eab81f
RD
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!)
d14a1e28
RD
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) {
28eab81f 798 void* cookie = 0;
61136550 799 wxTreeItemId* ritem = new wxTreeItemId(self->GetFirstChild(item, cookie));
6e6b3557 800 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28 801 PyObject* tup = PyTuple_New(2);
a72f4631 802 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true));
28eab81f 803 PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void")));
da32eb53 804 wxPyEndBlockThreads(blocked);
d14a1e28
RD
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.
28eab81f 813 PyObject* GetNextChild(const wxTreeItemId& item, void* cookie) {
61136550 814 wxTreeItemId* ritem = new wxTreeItemId(self->GetNextChild(item, cookie));
6e6b3557 815 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28 816 PyObject* tup = PyTuple_New(2);
a72f4631 817 PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(ritem, wxT("wxTreeItemId"), true));
28eab81f 818 PyTuple_SET_ITEM(tup, 1, wxPyMakeSwigPtr(cookie, wxT("void")));
da32eb53 819 wxPyEndBlockThreads(blocked);
d14a1e28 820 return tup;
28eab81f
RD
821 }
822
823
824 // TODO: GetPrevChild
825
d14a1e28 826 }
1fded56b
RD
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
7f80dd64
RD
851 %disownarg( wxPyTreeItemData* data );
852
1fded56b
RD
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
1b8c7ba6
RD
872 %Rename(InsertItemBefore,
873 wxTreeItemId, InsertItem(const wxTreeItemId& parent,
1fded56b
RD
874 size_t index,
875 const wxString& text,
876 int image = -1, int selectedImage = -1,
1b8c7ba6 877 wxPyTreeItemData *data = NULL));
1fded56b
RD
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
7f80dd64
RD
885 %cleardisown(wxPyTreeItemData* data );
886
1fded56b
RD
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
a72f4631
RD
918 void SelectItem(const wxTreeItemId& item, bool unselect_others=true,
919 bool extended_select=false);
1fded56b 920
a72f4631 921 void SelectAll(bool extended_select=false);
28eab81f 922
1fded56b
RD
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
d14a1e28 933 %extend {
1fded56b 934 // get the bounding rectangle of the item (or of its label only)
a72f4631 935 PyObject* GetBoundingRect(const wxTreeItemId& item, bool textOnly = false) {
1fded56b
RD
936 wxRect rect;
937 if (self->GetBoundingRect(item, rect, textOnly)) {
6e6b3557 938 wxPyBlock_t blocked = wxPyBeginBlockThreads();
1fded56b
RD
939 wxRect* r = new wxRect(rect);
940 PyObject* val = wxPyConstructObject((void*)r, wxT("wxRect"), 1);
da32eb53 941 wxPyEndBlockThreads(blocked);
1fded56b
RD
942 return val;
943 }
944 else {
d14a1e28 945 RETURN_NONE();
1fded56b
RD
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
28eab81f
RD
960 // searching
961 wxTreeItemId FindItem (const wxTreeItemId& item, const wxString& str, int flags = 0);
1fded56b
RD
962
963 wxWindow* GetHeaderWindow() const;
6d450e1a 964 wxScrolledWindow* GetMainWindow() const;
1fded56b 965
1fded56b
RD
966};
967
7e4b7f9a
RD
968//----------------------------------------------------------------------
969
970enum
971{
972 wxSCALE_HORIZONTAL,
973 wxSCALE_VERTICAL,
974 wxSCALE_UNIFORM,
975 wxSCALE_CUSTOM
976};
977
978MustHaveApp(wxStaticPicture);
979
980class wxStaticPicture : public wxControl
981{
982public:
983 %pythonAppend wxStaticPicture "self._setOORInfo(self)"
984 %pythonAppend wxStaticPicture() ""
985
d3397f6a
RD
986 wxStaticPicture( wxWindow* parent, wxWindowID id=-1,
987 const wxBitmap& label=wxNullBitmap,
7e4b7f9a
RD
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
d3397f6a
RD
995 bool Create( wxWindow* parent, wxWindowID id=-1,
996 const wxBitmap& label=wxNullBitmap,
7e4b7f9a
RD
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;
1fded56b 1006
7e4b7f9a
RD
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};
1fded56b
RD
1017
1018
950e7faf 1019//----------------------------------------------------------------------
ebf4302c
RD
1020//----------------------------------------------------------------------
1021
1022%init %{
1023
611dc22c 1024 wxPyPtrTypeMap_Add("wxTreeCompanionWindow", "wxPyTreeCompanionWindow");
1fded56b 1025 wxPyPtrTypeMap_Add("wxTreeListCtrl", "wxPyTreeListCtrl");
ebf4302c
RD
1026%}
1027
1028
ebf4302c
RD
1029%pragma(python) include="_gizmoextras.py";
1030
1031//----------------------------------------------------------------------
1032//----------------------------------------------------------------------
1033