2 // ScrollableControlTest.cs: Test cases for ScrollableControl.
5 // Gert Driesen (drieseng@users.sourceforge.net)
7 // (C) 2006 Gert Driesen
12 using System.Windows.Forms;
14 using NUnit.Framework;
16 namespace MonoTests.System.Windows.Forms
19 public class ScrollableControlTest : TestHelper
22 public void AutoScrollPositionTest ()
26 sc = new ScrollableControl ();
29 sc.AutoScrollPosition = new Point (-25, -50);
30 Assert.AreEqual (Point.Empty, sc.AutoScrollPosition, "#01");
32 sc.AutoScrollPosition = new Point (2500, 5000);
33 Assert.AreEqual (Point.Empty, sc.AutoScrollPosition, "#02");
35 sc.AutoScrollPosition = new Point (25, 50);
36 Assert.AreEqual (Point.Empty, sc.AutoScrollPosition, "#03");
40 sc.AutoScrollPosition = new Point (-25, -50);
41 Assert.AreEqual (Point.Empty, sc.AutoScrollPosition, "#04");
43 sc.AutoScrollPosition = new Point (2500, 5000);
44 Assert.AreEqual (Point.Empty, sc.AutoScrollPosition, "#05");
46 sc.AutoScrollPosition = new Point (25, 50);
47 Assert.AreEqual (Point.Empty, sc.AutoScrollPosition, "#06");
49 sc.Size = new Size (200, 400);
50 sc.Location = new Point (20, 40);
52 sc.AutoScrollPosition = new Point (-25, -50);
53 Assert.AreEqual (Point.Empty, sc.AutoScrollPosition, "#07");
55 sc.AutoScrollPosition = new Point (2500, 5000);
56 Assert.AreEqual (Point.Empty, sc.AutoScrollPosition, "#08");
58 sc.AutoScrollPosition = new Point (25, 50);
59 Assert.AreEqual (Point.Empty, sc.AutoScrollPosition, "#09");
64 c1.Location = new Point (-100, -200);
65 c1.Size = new Size (10, 10);
69 c2.Location = new Point (400, 800);
70 c2.Size = new Size (10, 10);
73 Assert.AreEqual (new Rectangle (0, 0, 410, 810), sc.DisplayRectangle, "#10");
75 sc.ScrollControlIntoView (c2);
77 Assert.AreEqual (new Point (-226, -426), sc.AutoScrollPosition, "#11");
78 Assert.AreEqual (new Rectangle (-226, -426, 410, 810), sc.DisplayRectangle, "#12");
79 Assert.AreEqual (new Point (-326, -626), c1.Location, "#13");
80 Assert.AreEqual (new Point (174, 374), c2.Location, "#14");
82 sc.AutoScrollPosition = new Point (-25, -50);
83 Assert.AreEqual (Point.Empty, sc.AutoScrollPosition, "#01");
84 Assert.AreEqual (new Rectangle (0, 0, 410, 810), sc.DisplayRectangle, "#15");
85 Assert.AreEqual (new Point (-100, -200), c1.Location, "#16");
86 Assert.AreEqual (new Point (400, 800), c2.Location, "#17");
88 sc.AutoScrollPosition = new Point (2500, 5000);
89 Assert.AreEqual (new Point (-226, -426), sc.AutoScrollPosition, "#18");
90 Assert.AreEqual (new Rectangle (-226, -426, 410, 810), sc.DisplayRectangle, "#19");
91 Assert.AreEqual (new Point (-326, -626), c1.Location, "#20");
92 Assert.AreEqual (new Point (174, 374), c2.Location, "#21");
94 sc.AutoScrollPosition = new Point (25, 50);
95 Assert.AreEqual (new Point (-25, -50), sc.AutoScrollPosition, "#22");
96 Assert.AreEqual (new Rectangle (-25, -50, 410, 810), sc.DisplayRectangle, "#23");
97 Assert.AreEqual (new Point (-125, -250), c1.Location, "#24");
98 Assert.AreEqual (new Point (375, 750), c2.Location, "#25");
100 sc.ScrollControlIntoView (c1);
103 Assert.AreEqual (Point.Empty, sc.AutoScrollPosition, "#26");
104 Assert.AreEqual (new Rectangle (0, 0, 410, 810), sc.DisplayRectangle, "#27");
105 Assert.AreEqual (new Point (-100, -200), c1.Location, "#28");
106 Assert.AreEqual (new Point (400, 800), c2.Location, "#29");
108 sc.AutoScrollPosition = new Point (2500, 5000);
109 Assert.AreEqual (new Point (-226, -426), sc.AutoScrollPosition, "#30");
110 Assert.AreEqual (new Rectangle (-226, -426, 410, 810), sc.DisplayRectangle, "#31");
111 Assert.AreEqual (new Point (-326, -626), c1.Location, "#32");
112 Assert.AreEqual (new Point (174, 374), c2.Location, "#33");
114 sc.AutoScrollPosition = new Point (25, 50);
115 Assert.AreEqual (new Point (-25, -50), sc.AutoScrollPosition, "#34");
116 Assert.AreEqual (new Rectangle (-25, -50, 410, 810), sc.DisplayRectangle, "#35");
117 Assert.AreEqual (new Point (-125, -250), c1.Location, "#36");
118 Assert.AreEqual (new Point (375, 750), c2.Location, "#37");
120 sc.ScrollControlIntoView (c2);
122 Assert.AreEqual (new Point (-226, -426), sc.AutoScrollPosition, "#38");
123 Assert.AreEqual (new Rectangle (-226, -426, 410, 810), sc.DisplayRectangle, "#39");
124 Assert.AreEqual (new Point (-326, -626), c1.Location, "#40");
125 Assert.AreEqual (new Point (174, 374), c2.Location, "#41");
127 sc.AutoScrollPosition = new Point (-25, -50);
128 Assert.AreEqual (Point.Empty, sc.AutoScrollPosition, "#42");
129 Assert.AreEqual (new Rectangle (0, 0, 410, 810), sc.DisplayRectangle, "#43");
130 Assert.AreEqual (new Point (-100, -200), c1.Location, "#44");
131 Assert.AreEqual (new Point (400, 800), c2.Location, "#45");
133 sc.AutoScrollPosition = new Point (2500, 5000);
134 Assert.AreEqual (new Point (-226, -426), sc.AutoScrollPosition, "#46");
135 Assert.AreEqual (new Rectangle (-226, -426, 410, 810), sc.DisplayRectangle, "#47");
136 Assert.AreEqual (new Point (-326, -626), c1.Location, "#48");
137 Assert.AreEqual (new Point (174, 374), c2.Location, "#49");
139 sc.AutoScrollPosition = new Point (25, 50);
140 Assert.AreEqual (new Point (-25, -50), sc.AutoScrollPosition, "#50");
141 Assert.AreEqual (new Rectangle (-25, -50, 410, 810), sc.DisplayRectangle, "#51");
142 Assert.AreEqual (new Point (-125, -250), c1.Location, "#52");
143 Assert.AreEqual (new Point (375, 750), c2.Location, "#53");
149 public void ResizeAnchoredTest ()
151 ScrollableControl sc = new ScrollableControl ();
152 object h = sc.Handle;
153 sc.Size = new Size (23, 45);
154 Label lbl = new Label ();
155 lbl.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
156 lbl.Size = sc.ClientSize;
157 sc.Controls.Add (lbl);
160 Assert.AreEqual (lbl.Location, Point.Empty, "#1");
161 Assert.AreEqual (lbl.Size, sc.ClientSize, "#2");
163 TestHelper.RemoveWarning (h);
166 public void AutoScroll ()
168 ScrollableControl sc = new ScrollableControl ();
169 Assert.IsFalse (sc.AutoScroll, "#A1");
170 Assert.AreEqual (0, sc.Controls.Count, "#A2");
172 sc.AutoScroll = true;
173 Assert.IsTrue(sc.AutoScroll, "#B1");
174 Assert.AreEqual (0, sc.Controls.Count, "#B2");
176 sc.AutoScroll = false;
177 Assert.IsFalse (sc.AutoScroll, "#C1");
178 Assert.AreEqual (0, sc.Controls.Count, "#C2");
182 public void AutoScrollMinSize ()
184 ScrollableControl sc = new ScrollableControl ();
185 Assert.AreEqual (Size.Empty, sc.AutoScrollMinSize, "#A1");
186 Assert.IsFalse (sc.AutoScroll, "#A2");
188 sc.AutoScrollMinSize = Size.Empty;
189 Assert.AreEqual (Size.Empty, sc.AutoScrollMinSize, "#B1");
190 Assert.IsFalse (sc.AutoScroll, "#B2");
192 sc.AutoScrollMinSize = new Size (10, 20);
193 Assert.AreEqual (new Size (10, 20), sc.AutoScrollMinSize, "#C1");
194 Assert.IsTrue (sc.AutoScroll, "#C2");
196 sc.AutoScroll = false;
197 Assert.AreEqual (new Size (10, 20), sc.AutoScrollMinSize, "#D1");
198 Assert.IsFalse (sc.AutoScroll, "#D2");
200 sc.AutoScrollMinSize = new Size (10, 20);
201 Assert.AreEqual (new Size (10, 20), sc.AutoScrollMinSize, "#E1");
202 Assert.IsFalse (sc.AutoScroll, "#E2");
204 sc.AutoScrollMinSize = new Size (20, 20);
205 Assert.AreEqual (new Size (20, 20), sc.AutoScrollMinSize, "#F1");
206 Assert.IsTrue (sc.AutoScroll, "#F2");
208 sc.AutoScroll = false;
209 Assert.AreEqual (new Size (20, 20), sc.AutoScrollMinSize, "#G1");
210 Assert.IsFalse (sc.AutoScroll, "#G2");
212 sc.AutoScrollMinSize = Size.Empty;
213 Assert.AreEqual (Size.Empty, sc.AutoScrollMinSize, "#H1");
214 Assert.IsTrue (sc.AutoScroll, "#H2");
216 sc.AutoScrollMinSize = new Size (10, 20);
217 Assert.AreEqual (new Size (10, 20), sc.AutoScrollMinSize, "#I1");
218 Assert.IsTrue (sc.AutoScroll, "#I2");
220 sc.AutoScrollMinSize = Size.Empty;
221 Assert.AreEqual (Size.Empty, sc.AutoScrollMinSize, "#J1");
222 Assert.IsTrue (sc.AutoScroll, "#J2");
227 public void MethodScrollToControl ()
229 if (TestHelper.RunningOnUnix)
230 Assert.Ignore ("Depends of scrollbar width, values are for Windows");
232 Form f = new Form ();
233 f.ShowInTaskbar = false;
236 PublicScrollableControl sc = new PublicScrollableControl ();
237 sc.Size = new Size (200, 200);
238 sc.AutoScroll = true;
242 Button b = new Button ();
246 Button b2 = new Button ();
248 sc.Controls.Add (b2);
250 Button b3 = new Button ();
252 sc.Controls.Add (b3);
254 Assert.AreEqual (new Point (0, 0), sc.PublicScrollToControl (b), "A1");
255 Assert.AreEqual (new Point (0, -180), sc.PublicScrollToControl (b2), "A2");
256 Assert.AreEqual (new Point (-172, 0), sc.PublicScrollToControl (b3), "A3");
258 sc.AutoScrollPosition = new Point (50, 70);
260 Assert.AreEqual (new Point (0, -15), sc.PublicScrollToControl (b), "A4");
261 Assert.AreEqual (new Point (0, -180), sc.PublicScrollToControl (b2), "A5");
262 Assert.AreEqual (new Point (-172, 0), sc.PublicScrollToControl (b3), "A6");
264 sc.AutoScrollPosition = new Point (150, 150);
266 Assert.AreEqual (new Point (0, -15), sc.PublicScrollToControl (b), "A7");
267 Assert.AreEqual (new Point (0, -180), sc.PublicScrollToControl (b2), "A8");
268 Assert.AreEqual (new Point (-172, 0), sc.PublicScrollToControl (b3), "A9");
273 private class PublicScrollableControl : ScrollableControl
275 public Point PublicScrollToControl (Control activeControl)
277 return base.ScrollToControl (activeControl);
282 public void Padding ()
284 ScrollableControl c = new ScrollableControl ();
285 c.Dock = DockStyle.Fill;
286 c.Padding = new Padding (40);
288 Assert.AreEqual (40, c.Padding.All, "A1");
289 Assert.AreEqual (40, c.DockPadding.All, "A2");
291 c.DockPadding.Right = 20;
293 Assert.AreEqual (20, c.Padding.Right, "A3");
294 Assert.AreEqual (20, c.DockPadding.Right, "A4");
296 c.Padding = new Padding (40, 40, 40, 40);
298 Assert.AreEqual (40, c.Padding.Right, "A5");
299 Assert.AreEqual (40, c.DockPadding.Right, "A6");
301 Form f = new Form ();
304 Button b = new Button ();
309 // Padding does not affect laying out the controls
310 Assert.AreEqual (new Point (0, 0), b.Location, "A7");
316 // Even if padding is not directly affecting the layout, it can
317 // cause the ScrollableControl instance to show the scrollbars
318 // *after* the first access to DockPadding
320 public void DockPaddingScroll ()
322 ScrollableControl scrollable = new ScrollableControl ();
323 scrollable.Padding = new Padding (10);
324 scrollable.Size = new Size (50, 50);
325 scrollable.AutoScroll = true;
327 Control c = new Control ();
328 c.Size = scrollable.Size; // Same size as parent, shouldn' need scrollbars
329 c.Parent = scrollable;
331 Form f = new Form ();
332 f.Controls.Add (scrollable);
336 Assert.AreEqual (false, scrollable.VerticalScroll.Visible, "#A0");
338 ScrollableControl.DockPaddingEdges dock_padding = scrollable.DockPadding;
339 Assert.IsTrue (dock_padding != null, "#B0");
341 // Refresh the layout, now that is affected by the creation of DockPadding
342 scrollable.PerformLayout ();
344 Assert.AreEqual (true, scrollable.VerticalScroll.Visible, "#C0");