**** Merged from MCS ****
[mono-project.git] / mcs / class / System / System.ComponentModel / CategoryAttribute.cs
blobd15b1abbaae6d956bd58f52348e21e59bc31f34c
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
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.
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 {
59 get {
60 if (action != null)
61 return action;
63 lock (typeof (CategoryAttribute)) {
64 if (action == null)
65 action = new CategoryAttribute ("Action");
67 return action;
71 public static CategoryAttribute Appearance {
72 get {
73 if (appearance != null)
74 return appearance;
76 lock (typeof (CategoryAttribute)) {
77 if (appearance == null)
78 appearance = new CategoryAttribute ("Appearance");
80 return appearance;
84 public static CategoryAttribute Behavior {
85 get {
86 if (behaviour != null)
87 return behaviour;
89 lock (typeof (CategoryAttribute)) {
90 if (behaviour == null)
91 behaviour = new CategoryAttribute ("Behavior");
93 return behaviour;
97 public static CategoryAttribute Data {
98 get {
99 if (data != null)
100 return data;
102 lock (typeof (CategoryAttribute)) {
103 if (data == null)
104 data = new CategoryAttribute ("Data");
106 return data;
110 public static CategoryAttribute Default {
111 get {
112 if (def != null)
113 return def;
115 lock (typeof (CategoryAttribute)) {
116 if (def == null)
117 def = new CategoryAttribute ();
119 return def;
123 public static CategoryAttribute Design {
124 get {
125 if (design != null)
126 return design;
128 lock (typeof (CategoryAttribute)) {
129 if (design == null)
130 design = new CategoryAttribute ("Design");
132 return design;
136 public static CategoryAttribute DragDrop {
137 get {
138 if (drag_drop != null)
139 return drag_drop;
141 lock (typeof (CategoryAttribute)) {
142 if (drag_drop == null)
143 drag_drop = new CategoryAttribute ("Drag Drop");
145 return drag_drop;
149 public static CategoryAttribute Focus {
150 get {
151 if (focus != null)
152 return focus;
154 lock (typeof (CategoryAttribute)) {
155 if (focus == null)
156 focus = new CategoryAttribute ("Focus");
158 return focus;
162 public static CategoryAttribute Format {
163 get {
164 if (format != null)
165 return format;
167 lock (typeof (CategoryAttribute)) {
168 if (format == null)
169 format = new CategoryAttribute ("Format");
171 return format;
175 public static CategoryAttribute Key {
176 get {
177 if (key != null)
178 return key;
180 lock (typeof (CategoryAttribute)) {
181 if (key == null)
182 key = new CategoryAttribute ("Key");
184 return key;
188 public static CategoryAttribute Layout {
189 get {
190 if (layout != null)
191 return layout;
193 lock (typeof (CategoryAttribute)) {
194 if (layout == null)
195 layout = new CategoryAttribute ("Layout");
197 return layout;
201 public static CategoryAttribute Mouse {
202 get {
203 if (mouse != null)
204 return mouse;
206 lock (typeof (CategoryAttribute)) {
207 if (mouse == null)
208 mouse = new CategoryAttribute ("Mouse");
210 return mouse;
214 public static CategoryAttribute WindowStyle {
215 get {
216 if (window_style != null)
217 return window_style;
219 lock (typeof (CategoryAttribute)) {
220 if (window_style == null)
221 window_style = new CategoryAttribute ("Window Style");
223 return window_style;
227 protected virtual string GetLocalizedString (string value)
229 return Locale.GetText (value);
232 public string Category {
233 get {
234 if (IsLocalized == false) {
235 IsLocalized = true;
236 string LocalizedString = GetLocalizedString (category);
237 if (LocalizedString != null)
238 category = LocalizedString;
241 return category;
245 public override bool Equals (object obj)
247 if (!(obj is CategoryAttribute))
248 return false;
249 if (obj == this)
250 return true;
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;