2008-09-24 Claudio Saavedra <csaavedra@igalia.com>
authorClaudio Saavedra <csaavedra@igalia.com>
Wed, 24 Sep 2008 10:45:02 +0000 (10:45 +0000)
committerClaudio Saavedra <csaavedra@igalia.com>
Wed, 24 Sep 2008 10:45:02 +0000 (10:45 +0000)
Patch contributed by Kimmo Hamalainen (kimmo.hamalainen@nokia.com)

* examples/hildon-note-example.c: (on_information_clicked),
(on_confirmation_clicked), (on_progress_clicked), (main): Add
debugging information.
* src/hildon-note-private.h: Remove close_if_pressed_outside,
not needed anymore.
* src/hildon-note.c: (hildon_note_class_init), (hildon_note_init),
(hildon_note_rebuild): Remove special handling of tapping outside/inside
in order to close: this will be handled by the WM from now on.

Fixes: NB#88891 (Allow WM to handle properly close-on-tap-outside behavior)

ChangeLog
examples/hildon-note-example.c
src/hildon-note-private.h
src/hildon-note.c

index 943acd2..a8a0f12 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2008-09-24  Claudio Saavedra  <csaavedra@igalia.com>
+
+       Patch contributed by Kimmo Hämäläinen (kimmo.hamalainen@nokia.com)
+
+       * examples/hildon-note-example.c: (on_information_clicked),
+       (on_confirmation_clicked), (on_progress_clicked), (main): Add
+       debugging information.
+       * src/hildon-note-private.h: Remove close_if_pressed_outside,
+       not needed anymore.
+       * src/hildon-note.c: (hildon_note_class_init), (hildon_note_init),
+       (hildon_note_rebuild): Remove special handling of tapping outside/inside
+       in order to close: this will be handled by the WM from now on.
+
+       Fixes: NB#88891 (Allow WM to handle properly close-on-tap-outside behavior)
+
 2008-09-24  Alberto Garcia  <agarcia@igalia.com>
 
        * src/hildon-app-menu-private.h
index d47a445..7d0e17c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is a part of hildon examples
  *
- * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
+ * Copyright (C) 2005-2008 Nokia Corporation. All rights reserved.
  *
  * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
  *
 #include                                        "hildon.h"
 
 static gboolean
-on_information_clicked                          (GtkWidget *widget)
+on_information_clicked                          (GtkWidget *widget, gpointer data)
 {
+    GtkWidget *window = data;
+    gint i;
     HildonNote* note = HILDON_NOTE (hildon_note_new_information (NULL, 
             "This is a really really really long text that should " 
             "get wrapped but never truncated because truncating stuff "
             "automatically is really really bad! Blah blah blah!"));
 
-    gtk_dialog_run (GTK_DIALOG (note));
+    gtk_window_set_transient_for (GTK_WINDOW(note), GTK_WINDOW(window));
+    i = gtk_dialog_run (GTK_DIALOG (note));
+    if (i == GTK_RESPONSE_DELETE_EVENT)
+      g_debug ("%s: GTK_RESPONSE_DELETE_EVENT", __FUNCTION__);
     gtk_object_destroy (GTK_OBJECT (note));
     
     return TRUE;
 }
 
 static gboolean
-on_confirmation_clicked                         (GtkWidget *widget)
+on_confirmation_clicked                         (GtkWidget *widget, gpointer data)
 {
     gint i;
+    GtkWidget *window = data;
     HildonNote* note = HILDON_NOTE (hildon_note_new_confirmation (NULL, 
             "Do you want to confirm?!"));
 
+    gtk_window_set_transient_for (GTK_WINDOW(note), GTK_WINDOW(window));
     i = gtk_dialog_run (GTK_DIALOG (note));
     gtk_object_destroy (GTK_OBJECT (note));
     
     if (i == GTK_RESPONSE_OK)
         g_debug ("Button 'OK' pressed");
+    else if (i == GTK_RESPONSE_DELETE_EVENT)
+        g_debug ("%s: GTK_RESPONSE_DELETE_EVENT", __FUNCTION__);
     else
         g_debug ("Button 'Cancel' pressed");
 
@@ -61,13 +70,20 @@ on_confirmation_clicked                         (GtkWidget *widget)
 }
 
 static gboolean
-on_progress_clicked                             (GtkWidget *widget)
+on_progress_clicked                             (GtkWidget *widget, gpointer data)
 {
+    gint i;
+    GtkWidget *window = data;
     GtkProgressBar *bar = GTK_PROGRESS_BAR (gtk_progress_bar_new ());
     HildonNote *note = HILDON_NOTE (hildon_note_new_cancel_with_progress_bar (NULL, 
                 "Do you want to foo bar?", bar));
 
-    gtk_dialog_run (GTK_DIALOG (note));
+    gtk_window_set_transient_for (GTK_WINDOW(note), GTK_WINDOW(window));
+    i = gtk_dialog_run (GTK_DIALOG (note));
+    if (i == GTK_RESPONSE_DELETE_EVENT)
+      g_debug ("%s: GTK_RESPONSE_DELETE_EVENT", __FUNCTION__);
+    else
+      g_debug ("Button 'Cancel' pressed");
     gtk_object_destroy (GTK_OBJECT (note));
 
     return TRUE;
@@ -88,13 +104,13 @@ main                                            (int argc,
 
     GtkVBox *vbox = GTK_VBOX (gtk_vbox_new (6, FALSE));
     GtkButton *button1 = GTK_BUTTON (gtk_button_new_with_label ("Information note"));
-    g_signal_connect (G_OBJECT (button1), "clicked", G_CALLBACK (on_information_clicked), NULL);
+    g_signal_connect (G_OBJECT (button1), "clicked", G_CALLBACK (on_information_clicked), window);
 
     GtkButton *button2 = GTK_BUTTON (gtk_button_new_with_label ("Confirmation note"));
-    g_signal_connect (G_OBJECT (button2), "clicked", G_CALLBACK (on_confirmation_clicked), NULL);
+    g_signal_connect (G_OBJECT (button2), "clicked", G_CALLBACK (on_confirmation_clicked), window);
 
     GtkButton *button3 = GTK_BUTTON (gtk_button_new_with_label ("Progress note"));
-    g_signal_connect (G_OBJECT (button3), "clicked", G_CALLBACK (on_progress_clicked), NULL);
+    g_signal_connect (G_OBJECT (button3), "clicked", G_CALLBACK (on_progress_clicked), window);
 
     g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
 
index 3514df2..183ef82 100644 (file)
@@ -41,7 +41,6 @@ struct                                          _HildonNotePrivate
     GtkWidget *box;
     GtkWidget *icon;
     GdkWindow *transfer_window;
-    guint close_if_pressed_outside : 1;
 
     HildonNoteType note_n;
     GtkWidget *progressbar;
index e82217f..0981dd8 100644 (file)
@@ -101,16 +101,6 @@ hildon_note_rebuild                             (HildonNote *note);
 static void
 hildon_note_finalize                            (GObject *obj_self);
 
-static gboolean
-hildon_note_button_release                      (GtkWidget *widget,
-                                                 GdkEventButton *event);
-
-static void
-hildon_note_map                                 (GtkWidget *widget);
-
-static void
-hildon_note_unmap                               (GtkWidget *widget);
-
 static void
 hildon_note_realize                             (GtkWidget *widget);
 
@@ -143,32 +133,6 @@ enum
 
 static GtkDialogClass*                          parent_class;
 
-static GdkWindow *
-grab_transfer_window_get                        (GtkWidget *widget)
-{
-    GdkWindow *window;
-    GdkWindowAttr attributes;
-    gint attributes_mask;
-
-    attributes.x = 0;
-    attributes.y = 0;
-    attributes.width = 10;
-    attributes.height = 10;
-    attributes.window_type = GDK_WINDOW_TEMP;
-    attributes.wclass = GDK_INPUT_ONLY;
-    attributes.override_redirect = TRUE;
-    attributes.event_mask = 0;
-
-    attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
-
-    window = gdk_window_new (gtk_widget_get_root_window (widget),
-                             &attributes, attributes_mask);
-    gdk_window_set_user_data (window, widget);
-
-    gdk_window_show (window);
-
-    return window;
-}
 
 static void
 hildon_note_set_property                        (GObject *object,
@@ -319,9 +283,6 @@ hildon_note_class_init                          (HildonNoteClass *class)
     object_class->finalize      = hildon_note_finalize;
     object_class->set_property  = hildon_note_set_property;
     object_class->get_property  = hildon_note_get_property;
-    widget_class->button_release_event = hildon_note_button_release;
-    widget_class->map           = hildon_note_map;
-    widget_class->unmap         = hildon_note_unmap;
     widget_class->realize       = hildon_note_realize;
 
     g_object_class_install_property (object_class,
@@ -396,8 +357,6 @@ hildon_note_init                                (HildonNote *dialog)
     gtk_label_set_line_wrap (GTK_LABEL (priv->label), TRUE);
     
     priv->icon  = gtk_image_new ();
-    priv->close_if_pressed_outside = FALSE;
-    priv->transfer_window = NULL;
 
     /* Acquire real references to our internal children, since
        they are not nessecarily packed into container in each
@@ -435,90 +394,6 @@ hildon_note_finalize                            (GObject *obj_self)
 }
 
 
-static gboolean
-hildon_note_button_release                      (GtkWidget *widget,
-                                                 GdkEventButton *event)
-{
-    int x, y;
-    gboolean info_note, released_outside;
-    HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (widget);
-
-    gdk_window_get_position (widget->window, &x, &y);
-
-    /* Whether the button has been released outside the widget */
-    released_outside = (event->x_root < x || event->x_root > x + widget->allocation.width ||
-                        event->y_root < y || event->y_root > y + widget->allocation.height);
-
-    /* Information notes are also closed by tapping on them */
-    info_note = (priv->note_n == HILDON_NOTE_TYPE_INFORMATION ||
-                 priv->note_n == HILDON_NOTE_TYPE_INFORMATION_THEME);
-
-    if (info_note || (released_outside && priv->close_if_pressed_outside)) {
-        gtk_dialog_response (GTK_DIALOG (widget), GTK_RESPONSE_CANCEL);
-    }
-
-    if (GTK_WIDGET_CLASS (parent_class)->button_release_event) {
-        return GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, event);
-    } else {
-        return FALSE;
-    }
-}
-
-static void
-hildon_note_map                                 (GtkWidget *widget)
-{
-    HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (widget);
-    g_assert (priv);
-
-    /* Map the window */
-    GTK_WIDGET_CLASS (parent_class)->map (widget);
-
-    if (priv->transfer_window == NULL && priv->close_if_pressed_outside) {
-        gboolean has_grab = FALSE;
-
-        priv->transfer_window = grab_transfer_window_get (widget);
-
-        if (gdk_pointer_grab (priv->transfer_window, TRUE,
-                              GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
-                              GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
-                              GDK_POINTER_MOTION_MASK, NULL, NULL,
-                              GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS) {
-            if (gdk_keyboard_grab (priv->transfer_window, TRUE,
-                                   GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS) {
-                has_grab = TRUE;
-            } else {
-                gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
-                                            GDK_CURRENT_TIME);
-            }
-        }
-
-        if (has_grab) {
-            gtk_grab_add (widget);
-        } else {
-            gdk_window_destroy (priv->transfer_window);
-            priv->transfer_window = NULL;
-        }
-    }
-}
-
-static void
-hildon_note_unmap                               (GtkWidget *widget)
-{
-    HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (widget);
-    g_assert (priv);
-
-    if (priv->transfer_window != NULL) {
-        /* Remove the grab */
-        gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
-                                    GDK_CURRENT_TIME);
-        gtk_grab_remove (widget);
-
-        /* Destroy the transfer window */
-        gdk_window_destroy (priv->transfer_window);
-        priv->transfer_window = NULL;
-    }
-}
-
 static void
 hildon_note_realize                             (GtkWidget *widget)
 {
@@ -604,9 +479,6 @@ hildon_note_rebuild                             (HildonNote *note)
         priv->cancelButton = NULL;
     }
 
-    /* By default the note won't be closed when pressing outside */
-    priv->close_if_pressed_outside = FALSE;
-
     /* Add needed buttons and images for each note type */
     switch (priv->note_n)
     {
@@ -625,7 +497,6 @@ hildon_note_rebuild                             (HildonNote *note)
 
         case HILDON_NOTE_TYPE_INFORMATION_THEME:
         case HILDON_NOTE_TYPE_INFORMATION:
-            priv->close_if_pressed_outside = TRUE;
             gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon),
                     HILDON_NOTE_INFORMATION_ICON,
                     HILDON_ICON_SIZE_BIG_NOTE);