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
33 enum { 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 **args)
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;
120 gtk_init (&argc, &args);
122 program = hildon_program_get_instance ();
124 /* Create the main window */
125 window = hildon_window_new ();
126 hildon_program_add_window (program, HILDON_WINDOW (window));
127 gtk_container_set_border_width (GTK_CONTAINER (window), 5);
129 /* Create a treeview */
130 tv = gtk_tree_view_new ();
131 renderer = gtk_cell_renderer_text_new ();
132 col = gtk_tree_view_column_new_with_attributes ("Title", renderer, "text", TEXT_COLUMN, NULL);
133 gtk_tree_view_append_column (GTK_TREE_VIEW(tv), col);
135 /* Add some rows to the treeview */
136 store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
137 for (i = 0; i < 100; i++) {
139 gchar *label = g_strdup_printf ("Row %d", i);
140 gtk_list_store_append (store, &iter);
141 gtk_list_store_set (store, &iter, TEXT_COLUMN, label, -1);
144 gtk_tree_view_set_model (GTK_TREE_VIEW (tv), GTK_TREE_MODEL (store));
145 g_object_unref (store);
147 /* Put everything in a pannable area */
148 panarea = hildon_pannable_area_new ();
149 gtk_container_add (GTK_CONTAINER (panarea), GTK_WIDGET (tv));
151 ctx = g_new0 (SearchContext, 1);
153 vbox = gtk_vbox_new (FALSE, 5);
154 hbox = gtk_hbox_new (FALSE, 5);
155 button = gtk_button_new_from_stock (GTK_STOCK_FIND);
157 entry = gtk_entry_new ();
158 gtk_entry_set_text (GTK_ENTRY (entry), "Enter some text to scroll");
160 g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (search_button_clicked), &scroll);
162 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
163 gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
164 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 10);
166 ctx->scroll_entry = entry;
168 hbox = gtk_hbox_new (FALSE, 5);
169 button = gtk_button_new_from_stock (GTK_STOCK_FIND);
171 entry = gtk_entry_new ();
172 gtk_entry_set_text (GTK_ENTRY (entry), "Enter some text to jump");
174 g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (search_button_clicked), &jump);
176 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
177 gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
178 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 10);
180 ctx->jump_entry = entry;
182 ctx->panarea = panarea;
184 g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
186 gtk_box_pack_start (GTK_BOX (vbox), panarea, TRUE, TRUE, 0);
188 gtk_container_add (GTK_CONTAINER (window), vbox);
190 gtk_widget_show_all (GTK_WIDGET (window));