Author: jpobst
Date: 2007-07-20 15:56:23 -0400 (Fri, 20 Jul 2007)
New Revision: 82386

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNode.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeView.cs
Log:
2007-07-20  Jonathan Pobst  <[EMAIL PROTECTED]>

        * TreeNode.cs: Implement ContextMenu, ContextMenuStrip, and Level.
        * TreeView.cs: Use the node's contextmenu[strip] if applicable.

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-07-20 19:49:09 UTC (rev 82385)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-07-20 19:56:23 UTC (rev 82386)
@@ -1,3 +1,8 @@
+2007-07-20  Jonathan Pobst  <[EMAIL PROTECTED]>
+
+       * TreeNode.cs: Implement ContextMenu, ContextMenuStrip, and Level.
+       * TreeView.cs: Use the node's contextmenu[strip] if applicable.
+
 2007-07-20  Ivan N. Zlatev  <[EMAIL PROTECTED]>
 
        * Control.cs, Form.cs, ContainerControl.cs,

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNode.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNode.cs      
2007-07-20 19:49:09 UTC (rev 82385)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeNode.cs      
2007-07-20 19:56:23 UTC (rev 82386)
@@ -44,6 +44,8 @@
                private int image_index = -1;
                private int selected_image_index = -1;
 #if NET_2_0
+               private ContextMenu context_menu;
+               private ContextMenuStrip context_menu_strip;
                private string image_key = String.Empty;
                private string selected_image_key = String.Empty;
                private int state_image_index = -1;
@@ -282,6 +284,18 @@
                }
 
 #if NET_2_0
+               [DefaultValue (null)]
+               public virtual ContextMenu ContextMenu {
+                       get { return context_menu; }
+                       set { context_menu = value; }
+               }
+               
+               [DefaultValue (null)]
+               public virtual ContextMenuStrip ContextMenuStrip {
+                       get { return context_menu_strip; }
+                       set { context_menu_strip = value; }
+               }
+               
                [Browsable (false)]
 #endif
                public TreeNode FirstNode {
@@ -446,6 +460,11 @@
                }
 
 #if NET_2_0
+               [Browsable (false)]
+               public int Level {
+                       get { return IndentLevel; }
+               }
+               
                public string Name
                {
                        get { return this.name; }

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeView.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeView.cs      
2007-07-20 19:49:09 UTC (rev 82385)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TreeView.cs      
2007-07-20 19:56:23 UTC (rev 82386)
@@ -1067,6 +1067,13 @@
                                                                2, val & 0xffff,
                                                                (val>>16) & 
0xffff, 0));
                                        break;
+#if NET_2_0
+                               case Msg.WM_CONTEXTMENU:
+                                       if (WmContextMenu (ref m))
+                                               return;
+                                               
+                                       break;
+#endif
                        }
                        base.WndProc (ref m);
                }
@@ -2046,6 +2053,44 @@
                                        (r.Top > top + height) || (r.Bottom < 
top));
                }
 
+#if NET_2_0
+               // Return true if message was handled, false to send it to base
+               private bool WmContextMenu (ref Message m)
+               {
+                       Point pt;
+                       TreeNode tn;
+                       
+                       pt = new Point (LowOrder ((int)m.LParam.ToInt32 ()), 
HighOrder ((int)m.LParam.ToInt32 ()));
+
+                       // This means it's a keyboard menu request
+                       if (pt.X == -1 || pt.Y == -1) {
+                               tn = SelectedNode;
+                               
+                               if (tn == null)
+                                       return false;
+                               
+                               pt = new Point (tn.Bounds.Left, tn.Bounds.Top + 
(tn.Bounds.Height / 2));
+                       } else {
+                               pt = PointToClient (pt);
+                               
+                               tn = GetNodeAt (pt);
+
+                               if (tn == null)
+                                       return false;
+                       }
+                       
+                       // At this point, we have a valid TreeNode
+                       if (tn.ContextMenu != null) {
+                               tn.ContextMenu.Show (this, pt);
+                               return true;
+                       } else if (tn.ContextMenuStrip != null) {
+                               tn.ContextMenuStrip.Show (this, pt);
+                               return true;
+                       }
+                       
+                       return true;
+               }
+#endif
                #endregion      // Internal & Private Methods and Properties
 
                #region Events

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to