Skip to content

Commit fd2def3

Browse files
committed
Scrollable controls expose a new property IScrollInfo.NumberOfVisibleLines that will be used for limiting MouseWheelScrolling
1 parent b0d95b3 commit fd2def3

File tree

7 files changed

+65
-19
lines changed

7 files changed

+65
-19
lines changed

MediaPortal/Source/UI/SkinEngine/Controls/Panels/StackPanel.cs

+10
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,16 @@ public virtual bool IsViewPortAtRight
824824
get { return Orientation == Orientation.Vertical || _actualLastVisibleChildIndex == GetVisibleChildren().Count - 1; }
825825
}
826826

827+
public int NumberOfVisibleLines
828+
{
829+
get
830+
{
831+
int numLines = 0;
832+
CalcHelper.Bound(ref numLines, 0, _actualLastVisibleChildIndex - _actualFirstVisibleChildIndex);
833+
return numLines > 0 ? numLines : 0;
834+
}
835+
}
836+
827837
#endregion
828838
}
829839
}

MediaPortal/Source/UI/SkinEngine/Controls/Panels/UniformGrid.cs

+5
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,11 @@ public bool IsViewPortAtRight
568568
get { return _scrollIndexX + _actualNumVisibleCols == _actualColumns; }
569569
}
570570

571+
public int NumberOfVisibleLines
572+
{
573+
get { return _actualNumVisibleRows; }
574+
}
575+
571576
#endregion
572577
}
573578
}

MediaPortal/Source/UI/SkinEngine/Controls/Panels/WrapPanel.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static LineMeasurement Create()
110110
protected IList<LineMeasurement> _arrangedLines = new List<LineMeasurement>();
111111
protected int _actualFirstVisibleLineIndex = 0;
112112
protected int _actualLastVisibleLineIndex = -1;
113-
113+
114114
#endregion
115115

116116
#region Ctor
@@ -990,6 +990,11 @@ public virtual bool IsViewPortAtRight
990990
get { return Orientation == Orientation.Horizontal || _actualLastVisibleLineIndex == GetVisibleChildren().Count - 1; }
991991
}
992992

993+
public int NumberOfVisibleLines
994+
{
995+
get { return _actualLastVisibleLineIndex - _actualFirstVisibleLineIndex + 1; }
996+
}
997+
993998
#endregion
994999
}
9951000
}

MediaPortal/Source/UI/SkinEngine/Controls/Visuals/IScrollInfo.cs

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ You should have received a copy of the GNU General Public License
2222

2323
#endregion
2424

25+
using System.Windows.Forms;
26+
2527
namespace MediaPortal.UI.SkinEngine.Controls.Visuals
2628
{
2729
/// <summary>
@@ -113,5 +115,12 @@ public interface IScrollInfo
113115
/// Returns the information if the viewport is at the right side of the available area.
114116
/// </summary>
115117
bool IsViewPortAtRight { get; }
118+
119+
/// <summary>
120+
/// Returns the number of lines that can be shown inside the viewport. This value can be used for calculating
121+
/// the number of lines to be scrolled when using mouse wheel. If this value is <c>0</c>, the system default
122+
/// scrolling will be used (usually scrolling by <seealso cref="SystemInformation.MouseWheelScrollLines"/>).
123+
/// </summary>
124+
int NumberOfVisibleLines { get; }
116125
}
117126
}

MediaPortal/Source/UI/SkinEngine/Controls/Visuals/ItemsPresenter.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public bool IsViewPortAtTop
379379
get
380380
{
381381
IScrollInfo si = _itemsHostPanel as IScrollInfo;
382-
return si == null ? true : si.IsViewPortAtTop;
382+
return si == null || si.IsViewPortAtTop;
383383
}
384384
}
385385

@@ -410,6 +410,15 @@ public bool IsViewPortAtRight
410410
}
411411
}
412412

413+
public int NumberOfVisibleLines
414+
{
415+
get
416+
{
417+
IScrollInfo si = _itemsHostPanel as IScrollInfo;
418+
return si == null ? 0 : si.NumberOfVisibleLines;
419+
}
420+
}
421+
413422
#endregion
414423
}
415424
}

MediaPortal/Source/UI/SkinEngine/Controls/Visuals/ScrollContentPresenter.cs

+11-6
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public override void BringIntoView(UIElement element, RectangleF elementBounds)
154154
if (IsHorzCentering)
155155
differenceX = CalculateCenteredScrollPos(elementBounds.X, elementBounds.Width, ActualPosition.X, ActualWidth);
156156
else if (_doScroll)
157-
differenceX = CalculateVisibleScrollDifference(elementBounds.X, elementBounds.Width, ActualPosition.X, ActualWidth);
157+
differenceX = CalculateVisibleScrollDifference(elementBounds.X, elementBounds.Width, ActualPosition.X, ActualWidth);
158158

159159
if (IsVertCentering)
160160
differenceY = CalculateCenteredScrollPos(elementBounds.Y, elementBounds.Height, ActualPosition.Y, ActualHeight) - _actualScrollOffsetY;
@@ -173,7 +173,7 @@ protected float CalculateVisibleScrollDifference(double elementPos, double eleme
173173
{
174174
double difference = 0.0f;
175175
if (elementPos + elementSize > actualPos + actualSize)
176-
difference = - (elementPos + elementSize - actualPos - actualSize);
176+
difference = -(elementPos + elementSize - actualPos - actualSize);
177177
if (elementPos + difference < actualPos)
178178
difference = actualPos - elementPos;
179179
return (float) difference;
@@ -260,7 +260,7 @@ public override void Render(RenderContext parentRenderContext)
260260
{
261261
if (OpacityMask == null && (TotalHeight > ActualHeight || TotalWidth > ActualWidth))
262262
{
263-
SolidColorBrush brush = new SolidColorBrush {Color = Color.Black};
263+
SolidColorBrush brush = new SolidColorBrush { Color = Color.Black };
264264
OpacityMask = brush;
265265
_forcedOpacityMask = true;
266266
}
@@ -288,7 +288,7 @@ public override void SaveUIState(IDictionary<string, object> state, string prefi
288288
base.SaveUIState(state, prefix);
289289
state[prefix + "/ScrollOffsetX"] = _scrollOffsetX;
290290
state[prefix + "/ScrollOffsetY"] = _scrollOffsetX;
291-
}
291+
}
292292

293293
public override void RestoreUIState(IDictionary<string, object> state, string prefix)
294294
{
@@ -450,7 +450,7 @@ public bool FocusPageDown()
450450
{
451451
if (currentElement.ActualPosition.Y + currentElement.ActualHeight + DELTA_DOUBLE > ActualPosition.Y + ActualHeight)
452452
// Already at bottom
453-
limitPosition = (float) (ActualPosition.Y + 2*ActualHeight);
453+
limitPosition = (float) (ActualPosition.Y + 2 * ActualHeight);
454454
else
455455
limitPosition = (float) (ActualPosition.Y + ActualHeight);
456456
}
@@ -526,7 +526,7 @@ public bool FocusPageRight()
526526
{
527527
if (currentElement.ActualPosition.X + ActualWidth + DELTA_DOUBLE > ActualPosition.X + ActualWidth)
528528
// Already at right
529-
limitPosition = (float) (ActualPosition.X + 2*ActualWidth);
529+
limitPosition = (float) (ActualPosition.X + 2 * ActualWidth);
530530
else
531531
limitPosition = (float) (ActualPosition.X + ActualWidth);
532532
}
@@ -651,6 +651,11 @@ public bool IsViewPortAtRight
651651
get { return TemplateControl == null || -_actualScrollOffsetX + ActualWidth + DELTA_DOUBLE >= TotalWidth; }
652652
}
653653

654+
public int NumberOfVisibleLines
655+
{
656+
get { return 0; /* As we are scrolling only by pixels here, we keep the default behavior */ }
657+
}
658+
654659
#endregion
655660
}
656661
}

MediaPortal/Source/UI/SkinEngine/Controls/Visuals/ScrollViewer.cs

+14-11
Original file line numberDiff line numberDiff line change
@@ -390,19 +390,22 @@ public override void OnMouseWheel(int numDetents)
390390
if (!IsMouseOver)
391391
return;
392392

393-
int numLines = numDetents * SystemInformation.MouseWheelScrollLines;
393+
IScrollViewerFocusSupport svfs = FindScrollControl() as IScrollViewerFocusSupport;
394+
if (svfs == null)
395+
return;
396+
397+
int scrollByLines = SystemInformation.MouseWheelScrollLines; // Use the system setting as default.
398+
399+
IScrollInfo scrollInfo = svfs as IScrollInfo;
400+
if (scrollInfo != null && scrollInfo.NumberOfVisibleLines != 0) // If ScrollControl can shown less items, use this as limit.
401+
scrollByLines = scrollInfo.NumberOfVisibleLines;
402+
403+
int numLines = numDetents * scrollByLines;
404+
394405
if (numLines < 0)
395-
{
396-
IScrollViewerFocusSupport svfs = FindScrollControl() as IScrollViewerFocusSupport;
397-
if (svfs != null)
398-
svfs.ScrollDown(-1 * numLines);
399-
}
406+
svfs.ScrollDown(-1*numLines);
400407
else if (numLines > 0)
401-
{
402-
IScrollViewerFocusSupport svfs = FindScrollControl() as IScrollViewerFocusSupport;
403-
if (svfs != null)
404-
svfs.ScrollUp(numLines);
405-
}
408+
svfs.ScrollUp(numLines);
406409
}
407410

408411
public override void OnKeyPressed(ref Key key)

0 commit comments

Comments
 (0)