External/Aga.Controls/Tree/NodeControls/NodeControl.cs
author StephaneLenclud
Thu, 18 Apr 2013 23:25:10 +0200
branchMiniDisplay
changeset 444 9b09e2ee0968
permissions -rw-r--r--
Front View plug-in does not init if no sensor added.
Fixing some format to make strings shorter.
Now trying to start SoundGraphAccess.exe process from same directory.
Packed mode now can display three sensors along with the current time.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 using System.Windows.Forms;
     5 using System.Drawing;
     6 using System.ComponentModel;
     7 
     8 namespace Aga.Controls.Tree.NodeControls
     9 {
    10 	[DesignTimeVisible(false), ToolboxItem(false)]
    11 	public abstract class NodeControl : Component
    12 	{
    13 		#region Properties
    14 
    15 		private TreeViewAdv _parent;
    16 		[Browsable(false)]
    17 		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    18 		public TreeViewAdv Parent
    19 		{
    20 			get { return _parent; }
    21 			set 
    22 			{
    23 				if (value != _parent)
    24 				{
    25 					if (_parent != null)
    26 						_parent.NodeControls.Remove(this);
    27 
    28 					if (value != null)
    29 						value.NodeControls.Add(this);
    30 				}
    31 			}
    32 		}
    33 
    34 		private IToolTipProvider _toolTipProvider;
    35 		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    36 		public IToolTipProvider ToolTipProvider
    37 		{
    38 			get { return _toolTipProvider; }
    39 			set { _toolTipProvider = value; }
    40 		}
    41 
    42 		private TreeColumn _parentColumn;
    43 		public TreeColumn ParentColumn
    44 		{
    45 			get { return _parentColumn; }
    46 			set 
    47 			{ 
    48 				_parentColumn = value; 
    49 				if (_parent != null)
    50 					_parent.FullUpdate();
    51 			}
    52 		}
    53 
    54 		private VerticalAlignment _verticalAlign = VerticalAlignment.Center;
    55 		[DefaultValue(VerticalAlignment.Center)]
    56 		public VerticalAlignment VerticalAlign
    57 		{
    58 			get { return _verticalAlign; }
    59 			set 
    60 			{ 
    61 				_verticalAlign = value;
    62 				if (_parent != null)
    63 					_parent.FullUpdate();
    64 			}
    65 		}
    66 
    67 		private int _leftMargin = 0;
    68 		public int LeftMargin
    69 		{
    70 			get { return _leftMargin; }
    71 			set 
    72 			{
    73 				if (value < 0)
    74 					throw new ArgumentOutOfRangeException();
    75 
    76 				_leftMargin = value;
    77 				if (_parent != null)
    78 					_parent.FullUpdate();
    79 			}
    80 		}
    81 		#endregion
    82 
    83 		internal virtual void AssignParent(TreeViewAdv parent)
    84 		{
    85 			_parent = parent;
    86 		}
    87 
    88 		protected virtual Rectangle GetBounds(TreeNodeAdv node, DrawContext context)
    89 		{
    90 			Rectangle r = context.Bounds;
    91 			Size s = GetActualSize(node, context);
    92 			Size bs = new Size(r.Width - LeftMargin, Math.Min(r.Height, s.Height));
    93 			switch (VerticalAlign)
    94 			{
    95 				case VerticalAlignment.Top:
    96 					return new Rectangle(new Point(r.X + LeftMargin, r.Y), bs);
    97 				case VerticalAlignment.Bottom:
    98 					return new Rectangle(new Point(r.X + LeftMargin, r.Bottom - s.Height), bs);
    99 				default:
   100 					return new Rectangle(new Point(r.X + LeftMargin, r.Y + (r.Height - s.Height) / 2), bs);
   101 			}
   102 		}
   103 
   104 		protected void CheckThread()
   105 		{
   106 			if (Parent != null && Control.CheckForIllegalCrossThreadCalls)
   107 				if (Parent.InvokeRequired)
   108 					throw new InvalidOperationException("Cross-thread calls are not allowed");
   109 		}
   110 
   111 		public bool IsVisible(TreeNodeAdv node)
   112 		{
   113 			NodeControlValueEventArgs args = new NodeControlValueEventArgs(node);
   114 			args.Value = true;
   115 			OnIsVisibleValueNeeded(args);
   116 			return Convert.ToBoolean(args.Value);
   117 		}
   118 
   119 		internal Size GetActualSize(TreeNodeAdv node, DrawContext context)
   120 		{
   121 			if (IsVisible(node))
   122 			{
   123 				Size s = MeasureSize(node, context);
   124 				return new Size(s.Width + LeftMargin, s.Height);
   125 			}
   126 			else
   127 				return Size.Empty;
   128 		}
   129 
   130 		public abstract Size MeasureSize(TreeNodeAdv node, DrawContext context);
   131 
   132 		public abstract void Draw(TreeNodeAdv node, DrawContext context);
   133 
   134 		public virtual string GetToolTip(TreeNodeAdv node)
   135 		{
   136 			if (ToolTipProvider != null)
   137 				return ToolTipProvider.GetToolTip(node, this);
   138 			else
   139 				return string.Empty;
   140 		}
   141 
   142 		public virtual void MouseDown(TreeNodeAdvMouseEventArgs args)
   143 		{
   144 		}
   145 
   146 		public virtual void MouseUp(TreeNodeAdvMouseEventArgs args)
   147 		{
   148 		}
   149 
   150 		public virtual void MouseDoubleClick(TreeNodeAdvMouseEventArgs args)
   151 		{
   152 		}
   153 
   154 		public virtual void KeyDown(KeyEventArgs args)
   155 		{
   156 		}
   157 
   158 		public virtual void KeyUp(KeyEventArgs args)
   159 		{
   160 		}
   161 
   162 		public event EventHandler<NodeControlValueEventArgs> IsVisibleValueNeeded;
   163 		protected virtual void OnIsVisibleValueNeeded(NodeControlValueEventArgs args)
   164 		{
   165 			if (IsVisibleValueNeeded != null)
   166 				IsVisibleValueNeeded(this, args);
   167 		}
   168 	}
   169 }