]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/vscroll.cpp
added XRC handler for wxStdDialogButtonSizer
[wxWidgets.git] / src / generic / vscroll.cpp
index e592f8054169030b2e9e3e99e83a40a03f43880d..d8d57b6e97f46986d00bdef1bc229bdb4a5f1d4b 100644 (file)
@@ -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
 }
 
 // ----------------------------------------------------------------------------
@@ -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