External/Aga.Controls/Tree/Input/ReorderColumnState.cs
author StephaneLenclud
Sun, 03 Feb 2013 18:01:50 +0100
branchMiniDisplay
changeset 433 090259cfd699
permissions -rw-r--r--
Adding SoundGraphDisplay and SensorFrontView classes.
They were respectively based on SystemTray and SensorNotifyIcon.
SoundGraphDisplay is now able to load iMONDisplay.dll providing it lives on your PATH.
Adding option to sensor context menu for adding it into FrontView.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 using System.Drawing;
     5 using System.Windows.Forms;
     6 
     7 namespace Aga.Controls.Tree
     8 {
     9 	internal class ReorderColumnState : ColumnState
    10 	{
    11 		#region Properties
    12 
    13 		private Point _location;
    14 		public Point Location
    15 		{
    16 			get { return _location; }
    17 		}
    18 
    19 		private Bitmap _ghostImage;
    20 		public Bitmap GhostImage
    21 		{
    22 			get { return _ghostImage; }
    23 		}
    24 
    25 		private TreeColumn _dropColumn;
    26 		public TreeColumn DropColumn
    27 		{
    28 			get { return _dropColumn; }
    29 		}
    30 
    31 		private int _dragOffset;
    32 		public int DragOffset
    33 		{
    34 			get { return _dragOffset; }
    35 		}
    36 
    37 		#endregion
    38 
    39 		public ReorderColumnState(TreeViewAdv tree, TreeColumn column, Point initialMouseLocation)
    40 			: base(tree, column)
    41 		{
    42 			_location = new Point(initialMouseLocation.X + Tree.OffsetX, 0);
    43 			_dragOffset = tree.GetColumnX(column) - initialMouseLocation.X;
    44 			_ghostImage = column.CreateGhostImage(new Rectangle(0, 0, column.Width, tree.ColumnHeaderHeight), tree.Font);
    45 		}
    46 
    47 		public override void KeyDown(KeyEventArgs args)
    48 		{
    49 			args.Handled = true;
    50 			if (args.KeyCode == Keys.Escape)
    51 				FinishResize();
    52 		}
    53 
    54 		public override void MouseDown(TreeNodeAdvMouseEventArgs args)
    55 		{
    56 		}
    57 
    58 		public override void MouseUp(TreeNodeAdvMouseEventArgs args)
    59 		{
    60 			FinishResize();
    61 		}
    62 
    63 		public override bool MouseMove(MouseEventArgs args)
    64 		{
    65 			_dropColumn = null;
    66 			_location = new Point(args.X + Tree.OffsetX, 0);
    67 			int x = 0;
    68 			foreach (TreeColumn c in Tree.Columns)
    69 			{
    70 				if (c.IsVisible)
    71 				{
    72 					if (_location.X < x + c.Width / 2)
    73 					{
    74 						_dropColumn = c;
    75 						break;
    76 					}
    77 					x += c.Width;
    78 				}
    79 			}
    80 			Tree.UpdateHeaders();
    81 			return true;
    82 		}
    83 
    84 		private void FinishResize()
    85 		{
    86 			Tree.ChangeInput();
    87 			if (Column == DropColumn)
    88 				Tree.UpdateView();
    89 			else
    90 			{
    91 				Tree.Columns.Remove(Column);
    92 				if (DropColumn == null)
    93 					Tree.Columns.Add(Column);
    94 				else
    95 					Tree.Columns.Insert(Tree.Columns.IndexOf(DropColumn), Column);
    96 
    97 				Tree.OnColumnReordered(Column);
    98 			}
    99 		}
   100 	}
   101 }