2 * This file is a part of hildon examples
4 * Copyright (C) 2009 Nokia Corporation, all rights reserved.
6 * Author: Alejandro Pinheiro <apinheiro@igalia.com>
7 * Based on hildon-touch-selector-example.c
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
28 #include <hildon/hildon.h>
30 static GtkWidget *create_selector ();
31 static GtkWidget *get_visible_content (GtkWidget * window);
33 static GtkWindow *parent_window = NULL;
35 static GtkWidget *label = NULL;
38 value_changed (HildonPickerButton * button,
41 HildonTouchSelector *selector;
42 gchar *aux_string = NULL;
43 GtkTreePath *path = NULL;
44 GtkTreeModel *model = NULL;
47 selector = hildon_picker_button_get_selector (button);
48 model = hildon_touch_selector_get_model (selector, 0);
49 path = hildon_touch_selector_get_last_activated_row (selector, 0);
52 gtk_tree_model_get_iter (model, &iter, path);
53 gtk_tree_model_get (model, &iter, 0, &aux_string, -1);
55 gtk_label_set_text (GTK_LABEL (label), aux_string);
58 gtk_tree_path_free (path);
64 GtkWidget *selector = NULL;
65 GSList *icon_list = NULL;
66 GtkListStore *store_icons = NULL;
68 GtkCellRenderer *renderer = NULL;
69 HildonTouchSelectorColumn *column = NULL;
71 selector = hildon_touch_selector_new ();
73 icon_list = gtk_stock_list_ids ();
75 store_icons = gtk_list_store_new (1, G_TYPE_STRING);
76 for (item = icon_list; item; item = g_slist_next (item)) {
78 gchar *label = item->data;
80 gtk_list_store_append (store_icons, &iter);
81 gtk_list_store_set (store_icons, &iter, 0, label, -1);
84 g_slist_free (icon_list);
86 renderer = gtk_cell_renderer_pixbuf_new ();
87 gtk_cell_renderer_set_fixed_size (renderer, -1, 100);
89 column = hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector),
90 GTK_TREE_MODEL (store_icons),
91 renderer, "stock-id", 0, NULL);
92 g_object_set (G_OBJECT (column), "text-column", 0, NULL);
94 hildon_touch_selector_set_hildon_ui_mode (HILDON_TOUCH_SELECTOR (selector),
95 HILDON_UI_MODE_NORMAL);
102 get_visible_content (GtkWidget * window)
104 GtkWidget *result = NULL;
105 GtkWidget *button = NULL;
108 label = gtk_label_new ("Here we are going to put the selection");
110 button = hildon_picker_button_new (HILDON_SIZE_AUTO, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
111 hildon_button_set_title (HILDON_BUTTON (button), "Click me..");
112 selector = create_selector ();
113 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
114 HILDON_TOUCH_SELECTOR (selector));
116 g_signal_connect (G_OBJECT (button), "value-changed",
117 G_CALLBACK (value_changed), window);
119 result = gtk_vbox_new (FALSE, 6);
121 gtk_container_add (GTK_CONTAINER (result), button);
122 gtk_container_add (GTK_CONTAINER (result), label);
128 main (int argc, char **argv)
130 HildonProgram *program = NULL;
131 GtkWidget *window = NULL;
133 hildon_gtk_init (&argc, &argv);
135 program = hildon_program_get_instance ();
136 g_set_application_name
137 ("hildon-touch-selector normal mode example");
139 window = hildon_stackable_window_new ();
140 parent_window = GTK_WINDOW (window);
141 hildon_program_add_window (program, HILDON_WINDOW (window));
143 gtk_container_set_border_width (GTK_CONTAINER (window), 6);
145 GtkWidget *vbox = get_visible_content (window);
147 gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vbox));
149 g_signal_connect (G_OBJECT (window), "destroy",
150 G_CALLBACK (gtk_main_quit), NULL);
151 gtk_widget_show_all (GTK_WIDGET (window));