1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface defs for wxVScrolledWindow, wxVListBox, and
8 // Created: 14-Aug-2003
10 // Copyright: (c) 2003 by Total Control Software
11 // Licence: wxWindows license
12 /////////////////////////////////////////////////////////////////////////////
17 //---------------------------------------------------------------------------
20 #include <wx/tipwin.h>
21 #include <wx/vscroll.h>
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.
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
38 class wxVarScrollHelperBase
42 // wxVarScrollHelperBase(wxWindow *winToScroll); *** ABC, can't instantiate
43 // virtual ~wxVarScrollHelperBase();
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);
51 // wxNOT_FOUND if none, i.e. if it is below the last item
52 virtual int HitTest(wxCoord coord) const;
54 // recalculate all our parameters and redisplay all units
55 virtual void RefreshAll();
58 // get the first currently visible unit
59 size_t GetVisibleBegin() const;
61 // get the last currently visible unit
62 size_t GetVisibleEnd() const;
64 // is this unit currently visible?
65 bool IsVisible(size_t unit) const;
67 // translate between scrolled and unscrolled coordinates
68 int CalcScrolledPosition(int coord) const;
69 int CalcUnscrolledPosition(int coord) const;
71 // update the thumb size shown by the scrollbar
72 virtual void UpdateScrollbar();
73 void RemoveScrollbar();
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;
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;
95 // Provides public API functions targeted for vertical-specific scrolling,
96 // wrapping the functionality of wxVarScrollHelperBase.
98 class wxVarVScrollHelper : public wxVarScrollHelperBase
102 // wxVarVScrollHelper(wxWindow *winToScroll); *** ABC, can't instantiate
104 void SetRowCount(size_t rowCount);
105 bool ScrollToRow(size_t row);
107 virtual bool ScrollRows(int rows);
108 virtual bool ScrollRowPages(int pages);
110 virtual void RefreshRow(size_t row);
111 virtual void RefreshRows(size_t from, size_t to);
113 virtual int HitTest(wxCoord y) const;
116 size_t GetRowCount() const;
117 size_t GetVisibleRowsBegin() const;
118 size_t GetVisibleRowsEnd() const;
119 bool IsRowVisible(size_t row) const;
121 virtual int GetOrientationTargetSize() const;
122 virtual int GetNonOrientationTargetSize() const;
123 virtual wxOrientation GetOrientation() const;
130 // Provides public API functions targeted for horizontal-specific scrolling,
131 // wrapping the functionality of wxVarScrollHelperBase.
133 class wxVarHScrollHelper : public wxVarScrollHelperBase
137 // wxVarHScrollHelper(wxWindow *winToScroll) *** ABC, can't instantiate
139 void SetColumnCount(size_t columnCount);
141 bool ScrollToColumn(size_t column);
142 virtual bool ScrollColumns(int columns);
143 virtual bool ScrollColumnPages(int pages);
145 virtual void RefreshColumn(size_t column);
146 virtual void RefreshColumns(size_t from, size_t to);
147 virtual int HitTest(wxCoord x) const;
150 size_t GetColumnCount() const;
151 size_t GetVisibleColumnsBegin() const;
152 size_t GetVisibleColumnsEnd() const;
153 bool IsColumnVisible(size_t column) const;
156 virtual int GetOrientationTargetSize() const;
157 virtual int GetNonOrientationTargetSize() const;
158 virtual wxOrientation GetOrientation() const;
167 // Provides public API functions targeted at functions with similar names in
168 // both wxVScrollHelper and wxHScrollHelper so class scope doesn't need to be
169 // specified (since we are using multiple inheritance). It also provides
170 // functions to make changing values for both orientations at the same time
173 class wxVarHVScrollHelper : public wxVarVScrollHelper,
174 public wxVarHScrollHelper
178 // wxVarHVScrollHelper(wxWindow *winToScroll); *** ABC, can't instantiate
181 // set the number of units the window contains for each axis: the derived
182 // class must provide the widths and heights for all units with indices up
183 // to each of the one given here in its OnGetColumnWidth() and
185 void SetRowColumnCount(size_t rowCount, size_t columnCount);
188 // with physical scrolling on, the device origin is changed properly when
189 // a wxPaintDC is prepared, children are actually moved and laid out
190 // properly, and the contents of the window (pixels) are actually moved
191 void EnablePhysicalScrolling(bool vscrolling = true, bool hscrolling = true);
194 // scroll to the specified row/column: it will become the first visible
195 // cell in the window
197 // return true if we scrolled the window, false if nothing was done
198 // bool ScrollToRowColumn(size_t row, size_t column);
199 bool ScrollToRowColumn(const wxPosition &pos);
201 // redraw the specified cell
202 // virtual void RefreshRowColumn(size_t row, size_t column);
203 virtual void RefreshRowColumn(const wxPosition &pos);
205 // redraw the specified regions (inclusive). If the target window for
206 // both orientations is the same the rectangle of cells is refreshed; if
207 // the target windows differ the entire client size opposite the
208 // orientation direction is refreshed between the specified limits
209 // virtual void RefreshRowsColumns(size_t fromRow, size_t toRow,
210 // size_t fromColumn, size_t toColumn);
211 virtual void RefreshRowsColumns(const wxPosition& from,
212 const wxPosition& to);
214 // Override wxPanel::HitTest to use our version
215 // virtual wxPosition HitTest(wxCoord x, wxCoord y) const;
216 virtual wxPosition HitTest(const wxPoint &pos) const;
218 // replacement implementation of wxWindow::Layout virtual method. To
219 // properly forward calls to wxWindow::Layout use
220 // WX_FORWARD_TO_SCROLL_HELPER() derived class. We use this version to
221 // call both base classes' ScrollLayout()
224 // get the number of units this window contains (previously set by
225 // Set[Column/Row/RowColumn/Unit]Count())
226 wxSize GetRowColumnCount() const;
228 // get the first currently visible units
229 wxPosition GetVisibleBegin() const;
230 wxPosition GetVisibleEnd() const;
232 // is this cell currently visible?
233 // bool IsVisible(size_t row, size_t column) const;
234 bool IsVisible(const wxPosition &pos) const;
240 //---------------------------------------------------------------------------
245 // First, the C++ version that can redirect to overridden Python methods
247 class wxPyVScrolledWindow : public wxVScrolledWindow
249 DECLARE_ABSTRACT_CLASS(wxPyVScrolledWindow)
251 wxPyVScrolledWindow() : wxVScrolledWindow() {}
253 wxPyVScrolledWindow(wxWindow *parent,
254 wxWindowID id = wxID_ANY,
255 const wxPoint& pos = wxDefaultPosition,
256 const wxSize& size = wxDefaultSize,
258 const wxString& name = wxPyPanelNameStr)
259 : wxVScrolledWindow(parent, id, pos, size, style, name)
262 // Overridable virtuals
264 // this function must be overridden in the derived class and it should
265 // return the height of the given line in pixels
266 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetRowHeight);
267 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetLineHeight); // old name
269 // this function doesn't have to be overridden but it may be useful to do
270 // it if calculating the lines heights is a relatively expensive operation
271 // as it gives the user code a possibility to calculate several of them at
274 // OnGetLinesHint() is normally called just before OnGetRowHeight() but you
275 // shouldn't rely on the latter being called for all lines in the interval
276 // specified here. It is also possible that OnGetRowHeight() will be
277 // called for the lines outside of this interval, so this is really just a
278 // hint, not a promise.
280 // finally note that lineMin is inclusive, while lineMax is exclusive, as
282 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetRowsHeightHint);
283 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetLinesHint); // old name
285 // when the number of lines changes, we try to estimate the total height
286 // of all lines which is a rather expensive operation in terms of lines
287 // access, so if the user code may estimate the average height
288 // better/faster than we do, it should override this function to implement
291 // this function should return the best guess for the total height it may
293 DEC_PYCALLBACK_COORD_const(EstimateTotalHeight);
296 // Also expose some other interesting protected methods
299 // get the total height of the lines between lineMin (inclusive) and
300 // lineMax (exclusive)
301 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const
302 { return wxVScrolledWindow::GetRowsHeight(lineMin, lineMax); }
308 IMPLEMENT_ABSTRACT_CLASS(wxPyVScrolledWindow, wxVScrolledWindow);
310 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetRowHeight);
311 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLineHeight);
312 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetRowsHeightHint);
313 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLinesHint);
315 IMP_PYCALLBACK_COORD_const (wxPyVScrolledWindow, wxVScrolledWindow, EstimateTotalHeight);
322 // Now define this class for SWIG
325 In the name of this class, "V" may stand for "variable" because it can be
326 used for scrolling lines of variable heights; "virtual" because it is not
327 necessary to know the heights of all lines in advance -- only those which
328 are shown on the screen need to be measured; or, even, "vertical" because
329 this class only supports scrolling in one direction currently (this could
330 and probably will change in the future however).
332 In any case, this is a generalization of the wxScrolledWindow class which
333 can be only used when all lines have the same height. It lacks some other
334 wxScrolledWindow features however, notably it currently lacks support for
335 horizontal scrolling; it can't scroll another window nor only a rectangle
336 of the window and not its entire client area.
339 MustHaveApp(wxPyVScrolledWindow);
341 %rename(VScrolledWindow) wxPyVScrolledWindow;
343 class wxPyVScrolledWindow : public wxPanel,
344 public wxVarVScrollHelper
347 %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self);" setCallbackInfo(VScrolledWindow)
348 %pythonAppend wxPyVScrolledWindow() ""
351 wxPyVScrolledWindow(wxWindow *parent,
352 wxWindowID id = wxID_ANY,
353 const wxPoint& pos = wxDefaultPosition,
354 const wxSize& size = wxDefaultSize,
356 const wxString& name = wxPyPanelNameStr);
358 %RenameCtor(PreVScrolledWindow, wxPyVScrolledWindow());
360 void _setCallbackInfo(PyObject* self, PyObject* _class);
362 bool Create(wxWindow *parent,
363 wxWindowID id = wxID_ANY,
364 const wxPoint& pos = wxDefaultPosition,
365 const wxSize& size = wxDefaultSize,
367 const wxString& name = wxPyPanelNameStr);
370 // get the total height of the lines between lineMin (inclusive) and
371 // lineMax (exclusive)
372 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const;
373 %pythoncode { GetLinesHeight = wx._deprecated(GetRowsHeight,
374 "Use GetRowsHeight instead.") }
376 virtual wxCoord EstimateTotalHeight() const;
378 int HitTest(const wxPoint& pt) const;
381 // Deprecated wrappers for methods whose name changed when adding the H
382 // classes. I just put them here instead of wrapping the
383 // wxVarVScrollLegacyAdaptor class.
385 def GetFirstVisibleLine(self):
386 return self.GetVisibleRowsBegin()
387 GetFirstVisibleLine = wx._deprecated(GetFirstVisibleLine, "Use GetVisibleRowsBegin instead" )
389 def GetLastVisibleLine(self):
390 return self.GetVisibleRowsEnd() - 1
391 GetLastVisibleLine = wx._deprecated(GetLastVisibleLine, "Use GetVisibleRowsEnd instead")
393 def GetLineCount(self):
394 return self.GetRowCount()
395 GetLineCount = wx._deprecated(GetLineCount, "Use GetRowCount instead")
397 def SetLineCount(self, count):
398 self.SetRowCount(count)
399 SetLineCount = wx._deprecated(SetLineCount, "Use SetRowCount instead")
401 def RefreshLine(self, line):
402 self.RefreshRow(line)
403 RefreshLine = wx._deprecated(RefreshLine, "Use RefreshRow instead")
405 def RefreshLines(self, frm, to):
406 self.RefreshRows(frm, to)
407 RefreshLines = wx._deprecated(RefreshLines, "Use RefreshRows instead")
409 def ScrollToLine(self, line):
410 return self.ScrollToRow(line)
411 ScrollToLine = wx._deprecated(ScrollToLine, "Use RefreshRow instead")
413 def ScrollLines(self, lines):
414 return self.ScrollRows(lines)
415 ScrollLines = wx._deprecated(ScrollLines, "Use ScrollRows instead")
417 def ScrollPages(self, pages):
418 return self.ScrollRowPages(pages)
419 ScrollPages = wx._deprecated(ScrollPages, "Use ScrollRowPages instead")
426 //---------------------------------------------------------------------------
430 // First, the C++ version that can redirect to overridden Python methods
432 class wxPyHScrolledWindow : public wxHScrolledWindow
434 DECLARE_ABSTRACT_CLASS(wxPyHScrolledWindow)
436 wxPyHScrolledWindow() : wxHScrolledWindow() {}
438 wxPyHScrolledWindow(wxWindow *parent,
439 wxWindowID id = wxID_ANY,
440 const wxPoint& pos = wxDefaultPosition,
441 const wxSize& size = wxDefaultSize,
443 const wxString& name = wxPyPanelNameStr)
444 : wxHScrolledWindow(parent, id, pos, size, style, name)
447 // Overridable virtuals
448 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetColumnWidth);
449 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetColumnsWidthHint);
450 DEC_PYCALLBACK_COORD_const(EstimateTotalWidth);
452 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const
453 { return wxHScrolledWindow::GetColumnsWidth(columnMin, columnMax); }
458 IMPLEMENT_ABSTRACT_CLASS(wxPyHScrolledWindow, wxHScrolledWindow);
460 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyHScrolledWindow, wxHScrolledWindow, OnGetColumnWidth);
461 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyHScrolledWindow, wxHScrolledWindow, OnGetColumnsWidthHint);
462 IMP_PYCALLBACK_COORD_const (wxPyHScrolledWindow, wxHScrolledWindow, EstimateTotalWidth);
468 // Now define this class for SWIG
470 // In the name of this class, "H" stands for "horizontal" because it can be
471 // used for scrolling columns of variable widths. It is not necessary to know
472 // the widths of all columns in advance -- only those which are shown on the
473 // screen need to be measured.
475 // This is a generalization of the wxScrolledWindow class which can be only
476 // used when all columns have the same width. It lacks some other
477 // wxScrolledWindow features however, notably it can't scroll only a rectangle
478 // of the window and not its entire client area.
480 MustHaveApp(wxPyHScrolledWindow);
482 %rename(HScrolledWindow) wxPyHScrolledWindow;
484 class wxPyHScrolledWindow : public wxPanel,
485 public wxVarHScrollHelper
488 %pythonAppend wxPyHScrolledWindow "self._setOORInfo(self);" setCallbackInfo(HScrolledWindow)
489 %pythonAppend wxPyHScrolledWindow() ""
492 wxPyHScrolledWindow(wxWindow *parent,
493 wxWindowID id = wxID_ANY,
494 const wxPoint& pos = wxDefaultPosition,
495 const wxSize& size = wxDefaultSize,
497 const wxString& name = wxPyPanelNameStr);
499 %RenameCtor(PreHScrolledWindow, wxPyHScrolledWindow());
501 void _setCallbackInfo(PyObject* self, PyObject* _class);
503 bool Create(wxWindow *parent,
504 wxWindowID id = wxID_ANY,
505 const wxPoint& pos = wxDefaultPosition,
506 const wxSize& size = wxDefaultSize,
508 const wxString& name = wxPyPanelNameStr);
511 int HitTest(const wxPoint& pt) const;
512 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const;
513 wxCoord EstimateTotalWidth() const;
518 //---------------------------------------------------------------------------
519 // wxHVScrolledWindow
523 // First, the C++ version that can redirect to overridden Python methods
525 class wxPyHVScrolledWindow : public wxHVScrolledWindow
527 DECLARE_ABSTRACT_CLASS(wxPyHScrolledWindow)
529 wxPyHVScrolledWindow() : wxHVScrolledWindow() {}
531 wxPyHVScrolledWindow(wxWindow *parent,
532 wxWindowID id = wxID_ANY,
533 const wxPoint& pos = wxDefaultPosition,
534 const wxSize& size = wxDefaultSize,
536 const wxString& name = wxPyPanelNameStr)
537 : wxHVScrolledWindow(parent, id, pos, size, style, name)
540 // Overridable virtuals
541 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetRowHeight);
542 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetRowsHeightHint);
543 DEC_PYCALLBACK_COORD_const(EstimateTotalHeight);
545 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetColumnWidth);
546 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetColumnsWidthHint);
547 DEC_PYCALLBACK_COORD_const(EstimateTotalWidth);
549 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const
550 { return wxHVScrolledWindow::GetRowsHeight(lineMin, lineMax); }
552 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const
553 { return wxHVScrolledWindow::GetColumnsWidth(columnMin, columnMax); }
558 IMPLEMENT_ABSTRACT_CLASS(wxPyHVScrolledWindow, wxHVScrolledWindow);
560 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetRowHeight);
561 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetRowsHeightHint);
562 IMP_PYCALLBACK_COORD_const (wxPyHVScrolledWindow, wxHVScrolledWindow, EstimateTotalHeight);
564 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetColumnWidth);
565 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyHVScrolledWindow, wxHVScrolledWindow, OnGetColumnsWidthHint);
566 IMP_PYCALLBACK_COORD_const (wxPyHVScrolledWindow, wxHVScrolledWindow, EstimateTotalWidth);
573 // Now define this class for SWIG
575 // This window inherits all functionality of both vertical and horizontal
576 // scrolled windows automatically handling everything needed to scroll both
577 // axis simultaneously.
579 MustHaveApp(wxPyHVScrolledWindow);
581 %rename(HVScrolledWindow) wxPyHVScrolledWindow;
583 class wxPyHVScrolledWindow : public wxPanel,
584 public wxVarHVScrollHelper
587 %pythonAppend wxPyHVScrolledWindow "self._setOORInfo(self);" setCallbackInfo(HVScrolledWindow)
588 %pythonAppend wxPyHVScrolledWindow() ""
591 wxPyHVScrolledWindow(wxWindow *parent,
592 wxWindowID id = wxID_ANY,
593 const wxPoint& pos = wxDefaultPosition,
594 const wxSize& size = wxDefaultSize,
596 const wxString& name = wxPyPanelNameStr);
598 %RenameCtor(PreHVScrolledWindow, wxPyHVScrolledWindow());
600 void _setCallbackInfo(PyObject* self, PyObject* _class);
602 bool Create(wxWindow *parent,
603 wxWindowID id = wxID_ANY,
604 const wxPoint& pos = wxDefaultPosition,
605 const wxSize& size = wxDefaultSize,
607 const wxString& name = wxPyPanelNameStr);
610 wxPosition HitTest(const wxPoint& pt) const;
612 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const;
613 wxCoord EstimateTotalHeight() const;
615 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const;
616 wxCoord EstimateTotalWidth() const;
621 //---------------------------------------------------------------------------
622 //---------------------------------------------------------------------------
626 #include <wx/vlbox.h>
629 MAKE_CONST_WXSTRING(VListBoxNameStr);
632 // First, the C++ version
634 class wxPyVListBox : public wxVListBox
636 DECLARE_ABSTRACT_CLASS(wxPyVListBox)
638 wxPyVListBox() : wxVListBox() {}
640 wxPyVListBox(wxWindow *parent,
641 wxWindowID id = wxID_ANY,
642 const wxPoint& pos = wxDefaultPosition,
643 const wxSize& size = wxDefaultSize,
645 const wxString& name = wxPyVListBoxNameStr)
646 : wxVListBox(parent, id, pos, size, style, name)
649 // Overridable virtuals
651 // the derived class must implement this function to actually draw the item
652 // with the given index on the provided DC
653 // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
654 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem);
657 // the derived class must implement this method to return the height of the
659 // virtual wxCoord OnMeasureItem(size_t n) const = 0;
660 DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem);
663 // this method may be used to draw separators between the lines; note that
664 // the rectangle may be modified, typically to deflate it a bit before
665 // passing to OnDrawItem()
667 // the base class version doesn't do anything
668 // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
669 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
672 // this method is used to draw the items background and, maybe, a border
675 // the base class version implements a reasonable default behaviour which
676 // consists in drawing the selected item with the standard background
677 // colour and drawing a border around the item if it is either selected or
679 // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
680 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
686 IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox);
688 IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem);
689 IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem);
690 IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyVListBox, wxVListBox, OnDrawSeparator);
691 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground);
697 // Now define this class for SWIG
700 This class has two main differences from a regular listbox: it can have an
701 arbitrarily huge number of items because it doesn't store them itself but
702 uses OnDrawItem() callback to draw them and its items can have variable
703 height as determined by OnMeasureItem().
705 It emits the same events as wxListBox and the same event macros may be used
708 MustHaveApp(wxPyVListBox);
710 %rename(VListBox) wxPyVListBox;
711 class wxPyVListBox : public wxPyVScrolledWindow
714 %pythonAppend wxPyVListBox "self._setOORInfo(self);" setCallbackInfo(VListBox)
715 %pythonAppend wxPyVListBox() ""
718 wxPyVListBox(wxWindow *parent,
719 wxWindowID id = wxID_ANY,
720 const wxPoint& pos = wxDefaultPosition,
721 const wxSize& size = wxDefaultSize,
723 const wxString& name = wxPyVListBoxNameStr);
725 %RenameCtor(PreVListBox, wxPyVListBox());
727 void _setCallbackInfo(PyObject* self, PyObject* _class);
729 bool Create(wxWindow *parent,
730 wxWindowID id = wxID_ANY,
731 const wxPoint& pos = wxDefaultPosition,
732 const wxSize& size = wxDefaultSize,
734 const wxString& name = wxPyVListBoxNameStr);
736 // get the number of items in the control
737 size_t GetItemCount() const;
739 // does this control use multiple selection?
740 bool HasMultipleSelection() const;
742 // get the currently selected item or wxNOT_FOUND if there is no selection
744 // this method is only valid for the single selection listboxes
745 int GetSelection() const;
747 // is this item the current one?
748 bool IsCurrent(size_t item) const;
750 // is this item selected?
751 bool IsSelected(size_t item) const;
753 // get the number of the selected items (maybe 0)
755 // this method is valid for both single and multi selection listboxes
756 size_t GetSelectedCount() const;
759 // get the first selected item, returns wxNOT_FOUND if none
761 // cookie is an opaque parameter which should be passed to
762 // GetNextSelected() later
764 // this method is only valid for the multi selection listboxes
765 //int GetFirstSelected(unsigned long& cookie) const;
766 PyObject* GetFirstSelected() {
767 unsigned long cookie = 0;
768 int selected = self->GetFirstSelected(cookie);
769 wxPyBlock_t blocked = wxPyBeginBlockThreads();
770 PyObject* tup = PyTuple_New(2);
771 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
772 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
773 wxPyEndBlockThreads(blocked);
777 // get next selection item, return wxNOT_FOUND if no more
779 // cookie must be the same parameter that was passed to GetFirstSelected()
782 // this method is only valid for the multi selection listboxes
783 // int GetNextSelected(unsigned long& cookie) const;
784 PyObject* GetNextSelected(unsigned long cookie) {
785 int selected = self->GetNextSelected(cookie);
786 wxPyBlock_t blocked = wxPyBeginBlockThreads();
787 PyObject* tup = PyTuple_New(2);
788 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
789 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
790 wxPyEndBlockThreads(blocked);
796 // get the margins around each item
797 wxPoint GetMargins() const;
799 // get the background colour of selected cells
800 const wxColour& GetSelectionBackground() const;
803 // set the number of items to be shown in the control
805 // this is just a synonym for wxVScrolledWindow::SetLineCount()
806 void SetItemCount(size_t count);
808 // delete all items from the control
811 // set the selection to the specified item, if it is wxNOT_FOUND the
812 // selection is unset
814 // this function is only valid for the single selection listboxes
815 void SetSelection(int selection);
817 // selects or deselects the specified item which must be valid (i.e. not
818 // equal to wxNOT_FOUND)
820 // return True if the items selection status has changed or False
823 // this function is only valid for the multiple selection listboxes
824 bool Select(size_t item, bool select = true);
826 // selects the items in the specified range whose end points may be given
829 // return True if any items selection status has changed, False otherwise
831 // this function is only valid for the single selection listboxes
832 bool SelectRange(size_t from, size_t to);
834 // toggle the selection of the specified item (must be valid)
836 // this function is only valid for the multiple selection listboxes
837 void Toggle(size_t item);
839 // select all items in the listbox
841 // the return code indicates if any items were affected by this operation
842 // (True) or if nothing has changed (False)
845 // unselect all items in the listbox
847 // the return code has the same meaning as for SelectAll()
850 // set the margins: horizontal margin is the distance between the window
851 // border and the item contents while vertical margin is half of the
852 // distance between items
854 // by default both margins are 0
855 void SetMargins(const wxPoint& pt);
856 %Rename(SetMarginsXY, void, SetMargins(wxCoord x, wxCoord y));
858 // change the background colour of the selected cells
859 void SetSelectionBackground(const wxColour& col);
861 // refreshes only the selected items
862 void RefreshSelected();
864 virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
865 virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
867 %property(FirstSelected, GetFirstSelected, doc="See `GetFirstSelected`");
868 %property(ItemCount, GetItemCount, SetItemCount, doc="See `GetItemCount` and `SetItemCount`");
869 %property(Margins, GetMargins, SetMargins, doc="See `GetMargins` and `SetMargins`");
870 %property(SelectedCount, GetSelectedCount, doc="See `GetSelectedCount`");
871 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
872 %property(SelectionBackground, GetSelectionBackground, SetSelectionBackground, doc="See `GetSelectionBackground` and `SetSelectionBackground`");
876 //---------------------------------------------------------------------------
880 #include <wx/htmllbox.h>
883 // First, the C++ version
885 class wxPyHtmlListBox : public wxHtmlListBox
887 DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox)
889 wxPyHtmlListBox() : wxHtmlListBox() {}
891 wxPyHtmlListBox(wxWindow *parent,
892 wxWindowID id = wxID_ANY,
893 const wxPoint& pos = wxDefaultPosition,
894 const wxSize& size = wxDefaultSize,
896 const wxString& name = wxPyVListBoxNameStr)
897 : wxHtmlListBox(parent, id, pos, size, style, name)
900 // Overridable virtuals
902 // this method must be implemented in the derived class and should return
903 // the body (i.e. without <html>) of the HTML for the given item
904 DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem);
906 // this function may be overridden to decorate HTML returned by OnGetItem()
907 DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup);
909 // These are from wxVListBox
910 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
911 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
914 // // this method allows to customize the selection appearance: it may be used
915 // // to specify the colour of the text which normally has the given colour
916 // // colFg when it is inside the selection
918 // // by default, the original colour is not used at all and all text has the
919 // // same (default for this system) colour inside selection
920 // virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
922 // // this is the same as GetSelectedTextColour() but allows to customize the
923 // // background colour -- this is even more rarely used as you can change it
924 // // globally using SetSelectionBackground()
925 // virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
928 // This method may be overriden to handle clicking on a link in
929 // the listbox. By default, clicking links is ignored.
930 virtual void OnLinkClicked(size_t n,
931 const wxHtmlLinkInfo& link);
937 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox)
939 IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem);
940 IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup);
941 IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawSeparator);
942 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawBackground);
945 void wxPyHtmlListBox::OnLinkClicked(size_t n,
946 const wxHtmlLinkInfo& link) {
948 wxPyBlock_t blocked = wxPyBeginBlockThreads();
949 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
950 PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0);
951 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", n, obj));
954 wxPyEndBlockThreads(blocked);
956 wxPyHtmlListBox::OnLinkClicked(n, link);
963 // Now define this class for SWIG
966 // wxHtmlListBox is a listbox whose items are wxHtmlCells
967 MustHaveApp(wxPyHtmlListBox);
968 %rename(HtmlListBox) wxPyHtmlListBox;
969 class wxPyHtmlListBox : public wxPyVListBox
972 %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);" setCallbackInfo(HtmlListBox)
973 %pythonAppend wxPyHtmlListBox() ""
976 // normal constructor which calls Create() internally
977 wxPyHtmlListBox(wxWindow *parent,
978 wxWindowID id = wxID_ANY,
979 const wxPoint& pos = wxDefaultPosition,
980 const wxSize& size = wxDefaultSize,
982 const wxString& name = wxPyVListBoxNameStr);
984 %RenameCtor(PreHtmlListBox, wxPyHtmlListBox());
986 void _setCallbackInfo(PyObject* self, PyObject* _class);
988 bool Create(wxWindow *parent,
989 wxWindowID id = wxID_ANY,
990 const wxPoint& pos = wxDefaultPosition,
991 const wxSize& size = wxDefaultSize,
993 const wxString& name = wxPyVListBoxNameStr);
997 void SetItemCount(size_t count);
999 // retrieve the file system used by the wxHtmlWinParser: if you use
1000 // relative paths in your HTML, you should use its ChangePathTo() method
1001 wxFileSystem& GetFileSystem();
1003 void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link);
1005 %property(FileSystem, GetFileSystem, doc="See `GetFileSystem`");
1010 //---------------------------------------------------------------------------
1013 const wxArrayString wxPyEmptyStringArray;
1015 MAKE_CONST_WXSTRING(SimpleHtmlListBoxNameStr);
1019 wxHLB_DEFAULT_STYLE,
1023 MustHaveApp(wxSimpleHtmlListBox);
1025 class wxSimpleHtmlListBox : public wxPyHtmlListBox,
1026 public wxItemContainer
1029 %pythonAppend wxSimpleHtmlListBox "self._setOORInfo(self)";
1030 %pythonAppend wxSimpleHtmlListBox() "";
1032 wxSimpleHtmlListBox(wxWindow *parent,
1034 const wxPoint& pos = wxDefaultPosition,
1035 const wxSize& size = wxDefaultSize,
1036 const wxArrayString& choices = wxPyEmptyStringArray,
1037 long style = wxHLB_DEFAULT_STYLE,
1038 const wxValidator& validator = wxDefaultValidator,
1039 const wxString& name = wxPySimpleHtmlListBoxNameStr);
1040 %RenameCtor(PreSimpleHtmlListBox, wxSimpleHtmlListBox());
1042 bool Create(wxWindow *parent,
1044 const wxPoint& pos = wxDefaultPosition,
1045 const wxSize& size= wxDefaultSize,
1046 const wxArrayString& choices = wxPyEmptyStringArray,
1047 long style = wxHLB_DEFAULT_STYLE,
1048 const wxValidator& validator = wxDefaultValidator,
1049 const wxString& name = wxPySimpleHtmlListBoxNameStr);
1052 //---------------------------------------------------------------------------
1055 // Map renamed classes back to their common name for OOR
1056 wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox");
1057 wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox");
1058 wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow");
1061 //---------------------------------------------------------------------------