2009-06-16 Carlos Alberto Cortez <calberto.cortez@gmail.com>
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Tue, 16 Jun 2009 15:15:29 +0000 (15:15 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Tue, 16 Jun 2009 15:15:29 +0000 (15:15 -0000)
* ToolBar.cs: Expose as internal the code used to show a dropdown menu.
* PrintPreviewDialog.cs: Handle the down/up arrow keys for our
DropDown element.
Fixes #509152.

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

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/PrintPreviewDialog.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolBar.cs

index 7228bf0d74a3b912172fcbd39ce94c11847c7755..1c70c4ceea0b2e0708b70321fea1ec9f169d28cb 100644 (file)
@@ -1,3 +1,10 @@
+2009-06-16  Carlos Alberto Cortez <calberto.cortez@gmail.com>
+
+       * ToolBar.cs: Expose as internal the code used to show a dropdown menu.
+       * PrintPreviewDialog.cs: Handle the down/up arrow keys for our
+       DropDown element.
+       Fixes #509152.
+
 2009-06-16  Ivan N. Zlatev  <contact@i-nz.net>
 
        * DataGridView.cs: Scrolling fixes.
index de75aca98a6d179d2d046f45745a1193b6f97e8d..9956ed8695db58cfa4b87530860fc03454919241 100644 (file)
@@ -207,6 +207,9 @@ namespace System.Windows.Forms {
 
                class PrintToolBar : ToolBar
                {
+                       bool dropdownmenu_visible;
+                       ContextMenu dropdownmenu;
+
                        public int GetNext (int pos)
                        {
                                // Select the next button that is *not* a separator
@@ -287,7 +290,24 @@ namespace System.Windows.Forms {
                                switch (key) {
                                        case Keys.Up:
                                        case Keys.Down:
-                                               return true; // Ignore.
+                                               // We know that this toolbar only has one DropDownButton
+                                               if (CurrentItem != -1 && items [CurrentItem].Button.Style == ToolBarButtonStyle.DropDownButton) {
+                                                       if (dropdownmenu == null) {
+                                                               dropdownmenu = (ContextMenu)(items [CurrentItem].Button.DropDownMenu);
+#if NET_2_0
+                                                               dropdownmenu.Collapse += new EventHandler (OnDropDownMenuCollapse);
+#endif
+                                                       }
+
+                                                       if (!dropdownmenu_visible) {
+                                                               items [CurrentItem].DDPressed = dropdownmenu_visible = true;
+                                                               items [CurrentItem].Invalidate ();
+
+                                                               ShowDropDownMenu (items [CurrentItem]);
+                                                       } else
+                                                               dropdownmenu.ProcessCmdKey (ref msg, key);
+                                               }
+                                               return true;
                                        case Keys.Left:
                                        case Keys.Right:
                                        case Keys.Tab:
@@ -297,6 +317,13 @@ namespace System.Windows.Forms {
 
                                return base.InternalPreProcessMessage (ref msg);
                        }
+
+#if NET_2_0
+                       void OnDropDownMenuCollapse (object o, EventArgs args)
+                       {
+                               dropdownmenu_visible = false;
+                       }
+#endif
                }
 
                void CloseButtonClicked (object sender, EventArgs e)
index d474d57db4aa08fa1e2e9df5062ede3ae7212478..53167fe0fb6b788e0d4caa5562cc868b015ff13c 100644 (file)
@@ -580,10 +580,13 @@ namespace System.Windows.Forms
                        if (e.Button.DropDownMenu == null)
                                return;
 
-                       ToolBarItem item = current_item;
+                       ShowDropDownMenu (current_item);
+               }
 
+               internal void ShowDropDownMenu (ToolBarItem item)
+               {
                        Point loc = new Point (item.Rectangle.X + 1, item.Rectangle.Bottom + 1);
-                       ((ContextMenu) e.Button.DropDownMenu).Show (this, loc);
+                       ((ContextMenu) item.Button.DropDownMenu).Show (this, loc);
 
                        item.DDPressed = false;
                        item.Hilight = false;