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 size_t GetRowCount() const;
114 size_t GetVisibleRowsBegin() const;
115 size_t GetVisibleRowsEnd() const;
116 bool IsRowVisible(size_t row) const;
118 virtual int GetOrientationTargetSize() const;
119 virtual int GetNonOrientationTargetSize() const;
120 virtual wxOrientation GetOrientation() const;
127 // Provides public API functions targeted for horizontal-specific scrolling,
128 // wrapping the functionality of wxVarScrollHelperBase.
130 class wxVarHScrollHelper : public wxVarScrollHelperBase
134 // wxVarHScrollHelper(wxWindow *winToScroll) *** ABC, can't instantiate
136 void SetColumnCount(size_t columnCount);
138 bool ScrollToColumn(size_t column);
139 virtual bool ScrollColumns(int columns);
140 virtual bool ScrollColumnPages(int pages);
142 virtual void RefreshColumn(size_t column);
143 virtual void RefreshColumns(size_t from, size_t to);
145 size_t GetColumnCount() const;
146 size_t GetVisibleColumnsBegin() const;
147 size_t GetVisibleColumnsEnd() const;
148 bool IsColumnVisible(size_t column) const;
151 virtual int GetOrientationTargetSize() const;
152 virtual int GetNonOrientationTargetSize() const;
153 virtual wxOrientation GetOrientation() const;
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
168 class wxVarHVScrollHelper : public wxVarVScrollHelper,
169 public wxVarHScrollHelper
173 // wxVarHVScrollHelper(wxWindow *winToScroll); *** ABC, can't instantiate
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
180 void SetRowColumnCount(size_t rowCount, size_t columnCount);
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);
189 // scroll to the specified row/column: it will become the first visible
190 // cell in the window
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);
196 // redraw the specified cell
197 // virtual void RefreshRowColumn(size_t row, size_t column);
198 virtual void RefreshRowColumn(const wxPosition &pos);
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);
209 // Override wxPanel::HitTest to use our version
210 // wxPosition VirtualHitTest(wxCoord x, wxCoord y) const;
211 wxPosition VirtualHitTest(const wxPoint &pos) const;
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()
219 // get the number of units this window contains (previously set by
220 // Set[Column/Row/RowColumn/Unit]Count())
221 wxSize GetRowColumnCount() const;
223 // get the first currently visible units
224 wxPosition GetVisibleBegin() const;
225 wxPosition GetVisibleEnd() const;
227 // is this cell currently visible?
228 // bool IsVisible(size_t row, size_t column) const;
229 bool IsVisible(const wxPosition &pos) const;
235 //---------------------------------------------------------------------------
240 // First, the C++ version that can redirect to overridden Python methods
242 class wxPyVScrolledWindow : public wxVScrolledWindow
244 DECLARE_ABSTRACT_CLASS(wxPyVScrolledWindow)
246 wxPyVScrolledWindow() : wxVScrolledWindow() {}
248 wxPyVScrolledWindow(wxWindow *parent,
249 wxWindowID id = wxID_ANY,
250 const wxPoint& pos = wxDefaultPosition,
251 const wxSize& size = wxDefaultSize,
253 const wxString& name = wxPyPanelNameStr)
254 : wxVScrolledWindow(parent, id, pos, size, style, name)
257 // Overridable virtuals
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
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
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.
275 // finally note that lineMin is inclusive, while lineMax is exclusive, as
277 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetRowsHeightHint);
278 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetLinesHint); // old name
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
286 // this function should return the best guess for the total height it may
288 DEC_PYCALLBACK_COORD_const(EstimateTotalHeight);
291 // Also expose some other interesting protected methods
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); }
303 IMPLEMENT_ABSTRACT_CLASS(wxPyVScrolledWindow, wxVScrolledWindow);
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);
310 IMP_PYCALLBACK_COORD_const (wxPyVScrolledWindow, wxVScrolledWindow, EstimateTotalHeight);
317 // Now define this class for SWIG
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).
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.
334 MustHaveApp(wxPyVScrolledWindow);
336 %rename(VScrolledWindow) wxPyVScrolledWindow;
338 class wxPyVScrolledWindow : public wxPanel,
339 public wxVarVScrollHelper
342 %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self);" setCallbackInfo(VScrolledWindow)
343 %pythonAppend wxPyVScrolledWindow() ""
346 wxPyVScrolledWindow(wxWindow *parent,
347 wxWindowID id = wxID_ANY,
348 const wxPoint& pos = wxDefaultPosition,
349 const wxSize& size = wxDefaultSize,
351 const wxString& name = wxPyPanelNameStr);
353 %RenameCtor(PreVScrolledWindow, wxPyVScrolledWindow());
355 void _setCallbackInfo(PyObject* self, PyObject* _class);
357 bool Create(wxWindow *parent,
358 wxWindowID id = wxID_ANY,
359 const wxPoint& pos = wxDefaultPosition,
360 const wxSize& size = wxDefaultSize,
362 const wxString& name = wxPyPanelNameStr);
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.") }
371 virtual wxCoord EstimateTotalHeight() const;
373 int HitTest(const wxPoint& pt) const;
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.
380 def GetFirstVisibleLine(self):
381 return self.GetVisibleRowsBegin()
382 GetFirstVisibleLine = wx._deprecated(GetFirstVisibleLine, "Use GetVisibleRowsBegin instead" )
384 def GetLastVisibleLine(self):
385 return self.GetVisibleRowsEnd() - 1
386 GetLastVisibleLine = wx._deprecated(GetLastVisibleLine, "Use GetVisibleRowsEnd instead")
388 def GetLineCount(self):
389 return self.GetRowCount()
390 GetLineCount = wx._deprecated(GetLineCount, "Use GetRowCount instead")
392 def SetLineCount(self, count):
393 self.SetRowCount(count)
394 SetLineCount = wx._deprecated(SetLineCount, "Use SetRowCount instead")
396 def RefreshLine(self, line):
397 self.RefreshRow(line)
398 RefreshLine = wx._deprecated(RefreshLine, "Use RefreshRow instead")
400 def RefreshLines(self, frm, to):
401 self.RefreshRows(frm, to)
402 RefreshLines = wx._deprecated(RefreshLines, "Use RefreshRows instead")
404 def ScrollToLine(self, line):
405 return self.ScrollToRow(line)
406 ScrollToLine = wx._deprecated(ScrollToLine, "Use RefreshRow instead")
408 def ScrollLines(self, lines):
409 return self.ScrollRows(lines)
410 ScrollLines = wx._deprecated(ScrollLines, "Use ScrollRows instead")
412 def ScrollPages(self, pages):
413 return self.ScrollRowPages(pages)
414 ScrollPages = wx._deprecated(ScrollPages, "Use ScrollRowPages instead")
421 //---------------------------------------------------------------------------
425 // First, the C++ version that can redirect to overridden Python methods
427 class wxPyHScrolledWindow : public wxHScrolledWindow
429 DECLARE_ABSTRACT_CLASS(wxPyHScrolledWindow)
431 wxPyHScrolledWindow() : wxHScrolledWindow() {}
433 wxPyHScrolledWindow(wxWindow *parent,
434 wxWindowID id = wxID_ANY,
435 const wxPoint& pos = wxDefaultPosition,
436 const wxSize& size = wxDefaultSize,
438 const wxString& name = wxPyPanelNameStr)
439 : wxHScrolledWindow(parent, id, pos, size, style, name)
442 // Overridable virtuals
443 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetColumnWidth);
444 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetColumnsWidthHint);
445 DEC_PYCALLBACK_COORD_const(EstimateTotalWidth);
447 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const
448 { return wxHScrolledWindow::GetColumnsWidth(columnMin, columnMax); }
453 IMPLEMENT_ABSTRACT_CLASS(wxPyHScrolledWindow, wxHScrolledWindow);
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);
463 // Now define this class for SWIG
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.
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.
475 MustHaveApp(wxPyHScrolledWindow);
477 %rename(HScrolledWindow) wxPyHScrolledWindow;
479 class wxPyHScrolledWindow : public wxPanel,
480 public wxVarHScrollHelper
483 %pythonAppend wxPyHScrolledWindow "self._setOORInfo(self);" setCallbackInfo(HScrolledWindow)
484 %pythonAppend wxPyHScrolledWindow() ""
487 wxPyHScrolledWindow(wxWindow *parent,
488 wxWindowID id = wxID_ANY,
489 const wxPoint& pos = wxDefaultPosition,
490 const wxSize& size = wxDefaultSize,
492 const wxString& name = wxPyPanelNameStr);
494 %RenameCtor(PreHScrolledWindow, wxPyHScrolledWindow());
496 void _setCallbackInfo(PyObject* self, PyObject* _class);
498 bool Create(wxWindow *parent,
499 wxWindowID id = wxID_ANY,
500 const wxPoint& pos = wxDefaultPosition,
501 const wxSize& size = wxDefaultSize,
503 const wxString& name = wxPyPanelNameStr);
506 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const;
507 wxCoord EstimateTotalWidth() const;
512 //---------------------------------------------------------------------------
513 // wxHVScrolledWindow
517 // First, the C++ version that can redirect to overridden Python methods
519 class wxPyHVScrolledWindow : public wxHVScrolledWindow
521 DECLARE_ABSTRACT_CLASS(wxPyHScrolledWindow)
523 wxPyHVScrolledWindow() : wxHVScrolledWindow() {}
525 wxPyHVScrolledWindow(wxWindow *parent,
526 wxWindowID id = wxID_ANY,
527 const wxPoint& pos = wxDefaultPosition,
528 const wxSize& size = wxDefaultSize,
530 const wxString& name = wxPyPanelNameStr)
531 : wxHVScrolledWindow(parent, id, pos, size, style, name)
534 // Overridable virtuals
535 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetRowHeight);
536 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetRowsHeightHint);
537 DEC_PYCALLBACK_COORD_const(EstimateTotalHeight);
539 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetColumnWidth);
540 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetColumnsWidthHint);
541 DEC_PYCALLBACK_COORD_const(EstimateTotalWidth);
543 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const
544 { return wxHVScrolledWindow::GetRowsHeight(lineMin, lineMax); }
546 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const
547 { return wxHVScrolledWindow::GetColumnsWidth(columnMin, columnMax); }
552 IMPLEMENT_ABSTRACT_CLASS(wxPyHVScrolledWindow, wxHVScrolledWindow);
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);
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);
567 // Now define this class for SWIG
569 // This window inherits all functionality of both vertical and horizontal
570 // scrolled windows automatically handling everything needed to scroll both
571 // axis simultaneously.
573 MustHaveApp(wxPyHVScrolledWindow);
575 %rename(HVScrolledWindow) wxPyHVScrolledWindow;
577 class wxPyHVScrolledWindow : public wxPanel,
578 public wxVarHVScrollHelper
581 %pythonAppend wxPyHVScrolledWindow "self._setOORInfo(self);" setCallbackInfo(HVScrolledWindow)
582 %pythonAppend wxPyHVScrolledWindow() ""
585 wxPyHVScrolledWindow(wxWindow *parent,
586 wxWindowID id = wxID_ANY,
587 const wxPoint& pos = wxDefaultPosition,
588 const wxSize& size = wxDefaultSize,
590 const wxString& name = wxPyPanelNameStr);
592 %RenameCtor(PreHVScrolledWindow, wxPyHVScrolledWindow());
594 void _setCallbackInfo(PyObject* self, PyObject* _class);
596 bool Create(wxWindow *parent,
597 wxWindowID id = wxID_ANY,
598 const wxPoint& pos = wxDefaultPosition,
599 const wxSize& size = wxDefaultSize,
601 const wxString& name = wxPyPanelNameStr);
604 wxCoord GetRowsHeight(size_t lineMin, size_t lineMax) const;
605 wxCoord EstimateTotalHeight() const;
607 wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const;
608 wxCoord EstimateTotalWidth() const;
613 //---------------------------------------------------------------------------
614 //---------------------------------------------------------------------------
618 #include <wx/vlbox.h>
621 MAKE_CONST_WXSTRING(VListBoxNameStr);
624 // First, the C++ version
626 class wxPyVListBox : public wxVListBox
628 DECLARE_ABSTRACT_CLASS(wxPyVListBox)
630 wxPyVListBox() : wxVListBox() {}
632 wxPyVListBox(wxWindow *parent,
633 wxWindowID id = wxID_ANY,
634 const wxPoint& pos = wxDefaultPosition,
635 const wxSize& size = wxDefaultSize,
637 const wxString& name = wxPyVListBoxNameStr)
638 : wxVListBox(parent, id, pos, size, style, name)
641 // Overridable virtuals
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);
649 // the derived class must implement this method to return the height of the
651 // virtual wxCoord OnMeasureItem(size_t n) const = 0;
652 DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem);
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()
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);
664 // this method is used to draw the items background and, maybe, a border
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
671 // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
672 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
678 IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox);
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);
689 // Now define this class for SWIG
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().
697 It emits the same events as wxListBox and the same event macros may be used
700 MustHaveApp(wxPyVListBox);
702 %rename(VListBox) wxPyVListBox;
703 class wxPyVListBox : public wxPyVScrolledWindow
706 %pythonAppend wxPyVListBox "self._setOORInfo(self);" setCallbackInfo(VListBox)
707 %pythonAppend wxPyVListBox() ""
710 wxPyVListBox(wxWindow *parent,
711 wxWindowID id = wxID_ANY,
712 const wxPoint& pos = wxDefaultPosition,
713 const wxSize& size = wxDefaultSize,
715 const wxString& name = wxPyVListBoxNameStr);
717 %RenameCtor(PreVListBox, wxPyVListBox());
719 void _setCallbackInfo(PyObject* self, PyObject* _class);
721 bool Create(wxWindow *parent,
722 wxWindowID id = wxID_ANY,
723 const wxPoint& pos = wxDefaultPosition,
724 const wxSize& size = wxDefaultSize,
726 const wxString& name = wxPyVListBoxNameStr);
728 // get the number of items in the control
729 size_t GetItemCount() const;
731 // does this control use multiple selection?
732 bool HasMultipleSelection() const;
734 // get the currently selected item or wxNOT_FOUND if there is no selection
736 // this method is only valid for the single selection listboxes
737 int GetSelection() const;
739 // is this item the current one?
740 bool IsCurrent(size_t item) const;
742 // is this item selected?
743 bool IsSelected(size_t item) const;
745 // get the number of the selected items (maybe 0)
747 // this method is valid for both single and multi selection listboxes
748 size_t GetSelectedCount() const;
751 // get the first selected item, returns wxNOT_FOUND if none
753 // cookie is an opaque parameter which should be passed to
754 // GetNextSelected() later
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);
769 // get next selection item, return wxNOT_FOUND if no more
771 // cookie must be the same parameter that was passed to GetFirstSelected()
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);
788 // get the margins around each item
789 wxPoint GetMargins() const;
791 // get the background colour of selected cells
792 const wxColour& GetSelectionBackground() const;
795 // set the number of items to be shown in the control
797 // this is just a synonym for wxVScrolledWindow::SetLineCount()
798 void SetItemCount(size_t count);
800 // delete all items from the control
803 // set the selection to the specified item, if it is wxNOT_FOUND the
804 // selection is unset
806 // this function is only valid for the single selection listboxes
807 void SetSelection(int selection);
809 // selects or deselects the specified item which must be valid (i.e. not
810 // equal to wxNOT_FOUND)
812 // return True if the items selection status has changed or False
815 // this function is only valid for the multiple selection listboxes
816 bool Select(size_t item, bool select = true);
818 // selects the items in the specified range whose end points may be given
821 // return True if any items selection status has changed, False otherwise
823 // this function is only valid for the single selection listboxes
824 bool SelectRange(size_t from, size_t to);
826 // toggle the selection of the specified item (must be valid)
828 // this function is only valid for the multiple selection listboxes
829 void Toggle(size_t item);
831 // select all items in the listbox
833 // the return code indicates if any items were affected by this operation
834 // (True) or if nothing has changed (False)
837 // unselect all items in the listbox
839 // the return code has the same meaning as for SelectAll()
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
846 // by default both margins are 0
847 void SetMargins(const wxPoint& pt);
848 %Rename(SetMarginsXY, void, SetMargins(wxCoord x, wxCoord y));
850 // change the background colour of the selected cells
851 void SetSelectionBackground(const wxColour& col);
853 // refreshes only the selected items
854 void RefreshSelected();
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;
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`");
868 //---------------------------------------------------------------------------
872 #include <wx/htmllbox.h>
875 // First, the C++ version
877 class wxPyHtmlListBox : public wxHtmlListBox
879 DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox)
881 wxPyHtmlListBox() : wxHtmlListBox() {}
883 wxPyHtmlListBox(wxWindow *parent,
884 wxWindowID id = wxID_ANY,
885 const wxPoint& pos = wxDefaultPosition,
886 const wxSize& size = wxDefaultSize,
888 const wxString& name = wxPyVListBoxNameStr)
889 : wxHtmlListBox(parent, id, pos, size, style, name)
892 // Overridable virtuals
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);
898 // this function may be overridden to decorate HTML returned by OnGetItem()
899 DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup);
901 // These are from wxVListBox
902 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
903 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
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
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;
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;
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);
929 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox)
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);
937 void wxPyHtmlListBox::OnLinkClicked(size_t n,
938 const wxHtmlLinkInfo& link) {
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));
946 wxPyEndBlockThreads(blocked);
948 wxPyHtmlListBox::OnLinkClicked(n, link);
955 // Now define this class for SWIG
958 // wxHtmlListBox is a listbox whose items are wxHtmlCells
959 MustHaveApp(wxPyHtmlListBox);
960 %rename(HtmlListBox) wxPyHtmlListBox;
961 class wxPyHtmlListBox : public wxPyVListBox
964 %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);" setCallbackInfo(HtmlListBox)
965 %pythonAppend wxPyHtmlListBox() ""
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,
974 const wxString& name = wxPyVListBoxNameStr);
976 %RenameCtor(PreHtmlListBox, wxPyHtmlListBox());
978 void _setCallbackInfo(PyObject* self, PyObject* _class);
980 bool Create(wxWindow *parent,
981 wxWindowID id = wxID_ANY,
982 const wxPoint& pos = wxDefaultPosition,
983 const wxSize& size = wxDefaultSize,
985 const wxString& name = wxPyVListBoxNameStr);
989 void SetItemCount(size_t count);
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();
995 void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link);
997 %property(FileSystem, GetFileSystem, doc="See `GetFileSystem`");
1002 //---------------------------------------------------------------------------
1005 const wxArrayString wxPyEmptyStringArray;
1007 MAKE_CONST_WXSTRING(SimpleHtmlListBoxNameStr);
1011 wxHLB_DEFAULT_STYLE,
1015 MustHaveApp(wxSimpleHtmlListBox);
1017 class wxSimpleHtmlListBox : public wxPyHtmlListBox,
1018 public wxItemContainer
1021 %pythonAppend wxSimpleHtmlListBox "self._setOORInfo(self)";
1022 %pythonAppend wxSimpleHtmlListBox() "";
1024 wxSimpleHtmlListBox(wxWindow *parent,
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());
1034 bool Create(wxWindow *parent,
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);
1044 //---------------------------------------------------------------------------
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");
1053 //---------------------------------------------------------------------------