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)
66 icon_view = hildon_gtk_icon_view_new (HILDON_UI_MODE_NORMAL);
68 icon_view = gtk_icon_view_new ();
69 #endif /* MAEMO_GTK */
74 icon_view = hildon_gtk_icon_view_new (HILDON_UI_MODE_EDIT);
76 icon_view = gtk_icon_view_new ();
77 #endif /* MAEMO_GTK */
79 gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
80 GTK_SELECTION_MULTIPLE);
84 gtk_icon_view_set_model (GTK_ICON_VIEW (icon_view), model);
86 renderer = gtk_cell_renderer_pixbuf_new ();
87 g_object_set (renderer, "stock-id", GTK_STOCK_NEW, NULL);
88 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), renderer, TRUE);
90 renderer = gtk_cell_renderer_text_new ();
91 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), renderer, FALSE);
92 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view), renderer, "text", 0, NULL);
98 delete_button_clicked (GtkButton *button,
99 GtkIconView *iconview)
102 GList *items, *iter, *refs;
105 items = gtk_icon_view_get_selected_items (iconview);
106 model = gtk_icon_view_get_model (iconview);
109 /* Get row references for all selected items */
110 for (iter = items; iter != NULL; iter = iter->next)
112 GtkTreePath *path = (GtkTreePath *) iter->data;
113 GtkTreeRowReference *ref = gtk_tree_row_reference_new (model, path);
114 refs = g_list_prepend (refs, gtk_tree_row_reference_copy (ref));
115 gtk_tree_row_reference_free (ref);
118 g_list_foreach (items, (GFunc) gtk_tree_path_free, NULL);
121 /* Remove all selected items from the model */
122 for (iter = refs; iter != NULL; iter = iter->next)
124 GtkTreeIter treeiter;
125 GtkTreeRowReference *ref = (GtkTreeRowReference *) iter->data;
126 GtkTreePath *path = gtk_tree_row_reference_get_path (ref);
127 gtk_tree_model_get_iter (model, &treeiter, path);
128 gtk_list_store_remove (GTK_LIST_STORE (model), &treeiter);
131 g_list_foreach (refs, (GFunc) gtk_tree_row_reference_free, NULL);
134 /* After removing the items, close the window */
135 window = gtk_widget_get_toplevel (GTK_WIDGET (iconview));
136 gtk_widget_destroy (window);
148 window = hildon_stackable_window_new ();
149 gtk_container_set_border_width (GTK_CONTAINER (window), 6);
151 vbox = gtk_vbox_new (FALSE, 10);
152 toolbar = hildon_edit_toolbar_new_with_text ("Choose items to delete", "Delete");
153 area = hildon_pannable_area_new ();
154 iconview = create_icon_view (EDIT_MODE);
156 gtk_container_add (GTK_CONTAINER (area), iconview);
157 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
158 gtk_box_pack_start (GTK_BOX (vbox), area, TRUE, TRUE, 0);
160 gtk_container_add (GTK_CONTAINER (window), vbox);
162 g_signal_connect (toolbar, "button-clicked", G_CALLBACK (delete_button_clicked), iconview);
163 g_signal_connect_swapped (toolbar, "arrow-clicked", G_CALLBACK (gtk_widget_destroy), window);
165 gtk_widget_show_all (window);
166 gtk_window_fullscreen (GTK_WINDOW (window));
179 hildon_gtk_init (&argc, &argv);
181 gtk_rc_parse_string ("style \"fremantle-widget\" {\n"
182 " GtkWidget::hildon-mode = 1\n"
183 "} class \"GtkIconView\" style \"fremantle-widget\"");
185 window = hildon_stackable_window_new ();
186 g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
187 gtk_container_set_border_width (GTK_CONTAINER (window), 6);
189 vbox = gtk_vbox_new (FALSE, 10);
190 area = hildon_pannable_area_new ();
191 iconview = create_icon_view (NORMAL_MODE);
192 button = hildon_gtk_button_new (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT);
193 gtk_button_set_label (GTK_BUTTON (button), "Delete some items");
195 gtk_container_add (GTK_CONTAINER (area), iconview);
196 gtk_box_pack_start (GTK_BOX (vbox), area, TRUE, TRUE, 0);
197 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
199 gtk_container_add (GTK_CONTAINER (window), vbox);
201 g_signal_connect (button, "clicked", G_CALLBACK (edit_window), NULL);
203 gtk_widget_show_all (window);