FRPropertyGrid.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing.Design;
  4. using System.Threading;
  5. using System.Globalization;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8. using System.Windows.Forms.PropertyGridInternal;
  9. using System.Windows.Forms.Design;
  10. using FastReport.Utils;
  11. using FastReport.TypeEditors;
  12. using FastReport.TypeConverters;
  13. using FastReport.Editor.Syntax.Parsers;
  14. namespace FastReport.Controls
  15. {
  16. internal enum PropertyGridContent
  17. {
  18. Properties,
  19. Events
  20. }
  21. #if !DEBUG
  22. [DesignTimeVisible(false)]
  23. #endif
  24. internal class FRPropertyGrid : PropertyGrid
  25. {
  26. private UIStyle style;
  27. public UIStyle Style
  28. {
  29. get { return style; }
  30. set
  31. {
  32. style = value;
  33. #if MONO
  34. ToolStripRenderer = UIStyleUtils.GetToolStripRenderer(style);
  35. #endif
  36. }
  37. }
  38. public FRPropertyGrid()
  39. {
  40. UseCompatibleTextRendering = false;
  41. PropertySort = PropertySort.Alphabetical;
  42. PropertyTabs.RemoveTabType(typeof(PropertiesTab));
  43. }
  44. }
  45. #if !DEBUG
  46. [DesignTimeVisible(false)]
  47. #endif
  48. internal class FRPropertiesGrid : FRPropertyGrid
  49. {
  50. protected override Type DefaultTabType
  51. {
  52. get { return typeof(FRPropertiesTab); }
  53. }
  54. public FRPropertiesGrid()
  55. {
  56. PropertyTabs.AddTabType(typeof(FRPropertiesTab));
  57. }
  58. }
  59. #if !DEBUG
  60. [DesignTimeVisible(false)]
  61. #endif
  62. internal class FREventsGrid : FRPropertyGrid
  63. {
  64. protected override Type DefaultTabType
  65. {
  66. get { return typeof(FREventsTab); }
  67. }
  68. public FREventsGrid()
  69. {
  70. PropertyTabs.AddTabType(typeof(FREventsTab));
  71. }
  72. }
  73. internal class FRPropertyDescriptor : PropertyDescriptor
  74. {
  75. private PropertyDescriptor descriptor;
  76. public override string Category
  77. {
  78. get
  79. {
  80. return GetCategory();
  81. }
  82. }
  83. private string GetCategory()
  84. {
  85. CultureInfo currentlangUI = Thread.CurrentThread.CurrentUICulture;
  86. Thread.CurrentThread.CurrentUICulture = Config.EngCultureInfo;
  87. string category = descriptor.Category;
  88. Thread.CurrentThread.CurrentUICulture = currentlangUI;
  89. if (Res.StringExists("Properties,Categories," + category))
  90. return Res.Get("Properties,Categories," + category);
  91. return category;
  92. }
  93. public override string DisplayName
  94. {
  95. get
  96. {
  97. return descriptor.DisplayName;
  98. }
  99. }
  100. public override string Description
  101. {
  102. get
  103. {
  104. try
  105. {
  106. return ReflectionRepository.DescriptionHelper.GetDescription(ComponentType.GetProperty(Name));
  107. }
  108. catch
  109. {
  110. }
  111. return descriptor.Description;
  112. }
  113. }
  114. public override Type ComponentType
  115. {
  116. get { return descriptor.ComponentType; }
  117. }
  118. public override bool IsReadOnly
  119. {
  120. get { return descriptor.IsReadOnly; }
  121. }
  122. public override Type PropertyType
  123. {
  124. get { return descriptor.PropertyType; }
  125. }
  126. public override bool CanResetValue(object component)
  127. {
  128. return descriptor.CanResetValue(component);
  129. }
  130. public override object GetValue(object component)
  131. {
  132. return descriptor.GetValue(component);
  133. }
  134. public override void ResetValue(object component)
  135. {
  136. descriptor.ResetValue(component);
  137. }
  138. public override void SetValue(object component, object value)
  139. {
  140. descriptor.SetValue(component, value);
  141. }
  142. public override bool ShouldSerializeValue(object component)
  143. {
  144. return descriptor.ShouldSerializeValue(component);
  145. }
  146. public FRPropertyDescriptor(PropertyDescriptor descriptor)
  147. : base(descriptor)
  148. {
  149. this.descriptor = descriptor;
  150. }
  151. }
  152. internal class FREventDescriptor : FRPropertyDescriptor
  153. {
  154. public override string DisplayName
  155. {
  156. get { return base.DisplayName.Replace("Event", ""); }
  157. }
  158. protected override Attribute[] AttributeArray
  159. {
  160. get
  161. {
  162. return new Attribute[] {
  163. new EditorAttribute(typeof(EventEditor), typeof(UITypeEditor)),
  164. new TypeConverterAttribute(typeof(EventConverter))};
  165. }
  166. set { base.AttributeArray = value; }
  167. }
  168. public FREventDescriptor(PropertyDescriptor descriptor)
  169. : base(descriptor)
  170. {
  171. }
  172. }
  173. internal class FRPropertiesTab : PropertyTab
  174. {
  175. #region Public Methods
  176. public override bool CanExtend(object extendee)
  177. {
  178. return true;
  179. }
  180. public override PropertyDescriptorCollection GetProperties(
  181. ITypeDescriptorContext context, object component, Attribute[] attributes)
  182. {
  183. return GetProperties(component, attributes);
  184. }
  185. public override PropertyDescriptorCollection GetProperties(object component, Attribute[] attributes)
  186. {
  187. PropertyDescriptorCollection props = TypeDescriptor.GetProperties(component);
  188. PropertyDescriptorCollection properties = new PropertyDescriptorCollection(null);
  189. foreach (PropertyDescriptor prop in props)
  190. {
  191. BrowsableAttribute browsable = prop.Attributes[typeof(BrowsableAttribute)] as BrowsableAttribute;
  192. // skip nonbrowsable properties
  193. if (browsable != null && browsable.Browsable == false)
  194. continue;
  195. // skip properties other than "Restriction" if DontModify flag is set
  196. if (component is Base && (component as Base).HasRestriction(Restrictions.DontModify) && prop.Name != "Restrictions")
  197. continue;
  198. // skip all properties if HideAllProperties flag is set
  199. if (component is Base && (component as Base).HasRestriction(Restrictions.HideAllProperties))
  200. continue;
  201. // check if property is not an event
  202. if (!prop.Name.EndsWith("Event"))
  203. properties.Add(new FRPropertyDescriptor(prop));
  204. }
  205. return properties;
  206. }
  207. public override Bitmap Bitmap
  208. {
  209. get { return Res.GetImage(78, 96); }
  210. }
  211. public override string TabName
  212. {
  213. get { return Res.Get("Designer,ToolWindow,Properties,PropertiesTab"); }
  214. }
  215. #endregion
  216. }
  217. internal class FREventsTab : PropertyTab
  218. {
  219. #region Public Methods
  220. public override bool CanExtend(object extendee)
  221. {
  222. return true;
  223. }
  224. public override PropertyDescriptorCollection GetProperties(
  225. ITypeDescriptorContext context, object component, Attribute[] attributes)
  226. {
  227. return GetProperties(component, attributes);
  228. }
  229. public override PropertyDescriptorCollection GetProperties(object component, Attribute[] attributes)
  230. {
  231. PropertyDescriptorCollection props = TypeDescriptor.GetProperties(component);
  232. PropertyDescriptorCollection properties = new PropertyDescriptorCollection(null);
  233. foreach (PropertyDescriptor prop in props)
  234. {
  235. BrowsableAttribute attr = prop.Attributes[typeof(BrowsableAttribute)] as BrowsableAttribute;
  236. // skip nonbrowsable properties
  237. if (attr != null && attr.Browsable == false) continue;
  238. // check if property is an event
  239. if (prop.Name.EndsWith("Event"))
  240. properties.Add(new FREventDescriptor(prop));
  241. }
  242. return properties;
  243. }
  244. public override Bitmap Bitmap
  245. {
  246. get { return Res.GetImage(79, 96); }
  247. }
  248. public override string TabName
  249. {
  250. get { return Res.Get("Designer,ToolWindow,Properties,EventsTab"); }
  251. }
  252. #endregion
  253. }
  254. }