X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b9048c56f0aa04b2adbb7813f9698abdda15184..30e24d9dd5a5abf1c9a375ea259eb239b122b7f7:/wxPython/src/_vscroll.i?ds=sidebyside diff --git a/wxPython/src/_vscroll.i b/wxPython/src/_vscroll.i index 90b84d9012..546c0db92b 100644 --- a/wxPython/src/_vscroll.i +++ b/wxPython/src/_vscroll.i @@ -35,7 +35,7 @@ %{ class wxPyVScrolledWindow : public wxVScrolledWindow { - DECLARE_ABSTRACT_CLASS(wxPyVScrolledWindow); + DECLARE_ABSTRACT_CLASS(wxPyVScrolledWindow) public: wxPyVScrolledWindow() : wxVScrolledWindow() {} @@ -87,7 +87,7 @@ public: // find the index of the line we need to show at the top of the window such // that the last (fully or partially) visible line is the given one - size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = False) + size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false) { return wxVScrolledWindow::FindFirstFromBottom(lineLast, fullyVisible); } // get the total height of the lines between lineMin (inclusive) and @@ -95,6 +95,11 @@ public: wxCoord GetLinesHeight(size_t lineMin, size_t lineMax) const { return wxVScrolledWindow::GetLinesHeight(lineMin, lineMax); } + // update the thumb size shown by the scrollbar + void UpdateScrollbar() { wxVScrolledWindow::UpdateScrollbar(); } + + // remove the scrollbar completely because we don't need it + void RemoveScrollbar() { wxVScrolledWindow::RemoveScrollbar(); } PYPRIVATE; }; @@ -125,10 +130,13 @@ IMP_PYCALLBACK_COORD_const (wxPyVScrolledWindow, wxVScrolledWindow, Est of the window and not its entire client area. */ -%name(VScrolledWindow) class wxPyVScrolledWindow : public wxPanel +MustHaveApp(wxPyVScrolledWindow); + +%rename(VScrolledWindow) wxPyVScrolledWindow; +class wxPyVScrolledWindow : public wxPanel { public: - %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self); self._setCallbackInfo(self, VScrolledWindow)" + %pythonAppend wxPyVScrolledWindow "self._setOORInfo(self);" setCallbackInfo(VScrolledWindow) %pythonAppend wxPyVScrolledWindow() "" @@ -139,7 +147,7 @@ public: long style = 0, const wxString& name = wxPyPanelNameStr); - %name(PreVScrolledWindow)wxPyVScrolledWindow(); + %RenameCtor(PreVScrolledWindow, wxPyVScrolledWindow()); void _setCallbackInfo(PyObject* self, PyObject* _class); @@ -174,7 +182,7 @@ public: // return the item at the specified (in physical coordinates) position or // wxNOT_FOUND if none, i.e. if it is below the last item - %name(HitTestXT) int HitTest(wxCoord x, wxCoord y) const; + %Rename(HitTestXY, int, HitTest(wxCoord x, wxCoord y) const); int HitTest(const wxPoint& pt) const; // recalculate all our parameters and redisplay all lines @@ -186,16 +194,42 @@ public: size_t GetLineCount() const; // get the first currently visible line - size_t GetFirstVisibleLine() const; + size_t GetVisibleBegin() const; // get the last currently visible line - size_t GetLastVisibleLine() const; + size_t GetVisibleEnd() const; // is this line currently visible? bool IsVisible(size_t line) const; + // this is the same as GetVisibleBegin(), exists to match + // GetLastVisibleLine() and for backwards compatibility only + size_t GetFirstVisibleLine() const; + + // get the last currently visible line + // + // this function is unsafe as it returns (size_t)-1 (i.e. a huge positive + // number) if the control is empty, use GetVisibleEnd() instead, this one + // is kept for backwards compatibility + size_t GetLastVisibleLine() const; + + // find the index of the line we need to show at the top of the window such + // that the last (fully or partially) visible line is the given one + size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false); + + // get the total height of the lines between lineMin (inclusive) and + // lineMax (exclusive) + wxCoord GetLinesHeight(size_t lineMin, size_t lineMax) const; + + %property(FirstVisibleLine, GetFirstVisibleLine, doc="See `GetFirstVisibleLine`"); + %property(LastVisibleLine, GetLastVisibleLine, doc="See `GetLastVisibleLine`"); + %property(LineCount, GetLineCount, SetLineCount, doc="See `GetLineCount` and `SetLineCount`"); + %property(VisibleBegin, GetVisibleBegin, doc="See `GetVisibleBegin`"); + %property(VisibleEnd, GetVisibleEnd, doc="See `GetVisibleEnd`"); }; + + //--------------------------------------------------------------------------- // wxVListBox @@ -210,7 +244,7 @@ MAKE_CONST_WXSTRING(VListBoxNameStr); %{ class wxPyVListBox : public wxVListBox { - DECLARE_ABSTRACT_CLASS(wxPyVListBox); + DECLARE_ABSTRACT_CLASS(wxPyVListBox) public: wxPyVListBox() : wxVListBox() {} @@ -243,7 +277,7 @@ public: // // the base class version doesn't do anything // virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const; - DEC_PYCALLBACK__DCRECTSIZET_constpure(OnDrawSeparator); + DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator); // this method is used to draw the items background and, maybe, a border @@ -264,7 +298,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxPyVListBox, wxVListBox); IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawItem); IMP_PYCALLBACK_COORD_SIZET_constpure (wxPyVListBox, wxVListBox, OnMeasureItem); -IMP_PYCALLBACK__DCRECTSIZET_constpure(wxPyVListBox, wxVListBox, OnDrawSeparator); +IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyVListBox, wxVListBox, OnDrawSeparator); IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground); %} @@ -282,10 +316,13 @@ IMP_PYCALLBACK__DCRECTSIZET_const (wxPyVListBox, wxVListBox, OnDrawBackground It emits the same events as wxListBox and the same event macros may be used with it. */ -%name(VListBox) class wxPyVListBox : public wxPyVScrolledWindow +MustHaveApp(wxPyVListBox); + +%rename(VListBox) wxPyVListBox; +class wxPyVListBox : public wxPyVScrolledWindow { public: - %pythonAppend wxPyVListBox "self._setOORInfo(self);self._setCallbackInfo(self, VListBox)" + %pythonAppend wxPyVListBox "self._setOORInfo(self);" setCallbackInfo(VListBox) %pythonAppend wxPyVListBox() "" @@ -296,7 +333,7 @@ public: long style = 0, const wxString& name = wxPyVListBoxNameStr); - %name(PreVListBox) wxPyVListBox(); + %RenameCtor(PreVListBox, wxPyVListBox()); void _setCallbackInfo(PyObject* self, PyObject* _class); @@ -329,22 +366,44 @@ public: // this method is valid for both single and multi selection listboxes size_t GetSelectedCount() const; - // get the first selected item, returns wxNOT_FOUND if none - // - // cookie is an opaque parameter which should be passed to - // GetNextSelected() later - // - // this method is only valid for the multi selection listboxes - int GetFirstSelected(unsigned long& cookie) const; - - // get next selection item, return wxNOT_FOUND if no more - // - // cookie must be the same parameter that was passed to GetFirstSelected() - // before - // - // this method is only valid for the multi selection listboxes - int GetNextSelected(unsigned long& cookie) const; + %extend { + // get the first selected item, returns wxNOT_FOUND if none + // + // cookie is an opaque parameter which should be passed to + // GetNextSelected() later + // + // this method is only valid for the multi selection listboxes + //int GetFirstSelected(unsigned long& cookie) const; + PyObject* GetFirstSelected() { + unsigned long cookie = 0; + int selected = self->GetFirstSelected(cookie); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + PyObject* tup = PyTuple_New(2); + PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected)); + PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie)); + wxPyEndBlockThreads(blocked); + return tup; + } + + // get next selection item, return wxNOT_FOUND if no more + // + // cookie must be the same parameter that was passed to GetFirstSelected() + // before + // + // this method is only valid for the multi selection listboxes + // int GetNextSelected(unsigned long& cookie) const; + PyObject* GetNextSelected(unsigned long cookie) { + int selected = self->GetNextSelected(cookie); + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + PyObject* tup = PyTuple_New(2); + PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(selected)); + PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie)); + wxPyEndBlockThreads(blocked); + return tup; + } + } + // get the margins around each item wxPoint GetMargins() const; @@ -373,7 +432,7 @@ public: // otherwise // // this function is only valid for the multiple selection listboxes - bool Select(size_t item, bool select = True); + bool Select(size_t item, bool select = true); // selects the items in the specified range whose end points may be given // in any order @@ -405,11 +464,20 @@ public: // // by default both margins are 0 void SetMargins(const wxPoint& pt); - %name(SetMarginsXY) void SetMargins(wxCoord x, wxCoord y); + %Rename(SetMarginsXY, void, SetMargins(wxCoord x, wxCoord y)); // change the background colour of the selected cells void SetSelectionBackground(const wxColour& col); + virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const; + virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const; + + %property(FirstSelected, GetFirstSelected, doc="See `GetFirstSelected`"); + %property(ItemCount, GetItemCount, SetItemCount, doc="See `GetItemCount` and `SetItemCount`"); + %property(Margins, GetMargins, SetMargins, doc="See `GetMargins` and `SetMargins`"); + %property(SelectedCount, GetSelectedCount, doc="See `GetSelectedCount`"); + %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`"); + %property(SelectionBackground, GetSelectionBackground, SetSelectionBackground, doc="See `GetSelectionBackground` and `SetSelectionBackground`"); }; @@ -424,7 +492,7 @@ public: %{ class wxPyHtmlListBox : public wxHtmlListBox { - DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox); + DECLARE_ABSTRACT_CLASS(wxPyHtmlListBox) public: wxPyHtmlListBox() : wxHtmlListBox() {} @@ -446,6 +514,10 @@ public: // this function may be overridden to decorate HTML returned by OnGetItem() DEC_PYCALLBACK_STRING_SIZET(OnGetItemMarkup); + // These are from wxVListBox + DEC_PYCALLBACK__DCRECTSIZET2_const(OnDrawSeparator); + DEC_PYCALLBACK__DCRECTSIZET_const(OnDrawBackground); + // TODO: // // this method allows to customize the selection appearance: it may be used // // to specify the colour of the text which normally has the given colour @@ -460,6 +532,11 @@ public: // // globally using SetSelectionBackground() // virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const; + + // This method may be overriden to handle clicking on a link in + // the listbox. By default, clicking links is ignored. + virtual void OnLinkClicked(size_t n, + const wxHtmlLinkInfo& link); PYPRIVATE; }; @@ -469,7 +546,24 @@ IMPLEMENT_ABSTRACT_CLASS(wxPyHtmlListBox, wxHtmlListBox) IMP_PYCALLBACK_STRING_SIZET_pure(wxPyHtmlListBox, wxHtmlListBox, OnGetItem); IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup); - +IMP_PYCALLBACK__DCRECTSIZET2_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawSeparator); +IMP_PYCALLBACK__DCRECTSIZET_const (wxPyHtmlListBox, wxHtmlListBox, OnDrawBackground); + + +void wxPyHtmlListBox::OnLinkClicked(size_t n, + const wxHtmlLinkInfo& link) { + bool found; + wxPyBlock_t blocked = wxPyBeginBlockThreads(); + if ((found = wxPyCBH_findCallback(m_myInst, "OnLinkClicked"))) { + PyObject* obj = wxPyConstructObject((void*)&link, wxT("wxHtmlLinkInfo"), 0); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iO)", n, obj)); + Py_DECREF(obj); + } + wxPyEndBlockThreads(blocked); + if (! found) + wxPyHtmlListBox::OnLinkClicked(n, link); +} + %} @@ -478,10 +572,12 @@ IMP_PYCALLBACK_STRING_SIZET (wxPyHtmlListBox, wxHtmlListBox, OnGetItemMarkup // wxHtmlListBox is a listbox whose items are wxHtmlCells -%name(HtmlListBox) class wxPyHtmlListBox : public wxPyVListBox +MustHaveApp(wxPyHtmlListBox); +%rename(HtmlListBox) wxPyHtmlListBox; +class wxPyHtmlListBox : public wxPyVListBox { public: - %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);self._setCallbackInfo(self, HtmlListBox)" + %pythonAppend wxPyHtmlListBox "self._setOORInfo(self);" setCallbackInfo(HtmlListBox) %pythonAppend wxPyHtmlListBox() "" @@ -493,7 +589,7 @@ public: long style = 0, const wxString& name = wxPyVListBoxNameStr); - %name(PreHtmlListBox) wxPyHtmlListBox(); + %RenameCtor(PreHtmlListBox, wxPyHtmlListBox()); void _setCallbackInfo(PyObject* self, PyObject* _class); @@ -508,10 +604,59 @@ public: void RefreshAll(); void SetItemCount(size_t count); + // retrieve the file system used by the wxHtmlWinParser: if you use + // relative paths in your HTML, you should use its ChangePathTo() method + wxFileSystem& GetFileSystem(); + + void OnLinkClicked(size_t n, const wxHtmlLinkInfo& link); + + %property(FileSystem, GetFileSystem, doc="See `GetFileSystem`"); }; +//--------------------------------------------------------------------------- + +%{ + const wxArrayString wxPyEmptyStringArray; +%} +MAKE_CONST_WXSTRING(SimpleHtmlListBoxNameStr); + + +enum { + wxHLB_DEFAULT_STYLE, + wxHLB_MULTIPLE +}; + +MustHaveApp(wxSimpleHtmlListBox); + +class wxSimpleHtmlListBox : public wxPyHtmlListBox, + public wxItemContainer +{ +public: + %pythonAppend wxSimpleHtmlListBox "self._setOORInfo(self)"; + %pythonAppend wxSimpleHtmlListBox() ""; + + wxSimpleHtmlListBox(wxWindow *parent, + wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + const wxArrayString& choices = wxPyEmptyStringArray, + long style = wxHLB_DEFAULT_STYLE, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPySimpleHtmlListBoxNameStr); + %RenameCtor(PreSimpleHtmlListBox, wxSimpleHtmlListBox()); + + bool Create(wxWindow *parent, + wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size= wxDefaultSize, + const wxArrayString& choices = wxPyEmptyStringArray, + long style = wxHLB_DEFAULT_STYLE, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPySimpleHtmlListBoxNameStr); +}; + //--------------------------------------------------------------------------- %init %{