123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- using System;
- using System.ComponentModel;
- using System.Drawing.Design;
- using System.Threading;
- using System.Globalization;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Windows.Forms.PropertyGridInternal;
- using System.Windows.Forms.Design;
- using FastReport.Utils;
- using FastReport.TypeEditors;
- using FastReport.TypeConverters;
- using FastReport.Editor.Syntax.Parsers;
- namespace FastReport.Controls
- {
- internal enum PropertyGridContent
- {
- Properties,
- Events
- }
- internal class FRPropertyGrid : PropertyGrid
- {
- public FRPropertyGrid()
- {
- UseCompatibleTextRendering = false;
- PropertySort = PropertySort.Alphabetical;
- PropertyTabs.RemoveTabType(typeof(PropertiesTab));
- }
- }
- internal class FRPropertiesGrid : FRPropertyGrid
- {
- protected override Type DefaultTabType
- {
- get { return typeof(FRPropertiesTab); }
- }
- public FRPropertiesGrid()
- {
- PropertyTabs.AddTabType(typeof(FRPropertiesTab));
- }
- }
- internal class FREventsGrid : FRPropertyGrid
- {
- protected override Type DefaultTabType
- {
- get { return typeof(FREventsTab); }
- }
- public FREventsGrid()
- {
- PropertyTabs.AddTabType(typeof(FREventsTab));
- }
- }
- internal class FRPropertyDescriptor : PropertyDescriptor
- {
- private PropertyDescriptor descriptor;
- public override string Category
- {
- get
- {
- return GetCategory();
- }
- }
- private string GetCategory()
- {
- CultureInfo currentlangUI = Thread.CurrentThread.CurrentUICulture;
- Thread.CurrentThread.CurrentUICulture = Config.EngCultureInfo;
- string category = descriptor.Category;
- Thread.CurrentThread.CurrentUICulture = currentlangUI;
- if (Res.StringExists("Properties,Categories," + category))
- return Res.Get("Properties,Categories," + category);
- return category;
- }
- public override string DisplayName
- {
- get
- {
- return descriptor.DisplayName;
- }
- }
- public override string Description
- {
- get
- {
- try
- {
- return ReflectionRepository.DescriptionHelper.GetDescription(ComponentType.GetProperty(Name));
- }
- catch
- {
- }
- return descriptor.Description;
- }
- }
- public override Type ComponentType
- {
- get { return descriptor.ComponentType; }
- }
- public override bool IsReadOnly
- {
- get { return descriptor.IsReadOnly; }
- }
- public override Type PropertyType
- {
- get { return descriptor.PropertyType; }
- }
- public override bool CanResetValue(object component)
- {
- return descriptor.CanResetValue(component);
- }
- public override object GetValue(object component)
- {
- return descriptor.GetValue(component);
- }
- public override void ResetValue(object component)
- {
- descriptor.ResetValue(component);
- }
- public override void SetValue(object component, object value)
- {
- descriptor.SetValue(component, value);
- }
- public override bool ShouldSerializeValue(object component)
- {
- return descriptor.ShouldSerializeValue(component);
- }
- public FRPropertyDescriptor(PropertyDescriptor descriptor)
- : base(descriptor)
- {
- this.descriptor = descriptor;
- }
- }
- internal class FREventDescriptor : FRPropertyDescriptor
- {
- public override string DisplayName
- {
- get { return base.DisplayName.Replace("Event", ""); }
- }
- protected override Attribute[] AttributeArray
- {
- get
- {
- return new Attribute[] {
- new EditorAttribute(typeof(EventEditor), typeof(UITypeEditor)),
- new TypeConverterAttribute(typeof(EventConverter))};
- }
- set { base.AttributeArray = value; }
- }
- public FREventDescriptor(PropertyDescriptor descriptor)
- : base(descriptor)
- {
- }
- }
- internal class FRPropertiesTab : PropertyTab
- {
- #region Public Methods
- public override bool CanExtend(object extendee)
- {
- return true;
- }
- public override PropertyDescriptorCollection GetProperties(
- ITypeDescriptorContext context, object component, Attribute[] attributes)
- {
- return GetProperties(component, attributes);
- }
- public override PropertyDescriptorCollection GetProperties(object component, Attribute[] attributes)
- {
- PropertyDescriptorCollection props = TypeDescriptor.GetProperties(component);
- PropertyDescriptorCollection properties = new PropertyDescriptorCollection(null);
- foreach (PropertyDescriptor prop in props)
- {
- BrowsableAttribute browsable = prop.Attributes[typeof(BrowsableAttribute)] as BrowsableAttribute;
- // skip nonbrowsable properties
- if (browsable != null && browsable.Browsable == false)
- continue;
- // skip properties other than "Restriction" if DontModify flag is set
- if (component is Base && (component as Base).HasRestriction(Restrictions.DontModify) && prop.Name != "Restrictions")
- continue;
- // skip all properties if HideAllProperties flag is set
- if (component is Base && (component as Base).HasRestriction(Restrictions.HideAllProperties))
- continue;
- // filter instance properties if Filtered is on
- if (component is ReportComponentBase r && (r.Report?.Designer?.PropertiesWindow?.Filtered ?? false))
- {
- if (typeof(ReportComponentBase).GetProperty(prop.Name) != null)
- continue;
- }
- // check if property is not an event
- if (!prop.Name.EndsWith("Event"))
- properties.Add(new FRPropertyDescriptor(prop));
- }
- return properties;
- }
- public override Bitmap Bitmap
- {
- get { return Res.GetImage(78, 96); }
- }
- public override string TabName
- {
- get { return Res.Get("Designer,ToolWindow,Properties,PropertiesTab"); }
- }
- #endregion
- }
- internal class FREventsTab : PropertyTab
- {
- #region Public Methods
- public override bool CanExtend(object extendee)
- {
- return true;
- }
- public override PropertyDescriptorCollection GetProperties(
- ITypeDescriptorContext context, object component, Attribute[] attributes)
- {
- return GetProperties(component, attributes);
- }
- public override PropertyDescriptorCollection GetProperties(object component, Attribute[] attributes)
- {
- PropertyDescriptorCollection props = TypeDescriptor.GetProperties(component);
- PropertyDescriptorCollection properties = new PropertyDescriptorCollection(null);
- foreach (PropertyDescriptor prop in props)
- {
- BrowsableAttribute attr = prop.Attributes[typeof(BrowsableAttribute)] as BrowsableAttribute;
- // skip nonbrowsable properties
- if (attr != null && attr.Browsable == false) continue;
- // check if property is an event
- if (prop.Name.EndsWith("Event"))
- properties.Add(new FREventDescriptor(prop));
- }
- return properties;
- }
- public override Bitmap Bitmap
- {
- get { return Res.GetImage(79, 96); }
- }
- public override string TabName
- {
- get { return Res.Get("Designer,ToolWindow,Properties,EventsTab"); }
- }
- #endregion
- }
- }
|