Make sure that all timeouts in HildonBanner are removed
[hildon] / examples / hildon-pannable-area-initial-hint-example.c
1 /*
2  * This file is a part of hildon examples
3  *
4  * Copyright (C) 2009 Nokia Corporation, all rights reserved.
5  *
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #include                                        <stdio.h>
25 #include                                        <stdlib.h>
26 #include                                        <glib.h>
27 #include                                        <gtk/gtk.h>
28 #include                                        <string.h>
29 #include                                        <hildon/hildon.h>
30
31 enum { TEXT_COLUMN, N_COLUMNS };
32
33 static void
34 on_add_clicked (GtkButton *button,
35                 gpointer user_data)
36 {
37   GtkListStore *store = NULL;
38   GtkTreeIter   iter;
39
40   store = GTK_LIST_STORE (user_data);
41
42   gtk_list_store_append (store, &iter);
43   gtk_list_store_set (store, &iter,
44                       TEXT_COLUMN, "Extra row", -1);
45 }
46
47 static void
48 on_remove_clicked (GtkButton *button,
49                    gpointer user_data)
50 {
51   GtkListStore *store = NULL;
52   GtkTreeIter   iter;
53
54   store = GTK_LIST_STORE (user_data);
55
56   if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store),
57                                      &iter)) {
58     gtk_list_store_remove (store, &iter);
59   }
60 }
61
62
63 static GtkWidget*
64 create_content ()
65 {
66   gint               i;
67   GtkWidget         *tv       = NULL;
68   GtkWidget         *panarea  = NULL;
69   GtkWidget         *button   = NULL;;
70   GtkTreeViewColumn *col      = NULL;
71   GtkCellRenderer   *renderer = NULL;
72   GtkListStore      *store    = NULL;
73   GtkWidget         *vbox     = NULL;
74
75   /* Create a treeview */
76 #ifdef MAEMO_GTK
77   tv = hildon_gtk_tree_view_new (HILDON_UI_MODE_NORMAL);
78 #else
79   tv = GTK_TREE_VIEW (gtk_tree_view_new ());
80 #endif /* MAEMO_GTK */
81
82   renderer = gtk_cell_renderer_text_new ();
83   g_object_set (renderer, "width", 1, "xalign", 0.5, NULL);
84
85   col = gtk_tree_view_column_new ();
86   gtk_tree_view_column_set_title (col, "Title");
87
88   gtk_tree_view_column_pack_start (col, renderer, TRUE);
89   gtk_tree_view_column_set_attributes (col, renderer, "text", TEXT_COLUMN, NULL);
90
91   gtk_tree_view_append_column (GTK_TREE_VIEW (tv), col);
92
93   /* Add some rows to the treeview */
94   store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
95
96   for (i = 0; i < 6; i++) {
97     GtkTreeIter iter;
98
99     gtk_list_store_append (store, &iter);
100     gtk_list_store_set (store, &iter,
101                         TEXT_COLUMN, "One row", -1);
102   }
103
104   gtk_tree_view_set_model (GTK_TREE_VIEW (tv), GTK_TREE_MODEL (store));
105   g_object_unref (store);
106
107   /* Put everything in a pannable area */
108   panarea = hildon_pannable_area_new ();
109   gtk_container_add (GTK_CONTAINER (panarea), GTK_WIDGET (tv));
110
111   vbox = gtk_vbox_new (FALSE, 5);
112
113   button = gtk_button_new_with_label ("Add a row");
114   g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (on_add_clicked), store);
115   gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
116
117   button = gtk_button_new_with_label ("Remove a row");
118   g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (on_remove_clicked), store);
119   gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
120
121   gtk_box_pack_start (GTK_BOX (vbox), panarea, TRUE, TRUE, 6);
122
123   return vbox;
124 }
125
126 int
127 main (int argc, char **argv)
128 {
129   HildonProgram *program = NULL;
130   GtkWidget     *window  = NULL;
131   GtkWidget     *content = NULL;
132
133   hildon_gtk_init (&argc, &argv);
134
135   program = hildon_program_get_instance ();
136
137   /* Create the main window */
138   window = hildon_window_new ();
139   hildon_program_add_window (program, HILDON_WINDOW (window));
140   gtk_container_set_border_width (GTK_CONTAINER (window), 5);
141
142   content = create_content ();
143
144   gtk_container_add (GTK_CONTAINER (window), content);
145
146   g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
147
148   gtk_widget_show_all (GTK_WIDGET (window));
149
150   gtk_main ();
151
152   return 0;
153 }