moel@345: using System; moel@345: using System.Collections.Generic; moel@345: using System.Text; moel@345: using System.Drawing; moel@345: using Aga.Controls.Properties; moel@345: using System.Windows.Forms; moel@345: using System.Windows.Forms.VisualStyles; moel@345: moel@345: namespace Aga.Controls.Tree.NodeControls moel@345: { moel@345: internal class NodePlusMinus : NodeControl moel@345: { moel@345: public const int ImageSize = 9; moel@345: public const int Width = 16; moel@345: private Bitmap _plus; moel@345: private Bitmap _minus; moel@345: moel@345: private VisualStyleRenderer _openedRenderer; moel@345: private VisualStyleRenderer OpenedRenderer moel@345: { moel@345: get moel@345: { moel@345: if (_openedRenderer == null) moel@345: _openedRenderer = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened); moel@345: return _openedRenderer; moel@345: moel@345: } moel@345: } moel@345: moel@345: private VisualStyleRenderer _closedRenderer; moel@345: private VisualStyleRenderer ClosedRenderer moel@345: { moel@345: get moel@345: { moel@345: if (_closedRenderer == null) moel@345: _closedRenderer = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Closed); moel@345: return _closedRenderer; moel@345: } moel@345: } moel@345: moel@345: public NodePlusMinus() moel@345: { moel@345: _plus = Resources.plus; moel@345: _minus = Resources.minus; moel@345: } moel@345: moel@345: public override Size MeasureSize(TreeNodeAdv node, DrawContext context) moel@345: { moel@345: return new Size(Width, Width); moel@345: } moel@345: moel@345: public override void Draw(TreeNodeAdv node, DrawContext context) moel@345: { moel@345: if (node.CanExpand) moel@345: { moel@345: Rectangle r = context.Bounds; moel@345: int dy = (int)Math.Round((float)(r.Height - ImageSize) / 2); moel@345: if (Application.RenderWithVisualStyles) moel@345: { moel@345: VisualStyleRenderer renderer; moel@345: if (node.IsExpanded) moel@345: renderer = OpenedRenderer; moel@345: else moel@345: renderer = ClosedRenderer; moel@345: renderer.DrawBackground(context.Graphics, new Rectangle(r.X, r.Y + dy, ImageSize, ImageSize)); moel@345: } moel@345: else moel@345: { moel@345: Image img; moel@345: if (node.IsExpanded) moel@345: img = _minus; moel@345: else moel@345: img = _plus; moel@345: context.Graphics.DrawImageUnscaled(img, new Point(r.X, r.Y + dy)); moel@345: } moel@345: } moel@345: } moel@345: moel@345: public override void MouseDown(TreeNodeAdvMouseEventArgs args) moel@345: { moel@345: if (args.Button == MouseButtons.Left) moel@345: { moel@345: args.Handled = true; moel@345: if (args.Node.CanExpand) moel@345: args.Node.IsExpanded = !args.Node.IsExpanded; moel@345: } moel@345: } moel@345: moel@345: public override void MouseDoubleClick(TreeNodeAdvMouseEventArgs args) moel@345: { moel@345: args.Handled = true; // Supress expand/collapse when double click on plus/minus moel@345: } moel@345: } moel@345: }