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