[maemo-commits] [maemo-commits] r11942 - in projects/haf/trunk/gtk+: . gtk

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue May 29 11:25:13 EEST 2007
Author: xan
Date: 2007-05-29 11:25:09 +0300 (Tue, 29 May 2007)
New Revision: 11942

Modified:
   projects/haf/trunk/gtk+/ChangeLog
   projects/haf/trunk/gtk+/gtk/gtkmenushell.c
Log:
	* gtk/gtkmenushell.c (_gtk_menu_shell_fake_button_events): do not
	generate the fake events if the click is inside our attached widget.
	This way the user can close a menu clicking on its parent (if it's
	attached). We blacklist menus attached to a GtkWindow to avoid this
	functionality in HildonWindow, as there is no reliable way (AFAIK) of
	detecting a click on the window decoration area that acts as a MenuBar.
	Also, consolidate the logic in one function.


Modified: projects/haf/trunk/gtk+/ChangeLog
===================================================================
--- projects/haf/trunk/gtk+/ChangeLog	2007-05-29 08:13:18 UTC (rev 11941)
+++ projects/haf/trunk/gtk+/ChangeLog	2007-05-29 08:25:09 UTC (rev 11942)
@@ -1,3 +1,13 @@
+2007-05-29  Xan Lopez  <xan.lopez at nokia.com>
+
+	* gtk/gtkmenushell.c (_gtk_menu_shell_fake_button_events): do not
+	generate the fake events if the click is inside our attached widget.
+	This way the user can close a menu clicking on its parent (if it's
+	attached). We blacklist menus attached to a GtkWindow to avoid this
+	functionality in HildonWindow, as there is no reliable way (AFAIK) of
+	detecting a click on the window decoration area that acts as a MenuBar.
+	Also, consolidate the logic in one function.	
+
 2007-05-28  Tommi Komulainen  <tommi.komulainen at nokia.com>
 
 	* gtk/gtkmenu.c: add SCROLL_DELAY_FACTOR

Modified: projects/haf/trunk/gtk+/gtk/gtkmenushell.c
===================================================================
--- projects/haf/trunk/gtk+/gtk/gtkmenushell.c	2007-05-29 08:13:18 UTC (rev 11941)
+++ projects/haf/trunk/gtk+/gtk/gtkmenushell.c	2007-05-29 08:25:09 UTC (rev 11942)
@@ -543,6 +543,53 @@
     }
 }
 
+#if defined(MAEMO_CHANGES) && defined(HAVE_XTST)
+
+static void
+_gtk_menu_shell_fake_button_events (GtkWidget *widget,
+                                    guint button,
+                                    gboolean send_press,
+                                    gboolean send_release)
+{
+  GdkDisplay *display;
+  gint x, y;
+  GtkWidget *attached_widget;
+
+  display = gtk_widget_get_display (widget);
+
+  attached_widget = gtk_menu_get_attach_widget (GTK_MENU (widget));
+
+  /* Blacklist GtkWindow to disable this functionality in HildonWindow,
+     as there is no reliable way of detecting the click on the window
+     decoration */
+  if (attached_widget && !GTK_IS_WINDOW (attached_widget))
+    {
+      /* Do not generate the events if the click is inside our
+         attach widget. This allows the user to close a menu
+         clicking on it parent for example */
+      gtk_widget_get_pointer (attached_widget, &x, &y);
+          
+      if ((x < 0) || (x > attached_widget->allocation.width) ||
+          (y < 0) || (y > attached_widget->allocation.height))
+        {
+
+          if (send_press)
+            XTestFakeButtonEvent (gdk_x11_display_get_xdisplay (display),
+                                  button,
+                                  TRUE,
+                                  0);
+
+          if (send_release)
+            XTestFakeButtonEvent (gdk_x11_display_get_xdisplay (display),
+                                  button,
+                                  FALSE,
+                                  0);
+        }
+    }
+}
+
+#endif
+
 static gint
 gtk_menu_shell_button_press (GtkWidget      *widget,
 			     GdkEventButton *event)
@@ -595,23 +642,18 @@
     }
   else
     {
-#if defined(MAEMO_CHANGES) && defined(HAVE_XTST)
-      GdkDisplay *display = gtk_widget_get_display (widget);
-#endif
-
       widget = gtk_get_event_widget ((GdkEvent*) event);
       if (widget == GTK_WIDGET (menu_shell))
 	{
 	  gtk_menu_shell_deactivate (menu_shell);
 	  g_signal_emit (menu_shell, menu_shell_signals[SELECTION_DONE], 0);
-	}
 
 #if defined(MAEMO_CHANGES) && defined(HAVE_XTST)
-      XTestFakeButtonEvent (gdk_x11_display_get_xdisplay (display),
-                            event->button,
-                            TRUE,
-                            0);
+          _gtk_menu_shell_fake_button_events (widget, event->button, TRUE, FALSE);
 #endif
+
+	}
+
     }
 
   if (menu_item && _gtk_menu_item_is_selectable (menu_item) &&
@@ -784,18 +826,11 @@
 
       if (deactivate)
         {
-#if defined(MAEMO_CHANGES) && defined(HAVE_XTST)
-          GdkDisplay *display = gtk_widget_get_display (widget);
-#endif
-
           gtk_menu_shell_deactivate (menu_shell);
           g_signal_emit (menu_shell, menu_shell_signals[SELECTION_DONE], 0);
 
 #if defined(MAEMO_CHANGES) && defined(HAVE_XTST)
-          XTestFakeButtonEvent (gdk_x11_display_get_xdisplay (display),
-                                event->button,
-                                FALSE,
-                                0);
+          _gtk_menu_shell_fake_button_events (widget, event->button, TRUE, TRUE);
 #endif
         }
 


More information about the maemo-commits mailing list