44
55using System ;
66using System . Collections . Generic ;
7+ using System . Drawing ;
78using System . IO ;
9+ using System . Reflection ;
810using System . Windows . Forms ;
911using System . Xml ;
1012using NUnit . Framework ;
@@ -31,6 +33,13 @@ public class DataTreeTests : MemoryOnlyBackendProviderRestoredForEachTestTestBas
3133 private DataTree m_dtree ;
3234 private Form m_parent ;
3335
36+ private sealed class ScrollTestDataTree : DataTree
37+ {
38+ protected override void OnPaint ( PaintEventArgs e )
39+ {
40+ }
41+ }
42+
3443 private CustomFieldForTest m_customField ;
3544 #region Fixture Setup and Teardown
3645 internal static Inventory GenerateParts ( )
@@ -77,6 +86,30 @@ public override void FixtureSetup()
7786 }
7887 #endregion
7988
89+ private static DataTree CreateScrollableDataTree ( Form parent )
90+ {
91+ var dataTree = new ScrollTestDataTree ( ) ;
92+ parent . Size = new Size ( 400 , 200 ) ;
93+ dataTree . Dock = DockStyle . Fill ;
94+ parent . Controls . Add ( dataTree ) ;
95+
96+ for ( int i = 0 ; i < 12 ; i ++ )
97+ {
98+ var slice = new Slice ( new Panel { Dock = DockStyle . Fill } )
99+ {
100+ Visible = true ,
101+ Size = new Size ( 360 , 50 ) ,
102+ Location = new Point ( 0 , i * 50 )
103+ } ;
104+ dataTree . Controls . Add ( slice ) ;
105+ slice . Install ( dataTree ) ;
106+ }
107+
108+ parent . Show ( ) ;
109+ Application . DoEvents ( ) ;
110+ return dataTree ;
111+ }
112+
80113 #region Test setup and teardown
81114 /// ------------------------------------------------------------------------------------
82115 /// <summary>
@@ -275,6 +308,102 @@ public void GetGuidForJumpToTool_UsesRootObject_WhenNoCurrentSlice()
275308 }
276309 }
277310
311+ [ Test ]
312+ public void GetWheelScrollPixels_UsesSystemWheelSettings ( )
313+ {
314+ m_dtree . Bounds = new Rectangle ( 0 , 0 , 200 , 100 ) ;
315+
316+ int delta = SystemInformation . MouseWheelScrollDelta ;
317+ int scrollLines = SystemInformation . MouseWheelScrollLines ;
318+ int expectedPixels ;
319+ if ( scrollLines == 0 )
320+ {
321+ expectedPixels = 0 ;
322+ }
323+ else if ( scrollLines == int . MaxValue )
324+ {
325+ expectedPixels = m_dtree . ClientRectangle . Height ;
326+ }
327+ else
328+ {
329+ expectedPixels = ( int ) Math . Round ( ( double ) scrollLines * m_dtree . Font . Height ,
330+ MidpointRounding . AwayFromZero ) ;
331+ }
332+
333+ Assert . That ( DataTree . GetWheelScrollPixels ( m_dtree , delta ) , Is . EqualTo ( expectedPixels ) ) ;
334+ Assert . That ( DataTree . GetWheelScrollPixels ( m_dtree , - delta ) , Is . EqualTo ( - expectedPixels ) ) ;
335+ }
336+
337+ [ Test ]
338+ public void TryGetWheelScrollPosition_ReturnsFalse_WhenAlreadyAtTop ( )
339+ {
340+ m_dtree . Bounds = new Rectangle ( 0 , 0 , 200 , 100 ) ;
341+ m_dtree . AutoScrollMinSize = new Size ( 200 , 1000 ) ;
342+ m_dtree . AutoScrollPosition = new Point ( 0 , 0 ) ;
343+
344+ int newY ;
345+ bool handled = DataTree . TryGetWheelScrollPosition ( m_dtree ,
346+ SystemInformation . MouseWheelScrollDelta , out newY ) ;
347+
348+ Assert . That ( handled , Is . False ) ;
349+ Assert . That ( newY , Is . EqualTo ( 0 ) ) ;
350+ }
351+
352+ [ Test ]
353+ public void CanRedirectWheelMessage_ReturnsFalse_WhenDataTreeHidden ( )
354+ {
355+ m_parent . Show ( ) ;
356+ m_dtree . Show ( ) ;
357+ Assert . That ( m_dtree . IsHandleCreated , Is . True ) ;
358+
359+ m_dtree . Hide ( ) ;
360+
361+ Assert . That ( DataTree . CanRedirectWheelMessage ( m_dtree ) , Is . False ) ;
362+ }
363+
364+ [ Test ]
365+ public void TryHandleWheelScroll_UpdatesScrollPosition_WhenScrollingIsPossible ( )
366+ {
367+ using ( var parent = new Form ( ) )
368+ {
369+ var dataTree = CreateScrollableDataTree ( parent ) ;
370+ dataTree . AutoScrollPosition = new Point ( 0 , 0 ) ;
371+
372+ bool handled = DataTree . TryHandleWheelScroll ( dataTree , - SystemInformation . MouseWheelScrollDelta ) ;
373+
374+ Assert . That ( handled , Is . True ) ;
375+ Assert . That ( - dataTree . AutoScrollPosition . Y , Is . GreaterThan ( 0 ) ) ;
376+ }
377+ }
378+
379+ [ Test ]
380+ public void TryScrollOwningDataTree_ScrollsContainingDataTree_FromDateSliceHostedControl ( )
381+ {
382+ using ( var parent = new Form ( ) )
383+ {
384+ var dataTree = CreateScrollableDataTree ( parent ) ;
385+ dataTree . AutoScrollPosition = new Point ( 0 , 0 ) ;
386+
387+ using ( var host = new Panel ( ) )
388+ using ( var control = new RichTextBox ( ) )
389+ {
390+ host . Bounds = new Rectangle ( 0 , 0 , 150 , 20 ) ;
391+ control . Dock = DockStyle . Fill ;
392+ host . Controls . Add ( control ) ;
393+ dataTree . Controls . Add ( host ) ;
394+ host . Show ( ) ;
395+ control . Show ( ) ;
396+ Application . DoEvents ( ) ;
397+
398+ bool handled = DateSlice . TryScrollOwningDataTree ( control ,
399+ - SystemInformation . MouseWheelScrollDelta ) ;
400+
401+ Assert . That ( handled , Is . True ) ;
402+ Assert . That ( - dataTree . AutoScrollPosition . Y , Is . GreaterThan ( 0 ) ) ;
403+ }
404+ }
405+ }
406+
278407 /// <summary></summary>
279408 [ Test ]
280409 public void OwnedObjects ( )
0 commit comments