]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_vscroll.i
mention wxLogInterposer(Temp)
[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 #include <wx/vscroll.h>
22 %}
23
24 %newgroup;
25 //---------------------------------------------------------------------------
26 // Base classes. I don't expect that these will ever be used directly from
27 // Python, (especially being derived from) so I own't worry about making their
28 // virutals overridable. They're just defined here for their public methods.
29
30
31
32 // Provides all base common scroll calculations needed for either orientation,
33 // automatic scrollbar functionality, saved scroll positions, functionality
34 // for changing the target window to be scrolled, as well as defining all
35 // required virtual functions that need to be implemented for any orientation
36 // specific work.
37
38 class wxVarScrollHelperBase
39 {
40 public:
41
42 // wxVarScrollHelperBase(wxWindow *winToScroll); *** ABC, can't instantiate
43 // virtual ~wxVarScrollHelperBase();
44
45
46 // with physical scrolling on, the device origin is changed properly when
47 // a wxPaintDC is prepared, children are actually moved and laid out
48 // properly, and the contents of the window (pixels) are actually moved
49 void EnablePhysicalScrolling(bool scrolling = true);
50
51 // wxNOT_FOUND if none, i.e. if it is below the last item
52 virtual int HitTest(wxCoord coord) const;
53
54 // recalculate all our parameters and redisplay all units
55 virtual void RefreshAll();
56
57
58 // get the first currently visible unit
59 size_t GetVisibleBegin() const;
60
61 // get the last currently visible unit
62 size_t GetVisibleEnd() const;
63
64 // is this unit currently visible?
65 bool IsVisible(size_t unit) const;
66
67 // translate between scrolled and unscrolled coordinates
68 int CalcScrolledPosition(int coord) const;
69 int CalcUnscrolledPosition(int coord) const;
70
71 // update the thumb size shown by the scrollbar
72 virtual void UpdateScrollbar();
73 void RemoveScrollbar();
74
75 // Normally the wxScrolledWindow will scroll itself, but in some rare
76 // occasions you might want it to scroll [part of] another window (e.g. a
77 // child of it in order to scroll only a portion the area between the
78 // scrollbars (spreadsheet: only cell area will move).
79 virtual void SetTargetWindow(wxWindow *target);
80 virtual wxWindow *GetTargetWindow() const;
81
82
83 // these functions must be overidden in the derived class to return
84 // orientation specific data (e.g. the width for vertically scrolling
85 // derivatives in the case of GetOrientationTargetSize())
86 virtual int GetOrientationTargetSize() const; // = 0;
87 virtual int GetNonOrientationTargetSize() const; // = 0;
88 virtual wxOrientation GetOrientation() const; // = 0;
89 };
90
91
92
93
94
95 // Provides public API functions targeted for vertical-specific scrolling,
96 // wrapping the functionality of wxVarScrollHelperBase.
97
98 class wxVarVScrollHelper : public wxVarScrollHelperBase
99 {
100 public:
101
102 // wxVarVScrollHelper(wxWindow *winToScroll); *** ABC, can't instantiate
103
104 void SetRowCount(size_t rowCount);
105 bool ScrollToRow(size_t row);
106
107 virtual bool ScrollRows(int rows);
108 virtual bool ScrollRowPages(int pages);
109
110 virtual void RefreshRow(size_t row);
111 virtual void RefreshRows(size_t from, size_t to);
112
113 size_t GetRowCount() const;
114 size_t GetVisibleRowsBegin() const;
115 size_t GetVisibleRowsEnd() const;
116 bool IsRowVisible(size_t row) const;
117
118 virtual int GetOrientationTargetSize() const;
119 virtual int GetNonOrientationTargetSize() const;
120 virtual wxOrientation GetOrientation() const;
121 };
122
123
124
125
126
127 // Provides public API functions targeted for horizontal-specific scrolling,
128 // wrapping the functionality of wxVarScrollHelperBase.
129
130 class wxVarHScrollHelper : public wxVarScrollHelperBase
131 {
132 public:
133
134 // wxVarHScrollHelper(wxWindow *winToScroll) *** ABC, can't instantiate
135
136 void SetColumnCount(size_t columnCount);
137
138 bool ScrollToColumn(size_t column);
139 virtual bool ScrollColumns(int columns);
140 virtual bool ScrollColumnPages(int pages);
141
142 virtual void RefreshColumn(size_t column);
143 virtual void RefreshColumns(size_t from, size_t to);
144
145 size_t GetColumnCount() const;
146 size_t GetVisibleColumnsBegin() const;
147 size_t GetVisibleColumnsEnd() const;
148 bool IsColumnVisible(size_t column) const;
149
150
151 virtual int GetOrientationTargetSize() const;
152 virtual int GetNonOrientationTargetSize() const;
153 virtual wxOrientation GetOrientation() const;
154
155 };
156
157
158
159
160
161
162 // Provides public API functions targeted at functions with similar names in
163 // both wxVScrollHelper and wxHScrollHelper so class scope doesn't need to be
164 // specified (since we are using multiple inheritance). It also provides
165 // functions to make changing values for both orientations at the same time
166 // easier.
167
168 class wxVarHVScrollHelper : public wxVarVScrollHelper,
169 public wxVarHScrollHelper
170 {
171 public:
172
173 // wxVarHVScrollHelper(wxWindow *winToScroll); *** ABC, can't instantiate
174
175
176 // set the number of units the window contains for each axis: the derived
177 // class must provide the widths and heights for all units with indices up
178 // to each of the one given here in its OnGetColumnWidth() and
179 // OnGetRowHeight()
180 void SetRowColumnCount(size_t rowCount, size_t columnCount);
181
182
183 // with physical scrolling on, the device origin is changed properly when
184 // a wxPaintDC is prepared, children are actually moved and laid out
185 // properly, and the contents of the window (pixels) are actually moved
186 void EnablePhysicalScrolling(bool vscrolling = true, bool hscrolling = true);
187
188
189 // scroll to the specified row/column: it will become the first visible
190 // cell in the window
191 //
192 // return true if we scrolled the window, false if nothing was done
193 // bool ScrollToRowColumn(size_t row, size_t column);
194 bool ScrollToRowColumn(const wxPosition &pos);
195
196 // redraw the specified cell
197 // virtual void RefreshRowColumn(size_t row, size_t column);
198 virtual void RefreshRowColumn(const wxPosition &pos);
199
200 // redraw the specified regions (inclusive). If the target window for
201 // both orientations is the same the rectangle of cells is refreshed; if
202 // the target windows differ the entire client size opposite the
203 // orientation direction is refreshed between the specified limits
204 // virtual void RefreshRowsColumns(size_t fromRow, size_t toRow,
205 // size_t fromColumn, size_t toColumn);
206 virtual void RefreshRowsColumns(const wxPosition& from,
207 const wxPosition& to);
208
209 // Override wxPanel::HitTest to use our version
210 // wxPosition VirtualHitTest(wxCoord x, wxCoord y) const;
211 wxPosition VirtualHitTest(const wxPoint &pos) const;
212
213 // replacement implementation of wxWindow::Layout virtual method. To
214 // properly forward calls to wxWindow::Layout use
215 // WX_FORWARD_TO_SCROLL_HELPER() derived class. We use this version to
216 // call both base classes' ScrollLayout()
217 bool ScrollLayout();
218
219 // get the number of units this window contains (previously set by
220 // Set[Column/Row/RowColumn/Unit]Count())
221 wxSize GetRowColumnCount() const;
222
223 // get the first currently visible units
224 wxPosition GetVisibleBegin() const;
225 wxPosition GetVisibleEnd() const;
226
227 // is this cell currently visible?
228 // bool IsVisible(size_t row, size_t column) const;
229 bool IsVisible(const wxPosition &pos) const;
230 };
231
232
233
234
235 //---------------------------------------------------------------------------
236 // wxVScrolledWindow
237
238
239
240 // First, the C++ version that can redirect to overridden Python methods
241 %{
242 class wxPyVScrolledWindow : public wxVScrolledWindow
243 {
244 DECLARE_ABSTRACT_CLASS(wxPyVScrolledWindow)
245 public:
246 wxPyVScrolledWindow() : wxVScrolledWindow() {}
247
248 wxPyVScrolledWindow(wxWindow *parent,
249 wxWindowID id = wxID_ANY,
250 const wxPoint& pos = wxDefaultPosition,
251 const wxSize& size = wxDefaultSize,
252 long style = 0,
253 const wxString& name = wxPyPanelNameStr)
254 : wxVScrolledWindow(parent, id, pos, size, style, name)
255 {}
256
257 // Overridable virtuals
258
259 // this function must be overridden in the derived class and it should
260 // return the height of the given line in pixels
261 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetRowHeight);
262 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetLineHeight); // old name
263
264 // this function doesn't have to be overridden but it may be useful to do
265 // it if calculating the lines heights is a relatively expensive operation
266 // as it gives the user code a possibility to calculate several of them at
267 // once
268 //
269 // OnGetLinesHint() is normally called just before OnGetRowHeight() but you
270 // shouldn't rely on the latter being called for all lines in the interval
271 // specified here. It is also possible that OnGetRowHeight() will be
272 // called for the lines outside of this interval, so this is really just a
273 // hint, not a promise.
274 //
275 // finally note that lineMin is inclusive, while lineMax is exclusive, as
276 // usual
277 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetRowsHeightHint);
278 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetLinesHint); // old name
279
280 // when the number of lines changes, we try to estimate the total height
281 // of all lines which is a rather expensive operation in terms of lines
282 // access, so if the user code may estimate the average height
283 // better/faster than we do, it should override this function to implement
284 // its own logic
285 //
286 // this function should return the best guess for the total height it may
287 // make
288 DEC_PYCALLBACK_COORD_const(EstimateTotalHeight);
289
290
291 // Also expose some other interesting protected methods
292
293
294 // get the total height of the lines between lineMin (inclusive) and
295 // lineMax (exclusive)
296 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const
297 { return wxVScrolledWindow::GetRowsHeight(lineMin, lineMax); }
298
299
300 PYPRIVATE;
301 };
302
303 IMPLEMENT_ABSTRACT_CLASS(wxPyVScrolledWindow, wxVScrolledWindow);
304
305 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetRowHeight);
306 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLineHeight);
307 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetRowsHeightHint);
308 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLinesHint);
309
310 IMP_PYCALLBACK_COORD_const (wxPyVScrolledWindow, wxVScrolledWindow, EstimateTotalHeight);
311 %}
312
313
314
315
316
317 // Now define this class for SWIG
318
319 /*
320 In the name of this class, "V" may stand for "variable" because it can be
321 used for scrolling lines of variable heights; "virtual" because it is not
322 necessary to know the heights of all lines in advance -- only those which
323 are shown on the screen need to be measured; or, even, "vertical" because
324 this class only supports scrolling in one direction currently (this could
325 and probably will change in the future however).
326
327 In any case, this is a generalization of the wxScrolledWindow class which
328 can be only used when all lines have the same height. It lacks some other
329 wxScrolledWindow features however, notably it currently lacks support for
330 horizontal scrolling; it can't scroll another window nor only a rectangle
331 of the window and not its entire client area.
332 */
333
334 MustHaveApp(wxPyVScrolledWindow);
335
336 %rename(VScrolledWindow) wxPyVScrolledWindow;
337
338 class wxPyVScrolledWindow : public wxPanel,
339 public wxVarVScrollHelper
340 {
341 public:
342 %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self);" setCallbackInfo(VScrolledWindow)
343 %pythonAppend wxPyVScrolledWindow() ""
344
345
346 wxPyVScrolledWindow(wxWindow *parent,
347 wxWindowID id = wxID_ANY,
348 const wxPoint& pos = wxDefaultPosition,
349 const wxSize& size = wxDefaultSize,
350 long style = 0,
351 const wxString& name = wxPyPanelNameStr);
352
353 %RenameCtor(PreVScrolledWindow, wxPyVScrolledWindow());
354
355 void _setCallbackInfo(PyObject* self, PyObject* _class);
356
357 bool Create(wxWindow *parent,
358 wxWindowID id = wxID_ANY,
359 const wxPoint& pos = wxDefaultPosition,
360 const wxSize& size = wxDefaultSize,
361 long style = 0,
362 const wxString& name = wxPyPanelNameStr);
363
364
365 // get the total height of the lines between lineMin (inclusive) and
366 // lineMax (exclusive)
367 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const;
368 %pythoncode { GetLinesHeight = wx._deprecated(GetRowsHeight,
369 "Use GetRowsHeight instead.") }
370
371 virtual wxCoord EstimateTotalHeight() const;
372
373 int HitTest(const wxPoint& pt) const;
374
375
376 // Deprecated wrappers for methods whose name changed when adding the H
377 // classes. I just put them here instead of wrapping the
378 // wxVarVScrollLegacyAdaptor class.
379 %pythoncode {
380 def GetFirstVisibleLine(self):
381 return self.GetVisibleRowsBegin()
382 GetFirstVisibleLine = wx._deprecated(GetFirstVisibleLine, "Use GetVisibleRowsBegin instead" )
383
384 def GetLastVisibleLine(self):
385 return self.GetVisibleRowsEnd() - 1
386 GetLastVisibleLine = wx._deprecated(GetLastVisibleLine, "Use GetVisibleRowsEnd instead")
387
388 def GetLineCount(self):
389 return self.GetRowCount()
390 GetLineCount = wx._deprecated(GetLineCount, "Use GetRowCount instead")
391
392 def SetLineCount(self, count):
393 self.SetRowCount(count)
394 SetLineCount = wx._deprecated(SetLineCount, "Use SetRowCount instead")
395
396 def RefreshLine(self, line):
397 self.RefreshRow(line)
398 RefreshLine = wx._deprecated(RefreshLine, "Use RefreshRow instead")
399
400 def RefreshLines(self, frm, to):
401 self.RefreshRows(frm, to)
402 RefreshLines = wx._deprecated(RefreshLines, "Use RefreshRows instead")
403
404 def ScrollToLine(self, line):
405 return self.ScrollToRow(line)
406 ScrollToLine = wx._deprecated(ScrollToLine, "Use RefreshRow instead")
407
408 def ScrollLines(self, lines):
409 return self.ScrollRows(lines)
410 ScrollLines = wx._deprecated(ScrollLines, "Use ScrollRows instead")
411
412 def ScrollPages(self, pages):
413 return self.ScrollRowPages(pages)
414 ScrollPages = wx._deprecated(ScrollPages, "Use ScrollRowPages instead")
415 }
416
417 };
418
419
420
421 //---------------------------------------------------------------------------
422 // wxHScrolledWindow
423
424
425 // First, the C++ version that can redirect to overridden Python methods
426 %{
427 class wxPyHScrolledWindow : public wxHScrolledWindow
428 {
429 DECLARE_ABSTRACT_CLASS(wxPyHScrolledWindow)
430 public:
431 wxPyHScrolledWindow() : wxHScrolledWindow() {}
432
433 wxPyHScrolledWindow(wxWindow *parent,
434 wxWindowID id = wxID_ANY,
435 const wxPoint& pos = wxDefaultPosition,
436 const wxSize& size = wxDefaultSize,
437 long style = 0,
438 const wxString& name = wxPyPanelNameStr)
439 : wxHScrolledWindow(parent, id, pos, size, style, name)
440 {}
441
442 // Overridable virtuals
443 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetColumnWidth);
444 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetColumnsWidthHint);
445 DEC_PYCALLBACK_COORD_const(EstimateTotalWidth);
446
447 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const
448 { return wxHScrolledWindow::GetColumnsWidth(columnMin, columnMax); }
449
450 PYPRIVATE;
451 };
452
453 IMPLEMENT_ABSTRACT_CLASS(wxPyHScrolledWindow, wxHScrolledWindow);
454
455 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyHScrolledWindow, wxHScrolledWindow, OnGetColumnWidth);
456 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyHScrolledWindow, wxHScrolledWindow, OnGetColumnsWidthHint);
457 IMP_PYCALLBACK_COORD_const (wxPyHScrolledWindow, wxHScrolledWindow, EstimateTotalWidth);
458
459 %}
460
461
462
463 // Now define this class for SWIG
464
465 // In the name of this class, "H" stands for "horizontal" because it can be
466 // used for scrolling columns of variable widths. It is not necessary to know
467 // the widths of all columns in advance -- only those which are shown on the
468 // screen need to be measured.
469
470 // This is a generalization of the wxScrolledWindow class which can be only
471 // used when all columns have the same width. It lacks some other
472 // wxScrolledWindow features however, notably it can't scroll only a rectangle
473 // of the window and not its entire client area.
474
475 MustHaveApp(wxPyHScrolledWindow);
476
477 %rename(HScrolledWindow) wxPyHScrolledWindow;
478
479 class wxPyHScrolledWindow : public wxPanel,
480 public wxVarHScrollHelper
481 {
482 public:
483 %pythonAppend wxPyHScrolledWindow "self._setOORInfo(self);" setCallbackInfo(HScrolledWindow)
484 %pythonAppend wxPyHScrolledWindow() ""
485
486
487 wxPyHScrolledWindow(wxWindow *parent,
488 wxWindowID id = wxID_ANY,
489 const wxPoint& pos = wxDefaultPosition,
490 const wxSize& size = wxDefaultSize,
491 long style = 0,
492 const wxString& name = wxPyPanelNameStr);
493
494 %RenameCtor(PreHScrolledWindow, wxPyHScrolledWindow());
495
496 void _setCallbackInfo(PyObject* self, PyObject* _class);
497
498 bool Create(wxWindow *parent,
499 wxWindowID id = wxID_ANY,
500 const wxPoint& pos = wxDefaultPosition,
501 const wxSize& size = wxDefaultSize,
502 long style = 0,
503 const wxString& name = wxPyPanelNameStr);
504
505
506 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const;
507 wxCoord EstimateTotalWidth() const;
508 };
509
510
511
512 //---------------------------------------------------------------------------
513 // wxHVScrolledWindow
514
515
516
517 // First, the C++ version that can redirect to overridden Python methods
518 %{
519 class wxPyHVScrolledWindow : public wxHVScrolledWindow
520 {
521 DECLARE_ABSTRACT_CLASS(wxPyHScrolledWindow)
522 public:
523 wxPyHVScrolledWindow() : wxHVScrolledWindow() {}
524
525 wxPyHVScrolledWindow(wxWindow *parent,
526 wxWindowID id = wxID_ANY,
527 const wxPoint& pos = wxDefaultPosition,
528 const wxSize& size = wxDefaultSize,
529 long style = 0,
530 const wxString& name = wxPyPanelNameStr)
531 : wxHVScrolledWindow(parent, id, pos, size, style, name)
532 {}
533
534 // Overridable virtuals
535 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetRowHeight);
536 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetRowsHeightHint);
537 DEC_PYCALLBACK_COORD_const(EstimateTotalHeight);
538
539 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetColumnWidth);
540 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetColumnsWidthHint);
541 DEC_PYCALLBACK_COORD_const(EstimateTotalWidth);
542
543 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const
544 { return wxHVScrolledWindow::GetRowsHeight(lineMin, lineMax); }
545
546 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const
547 { return wxHVScrolledWindow::GetColumnsWidth(columnMin, columnMax); }
548
549 PYPRIVATE;
550 };
551
552 IMPLEMENT_ABSTRACT_CLASS(wxPyHVScrolledWindow, wxHVScrolledWindow);
553
554 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetRowHeight);
555 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetRowsHeightHint);
556 IMP_PYCALLBACK_COORD_const (wxPyHVScrolledWindow, wxHVScrolledWindow, EstimateTotalHeight);
557
558 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetColumnWidth);
559 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetColumnsWidthHint);
560 IMP_PYCALLBACK_COORD_const (wxPyHVScrolledWindow, wxHVScrolledWindow, EstimateTotalWidth);
561
562 %}
563
564
565
566
567 // Now define this class for SWIG
568
569 // This window inherits all functionality of both vertical and horizontal
570 // scrolled windows automatically handling everything needed to scroll both
571 // axis simultaneously.
572
573 MustHaveApp(wxPyHVScrolledWindow);
574
575 %rename(HVScrolledWindow) wxPyHVScrolledWindow;
576
577 class wxPyHVScrolledWindow : public wxPanel,
578 public wxVarHVScrollHelper
579 {
580 public:
581 %pythonAppend wxPyHVScrolledWindow "self._setOORInfo(self);" setCallbackInfo(HVScrolledWindow)
582 %pythonAppend wxPyHVScrolledWindow() ""
583
584
585 wxPyHVScrolledWindow(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 = wxPyPanelNameStr);
591
592 %RenameCtor(PreHVScrolledWindow, wxPyHVScrolledWindow());
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 = wxPyPanelNameStr);
602
603
604 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const;
605 wxCoord EstimateTotalHeight() const;
606
607 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const;
608 wxCoord EstimateTotalWidth() const;
609 };
610
611
612
613 //---------------------------------------------------------------------------
614 //---------------------------------------------------------------------------
615 // wxVListBox
616
617 %{
618 #include <wx/vlbox.h>
619 %}
620
621 MAKE_CONST_WXSTRING(VListBoxNameStr);
622
623
624 // First, the C++ version
625 %{
626 class wxPyVListBox : public wxVListBox
627 {
628 DECLARE_ABSTRACT_CLASS(wxPyVListBox)
629 public:
630 wxPyVListBox() : wxVListBox() {}
631
632 wxPyVListBox(wxWindow *parent,
633 wxWindowID id = wxID_ANY,
634 const wxPoint& pos = wxDefaultPosition,
635 const wxSize& size = wxDefaultSize,
636 long style = 0,
637 const wxString& name = wxPyVListBoxNameStr)
638 : wxVListBox(parent, id, pos, size, style, name)
639 {}
640
641 // Overridable virtuals
642
643 // the derived class must implement this function to actually draw the item
644 // with the given index on the provided DC
645 // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
646 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem);
647
648
649 // the derived class must implement this method to return the height of the
650 // specified item
651 // virtual wxCoord OnMeasureItem(size_t n) const = 0;
652 DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem);
653
654
655 // this method may be used to draw separators between the lines; note that
656 // the rectangle may be modified, typically to deflate it a bit before
657 // passing to OnDrawItem()
658 //
659 // the base class version doesn't do anything
660 // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
661 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
662
663
664 // this method is used to draw the items background and, maybe, a border
665 // around it
666 //
667 // the base class version implements a reasonable default behaviour which
668 // consists in drawing the selected item with the standard background
669 // colour and drawing a border around the item if it is either selected or
670 // current
671 // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
672 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
673
674
675 PYPRIVATE;
676 };
677
678 IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox);
679
680 IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem);
681 IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem);
682 IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyVListBox, wxVListBox, OnDrawSeparator);
683 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground);
684
685 %}
686
687
688
689 // Now define this class for SWIG
690
691 /*
692 This class has two main differences from a regular listbox: it can have an
693 arbitrarily huge number of items because it doesn't store them itself but
694 uses OnDrawItem() callback to draw them and its items can have variable
695 height as determined by OnMeasureItem().
696
697 It emits the same events as wxListBox and the same event macros may be used
698 with it.
699 */
700 MustHaveApp(wxPyVListBox);
701
702 %rename(VListBox) wxPyVListBox;
703 class wxPyVListBox : public wxPyVScrolledWindow
704 {
705 public:
706 %pythonAppend wxPyVListBox "self._setOORInfo(self);" setCallbackInfo(VListBox)
707 %pythonAppend wxPyVListBox() ""
708
709
710 wxPyVListBox(wxWindow *parent,
711 wxWindowID id = wxID_ANY,
712 const wxPoint& pos = wxDefaultPosition,
713 const wxSize& size = wxDefaultSize,
714 long style = 0,
715 const wxString& name = wxPyVListBoxNameStr);
716
717 %RenameCtor(PreVListBox, wxPyVListBox());
718
719 void _setCallbackInfo(PyObject* self, PyObject* _class);
720
721 bool Create(wxWindow *parent,
722 wxWindowID id = wxID_ANY,
723 const wxPoint& pos = wxDefaultPosition,
724 const wxSize& size = wxDefaultSize,
725 long style = 0,
726 const wxString& name = wxPyVListBoxNameStr);
727
728 // get the number of items in the control
729 size_t GetItemCount() const;
730
731 // does this control use multiple selection?
732 bool HasMultipleSelection() const;
733
734 // get the currently selected item or wxNOT_FOUND if there is no selection
735 //
736 // this method is only valid for the single selection listboxes
737 int GetSelection() const;
738
739 // is this item the current one?
740 bool IsCurrent(size_t item) const;
741
742 // is this item selected?
743 bool IsSelected(size_t item) const;
744
745 // get the number of the selected items (maybe 0)
746 //
747 // this method is valid for both single and multi selection listboxes
748 size_t GetSelectedCount() const;
749
750 %extend {
751 // get the first selected item, returns wxNOT_FOUND if none
752 //
753 // cookie is an opaque parameter which should be passed to
754 // GetNextSelected() later
755 //
756 // this method is only valid for the multi selection listboxes
757 //int GetFirstSelected(unsigned long& cookie) const;
758 PyObject* GetFirstSelected() {
759 unsigned long cookie = 0;
760 int selected = self->GetFirstSelected(cookie);
761 wxPyBlock_t blocked = wxPyBeginBlockThreads();
762 PyObject* tup = PyTuple_New(2);
763 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
764 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
765 wxPyEndBlockThreads(blocked);
766 return tup;
767 }
768
769 // get next selection item, return wxNOT_FOUND if no more
770 //
771 // cookie must be the same parameter that was passed to GetFirstSelected()
772 // before
773 //
774 // this method is only valid for the multi selection listboxes
775 // int GetNextSelected(unsigned long& cookie) const;
776 PyObject* GetNextSelected(unsigned long cookie) {
777 int selected = self->GetNextSelected(cookie);
778 wxPyBlock_t blocked = wxPyBeginBlockThreads();
779 PyObject* tup = PyTuple_New(2);
780 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
781 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
782 wxPyEndBlockThreads(blocked);
783 return tup;
784 }
785 }
786
787
788 // get the margins around each item
789 wxPoint GetMargins() const;
790
791 // get the background colour of selected cells
792 const wxColour& GetSelectionBackground() const;
793
794
795 // set the number of items to be shown in the control
796 //
797 // this is just a synonym for wxVScrolledWindow::SetLineCount()
798 void SetItemCount(size_t count);
799
800 // delete all items from the control
801 void Clear();
802
803 // set the selection to the specified item, if it is wxNOT_FOUND the
804 // selection is unset
805 //
806 // this function is only valid for the single selection listboxes
807 void SetSelection(int selection);
808
809 // selects or deselects the specified item which must be valid (i.e. not
810 // equal to wxNOT_FOUND)
811 //
812 // return True if the items selection status has changed or False
813 // otherwise
814 //
815 // this function is only valid for the multiple selection listboxes
816 bool Select(size_t item, bool select = true);
817
818 // selects the items in the specified range whose end points may be given
819 // in any order
820 //
821 // return True if any items selection status has changed, False otherwise
822 //
823 // this function is only valid for the single selection listboxes
824 bool SelectRange(size_t from, size_t to);
825
826 // toggle the selection of the specified item (must be valid)
827 //
828 // this function is only valid for the multiple selection listboxes
829 void Toggle(size_t item);
830
831 // select all items in the listbox
832 //
833 // the return code indicates if any items were affected by this operation
834 // (True) or if nothing has changed (False)
835 bool SelectAll();
836
837 // unselect all items in the listbox
838 //
839 // the return code has the same meaning as for SelectAll()
840 bool DeselectAll();
841
842 // set the margins: horizontal margin is the distance between the window
843 // border and the item contents while vertical margin is half of the
844 // distance between items
845 //
846 // by default both margins are 0
847 void SetMargins(const wxPoint& pt);
848 %Rename(SetMarginsXY, void, SetMargins(wxCoord x, wxCoord y));
849
850 // change the background colour of the selected cells
851 void SetSelectionBackground(const wxColour& col);
852
853 // refreshes only the selected items
854 void RefreshSelected();
855
856 virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
857 virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
858
859 %property(FirstSelected, GetFirstSelected, doc="See `GetFirstSelected`");
860 %property(ItemCount, GetItemCount, SetItemCount, doc="See `GetItemCount` and `SetItemCount`");
861 %property(Margins, GetMargins, SetMargins, doc="See `GetMargins` and `SetMargins`");
862 %property(SelectedCount, GetSelectedCount, doc="See `GetSelectedCount`");
863 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
864 %property(SelectionBackground, GetSelectionBackground, SetSelectionBackground, doc="See `GetSelectionBackground` and `SetSelectionBackground`");
865 };
866
867
868 //---------------------------------------------------------------------------
869 // wxHtmlListBox
870
871 %{
872 #include <wx/htmllbox.h>
873 %}
874
875 // First, the C++ version
876 %{
877 class wxPyHtmlListBox : public wxHtmlListBox
878 {
879 DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox)
880 public:
881 wxPyHtmlListBox() : wxHtmlListBox() {}
882
883 wxPyHtmlListBox(wxWindow *parent,
884 wxWindowID id = wxID_ANY,
885 const wxPoint& pos = wxDefaultPosition,
886 const wxSize& size = wxDefaultSize,
887 long style = 0,
888 const wxString& name = wxPyVListBoxNameStr)
889 : wxHtmlListBox(parent, id, pos, size, style, name)
890 {}
891
892 // Overridable virtuals
893
894 // this method must be implemented in the derived class and should return
895 // the body (i.e. without <html>) of the HTML for the given item
896 DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem);
897
898 // this function may be overridden to decorate HTML returned by OnGetItem()
899 DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup);
900
901 // These are from wxVListBox
902 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
903 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
904
905 // TODO:
906 // // this method allows to customize the selection appearance: it may be used
907 // // to specify the colour of the text which normally has the given colour
908 // // colFg when it is inside the selection
909 // //
910 // // by default, the original colour is not used at all and all text has the
911 // // same (default for this system) colour inside selection
912 // virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
913
914 // // this is the same as GetSelectedTextColour() but allows to customize the
915 // // background colour -- this is even more rarely used as you can change it
916 // // globally using SetSelectionBackground()
917 // virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
918
919
920 // This method may be overriden to handle clicking on a link in
921 // the listbox. By default, clicking links is ignored.
922 virtual void OnLinkClicked(size_t n,
923 const wxHtmlLinkInfo& link);
924
925 PYPRIVATE;
926 };
927
928
929 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox)
930
931 IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem);
932 IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup);
933 IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawSeparator);
934 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawBackground);
935
936
937 void wxPyHtmlListBox::OnLinkClicked(size_t n,
938 const wxHtmlLinkInfo& link) {
939 bool found;
940 wxPyBlock_t blocked = wxPyBeginBlockThreads();
941 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
942 PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0);
943 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", n, obj));
944 Py_DECREF(obj);
945 }
946 wxPyEndBlockThreads(blocked);
947 if (! found)
948 wxPyHtmlListBox::OnLinkClicked(n, link);
949 }
950
951 %}
952
953
954
955 // Now define this class for SWIG
956
957
958 // wxHtmlListBox is a listbox whose items are wxHtmlCells
959 MustHaveApp(wxPyHtmlListBox);
960 %rename(HtmlListBox) wxPyHtmlListBox;
961 class wxPyHtmlListBox : public wxPyVListBox
962 {
963 public:
964 %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);" setCallbackInfo(HtmlListBox)
965 %pythonAppend wxPyHtmlListBox() ""
966
967
968 // normal constructor which calls Create() internally
969 wxPyHtmlListBox(wxWindow *parent,
970 wxWindowID id = wxID_ANY,
971 const wxPoint& pos = wxDefaultPosition,
972 const wxSize& size = wxDefaultSize,
973 long style = 0,
974 const wxString& name = wxPyVListBoxNameStr);
975
976 %RenameCtor(PreHtmlListBox, wxPyHtmlListBox());
977
978 void _setCallbackInfo(PyObject* self, PyObject* _class);
979
980 bool Create(wxWindow *parent,
981 wxWindowID id = wxID_ANY,
982 const wxPoint& pos = wxDefaultPosition,
983 const wxSize& size = wxDefaultSize,
984 long style = 0,
985 const wxString& name = wxPyVListBoxNameStr);
986
987
988 void RefreshAll();
989 void SetItemCount(size_t count);
990
991 // retrieve the file system used by the wxHtmlWinParser: if you use
992 // relative paths in your HTML, you should use its ChangePathTo() method
993 wxFileSystem& GetFileSystem();
994
995 void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link);
996
997 %property(FileSystem, GetFileSystem, doc="See `GetFileSystem`");
998 };
999
1000
1001
1002 //---------------------------------------------------------------------------
1003
1004 %{
1005 const wxArrayString wxPyEmptyStringArray;
1006 %}
1007 MAKE_CONST_WXSTRING(SimpleHtmlListBoxNameStr);
1008
1009
1010 enum {
1011 wxHLB_DEFAULT_STYLE,
1012 wxHLB_MULTIPLE
1013 };
1014
1015 MustHaveApp(wxSimpleHtmlListBox);
1016
1017 class wxSimpleHtmlListBox : public wxPyHtmlListBox,
1018 public wxItemContainer
1019 {
1020 public:
1021 %pythonAppend wxSimpleHtmlListBox "self._setOORInfo(self)";
1022 %pythonAppend wxSimpleHtmlListBox() "";
1023
1024 wxSimpleHtmlListBox(wxWindow *parent,
1025 wxWindowID id = -1,
1026 const wxPoint& pos = wxDefaultPosition,
1027 const wxSize& size = wxDefaultSize,
1028 const wxArrayString& choices = wxPyEmptyStringArray,
1029 long style = wxHLB_DEFAULT_STYLE,
1030 const wxValidator& validator = wxDefaultValidator,
1031 const wxString& name = wxPySimpleHtmlListBoxNameStr);
1032 %RenameCtor(PreSimpleHtmlListBox, wxSimpleHtmlListBox());
1033
1034 bool Create(wxWindow *parent,
1035 wxWindowID id = -1,
1036 const wxPoint& pos = wxDefaultPosition,
1037 const wxSize& size= wxDefaultSize,
1038 const wxArrayString& choices = wxPyEmptyStringArray,
1039 long style = wxHLB_DEFAULT_STYLE,
1040 const wxValidator& validator = wxDefaultValidator,
1041 const wxString& name = wxPySimpleHtmlListBoxNameStr);
1042 };
1043
1044 //---------------------------------------------------------------------------
1045
1046 %init %{
1047 // Map renamed classes back to their common name for OOR
1048 wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox");
1049 wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox");
1050 wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow");
1051 %}
1052
1053 //---------------------------------------------------------------------------