Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Type: DevExpress.XtraVerticalGrid.PropertyGridControl
- // Assembly: DevExpress.XtraVerticalGrid.v10.2, Version=10.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
- // Assembly location: D:\Working\Projects\AutoCalc\3rdParty\DevExpress\DevExpress.XtraVerticalGrid.v10.2.dll
- using DevExpress.Utils;
- using DevExpress.Utils.About;
- using DevExpress.Utils.Controls;
- using DevExpress.Utils.Design;
- using DevExpress.Utils.Menu;
- using DevExpress.Utils.Serializing;
- using DevExpress.XtraEditors;
- using DevExpress.XtraEditors.Container;
- using DevExpress.XtraEditors.Controls;
- using DevExpress.XtraEditors.Repository;
- using DevExpress.XtraEditors.ViewInfo;
- using DevExpress.XtraVerticalGrid.Data;
- using DevExpress.XtraVerticalGrid.Editors;
- using DevExpress.XtraVerticalGrid.Events;
- using DevExpress.XtraVerticalGrid.Rows;
- using DevExpress.XtraVerticalGrid.ViewInfo;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.ComponentModel.Design;
- using System.Drawing;
- using System.Drawing.Design;
- using System.Reflection;
- using System.Windows.Forms;
- using System.Windows.Forms.Design;
- namespace DevExpress.XtraVerticalGrid
- {
- [Designer("DevExpress.XtraVerticalGrid.Design.PropertyGridDesigner, DevExpress.XtraVerticalGrid.v10.2.Design", typeof (IDesigner))]
- [LicenseProvider(typeof (DXVerticalGridLicenseProvider))]
- [Description("Displays properties of any object and allows them to be edited.")]
- [DefaultProperty("Rows")]
- [ToolboxItem(true)]
- [ToolboxTabName("DX.10.2: Data")]
- public class PropertyGridControl : VGridControlBase, IServiceProvider, IDXManagerPopupMenu, IPropertyDescriptorService
- {
- private Hashtable defaultEditorMarkers = new Hashtable();
- private Hashtable objects = new Hashtable();
- public const string FieldNameDelimiter = ".";
- private PGridDefaultEditors defaultEditors;
- private AttributeCollection browsableAttributes;
- private object[] dataSource;
- private bool fAutoGenerateRows;
- private RepositoryItemComboBox fComboEditor;
- private RepositoryItemButtonEdit fButtonEditor;
- private RepositoryItemPopupContainerEdit fPopupEditor;
- private RepositoryItemTextEdit fTextEditor;
- private PGridDataManager dataManager;
- private RowPositionKeeper oldFocusedPosition;
- private readonly WindowsFormsEditorService windowsFormsEditorService;
- private readonly Dictionary<string, UITypeEditor> customUITypeEditors;
- private int rowLoadingUnlockCount;
- private IServiceProvider serviceProvider;
- protected internal PGridDataModeHelper DataModeHelper
- {
- get
- {
- return (PGridDataModeHelper) this.DataManager.DataModeHelper;
- }
- }
- protected internal PGridEditorContainerHelper EditorHelper
- {
- get
- {
- return (PGridEditorContainerHelper) base.EditorHelper;
- }
- }
- public override object EditingValue
- {
- get
- {
- if (this.ActiveEditor == null)
- return (object) null;
- else
- return this.EditorHelper.ConvertFromValue(this.ActiveEditor.EditValue);
- }
- set
- {
- if (this.ActiveEditor == null)
- return;
- this.ActiveEditor.EditValue = this.EditorHelper.ConvertToValue(value);
- }
- }
- [DefaultValue(null)]
- [Category("Data")]
- [TypeConverter(typeof (PropertyGridControl.SelectedObjectConverter))]
- [Description("Gets or sets the object whose settings are edited by the PropertyGridControl.")]
- public object SelectedObject
- {
- get
- {
- if (this.dataSource != null && this.dataSource.Length != 0)
- return this.dataSource[0];
- else
- return (object) null;
- }
- set
- {
- if (value == null)
- this.SelectedObjects = new object[0];
- else
- this.SelectedObjects = new object[1]
- {
- value
- };
- }
- }
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public object[] SelectedObjects
- {
- get
- {
- if (this.dataSource == null)
- return new object[0];
- else
- return (object[]) this.dataSource.Clone();
- }
- set
- {
- if (this.AreEqual(this.dataSource, value))
- return;
- this.TrySaveFocusedRow();
- this.dataSource = value == null ? (object[]) null : (object[]) value.Clone();
- if (!this.IsLoading && !this.GridDisposing)
- {
- this.CloseEditor();
- if (this.Site != null && this.Site.DesignMode && this.Rows.Count > 0)
- {
- IUIService uiService = (IUIService) this.Site.GetService(typeof (IUIService));
- if (uiService == null || uiService.ShowMessage(value == null ? "Do you want to clear the row collection?" : "Do you want to repopulate the row collection?\nWarning: the existing rows will be destroyed.", "Row Designer", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- using (new UndoEngineHelper((IComponent) this))
- {
- this.BeginUpdate();
- try
- {
- this.Rows.DestroyRows();
- }
- finally
- {
- this.CancelUpdate();
- }
- }
- }
- }
- else if (this.AutoGenerateRows)
- {
- this.BeginUpdate();
- this.Rows.DestroyRows();
- this.CancelUpdate();
- }
- }
- this.ActivateDataSource();
- }
- }
- [DefaultValue(false)]
- [Description("Gets or sets whether rows are automatically created in the control for all fields in the bound object.")]
- [Category("Data")]
- public bool AutoGenerateRows
- {
- get
- {
- return this.fAutoGenerateRows;
- }
- set
- {
- if (value == this.fAutoGenerateRows)
- return;
- this.fAutoGenerateRows = value;
- }
- }
- [Description("Contains options that affect the display of context menus in a PropertyGridControl.")]
- [Category("Options")]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
- [XtraSerializableProperty(XtraSerializationVisibility.Content, XtraSerializationFlags.DefaultValue)]
- public PGridOptionsMenu OptionsMenu
- {
- get
- {
- return (PGridOptionsMenu) base.OptionsMenu;
- }
- }
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
- [Category("Options")]
- [Description("Provides access to the grid's behavior options.")]
- [XtraSerializableProperty(XtraSerializationVisibility.Content, XtraSerializationFlags.DefaultValue)]
- public PGridOptionsBehavior OptionsBehavior
- {
- get
- {
- return (PGridOptionsBehavior) base.OptionsBehavior;
- }
- }
- [Category("Options")]
- [Description("Provides access to the vertical grid's display options. ")]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
- [XtraSerializableProperty(XtraSerializationVisibility.Content, XtraSerializationFlags.DefaultValue)]
- public PGridOptionsView OptionsView
- {
- get
- {
- return (PGridOptionsView) base.OptionsView;
- }
- }
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public IServiceProvider ServiceProvider
- {
- get
- {
- return this.serviceProvider;
- }
- set
- {
- if (value == this.serviceProvider)
- return;
- if (this.serviceProvider != null)
- {
- this.UnsubscribeComponentEvents(this.serviceProvider);
- this.serviceProvider = (IServiceProvider) null;
- }
- if (value != null)
- this.SubscribeComponentEvents(value);
- this.serviceProvider = value;
- }
- }
- internal WindowsFormsEditorService WindowsFormsEditorService
- {
- get
- {
- return this.windowsFormsEditorService;
- }
- }
- protected internal virtual bool IsUnlockedRowLoading
- {
- get
- {
- return this.rowLoadingUnlockCount != 0;
- }
- }
- protected internal override VGridDataManager DataManager
- {
- get
- {
- return (VGridDataManager) this.dataManager;
- }
- }
- internal RepositoryItemButtonEdit ButtonEditor
- {
- get
- {
- if (this.fButtonEditor == null)
- this.fButtonEditor = (RepositoryItemButtonEdit) new PGRepositoryItemButtonEdit();
- return this.fButtonEditor;
- }
- }
- internal RepositoryItemComboBox ComboEditor
- {
- get
- {
- if (this.fComboEditor == null)
- {
- this.fComboEditor = (RepositoryItemComboBox) new PGRepositoryItemComboBox();
- this.fComboEditor.ShowDropDown = ShowDropDown.Never;
- this.fComboEditor.CycleOnDblClick = true;
- }
- return this.fComboEditor;
- }
- }
- internal RepositoryItemPopupContainerEdit PopupEditor
- {
- get
- {
- if (this.fPopupEditor == null)
- this.fPopupEditor = (RepositoryItemPopupContainerEdit) new PGRepositoryItemPopupContainerEdit();
- return this.fPopupEditor;
- }
- }
- internal RepositoryItemTextEdit TextEditor
- {
- get
- {
- if (this.fTextEditor == null)
- this.fTextEditor = (RepositoryItemTextEdit) new PGRepositoryItemTextEdit();
- return this.fTextEditor;
- }
- }
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
- [Category("Data")]
- [Browsable(false)]
- public PGridDefaultEditors DefaultEditors
- {
- get
- {
- return this.defaultEditors;
- }
- }
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [Browsable(false)]
- public AttributeCollection BrowsableAttributes
- {
- get
- {
- if (this.browsableAttributes == null)
- this.browsableAttributes = new AttributeCollection(new Attribute[1]
- {
- (Attribute) BrowsableAttribute.Yes
- });
- return this.browsableAttributes;
- }
- set
- {
- this.browsableAttributes = value;
- if (this.AutoGenerateRows)
- this.Rows.DestroyRows();
- this.ActivateDataSource();
- }
- }
- protected internal Dictionary<string, UITypeEditor> CustomUITypeEditors
- {
- get
- {
- return this.customUITypeEditors;
- }
- }
- [Obsolete("Use 'PopupMenuShowing' instead", false)]
- [Description("Allows context menus for rows to be customized.")]
- [Category("Behavior")]
- [Browsable(false)]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public event PropertyGridMenuEventHandler ShowMenu
- {
- add
- {
- this.Events.AddHandler(VGridControlBase.GS.showMenu, (Delegate) value);
- }
- remove
- {
- this.Events.RemoveHandler(VGridControlBase.GS.showMenu, (Delegate) value);
- }
- }
- [Category("Data")]
- [Description("Allows you to filter properties or display custom properties.")]
- public event CustomPropertyDescriptorsEventHandler CustomPropertyDescriptors
- {
- add
- {
- this.Events.AddHandler(VGridControlBase.GS.customPropertyDescriptors, (Delegate) value);
- }
- remove
- {
- this.Events.RemoveHandler(VGridControlBase.GS.customPropertyDescriptors, (Delegate) value);
- }
- }
- public PropertyGridControl()
- {
- this.dataManager = new PGridDataManager(this);
- this.defaultEditors = new PGridDefaultEditors(this);
- this.LayoutStyle = LayoutViewStyle.SingleRecordView;
- this.windowsFormsEditorService = new WindowsFormsEditorService(this);
- this.customUITypeEditors = new Dictionary<string, UITypeEditor>();
- }
- protected override VGridOptionsView CreateOptionsView()
- {
- return (VGridOptionsView) new PGridOptionsView();
- }
- protected override VGridOptionsBehavior CreateOptionsBehavior()
- {
- return (VGridOptionsBehavior) new PGridOptionsBehavior();
- }
- protected override VGridRows CreateRows()
- {
- return (VGridRows) new PGridVirtualRows(this);
- }
- protected override VGridMenuBase CreateMenu()
- {
- return (VGridMenuBase) new PGridMenu(this);
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- this.fGridDisposing = true;
- this.DisposeAutoEditors();
- this.ServiceProvider = (IServiceProvider) null;
- this.SelectedObject = (object) null;
- }
- base.Dispose(disposing);
- }
- private void DisposeAutoEditors()
- {
- this.Dispose((RepositoryItem) this.fComboEditor);
- this.Dispose((RepositoryItem) this.fButtonEditor);
- this.Dispose((RepositoryItem) this.fPopupEditor);
- this.Dispose((RepositoryItem) this.fTextEditor);
- }
- private void Dispose(RepositoryItem item)
- {
- if (item == null)
- return;
- item.Dispose();
- item = (RepositoryItem) null;
- }
- protected override void ActivateDataSource()
- {
- if (this.IsLoading)
- return;
- this.DataManager.SetGridDataSource((BindingContext) null, (object) this.SelectedObjects, (string) null);
- this.OnDataManager_Reset((object) this.DataManager, EventArgs.Empty);
- this.LayoutChanged();
- if (this.DataManager.CurrentControllerRow < 0 || this.DataManager.CurrentControllerRow > this.RecordCount - 1)
- this.FocusedRecord = Math.Min(0, this.RecordCount - 1);
- else
- this.FocusedRecord = this.DataManager.CurrentControllerRow;
- this.FocusedRecordCellIndex = this.RecordCount == 0 ? -1 : 0;
- }
- protected override void SetFocusedRowAfterChangingVisibleRows()
- {
- this.TryLoadFocusedRow();
- base.SetFocusedRowAfterChangingVisibleRows();
- }
- private void TrySaveFocusedRow()
- {
- if (this.FocusedRow == null || !this.FocusedRow.IsConnected)
- return;
- this.oldFocusedPosition = new RowPositionKeeper(this.FocusedRow);
- }
- private void TryLoadFocusedRow()
- {
- if (this.oldFocusedPosition == null)
- return;
- this.oldFocusedPosition.Restore(this);
- this.oldFocusedPosition = (RowPositionKeeper) null;
- }
- private bool AreEqual(object[] dataSource, object[] value)
- {
- bool flag = false;
- if (value != null && dataSource != null && dataSource.Length == value.Length)
- {
- int index = 0;
- while (index < value.Length && dataSource[index] == value[index])
- ++index;
- if (index == value.Length)
- flag = true;
- }
- return flag;
- }
- private void SubscribeComponentEvents(IServiceProvider provider)
- {
- IComponentChangeService componentChangeService = PropertyHelper.GetComponentChangeService(provider);
- if (componentChangeService == null)
- return;
- componentChangeService.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
- componentChangeService.ComponentRemoved += new ComponentEventHandler(this.OnComponentRemoved);
- }
- private void UnsubscribeComponentEvents(IServiceProvider provider)
- {
- IComponentChangeService componentChangeService = PropertyHelper.GetComponentChangeService(provider);
- if (componentChangeService == null)
- return;
- componentChangeService.ComponentChanged -= new ComponentChangedEventHandler(this.OnComponentChanged);
- componentChangeService.ComponentRemoved -= new ComponentEventHandler(this.OnComponentRemoved);
- }
- private void OnComponentRemoved(object sender, ComponentEventArgs e)
- {
- for (int index = 0; index < this.SelectedObjects.Length; ++index)
- {
- if (this.SelectedObjects[index] == e.Component)
- {
- object[] objArray = new object[this.SelectedObjects.Length - 1];
- Array.Copy((Array) this.SelectedObjects, 0, (Array) objArray, 0, index);
- if (index < objArray.Length)
- Array.Copy((Array) this.SelectedObjects, index + 1, (Array) objArray, index, objArray.Length - index);
- this.SelectedObjects = objArray;
- break;
- }
- }
- }
- private void OnComponentChanged(object sender, ComponentChangedEventArgs e)
- {
- bool flag = false;
- int length = this.SelectedObjects.Length;
- for (int index = 0; index < length; ++index)
- {
- if (this.SelectedObjects[index] == e.Component)
- {
- flag = true;
- break;
- }
- }
- if (!flag)
- return;
- this.ComponentChanged();
- }
- protected virtual void ComponentChanged()
- {
- this.DataModeHelper.Invalidate();
- this.InvalidateUpdate();
- }
- private bool ShouldSerializeOptionsMenu()
- {
- return this.OptionsMenu.ShouldSerializeCore((IComponent) this);
- }
- internal void ProcessUIEditing(object sender, ButtonPressedEventArgs args)
- {
- if (args != null && args.Button != null && !args.Button.IsDefaultButton)
- return;
- this.WindowsFormsEditorService.ProcessUIEditing();
- }
- object IServiceProvider.GetService(System.Type serviceType)
- {
- if (serviceType == typeof (IWindowsFormsEditorService))
- return (object) this.windowsFormsEditorService;
- if (serviceType == typeof (IPropertyDescriptorService))
- return (object) this;
- if (this.ServiceProvider == null)
- return (object) null;
- else
- return this.ServiceProvider.GetService(serviceType);
- }
- protected internal virtual void UnlockRowLoading()
- {
- ++this.rowLoadingUnlockCount;
- }
- protected internal virtual void LockRowLoading()
- {
- --this.rowLoadingUnlockCount;
- }
- protected override EditorContainerHelper CreateHelper()
- {
- return (EditorContainerHelper) new PGridEditorContainerHelper((VGridControlBase) this);
- }
- protected internal override bool IsDefault(RepositoryItem item)
- {
- if (item == null)
- return false;
- else
- return this.defaultEditorMarkers.Contains((object) item);
- }
- protected internal override void OnClearViewInfo()
- {
- base.OnClearViewInfo();
- this.defaultEditorMarkers.Clear();
- }
- protected RepositoryItem MakeDefault(RepositoryItem item)
- {
- if (item != null)
- this.defaultEditorMarkers.Add((object) item, (object) true);
- return item;
- }
- protected internal override RepositoryItem CreateDefaultRowEdit(RowProperties p)
- {
- DescriptorContext descriptorContext = this.DataModeHelper.GetDescriptorContext(p.FieldName);
- PropertyDescriptor propertyDescriptor = descriptorContext.PropertyDescriptor;
- if (p.Row == null || propertyDescriptor == null)
- return this.MakeDefault((RepositoryItem) base.CreateDefaultRowEdit(p).Clone());
- if (this.OptionsBehavior.UseDefaultEditorsCollection)
- {
- DevExpress.XtraVerticalGrid.Rows.DefaultEditor defaultEditor = this.DefaultEditors[propertyDescriptor.PropertyType];
- if (defaultEditor != null && defaultEditor.Edit != null)
- return this.MakeDefault((RepositoryItem) defaultEditor.Edit.Clone());
- }
- switch (this.DataModeHelper.GetEditStyle(descriptorContext))
- {
- case UITypeEditorEditStyle.Modal:
- return this.MakeDefault((RepositoryItem) this.ButtonEditor.Clone());
- case UITypeEditorEditStyle.DropDown:
- return this.MakeDefault((RepositoryItem) this.PopupEditor.Clone());
- default:
- if (PropertyHelper.GetStandardValuesSupported((ITypeDescriptorContext) descriptorContext))
- return this.MakeDefault((RepositoryItem) this.ComboEditor.Clone());
- else
- return this.MakeDefault((RepositoryItem) this.TextEditor.Clone());
- }
- }
- protected override void ConfigureRowEdit(RepositoryItem item, RowProperties p)
- {
- base.ConfigureRowEdit(item, p);
- DescriptorContext descriptorContext = this.DataModeHelper.GetDescriptorContext(p.FieldName);
- PropertyDescriptor propertyDescriptor = descriptorContext.PropertyDescriptor;
- if (p.Row == null || propertyDescriptor == null)
- return;
- item.BeginUpdate();
- if (!item.ReadOnly && this.IsDefault(item))
- item.ReadOnly = this.ViewInfoHelper.ShouldRenderReadOnly(p.FieldName, p);
- RepositoryItemButtonEdit repositoryItemButtonEdit = item as RepositoryItemButtonEdit;
- if (repositoryItemButtonEdit != null && (this.IsDefault(item) || !this.IsDefault(item) && repositoryItemButtonEdit.TextEditStyle == TextEditStyles.Standard))
- repositoryItemButtonEdit.TextEditStyle = PropertyHelper.AllowTextEdit((ITypeDescriptorContext) descriptorContext) ? TextEditStyles.Standard : TextEditStyles.DisableTextEditor;
- if (this.IsAutoEditor(item) && PropertyHelper.IsPassword(descriptorContext))
- {
- RepositoryItemTextEdit repositoryItemTextEdit = item as RepositoryItemTextEdit;
- if (repositoryItemTextEdit != null)
- repositoryItemTextEdit.PasswordChar = this.OptionsView.PasswordChar;
- }
- item.CancelUpdate();
- }
- protected internal virtual bool IsAutoEditor(RepositoryItem item)
- {
- if (item is IAutoEditor)
- return true;
- else
- return false;
- }
- protected override void OnOptionsBehaviorChanged(object sender, BaseOptionChangedEventArgs e)
- {
- if (!(e.Name == "UseDefaultEditorsCollection"))
- return;
- this.ResetGeneratedRowEdits();
- }
- protected override void OnOptionsViewChanged(object sender, BaseOptionChangedEventArgs e)
- {
- base.OnOptionsViewChanged(sender, e);
- if (!(e.Name == "PasswordChar"))
- return;
- this.ResetGeneratedRowEdits();
- }
- protected override void AddVisibleRows(VGridRows rows, bool root)
- {
- if (this.OptionsView == null)
- return;
- if (!root || this.OptionsView.ShowRootCategories)
- {
- base.AddVisibleRows(rows, root);
- }
- else
- {
- List<BaseRow> list = new List<BaseRow>();
- foreach (BaseRow baseRow1 in rows)
- {
- if (baseRow1.Visible)
- {
- if (!(baseRow1 is CategoryRow))
- {
- list.Add(baseRow1);
- }
- else
- {
- foreach (BaseRow baseRow2 in baseRow1.ChildRows)
- {
- if (baseRow2.Visible)
- list.Add(baseRow2);
- }
- }
- }
- }
- list.Sort((IComparer<BaseRow>) new PGridRowComparer((IList) list));
- foreach (BaseRow row in list)
- {
- this.VisibleRows.Add(row);
- if (row.Expanded)
- this.AddVisibleRows(row.ChildRows, false);
- }
- }
- }
- protected override void ProcessEditorAfterPost(object value)
- {
- base.ProcessEditorAfterPost(value);
- this.EditorHelper.UnmodifiedEditValue = value;
- }
- protected internal void RetrieveFieldsCore(VGridRows rows, bool createCategories, string parentPropertyName, bool forceChildRowsCreating)
- {
- rows.IsLoadedCore = true;
- object singleValue = PropertyHelper.GetSingleValue(this, parentPropertyName);
- if (singleValue == null || this.objects.ContainsKey(singleValue))
- return;
- DescriptorContext descriptorContext = this.DataModeHelper.GetSingleDescriptorContext(parentPropertyName);
- if (!PropertyHelper.IsRoot(parentPropertyName) && !PropertyHelper.GetPropertiesSupported(singleValue, (ITypeDescriptorContext) descriptorContext))
- return;
- PropertyDescriptorCollection properties = descriptorContext.GetProperties(singleValue, this.GetBrowsableAttributesArray());
- if (properties == null || properties.Count == 0)
- return;
- this.objects.Add(singleValue, (object) null);
- Dictionary<string, BaseRow> categories = new Dictionary<string, BaseRow>();
- PropertyDescriptorCollection descriptorCollection = this.ApplySorting(properties);
- int retrieveIndex = -1;
- foreach (PropertyDescriptor pd in descriptorCollection)
- {
- ++retrieveIndex;
- string propertyName = this.GetPropertyName(parentPropertyName, pd.Name);
- if (!this.DataModeHelper.IsMultiSource || this.ShouldIncludeMultiProperty(propertyName))
- {
- PGridEditorRow row = (PGridEditorRow) this.CreateEditorRow(propertyName);
- this.AssignRetrieveIndex((BaseRow) row, retrieveIndex, descriptorCollection.Count, pd);
- row.Properties.Caption = this.GetCaption(pd);
- this.TryExtractChildren(row, forceChildRowsCreating, propertyName);
- this.TryAddToCategory(rows, createCategories, categories, pd, (BaseRow) row);
- }
- }
- if (createCategories)
- rows.AddRange(this.GetCategories(categories));
- this.objects.Remove(singleValue);
- }
- protected virtual PropertyDescriptorCollection ApplySorting(PropertyDescriptorCollection properties)
- {
- if (this.GetComparer(properties) != null)
- return properties;
- else
- return properties.Sort((IComparer) new DisplayNameComparer());
- }
- private object GetComparer(PropertyDescriptorCollection properties)
- {
- object obj = (object) null;
- try
- {
- obj = properties.GetType().GetField("comparer", BindingFlags.Instance | BindingFlags.NonPublic).GetValue((object) properties);
- }
- catch
- {
- }
- return obj;
- }
- private void AssignRetrieveIndex(BaseRow row, int retrieveIndex, int rowCount, PropertyDescriptor pd)
- {
- IRetrievable retrievable = row as IRetrievable;
- if (retrievable == null)
- return;
- if (this.NeedParenthesize(pd))
- retrievable.RetrieveIndex = retrieveIndex - rowCount;
- else
- retrievable.RetrieveIndex = retrieveIndex;
- }
- protected virtual BaseRow CreateEditorRow(string propertyName)
- {
- BaseRow editorRow = base.CreateEditorRow();
- editorRow.Properties.FieldName = propertyName;
- return editorRow;
- }
- public override BaseRow CreateEditorRow()
- {
- return (BaseRow) new PGridEditorRow();
- }
- private string GetPropertyName(string parentPropertyName, string name)
- {
- if (!string.IsNullOrEmpty(parentPropertyName))
- return parentPropertyName + "." + name;
- else
- return name;
- }
- private string GetCaption(PropertyDescriptor pd)
- {
- if (this.NeedParenthesize(pd))
- return this.ParenthesizeCaption(pd.DisplayName);
- else
- return pd.DisplayName;
- }
- private void TryAddToCategory(VGridRows rows, bool createCategories, Dictionary<string, BaseRow> categories, PropertyDescriptor pd, BaseRow row)
- {
- if (createCategories)
- {
- string category = pd.Category;
- BaseRow baseRow = (BaseRow) null;
- if (!categories.TryGetValue(category, out baseRow))
- {
- baseRow = (BaseRow) new CategoryRow(category);
- categories[category] = baseRow;
- }
- baseRow.ChildRows.Add(row);
- }
- else
- rows.Add(row);
- }
- private void TryExtractChildren(PGridEditorRow row, bool forceChildRowsCreating, string propertyName)
- {
- object singleValue = PropertyHelper.GetSingleValue(this, propertyName);
- if (singleValue == null || !PropertyHelper.GetPropertiesSupported(singleValue, (ITypeDescriptorContext) this.DataModeHelper.GetSingleDescriptorContext(propertyName)))
- {
- row.IsChildRowsLoaded = true;
- }
- else
- {
- if (forceChildRowsCreating)
- this.RetrieveFieldsCore(row.ChildRows, false, propertyName, forceChildRowsCreating);
- else
- row.IsChildRowsLoaded = false;
- row.Expanded = false;
- }
- }
- private bool ShouldIncludeMultiProperty(string propertyName)
- {
- if (!this.DataModeHelper.IsMultiSource)
- return false;
- else
- return this.DataModeHelper.GetDescriptorContext(propertyName).PropertyDescriptor != null;
- }
- private bool NeedParenthesize(PropertyDescriptor pd)
- {
- return ((ParenthesizePropertyNameAttribute) pd.Attributes[typeof (ParenthesizePropertyNameAttribute)]).NeedParenthesis;
- }
- private BaseRow[] GetCategories(Dictionary<string, BaseRow> categories)
- {
- List<BaseRow> list = new List<BaseRow>(categories.Count);
- foreach (BaseRow baseRow in categories.Values)
- {
- baseRow.ChildRows.Sort((IComparer) new PGridRowComparer((IList) baseRow.ChildRows));
- list.Add(baseRow);
- }
- list.Sort((IComparer<BaseRow>) new CaptionComparer());
- return list.ToArray();
- }
- internal Attribute[] GetBrowsableAttributesArray()
- {
- Attribute[] attributeArray = new Attribute[this.BrowsableAttributes.Count];
- this.BrowsableAttributes.CopyTo((Array) attributeArray, 0);
- return attributeArray;
- }
- private string ParenthesizeCaption(string caption)
- {
- return "(" + caption + ")";
- }
- protected internal override void OnRowChanged(BaseRow row, VGridRows rows, RowProperties rowProperties, RowChangeTypeEnum changeType)
- {
- base.OnRowChanged(row, rows, rowProperties, changeType);
- if (changeType == RowChangeTypeEnum.Value && !this.IsLoading)
- this.GetRefreshStrategy(rowProperties, this.GetCellValue(row, 0)).Refresh();
- this.DataModeHelper.ChangedImmutableFieldName = (string) null;
- }
- protected virtual PropertyGridControl.RefreshStrategyBase GetRefreshStrategy(RowProperties props, object newValue)
- {
- if (this.NeedRefreshRefreshProperty(props))
- return (PropertyGridControl.RefreshStrategyBase) new PropertyGridControl.RefreshAllStrategy(props);
- if (PropertyHelper.GetPropertiesSupported(newValue, (ITypeDescriptorContext) this.DataModeHelper.GetDescriptorContext(props.FieldName)))
- return (PropertyGridControl.RefreshStrategyBase) new PropertyGridControl.RefreshChildrenStrategy(props);
- if (string.IsNullOrEmpty(this.DataModeHelper.ChangedImmutableFieldName))
- return (PropertyGridControl.RefreshStrategyBase) new PropertyGridControl.VoidRefreshStrategy();
- BaseRow rowByFieldName = this.GetRowByFieldName(this.DataModeHelper.ChangedImmutableFieldName);
- if (rowByFieldName == null)
- return (PropertyGridControl.RefreshStrategyBase) new PropertyGridControl.VoidRefreshStrategy();
- else
- return (PropertyGridControl.RefreshStrategyBase) new PropertyGridControl.UpdateChildrenDataStrategy(rowByFieldName.Properties);
- }
- private bool NeedRefreshRefreshProperty(RowProperties properties)
- {
- if (this.AutoGenerateRows)
- return this.DataModeHelper.HasRefreshPropertiesAttribute(properties);
- else
- return false;
- }
- protected override bool GenerateRowsOnDataManagerReset()
- {
- if (base.GenerateRowsOnDataManagerReset())
- return !this.DesignMode;
- else
- return false;
- }
- public override void RetrieveFields()
- {
- this.RetrieveFields(!this.OptionsBehavior.AllowDynamicRowLoading);
- }
- public void RetrieveFields(bool forceChildRowsCreating)
- {
- if (this.SelectedObject == null)
- return;
- this.BeginUpdate();
- try
- {
- this.DataModeHelper.Invalidate();
- this.Rows.DestroyRows();
- this.objects = new Hashtable();
- this.RetrieveFieldsCore(this.Rows, true, "", forceChildRowsCreating);
- }
- finally
- {
- this.EndUpdate();
- }
- }
- internal BaseRow GetLoadedRowByFieldName(string fieldName)
- {
- return this.Rows.GetLoadedRowByFieldName(fieldName, true);
- }
- public PropertyDescriptor GetPropertyDescriptor(BaseRow row)
- {
- object targetObject;
- return this.GetPropertyDescriptor(row, out targetObject);
- }
- public PropertyDescriptor GetPropertyDescriptor(BaseRow row, out object targetObject)
- {
- if (row == null)
- throw new ArgumentNullException("row");
- DescriptorContext descriptorContext = this.DataModeHelper.GetDescriptorContext(row.Properties.FieldName);
- targetObject = descriptorContext.Instance;
- return descriptorContext.PropertyDescriptor;
- }
- internal void UpdateEditor()
- {
- this.PostEditor();
- if (this.ActiveEditor == null)
- return;
- this.ActiveEditor.Properties.Appearance.Assign(this.UpdateFocusedAppearance());
- }
- private AppearanceObject UpdateFocusedAppearance()
- {
- RowValueInfo rowValueInfo = this.ViewInfo[this.FocusedRow].ValuesInfo[this.FocusedRecordCellIndex];
- rowValueInfo.CalcAppearance(this.ViewInfo);
- return rowValueInfo.Style;
- }
- protected internal override void RowDoubleClick(BaseRow row)
- {
- if (row != null && row.HasChildren)
- {
- base.RowDoubleClick(row);
- }
- else
- {
- if (this.ActiveEditor == null)
- this.ShowEditor();
- ComboBoxEdit comboEdit;
- if (this.ActiveEditor == null || this.ActiveEditor.Properties.ReadOnly || (comboEdit = this.ActiveEditor as ComboBoxEdit) == null)
- return;
- this.ScrollComboBox(comboEdit);
- }
- }
- protected internal override void UpdateEditViewInfoData(BaseEditViewInfo editViewInfo, RowProperties properties, int recordIndex)
- {
- base.UpdateEditViewInfoData(editViewInfo, properties, recordIndex);
- if (!this.OverrideEditorDisplayText(editViewInfo.Item, properties))
- return;
- string textData = this.DataModeHelper.GetTextData(properties, recordIndex);
- if (properties.Format.FormatType != FormatType.None || textData == null)
- return;
- editViewInfo.SetDisplayText(textData);
- }
- protected virtual bool OverrideEditorDisplayText(RepositoryItem item, RowProperties properties)
- {
- if (properties == null)
- return false;
- bool flag = this.EditorHelper.OverrideEditorDisplayText(item, properties.FieldName);
- RepositoryItemTextEdit repositoryItemTextEdit = item as RepositoryItemTextEdit;
- if (repositoryItemTextEdit != null && (int) repositoryItemTextEdit.PasswordChar != 0)
- return false;
- else
- return flag;
- }
- protected virtual void CheckPropertyDescriptors(PropertyDescriptorCollection properties)
- {
- if (properties == null)
- return;
- foreach (PropertyDescriptor propertyDescriptor in properties)
- {
- if (propertyDescriptor == null)
- throw new ArgumentNullException("Properties");
- }
- }
- internal bool CanResetDefaultValue(RowProperties properties)
- {
- return this.DataModeHelper.CanResetDefaultValue(properties);
- }
- internal void ResetDefaultValue(BaseRow row)
- {
- this.DataModeHelper.Reset = true;
- try
- {
- this.SetCellValue(row, 0, (object) null);
- if (this.ActiveEditor == null || row != this.FocusedRow)
- return;
- this.EditingValue = this.GetCellValue(row, 0);
- }
- finally
- {
- this.DataModeHelper.Reset = false;
- }
- }
- private void ScrollComboBox(ComboBoxEdit comboEdit)
- {
- int count = comboEdit.Properties.Items.Count;
- if (count == 0)
- return;
- comboEdit.IsModified = true;
- comboEdit.SelectedIndex = comboEdit.SelectedIndex >= count - 1 ? 0 : comboEdit.SelectedIndex + 1;
- this.PostEditor();
- }
- protected internal override void RaiseShowMenu(PopupMenuShowingEventArgs e)
- {
- this.RaiseShowMenuCore(e);
- PropertyGridMenuEventHandler menuEventHandler = (PropertyGridMenuEventHandler) this.Events[VGridControlBase.GS.showMenu];
- if (menuEventHandler == null)
- return;
- PropertyGridMenuEventArgs e1 = new PropertyGridMenuEventArgs(e.Menu, e.Row);
- menuEventHandler((object) this, e1);
- }
- protected virtual void RaiseCustomPropertyDescriptors(CustomPropertyDescriptorsEventArgs e)
- {
- CustomPropertyDescriptorsEventHandler descriptorsEventHandler = (CustomPropertyDescriptorsEventHandler) this.Events[VGridControlBase.GS.customPropertyDescriptors];
- if (descriptorsEventHandler == null)
- return;
- descriptorsEventHandler((object) this, e);
- }
- protected internal virtual void ProcessUIEditingException(Exception e)
- {
- int num = (int) MessageBox.Show(e.Message, "Error Information", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- }
- internal UITypeEditor GetUITypeEditor(PropertyDescriptor propertyDescriptor)
- {
- UITypeEditor uiTypeEditor;
- if (this.CustomUITypeEditors.TryGetValue(propertyDescriptor.Name, out uiTypeEditor))
- return uiTypeEditor;
- try
- {
- return propertyDescriptor.GetEditor(typeof (UITypeEditor)) as UITypeEditor;
- }
- catch
- {
- return (UITypeEditor) null;
- }
- }
- protected internal override VGridViewInfoHelper CreateViewInfoHelper()
- {
- return (VGridViewInfoHelper) new PGridViewInfoHelper(this);
- }
- PropertyDescriptorCollection IPropertyDescriptorService.GetProperties(object source, ITypeDescriptorContext context, Attribute[] attributes)
- {
- CustomPropertyDescriptorsEventArgs e = new CustomPropertyDescriptorsEventArgs(source, context, attributes);
- this.RaiseCustomPropertyDescriptors(e);
- this.CheckPropertyDescriptors(e.Properties);
- return e.Properties;
- }
- protected internal virtual void ConfigurePredefinedProperties(DevExpress.XtraVerticalGrid.Rows.DefaultEditor edit)
- {
- RepositoryItemColorEdit repositoryItemColorEdit = edit.Edit as RepositoryItemColorEdit;
- if (repositoryItemColorEdit == null || edit.EditingType != typeof (Color))
- return;
- repositoryItemColorEdit.TextEditStyle = TextEditStyles.Standard;
- }
- protected override bool BreakPostOnEquals()
- {
- if (!base.BreakPostOnEquals() && !this.GridDisposing)
- return object.Equals(this.EditorHelper.UnmodifiedEditValue, this.ActiveEditor.EditValue);
- else
- return true;
- }
- private class SelectedObjectConverter : ReferenceConverter
- {
- public SelectedObjectConverter()
- : base(typeof (IComponent))
- {
- }
- }
- protected abstract class RefreshStrategyBase
- {
- private readonly RowProperties rowProperties;
- private readonly PropertyGridControl grid;
- public PropertyGridControl Grid
- {
- get
- {
- return this.grid;
- }
- }
- public BaseRow Row
- {
- get
- {
- return this.RowProperties.Row;
- }
- }
- public RowProperties RowProperties
- {
- get
- {
- return this.rowProperties;
- }
- }
- public string FieldName
- {
- get
- {
- return this.RowProperties.FieldName;
- }
- }
- public RefreshStrategyBase(RowProperties rowProperties)
- {
- if (rowProperties == null)
- return;
- this.rowProperties = rowProperties;
- this.grid = (PropertyGridControl) rowProperties.Row.Grid;
- }
- public abstract void Refresh();
- }
- private class VoidRefreshStrategy : PropertyGridControl.RefreshStrategyBase
- {
- public VoidRefreshStrategy()
- : base((RowProperties) null)
- {
- }
- public override void Refresh()
- {
- }
- }
- private class RefreshAllStrategy : PropertyGridControl.RefreshStrategyBase
- {
- public RefreshAllStrategy(RowProperties props)
- : base(props)
- {
- }
- public override void Refresh()
- {
- this.Grid.BeginUpdate();
- SaveExpandedStateOperation expandedStateOperation = new SaveExpandedStateOperation();
- this.Grid.RowsIterator.DoOperation((RowOperation) expandedStateOperation);
- object[] selectedObjects = this.Grid.SelectedObjects;
- this.Grid.SelectedObjects = (object[]) null;
- this.Grid.SelectedObjects = selectedObjects;
- this.Grid.RowsIterator.DoOperation((RowOperation) new LoadExpandedStateOperation(expandedStateOperation.ExpandedRowStateStore));
- this.Grid.EndUpdate();
- }
- }
- private class RefreshChildrenStrategy : PropertyGridControl.RefreshStrategyBase
- {
- public RefreshChildrenStrategy(RowProperties props)
- : base(props)
- {
- }
- public override void Refresh()
- {
- if (!this.Row.ChildRows.IsLoaded)
- return;
- OneRowState oneRowState = new OneRowState(this.Row);
- this.Grid.BeginUpdate();
- this.Row.ChildRows.DestroyRows();
- this.Grid.RetrieveFieldsCore(this.Row.ChildRows, false, this.FieldName, true);
- this.Grid.EndUpdate();
- oneRowState.Restore(this.Grid);
- }
- }
- private class UpdateChildrenDataStrategy : PropertyGridControl.RefreshStrategyBase
- {
- public UpdateChildrenDataStrategy(RowProperties props)
- : base(props)
- {
- }
- public override void Refresh()
- {
- if (!this.Row.ChildRows.IsLoaded)
- return;
- this.Grid.BeginUpdate();
- this.Grid.RowsIterator.DoLocalOperation((RowOperation) new DelegateRowPropertiesOperation(new DelegateRowPropertiesOperation.ExecuteDelegate(this.InvalidateRow)), this.Row);
- this.Grid.EndUpdate();
- }
- private void InvalidateRow(RowProperties properties)
- {
- this.Grid.ViewInfo.UpdateCellData(properties.Row, 0, properties.CellIndex);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement