2008-10-06 Claudio Saavedra <csaavedra@igalia.com>
[hildon] / examples / hildon-stackable-window-example.c
1 /*
2  * This file is a part of hildon examples
3  *
4  * Copyright (C) 2008 Nokia Corporation, all rights reserved.
5  *
6  * Author: Karl Lattimer <karl.lattimer@nokia.com>
7  *
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.
12  *
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.
17  *
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
21  * 02110-1301 USA
22  *
23  */
24
25 #include                                        <stdio.h>
26 #include                                        <stdlib.h>
27 #include                                        <glib.h>
28 #include                                        <gtk/gtk.h>
29 #include                                        "hildon.h"
30
31 #include                                        <X11/X.h>
32 #include                                        <X11/Xlib.h>
33 #include                                        <X11/Xatom.h>
34
35 static void
36 add_window                                      (GtkWidget* w);
37
38 static GtkWidget*
39 new_window                                      (gboolean ismain)
40 {
41     GtkWidget *window, *hbbox, *add;
42     static int count = 0;
43     gchar* title;
44
45     window = hildon_stackable_window_new ();
46
47     if (count == 0)
48         title = g_strdup ("main window");
49     else
50         title = g_strdup_printf ("win%d", count);
51
52     gtk_window_set_title (GTK_WINDOW (window), title);
53     g_free (title);
54
55     count++;
56
57     gtk_container_set_border_width (GTK_CONTAINER (window), 6);
58
59     hbbox = gtk_hbutton_box_new ();
60     gtk_container_add (GTK_CONTAINER (window), hbbox);
61
62     add = gtk_button_new_with_label ("Add a window");
63     gtk_box_pack_start (GTK_BOX (hbbox), add, FALSE, FALSE, 0);
64
65     g_signal_connect (G_OBJECT (add), "clicked", G_CALLBACK (add_window), NULL);
66
67     if (!ismain)
68     {
69         GtkWidget *detach, *back;
70         detach = GTK_WIDGET (gtk_button_new_with_label ("Destroy"));
71         gtk_box_pack_end (GTK_BOX (hbbox), detach, FALSE, FALSE, 0);
72
73         g_signal_connect_swapped (G_OBJECT (detach), "clicked",
74                                   G_CALLBACK (gtk_widget_destroy),
75                                   HILDON_STACKABLE_WINDOW (window));
76
77         back = GTK_WIDGET (gtk_button_new_with_label ("Back to root"));
78         gtk_box_pack_end (GTK_BOX (hbbox), back, FALSE, FALSE, 0);
79
80         g_signal_connect_swapped (G_OBJECT (back), "clicked",
81                                   G_CALLBACK (hildon_program_go_to_root_window),
82                                   hildon_program_get_instance ());
83     }
84
85     return window;
86 }
87
88 static void
89 add_window                                      (GtkWidget *w)
90 {
91     GtkWidget *window = new_window (FALSE);
92     gtk_widget_show_all (window);
93
94     return;
95 }
96
97 int
98 main                                            (int argc,
99                                                  char **args)
100 {
101     GtkWidget *window;
102
103     gtk_init (&argc, &args);
104
105     g_set_application_name ("stack");
106
107     window = new_window (TRUE);
108
109     g_signal_connect (G_OBJECT (window), "delete_event",
110                       G_CALLBACK (gtk_main_quit), NULL);
111
112     gtk_widget_show_all (GTK_WIDGET (window));
113
114     gtk_main ();
115
116     return 0;
117 }