CategoryAttribute.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. namespace System.ComponentModel {
  33. [AttributeUsage (AttributeTargets.All)]
  34. public class CategoryAttribute : Attribute
  35. {
  36. private string category;
  37. private bool IsLocalized = false;
  38. static CategoryAttribute action, appearance, behaviour, data, def;
  39. static CategoryAttribute design, drag_drop, focus, format, key;
  40. static CategoryAttribute layout, mouse, window_style;
  41. public CategoryAttribute ()
  42. {
  43. this.category = "Misc";
  44. }
  45. public CategoryAttribute (string category)
  46. {
  47. this.category = category;
  48. }
  49. public static CategoryAttribute Action {
  50. get {
  51. if (action != null)
  52. return action;
  53. lock (typeof (CategoryAttribute)) {
  54. if (action == null)
  55. action = new CategoryAttribute ("Action");
  56. }
  57. return action;
  58. }
  59. }
  60. public static CategoryAttribute Appearance {
  61. get {
  62. if (appearance != null)
  63. return appearance;
  64. lock (typeof (CategoryAttribute)) {
  65. if (appearance == null)
  66. appearance = new CategoryAttribute ("Appearance");
  67. }
  68. return appearance;
  69. }
  70. }
  71. public static CategoryAttribute Behavior {
  72. get {
  73. if (behaviour != null)
  74. return behaviour;
  75. lock (typeof (CategoryAttribute)) {
  76. if (behaviour == null)
  77. behaviour = new CategoryAttribute ("Behavior");
  78. }
  79. return behaviour;
  80. }
  81. }
  82. public static CategoryAttribute Data {
  83. get {
  84. if (data != null)
  85. return data;
  86. lock (typeof (CategoryAttribute)) {
  87. if (data == null)
  88. data = new CategoryAttribute ("Data");
  89. }
  90. return data;
  91. }
  92. }
  93. public static CategoryAttribute Default {
  94. get {
  95. if (def != null)
  96. return def;
  97. lock (typeof (CategoryAttribute)) {
  98. if (def == null)
  99. def = new CategoryAttribute ();
  100. }
  101. return def;
  102. }
  103. }
  104. public static CategoryAttribute Design {
  105. get {
  106. if (design != null)
  107. return design;
  108. lock (typeof (CategoryAttribute)) {
  109. if (design == null)
  110. design = new CategoryAttribute ("Design");
  111. }
  112. return design;
  113. }
  114. }
  115. public static CategoryAttribute DragDrop {
  116. get {
  117. if (drag_drop != null)
  118. return drag_drop;
  119. lock (typeof (CategoryAttribute)) {
  120. if (drag_drop == null)
  121. drag_drop = new CategoryAttribute ("Drag Drop");
  122. }
  123. return drag_drop;
  124. }
  125. }
  126. public static CategoryAttribute Focus {
  127. get {
  128. if (focus != null)
  129. return focus;
  130. lock (typeof (CategoryAttribute)) {
  131. if (focus == null)
  132. focus = new CategoryAttribute ("Focus");
  133. }
  134. return focus;
  135. }
  136. }
  137. public static CategoryAttribute Format {
  138. get {
  139. if (format != null)
  140. return format;
  141. lock (typeof (CategoryAttribute)) {
  142. if (format == null)
  143. format = new CategoryAttribute ("Format");
  144. }
  145. return format;
  146. }
  147. }
  148. public static CategoryAttribute Key {
  149. get {
  150. if (key != null)
  151. return key;
  152. lock (typeof (CategoryAttribute)) {
  153. if (key == null)
  154. key = new CategoryAttribute ("Key");
  155. }
  156. return key;
  157. }
  158. }
  159. public static CategoryAttribute Layout {
  160. get {
  161. if (layout != null)
  162. return layout;
  163. lock (typeof (CategoryAttribute)) {
  164. if (layout == null)
  165. layout = new CategoryAttribute ("Layout");
  166. }
  167. return layout;
  168. }
  169. }
  170. public static CategoryAttribute Mouse {
  171. get {
  172. if (mouse != null)
  173. return mouse;
  174. lock (typeof (CategoryAttribute)) {
  175. if (mouse == null)
  176. mouse = new CategoryAttribute ("Mouse");
  177. }
  178. return mouse;
  179. }
  180. }
  181. public static CategoryAttribute WindowStyle {
  182. get {
  183. if (window_style != null)
  184. return window_style;
  185. lock (typeof (CategoryAttribute)) {
  186. if (window_style == null)
  187. window_style = new CategoryAttribute ("Window Style");
  188. }
  189. return window_style;
  190. }
  191. }
  192. protected virtual string GetLocalizedString (string value)
  193. {
  194. return Locale.GetText (value);
  195. }
  196. public string Category {
  197. get {
  198. if (IsLocalized == false) {
  199. IsLocalized = true;
  200. string LocalizedString = GetLocalizedString (category);
  201. if (LocalizedString != null)
  202. category = LocalizedString;
  203. }
  204. return category;
  205. }
  206. }
  207. public override bool Equals (object obj)
  208. {
  209. if (!(obj is CategoryAttribute))
  210. return false;
  211. if (obj == this)
  212. return true;
  213. return ((CategoryAttribute) obj).Category == category;
  214. }
  215. public override int GetHashCode ()
  216. {
  217. return category.GetHashCode ();
  218. }
  219. public override bool IsDefaultAttribute ()
  220. {
  221. return category == CategoryAttribute.Default.Category;
  222. }
  223. }
  224. }