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 volatile CategoryAttribute async;
49 static object lockobj = new object ();
51 public CategoryAttribute ()
53 this.category = "Misc";
56 public CategoryAttribute (string category)
58 this.category = category;
62 public static CategoryAttribute Action {
69 action = new CategoryAttribute ("Action");
75 public static CategoryAttribute Appearance {
77 if (appearance != null)
81 if (appearance == null)
82 appearance = new CategoryAttribute ("Appearance");
89 public static CategoryAttribute Asynchronous {
91 if (behaviour != null)
96 async = new CategoryAttribute ("Asynchrinous");
103 public static CategoryAttribute Behavior {
105 if (behaviour != null)
109 if (behaviour == null)
110 behaviour = new CategoryAttribute ("Behavior");
116 public static CategoryAttribute Data {
123 data = new CategoryAttribute ("Data");
129 public static CategoryAttribute Default {
136 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)
162 drag_drop = new CategoryAttribute ("Drag Drop");
168 public static CategoryAttribute Focus {
175 focus = new CategoryAttribute ("Focus");
181 public static CategoryAttribute Format {
188 format = new CategoryAttribute ("Format");
194 public static CategoryAttribute Key {
201 key = new CategoryAttribute ("Key");
207 public static CategoryAttribute Layout {
214 layout = new CategoryAttribute ("Layout");
220 public static CategoryAttribute Mouse {
227 mouse = new CategoryAttribute ("Mouse");
233 public static CategoryAttribute WindowStyle {
235 if (window_style != null)
239 if (window_style == null)
240 window_style = new CategoryAttribute ("Window Style");
246 protected virtual string GetLocalizedString (string value)
248 return Locale.GetText (value);
251 public string Category {
253 if (IsLocalized == false) {
255 string LocalizedString = GetLocalizedString (category);
256 if (LocalizedString != null)
257 category = LocalizedString;
264 public override bool Equals (object obj)
266 if (!(obj is CategoryAttribute))
270 return ((CategoryAttribute) obj).Category == category;
273 public override int GetHashCode ()
275 return category.GetHashCode ();
278 public override bool IsDefaultAttribute ()
280 return category == CategoryAttribute.Default.Category;