1 //------------------------------------------------------------------------------
2 // <copyright file="CategoryAttribute.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
9 namespace System.ComponentModel {
11 using System.ComponentModel;
12 using System.Diagnostics;
13 using System.Security.Permissions;
16 /// <para>Specifies the category in which the property or event will be displayed in a
17 /// visual designer.</para>
19 [AttributeUsage(AttributeTargets.All)]
20 public class CategoryAttribute : Attribute {
21 private static volatile CategoryAttribute appearance;
22 private static volatile CategoryAttribute asynchronous;
23 private static volatile CategoryAttribute behavior;
24 private static volatile CategoryAttribute data;
25 private static volatile CategoryAttribute design;
26 private static volatile CategoryAttribute action;
27 private static volatile CategoryAttribute format;
28 private static volatile CategoryAttribute layout;
29 private static volatile CategoryAttribute mouse;
30 private static volatile CategoryAttribute key;
31 private static volatile CategoryAttribute focus;
32 private static volatile CategoryAttribute windowStyle;
33 private static volatile CategoryAttribute dragDrop;
34 private static volatile CategoryAttribute defAttr;
36 private bool localized;
40 /// Provides the actual category name.
43 private string categoryValue;
46 /// <para>Gets the action category attribute.</para>
48 public static CategoryAttribute Action {
51 action = new CategoryAttribute("Action");
58 /// <para>Gets the appearance category attribute.</para>
60 public static CategoryAttribute Appearance {
62 if (appearance == null) {
63 appearance = new CategoryAttribute("Appearance");
70 /// <para>Gets the asynchronous category attribute.</para>
72 public static CategoryAttribute Asynchronous {
74 if (asynchronous == null) {
75 asynchronous = new CategoryAttribute("Asynchronous");
82 /// <para>Gets the behavior category attribute.</para>
84 public static CategoryAttribute Behavior {
86 if (behavior == null) {
87 behavior = new CategoryAttribute("Behavior");
94 /// <para>Gets the data category attribute.</para>
96 public static CategoryAttribute Data {
99 data = new CategoryAttribute("Data");
106 /// <para>Gets the default category attribute.</para>
108 public static CategoryAttribute Default {
110 if (defAttr == null) {
111 defAttr = new CategoryAttribute();
118 /// <para>Gets the design category attribute.</para>
120 public static CategoryAttribute Design {
122 if (design == null) {
123 design = new CategoryAttribute("Design");
130 /// <para>Gets the drag and drop category attribute.</para>
132 public static CategoryAttribute DragDrop {
134 if (dragDrop == null) {
135 dragDrop = new CategoryAttribute("DragDrop");
142 /// <para>Gets the focus category attribute.</para>
144 public static CategoryAttribute Focus {
147 focus = new CategoryAttribute("Focus");
154 /// <para>Gets the format category attribute.</para>
156 public static CategoryAttribute Format {
158 if (format == null) {
159 format = new CategoryAttribute("Format");
166 /// <para>Gets the keyboard category attribute.</para>
168 public static CategoryAttribute Key {
171 key = new CategoryAttribute("Key");
178 /// <para>Gets the layout category attribute.</para>
180 public static CategoryAttribute Layout {
182 if (layout == null) {
183 layout = new CategoryAttribute("Layout");
190 /// <para>Gets the mouse category attribute.</para>
192 public static CategoryAttribute Mouse {
195 mouse = new CategoryAttribute("Mouse");
202 /// <para> Gets the window style category
203 /// attribute.</para>
205 public static CategoryAttribute WindowStyle {
207 if (windowStyle == null) {
208 windowStyle = new CategoryAttribute("WindowStyle");
215 /// <para>Initializes a new instance of the <see cref='System.ComponentModel.CategoryAttribute'/>
216 /// class with the default category.</para>
218 public CategoryAttribute() : this("Default") {
222 /// <para>Initializes a new instance of the <see cref='System.ComponentModel.CategoryAttribute'/> class with
223 /// the specified category name.</para>
225 public CategoryAttribute(string category) {
226 this.categoryValue = category;
227 this.localized = false;
231 /// <para>Gets the name of the category for the property or event
232 /// that this attribute is bound to.</para>
234 public string Category {
238 string localizedValue = GetLocalizedString(categoryValue);
239 if (localizedValue != null) {
240 categoryValue = localizedValue;
243 return categoryValue;
253 public override bool Equals(object obj){
258 if (obj is CategoryAttribute){
259 return Category.Equals(((CategoryAttribute)obj).Category);
265 /// <para>[To be supplied.]</para>
267 public override int GetHashCode() {
268 return Category.GetHashCode();
272 /// <para>Looks up the localized name of a given category.</para>
274 protected virtual string GetLocalizedString(string value) {
276 return (string)SR.GetObject("PropertyCategory" + value);
279 string localizedString = SR.GetString("PropertyCategory" + value, out usedFallback);
283 return localizedString;
294 public override bool IsDefaultAttribute() {
295 return Category.Equals(Default.Category);