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>
23 //---------------------------------------------------------------------------
30 #include <wx/vscroll.h>
34 // First, the C++ version
36 class wxPyVScrolledWindow : public wxVScrolledWindow
38 DECLARE_ABSTRACT_CLASS(wxPyVScrolledWindow)
40 wxPyVScrolledWindow() : wxVScrolledWindow() {}
42 wxPyVScrolledWindow(wxWindow *parent,
43 wxWindowID id = wxID_ANY,
44 const wxPoint& pos = wxDefaultPosition,
45 const wxSize& size = wxDefaultSize,
47 const wxString& name = wxPyPanelNameStr)
48 : wxVScrolledWindow(parent, id, pos, size, style, name)
51 // Overridable virtuals
53 // this function must be overridden in the derived class and it should
54 // return the height of the given line in pixels
55 DEC_PYCALLBACK_COORD_SIZET_constpure(OnGetLineHeight);
58 // this function doesn't have to be overridden but it may be useful to do
59 // it if calculating the lines heights is a relatively expensive operation
60 // as it gives the user code a possibility to calculate several of them at
63 // OnGetLinesHint() is normally called just before OnGetLineHeight() but you
64 // shouldn't rely on the latter being called for all lines in the interval
65 // specified here. It is also possible that OnGetLineHeight() will be
66 // called for the lines outside of this interval, so this is really just a
67 // hint, not a promise.
69 // finally note that lineMin is inclusive, while lineMax is exclusive, as
71 DEC_PYCALLBACK_VOID_SIZETSIZET_const(OnGetLinesHint);
74 // when the number of lines changes, we try to estimate the total height
75 // of all lines which is a rather expensive operation in terms of lines
76 // access, so if the user code may estimate the average height
77 // better/faster than we do, it should override this function to implement
80 // this function should return the best guess for the total height it may
82 DEC_PYCALLBACK_COORD_const(EstimateTotalHeight);
85 // Also expose some other interesting protected methods
88 // find the index of the line we need to show at the top of the window such
89 // that the last (fully or partially) visible line is the given one
90 size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false)
91 { return wxVScrolledWindow::FindFirstFromBottom(lineLast, fullyVisible); }
93 // get the total height of the lines between lineMin (inclusive) and
94 // lineMax (exclusive)
95 wxCoord GetLinesHeight(size_t lineMin, size_t lineMax) const
96 { return wxVScrolledWindow::GetLinesHeight(lineMin, lineMax); }
98 // update the thumb size shown by the scrollbar
99 void UpdateScrollbar() { wxVScrolledWindow::UpdateScrollbar(); }
101 // remove the scrollbar completely because we don't need it
102 void RemoveScrollbar() { wxVScrolledWindow::RemoveScrollbar(); }
107 IMPLEMENT_ABSTRACT_CLASS(wxPyVScrolledWindow, wxVScrolledWindow);
109 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLineHeight);
110 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLinesHint);
111 IMP_PYCALLBACK_COORD_const (wxPyVScrolledWindow, wxVScrolledWindow, EstimateTotalHeight);
116 // Now define this class for SWIG
119 In the name of this class, "V" may stand for "variable" because it can be
120 used for scrolling lines of variable heights; "virtual" because it is not
121 necessary to know the heights of all lines in advance -- only those which
122 are shown on the screen need to be measured; or, even, "vertical" because
123 this class only supports scrolling in one direction currently (this could
124 and probably will change in the future however).
126 In any case, this is a generalization of the wxScrolledWindow class which
127 can be only used when all lines have the same height. It lacks some other
128 wxScrolledWindow features however, notably it currently lacks support for
129 horizontal scrolling; it can't scroll another window nor only a rectangle
130 of the window and not its entire client area.
133 MustHaveApp(wxPyVScrolledWindow);
135 %rename(VScrolledWindow) wxPyVScrolledWindow;
136 class wxPyVScrolledWindow : public wxPanel
139 %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self);" setCallbackInfo(VScrolledWindow)
140 %pythonAppend wxPyVScrolledWindow() ""
143 wxPyVScrolledWindow(wxWindow *parent,
144 wxWindowID id = wxID_ANY,
145 const wxPoint& pos = wxDefaultPosition,
146 const wxSize& size = wxDefaultSize,
148 const wxString& name = wxPyPanelNameStr);
150 %RenameCtor(PreVScrolledWindow, wxPyVScrolledWindow());
152 void _setCallbackInfo(PyObject* self, PyObject* _class);
154 bool Create(wxWindow *parent,
155 wxWindowID id = wxID_ANY,
156 const wxPoint& pos = wxDefaultPosition,
157 const wxSize& size = wxDefaultSize,
159 const wxString& name = wxPyPanelNameStr);
162 // set the number of lines the window contains: the derived class must
163 // provide the heights for all lines with indices up to the one given here
164 // in its OnGetLineHeight()
165 void SetLineCount(size_t count);
167 // scroll to the specified line: it will become the first visible line in
170 // return True if we scrolled the window, False if nothing was done
171 bool ScrollToLine(size_t line);
173 // scroll by the specified number of lines/pages
174 virtual bool ScrollLines(int lines);
175 virtual bool ScrollPages(int pages);
177 // redraw the specified line
178 void RefreshLine(size_t line);
180 // redraw all lines in the specified range (inclusive)
181 void RefreshLines(size_t from, size_t to);
183 // return the item at the specified (in physical coordinates) position or
184 // wxNOT_FOUND if none, i.e. if it is below the last item
185 %Rename(HitTestXY, int, HitTest(wxCoord x, wxCoord y) const);
186 int HitTest(const wxPoint& pt) const;
188 // recalculate all our parameters and redisplay all lines
189 virtual void RefreshAll();
192 // get the number of lines this window contains (previously set by
194 size_t GetLineCount() const;
196 // get the first currently visible line
197 size_t GetVisibleBegin() const;
199 // get the last currently visible line
200 size_t GetVisibleEnd() const;
202 // is this line currently visible?
203 bool IsVisible(size_t line) const;
205 // this is the same as GetVisibleBegin(), exists to match
206 // GetLastVisibleLine() and for backwards compatibility only
207 size_t GetFirstVisibleLine() const;
209 // get the last currently visible line
211 // this function is unsafe as it returns (size_t)-1 (i.e. a huge positive
212 // number) if the control is empty, use GetVisibleEnd() instead, this one
213 // is kept for backwards compatibility
214 size_t GetLastVisibleLine() const;
216 // find the index of the line we need to show at the top of the window such
217 // that the last (fully or partially) visible line is the given one
218 size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false);
220 // get the total height of the lines between lineMin (inclusive) and
221 // lineMax (exclusive)
222 wxCoord GetLinesHeight(size_t lineMin, size_t lineMax) const;
224 %property(FirstVisibleLine, GetFirstVisibleLine, doc="See `GetFirstVisibleLine`");
225 %property(LastVisibleLine, GetLastVisibleLine, doc="See `GetLastVisibleLine`");
226 %property(LineCount, GetLineCount, SetLineCount, doc="See `GetLineCount` and `SetLineCount`");
227 %property(VisibleBegin, GetVisibleBegin, doc="See `GetVisibleBegin`");
228 %property(VisibleEnd, GetVisibleEnd, doc="See `GetVisibleEnd`");
233 //---------------------------------------------------------------------------
237 #include <wx/vlbox.h>
240 MAKE_CONST_WXSTRING(VListBoxNameStr);
243 // First, the C++ version
245 class wxPyVListBox : public wxVListBox
247 DECLARE_ABSTRACT_CLASS(wxPyVListBox)
249 wxPyVListBox() : wxVListBox() {}
251 wxPyVListBox(wxWindow *parent,
252 wxWindowID id = wxID_ANY,
253 const wxPoint& pos = wxDefaultPosition,
254 const wxSize& size = wxDefaultSize,
256 const wxString& name = wxPyVListBoxNameStr)
257 : wxVListBox(parent, id, pos, size, style, name)
260 // Overridable virtuals
262 // the derived class must implement this function to actually draw the item
263 // with the given index on the provided DC
264 // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
265 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem);
268 // the derived class must implement this method to return the height of the
270 // virtual wxCoord OnMeasureItem(size_t n) const = 0;
271 DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem);
274 // this method may be used to draw separators between the lines; note that
275 // the rectangle may be modified, typically to deflate it a bit before
276 // passing to OnDrawItem()
278 // the base class version doesn't do anything
279 // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
280 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
283 // this method is used to draw the items background and, maybe, a border
286 // the base class version implements a reasonable default behaviour which
287 // consists in drawing the selected item with the standard background
288 // colour and drawing a border around the item if it is either selected or
290 // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
291 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
297 IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox);
299 IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem);
300 IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem);
301 IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyVListBox, wxVListBox, OnDrawSeparator);
302 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground);
308 // Now define this class for SWIG
311 This class has two main differences from a regular listbox: it can have an
312 arbitrarily huge number of items because it doesn't store them itself but
313 uses OnDrawItem() callback to draw them and its items can have variable
314 height as determined by OnMeasureItem().
316 It emits the same events as wxListBox and the same event macros may be used
319 MustHaveApp(wxPyVListBox);
321 %rename(VListBox) wxPyVListBox;
322 class wxPyVListBox : public wxPyVScrolledWindow
325 %pythonAppend wxPyVListBox "self._setOORInfo(self);" setCallbackInfo(VListBox)
326 %pythonAppend wxPyVListBox() ""
329 wxPyVListBox(wxWindow *parent,
330 wxWindowID id = wxID_ANY,
331 const wxPoint& pos = wxDefaultPosition,
332 const wxSize& size = wxDefaultSize,
334 const wxString& name = wxPyVListBoxNameStr);
336 %RenameCtor(PreVListBox, wxPyVListBox());
338 void _setCallbackInfo(PyObject* self, PyObject* _class);
340 bool Create(wxWindow *parent,
341 wxWindowID id = wxID_ANY,
342 const wxPoint& pos = wxDefaultPosition,
343 const wxSize& size = wxDefaultSize,
345 const wxString& name = wxPyVListBoxNameStr);
347 // get the number of items in the control
348 size_t GetItemCount() const;
350 // does this control use multiple selection?
351 bool HasMultipleSelection() const;
353 // get the currently selected item or wxNOT_FOUND if there is no selection
355 // this method is only valid for the single selection listboxes
356 int GetSelection() const;
358 // is this item the current one?
359 bool IsCurrent(size_t item) const;
361 // is this item selected?
362 bool IsSelected(size_t item) const;
364 // get the number of the selected items (maybe 0)
366 // this method is valid for both single and multi selection listboxes
367 size_t GetSelectedCount() const;
370 // get the first selected item, returns wxNOT_FOUND if none
372 // cookie is an opaque parameter which should be passed to
373 // GetNextSelected() later
375 // this method is only valid for the multi selection listboxes
376 //int GetFirstSelected(unsigned long& cookie) const;
377 PyObject* GetFirstSelected() {
378 unsigned long cookie = 0;
379 int selected = self->GetFirstSelected(cookie);
380 wxPyBlock_t blocked = wxPyBeginBlockThreads();
381 PyObject* tup = PyTuple_New(2);
382 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
383 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
384 wxPyEndBlockThreads(blocked);
388 // get next selection item, return wxNOT_FOUND if no more
390 // cookie must be the same parameter that was passed to GetFirstSelected()
393 // this method is only valid for the multi selection listboxes
394 // int GetNextSelected(unsigned long& cookie) const;
395 PyObject* GetNextSelected(unsigned long cookie) {
396 int selected = self->GetNextSelected(cookie);
397 wxPyBlock_t blocked = wxPyBeginBlockThreads();
398 PyObject* tup = PyTuple_New(2);
399 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
400 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
401 wxPyEndBlockThreads(blocked);
407 // get the margins around each item
408 wxPoint GetMargins() const;
410 // get the background colour of selected cells
411 const wxColour& GetSelectionBackground() const;
414 // set the number of items to be shown in the control
416 // this is just a synonym for wxVScrolledWindow::SetLineCount()
417 void SetItemCount(size_t count);
419 // delete all items from the control
422 // set the selection to the specified item, if it is wxNOT_FOUND the
423 // selection is unset
425 // this function is only valid for the single selection listboxes
426 void SetSelection(int selection);
428 // selects or deselects the specified item which must be valid (i.e. not
429 // equal to wxNOT_FOUND)
431 // return True if the items selection status has changed or False
434 // this function is only valid for the multiple selection listboxes
435 bool Select(size_t item, bool select = true);
437 // selects the items in the specified range whose end points may be given
440 // return True if any items selection status has changed, False otherwise
442 // this function is only valid for the single selection listboxes
443 bool SelectRange(size_t from, size_t to);
445 // toggle the selection of the specified item (must be valid)
447 // this function is only valid for the multiple selection listboxes
448 void Toggle(size_t item);
450 // select all items in the listbox
452 // the return code indicates if any items were affected by this operation
453 // (True) or if nothing has changed (False)
456 // unselect all items in the listbox
458 // the return code has the same meaning as for SelectAll()
461 // set the margins: horizontal margin is the distance between the window
462 // border and the item contents while vertical margin is half of the
463 // distance between items
465 // by default both margins are 0
466 void SetMargins(const wxPoint& pt);
467 %Rename(SetMarginsXY, void, SetMargins(wxCoord x, wxCoord y));
469 // change the background colour of the selected cells
470 void SetSelectionBackground(const wxColour& col);
472 virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
473 virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
475 %property(FirstSelected, GetFirstSelected, doc="See `GetFirstSelected`");
476 %property(ItemCount, GetItemCount, SetItemCount, doc="See `GetItemCount` and `SetItemCount`");
477 %property(Margins, GetMargins, SetMargins, doc="See `GetMargins` and `SetMargins`");
478 %property(SelectedCount, GetSelectedCount, doc="See `GetSelectedCount`");
479 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
480 %property(SelectionBackground, GetSelectionBackground, SetSelectionBackground, doc="See `GetSelectionBackground` and `SetSelectionBackground`");
484 //---------------------------------------------------------------------------
488 #include <wx/htmllbox.h>
491 // First, the C++ version
493 class wxPyHtmlListBox : public wxHtmlListBox
495 DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox)
497 wxPyHtmlListBox() : wxHtmlListBox() {}
499 wxPyHtmlListBox(wxWindow *parent,
500 wxWindowID id = wxID_ANY,
501 const wxPoint& pos = wxDefaultPosition,
502 const wxSize& size = wxDefaultSize,
504 const wxString& name = wxPyVListBoxNameStr)
505 : wxHtmlListBox(parent, id, pos, size, style, name)
508 // Overridable virtuals
510 // this method must be implemented in the derived class and should return
511 // the body (i.e. without <html>) of the HTML for the given item
512 DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem);
514 // this function may be overridden to decorate HTML returned by OnGetItem()
515 DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup);
517 // These are from wxVListBox
518 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
519 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
522 // // this method allows to customize the selection appearance: it may be used
523 // // to specify the colour of the text which normally has the given colour
524 // // colFg when it is inside the selection
526 // // by default, the original colour is not used at all and all text has the
527 // // same (default for this system) colour inside selection
528 // virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
530 // // this is the same as GetSelectedTextColour() but allows to customize the
531 // // background colour -- this is even more rarely used as you can change it
532 // // globally using SetSelectionBackground()
533 // virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
536 // This method may be overriden to handle clicking on a link in
537 // the listbox. By default, clicking links is ignored.
538 virtual void OnLinkClicked(size_t n,
539 const wxHtmlLinkInfo& link);
545 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox)
547 IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem);
548 IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup);
549 IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawSeparator);
550 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawBackground);
553 void wxPyHtmlListBox::OnLinkClicked(size_t n,
554 const wxHtmlLinkInfo& link) {
556 wxPyBlock_t blocked = wxPyBeginBlockThreads();
557 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
558 PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0);
559 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", n, obj));
562 wxPyEndBlockThreads(blocked);
564 wxPyHtmlListBox::OnLinkClicked(n, link);
571 // Now define this class for SWIG
574 // wxHtmlListBox is a listbox whose items are wxHtmlCells
575 MustHaveApp(wxPyHtmlListBox);
576 %rename(HtmlListBox) wxPyHtmlListBox;
577 class wxPyHtmlListBox : public wxPyVListBox
580 %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);" setCallbackInfo(HtmlListBox)
581 %pythonAppend wxPyHtmlListBox() ""
584 // normal constructor which calls Create() internally
585 wxPyHtmlListBox(wxWindow *parent,
586 wxWindowID id = wxID_ANY,
587 const wxPoint& pos = wxDefaultPosition,
588 const wxSize& size = wxDefaultSize,
590 const wxString& name = wxPyVListBoxNameStr);
592 %RenameCtor(PreHtmlListBox, wxPyHtmlListBox());
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 = wxPyVListBoxNameStr);
605 void SetItemCount(size_t count);
607 // retrieve the file system used by the wxHtmlWinParser: if you use
608 // relative paths in your HTML, you should use its ChangePathTo() method
609 wxFileSystem& GetFileSystem();
611 void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link);
613 %property(FileSystem, GetFileSystem, doc="See `GetFileSystem`");
618 //---------------------------------------------------------------------------
621 const wxArrayString wxPyEmptyStringArray;
623 MAKE_CONST_WXSTRING(SimpleHtmlListBoxNameStr);
631 MustHaveApp(wxSimpleHtmlListBox);
633 class wxSimpleHtmlListBox : public wxPyHtmlListBox,
634 public wxItemContainer
637 %pythonAppend wxSimpleHtmlListBox "self._setOORInfo(self)";
638 %pythonAppend wxSimpleHtmlListBox() "";
640 wxSimpleHtmlListBox(wxWindow *parent,
642 const wxPoint& pos = wxDefaultPosition,
643 const wxSize& size = wxDefaultSize,
644 const wxArrayString& choices = wxPyEmptyStringArray,
645 long style = wxHLB_DEFAULT_STYLE,
646 const wxValidator& validator = wxDefaultValidator,
647 const wxString& name = wxPySimpleHtmlListBoxNameStr);
648 %RenameCtor(PreSimpleHtmlListBox, wxSimpleHtmlListBox());
650 bool Create(wxWindow *parent,
652 const wxPoint& pos = wxDefaultPosition,
653 const wxSize& size= wxDefaultSize,
654 const wxArrayString& choices = wxPyEmptyStringArray,
655 long style = wxHLB_DEFAULT_STYLE,
656 const wxValidator& validator = wxDefaultValidator,
657 const wxString& name = wxPySimpleHtmlListBoxNameStr);
660 //---------------------------------------------------------------------------
663 // Map renamed classes back to their common name for OOR
664 wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox");
665 wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox");
666 wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow");
669 //---------------------------------------------------------------------------