2 * This file is a part of hildon examples
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * Author: Alberto Garcia <agarcia@igalia.com>
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.
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.
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
31 enum { TEXT_COLUMN, N_COLUMNS };
34 on_button_clicked (GtkWidget *widget, gpointer data)
36 g_debug ("Button %d clicked", GPOINTER_TO_INT (data));
40 main (int argc, char **args)
43 HildonProgram *program;
44 GtkWidget *window, *tv, *panarea;
45 GtkTreeViewColumn *col;
46 GtkCellRenderer *renderer;
50 gtk_init (&argc, &args);
52 program = hildon_program_get_instance ();
54 /* Create the main window */
55 window = hildon_window_new ();
56 hildon_program_add_window (program, HILDON_WINDOW (window));
58 gtk_container_set_border_width (GTK_CONTAINER (window), 5);
60 /* Create a VBox and pack some buttons */
61 vbox = GTK_VBOX (gtk_vbox_new (FALSE, 1));
62 for (i = 0; i < 30; i++) {
63 gchar *label = g_strdup_printf ("Button number %d", i);
64 GtkWidget *but = gtk_button_new_with_label (label);
65 gtk_box_pack_start (GTK_BOX (vbox), but, TRUE, TRUE, 0);
66 g_signal_connect (G_OBJECT (but), "clicked", G_CALLBACK (on_button_clicked), GINT_TO_POINTER (i));
70 /* Create a treeview */
71 tv = gtk_tree_view_new ();
72 renderer = gtk_cell_renderer_text_new ();
73 col = gtk_tree_view_column_new_with_attributes ("Title", renderer, "text", TEXT_COLUMN, NULL);
74 gtk_tree_view_append_column (GTK_TREE_VIEW(tv), col);
76 /* Add some rows to the treeview */
77 store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
78 for (i = 0; i < 100; i++) {
80 gchar *label = g_strdup_printf ("Row number %d", i);
81 gtk_list_store_append (store, &iter);
82 gtk_list_store_set (store, &iter, TEXT_COLUMN, label, -1);
85 gtk_tree_view_set_model (GTK_TREE_VIEW (tv), GTK_TREE_MODEL (store));
86 g_object_unref (store);
88 /* Pack the treeview in the VBox */
89 gtk_box_pack_start (GTK_BOX (vbox), tv, TRUE, TRUE, 0);
91 /* Put everything in a pannable area */
92 panarea = hildon_pannable_area_new ();
93 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (panarea), GTK_WIDGET (vbox));
94 gtk_container_add (GTK_CONTAINER (window), panarea);
96 g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
98 gtk_widget_show_all (GTK_WIDGET (window));