* Pen.cs: Added a note on Dispose method.
[mono.git] / mcs / class / System.Drawing / System.Drawing / SolidBrush.cs
1 //
2 // System.Drawing.SolidBrush.cs
3 //
4 // Author:
5 //   Dennis Hayes (dennish@Raytek.com)
6 //   Alexandre Pigolkine(pigolkine@gmx.de)
7 //   Ravindra (rkumar@novell.com)
8 //
9 // (C) 2002 Ximian, Inc.
10 // (C) 2004 Novell, Inc.
11 //
12 using System;
13
14 namespace System.Drawing
15 {
16         public sealed class SolidBrush : Brush {
17                 
18                 internal bool isModifiable = true;
19                 private Color color;
20
21                 internal SolidBrush (IntPtr ptr)
22                         : base (ptr)
23                 {
24                         int val;
25                         Status status = GDIPlus.GdipGetSolidFillColor (ptr, out val);
26                         GDIPlus.CheckStatus (status);
27                         color = Color.FromArgb (val);
28                 }
29
30                 public SolidBrush (Color color)
31                 {
32                         this.color = color;
33                         int brush;
34                         Status status = GDIPlus.GdipCreateSolidFill (color.ToArgb (), out brush);
35                         GDIPlus.CheckStatus (status);
36                         nativeObject = (IntPtr) brush;
37                 }
38
39                 public Color Color {
40                         get {
41                                 return color;
42                         }
43                         set {
44                                 if (isModifiable) {
45                                         color = value;
46                                         Status status = GDIPlus.GdipSetSolidFillColor (nativeObject, value.ToArgb ());
47                                         GDIPlus.CheckStatus (status);
48                                 }
49                                 else
50                                         throw new ArgumentException ("This SolidBrush object can't be modified.");
51                         }
52                 }
53                 
54                 public override object Clone()
55                 {
56                         IntPtr clonePtr;
57                         Status status = GDIPlus.GdipCloneBrush (nativeObject, out clonePtr);
58                         GDIPlus.CheckStatus (status);
59
60                         SolidBrush clone = new SolidBrush (clonePtr);
61                         return clone;
62                 }
63                 
64                 protected override void Dispose (bool disposing)
65                 {
66                         // SolidBrush is disposed if and only if it is not disposed
67                         // and it is modifiable OR it is not disposed and it is being
68                         // collected by GC.
69                         if ((disposed == false) && (isModifiable || disposing == false)) {
70                                 Status status = GDIPlus.GdipDeleteBrush (nativeObject);
71                                 GDIPlus.CheckStatus (status);
72                                 disposed = true;
73                         }
74                         else
75                                 throw new ArgumentException ("This SolidBrush object can't be modified.");
76                 }
77         }
78 }
79