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 = false;
42 static CategoryAttribute action, appearance, behaviour, data, def;
43 static CategoryAttribute design, drag_drop, focus, format, key;
44 static CategoryAttribute layout, mouse, window_style;
47 public CategoryAttribute ()
49 this.category = "Misc";
52 public CategoryAttribute (string category)
54 this.category = category;
58 public static CategoryAttribute Action {
63 lock (typeof (CategoryAttribute)) {
65 action = new CategoryAttribute ("Action");
71 public static CategoryAttribute Appearance {
73 if (appearance != null)
76 lock (typeof (CategoryAttribute)) {
77 if (appearance == null)
78 appearance = new CategoryAttribute ("Appearance");
84 public static CategoryAttribute Behavior {
86 if (behaviour != null)
89 lock (typeof (CategoryAttribute)) {
90 if (behaviour == null)
91 behaviour = new CategoryAttribute ("Behavior");
97 public static CategoryAttribute Data {
102 lock (typeof (CategoryAttribute)) {
104 data = new CategoryAttribute ("Data");
110 public static CategoryAttribute Default {
115 lock (typeof (CategoryAttribute)) {
117 def = new CategoryAttribute ();
123 public static CategoryAttribute Design {
128 lock (typeof (CategoryAttribute)) {
130 design = new CategoryAttribute ("Design");
136 public static CategoryAttribute DragDrop {
138 if (drag_drop != null)
141 lock (typeof (CategoryAttribute)) {
142 if (drag_drop == null)
143 drag_drop = new CategoryAttribute ("Drag Drop");
149 public static CategoryAttribute Focus {
154 lock (typeof (CategoryAttribute)) {
156 focus = new CategoryAttribute ("Focus");
162 public static CategoryAttribute Format {
167 lock (typeof (CategoryAttribute)) {
169 format = new CategoryAttribute ("Format");
175 public static CategoryAttribute Key {
180 lock (typeof (CategoryAttribute)) {
182 key = new CategoryAttribute ("Key");
188 public static CategoryAttribute Layout {
193 lock (typeof (CategoryAttribute)) {
195 layout = new CategoryAttribute ("Layout");
201 public static CategoryAttribute Mouse {
206 lock (typeof (CategoryAttribute)) {
208 mouse = new CategoryAttribute ("Mouse");
214 public static CategoryAttribute WindowStyle {
216 if (window_style != null)
219 lock (typeof (CategoryAttribute)) {
220 if (window_style == null)
221 window_style = new CategoryAttribute ("Window Style");
227 protected virtual string GetLocalizedString (string value)
229 return Locale.GetText (value);
232 public string Category {
234 if (IsLocalized == false) {
236 string LocalizedString = GetLocalizedString (category);
237 if (LocalizedString != null)
238 category = LocalizedString;
245 public override bool Equals (object obj)
247 if (!(obj is CategoryAttribute))
251 return ((CategoryAttribute) obj).Category == category;
254 public override int GetHashCode ()
256 return category.GetHashCode ();
259 public override bool IsDefaultAttribute ()
261 return category == CategoryAttribute.Default.Category;