tmf: Support horizontal scroll with mouse wheel in time graph
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 15 Mar 2016 17:38:15 +0000 (13:38 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Fri, 18 Mar 2016 03:06:25 +0000 (23:06 -0400)
Horizontal scroll can now be performed using Shift+MouseWheel while over
the time graph control state area.

MouseWheel over the time scale, marker axis and horizontal scroll bar
will now perform horizontal scroll, while Ctrl+MouseWheel over those
same controls will now perform horizontal zoom.

Table of MouseWheel actions:

modifier:      None       Shift      Ctrl     Shift+Ctrl
time scale     hScroll    hScroll    hZoom    hZoom
time graph     vScroll    hScroll    hZoom    vZoom
marker axis    hScroll    hScroll    hZoom    hZoom
h.scrollbar    hScroll    hScroll    hZoom    hZoom
v.scrollbar    vScroll    vScroll    vScroll  vScroll
outside (Win)  vScroll    vScroll    vScroll  vScroll

Change-Id: I0e48dd37b121b934ef872509aa721506876ca199
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/68464
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
doc/org.eclipse.tracecompass.doc.user/doc/User-Guide.mediawiki
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java

index 97efe2a93ca0555c8620fbbab5fad0cdefc60850..90bce496f1c499914be844166e584198554c1474 100644 (file)
@@ -1656,6 +1656,7 @@ The states flow is usable with the mouse. The following actions are set:
 * '''right-drag horizontally''': [[#Zoom region|zoom region]]
 * '''click on a colored bar''': the associated process node is selected and the current time indicator is moved where the click happened
 * '''mouse wheel up/down''': scroll up or down
+* '''Shift-mouse wheel up/down''': scroll left or right
 * '''Ctrl-mouse wheel up/down''': zoom in or out horizontally
 * '''Shift-Ctrl-mouse wheel up/down''': zoom in or out vertically
 * '''drag the time ruler horizontally''': zoom in or out with fixed start time
index 76de9c8963aee9f21c358b2260052b31c84bf607..44b32075e40b0c9fa58518e21d2307158c7ea6b9 100644 (file)
@@ -52,6 +52,7 @@ import org.eclipse.swt.events.MouseWheelListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.RGBA;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.layout.FillLayout;
@@ -505,7 +506,11 @@ public class TimeGraphViewer implements ITimeDataProvider, IMarkerAxisListener,
                 if (e.count == 0) {
                     return;
                 }
-                fTimeGraphCtrl.zoom(e.count > 0);
+                if ((e.stateMask & SWT.CTRL) != 0) {
+                    fTimeGraphCtrl.zoom(e.count > 0);
+                } else {
+                    fTimeGraphCtrl.horizontalScroll(e.count > 0);
+                }
             }
         });
 
@@ -521,7 +526,28 @@ public class TimeGraphViewer implements ITimeDataProvider, IMarkerAxisListener,
                 if (e.count == 0) {
                     return;
                 }
-                adjustVerticalScrollBar();
+                /*
+                 * On some platforms the mouse scroll event is sent to the
+                 * control that has focus even if it is not under the cursor.
+                 * Handle the event only if not over the time graph control.
+                 */
+                Point ctrlParentCoords = fTimeAlignedComposite.toControl(fTimeGraphCtrl.toDisplay(e.x, e.y));
+                Point scrollBarParentCoords = fDataViewer.toControl(fTimeGraphCtrl.toDisplay(e.x, e.y));
+                if (fTimeGraphCtrl.getBounds().contains(ctrlParentCoords)) {
+                    /* the time graph control handles the event */
+                    adjustVerticalScrollBar();
+                } else if (fTimeScaleCtrl.getBounds().contains(ctrlParentCoords)
+                        || fMarkerAxisCtrl.getBounds().contains(ctrlParentCoords)
+                        || fHorizontalScrollBar.getBounds().contains(scrollBarParentCoords)) {
+                    if ((e.stateMask & SWT.CTRL) != 0) {
+                        fTimeGraphCtrl.zoom(e.count > 0);
+                    } else {
+                        fTimeGraphCtrl.horizontalScroll(e.count > 0);
+                    }
+                } else {
+                    /* over the vertical scroll bar or outside of the viewer */
+                    setTopIndex(getTopIndex() - e.count);
+                }
             }
         });
         fTimeGraphCtrl.addKeyListener(new KeyAdapter() {
@@ -559,7 +585,11 @@ public class TimeGraphViewer implements ITimeDataProvider, IMarkerAxisListener,
                 if (e.count == 0) {
                     return;
                 }
-                fTimeGraphCtrl.zoom(e.count > 0);
+                if ((e.stateMask & SWT.CTRL) != 0) {
+                    fTimeGraphCtrl.zoom(e.count > 0);
+                } else {
+                    fTimeGraphCtrl.horizontalScroll(e.count > 0);
+                }
             }
         });
 
@@ -582,10 +612,10 @@ public class TimeGraphViewer implements ITimeDataProvider, IMarkerAxisListener,
                 if (event.count == 0) {
                     return;
                 }
-                if ((event.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL) {
-                    getTimeGraphControl().zoom(event.count > 0);
+                if ((event.stateMask & SWT.CTRL) != 0) {
+                    fTimeGraphCtrl.zoom(event.count > 0);
                 } else {
-                    getTimeGraphControl().horizontalScroll(event.count > 0);
+                    fTimeGraphCtrl.horizontalScroll(event.count > 0);
                 }
             }
         });
index e02e3058ff37fcee25ca1fd11018994e999d7b10..c0d42d7bd595cf49c8246172bf5e0fcabfc10f24 100644 (file)
@@ -2700,61 +2700,53 @@ public class TimeGraphControl extends TimeGraphBaseControl
         if (fDragState != DRAG_NONE || e.count == 0) {
             return;
         }
+
+        /*
+         * On some platforms the mouse scroll event is sent to the
+         * control that has focus even if it is not under the cursor.
+         * Handle the event only if over the time graph control.
+         */
+        Point size = getSize();
+        Rectangle bounds = new Rectangle(0, 0, size.x, size.y);
+        if (!bounds.contains(e.x, e.y)) {
+            return;
+        }
+
         boolean horizontalZoom = false;
         boolean horizontalScroll = false;
         boolean verticalZoom = false;
-        Point p = getParent().toControl(getDisplay().getCursorLocation());
-        Point parentSize = getParent().getSize();
-        if (p.x >= 0 && p.x < parentSize.x && p.y >= 0 && p.y < parentSize.y) {
-            // over the parent control
-            if (e.x > getSize().x) {
-                // over the vertical scroll bar
-                if ((e.stateMask & SWT.MODIFIER_MASK) == (SWT.SHIFT | SWT.CTRL)) {
-                    verticalZoom = true;
-                }
-            } else if (e.y < 0) {
-                // over the time scale
-                horizontalZoom = true;
-            } else if (e.y >= getSize().y) {
-                // over the marker axis
+        boolean verticalScroll = false;
+
+        // over the time graph control
+        if ((e.stateMask & SWT.MODIFIER_MASK) == (SWT.SHIFT | SWT.CTRL)) {
+            verticalZoom = true;
+        } else if (e.x < fTimeProvider.getNameSpace()) {
+            // over the name space
+            verticalScroll = true;
+        } else {
+            // over the state area
+            if ((e.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL) {
+                // over the state area, CTRL pressed
                 horizontalZoom = true;
+            } else if ((e.stateMask & SWT.MODIFIER_MASK) == SWT.SHIFT) {
+                // over the state area, SHIFT pressed
+                horizontalScroll = true;
             } else {
-                if ((e.stateMask & SWT.MODIFIER_MASK) == (SWT.SHIFT | SWT.CTRL)) {
-                    verticalZoom = true;
-                } else if (e.x < fTimeProvider.getNameSpace()) {
-                    // over the name space
-                    horizontalZoom = false;
-                } else {
-                    // over the state area
-                    if ((e.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL) {
-                        // over the state area, CTRL pressed
-                        horizontalZoom = true;
-                    } else {
-                        // over the state area, CTRL not pressed
-                        horizontalZoom = false;
-                    }
-                }
+                // over the state area, no modifier pressed
+                verticalScroll = true;
             }
         }
         if (verticalZoom) {
             fVerticalZoomAlignEntry = getVerticalZoomAlignCursor(e.y);
-            if (e.count > 0) {
-                verticalZoom(true);
-            } else if (e.count < 0) {
-                verticalZoom(false);
-            }
+            verticalZoom(e.count > 0);
             if (fVerticalZoomAlignEntry != null) {
                 setElementPosition(fVerticalZoomAlignEntry.getKey(), fVerticalZoomAlignEntry.getValue());
             }
         } else if (horizontalZoom && fTimeProvider.getTime0() != fTimeProvider.getTime1()) {
-            if (e.count > 0) {
-                zoom(true);
-            } else if (e.count < 0) {
-                zoom(false);
-            }
+            zoom(e.count > 0);
         } else if (horizontalScroll) {
             horizontalScroll(e.count > 0);
-        } else {
+        } else if (verticalScroll){
             setTopIndex(getTopIndex() - e.count);
         }
     }
This page took 0.031185 seconds and 5 git commands to generate.