From: Alberto Garcia Date: Wed, 25 Jun 2008 17:02:19 +0000 (+0000) Subject: * examples/hildon-stackable-window-example.c (new_window): * src/Makefile.am (noinst_... X-Git-Tag: 2.1.66-1~683 X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;ds=inline;h=8a95e38835d478bf3d24ee0b6e8dcd6b5175580f;p=hildon * examples/hildon-stackable-window-example.c (new_window): * src/Makefile.am (noinst_HEADERS): * src/hildon-program.c (hildon_program_go_to_root_window): * src/hildon-program.h: * src/hildon-stackable-window-private.h: * src/hildon-stackable-window.c: * src/hildon-stackable-window.h: Create hildon-stackable-window-private.h Move hildon_stackable_window_go_to_root_window() to HildonProgram --- diff --git a/ChangeLog b/ChangeLog index ed58e8f..90adb72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2008-06-25 Alberto Garcia + * examples/hildon-stackable-window-example.c (new_window): + * src/Makefile.am (noinst_HEADERS): + * src/hildon-program.c (hildon_program_go_to_root_window): + * src/hildon-program.h: + * src/hildon-stackable-window-private.h: + * src/hildon-stackable-window.c: + * src/hildon-stackable-window.h: + Create hildon-stackable-window-private.h + Move hildon_stackable_window_go_to_root_window() to HildonProgram + * examples/hildon-app-menu-example.c (create_menu): * examples/hildon-hvolumebar-insensitive-example.c (main): * examples/hildon-hvolumebar-timer-example.c (on_idle): diff --git a/examples/hildon-stackable-window-example.c b/examples/hildon-stackable-window-example.c index 73a105c..09367f2 100644 --- a/examples/hildon-stackable-window-example.c +++ b/examples/hildon-stackable-window-example.c @@ -85,8 +85,8 @@ new_window (gboolean ismain) gtk_box_pack_end (GTK_BOX (hbbox), back, FALSE, FALSE, 0); g_signal_connect_swapped (G_OBJECT (back), "clicked", - G_CALLBACK (hildon_stackable_window_go_to_root_window), - HILDON_STACKABLE_WINDOW (window)); + G_CALLBACK (hildon_program_go_to_root_window), + hildon_program_get_instance ()); } return window; diff --git a/src/Makefile.am b/src/Makefile.am index 16f7159..73d4e4e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -144,6 +144,7 @@ noinst_HEADERS = hildon-banner-private.h \ hildon-volumebar-private.h \ hildon-weekday-picker-private.h \ hildon-window-private.h \ + hildon-stackable-window-private.h \ hildon-wizard-dialog-private.h \ hildon-calendar-private.h \ hildon-app-menu-private.h \ diff --git a/src/hildon-program.c b/src/hildon-program.c index 9cc94f0..b8a93e3 100644 --- a/src/hildon-program.c +++ b/src/hildon-program.c @@ -82,6 +82,8 @@ #include "hildon-program.h" #include "hildon-program-private.h" #include "hildon-window-private.h" +#include "hildon-stackable-window.h" +#include "hildon-stackable-window-private.h" #include static void @@ -684,3 +686,80 @@ hildon_program_get_is_topmost (HildonProgram *self) return priv->is_topmost; } + +/** + * hildon_program_go_to_root_window: + * @self: A #HildonProgram + * + * Will close all windows in the #HildonProgram but the first one (the + * root window) by sending them a delete event. If any of the windows + * refuses to close (by handling it) no further events will be + * sent. All windows in the program must be #HildonStackableWindow for + * this to work. + */ +void +hildon_program_go_to_root_window (HildonProgram *self) +{ + HildonProgramPrivate *priv; + GSList *windows, *iter; + gboolean windows_left; + + g_return_if_fail (HILDON_IS_PROGRAM (self)); + priv = HILDON_PROGRAM_GET_PRIVATE (self); + g_assert (priv); + + /* List of windows in reverse order (starting from the topmost one) */ + windows = g_slist_reverse (g_slist_copy (priv->windows)); + iter = windows; + + /* Destroy all the windows but the last one (which is the root + * window, as the list is reversed) */ + windows_left = (iter != NULL && iter->next != NULL); + while (windows_left) + { + if (HILDON_IS_STACKABLE_WINDOW (iter->data)) + { + GdkEvent *event; + HildonStackableWindow *win; + + /* Mark the window as "going home" */ + win = HILDON_STACKABLE_WINDOW (iter->data); + hildon_stackable_window_set_going_home (win, TRUE); + + /* Set win pointer to NULL if the window is destroyed */ + g_object_add_weak_pointer (G_OBJECT (win), (gpointer) &win); + + /* Send a delete event */ + event = gdk_event_new (GDK_DELETE); + event->any.window = g_object_ref (GTK_WIDGET (win)->window); + gtk_main_do_event (event); + gdk_event_free (event); + + /* Continue sending delete events if the window has been destroyed */ + if (win == NULL) + { + iter = iter->next; + windows_left = (iter != NULL && iter->next != NULL); + } + else + { + g_object_remove_weak_pointer (G_OBJECT (win), (gpointer) &win); + hildon_stackable_window_set_going_home (win, FALSE); + windows_left = FALSE; + } + } + else + { + g_warning ("Window list contains a non-stackable window"); + windows_left = FALSE; + } + } + + /* Show the last window that hasn't been destroyed */ + if (iter != NULL && GTK_IS_WIDGET (iter->data)) + { + gtk_widget_show (GTK_WIDGET (iter->data)); + } + + g_slist_free (windows); +} diff --git a/src/hildon-program.h b/src/hildon-program.h index 11a69e5..c2460e4 100644 --- a/src/hildon-program.h +++ b/src/hildon-program.h @@ -108,6 +108,9 @@ hildon_program_get_common_toolbar (HildonProgram *self); gboolean hildon_program_get_is_topmost (HildonProgram *self); +void +hildon_program_go_to_root_window (HildonProgram *self); + G_END_DECLS #endif /* __HILDON_PROGRAM_H__ */ diff --git a/src/hildon-stackable-window-private.h b/src/hildon-stackable-window-private.h new file mode 100644 index 0000000..f7058f5 --- /dev/null +++ b/src/hildon-stackable-window-private.h @@ -0,0 +1,50 @@ +/* + * This file is a part of hildon + * + * Copyright (C) 2008 Nokia Corporation, all rights reserved. + * + * Contact: Karl Lattimer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#ifndef __HILDON_STACKABLE_WINDOW_PRIVATE_H__ +#define __HILDON_STACKABLE_WINDOW_PRIVATE_H__ + +G_BEGIN_DECLS + +typedef struct _HildonStackableWindowPrivate HildonStackableWindowPrivate; + +struct _HildonStackableWindowPrivate +{ + gboolean going_home; +}; + +#define HILDON_STACKABLE_WINDOW_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\ + HILDON_TYPE_STACKABLE_WINDOW, HildonStackableWindowPrivate)) + +void G_GNUC_INTERNAL +hildon_stackable_window_set_going_home (HildonStackableWindow *self, + gboolean going_home); + +gboolean G_GNUC_INTERNAL +hildon_stackable_window_get_going_home (HildonStackableWindow *self); + +G_END_DECLS + +#endif /* __HILDON_STACKABLE_WINDOW_PRIVATE_H__ */ diff --git a/src/hildon-stackable-window.c b/src/hildon-stackable-window.c index aaf840a..68cd644 100644 --- a/src/hildon-stackable-window.c +++ b/src/hildon-stackable-window.c @@ -36,24 +36,14 @@ #include #include #include "hildon-stackable-window.h" +#include "hildon-stackable-window-private.h" #include "hildon-program.h" #include "hildon-window-private.h" #include "hildon-program-private.h" -typedef struct _HildonStackableWindowPrivate HildonStackableWindowPrivate; - -struct _HildonStackableWindowPrivate -{ - gboolean going_home; -}; - -#define HILDON_STACKABLE_WINDOW_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\ - HILDON_TYPE_STACKABLE_WINDOW, HildonStackableWindowPrivate)) - G_DEFINE_TYPE (HildonStackableWindow, hildon_stackable_window, HILDON_TYPE_WINDOW); -static void +void G_GNUC_INTERNAL hildon_stackable_window_set_going_home (HildonStackableWindow *self, gboolean going_home) { @@ -61,7 +51,7 @@ hildon_stackable_window_set_going_home (HildonStackableWindow *self, priv->going_home = going_home; } -static gboolean +gboolean G_GNUC_INTERNAL hildon_stackable_window_get_going_home (HildonStackableWindow *self) { HildonStackableWindowPrivate *priv = HILDON_STACKABLE_WINDOW_GET_PRIVATE (self); @@ -231,76 +221,3 @@ hildon_stackable_window_new (void) return GTK_WIDGET (newwindow); } - -/** - * hildon_stackable_window_go_to_root_window: - * @self: A #HildonStackableWindow - * - * Will close all the stackable windows in the @HildonProgram but the - * first one (the root window) by sending them a delete event. If any - * of the windows refuses to close (by handling it) no further events - * will be sent. - */ -void -hildon_stackable_window_go_to_root_window (HildonStackableWindow *self) -{ - GSList *windows, *iter; - gboolean windows_left; - - g_return_if_fail (HILDON_IS_STACKABLE_WINDOW (self)); - - /* List of windows in reverse order (starting from the topmost one) */ - windows = g_slist_reverse (g_slist_copy (get_window_list (GTK_WIDGET (self)))); - iter = windows; - - /* Destroy all the windows but the last one (which is the root - * window, as the list is reversed) */ - windows_left = (iter != NULL && iter->next != NULL); - while (windows_left) - { - if (HILDON_IS_STACKABLE_WINDOW (iter->data)) - { - GdkEvent *event; - HildonStackableWindow *win; - - /* Mark the window as "going home" */ - win = HILDON_STACKABLE_WINDOW (iter->data); - hildon_stackable_window_set_going_home (win, TRUE); - - /* Set win pointer to NULL if the window is destroyed */ - g_object_add_weak_pointer (G_OBJECT (win), (gpointer) &win); - - /* Send a delete event */ - event = gdk_event_new (GDK_DELETE); - event->any.window = g_object_ref (GTK_WIDGET (win)->window); - gtk_main_do_event (event); - gdk_event_free (event); - - /* Continue sending delete events if the window has been destroyed */ - if (win == NULL) - { - iter = iter->next; - windows_left = (iter != NULL && iter->next != NULL); - } - else - { - g_object_remove_weak_pointer (G_OBJECT (win), (gpointer) &win); - hildon_stackable_window_set_going_home (win, FALSE); - windows_left = FALSE; - } - } - else - { - g_warning ("Window list contains a non-stackable window"); - windows_left = FALSE; - } - } - - /* Show the last window that hasn't been destroyed */ - if (iter != NULL && GTK_IS_WIDGET (iter->data)) - { - gtk_widget_show (GTK_WIDGET (iter->data)); - } - - g_slist_free (windows); -} diff --git a/src/hildon-stackable-window.h b/src/hildon-stackable-window.h index b6ae032..ee180f8 100644 --- a/src/hildon-stackable-window.h +++ b/src/hildon-stackable-window.h @@ -80,9 +80,6 @@ hildon_stackable_window_get_type (void) G_GNUC_CONST; GtkWidget* hildon_stackable_window_new (void); -void -hildon_stackable_window_go_to_root_window (HildonStackableWindow* self); - G_END_DECLS #endif /* __HILDON_STACKABLE_WINDOW_H__ */