1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/External/Aga.Controls/Tree/NodeControls/NodePlusMinus.cs Sun May 27 15:16:19 2012 +0000
1.3 @@ -0,0 +1,94 @@
1.4 +using System;
1.5 +using System.Collections.Generic;
1.6 +using System.Text;
1.7 +using System.Drawing;
1.8 +using Aga.Controls.Properties;
1.9 +using System.Windows.Forms;
1.10 +using System.Windows.Forms.VisualStyles;
1.11 +
1.12 +namespace Aga.Controls.Tree.NodeControls
1.13 +{
1.14 + internal class NodePlusMinus : NodeControl
1.15 + {
1.16 + public const int ImageSize = 9;
1.17 + public const int Width = 16;
1.18 + private Bitmap _plus;
1.19 + private Bitmap _minus;
1.20 +
1.21 + private VisualStyleRenderer _openedRenderer;
1.22 + private VisualStyleRenderer OpenedRenderer
1.23 + {
1.24 + get
1.25 + {
1.26 + if (_openedRenderer == null)
1.27 + _openedRenderer = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened);
1.28 + return _openedRenderer;
1.29 +
1.30 + }
1.31 + }
1.32 +
1.33 + private VisualStyleRenderer _closedRenderer;
1.34 + private VisualStyleRenderer ClosedRenderer
1.35 + {
1.36 + get
1.37 + {
1.38 + if (_closedRenderer == null)
1.39 + _closedRenderer = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Closed);
1.40 + return _closedRenderer;
1.41 + }
1.42 + }
1.43 +
1.44 + public NodePlusMinus()
1.45 + {
1.46 + _plus = Resources.plus;
1.47 + _minus = Resources.minus;
1.48 + }
1.49 +
1.50 + public override Size MeasureSize(TreeNodeAdv node, DrawContext context)
1.51 + {
1.52 + return new Size(Width, Width);
1.53 + }
1.54 +
1.55 + public override void Draw(TreeNodeAdv node, DrawContext context)
1.56 + {
1.57 + if (node.CanExpand)
1.58 + {
1.59 + Rectangle r = context.Bounds;
1.60 + int dy = (int)Math.Round((float)(r.Height - ImageSize) / 2);
1.61 + if (Application.RenderWithVisualStyles)
1.62 + {
1.63 + VisualStyleRenderer renderer;
1.64 + if (node.IsExpanded)
1.65 + renderer = OpenedRenderer;
1.66 + else
1.67 + renderer = ClosedRenderer;
1.68 + renderer.DrawBackground(context.Graphics, new Rectangle(r.X, r.Y + dy, ImageSize, ImageSize));
1.69 + }
1.70 + else
1.71 + {
1.72 + Image img;
1.73 + if (node.IsExpanded)
1.74 + img = _minus;
1.75 + else
1.76 + img = _plus;
1.77 + context.Graphics.DrawImageUnscaled(img, new Point(r.X, r.Y + dy));
1.78 + }
1.79 + }
1.80 + }
1.81 +
1.82 + public override void MouseDown(TreeNodeAdvMouseEventArgs args)
1.83 + {
1.84 + if (args.Button == MouseButtons.Left)
1.85 + {
1.86 + args.Handled = true;
1.87 + if (args.Node.CanExpand)
1.88 + args.Node.IsExpanded = !args.Node.IsExpanded;
1.89 + }
1.90 + }
1.91 +
1.92 + public override void MouseDoubleClick(TreeNodeAdvMouseEventArgs args)
1.93 + {
1.94 + args.Handled = true; // Supress expand/collapse when double click on plus/minus
1.95 + }
1.96 + }
1.97 +}