2 * Copyright (C) 2002 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include <sys/types.h>
24 #include "prop-editor.h"
26 #define NUMBER_OF_ITEMS 10
29 fill_model (GtkTreeModel *model)
35 GtkListStore *store = GTK_LIST_STORE (model);
37 pixbuf = gdk_pixbuf_new_from_file ("gnome-textfile.png", NULL);
41 gtk_list_store_prepend (store, &iter);
43 gtk_list_store_set (store, &iter,
45 1, "Really really\nreally really loooooooooong item name",
47 3, "This is a <b>Test</b> of <i>markup</i>",
50 while (i < NUMBER_OF_ITEMS - 1)
52 str = g_strdup_printf ("Icon %d", i);
53 str2 = g_strdup_printf ("Icon <b>%d</b>", i);
54 gtk_list_store_prepend (store, &iter);
55 gtk_list_store_set (store, &iter,
66 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 2, GTK_SORT_ASCENDING);
74 store = gtk_list_store_new (4, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
76 return GTK_TREE_MODEL (store);
81 foreach_selected_remove (GtkWidget *button, GtkIconView *icon_list)
86 GList *list, *selected;
88 selected = gtk_icon_view_get_selected_items (icon_list);
89 model = gtk_icon_view_get_model (icon_list);
91 for (list = selected; list; list = list->next)
93 GtkTreePath *path = list->data;
95 gtk_tree_model_get_iter (model, &iter, path);
96 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
98 gtk_tree_path_free (path);
101 g_list_free (selected);
106 add_many (GtkWidget *button, GtkIconView *icon_list)
108 static gint count = NUMBER_OF_ITEMS;
116 store = GTK_LIST_STORE (gtk_icon_view_get_model (icon_list));
117 pixbuf = gdk_pixbuf_new_from_file ("gnome-textfile.png", NULL);
120 for (i = 0; i < 100; i++)
122 str = g_strdup_printf ("Icon %d", count);
123 str2 = g_strdup_printf ("Icon <b>%d</b>", count);
124 gtk_list_store_prepend (store, &iter);
125 gtk_list_store_set (store, &iter,
139 selection_changed (GtkIconView *icon_list)
141 g_print ("Selection changed!\n");
145 item_cb (GtkWidget *menuitem,
147 GtkIconView *icon_list)
152 model = gtk_icon_view_get_model (icon_list);
154 gtk_tree_model_get_iter (model, &iter, path);
156 gtk_tree_model_get (model, &iter,
158 g_print ("Item activated, text is %s\n", text);
162 do_popup_menu (GtkWidget *icon_list,
163 GdkEventButton *event)
168 int button, event_time;
170 path = gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (icon_list),
172 g_print ("foo: %p\n", path);
177 menu = gtk_menu_new ();
179 menuitem = gtk_menu_item_new_with_label ("Activate");
180 gtk_widget_show (menuitem);
181 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
182 g_signal_connect (menuitem, "activate", G_CALLBACK (item_cb), path);
186 button = event->button;
187 event_time = event->time;
192 event_time = gtk_get_current_event_time ();
195 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
197 gtk_tree_path_free (path);
202 button_press_event_handler (GtkWidget *widget,
203 GdkEventButton *event)
205 /* Ignore double-clicks and triple-clicks */
206 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
208 do_popup_menu (widget, event);
216 popup_menu_handler (GtkWidget *widget)
218 do_popup_menu (widget, NULL);
223 main (gint argc, gchar **argv)
226 GtkWidget *window, *icon_list, *scrolled_window;
227 GtkWidget *vbox, *bbox;
229 GtkWidget *prop_editor;
232 gtk_init (&argc, &argv);
234 /* to test rtl layout, set RTL=1 in the environment */
235 if (g_getenv ("RTL"))
236 gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
238 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
239 gtk_window_set_default_size (GTK_WINDOW (window), 700, 400);
241 paned = gtk_hpaned_new ();
242 gtk_container_add (GTK_CONTAINER (window), paned);
244 icon_list = gtk_icon_view_new ();
245 gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_list), GTK_SELECTION_MULTIPLE);
247 g_signal_connect_after (icon_list, "button_press_event",
248 G_CALLBACK (button_press_event_handler), NULL);
249 g_signal_connect (icon_list, "selection_changed",
250 G_CALLBACK (selection_changed), NULL);
251 g_signal_connect (icon_list, "popup_menu",
252 G_CALLBACK (popup_menu_handler), NULL);
254 g_signal_connect (icon_list, "item_activated",
255 G_CALLBACK (item_cb), icon_list);
257 model = create_model ();
258 gtk_icon_view_set_model (GTK_ICON_VIEW (icon_list), model);
260 gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icon_list), 0);
261 gtk_icon_view_set_text_column (GTK_ICON_VIEW (icon_list), 1);
263 prop_editor = create_prop_editor (G_OBJECT (icon_list), 0);
264 gtk_widget_show_all (prop_editor);
266 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
267 gtk_container_add (GTK_CONTAINER (scrolled_window), icon_list);
268 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
269 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
270 vbox = gtk_vbox_new (FALSE, 0);
271 gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
272 bbox = gtk_hbutton_box_new ();
273 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_START);
274 gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
276 button = gtk_button_new_with_label ("Add many");
277 g_signal_connect (button, "clicked", G_CALLBACK (add_many), icon_list);
278 gtk_box_pack_start_defaults (GTK_BOX (bbox), button);
280 button = gtk_button_new_with_label ("Remove selected");
281 g_signal_connect (button, "clicked", G_CALLBACK (foreach_selected_remove), icon_list);
282 gtk_box_pack_start_defaults (GTK_BOX (bbox), button);
284 gtk_paned_pack1 (GTK_PANED (paned), vbox, TRUE, FALSE);
286 icon_list = gtk_icon_view_new ();
288 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
289 gtk_container_add (GTK_CONTAINER (scrolled_window), icon_list);
290 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
291 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
292 gtk_paned_pack2 (GTK_PANED (paned), scrolled_window, TRUE, FALSE);
294 gtk_widget_show_all (window);