]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_vscroll.i
Give wxEVT_WEBKIT_STATE_CHANGED a dummy value too.
[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 MustHaveApp(wxPyVScrolledWindow);
129
130 %name(VScrolledWindow) class wxPyVScrolledWindow : public wxPanel
131 {
132 public:
133 %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self); self._setCallbackInfo(self, VScrolledWindow)"
134 %pythonAppend wxPyVScrolledWindow() ""
135
136
137 wxPyVScrolledWindow(wxWindow *parent,
138 wxWindowID id = wxID_ANY,
139 const wxPoint& pos = wxDefaultPosition,
140 const wxSize& size = wxDefaultSize,
141 long style = 0,
142 const wxString& name = wxPyPanelNameStr);
143
144 %name(PreVScrolledWindow)wxPyVScrolledWindow();
145
146 void _setCallbackInfo(PyObject* self, PyObject* _class);
147
148 bool Create(wxWindow *parent,
149 wxWindowID id = wxID_ANY,
150 const wxPoint& pos = wxDefaultPosition,
151 const wxSize& size = wxDefaultSize,
152 long style = 0,
153 const wxString& name = wxPyPanelNameStr);
154
155
156 // set the number of lines the window contains: the derived class must
157 // provide the heights for all lines with indices up to the one given here
158 // in its OnGetLineHeight()
159 void SetLineCount(size_t count);
160
161 // scroll to the specified line: it will become the first visible line in
162 // the window
163 //
164 // return True if we scrolled the window, False if nothing was done
165 bool ScrollToLine(size_t line);
166
167 // scroll by the specified number of lines/pages
168 virtual bool ScrollLines(int lines);
169 virtual bool ScrollPages(int pages);
170
171 // redraw the specified line
172 void RefreshLine(size_t line);
173
174 // redraw all lines in the specified range (inclusive)
175 void RefreshLines(size_t from, size_t to);
176
177 // return the item at the specified (in physical coordinates) position or
178 // wxNOT_FOUND if none, i.e. if it is below the last item
179 %name(HitTestXY) int HitTest(wxCoord x, wxCoord y) const;
180 int HitTest(const wxPoint& pt) const;
181
182 // recalculate all our parameters and redisplay all lines
183 virtual void RefreshAll();
184
185
186 // get the number of lines this window contains (previously set by
187 // SetLineCount())
188 size_t GetLineCount() const;
189
190 // get the first currently visible line
191 size_t GetFirstVisibleLine() const;
192
193 // get the last currently visible line
194 size_t GetLastVisibleLine() const;
195
196 // is this line currently visible?
197 bool IsVisible(size_t line) const;
198
199 };
200
201 //---------------------------------------------------------------------------
202 // wxVListBox
203
204 %{
205 #include <wx/vlbox.h>
206 %}
207
208 MAKE_CONST_WXSTRING(VListBoxNameStr);
209
210
211 // First, the C++ version
212 %{
213 class wxPyVListBox : public wxVListBox
214 {
215 DECLARE_ABSTRACT_CLASS(wxPyVListBox);
216 public:
217 wxPyVListBox() : wxVListBox() {}
218
219 wxPyVListBox(wxWindow *parent,
220 wxWindowID id = wxID_ANY,
221 const wxPoint& pos = wxDefaultPosition,
222 const wxSize& size = wxDefaultSize,
223 long style = 0,
224 const wxString& name = wxPyVListBoxNameStr)
225 : wxVListBox(parent, id, pos, size, style, name)
226 {}
227
228 // Overridable virtuals
229
230 // the derived class must implement this function to actually draw the item
231 // with the given index on the provided DC
232 // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
233 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem);
234
235
236 // the derived class must implement this method to return the height of the
237 // specified item
238 // virtual wxCoord OnMeasureItem(size_t n) const = 0;
239 DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem);
240
241
242 // this method may be used to draw separators between the lines; note that
243 // the rectangle may be modified, typically to deflate it a bit before
244 // passing to OnDrawItem()
245 //
246 // the base class version doesn't do anything
247 // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
248 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawSeparator);
249
250
251 // this method is used to draw the items background and, maybe, a border
252 // around it
253 //
254 // the base class version implements a reasonable default behaviour which
255 // consists in drawing the selected item with the standard background
256 // colour and drawing a border around the item if it is either selected or
257 // current
258 // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
259 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
260
261
262 PYPRIVATE;
263 };
264
265 IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox);
266
267 IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem);
268 IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem);
269 IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawSeparator);
270 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground);
271
272 %}
273
274
275
276 // Now define this class for SWIG
277
278 /*
279 This class has two main differences from a regular listbox: it can have an
280 arbitrarily huge number of items because it doesn't store them itself but
281 uses OnDrawItem() callback to draw them and its items can have variable
282 height as determined by OnMeasureItem().
283
284 It emits the same events as wxListBox and the same event macros may be used
285 with it.
286 */
287 MustHaveApp(wxPyVListBox);
288
289 %name(VListBox) class wxPyVListBox : public wxPyVScrolledWindow
290 {
291 public:
292 %pythonAppend wxPyVListBox "self._setOORInfo(self);self._setCallbackInfo(self, VListBox)"
293 %pythonAppend wxPyVListBox() ""
294
295
296 wxPyVListBox(wxWindow *parent,
297 wxWindowID id = wxID_ANY,
298 const wxPoint& pos = wxDefaultPosition,
299 const wxSize& size = wxDefaultSize,
300 long style = 0,
301 const wxString& name = wxPyVListBoxNameStr);
302
303 %name(PreVListBox) wxPyVListBox();
304
305 void _setCallbackInfo(PyObject* self, PyObject* _class);
306
307 bool Create(wxWindow *parent,
308 wxWindowID id = wxID_ANY,
309 const wxPoint& pos = wxDefaultPosition,
310 const wxSize& size = wxDefaultSize,
311 long style = 0,
312 const wxString& name = wxPyVListBoxNameStr);
313
314 // get the number of items in the control
315 size_t GetItemCount() const;
316
317 // does this control use multiple selection?
318 bool HasMultipleSelection() const;
319
320 // get the currently selected item or wxNOT_FOUND if there is no selection
321 //
322 // this method is only valid for the single selection listboxes
323 int GetSelection() const;
324
325 // is this item the current one?
326 bool IsCurrent(size_t item) const;
327
328 // is this item selected?
329 bool IsSelected(size_t item) const;
330
331 // get the number of the selected items (maybe 0)
332 //
333 // this method is valid for both single and multi selection listboxes
334 size_t GetSelectedCount() const;
335
336 %extend {
337 // get the first selected item, returns wxNOT_FOUND if none
338 //
339 // cookie is an opaque parameter which should be passed to
340 // GetNextSelected() later
341 //
342 // this method is only valid for the multi selection listboxes
343 //int GetFirstSelected(unsigned long& cookie) const;
344 PyObject* GetFirstSelected() {
345 unsigned long cookie = 0;
346 int selected = self->GetFirstSelected(cookie);
347 bool blocked = wxPyBeginBlockThreads();
348 PyObject* tup = PyTuple_New(2);
349 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
350 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
351 wxPyEndBlockThreads(blocked);
352 return tup;
353 }
354
355 // get next selection item, return wxNOT_FOUND if no more
356 //
357 // cookie must be the same parameter that was passed to GetFirstSelected()
358 // before
359 //
360 // this method is only valid for the multi selection listboxes
361 // int GetNextSelected(unsigned long& cookie) const;
362 PyObject* GetNextSelected(unsigned long cookie) {
363 int selected = self->GetNextSelected(cookie);
364 bool blocked = wxPyBeginBlockThreads();
365 PyObject* tup = PyTuple_New(2);
366 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
367 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
368 wxPyEndBlockThreads(blocked);
369 return tup;
370 }
371 }
372
373
374 // get the margins around each item
375 wxPoint GetMargins() const;
376
377 // get the background colour of selected cells
378 const wxColour& GetSelectionBackground() const;
379
380
381 // set the number of items to be shown in the control
382 //
383 // this is just a synonym for wxVScrolledWindow::SetLineCount()
384 void SetItemCount(size_t count);
385
386 // delete all items from the control
387 void Clear();
388
389 // set the selection to the specified item, if it is wxNOT_FOUND the
390 // selection is unset
391 //
392 // this function is only valid for the single selection listboxes
393 void SetSelection(int selection);
394
395 // selects or deselects the specified item which must be valid (i.e. not
396 // equal to wxNOT_FOUND)
397 //
398 // return True if the items selection status has changed or False
399 // otherwise
400 //
401 // this function is only valid for the multiple selection listboxes
402 bool Select(size_t item, bool select = true);
403
404 // selects the items in the specified range whose end points may be given
405 // in any order
406 //
407 // return True if any items selection status has changed, False otherwise
408 //
409 // this function is only valid for the single selection listboxes
410 bool SelectRange(size_t from, size_t to);
411
412 // toggle the selection of the specified item (must be valid)
413 //
414 // this function is only valid for the multiple selection listboxes
415 void Toggle(size_t item);
416
417 // select all items in the listbox
418 //
419 // the return code indicates if any items were affected by this operation
420 // (True) or if nothing has changed (False)
421 bool SelectAll();
422
423 // unselect all items in the listbox
424 //
425 // the return code has the same meaning as for SelectAll()
426 bool DeselectAll();
427
428 // set the margins: horizontal margin is the distance between the window
429 // border and the item contents while vertical margin is half of the
430 // distance between items
431 //
432 // by default both margins are 0
433 void SetMargins(const wxPoint& pt);
434 %name(SetMarginsXY) void SetMargins(wxCoord x, wxCoord y);
435
436 // change the background colour of the selected cells
437 void SetSelectionBackground(const wxColour& col);
438
439 };
440
441
442 //---------------------------------------------------------------------------
443 // wxHtmlListBox
444
445 %{
446 #include <wx/htmllbox.h>
447 %}
448
449 // First, the C++ version
450 %{
451 class wxPyHtmlListBox : public wxHtmlListBox
452 {
453 DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox);
454 public:
455 wxPyHtmlListBox() : wxHtmlListBox() {}
456
457 wxPyHtmlListBox(wxWindow *parent,
458 wxWindowID id = wxID_ANY,
459 const wxPoint& pos = wxDefaultPosition,
460 const wxSize& size = wxDefaultSize,
461 long style = 0,
462 const wxString& name = wxPyVListBoxNameStr)
463 : wxHtmlListBox(parent, id, pos, size, style, name)
464 {}
465
466 // Overridable virtuals
467
468 // this method must be implemented in the derived class and should return
469 // the body (i.e. without <html>) of the HTML for the given item
470 DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem);
471
472 // this function may be overridden to decorate HTML returned by OnGetItem()
473 DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup);
474
475 // TODO:
476 // // this method allows to customize the selection appearance: it may be used
477 // // to specify the colour of the text which normally has the given colour
478 // // colFg when it is inside the selection
479 // //
480 // // by default, the original colour is not used at all and all text has the
481 // // same (default for this system) colour inside selection
482 // virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
483
484 // // this is the same as GetSelectedTextColour() but allows to customize the
485 // // background colour -- this is even more rarely used as you can change it
486 // // globally using SetSelectionBackground()
487 // virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
488
489
490 PYPRIVATE;
491 };
492
493
494 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox)
495
496 IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem);
497 IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup);
498
499 %}
500
501
502
503 // Now define this class for SWIG
504
505
506 // wxHtmlListBox is a listbox whose items are wxHtmlCells
507 MustHaveApp(wxPyHtmlListBox);
508 %name(HtmlListBox) class wxPyHtmlListBox : public wxPyVListBox
509 {
510 public:
511 %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);self._setCallbackInfo(self, HtmlListBox)"
512 %pythonAppend wxPyHtmlListBox() ""
513
514
515 // normal constructor which calls Create() internally
516 wxPyHtmlListBox(wxWindow *parent,
517 wxWindowID id = wxID_ANY,
518 const wxPoint& pos = wxDefaultPosition,
519 const wxSize& size = wxDefaultSize,
520 long style = 0,
521 const wxString& name = wxPyVListBoxNameStr);
522
523 %name(PreHtmlListBox) wxPyHtmlListBox();
524
525 void _setCallbackInfo(PyObject* self, PyObject* _class);
526
527 bool Create(wxWindow *parent,
528 wxWindowID id = wxID_ANY,
529 const wxPoint& pos = wxDefaultPosition,
530 const wxSize& size = wxDefaultSize,
531 long style = 0,
532 const wxString& name = wxPyVListBoxNameStr);
533
534
535 void RefreshAll();
536 void SetItemCount(size_t count);
537
538 // retrieve the file system used by the wxHtmlWinParser: if you use
539 // relative paths in your HTML, you should use its ChangePathTo() method
540 wxFileSystem& GetFileSystem();
541 };
542
543
544
545 //---------------------------------------------------------------------------
546
547 %init %{
548 // Map renamed classes back to their common name for OOR
549 wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox");
550 wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox");
551 wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow");
552 %}
553
554 //---------------------------------------------------------------------------