2 * This file is a part of hildon
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * SECTION:hildon-stackable-window
27 * @short_description: Stackable top-level window in the Hildon framework.
28 * @see_also: #HildonWindowStack, #HildonProgram, #HildonWindow
30 * The #HildonStackableWindow is a
31 * top-level window that can be stacked in a #HildonWindowStack. It is derived
32 * from #HildonWindow. Applications that use stackable windows are organized
33 * in a hierarchical way so users can go from any window back to the
34 * application's root window.
36 * The user can only see and interact with the window on top of the
37 * stack. Although all other windows are mapped and visible, they are
38 * obscured by the topmost one so in practice they appear as if they
41 * To add a window to the stack, just use gtk_widget_show(). The
42 * previous one will be obscured by the new one. When the new window
43 * is destroyed, the previous one will appear again.
45 * Alternatively, you can remove a window from the top of the stack
46 * without destroying it by using hildon_window_stack_pop(). The
47 * window will be automatically hidden and the previous one will
50 * For advanced details on stack handling, see #HildonWindowStack
53 * <title>Basic HildonStackableWindow example</title>
56 * show_new_window (void)
60 * win = hildon_stackable_window_new ();
62 * // ... configure new window
64 * gtk_widget_show (win);
68 * main (int argc, char **argv)
73 * gtk_init (&argc, &args);
75 * win = hildon_stackable_window_new ();
76 * gtk_window_set_title (GTK_WINDOW (win), "Main window);
78 * // ... add some widgets to the window
80 * g_signal_connect (button, "clicked", G_CALLBACK (show_new_window), NULL);
81 * g_signal_connect (win, "destroy", G_CALLBACK (gtk_main_quit), NULL);
83 * gtk_widget_show_all (win);
92 #undef HILDON_DISABLE_DEPRECATED
95 #include <X11/Xatom.h>
98 #include "hildon-stackable-window.h"
99 #include "hildon-stackable-window-private.h"
100 #include "hildon-window-stack.h"
101 #include "hildon-window-stack-private.h"
103 G_DEFINE_TYPE (HildonStackableWindow, hildon_stackable_window, HILDON_TYPE_WINDOW);
106 hildon_stackable_window_set_stack (HildonStackableWindow *self,
107 HildonWindowStack *stack,
110 HildonStackableWindowPrivate *priv = HILDON_STACKABLE_WINDOW_GET_PRIVATE (self);
113 g_object_ref (stack);
116 g_object_unref (priv->stack);
119 priv->stack_position = position;
123 * hildon_stackable_window_get_stack:
124 * @self: a #HildonStackableWindow
126 * Returns the stack where window @self is on, or %NULL if the window
129 * Return value: a #HildonWindowStack, or %NULL
134 hildon_stackable_window_get_stack (HildonStackableWindow *self)
136 HildonStackableWindowPrivate *priv;
138 g_return_val_if_fail (HILDON_IS_STACKABLE_WINDOW (self), NULL);
140 priv = HILDON_STACKABLE_WINDOW_GET_PRIVATE (self);
146 * hildon_stackable_window_set_main_menu:
147 * @self: a #HildonStackableWindow
148 * @menu: a #HildonAppMenu to be used for this window
150 * Sets the menu to be used for this window.
152 * Deprecated: Hildon 2.2: use hildon_window_set_app_menu()
155 hildon_stackable_window_set_main_menu (HildonStackableWindow *self,
158 hildon_window_set_app_menu (HILDON_WINDOW (self), menu);
162 hildon_stackable_window_map (GtkWidget *widget)
167 HildonStackableWindowPrivate *priv = HILDON_STACKABLE_WINDOW_GET_PRIVATE (widget);
169 val = priv->stack_position;
171 /* Set additional property "_HILDON_STACKABLE_WINDOW", to allow the WM to manage
172 it as a stackable window. */
173 display = gdk_drawable_get_display (widget->window);
174 atom = gdk_x11_get_xatom_by_name_for_display (display, "_HILDON_STACKABLE_WINDOW");
175 XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (widget->window), atom,
176 XA_INTEGER, 32, PropModeReplace,
177 (unsigned char *) &val, 1);
179 GTK_WIDGET_CLASS (hildon_stackable_window_parent_class)->map (widget);
183 hildon_stackable_window_show (GtkWidget *widget)
185 HildonStackableWindowPrivate *priv = HILDON_STACKABLE_WINDOW_GET_PRIVATE (widget);
187 /* Stack the window if not already stacked */
188 if (priv->stack == NULL) {
189 HildonWindowStack *stack = hildon_window_stack_get_default ();
190 _hildon_window_stack_do_push (stack, HILDON_STACKABLE_WINDOW (widget));
193 GTK_WIDGET_CLASS (hildon_stackable_window_parent_class)->show (widget);
197 hildon_stackable_window_hide (GtkWidget *widget)
199 HildonStackableWindowPrivate *priv = HILDON_STACKABLE_WINDOW_GET_PRIVATE (widget);
202 hildon_window_stack_remove (HILDON_STACKABLE_WINDOW (widget));
205 GTK_WIDGET_CLASS (hildon_stackable_window_parent_class)->hide (widget);
209 hildon_stackable_window_delete_event (GtkWidget *widget,
212 HildonStackableWindowPrivate *priv = HILDON_STACKABLE_WINDOW_GET_PRIVATE (widget);
213 gboolean retvalue = FALSE;
215 if (priv->stack && hildon_window_stack_peek (priv->stack) != widget) {
216 /* Ignore the delete event if this window is not the topmost one */
218 } else if (GTK_WIDGET_CLASS (hildon_stackable_window_parent_class)->delete_event) {
219 retvalue = GTK_WIDGET_CLASS (hildon_stackable_window_parent_class)->delete_event (widget, event);
226 hildon_stackable_window_class_init (HildonStackableWindowClass *klass)
228 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
230 widget_class->map = hildon_stackable_window_map;
231 widget_class->show = hildon_stackable_window_show;
232 widget_class->hide = hildon_stackable_window_hide;
233 widget_class->delete_event = hildon_stackable_window_delete_event;
235 g_type_class_add_private (klass, sizeof (HildonStackableWindowPrivate));
239 hildon_stackable_window_init (HildonStackableWindow *self)
241 HildonStackableWindowPrivate *priv = HILDON_STACKABLE_WINDOW_GET_PRIVATE (self);
244 priv->stack_position = -1;
248 * hildon_stackable_window_new:
250 * Creates a new #HildonStackableWindow.
252 * Return value: A #HildonStackableWindow
257 hildon_stackable_window_new (void)
259 HildonStackableWindow *newwindow = g_object_new (HILDON_TYPE_STACKABLE_WINDOW, NULL);
261 return GTK_WIDGET (newwindow);