[maemo-commits] [maemo-commits] r10844 - in projects/haf/branches/gtk+/maemo-gtk-2-10: . gtk

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Fri Mar 30 12:39:12 EEST 2007
Author: mitch
Date: 2007-03-30 12:39:10 +0300 (Fri, 30 Mar 2007)
New Revision: 10844

Modified:
   projects/haf/branches/gtk+/maemo-gtk-2-10/ChangeLog
   projects/haf/branches/gtk+/maemo-gtk-2-10/gtk/gtkmenu.c
Log:
2007-03-30  Michael Natterer  <mitch at imendio.com>

	Replace some MAEMO_CHANGES code with the version merged to
	upstream trunk:

	Don't close menus on clicks on their border area (bug #423761).
	(modified patch from maemo-gtk).

	* gtk/gtkmenu.c (gtk_menu_button_press)
	(gtk_menu_button_release): bail out early if the click was on the
	menu's border (not on any item and not outside the window).

	(pointer_in_menu_window): new utility function which checks if
	passed root coords are inside the menu_shell or one of its
	parent shells.

	Maemo-only:

	(gtk_menu_motion_notify): use pointer_in_menu_window() instead
	of the old pointer_in_menu_tree() which didn't take root coords.



Modified: projects/haf/branches/gtk+/maemo-gtk-2-10/ChangeLog
===================================================================
--- projects/haf/branches/gtk+/maemo-gtk-2-10/ChangeLog	2007-03-30 07:17:20 UTC (rev 10843)
+++ projects/haf/branches/gtk+/maemo-gtk-2-10/ChangeLog	2007-03-30 09:39:10 UTC (rev 10844)
@@ -1,3 +1,24 @@
+2007-03-30  Michael Natterer  <mitch at imendio.com>
+
+	Replace some MAEMO_CHANGES code with the version merged to
+	upstream trunk:
+
+	Don't close menus on clicks on their border area (bug #423761).
+	(modified patch from maemo-gtk).
+
+	* gtk/gtkmenu.c (gtk_menu_button_press)
+	(gtk_menu_button_release): bail out early if the click was on the
+	menu's border (not on any item and not outside the window).
+
+	(pointer_in_menu_window): new utility function which checks if
+	passed root coords are inside the menu_shell or one of its
+	parent shells.
+
+	Maemo-only:
+
+	(gtk_menu_motion_notify): use pointer_in_menu_window() instead
+	of the old pointer_in_menu_tree() which didn't take root coords.
+
 2007-03-29  Tommi Komulainen  <tommi.komulainen at nokia.com>
 
 	* gtk/gtkmenuitem.c (gtk_menu_item_paint): Remove the patch that

Modified: projects/haf/branches/gtk+/maemo-gtk-2-10/gtk/gtkmenu.c
===================================================================
--- projects/haf/branches/gtk+/maemo-gtk-2-10/gtk/gtkmenu.c	2007-03-30 07:17:20 UTC (rev 10843)
+++ projects/haf/branches/gtk+/maemo-gtk-2-10/gtk/gtkmenu.c	2007-03-30 09:39:10 UTC (rev 10844)
@@ -2674,39 +2674,6 @@
 }
 
 #ifdef MAEMO_CHANGES
-static GtkWidget *
-find_active_menu_item (GdkEventButton *event)
-{
-  GtkWidget *menu_item;
-
-  menu_item = gtk_get_event_widget ((GdkEvent*) event);
-  while (menu_item && !GTK_IS_MENU_ITEM (menu_item))
-    menu_item = menu_item->parent;
-
-  return menu_item;
-}
-
-static gboolean
-pointer_in_menu_tree (GtkWidget *widget)
-{
-  GtkMenuShell *mshell;
-  gint width, height, x, y;
-
-  mshell = GTK_MENU_SHELL (widget);
-
-  gdk_window_get_pointer (widget->window, &x, &y, NULL);
-  gdk_drawable_get_size (widget->window, &width, &height);
-
-  if ((x <= width) && (x >= 0) && (y <= height) && (y >= 0))
-    return TRUE;
-
-  if ((mshell->parent_menu_shell != NULL) &&
-      GTK_IS_MENU (mshell->parent_menu_shell))
-    return pointer_in_menu_tree (mshell->parent_menu_shell);
-
-  return FALSE;
-}
-
 static gint
 distance_traveled (GtkWidget *widget)
 {
@@ -2754,27 +2721,55 @@
 }
 
 static gboolean
+pointer_in_menu_window (GtkWidget *widget,
+                        gdouble    x_root,
+                        gdouble    y_root)
+{
+  GtkMenu *menu = GTK_MENU (widget);
+
+  if (GTK_WIDGET_MAPPED (menu->toplevel))
+    {
+      GtkMenuShell *menu_shell;
+      gint          window_x, window_y;
+
+      gdk_window_get_position (menu->toplevel->window, &window_x, &window_y);
+
+      if (x_root >= window_x && x_root < window_x + widget->allocation.width &&
+          y_root >= window_y && y_root < window_y + widget->allocation.height)
+        return TRUE;
+
+      menu_shell = GTK_MENU_SHELL (widget);
+
+      if (GTK_IS_MENU (menu_shell->parent_menu_shell))
+        return pointer_in_menu_window (menu_shell->parent_menu_shell,
+                                       x_root, y_root);
+    }
+
+  return FALSE;
+}
+
+static gboolean
 gtk_menu_button_press (GtkWidget      *widget,
                        GdkEventButton *event)
 {
   if (event->type != GDK_BUTTON_PRESS)
     return FALSE;
 
-  /* Don't pop down the menu for presses over scroll arrows
+  /* Don't pass down to menu shell for presses over scroll arrows
    */
   if (gtk_menu_button_scroll (GTK_MENU (widget), event))
     return TRUE;
 
-#ifdef MAEMO_CHANGES
-  if (!find_active_menu_item (event))
-    {
-      /*  Don't pass down to menu shell if a non-menuitem part of the menu
-       *  was clicked.
-       */
-      if (pointer_in_menu_tree (widget))
-        return TRUE;
-    }
-#endif /* MAEMO_CHANGES */
+  /*  Don't pass down to menu shell if a non-menuitem part of the menu
+   *  was clicked. The check for the event_widget being a GtkMenuShell
+   *  works because we have the pointer grabbed on menu_shell->window
+   *  with owner_events=TRUE, so all events that are either outside
+   *  the menu or on its border are delivered relative to
+   *  menu_shell->window.
+   */
+  if (GTK_IS_MENU_SHELL (gtk_get_event_widget ((GdkEvent *) event)) &&
+      pointer_in_menu_window (widget, event->x_root, event->y_root))
+    return TRUE;
 
   return GTK_WIDGET_CLASS (gtk_menu_parent_class)->button_press_event (widget, event);
 }
@@ -2794,13 +2789,20 @@
   if (event->type != GDK_BUTTON_RELEASE)
     return FALSE;
 
-  /* Don't pop down the menu for releases over scroll arrows
+  /* Don't pass down to menu shell for releases over scroll arrows
    */
   if (gtk_menu_button_scroll (GTK_MENU (widget), event))
     return TRUE;
 
-#ifdef MAEMO_CHANGES
-  if (!find_active_menu_item (event))
+  /*  Don't pass down to menu shell if a non-menuitem part of the menu
+   *  was clicked (see comment in button_press()).
+   */
+#ifndef MAEMO_CHANGES
+  if (GTK_IS_MENU_SHELL (gtk_get_event_widget ((GdkEvent *) event)) &&
+      pointer_in_menu_window (widget, event->x_root, event->y_root))
+    return TRUE;
+#else
+  if (GTK_IS_MENU_SHELL (gtk_get_event_widget ((GdkEvent *) event)))
     {
       if (priv->context_menu &&
           (priv->popup_pointer_x >= 0) &&
@@ -2820,10 +2822,7 @@
             return TRUE;
         }
 
-      /*  Don't pass down to menu shell if a non-menuitem part of the menu
-       *  was clicked.
-       */
-      if (pointer_in_menu_tree (widget))
+      if (pointer_in_menu_window (widget, event->x_root, event->y_root))
         return TRUE;
     }
 #endif /* MAEMO_CHANGES */
@@ -3076,7 +3075,7 @@
           /* Context menu mode. If we dragged out of the menu, close
            * the menu, as by the specs.
            */
-          if (!pointer_in_menu_tree (widget) &&
+          if (!pointer_in_menu_window (widget, event->x_root, event->y_root) &&
               (distance_traveled (widget) >= 20) &&
               (event->state & GDK_BUTTON1_MASK))
             {


More information about the maemo-commits mailing list