Added the source code of Aga.Controls (TreeViewAdv for .Net) version 1.7.0.0.
2 using System.Collections.Generic;
4 using System.Windows.Forms;
6 using System.ComponentModel;
8 namespace Aga.Controls.Tree.NodeControls
10 public abstract class EditableControl : InteractiveControl
13 private bool _editFlag;
17 private bool _editOnClick = false;
19 public bool EditOnClick
21 get { return _editOnClick; }
22 set { _editOnClick = value; }
27 protected EditableControl()
30 _timer.Interval = 500;
31 _timer.Tick += new EventHandler(TimerTick);
34 private void TimerTick(object sender, EventArgs e)
42 public void SetEditorBounds(EditorContext context)
44 Size size = CalculateEditorSize(context);
45 context.Editor.Bounds = new Rectangle(context.Bounds.X, context.Bounds.Y,
46 Math.Min(size.Width, context.Bounds.Width),
47 Math.Min(size.Height, Parent.ClientSize.Height - context.Bounds.Y)
51 protected abstract Size CalculateEditorSize(EditorContext context);
53 protected virtual bool CanEdit(TreeNodeAdv node)
55 return (node.Tag != null) && IsEditEnabled(node);
58 public void BeginEdit()
60 if (Parent != null && Parent.CurrentNode != null && CanEdit(Parent.CurrentNode))
62 CancelEventArgs args = new CancelEventArgs();
63 OnEditorShowing(args);
66 var editor = CreateEditor(Parent.CurrentNode);
67 Parent.DisplayEditor(editor, this);
72 public void EndEdit(bool applyChanges)
75 if (Parent.HideEditor(applyChanges))
79 public virtual void UpdateEditor(Control control)
83 internal void ApplyChanges(TreeNodeAdv node, Control editor)
85 DoApplyChanges(node, editor);
89 internal void DoDisposeEditor(Control editor)
91 DisposeEditor(editor);
94 protected abstract void DoApplyChanges(TreeNodeAdv node, Control editor);
96 protected abstract Control CreateEditor(TreeNodeAdv node);
98 protected abstract void DisposeEditor(Control editor);
100 public virtual void Cut(Control control)
104 public virtual void Copy(Control control)
108 public virtual void Paste(Control control)
112 public virtual void Delete(Control control)
116 public override void MouseDown(TreeNodeAdvMouseEventArgs args)
118 _editFlag = (!EditOnClick && args.Button == MouseButtons.Left
119 && args.ModifierKeys == Keys.None && args.Node.IsSelected);
122 public override void MouseUp(TreeNodeAdvMouseEventArgs args)
124 if (args.Node.IsSelected)
126 if (EditOnClick && args.Button == MouseButtons.Left && args.ModifierKeys == Keys.None)
128 Parent.ItemDragMode = false;
132 else if (_editFlag)// && args.Node.IsSelected)
137 public override void MouseDoubleClick(TreeNodeAdvMouseEventArgs args)
143 protected override void Dispose(bool disposing)
145 base.Dispose(disposing);
152 public event CancelEventHandler EditorShowing;
153 protected void OnEditorShowing(CancelEventArgs args)
155 if (EditorShowing != null)
156 EditorShowing(this, args);
159 public event EventHandler EditorHided;
160 protected void OnEditorHided()
162 if (EditorHided != null)
163 EditorHided(this, EventArgs.Empty);
166 public event EventHandler ChangesApplied;
167 protected void OnChangesApplied()
169 if (ChangesApplied != null)
170 ChangesApplied(this, EventArgs.Empty);