]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/scrlwing.cpp
GetScrollLines?
[wxWidgets.git] / src / generic / scrlwing.cpp
index 53b6270584321450c34b2645f8f97925b6a84637..b6646136f1167d39cbeb459c518a3c4346686eff 100644 (file)
     #include "wx/utils.h"
     #include "wx/panel.h"
     #include "wx/dcclient.h"
+    #if wxUSE_TIMER
+        #include "wx/timer.h"
+    #endif
+    #include "wx/sizer.h"
 #endif
 
-#if wxUSE_TIMER
-    #include "wx/timer.h"
-#endif
-
-#include "wx/sizer.h"
 #include "wx/recguard.h"
 
 #ifdef __WXMSW__
@@ -312,6 +311,8 @@ wxScrollHelper::wxScrollHelper(wxWindow *win)
     m_handler = NULL;
 
     m_win = win;
+    
+    m_win->SetScrollHelper( this );
 
     // by default, the associated window is also the target window
     DoSetTargetWindow(win);
@@ -845,6 +846,15 @@ void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const
         *y_unit = m_yScrollPixelsPerLine;
 }
 
+
+int wxScrollHelper::GetScrollLines( int orient ) const
+{
+    if ( orient == wxHORIZONTAL )
+        return m_xScrollLines;
+    else
+        return m_yScrollLines;
+}
+
 int wxScrollHelper::GetScrollPageSize(int orient) const
 {
     if ( orient == wxHORIZONTAL )
@@ -882,7 +892,7 @@ void wxScrollHelper::Scroll( int x_pos, int y_pos )
 
         // Calculate page size i.e. number of scroll units you get on the
         // current client window
-        int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
+        int noPagePositions = w/m_xScrollPixelsPerLine;
         if (noPagePositions < 1) noPagePositions = 1;
 
         // Correct position if greater than extent of canvas minus
@@ -890,7 +900,8 @@ void wxScrollHelper::Scroll( int x_pos, int y_pos )
         m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition );
         m_xScrollPosition = wxMax( 0, m_xScrollPosition );
 
-        if (old_x != m_xScrollPosition) {
+        if (old_x != m_xScrollPosition)
+        {
             m_win->SetScrollPos( wxHORIZONTAL, m_xScrollPosition );
             m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0,
                                           GetScrollRect() );
@@ -903,7 +914,7 @@ void wxScrollHelper::Scroll( int x_pos, int y_pos )
 
         // Calculate page size i.e. number of scroll units you get on the
         // current client window
-        int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
+        int noPagePositions = h/m_yScrollPixelsPerLine;
         if (noPagePositions < 1) noPagePositions = 1;
 
         // Correct position if greater than extent of canvas minus
@@ -911,7 +922,8 @@ void wxScrollHelper::Scroll( int x_pos, int y_pos )
         m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
         m_yScrollPosition = wxMax( 0, m_yScrollPosition );
 
-        if (old_y != m_yScrollPosition) {
+        if (old_y != m_yScrollPosition)
+        {
             m_win->SetScrollPos( wxVERTICAL, m_yScrollPosition );
             m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine,
                                           GetScrollRect() );
@@ -937,7 +949,33 @@ void wxScrollHelper::GetViewStart (int *x, int *y) const
 void wxScrollHelper::DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const
 {
     if ( xx )
-        *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine;
+    {
+        if ((m_xScrollLines == 0) || (m_xScrollPixelsPerLine == 0))
+        {
+            // nothing to do
+            *xx = x;
+        }
+        else
+        {
+#ifdef __WXGTK__
+            if (m_win->GetLayoutDirection() == wxLayout_RightToLeft)
+            {
+                int w = 0, h = 0;
+                GetTargetSize(&w, &h);
+
+                // Calculate page size i.e. number of scroll units you get on the
+                // current client window
+                int noPagePositions = w/m_xScrollPixelsPerLine;
+                if (noPagePositions < 1) noPagePositions = 1;
+                *xx = x - ((m_xScrollLines - noPagePositions - m_xScrollPosition) * m_xScrollPixelsPerLine);
+            }
+            else
+#endif
+            {
+                *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine;
+            }
+        }
+    }
     if ( yy )
         *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine;
 }
@@ -945,7 +983,33 @@ void wxScrollHelper::DoCalcScrolledPosition(int x, int y, int *xx, int *yy) cons
 void wxScrollHelper::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
 {
     if ( xx )
-        *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine;
+    {
+        if ((m_xScrollLines == 0) || (m_xScrollPixelsPerLine == 0))
+        {
+            // nothing to do
+            *xx = x;
+        }
+        else
+        {
+#ifdef __WXGTK__
+            if (m_win->GetLayoutDirection() == wxLayout_RightToLeft)
+            {
+                int w = 0, h = 0;
+                GetTargetSize(&w, &h);
+
+                // Calculate page size i.e. number of scroll units you get on the
+                // current client window
+                int noPagePositions = w/m_xScrollPixelsPerLine;
+                if (noPagePositions < 1) noPagePositions = 1;
+                *xx = x + ((m_xScrollLines - noPagePositions - m_xScrollPosition) * m_xScrollPixelsPerLine);
+            }
+            else
+#endif
+            {
+                *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine;
+            }
+        }
+    }
     if ( yy )
         *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine;
 }