Re: TODO list item: menu selection



On 7 Apr 2000, Owen Taylor wrote:

> 
> David Santiago <mrcooger@cyberverse.com> writes:
> 
> > As I said, this hadn't occurred to me, so I went ahead and redid it like
> > this. The code is much simpler, indeed. I'd much prefer this. However, the
> > problem is that case with the left/right arrow keys. When this method is
> > used, I can't make it respond to this case correctly. How would one go
> > about correcting this? 
> 
> They way I would do this is handle it in the spot where we do the 
> left/right arrow keys:
> 
> .
> .
> .
>
> So, you would change:
> 
> 	    gtk_menu_shell_move_selected (parent_menu_shell, -1);
> 
> To, something like:
>          
>   gtk_menu_shell_move_selected (parent_menu_shell, -1);
> 
>   GtkMenuItem *item = GTK_MENU_ITEM (parent_menu_shell->active_menu_item);
> 
>   if (item->submenu)
>     {
>        GtkMenuShell *submenu = GTK_MENU_SHELL (item->submenu);
>        if (submenu->children)
>          gtk_menu_shell_select_item (submenu, submenu->children->data);
>     }
> 
> The operation of selecting the first child of the active submenu
> probably should be encapsulated in a separate function like
> gtk_menu_shell_select_submenu_first ().

OK, here we go again. I am including my new patch, totally rewritten. It
handles all the cases correctly, and uses the methods you've suggested
(thanks!). The GtkMenuItem structure is unchanged, the code for selecting
menu items got a bit cleaner, and the logic for selecting the first
submenu item was moved to the places where the key presses are handled, in
the menu shell. Hope it's good! 

 Thanks
   David :) 
 
> Regards,
>                                         Owen
> 
> 
> 

Index: gtkmenuitem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenuitem.c,v
retrieving revision 1.37
diff -u -r1.37 gtkmenuitem.c
--- gtkmenuitem.c	1999/11/22 21:52:47	1.37
+++ gtkmenuitem.c	2000/04/07 20:16:32
@@ -63,7 +63,7 @@
 static void gtk_real_menu_item_deselect  (GtkItem          *item);
 static void gtk_real_menu_item_activate_item  (GtkMenuItem      *item);
 static gint gtk_menu_item_select_timeout (gpointer          data);
-static void gtk_menu_item_select_timeout_unlocked (gpointer     data);
+static void gtk_menu_item_popup_submenu  (gpointer     data);
 static void gtk_menu_item_position_menu  (GtkMenu          *menu,
 					  gint             *x,
 					  gint             *y,
@@ -553,7 +553,7 @@
 					    gtk_menu_item_select_timeout,
 					    menu_item);
       else
-	gtk_menu_item_select_timeout_unlocked (menu_item);
+	gtk_menu_item_popup_submenu (menu_item);
       if(event) gdk_event_free(event);
     }
   
@@ -598,6 +598,7 @@
 gtk_real_menu_item_activate_item (GtkMenuItem *menu_item)
 {
   GtkWidget *widget;
+  GtkMenuShell *submenu; 
 
   g_return_if_fail (menu_item != NULL);
   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
@@ -621,7 +622,12 @@
 	      menu_shell->active = TRUE;
 	    }
 
-	  gtk_menu_shell_select_item (GTK_MENU_SHELL (widget->parent), widget);
+	  gtk_menu_shell_select_item (GTK_MENU_SHELL (widget->parent), widget); 
+	  gtk_menu_item_popup_submenu (widget); 
+
+	  submenu = GTK_MENU_SHELL (menu_item->submenu);
+	  if (submenu->children)
+	    gtk_menu_shell_select_item (submenu, submenu->children->data);
 	}
     }
 }
@@ -631,7 +637,7 @@
 {
   GDK_THREADS_ENTER ();
 
-  gtk_menu_item_select_timeout_unlocked (data);
+  gtk_menu_item_popup_submenu (data);
 
   GDK_THREADS_LEAVE ();
 
@@ -639,7 +645,7 @@
 }
 
 static void
-gtk_menu_item_select_timeout_unlocked (gpointer data)
+gtk_menu_item_popup_submenu (gpointer data)
 {
   GtkMenuItem *menu_item;
 
@@ -655,16 +661,6 @@
 		      menu_item,
 		      GTK_MENU_SHELL (GTK_WIDGET (menu_item)->parent)->button,
 		      0);
-      
-      /* This is a bit of a hack - we want to select the first item
-       * of menus hanging of a menu bar, but not for cascading submenus
-       */
-      if (GTK_IS_MENU_BAR (GTK_WIDGET (menu_item)->parent))
-	{
-	  GtkMenuShell *submenu = GTK_MENU_SHELL (menu_item->submenu);
-	  if (submenu->children)
-	    gtk_menu_shell_select_item (submenu, submenu->children->data);
-	}
     }
 }
 
Index: gtkmenushell.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenushell.c,v
retrieving revision 1.30
diff -u -r1.30 gtkmenushell.c
--- gtkmenushell.c	2000/03/14 19:57:24	1.30
+++ gtkmenushell.c	2000/04/07 20:16:35
@@ -136,6 +136,7 @@
 static GtkWidget *gtk_menu_shell_get_item    (GtkMenuShell      *menu_shell,
 					      GdkEvent          *event);
 static GtkType    gtk_menu_shell_child_type  (GtkContainer      *container);
+static void gtk_menu_shell_select_submenu_first (GtkMenuShell   *menu_shell); 
 
 static void gtk_real_menu_shell_move_current (GtkMenuShell      *menu_shell,
 					      GtkMenuDirectionType direction);
@@ -904,6 +905,21 @@
 }
 
 static void
+gtk_menu_shell_select_submenu_first (GtkMenuShell     *menu_shell)
+{
+  GtkMenuItem *menu_item;
+
+  menu_item = GTK_MENU_ITEM (menu_shell->active_menu_item); 
+  
+  if (menu_item->submenu)
+    {
+      GtkMenuShell *submenu = GTK_MENU_SHELL (menu_item->submenu); 
+      if (submenu->children)
+	gtk_menu_shell_select_item (submenu, submenu->children->data); 
+    }
+}
+
+static void
 gtk_real_menu_shell_move_current (GtkMenuShell      *menu_shell,
 				  GtkMenuDirectionType direction)
 {
@@ -923,8 +939,11 @@
 	  if (GTK_MENU_SHELL_CLASS (GTK_OBJECT (parent_menu_shell)->klass)->submenu_placement == 
 		       GTK_MENU_SHELL_CLASS (GTK_OBJECT (menu_shell)->klass)->submenu_placement)
 	    gtk_menu_shell_deselect (menu_shell);
-	  else
-	    gtk_menu_shell_move_selected (parent_menu_shell, -1);
+	  else 
+	    {
+	      gtk_menu_shell_move_selected (parent_menu_shell, -1);
+	      gtk_menu_shell_select_submenu_first (parent_menu_shell); 
+	    }
 	}
       break;
       
@@ -946,7 +965,10 @@
 	    parent_menu_shell = GTK_MENU_SHELL (parent_menu_shell->parent_menu_shell);
 	  
 	  if (parent_menu_shell)
-	    gtk_menu_shell_move_selected (parent_menu_shell, 1);
+	    {
+	      gtk_menu_shell_move_selected (parent_menu_shell, 1);
+	      gtk_menu_shell_select_submenu_first (parent_menu_shell);
+	    }
 	}
       break;
       


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]