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); self._setCallbackInfo(self, 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;
227 //---------------------------------------------------------------------------
231 #include <wx/vlbox.h>
234 MAKE_CONST_WXSTRING(VListBoxNameStr);
237 // First, the C++ version
239 class wxPyVListBox : public wxVListBox
241 DECLARE_ABSTRACT_CLASS(wxPyVListBox)
243 wxPyVListBox() : wxVListBox() {}
245 wxPyVListBox(wxWindow *parent,
246 wxWindowID id = wxID_ANY,
247 const wxPoint& pos = wxDefaultPosition,
248 const wxSize& size = wxDefaultSize,
250 const wxString& name = wxPyVListBoxNameStr)
251 : wxVListBox(parent, id, pos, size, style, name)
254 // Overridable virtuals
256 // the derived class must implement this function to actually draw the item
257 // with the given index on the provided DC
258 // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
259 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem);
262 // the derived class must implement this method to return the height of the
264 // virtual wxCoord OnMeasureItem(size_t n) const = 0;
265 DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem);
268 // this method may be used to draw separators between the lines; note that
269 // the rectangle may be modified, typically to deflate it a bit before
270 // passing to OnDrawItem()
272 // the base class version doesn't do anything
273 // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
274 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
277 // this method is used to draw the items background and, maybe, a border
280 // the base class version implements a reasonable default behaviour which
281 // consists in drawing the selected item with the standard background
282 // colour and drawing a border around the item if it is either selected or
284 // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
285 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
291 IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox);
293 IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem);
294 IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem);
295 IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyVListBox, wxVListBox, OnDrawSeparator);
296 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground);
302 // Now define this class for SWIG
305 This class has two main differences from a regular listbox: it can have an
306 arbitrarily huge number of items because it doesn't store them itself but
307 uses OnDrawItem() callback to draw them and its items can have variable
308 height as determined by OnMeasureItem().
310 It emits the same events as wxListBox and the same event macros may be used
313 MustHaveApp(wxPyVListBox);
315 %rename(VListBox) wxPyVListBox;
316 class wxPyVListBox : public wxPyVScrolledWindow
319 %pythonAppend wxPyVListBox "self._setOORInfo(self);self._setCallbackInfo(self, VListBox)"
320 %pythonAppend wxPyVListBox() ""
323 wxPyVListBox(wxWindow *parent,
324 wxWindowID id = wxID_ANY,
325 const wxPoint& pos = wxDefaultPosition,
326 const wxSize& size = wxDefaultSize,
328 const wxString& name = wxPyVListBoxNameStr);
330 %RenameCtor(PreVListBox, wxPyVListBox());
332 void _setCallbackInfo(PyObject* self, PyObject* _class);
334 bool Create(wxWindow *parent,
335 wxWindowID id = wxID_ANY,
336 const wxPoint& pos = wxDefaultPosition,
337 const wxSize& size = wxDefaultSize,
339 const wxString& name = wxPyVListBoxNameStr);
341 // get the number of items in the control
342 size_t GetItemCount() const;
344 // does this control use multiple selection?
345 bool HasMultipleSelection() const;
347 // get the currently selected item or wxNOT_FOUND if there is no selection
349 // this method is only valid for the single selection listboxes
350 int GetSelection() const;
352 // is this item the current one?
353 bool IsCurrent(size_t item) const;
355 // is this item selected?
356 bool IsSelected(size_t item) const;
358 // get the number of the selected items (maybe 0)
360 // this method is valid for both single and multi selection listboxes
361 size_t GetSelectedCount() const;
364 // get the first selected item, returns wxNOT_FOUND if none
366 // cookie is an opaque parameter which should be passed to
367 // GetNextSelected() later
369 // this method is only valid for the multi selection listboxes
370 //int GetFirstSelected(unsigned long& cookie) const;
371 PyObject* GetFirstSelected() {
372 unsigned long cookie = 0;
373 int selected = self->GetFirstSelected(cookie);
374 wxPyBlock_t blocked = wxPyBeginBlockThreads();
375 PyObject* tup = PyTuple_New(2);
376 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
377 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
378 wxPyEndBlockThreads(blocked);
382 // get next selection item, return wxNOT_FOUND if no more
384 // cookie must be the same parameter that was passed to GetFirstSelected()
387 // this method is only valid for the multi selection listboxes
388 // int GetNextSelected(unsigned long& cookie) const;
389 PyObject* GetNextSelected(unsigned long cookie) {
390 int selected = self->GetNextSelected(cookie);
391 wxPyBlock_t blocked = wxPyBeginBlockThreads();
392 PyObject* tup = PyTuple_New(2);
393 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
394 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
395 wxPyEndBlockThreads(blocked);
401 // get the margins around each item
402 wxPoint GetMargins() const;
404 // get the background colour of selected cells
405 const wxColour& GetSelectionBackground() const;
408 // set the number of items to be shown in the control
410 // this is just a synonym for wxVScrolledWindow::SetLineCount()
411 void SetItemCount(size_t count);
413 // delete all items from the control
416 // set the selection to the specified item, if it is wxNOT_FOUND the
417 // selection is unset
419 // this function is only valid for the single selection listboxes
420 void SetSelection(int selection);
422 // selects or deselects the specified item which must be valid (i.e. not
423 // equal to wxNOT_FOUND)
425 // return True if the items selection status has changed or False
428 // this function is only valid for the multiple selection listboxes
429 bool Select(size_t item, bool select = true);
431 // selects the items in the specified range whose end points may be given
434 // return True if any items selection status has changed, False otherwise
436 // this function is only valid for the single selection listboxes
437 bool SelectRange(size_t from, size_t to);
439 // toggle the selection of the specified item (must be valid)
441 // this function is only valid for the multiple selection listboxes
442 void Toggle(size_t item);
444 // select all items in the listbox
446 // the return code indicates if any items were affected by this operation
447 // (True) or if nothing has changed (False)
450 // unselect all items in the listbox
452 // the return code has the same meaning as for SelectAll()
455 // set the margins: horizontal margin is the distance between the window
456 // border and the item contents while vertical margin is half of the
457 // distance between items
459 // by default both margins are 0
460 void SetMargins(const wxPoint& pt);
461 %Rename(SetMarginsXY, void, SetMargins(wxCoord x, wxCoord y));
463 // change the background colour of the selected cells
464 void SetSelectionBackground(const wxColour& col);
466 virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
467 virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
471 //---------------------------------------------------------------------------
475 #include <wx/htmllbox.h>
478 // First, the C++ version
480 class wxPyHtmlListBox : public wxHtmlListBox
482 DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox)
484 wxPyHtmlListBox() : wxHtmlListBox() {}
486 wxPyHtmlListBox(wxWindow *parent,
487 wxWindowID id = wxID_ANY,
488 const wxPoint& pos = wxDefaultPosition,
489 const wxSize& size = wxDefaultSize,
491 const wxString& name = wxPyVListBoxNameStr)
492 : wxHtmlListBox(parent, id, pos, size, style, name)
495 // Overridable virtuals
497 // this method must be implemented in the derived class and should return
498 // the body (i.e. without <html>) of the HTML for the given item
499 DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem);
501 // this function may be overridden to decorate HTML returned by OnGetItem()
502 DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup);
504 // These are from wxVListBox
505 DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator);
506 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
509 // // this method allows to customize the selection appearance: it may be used
510 // // to specify the colour of the text which normally has the given colour
511 // // colFg when it is inside the selection
513 // // by default, the original colour is not used at all and all text has the
514 // // same (default for this system) colour inside selection
515 // virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
517 // // this is the same as GetSelectedTextColour() but allows to customize the
518 // // background colour -- this is even more rarely used as you can change it
519 // // globally using SetSelectionBackground()
520 // virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
523 // This method may be overriden to handle clicking on a link in
524 // the listbox. By default, clicking links is ignored.
525 virtual void OnLinkClicked(size_t n,
526 const wxHtmlLinkInfo& link);
532 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox)
534 IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem);
535 IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup);
536 IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawSeparator);
537 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawBackground);
540 void wxPyHtmlListBox::OnLinkClicked(size_t n,
541 const wxHtmlLinkInfo& link) {
543 wxPyBlock_t blocked = wxPyBeginBlockThreads();
544 if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) {
545 PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0);
546 wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", n, obj));
549 wxPyEndBlockThreads(blocked);
551 wxPyHtmlListBox::OnLinkClicked(n, link);
558 // Now define this class for SWIG
561 // wxHtmlListBox is a listbox whose items are wxHtmlCells
562 MustHaveApp(wxPyHtmlListBox);
563 %rename(HtmlListBox) wxPyHtmlListBox;
564 class wxPyHtmlListBox : public wxPyVListBox
567 %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);self._setCallbackInfo(self, HtmlListBox)"
568 %pythonAppend wxPyHtmlListBox() ""
571 // normal constructor which calls Create() internally
572 wxPyHtmlListBox(wxWindow *parent,
573 wxWindowID id = wxID_ANY,
574 const wxPoint& pos = wxDefaultPosition,
575 const wxSize& size = wxDefaultSize,
577 const wxString& name = wxPyVListBoxNameStr);
579 %RenameCtor(PreHtmlListBox, wxPyHtmlListBox());
581 void _setCallbackInfo(PyObject* self, PyObject* _class);
583 bool Create(wxWindow *parent,
584 wxWindowID id = wxID_ANY,
585 const wxPoint& pos = wxDefaultPosition,
586 const wxSize& size = wxDefaultSize,
588 const wxString& name = wxPyVListBoxNameStr);
592 void SetItemCount(size_t count);
594 // retrieve the file system used by the wxHtmlWinParser: if you use
595 // relative paths in your HTML, you should use its ChangePathTo() method
596 wxFileSystem& GetFileSystem();
598 void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link);
603 //---------------------------------------------------------------------------
606 // Map renamed classes back to their common name for OOR
607 wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox");
608 wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox");
609 wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow");
612 //---------------------------------------------------------------------------