Kaynağa Gözat

* Control.cs: Verify value set for Dock property. Code formatting
updates.
* ControlTest.cs: Added test for invalid Dock value.

svn path=/trunk/mcs/; revision=69352

Gert Driesen 19 yıl önce
ebeveyn
işleme
e1c5262e98

+ 5 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog

@@ -1,3 +1,8 @@
+2006-12-11  Gert Driesen  <[email protected]>
+
+	* Control.cs: Verify value set for Dock property. Code formatting
+	updates.
+
 2006-12-11  Jackson Harper  <[email protected]>
 
 	* TextControl.cs: Draw the caret and the selection when a flag is

+ 39 - 39
mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs

@@ -56,7 +56,7 @@ namespace System.Windows.Forms
 	[DesignerSerializer("System.Windows.Forms.Design.ControlCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
 	[ToolboxItemFilter("System.Windows.Forms")]
 	public class Control : Component, ISynchronizeInvoke, IWin32Window
-        {
+	{
 		#region Local Variables
 
 		// Basic
@@ -332,9 +332,9 @@ namespace System.Windows.Forms
 				if (value == null)
 					return;
 				
-                                if (Contains (value)) {
+				if (Contains (value)) {
 					owner.PerformLayout();
-                                        return;
+					return;
 				}
 
 				if (value.tab_index == -1) {
@@ -695,8 +695,8 @@ namespace System.Windows.Forms
 		#endregion	// ControlCollection Class
 		
 		#region Public Constructors
-		public Control() {			
-
+		public Control()
+		{
 			anchor_style = AnchorStyles.Top | AnchorStyles.Left;
 
 			is_created = false;
@@ -709,7 +709,7 @@ namespace System.Windows.Forms
 			is_toplevel = false;
 			causes_validation = true;
 			has_focus = false;
-			layout_suspended = 0;		
+			layout_suspended = 0;
 			mouse_clicks = 1;
 			tab_index = -1;
 			cursor = null;
@@ -743,7 +743,7 @@ namespace System.Windows.Forms
 			parent = null;
 			background_image = null;
 			text = string.Empty;
-			name = string.Empty;			
+			name = string.Empty;
 
 			window = new ControlNativeWindow(this);
 			child_controls = CreateControlsInstance();
@@ -804,7 +804,6 @@ namespace System.Windows.Forms
 					DestroyHandle();
 				}
 
-
 				if (parent != null) {
 					parent.Controls.Remove(this);
 				}
@@ -849,9 +848,7 @@ namespace System.Windows.Forms
 			AsyncMethodData		data;
 
 			if (!disposing) {
-				Control			p;
-
-				p = this;
+				Control p = this;
 				do {
 					if (!p.IsHandleCreated) {
 						throw new InvalidOperationException("Cannot call Invoke or InvokeAsync on a control until the window handle is created");
@@ -1122,7 +1119,7 @@ namespace System.Windows.Forms
 				buttons |= MouseButtons.Middle;
 				
 			if ((param & (int) MsgButtons.MK_RBUTTON) != 0)
-				buttons |= MouseButtons.Right;    	
+				buttons |= MouseButtons.Right;
 				
 			return buttons;
 
@@ -1166,7 +1163,6 @@ namespace System.Windows.Forms
 				index = -1;
 			}
 
-
 			for (int i = 0, pos = -1; i < end; i++) {
 				if (start == container.child_controls[i]) {
 					pos = i;
@@ -1336,7 +1332,6 @@ namespace System.Windows.Forms
 			}
 		}
 
-
 		private void ChangeParent(Control new_parent) {
 			bool		pre_enabled;
 			bool		pre_visible;
@@ -1810,7 +1805,7 @@ namespace System.Windows.Forms
 		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
 		public bool ContainsFocus {
 			get {
-				IntPtr	focused_window;
+				IntPtr focused_window;
 
 				focused_window = XplatUI.GetFocus();
 				if (IsHandleCreated) {
@@ -1877,7 +1872,7 @@ namespace System.Windows.Forms
 
 			set {
 				if (cursor != value) {
-					Point	pt;
+					Point pt;
 
 					cursor = value;
 					
@@ -1949,6 +1944,11 @@ namespace System.Windows.Forms
 					return;
 				}
 
+				if (!Enum.IsDefined (typeof (DockStyle), value)) {
+					throw new InvalidEnumArgumentException ("value", (int) value,
+						typeof (DockStyle));
+				}
+
 				dock_style = value;
 
 				if (dock_style == DockStyle.None) {
@@ -1990,12 +1990,12 @@ namespace System.Windows.Forms
 				if (old_value != value && !value && this.has_focus)
 					SelectNextControl(this, true, true, true, true);
 
-				OnEnabledChanged (EventArgs.Empty);				
+				OnEnabledChanged (EventArgs.Empty);
 			}
 		}
 
 		[EditorBrowsable(EditorBrowsableState.Advanced)]
-	        [Browsable(false)]
+		[Browsable(false)]
 		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
 		public virtual bool Focused {
 			get {
@@ -2004,7 +2004,7 @@ namespace System.Windows.Forms
 		}
 
 		[DispId(-512)]
-	        [AmbientValue(null)]
+		[AmbientValue(null)]
 		[Localizable(true)]
 		[MWFCategory("Appearance")]
 		public virtual Font Font {
@@ -2026,9 +2026,9 @@ namespace System.Windows.Forms
 					return;
 				}
 
-				font = value;	
+				font = value;
 				Invalidate();
-				OnFontChanged (EventArgs.Empty);				
+				OnFontChanged (EventArgs.Empty);
 			}
 		}
 
@@ -2104,10 +2104,10 @@ namespace System.Windows.Forms
 		public ImeMode ImeMode {
 			get {
 				if (ime_mode == ImeMode.Inherit) {
-                                	if (parent != null)
-                                                return parent.ImeMode;
-                                        else
-                                                return ImeMode.NoControl; // default value
+					if (parent != null)
+						return parent.ImeMode;
+					else
+						return ImeMode.NoControl; // default value
 				}
 				return ime_mode;
 			}
@@ -2122,7 +2122,7 @@ namespace System.Windows.Forms
 		}
 
 		[EditorBrowsable(EditorBrowsableState.Advanced)]
-	        [Browsable(false)]
+		[Browsable(false)]
 		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
 		public bool InvokeRequired {						// ISynchronizeInvoke
 			get {
@@ -2262,13 +2262,13 @@ namespace System.Windows.Forms
 		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
 		public string ProductName {
 			get {
-                                Type t = typeof (AssemblyProductAttribute);
-                                Assembly assembly = GetType().Module.Assembly;
-                                object [] attrs = assembly.GetCustomAttributes (t, false);
-                                AssemblyProductAttribute a = null;
-                                // On MS we get a NullRefException if product attribute is not
-                                // set. 
-                              	if (attrs != null && attrs.Length > 0)
+				Type t = typeof (AssemblyProductAttribute);
+				Assembly assembly = GetType().Module.Assembly;
+				object [] attrs = assembly.GetCustomAttributes (t, false);
+				AssemblyProductAttribute a = null;
+				// On MS we get a NullRefException if product attribute is not
+				// set. 
+				if (attrs != null && attrs.Length > 0)
 					a = (AssemblyProductAttribute) attrs [0];
 				return a.Product;
 			}
@@ -2679,7 +2679,7 @@ namespace System.Windows.Forms
 		}
 
 		public static bool IsMnemonic(char charCode, string text) {
-			int amp;			
+			int amp;
 
 			amp = text.IndexOf('&');
 
@@ -3175,7 +3175,7 @@ namespace System.Windows.Forms
 			BackColor = Color.Empty;
 		}
 
-	        [EditorBrowsable(EditorBrowsableState.Never)]
+		[EditorBrowsable(EditorBrowsableState.Never)]
 		public void ResetBindings() {
 			data_bindings.Clear();
 		}
@@ -3282,7 +3282,7 @@ namespace System.Windows.Forms
 					c.Select (true, true);
 					return true;
 				}
-			} while (c != ctl);	// If we wrap back to ourselves we stop
+			} while (c != ctl); // If we wrap back to ourselves we stop
 
 			return false;
 		}
@@ -4318,7 +4318,7 @@ namespace System.Windows.Forms
 			}
 
 			default:
-				DefWndProc(ref m);	
+				DefWndProc(ref m);
 				return;
 			}
 		}
@@ -4996,7 +4996,7 @@ namespace System.Windows.Forms
 			add { Events.AddHandler (DockChangedEvent, value); }
 			remove { Events.RemoveHandler (DockChangedEvent, value); }
 		}
-      
+
 		public event EventHandler DoubleClick {
 			add { Events.AddHandler (DoubleClickEvent, value); }
 			remove { Events.RemoveHandler (DoubleClickEvent, value); }
@@ -5021,7 +5021,7 @@ namespace System.Windows.Forms
 			add { Events.AddHandler (DragOverEvent, value); }
 			remove { Events.RemoveHandler (DragOverEvent, value); }
 		}
-	       
+
 		public event EventHandler EnabledChanged {
 			add { Events.AddHandler (EnabledChangedEvent, value); }
 			remove { Events.RemoveHandler (EnabledChangedEvent, value); }

+ 4 - 0
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog

@@ -1,3 +1,7 @@
+2006-12-11  Gert Driesen  <[email protected]>
+
+	* ControlTest.cs: Added test for invalid Dock value.
+
 2006-12-11  Andreia Gaita  <[email protected]>
 
 	* TabControlTest.cs: add tests to check if SelectedIndex is

+ 19 - 2
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ControlTest.cs

@@ -6,11 +6,12 @@
 //
 
 using System;
-using System.Windows.Forms;
+using InvalidEnumArgumentException = System.ComponentModel.InvalidEnumArgumentException;
 using System.Drawing;
-using System.Threading;
 using System.Reflection;
 using System.Runtime.Remoting;
+using System.Threading;
+using System.Windows.Forms;
 
 using NUnit.Framework;
 
@@ -905,6 +906,22 @@ namespace MonoTests.System.Windows.Forms
 			Assert.AreEqual(Control.DefaultBackColor, c.BackColor, "Setting empty color failed");
 		}
 
+		[Test]
+		public void Dock_Value_Invalid ()
+		{
+			Control c = new Control ();
+			try {
+				c.Dock = (DockStyle) 666;
+				Assert.Fail ("#1");
+			} catch (InvalidEnumArgumentException ex) {
+				Assert.AreEqual (typeof (InvalidEnumArgumentException), ex.GetType (), "#2");
+				Assert.IsNotNull (ex.Message, "#3");
+				Assert.IsNotNull (ex.ParamName, "#4");
+				Assert.AreEqual ("value", ex.ParamName, "#5");
+				Assert.IsNull (ex.InnerException, "#6");
+			}
+		}
+
 		[Test]
 		public void EnabledTest1() {
 			Control	child;