2009-08-31 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / FlatButtonAppearance.cs
1 //
2 //  FlatButtonAppearance.cs
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Copyright (c) 2006 Daniel Nauck
24 //
25 // Author:
26 //      Daniel Nauck    (dna(at)mono-project(dot)de)
27
28
29 using System;
30 using System.ComponentModel;
31 using System.Drawing;
32 using System.Windows.Forms;
33 using System.Globalization;
34
35 namespace System.Windows.Forms
36 {
37 #if NET_2_0
38         [TypeConverter (typeof (FlatButtonAppearanceConverter))]
39         public 
40 #endif
41         class FlatButtonAppearance
42         {
43                 private Color borderColor = Color.Empty;
44                 private int borderSize = 1;
45                 private Color checkedBackColor = Color.Empty;
46                 private Color mouseDownBackColor = Color.Empty;
47                 private Color mouseOverBackColor = Color.Empty;
48                 private ButtonBase owner = null;
49
50                 internal FlatButtonAppearance (ButtonBase owner)
51                 {
52                         this.owner = owner;
53                 }
54
55                 [EditorBrowsable(EditorBrowsableState.Always)]
56                 [DefaultValue(typeof(Color), "")]
57                 [NotifyParentProperty(true)]
58                 [Browsable(true)]
59                 public Color BorderColor
60                 {
61                         get { return borderColor; }
62                         set {
63                                 if(borderColor == value)
64                                         return;
65
66                                 if (value == Color.Transparent)
67                                         throw new NotSupportedException ("Cannot have a Transparent border.");
68                                         
69                                 borderColor = value;
70                                 
71                                 if(owner != null)
72                                         owner.Invalidate ();
73                         }
74                 }
75
76                 [EditorBrowsable(EditorBrowsableState.Always)]
77                 [DefaultValue(1)]
78                 [NotifyParentProperty(true)]
79                 [Browsable(true)]
80                 public int BorderSize
81                 {
82                         get { return borderSize; }
83                         set {
84                                 if(borderSize == value)
85                                         return;
86
87                                 if (value < 0)
88                                         throw new ArgumentOutOfRangeException ("value", string.Format ("'{0}' is not a valid value for 'BorderSize'. 'BorderSize' must be greater or equal than {1}.", value, 0));
89
90                                 borderSize = value;
91
92                                 if(owner != null)
93                                         owner.Invalidate ();
94                         }
95                 }
96
97                 [EditorBrowsable(EditorBrowsableState.Always)]
98                 [DefaultValue(typeof(Color), "")]
99                 [NotifyParentProperty(true)]
100                 [Browsable(true)]
101                 public Color CheckedBackColor 
102                 {
103                         get { return checkedBackColor; }
104                         set {
105                                 if(checkedBackColor == value)
106                                         return;
107
108                                 checkedBackColor = value;
109
110                                 if(owner != null)
111                                         owner.Invalidate ();
112                         }
113                 }
114
115                 [EditorBrowsable(EditorBrowsableState.Always)]
116                 [DefaultValue(typeof(Color), "")]
117                 [Browsable(true)]
118                 [NotifyParentProperty(true)]
119                 public Color MouseDownBackColor
120                 {
121                         get { return mouseDownBackColor; }
122                         set {
123                                 if(mouseDownBackColor == value)
124                                         return;
125
126                                 mouseDownBackColor = value;
127
128                                 if(owner != null)
129                                         owner.Invalidate ();
130                         }
131                 }
132
133                 [EditorBrowsable(EditorBrowsableState.Always)]
134                 [DefaultValue(typeof(Color), "")]
135                 [NotifyParentProperty(true)]
136                 [Browsable(true)]
137                 public Color MouseOverBackColor
138                 {
139                         get { return mouseOverBackColor; }
140                         set {
141                                 if(mouseOverBackColor == value)
142                                         return;
143
144                                 mouseOverBackColor = value;
145
146                                 if(owner != null)
147                                         owner.Invalidate ();
148                         }
149                 }
150         }
151         
152 #if NET_2_0
153         internal class FlatButtonAppearanceConverter : ExpandableObjectConverter
154         {
155                 public override object ConvertTo (ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
156                 {
157                         if (destinationType == typeof (string))
158                             return String.Empty;
159                         return base.ConvertTo (context, culture, value, destinationType);
160                 }
161
162                 public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
163                 {
164                         if (destinationType == typeof (string))
165                                 return true;
166                         return base.CanConvertTo (context, destinationType);
167                 }
168         }
169 #endif
170 }