Browse Source

fixed: CopyFrom and MergeWith behave differently between 1.1 and 2.0.
added ClearDefaults method for 2.0.

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

Igor Zelmanovich 19 years ago
parent
commit
206b4d0fed

+ 6 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,9 @@
+2006-08-22 Igor Zelmanovich <[email protected]>
+
+	* FontInfo.cs: 
+	fixed: CopyFrom and MergeWith behave differently between 1.1 and 2.0.
+	added ClearDefaults method for 2.0.
+
 2006-08-08 Vladimir Krasnov <[email protected]>
 
 	* ObjectDataSourceStatusEventArgs.cs: ExceptionHandled default value

+ 73 - 1
mcs/class/System.Web/System.Web.UI.WebControls/FontInfo.cs

@@ -311,11 +311,44 @@ namespace System.Web.UI.WebControls {
 		#region Public Instance Methods
 		public void CopyFrom(FontInfo f) 
 		{
+			//Methods CopyFrom and MergeWith behave differently between 1.1 and 2.0
+			if (f == null || f.IsEmpty)
+				return;
+
 			if (f == this)
 				return;
 
-			this.Reset();
+#if NET_2_0
+			// MS stores the property in the bag if it's value is false
+			if ((f.fontstyles & FontStyles.Bold) != 0) {
+				this.Bold = f.Bold;
+			}
+
+			if ((f.fontstyles & FontStyles.Italic) != 0) {
+				this.Italic = f.Italic;
+			}
+
+			// MS seems to have some weird behaviour, even if f's Name has been set to String.Empty we still get an empty array
+			if ((f.fontstyles & FontStyles.Names) != 0) {
+				this.Names = f.Names;
+			}
+
+			if ((f.fontstyles & FontStyles.Overline) != 0) {
+				this.Overline = f.Overline;
+			}
+
+			if ((f.fontstyles & FontStyles.Size) != 0) {
+				this.Size = f.Size;
+			}
+
+			if ((f.fontstyles & FontStyles.Strikeout) != 0) {
+				this.Strikeout = f.Strikeout;
+			}
 
+			if ((f.fontstyles & FontStyles.Underline) != 0) {
+				this.Underline = f.Underline;
+			}
+#else
 			// MS does not store the property in the bag if it's value is false
 			if (((f.fontstyles & FontStyles.Bold) != 0) && f.Bold) 
 			{
@@ -352,10 +385,41 @@ namespace System.Web.UI.WebControls {
 			{
 				this.Underline = true;
 			}
+#endif
 		}
 
 		public void MergeWith(FontInfo f) 
 		{
+			//Methods CopyFrom and MergeWith behave differently between 1.1 and 2.0
+#if NET_2_0
+			if (((fontstyles & FontStyles.Bold) == 0) && ((f.fontstyles & FontStyles.Bold) != 0)) {
+				this.Bold = f.Bold;
+			}
+
+			if (((fontstyles & FontStyles.Italic) == 0) && ((f.fontstyles & FontStyles.Italic) != 0)) {
+				this.Italic = f.Italic;
+			}
+
+			if (((fontstyles & FontStyles.Names) == 0) && ((f.fontstyles & FontStyles.Names) != 0)) {
+				this.Names = f.Names;
+			}
+
+			if (((fontstyles & FontStyles.Overline) == 0) && ((f.fontstyles & FontStyles.Overline) != 0)) {
+				this.Overline = f.Overline;
+			}
+
+			if (((fontstyles & FontStyles.Size) == 0) && ((f.fontstyles & FontStyles.Size) != 0)) {
+				this.Size = f.Size;
+			}
+
+			if (((fontstyles & FontStyles.Strikeout) == 0) && ((f.fontstyles & FontStyles.Strikeout) != 0)) {
+				this.Strikeout = f.Strikeout;
+			}
+
+			if (((fontstyles & FontStyles.Underline) == 0) && ((f.fontstyles & FontStyles.Underline) != 0)) {
+				this.Underline = f.Underline;
+			}
+#else
 			if (((fontstyles & FontStyles.Bold) == 0) && ((f.fontstyles & FontStyles.Bold) != 0) && f.Bold) 
 			{
 				this.Bold = true;
@@ -390,6 +454,7 @@ namespace System.Web.UI.WebControls {
 			{
 				this.Underline = true;
 			}
+#endif
 		}
 
 		public bool ShouldSerializeNames() 
@@ -406,6 +471,13 @@ namespace System.Web.UI.WebControls {
 
 			return this.Name + ", " + this.Size.ToString();
 		}
+#if NET_2_0
+
+		public void ClearDefaults () {
+			Reset ();
+		}
+
+#endif
 		#endregion	// Public Instance Methods
 
 		#region Private Methods

+ 4 - 0
mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,7 @@
+2006-08-22 Igor Zelmanovich <[email protected]>
+
+	* FontInfoTest.cs: added test: CopyFrom and MergeWith behave differently between 1.1 and 2.0 
+
 2006-08-17 Igor Zelmanovich <[email protected]>
 
 	* StyleTest.cs: added test ensures that IsEmpty returns false for 

+ 56 - 0
mcs/class/System.Web/Test/System.Web.UI.WebControls/FontInfoTest.cs

@@ -90,6 +90,62 @@ namespace MonoTests.System.Web.UI.WebControls
 			copy.CopyFrom (s);
 			Assert.AreEqual (s.BackColor, Color.Red, "Copy1");
 		}
+
+		[Test]
+		public void FontInfo_CopyFrom () {
+
+			//Methods CopyFrom and MergeWith behave differently between 1.1 and 2.0
+			Style s = new Style ();
+			Style copy = new Style ();
+
+			s.Font.Bold = true;
+			s.Font.Underline = false;
+
+			copy.Font.Italic = true;
+			copy.Font.Underline = true;
+
+			copy.Font.CopyFrom (s.Font);
+
+			Assert.AreEqual (true, copy.Font.Italic, "CopyFrom#1");
+			Assert.AreEqual (true, copy.Font.Bold, "CopyFrom#2");
+#if NET_2_0
+			Assert.AreEqual (false, copy.Font.Underline, "CopyFrom#3");
+#else
+			Assert.AreEqual (true, copy.Font.Underline, "CopyFrom#3");
+#endif
+		}
+		
+		[Test]
+		public void FontInfo_MergeWith () {
+
+			//Methods CopyFrom and MergeWith behave differently between 1.1 and 2.0
+			Style s = new Style ();
+			Style copy = new Style ();
+
+			s.Font.Overline = false;
+			s.Font.Bold = true;
+			s.Font.Underline = true;
+
+			copy.Font.Italic = true;
+			copy.Font.Underline = false;
+
+			copy.Font.MergeWith (s.Font);
+
+			Assert.AreEqual (true, copy.Font.Italic, "MergeWith#1");
+			Assert.AreEqual (true, copy.Font.Bold, "MergeWith#2");
+			Assert.AreEqual (false, copy.Font.Underline, "MergeWith#3");
+			Assert.AreEqual (false, copy.Font.Overline, "MergeWith#4");
+
+			Style copy2 = new Style ();
+			copy2.Font.Overline = true;
+			copy2.Font.CopyFrom (copy.Font);
+
+#if NET_2_0
+			Assert.AreEqual (false, copy2.Font.Overline, "MergeWith#5");
+#else
+			Assert.AreEqual (true, copy2.Font.Overline, "MergeWith#5");
+#endif
+		}
 	}
 }