2 * This file is a part of hildon examples
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * Based in hildon-pannable-area-example.c
7 * by Karl Lattimer <karl.lattimer@nokia.com>
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.
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.
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
35 on_button_clicked (GtkWidget *widget, gpointer data)
37 g_debug ("Button %d clicked", GPOINTER_TO_INT (data));
42 find_button_clicked (GtkButton *button,
45 HildonPannableArea *panarea;
47 panarea = HILDON_PANNABLE_AREA (user_data);
49 hildon_pannable_area_scroll_to_child (panarea, btn);
53 main (int argc, char **args)
56 HildonProgram *program;
57 GtkWidget *window, *panarea, *button;
58 GtkWidget *hbox, *vbox;
60 gtk_init (&argc, &args);
62 program = hildon_program_get_instance ();
64 /* Create the main window */
65 window = hildon_window_new ();
66 hildon_program_add_window (program, HILDON_WINDOW (window));
67 gtk_container_set_border_width (GTK_CONTAINER (window), 5);
69 /* Create a VBox and pack some buttons */
70 vbox = gtk_vbox_new (FALSE, 1);
71 for (i = 0; i < 80; i++) {
72 gchar *label = g_strdup_printf ("Button number %d", i);
74 button = gtk_button_new_with_label (label);
75 gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
76 g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (on_button_clicked), GINT_TO_POINTER (i));
80 /* Put everything in a pannable area */
81 panarea = hildon_pannable_area_new ();
82 hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA (panarea), GTK_WIDGET (vbox));
84 vbox = gtk_vbox_new (FALSE, 10);
85 hbox = gtk_hbox_new (FALSE, 10);
87 button = gtk_button_new_with_label ("Find the latest clicked button");
88 g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (find_button_clicked), panarea);
89 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
91 g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
93 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 10);
94 gtk_box_pack_start (GTK_BOX (vbox), panarea, TRUE, TRUE, 0);
96 gtk_container_add (GTK_CONTAINER (window), vbox);
98 gtk_widget_show_all (GTK_WIDGET (window));