first commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Aga.Controls.Tree
|
||||
{
|
||||
internal class ClickColumnState : ColumnState
|
||||
{
|
||||
private Point _location;
|
||||
|
||||
public ClickColumnState(TreeViewAdv tree, TreeColumn column, Point location)
|
||||
: base(tree, column)
|
||||
{
|
||||
_location = location;
|
||||
}
|
||||
|
||||
public override void KeyDown(KeyEventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
public override void MouseDown(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool MouseMove(MouseEventArgs args)
|
||||
{
|
||||
if (TreeViewAdv.Dist(_location, args.Location) > TreeViewAdv.ItemDragSensivity
|
||||
&& Tree.AllowColumnReorder)
|
||||
{
|
||||
Tree.Input = new ReorderColumnState(Tree, Column, args.Location);
|
||||
Tree.UpdateView();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void MouseUp(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
Tree.ChangeInput();
|
||||
Tree.UpdateView();
|
||||
Tree.OnColumnClicked(Column);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Aga.Controls.Tree
|
||||
{
|
||||
internal abstract class ColumnState : InputState
|
||||
{
|
||||
private TreeColumn _column;
|
||||
public TreeColumn Column
|
||||
{
|
||||
get { return _column; }
|
||||
}
|
||||
|
||||
public ColumnState(TreeViewAdv tree, TreeColumn column)
|
||||
: base(tree)
|
||||
{
|
||||
_column = column;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
namespace Aga.Controls.Tree
|
||||
{
|
||||
internal abstract class InputState
|
||||
{
|
||||
private TreeViewAdv _tree;
|
||||
|
||||
public TreeViewAdv Tree
|
||||
{
|
||||
get { return _tree; }
|
||||
}
|
||||
|
||||
public InputState(TreeViewAdv tree)
|
||||
{
|
||||
_tree = tree;
|
||||
}
|
||||
|
||||
public abstract void KeyDown(System.Windows.Forms.KeyEventArgs args);
|
||||
public abstract void MouseDown(TreeNodeAdvMouseEventArgs args);
|
||||
public abstract void MouseUp(TreeNodeAdvMouseEventArgs args);
|
||||
|
||||
/// <summary>
|
||||
/// handle OnMouseMove event
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns>true if event was handled and should be dispatched</returns>
|
||||
public virtual bool MouseMove(MouseEventArgs args)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void MouseDoubleClick(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Aga.Controls.Tree
|
||||
{
|
||||
internal class InputWithControl: NormalInputState
|
||||
{
|
||||
public InputWithControl(TreeViewAdv tree): base(tree)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DoMouseOperation(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
if (Tree.SelectionMode == TreeSelectionMode.Single)
|
||||
{
|
||||
base.DoMouseOperation(args);
|
||||
}
|
||||
else if (CanSelect(args.Node))
|
||||
{
|
||||
args.Node.IsSelected = !args.Node.IsSelected;
|
||||
Tree.SelectionStart = args.Node;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void MouseDownAtEmptySpace(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Aga.Controls.Tree
|
||||
{
|
||||
internal class InputWithShift: NormalInputState
|
||||
{
|
||||
public InputWithShift(TreeViewAdv tree): base(tree)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void FocusRow(TreeNodeAdv node)
|
||||
{
|
||||
Tree.SuspendSelectionEvent = true;
|
||||
try
|
||||
{
|
||||
if (Tree.SelectionMode == TreeSelectionMode.Single || Tree.SelectionStart == null)
|
||||
base.FocusRow(node);
|
||||
else if (CanSelect(node))
|
||||
{
|
||||
SelectAllFromStart(node);
|
||||
Tree.CurrentNode = node;
|
||||
Tree.ScrollTo(node);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Tree.SuspendSelectionEvent = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DoMouseOperation(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
if (Tree.SelectionMode == TreeSelectionMode.Single || Tree.SelectionStart == null)
|
||||
{
|
||||
base.DoMouseOperation(args);
|
||||
}
|
||||
else if (CanSelect(args.Node))
|
||||
{
|
||||
Tree.SuspendSelectionEvent = true;
|
||||
try
|
||||
{
|
||||
SelectAllFromStart(args.Node);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Tree.SuspendSelectionEvent = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void MouseDownAtEmptySpace(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
private void SelectAllFromStart(TreeNodeAdv node)
|
||||
{
|
||||
Tree.ClearSelectionInternal();
|
||||
int a = node.Row;
|
||||
int b = Tree.SelectionStart.Row;
|
||||
for (int i = Math.Min(a, b); i <= Math.Max(a, b); i++)
|
||||
{
|
||||
if (Tree.SelectionMode == TreeSelectionMode.Multi || Tree.RowMap[i].Parent == node.Parent)
|
||||
Tree.RowMap[i].IsSelected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Aga.Controls.Tree
|
||||
{
|
||||
internal class NormalInputState : InputState
|
||||
{
|
||||
private bool _mouseDownFlag = false;
|
||||
|
||||
public NormalInputState(TreeViewAdv tree) : base(tree)
|
||||
{
|
||||
}
|
||||
|
||||
public override void KeyDown(KeyEventArgs args)
|
||||
{
|
||||
if (Tree.CurrentNode == null && Tree.Root.Nodes.Count > 0)
|
||||
Tree.CurrentNode = Tree.Root.Nodes[0];
|
||||
|
||||
if (Tree.CurrentNode != null)
|
||||
{
|
||||
switch (args.KeyCode)
|
||||
{
|
||||
case Keys.Right:
|
||||
if (!Tree.CurrentNode.IsExpanded)
|
||||
Tree.CurrentNode.IsExpanded = true;
|
||||
else if (Tree.CurrentNode.Nodes.Count > 0)
|
||||
Tree.SelectedNode = Tree.CurrentNode.Nodes[0];
|
||||
args.Handled = true;
|
||||
break;
|
||||
case Keys.Left:
|
||||
if (Tree.CurrentNode.IsExpanded)
|
||||
Tree.CurrentNode.IsExpanded = false;
|
||||
else if (Tree.CurrentNode.Parent != Tree.Root)
|
||||
Tree.SelectedNode = Tree.CurrentNode.Parent;
|
||||
args.Handled = true;
|
||||
break;
|
||||
case Keys.Down:
|
||||
NavigateForward(1);
|
||||
args.Handled = true;
|
||||
break;
|
||||
case Keys.Up:
|
||||
NavigateBackward(1);
|
||||
args.Handled = true;
|
||||
break;
|
||||
case Keys.PageDown:
|
||||
NavigateForward(Math.Max(1, Tree.CurrentPageSize - 1));
|
||||
args.Handled = true;
|
||||
break;
|
||||
case Keys.PageUp:
|
||||
NavigateBackward(Math.Max(1, Tree.CurrentPageSize - 1));
|
||||
args.Handled = true;
|
||||
break;
|
||||
case Keys.Home:
|
||||
if (Tree.RowMap.Count > 0)
|
||||
FocusRow(Tree.RowMap[0]);
|
||||
args.Handled = true;
|
||||
break;
|
||||
case Keys.End:
|
||||
if (Tree.RowMap.Count > 0)
|
||||
FocusRow(Tree.RowMap[Tree.RowMap.Count-1]);
|
||||
args.Handled = true;
|
||||
break;
|
||||
case Keys.Subtract:
|
||||
Tree.CurrentNode.Collapse();
|
||||
args.Handled = true;
|
||||
args.SuppressKeyPress = true;
|
||||
break;
|
||||
case Keys.Add:
|
||||
Tree.CurrentNode.Expand();
|
||||
args.Handled = true;
|
||||
args.SuppressKeyPress = true;
|
||||
break;
|
||||
case Keys.Multiply:
|
||||
Tree.CurrentNode.ExpandAll();
|
||||
args.Handled = true;
|
||||
args.SuppressKeyPress = true;
|
||||
break;
|
||||
case Keys.A:
|
||||
if (args.Modifiers == Keys.Control)
|
||||
Tree.SelectAllNodes();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void MouseDown(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
if (args.Node != null)
|
||||
{
|
||||
Tree.ItemDragMode = true;
|
||||
Tree.ItemDragStart = args.Location;
|
||||
|
||||
if (args.Button == MouseButtons.Left || args.Button == MouseButtons.Right)
|
||||
{
|
||||
Tree.BeginUpdate();
|
||||
try
|
||||
{
|
||||
Tree.CurrentNode = args.Node;
|
||||
if (args.Node.IsSelected)
|
||||
_mouseDownFlag = true;
|
||||
else
|
||||
{
|
||||
_mouseDownFlag = false;
|
||||
DoMouseOperation(args);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Tree.EndUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Tree.ItemDragMode = false;
|
||||
MouseDownAtEmptySpace(args);
|
||||
}
|
||||
}
|
||||
|
||||
public override void MouseUp(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
Tree.ItemDragMode = false;
|
||||
if (_mouseDownFlag && args.Node != null)
|
||||
{
|
||||
if (args.Button == MouseButtons.Left)
|
||||
DoMouseOperation(args);
|
||||
else if (args.Button == MouseButtons.Right)
|
||||
Tree.CurrentNode = args.Node;
|
||||
}
|
||||
_mouseDownFlag = false;
|
||||
}
|
||||
|
||||
|
||||
private void NavigateBackward(int n)
|
||||
{
|
||||
int row = Math.Max(Tree.CurrentNode.Row - n, 0);
|
||||
if (row != Tree.CurrentNode.Row)
|
||||
FocusRow(Tree.RowMap[row]);
|
||||
}
|
||||
|
||||
private void NavigateForward(int n)
|
||||
{
|
||||
int row = Math.Min(Tree.CurrentNode.Row + n, Tree.RowCount - 1);
|
||||
if (row != Tree.CurrentNode.Row)
|
||||
FocusRow(Tree.RowMap[row]);
|
||||
}
|
||||
|
||||
protected virtual void MouseDownAtEmptySpace(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
Tree.ClearSelection();
|
||||
}
|
||||
|
||||
protected virtual void FocusRow(TreeNodeAdv node)
|
||||
{
|
||||
Tree.SuspendSelectionEvent = true;
|
||||
try
|
||||
{
|
||||
Tree.ClearSelectionInternal();
|
||||
Tree.CurrentNode = node;
|
||||
Tree.SelectionStart = node;
|
||||
node.IsSelected = true;
|
||||
Tree.ScrollTo(node);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Tree.SuspendSelectionEvent = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected bool CanSelect(TreeNodeAdv node)
|
||||
{
|
||||
if (Tree.SelectionMode == TreeSelectionMode.MultiSameParent)
|
||||
{
|
||||
return (Tree.SelectionStart == null || node.Parent == Tree.SelectionStart.Parent);
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void DoMouseOperation(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
if (Tree.SelectedNodes.Count == 1 && args.Node != null && args.Node.IsSelected)
|
||||
return;
|
||||
|
||||
Tree.SuspendSelectionEvent = true;
|
||||
try
|
||||
{
|
||||
Tree.ClearSelectionInternal();
|
||||
if (args.Node != null)
|
||||
args.Node.IsSelected = true;
|
||||
Tree.SelectionStart = args.Node;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Tree.SuspendSelectionEvent = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Aga.Controls.Tree
|
||||
{
|
||||
internal class ReorderColumnState : ColumnState
|
||||
{
|
||||
#region Properties
|
||||
|
||||
private Point _location;
|
||||
public Point Location
|
||||
{
|
||||
get { return _location; }
|
||||
}
|
||||
|
||||
private Bitmap _ghostImage;
|
||||
public Bitmap GhostImage
|
||||
{
|
||||
get { return _ghostImage; }
|
||||
}
|
||||
|
||||
private TreeColumn _dropColumn;
|
||||
public TreeColumn DropColumn
|
||||
{
|
||||
get { return _dropColumn; }
|
||||
}
|
||||
|
||||
private int _dragOffset;
|
||||
public int DragOffset
|
||||
{
|
||||
get { return _dragOffset; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public ReorderColumnState(TreeViewAdv tree, TreeColumn column, Point initialMouseLocation)
|
||||
: base(tree, column)
|
||||
{
|
||||
_location = new Point(initialMouseLocation.X + Tree.OffsetX, 0);
|
||||
_dragOffset = tree.GetColumnX(column) - initialMouseLocation.X;
|
||||
_ghostImage = column.CreateGhostImage(new Rectangle(0, 0, column.Width, tree.ColumnHeaderHeight), tree.Font);
|
||||
}
|
||||
|
||||
public override void KeyDown(KeyEventArgs args)
|
||||
{
|
||||
args.Handled = true;
|
||||
if (args.KeyCode == Keys.Escape)
|
||||
FinishResize();
|
||||
}
|
||||
|
||||
public override void MouseDown(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
public override void MouseUp(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
FinishResize();
|
||||
}
|
||||
|
||||
public override bool MouseMove(MouseEventArgs args)
|
||||
{
|
||||
_dropColumn = null;
|
||||
_location = new Point(args.X + Tree.OffsetX, 0);
|
||||
int x = 0;
|
||||
foreach (TreeColumn c in Tree.Columns)
|
||||
{
|
||||
if (c.IsVisible)
|
||||
{
|
||||
if (_location.X < x + c.Width / 2)
|
||||
{
|
||||
_dropColumn = c;
|
||||
break;
|
||||
}
|
||||
x += c.Width;
|
||||
}
|
||||
}
|
||||
Tree.UpdateHeaders();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void FinishResize()
|
||||
{
|
||||
Tree.ChangeInput();
|
||||
if (Column == DropColumn)
|
||||
Tree.UpdateView();
|
||||
else
|
||||
{
|
||||
Tree.Columns.Remove(Column);
|
||||
if (DropColumn == null)
|
||||
Tree.Columns.Add(Column);
|
||||
else
|
||||
Tree.Columns.Insert(Tree.Columns.IndexOf(DropColumn), Column);
|
||||
|
||||
Tree.OnColumnReordered(Column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Security.Permissions;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Aga.Controls.Tree
|
||||
{
|
||||
internal class ResizeColumnState: ColumnState
|
||||
{
|
||||
private Point _initLocation;
|
||||
private int _initWidth;
|
||||
|
||||
public ResizeColumnState(TreeViewAdv tree, TreeColumn column, Point p)
|
||||
: base(tree, column)
|
||||
{
|
||||
_initLocation = p;
|
||||
_initWidth = column.Width;
|
||||
}
|
||||
|
||||
public override void KeyDown(KeyEventArgs args)
|
||||
{
|
||||
args.Handled = true;
|
||||
if (args.KeyCode == Keys.Escape)
|
||||
FinishResize();
|
||||
}
|
||||
|
||||
public override void MouseDown(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
}
|
||||
|
||||
public override void MouseUp(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
FinishResize();
|
||||
}
|
||||
|
||||
private void FinishResize()
|
||||
{
|
||||
Tree.ChangeInput();
|
||||
Tree.FullUpdate();
|
||||
Tree.OnColumnWidthChanged(Column);
|
||||
}
|
||||
|
||||
public override bool MouseMove(MouseEventArgs args)
|
||||
{
|
||||
Column.Width = _initWidth + args.Location.X - _initLocation.X;
|
||||
Tree.UpdateView();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void MouseDoubleClick(TreeNodeAdvMouseEventArgs args)
|
||||
{
|
||||
Tree.AutoSizeColumn(Column);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user