in src/XmlNotepad/TreeView.cs [1514:1587]
internal void Draw(Graphics g, Font f, Pen pen, LineStates state, int lineHeight, int indent, int x, int y, ref Size imgSize, Image img, bool selected)
{
int startX = x;
Debug.Assert(this._view != null);
for (int i = 0; i < state.Depth; i++)
{
LineState ls = state[i];
int x2 = x + (imgSize.Width / 2);
int x3 = x + indent;
int y2 = y + lineHeight / 2;
int y3 = y + lineHeight;
bool leaf = i + 1 == state.Depth;
if (leaf)
{
g.DrawLine(pen, x2, y2, x3, y2); // horizontal bar
}
if ((ls & LineState.Last) == LineState.Last)
{
if (((ls & LineState.HasParent) == LineState.HasParent ||
((ls & LineState.First) == 0 && (ls & LineState.Last) == LineState.Last)) && leaf)
{
g.DrawLine(pen, x2, y, x2, y2); // half vertical bar connecting to parent.
}
}
else if ((ls & LineState.HasParent) == LineState.HasParent || ((ls & LineState.First) == 0))
{
g.DrawLine(pen, x2, y, x2, y3); // full vertical bar
}
else if ((ls & LineState.First) == LineState.First)
{ // we know it's also not the last, so
g.DrawLine(pen, x2, y2, x2, y3); // half vertical bar connecting to next child.
}
x += indent;
}
// draw +/- box
// draw node image.
int imgWidth = imgSize.Width;
int imgHeight = imgSize.Height;
if (img != null)
{
int iy = y;
if (imgHeight < lineHeight)
{
iy += (lineHeight - imgHeight) / 2; // center it
}
Rectangle rect = new Rectangle(x, iy, imgWidth, imgHeight);
g.DrawImage(img, rect);
}
string text = this.Label;
if (text != null && _view != null)
{
Brush brush;
if (selected && _view.IsEditing)
{
return;
}
if (selected && _view.Focused)
{
brush = Brushes.HighlightTextBrush(this.ForeColor);
g.FillRectangle(SystemBrushes.Highlight, this._labelBounds);
}
else
{
brush = new SolidBrush(this.ForeColor);
}
Layout(g, f, lineHeight, startX, indent, state.Depth, y, imgSize);
g.DrawString(text, f, brush, this._labelBounds.Left, this._labelBounds.Top, StringFormat.GenericTypographic);
brush.Dispose();
}
}