* TreeView.cs: Draw checkmarks, handle detecting check mark clicks
authorJackson Harper <jackson@novell.com>
Sun, 2 Jan 2005 23:41:01 +0000 (23:41 -0000)
committerJackson Harper <jackson@novell.com>
Sun, 2 Jan 2005 23:41:01 +0000 (23:41 -0000)
* TreeNode.cs: Add a bounding box for the checkbox, refresh the
tree when a check is changed. TODO: Only refresh the checked node.

svn path=/trunk/mcs/; revision=38243

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNode.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeView.cs

index 5bf530d4d8c08e325bdf33733310857e930a57a9..02e81b83e3869554e619be3903f6b7e4bd268d2e 100644 (file)
@@ -1,3 +1,9 @@
+2005-01-02  Jackson Harper  <jackson@ximian.com>
+
+       * TreeView.cs: Draw checkmarks, handle detecting check mark clicks
+       * TreeNode.cs: Add a bounding box for the checkbox, refresh the
+       tree when a check is changed. TODO: Only refresh the checked node.
+
 2004-12-30  Jackson Harper  <jackson@ximian.com>
 
        * TreeView.cs: Draw checkbox boxes when checkboxes are enabled.
index efc72b16b41f3401a8af5c35e235bdb9c748628d..5b76d5ad7c74bdb804ae782e7679618a8e583a06 100644 (file)
@@ -43,7 +43,8 @@ namespace System.Windows.Forms {
                
                private bool is_expanded = true;
                private Rectangle bounds = Rectangle.Empty;
-               internal Rectangle plus_minus_bounds = Rectangle.Empty;
+               private Rectangle plus_minus_bounds = Rectangle.Empty;
+               private Rectangle checkbox_bounds = Rectangle.Empty;
                private bool check;
                internal OwnerDrawPropertyBag prop_bag;
 
@@ -144,9 +145,21 @@ namespace System.Windows.Forms {
                        get { return plus_minus_bounds; }
                }
 
+               internal Rectangle CheckBoxBounds {
+                       get { return checkbox_bounds; }
+               }
+
                public bool Checked {
                        get { return check; }
-                       set { check = value; }
+                       set {
+                               if (check == value)
+                                       return;
+                               check = value;
+
+                               // We should just be invalidating the node
+                               if (TreeView != null)
+                                       tree_view.Refresh ();
+                       }
                }
 
                public Color BackColor {
@@ -428,6 +441,14 @@ namespace System.Windows.Forms {
                        plus_minus_bounds.Height = height;
                }
 
+               internal void UpdateCheckBoxBounds (int x, int y, int width, int height)
+               {
+                       checkbox_bounds.X = x;
+                       checkbox_bounds.Y = y;
+                       checkbox_bounds.Width = width;
+                       checkbox_bounds.Height = height;
+               }
+
                internal void SetAddedData (TreeView tree_view, TreeNode parent, int index)
                {
                        this.tree_view = tree_view;
index 5917b5709900413688e8677b3002cd1033a6dbd3..9d6830266e68ee82baf15edf51c98ea7c10e4d66 100644 (file)
@@ -602,7 +602,7 @@ namespace System.Windows.Forms {
                {
                        node.UpdatePlusMinusBounds (x, middle - 4, 8, 8);
 
-                       DeviceContext.DrawRectangle (SystemPens.ControlDark, node.plus_minus_bounds);
+                       DeviceContext.DrawRectangle (SystemPens.ControlDark, node.PlusMinusBounds);
 
                        if (node.IsExpanded) {
                                DeviceContext.DrawLine (SystemPens.ControlDarkDark, x + 2, middle, x + 6, middle); 
@@ -615,7 +615,20 @@ namespace System.Windows.Forms {
                private void DrawNodeCheckBox (TreeNode node, int x, int y)
                {
                        int offset = (ItemHeight - 10) / 2;
-                       DeviceContext.DrawRectangle (new Pen (Color.Black, 2), x + 0.5F + 3, y + 0.5F + offset, 10, 10);
+
+                       node.UpdateCheckBoxBounds (x + 3, y + offset, 10, 10);
+
+                       DeviceContext.DrawRectangle (new Pen (Color.Black, 2), x + 0.5F + 3, y + 0.5F + offset, 11, 11);
+
+                       if (node.Checked) {
+                               Pen check_pen = new Pen (Color.Black, 1);
+
+                               DeviceContext.DrawLine (check_pen, x + 6, y + offset + 5, x + 8, y + offset + 8);
+                               DeviceContext.DrawLine (check_pen, x + 6, y + offset + 6, x + 8, y + offset + 9);
+
+                               DeviceContext.DrawLine (check_pen, x + 7, y + offset + 8, x + 13, y + offset + 3);
+                               DeviceContext.DrawLine (check_pen, x + 7, y + offset + 9, x + 13, y + offset + 4);
+                       }
                }
 
                private void DrawNodeLines (TreeNode node, Pen dash, int x, int y, int middle, int item_height, int node_count)
@@ -829,6 +842,10 @@ namespace System.Windows.Forms {
                                        node.Toggle ();
                                        break;
                                }
+                               if (node.CheckBoxBounds.Contains (e.X, e.Y)) {
+                                       node.Checked = !node.Checked;
+                                       break;
+                               }
                        }
                }