]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/vscroll.cpp
compile fix
[wxWidgets.git] / src / generic / vscroll.cpp
index abe374f694957200ede299d5b31d061306a15c19..d8d57b6e97f46986d00bdef1bc229bdb4a5f1d4b 100644 (file)
@@ -17,7 +17,7 @@
 // headers
 // ----------------------------------------------------------------------------
 
-#if defined(__GNUG__) && !defined(__APPLE__)
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 #pragma implementation "vscroll.h"
 #endif
 
@@ -37,6 +37,9 @@
 BEGIN_EVENT_TABLE(wxVScrolledWindow, wxPanel)
     EVT_SIZE(wxVScrolledWindow::OnSize)
     EVT_SCROLLWIN(wxVScrolledWindow::OnScroll)
+#if wxUSE_MOUSEWHEEL
+    EVT_MOUSEWHEEL(wxVScrolledWindow::OnMouseWheel)
+#endif
 END_EVENT_TABLE()
 
 
@@ -60,6 +63,10 @@ void wxVScrolledWindow::Init()
     m_nVisible = 1;
 
     m_heightTotal = 0;
+
+#if wxUSE_MOUSEWHEEL
+    m_sumWheelRotation = 0;
+#endif
 }
 
 // ----------------------------------------------------------------------------
@@ -92,7 +99,7 @@ wxCoord wxVScrolledWindow::EstimateTotalHeight() const
 
         // use the height of the lines we looked as the average
         heightTotal = (wxCoord)
-                (((float)m_heightTotal / (3*NUM_LINES_TO_SAMPLE)) * m_lineMax);
+                (((float)heightTotal / (3*NUM_LINES_TO_SAMPLE)) * m_lineMax);
     }
 
     return heightTotal;
@@ -374,6 +381,7 @@ void wxVScrolledWindow::OnScroll(wxScrollWinEvent& event)
     size_t lineFirstNew;
 
     const wxEventType evtType = event.GetEventType();
+
     if ( evtType == wxEVT_SCROLLWIN_TOP )
     {
         lineFirstNew = 0;
@@ -398,21 +406,19 @@ void wxVScrolledWindow::OnScroll(wxScrollWinEvent& event)
     {
         lineFirstNew = GetLastVisibleLine();
     }
-    else // unknown scroll event?
+    else if ( evtType == wxEVT_SCROLLWIN_THUMBRELEASE )
     {
-        if ( evtType == wxEVT_SCROLLWIN_THUMBRELEASE )
-        {
-            lineFirstNew = event.GetPosition();
-        }
-        else
-        {
-            wxASSERT_MSG( evtType == wxEVT_SCROLLWIN_THUMBTRACK,
-                            _T("unknown scroll event type?") );
+        lineFirstNew = event.GetPosition();
+    }
+    else if ( evtType == wxEVT_SCROLLWIN_THUMBTRACK )
+    {
+        lineFirstNew = event.GetPosition();
+    }
 
-            // don't do anything, otherwise dragging the thumb around would
-            // be too slow
-            return;
-        }
+    else // unknown scroll event?
+    {
+        wxFAIL_MSG( _T("unknown scroll event type?") );
+        return;
     }
 
     ScrollToLine(lineFirstNew);
@@ -422,3 +428,25 @@ void wxVScrolledWindow::OnScroll(wxScrollWinEvent& event)
 #endif // __WXMAC__
 }
 
+#if wxUSE_MOUSEWHEEL
+
+void wxVScrolledWindow::OnMouseWheel(wxMouseEvent& event)
+{
+    m_sumWheelRotation += event.GetWheelRotation();
+    int delta = event.GetWheelDelta();
+
+    // how much to scroll this time
+    int units_to_scroll = -(m_sumWheelRotation/delta);
+    if ( !units_to_scroll )
+        return;
+
+    m_sumWheelRotation += units_to_scroll*delta;
+
+    if ( !event.IsPageScroll() )
+        ScrollLines( units_to_scroll*event.GetLinesPerAction() );
+    else
+        // scroll pages instead of lines
+        ScrollPages( units_to_scroll );
+}
+
+#endif