FRPropertyGrid.cs 8.2 KB

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