Re: patch #59456, #59456-2, #64977 -- menu stuff



On Thu, 2001-11-29 at 01:00, Owen Taylor wrote:
> 
> [...]
> 
> Looks to me like this will mean that MENU_SHELL_TIMEOUT will no
> longer work since we'll always deactivate on the release after the
> initial click. It seems to me:
> 
>  - the check/clear of just-activate should occur outside the
>    > MENU_SHELL_TIMEOUT block
>  - but the actual use of it for deactivation should be inside
>    the > MENU_SHELL_TIMEOUT block.
> 

Fixed this in the new diff.

regards,


	Kris

> Am I missing something here? The rest looks fine now.
> 
>                                         Owen

Index: gtkmenu.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenu.c,v
retrieving revision 1.76
diff -u -r1.76 gtkmenu.c
--- gtkmenu.c	2001/11/20 23:43:02	1.76
+++ gtkmenu.c	2001/11/29 17:12:39
@@ -1716,7 +1716,8 @@
    * which may be different from 'widget'.
    */
   menu_item = gtk_get_event_widget ((GdkEvent*) event);
-  if (!menu_item || !GTK_IS_MENU_ITEM (menu_item) || !GTK_WIDGET_IS_SENSITIVE (menu_item) ||
+  if (!menu_item || !GTK_IS_MENU_ITEM (menu_item) ||
+      !_gtk_menu_item_is_selectable (menu_item) ||
       !GTK_IS_MENU (menu_item->parent))
     return FALSE;
 
Index: gtkmenuitem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenuitem.c,v
retrieving revision 1.62
diff -u -r1.62 gtkmenuitem.c
--- gtkmenuitem.c	2001/11/17 23:28:50	1.62
+++ gtkmenuitem.c	2001/11/29 17:12:40
@@ -31,6 +31,8 @@
 #include "gtkmenu.h"
 #include "gtkmenubar.h"
 #include "gtkmenuitem.h"
+#include "gtktearoffmenuitem.h"
+#include "gtkseparatormenuitem.h"
 #include "gtksignal.h"
 
 
@@ -757,7 +759,13 @@
 
 	  submenu = GTK_MENU_SHELL (menu_item->submenu);
 	  if (submenu->children)
-	    gtk_menu_shell_select_item (submenu, submenu->children->data);
+	    {
+	      if (submenu->children->next &&
+		  GTK_IS_TEAROFF_MENU_ITEM (submenu->children->data))
+		gtk_menu_shell_select_item (submenu, submenu->children->next->data);
+	      else
+		gtk_menu_shell_select_item (submenu, submenu->children->data);
+	    }
 	}
     }
 }
@@ -1102,4 +1110,17 @@
 
   if (bin->child)
     callback (bin->child, callback_data);
+}
+
+gboolean
+_gtk_menu_item_is_selectable (GtkWidget *menu_item)
+{
+  if ((!GTK_BIN (menu_item)->child &&
+       G_OBJECT_TYPE (menu_item) == GTK_TYPE_MENU_ITEM) ||
+      GTK_IS_SEPARATOR_MENU_ITEM (menu_item) ||
+      !GTK_WIDGET_IS_SENSITIVE (menu_item) ||
+      !GTK_WIDGET_VISIBLE (menu_item))
+    return FALSE;
+
+  return TRUE;
 }
Index: gtkmenuitem.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenuitem.h,v
retrieving revision 1.22
diff -u -r1.22 gtkmenuitem.h
--- gtkmenuitem.h	2001/11/16 15:20:27	1.22
+++ gtkmenuitem.h	2001/11/29 17:12:40
@@ -110,10 +110,12 @@
 void	   gtk_menu_item_set_accel_path	      (GtkMenuItem	   *menu_item,
 					       const gchar	   *accel_path);
 
+/* private */
 void	  _gtk_menu_item_refresh_accel_path   (GtkMenuItem	   *menu_item,
 					       const gchar	   *prefix,
 					       GtkAccelGroup	   *accel_group,
 					       gboolean		    group_changed);
+gboolean  _gtk_menu_item_is_selectable        (GtkWidget           *menu_item);
 
 #ifndef GTK_DISABLE_DEPRECATED
 #define gtk_menu_item_right_justify(menu_item) gtk_menu_item_set_right_justified ((menu_item), TRUE)
Index: gtkmenushell.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenushell.c,v
retrieving revision 1.49
diff -u -r1.49 gtkmenushell.c
--- gtkmenushell.c	2001/11/24 21:05:10	1.49
+++ gtkmenushell.c	2001/11/29 17:12:41
@@ -29,7 +29,6 @@
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
 #include "gtkmenuitem.h"
-#include "gtktearoffmenuitem.h" /* FIXME */
 #include "gtkmenushell.h"
 #include "gtksignal.h"
 #include "gtkwindow.h"
@@ -411,12 +410,17 @@
 
       menu_item = gtk_menu_shell_get_item (menu_shell, (GdkEvent *)event);
 
-      if (menu_item &&
-	  GTK_WIDGET_IS_SENSITIVE (menu_item))
+      if (menu_item && _gtk_menu_item_is_selectable (menu_item))
 	{
 	  if ((menu_item->parent == widget) &&
 	      (menu_item != menu_shell->active_menu_item))
-	    gtk_menu_shell_select_item (menu_shell, menu_item);
+	    {
+	      if (GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement == GTK_TOP_BOTTOM)
+		g_object_set_data (G_OBJECT (menu_shell),
+				   "gtk-menushell-just-activated",
+				   GUINT_TO_POINTER (1));
+	      gtk_menu_shell_select_item (menu_shell, menu_item);
+	    }
 	}
     }
   else
@@ -446,22 +450,39 @@
   menu_shell = GTK_MENU_SHELL (widget);
   if (menu_shell->active)
     {
+      gboolean deactivate_immediately = FALSE;
+
       if (menu_shell->button && (event->button != menu_shell->button))
 	{
 	  menu_shell->button = 0;
 	  if (menu_shell->parent_menu_shell)
 	    return gtk_widget_event (menu_shell->parent_menu_shell, (GdkEvent*) event);
 	}
-      
+
       menu_shell->button = 0;
       menu_item = gtk_menu_shell_get_item (menu_shell, (GdkEvent*) event);
 
       deactivate = TRUE;
 
+      if (menu_item
+	  && GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement == GTK_TOP_BOTTOM)
+	{
+	  if (g_object_get_data (G_OBJECT (menu_shell), "gtk-menushell-just-activated"))
+	    g_object_set_data (G_OBJECT (menu_shell), "gtk-menushell-just-activated", NULL);
+	  else
+	    deactivate_immediately = TRUE;
+	}
+
       if ((event->time - menu_shell->activate_time) > MENU_SHELL_TIMEOUT)
 	{
+	  if (deactivate_immediately)
+	    {
+	      gtk_menu_shell_deactivate (menu_shell);
+	      return TRUE;
+	    }
+	    
 	  if (menu_item && (menu_shell->active_menu_item == menu_item) &&
-	      GTK_WIDGET_IS_SENSITIVE (menu_item))
+	      _gtk_menu_item_is_selectable (menu_item))
 	    {
 	      if (GTK_MENU_ITEM (menu_item)->submenu == NULL)
 		{
@@ -469,7 +490,7 @@
 		  return TRUE;
 		}
 	    }
-	  else if (menu_item && !GTK_WIDGET_IS_SENSITIVE (menu_item))
+	  else if (menu_item && !_gtk_menu_item_is_selectable (menu_item))
 	    deactivate = FALSE;
 	  else if (menu_shell->parent_menu_shell)
 	    {
@@ -562,7 +583,9 @@
     {
       menu_item = gtk_get_event_widget ((GdkEvent*) event);
 
-      if (!menu_item || !GTK_WIDGET_IS_SENSITIVE (menu_item))
+      if (!menu_item ||
+	  (GTK_IS_MENU_ITEM (menu_item) && 
+	   !_gtk_menu_item_is_selectable (menu_item)))
 	return TRUE;
       
       if ((menu_item->parent == widget) &&
@@ -614,7 +637,7 @@
 	  return TRUE;
 	}
 
-      if (!GTK_WIDGET_IS_SENSITIVE (menu_item))
+      if (!_gtk_menu_item_is_selectable (event_widget))
 	return TRUE;
 
       if ((menu_shell->active_menu_item == event_widget) &&
@@ -785,7 +808,7 @@
 				 GtkWidget    *menu_item)
 {
   gtk_menu_shell_deselect (menu_shell);
-  
+
   menu_shell->active_menu_item = menu_item;
   _gtk_menu_item_set_placement (GTK_MENU_ITEM (menu_shell->active_menu_item),
 			       GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement);
@@ -874,9 +897,7 @@
 	{
 	  node = node->next;
 	  while (node != start_node && 
-		 (!node ||
-		  !GTK_WIDGET_IS_SENSITIVE (node->data) ||
-		  !GTK_WIDGET_VISIBLE (node->data) ))
+		 (!node || !_gtk_menu_item_is_selectable (node->data)))
 	    {
 	      if (!node)
 		node = menu_shell->children;
@@ -888,9 +909,7 @@
 	{
 	  node = node->prev;
 	  while (node != start_node &&
-		 (!node ||
-		  !GTK_WIDGET_IS_SENSITIVE (node->data) ||
-		  !GTK_WIDGET_VISIBLE (node->data) ))
+		 (!node || !_gtk_menu_item_is_selectable (node->data)))
 	    {
 	      if (!node)
 		node = g_list_last (menu_shell->children);
@@ -949,7 +968,7 @@
       
     case GTK_MENU_DIR_CHILD:
       if (menu_shell->active_menu_item &&
-	  GTK_BIN (menu_shell->active_menu_item)->child &&
+	  _gtk_menu_item_is_selectable (menu_shell->active_menu_item) &&
 	  GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu)
 	{
 	  menu_shell = GTK_MENU_SHELL (GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu);
@@ -995,7 +1014,7 @@
 				      gboolean           force_hide)
 {
   if (menu_shell->active_menu_item &&
-      GTK_WIDGET_IS_SENSITIVE (menu_shell->active_menu_item) &&
+      _gtk_menu_item_is_selectable (menu_shell->active_menu_item) &&
       GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu == NULL)
     {
       gtk_menu_shell_activate_item (menu_shell,
@@ -1014,4 +1033,3 @@
   gtk_menu_shell_deactivate (menu_shell);
   gtk_signal_emit (GTK_OBJECT (menu_shell), menu_shell_signals[SELECTION_DONE]);
 }
-


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