CategoryAttribute.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. //
  2. // System.ComponentModel.CategoryAttribute.cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) Ximian, Inc. http://www.ximian.com
  9. // (C) 2003 Andreas Nahr
  10. //
  11. //
  12. namespace System.ComponentModel {
  13. [AttributeUsage (AttributeTargets.Property | AttributeTargets.Event)]
  14. public class CategoryAttribute : Attribute
  15. {
  16. private string category;
  17. private bool IsLocalized = false;
  18. static CategoryAttribute action, appearance, behaviour, data, def;
  19. static CategoryAttribute design, drag_drop, focus, format, key;
  20. static CategoryAttribute layout, mouse, window_style;
  21. public CategoryAttribute ()
  22. {
  23. this.category = "Misc";
  24. }
  25. public CategoryAttribute (string category)
  26. {
  27. this.category = category;
  28. }
  29. public static CategoryAttribute Action {
  30. get {
  31. if (action != null)
  32. return action;
  33. lock (typeof (CategoryAttribute)) {
  34. if (action == null)
  35. action = new CategoryAttribute ("Action");
  36. }
  37. return action;
  38. }
  39. }
  40. public static CategoryAttribute Appearance {
  41. get {
  42. if (appearance != null)
  43. return appearance;
  44. lock (typeof (CategoryAttribute)) {
  45. if (appearance == null)
  46. appearance = new CategoryAttribute ("Appearance");
  47. }
  48. return appearance;
  49. }
  50. }
  51. public static CategoryAttribute Behavior {
  52. get {
  53. if (behaviour != null)
  54. return behaviour;
  55. lock (typeof (CategoryAttribute)) {
  56. if (behaviour == null)
  57. behaviour = new CategoryAttribute ("Behavior");
  58. }
  59. return behaviour;
  60. }
  61. }
  62. public static CategoryAttribute Data {
  63. get {
  64. if (data != null)
  65. return data;
  66. lock (typeof (CategoryAttribute)) {
  67. if (data == null)
  68. data = new CategoryAttribute ("Data");
  69. }
  70. return data;
  71. }
  72. }
  73. public static CategoryAttribute Default {
  74. get {
  75. if (def != null)
  76. return def;
  77. lock (typeof (CategoryAttribute)) {
  78. if (def == null)
  79. def = new CategoryAttribute ();
  80. }
  81. return def;
  82. }
  83. }
  84. public static CategoryAttribute Design {
  85. get {
  86. if (design != null)
  87. return design;
  88. lock (typeof (CategoryAttribute)) {
  89. if (design == null)
  90. design = new CategoryAttribute ("Design");
  91. }
  92. return design;
  93. }
  94. }
  95. public static CategoryAttribute DragDrop {
  96. get {
  97. if (drag_drop != null)
  98. return drag_drop;
  99. lock (typeof (CategoryAttribute)) {
  100. if (drag_drop == null)
  101. drag_drop = new CategoryAttribute ("Drag Drop");
  102. }
  103. return drag_drop;
  104. }
  105. }
  106. public static CategoryAttribute Focus {
  107. get {
  108. if (focus != null)
  109. return focus;
  110. lock (typeof (CategoryAttribute)) {
  111. if (focus == null)
  112. focus = new CategoryAttribute ("Focus");
  113. }
  114. return focus;
  115. }
  116. }
  117. public static CategoryAttribute Format {
  118. get {
  119. if (format != null)
  120. return format;
  121. lock (typeof (CategoryAttribute)) {
  122. if (format == null)
  123. format = new CategoryAttribute ("Format");
  124. }
  125. return format;
  126. }
  127. }
  128. public static CategoryAttribute Key {
  129. get {
  130. if (key != null)
  131. return key;
  132. lock (typeof (CategoryAttribute)) {
  133. if (key == null)
  134. key = new CategoryAttribute ("Key");
  135. }
  136. return key;
  137. }
  138. }
  139. public static CategoryAttribute Layout {
  140. get {
  141. if (layout != null)
  142. return layout;
  143. lock (typeof (CategoryAttribute)) {
  144. if (layout == null)
  145. layout = new CategoryAttribute ("Layout");
  146. }
  147. return layout;
  148. }
  149. }
  150. public static CategoryAttribute Mouse {
  151. get {
  152. if (mouse != null)
  153. return mouse;
  154. lock (typeof (CategoryAttribute)) {
  155. if (mouse == null)
  156. mouse = new CategoryAttribute ("Mouse");
  157. }
  158. return mouse;
  159. }
  160. }
  161. public static CategoryAttribute WindowStyle {
  162. get {
  163. if (window_style != null)
  164. return window_style;
  165. lock (typeof (CategoryAttribute)) {
  166. if (window_style == null)
  167. window_style = new CategoryAttribute ("Window Style");
  168. }
  169. return window_style;
  170. }
  171. }
  172. protected virtual string GetLocalizedString (string value)
  173. {
  174. return Locale.GetText (value);
  175. }
  176. public string Category {
  177. get {
  178. if (IsLocalized == false) {
  179. IsLocalized = true;
  180. string LocalizedString = GetLocalizedString (category);
  181. if (LocalizedString != null)
  182. category = LocalizedString;
  183. }
  184. return category;
  185. }
  186. }
  187. public override bool Equals (object obj)
  188. {
  189. if (!(obj is CategoryAttribute))
  190. return false;
  191. if (obj == this)
  192. return true;
  193. return ((CategoryAttribute) obj).Category == category;
  194. }
  195. public override int GetHashCode ()
  196. {
  197. return category.GetHashCode ();
  198. }
  199. public override bool IsDefaultAttribute ()
  200. {
  201. return category == CategoryAttribute.Default.Category;
  202. }
  203. }
  204. }