External/Aga.Controls/Tree/NodeControls/NodePlusMinus.cs
author moel.mich
Sun, 27 May 2012 16:08:54 +0000
changeset 346 f652ab1e06e2
permissions -rw-r--r--
Added the small modifications to the Aga.Controls required by the Open Hardware Monitor.
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 Aga.Controls.Properties;
moel@345
     6
using System.Windows.Forms;
moel@345
     7
using System.Windows.Forms.VisualStyles;
moel@345
     8
moel@345
     9
namespace Aga.Controls.Tree.NodeControls
moel@345
    10
{
moel@345
    11
	internal class NodePlusMinus : NodeControl
moel@345
    12
	{
moel@345
    13
		public const int ImageSize = 9;
moel@345
    14
		public const int Width = 16;
moel@345
    15
		private Bitmap _plus;
moel@345
    16
		private Bitmap _minus;
moel@345
    17
moel@345
    18
		private VisualStyleRenderer _openedRenderer;
moel@345
    19
		private VisualStyleRenderer OpenedRenderer
moel@345
    20
		{
moel@345
    21
			get
moel@345
    22
			{
moel@345
    23
				if (_openedRenderer == null)
moel@345
    24
					_openedRenderer = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened);
moel@345
    25
				return _openedRenderer;
moel@345
    26
moel@345
    27
			}
moel@345
    28
		}
moel@345
    29
moel@345
    30
		private VisualStyleRenderer _closedRenderer;
moel@345
    31
		private VisualStyleRenderer ClosedRenderer
moel@345
    32
		{
moel@345
    33
			get
moel@345
    34
			{
moel@345
    35
				if (_closedRenderer == null)
moel@345
    36
					_closedRenderer = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Closed);
moel@345
    37
				return _closedRenderer;
moel@345
    38
			}
moel@345
    39
		}
moel@345
    40
moel@345
    41
		public NodePlusMinus()
moel@345
    42
		{
moel@345
    43
			_plus = Resources.plus;
moel@345
    44
			_minus = Resources.minus;
moel@345
    45
		}
moel@345
    46
moel@345
    47
		public override Size MeasureSize(TreeNodeAdv node, DrawContext context)
moel@345
    48
		{
moel@345
    49
			return new Size(Width, Width);
moel@345
    50
		}
moel@345
    51
moel@345
    52
		public override void Draw(TreeNodeAdv node, DrawContext context)
moel@345
    53
		{
moel@345
    54
			if (node.CanExpand)
moel@345
    55
			{
moel@345
    56
				Rectangle r = context.Bounds;
moel@345
    57
				int dy = (int)Math.Round((float)(r.Height - ImageSize) / 2);
moel@345
    58
				if (Application.RenderWithVisualStyles)
moel@345
    59
				{
moel@345
    60
					VisualStyleRenderer renderer;
moel@345
    61
					if (node.IsExpanded)
moel@345
    62
						renderer = OpenedRenderer;
moel@345
    63
					else
moel@345
    64
						renderer = ClosedRenderer;
moel@345
    65
					renderer.DrawBackground(context.Graphics, new Rectangle(r.X, r.Y + dy, ImageSize, ImageSize));
moel@345
    66
				}
moel@345
    67
				else
moel@345
    68
				{
moel@345
    69
					Image img;
moel@345
    70
					if (node.IsExpanded)
moel@345
    71
						img = _minus;
moel@345
    72
					else
moel@345
    73
						img = _plus;
moel@345
    74
					context.Graphics.DrawImageUnscaled(img, new Point(r.X, r.Y + dy));
moel@345
    75
				}
moel@345
    76
			}
moel@345
    77
		}
moel@345
    78
moel@345
    79
		public override void MouseDown(TreeNodeAdvMouseEventArgs args)
moel@345
    80
		{
moel@345
    81
			if (args.Button == MouseButtons.Left)
moel@345
    82
			{
moel@345
    83
				args.Handled = true;
moel@345
    84
				if (args.Node.CanExpand)
moel@345
    85
					args.Node.IsExpanded = !args.Node.IsExpanded;
moel@345
    86
			}
moel@345
    87
		}
moel@345
    88
moel@345
    89
		public override void MouseDoubleClick(TreeNodeAdvMouseEventArgs args)
moel@345
    90
		{
moel@345
    91
			args.Handled = true; // Supress expand/collapse when double click on plus/minus
moel@345
    92
		}
moel@345
    93
	}
moel@345
    94
}