External/Aga.Controls/Tree/Input/ReorderColumnState.cs
author moel.mich
Sun, 27 May 2012 15:16:19 +0000
changeset 345 0c551e8818e0
permissions -rw-r--r--
Added the source code of Aga.Controls (TreeViewAdv for .Net) version 1.7.0.0.
moel@345
     1
using System;
moel@345
     2
using System.Collections.Generic;
moel@345
     3
using System.Text;
moel@345
     4
using System.Drawing;
moel@345
     5
using System.Windows.Forms;
moel@345
     6
moel@345
     7
namespace Aga.Controls.Tree
moel@345
     8
{
moel@345
     9
	internal class ReorderColumnState : ColumnState
moel@345
    10
	{
moel@345
    11
		#region Properties
moel@345
    12
moel@345
    13
		private Point _location;
moel@345
    14
		public Point Location
moel@345
    15
		{
moel@345
    16
			get { return _location; }
moel@345
    17
		}
moel@345
    18
moel@345
    19
		private Bitmap _ghostImage;
moel@345
    20
		public Bitmap GhostImage
moel@345
    21
		{
moel@345
    22
			get { return _ghostImage; }
moel@345
    23
		}
moel@345
    24
moel@345
    25
		private TreeColumn _dropColumn;
moel@345
    26
		public TreeColumn DropColumn
moel@345
    27
		{
moel@345
    28
			get { return _dropColumn; }
moel@345
    29
		}
moel@345
    30
moel@345
    31
		private int _dragOffset;
moel@345
    32
		public int DragOffset
moel@345
    33
		{
moel@345
    34
			get { return _dragOffset; }
moel@345
    35
		}
moel@345
    36
moel@345
    37
		#endregion
moel@345
    38
moel@345
    39
		public ReorderColumnState(TreeViewAdv tree, TreeColumn column, Point initialMouseLocation)
moel@345
    40
			: base(tree, column)
moel@345
    41
		{
moel@345
    42
			_location = new Point(initialMouseLocation.X + Tree.OffsetX, 0);
moel@345
    43
			_dragOffset = tree.GetColumnX(column) - initialMouseLocation.X;
moel@345
    44
			_ghostImage = column.CreateGhostImage(new Rectangle(0, 0, column.Width, tree.ColumnHeaderHeight), tree.Font);
moel@345
    45
		}
moel@345
    46
moel@345
    47
		public override void KeyDown(KeyEventArgs args)
moel@345
    48
		{
moel@345
    49
			args.Handled = true;
moel@345
    50
			if (args.KeyCode == Keys.Escape)
moel@345
    51
				FinishResize();
moel@345
    52
		}
moel@345
    53
moel@345
    54
		public override void MouseDown(TreeNodeAdvMouseEventArgs args)
moel@345
    55
		{
moel@345
    56
		}
moel@345
    57
moel@345
    58
		public override void MouseUp(TreeNodeAdvMouseEventArgs args)
moel@345
    59
		{
moel@345
    60
			FinishResize();
moel@345
    61
		}
moel@345
    62
moel@345
    63
		public override bool MouseMove(MouseEventArgs args)
moel@345
    64
		{
moel@345
    65
			_dropColumn = null;
moel@345
    66
			_location = new Point(args.X + Tree.OffsetX, 0);
moel@345
    67
			int x = 0;
moel@345
    68
			foreach (TreeColumn c in Tree.Columns)
moel@345
    69
			{
moel@345
    70
				if (c.IsVisible)
moel@345
    71
				{
moel@345
    72
					if (_location.X < x + c.Width / 2)
moel@345
    73
					{
moel@345
    74
						_dropColumn = c;
moel@345
    75
						break;
moel@345
    76
					}
moel@345
    77
					x += c.Width;
moel@345
    78
				}
moel@345
    79
			}
moel@345
    80
			Tree.UpdateHeaders();
moel@345
    81
			return true;
moel@345
    82
		}
moel@345
    83
moel@345
    84
		private void FinishResize()
moel@345
    85
		{
moel@345
    86
			Tree.ChangeInput();
moel@345
    87
			if (Column == DropColumn)
moel@345
    88
				Tree.UpdateView();
moel@345
    89
			else
moel@345
    90
			{
moel@345
    91
				Tree.Columns.Remove(Column);
moel@345
    92
				if (DropColumn == null)
moel@345
    93
					Tree.Columns.Add(Column);
moel@345
    94
				else
moel@345
    95
					Tree.Columns.Insert(Tree.Columns.IndexOf(DropColumn), Column);
moel@345
    96
moel@345
    97
				Tree.OnColumnReordered(Column);
moel@345
    98
			}
moel@345
    99
		}
moel@345
   100
	}
moel@345
   101
}