4 * Copyright (C) 2008 - 2009 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"
26 #include "layout_image.h"
30 #include "ui_fileops.h"
32 #include "ui_tree_edit.h"
33 #include "uri_utils.h"
35 #include "icons/marker.xpm"
36 #define MARKER_WIDTH 26
37 #define MARKER_HEIGHT 32
39 #include <gdk/gdkkeysyms.h> /* for keyboard values */
41 /* between these, the icon width is increased by thumb_max_width / 2 */
42 #define THUMB_MIN_ICON_WIDTH 128
43 #define THUMB_MAX_ICON_WIDTH 150
45 #define COLLECT_TABLE_MAX_COLUMNS 32
46 #define THUMB_BORDER_PADDING 2
48 #define COLLECT_TABLE_TIP_DELAY 500
49 #define COLLECT_TABLE_TIP_DELAY_PATH (COLLECT_TABLE_TIP_DELAY * 1.7)
53 CTABLE_COLUMN_POINTER = 0,
59 SELECTION_SELECTED = 1 << 0,
60 SELECTION_PRELIGHT = 1 << 1,
61 SELECTION_FOCUS = 1 << 2
65 #define INFO_SELECTED(x) (x->flag_mask & SELECTION_SELECTED)
68 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force);
72 *-------------------------------------------------------------------
74 *-------------------------------------------------------------------
77 static gint collection_table_find_position(CollectTable *ct, CollectInfo *info, gint *row, gint *col)
81 n = g_list_index(ct->cd->list, info);
83 if (n < 0) return FALSE;
85 *row = n / ct->columns;
86 *col = n - (*row * ct->columns);
91 static gint collection_table_find_iter(CollectTable *ct, CollectInfo *info, GtkTreeIter *iter, gint *column)
96 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
97 if (!collection_table_find_position(ct, info, &row, &col)) return FALSE;
98 if (!gtk_tree_model_iter_nth_child(store, iter, NULL, row)) return FALSE;
99 if (column) *column = col;
104 static CollectInfo *collection_table_find_data(CollectTable *ct, gint row, gint col, GtkTreeIter *iter)
109 if (row < 0 || col < 0) return NULL;
111 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
112 if (gtk_tree_model_iter_nth_child(store, &p, NULL, row))
116 gtk_tree_model_get(store, &p, CTABLE_COLUMN_POINTER, &list, -1);
117 if (!list) return NULL;
121 return g_list_nth_data(list, col);
127 static CollectInfo *collection_table_find_data_by_coord(CollectTable *ct, gint x, gint y, GtkTreeIter *iter)
130 GtkTreeViewColumn *column;
136 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
137 &tpath, &column, NULL, NULL))
140 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
141 gtk_tree_model_get_iter(store, &row, tpath);
142 gtk_tree_path_free(tpath);
144 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
145 if (!list) return NULL;
147 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
148 if (iter) *iter = row;
149 return g_list_nth_data(list, n);
152 static guint collection_table_list_count(CollectTable *ct, gint64 *bytes)
162 CollectInfo *ci = work->data;
170 return g_list_length(ct->cd->list);
173 static guint collection_table_selection_count(CollectTable *ct, gint64 *bytes)
180 work = ct->selection;
183 CollectInfo *ci = work->data;
191 return g_list_length(ct->selection);
194 static void collection_table_update_status(CollectTable *ct)
202 if (!ct->status_label) return;
204 n = collection_table_list_count(ct, &n_bytes);
205 s = collection_table_selection_count(ct, &s_bytes);
209 gchar *b = text_from_size_abrev(n_bytes);
210 gchar *sb = text_from_size_abrev(s_bytes);
211 buf = g_strdup_printf(_("%s, %d images (%s, %d)"), b, n, sb, s);
217 gchar *b = text_from_size_abrev(n_bytes);
218 buf = g_strdup_printf(_("%s, %d images"), b, n);
223 buf = g_strdup(_("Empty"));
226 gtk_label_set_text(GTK_LABEL(ct->status_label), buf);
230 static void collection_table_update_extras(CollectTable *ct, gint loading, gdouble value)
234 if (!ct->extra_label) return;
237 text = _("Loading thumbs...");
241 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ct->extra_label), value);
242 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ct->extra_label), text);
245 static void collection_table_toggle_filenames(CollectTable *ct)
247 ct->show_text = !ct->show_text;
248 options->show_icon_names = ct->show_text;
250 collection_table_populate_at_new_size(ct, ct->listview->allocation.width, ct->listview->allocation.height, TRUE);
253 static gint collection_table_get_icon_width(CollectTable *ct)
257 if (!ct->show_text) return options->thumbnails.max_width;
259 width = options->thumbnails.max_width + options->thumbnails.max_width / 2;
260 if (width < THUMB_MIN_ICON_WIDTH) width = THUMB_MIN_ICON_WIDTH;
261 if (width > THUMB_MAX_ICON_WIDTH) width = options->thumbnails.max_width;
267 *-------------------------------------------------------------------
269 *-------------------------------------------------------------------
272 static void collection_table_selection_set(CollectTable *ct, CollectInfo *info, SelectionType value, GtkTreeIter *iter)
279 if (info->flag_mask == value) return;
280 info->flag_mask = value;
282 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
285 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
286 if (list) gtk_list_store_set(GTK_LIST_STORE(store), iter, CTABLE_COLUMN_POINTER, list, -1);
292 if (collection_table_find_iter(ct, info, &row, NULL))
294 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
295 if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, CTABLE_COLUMN_POINTER, list, -1);
300 static void collection_table_selection_add(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
304 collection_table_selection_set(ct, info, info->flag_mask | mask, iter);
307 static void collection_table_selection_remove(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
311 collection_table_selection_set(ct, info, info->flag_mask & ~mask, iter);
314 *-------------------------------------------------------------------
316 *-------------------------------------------------------------------
319 static void collection_table_verify_selections(CollectTable *ct)
323 work = ct->selection;
326 CollectInfo *info = work->data;
328 if (!g_list_find(ct->cd->list, info))
330 ct->selection = g_list_remove(ct->selection, info);
335 void collection_table_select_all(CollectTable *ct)
339 g_list_free(ct->selection);
340 ct->selection = NULL;
345 ct->selection = g_list_append(ct->selection, work->data);
346 collection_table_selection_add(ct, work->data, SELECTION_SELECTED, NULL);
350 collection_table_update_status(ct);
353 void collection_table_unselect_all(CollectTable *ct)
357 work = ct->selection;
360 collection_table_selection_remove(ct, work->data, SELECTION_SELECTED, NULL);
364 g_list_free(ct->selection);
365 ct->selection = NULL;
367 collection_table_update_status(ct);
370 /* Invert the current collection's selection */
371 static void collection_table_select_invert_all(CollectTable *ct)
374 GList *new_selection = NULL;
379 CollectInfo *info = work->data;
381 if (INFO_SELECTED(info))
383 collection_table_selection_remove(ct, info, SELECTION_SELECTED, NULL);
387 new_selection = g_list_append(new_selection, info);
388 collection_table_selection_add(ct, info, SELECTION_SELECTED, NULL);
395 g_list_free(ct->selection);
396 ct->selection = new_selection;
398 collection_table_update_status(ct);
401 static void collection_table_select(CollectTable *ct, CollectInfo *info)
403 ct->prev_selection = info;
405 if (!info || INFO_SELECTED(info)) return;
407 ct->selection = g_list_append(ct->selection, info);
408 collection_table_selection_add(ct, info, SELECTION_SELECTED, NULL);
410 collection_table_update_status(ct);
413 static void collection_table_unselect(CollectTable *ct, CollectInfo *info)
415 ct->prev_selection = info;
417 if (!info || !INFO_SELECTED(info) ) return;
419 ct->selection = g_list_remove(ct->selection, info);
420 collection_table_selection_remove(ct, info, SELECTION_SELECTED, NULL);
422 collection_table_update_status(ct);
425 static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gint select)
429 collection_table_select(ct, info);
433 collection_table_unselect(ct, info);
437 static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gint select)
444 if (!collection_table_find_position(ct, start, &row1, &col1) ||
445 !collection_table_find_position(ct, end, &row2, &col2) ) return;
447 ct->prev_selection = end;
449 if (!options->collections.rectangular_selection)
454 if (g_list_index(ct->cd->list, start) > g_list_index(ct->cd->list, end))
461 work = g_list_find(ct->cd->list, start);
465 collection_table_select_util(ct, info, select);
467 if (work->data != end)
488 DEBUG_1("table: %d x %d to %d x %d", row1, col1, row2, col2);
490 for (i = row1; i <= row2; i++)
492 for (j = col1; j <= col2; j++)
494 CollectInfo *info = collection_table_find_data(ct, i, j, NULL);
495 if (info) collection_table_select_util(ct, info, select);
500 GList *collection_table_selection_get_list(CollectTable *ct)
502 return collection_list_to_filelist(ct->selection);
505 static GList *collection_table_get_list(CollectTable *ct)
507 return collection_list_to_filelist(ct->cd->list);
511 *-------------------------------------------------------------------
512 * tooltip type window
513 *-------------------------------------------------------------------
516 static void tip_show(CollectTable *ct)
521 if (ct->tip_window) return;
523 gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
525 ct->tip_info = collection_table_find_data_by_coord(ct, x, y, NULL);
526 if (!ct->tip_info) return;
528 ct->tip_window = gtk_window_new(GTK_WINDOW_POPUP);
529 gtk_window_set_resizable(GTK_WINDOW(ct->tip_window), FALSE);
530 gtk_container_set_border_width(GTK_CONTAINER(ct->tip_window), 2);
532 label = gtk_label_new(ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
534 g_object_set_data(G_OBJECT(ct->tip_window), "tip_label", label);
535 gtk_container_add(GTK_CONTAINER(ct->tip_window), label);
536 gtk_widget_show(label);
538 gdk_window_get_pointer(NULL, &x, &y, NULL);
540 if (!GTK_WIDGET_REALIZED(ct->tip_window)) gtk_widget_realize(ct->tip_window);
541 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
542 gtk_widget_show(ct->tip_window);
545 static void tip_hide(CollectTable *ct)
547 if (ct->tip_window) gtk_widget_destroy(ct->tip_window);
548 ct->tip_window = NULL;
551 static gint tip_schedule_cb(gpointer data)
553 CollectTable *ct = data;
555 if (ct->tip_delay_id == -1) return FALSE;
559 ct->tip_delay_id = -1;
563 static void tip_schedule(CollectTable *ct)
567 if (ct->tip_delay_id != -1)
569 g_source_remove(ct->tip_delay_id);
570 ct->tip_delay_id = -1;
573 ct->tip_delay_id = g_timeout_add(ct->show_text ? COLLECT_TABLE_TIP_DELAY_PATH : COLLECT_TABLE_TIP_DELAY, tip_schedule_cb, ct);
576 static void tip_unschedule(CollectTable *ct)
580 if (ct->tip_delay_id != -1) g_source_remove(ct->tip_delay_id);
581 ct->tip_delay_id = -1;
584 static void tip_update(CollectTable *ct, CollectInfo *info)
592 gdk_window_get_pointer(NULL, &x, &y, NULL);
593 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
595 if (info != ct->tip_info)
606 label = g_object_get_data(G_OBJECT(ct->tip_window), "tip_label");
607 gtk_label_set_text(GTK_LABEL(label), ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
613 *-------------------------------------------------------------------
615 *-------------------------------------------------------------------
618 static void collection_table_popup_save_as_cb(GtkWidget *widget, gpointer data)
620 CollectTable *ct = data;
622 collection_dialog_save_as(NULL, ct->cd);
625 static void collection_table_popup_save_cb(GtkWidget *widget, gpointer data)
627 CollectTable *ct = data;
631 collection_table_popup_save_as_cb(widget, data);
635 if (!collection_save(ct->cd, ct->cd->path))
637 log_printf("failed saving to collection path: %s\n", ct->cd->path);
641 static GList *collection_table_popup_file_list(CollectTable *ct)
643 if (!ct->click_info) return NULL;
645 if (INFO_SELECTED(ct->click_info))
647 return collection_table_selection_get_list(ct);
650 return g_list_append(NULL, file_data_ref(ct->click_info->fd));
653 static void collection_table_popup_edit_cb(GtkWidget *widget, gpointer data)
656 const gchar *key = data;
659 ct = submenu_item_get_data(widget);
663 list = collection_table_popup_file_list(ct);
666 file_util_start_editor_from_filelist(key, list, ct->listview);
671 static void collection_table_popup_copy_cb(GtkWidget *widget, gpointer data)
673 CollectTable *ct = data;
675 file_util_copy(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);
678 static void collection_table_popup_move_cb(GtkWidget *widget, gpointer data)
680 CollectTable *ct = data;
682 file_util_move(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);
685 static void collection_table_popup_rename_cb(GtkWidget *widget, gpointer data)
687 CollectTable *ct = data;
689 file_util_rename(NULL, collection_table_popup_file_list(ct), ct->listview);
692 static void collection_table_popup_delete_cb(GtkWidget *widget, gpointer data)
694 CollectTable *ct = data;
696 file_util_delete(NULL, collection_table_popup_file_list(ct), ct->listview);
699 static void collection_table_popup_copy_path_cb(GtkWidget *widget, gpointer data)
701 CollectTable *ct = data;
703 file_util_copy_path_list_to_clipboard(collection_table_popup_file_list(ct));
706 static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data)
711 ct = submenu_item_get_data(widget);
715 type = (SortType)GPOINTER_TO_INT(data);
717 collection_set_sort_method(ct->cd, type);
720 static void collection_table_popup_view_new_cb(GtkWidget *widget, gpointer data)
722 CollectTable *ct = data;
724 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
726 view_window_new_from_collection(ct->cd, ct->click_info);
730 static void collection_table_popup_view_cb(GtkWidget *widget, gpointer data)
732 CollectTable *ct = data;
734 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
736 layout_image_set_collection(NULL, ct->cd, ct->click_info);
740 static void collection_table_popup_selectall_cb(GtkWidget *widget, gpointer data)
742 CollectTable *ct = data;
744 collection_table_select_all(ct);
745 ct->prev_selection= ct->click_info;
748 static void collection_table_popup_unselectall_cb(GtkWidget *widget, gpointer data)
750 CollectTable *ct = data;
752 collection_table_unselect_all(ct);
753 ct->prev_selection= ct->click_info;
756 static void collection_table_popup_select_invert_cb(GtkWidget *widget, gpointer data)
758 CollectTable *ct = data;
760 collection_table_select_invert_all(ct);
761 ct->prev_selection= ct->click_info;
764 static void collection_table_popup_remove_cb(GtkWidget *widget, gpointer data)
766 CollectTable *ct = data;
769 if (!ct->click_info) return;
771 if (INFO_SELECTED(ct->click_info))
773 list = g_list_copy(ct->selection);
777 list = g_list_append(NULL, ct->click_info);
780 collection_remove_by_info_list(ct->cd, list);
784 static void collection_table_popup_add_filelist_cb(GtkWidget *widget, gpointer data)
786 CollectTable *ct = data;
789 list = layout_list(NULL);
793 collection_table_add_filelist(ct, list);
798 static void collection_table_popup_add_collection_cb(GtkWidget *widget, gpointer data)
800 CollectTable *ct = data;
802 collection_dialog_append(NULL, ct->cd);
805 static void collection_table_popup_find_dupes_cb(GtkWidget *widget, gpointer data)
807 CollectTable *ct = data;
810 dw = dupe_window_new(DUPE_MATCH_NAME);
811 dupe_window_add_collection(dw, ct->cd);
814 static void collection_table_popup_print_cb(GtkWidget *widget, gpointer data)
816 CollectTable *ct = data;
819 fd = (ct->click_info) ? ct->click_info->fd : NULL;
821 print_window_new(fd, collection_table_selection_get_list(ct), collection_table_get_list(ct), ct->listview);
824 static void collection_table_popup_show_names_cb(GtkWidget *widget, gpointer data)
826 CollectTable *ct = data;
828 collection_table_toggle_filenames(ct);
831 static void collection_table_popup_destroy_cb(GtkWidget *widget, gpointer data)
833 CollectTable *ct = data;
835 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
836 ct->click_info = NULL;
839 filelist_free(ct->drop_list);
840 ct->drop_list = NULL;
841 ct->drop_info = NULL;
844 static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon)
850 menu = popup_menu_short_lived();
852 g_signal_connect(G_OBJECT(menu), "destroy",
853 G_CALLBACK(collection_table_popup_destroy_cb), ct);
855 menu_item_add_sensitive(menu, _("_View"), over_icon,
856 G_CALLBACK(collection_table_popup_view_cb), ct);
857 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, over_icon,
858 G_CALLBACK(collection_table_popup_view_new_cb), ct);
859 menu_item_add_divider(menu);
860 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, over_icon,
861 G_CALLBACK(collection_table_popup_remove_cb), ct);
863 menu_item_add_stock(menu, _("Append from file list"), GTK_STOCK_ADD,
864 G_CALLBACK(collection_table_popup_add_filelist_cb), ct);
865 menu_item_add_stock(menu, _("Append from collection..."), GTK_STOCK_OPEN,
866 G_CALLBACK(collection_table_popup_add_collection_cb), ct);
867 menu_item_add_divider(menu);
869 item = menu_item_add(menu, _("_Selection"), NULL, NULL);
870 submenu = gtk_menu_new();
871 menu_item_add(submenu, _("Select all"),
872 G_CALLBACK(collection_table_popup_selectall_cb), ct);
873 menu_item_add(submenu, _("Select none"),
874 G_CALLBACK(collection_table_popup_unselectall_cb), ct);
875 menu_item_add(submenu, _("Invert selection"),
876 G_CALLBACK(collection_table_popup_select_invert_cb), ct);
877 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
878 menu_item_add_divider(menu);
880 submenu_add_edit(menu, &item,
881 G_CALLBACK(collection_table_popup_edit_cb), ct);
882 gtk_widget_set_sensitive(item, over_icon);
884 menu_item_add_divider(menu);
885 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, over_icon,
886 G_CALLBACK(collection_table_popup_copy_cb), ct);
887 menu_item_add_sensitive(menu, _("_Move..."), over_icon,
888 G_CALLBACK(collection_table_popup_move_cb), ct);
889 menu_item_add_sensitive(menu, _("_Rename..."), over_icon,
890 G_CALLBACK(collection_table_popup_rename_cb), ct);
891 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, over_icon,
892 G_CALLBACK(collection_table_popup_delete_cb), ct);
893 if (options->show_copy_path)
894 menu_item_add_sensitive(menu, _("_Copy path"), over_icon,
895 G_CALLBACK(collection_table_popup_copy_path_cb), ct);
896 menu_item_add_divider(menu);
898 submenu_add_sort(menu, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0);
899 menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
900 G_CALLBACK(collection_table_popup_show_names_cb), ct);
901 menu_item_add_divider(menu);
902 menu_item_add_stock(menu, _("_Save collection"), GTK_STOCK_SAVE,
903 G_CALLBACK(collection_table_popup_save_cb), ct);
904 menu_item_add_stock(menu, _("Save collection _as..."), GTK_STOCK_SAVE_AS,
905 G_CALLBACK(collection_table_popup_save_as_cb), ct);
906 menu_item_add_divider(menu);
907 menu_item_add_stock(menu, _("_Find duplicates..."), GTK_STOCK_FIND,
908 G_CALLBACK(collection_table_popup_find_dupes_cb), ct);
909 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, over_icon,
910 G_CALLBACK(collection_table_popup_print_cb), ct);
915 *-------------------------------------------------------------------
917 *-------------------------------------------------------------------
920 static void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
925 if (g_list_find(ct->cd->list, ct->focus_info))
927 if (info == ct->focus_info)
929 /* ensure focus row col are correct */
930 collection_table_find_position(ct, ct->focus_info,
931 &ct->focus_row, &ct->focus_column);
934 collection_table_selection_remove(ct, ct->focus_info, SELECTION_FOCUS, NULL);
937 if (!collection_table_find_position(ct, info, &row, &col))
939 ct->focus_info = NULL;
941 ct->focus_column = -1;
945 ct->focus_info = info;
947 ct->focus_column = col;
948 collection_table_selection_add(ct, ct->focus_info, SELECTION_FOCUS, NULL);
950 if (collection_table_find_iter(ct, ct->focus_info, &iter, NULL))
953 GtkTreeViewColumn *column;
956 tree_view_row_make_visible(GTK_TREE_VIEW(ct->listview), &iter, FALSE);
958 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
959 tpath = gtk_tree_model_get_path(store, &iter);
960 /* focus is set to an extra column with 0 width to hide focus, we draw it ourself */
961 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), COLLECT_TABLE_MAX_COLUMNS);
962 gtk_tree_view_set_cursor(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE);
963 gtk_tree_path_free(tpath);
967 static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gint relative)
974 new_row = ct->focus_row;
975 new_col = ct->focus_column;
978 if (new_row < 0) new_row = 0;
979 if (new_row >= ct->rows) new_row = ct->rows - 1;
999 new_col = ct->columns - 1;
1006 if (new_col >= ct->columns)
1008 if (new_row < ct->rows - 1)
1015 new_col = ct->columns - 1;
1025 if (new_row >= ct->rows)
1028 new_row = ct->rows - 1;
1031 new_col = ct->columns - 1;
1033 if (new_col >= ct->columns) new_col = ct->columns - 1;
1036 if (new_row == ct->rows - 1)
1040 /* if we moved beyond the last image, go to the last image */
1042 l = g_list_length(ct->cd->list);
1043 if (ct->rows > 1) l -= (ct->rows - 1) * ct->columns;
1044 if (new_col >= l) new_col = l - 1;
1047 if (new_row == -1 || new_col == -1)
1049 if (!ct->cd->list) return;
1050 new_row = new_col = 0;
1053 collection_table_set_focus(ct, collection_table_find_data(ct, new_row, new_col, NULL));
1056 static void collection_table_update_focus(CollectTable *ct)
1061 if (ct->focus_info && collection_table_find_position(ct, ct->focus_info, &new_row, &new_col))
1063 /* first find the old focus, if it exists and is valid */
1067 /* (try to) stay where we were */
1068 new_row = ct->focus_row;
1069 new_col = ct->focus_column;
1072 collection_table_move_focus(ct, new_row, new_col, FALSE);
1075 /* used to figure the page up/down distances */
1076 static gint page_height(CollectTable *ct)
1083 adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
1084 page_size = (gint)adj->page_increment;
1086 row_height = options->thumbnails.max_height + THUMB_BORDER_PADDING * 2;
1087 if (ct->show_text) row_height += options->thumbnails.max_height / 3;
1089 ret = page_size / row_height;
1090 if (ret < 1) ret = 1;
1095 static void collection_table_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
1097 CollectTable *ct = data;
1098 GtkTreeModel *store;
1104 if (!collection_table_find_iter(ct, ct->click_info, &iter, &column)) return;
1105 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1106 tpath = gtk_tree_model_get_path(store, &iter);
1107 tree_view_get_cell_clamped(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE, x, y, &cw, &ch);
1108 gtk_tree_path_free(tpath);
1110 popup_menu_position_clamp(menu, x, y, 0);
1113 static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
1115 CollectTable *ct = data;
1122 switch (event->keyval)
1124 case GDK_Left: case GDK_KP_Left:
1127 case GDK_Right: case GDK_KP_Right:
1130 case GDK_Up: case GDK_KP_Up:
1133 case GDK_Down: case GDK_KP_Down:
1136 case GDK_Page_Up: case GDK_KP_Page_Up:
1137 focus_row = -page_height(ct);
1139 case GDK_Page_Down: case GDK_KP_Page_Down:
1140 focus_row = page_height(ct);
1142 case GDK_Home: case GDK_KP_Home:
1143 focus_row = -ct->focus_row;
1144 focus_col = -ct->focus_column;
1146 case GDK_End: case GDK_KP_End:
1147 focus_row = ct->rows - 1 - ct->focus_row;
1148 focus_col = ct->columns - 1 - ct->focus_column;
1151 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1154 ct->click_info = info;
1155 if (event->state & GDK_CONTROL_MASK)
1157 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1161 collection_table_unselect_all(ct);
1162 collection_table_select(ct, info);
1167 if (event->state & GDK_CONTROL_MASK) collection_table_toggle_filenames(ct);
1171 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1172 ct->click_info = info;
1174 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1177 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1178 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, collection_table_menu_pos_cb, ct, 0, GDK_CURRENT_TIME);
1181 stop_signal = FALSE;
1185 if (focus_row != 0 || focus_col != 0)
1187 CollectInfo *new_info;
1188 CollectInfo *old_info;
1190 old_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1191 collection_table_move_focus(ct, focus_row, focus_col, TRUE);
1192 new_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1194 if (new_info != old_info)
1196 if (event->state & GDK_SHIFT_MASK)
1198 if (!options->collections.rectangular_selection)
1200 collection_table_select_region_util(ct, old_info, new_info, FALSE);
1204 collection_table_select_region_util(ct, ct->click_info, old_info, FALSE);
1206 collection_table_select_region_util(ct, ct->click_info, new_info, TRUE);
1208 else if (event->state & GDK_CONTROL_MASK)
1210 ct->click_info = new_info;
1214 ct->click_info = new_info;
1215 collection_table_unselect_all(ct);
1216 collection_table_select(ct, new_info);
1224 g_signal_stop_emission_by_name(GTK_OBJECT(widget), "key_press_event");
1233 *-------------------------------------------------------------------
1235 *-------------------------------------------------------------------
1238 static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gint *after, GdkRectangle *cell,
1239 gint use_coord, gint x, gint y)
1241 CollectInfo *info = NULL;
1242 GtkTreeModel *store;
1245 GtkTreeViewColumn *column;
1247 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1249 if (!use_coord) gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
1254 if (collection_table_find_iter(ct, source, &iter, &col))
1256 tpath = gtk_tree_model_get_path(store, &iter);
1257 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1258 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1259 gtk_tree_path_free(tpath);
1262 *after = (x > cell->x + (cell->width / 2));
1267 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
1268 &tpath, &column, NULL, NULL))
1273 gtk_tree_model_get_iter(store, &iter, tpath);
1274 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1276 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
1277 info = g_list_nth_data(list, n);
1281 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1282 *after = (x > cell->x + (cell->width / 2));
1285 gtk_tree_path_free(tpath);
1292 work = g_list_last(ct->cd->list);
1300 if (collection_table_find_iter(ct, info, &iter, &col))
1302 tpath = gtk_tree_model_get_path(store, &iter);
1303 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1304 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1305 gtk_tree_path_free(tpath);
1313 static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint y)
1319 info = collection_table_insert_find(ct, NULL, &after, &cell, TRUE, x, y);
1325 work = g_list_find(ct->cd->list, info);
1326 if (work && work->next)
1328 info = work->next->data;
1339 static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gint enable)
1347 if (ct->marker_window) gdk_window_destroy(ct->marker_window);
1348 ct->marker_window = NULL;
1353 info = collection_table_insert_find(ct, info, &after, &cell, FALSE, 0, 0);
1355 /* this setting does not take into account (after), but since it is not really used... */
1356 ct->marker_info = info;
1361 if (!ct->marker_window)
1364 GdkWindowAttr attributes;
1365 gint attributes_mask;
1371 parent = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(ct->listview));
1373 pb = gdk_pixbuf_new_from_xpm_data((const gchar **)marker_xpm);
1374 gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128);
1377 gdk_drawable_get_size(pixmap, &w, &h);
1379 attributes.window_type = GDK_WINDOW_CHILD;
1380 attributes.wclass = GDK_INPUT_OUTPUT;
1381 attributes.width = w;
1382 attributes.height = h;
1383 attributes.event_mask = gtk_widget_get_events(ct->listview);
1384 attributes_mask = 0;
1386 ct->marker_window = gdk_window_new(parent, &attributes, attributes_mask);
1387 gdk_window_set_back_pixmap(ct->marker_window, pixmap, FALSE);
1388 gdk_window_shape_combine_mask(ct->marker_window, mask, 0, 0);
1390 g_object_unref(pixmap);
1391 if (mask) g_object_unref(mask);
1399 gdk_drawable_get_size(ct->marker_window, &w, &h);
1407 x = cell.x + cell.width;
1410 y = cell.y + (cell.height / 2) - (h / 2);
1412 gdk_window_move(ct->marker_window, x, y);
1413 gdk_window_clear(ct->marker_window);
1414 if (!gdk_window_is_visible(ct->marker_window)) gdk_window_show(ct->marker_window);
1418 if (gdk_window_is_visible(ct->marker_window)) gdk_window_hide(ct->marker_window);
1423 *-------------------------------------------------------------------
1424 * mouse drag auto-scroll
1425 *-------------------------------------------------------------------
1428 static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gint drop_event)
1432 info = collection_table_find_data_by_coord(ct, x, y, NULL);
1437 collection_table_insert_marker(ct, info, TRUE);
1441 tip_update(ct, info);
1445 static gint collection_table_auto_scroll_idle_cb(gpointer data)
1447 CollectTable *ct = data;
1452 if (ct->drop_idle_id == -1) return FALSE;
1454 window = ct->listview->window;
1455 gdk_window_get_pointer(window, &x, &y, NULL);
1456 gdk_drawable_get_size(window, &w, &h);
1457 if (x >= 0 && x < w && y >= 0 && y < h)
1459 collection_table_motion_update(ct, x, y, TRUE);
1462 ct->drop_idle_id = -1;
1466 static gint collection_table_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data)
1468 CollectTable *ct = data;
1470 if (ct->drop_idle_id == -1) ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
1475 static void collection_table_scroll(CollectTable *ct, gint scroll)
1479 if (ct->drop_idle_id != -1)
1481 g_source_remove(ct->drop_idle_id);
1482 ct->drop_idle_id = -1;
1484 widget_auto_scroll_stop(ct->listview);
1485 collection_table_insert_marker(ct, NULL, FALSE);
1489 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
1490 widget_auto_scroll_start(ct->listview, adj, -1, options->thumbnails.max_height / 2,
1491 collection_table_auto_scroll_notify_cb, ct);
1496 *-------------------------------------------------------------------
1498 *-------------------------------------------------------------------
1501 static gint collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1503 CollectTable *ct = data;
1505 collection_table_motion_update(ct, (gint)bevent->x, (gint)bevent->y, FALSE);
1510 static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1512 CollectTable *ct = data;
1518 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1520 ct->click_info = info;
1521 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, &iter);
1523 switch (bevent->button)
1525 case MOUSE_BUTTON_LEFT:
1526 if (bevent->type == GDK_2BUTTON_PRESS)
1530 layout_image_set_collection(NULL, ct->cd, info);
1533 else if (!GTK_WIDGET_HAS_FOCUS(ct->listview))
1535 gtk_widget_grab_focus(ct->listview);
1538 case MOUSE_BUTTON_RIGHT:
1539 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1540 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
1549 static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1551 CollectTable *ct = data;
1553 CollectInfo *info = NULL;
1557 if ((gint)bevent->x != 0 || (gint) bevent->y != 0)
1559 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1564 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1567 if (bevent->button == MOUSE_BUTTON_LEFT &&
1568 info && ct->click_info == info)
1570 collection_table_set_focus(ct, info);
1572 if (bevent->state & GDK_CONTROL_MASK)
1576 select = !INFO_SELECTED(info);
1577 if ((bevent->state & GDK_SHIFT_MASK) && ct->prev_selection)
1579 collection_table_select_region_util(ct, ct->prev_selection, info, select);
1583 collection_table_select_util(ct, info, select);
1588 collection_table_unselect_all(ct);
1590 if ((bevent->state & GDK_SHIFT_MASK) &&
1593 collection_table_select_region_util(ct, ct->prev_selection, info, TRUE);
1597 collection_table_select_util(ct, info, TRUE);
1601 else if (bevent->button == MOUSE_BUTTON_MIDDLE &&
1602 info && ct->click_info == info)
1604 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1610 static gint collection_table_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
1612 CollectTable *ct = data;
1619 *-------------------------------------------------------------------
1620 * populate, add, insert, etc.
1621 *-------------------------------------------------------------------
1624 static gboolean collection_table_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data)
1628 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
1634 static void collection_table_clear_store(CollectTable *ct)
1636 GtkTreeModel *store;
1638 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1639 gtk_tree_model_foreach(store, collection_table_destroy_node_cb, NULL);
1641 gtk_list_store_clear(GTK_LIST_STORE(store));
1644 static GList *collection_table_add_row(CollectTable *ct, GtkTreeIter *iter)
1646 GtkListStore *store;
1650 for (i = 0; i < ct->columns; i++) list = g_list_prepend(list, NULL);
1652 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)));
1653 gtk_list_store_append(store, iter);
1654 gtk_list_store_set(store, iter, CTABLE_COLUMN_POINTER, list, -1);
1659 static void collection_table_populate(CollectTable *ct, gint resize)
1664 collection_table_verify_selections(ct);
1666 collection_table_clear_store(ct);
1673 thumb_width = collection_table_get_icon_width(ct);
1675 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
1677 GtkTreeViewColumn *column;
1678 GtkCellRenderer *cell;
1681 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), i);
1682 gtk_tree_view_column_set_visible(column, (i < ct->columns));
1683 gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6));
1685 list = gtk_tree_view_column_get_cell_renderers(column);
1686 cell = (list) ? list->data : NULL;
1689 if (cell && GQV_IS_CELL_RENDERER_ICON(cell))
1691 g_object_set(G_OBJECT(cell), "fixed_width", thumb_width,
1692 "fixed_height", options->thumbnails.max_height,
1693 "show_text", ct->show_text, NULL);
1696 if (GTK_WIDGET_REALIZED(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
1700 work = ct->cd->list;
1708 list = collection_table_add_row(ct, &iter);
1709 while (work && list)
1711 list->data = work->data;
1719 collection_table_update_focus(ct);
1720 collection_table_update_status(ct);
1723 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force)
1728 thumb_width = collection_table_get_icon_width(ct);
1730 new_cols = w / (thumb_width + (THUMB_BORDER_PADDING * 6));
1731 if (new_cols < 1) new_cols = 1;
1733 if (!force && new_cols == ct->columns) return;
1735 ct->columns = new_cols;
1737 collection_table_populate(ct, TRUE);
1739 DEBUG_1("col tab pop cols=%d rows=%d", ct->columns, ct->rows);
1742 static void collection_table_sync(CollectTable *ct)
1744 GtkTreeModel *store;
1749 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1754 work = ct->cd->list;
1760 if (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1762 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1763 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1767 list = collection_table_add_row(ct, &iter);
1792 while (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1796 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1797 gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
1803 collection_table_update_focus(ct);
1804 collection_table_update_status(ct);
1807 static gint collection_table_sync_idle_cb(gpointer data)
1809 CollectTable *ct = data;
1811 if (ct->sync_idle_id == -1) return FALSE;
1812 ct->sync_idle_id = -1;
1814 collection_table_sync(ct);
1818 static void collection_table_sync_idle(CollectTable *ct)
1820 if (ct->sync_idle_id == -1)
1822 /* high priority, the view needs to be resynced before a redraw
1823 * may contain invalid pointers at this time
1825 ct->sync_idle_id = g_idle_add_full(G_PRIORITY_HIGH, collection_table_sync_idle_cb, ct, NULL);
1829 void collection_table_add_filelist(CollectTable *ct, GList *list)
1838 collection_add(ct->cd, (FileData *)work->data, FALSE);
1843 static void collection_table_insert_filelist(CollectTable *ct, GList *list, CollectInfo *insert_info)
1852 collection_insert(ct->cd, (FileData *)work->data, insert_info, FALSE);
1856 collection_table_sync_idle(ct);
1859 static void collection_table_move_by_info_list(CollectTable *ct, GList *info_list, gint row, gint col)
1862 GList *insert_pos = NULL;
1866 if (!info_list) return;
1868 info = collection_table_find_data(ct, row, col, NULL);
1870 if (!info_list->next && info_list->data == info) return;
1872 if (info) insert_pos = g_list_find(ct->cd->list, info);
1874 /* FIXME: this may get slow for large lists */
1876 while (insert_pos && work)
1878 if (insert_pos->data == work->data)
1880 insert_pos = insert_pos->next;
1892 ct->cd->list = g_list_remove(ct->cd->list, work->data);
1896 /* place them back in */
1897 temp = g_list_copy(info_list);
1901 ct->cd->list = uig_list_insert_list(ct->cd->list, insert_pos, temp);
1905 ct->cd->list = g_list_concat(temp, ct->cd->list);
1909 ct->cd->list = g_list_concat(ct->cd->list, temp);
1912 ct->cd->changed = TRUE;
1914 collection_table_sync_idle(ct);
1919 *-------------------------------------------------------------------
1921 *-------------------------------------------------------------------
1924 void collection_table_file_update(CollectTable *ct, CollectInfo *info)
1932 collection_table_update_extras(ct, FALSE, 0.0);
1936 if (!collection_table_find_position(ct, info, &row, &col)) return;
1938 if (ct->columns != 0 && ct->rows != 0)
1940 value = (gdouble)(row * ct->columns + col) / (ct->columns * ct->rows);
1947 collection_table_update_extras(ct, TRUE, value);
1949 if (collection_table_find_iter(ct, info, &iter, NULL))
1951 GtkTreeModel *store;
1954 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1955 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1956 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1960 void collection_table_file_add(CollectTable *ct, CollectInfo *info)
1962 collection_table_sync_idle(ct);
1965 void collection_table_file_insert(CollectTable *ct, CollectInfo *ci)
1967 collection_table_sync_idle(ct);
1970 void collection_table_file_remove(CollectTable *ct, CollectInfo *ci)
1972 if (ci && INFO_SELECTED(ci))
1974 ct->selection = g_list_remove(ct->selection, ci);
1977 collection_table_sync_idle(ct);
1980 void collection_table_refresh(CollectTable *ct)
1982 collection_table_populate(ct, FALSE);
1986 *-------------------------------------------------------------------
1988 *-------------------------------------------------------------------
1991 static void collection_table_add_dir_recursive(CollectTable *ct, FileData *dir_fd, gint recursive)
1997 if (!filelist_read(dir_fd, &f, recursive ? &d : NULL))
2000 f = filelist_filter(f, FALSE);
2001 d = filelist_filter(d, TRUE);
2003 f = filelist_sort_path(f);
2004 d = filelist_sort_path(d);
2006 collection_table_insert_filelist(ct, f, ct->marker_info);
2008 work = g_list_last(d);
2011 collection_table_add_dir_recursive(ct, (FileData *)work->data, TRUE);
2019 static void confirm_dir_list_do(CollectTable *ct, GList *list, gint recursive)
2024 FileData *fd = work->data;
2026 if (isdir(fd->path)) collection_table_add_dir_recursive(ct, fd, recursive);
2028 collection_table_insert_filelist(ct, list, ct->marker_info);
2032 static void confirm_dir_list_add(GtkWidget *widget, gpointer data)
2034 CollectTable *ct = data;
2036 confirm_dir_list_do(ct, ct->drop_list, FALSE);
2039 static void confirm_dir_list_recurse(GtkWidget *widget, gpointer data)
2041 CollectTable *ct = data;
2043 confirm_dir_list_do(ct, ct->drop_list, TRUE);
2046 static void confirm_dir_list_skip(GtkWidget *widget, gpointer data)
2048 CollectTable *ct = data;
2050 collection_table_insert_filelist(ct, ct->drop_list, ct->marker_info);
2053 static GtkWidget *collection_table_drop_menu(CollectTable *ct)
2057 menu = popup_menu_short_lived();
2058 g_signal_connect(G_OBJECT(menu), "destroy",
2059 G_CALLBACK(collection_table_popup_destroy_cb), ct);
2061 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL);
2062 menu_item_add_divider(menu);
2063 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK,
2064 G_CALLBACK(confirm_dir_list_add), ct);
2065 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD,
2066 G_CALLBACK(confirm_dir_list_recurse), ct);
2067 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE,
2068 G_CALLBACK(confirm_dir_list_skip), ct);
2069 menu_item_add_divider(menu);
2070 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, ct);
2076 *-------------------------------------------------------------------
2078 *-------------------------------------------------------------------
2081 static GtkTargetEntry collection_drag_types[] = {
2082 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
2083 { "text/uri-list", 0, TARGET_URI_LIST },
2084 { "text/plain", 0, TARGET_TEXT_PLAIN }
2086 static gint n_collection_drag_types = 3;
2088 static GtkTargetEntry collection_drop_types[] = {
2089 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
2090 { "text/uri-list", 0, TARGET_URI_LIST }
2092 static gint n_collection_drop_types = 2;
2095 static void collection_table_dnd_get(GtkWidget *widget, GdkDragContext *context,
2096 GtkSelectionData *selection_data, guint info,
2097 guint time, gpointer data)
2099 CollectTable *ct = data;
2102 gchar *uri_text = NULL;
2105 if (!ct->click_info) return;
2107 selected = INFO_SELECTED(ct->click_info);
2111 case TARGET_APP_COLLECTION_MEMBER:
2114 uri_text = collection_info_list_to_dnd_data(ct->cd, ct->selection, &total);
2118 list = g_list_append(NULL, ct->click_info);
2119 uri_text = collection_info_list_to_dnd_data(ct->cd, list, &total);
2123 case TARGET_URI_LIST:
2124 case TARGET_TEXT_PLAIN:
2128 list = collection_table_selection_get_list(ct);
2132 list = g_list_append(NULL, file_data_ref(ct->click_info->fd));
2136 uri_text = uri_text_from_filelist(list, &total, (info == TARGET_TEXT_PLAIN));
2137 filelist_free(list);
2141 gtk_selection_data_set(selection_data, selection_data->target,
2142 8, (guchar *)uri_text, total);
2147 static void collection_table_dnd_receive(GtkWidget *widget, GdkDragContext *context,
2149 GtkSelectionData *selection_data, guint info,
2150 guint time, gpointer data)
2152 CollectTable *ct = data;
2154 GList *info_list = NULL;
2155 CollectionData *source;
2156 CollectInfo *drop_info;
2159 DEBUG_1("%s", selection_data->data);
2161 collection_table_scroll(ct, FALSE);
2162 collection_table_insert_marker(ct, NULL, FALSE);
2164 drop_info = collection_table_insert_point(ct, x, y);
2168 case TARGET_APP_COLLECTION_MEMBER:
2169 source = collection_from_dnd_data((gchar *)selection_data->data, &list, &info_list);
2172 if (source == ct->cd)
2177 /* it is a move within a collection */
2178 filelist_free(list);
2183 collection_table_move_by_info_list(ct, info_list, -1, -1);
2185 else if (collection_table_find_position(ct, drop_info, &row, &col))
2187 collection_table_move_by_info_list(ct, info_list, row, col);
2192 /* it is a move/copy across collections */
2193 if (context->action == GDK_ACTION_MOVE)
2195 collection_remove_by_info_list(source, info_list);
2198 g_list_free(info_list);
2201 case TARGET_URI_LIST:
2202 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE);
2206 FileData *fd = work->data;
2207 if (isdir(fd->path))
2211 ct->drop_list = list;
2212 ct->drop_info = drop_info;
2213 menu = collection_table_drop_menu(ct);
2214 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time);
2227 collection_table_insert_filelist(ct, list, drop_info);
2228 filelist_free(list);
2232 static void collection_table_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
2234 CollectTable *ct = data;
2236 if (ct->click_info && ct->click_info->pixbuf)
2240 if (INFO_SELECTED(ct->click_info))
2241 items = g_list_length(ct->selection);
2244 dnd_set_drag_icon(widget, context, ct->click_info->pixbuf, items);
2248 static void collection_table_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
2250 CollectTable *ct = data;
2252 /* apparently a leave event is not generated on a drop */
2255 collection_table_scroll(ct, FALSE);
2258 static gint collection_table_dnd_motion(GtkWidget *widget, GdkDragContext *context,
2259 gint x, gint y, guint time, gpointer data)
2261 CollectTable *ct = data;
2263 collection_table_motion_update(ct, x, y, TRUE);
2264 collection_table_scroll(ct, TRUE);
2269 static void collection_table_dnd_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data)
2271 CollectTable *ct = data;
2273 collection_table_scroll(ct, FALSE);
2276 static void collection_table_dnd_init(CollectTable *ct)
2278 gtk_drag_source_set(ct->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
2279 collection_drag_types, n_collection_drag_types,
2280 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
2281 g_signal_connect(G_OBJECT(ct->listview), "drag_data_get",
2282 G_CALLBACK(collection_table_dnd_get), ct);
2283 g_signal_connect(G_OBJECT(ct->listview), "drag_begin",
2284 G_CALLBACK(collection_table_dnd_begin), ct);
2285 g_signal_connect(G_OBJECT(ct->listview), "drag_end",
2286 G_CALLBACK(collection_table_dnd_end), ct);
2288 gtk_drag_dest_set(ct->listview,
2289 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
2290 collection_drop_types, n_collection_drop_types,
2291 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK);
2292 g_signal_connect(G_OBJECT(ct->listview), "drag_motion",
2293 G_CALLBACK(collection_table_dnd_motion), ct);
2294 g_signal_connect(G_OBJECT(ct->listview), "drag_leave",
2295 G_CALLBACK(collection_table_dnd_leave), ct);
2296 g_signal_connect(G_OBJECT(ct->listview), "drag_data_received",
2297 G_CALLBACK(collection_table_dnd_receive), ct);
2301 *-----------------------------------------------------------------------------
2303 *-----------------------------------------------------------------------------
2306 typedef struct _ColumnData ColumnData;
2313 static void collection_table_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
2314 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
2316 ColumnData *cd = data;
2326 gtk_tree_model_get(tree_model, iter, CTABLE_COLUMN_POINTER, &list, -1);
2327 info = g_list_nth_data(list, cd->number);
2329 style = gtk_widget_get_style(ct->listview);
2330 if (info && (info->flag_mask & SELECTION_SELECTED) )
2332 memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg));
2333 memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg));
2337 memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg));
2338 memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg));
2341 if (info && (info->flag_mask & SELECTION_PRELIGHT))
2344 shift_color(&color_fg, -1, 0);
2346 shift_color(&color_bg, -1, 0);
2349 if (GQV_IS_CELL_RENDERER_ICON(cell))
2353 g_object_set(cell, "pixbuf", info->pixbuf,
2354 "text", info->fd->name,
2355 "cell-background-gdk", &color_bg,
2356 "cell-background-set", TRUE,
2357 "foreground-gdk", &color_fg,
2358 "foreground-set", TRUE,
2359 "has-focus", (ct->focus_info == info), NULL);
2363 g_object_set(cell, "pixbuf", NULL,
2365 "cell-background-set", FALSE,
2366 "foreground-set", FALSE,
2367 "has-focus", FALSE, NULL);
2372 static void collection_table_append_column(CollectTable *ct, gint n)
2375 GtkTreeViewColumn *column;
2376 GtkCellRenderer *renderer;
2378 column = gtk_tree_view_column_new();
2379 gtk_tree_view_column_set_min_width(column, 0);
2381 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
2382 gtk_tree_view_column_set_alignment(column, 0.5);
2384 renderer = gqv_cell_renderer_icon_new();
2385 gtk_tree_view_column_pack_start(column, renderer, FALSE);
2386 g_object_set(G_OBJECT(renderer), "xpad", THUMB_BORDER_PADDING * 2,
2387 "ypad", THUMB_BORDER_PADDING,
2388 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
2390 g_object_set_data(G_OBJECT(column), "column_number", GINT_TO_POINTER(n));
2392 cd = g_new0(ColumnData, 1);
2395 gtk_tree_view_column_set_cell_data_func(column, renderer, collection_table_cell_data_cb, cd, g_free);
2397 gtk_tree_view_append_column(GTK_TREE_VIEW(ct->listview), column);
2401 *-------------------------------------------------------------------
2403 *-------------------------------------------------------------------
2406 static void collection_table_destroy(GtkWidget *widget, gpointer data)
2408 CollectTable *ct = data;
2412 g_signal_handlers_disconnect_matched(GTK_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA,
2414 gtk_widget_destroy(ct->popup);
2417 if (ct->sync_idle_id != -1) g_source_remove(ct->sync_idle_id);
2420 collection_table_scroll(ct, FALSE);
2425 static void collection_table_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
2427 CollectTable *ct = data;
2429 collection_table_populate_at_new_size(ct, allocation->width, allocation->height, FALSE);
2432 CollectTable *collection_table_new(CollectionData *cd)
2435 GtkListStore *store;
2436 GtkTreeSelection *selection;
2439 ct = g_new0(CollectTable, 1);
2444 ct->selection = NULL;
2445 ct->prev_selection = NULL;
2447 ct->tip_window = NULL;
2448 ct->tip_delay_id = -1;
2450 ct->marker_window = NULL;
2451 ct->marker_info = NULL;
2453 ct->status_label = NULL;
2454 ct->extra_label = NULL;
2457 ct->focus_column = 0;
2458 ct->focus_info = NULL;
2460 ct->show_text = options->show_icon_names;
2462 ct->sync_idle_id = -1;
2463 ct->drop_idle_id = -1;
2466 ct->drop_info = NULL;
2467 ct->drop_list = NULL;
2469 ct->scrolled = gtk_scrolled_window_new(NULL, NULL);
2470 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN);
2471 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ct->scrolled),
2472 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2474 store = gtk_list_store_new(1, G_TYPE_POINTER);
2475 ct->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
2476 g_object_unref(store);
2478 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ct->listview));
2479 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_NONE);
2481 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ct->listview), FALSE);
2482 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ct->listview), FALSE);
2484 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
2486 collection_table_append_column(ct, i);
2489 /* zero width column to hide tree view focus, we draw it ourselves */
2490 collection_table_append_column(ct, i);
2491 /* end column to fill white space */
2492 collection_table_append_column(ct, i);
2494 g_signal_connect(G_OBJECT(ct->listview), "destroy",
2495 G_CALLBACK(collection_table_destroy), ct);
2496 g_signal_connect(G_OBJECT(ct->listview), "size_allocate",
2497 G_CALLBACK(collection_table_sized), ct);
2498 g_signal_connect(G_OBJECT(ct->listview), "key_press_event",
2499 G_CALLBACK(collection_table_press_key_cb), ct);
2501 gtk_container_add(GTK_CONTAINER(ct->scrolled), ct->listview);
2502 gtk_widget_show(ct->listview);
2504 collection_table_dnd_init(ct);
2506 gtk_widget_set_events(ct->listview, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK |
2507 GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK);
2508 g_signal_connect(G_OBJECT(ct->listview),"button_press_event",
2509 G_CALLBACK(collection_table_press_cb), ct);
2510 g_signal_connect(G_OBJECT(ct->listview),"button_release_event",
2511 G_CALLBACK(collection_table_release_cb), ct);
2512 g_signal_connect(G_OBJECT(ct->listview),"motion_notify_event",
2513 G_CALLBACK(collection_table_motion_cb), ct);
2514 g_signal_connect(G_OBJECT(ct->listview), "leave_notify_event",
2515 G_CALLBACK(collection_table_leave_cb), ct);
2520 void collection_table_set_labels(CollectTable *ct, GtkWidget *status, GtkWidget *extra)
2522 ct->status_label = status;
2523 ct->extra_label = extra;
2524 collection_table_update_status(ct);
2525 collection_table_update_extras(ct, FALSE, 0.0);
2528 CollectInfo *collection_table_get_focus_info(CollectTable *ct)
2530 return collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
2532 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */