2 * This file is a part of hildon examples
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; version 2.1 of
9 * the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 static gint global_stack_count = 1;
28 add_window (GtkWidget *button,
29 HildonStackableWindow *parent);
32 push_windows (GtkWidget *button,
36 pop_windows (GtkWidget *button,
40 new_window (HildonStackableWindow *parent)
42 GtkWidget *window, *hbbox, *vbox, *label, *add, *new;
43 GtkWidget *spin1hbox, *spin1label1, *spin1, *spin1label2, *pushbtn, *align1;
44 GtkWidget *spin2hbox, *spin2label1, *spin2, *spin2label2, *popbtn, *align2;
45 gint stack_number, win_number;
48 window = hildon_stackable_window_new ();
51 stack_number = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (parent), "stack-number"));
52 win_number = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (parent), "win-number")) + 1;
54 stack_number = global_stack_count++;
57 g_object_set_data (G_OBJECT (window), "stack-number", GINT_TO_POINTER (stack_number));
58 g_object_set_data (G_OBJECT (window), "win-number", GINT_TO_POINTER (win_number));
61 text = g_strdup_printf ("Stack number %d - window %d", stack_number, win_number);
62 gtk_window_set_title (GTK_WINDOW (window), text);
66 text = g_strdup_printf ("Stack number %d\nWindow number %d", stack_number, win_number);
67 label = gtk_label_new (text);
70 hbbox = gtk_hbutton_box_new ();
72 /* Button to push a window to the current stack */
73 add = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
74 gtk_button_set_label (GTK_BUTTON (add), "Add a window to this stack");
75 gtk_box_pack_start (GTK_BOX (hbbox), add, FALSE, FALSE, 0);
76 g_signal_connect (G_OBJECT (add), "clicked", G_CALLBACK (add_window), window);
78 /* Button to create a new stack */
79 new = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
80 gtk_button_set_label (GTK_BUTTON (new), "Add a window to a new stack");
81 gtk_box_pack_start (GTK_BOX (hbbox), new, FALSE, FALSE, 0);
82 g_signal_connect (G_OBJECT (new), "clicked", G_CALLBACK (add_window), NULL);
84 /* Spinbox and button to push many windows */
85 spin1hbox = gtk_hbox_new (FALSE, 0);
86 spin1label1 = gtk_label_new ("Push");
87 spin1 = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (2, 2, 5, 1, 1, 1)), 1, 0);
88 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin1), TRUE);
89 spin1label2 = gtk_label_new ("windows");
90 pushbtn = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
91 gtk_button_set_label (GTK_BUTTON (pushbtn), "Push windows");
92 gtk_box_pack_start (GTK_BOX (spin1hbox), spin1label1, FALSE, FALSE, 0);
93 gtk_box_pack_start (GTK_BOX (spin1hbox), spin1, FALSE, FALSE, 0);
94 gtk_box_pack_start (GTK_BOX (spin1hbox), spin1label2, FALSE, FALSE, 0);
95 gtk_box_pack_start (GTK_BOX (spin1hbox), pushbtn, FALSE, FALSE, 10);
96 align1 = gtk_alignment_new (0.5, 0.5, 0, 0);
97 gtk_container_add (GTK_CONTAINER (align1), spin1hbox);
98 g_signal_connect (G_OBJECT (pushbtn), "clicked", G_CALLBACK (push_windows), spin1);
100 /* Spinbox and button to pop many windows */
101 spin2hbox = gtk_hbox_new (FALSE, 0);
102 spin2label1 = gtk_label_new ("Pop");
103 spin2 = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (2, 2, 5, 1, 1, 1)), 1, 0);
104 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin2), TRUE);
105 spin2label2 = gtk_label_new ("windows");
106 popbtn = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
107 gtk_button_set_label (GTK_BUTTON (popbtn), "Pop windows");
108 gtk_box_pack_start (GTK_BOX (spin2hbox), spin2label1, FALSE, FALSE, 0);
109 gtk_box_pack_start (GTK_BOX (spin2hbox), spin2, FALSE, FALSE, 0);
110 gtk_box_pack_start (GTK_BOX (spin2hbox), spin2label2, FALSE, FALSE, 0);
111 gtk_box_pack_start (GTK_BOX (spin2hbox), popbtn, FALSE, FALSE, 10);
112 align2 = gtk_alignment_new (0.5, 0.5, 0, 0);
113 gtk_container_add (GTK_CONTAINER (align2), spin2hbox);
114 g_signal_connect (G_OBJECT (popbtn), "clicked", G_CALLBACK (pop_windows), spin2);
116 vbox = gtk_vbox_new (FALSE, 0);
117 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
118 gtk_box_pack_start (GTK_BOX (vbox), hbbox, FALSE, FALSE, 10);
119 gtk_box_pack_start (GTK_BOX (vbox), align1, FALSE, FALSE, 10);
120 gtk_box_pack_start (GTK_BOX (vbox), align2, FALSE, FALSE, 10);
122 gtk_container_set_border_width (GTK_CONTAINER (window), 6);
123 gtk_container_add (GTK_CONTAINER (window), vbox);
124 gtk_widget_show_all (vbox);
130 add_window (GtkWidget *button,
131 HildonStackableWindow *parent)
133 HildonWindowStack *stack = NULL;
137 stack = hildon_stackable_window_get_stack (parent);
139 stack = hildon_window_stack_new ();
142 window = new_window (parent);
145 stack = hildon_window_stack_get_default ();
147 hildon_window_stack_push_1 (stack, HILDON_STACKABLE_WINDOW (window));
151 push_windows (GtkWidget *button,
155 HildonWindowStack *stack = NULL;
156 HildonStackableWindow *parent;
157 gint nwindows = gtk_spin_button_get_value_as_int (spin);
159 parent = HILDON_STACKABLE_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (spin)));
160 stack = hildon_stackable_window_get_stack (parent);
162 while (nwindows > 0) {
163 parent = HILDON_STACKABLE_WINDOW (new_window (parent));
164 l = g_list_append (l, parent);
167 hildon_window_stack_push_list (stack, l);
172 pop_windows (GtkWidget *button,
175 HildonWindowStack *stack = NULL;
176 HildonStackableWindow *win;
177 gint nwindows = gtk_spin_button_get_value_as_int (spin);
179 win = HILDON_STACKABLE_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (spin)));
180 stack = hildon_stackable_window_get_stack (win);
182 hildon_window_stack_pop (stack, nwindows, NULL);
191 hildon_gtk_init (&argc, &argv);
193 g_set_application_name ("hildon-stackable-window-example");
195 window = new_window (NULL);
197 g_signal_connect (G_OBJECT (window), "destroy",
198 G_CALLBACK (gtk_main_quit), NULL);
200 gtk_widget_show (window);