diff --git a/Terminal.Gui/Core.cs b/Terminal.Gui/Core.cs
index 0078fce55..856a6fb63 100644
--- a/Terminal.Gui/Core.cs
+++ b/Terminal.Gui/Core.cs
@@ -2273,8 +2273,12 @@ namespace Terminal.Gui {
OfY = me.Y - newxy.Y,
View = view
};
- mouseGrabView.MouseEvent (nme);
- return;
+ if (OutsideFrame (new Point (nme.X, nme.Y), mouseGrabView.Frame))
+ lastMouseOwnerView.OnMouseLeave (me);
+ if (mouseGrabView != null) {
+ mouseGrabView.MouseEvent (nme);
+ return;
+ }
}
if (view != null) {
@@ -2309,6 +2313,11 @@ namespace Terminal.Gui {
}
}
+ static bool OutsideFrame (Point p, Rect r)
+ {
+ return p.X < 0 || p.X > r.Width - 1 || p.Y < 0 || p.Y > r.Height - 1;
+ }
+
///
/// Action that is invoked once at beginning.
///
diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs
index b10e567b2..e67f43eed 100644
--- a/Terminal.Gui/Views/ScrollView.cs
+++ b/Terminal.Gui/Views/ScrollView.cs
@@ -14,6 +14,8 @@
// - Perhaps allow an option to not display the scrollbar arrow indicators?
using System;
+using System.Reflection;
+
namespace Terminal.Gui {
///
/// ScrollBarViews are views that display a 1-character scrollbar, either horizontal or vertical
@@ -73,7 +75,7 @@ namespace Terminal.Gui {
/// Frame for the scrollbar.
/// The size that this scrollbar represents.
/// The position within this scrollbar.
- /// If set to true this is a vertical scrollbar, otherwize, the scrollbar is horizontal.
+ /// If set to true this is a vertical scrollbar, otherwise, the scrollbar is horizontal.
public ScrollBarView (Rect rect, int size, int position, bool isVertical) : base (rect)
{
vertical = isVertical;
@@ -314,9 +316,35 @@ namespace Terminal.Gui {
/// The view to add to the scrollview.
public override void Add (View view)
{
+ if (!IsOverridden (view)) {
+ view.MouseEnter += View_MouseEnter;
+ view.MouseLeave += View_MouseLeave;
+ vertical.MouseEnter += View_MouseEnter;
+ vertical.MouseLeave += View_MouseLeave;
+ horizontal.MouseEnter += View_MouseEnter;
+ horizontal.MouseLeave += View_MouseLeave;
+ }
contentView.Add (view);
}
+ void View_MouseLeave (object sender, MouseEvent e)
+ {
+ Application.UngrabMouse ();
+ }
+
+ void View_MouseEnter (object sender, MouseEvent e)
+ {
+ Application.GrabMouse (this);
+ }
+
+ bool IsOverridden (View view)
+ {
+ Type t = view.GetType ();
+ MethodInfo m = t.GetMethod ("MouseEvent");
+
+ return m.DeclaringType == t && m.GetBaseDefinition ().DeclaringType == typeof (Responder);
+ }
+
///
/// Gets or sets the visibility for the horizontal scroll indicator.
///
@@ -463,7 +491,7 @@ namespace Terminal.Gui {
switch (kb.Key) {
case Key.CursorUp:
return ScrollUp (1);
- case (Key) 'v' | Key.AltMask:
+ case (Key)'v' | Key.AltMask:
case Key.PageUp:
return ScrollUp (Bounds.Height);
@@ -489,5 +517,18 @@ namespace Terminal.Gui {
}
return false;
}
+
+ public override bool MouseEvent (MouseEvent me)
+ {
+ if (me.Flags != MouseFlags.WheeledDown && me.Flags != MouseFlags.WheeledUp)
+ return false;
+
+ if (me.Flags == MouseFlags.WheeledDown)
+ ScrollDown (1);
+ else if (me.Flags == MouseFlags.WheeledUp)
+ ScrollUp (1);
+
+ return true;
+ }
}
}