External/Aga.Controls/Tree/Input/ReorderColumnState.cs
changeset 345 0c551e8818e0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/External/Aga.Controls/Tree/Input/ReorderColumnState.cs	Sun May 27 15:16:19 2012 +0000
     1.3 @@ -0,0 +1,101 @@
     1.4 +using System;
     1.5 +using System.Collections.Generic;
     1.6 +using System.Text;
     1.7 +using System.Drawing;
     1.8 +using System.Windows.Forms;
     1.9 +
    1.10 +namespace Aga.Controls.Tree
    1.11 +{
    1.12 +	internal class ReorderColumnState : ColumnState
    1.13 +	{
    1.14 +		#region Properties
    1.15 +
    1.16 +		private Point _location;
    1.17 +		public Point Location
    1.18 +		{
    1.19 +			get { return _location; }
    1.20 +		}
    1.21 +
    1.22 +		private Bitmap _ghostImage;
    1.23 +		public Bitmap GhostImage
    1.24 +		{
    1.25 +			get { return _ghostImage; }
    1.26 +		}
    1.27 +
    1.28 +		private TreeColumn _dropColumn;
    1.29 +		public TreeColumn DropColumn
    1.30 +		{
    1.31 +			get { return _dropColumn; }
    1.32 +		}
    1.33 +
    1.34 +		private int _dragOffset;
    1.35 +		public int DragOffset
    1.36 +		{
    1.37 +			get { return _dragOffset; }
    1.38 +		}
    1.39 +
    1.40 +		#endregion
    1.41 +
    1.42 +		public ReorderColumnState(TreeViewAdv tree, TreeColumn column, Point initialMouseLocation)
    1.43 +			: base(tree, column)
    1.44 +		{
    1.45 +			_location = new Point(initialMouseLocation.X + Tree.OffsetX, 0);
    1.46 +			_dragOffset = tree.GetColumnX(column) - initialMouseLocation.X;
    1.47 +			_ghostImage = column.CreateGhostImage(new Rectangle(0, 0, column.Width, tree.ColumnHeaderHeight), tree.Font);
    1.48 +		}
    1.49 +
    1.50 +		public override void KeyDown(KeyEventArgs args)
    1.51 +		{
    1.52 +			args.Handled = true;
    1.53 +			if (args.KeyCode == Keys.Escape)
    1.54 +				FinishResize();
    1.55 +		}
    1.56 +
    1.57 +		public override void MouseDown(TreeNodeAdvMouseEventArgs args)
    1.58 +		{
    1.59 +		}
    1.60 +
    1.61 +		public override void MouseUp(TreeNodeAdvMouseEventArgs args)
    1.62 +		{
    1.63 +			FinishResize();
    1.64 +		}
    1.65 +
    1.66 +		public override bool MouseMove(MouseEventArgs args)
    1.67 +		{
    1.68 +			_dropColumn = null;
    1.69 +			_location = new Point(args.X + Tree.OffsetX, 0);
    1.70 +			int x = 0;
    1.71 +			foreach (TreeColumn c in Tree.Columns)
    1.72 +			{
    1.73 +				if (c.IsVisible)
    1.74 +				{
    1.75 +					if (_location.X < x + c.Width / 2)
    1.76 +					{
    1.77 +						_dropColumn = c;
    1.78 +						break;
    1.79 +					}
    1.80 +					x += c.Width;
    1.81 +				}
    1.82 +			}
    1.83 +			Tree.UpdateHeaders();
    1.84 +			return true;
    1.85 +		}
    1.86 +
    1.87 +		private void FinishResize()
    1.88 +		{
    1.89 +			Tree.ChangeInput();
    1.90 +			if (Column == DropColumn)
    1.91 +				Tree.UpdateView();
    1.92 +			else
    1.93 +			{
    1.94 +				Tree.Columns.Remove(Column);
    1.95 +				if (DropColumn == null)
    1.96 +					Tree.Columns.Add(Column);
    1.97 +				else
    1.98 +					Tree.Columns.Insert(Tree.Columns.IndexOf(DropColumn), Column);
    1.99 +
   1.100 +				Tree.OnColumnReordered(Column);
   1.101 +			}
   1.102 +		}
   1.103 +	}
   1.104 +}
   1.105 \ No newline at end of file