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
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 gtk_init (&argc, &argv);
168 gtk_rc_parse_string ("style \"fremantle-widget\" {\n"
169 " GtkWidget::hildon-mode = 1\n"
170 "} widget \"*.fremantle-widget\" style \"fremantle-widget\"");
172 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
173 g_signal_connect (window, "delete-event",
174 G_CALLBACK (gtk_main_quit), NULL);
175 gtk_container_set_border_width (GTK_CONTAINER (window), 6);
177 mainbox = gtk_vbox_new (FALSE, 6);
178 gtk_container_add (GTK_CONTAINER (window), mainbox);
181 label = gtk_label_new (NULL);
182 gtk_label_set_markup (GTK_LABEL (label), "<b>Old-style behavior</b>");
183 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
184 gtk_box_pack_start (GTK_BOX (mainbox), label, FALSE, FALSE, 0);
186 padbox = gtk_hbox_new (FALSE, 6);
187 gtk_box_pack_start (GTK_BOX (mainbox), padbox, FALSE, FALSE, 6);
189 gtk_box_pack_start (GTK_BOX (padbox), gtk_label_new (" "),
192 vbox = gtk_vbox_new (FALSE, 6);
193 gtk_box_pack_start (GTK_BOX (padbox), vbox, TRUE, TRUE, 6);
195 button = gtk_button_new_with_label ("Single selection");
196 g_signal_connect (button, "clicked",
197 G_CALLBACK (create_icon_view_window), 0x0);
198 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
200 button = gtk_button_new_with_label ("Multiple selections");
201 g_signal_connect (button, "clicked",
202 G_CALLBACK (create_icon_view_window),
203 GINT_TO_POINTER (MULTI_SELECT));
204 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
207 label = gtk_label_new (NULL);
208 gtk_label_set_markup (GTK_LABEL (label), "<b>Fremantle Normal mode</b>");
209 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
210 gtk_box_pack_start (GTK_BOX (mainbox), label, FALSE, FALSE, 0);
212 padbox = gtk_hbox_new (FALSE, 6);
213 gtk_box_pack_start (GTK_BOX (mainbox), padbox, FALSE, FALSE, 6);
215 gtk_box_pack_start (GTK_BOX (padbox), gtk_label_new (" "),
218 vbox = gtk_vbox_new (FALSE, 6);
219 gtk_box_pack_start (GTK_BOX (padbox), vbox, TRUE, TRUE, 6);
221 button = gtk_button_new_with_label ("Direct activation");
222 g_signal_connect (button, "clicked",
223 G_CALLBACK (create_icon_view_window),
224 GINT_TO_POINTER (NORMAL_MODE));
225 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
228 label = gtk_label_new (NULL);
229 gtk_label_set_markup (GTK_LABEL (label), "<b>Fremantle Edit mode</b>");
230 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
231 gtk_box_pack_start (GTK_BOX (mainbox), label, FALSE, FALSE, 0);
233 padbox = gtk_hbox_new (FALSE, 6);
234 gtk_box_pack_start (GTK_BOX (mainbox), padbox, FALSE, FALSE, 6);
236 gtk_box_pack_start (GTK_BOX (padbox), gtk_label_new (" "),
239 vbox = gtk_vbox_new (FALSE, 6);
240 gtk_box_pack_start (GTK_BOX (padbox), vbox, TRUE, TRUE, 6);
242 button = gtk_button_new_with_label ("Single selection");
243 g_signal_connect (button, "clicked",
244 G_CALLBACK (create_icon_view_window),
245 GINT_TO_POINTER (EDIT_MODE));
246 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
248 button = gtk_button_new_with_label ("Multiple selections");
249 g_signal_connect (button, "clicked",
250 G_CALLBACK (create_icon_view_window),
251 GINT_TO_POINTER (EDIT_MODE | MULTI_SELECT));
252 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
255 button = gtk_button_new_with_label ("Close");
256 g_signal_connect (button, "clicked",
257 G_CALLBACK (gtk_main_quit), NULL);
258 gtk_box_pack_end (GTK_BOX (mainbox), button, FALSE, FALSE, 0);
260 gtk_box_pack_end (GTK_BOX (mainbox), gtk_hseparator_new (),
263 gtk_widget_show_all (window);