CategoryAttribute.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. public static readonly CategoryAttribute Default = new CategoryAttribute ();
  19. public static readonly CategoryAttribute Action = new CategoryAttribute ("Action");
  20. public static readonly CategoryAttribute Appearance = new CategoryAttribute ("Appearance");
  21. public static readonly CategoryAttribute Behavior = new CategoryAttribute ("Behavior");
  22. public static readonly CategoryAttribute Data = new CategoryAttribute ("Data");
  23. public static readonly CategoryAttribute Design = new CategoryAttribute ("Design");
  24. public static readonly CategoryAttribute DragDrop = new CategoryAttribute ("Drag Drop");
  25. public static readonly CategoryAttribute Focus = new CategoryAttribute ("Focus");
  26. public static readonly CategoryAttribute Format = new CategoryAttribute ("Format");
  27. public static readonly CategoryAttribute Key = new CategoryAttribute ("Key");
  28. public static readonly CategoryAttribute Layout = new CategoryAttribute ("Layout");
  29. public static readonly CategoryAttribute Mouse = new CategoryAttribute ("Mouse");
  30. public static readonly CategoryAttribute WindowStyle = new CategoryAttribute ("Window Style");
  31. public CategoryAttribute ()
  32. {
  33. this.category = "Misc";
  34. }
  35. public CategoryAttribute (string category)
  36. {
  37. this.category = category;
  38. }
  39. protected virtual string GetLocalizedString (string value)
  40. {
  41. // FIXME: Check if other implementation exists
  42. return null;
  43. }
  44. public string Category {
  45. get {
  46. if (IsLocalized == false) {
  47. IsLocalized = true;
  48. string LocalizedString = GetLocalizedString (category);
  49. if (LocalizedString != null)
  50. category = LocalizedString;
  51. }
  52. return category;
  53. }
  54. }
  55. public override bool Equals (object obj)
  56. {
  57. if (!(obj is CategoryAttribute))
  58. return false;
  59. if (obj == this)
  60. return true;
  61. return ((CategoryAttribute) obj).Category == category;
  62. }
  63. public override int GetHashCode ()
  64. {
  65. return category.GetHashCode ();
  66. }
  67. public override bool IsDefaultAttribute ()
  68. {
  69. return category == CategoryAttribute.Default.Category;
  70. }
  71. // OLD IMPLEMENTATION - redid the implementation without storing any of the static
  72. // members which require to do locks to keep in sync
  73. // static CategoryAttribute action, appearance, behaviour, data, def;
  74. // static CategoryAttribute design, drag_drop, focus, format, key;
  75. // static CategoryAttribute layout, mouse, window_style;
  76. //
  77. // public CategoryAttribute (string category)
  78. // {
  79. // this.category = category;
  80. // }
  81. //
  82. // public CategoryAttribute ()
  83. // {
  84. // this.category = "Misc";
  85. // }
  86. //
  87. // [MonoTODO]
  88. // protected virtual string GetLocalizedString (string value)
  89. // {
  90. // // FIXME: IMPLEMENT
  91. //
  92. // return category;
  93. // }
  94. //
  95. // public string Category {
  96. // get {
  97. // return category;
  98. // }
  99. // }
  100. //
  101. // public static CategoryAttribute Action {
  102. // get {
  103. // if (action != null)
  104. // return action;
  105. //
  106. // lock (typeof (CategoryAttribute)){
  107. // if (action == null)
  108. // action = new CategoryAttribute ("Action");
  109. // }
  110. //
  111. // return action;
  112. // }
  113. // }
  114. //
  115. // public static CategoryAttribute Appearance {
  116. // get {
  117. // if (appearance != null)
  118. // return appearance;
  119. //
  120. // lock (typeof (CategoryAttribute)){
  121. // if (appearance == null)
  122. // appearance = new CategoryAttribute ("Appearance");
  123. // }
  124. //
  125. // return appearance;
  126. // }
  127. // }
  128. //
  129. // public static CategoryAttribute Behaviour {
  130. // get {
  131. // if (behaviour != null)
  132. // return behaviour;
  133. //
  134. // lock (typeof (CategoryAttribute)){
  135. // if (behaviour == null)
  136. // behaviour = new CategoryAttribute ("Action");
  137. // }
  138. //
  139. // return behaviour;
  140. // }
  141. // }
  142. //
  143. // public static CategoryAttribute Data {
  144. // get {
  145. // if (data != null)
  146. // return data;
  147. //
  148. // lock (typeof (CategoryAttribute)){
  149. // if (data == null)
  150. // data = new CategoryAttribute ("Data");
  151. // }
  152. //
  153. // return data;
  154. // }
  155. // }
  156. //
  157. // public static CategoryAttribute Default {
  158. // get {
  159. // if (def != null)
  160. // return def;
  161. //
  162. // lock (typeof (CategoryAttribute)){
  163. // if (def == null)
  164. // def = new CategoryAttribute ("Default");
  165. // }
  166. //
  167. // return def;
  168. // }
  169. // }
  170. //
  171. // public static CategoryAttribute Design {
  172. // get {
  173. // if (design != null)
  174. // return design;
  175. //
  176. // lock (typeof (CategoryAttribute)){
  177. // if (design == null)
  178. // design = new CategoryAttribute ("Design");
  179. // }
  180. //
  181. // return design;
  182. // }
  183. // }
  184. //
  185. // public static CategoryAttribute DragDrop {
  186. // get {
  187. // if (drag_drop != null)
  188. // return drag_drop;
  189. //
  190. // lock (typeof (CategoryAttribute)){
  191. // if (drag_drop == null)
  192. // drag_drop = new CategoryAttribute ("Drag Drop");
  193. // }
  194. //
  195. // return drag_drop;
  196. // }
  197. // }
  198. //
  199. // public static CategoryAttribute Focus {
  200. // get {
  201. // if (focus != null)
  202. // return focus;
  203. //
  204. // lock (typeof (CategoryAttribute)){
  205. // if (focus == null)
  206. // focus = new CategoryAttribute ("Focus");
  207. // }
  208. //
  209. // return focus;
  210. // }
  211. // }
  212. //
  213. // public static CategoryAttribute Format {
  214. // get {
  215. // if (format != null)
  216. // return format;
  217. //
  218. // lock (typeof (CategoryAttribute)){
  219. // if (format == null)
  220. // format = new CategoryAttribute ("Format");
  221. // }
  222. //
  223. // return format;
  224. // }
  225. // }
  226. //
  227. // public static CategoryAttribute Key {
  228. // get {
  229. // if (key != null)
  230. // return key;
  231. //
  232. // lock (typeof (CategoryAttribute)){
  233. // if (key == null)
  234. // key = new CategoryAttribute ("Key");
  235. // }
  236. //
  237. // return key;
  238. // }
  239. // }
  240. //
  241. // public static CategoryAttribute Layout {
  242. // get {
  243. // if (layout != null)
  244. // return layout;
  245. //
  246. // lock (typeof (CategoryAttribute)){
  247. // if (layout == null)
  248. // layout = new CategoryAttribute ("Layout");
  249. // }
  250. //
  251. // return layout;
  252. // }
  253. // }
  254. //
  255. // public static CategoryAttribute Mouse {
  256. // get {
  257. // if (mouse != null)
  258. // return mouse;
  259. //
  260. // lock (typeof (CategoryAttribute)){
  261. // if (mouse == null)
  262. // mouse = new CategoryAttribute ("Mouse");
  263. // }
  264. //
  265. // return mouse;
  266. // }
  267. // }
  268. //
  269. // public static CategoryAttribute WindowStyle {
  270. // get {
  271. // if (window_style != null)
  272. // return window_style;
  273. //
  274. // lock (typeof (CategoryAttribute)){
  275. // if (window_style == null)
  276. // window_style = new CategoryAttribute ("Window Style");
  277. // }
  278. //
  279. // return window_style;
  280. // }
  281. // }
  282. }
  283. }