using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using InABox.Core; namespace InABox.DynamicGrid { public delegate void EditorControlValueChangedHandler(IDynamicEditorControl sender, Dictionary values); public interface IDynamicEditorControl { string ColumnName { get; set; } bool Loaded { get; set; } BaseEditor EditorDefinition { get; set; } bool IsEnabled { get; set; } void SetFocus(); int DesiredHeight(); event EditorControlValueChangedHandler OnEditorValueChanged; void Configure(); void SetEnabled(bool enabled); void SetVisible(bool enabled); void SetValue(object value); object GetValue(); } public interface ILookupEditorControl : IDynamicEditorControl { Dictionary OtherColumns { get; } event OnDefineLookup OnDefineLookups; event OnLookupsDefined OnLookupsDefined; void LoadLookups(CoreTable values); } public interface IPopupEditorControl { event OnDefineFilter OnDefineFilter; } public abstract class BaseDynamicEditorControl : ContentControl, IDynamicEditorControl { public static readonly DependencyProperty ColumnNameProperty = DependencyProperty.Register(nameof(ColumnName), typeof(string), typeof(BaseDynamicEditorControl)); public static readonly DependencyProperty ColorProperty = DependencyProperty.Register("Color", typeof(Color), typeof(BaseDynamicEditorControl)); public new static readonly DependencyProperty IsEnabledProperty = DependencyProperty.Register(nameof(IsEnabled), typeof(bool), typeof(BaseDynamicEditorControl)); private BaseEditor _editordefinition; public BaseDynamicEditorControl() { Color = Colors.LightYellow; } public Color Color { get => (Color)GetValue(ColorProperty); set { SetValue(ColorProperty, value); if (EditorDefinition != null) SetColor(Color); } } public string ColumnName { get => (string)GetValue(ColumnNameProperty); set => SetValue(ColumnNameProperty, value); } [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public BaseEditor EditorDefinition { get => _editordefinition; set { _editordefinition = value; Content = CreateEditor(); SetColor(Color); } } [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public bool Loaded { get; set; } public virtual event EditorControlValueChangedHandler OnEditorValueChanged; public abstract int DesiredHeight(); public abstract void SetFocus(); public virtual void Configure() { } public abstract void SetEnabled(bool enabled); public abstract void SetVisible(bool visible); public abstract void SetValue(object? value); public abstract object GetValue(); public new bool IsEnabled { get => (bool)GetValue(IsEnabledProperty); set { SetValue(IsEnabledProperty, value); SetEnabled(value); } } protected abstract FrameworkElement CreateEditor(); public abstract int DesiredWidth(); public abstract void SetColor(Color color); protected List