4 * Copyright (C) 2008 The Geeqie Team
8 * This software is released under the GNU General Public License (GNU GPL).
9 * Please read the included file COPYING for more information.
10 * This software comes with no warranty of any kind, use at your own risk!
15 #include "collect-table.h"
17 #include "cellrenderericon.h"
18 #include "collect-dlg.h"
19 #include "collect-io.h"
27 #include "layout_image.h"
31 #include "ui_fileops.h"
33 #include "ui_tree_edit.h"
34 #include "uri_utils.h"
36 #include "icons/marker.xpm"
37 #define MARKER_WIDTH 26
38 #define MARKER_HEIGHT 32
40 #include <gdk/gdkkeysyms.h> /* for keyboard values */
42 /* between these, the icon width is increased by thumb_max_width / 2 */
43 #define THUMB_MIN_ICON_WIDTH 128
44 #define THUMB_MAX_ICON_WIDTH 150
46 #define COLLECT_TABLE_MAX_COLUMNS 32
47 #define THUMB_BORDER_PADDING 2
49 #define COLLECT_TABLE_TIP_DELAY 500
50 #define COLLECT_TABLE_TIP_DELAY_PATH (COLLECT_TABLE_TIP_DELAY * 1.7)
54 CTABLE_COLUMN_POINTER = 0,
60 SELECTION_SELECTED = 1 << 0,
61 SELECTION_PRELIGHT = 1 << 1,
62 SELECTION_FOCUS = 1 << 2
66 #define INFO_SELECTED(x) (x->flag_mask & SELECTION_SELECTED)
69 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force);
73 *-------------------------------------------------------------------
75 *-------------------------------------------------------------------
78 static gint collection_table_find_position(CollectTable *ct, CollectInfo *info, gint *row, gint *col)
82 n = g_list_index(ct->cd->list, info);
84 if (n < 0) return FALSE;
86 *row = n / ct->columns;
87 *col = n - (*row * ct->columns);
92 static gint collection_table_find_iter(CollectTable *ct, CollectInfo *info, GtkTreeIter *iter, gint *column)
97 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
98 if (!collection_table_find_position(ct, info, &row, &col)) return FALSE;
99 if (!gtk_tree_model_iter_nth_child(store, iter, NULL, row)) return FALSE;
100 if (column) *column = col;
105 static CollectInfo *collection_table_find_data(CollectTable *ct, gint row, gint col, GtkTreeIter *iter)
110 if (row < 0 || col < 0) return NULL;
112 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
113 if (gtk_tree_model_iter_nth_child(store, &p, NULL, row))
117 gtk_tree_model_get(store, &p, CTABLE_COLUMN_POINTER, &list, -1);
118 if (!list) return NULL;
122 return g_list_nth_data(list, col);
128 static CollectInfo *collection_table_find_data_by_coord(CollectTable *ct, gint x, gint y, GtkTreeIter *iter)
131 GtkTreeViewColumn *column;
137 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
138 &tpath, &column, NULL, NULL))
141 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
142 gtk_tree_model_get_iter(store, &row, tpath);
143 gtk_tree_path_free(tpath);
145 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
146 if (!list) return NULL;
148 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
149 if (iter) *iter = row;
150 return g_list_nth_data(list, n);
153 static guint collection_table_list_count(CollectTable *ct, gint64 *bytes)
163 CollectInfo *ci = work->data;
171 return g_list_length(ct->cd->list);
174 static guint collection_table_selection_count(CollectTable *ct, gint64 *bytes)
181 work = ct->selection;
184 CollectInfo *ci = work->data;
192 return g_list_length(ct->selection);
195 static void collection_table_update_status(CollectTable *ct)
203 if (!ct->status_label) return;
205 n = collection_table_list_count(ct, &n_bytes);
206 s = collection_table_selection_count(ct, &s_bytes);
210 gchar *b = text_from_size_abrev(n_bytes);
211 gchar *sb = text_from_size_abrev(s_bytes);
212 buf = g_strdup_printf(_("%s, %d images (%s, %d)"), b, n, sb, s);
218 gchar *b = text_from_size_abrev(n_bytes);
219 buf = g_strdup_printf(_("%s, %d images"), b, n);
224 buf = g_strdup(_("Empty"));
227 gtk_label_set_text(GTK_LABEL(ct->status_label), buf);
231 static void collection_table_update_extras(CollectTable *ct, gint loading, gdouble value)
235 if (!ct->extra_label) return;
238 text = _("Loading thumbs...");
242 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ct->extra_label), value);
243 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ct->extra_label), text);
246 static void collection_table_toggle_filenames(CollectTable *ct)
248 ct->show_text = !ct->show_text;
249 options->show_icon_names = ct->show_text;
251 collection_table_populate_at_new_size(ct, ct->listview->allocation.width, ct->listview->allocation.height, TRUE);
254 static gint collection_table_get_icon_width(CollectTable *ct)
258 if (!ct->show_text) return options->thumbnails.max_width;
260 width = options->thumbnails.max_width + options->thumbnails.max_width / 2;
261 if (width < THUMB_MIN_ICON_WIDTH) width = THUMB_MIN_ICON_WIDTH;
262 if (width > THUMB_MAX_ICON_WIDTH) width = options->thumbnails.max_width;
268 *-------------------------------------------------------------------
270 *-------------------------------------------------------------------
273 static void collection_table_selection_set(CollectTable *ct, CollectInfo *info, SelectionType value, GtkTreeIter *iter)
280 if (info->flag_mask == value) return;
281 info->flag_mask = value;
283 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
286 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
287 if (list) gtk_list_store_set(GTK_LIST_STORE(store), iter, CTABLE_COLUMN_POINTER, list, -1);
293 if (collection_table_find_iter(ct, info, &row, NULL))
295 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
296 if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, CTABLE_COLUMN_POINTER, list, -1);
301 static void collection_table_selection_add(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
305 collection_table_selection_set(ct, info, info->flag_mask | mask, iter);
308 static void collection_table_selection_remove(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
312 collection_table_selection_set(ct, info, info->flag_mask & ~mask, iter);
315 *-------------------------------------------------------------------
317 *-------------------------------------------------------------------
320 static void collection_table_verify_selections(CollectTable *ct)
324 work = ct->selection;
327 CollectInfo *info = work->data;
329 if (!g_list_find(ct->cd->list, info))
331 ct->selection = g_list_remove(ct->selection, info);
336 void collection_table_select_all(CollectTable *ct)
340 g_list_free(ct->selection);
341 ct->selection = NULL;
346 ct->selection = g_list_append(ct->selection, work->data);
347 collection_table_selection_add(ct, work->data, SELECTION_SELECTED, NULL);
351 collection_table_update_status(ct);
354 void collection_table_unselect_all(CollectTable *ct)
358 work = ct->selection;
361 collection_table_selection_remove(ct, work->data, SELECTION_SELECTED, NULL);
365 g_list_free(ct->selection);
366 ct->selection = NULL;
368 collection_table_update_status(ct);
371 /* Invert the current collection's selection */
372 static void collection_table_select_invert_all(CollectTable *ct)
375 GList *new_selection = NULL;
380 CollectInfo *info = work->data;
382 if (INFO_SELECTED(info))
384 collection_table_selection_remove(ct, info, SELECTION_SELECTED, NULL);
388 new_selection = g_list_append(new_selection, info);
389 collection_table_selection_add(ct, info, SELECTION_SELECTED, NULL);
396 g_list_free(ct->selection);
397 ct->selection = new_selection;
399 collection_table_update_status(ct);
402 static void collection_table_select(CollectTable *ct, CollectInfo *info)
404 ct->prev_selection = info;
406 if (!info || INFO_SELECTED(info)) return;
408 ct->selection = g_list_append(ct->selection, info);
409 collection_table_selection_add(ct, info, SELECTION_SELECTED, NULL);
411 collection_table_update_status(ct);
414 static void collection_table_unselect(CollectTable *ct, CollectInfo *info)
416 ct->prev_selection = info;
418 if (!info || !INFO_SELECTED(info) ) return;
420 ct->selection = g_list_remove(ct->selection, info);
421 collection_table_selection_remove(ct, info, SELECTION_SELECTED, NULL);
423 collection_table_update_status(ct);
426 static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gint select)
430 collection_table_select(ct, info);
434 collection_table_unselect(ct, info);
438 static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gint select)
445 if (!collection_table_find_position(ct, start, &row1, &col1) ||
446 !collection_table_find_position(ct, end, &row2, &col2) ) return;
448 ct->prev_selection = end;
450 if (!options->collections.rectangular_selection)
455 if (g_list_index(ct->cd->list, start) > g_list_index(ct->cd->list, end))
462 work = g_list_find(ct->cd->list, start);
466 collection_table_select_util(ct, info, select);
468 if (work->data != end)
489 DEBUG_1("table: %d x %d to %d x %d", row1, col1, row2, col2);
491 for (i = row1; i <= row2; i++)
493 for (j = col1; j <= col2; j++)
495 CollectInfo *info = collection_table_find_data(ct, i, j, NULL);
496 if (info) collection_table_select_util(ct, info, select);
501 GList *collection_table_selection_get_list(CollectTable *ct)
503 return collection_list_to_filelist(ct->selection);
506 static GList *collection_table_get_list(CollectTable *ct)
508 return collection_list_to_filelist(ct->cd->list);
512 *-------------------------------------------------------------------
513 * tooltip type window
514 *-------------------------------------------------------------------
517 static void tip_show(CollectTable *ct)
522 if (ct->tip_window) return;
524 gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
526 ct->tip_info = collection_table_find_data_by_coord(ct, x, y, NULL);
527 if (!ct->tip_info) return;
529 ct->tip_window = gtk_window_new(GTK_WINDOW_POPUP);
530 gtk_window_set_resizable(GTK_WINDOW(ct->tip_window), FALSE);
531 gtk_container_set_border_width(GTK_CONTAINER(ct->tip_window), 2);
533 label = gtk_label_new(ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
535 g_object_set_data(G_OBJECT(ct->tip_window), "tip_label", label);
536 gtk_container_add(GTK_CONTAINER(ct->tip_window), label);
537 gtk_widget_show(label);
539 gdk_window_get_pointer(NULL, &x, &y, NULL);
541 if (!GTK_WIDGET_REALIZED(ct->tip_window)) gtk_widget_realize(ct->tip_window);
542 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
543 gtk_widget_show(ct->tip_window);
546 static void tip_hide(CollectTable *ct)
548 if (ct->tip_window) gtk_widget_destroy(ct->tip_window);
549 ct->tip_window = NULL;
552 static gint tip_schedule_cb(gpointer data)
554 CollectTable *ct = data;
556 if (ct->tip_delay_id == -1) return FALSE;
560 ct->tip_delay_id = -1;
564 static void tip_schedule(CollectTable *ct)
568 if (ct->tip_delay_id != -1)
570 g_source_remove(ct->tip_delay_id);
571 ct->tip_delay_id = -1;
574 ct->tip_delay_id = g_timeout_add(ct->show_text ? COLLECT_TABLE_TIP_DELAY_PATH : COLLECT_TABLE_TIP_DELAY, tip_schedule_cb, ct);
577 static void tip_unschedule(CollectTable *ct)
581 if (ct->tip_delay_id != -1) g_source_remove(ct->tip_delay_id);
582 ct->tip_delay_id = -1;
585 static void tip_update(CollectTable *ct, CollectInfo *info)
593 gdk_window_get_pointer(NULL, &x, &y, NULL);
594 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
596 if (info != ct->tip_info)
607 label = g_object_get_data(G_OBJECT(ct->tip_window), "tip_label");
608 gtk_label_set_text(GTK_LABEL(label), ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
614 *-------------------------------------------------------------------
616 *-------------------------------------------------------------------
619 static void collection_table_popup_save_as_cb(GtkWidget *widget, gpointer data)
621 CollectTable *ct = data;
623 collection_dialog_save_as(NULL, ct->cd);
626 static void collection_table_popup_save_cb(GtkWidget *widget, gpointer data)
628 CollectTable *ct = data;
632 collection_table_popup_save_as_cb(widget, data);
636 if (!collection_save(ct->cd, ct->cd->path))
638 log_printf("failed saving to collection path: %s\n", ct->cd->path);
642 static GList *collection_table_popup_file_list(CollectTable *ct)
644 if (!ct->click_info) return NULL;
646 if (INFO_SELECTED(ct->click_info))
648 return collection_table_selection_get_list(ct);
651 return g_list_append(NULL, file_data_ref(ct->click_info->fd));
654 static void collection_table_popup_edit_cb(GtkWidget *widget, gpointer data)
657 const gchar *key = data;
660 ct = submenu_item_get_data(widget);
664 list = collection_table_popup_file_list(ct);
667 file_util_start_editor_from_filelist(key, list, ct->listview);
672 static void collection_table_popup_info_cb(GtkWidget *widget, gpointer data)
674 CollectTable *ct = data;
676 info_window_new(NULL, collection_table_popup_file_list(ct), NULL);
679 static void collection_table_popup_copy_cb(GtkWidget *widget, gpointer data)
681 CollectTable *ct = data;
683 file_util_copy(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);
686 static void collection_table_popup_move_cb(GtkWidget *widget, gpointer data)
688 CollectTable *ct = data;
690 file_util_move(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);
693 static void collection_table_popup_rename_cb(GtkWidget *widget, gpointer data)
695 CollectTable *ct = data;
697 file_util_rename(NULL, collection_table_popup_file_list(ct), ct->listview);
700 static void collection_table_popup_delete_cb(GtkWidget *widget, gpointer data)
702 CollectTable *ct = data;
704 file_util_delete(NULL, collection_table_popup_file_list(ct), ct->listview);
707 static void collection_table_popup_copy_path_cb(GtkWidget *widget, gpointer data)
709 CollectTable *ct = data;
711 file_util_copy_path_list_to_clipboard(collection_table_popup_file_list(ct));
714 static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data)
719 ct = submenu_item_get_data(widget);
723 type = (SortType)GPOINTER_TO_INT(data);
725 collection_set_sort_method(ct->cd, type);
728 static void collection_table_popup_view_new_cb(GtkWidget *widget, gpointer data)
730 CollectTable *ct = data;
732 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
734 view_window_new_from_collection(ct->cd, ct->click_info);
738 static void collection_table_popup_view_cb(GtkWidget *widget, gpointer data)
740 CollectTable *ct = data;
742 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
744 layout_image_set_collection(NULL, ct->cd, ct->click_info);
748 static void collection_table_popup_selectall_cb(GtkWidget *widget, gpointer data)
750 CollectTable *ct = data;
752 collection_table_select_all(ct);
753 ct->prev_selection= ct->click_info;
756 static void collection_table_popup_unselectall_cb(GtkWidget *widget, gpointer data)
758 CollectTable *ct = data;
760 collection_table_unselect_all(ct);
761 ct->prev_selection= ct->click_info;
764 static void collection_table_popup_select_invert_cb(GtkWidget *widget, gpointer data)
766 CollectTable *ct = data;
768 collection_table_select_invert_all(ct);
769 ct->prev_selection= ct->click_info;
772 static void collection_table_popup_remove_cb(GtkWidget *widget, gpointer data)
774 CollectTable *ct = data;
777 if (!ct->click_info) return;
779 if (INFO_SELECTED(ct->click_info))
781 list = g_list_copy(ct->selection);
785 list = g_list_append(NULL, ct->click_info);
788 collection_remove_by_info_list(ct->cd, list);
792 static void collection_table_popup_add_filelist_cb(GtkWidget *widget, gpointer data)
794 CollectTable *ct = data;
797 list = layout_list(NULL);
801 collection_table_add_filelist(ct, list);
806 static void collection_table_popup_add_collection_cb(GtkWidget *widget, gpointer data)
808 CollectTable *ct = data;
810 collection_dialog_append(NULL, ct->cd);
813 static void collection_table_popup_find_dupes_cb(GtkWidget *widget, gpointer data)
815 CollectTable *ct = data;
818 dw = dupe_window_new(DUPE_MATCH_NAME);
819 dupe_window_add_collection(dw, ct->cd);
822 static void collection_table_popup_print_cb(GtkWidget *widget, gpointer data)
824 CollectTable *ct = data;
827 fd = (ct->click_info) ? ct->click_info->fd : NULL;
829 print_window_new(fd, collection_table_selection_get_list(ct), collection_table_get_list(ct), ct->listview);
832 static void collection_table_popup_show_names_cb(GtkWidget *widget, gpointer data)
834 CollectTable *ct = data;
836 collection_table_toggle_filenames(ct);
839 static void collection_table_popup_destroy_cb(GtkWidget *widget, gpointer data)
841 CollectTable *ct = data;
843 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
844 ct->click_info = NULL;
847 filelist_free(ct->drop_list);
848 ct->drop_list = NULL;
849 ct->drop_info = NULL;
852 static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon)
858 menu = popup_menu_short_lived();
860 g_signal_connect(G_OBJECT(menu), "destroy",
861 G_CALLBACK(collection_table_popup_destroy_cb), ct);
863 menu_item_add_sensitive(menu, _("_View"), over_icon,
864 G_CALLBACK(collection_table_popup_view_cb), ct);
865 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, over_icon,
866 G_CALLBACK(collection_table_popup_view_new_cb), ct);
867 menu_item_add_divider(menu);
868 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, over_icon,
869 G_CALLBACK(collection_table_popup_remove_cb), ct);
871 menu_item_add_stock(menu, _("Append from file list"), GTK_STOCK_ADD,
872 G_CALLBACK(collection_table_popup_add_filelist_cb), ct);
873 menu_item_add_stock(menu, _("Append from collection..."), GTK_STOCK_OPEN,
874 G_CALLBACK(collection_table_popup_add_collection_cb), ct);
875 menu_item_add_divider(menu);
877 item = menu_item_add(menu, _("_Selection"), NULL, NULL);
878 submenu = gtk_menu_new();
879 menu_item_add(submenu, _("Select all"),
880 G_CALLBACK(collection_table_popup_selectall_cb), ct);
881 menu_item_add(submenu, _("Select none"),
882 G_CALLBACK(collection_table_popup_unselectall_cb), ct);
883 menu_item_add(submenu, _("Invert selection"),
884 G_CALLBACK(collection_table_popup_select_invert_cb), ct);
885 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
886 menu_item_add_divider(menu);
888 submenu_add_edit(menu, &item,
889 G_CALLBACK(collection_table_popup_edit_cb), ct);
890 gtk_widget_set_sensitive(item, over_icon);
892 menu_item_add_sensitive(menu, _("_Properties"), over_icon,
893 G_CALLBACK(collection_table_popup_info_cb), ct);
894 menu_item_add_divider(menu);
895 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, over_icon,
896 G_CALLBACK(collection_table_popup_copy_cb), ct);
897 menu_item_add_sensitive(menu, _("_Move..."), over_icon,
898 G_CALLBACK(collection_table_popup_move_cb), ct);
899 menu_item_add_sensitive(menu, _("_Rename..."), over_icon,
900 G_CALLBACK(collection_table_popup_rename_cb), ct);
901 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, over_icon,
902 G_CALLBACK(collection_table_popup_delete_cb), ct);
903 if (options->show_copy_path)
904 menu_item_add_sensitive(menu, _("_Copy path"), over_icon,
905 G_CALLBACK(collection_table_popup_copy_path_cb), ct);
906 menu_item_add_divider(menu);
908 submenu_add_sort(menu, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0);
909 menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
910 G_CALLBACK(collection_table_popup_show_names_cb), ct);
911 menu_item_add_divider(menu);
912 menu_item_add_stock(menu, _("_Save collection"), GTK_STOCK_SAVE,
913 G_CALLBACK(collection_table_popup_save_cb), ct);
914 menu_item_add_stock(menu, _("Save collection _as..."), GTK_STOCK_SAVE_AS,
915 G_CALLBACK(collection_table_popup_save_as_cb), ct);
916 menu_item_add_divider(menu);
917 menu_item_add_stock(menu, _("_Find duplicates..."), GTK_STOCK_FIND,
918 G_CALLBACK(collection_table_popup_find_dupes_cb), ct);
919 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, over_icon,
920 G_CALLBACK(collection_table_popup_print_cb), ct);
925 *-------------------------------------------------------------------
927 *-------------------------------------------------------------------
930 static void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
935 if (g_list_find(ct->cd->list, ct->focus_info))
937 if (info == ct->focus_info)
939 /* ensure focus row col are correct */
940 collection_table_find_position(ct, ct->focus_info,
941 &ct->focus_row, &ct->focus_column);
944 collection_table_selection_remove(ct, ct->focus_info, SELECTION_FOCUS, NULL);
947 if (!collection_table_find_position(ct, info, &row, &col))
949 ct->focus_info = NULL;
951 ct->focus_column = -1;
955 ct->focus_info = info;
957 ct->focus_column = col;
958 collection_table_selection_add(ct, ct->focus_info, SELECTION_FOCUS, NULL);
960 if (collection_table_find_iter(ct, ct->focus_info, &iter, NULL))
963 GtkTreeViewColumn *column;
966 tree_view_row_make_visible(GTK_TREE_VIEW(ct->listview), &iter, FALSE);
968 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
969 tpath = gtk_tree_model_get_path(store, &iter);
970 /* focus is set to an extra column with 0 width to hide focus, we draw it ourself */
971 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), COLLECT_TABLE_MAX_COLUMNS);
972 gtk_tree_view_set_cursor(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE);
973 gtk_tree_path_free(tpath);
977 static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gint relative)
984 new_row = ct->focus_row;
985 new_col = ct->focus_column;
988 if (new_row < 0) new_row = 0;
989 if (new_row >= ct->rows) new_row = ct->rows - 1;
1009 new_col = ct->columns - 1;
1016 if (new_col >= ct->columns)
1018 if (new_row < ct->rows - 1)
1025 new_col = ct->columns - 1;
1035 if (new_row >= ct->rows)
1038 new_row = ct->rows - 1;
1041 new_col = ct->columns - 1;
1043 if (new_col >= ct->columns) new_col = ct->columns - 1;
1046 if (new_row == ct->rows - 1)
1050 /* if we moved beyond the last image, go to the last image */
1052 l = g_list_length(ct->cd->list);
1053 if (ct->rows > 1) l -= (ct->rows - 1) * ct->columns;
1054 if (new_col >= l) new_col = l - 1;
1057 if (new_row == -1 || new_col == -1)
1059 if (!ct->cd->list) return;
1060 new_row = new_col = 0;
1063 collection_table_set_focus(ct, collection_table_find_data(ct, new_row, new_col, NULL));
1066 static void collection_table_update_focus(CollectTable *ct)
1071 if (ct->focus_info && collection_table_find_position(ct, ct->focus_info, &new_row, &new_col))
1073 /* first find the old focus, if it exists and is valid */
1077 /* (try to) stay where we were */
1078 new_row = ct->focus_row;
1079 new_col = ct->focus_column;
1082 collection_table_move_focus(ct, new_row, new_col, FALSE);
1085 /* used to figure the page up/down distances */
1086 static gint page_height(CollectTable *ct)
1093 adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
1094 page_size = (gint)adj->page_increment;
1096 row_height = options->thumbnails.max_height + THUMB_BORDER_PADDING * 2;
1097 if (ct->show_text) row_height += options->thumbnails.max_height / 3;
1099 ret = page_size / row_height;
1100 if (ret < 1) ret = 1;
1105 static void collection_table_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
1107 CollectTable *ct = data;
1108 GtkTreeModel *store;
1114 if (!collection_table_find_iter(ct, ct->click_info, &iter, &column)) return;
1115 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1116 tpath = gtk_tree_model_get_path(store, &iter);
1117 tree_view_get_cell_clamped(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE, x, y, &cw, &ch);
1118 gtk_tree_path_free(tpath);
1120 popup_menu_position_clamp(menu, x, y, 0);
1123 static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
1125 CollectTable *ct = data;
1132 switch (event->keyval)
1134 case GDK_Left: case GDK_KP_Left:
1137 case GDK_Right: case GDK_KP_Right:
1140 case GDK_Up: case GDK_KP_Up:
1143 case GDK_Down: case GDK_KP_Down:
1146 case GDK_Page_Up: case GDK_KP_Page_Up:
1147 focus_row = -page_height(ct);
1149 case GDK_Page_Down: case GDK_KP_Page_Down:
1150 focus_row = page_height(ct);
1152 case GDK_Home: case GDK_KP_Home:
1153 focus_row = -ct->focus_row;
1154 focus_col = -ct->focus_column;
1156 case GDK_End: case GDK_KP_End:
1157 focus_row = ct->rows - 1 - ct->focus_row;
1158 focus_col = ct->columns - 1 - ct->focus_column;
1161 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1164 ct->click_info = info;
1165 if (event->state & GDK_CONTROL_MASK)
1167 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1171 collection_table_unselect_all(ct);
1172 collection_table_select(ct, info);
1177 if (event->state & GDK_CONTROL_MASK) collection_table_toggle_filenames(ct);
1181 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1182 ct->click_info = info;
1184 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1187 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1188 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, collection_table_menu_pos_cb, ct, 0, GDK_CURRENT_TIME);
1191 stop_signal = FALSE;
1195 if (focus_row != 0 || focus_col != 0)
1197 CollectInfo *new_info;
1198 CollectInfo *old_info;
1200 old_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1201 collection_table_move_focus(ct, focus_row, focus_col, TRUE);
1202 new_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1204 if (new_info != old_info)
1206 if (event->state & GDK_SHIFT_MASK)
1208 if (!options->collections.rectangular_selection)
1210 collection_table_select_region_util(ct, old_info, new_info, FALSE);
1214 collection_table_select_region_util(ct, ct->click_info, old_info, FALSE);
1216 collection_table_select_region_util(ct, ct->click_info, new_info, TRUE);
1218 else if (event->state & GDK_CONTROL_MASK)
1220 ct->click_info = new_info;
1224 ct->click_info = new_info;
1225 collection_table_unselect_all(ct);
1226 collection_table_select(ct, new_info);
1234 g_signal_stop_emission_by_name(GTK_OBJECT(widget), "key_press_event");
1243 *-------------------------------------------------------------------
1245 *-------------------------------------------------------------------
1248 static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gint *after, GdkRectangle *cell,
1249 gint use_coord, gint x, gint y)
1251 CollectInfo *info = NULL;
1252 GtkTreeModel *store;
1255 GtkTreeViewColumn *column;
1257 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1259 if (!use_coord) gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
1264 if (collection_table_find_iter(ct, source, &iter, &col))
1266 tpath = gtk_tree_model_get_path(store, &iter);
1267 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1268 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1269 gtk_tree_path_free(tpath);
1272 *after = (x > cell->x + (cell->width / 2));
1277 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
1278 &tpath, &column, NULL, NULL))
1283 gtk_tree_model_get_iter(store, &iter, tpath);
1284 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1286 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
1287 info = g_list_nth_data(list, n);
1291 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1292 *after = (x > cell->x + (cell->width / 2));
1295 gtk_tree_path_free(tpath);
1302 work = g_list_last(ct->cd->list);
1310 if (collection_table_find_iter(ct, info, &iter, &col))
1312 tpath = gtk_tree_model_get_path(store, &iter);
1313 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1314 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1315 gtk_tree_path_free(tpath);
1323 static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint y)
1329 info = collection_table_insert_find(ct, NULL, &after, &cell, TRUE, x, y);
1335 work = g_list_find(ct->cd->list, info);
1336 if (work && work->next)
1338 info = work->next->data;
1349 static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gint enable)
1357 if (ct->marker_window) gdk_window_destroy(ct->marker_window);
1358 ct->marker_window = NULL;
1363 info = collection_table_insert_find(ct, info, &after, &cell, FALSE, 0, 0);
1365 /* this setting does not take into account (after), but since it is not really used... */
1366 ct->marker_info = info;
1371 if (!ct->marker_window)
1374 GdkWindowAttr attributes;
1375 gint attributes_mask;
1381 parent = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(ct->listview));
1383 pb = gdk_pixbuf_new_from_xpm_data((const gchar **)marker_xpm);
1384 gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128);
1387 gdk_drawable_get_size(pixmap, &w, &h);
1389 attributes.window_type = GDK_WINDOW_CHILD;
1390 attributes.wclass = GDK_INPUT_OUTPUT;
1391 attributes.width = w;
1392 attributes.height = h;
1393 attributes.event_mask = gtk_widget_get_events(ct->listview);
1394 attributes_mask = 0;
1396 ct->marker_window = gdk_window_new(parent, &attributes, attributes_mask);
1397 gdk_window_set_back_pixmap(ct->marker_window, pixmap, FALSE);
1398 gdk_window_shape_combine_mask(ct->marker_window, mask, 0, 0);
1400 g_object_unref(pixmap);
1401 if (mask) g_object_unref(mask);
1409 gdk_drawable_get_size(ct->marker_window, &w, &h);
1417 x = cell.x + cell.width;
1420 y = cell.y + (cell.height / 2) - (h / 2);
1422 gdk_window_move(ct->marker_window, x, y);
1423 gdk_window_clear(ct->marker_window);
1424 if (!gdk_window_is_visible(ct->marker_window)) gdk_window_show(ct->marker_window);
1428 if (gdk_window_is_visible(ct->marker_window)) gdk_window_hide(ct->marker_window);
1433 *-------------------------------------------------------------------
1434 * mouse drag auto-scroll
1435 *-------------------------------------------------------------------
1438 static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gint drop_event)
1442 info = collection_table_find_data_by_coord(ct, x, y, NULL);
1447 collection_table_insert_marker(ct, info, TRUE);
1451 tip_update(ct, info);
1455 static gint collection_table_auto_scroll_idle_cb(gpointer data)
1457 CollectTable *ct = data;
1462 if (ct->drop_idle_id == -1) return FALSE;
1464 window = ct->listview->window;
1465 gdk_window_get_pointer(window, &x, &y, NULL);
1466 gdk_drawable_get_size(window, &w, &h);
1467 if (x >= 0 && x < w && y >= 0 && y < h)
1469 collection_table_motion_update(ct, x, y, TRUE);
1472 ct->drop_idle_id = -1;
1476 static gint collection_table_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data)
1478 CollectTable *ct = data;
1480 if (ct->drop_idle_id == -1) ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
1485 static void collection_table_scroll(CollectTable *ct, gint scroll)
1489 if (ct->drop_idle_id != -1)
1491 g_source_remove(ct->drop_idle_id);
1492 ct->drop_idle_id = -1;
1494 widget_auto_scroll_stop(ct->listview);
1495 collection_table_insert_marker(ct, NULL, FALSE);
1499 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
1500 widget_auto_scroll_start(ct->listview, adj, -1, options->thumbnails.max_height / 2,
1501 collection_table_auto_scroll_notify_cb, ct);
1506 *-------------------------------------------------------------------
1508 *-------------------------------------------------------------------
1511 static gint collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1513 CollectTable *ct = data;
1515 collection_table_motion_update(ct, (gint)bevent->x, (gint)bevent->y, FALSE);
1520 static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1522 CollectTable *ct = data;
1528 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1530 ct->click_info = info;
1531 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, &iter);
1533 switch (bevent->button)
1535 case MOUSE_BUTTON_LEFT:
1536 if (bevent->type == GDK_2BUTTON_PRESS)
1540 layout_image_set_collection(NULL, ct->cd, info);
1543 else if (!GTK_WIDGET_HAS_FOCUS(ct->listview))
1545 gtk_widget_grab_focus(ct->listview);
1548 case MOUSE_BUTTON_RIGHT:
1549 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1550 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
1559 static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1561 CollectTable *ct = data;
1563 CollectInfo *info = NULL;
1567 if ((gint)bevent->x != 0 || (gint) bevent->y != 0)
1569 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1574 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1577 if (bevent->button == MOUSE_BUTTON_LEFT &&
1578 info && ct->click_info == info)
1580 collection_table_set_focus(ct, info);
1582 if (bevent->state & GDK_CONTROL_MASK)
1586 select = !INFO_SELECTED(info);
1587 if ((bevent->state & GDK_SHIFT_MASK) && ct->prev_selection)
1589 collection_table_select_region_util(ct, ct->prev_selection, info, select);
1593 collection_table_select_util(ct, info, select);
1598 collection_table_unselect_all(ct);
1600 if ((bevent->state & GDK_SHIFT_MASK) &&
1603 collection_table_select_region_util(ct, ct->prev_selection, info, TRUE);
1607 collection_table_select_util(ct, info, TRUE);
1611 else if (bevent->button == MOUSE_BUTTON_MIDDLE &&
1612 info && ct->click_info == info)
1614 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1620 static gint collection_table_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
1622 CollectTable *ct = data;
1629 *-------------------------------------------------------------------
1630 * populate, add, insert, etc.
1631 *-------------------------------------------------------------------
1634 static gboolean collection_table_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data)
1638 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
1644 static void collection_table_clear_store(CollectTable *ct)
1646 GtkTreeModel *store;
1648 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1649 gtk_tree_model_foreach(store, collection_table_destroy_node_cb, NULL);
1651 gtk_list_store_clear(GTK_LIST_STORE(store));
1654 static GList *collection_table_add_row(CollectTable *ct, GtkTreeIter *iter)
1656 GtkListStore *store;
1660 for (i = 0; i < ct->columns; i++) list = g_list_prepend(list, NULL);
1662 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)));
1663 gtk_list_store_append(store, iter);
1664 gtk_list_store_set(store, iter, CTABLE_COLUMN_POINTER, list, -1);
1669 static void collection_table_populate(CollectTable *ct, gint resize)
1674 collection_table_verify_selections(ct);
1676 collection_table_clear_store(ct);
1683 thumb_width = collection_table_get_icon_width(ct);
1685 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
1687 GtkTreeViewColumn *column;
1688 GtkCellRenderer *cell;
1691 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), i);
1692 gtk_tree_view_column_set_visible(column, (i < ct->columns));
1693 gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6));
1695 list = gtk_tree_view_column_get_cell_renderers(column);
1696 cell = (list) ? list->data : NULL;
1699 if (cell && GQV_IS_CELL_RENDERER_ICON(cell))
1701 g_object_set(G_OBJECT(cell), "fixed_width", thumb_width,
1702 "fixed_height", options->thumbnails.max_height,
1703 "show_text", ct->show_text, NULL);
1706 if (GTK_WIDGET_REALIZED(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
1710 work = ct->cd->list;
1718 list = collection_table_add_row(ct, &iter);
1719 while (work && list)
1721 list->data = work->data;
1729 collection_table_update_focus(ct);
1730 collection_table_update_status(ct);
1733 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force)
1738 thumb_width = collection_table_get_icon_width(ct);
1740 new_cols = w / (thumb_width + (THUMB_BORDER_PADDING * 6));
1741 if (new_cols < 1) new_cols = 1;
1743 if (!force && new_cols == ct->columns) return;
1745 ct->columns = new_cols;
1747 collection_table_populate(ct, TRUE);
1749 DEBUG_1("col tab pop cols=%d rows=%d", ct->columns, ct->rows);
1752 static void collection_table_sync(CollectTable *ct)
1754 GtkTreeModel *store;
1759 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1764 work = ct->cd->list;
1770 if (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1772 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1773 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1777 list = collection_table_add_row(ct, &iter);
1802 while (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1806 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1807 gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
1813 collection_table_update_focus(ct);
1814 collection_table_update_status(ct);
1817 static gint collection_table_sync_idle_cb(gpointer data)
1819 CollectTable *ct = data;
1821 if (ct->sync_idle_id == -1) return FALSE;
1822 ct->sync_idle_id = -1;
1824 collection_table_sync(ct);
1828 static void collection_table_sync_idle(CollectTable *ct)
1830 if (ct->sync_idle_id == -1)
1832 /* high priority, the view needs to be resynced before a redraw
1833 * may contain invalid pointers at this time
1835 ct->sync_idle_id = g_idle_add_full(G_PRIORITY_HIGH, collection_table_sync_idle_cb, ct, NULL);
1839 void collection_table_add_filelist(CollectTable *ct, GList *list)
1848 collection_add(ct->cd, (FileData *)work->data, FALSE);
1853 static void collection_table_insert_filelist(CollectTable *ct, GList *list, CollectInfo *insert_info)
1862 collection_insert(ct->cd, (FileData *)work->data, insert_info, FALSE);
1866 collection_table_sync_idle(ct);
1869 static void collection_table_move_by_info_list(CollectTable *ct, GList *info_list, gint row, gint col)
1872 GList *insert_pos = NULL;
1876 if (!info_list) return;
1878 info = collection_table_find_data(ct, row, col, NULL);
1880 if (!info_list->next && info_list->data == info) return;
1882 if (info) insert_pos = g_list_find(ct->cd->list, info);
1884 /* FIXME: this may get slow for large lists */
1886 while (insert_pos && work)
1888 if (insert_pos->data == work->data)
1890 insert_pos = insert_pos->next;
1902 ct->cd->list = g_list_remove(ct->cd->list, work->data);
1906 /* place them back in */
1907 temp = g_list_copy(info_list);
1911 ct->cd->list = uig_list_insert_list(ct->cd->list, insert_pos, temp);
1915 ct->cd->list = g_list_concat(temp, ct->cd->list);
1919 ct->cd->list = g_list_concat(ct->cd->list, temp);
1922 ct->cd->changed = TRUE;
1924 collection_table_sync_idle(ct);
1929 *-------------------------------------------------------------------
1931 *-------------------------------------------------------------------
1934 void collection_table_file_update(CollectTable *ct, CollectInfo *info)
1942 collection_table_update_extras(ct, FALSE, 0.0);
1946 if (!collection_table_find_position(ct, info, &row, &col)) return;
1948 if (ct->columns != 0 && ct->rows != 0)
1950 value = (gdouble)(row * ct->columns + col) / (ct->columns * ct->rows);
1957 collection_table_update_extras(ct, TRUE, value);
1959 if (collection_table_find_iter(ct, info, &iter, NULL))
1961 GtkTreeModel *store;
1964 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1965 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1966 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1970 void collection_table_file_add(CollectTable *ct, CollectInfo *info)
1972 collection_table_sync_idle(ct);
1975 void collection_table_file_insert(CollectTable *ct, CollectInfo *ci)
1977 collection_table_sync_idle(ct);
1980 void collection_table_file_remove(CollectTable *ct, CollectInfo *ci)
1982 if (ci && INFO_SELECTED(ci))
1984 ct->selection = g_list_remove(ct->selection, ci);
1987 collection_table_sync_idle(ct);
1990 void collection_table_refresh(CollectTable *ct)
1992 collection_table_populate(ct, FALSE);
1996 *-------------------------------------------------------------------
1998 *-------------------------------------------------------------------
2001 static void collection_table_add_dir_recursive(CollectTable *ct, FileData *dir_fd, gint recursive)
2007 if (!filelist_read(dir_fd, &f, recursive ? &d : NULL))
2010 f = filelist_filter(f, FALSE);
2011 d = filelist_filter(d, TRUE);
2013 f = filelist_sort_path(f);
2014 d = filelist_sort_path(d);
2016 collection_table_insert_filelist(ct, f, ct->marker_info);
2018 work = g_list_last(d);
2021 collection_table_add_dir_recursive(ct, (FileData *)work->data, TRUE);
2029 static void confirm_dir_list_do(CollectTable *ct, GList *list, gint recursive)
2034 FileData *fd = work->data;
2036 if (isdir(fd->path)) collection_table_add_dir_recursive(ct, fd, recursive);
2038 collection_table_insert_filelist(ct, list, ct->marker_info);
2042 static void confirm_dir_list_add(GtkWidget *widget, gpointer data)
2044 CollectTable *ct = data;
2046 confirm_dir_list_do(ct, ct->drop_list, FALSE);
2049 static void confirm_dir_list_recurse(GtkWidget *widget, gpointer data)
2051 CollectTable *ct = data;
2053 confirm_dir_list_do(ct, ct->drop_list, TRUE);
2056 static void confirm_dir_list_skip(GtkWidget *widget, gpointer data)
2058 CollectTable *ct = data;
2060 collection_table_insert_filelist(ct, ct->drop_list, ct->marker_info);
2063 static GtkWidget *collection_table_drop_menu(CollectTable *ct)
2067 menu = popup_menu_short_lived();
2068 g_signal_connect(G_OBJECT(menu), "destroy",
2069 G_CALLBACK(collection_table_popup_destroy_cb), ct);
2071 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL);
2072 menu_item_add_divider(menu);
2073 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK,
2074 G_CALLBACK(confirm_dir_list_add), ct);
2075 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD,
2076 G_CALLBACK(confirm_dir_list_recurse), ct);
2077 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE,
2078 G_CALLBACK(confirm_dir_list_skip), ct);
2079 menu_item_add_divider(menu);
2080 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, ct);
2086 *-------------------------------------------------------------------
2088 *-------------------------------------------------------------------
2091 static GtkTargetEntry collection_drag_types[] = {
2092 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
2093 { "text/uri-list", 0, TARGET_URI_LIST },
2094 { "text/plain", 0, TARGET_TEXT_PLAIN }
2096 static gint n_collection_drag_types = 3;
2098 static GtkTargetEntry collection_drop_types[] = {
2099 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
2100 { "text/uri-list", 0, TARGET_URI_LIST }
2102 static gint n_collection_drop_types = 2;
2105 static void collection_table_dnd_get(GtkWidget *widget, GdkDragContext *context,
2106 GtkSelectionData *selection_data, guint info,
2107 guint time, gpointer data)
2109 CollectTable *ct = data;
2112 gchar *uri_text = NULL;
2115 if (!ct->click_info) return;
2117 selected = INFO_SELECTED(ct->click_info);
2121 case TARGET_APP_COLLECTION_MEMBER:
2124 uri_text = collection_info_list_to_dnd_data(ct->cd, ct->selection, &total);
2128 list = g_list_append(NULL, ct->click_info);
2129 uri_text = collection_info_list_to_dnd_data(ct->cd, list, &total);
2133 case TARGET_URI_LIST:
2134 case TARGET_TEXT_PLAIN:
2138 list = collection_table_selection_get_list(ct);
2142 list = g_list_append(NULL, file_data_ref(ct->click_info->fd));
2146 uri_text = uri_text_from_filelist(list, &total, (info == TARGET_TEXT_PLAIN));
2147 filelist_free(list);
2151 gtk_selection_data_set(selection_data, selection_data->target,
2152 8, (guchar *)uri_text, total);
2157 static void collection_table_dnd_receive(GtkWidget *widget, GdkDragContext *context,
2159 GtkSelectionData *selection_data, guint info,
2160 guint time, gpointer data)
2162 CollectTable *ct = data;
2164 GList *info_list = NULL;
2165 CollectionData *source;
2166 CollectInfo *drop_info;
2169 DEBUG_1("%s", selection_data->data);
2171 collection_table_scroll(ct, FALSE);
2172 collection_table_insert_marker(ct, NULL, FALSE);
2174 drop_info = collection_table_insert_point(ct, x, y);
2178 case TARGET_APP_COLLECTION_MEMBER:
2179 source = collection_from_dnd_data((gchar *)selection_data->data, &list, &info_list);
2182 if (source == ct->cd)
2187 /* it is a move within a collection */
2188 filelist_free(list);
2193 collection_table_move_by_info_list(ct, info_list, -1, -1);
2195 else if (collection_table_find_position(ct, drop_info, &row, &col))
2197 collection_table_move_by_info_list(ct, info_list, row, col);
2202 /* it is a move/copy across collections */
2203 if (context->action == GDK_ACTION_MOVE)
2205 collection_remove_by_info_list(source, info_list);
2208 g_list_free(info_list);
2211 case TARGET_URI_LIST:
2212 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE);
2216 FileData *fd = work->data;
2217 if (isdir(fd->path))
2221 ct->drop_list = list;
2222 ct->drop_info = drop_info;
2223 menu = collection_table_drop_menu(ct);
2224 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time);
2237 collection_table_insert_filelist(ct, list, drop_info);
2238 filelist_free(list);
2242 static void collection_table_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
2244 CollectTable *ct = data;
2246 if (ct->click_info && ct->click_info->pixbuf)
2250 if (INFO_SELECTED(ct->click_info))
2251 items = g_list_length(ct->selection);
2254 dnd_set_drag_icon(widget, context, ct->click_info->pixbuf, items);
2258 static void collection_table_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
2260 CollectTable *ct = data;
2262 /* apparently a leave event is not generated on a drop */
2265 collection_table_scroll(ct, FALSE);
2268 static gint collection_table_dnd_motion(GtkWidget *widget, GdkDragContext *context,
2269 gint x, gint y, guint time, gpointer data)
2271 CollectTable *ct = data;
2273 collection_table_motion_update(ct, x, y, TRUE);
2274 collection_table_scroll(ct, TRUE);
2279 static void collection_table_dnd_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data)
2281 CollectTable *ct = data;
2283 collection_table_scroll(ct, FALSE);
2286 static void collection_table_dnd_init(CollectTable *ct)
2288 gtk_drag_source_set(ct->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
2289 collection_drag_types, n_collection_drag_types,
2290 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
2291 g_signal_connect(G_OBJECT(ct->listview), "drag_data_get",
2292 G_CALLBACK(collection_table_dnd_get), ct);
2293 g_signal_connect(G_OBJECT(ct->listview), "drag_begin",
2294 G_CALLBACK(collection_table_dnd_begin), ct);
2295 g_signal_connect(G_OBJECT(ct->listview), "drag_end",
2296 G_CALLBACK(collection_table_dnd_end), ct);
2298 gtk_drag_dest_set(ct->listview,
2299 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
2300 collection_drop_types, n_collection_drop_types,
2301 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK);
2302 g_signal_connect(G_OBJECT(ct->listview), "drag_motion",
2303 G_CALLBACK(collection_table_dnd_motion), ct);
2304 g_signal_connect(G_OBJECT(ct->listview), "drag_leave",
2305 G_CALLBACK(collection_table_dnd_leave), ct);
2306 g_signal_connect(G_OBJECT(ct->listview), "drag_data_received",
2307 G_CALLBACK(collection_table_dnd_receive), ct);
2311 *-----------------------------------------------------------------------------
2313 *-----------------------------------------------------------------------------
2316 typedef struct _ColumnData ColumnData;
2323 static void collection_table_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
2324 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
2326 ColumnData *cd = data;
2336 gtk_tree_model_get(tree_model, iter, CTABLE_COLUMN_POINTER, &list, -1);
2337 info = g_list_nth_data(list, cd->number);
2339 style = gtk_widget_get_style(ct->listview);
2340 if (info && (info->flag_mask & SELECTION_SELECTED) )
2342 memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg));
2343 memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg));
2347 memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg));
2348 memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg));
2351 if (info && (info->flag_mask & SELECTION_PRELIGHT))
2354 shift_color(&color_fg, -1, 0);
2356 shift_color(&color_bg, -1, 0);
2359 if (GQV_IS_CELL_RENDERER_ICON(cell))
2363 g_object_set(cell, "pixbuf", info->pixbuf,
2364 "text", info->fd->name,
2365 "cell-background-gdk", &color_bg,
2366 "cell-background-set", TRUE,
2367 "foreground-gdk", &color_fg,
2368 "foreground-set", TRUE,
2369 "has-focus", (ct->focus_info == info), NULL);
2373 g_object_set(cell, "pixbuf", NULL,
2375 "cell-background-set", FALSE,
2376 "foreground-set", FALSE,
2377 "has-focus", FALSE, NULL);
2382 static void collection_table_append_column(CollectTable *ct, gint n)
2385 GtkTreeViewColumn *column;
2386 GtkCellRenderer *renderer;
2388 column = gtk_tree_view_column_new();
2389 gtk_tree_view_column_set_min_width(column, 0);
2391 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
2392 gtk_tree_view_column_set_alignment(column, 0.5);
2394 renderer = gqv_cell_renderer_icon_new();
2395 gtk_tree_view_column_pack_start(column, renderer, FALSE);
2396 g_object_set(G_OBJECT(renderer), "xpad", THUMB_BORDER_PADDING * 2,
2397 "ypad", THUMB_BORDER_PADDING,
2398 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
2400 g_object_set_data(G_OBJECT(column), "column_number", GINT_TO_POINTER(n));
2402 cd = g_new0(ColumnData, 1);
2405 gtk_tree_view_column_set_cell_data_func(column, renderer, collection_table_cell_data_cb, cd, g_free);
2407 gtk_tree_view_append_column(GTK_TREE_VIEW(ct->listview), column);
2411 *-------------------------------------------------------------------
2413 *-------------------------------------------------------------------
2416 static void collection_table_destroy(GtkWidget *widget, gpointer data)
2418 CollectTable *ct = data;
2422 g_signal_handlers_disconnect_matched(GTK_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA,
2424 gtk_widget_destroy(ct->popup);
2427 if (ct->sync_idle_id != -1) g_source_remove(ct->sync_idle_id);
2430 collection_table_scroll(ct, FALSE);
2435 static void collection_table_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
2437 CollectTable *ct = data;
2439 collection_table_populate_at_new_size(ct, allocation->width, allocation->height, FALSE);
2442 CollectTable *collection_table_new(CollectionData *cd)
2445 GtkListStore *store;
2446 GtkTreeSelection *selection;
2449 ct = g_new0(CollectTable, 1);
2454 ct->selection = NULL;
2455 ct->prev_selection = NULL;
2457 ct->tip_window = NULL;
2458 ct->tip_delay_id = -1;
2460 ct->marker_window = NULL;
2461 ct->marker_info = NULL;
2463 ct->status_label = NULL;
2464 ct->extra_label = NULL;
2467 ct->focus_column = 0;
2468 ct->focus_info = NULL;
2470 ct->show_text = options->show_icon_names;
2472 ct->sync_idle_id = -1;
2473 ct->drop_idle_id = -1;
2476 ct->drop_info = NULL;
2477 ct->drop_list = NULL;
2479 ct->scrolled = gtk_scrolled_window_new(NULL, NULL);
2480 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN);
2481 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ct->scrolled),
2482 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2484 store = gtk_list_store_new(1, G_TYPE_POINTER);
2485 ct->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
2486 g_object_unref(store);
2488 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ct->listview));
2489 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_NONE);
2491 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ct->listview), FALSE);
2492 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ct->listview), FALSE);
2494 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
2496 collection_table_append_column(ct, i);
2499 /* zero width column to hide tree view focus, we draw it ourselves */
2500 collection_table_append_column(ct, i);
2501 /* end column to fill white space */
2502 collection_table_append_column(ct, i);
2504 g_signal_connect(G_OBJECT(ct->listview), "destroy",
2505 G_CALLBACK(collection_table_destroy), ct);
2506 g_signal_connect(G_OBJECT(ct->listview), "size_allocate",
2507 G_CALLBACK(collection_table_sized), ct);
2508 g_signal_connect(G_OBJECT(ct->listview), "key_press_event",
2509 G_CALLBACK(collection_table_press_key_cb), ct);
2511 gtk_container_add(GTK_CONTAINER(ct->scrolled), ct->listview);
2512 gtk_widget_show(ct->listview);
2514 collection_table_dnd_init(ct);
2516 gtk_widget_set_events(ct->listview, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK |
2517 GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK);
2518 g_signal_connect(G_OBJECT(ct->listview),"button_press_event",
2519 G_CALLBACK(collection_table_press_cb), ct);
2520 g_signal_connect(G_OBJECT(ct->listview),"button_release_event",
2521 G_CALLBACK(collection_table_release_cb), ct);
2522 g_signal_connect(G_OBJECT(ct->listview),"motion_notify_event",
2523 G_CALLBACK(collection_table_motion_cb), ct);
2524 g_signal_connect(G_OBJECT(ct->listview), "leave_notify_event",
2525 G_CALLBACK(collection_table_leave_cb), ct);
2530 void collection_table_set_labels(CollectTable *ct, GtkWidget *status, GtkWidget *extra)
2532 ct->status_label = status;
2533 ct->extra_label = extra;
2534 collection_table_update_status(ct);
2535 collection_table_update_extras(ct, FALSE, 0.0);
2538 CollectInfo *collection_table_get_focus_info(CollectTable *ct)
2540 return collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
2542 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */