Merge pull request #440 from mono-soc-2012/garyb/resources
[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         [TypeConverter (typeof (FlatButtonAppearanceConverter))]
38         public class FlatButtonAppearance
39         {
40                 private Color borderColor = Color.Empty;
41                 private int borderSize = 1;
42                 private Color checkedBackColor = Color.Empty;
43                 private Color mouseDownBackColor = Color.Empty;
44                 private Color mouseOverBackColor = Color.Empty;
45                 private ButtonBase owner = null;
46
47                 internal FlatButtonAppearance (ButtonBase owner)
48                 {
49                         this.owner = owner;
50                 }
51
52                 [EditorBrowsable(EditorBrowsableState.Always)]
53                 [DefaultValue(typeof(Color), "")]
54                 [NotifyParentProperty(true)]
55                 [Browsable(true)]
56                 public Color BorderColor
57                 {
58                         get { return borderColor; }
59                         set {
60                                 if(borderColor == value)
61                                         return;
62
63                                 if (value == Color.Transparent)
64                                         throw new NotSupportedException ("Cannot have a Transparent border.");
65                                         
66                                 borderColor = value;
67                                 
68                                 if(owner != null)
69                                         owner.Invalidate ();
70                         }
71                 }
72
73                 [EditorBrowsable(EditorBrowsableState.Always)]
74                 [DefaultValue(1)]
75                 [NotifyParentProperty(true)]
76                 [Browsable(true)]
77                 public int BorderSize
78                 {
79                         get { return borderSize; }
80                         set {
81                                 if(borderSize == value)
82                                         return;
83
84                                 if (value < 0)
85                                         throw new ArgumentOutOfRangeException ("value", string.Format ("'{0}' is not a valid value for 'BorderSize'. 'BorderSize' must be greater or equal than {1}.", value, 0));
86
87                                 borderSize = value;
88
89                                 if(owner != null)
90                                         owner.Invalidate ();
91                         }
92                 }
93
94                 [EditorBrowsable(EditorBrowsableState.Always)]
95                 [DefaultValue(typeof(Color), "")]
96                 [NotifyParentProperty(true)]
97                 [Browsable(true)]
98                 public Color CheckedBackColor 
99                 {
100                         get { return checkedBackColor; }
101                         set {
102                                 if(checkedBackColor == value)
103                                         return;
104
105                                 checkedBackColor = value;
106
107                                 if(owner != null)
108                                         owner.Invalidate ();
109                         }
110                 }
111
112                 [EditorBrowsable(EditorBrowsableState.Always)]
113                 [DefaultValue(typeof(Color), "")]
114                 [Browsable(true)]
115                 [NotifyParentProperty(true)]
116                 public Color MouseDownBackColor
117                 {
118                         get { return mouseDownBackColor; }
119                         set {
120                                 if(mouseDownBackColor == value)
121                                         return;
122
123                                 mouseDownBackColor = value;
124
125                                 if(owner != null)
126                                         owner.Invalidate ();
127                         }
128                 }
129
130                 [EditorBrowsable(EditorBrowsableState.Always)]
131                 [DefaultValue(typeof(Color), "")]
132                 [NotifyParentProperty(true)]
133                 [Browsable(true)]
134                 public Color MouseOverBackColor
135                 {
136                         get { return mouseOverBackColor; }
137                         set {
138                                 if(mouseOverBackColor == value)
139                                         return;
140
141                                 mouseOverBackColor = value;
142
143                                 if(owner != null)
144                                         owner.Invalidate ();
145                         }
146                 }
147         }
148         
149         internal class FlatButtonAppearanceConverter : ExpandableObjectConverter
150         {
151                 public override object ConvertTo (ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
152                 {
153                         if (destinationType == typeof (string))
154                             return String.Empty;
155                         return base.ConvertTo (context, culture, value, destinationType);
156                 }
157
158                 public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
159                 {
160                         if (destinationType == typeof (string))
161                                 return true;
162                         return base.CanConvertTo (context, destinationType);
163                 }
164         }
165 }