Make sure that all timeouts in HildonBanner are removed
[hildon] / examples / hildon-pannable-area-buttons-scroll-example.c
1 /*
2  * This file is a part of hildon examples
3  *
4  * Copyright (C) 2008 Nokia Corporation, all rights reserved.
5  *
6  * Based in hildon-pannable-area-example.c
7  * by Karl Lattimer <karl.lattimer@nokia.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; version 2.1 of
12  * the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23  *
24  */
25
26 #include                                        <hildon/hildon.h>
27
28 GtkWidget *btn;
29
30 static void
31 on_button_clicked (GtkWidget *widget, gpointer data)
32 {
33     g_debug ("Button %d clicked", GPOINTER_TO_INT (data));
34     btn = widget;
35 }
36
37 static void
38 find_button_clicked (GtkButton *button,
39                      gpointer user_data)
40 {
41         HildonPannableArea *panarea;
42
43         panarea = HILDON_PANNABLE_AREA (user_data);
44
45         hildon_pannable_area_scroll_to_child (panarea, btn);
46 }
47
48 int
49 main (int argc, char **argv)
50 {
51     int i;
52     HildonProgram *program;
53     GtkWidget *window, *panarea, *button;
54     GtkWidget *hbox, *vbox;
55
56     hildon_gtk_init (&argc, &argv);
57
58     program = hildon_program_get_instance ();
59
60     /* Create the main window */
61     window = hildon_window_new ();
62     hildon_program_add_window (program, HILDON_WINDOW (window));
63     gtk_container_set_border_width (GTK_CONTAINER (window), 5);
64
65     /* Create a VBox and pack some buttons */
66     vbox = gtk_vbox_new (FALSE, 1);
67     for (i = 0; i < 80; i++) {
68             gchar *label = g_strdup_printf ("Button number %d", i);
69
70             button = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
71             gtk_button_set_label (GTK_BUTTON (button), label);
72             gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
73             g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (on_button_clicked), GINT_TO_POINTER (i));
74             g_free (label);
75     }
76
77     /* Put everything in a pannable area */
78     panarea = hildon_pannable_area_new ();
79     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA (panarea), GTK_WIDGET (vbox));
80
81     vbox = gtk_vbox_new (FALSE, 10);
82     hbox = gtk_hbox_new (FALSE, 10);
83
84     button = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
85     gtk_button_set_label (GTK_BUTTON (button), "Find the latest clicked button");
86     g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (find_button_clicked), panarea);
87     gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
88
89     g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
90
91     gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 10);
92     gtk_box_pack_start (GTK_BOX (vbox), panarea, TRUE, TRUE, 0);
93
94     gtk_container_add (GTK_CONTAINER (window), vbox);
95
96     gtk_widget_show_all (GTK_WIDGET (window));
97
98     gtk_main ();
99
100     return 0;
101 }