View | Details | Raw Unified | Return to bug 2912
Collapse All | Expand All

(-)a/mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/DefaultLayout.cs (-1 / +16 lines)
Lines 253-259 namespace System.Windows.Forms.Layout Link Here
253
			int height;
253
			int height;
254
			Size preferredsize = child.PreferredSize;
254
			Size preferredsize = child.PreferredSize;
255
255
256
			if (child.GetAutoSizeMode () == AutoSizeMode.GrowAndShrink || (child.Dock != DockStyle.None && !(child is Button))) {
256
			if (child.GetAutoSizeMode () == AutoSizeMode.GrowAndShrink || (child.Dock != DockStyle.None && !(child is Button) && !(child is FlowLayoutPanel))) {
257
				width = preferredsize.Width;
257
				width = preferredsize.Width;
258
				height = preferredsize.Height;
258
				height = preferredsize.Height;
259
			} else {
259
			} else {
Lines 265-270 namespace System.Windows.Forms.Layout Link Here
265
					height = preferredsize.Height;
265
					height = preferredsize.Height;
266
			}
266
			}
267
267
268
			if (child.AutoSize && child is FlowLayoutPanel && child.Dock != DockStyle.None) {
269
				switch (child.Dock) {
270
					case DockStyle.Left:
271
					case DockStyle.Right:
272
						if (preferredsize.Width < child.ExplicitBounds.Width && preferredsize.Height < child.Parent.PaddingClientRectangle.Height)
273
							width = preferredsize.Width;
274
						break;
275
					case DockStyle.Top:
276
					case DockStyle.Bottom:
277
						if (preferredsize.Height < child.ExplicitBounds.Height && preferredsize.Width < child.Parent.PaddingClientRectangle.Width)
278
							height = preferredsize.Height;
279
						break;
280
				}
281
			}
282
268
			// Sanity
283
			// Sanity
269
			if (width < child.MinimumSize.Width)
284
			if (width < child.MinimumSize.Width)
270
				width = child.MinimumSize.Width;
285
				width = child.MinimumSize.Width;
(-)a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FlowLayoutPanel.cs (+16 lines)
Lines 112-117 namespace System.Windows.Forms Link Here
112
			else
112
			else
113
				base.CalculateCanvasSize (canOverride);
113
				base.CalculateCanvasSize (canOverride);
114
		}
114
		}
115
116
		protected override void OnLayout (LayoutEventArgs levent)
117
		{
118
			base.OnLayout (levent);
119
120
#if NET_2_0
121
			// base.OnLayout() calls CalculateCanvasSize(true) in which we just set the canvas to
122
			// clientsize so we could re-layout everything according to the flow.
123
			// This time we want to actually calculate the canvas.
124
			CalculateCanvasSize (false);
125
			if (AutoSize && (canvas_size.Width > ClientSize.Width || canvas_size.Height > ClientSize.Height)) {
126
				ClientSize = canvas_size;
127
			}
128
			AdjustFormScrollbars (AutoScroll);
129
#endif
130
		}
115
		
131
		
116
		internal override Size GetPreferredSizeCore (Size proposedSize)
132
		internal override Size GetPreferredSizeCore (Size proposedSize)
117
		{
133
		{
(-)a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ScrollableControl.cs (-10 lines)
Lines 696-711 namespace System.Windows.Forms { Link Here
696
696
697
			AdjustFormScrollbars(AutoScroll);	// Dunno what the logic is. Passing AutoScroll seems to match MS behaviour
697
			AdjustFormScrollbars(AutoScroll);	// Dunno what the logic is. Passing AutoScroll seems to match MS behaviour
698
			base.OnLayout(levent);
698
			base.OnLayout(levent);
699
700
#if NET_2_0
701
			// The first time through, we just set the canvas to clientsize
702
			// so we could re-layout everything according to the flow.
703
			// This time we want to actually calculate the canvas.
704
			if (this is FlowLayoutPanel) {
705
				CalculateCanvasSize (false);
706
				AdjustFormScrollbars (AutoScroll);
707
			}
708
#endif
709
		}
699
		}
710
700
711
		[EditorBrowsable(EditorBrowsableState.Advanced)]
701
		[EditorBrowsable(EditorBrowsableState.Advanced)]
(-)a/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FlowPanelTests.cs (-1 / +314 lines)
Lines 1329-1331 namespace MonoTests.System.Windows.Forms Link Here
1329
	}
1329
	}
1330
}
1330
}
1331
#endif
1331
#endif
1332
- 
1332
	[TestFixture]
1333
	public class FlowPanelTests_AutoSize: TestHelper
1334
	{
1335
		private Form f;
1336
		protected override void SetUp ()
1337
		{
1338
			base.SetUp ();
1339
			f = new Form ();
1340
			f.AutoSize = false;
1341
			f.ClientSize = new Size (100, 300);
1342
			f.ShowInTaskbar = false;
1343
			f.Show ();
1344
		}
1345
1346
		protected override void TearDown ()
1347
		{
1348
			f.Dispose ();
1349
			base.TearDown ();
1350
		}
1351
1352
		[Test]
1353
		public void AutoSizeGrowOnly_ResizeIfLarger ()
1354
		{
1355
			var panel = new FlowLayoutPanel ();
1356
			panel.SuspendLayout ();
1357
			panel.AutoSize = true;
1358
			panel.AutoSizeMode = AutoSizeMode.GrowOnly;
1359
			panel.WrapContents = true;
1360
			panel.Bounds = new Rectangle (5, 5, 10, 10);
1361
			panel.Dock = DockStyle.None;
1362
1363
			var c = new Label ();
1364
			c.Size = new Size (90, 25);
1365
			panel.Controls.Add (c);
1366
			c = new Label ();
1367
			c.Size = new Size (90, 25);
1368
			panel.Controls.Add (c);
1369
			f.Controls.Add (panel);
1370
			panel.ResumeLayout (true);
1371
1372
			Assert.AreEqual (192, panel.Width, "1"); // 2 * 90 + 4 * 3 margin
1373
			Assert.AreEqual (25, panel.Height, "2");
1374
		}
1375
1376
		[Test]
1377
		public void AutoSizeGrowOnly_ResizeIfLarger_DockBottom ()
1378
		{
1379
			var panel = new FlowLayoutPanel ();
1380
			panel.SuspendLayout ();
1381
			panel.AutoSize = true;
1382
			panel.AutoSizeMode = AutoSizeMode.GrowOnly;
1383
			panel.WrapContents = true;
1384
			panel.Bounds = new Rectangle (5, 5, 10, 10);
1385
			panel.Dock = DockStyle.Bottom;
1386
1387
			var c = new Label ();
1388
			c.Size = new Size (90, 25);
1389
			panel.Controls.Add (c);
1390
			c = new Label ();
1391
			c.Size = new Size (90, 25);
1392
			panel.Controls.Add (c);
1393
			f.Controls.Add (panel);
1394
			panel.ResumeLayout (true);
1395
1396
			Assert.AreEqual (250, panel.Top, "1");
1397
			Assert.AreEqual (f.ClientRectangle.Width, panel.Width, "2");
1398
			Assert.AreEqual (50, panel.Height, "3");
1399
		}
1400
1401
		[Test]
1402
		public void AutoSizeGrowOnly_DontResizeIfSmaller ()
1403
		{
1404
			var panel = new FlowLayoutPanel ();
1405
			panel.SuspendLayout ();
1406
			panel.AutoSize = true;
1407
			panel.AutoSizeMode = AutoSizeMode.GrowOnly;
1408
			panel.WrapContents = true;
1409
			panel.Bounds = new Rectangle(5, 5, 100, 100);
1410
			panel.Dock = DockStyle.None;
1411
1412
			var c = new Label ();
1413
			c.Size = new Size (90, 25);
1414
			panel.Controls.Add (c);
1415
			f.Controls.Add (panel);
1416
			panel.ResumeLayout (true);
1417
1418
			Assert.AreEqual (100, panel.Width, "1");
1419
			Assert.AreEqual (100, panel.Height, "2");
1420
		}
1421
1422
		[Test]
1423
		public void AutoSizeGrowOnly_ResizeIfSmaller_DockTop ()
1424
		{
1425
			var panel = new FlowLayoutPanel ();
1426
			panel.SuspendLayout ();
1427
			panel.AutoSize = true;
1428
			panel.AutoSizeMode = AutoSizeMode.GrowOnly;
1429
			panel.WrapContents = true;
1430
			panel.Bounds = new Rectangle(5, 5, 100, 100);
1431
			panel.Dock = DockStyle.Top;
1432
1433
			var c = new Label ();
1434
			c.Size = new Size (90, 25);
1435
			panel.Controls.Add (c);
1436
			f.Controls.Add(panel);
1437
			panel.ResumeLayout (true);
1438
1439
			Assert.AreEqual (0, panel.Top, "1");
1440
			Assert.AreEqual (f.ClientRectangle.Width, panel.Width, "2");
1441
			Assert.AreEqual (25, panel.Height, "3");
1442
		}
1443
1444
		[Test]
1445
		public void AutoSizeGrowOnly_ResizeIfSmaller_DockBottom ()
1446
		{
1447
			var panel = new FlowLayoutPanel ();
1448
			panel.SuspendLayout ();
1449
			panel.AutoSize = true;
1450
			panel.AutoSizeMode = AutoSizeMode.GrowOnly;
1451
			panel.WrapContents = true;
1452
			panel.Bounds = new Rectangle(5, 5, 100, 100);
1453
			panel.Dock = DockStyle.Bottom;
1454
1455
			var c = new Label ();
1456
			c.Size = new Size (90, 25);
1457
			panel.Controls.Add (c);
1458
			f.Controls.Add(panel);
1459
			panel.ResumeLayout (true);
1460
1461
			Assert.AreEqual (275, panel.Top, "1");
1462
			Assert.AreEqual (f.ClientRectangle.Width, panel.Width, "2");
1463
			Assert.AreEqual (25, panel.Height, "3");
1464
		}
1465
1466
		[Test]
1467
		public void AutoSizeGrowOnly_ResizeIfSmaller_DockLeft ()
1468
		{
1469
			f.ClientSize = new Size (300, 100);
1470
1471
			var panel = new FlowLayoutPanel ();
1472
			panel.SuspendLayout ();
1473
			panel.AutoSize = true;
1474
			panel.AutoSizeMode = AutoSizeMode.GrowOnly;
1475
			panel.WrapContents = true;
1476
			panel.Bounds = new Rectangle(5, 5, 100, 100);
1477
			panel.Dock = DockStyle.Left;
1478
1479
			var c = new Label ();
1480
			c.Size = new Size (25, 90);
1481
			panel.Controls.Add (c);
1482
			f.Controls.Add(panel);
1483
			panel.ResumeLayout (true);
1484
1485
			Assert.AreEqual (0, panel.Left, "1");
1486
			Assert.AreEqual (f.ClientRectangle.Height, panel.Height, "2");
1487
			Assert.AreEqual (31, panel.Width, "3"); // 25 + 2*3 margin
1488
		}
1489
1490
		[Test]
1491
		public void AutoSizeGrowOnly_ResizeIfSmaller_DockRight ()
1492
		{
1493
			f.ClientSize = new Size (300, 100);
1494
1495
			var panel = new FlowLayoutPanel ();
1496
			panel.SuspendLayout ();
1497
			panel.AutoSize = true;
1498
			panel.AutoSizeMode = AutoSizeMode.GrowOnly;
1499
			panel.WrapContents = true;
1500
			panel.Bounds = new Rectangle(5, 5, 100, 100);
1501
			panel.Dock = DockStyle.Right;
1502
1503
			var c = new Label ();
1504
			c.Size = new Size (25, 90);
1505
			panel.Controls.Add (c);
1506
			f.Controls.Add(panel);
1507
			panel.ResumeLayout (true);
1508
1509
			Assert.AreEqual (269, panel.Left, "1");
1510
			Assert.AreEqual (f.ClientRectangle.Height, panel.Height, "2");
1511
			Assert.AreEqual (31, panel.Width, "3"); // 25 + 2*3 margin
1512
		}
1513
1514
		[Test]
1515
		public void AutoSizeGrowAndShrink_ResizeIfSmaller ()
1516
		{
1517
			var panel = new FlowLayoutPanel ();
1518
			panel.SuspendLayout ();
1519
			panel.AutoSize = true;
1520
			panel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
1521
			panel.WrapContents = true;
1522
			panel.Bounds = new Rectangle (5, 5, 100, 100);
1523
			panel.Dock = DockStyle.None;
1524
1525
			var c = new Label ();
1526
			c.Size = new Size (90, 25);
1527
			panel.Controls.Add (c);
1528
			f.Controls.Add(panel);
1529
			panel.ResumeLayout (true);
1530
1531
			Assert.AreEqual (96, panel.Width, "1"); // 90 + 2*3 margin
1532
			Assert.AreEqual (25, panel.Height, "2");
1533
		}
1534
1535
		[Test]
1536
		public void AutoSizeGrowAndShrink_ResizeIfSmaller_DockBottom ()
1537
		{
1538
			var panel = new FlowLayoutPanel ();
1539
			panel.SuspendLayout ();
1540
			panel.AutoSize = true;
1541
			panel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
1542
			panel.WrapContents = true;
1543
			panel.Bounds = new Rectangle (5, 5, 100, 100);
1544
			panel.Dock = DockStyle.Bottom;
1545
1546
			var c = new Label ();
1547
			c.Size = new Size (90, 25);
1548
			panel.Controls.Add (c);
1549
			f.Controls.Add (panel);
1550
			panel.ResumeLayout (true);
1551
1552
			Assert.AreEqual (275, panel.Top, "1");
1553
			Assert.AreEqual (f.ClientRectangle.Width, panel.Width, "2");
1554
			Assert.AreEqual (25, panel.Height, "3");
1555
		}
1556
1557
		[Test]
1558
		public void NoAutoSize_DontResizeIfLarger ()
1559
		{
1560
			var panel = new FlowLayoutPanel ();
1561
			panel.SuspendLayout ();
1562
			panel.AutoSize = false;
1563
			panel.WrapContents = true;
1564
			panel.Bounds = new Rectangle (5, 5, 10, 10);
1565
			panel.Dock = DockStyle.None;
1566
1567
			var c = new Label ();
1568
			c.Size = new Size (90, 25);
1569
			panel.Controls.Add (c);
1570
			c = new Label ();
1571
			c.Size = new Size (90, 25);
1572
			panel.Controls.Add (c);
1573
			f.Controls.Add (panel);
1574
			panel.ResumeLayout (true);
1575
1576
			Assert.AreEqual (10, panel.Width, "1");
1577
			Assert.AreEqual (10, panel.Height, "2");
1578
		}
1579
1580
		[Test]
1581
		public void NoAutoSize_DontResizeIfLarger_DockBottom ()
1582
		{
1583
			var panel = new FlowLayoutPanel ();
1584
			panel.SuspendLayout ();
1585
			panel.AutoSize = false;
1586
			panel.WrapContents = true;
1587
			panel.Bounds = new Rectangle (5, 5, 10, 10);
1588
			panel.Dock = DockStyle.Bottom;
1589
1590
			var c = new Label ();
1591
			c.Size = new Size (90, 25);
1592
			panel.Controls.Add (c);
1593
			c = new Label ();
1594
			c.Size = new Size (90, 25);
1595
			panel.Controls.Add (c);
1596
			f.Controls.Add (panel);
1597
			panel.ResumeLayout (true);
1598
1599
			Assert.AreEqual (290, panel.Top, "1");
1600
			Assert.AreEqual (f.ClientRectangle.Width, panel.Width, "2");
1601
			Assert.AreEqual (10, panel.Height, "3");
1602
		}
1603
1604
		[Test]
1605
		public void NoAutoSize_DontResizeIfSmaller ()
1606
		{
1607
			var panel = new FlowLayoutPanel ();
1608
			panel.SuspendLayout ();
1609
			panel.AutoSize = false;
1610
			panel.WrapContents = true;
1611
			panel.Bounds = new Rectangle(5, 5, 100, 100);
1612
			panel.Dock = DockStyle.None;
1613
1614
			var c = new Label ();
1615
			c.Size = new Size (90, 25);
1616
			panel.Controls.Add (c);
1617
			f.Controls.Add (panel);
1618
			panel.ResumeLayout (true);
1619
1620
			Assert.AreEqual (100, panel.Width, "1");
1621
			Assert.AreEqual (100, panel.Height, "2");
1622
		}
1623
1624
		[Test]
1625
		public void NoAutoSize_DontResizeIfSmaller_DockBottom ()
1626
		{
1627
			var panel = new FlowLayoutPanel ();
1628
			panel.SuspendLayout ();
1629
			panel.AutoSize = false;
1630
			panel.WrapContents = true;
1631
			panel.Bounds = new Rectangle(5, 5, 100, 100);
1632
			panel.Dock = DockStyle.Bottom;
1633
1634
			var c = new Label ();
1635
			c.Size = new Size (90, 25);
1636
			panel.Controls.Add (c);
1637
			f.Controls.Add(panel);
1638
			panel.ResumeLayout (true);
1639
1640
			Assert.AreEqual (200, panel.Top, "1");
1641
			Assert.AreEqual (f.ClientRectangle.Width, panel.Width, "2");
1642
			Assert.AreEqual (100, panel.Height, "3");
1643
		}
1644
	}
1645
}

Return to bug 2912