]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/scrlwing.cpp
fixed bug in ButtonHitTest() which caused invisible buttons to be pressable
[wxWidgets.git] / src / generic / scrlwing.cpp
index e2aced4a81044aa237d39e5d5c6275f34f021f91..92ebe1aedb1212de389b06435165c2e563f65a62 100644 (file)
@@ -38,9 +38,9 @@
     #if wxUSE_TIMER
         #include "wx/timer.h"
     #endif
+    #include "wx/sizer.h"
 #endif
 
-#include "wx/sizer.h"
 #include "wx/recguard.h"
 
 #ifdef __WXMSW__
@@ -311,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);
@@ -460,6 +462,11 @@ void wxScrollHelper::HandleOnScroll(wxScrollWinEvent& event)
         return;
     }
 
+    // flush all pending repaints before we change m_{x,y}ScrollPosition, as
+    // otherwise invalidated area could be updated incorrectly later when
+    // ScrollWindow() makes sure they're repainted before scrolling them
+    m_targetWindow->Update();
+
     int orient = event.GetOrientation();
     if (orient == wxHORIZONTAL)
     {
@@ -813,8 +820,17 @@ void wxScrollHelper::AdjustScrollbars()
 void wxScrollHelper::DoPrepareDC(wxDC& dc)
 {
     wxPoint pt = dc.GetDeviceOrigin();
-    dc.SetDeviceOrigin( pt.x - m_xScrollPosition * m_xScrollPixelsPerLine,
-                        pt.y - m_yScrollPosition * m_yScrollPixelsPerLine );
+#ifdef __WXGTK__
+    // It may actually be correct to always query
+    // the m_sign from the DC here, but I leve the
+    // #ifdef GTK for now.
+    if (m_win->GetLayoutDirection() == wxLayout_RightToLeft)
+        dc.SetDeviceOrigin( pt.x + m_xScrollPosition * m_xScrollPixelsPerLine,
+                            pt.y - m_yScrollPosition * m_yScrollPixelsPerLine );
+    else
+#endif
+        dc.SetDeviceOrigin( pt.x - m_xScrollPosition * m_xScrollPixelsPerLine,
+                            pt.y - m_yScrollPosition * m_yScrollPixelsPerLine );
     dc.SetUserScale( m_scaleX, m_scaleY );
 }
 
@@ -844,6 +860,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 )
@@ -874,6 +899,11 @@ void wxScrollHelper::Scroll( int x_pos, int y_pos )
     int w = 0, h = 0;
     GetTargetSize(&w, &h);
 
+    // flush all pending repaints before we change m_{x,y}ScrollPosition, as
+    // otherwise invalidated area could be updated incorrectly later when
+    // ScrollWindow() makes sure they're repainted before scrolling them
+    m_targetWindow->Update();
+
     if ((x_pos != -1) && (m_xScrollPixelsPerLine))
     {
         int old_x = m_xScrollPosition;
@@ -881,7 +911,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
@@ -889,7 +919,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() );
@@ -902,7 +933,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
@@ -910,7 +941,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() );