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-pannable-area.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;
74 icon_view = g_object_new (GTK_TYPE_ICON_VIEW,
75 "model", create_model (),
77 "hildon-ui-mode", mode,
81 gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
82 GTK_SELECTION_MULTIPLE);
83 else if (mode != HILDON_UI_MODE_NORMAL)
84 gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
85 GTK_SELECTION_SINGLE);
87 renderer = gtk_cell_renderer_pixbuf_new ();
88 g_object_set (renderer, "stock-id", GTK_STOCK_NEW, NULL);
89 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view),
93 renderer = gtk_cell_renderer_text_new ();
94 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view),
97 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
106 create_icon_view_window (GtkWidget *button,
112 GtkWidget *icon_view;
113 HildonUIMode mode = 0;
115 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
116 g_signal_connect (window, "delete-event",
117 G_CALLBACK (gtk_widget_destroy), window);
118 gtk_container_set_border_width (GTK_CONTAINER (window), 6);
120 sw = hildon_pannable_area_new ();
121 gtk_container_add (GTK_CONTAINER (window), sw);
123 if ((GPOINTER_TO_INT (user_data) & NORMAL_MODE) == NORMAL_MODE)
125 mode = HILDON_UI_MODE_NORMAL;
126 name = "fremantle-widget";
128 else if ((GPOINTER_TO_INT (user_data) & EDIT_MODE) == EDIT_MODE)
130 mode = HILDON_UI_MODE_EDIT;
131 name = "fremantle-widget";
136 icon_view = create_icon_view (mode, name,
137 (GPOINTER_TO_INT (user_data) & MULTI_SELECT) == MULTI_SELECT);
139 /* Some signals doing printfs() to see if the behavior is correct. */
140 g_signal_connect (icon_view, "item-activated",
141 G_CALLBACK (item_activated_callback), NULL);
143 gtk_widget_set_size_request (icon_view, 480, 800);
144 gtk_container_add (GTK_CONTAINER (sw), icon_view);
146 gtk_widget_show_all (window);
150 main (int argc, char **argv)
159 gtk_init (&argc, &argv);
161 gtk_rc_parse_string ("style \"fremantle-widget\" {\n"
162 " GtkWidget::hildon-mode = 1\n"
163 "} widget \"*.fremantle-widget\" style \"fremantle-widget\"");
165 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
166 g_signal_connect (window, "delete-event",
167 G_CALLBACK (gtk_main_quit), NULL);
168 gtk_container_set_border_width (GTK_CONTAINER (window), 6);
170 mainbox = gtk_vbox_new (FALSE, 6);
171 gtk_container_add (GTK_CONTAINER (window), mainbox);
174 label = gtk_label_new (NULL);
175 gtk_label_set_markup (GTK_LABEL (label), "<b>Old-style behavior</b>");
176 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
177 gtk_box_pack_start (GTK_BOX (mainbox), label, FALSE, FALSE, 0);
179 padbox = gtk_hbox_new (FALSE, 6);
180 gtk_box_pack_start (GTK_BOX (mainbox), padbox, FALSE, FALSE, 6);
182 gtk_box_pack_start (GTK_BOX (padbox), gtk_label_new (" "),
185 vbox = gtk_vbox_new (FALSE, 6);
186 gtk_box_pack_start (GTK_BOX (padbox), vbox, TRUE, TRUE, 6);
188 button = gtk_button_new_with_label ("Single selection");
189 g_signal_connect (button, "clicked",
190 G_CALLBACK (create_icon_view_window), 0x0);
191 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
193 button = gtk_button_new_with_label ("Multiple selections");
194 g_signal_connect (button, "clicked",
195 G_CALLBACK (create_icon_view_window),
196 GINT_TO_POINTER (MULTI_SELECT));
197 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
200 label = gtk_label_new (NULL);
201 gtk_label_set_markup (GTK_LABEL (label), "<b>Fremantle Normal mode</b>");
202 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
203 gtk_box_pack_start (GTK_BOX (mainbox), label, FALSE, FALSE, 0);
205 padbox = gtk_hbox_new (FALSE, 6);
206 gtk_box_pack_start (GTK_BOX (mainbox), padbox, FALSE, FALSE, 6);
208 gtk_box_pack_start (GTK_BOX (padbox), gtk_label_new (" "),
211 vbox = gtk_vbox_new (FALSE, 6);
212 gtk_box_pack_start (GTK_BOX (padbox), vbox, TRUE, TRUE, 6);
214 button = gtk_button_new_with_label ("Direct activation");
215 g_signal_connect (button, "clicked",
216 G_CALLBACK (create_icon_view_window),
217 GINT_TO_POINTER (NORMAL_MODE));
218 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
221 label = gtk_label_new (NULL);
222 gtk_label_set_markup (GTK_LABEL (label), "<b>Fremantle Edit mode</b>");
223 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
224 gtk_box_pack_start (GTK_BOX (mainbox), label, FALSE, FALSE, 0);
226 padbox = gtk_hbox_new (FALSE, 6);
227 gtk_box_pack_start (GTK_BOX (mainbox), padbox, FALSE, FALSE, 6);
229 gtk_box_pack_start (GTK_BOX (padbox), gtk_label_new (" "),
232 vbox = gtk_vbox_new (FALSE, 6);
233 gtk_box_pack_start (GTK_BOX (padbox), vbox, TRUE, TRUE, 6);
235 button = gtk_button_new_with_label ("Single selection");
236 g_signal_connect (button, "clicked",
237 G_CALLBACK (create_icon_view_window),
238 GINT_TO_POINTER (EDIT_MODE));
239 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
241 button = gtk_button_new_with_label ("Multiple selections");
242 g_signal_connect (button, "clicked",
243 G_CALLBACK (create_icon_view_window),
244 GINT_TO_POINTER (EDIT_MODE | MULTI_SELECT));
245 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
248 button = gtk_button_new_with_label ("Close");
249 g_signal_connect (button, "clicked",
250 G_CALLBACK (gtk_main_quit), NULL);
251 gtk_box_pack_end (GTK_BOX (mainbox), button, FALSE, FALSE, 0);
253 gtk_box_pack_end (GTK_BOX (mainbox), gtk_hseparator_new (),
256 gtk_widget_show_all (window);