]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_vscroll.i
Added some aliases
[wxWidgets.git] / wxPython / src / _vscroll.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _vscroll.i
3 // Purpose: SWIG interface defs for wxVScrolledWindow, wxVListBox, and
4 // wxHtmlListBox
5 //
6 // Author: Robin Dunn
7 //
8 // Created: 14-Aug-2003
9 // RCS-ID: $Id$
10 // Copyright: (c) 2003 by Total Control Software
11 // Licence: wxWindows license
12 /////////////////////////////////////////////////////////////////////////////
13
14 // Not a %module
15
16
17 //---------------------------------------------------------------------------
18
19 %{
20 #include <wx/tipwin.h>
21 %}
22
23 //---------------------------------------------------------------------------
24 %newgroup;
25
26
27 // wxVScrolledWindow
28
29 %{
30 #include <wx/vscroll.h>
31 %}
32
33
34 // First, the C++ version
35 %{
36 class wxPyVScrolledWindow : public wxVScrolledWindow
37 {
38 DECLARE_ABSTRACT_CLASS(wxPyVScrolledWindow);
39 public:
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
90 size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = False)
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
102 IMPLEMENT_ABSTRACT_CLASS(wxPyVScrolledWindow, wxVScrolledWindow);
103
104 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLineHeight);
105 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLinesHint);
106 IMP_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
128 %name(VScrolledWindow) class wxPyVScrolledWindow : public wxPanel
129 {
130 public:
131 %addtofunc wxPyVScrolledWindow "self._setOORInfo(self); self._setCallbackInfo(self, VScrolledWindow)"
132 %addtofunc wxPyVScrolledWindow() ""
133
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
142 %name(PreVScrolledWindow)wxPyVScrolledWindow();
143
144 void _setCallbackInfo(PyObject* self, PyObject* _class);
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 //
162 // return True if we scrolled the window, False if nothing was done
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>
204 DECLARE_DEF_STRING(VListBoxNameStr);
205 %}
206
207
208 // First, the C++ version
209 %{
210 class wxPyVListBox : public wxVListBox
211 {
212 DECLARE_ABSTRACT_CLASS(wxPyVListBox);
213 public:
214 wxPyVListBox() : wxVListBox() {}
215
216 wxPyVListBox(wxWindow *parent,
217 wxWindowID id = wxID_ANY,
218 const wxPoint& pos = wxDefaultPosition,
219 const wxSize& size = wxDefaultSize,
220 long style = 0,
221 const wxString& name = wxPyVListBoxNameStr)
222 : wxVListBox(parent, id, pos, size, style, name)
223 {}
224
225 // Overridable virtuals
226
227 // the derived class must implement this function to actually draw the item
228 // with the given index on the provided DC
229 // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
230 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem);
231
232
233 // the derived class must implement this method to return the height of the
234 // specified item
235 // virtual wxCoord OnMeasureItem(size_t n) const = 0;
236 DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem);
237
238
239 // this method may be used to draw separators between the lines; note that
240 // the rectangle may be modified, typically to deflate it a bit before
241 // passing to OnDrawItem()
242 //
243 // the base class version doesn't do anything
244 // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
245 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawSeparator);
246
247
248 // this method is used to draw the items background and, maybe, a border
249 // around it
250 //
251 // the base class version implements a reasonable default behaviour which
252 // consists in drawing the selected item with the standard background
253 // colour and drawing a border around the item if it is either selected or
254 // current
255 // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
256 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
257
258
259 PYPRIVATE;
260 };
261
262 IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox);
263
264 IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem);
265 IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem);
266 IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawSeparator);
267 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground);
268
269 %}
270
271
272
273 // Now define this class for SWIG
274
275 /*
276 This class has two main differences from a regular listbox: it can have an
277 arbitrarily huge number of items because it doesn't store them itself but
278 uses OnDrawItem() callback to draw them and its items can have variable
279 height as determined by OnMeasureItem().
280
281 It emits the same events as wxListBox and the same event macros may be used
282 with it.
283 */
284 %name(VListBox) class wxPyVListBox : public wxPyVScrolledWindow
285 {
286 public:
287 %addtofunc wxPyVListBox "self._setOORInfo(self);self._setCallbackInfo(self, VListBox)"
288 %addtofunc wxPyVListBox() ""
289
290
291 wxPyVListBox(wxWindow *parent,
292 wxWindowID id = wxID_ANY,
293 const wxPoint& pos = wxDefaultPosition,
294 const wxSize& size = wxDefaultSize,
295 long style = 0,
296 const wxString& name = wxPyVListBoxNameStr);
297
298 %name(PreVListBox) wxPyVListBox();
299
300 void _setCallbackInfo(PyObject* self, PyObject* _class);
301
302 bool Create(wxWindow *parent,
303 wxWindowID id = wxID_ANY,
304 const wxPoint& pos = wxDefaultPosition,
305 const wxSize& size = wxDefaultSize,
306 long style = 0,
307 const wxString& name = wxPyVListBoxNameStr);
308
309 // get the number of items in the control
310 size_t GetItemCount() const;
311
312 // does this control use multiple selection?
313 bool HasMultipleSelection() const;
314
315 // get the currently selected item or wxNOT_FOUND if there is no selection
316 //
317 // this method is only valid for the single selection listboxes
318 int GetSelection() const;
319
320 // is this item the current one?
321 bool IsCurrent(size_t item) const;
322
323 // is this item selected?
324 bool IsSelected(size_t item) const;
325
326 // get the number of the selected items (maybe 0)
327 //
328 // this method is valid for both single and multi selection listboxes
329 size_t GetSelectedCount() const;
330
331 // get the first selected item, returns wxNOT_FOUND if none
332 //
333 // cookie is an opaque parameter which should be passed to
334 // GetNextSelected() later
335 //
336 // this method is only valid for the multi selection listboxes
337 int GetFirstSelected(unsigned long& cookie) const;
338
339 // get next selection item, return wxNOT_FOUND if no more
340 //
341 // cookie must be the same parameter that was passed to GetFirstSelected()
342 // before
343 //
344 // this method is only valid for the multi selection listboxes
345 int GetNextSelected(unsigned long& cookie) const;
346
347 // get the margins around each item
348 wxPoint GetMargins() const;
349
350 // get the background colour of selected cells
351 const wxColour& GetSelectionBackground() const;
352
353
354 // set the number of items to be shown in the control
355 //
356 // this is just a synonym for wxVScrolledWindow::SetLineCount()
357 void SetItemCount(size_t count);
358
359 // delete all items from the control
360 void Clear();
361
362 // set the selection to the specified item, if it is wxNOT_FOUND the
363 // selection is unset
364 //
365 // this function is only valid for the single selection listboxes
366 void SetSelection(int selection);
367
368 // selects or deselects the specified item which must be valid (i.e. not
369 // equal to wxNOT_FOUND)
370 //
371 // return True if the items selection status has changed or False
372 // otherwise
373 //
374 // this function is only valid for the multiple selection listboxes
375 bool Select(size_t item, bool select = True);
376
377 // selects the items in the specified range whose end points may be given
378 // in any order
379 //
380 // return True if any items selection status has changed, False otherwise
381 //
382 // this function is only valid for the single selection listboxes
383 bool SelectRange(size_t from, size_t to);
384
385 // toggle the selection of the specified item (must be valid)
386 //
387 // this function is only valid for the multiple selection listboxes
388 void Toggle(size_t item);
389
390 // select all items in the listbox
391 //
392 // the return code indicates if any items were affected by this operation
393 // (True) or if nothing has changed (False)
394 bool SelectAll();
395
396 // unselect all items in the listbox
397 //
398 // the return code has the same meaning as for SelectAll()
399 bool DeselectAll();
400
401 // set the margins: horizontal margin is the distance between the window
402 // border and the item contents while vertical margin is half of the
403 // distance between items
404 //
405 // by default both margins are 0
406 void SetMargins(const wxPoint& pt);
407 %name(SetMarginsXY) void SetMargins(wxCoord x, wxCoord y);
408
409 // change the background colour of the selected cells
410 void SetSelectionBackground(const wxColour& col);
411
412 };
413
414
415 //---------------------------------------------------------------------------
416 // wxHtmlListBox
417
418 %{
419 #include <wx/htmllbox.h>
420 %}
421
422 // First, the C++ version
423 %{
424 class wxPyHtmlListBox : public wxHtmlListBox
425 {
426 DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox);
427 public:
428 wxPyHtmlListBox() : wxHtmlListBox() {}
429
430 wxPyHtmlListBox(wxWindow *parent,
431 wxWindowID id = wxID_ANY,
432 const wxPoint& pos = wxDefaultPosition,
433 const wxSize& size = wxDefaultSize,
434 long style = 0,
435 const wxString& name = wxPyVListBoxNameStr)
436 : wxHtmlListBox(parent, id, pos, size, style, name)
437 {}
438
439 // Overridable virtuals
440
441 // this method must be implemented in the derived class and should return
442 // the body (i.e. without <html>) of the HTML for the given item
443 DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem);
444
445 // this function may be overridden to decorate HTML returned by OnGetItem()
446 DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup);
447
448 // TODO:
449 // // this method allows to customize the selection appearance: it may be used
450 // // to specify the colour of the text which normally has the given colour
451 // // colFg when it is inside the selection
452 // //
453 // // by default, the original colour is not used at all and all text has the
454 // // same (default for this system) colour inside selection
455 // virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
456
457 // // this is the same as GetSelectedTextColour() but allows to customize the
458 // // background colour -- this is even more rarely used as you can change it
459 // // globally using SetSelectionBackground()
460 // virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
461
462
463 PYPRIVATE;
464 };
465
466
467 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox)
468
469 IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem);
470 IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup);
471
472 %}
473
474
475
476 // Now define this class for SWIG
477
478
479 // wxHtmlListBox is a listbox whose items are wxHtmlCells
480 %name(HtmlListBox) class wxPyHtmlListBox : public wxPyVListBox
481 {
482 public:
483 %addtofunc wxPyHtmlListBox "self._setOORInfo(self);self._setCallbackInfo(self, HtmlListBox)"
484 %addtofunc wxPyHtmlListBox() ""
485
486
487 // normal constructor which calls Create() internally
488 wxPyHtmlListBox(wxWindow *parent,
489 wxWindowID id = wxID_ANY,
490 const wxPoint& pos = wxDefaultPosition,
491 const wxSize& size = wxDefaultSize,
492 long style = 0,
493 const wxString& name = wxPyVListBoxNameStr);
494
495 %name(PreHtmlListBox) wxPyHtmlListBox();
496
497 void _setCallbackInfo(PyObject* self, PyObject* _class);
498
499 bool Create(wxWindow *parent,
500 wxWindowID id = wxID_ANY,
501 const wxPoint& pos = wxDefaultPosition,
502 const wxSize& size = wxDefaultSize,
503 long style = 0,
504 const wxString& name = wxPyVListBoxNameStr);
505
506
507 void RefreshAll();
508 void SetItemCount(size_t count);
509
510 };
511
512
513
514 //---------------------------------------------------------------------------
515
516 %init %{
517 // Map renamed classes back to their common name for OOR
518 wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox");
519 wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox");
520 wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow");
521 %}
522
523 //---------------------------------------------------------------------------