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