2 // System.ComponentModel.CategoryAttribute.cs
5 // Miguel de Icaza (miguel@ximian.com)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Ximian, Inc. http://www.ximian.com
9 // (C) 2003 Andreas Nahr
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:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
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.
34 namespace System.ComponentModel {
36 [AttributeUsage (AttributeTargets.All)]
37 public class CategoryAttribute : Attribute
39 private string category;
40 private bool IsLocalized;
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;
46 static object lockobj = new object ();
48 public CategoryAttribute ()
50 this.category = "Misc";
53 public CategoryAttribute (string category)
55 this.category = category;
59 public static CategoryAttribute Action {
66 action = new CategoryAttribute ("Action");
72 public static CategoryAttribute Appearance {
74 if (appearance != null)
78 if (appearance == null)
79 appearance = new CategoryAttribute ("Appearance");
85 public static CategoryAttribute Behavior {
87 if (behaviour != null)
91 if (behaviour == null)
92 behaviour = new CategoryAttribute ("Behavior");
98 public static CategoryAttribute Data {
105 data = new CategoryAttribute ("Data");
111 public static CategoryAttribute Default {
118 def = new CategoryAttribute ();
124 public static CategoryAttribute Design {
131 design = new CategoryAttribute ("Design");
137 public static CategoryAttribute DragDrop {
139 if (drag_drop != null)
143 if (drag_drop == null)
144 drag_drop = new CategoryAttribute ("Drag Drop");
150 public static CategoryAttribute Focus {
157 focus = new CategoryAttribute ("Focus");
163 public static CategoryAttribute Format {
170 format = new CategoryAttribute ("Format");
176 public static CategoryAttribute Key {
183 key = new CategoryAttribute ("Key");
189 public static CategoryAttribute Layout {
196 layout = new CategoryAttribute ("Layout");
202 public static CategoryAttribute Mouse {
209 mouse = new CategoryAttribute ("Mouse");
215 public static CategoryAttribute WindowStyle {
217 if (window_style != null)
221 if (window_style == null)
222 window_style = new CategoryAttribute ("Window Style");
228 protected virtual string GetLocalizedString (string value)
230 return Locale.GetText (value);
233 public string Category {
235 if (IsLocalized == false) {
237 string LocalizedString = GetLocalizedString (category);
238 if (LocalizedString != null)
239 category = LocalizedString;
246 public override bool Equals (object obj)
248 if (!(obj is CategoryAttribute))
252 return ((CategoryAttribute) obj).Category == category;
255 public override int GetHashCode ()
257 return category.GetHashCode ();
260 public override bool IsDefaultAttribute ()
262 return category == CategoryAttribute.Default.Category;