using System; namespace Gwen.Control { /// /// Tree control. /// public class TreeControl : TreeNode { private readonly ScrollControl m_ScrollControl; private bool m_MultiSelect; /// /// Determines if multiple nodes can be selected at the same time. /// public bool AllowMultiSelect { get { return m_MultiSelect; } set { m_MultiSelect = value; } } /// /// Initializes a new instance of the class. /// /// Parent control. public TreeControl(Base parent) : base(parent) { m_TreeControl = this; RemoveChild(m_ToggleButton, true); m_ToggleButton = null; RemoveChild(m_Title, true); m_Title = null; RemoveChild(m_InnerPanel, true); m_InnerPanel = null; m_MultiSelect = false; m_ScrollControl = new ScrollControl(this); m_ScrollControl.Dock = Pos.Fill; m_ScrollControl.EnableScroll(false, true); m_ScrollControl.AutoHideBars = true; m_ScrollControl.Margin = Margin.One; m_InnerPanel = m_ScrollControl; m_ScrollControl.SetInnerSize(1000, 1000); // todo: why such arbitrary numbers? } /// /// Renders the control using specified skin. /// /// Skin to use. protected override void Render(Skin.Base skin) { if (ShouldDrawBackground) skin.DrawTreeControl(this); } /// /// Handler invoked when control children's bounds change. /// /// /// protected override void OnChildBoundsChanged(Rectangle oldChildBounds, Base child) { if (m_ScrollControl != null) m_ScrollControl.UpdateScrollBars(); } /// /// Removes all child nodes. /// public virtual void RemoveAll() { m_ScrollControl.DeleteAll(); } /// /// Handler for node added event. /// /// Node added. public virtual void OnNodeAdded(TreeNode node) { node.LabelPressed += OnNodeSelected; } /// /// Handler for node selected event. /// /// Node selected. protected virtual void OnNodeSelected(Base Control) { if (!m_MultiSelect /*|| InputHandler.InputHandler.IsKeyDown(Key.Control)*/) UnselectAll(); } } }