/*
* 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");
}
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;
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);
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);
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,
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,
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
}
-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)
{
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)
{
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);