Here you go
Chris
Index: System.Windows.Forms/TreeView.cs
===================================================================
--- System.Windows.Forms/TreeView.cs (revision 60710)
+++ System.Windows.Forms/TreeView.cs (working copy)
@@ -893,7 +893,7 @@
}
if (node == root_node) {
- Refresh ();
+ Calc ();
return;
}
@@ -947,6 +947,63 @@
Draw (pe.ClipRectangle, pe.Graphics);
}
+ private void Calc ()
+ {
+ if (top_node == null && Nodes.Count > 0)
+ top_node = nodes [0];
+
+ if (selected_node == null && Nodes.Count > 0)
+ SelectedNode = nodes [0];
+
+ // Decide if we need a scrollbar
+ int old_open_node_count = open_node_count;
+
+ //Rectangle fill = ClientRectangle;
+ add_vscroll = false;
+ add_hscroll = false;
+
+ Color dash_color = ControlPaint.Dark (BackColor);
+ if (dash_color == BackColor)
+ dash_color = ControlPaint.Light (BackColor);
+ dash = new Pen (dash_color, 1);
+ dash.DashStyle = DashStyle.Dot;
+
+ int depth = 0;
+ int item_height = ItemHeight;
+ int height = ClientRectangle.Height;
+
+ open_node_count = 0;
+ used_height = 0;
+ foreach (TreeNode node in nodes) {
+ DrawNode (node, null, ClientRectangle, ref depth, item_height, height, false);
+ depth = 0;
+ }
+
+ add_vscroll = (open_node_count * ItemHeight) > ClientRectangle.Height;
+
+ if (max_node_width > ClientRectangle.Width)
+ add_hscroll = true;
+
+ if (add_vscroll)
+ add_hscroll = max_node_width > ClientRectangle.Width - ThemeEngine.Current.VScrollBarDefaultSize.Width;
+ if (add_hscroll)
+ add_vscroll = (open_node_count * ItemHeight) > ClientRectangle.Height - ThemeEngine.Current.HScrollBarDefaultSize.Height;
+
+ if (add_hscroll) {
+ AddHorizontalScrollBar ();
+ } else if (hbar != null) {
+ hbar_offset = 0;
+ hbar.Visible = false;
+ }
+
+ if (add_vscroll) {
+ AddVerticalScrollBar (open_node_count, old_open_node_count != open_node_count);
+ } else if (vbar != null) {
+ vbar.Visible = false;
+ skipped_nodes = 0;
+ }
+ }
+
private void Draw (Rectangle clip, Graphics dc)
{
if (top_node == null && Nodes.Count > 0)
@@ -977,7 +1034,7 @@
open_node_count = 0;
used_height = 0;
foreach (TreeNode node in nodes) {
- DrawNode (node, dc, clip, ref depth, item_height, height);
+ DrawNode (node, dc, clip, ref depth, item_height, height, true);
depth = 0;
}
@@ -1167,7 +1224,7 @@
node.Bounds, string_format);
}
- private void DrawNode (TreeNode node, Graphics dc, Rectangle clip, ref int depth, int item_height, int max_height)
+ private void DrawNode (TreeNode node, Graphics dc, Rectangle clip, ref int depth, int item_height, int max_height, bool really_draw)
{
open_node_count++;
int x = (!show_root_lines && node.Parent != null ? depth - 1 : depth) * indent - hbar_offset;
@@ -1180,7 +1237,7 @@
if (clip.Top > y + ItemHeight || clip.Bottom < y)
visible = false;
- if (visible && full_row_select) {
+ if (really_draw && visible && full_row_select) {
Rectangle r = new Rectangle(1, y+2, ViewportRectangle.Width-2, item_height);
DrawSelectionAndFocus(node, dc, r);
}
@@ -1188,7 +1245,7 @@
if (show_root_lines || node.Parent != null) {
x += 5;
if (_n_count > 0) {
- if (show_plus_minus && visible) {
+ if (really_draw && show_plus_minus && visible) {
DrawNodePlusMinus (node, dc, x, middle);
}
}
@@ -1198,26 +1255,26 @@
int ox = x;
if (checkboxes) {
- if (visible)
+ if (really_draw && visible)
DrawNodeCheckBox (node, dc, ox, middle);
ox += 19;
}
- if (show_lines)
+ if (really_draw && show_lines)
DrawNodeLines (node, dc, visible, dash, x, y, middle, item_height, _n_count);
if (ImageList != null) {
- if (visible)
- DrawNodeImage (node, dc, clip, ox, y);
+ if (really_draw && visible)
+ DrawNodeImage (node, dc, clip, ox, y);
// MS leaves the space for the image if the ImageList is
// non null regardless of whether or not an image is drawn
ox += ImageList.ImageSize.Width + 3; // leave a little space so the text isn't against the image
}
- UpdateNodeBounds (node, ox, y, item_height, dc);
+ UpdateNodeBounds (node, ox, y, item_height, dc == null ? DeviceContext : dc);
bool bounds_in_clip = clip.IntersectsWith (node.Bounds) || full_row_select;
- if (visible && bounds_in_clip) {
+ if (really_draw && visible && bounds_in_clip) {
if (node.IsEditing)
DrawEditNode (node);
else
@@ -1239,7 +1296,7 @@
if (node.IsExpanded) {
for (int i = 0; i < _n_count; i++) {
int tdepth = depth;
- DrawNode (node.nodes [i], dc, clip, ref tdepth, item_height, max_height);
+ DrawNode (node.nodes [i], dc, clip, ref tdepth, item_height, max_height, really_draw);
}
}
_______________________________________________
Mono-winforms-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-winforms-list