]> git.saurik.com Git - wxWidgets.git/commitdiff
add convenient GetViewStart() and Scroll() overloads taking wxPoint instead of 2...
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 24 Dec 2008 15:11:00 +0000 (15:11 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 24 Dec 2008 15:11:00 +0000 (15:11 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57527 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/scrolwin.h
include/wx/scrolwin.h
interface/wx/scrolwin.h
samples/scroll/scroll.cpp
src/generic/scrlwing.cpp
src/gtk/scrolwin.cpp

index f99fb60c6203821d41c8b2689a59e6782e43a365..facf1d2b49fff5f7450eb013558f7e4b120e8b01 100644 (file)
@@ -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)
index 0ba4976501307350640ab18159f178bb114d2027..4ef5499dac9de9685a80063e9f8a4345b0011d35 100644 (file)
@@ -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();
index aff424c54770a90d8e8190deb3c4ce62a397fee1..b3664bee2ef805e7cbd96d48507486aaaeb8f90d 100644 (file)
@@ -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
index 2599f6787c85b9ef2f744af091a55f0f155ef583..2186f19bbcbd0b96bf6c1e6cb054e44509b57c6c 100644 (file)
@@ -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;
index 55f429e48e02c003470634f8012a19ff640dae4f..c393f20e6ddd8cbbc68a9a4b54eacaf58d5d719c 100644 (file)
@@ -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;
index 2f9bc568fa66cc6bedc1a9d6da3383a138c91040..0447f58d42ed14f9abb5add5e78fb14fcca4416c 100644 (file)
@@ -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);
 }