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
31 #include <hildon/hildon.h>
33 enum { PIXBUF_COLUMN, TEXT_COLUMN, N_COLUMNS };
36 GtkWidget *scroll_entry;
37 GtkWidget *jump_entry;
45 search_button_clicked (GtkButton *button,
56 gboolean jump_or_scroll;
58 jump_or_scroll = *((gboolean *) user_data);
62 s1 = gtk_entry_get_text (GTK_ENTRY (ctx->scroll_entry));
66 s1 = gtk_entry_get_text (GTK_ENTRY (ctx->jump_entry));
69 model = gtk_tree_view_get_model (GTK_TREE_VIEW (ctx->treeview));
71 gtk_tree_model_get_iter_first (model, &iter);
74 gtk_tree_model_get (model, &iter, TEXT_COLUMN, &s2, -1);
75 found = (strcmp (s1, s2) == 0);
77 } while (found != TRUE && gtk_tree_model_iter_next (model, &iter));
80 GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW (ctx->treeview));
82 path = gtk_tree_model_get_path (model, &iter);
84 gtk_tree_view_get_background_area (GTK_TREE_VIEW (ctx->treeview),
86 gtk_tree_view_convert_bin_window_to_tree_coords (GTK_TREE_VIEW (ctx->treeview),
88 g_print ("text found in (0, %d)\n", y);
90 gtk_tree_selection_select_path (selection, path);
93 hildon_pannable_area_scroll_to (HILDON_PANNABLE_AREA (ctx->panarea),
98 hildon_pannable_area_jump_to (HILDON_PANNABLE_AREA (ctx->panarea),
102 gtk_tree_path_free (path);
107 main (int argc, char **argv)
110 HildonProgram *program;
111 GtkWidget *window, *tv, *panarea, *button;
112 GtkTreeViewColumn *col;
113 GtkCellRenderer *renderer;
115 GtkWidget *hbox, *vbox;
117 gboolean scroll = TRUE;
118 gboolean jump = FALSE;
119 GSList *stocks, *item;
121 hildon_gtk_init (&argc, &argv);
123 program = hildon_program_get_instance ();
125 /* Create the main window */
126 window = hildon_window_new ();
127 hildon_program_add_window (program, HILDON_WINDOW (window));
128 gtk_container_set_border_width (GTK_CONTAINER (window), 5);
130 /* Create a treeview */
131 tv = gtk_tree_view_new ();
133 col = gtk_tree_view_column_new ();
134 gtk_tree_view_column_set_title (col, "Title");
136 renderer = gtk_cell_renderer_pixbuf_new ();
137 gtk_cell_renderer_set_fixed_size (renderer, 48, 48);
138 gtk_tree_view_column_pack_start (col, renderer, FALSE);
139 gtk_tree_view_column_set_attributes (col, renderer, "stock-id", PIXBUF_COLUMN, NULL);
141 renderer = gtk_cell_renderer_text_new ();
142 gtk_tree_view_column_pack_start (col, renderer, FALSE);
143 gtk_tree_view_column_set_attributes (col, renderer, "text", TEXT_COLUMN, NULL);
144 gtk_tree_view_append_column (GTK_TREE_VIEW(tv), col);
146 /* Add some rows to the treeview */
147 stocks = gtk_stock_list_ids ();
149 store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
150 for (i = 0; i < 100; i++) {
152 GtkStockItem stock_item;
155 stock_id = (gchar *)item->data;
156 gtk_stock_lookup (stock_id, &stock_item);
157 gtk_list_store_append (store, &iter);
158 gtk_list_store_set (store, &iter, PIXBUF_COLUMN, stock_id, TEXT_COLUMN, stock_item.label, -1);
160 item = item->next? item->next : stocks;
162 gtk_tree_view_set_model (GTK_TREE_VIEW (tv), GTK_TREE_MODEL (store));
163 g_object_unref (store);
165 g_slist_foreach (stocks, (GFunc)g_free, NULL);
166 g_slist_free (stocks);
168 /* Put everything in a pannable area */
169 panarea = hildon_pannable_area_new ();
170 gtk_container_add (GTK_CONTAINER (panarea), GTK_WIDGET (tv));
172 ctx = g_new0 (SearchContext, 1);
174 vbox = gtk_vbox_new (FALSE, 5);
175 hbox = gtk_hbox_new (FALSE, 5);
176 button = gtk_button_new_from_stock (GTK_STOCK_FIND);
178 entry = gtk_entry_new ();
179 gtk_entry_set_text (GTK_ENTRY (entry), "Enter some text to scroll");
181 g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (search_button_clicked), &scroll);
183 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
184 gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
185 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 10);
187 ctx->scroll_entry = entry;
189 hbox = gtk_hbox_new (FALSE, 5);
190 button = gtk_button_new_from_stock (GTK_STOCK_FIND);
192 entry = gtk_entry_new ();
193 gtk_entry_set_text (GTK_ENTRY (entry), "Enter some text to jump");
195 g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (search_button_clicked), &jump);
197 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
198 gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
199 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 10);
201 ctx->jump_entry = entry;
203 ctx->panarea = panarea;
205 g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
207 gtk_box_pack_start (GTK_BOX (vbox), panarea, TRUE, TRUE, 0);
209 gtk_container_add (GTK_CONTAINER (window), vbox);
211 gtk_widget_show_all (GTK_WIDGET (window));