]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_vscroll.i
PS can output to ta stream (but still need to make output streams more
[wxWidgets.git] / wxPython / src / _vscroll.i
CommitLineData
08127323 1/////////////////////////////////////////////////////////////////////////////
d14a1e28
RD
2// Name: _vscroll.i
3// Purpose: SWIG interface defs for wxVScrolledWindow, wxVListBox, and
4// wxHtmlListBox
08127323
RD
5//
6// Author: Robin Dunn
7//
d14a1e28 8// Created: 14-Aug-2003
08127323 9// RCS-ID: $Id$
d14a1e28 10// Copyright: (c) 2003 by Total Control Software
08127323
RD
11// Licence: wxWindows license
12/////////////////////////////////////////////////////////////////////////////
13
d14a1e28 14// Not a %module
08127323
RD
15
16
17//---------------------------------------------------------------------------
0122b7e3
RD
18
19%{
d14a1e28 20#include <wx/tipwin.h>
0122b7e3
RD
21%}
22
1fded56b 23//---------------------------------------------------------------------------
d14a1e28 24%newgroup;
1fded56b 25
4416b508 26
3628e088
RD
27// wxVScrolledWindow
28
29%{
30#include <wx/vscroll.h>
3628e088
RD
31%}
32
33
34// First, the C++ version
35%{
36class wxPyVScrolledWindow : public wxVScrolledWindow
37{
38 DECLARE_ABSTRACT_CLASS(wxPyVScrolledWindow);
39public:
40 wxPyVScrolledWindow() : wxVScrolledWindow() {}
41
42 wxPyVScrolledWindow(wxWindow *parent,
43 wxWindowID id = wxID_ANY,
44 const wxPoint& pos = wxDefaultPosition,
45 const wxSize& size = wxDefaultSize,
46 long style = 0,
47 const wxString& name = wxPyPanelNameStr)
48 : wxVScrolledWindow(parent, id, pos, size, style, name)
49 {}
50
51 // Overridable virtuals
52
53 // this function must be overridden in the derived class and it should
54 // return the height of the given line in pixels
55 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetLineHeight);
56
57
58 // this function doesn't have to be overridden but it may be useful to do
59 // it if calculating the lines heights is a relatively expensive operation
60 // as it gives the user code a possibility to calculate several of them at
61 // once
62 //
63 // OnGetLinesHint() is normally called just before OnGetLineHeight() but you
64 // shouldn't rely on the latter being called for all lines in the interval
65 // specified here. It is also possible that OnGetLineHeight() will be
66 // called for the lines outside of this interval, so this is really just a
67 // hint, not a promise.
68 //
69 // finally note that lineMin is inclusive, while lineMax is exclusive, as
70 // usual
71 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetLinesHint);
72
73
74 // when the number of lines changes, we try to estimate the total height
75 // of all lines which is a rather expensive operation in terms of lines
76 // access, so if the user code may estimate the average height
77 // better/faster than we do, it should override this function to implement
78 // its own logic
79 //
80 // this function should return the best guess for the total height it may
81 // make
82 DEC_PYCALLBACK_COORD_const(EstimateTotalHeight);
83
84
85 // Also expose some other interesting protected methods
86
87
88 // find the index of the line we need to show at the top of the window such
89 // that the last (fully or partially) visible line is the given one
dd9f7fea 90 size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = False)
3628e088
RD
91 { return wxVScrolledWindow::FindFirstFromBottom(lineLast, fullyVisible); }
92
93 // get the total height of the lines between lineMin (inclusive) and
94 // lineMax (exclusive)
95 wxCoord GetLinesHeight(size_t lineMin, size_t lineMax) const
96 { return wxVScrolledWindow::GetLinesHeight(lineMin, lineMax); }
97
98
99 PYPRIVATE;
100};
101
102IMPLEMENT_ABSTRACT_CLASS(wxPyVScrolledWindow, wxVScrolledWindow);
103
104IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLineHeight);
105IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLinesHint);
106IMP_PYCALLBACK_COORD_const (wxPyVScrolledWindow, wxVScrolledWindow, EstimateTotalHeight);
107%}
108
109
110
111// Now define this class for SWIG
112
113/*
114 In the name of this class, "V" may stand for "variable" because it can be
115 used for scrolling lines of variable heights; "virtual" because it is not
116 necessary to know the heights of all lines in advance -- only those which
117 are shown on the screen need to be measured; or, even, "vertical" because
118 this class only supports scrolling in one direction currently (this could
119 and probably will change in the future however).
120
121 In any case, this is a generalization of the wxScrolledWindow class which
122 can be only used when all lines have the same height. It lacks some other
123 wxScrolledWindow features however, notably it currently lacks support for
124 horizontal scrolling; it can't scroll another window nor only a rectangle
125 of the window and not its entire client area.
126 */
127
d14a1e28 128%name(VScrolledWindow) class wxPyVScrolledWindow : public wxPanel
3628e088
RD
129{
130public:
2b9048c5
RD
131 %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self); self._setCallbackInfo(self, VScrolledWindow)"
132 %pythonAppend wxPyVScrolledWindow() ""
d14a1e28 133
3628e088
RD
134
135 wxPyVScrolledWindow(wxWindow *parent,
136 wxWindowID id = wxID_ANY,
137 const wxPoint& pos = wxDefaultPosition,
138 const wxSize& size = wxDefaultSize,
139 long style = 0,
140 const wxString& name = wxPyPanelNameStr);
141
d14a1e28 142 %name(PreVScrolledWindow)wxPyVScrolledWindow();
3628e088
RD
143
144 void _setCallbackInfo(PyObject* self, PyObject* _class);
3628e088
RD
145
146 bool Create(wxWindow *parent,
147 wxWindowID id = wxID_ANY,
148 const wxPoint& pos = wxDefaultPosition,
149 const wxSize& size = wxDefaultSize,
150 long style = 0,
151 const wxString& name = wxPyPanelNameStr);
152
153
154 // set the number of lines the window contains: the derived class must
155 // provide the heights for all lines with indices up to the one given here
156 // in its OnGetLineHeight()
157 void SetLineCount(size_t count);
158
159 // scroll to the specified line: it will become the first visible line in
160 // the window
161 //
dd9f7fea 162 // return True if we scrolled the window, False if nothing was done
3628e088
RD
163 bool ScrollToLine(size_t line);
164
165 // scroll by the specified number of lines/pages
166 virtual bool ScrollLines(int lines);
167 virtual bool ScrollPages(int pages);
168
169 // redraw the specified line
170 void RefreshLine(size_t line);
171
172 // redraw all lines in the specified range (inclusive)
173 void RefreshLines(size_t from, size_t to);
174
175 // return the item at the specified (in physical coordinates) position or
176 // wxNOT_FOUND if none, i.e. if it is below the last item
177 %name(HitTestXT) int HitTest(wxCoord x, wxCoord y) const;
178 int HitTest(const wxPoint& pt) const;
179
180 // recalculate all our parameters and redisplay all lines
181 virtual void RefreshAll();
182
183
184 // get the number of lines this window contains (previously set by
185 // SetLineCount())
186 size_t GetLineCount() const;
187
188 // get the first currently visible line
189 size_t GetFirstVisibleLine() const;
190
191 // get the last currently visible line
192 size_t GetLastVisibleLine() const;
193
194 // is this line currently visible?
195 bool IsVisible(size_t line) const;
196
197};
198
199//---------------------------------------------------------------------------
200// wxVListBox
201
202%{
203#include <wx/vlbox.h>
3628e088
RD
204%}
205
b2dc1044
RD
206MAKE_CONST_WXSTRING(VListBoxNameStr);
207
3628e088
RD
208
209// First, the C++ version
210%{
211class wxPyVListBox : public wxVListBox
212{
213 DECLARE_ABSTRACT_CLASS(wxPyVListBox);
214public:
215 wxPyVListBox() : wxVListBox() {}
216
217 wxPyVListBox(wxWindow *parent,
218 wxWindowID id = wxID_ANY,
219 const wxPoint& pos = wxDefaultPosition,
220 const wxSize& size = wxDefaultSize,
221 long style = 0,
222 const wxString& name = wxPyVListBoxNameStr)
223 : wxVListBox(parent, id, pos, size, style, name)
224 {}
225
226 // Overridable virtuals
227
228 // the derived class must implement this function to actually draw the item
229 // with the given index on the provided DC
230 // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
231 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem);
232
233
234 // the derived class must implement this method to return the height of the
235 // specified item
236 // virtual wxCoord OnMeasureItem(size_t n) const = 0;
237 DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem);
238
239
240 // this method may be used to draw separators between the lines; note that
241 // the rectangle may be modified, typically to deflate it a bit before
242 // passing to OnDrawItem()
243 //
244 // the base class version doesn't do anything
245 // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
246 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawSeparator);
247
248
249 // this method is used to draw the items background and, maybe, a border
250 // around it
251 //
252 // the base class version implements a reasonable default behaviour which
253 // consists in drawing the selected item with the standard background
254 // colour and drawing a border around the item if it is either selected or
255 // current
256 // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
257 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
258
259
260 PYPRIVATE;
261};
262
263IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox);
264
265IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem);
266IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem);
267IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawSeparator);
268IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground);
269
270%}
271
272
273
274// Now define this class for SWIG
275
276/*
277 This class has two main differences from a regular listbox: it can have an
278 arbitrarily huge number of items because it doesn't store them itself but
279 uses OnDrawItem() callback to draw them and its items can have variable
280 height as determined by OnMeasureItem().
281
282 It emits the same events as wxListBox and the same event macros may be used
283 with it.
284 */
d14a1e28 285%name(VListBox) class wxPyVListBox : public wxPyVScrolledWindow
3628e088
RD
286{
287public:
2b9048c5
RD
288 %pythonAppend wxPyVListBox "self._setOORInfo(self);self._setCallbackInfo(self, VListBox)"
289 %pythonAppend wxPyVListBox() ""
d14a1e28 290
3628e088
RD
291
292 wxPyVListBox(wxWindow *parent,
293 wxWindowID id = wxID_ANY,
294 const wxPoint& pos = wxDefaultPosition,
295 const wxSize& size = wxDefaultSize,
296 long style = 0,
297 const wxString& name = wxPyVListBoxNameStr);
298
d14a1e28 299 %name(PreVListBox) wxPyVListBox();
3628e088
RD
300
301 void _setCallbackInfo(PyObject* self, PyObject* _class);
3628e088
RD
302
303 bool Create(wxWindow *parent,
304 wxWindowID id = wxID_ANY,
305 const wxPoint& pos = wxDefaultPosition,
306 const wxSize& size = wxDefaultSize,
307 long style = 0,
308 const wxString& name = wxPyVListBoxNameStr);
309
310 // get the number of items in the control
311 size_t GetItemCount() const;
312
313 // does this control use multiple selection?
314 bool HasMultipleSelection() const;
315
316 // get the currently selected item or wxNOT_FOUND if there is no selection
317 //
318 // this method is only valid for the single selection listboxes
319 int GetSelection() const;
320
321 // is this item the current one?
322 bool IsCurrent(size_t item) const;
323
324 // is this item selected?
325 bool IsSelected(size_t item) const;
326
327 // get the number of the selected items (maybe 0)
328 //
329 // this method is valid for both single and multi selection listboxes
330 size_t GetSelectedCount() const;
331
332 // get the first selected item, returns wxNOT_FOUND if none
333 //
334 // cookie is an opaque parameter which should be passed to
335 // GetNextSelected() later
336 //
337 // this method is only valid for the multi selection listboxes
338 int GetFirstSelected(unsigned long& cookie) const;
339
340 // get next selection item, return wxNOT_FOUND if no more
341 //
342 // cookie must be the same parameter that was passed to GetFirstSelected()
343 // before
344 //
345 // this method is only valid for the multi selection listboxes
346 int GetNextSelected(unsigned long& cookie) const;
347
348 // get the margins around each item
349 wxPoint GetMargins() const;
350
351 // get the background colour of selected cells
352 const wxColour& GetSelectionBackground() const;
353
354
355 // set the number of items to be shown in the control
356 //
357 // this is just a synonym for wxVScrolledWindow::SetLineCount()
358 void SetItemCount(size_t count);
359
360 // delete all items from the control
361 void Clear();
362
363 // set the selection to the specified item, if it is wxNOT_FOUND the
364 // selection is unset
365 //
366 // this function is only valid for the single selection listboxes
367 void SetSelection(int selection);
368
369 // selects or deselects the specified item which must be valid (i.e. not
370 // equal to wxNOT_FOUND)
371 //
dd9f7fea 372 // return True if the items selection status has changed or False
3628e088
RD
373 // otherwise
374 //
375 // this function is only valid for the multiple selection listboxes
dd9f7fea 376 bool Select(size_t item, bool select = True);
3628e088
RD
377
378 // selects the items in the specified range whose end points may be given
379 // in any order
380 //
dd9f7fea 381 // return True if any items selection status has changed, False otherwise
3628e088
RD
382 //
383 // this function is only valid for the single selection listboxes
384 bool SelectRange(size_t from, size_t to);
385
386 // toggle the selection of the specified item (must be valid)
387 //
388 // this function is only valid for the multiple selection listboxes
389 void Toggle(size_t item);
390
391 // select all items in the listbox
392 //
393 // the return code indicates if any items were affected by this operation
dd9f7fea 394 // (True) or if nothing has changed (False)
3628e088
RD
395 bool SelectAll();
396
397 // unselect all items in the listbox
398 //
399 // the return code has the same meaning as for SelectAll()
400 bool DeselectAll();
401
402 // set the margins: horizontal margin is the distance between the window
403 // border and the item contents while vertical margin is half of the
404 // distance between items
405 //
406 // by default both margins are 0
407 void SetMargins(const wxPoint& pt);
408 %name(SetMarginsXY) void SetMargins(wxCoord x, wxCoord y);
409
410 // change the background colour of the selected cells
411 void SetSelectionBackground(const wxColour& col);
412
413};
414
415
416//---------------------------------------------------------------------------
417// wxHtmlListBox
418
419%{
420#include <wx/htmllbox.h>
421%}
422
423// First, the C++ version
424%{
425class wxPyHtmlListBox : public wxHtmlListBox
426{
427 DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox);
428public:
429 wxPyHtmlListBox() : wxHtmlListBox() {}
430
431 wxPyHtmlListBox(wxWindow *parent,
432 wxWindowID id = wxID_ANY,
433 const wxPoint& pos = wxDefaultPosition,
434 const wxSize& size = wxDefaultSize,
435 long style = 0,
436 const wxString& name = wxPyVListBoxNameStr)
437 : wxHtmlListBox(parent, id, pos, size, style, name)
438 {}
439
440 // Overridable virtuals
441
442 // this method must be implemented in the derived class and should return
443 // the body (i.e. without <html>) of the HTML for the given item
444 DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem);
445
446 // this function may be overridden to decorate HTML returned by OnGetItem()
447 DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup);
448
449// TODO:
450// // this method allows to customize the selection appearance: it may be used
451// // to specify the colour of the text which normally has the given colour
452// // colFg when it is inside the selection
453// //
454// // by default, the original colour is not used at all and all text has the
455// // same (default for this system) colour inside selection
456// virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
457
458// // this is the same as GetSelectedTextColour() but allows to customize the
459// // background colour -- this is even more rarely used as you can change it
460// // globally using SetSelectionBackground()
461// virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
462
463
464 PYPRIVATE;
465};
466
467
468IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox)
469
470IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem);
471IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup);
472
473%}
474
475
476
477// Now define this class for SWIG
478
479
480// wxHtmlListBox is a listbox whose items are wxHtmlCells
d14a1e28 481%name(HtmlListBox) class wxPyHtmlListBox : public wxPyVListBox
3628e088
RD
482{
483public:
2b9048c5
RD
484 %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);self._setCallbackInfo(self, HtmlListBox)"
485 %pythonAppend wxPyHtmlListBox() ""
d14a1e28 486
3628e088
RD
487
488 // normal constructor which calls Create() internally
489 wxPyHtmlListBox(wxWindow *parent,
490 wxWindowID id = wxID_ANY,
491 const wxPoint& pos = wxDefaultPosition,
492 const wxSize& size = wxDefaultSize,
493 long style = 0,
494 const wxString& name = wxPyVListBoxNameStr);
495
d14a1e28 496 %name(PreHtmlListBox) wxPyHtmlListBox();
3628e088
RD
497
498 void _setCallbackInfo(PyObject* self, PyObject* _class);
3628e088
RD
499
500 bool Create(wxWindow *parent,
501 wxWindowID id = wxID_ANY,
502 const wxPoint& pos = wxDefaultPosition,
503 const wxSize& size = wxDefaultSize,
504 long style = 0,
505 const wxString& name = wxPyVListBoxNameStr);
506
507
508 void RefreshAll();
509 void SetItemCount(size_t count);
510
511};
512
513
d14a1e28 514
3628e088 515//---------------------------------------------------------------------------
4416b508 516
771eb7a2
RD
517%init %{
518 // Map renamed classes back to their common name for OOR
d14a1e28
RD
519 wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox");
520 wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox");
771eb7a2
RD
521 wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow");
522%}
523
d14a1e28 524//---------------------------------------------------------------------------