using System; //using System.Windows.Forms; using Gwen.ControlInternal; namespace Gwen.Control { /// /// Properties table. /// public class Properties : Base { private readonly SplitterBar m_SplitterBar; /// /// Returns the width of the first column (property names). /// public int SplitWidth { get { return m_SplitterBar.X; } } // todo: rename? /// /// Invoked when a property value has been changed. /// public event GwenEventHandler ValueChanged; /// /// Initializes a new instance of the class. /// /// Parent control. public Properties(Base parent) : base(parent) { m_SplitterBar = new SplitterBar(this); m_SplitterBar.SetPosition(80, 0); //m_SplitterBar.Cursor = Cursors.SizeWE; m_SplitterBar.Dragged += OnSplitterMoved; m_SplitterBar.ShouldDrawBackground = false; } /// /// Function invoked after layout. /// /// Skin to use. protected override void PostLayout(Skin.Base skin) { m_SplitterBar.Height = 0; if (SizeToChildren(false, true)) { InvalidateParent(); } m_SplitterBar.SetSize(3, Height); } /// /// Handles the splitter moved event. /// /// Event source. protected virtual void OnSplitterMoved(Base control) { InvalidateChildren(); } /// /// Adds a new text property row. /// /// Property name. /// Initial value. /// Newly created row. public PropertyRow Add(String label, String value="") { return Add(label, new Property.Text(this), value); } /// /// Adds a new property row. /// /// Property name. /// Property control. /// Initial value. /// Newly created row. public PropertyRow Add(String label, Property.Base prop, String value="") { PropertyRow row = new PropertyRow(this, prop); row.Dock = Pos.Top; row.Label = label; row.ValueChanged += OnRowValueChanged; prop.SetValue(value, true); m_SplitterBar.BringToFront(); return row; } private void OnRowValueChanged(Base control) { if (ValueChanged != null) ValueChanged.Invoke(control); } /// /// Deletes all rows. /// public void DeleteAll() { m_InnerPanel.DeleteAllChildren(); } } }