External/Aga.Controls/Tree/NodeControls/NodePlusMinus.cs
author moel.mich
Sun, 23 Sep 2012 18:37:43 +0000
changeset 380 573f1fff48b2
permissions -rw-r--r--
Fixed Issue 387. The new implementation does not try to start a ring 0 driver that already exists, but could not be opened. It tries to delete the driver and install it new. The driver is now stored temporarily in the application folder. The driver is not correctly removed on system shutdown.
     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 }