2 * This file is a part of hildon examples
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; version 2.1 of
9 * the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
37 static GtkListStore *store = NULL;
40 return GTK_TREE_MODEL (store);
42 store = gtk_list_store_new (1, G_TYPE_STRING);
44 for (i = 0; i < 50; i++)
48 str = g_strdup_printf ("\nRow %d\n", i);
49 gtk_list_store_insert_with_values (store, NULL, i, 0, str, -1);
53 return GTK_TREE_MODEL (store);
57 create_icon_view (TreeViewMode tvmode)
61 GtkCellRenderer *renderer;
63 if (tvmode == NORMAL_MODE)
65 icon_view = hildon_gtk_icon_view_new (HILDON_UI_MODE_NORMAL);
69 icon_view = hildon_gtk_icon_view_new (HILDON_UI_MODE_EDIT);
70 gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
71 GTK_SELECTION_MULTIPLE);
75 gtk_icon_view_set_model (GTK_ICON_VIEW (icon_view), model);
77 renderer = gtk_cell_renderer_pixbuf_new ();
78 g_object_set (renderer, "stock-id", GTK_STOCK_NEW, NULL);
79 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), renderer, TRUE);
81 renderer = gtk_cell_renderer_text_new ();
82 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), renderer, FALSE);
83 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view), renderer, "text", 0, NULL);
89 delete_button_clicked (GtkButton *button,
90 GtkIconView *iconview)
93 GList *items, *iter, *refs;
96 items = gtk_icon_view_get_selected_items (iconview);
97 model = gtk_icon_view_get_model (iconview);
100 /* Get row references for all selected items */
101 for (iter = items; iter != NULL; iter = iter->next)
103 GtkTreePath *path = (GtkTreePath *) iter->data;
104 GtkTreeRowReference *ref = gtk_tree_row_reference_new (model, path);
105 refs = g_list_prepend (refs, gtk_tree_row_reference_copy (ref));
106 gtk_tree_row_reference_free (ref);
109 g_list_foreach (items, (GFunc) gtk_tree_path_free, NULL);
112 /* Remove all selected items from the model */
113 for (iter = refs; iter != NULL; iter = iter->next)
115 GtkTreeIter treeiter;
116 GtkTreeRowReference *ref = (GtkTreeRowReference *) iter->data;
117 GtkTreePath *path = gtk_tree_row_reference_get_path (ref);
118 gtk_tree_model_get_iter (model, &treeiter, path);
119 gtk_list_store_remove (GTK_LIST_STORE (model), &treeiter);
122 g_list_foreach (refs, (GFunc) gtk_tree_row_reference_free, NULL);
125 /* After removing the items, close the window */
126 window = gtk_widget_get_toplevel (GTK_WIDGET (iconview));
127 gtk_widget_destroy (window);
139 window = hildon_stackable_window_new ();
140 gtk_container_set_border_width (GTK_CONTAINER (window), 6);
142 vbox = gtk_vbox_new (FALSE, 10);
143 toolbar = hildon_edit_toolbar_new_with_text ("Choose items to delete", "Delete");
144 area = hildon_pannable_area_new ();
145 iconview = create_icon_view (EDIT_MODE);
147 gtk_container_add (GTK_CONTAINER (area), iconview);
148 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
149 gtk_box_pack_start (GTK_BOX (vbox), area, TRUE, TRUE, 0);
151 gtk_container_add (GTK_CONTAINER (window), vbox);
153 g_signal_connect (toolbar, "button-clicked", G_CALLBACK (delete_button_clicked), iconview);
154 g_signal_connect_swapped (toolbar, "arrow-clicked", G_CALLBACK (gtk_widget_destroy), window);
156 gtk_widget_show_all (window);
157 gtk_window_fullscreen (GTK_WINDOW (window));
170 gtk_init (&argc, &argv);
172 gtk_rc_parse_string ("style \"fremantle-widget\" {\n"
173 " GtkWidget::hildon-mode = 1\n"
174 "} class \"GtkIconView\" style \"fremantle-widget\"");
176 window = hildon_stackable_window_new ();
177 g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
178 gtk_container_set_border_width (GTK_CONTAINER (window), 6);
180 vbox = gtk_vbox_new (FALSE, 10);
181 area = hildon_pannable_area_new ();
182 iconview = create_icon_view (NORMAL_MODE);
183 button = hildon_gtk_button_new (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT);
184 gtk_button_set_label (GTK_BUTTON (button), "Delete some items");
186 gtk_container_add (GTK_CONTAINER (area), iconview);
187 gtk_box_pack_start (GTK_BOX (vbox), area, TRUE, TRUE, 0);
188 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
190 gtk_container_add (GTK_CONTAINER (window), vbox);
192 g_signal_connect (button, "clicked", G_CALLBACK (edit_window), NULL);
194 gtk_widget_show_all (window);