2 * This file is a part of hildon examples
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * Author: Karl Lattimer <karl.lattimer@nokia.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, OPTIONAL_COLUMN, N_COLUMNS };
37 HiddenColContext *ctx;
40 horizontal_movement (HildonPannableArea *area,
41 HildonMovementDirection direction,
42 gdouble x, gdouble y, gpointer user_data)
47 GtkTreeViewColumn *col = GTK_TREE_VIEW_COLUMN (user_data);
48 GtkWidget *child = hildon_pannable_get_child_widget_at (area, x, y);
50 g_print ("widget %p treeview %p\n", child, ctx->treeview);
52 if (child == ctx->treeview) {
53 if (direction == HILDON_MOVEMENT_LEFT){
55 path = gtk_tree_path_new_first ();
57 gtk_tree_view_get_background_area (GTK_TREE_VIEW (ctx->treeview),
60 gtk_tree_view_convert_bin_window_to_tree_coords (GTK_TREE_VIEW (ctx->treeview),
61 rect.x, 0, &col_x, NULL);
63 gtk_tree_path_free (path);
65 hildon_pannable_area_scroll_to (area, col_x, -1);
68 hildon_pannable_area_scroll_to (area, 0, -1);
72 g_print ("horizontal_movement %lf, %lf\n", x, y);
76 vertical_movement (HildonPannableArea *area,
77 HildonMovementDirection direction,
81 g_print ("vertical_movement: %lf, %lf\n", x, y);
85 get_sawtooth_label (gchar **label, guint num)
87 static gchar *sawtooth = NULL;
88 gchar *label_aux, *sawtooth_aux;
91 sawtooth_aux = g_strconcat (" ", sawtooth, NULL);
94 sawtooth = sawtooth_aux;
96 sawtooth = g_strdup (" ");
99 label_aux = g_strconcat (sawtooth, *label, NULL);
106 main (int argc, char **args)
109 HildonProgram *program;
110 GtkWidget *window, *tv, *panarea;
111 GtkTreeViewColumn *col;
112 GtkCellRenderer *renderer;
115 gtk_init (&argc, &args);
117 program = hildon_program_get_instance ();
119 ctx = g_new0 (HiddenColContext, 1);
121 /* Create the main window */
122 window = hildon_window_new ();
123 hildon_program_add_window (program, HILDON_WINDOW (window));
125 gtk_container_set_border_width (GTK_CONTAINER (window), 5);
127 /* Create a treeview */
128 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_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
135 gtk_tree_view_column_set_fixed_width (col, 700);
137 gtk_tree_view_append_column (GTK_TREE_VIEW(tv), col);
139 col = gtk_tree_view_column_new_with_attributes ("Title", renderer, "text", OPTIONAL_COLUMN, NULL);
140 gtk_tree_view_append_column (GTK_TREE_VIEW(tv), col);
142 /* Add some rows to the treeview */
143 store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
144 for (i = 0; i < 100; i++) {
146 gchar *label = g_strdup_printf ("Row number %d", i);
147 gchar *label_optional = g_strdup_printf ("< >");
149 get_sawtooth_label (&label, i);
151 gtk_list_store_append (store, &iter);
152 gtk_list_store_set (store, &iter, TEXT_COLUMN, label, -1);
153 gtk_list_store_set (store, &iter, OPTIONAL_COLUMN, label_optional, -1);
155 g_free (label_optional);
157 gtk_tree_view_set_model (GTK_TREE_VIEW (tv), GTK_TREE_MODEL (store));
158 g_object_unref (store);
160 /* Put everything in a pannable area */
161 panarea = hildon_pannable_area_new ();
162 g_object_set (panarea, "mov_mode", HILDON_MOVEMENT_MODE_VERT,
164 "hscrollbar_policy", GTK_POLICY_NEVER, NULL);
166 gtk_container_add (GTK_CONTAINER (panarea), GTK_WIDGET (tv));
167 gtk_container_add (GTK_CONTAINER (window), panarea);
169 g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
171 g_signal_connect (G_OBJECT (panarea), "horizontal_movement", G_CALLBACK (horizontal_movement), col);
172 g_signal_connect (G_OBJECT (panarea), "vertical_movement", G_CALLBACK (vertical_movement), NULL);
174 gtk_widget_show_all (GTK_WIDGET (window));