]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_vscroll.i
adding missing typedefs for 10.4
[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 // update the thumb size shown by the scrollbar
99 void UpdateScrollbar() { wxVScrolledWindow::UpdateScrollbar(); }
100
101 // remove the scrollbar completely because we don't need it
102 void RemoveScrollbar() { wxVScrolledWindow::RemoveScrollbar(); }
103
104 PYPRIVATE;
105 };
106
107 IMPLEMENT_ABSTRACT_CLASS(wxPyVScrolledWindow, wxVScrolledWindow);
108
109 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLineHeight);
110 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLinesHint);
111 IMP_PYCALLBACK_COORD_const (wxPyVScrolledWindow, wxVScrolledWindow, EstimateTotalHeight);
112 %}
113
114
115
116 // Now define this class for SWIG
117
118 /*
119 In the name of this class, "V" may stand for "variable" because it can be
120 used for scrolling lines of variable heights; "virtual" because it is not
121 necessary to know the heights of all lines in advance -- only those which
122 are shown on the screen need to be measured; or, even, "vertical" because
123 this class only supports scrolling in one direction currently (this could
124 and probably will change in the future however).
125
126 In any case, this is a generalization of the wxScrolledWindow class which
127 can be only used when all lines have the same height. It lacks some other
128 wxScrolledWindow features however, notably it currently lacks support for
129 horizontal scrolling; it can't scroll another window nor only a rectangle
130 of the window and not its entire client area.
131 */
132
133 MustHaveApp(wxPyVScrolledWindow);
134
135 %rename(VScrolledWindow) wxPyVScrolledWindow;
136 class wxPyVScrolledWindow : public wxPanel
137 {
138 public:
139 %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self); self._setCallbackInfo(self, VScrolledWindow)"
140 %pythonAppend wxPyVScrolledWindow() ""
141
142
143 wxPyVScrolledWindow(wxWindow *parent,
144 wxWindowID id = wxID_ANY,
145 const wxPoint& pos = wxDefaultPosition,
146 const wxSize& size = wxDefaultSize,
147 long style = 0,
148 const wxString& name = wxPyPanelNameStr);
149
150 %RenameCtor(PreVScrolledWindow, wxPyVScrolledWindow());
151
152 void _setCallbackInfo(PyObject* self, PyObject* _class);
153
154 bool Create(wxWindow *parent,
155 wxWindowID id = wxID_ANY,
156 const wxPoint& pos = wxDefaultPosition,
157 const wxSize& size = wxDefaultSize,
158 long style = 0,
159 const wxString& name = wxPyPanelNameStr);
160
161
162 // set the number of lines the window contains: the derived class must
163 // provide the heights for all lines with indices up to the one given here
164 // in its OnGetLineHeight()
165 void SetLineCount(size_t count);
166
167 // scroll to the specified line: it will become the first visible line in
168 // the window
169 //
170 // return True if we scrolled the window, False if nothing was done
171 bool ScrollToLine(size_t line);
172
173 // scroll by the specified number of lines/pages
174 virtual bool ScrollLines(int lines);
175 virtual bool ScrollPages(int pages);
176
177 // redraw the specified line
178 void RefreshLine(size_t line);
179
180 // redraw all lines in the specified range (inclusive)
181 void RefreshLines(size_t from, size_t to);
182
183 // return the item at the specified (in physical coordinates) position or
184 // wxNOT_FOUND if none, i.e. if it is below the last item
185 %Rename(HitTestXY, int, HitTest(wxCoord x, wxCoord y) const);
186 int HitTest(const wxPoint& pt) const;
187
188 // recalculate all our parameters and redisplay all lines
189 virtual void RefreshAll();
190
191
192 // get the number of lines this window contains (previously set by
193 // SetLineCount())
194 size_t GetLineCount() const;
195
196 // get the first currently visible line
197 size_t GetVisibleBegin() const;
198
199 // get the last currently visible line
200 size_t GetVisibleEnd() const;
201
202 // is this line currently visible?
203 bool IsVisible(size_t line) const;
204
205 // this is the same as GetVisibleBegin(), exists to match
206 // GetLastVisibleLine() and for backwards compatibility only
207 size_t GetFirstVisibleLine() const;
208
209 // get the last currently visible line
210 //
211 // this function is unsafe as it returns (size_t)-1 (i.e. a huge positive
212 // number) if the control is empty, use GetVisibleEnd() instead, this one
213 // is kept for backwards compatibility
214 size_t GetLastVisibleLine() const;
215
216 // find the index of the line we need to show at the top of the window such
217 // that the last (fully or partially) visible line is the given one
218 size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false);
219
220 // get the total height of the lines between lineMin (inclusive) and
221 // lineMax (exclusive)
222 wxCoord GetLinesHeight(size_t lineMin, size_t lineMax) const;
223
224 %property(FirstVisibleLine, GetFirstVisibleLine, doc="See `GetFirstVisibleLine`");
225 %property(LastVisibleLine, GetLastVisibleLine, doc="See `GetLastVisibleLine`");
226 %property(LineCount, GetLineCount, SetLineCount, doc="See `GetLineCount` and `SetLineCount`");
227 %property(VisibleBegin, GetVisibleBegin, doc="See `GetVisibleBegin`");
228 %property(VisibleEnd, GetVisibleEnd, doc="See `GetVisibleEnd`");
229 };
230
231
232
233 //---------------------------------------------------------------------------
234 // wxVListBox
235
236 %{
237 #include <wx/vlbox.h>
238 %}
239
240 MAKE_CONST_WXSTRING(VListBoxNameStr);
241
242
243 // First, the C++ version
244 %{
245 class wxPyVListBox : public wxVListBox
246 {
247 DECLARE_ABSTRACT_CLASS(wxPyVListBox)
248 public:
249 wxPyVListBox() : wxVListBox() {}
250
251 wxPyVListBox(wxWindow *parent,
252 wxWindowID id = wxID_ANY,
253 const wxPoint& pos = wxDefaultPosition,
254 const wxSize& size = wxDefaultSize,
255 long style = 0,
256 const wxString& name = wxPyVListBoxNameStr)
257 : wxVListBox(parent, id, pos, size, style, name)
258 {}
259
260 // Overridable virtuals
261
262 // the derived class must implement this function to actually draw the item
263 // with the given index on the provided DC
264 // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
265 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem);
266
267
268 // the derived class must implement this method to return the height of the
269 // specified item
270 // virtual wxCoord OnMeasureItem(size_t n) const = 0;
271 DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem);
272
273
274 // this method may be used to draw separators between the lines; note that
275 // the rectangle may be modified, typically to deflate it a bit before
276 // passing to OnDrawItem()
277 //
278 // the base class version doesn't do anything
279 // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
280 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
281
282
283 // this method is used to draw the items background and, maybe, a border
284 // around it
285 //
286 // the base class version implements a reasonable default behaviour which
287 // consists in drawing the selected item with the standard background
288 // colour and drawing a border around the item if it is either selected or
289 // current
290 // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
291 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
292
293
294 PYPRIVATE;
295 };
296
297 IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox);
298
299 IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem);
300 IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem);
301 IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyVListBox, wxVListBox, OnDrawSeparator);
302 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground);
303
304 %}
305
306
307
308 // Now define this class for SWIG
309
310 /*
311 This class has two main differences from a regular listbox: it can have an
312 arbitrarily huge number of items because it doesn't store them itself but
313 uses OnDrawItem() callback to draw them and its items can have variable
314 height as determined by OnMeasureItem().
315
316 It emits the same events as wxListBox and the same event macros may be used
317 with it.
318 */
319 MustHaveApp(wxPyVListBox);
320
321 %rename(VListBox) wxPyVListBox;
322 class wxPyVListBox : public wxPyVScrolledWindow
323 {
324 public:
325 %pythonAppend wxPyVListBox "self._setOORInfo(self);self._setCallbackInfo(self, VListBox)"
326 %pythonAppend wxPyVListBox() ""
327
328
329 wxPyVListBox(wxWindow *parent,
330 wxWindowID id = wxID_ANY,
331 const wxPoint& pos = wxDefaultPosition,
332 const wxSize& size = wxDefaultSize,
333 long style = 0,
334 const wxString& name = wxPyVListBoxNameStr);
335
336 %RenameCtor(PreVListBox, wxPyVListBox());
337
338 void _setCallbackInfo(PyObject* self, PyObject* _class);
339
340 bool Create(wxWindow *parent,
341 wxWindowID id = wxID_ANY,
342 const wxPoint& pos = wxDefaultPosition,
343 const wxSize& size = wxDefaultSize,
344 long style = 0,
345 const wxString& name = wxPyVListBoxNameStr);
346
347 // get the number of items in the control
348 size_t GetItemCount() const;
349
350 // does this control use multiple selection?
351 bool HasMultipleSelection() const;
352
353 // get the currently selected item or wxNOT_FOUND if there is no selection
354 //
355 // this method is only valid for the single selection listboxes
356 int GetSelection() const;
357
358 // is this item the current one?
359 bool IsCurrent(size_t item) const;
360
361 // is this item selected?
362 bool IsSelected(size_t item) const;
363
364 // get the number of the selected items (maybe 0)
365 //
366 // this method is valid for both single and multi selection listboxes
367 size_t GetSelectedCount() const;
368
369 %extend {
370 // get the first selected item, returns wxNOT_FOUND if none
371 //
372 // cookie is an opaque parameter which should be passed to
373 // GetNextSelected() later
374 //
375 // this method is only valid for the multi selection listboxes
376 //int GetFirstSelected(unsigned long& cookie) const;
377 PyObject* GetFirstSelected() {
378 unsigned long cookie = 0;
379 int selected = self->GetFirstSelected(cookie);
380 wxPyBlock_t blocked = wxPyBeginBlockThreads();
381 PyObject* tup = PyTuple_New(2);
382 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
383 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
384 wxPyEndBlockThreads(blocked);
385 return tup;
386 }
387
388 // get next selection item, return wxNOT_FOUND if no more
389 //
390 // cookie must be the same parameter that was passed to GetFirstSelected()
391 // before
392 //
393 // this method is only valid for the multi selection listboxes
394 // int GetNextSelected(unsigned long& cookie) const;
395 PyObject* GetNextSelected(unsigned long cookie) {
396 int selected = self->GetNextSelected(cookie);
397 wxPyBlock_t blocked = wxPyBeginBlockThreads();
398 PyObject* tup = PyTuple_New(2);
399 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
400 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
401 wxPyEndBlockThreads(blocked);
402 return tup;
403 }
404 }
405
406
407 // get the margins around each item
408 wxPoint GetMargins() const;
409
410 // get the background colour of selected cells
411 const wxColour& GetSelectionBackground() const;
412
413
414 // set the number of items to be shown in the control
415 //
416 // this is just a synonym for wxVScrolledWindow::SetLineCount()
417 void SetItemCount(size_t count);
418
419 // delete all items from the control
420 void Clear();
421
422 // set the selection to the specified item, if it is wxNOT_FOUND the
423 // selection is unset
424 //
425 // this function is only valid for the single selection listboxes
426 void SetSelection(int selection);
427
428 // selects or deselects the specified item which must be valid (i.e. not
429 // equal to wxNOT_FOUND)
430 //
431 // return True if the items selection status has changed or False
432 // otherwise
433 //
434 // this function is only valid for the multiple selection listboxes
435 bool Select(size_t item, bool select = true);
436
437 // selects the items in the specified range whose end points may be given
438 // in any order
439 //
440 // return True if any items selection status has changed, False otherwise
441 //
442 // this function is only valid for the single selection listboxes
443 bool SelectRange(size_t from, size_t to);
444
445 // toggle the selection of the specified item (must be valid)
446 //
447 // this function is only valid for the multiple selection listboxes
448 void Toggle(size_t item);
449
450 // select all items in the listbox
451 //
452 // the return code indicates if any items were affected by this operation
453 // (True) or if nothing has changed (False)
454 bool SelectAll();
455
456 // unselect all items in the listbox
457 //
458 // the return code has the same meaning as for SelectAll()
459 bool DeselectAll();
460
461 // set the margins: horizontal margin is the distance between the window
462 // border and the item contents while vertical margin is half of the
463 // distance between items
464 //
465 // by default both margins are 0
466 void SetMargins(const wxPoint& pt);
467 %Rename(SetMarginsXY, void, SetMargins(wxCoord x, wxCoord y));
468
469 // change the background colour of the selected cells
470 void SetSelectionBackground(const wxColour& col);
471
472 virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
473 virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
474
475 %property(FirstSelected, GetFirstSelected, doc="See `GetFirstSelected`");
476 %property(ItemCount, GetItemCount, SetItemCount, doc="See `GetItemCount` and `SetItemCount`");
477 %property(Margins, GetMargins, SetMargins, doc="See `GetMargins` and `SetMargins`");
478 %property(SelectedCount, GetSelectedCount, doc="See `GetSelectedCount`");
479 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
480 %property(SelectionBackground, GetSelectionBackground, SetSelectionBackground, doc="See `GetSelectionBackground` and `SetSelectionBackground`");
481 };
482
483
484 //---------------------------------------------------------------------------
485 // wxHtmlListBox
486
487 %{
488 #include <wx/htmllbox.h>
489 %}
490
491 // First, the C++ version
492 %{
493 class wxPyHtmlListBox : public wxHtmlListBox
494 {
495 DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox)
496 public:
497 wxPyHtmlListBox() : wxHtmlListBox() {}
498
499 wxPyHtmlListBox(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 : wxHtmlListBox(parent, id, pos, size, style, name)
506 {}
507
508 // Overridable virtuals
509
510 // this method must be implemented in the derived class and should return
511 // the body (i.e. without <html>) of the HTML for the given item
512 DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem);
513
514 // this function may be overridden to decorate HTML returned by OnGetItem()
515 DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup);
516
517 // These are from wxVListBox
518 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
519 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
520
521 // TODO:
522 // // this method allows to customize the selection appearance: it may be used
523 // // to specify the colour of the text which normally has the given colour
524 // // colFg when it is inside the selection
525 // //
526 // // by default, the original colour is not used at all and all text has the
527 // // same (default for this system) colour inside selection
528 // virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
529
530 // // this is the same as GetSelectedTextColour() but allows to customize the
531 // // background colour -- this is even more rarely used as you can change it
532 // // globally using SetSelectionBackground()
533 // virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
534
535
536 // This method may be overriden to handle clicking on a link in
537 // the listbox. By default, clicking links is ignored.
538 virtual void OnLinkClicked(size_t n,
539 const wxHtmlLinkInfo& link);
540
541 PYPRIVATE;
542 };
543
544
545 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox)
546
547 IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem);
548 IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup);
549 IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawSeparator);
550 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawBackground);
551
552
553 void wxPyHtmlListBox::OnLinkClicked(size_t n,
554 const wxHtmlLinkInfo& link) {
555 bool found;
556 wxPyBlock_t blocked = wxPyBeginBlockThreads();
557 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
558 PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0);
559 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", n, obj));
560 Py_DECREF(obj);
561 }
562 wxPyEndBlockThreads(blocked);
563 if (! found)
564 wxPyHtmlListBox::OnLinkClicked(n, link);
565 }
566
567 %}
568
569
570
571 // Now define this class for SWIG
572
573
574 // wxHtmlListBox is a listbox whose items are wxHtmlCells
575 MustHaveApp(wxPyHtmlListBox);
576 %rename(HtmlListBox) wxPyHtmlListBox;
577 class wxPyHtmlListBox : public wxPyVListBox
578 {
579 public:
580 %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);self._setCallbackInfo(self, HtmlListBox)"
581 %pythonAppend wxPyHtmlListBox() ""
582
583
584 // normal constructor which calls Create() internally
585 wxPyHtmlListBox(wxWindow *parent,
586 wxWindowID id = wxID_ANY,
587 const wxPoint& pos = wxDefaultPosition,
588 const wxSize& size = wxDefaultSize,
589 long style = 0,
590 const wxString& name = wxPyVListBoxNameStr);
591
592 %RenameCtor(PreHtmlListBox, wxPyHtmlListBox());
593
594 void _setCallbackInfo(PyObject* self, PyObject* _class);
595
596 bool Create(wxWindow *parent,
597 wxWindowID id = wxID_ANY,
598 const wxPoint& pos = wxDefaultPosition,
599 const wxSize& size = wxDefaultSize,
600 long style = 0,
601 const wxString& name = wxPyVListBoxNameStr);
602
603
604 void RefreshAll();
605 void SetItemCount(size_t count);
606
607 // retrieve the file system used by the wxHtmlWinParser: if you use
608 // relative paths in your HTML, you should use its ChangePathTo() method
609 wxFileSystem& GetFileSystem();
610
611 void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link);
612
613 %property(FileSystem, GetFileSystem, doc="See `GetFileSystem`");
614 };
615
616
617
618 //---------------------------------------------------------------------------
619
620 %init %{
621 // Map renamed classes back to their common name for OOR
622 wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox");
623 wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox");
624 wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow");
625 %}
626
627 //---------------------------------------------------------------------------