2 * This file is a part of hildon examples
4 * Copyright (C) 2009 Nokia Corporation, all rights reserved.
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.
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.
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
29 #include <hildon/hildon.h>
31 enum { TEXT_COLUMN, N_COLUMNS };
34 on_add_clicked (GtkButton *button,
37 GtkListStore *store = NULL;
40 store = GTK_LIST_STORE (user_data);
42 gtk_list_store_append (store, &iter);
43 gtk_list_store_set (store, &iter,
44 TEXT_COLUMN, "Extra row", -1);
48 on_remove_clicked (GtkButton *button,
51 GtkListStore *store = NULL;
54 store = GTK_LIST_STORE (user_data);
56 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store),
58 gtk_list_store_remove (store, &iter);
68 GtkWidget *panarea = NULL;
69 GtkWidget *button = NULL;;
70 GtkTreeViewColumn *col = NULL;
71 GtkCellRenderer *renderer = NULL;
72 GtkListStore *store = NULL;
73 GtkWidget *vbox = NULL;
75 /* Create a treeview */
77 tv = hildon_gtk_tree_view_new (HILDON_UI_MODE_NORMAL);
79 tv = GTK_TREE_VIEW (gtk_tree_view_new ());
80 #endif /* MAEMO_GTK */
82 renderer = gtk_cell_renderer_text_new ();
83 g_object_set (renderer, "width", 1, "xalign", 0.5, NULL);
85 col = gtk_tree_view_column_new ();
86 gtk_tree_view_column_set_title (col, "Title");
88 gtk_tree_view_column_pack_start (col, renderer, TRUE);
89 gtk_tree_view_column_set_attributes (col, renderer, "text", TEXT_COLUMN, NULL);
91 gtk_tree_view_append_column (GTK_TREE_VIEW (tv), col);
93 /* Add some rows to the treeview */
94 store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
96 for (i = 0; i < 6; i++) {
99 gtk_list_store_append (store, &iter);
100 gtk_list_store_set (store, &iter,
101 TEXT_COLUMN, "One row", -1);
104 gtk_tree_view_set_model (GTK_TREE_VIEW (tv), GTK_TREE_MODEL (store));
105 g_object_unref (store);
107 /* Put everything in a pannable area */
108 panarea = hildon_pannable_area_new ();
109 gtk_container_add (GTK_CONTAINER (panarea), GTK_WIDGET (tv));
111 vbox = gtk_vbox_new (FALSE, 5);
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);
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);
121 gtk_box_pack_start (GTK_BOX (vbox), panarea, TRUE, TRUE, 6);
127 main (int argc, char **argv)
129 HildonProgram *program = NULL;
130 GtkWidget *window = NULL;
131 GtkWidget *content = NULL;
133 hildon_gtk_init (&argc, &argv);
135 program = hildon_program_get_instance ();
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);
142 content = create_content ();
144 gtk_container_add (GTK_CONTAINER (window), content);
146 g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
148 gtk_widget_show_all (GTK_WIDGET (window));