diff options
author | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2011-10-28 02:10:43 +0400 |
---|---|---|
committer | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2011-10-28 02:10:43 +0400 |
commit | ed40cd29f3b91f1075d1759c55e41909d888d0bb (patch) | |
tree | 744dd4e53abb393edcded8a23541bc27df854f2c /main/src/addins/VersionControl | |
parent | 1068044073baf0bf228a5b0b3b0de24e43969eb6 (diff) |
Unify handling of mouse scroll deltas in custom scrollwindows
Diffstat (limited to 'main/src/addins/VersionControl')
2 files changed, 23 insertions, 24 deletions
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/BlameWidget.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/BlameWidget.cs index f51021eca4..56bbc112d4 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/BlameWidget.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/BlameWidget.cs @@ -271,13 +271,20 @@ namespace MonoDevelop.VersionControl.Views protected override bool OnScrollEvent (EventScroll evnt) { - Scrollbar scrollWidget = (evnt.Direction == ScrollDirection.Up || evnt.Direction == ScrollDirection.Down) ? (Scrollbar)vScrollBar : hScrollBar; - if (scrollWidget.Visible) { - double newValue = scrollWidget.Adjustment.Value + GetWheelDelta (scrollWidget, evnt.Direction); - newValue = System.Math.Max (System.Math.Min (scrollWidget.Adjustment.Upper - scrollWidget.Adjustment.PageSize, newValue), scrollWidget.Adjustment.Lower); - scrollWidget.Adjustment.Value = newValue; - } - return base.OnScrollEvent (evnt); + var direction = evnt.Direction; + Scrollbar scrollWidget = (direction == ScrollDirection.Up || direction == ScrollDirection.Down) + ? (Scrollbar)vScrollBar + : hScrollBar; + + if (!scrollWidget.Visible) + return base.OnScrollEvent (evnt); + + var adj = scrollWidget.Adjustment; + double pageDelta = System.Math.Pow (adj.PageSize, 2.0 / 3.0); + double newValue = adj.Value + GtkWorkarounds.GetScrollWheelDelta (evnt, pageDelta, scrollWidget.Inverted); + newValue = System.Math.Max (System.Math.Min (adj.Upper - adj.PageSize, newValue), adj.Lower); + adj.Value = newValue; + return true; } protected override void OnSizeRequested (ref Gtk.Requisition requisition) diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/EditorCompareWidgetBase.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/EditorCompareWidgetBase.cs index ae438f8b8d..22b20f7901 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/EditorCompareWidgetBase.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/EditorCompareWidgetBase.cs @@ -387,8 +387,6 @@ namespace MonoDevelop.VersionControl.Views attachedVAdjustments.Select (adj => adj.PageIncrement / (adj.Upper - adj.Lower)).Min (), attachedVAdjustments.Select (adj => adj.PageSize / (adj.Upper - adj.Lower)).Min ()); - - hAdjustment.SetBounds (0, 1.0, attachedHAdjustments.Select (adj => adj.StepIncrement / (adj.Upper - adj.Lower)).Min (), attachedHAdjustments.Select (adj => adj.PageIncrement / (adj.Upper - adj.Lower)).Min (), @@ -514,24 +512,18 @@ namespace MonoDevelop.VersionControl.Views base.OnSizeAllocated (allocation); } - static double GetWheelDelta (Adjustment adjustment, ScrollDirection direction) - { - double delta = adjustment.StepIncrement * 4; - if (direction == ScrollDirection.Up || direction == ScrollDirection.Left) - delta = -delta; - return delta; - } - protected override bool OnScrollEvent (EventScroll evnt) { - var adjustment = (evnt.Direction == ScrollDirection.Up || evnt.Direction == ScrollDirection.Down) ? vAdjustment : hAdjustment; + var adj = (evnt.Direction == ScrollDirection.Up || evnt.Direction == ScrollDirection.Down) ? vAdjustment : hAdjustment; - if (adjustment.PageSize < adjustment.Upper) { - double newValue = adjustment.Value + GetWheelDelta (adjustment, evnt.Direction); - newValue = System.Math.Max (System.Math.Min (adjustment.Upper - adjustment.PageSize, newValue), adjustment.Lower); - adjustment.Value = newValue; - } - return base.OnScrollEvent (evnt); + if (adj.PageSize >= (adj.Upper - adj.Lower)) + return base.OnScrollEvent (evnt); + + double pageDelta = System.Math.Pow (adj.PageSize, 2.0 / 3.0); + double newValue = adj.Value + GtkWorkarounds.GetScrollWheelDelta (evnt, pageDelta, false); + newValue = System.Math.Max (System.Math.Min (1.0 - adj.PageSize, newValue), 0.0); + adj.Value = newValue; + return true; } protected override void OnSizeRequested (ref Gtk.Requisition requisition) |