From 0b0f6f87d5112708311954fa4e9109e8ef77c05f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 24 Dec 2008 15:11:00 +0000 Subject: [PATCH] add convenient GetViewStart() and Scroll() overloads taking wxPoint instead of 2 int[ pointer]s git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57527 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/scrolwin.h | 11 ++++++----- include/wx/scrolwin.h | 18 +++++++++++++++--- interface/wx/scrolwin.h | 14 ++++++++++---- samples/scroll/scroll.cpp | 19 ++++--------------- src/generic/scrlwing.cpp | 4 ++-- src/gtk/scrolwin.cpp | 14 +++++++------- 6 files changed, 44 insertions(+), 36 deletions(-) diff --git a/include/wx/gtk/scrolwin.h b/include/wx/gtk/scrolwin.h index f99fb60c62..facf1d2b49 100644 --- a/include/wx/gtk/scrolwin.h +++ b/include/wx/gtk/scrolwin.h @@ -27,7 +27,6 @@ public: int xPos = 0, int yPos = 0, bool noRefresh = false); virtual void AdjustScrollbars(); - virtual void Scroll(int x, int y); protected: // this does (each) half of AdjustScrollbars() work @@ -60,10 +59,12 @@ protected: } // and this does the same for Scroll() - void DoScroll(int orient, - int pos, - int pixelsPerLine, - int *posOld); + void DoScrollOneDir(int orient, + int pos, + int pixelsPerLine, + int *posOld); + + virtual void DoScroll(int x, int y); private: DECLARE_NO_COPY_CLASS(wxScrollHelperNative) diff --git a/include/wx/scrolwin.h b/include/wx/scrolwin.h index 0ba4976501..4ef5499dac 100644 --- a/include/wx/scrolwin.h +++ b/include/wx/scrolwin.h @@ -62,13 +62,14 @@ public: bool noRefresh = false ); // scroll to the given (in logical coords) position - virtual void Scroll(int x, int y); + void Scroll(int x, int y) { DoScroll(x, y); } + void Scroll(const wxPoint& pt) { DoScroll(pt.x, pt.y); } // get/set the page size for this orientation (wxVERTICAL/wxHORIZONTAL) int GetScrollPageSize(int orient) const; void SetScrollPageSize(int orient, int pageSize); - // get the number of lines the window can scroll, + // get the number of lines the window can scroll, // returns 0 if no scrollbars are there. int GetScrollLines( int orient ) const; @@ -87,7 +88,14 @@ public: virtual void EnableScrolling(bool x_scrolling, bool y_scrolling); // Get the view start - virtual void GetViewStart(int *x, int *y) const; + void GetViewStart(int *x, int *y) const { DoGetViewStart(x, y); } + + wxPoint GetViewStart() const + { + wxPoint pt; + DoGetViewStart(&pt.x, &pt.y); + return pt; + } // Set the scale factor, used in PrepareDC void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; } @@ -191,6 +199,10 @@ protected: *h = size.y; } + // implementation of public methods with the same name + virtual void DoGetViewStart(int *x, int *y) const; + virtual void DoScroll(int x, int y); + // implementations of various wxWindow virtual methods which should be // forwarded to us (this can be done by WX_FORWARD_TO_SCROLL_HELPER()) bool ScrollLayout(); diff --git a/interface/wx/scrolwin.h b/interface/wx/scrolwin.h index aff424c547..b3664bee2e 100644 --- a/interface/wx/scrolwin.h +++ b/interface/wx/scrolwin.h @@ -251,6 +251,7 @@ public: */ void GetScrollPixelsPerUnit(int* xUnit, int* yUnit) const; + //@{ /** Get the position at which the visible portion of the window starts. @@ -268,9 +269,11 @@ public: have to multiply by the number of pixels per scroll increment. - @see SetScrollbars() + @see SetScrollbars(), Scroll() */ void GetViewStart(int* x, int* y) const; + wxPoint GetViewStart() const; + //@} /** Gets the size in device units of the scrollable window area (as @@ -313,6 +316,7 @@ public: */ void PrepareDC(wxDC& dc); + //@{ /** Scrolls a window so the view start is at the given point. @@ -323,13 +327,15 @@ public: @remarks The positions are in scroll units, not pixels, so to convert to pixels you will have to multiply by the number of - pixels per scroll increment. If either parameter is -1, - that position will be ignored (no change in that - direction). + pixels per scroll increment. If either parameter is + wxDefaultCoord (-1), that position will be ignored (no change + in that direction). @see SetScrollbars(), GetScrollPixelsPerUnit() */ void Scroll(int x, int y); + void Scroll(const wxPoint& pt); + //@} /** Set the horizontal and vertical scrolling increment only. See the diff --git a/samples/scroll/scroll.cpp b/samples/scroll/scroll.cpp index 2599f6787c..2186f19bbc 100644 --- a/samples/scroll/scroll.cpp +++ b/samples/scroll/scroll.cpp @@ -493,10 +493,7 @@ private: { m_inDoSync = true; - int x, y; - GetViewStart(&x, &y); - - m_winSync->Scroll(x, y); + m_winSync->Scroll(GetViewStart()); m_inDoSync = false; } @@ -771,9 +768,7 @@ void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) ) { wxLogMessage("Scrolling 2 units up.\n" "The white square and the controls should move equally!"); - int x,y; - GetViewStart( &x, &y ); - Scroll( wxDefaultCoord, y+2 ); + Scroll( wxDefaultCoord, GetViewStart().y+2 ); } // ---------------------------------------------------------------------------- @@ -1059,20 +1054,14 @@ MyAutoScrollingWindow::DeviceCoordsToGraphicalChars(wxPoint pos) const { pos.x /= m_fontW; pos.y /= m_fontH; - int vX, vY; - GetViewStart(&vX, &vY); - pos.x += vX; - pos.y += vY; + pos += GetViewStart(); return pos; } wxPoint MyAutoScrollingWindow::GraphicalCharToDeviceCoords(wxPoint pos) const { - int vX, vY; - GetViewStart(&vX, &vY); - pos.x -= vX; - pos.y -= vY; + pos -= GetViewStart(); pos.x *= m_fontW; pos.y *= m_fontH; return pos; diff --git a/src/generic/scrlwing.cpp b/src/generic/scrlwing.cpp index 55f429e48e..c393f20e6d 100644 --- a/src/generic/scrlwing.cpp +++ b/src/generic/scrlwing.cpp @@ -894,7 +894,7 @@ void wxScrollHelper::SetScrollPageSize(int orient, int pageSize) /* * Scroll to given position (scroll position, not pixel position) */ -void wxScrollHelper::Scroll( int x_pos, int y_pos ) +void wxScrollHelper::DoScroll( int x_pos, int y_pos ) { if (!m_targetWindow) return; @@ -973,7 +973,7 @@ void wxScrollHelper::EnableScrolling (bool x_scroll, bool y_scroll) } // Where the current view starts from -void wxScrollHelper::GetViewStart (int *x, int *y) const +void wxScrollHelper::DoGetViewStart (int *x, int *y) const { if ( x ) *x = m_xScrollPosition; diff --git a/src/gtk/scrolwin.cpp b/src/gtk/scrolwin.cpp index 2f9bc568fa..0447f58d42 100644 --- a/src/gtk/scrolwin.cpp +++ b/src/gtk/scrolwin.cpp @@ -163,10 +163,10 @@ void wxScrollHelperNative::AdjustScrollbars() } } -void wxScrollHelperNative::DoScroll(int orient, - int pos, - int pixelsPerLine, - int *posOld) +void wxScrollHelperNative::DoScrollOneDir(int orient, + int pos, + int pixelsPerLine, + int *posOld) { if ( pos != -1 && pos != *posOld && pixelsPerLine ) { @@ -181,10 +181,10 @@ void wxScrollHelperNative::DoScroll(int orient, } } -void wxScrollHelperNative::Scroll( int x_pos, int y_pos ) +void wxScrollHelperNative::DoScroll( int x_pos, int y_pos ) { wxCHECK_RET( m_targetWindow != 0, _T("No target window") ); - DoScroll(wxHORIZONTAL, x_pos, m_xScrollPixelsPerLine, &m_xScrollPosition); - DoScroll(wxVERTICAL, y_pos, m_yScrollPixelsPerLine, &m_yScrollPosition); + DoScrollOneDir(wxHORIZONTAL, x_pos, m_xScrollPixelsPerLine, &m_xScrollPosition); + DoScrollOneDir(wxVERTICAL, y_pos, m_yScrollPixelsPerLine, &m_yScrollPosition); } -- 2.45.2