1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
/*
* This file is a part of hildon examples
*
* Copyright (C) 2008 Nokia Corporation, all rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#include <glib.h>
#include <gtk/gtk.h>
#include "hildon-program.h"
#include "hildon-stackable-window.h"
#include "hildon-touch-selector.h"
#include "hildon-picker-dialog.h"
#include "hildon-picker-button.h"
static GtkWidget *create_selector ();
static GtkWidget *get_visible_content (GtkWidget * window);
static GtkWindow *parent_window = NULL;
static GtkWidget *label = NULL;
static void
value_changed (HildonPickerButton * button,
gpointer user_data)
{
HildonTouchSelector *selector;
gchar *aux_string = NULL;
selector = hildon_picker_button_get_selector (button);
aux_string = hildon_touch_selector_get_current_text (selector);
gtk_label_set_text (GTK_LABEL (label), aux_string);
g_free (aux_string);
}
static GtkWidget *
create_selector ()
{
GtkWidget *selector = NULL;
GSList *icon_list = NULL;
GtkListStore *store_icons = NULL;
GSList *item = NULL;
GtkCellRenderer *renderer = NULL;
HildonTouchSelectorColumn *column = NULL;
selector = hildon_touch_selector_new ();
icon_list = gtk_stock_list_ids ();
store_icons = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
for (item = icon_list; item; item = g_slist_next (item)) {
GtkTreeIter iter;
GtkStockItem stock_item;
gchar *stock_id;
stock_id = (gchar *)item->data;
gtk_stock_lookup (stock_id, &stock_item);
gtk_list_store_append (store_icons, &iter);
gtk_list_store_set (store_icons, &iter, 0, stock_id, 1, stock_item.label, -1);
g_free (stock_id);
}
g_slist_free (icon_list);
column = hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector),
GTK_TREE_MODEL (store_icons),
NULL, NULL);
g_object_set (G_OBJECT(column), "text-column", 1, NULL);
renderer = gtk_cell_renderer_pixbuf_new ();
gtk_cell_renderer_set_fixed_size (renderer, 75, 75);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), renderer,
"stock-id", 0, NULL);
renderer = gtk_cell_renderer_text_new ();
g_object_set (renderer, "xalign", 0.5, NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), renderer,
"text", 1, NULL);
hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector),
HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
return selector;
}
static GtkWidget *
get_visible_content (GtkWidget * window)
{
GtkWidget *result = NULL;
GtkWidget *button = NULL;
GtkWidget *selector;
label = gtk_label_new ("Here we are going to put the selection");
button = hildon_picker_button_new (HILDON_SIZE_AUTO, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
hildon_button_set_title (HILDON_BUTTON (button), "Click me..");
selector = create_selector ();
hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
HILDON_TOUCH_SELECTOR (selector));
g_signal_connect (G_OBJECT (button), "value-changed",
G_CALLBACK (value_changed), window);
result = gtk_vbox_new (FALSE, 6);
gtk_container_add (GTK_CONTAINER (result), button);
gtk_container_add (GTK_CONTAINER (result), label);
return result;
}
int
main (int argc, char **args)
{
HildonProgram *program = NULL;
GtkWidget *window = NULL;
gtk_init (&argc, &args);
program = hildon_program_get_instance ();
g_set_application_name
("hildon-touch-selector cell renderer example program");
window = hildon_stackable_window_new ();
parent_window = GTK_WINDOW (window);
hildon_program_add_window (program, HILDON_WINDOW (window));
gtk_container_set_border_width (GTK_CONTAINER (window), 6);
gtk_rc_parse_string ("style \"fremantle-widget\" {\n"
" GtkWidget::hildon-mode = 1 \n"
"} widget \"*.fremantle-widget\" style \"fremantle-widget\"\n");
GtkWidget *vbox = get_visible_content (window);
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vbox));
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show_all (GTK_WIDGET (window));
gtk_main ();
return 0;
}
|