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 * Based on testhildoniconview.c by Kristian Rietveld <kris@imendio.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; version 2.1 of
13 * the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 #include <hildon/hildon.h>
32 MULTI_SELECT = 1 << 0,
44 store = gtk_list_store_new (1, G_TYPE_STRING);
46 for (i = 0; i < 50; i++)
50 str = g_strdup_printf ("\nRow %d\n", i);
51 gtk_list_store_insert_with_values (store, NULL, i, 0, str, -1);
55 return GTK_TREE_MODEL (store);
59 item_activated_callback (GtkWidget *icon_view,
63 g_print ("item-activated emitted.\n");
67 create_icon_view (HildonUIMode mode,
69 gboolean multi_select)
72 GtkCellRenderer *renderer;
75 if (name && g_str_equal (name, "fremantle-widget"))
76 icon_view = hildon_gtk_icon_view_new (mode);
78 icon_view = gtk_icon_view_new ();
81 gtk_widget_set_name (icon_view, name);
83 model = create_model ();
84 gtk_icon_view_set_model (GTK_ICON_VIEW (icon_view), model);
85 g_object_unref (model);
88 gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
89 GTK_SELECTION_MULTIPLE);
90 else if (mode != HILDON_UI_MODE_NORMAL)
91 gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
92 GTK_SELECTION_SINGLE);
94 renderer = gtk_cell_renderer_pixbuf_new ();
95 g_object_set (renderer, "stock-id", GTK_STOCK_NEW, NULL);
96 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view),
100 renderer = gtk_cell_renderer_text_new ();
101 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view),
104 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
113 create_icon_view_window (GtkWidget *button,
119 GtkWidget *icon_view;
120 HildonUIMode mode = 0;
122 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
123 g_signal_connect (window, "delete-event",
124 G_CALLBACK (gtk_widget_destroy), window);
125 gtk_container_set_border_width (GTK_CONTAINER (window), 6);
127 sw = hildon_pannable_area_new ();
128 gtk_container_add (GTK_CONTAINER (window), sw);
130 if ((GPOINTER_TO_INT (user_data) & NORMAL_MODE) == NORMAL_MODE)
132 mode = HILDON_UI_MODE_NORMAL;
133 name = "fremantle-widget";
135 else if ((GPOINTER_TO_INT (user_data) & EDIT_MODE) == EDIT_MODE)
137 mode = HILDON_UI_MODE_EDIT;
138 name = "fremantle-widget";
143 icon_view = create_icon_view (mode, name,
144 (GPOINTER_TO_INT (user_data) & MULTI_SELECT) == MULTI_SELECT);
146 /* Some signals doing printfs() to see if the behavior is correct. */
147 g_signal_connect (icon_view, "item-activated",
148 G_CALLBACK (item_activated_callback), NULL);
150 gtk_widget_set_size_request (icon_view, 480, 800);
151 gtk_container_add (GTK_CONTAINER (sw), icon_view);
153 gtk_widget_show_all (window);
157 main (int argc, char **argv)
166 hildon_gtk_init (&argc, &argv);
168 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
169 g_signal_connect (window, "delete-event",
170 G_CALLBACK (gtk_main_quit), NULL);
171 gtk_container_set_border_width (GTK_CONTAINER (window), 6);
173 mainbox = gtk_vbox_new (FALSE, 6);
174 gtk_container_add (GTK_CONTAINER (window), mainbox);
177 label = gtk_label_new (NULL);
178 gtk_label_set_markup (GTK_LABEL (label), "<b>Old-style behavior</b>");
179 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
180 gtk_box_pack_start (GTK_BOX (mainbox), label, FALSE, FALSE, 0);
182 padbox = gtk_hbox_new (FALSE, 6);
183 gtk_box_pack_start (GTK_BOX (mainbox), padbox, FALSE, FALSE, 6);
185 gtk_box_pack_start (GTK_BOX (padbox), gtk_label_new (" "),
188 vbox = gtk_vbox_new (FALSE, 6);
189 gtk_box_pack_start (GTK_BOX (padbox), vbox, TRUE, TRUE, 6);
191 button = gtk_button_new_with_label ("Single selection");
192 g_signal_connect (button, "clicked",
193 G_CALLBACK (create_icon_view_window), 0x0);
194 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
196 button = gtk_button_new_with_label ("Multiple selections");
197 g_signal_connect (button, "clicked",
198 G_CALLBACK (create_icon_view_window),
199 GINT_TO_POINTER (MULTI_SELECT));
200 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
203 label = gtk_label_new (NULL);
204 gtk_label_set_markup (GTK_LABEL (label), "<b>Fremantle Normal mode</b>");
205 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
206 gtk_box_pack_start (GTK_BOX (mainbox), label, FALSE, FALSE, 0);
208 padbox = gtk_hbox_new (FALSE, 6);
209 gtk_box_pack_start (GTK_BOX (mainbox), padbox, FALSE, FALSE, 6);
211 gtk_box_pack_start (GTK_BOX (padbox), gtk_label_new (" "),
214 vbox = gtk_vbox_new (FALSE, 6);
215 gtk_box_pack_start (GTK_BOX (padbox), vbox, TRUE, TRUE, 6);
217 button = gtk_button_new_with_label ("Direct activation");
218 g_signal_connect (button, "clicked",
219 G_CALLBACK (create_icon_view_window),
220 GINT_TO_POINTER (NORMAL_MODE));
221 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
224 label = gtk_label_new (NULL);
225 gtk_label_set_markup (GTK_LABEL (label), "<b>Fremantle Edit mode</b>");
226 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
227 gtk_box_pack_start (GTK_BOX (mainbox), label, FALSE, FALSE, 0);
229 padbox = gtk_hbox_new (FALSE, 6);
230 gtk_box_pack_start (GTK_BOX (mainbox), padbox, FALSE, FALSE, 6);
232 gtk_box_pack_start (GTK_BOX (padbox), gtk_label_new (" "),
235 vbox = gtk_vbox_new (FALSE, 6);
236 gtk_box_pack_start (GTK_BOX (padbox), vbox, TRUE, TRUE, 6);
238 button = gtk_button_new_with_label ("Single selection");
239 g_signal_connect (button, "clicked",
240 G_CALLBACK (create_icon_view_window),
241 GINT_TO_POINTER (EDIT_MODE));
242 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
244 button = gtk_button_new_with_label ("Multiple selections");
245 g_signal_connect (button, "clicked",
246 G_CALLBACK (create_icon_view_window),
247 GINT_TO_POINTER (EDIT_MODE | MULTI_SELECT));
248 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
251 button = gtk_button_new_with_label ("Close");
252 g_signal_connect (button, "clicked",
253 G_CALLBACK (gtk_main_quit), NULL);
254 gtk_box_pack_end (GTK_BOX (mainbox), button, FALSE, FALSE, 0);
256 gtk_box_pack_end (GTK_BOX (mainbox), gtk_hseparator_new (),
259 gtk_widget_show_all (window);