Browse Source

* Pen.cs: Modified exception message. Fixed Transform, DashPattern,
and DashCap properties. Implementing CoumpoundArray, StartCap, EndCap
properties and SetLineCap method. In constructors use IntPtr instead
of int.
* SolidBrush.cs: Modified exception message.
* TextureBrush.cs: Fixed Transform property.
* gdipFunctions.cs: Fixed P/Invokes for Pen.cs, TextureBrush.cs and
LinearGradientBrush.cs.

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

Ravindra 21 years ago
parent
commit
238da299bc

+ 11 - 0
mcs/class/System.Drawing/System.Drawing/ChangeLog

@@ -1,3 +1,14 @@
+2004-05-04  Ravindra <[email protected]>
+
+	* Pen.cs: Modified exception message. Fixed Transform, DashPattern,
+	and DashCap properties. Implementing CoumpoundArray, StartCap, EndCap
+	properties and SetLineCap method. In constructors use IntPtr instead
+	of int.
+	* SolidBrush.cs: Modified exception message.
+	* TextureBrush.cs: Fixed Transform property.
+	* gdipFunctions.cs: Fixed P/Invokes for Pen.cs, TextureBrush.cs and
+	LinearGradientBrush.cs.
+
 2004-04-30  Sanjay Gupta <[email protected]>
 
 	* Image.cs: Implemented FrameDimensionsList property.

+ 71 - 87
mcs/class/System.Drawing/System.Drawing/Pen.cs

@@ -22,7 +22,6 @@ namespace System.Drawing {
 		internal bool isModifiable = true;
 		internal Brush brush;
 		internal Color color;
-		internal Matrix matrix;
 
                 internal Pen (IntPtr p)
                 {
@@ -39,11 +38,9 @@ namespace System.Drawing {
 
 		public Pen (Brush brush, float width)
 		{
-			int pen;
-			Status status = GDIPlus.GdipCreatePen2 (brush.nativeObject, width, Unit.UnitWorld, out pen);
+			Status status = GDIPlus.GdipCreatePen2 (brush.nativeObject, width, Unit.UnitWorld, out nativeObject);
 			GDIPlus.CheckStatus (status);
 
-			nativeObject = (IntPtr) pen;
 			this.brush = brush;
 			if (brush is SolidBrush) {
 				color = ((SolidBrush) brush).Color;
@@ -54,10 +51,9 @@ namespace System.Drawing {
 
 		public Pen (Color color, float width)
 		{
-			int pen;
-			Status status = GDIPlus.GdipCreatePen1 (color.ToArgb (), width, Unit.UnitWorld, out pen);
+			Status status = GDIPlus.GdipCreatePen1 (color.ToArgb (), width, Unit.UnitWorld, out nativeObject);
 			GDIPlus.CheckStatus (status);
-			nativeObject = (IntPtr)pen;
+
 			this.color = color;
 			brush = new SolidBrush (color);
 			status = GDIPlus.GdipSetPenBrushFill (nativeObject, brush.nativeObject);
@@ -81,7 +77,7 @@ namespace System.Drawing {
 					GDIPlus.CheckStatus (status);
 				}
 				else
-					throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+					throw new ArgumentException ("This Pen object can't be modified.");
 
 			}
 		}
@@ -111,7 +107,7 @@ namespace System.Drawing {
 					}
 				}
 				else
-					throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+					throw new ArgumentException ("This Pen object can't be modified.");
 			}
 		}
 
@@ -130,41 +126,32 @@ namespace System.Drawing {
 					GDIPlus.CheckStatus (status);
 				}
 				else
-					throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+					throw new ArgumentException ("This Pen object can't be modified.");
 			}
 		}
 
-                public float [] CompoundArray {
-                        get {
-                                throw new NotImplementedException ();
-//                                 int count;
-//                                 Status status = GDIPlus.GdipGetPenCompoundArrayCount (nativeObject, out count);
-
-//                                 IntPtr tmp = Marshal.AllocHGlobal (8 * count);
-//                                 status = GDIPlus.GdipGetPenCompoundArray (nativeObject, out tmp, out count);
-
-//                                 float [] retval = new float [count];
-//                                 Marshal.Copy (tmp, retval, 0, count);
+		public float [] CompoundArray {
+			get {
+				int count;
+				Status status = GDIPlus.GdipGetPenCompoundCount (nativeObject, out count);
+				GDIPlus.CheckStatus (status);
 
-//                                 Marshal.FreeHGlobal (tmp);
+				float [] compArray = new float [count];
+				status = GDIPlus.GdipGetPenCompoundArray (nativeObject, compArray, count);
+				GDIPlus.CheckStatus (status);
 
-//                                 return retval;
-                        }
+				return compArray;
+			}
 
-                        set {
-                                throw new NotImplementedException ();                                
-//                              if (isModifiable) {
-//                                 int length = value.Length;
-//                                 IntPtr tmp = Marshal.AllocHGlobal (8 * length);
-//                                 Marshal.Copy (value, 0, tmp, length);
-//                                 Status status = GDIPlus.GdipSetPenCompoundArray (nativeObject, tmp, length);
-
-//                                 Marshal.FreeHGlobal (tmp);
-//                              }
-//                              else
-//				   throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
-                        }
-                }
+			set {
+				if (isModifiable) {
+					Status status = GDIPlus.GdipSetPenCompoundArray (nativeObject, value, value.Length);
+					GDIPlus.CheckStatus (status);
+				}
+				else
+					throw new ArgumentException ("This Pen object can't be modified.");
+			}
+		}
 
                 [MonoTODO]
                 public CustomLineCap CustomEndCap {
@@ -195,18 +182,18 @@ namespace System.Drawing {
 
                         get {
                                 DashCap retval;
-                                Status status = GDIPlus.GdipGetPenDashCap (nativeObject, out retval);
+                                Status status = GDIPlus.GdipGetPenDashCap197819 (nativeObject, out retval);
 				GDIPlus.CheckStatus (status);
                                 return retval;
                         }
 
                         set {
 				if (isModifiable) {
-                                	Status status = GDIPlus.GdipSetPenDashCap (nativeObject, value);
+                                	Status status = GDIPlus.GdipSetPenDashCap197819 (nativeObject, value);
 					GDIPlus.CheckStatus (status);
 				}
 				else
-					throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+					throw new ArgumentException ("This Pen object can't be modified.");
                         }
                 }
 
@@ -225,7 +212,7 @@ namespace System.Drawing {
 					GDIPlus.CheckStatus (status);
 				}
 				else
-					throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+					throw new ArgumentException ("This Pen object can't be modified.");
                         }
                 }
 
@@ -234,27 +221,21 @@ namespace System.Drawing {
                                 int count;
                                 Status status = GDIPlus.GdipGetPenDashCount (nativeObject, out count);
 				GDIPlus.CheckStatus (status);
-                                IntPtr tmp = Marshal.AllocHGlobal (8 * count);
-                                status = GDIPlus.GdipGetPenDashArray (nativeObject, out tmp, out count);
-                                float [] retval = new float [count];
-                                Marshal.Copy (tmp, retval, 0, count);
 
-                                Marshal.FreeHGlobal (tmp);
+				float [] pattern = new float [count];
+                                status = GDIPlus.GdipGetPenDashArray (nativeObject, pattern, count);
 				GDIPlus.CheckStatus (status);
-                                return retval;
+
+                                return pattern;
                         }
 
                         set {
 				if (isModifiable) {
-                                	int length = value.Length;
-                                	IntPtr tmp = Marshal.AllocHGlobal (8 * length);
-                                	Marshal.Copy (value, 0, tmp, length);
-                                	Status status = GDIPlus.GdipSetPenDashArray (nativeObject, tmp, length);
-                                	Marshal.FreeHGlobal (tmp);
+                                	Status status = GDIPlus.GdipSetPenDashArray (nativeObject, value, value.Length);
 					GDIPlus.CheckStatus (status);
 				}
 				else
-					throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+					throw new ArgumentException ("This Pen object can't be modified.");
                         }
                 }
 
@@ -272,43 +253,45 @@ namespace System.Drawing {
 					GDIPlus.CheckStatus (status);
 				}
 				else
-					throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+					throw new ArgumentException ("This Pen object can't be modified.");
 			}
 		}
 
 		public LineCap StartCap {
 			get {
-                                throw new NotImplementedException ();
-// 				LineCap retval;
-//                                 Status status = GDIPlus.GdipGetPenStartCap (nativeObject, out retval);
+				LineCap retval;
+				Status status = GDIPlus.GdipGetPenStartCap (nativeObject, out retval);
+				GDIPlus.CheckStatus (status);
 
-//                                 return retval;
+				return retval;
 			}
 
 			set {
-                                throw new NotImplementedException ();                                
-//			if (isModifiable)
-// 				Status status = GDIPlus.GdipSetPenStartCap (nativeObject, value);
-//			else
-//				throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+				if (isModifiable) {
+					Status status = GDIPlus.GdipSetPenStartCap (nativeObject, value);
+					GDIPlus.CheckStatus (status);
+				}
+				else
+					throw new ArgumentException ("This Pen object can't be modified.");
 			}
 		}
  
 		public LineCap EndCap {
 			get {
-                                throw new NotImplementedException ();                                
-// 				LineCap retval;
-//                                 Status status = GDIPlus.GdipGetPenEndCap (nativeObject, out retval);
+				LineCap retval;
+				Status status = GDIPlus.GdipGetPenEndCap (nativeObject, out retval);
+				GDIPlus.CheckStatus (status);
 
-//                                 return retval;
+				return retval;
 			}
 
 			set {
-                                throw new NotImplementedException ();                                
-//			if (isModifiable)
-// 				Status status = GDIPlus.GdipSetPenEndCap (nativeObject, value);
-//			else
-//				throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+				if (isModifiable) {
+					Status status = GDIPlus.GdipSetPenEndCap (nativeObject, value);
+					GDIPlus.CheckStatus (status);
+				}
+				else
+					throw new ArgumentException ("This Pen object can't be modified.");
 			}
 		}
  
@@ -327,7 +310,7 @@ namespace System.Drawing {
 					GDIPlus.CheckStatus (status);
 				}
 				else
-					throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+					throw new ArgumentException ("This Pen object can't be modified.");
                         }
                                 
                 }
@@ -347,7 +330,7 @@ namespace System.Drawing {
 					GDIPlus.CheckStatus (status);
 				}
 				else
-					throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+					throw new ArgumentException ("This Pen object can't be modified.");
                         }
                                 
                 }
@@ -371,12 +354,10 @@ namespace System.Drawing {
                 public Matrix Transform {
 
                         get {
-				if (matrix == null) {
-					IntPtr m;
-					Status status = GDIPlus.GdipGetPenTransform (nativeObject, out m);
-					GDIPlus.CheckStatus (status);
-					matrix = new Matrix (m);
-				}
+				Matrix matrix = new Matrix ();
+				Status status = GDIPlus.GdipGetPenTransform (nativeObject, matrix.nativeMatrix);
+				GDIPlus.CheckStatus (status);
+
 				return matrix;
                         }
 
@@ -384,10 +365,9 @@ namespace System.Drawing {
 				if (isModifiable) {
                                 	Status status = GDIPlus.GdipSetPenTransform (nativeObject, value.nativeMatrix);
 					GDIPlus.CheckStatus (status);
-					matrix = value;
 				}
 				else
-					throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+					throw new ArgumentException ("This Pen object can't be modified.");
                         }
                 }
 
@@ -404,7 +384,7 @@ namespace System.Drawing {
 					GDIPlus.CheckStatus (status);
 				}
 				else
-					throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+					throw new ArgumentException ("This Pen object can't be modified.");
 			}
 		}
 
@@ -430,7 +410,7 @@ namespace System.Drawing {
 				GDIPlus.CheckStatus (status);
 			}
 			else
-				throw new ArgumentException ("You may not change this Pen because it does not belong to you.");
+				throw new ArgumentException ("This Pen object can't be modified.");
 		}
 
 		~Pen ()
@@ -479,8 +459,12 @@ namespace System.Drawing {
 
                 public void SetLineCap (LineCap startCap, LineCap endCap, DashCap dashCap)
                 {
-			// do a check for isModifiable when implementing this method
-                        // Status status = GDIPlus.GdipSetLineCap197819 (nativeObject, startCap, endCap, dashCap);
+			if (isModifiable) {
+				Status status = GDIPlus.GdipSetPenLineCap197819 (nativeObject, startCap, endCap, dashCap);
+				GDIPlus.CheckStatus (status);
+			}
+			else
+				throw new ArgumentException ("This Pen object can't be modified.");
                 }
 
                 public void TranslateTransform (float dx, float dy)

+ 2 - 2
mcs/class/System.Drawing/System.Drawing/SolidBrush.cs

@@ -47,7 +47,7 @@ namespace System.Drawing
 					GDIPlus.CheckStatus (status);
 				}
 				else
-					throw new ArgumentException ("You may not change this Brush because it does not belong to you.");
+					throw new ArgumentException ("This SolidBrush object can't be modified.");
 			}
 		}
 		
@@ -69,7 +69,7 @@ namespace System.Drawing
 				GDIPlus.CheckStatus (status);
 			}
 			else
-				throw new ArgumentException ("You may not change this Brush because it does not belong to you.");
+				throw new ArgumentException ("This SolidBrush object can't be modified.");
 		}
 	}
 }

+ 4 - 9
mcs/class/System.Drawing/System.Drawing/TextureBrush.cs

@@ -21,14 +21,12 @@ namespace System.Drawing
 	public sealed class TextureBrush : Brush
 	{
 		Image image;
-		Matrix matrix;
 
 		internal TextureBrush (IntPtr ptr) : base (ptr)
 		{
 			// get image from IntPtr
 			// image could be Bitmap or Metafile
 			image = Image;
-			matrix = Transform;
 		}
 
 		public TextureBrush (Image image) : this (image, WrapMode.Tile)
@@ -100,18 +98,15 @@ namespace System.Drawing
 
 		public Matrix Transform {
 			get {
-				if (matrix == null) {
-					IntPtr m;
-					Status status =	GDIPlus.GdipGetTextureTransform (nativeObject, out m);
-					GDIPlus.CheckStatus (status);
-					matrix = new Matrix (m);
-				}
+				Matrix matrix = new Matrix ();
+				Status status =	GDIPlus.GdipGetTextureTransform (nativeObject, matrix.nativeMatrix);
+				GDIPlus.CheckStatus (status);
+
 				return matrix;
 			}
 			set {
 				Status status = GDIPlus.GdipSetTextureTransform (nativeObject, value.nativeMatrix);
 				GDIPlus.CheckStatus (status);
-				matrix = value;
 			}
 		}
 

+ 25 - 30
mcs/class/System.Drawing/System.Drawing/gdipFunctions.cs

@@ -297,7 +297,7 @@ namespace System.Drawing {
 		[DllImport("gdiplus.dll")]
 		static internal extern Status GdipCreateTexture2 (IntPtr image, WrapMode wrapMode, float x, float y, float width, float height, out IntPtr texture);
 		[DllImport("gdiplus.dll")]
-		static internal extern Status GdipGetTextureTransform (IntPtr texture, out IntPtr matrix);
+		static internal extern Status GdipGetTextureTransform (IntPtr texture, IntPtr matrix);
 		[DllImport("gdiplus.dll")]
 		static internal extern Status GdipSetTextureTransform (IntPtr texture, IntPtr matrix);
 		[DllImport("gdiplus.dll")]
@@ -397,7 +397,7 @@ namespace System.Drawing {
 		[DllImport("gdiplus.dll")]
 		static internal extern Status GdipSetLineTransform (IntPtr brush, IntPtr matrix);
 		[DllImport("gdiplus.dll")]
-		static internal extern Status GdipGetLineTransform (IntPtr brush, out IntPtr matrix);
+		static internal extern Status GdipGetLineTransform (IntPtr brush, IntPtr matrix);
 		[DllImport("gdiplus.dll")]
 		static internal extern Status GdipSetLineWrapMode (IntPtr brush, WrapMode wrapMode);
 		[DllImport("gdiplus.dll")]
@@ -651,9 +651,9 @@ namespace System.Drawing {
 				
 		// Pen functions
 		[DllImport("gdiplus.dll")]
-		internal static extern Status GdipCreatePen1(int argb, float width, Unit unit, out int pen);
+		internal static extern Status GdipCreatePen1 (int argb, float width, Unit unit, out IntPtr pen);
 		[DllImport("gdiplus.dll")]
-		internal static extern Status GdipCreatePen2 (IntPtr brush, float width, Unit unit, out int pen);
+		internal static extern Status GdipCreatePen2 (IntPtr brush, float width, Unit unit, out IntPtr pen);
                 [DllImport("gdiplus.dll")]
                 internal static extern Status GdipClonePen (IntPtr pen, out IntPtr clonepen);
 		[DllImport("gdiplus.dll")]
@@ -666,16 +666,16 @@ namespace System.Drawing {
                 internal static extern Status GdipSetPenColor (IntPtr pen, int color);
                 [DllImport("gdiplus.dll")]                
                 internal static extern Status GdipGetPenColor (IntPtr pen, out int color);
-//                 [DllImport("gdiplus.dll")]
-//                 internal static extern Status GdipSetPenCompoundArray (IntPtr pen, IntPtr dash, int count);
-//                 [DllImport("gdiplus.dll")]
-//                 internal static extern Status GdipGetPenCompoundArray (IntPtr pen, out IntPtr dash, out int count);
-//                 [DllImport("gdiplus.dll")]
-//                 internal static extern Status GdipGetPenCompoundArrayCount (IntPtr pen, out int count);
                 [DllImport("gdiplus.dll")]
-                internal static extern Status GdipSetPenDashCap (IntPtr pen, DashCap dashCap);
+                internal static extern Status GdipSetPenCompoundArray (IntPtr pen, float[] dash, int count);
                 [DllImport("gdiplus.dll")]
-                internal static extern Status GdipGetPenDashCap (IntPtr pen, out DashCap dashCap);
+                internal static extern Status GdipGetPenCompoundArray (IntPtr pen, float[] dash, int count);
+                [DllImport("gdiplus.dll")]
+                internal static extern Status GdipGetPenCompoundCount (IntPtr pen, out int count);
+                [DllImport("gdiplus.dll")]
+                internal static extern Status GdipSetPenDashCap197819 (IntPtr pen, DashCap dashCap);
+                [DllImport("gdiplus.dll")]
+                internal static extern Status GdipGetPenDashCap197819 (IntPtr pen, out DashCap dashCap);
                 [DllImport("gdiplus.dll")]
                 internal static extern Status GdipSetPenDashStyle (IntPtr pen, DashStyle dashStyle);
                 [DllImport("gdiplus.dll")]
@@ -685,13 +685,11 @@ namespace System.Drawing {
                 [DllImport("gdiplus.dll")]
                 internal static extern Status GdipGetPenDashOffset (IntPtr pen, out float offset);
                 [DllImport("gdiplus.dll")]
-                internal static extern Status GdipSetPenDashCount (IntPtr pen, int count);
-                [DllImport("gdiplus.dll")]
                 internal static extern Status GdipGetPenDashCount (IntPtr pen, out int count);
                 [DllImport("gdiplus.dll")]
-                internal static extern Status GdipSetPenDashArray (IntPtr pen, IntPtr dash, int count);
+                internal static extern Status GdipSetPenDashArray (IntPtr pen, float[] dash, int count);
                 [DllImport("gdiplus.dll")]
-                internal static extern Status GdipGetPenDashArray (IntPtr pen, out IntPtr dash, out int count);
+                internal static extern Status GdipGetPenDashArray (IntPtr pen, float[] dash, int count);
 		[DllImport("gdiplus.dll")]
                 internal static extern Status GdipSetPenMiterLimit (IntPtr pen, float miterLimit);
 		[DllImport("gdiplus.dll")]
@@ -700,31 +698,28 @@ namespace System.Drawing {
                 internal static extern Status GdipSetPenLineJoin (IntPtr pen, LineJoin lineJoin);
 		[DllImport("gdiplus.dll")]
                 internal static extern Status GdipGetPenLineJoin (IntPtr pen, out LineJoin lineJoin);
-// 		[DllImport("gdiplus.dll")]
-//                 internal static extern Status GdipSetPenLineCap197819 (IntPtr pen, LineCap startCap, LineCap endCap, DashCap dashCap);
-// 		[DllImport("gdiplus.dll")]
-//                 internal static extern Status GdipGetPenLineCap197819 (IntPtr pen, out LineCap startCap, out LineCap endCap, out DashCap dashCap);
+		[DllImport("gdiplus.dll")]
+		internal static extern Status GdipSetPenLineCap197819 (IntPtr pen, LineCap startCap, LineCap endCap, DashCap dashCap);
 		[DllImport("gdiplus.dll")]
                 internal static extern Status GdipSetPenMode (IntPtr pen, PenAlignment alignment);
 		[DllImport("gdiplus.dll")]
                 internal static extern Status GdipGetPenMode (IntPtr pen, out PenAlignment alignment);
-// 		[DllImport("gdiplus.dll")]
-//                 internal static extern Status GdipSetPenStartCap (IntPtr pen, LineCap startCap);
-// 		[DllImport("gdiplus.dll")]
-//                 internal static extern Status GdipGetPenStartCap (IntPtr pen, out LineCap startCap);
-// 		[DllImport("gdiplus.dll")]
-//                 internal static extern Status GdipSetPenEndCap (IntPtr pen, LineCap endCap);
-// 		[DllImport("gdiplus.dll")]
-//                 internal static extern Status GdipGetPenEndCap (IntPtr pen, out LineCap endCap);
+		[DllImport("gdiplus.dll")]
+		internal static extern Status GdipSetPenStartCap (IntPtr pen, LineCap startCap);
+		[DllImport("gdiplus.dll")]
+		internal static extern Status GdipGetPenStartCap (IntPtr pen, out LineCap startCap);
+		[DllImport("gdiplus.dll")]
+		internal static extern Status GdipSetPenEndCap (IntPtr pen, LineCap endCap);
+		[DllImport("gdiplus.dll")]
+		internal static extern Status GdipGetPenEndCap (IntPtr pen, out LineCap endCap);
 		[DllImport("gdiplus.dll")]
                 internal static extern Status GdipSetPenTransform (IntPtr pen, IntPtr matrix);
 		[DllImport("gdiplus.dll")]
-                internal static extern Status GdipGetPenTransform (IntPtr pen, out IntPtr matrix);
+                internal static extern Status GdipGetPenTransform (IntPtr pen, IntPtr matrix);
 		[DllImport("gdiplus.dll")]
                 internal static extern Status GdipSetPenWidth (IntPtr pen, float width);
 		[DllImport("gdiplus.dll")]
                 internal static extern Status GdipGetPenWidth (IntPtr pen, out float width);
-                
 		[DllImport("gdiplus.dll")]
                 internal static extern Status GdipResetPenTransform (IntPtr pen);
 		[DllImport("gdiplus.dll")]