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;
45 static volatile CategoryAttribute async;
47 static object lockobj = new object ();
49 public CategoryAttribute ()
51 this.category = "Misc";
54 public CategoryAttribute (string category)
56 this.category = category;
60 public static CategoryAttribute Action {
67 action = new CategoryAttribute ("Action");
73 public static CategoryAttribute Appearance {
75 if (appearance != null)
79 if (appearance == null)
80 appearance = new CategoryAttribute ("Appearance");
86 public static CategoryAttribute Asynchronous {
88 if (behaviour != null)
93 async = new CategoryAttribute ("Asynchronous");
99 public static CategoryAttribute Behavior {
101 if (behaviour != null)
105 if (behaviour == null)
106 behaviour = new CategoryAttribute ("Behavior");
112 public static CategoryAttribute Data {
119 data = new CategoryAttribute ("Data");
125 public static CategoryAttribute Default {
133 def = new CategoryAttribute ("Default");
135 def = new CategoryAttribute ();
142 public static CategoryAttribute Design {
149 design = new CategoryAttribute ("Design");
155 public static CategoryAttribute DragDrop {
157 if (drag_drop != null)
161 if (drag_drop == null)
163 drag_drop = new CategoryAttribute ("DragDrop");
165 drag_drop = new CategoryAttribute ("Drag Drop");
172 public static CategoryAttribute Focus {
179 focus = new CategoryAttribute ("Focus");
185 public static CategoryAttribute Format {
192 format = new CategoryAttribute ("Format");
198 public static CategoryAttribute Key {
205 key = new CategoryAttribute ("Key");
211 public static CategoryAttribute Layout {
218 layout = new CategoryAttribute ("Layout");
224 public static CategoryAttribute Mouse {
231 mouse = new CategoryAttribute ("Mouse");
237 public static CategoryAttribute WindowStyle {
239 if (window_style != null)
243 if (window_style == null)
245 window_style = new CategoryAttribute ("WindowStyle");
247 window_style = new CategoryAttribute ("Window Style");
254 protected virtual string GetLocalizedString (string value)
256 return Locale.GetText (value);
259 public string Category {
261 if (IsLocalized == false) {
263 string LocalizedString = GetLocalizedString (category);
264 if (LocalizedString != null)
265 category = LocalizedString;
272 public override bool Equals (object obj)
274 if (!(obj is CategoryAttribute))
278 return ((CategoryAttribute) obj).Category == category;
281 public override int GetHashCode ()
283 return category.GetHashCode ();
286 public override bool IsDefaultAttribute ()
288 return category == CategoryAttribute.Default.Category;