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); }
102 IMPLEMENT_ABSTRACT_CLASS(wxPyVScrolledWindow, wxVScrolledWindow);
104 IMP_PYCALLBACK_COORD_SIZET_constpure(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLineHeight);
105 IMP_PYCALLBACK_VOID_SIZETSIZET_const(wxPyVScrolledWindow, wxVScrolledWindow, OnGetLinesHint);
106 IMP_PYCALLBACK_COORD_const (wxPyVScrolledWindow, wxVScrolledWindow, EstimateTotalHeight);
111 // Now define this class for SWIG
114 In the name of this class, "V" may stand for "variable" because it can be
115 used for scrolling lines of variable heights; "virtual" because it is not
116 necessary to know the heights of all lines in advance -- only those which
117 are shown on the screen need to be measured; or, even, "vertical" because
118 this class only supports scrolling in one direction currently (this could
119 and probably will change in the future however).
121 In any case, this is a generalization of the wxScrolledWindow class which
122 can be only used when all lines have the same height. It lacks some other
123 wxScrolledWindow features however, notably it currently lacks support for
124 horizontal scrolling; it can't scroll another window nor only a rectangle
125 of the window and not its entire client area.
128 MustHaveApp(wxPyVScrolledWindow);
130 %rename(VScrolledWindow) wxPyVScrolledWindow;
131 class wxPyVScrolledWindow : public wxPanel
134 %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self); self._setCallbackInfo(self, VScrolledWindow)"
135 %pythonAppend wxPyVScrolledWindow() ""
138 wxPyVScrolledWindow(wxWindow *parent,
139 wxWindowID id = wxID_ANY,
140 const wxPoint& pos = wxDefaultPosition,
141 const wxSize& size = wxDefaultSize,
143 const wxString& name = wxPyPanelNameStr);
145 %RenameCtor(PreVScrolledWindow, wxPyVScrolledWindow());
147 void _setCallbackInfo(PyObject* self, PyObject* _class);
149 bool Create(wxWindow *parent,
150 wxWindowID id = wxID_ANY,
151 const wxPoint& pos = wxDefaultPosition,
152 const wxSize& size = wxDefaultSize,
154 const wxString& name = wxPyPanelNameStr);
157 // set the number of lines the window contains: the derived class must
158 // provide the heights for all lines with indices up to the one given here
159 // in its OnGetLineHeight()
160 void SetLineCount(size_t count);
162 // scroll to the specified line: it will become the first visible line in
165 // return True if we scrolled the window, False if nothing was done
166 bool ScrollToLine(size_t line);
168 // scroll by the specified number of lines/pages
169 virtual bool ScrollLines(int lines);
170 virtual bool ScrollPages(int pages);
172 // redraw the specified line
173 void RefreshLine(size_t line);
175 // redraw all lines in the specified range (inclusive)
176 void RefreshLines(size_t from, size_t to);
178 // return the item at the specified (in physical coordinates) position or
179 // wxNOT_FOUND if none, i.e. if it is below the last item
180 %Rename(HitTestXY, int, HitTest(wxCoord x, wxCoord y) const);
181 int HitTest(const wxPoint& pt) const;
183 // recalculate all our parameters and redisplay all lines
184 virtual void RefreshAll();
187 // get the number of lines this window contains (previously set by
189 size_t GetLineCount() const;
191 // get the first currently visible line
192 size_t GetVisibleBegin() const;
194 // get the last currently visible line
195 size_t GetVisibleEnd() const;
197 // is this line currently visible?
198 bool IsVisible(size_t line) const;
200 // this is the same as GetVisibleBegin(), exists to match
201 // GetLastVisibleLine() and for backwards compatibility only
202 size_t GetFirstVisibleLine() const;
204 // get the last currently visible line
206 // this function is unsafe as it returns (size_t)-1 (i.e. a huge positive
207 // number) if the control is empty, use GetVisibleEnd() instead, this one
208 // is kept for backwards compatibility
209 size_t GetLastVisibleLine() const;
213 //---------------------------------------------------------------------------
217 #include <wx/vlbox.h>
220 MAKE_CONST_WXSTRING(VListBoxNameStr);
223 // First, the C++ version
225 class wxPyVListBox : public wxVListBox
227 DECLARE_ABSTRACT_CLASS(wxPyVListBox)
229 wxPyVListBox() : wxVListBox() {}
231 wxPyVListBox(wxWindow *parent,
232 wxWindowID id = wxID_ANY,
233 const wxPoint& pos = wxDefaultPosition,
234 const wxSize& size = wxDefaultSize,
236 const wxString& name = wxPyVListBoxNameStr)
237 : wxVListBox(parent, id, pos, size, style, name)
240 // Overridable virtuals
242 // the derived class must implement this function to actually draw the item
243 // with the given index on the provided DC
244 // virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
245 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawItem);
248 // the derived class must implement this method to return the height of the
250 // virtual wxCoord OnMeasureItem(size_t n) const = 0;
251 DEC_PYCALLBACK_COORD_SIZET_constpure(OnMeasureItem);
254 // this method may be used to draw separators between the lines; note that
255 // the rectangle may be modified, typically to deflate it a bit before
256 // passing to OnDrawItem()
258 // the base class version doesn't do anything
259 // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
260 DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawSeparator);
263 // this method is used to draw the items background and, maybe, a border
266 // the base class version implements a reasonable default behaviour which
267 // consists in drawing the selected item with the standard background
268 // colour and drawing a border around the item if it is either selected or
270 // virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
271 DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground);
277 IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox);
279 IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem);
280 IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem);
281 IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawSeparator);
282 IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground);
288 // Now define this class for SWIG
291 This class has two main differences from a regular listbox: it can have an
292 arbitrarily huge number of items because it doesn't store them itself but
293 uses OnDrawItem() callback to draw them and its items can have variable
294 height as determined by OnMeasureItem().
296 It emits the same events as wxListBox and the same event macros may be used
299 MustHaveApp(wxPyVListBox);
301 %rename(VListBox) wxPyVListBox;
302 class wxPyVListBox : public wxPyVScrolledWindow
305 %pythonAppend wxPyVListBox "self._setOORInfo(self);self._setCallbackInfo(self, VListBox)"
306 %pythonAppend wxPyVListBox() ""
309 wxPyVListBox(wxWindow *parent,
310 wxWindowID id = wxID_ANY,
311 const wxPoint& pos = wxDefaultPosition,
312 const wxSize& size = wxDefaultSize,
314 const wxString& name = wxPyVListBoxNameStr);
316 %RenameCtor(PreVListBox, wxPyVListBox());
318 void _setCallbackInfo(PyObject* self, PyObject* _class);
320 bool Create(wxWindow *parent,
321 wxWindowID id = wxID_ANY,
322 const wxPoint& pos = wxDefaultPosition,
323 const wxSize& size = wxDefaultSize,
325 const wxString& name = wxPyVListBoxNameStr);
327 // get the number of items in the control
328 size_t GetItemCount() const;
330 // does this control use multiple selection?
331 bool HasMultipleSelection() const;
333 // get the currently selected item or wxNOT_FOUND if there is no selection
335 // this method is only valid for the single selection listboxes
336 int GetSelection() const;
338 // is this item the current one?
339 bool IsCurrent(size_t item) const;
341 // is this item selected?
342 bool IsSelected(size_t item) const;
344 // get the number of the selected items (maybe 0)
346 // this method is valid for both single and multi selection listboxes
347 size_t GetSelectedCount() const;
350 // get the first selected item, returns wxNOT_FOUND if none
352 // cookie is an opaque parameter which should be passed to
353 // GetNextSelected() later
355 // this method is only valid for the multi selection listboxes
356 //int GetFirstSelected(unsigned long& cookie) const;
357 PyObject* GetFirstSelected() {
358 unsigned long cookie = 0;
359 int selected = self->GetFirstSelected(cookie);
360 wxPyBlock_t blocked = wxPyBeginBlockThreads();
361 PyObject* tup = PyTuple_New(2);
362 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
363 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
364 wxPyEndBlockThreads(blocked);
368 // get next selection item, return wxNOT_FOUND if no more
370 // cookie must be the same parameter that was passed to GetFirstSelected()
373 // this method is only valid for the multi selection listboxes
374 // int GetNextSelected(unsigned long& cookie) const;
375 PyObject* GetNextSelected(unsigned long cookie) {
376 int selected = self->GetNextSelected(cookie);
377 wxPyBlock_t blocked = wxPyBeginBlockThreads();
378 PyObject* tup = PyTuple_New(2);
379 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected));
380 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
381 wxPyEndBlockThreads(blocked);
387 // get the margins around each item
388 wxPoint GetMargins() const;
390 // get the background colour of selected cells
391 const wxColour& GetSelectionBackground() const;
394 // set the number of items to be shown in the control
396 // this is just a synonym for wxVScrolledWindow::SetLineCount()
397 void SetItemCount(size_t count);
399 // delete all items from the control
402 // set the selection to the specified item, if it is wxNOT_FOUND the
403 // selection is unset
405 // this function is only valid for the single selection listboxes
406 void SetSelection(int selection);
408 // selects or deselects the specified item which must be valid (i.e. not
409 // equal to wxNOT_FOUND)
411 // return True if the items selection status has changed or False
414 // this function is only valid for the multiple selection listboxes
415 bool Select(size_t item, bool select = true);
417 // selects the items in the specified range whose end points may be given
420 // return True if any items selection status has changed, False otherwise
422 // this function is only valid for the single selection listboxes
423 bool SelectRange(size_t from, size_t to);
425 // toggle the selection of the specified item (must be valid)
427 // this function is only valid for the multiple selection listboxes
428 void Toggle(size_t item);
430 // select all items in the listbox
432 // the return code indicates if any items were affected by this operation
433 // (True) or if nothing has changed (False)
436 // unselect all items in the listbox
438 // the return code has the same meaning as for SelectAll()
441 // set the margins: horizontal margin is the distance between the window
442 // border and the item contents while vertical margin is half of the
443 // distance between items
445 // by default both margins are 0
446 void SetMargins(const wxPoint& pt);
447 %Rename(SetMarginsXY, void, SetMargins(wxCoord x, wxCoord y));
449 // change the background colour of the selected cells
450 void SetSelectionBackground(const wxColour& col);
455 //---------------------------------------------------------------------------
459 #include <wx/htmllbox.h>
462 // First, the C++ version
464 class wxPyHtmlListBox : public wxHtmlListBox
466 DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox)
468 wxPyHtmlListBox() : wxHtmlListBox() {}
470 wxPyHtmlListBox(wxWindow *parent,
471 wxWindowID id = wxID_ANY,
472 const wxPoint& pos = wxDefaultPosition,
473 const wxSize& size = wxDefaultSize,
475 const wxString& name = wxPyVListBoxNameStr)
476 : wxHtmlListBox(parent, id, pos, size, style, name)
479 // Overridable virtuals
481 // this method must be implemented in the derived class and should return
482 // the body (i.e. without <html>) of the HTML for the given item
483 DEC_PYCALLBACK_STRING_SIZET_pure(OnGetItem);
485 // this function may be overridden to decorate HTML returned by OnGetItem()
486 DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup);
489 // // this method allows to customize the selection appearance: it may be used
490 // // to specify the colour of the text which normally has the given colour
491 // // colFg when it is inside the selection
493 // // by default, the original colour is not used at all and all text has the
494 // // same (default for this system) colour inside selection
495 // virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
497 // // this is the same as GetSelectedTextColour() but allows to customize the
498 // // background colour -- this is even more rarely used as you can change it
499 // // globally using SetSelectionBackground()
500 // virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
507 IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox)
509 IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem);
510 IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup);
516 // Now define this class for SWIG
519 // wxHtmlListBox is a listbox whose items are wxHtmlCells
520 MustHaveApp(wxPyHtmlListBox);
521 %rename(HtmlListBox) wxPyHtmlListBox;
522 class wxPyHtmlListBox : public wxPyVListBox
525 %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);self._setCallbackInfo(self, HtmlListBox)"
526 %pythonAppend wxPyHtmlListBox() ""
529 // normal constructor which calls Create() internally
530 wxPyHtmlListBox(wxWindow *parent,
531 wxWindowID id = wxID_ANY,
532 const wxPoint& pos = wxDefaultPosition,
533 const wxSize& size = wxDefaultSize,
535 const wxString& name = wxPyVListBoxNameStr);
537 %RenameCtor(PreHtmlListBox, wxPyHtmlListBox());
539 void _setCallbackInfo(PyObject* self, PyObject* _class);
541 bool Create(wxWindow *parent,
542 wxWindowID id = wxID_ANY,
543 const wxPoint& pos = wxDefaultPosition,
544 const wxSize& size = wxDefaultSize,
546 const wxString& name = wxPyVListBoxNameStr);
550 void SetItemCount(size_t count);
552 // retrieve the file system used by the wxHtmlWinParser: if you use
553 // relative paths in your HTML, you should use its ChangePathTo() method
554 wxFileSystem& GetFileSystem();
559 //---------------------------------------------------------------------------
562 // Map renamed classes back to their common name for OOR
563 wxPyPtrTypeMap_Add("wxHtmlListBox", "wxPyHtmlListBox");
564 wxPyPtrTypeMap_Add("wxVListBox", "wxPyVListBox");
565 wxPyPtrTypeMap_Add("wxVScrolledWindow", "wxPyVScrolledWindow");
568 //---------------------------------------------------------------------------