Fixed space indents to tabs to adhere to Mono coding guidelines.
[mono.git] / mcs / class / System / System.ComponentModel / CategoryAttribute.cs
1 //
2 // System.ComponentModel.CategoryAttribute.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) Ximian, Inc.  http://www.ximian.com
9 // (C) 2003 Andreas Nahr
10 //
11 //
12
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 namespace System.ComponentModel {
35
36         [AttributeUsage (AttributeTargets.All)]
37         public class CategoryAttribute : Attribute
38         {
39                 private string category;
40                 private bool IsLocalized;
41
42                 static volatile CategoryAttribute action, appearance, behaviour, data,   def;
43                 static volatile CategoryAttribute design, drag_drop,  focus,     format, key;
44                 static volatile CategoryAttribute layout, mouse,      window_style;
45                 static volatile CategoryAttribute async;
46
47                 static object lockobj = new object ();
48
49                 public CategoryAttribute ()
50                 {
51                         this.category = "Misc";
52                 }
53
54                 public CategoryAttribute (string category)
55                 {
56                         this.category = category;
57                 }
58
59
60                 public static CategoryAttribute Action {
61                         get {
62                                 if (action != null)
63                                         return action;
64
65                                 lock (lockobj) {
66                                         if (action == null)
67                                                 action = new CategoryAttribute ("Action");
68                                 }
69                                 return action;
70                         }
71                 }
72
73                 public static CategoryAttribute Appearance {
74                         get {
75                                 if (appearance != null)
76                                         return appearance;
77
78                                 lock (lockobj) {
79                                         if (appearance == null)
80                                                 appearance = new CategoryAttribute ("Appearance");
81                                 }
82                                 return appearance;
83                         }
84                 }
85
86                 public static CategoryAttribute Asynchronous {
87                         get {
88                                 if (behaviour != null)
89                                         return behaviour;
90
91                                 lock (lockobj) {
92                                         if (async == null)
93                                                 async = new CategoryAttribute ("Asynchronous");
94                                 }
95                                 return async;
96                         }
97                 }
98
99                 public static CategoryAttribute Behavior {
100                         get {
101                                 if (behaviour != null)
102                                         return behaviour;
103
104                                 lock (lockobj) {
105                                         if (behaviour == null)
106                                                 behaviour = new CategoryAttribute ("Behavior");
107                                 }
108                                 return behaviour;
109                         }
110                 }
111
112                 public static CategoryAttribute Data {
113                         get {
114                                 if (data != null)
115                                         return data;
116
117                                 lock (lockobj) {
118                                         if (data == null)
119                                                 data = new CategoryAttribute ("Data");
120                                 }
121                                 return data;
122                         }
123                 }
124
125                 public static CategoryAttribute Default {
126                         get {
127                                 if (def != null)
128                                         return def;
129
130                                 lock (lockobj) {
131                                         if (def == null)
132 #if NET_2_1
133                                                 def = new CategoryAttribute ("Default");
134 #else
135                                                 def = new CategoryAttribute ();
136 #endif
137                                 }
138                                 return def;
139                         }
140                 }
141
142                 public static CategoryAttribute Design {
143                         get {
144                                 if (design != null)
145                                         return design;
146
147                                 lock (lockobj) {
148                                         if (design == null)
149                                                 design = new CategoryAttribute ("Design");
150                                 }
151                                 return design;
152                         }
153                 }
154
155                 public static CategoryAttribute DragDrop {
156                         get {
157                                 if (drag_drop != null)
158                                         return drag_drop;
159
160                                 lock (lockobj) {
161                                         if (drag_drop == null)
162 #if NET_2_1
163                                                 drag_drop = new CategoryAttribute ("DragDrop");
164 #else
165                                                 drag_drop = new CategoryAttribute ("Drag Drop");
166 #endif
167                                 }
168                                 return drag_drop;
169                         }
170                 }
171
172                 public static CategoryAttribute Focus {
173                         get {
174                                 if (focus != null)
175                                         return focus;
176
177                                 lock (lockobj) {
178                                         if (focus == null)
179                                                 focus = new CategoryAttribute ("Focus");
180                                 }
181                                 return focus;
182                         }
183                 }
184
185                 public static CategoryAttribute Format {
186                         get {
187                                 if (format != null)
188                                         return format;
189
190                                 lock (lockobj) {
191                                         if (format == null)
192                                                 format = new CategoryAttribute ("Format");
193                                 }
194                                 return format;
195                         }
196                 }
197
198                 public static CategoryAttribute Key {
199                         get {
200                                 if (key != null)
201                                         return key;
202
203                                 lock (lockobj) {
204                                         if (key == null)
205                                                 key = new CategoryAttribute ("Key");
206                                 }
207                                 return key;
208                         }
209                 }
210
211                 public static CategoryAttribute Layout {
212                         get {
213                                 if (layout != null)
214                                         return layout;
215
216                                 lock (lockobj) {
217                                         if (layout == null)
218                                                 layout = new CategoryAttribute ("Layout");
219                                 }
220                                 return layout;
221                         }
222                 }
223
224                 public static CategoryAttribute Mouse {
225                         get {
226                                 if (mouse != null)
227                                         return mouse;
228
229                                 lock (lockobj) {
230                                         if (mouse == null)
231                                                 mouse = new CategoryAttribute ("Mouse");
232                                 }
233                                 return mouse;
234                         }
235                 }
236
237                 public static CategoryAttribute WindowStyle {
238                         get {
239                                 if (window_style != null)
240                                         return window_style;
241
242                                 lock (lockobj) {
243                                         if (window_style == null)
244 #if NET_2_1
245                                                 window_style = new CategoryAttribute ("WindowStyle");
246 #else
247                                                 window_style = new CategoryAttribute ("Window Style");
248 #endif
249                                 }
250                                 return window_style;
251                         }
252                 }
253
254                 protected virtual string GetLocalizedString (string value)
255                 {
256                         return Locale.GetText (value);
257                 }
258
259                 public string Category {
260                         get {
261                                 if (IsLocalized == false) {
262                                         IsLocalized = true;
263                                         string LocalizedString = GetLocalizedString (category);
264                                         if (LocalizedString != null)
265                                                 category = LocalizedString;
266                                 }
267
268                                 return category;
269                         }
270                 }
271
272                 public override bool Equals (object obj)
273                 {
274                         if (!(obj is CategoryAttribute))
275                                 return false;
276                         if (obj == this)
277                                 return true;
278                         return ((CategoryAttribute) obj).Category == category;
279                 }
280
281                 public override int GetHashCode ()
282                 {
283                         return category.GetHashCode ();
284                 }
285
286                 public override bool IsDefaultAttribute ()
287                 {
288                         return category == CategoryAttribute.Default.Category;
289                 }
290         }
291 }
292