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_bookmark.h"
32 #include "ui_fileops.h"
34 #include "ui_tree_edit.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;
133 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
134 &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);
147 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
150 if (iter) *iter = row;
151 return g_list_nth_data(list, n);
158 static void collection_table_update_status(CollectTable *ct)
160 if (ct->status_label)
166 buf = g_strdup(_("Empty"));
168 else if (ct->selection)
170 buf = g_strdup_printf(_("%d images (%d)"), g_list_length(ct->cd->list), g_list_length(ct->selection));
174 buf = g_strdup_printf(_("%d images"), g_list_length(ct->cd->list));
177 gtk_label_set_text(GTK_LABEL(ct->status_label), buf);
182 static void collection_table_update_extras(CollectTable *ct, gint loading, gdouble value)
188 text = _("Loading thumbs...");
192 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ct->extra_label), value);
193 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ct->extra_label), text);
197 static void collection_table_toggle_filenames(CollectTable *ct)
199 ct->show_text = !ct->show_text;
200 options->show_icon_names = ct->show_text;
202 collection_table_populate_at_new_size(ct, ct->listview->allocation.width, ct->listview->allocation.height, TRUE);
205 static gint collection_table_get_icon_width(CollectTable *ct)
209 if (!ct->show_text) return options->thumbnails.max_width;
211 width = options->thumbnails.max_width + options->thumbnails.max_width / 2;
212 if (width < THUMB_MIN_ICON_WIDTH) width = THUMB_MIN_ICON_WIDTH;
213 if (width > THUMB_MAX_ICON_WIDTH) width = options->thumbnails.max_width;
219 *-------------------------------------------------------------------
221 *-------------------------------------------------------------------
224 static void collection_table_selection_set(CollectTable *ct, CollectInfo *info, SelectionType value, GtkTreeIter *iter)
231 if (info->flag_mask == value) return;
232 info->flag_mask = value;
234 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
237 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
238 if (list) gtk_list_store_set(GTK_LIST_STORE(store), iter, CTABLE_COLUMN_POINTER, list, -1);
244 if (collection_table_find_iter(ct, info, &row, NULL))
246 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
247 if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, CTABLE_COLUMN_POINTER, list, -1);
252 static void collection_table_selection_add(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
256 collection_table_selection_set(ct, info, info->flag_mask | mask, iter);
259 static void collection_table_selection_remove(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
263 collection_table_selection_set(ct, info, info->flag_mask & ~mask, iter);
266 *-------------------------------------------------------------------
268 *-------------------------------------------------------------------
271 static void collection_table_verify_selections(CollectTable *ct)
275 work = ct->selection;
278 CollectInfo *info = work->data;
280 if (!g_list_find(ct->cd->list, info))
282 ct->selection = g_list_remove(ct->selection, info);
287 void collection_table_select_all(CollectTable *ct)
291 g_list_free(ct->selection);
292 ct->selection = NULL;
297 ct->selection = g_list_append(ct->selection, work->data);
298 collection_table_selection_add(ct, work->data, SELECTION_SELECTED, NULL);
302 collection_table_update_status(ct);
305 void collection_table_unselect_all(CollectTable *ct)
309 work = ct->selection;
312 collection_table_selection_remove(ct, work->data, SELECTION_SELECTED, NULL);
316 g_list_free(ct->selection);
317 ct->selection = NULL;
319 collection_table_update_status(ct);
322 static void collection_table_select(CollectTable *ct, CollectInfo *info)
324 ct->prev_selection = info;
326 if (!info || INFO_SELECTED(info)) return;
328 ct->selection = g_list_append(ct->selection, info);
329 collection_table_selection_add(ct, info, SELECTION_SELECTED, NULL);
331 collection_table_update_status(ct);
334 static void collection_table_unselect(CollectTable *ct, CollectInfo *info)
336 ct->prev_selection = info;
338 if (!info || !INFO_SELECTED(info) ) return;
340 ct->selection = g_list_remove(ct->selection, info);
341 collection_table_selection_remove(ct, info, SELECTION_SELECTED, NULL);
343 collection_table_update_status(ct);
346 static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gint select)
350 collection_table_select(ct, info);
354 collection_table_unselect(ct, info);
358 static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gint select)
365 if (!collection_table_find_position(ct, start, &row1, &col1) ||
366 !collection_table_find_position(ct, end, &row2, &col2) ) return;
368 ct->prev_selection = end;
370 if (!options->collections.rectangular_selection)
375 if (g_list_index(ct->cd->list, start) > g_list_index(ct->cd->list, end))
382 work = g_list_find(ct->cd->list, start);
386 collection_table_select_util(ct, info, select);
388 if (work->data != end)
409 DEBUG_1("table: %d x %d to %d x %d", row1, col1, row2, col2);
411 for (i = row1; i <= row2; i++)
413 for (j = col1; j <= col2; j++)
415 CollectInfo *info = collection_table_find_data(ct, i, j, NULL);
416 if (info) collection_table_select_util(ct, info, select);
421 GList *collection_table_selection_get_list(CollectTable *ct)
423 return collection_list_to_filelist(ct->selection);
426 static GList *collection_table_get_list(CollectTable *ct)
428 return collection_list_to_filelist(ct->cd->list);
432 *-------------------------------------------------------------------
433 * tooltip type window
434 *-------------------------------------------------------------------
437 static void tip_show(CollectTable *ct)
442 if (ct->tip_window) return;
444 gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
446 ct->tip_info = collection_table_find_data_by_coord(ct, x, y, NULL);
447 if (!ct->tip_info) return;
449 ct->tip_window = gtk_window_new(GTK_WINDOW_POPUP);
450 gtk_window_set_resizable(GTK_WINDOW(ct->tip_window), FALSE);
451 gtk_container_set_border_width(GTK_CONTAINER(ct->tip_window), 2);
453 label = gtk_label_new(ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
455 g_object_set_data(G_OBJECT(ct->tip_window), "tip_label", label);
456 gtk_container_add(GTK_CONTAINER(ct->tip_window), label);
457 gtk_widget_show(label);
459 gdk_window_get_pointer(NULL, &x, &y, NULL);
461 if (!GTK_WIDGET_REALIZED(ct->tip_window)) gtk_widget_realize(ct->tip_window);
462 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
463 gtk_widget_show(ct->tip_window);
466 static void tip_hide(CollectTable *ct)
468 if (ct->tip_window) gtk_widget_destroy(ct->tip_window);
469 ct->tip_window = NULL;
472 static gint tip_schedule_cb(gpointer data)
474 CollectTable *ct = data;
476 if (ct->tip_delay_id == -1) return FALSE;
480 ct->tip_delay_id = -1;
484 static void tip_schedule(CollectTable *ct)
488 if (ct->tip_delay_id != -1)
490 g_source_remove(ct->tip_delay_id);
491 ct->tip_delay_id = -1;
494 ct->tip_delay_id = g_timeout_add(ct->show_text ? COLLECT_TABLE_TIP_DELAY_PATH : COLLECT_TABLE_TIP_DELAY, tip_schedule_cb, ct);
497 static void tip_unschedule(CollectTable *ct)
501 if (ct->tip_delay_id != -1) g_source_remove(ct->tip_delay_id);
502 ct->tip_delay_id = -1;
505 static void tip_update(CollectTable *ct, CollectInfo *info)
513 gdk_window_get_pointer(NULL, &x, &y, NULL);
514 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
516 if (info != ct->tip_info)
527 label = g_object_get_data(G_OBJECT(ct->tip_window), "tip_label");
528 gtk_label_set_text(GTK_LABEL(label), ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
534 *-------------------------------------------------------------------
536 *-------------------------------------------------------------------
539 static void collection_table_popup_save_as_cb(GtkWidget *widget, gpointer data)
541 CollectTable *ct = data;
543 collection_dialog_save_as(NULL, ct->cd);
546 static void collection_table_popup_save_cb(GtkWidget *widget, gpointer data)
548 CollectTable *ct = data;
552 collection_table_popup_save_as_cb(widget, data);
556 if (!collection_save(ct->cd, ct->cd->path))
558 log_printf("failed saving to collection path: %s\n", ct->cd->path);
562 static GList *collection_table_popup_file_list(CollectTable *ct)
564 if (!ct->click_info) return NULL;
566 if (INFO_SELECTED(ct->click_info))
568 return collection_table_selection_get_list(ct);
571 return g_list_append(NULL, file_data_ref(ct->click_info->fd));
574 static void collection_table_popup_edit_cb(GtkWidget *widget, gpointer data)
580 ct = submenu_item_get_data(widget);
583 n = GPOINTER_TO_INT(data);
585 list = collection_table_popup_file_list(ct);
588 start_editor_from_filelist(n, list);
593 static void collection_table_popup_info_cb(GtkWidget *widget, gpointer data)
595 CollectTable *ct = data;
597 info_window_new(NULL, collection_table_popup_file_list(ct), NULL);
600 static void collection_table_popup_copy_cb(GtkWidget *widget, gpointer data)
602 CollectTable *ct = data;
604 file_util_copy(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);
607 static void collection_table_popup_move_cb(GtkWidget *widget, gpointer data)
609 CollectTable *ct = data;
611 file_util_move(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);
614 static void collection_table_popup_rename_cb(GtkWidget *widget, gpointer data)
616 CollectTable *ct = data;
618 file_util_rename(NULL, collection_table_popup_file_list(ct), ct->listview);
621 static void collection_table_popup_delete_cb(GtkWidget *widget, gpointer data)
623 CollectTable *ct = data;
625 file_util_delete(NULL, collection_table_popup_file_list(ct), ct->listview);
628 static void collection_table_popup_copy_path_cb(GtkWidget *widget, gpointer data)
630 CollectTable *ct = data;
632 file_util_copy_path_list_to_clipboard(collection_table_popup_file_list(ct));
635 static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data)
640 ct = submenu_item_get_data(widget);
644 type = (SortType)GPOINTER_TO_INT(data);
646 collection_set_sort_method(ct->cd, type);
649 static void collection_table_popup_view_new_cb(GtkWidget *widget, gpointer data)
651 CollectTable *ct = data;
653 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
655 view_window_new_from_collection(ct->cd, ct->click_info);
659 static void collection_table_popup_view_cb(GtkWidget *widget, gpointer data)
661 CollectTable *ct = data;
663 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
665 layout_image_set_collection(NULL, ct->cd, ct->click_info);
669 static void collection_table_popup_selectall_cb(GtkWidget *widget, gpointer data)
671 CollectTable *ct = data;
673 collection_table_select_all(ct);
674 ct->prev_selection= ct->click_info;
677 static void collection_table_popup_unselectall_cb(GtkWidget *widget, gpointer data)
679 CollectTable *ct = data;
681 collection_table_unselect_all(ct);
682 ct->prev_selection= ct->click_info;
685 static void collection_table_popup_remove_cb(GtkWidget *widget, gpointer data)
687 CollectTable *ct = data;
690 if (!ct->click_info) return;
692 if (INFO_SELECTED(ct->click_info))
694 list = g_list_copy(ct->selection);
698 list = g_list_append(NULL, ct->click_info);
701 collection_remove_by_info_list(ct->cd, list);
705 static void collection_table_popup_add_filelist_cb(GtkWidget *widget, gpointer data)
707 CollectTable *ct = data;
710 list = layout_list(NULL);
714 collection_table_add_filelist(ct, list);
719 static void collection_table_popup_add_collection_cb(GtkWidget *widget, gpointer data)
721 CollectTable *ct = data;
723 collection_dialog_append(NULL, ct->cd);
726 static void collection_table_popup_find_dupes_cb(GtkWidget *widget, gpointer data)
728 CollectTable *ct = data;
731 dw = dupe_window_new(DUPE_MATCH_NAME);
732 dupe_window_add_collection(dw, ct->cd);
735 static void collection_table_popup_print_cb(GtkWidget *widget, gpointer data)
737 CollectTable *ct = data;
740 fd = (ct->click_info) ? ct->click_info->fd : NULL;
742 print_window_new(fd, collection_table_selection_get_list(ct), collection_table_get_list(ct), ct->listview);
745 static void collection_table_popup_show_names_cb(GtkWidget *widget, gpointer data)
747 CollectTable *ct = data;
749 collection_table_toggle_filenames(ct);
752 static void collection_table_popup_destroy_cb(GtkWidget *widget, gpointer data)
754 CollectTable *ct = data;
756 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
757 ct->click_info = NULL;
760 filelist_free(ct->drop_list);
761 ct->drop_list = NULL;
762 ct->drop_info = NULL;
765 static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon)
770 menu = popup_menu_short_lived();
772 g_signal_connect(G_OBJECT(menu), "destroy",
773 G_CALLBACK(collection_table_popup_destroy_cb), ct);
775 menu_item_add_sensitive(menu, _("_View"), over_icon,
776 G_CALLBACK(collection_table_popup_view_cb), ct);
777 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, over_icon,
778 G_CALLBACK(collection_table_popup_view_new_cb), ct);
779 menu_item_add_divider(menu);
780 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, over_icon,
781 G_CALLBACK(collection_table_popup_remove_cb), ct);
783 menu_item_add_stock(menu, _("Append from file list"), GTK_STOCK_ADD,
784 G_CALLBACK(collection_table_popup_add_filelist_cb), ct);
785 menu_item_add_stock(menu, _("Append from collection..."), GTK_STOCK_OPEN,
786 G_CALLBACK(collection_table_popup_add_collection_cb), ct);
787 menu_item_add_divider(menu);
788 menu_item_add(menu, _("Select all"),
789 G_CALLBACK(collection_table_popup_selectall_cb), ct);
790 menu_item_add(menu, _("Select none"),
791 G_CALLBACK(collection_table_popup_unselectall_cb), ct);
792 menu_item_add_divider(menu);
794 submenu_add_edit(menu, &item,
795 G_CALLBACK(collection_table_popup_edit_cb), ct);
796 gtk_widget_set_sensitive(item, over_icon);
798 menu_item_add_sensitive(menu, _("_Properties"), over_icon,
799 G_CALLBACK(collection_table_popup_info_cb), ct);
800 menu_item_add_divider(menu);
801 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, over_icon,
802 G_CALLBACK(collection_table_popup_copy_cb), ct);
803 menu_item_add_sensitive(menu, _("_Move..."), over_icon,
804 G_CALLBACK(collection_table_popup_move_cb), ct);
805 menu_item_add_sensitive(menu, _("_Rename..."), over_icon,
806 G_CALLBACK(collection_table_popup_rename_cb), ct);
807 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, over_icon,
808 G_CALLBACK(collection_table_popup_delete_cb), ct);
809 if (options->show_copy_path)
810 menu_item_add_sensitive(menu, _("_Copy path"), over_icon,
811 G_CALLBACK(collection_table_popup_copy_path_cb), ct);
812 menu_item_add_divider(menu);
814 submenu_add_sort(menu, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0);
815 menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
816 G_CALLBACK(collection_table_popup_show_names_cb), ct);
817 menu_item_add_divider(menu);
818 menu_item_add_stock(menu, _("_Save collection"), GTK_STOCK_SAVE,
819 G_CALLBACK(collection_table_popup_save_cb), ct);
820 menu_item_add_stock(menu, _("Save collection _as..."), GTK_STOCK_SAVE_AS,
821 G_CALLBACK(collection_table_popup_save_as_cb), ct);
822 menu_item_add_divider(menu);
823 menu_item_add_stock(menu, _("_Find duplicates..."), GTK_STOCK_FIND,
824 G_CALLBACK(collection_table_popup_find_dupes_cb), ct);
825 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, over_icon,
826 G_CALLBACK(collection_table_popup_print_cb), ct);
831 *-------------------------------------------------------------------
833 *-------------------------------------------------------------------
836 static void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
841 if (g_list_find(ct->cd->list, ct->focus_info))
843 if (info == ct->focus_info)
845 /* ensure focus row col are correct */
846 collection_table_find_position(ct, ct->focus_info,
847 &ct->focus_row, &ct->focus_column);
850 collection_table_selection_remove(ct, ct->focus_info, SELECTION_FOCUS, NULL);
853 if (!collection_table_find_position(ct, info, &row, &col))
855 ct->focus_info = NULL;
857 ct->focus_column = -1;
861 ct->focus_info = info;
863 ct->focus_column = col;
864 collection_table_selection_add(ct, ct->focus_info, SELECTION_FOCUS, NULL);
866 if (collection_table_find_iter(ct, ct->focus_info, &iter, NULL))
869 GtkTreeViewColumn *column;
872 tree_view_row_make_visible(GTK_TREE_VIEW(ct->listview), &iter, FALSE);
874 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
875 tpath = gtk_tree_model_get_path(store, &iter);
876 /* focus is set to an extra column with 0 width to hide focus, we draw it ourself */
877 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), COLLECT_TABLE_MAX_COLUMNS);
878 gtk_tree_view_set_cursor(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE);
879 gtk_tree_path_free(tpath);
883 static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gint relative)
890 new_row = ct->focus_row;
891 new_col = ct->focus_column;
894 if (new_row < 0) new_row = 0;
895 if (new_row >= ct->rows) new_row = ct->rows - 1;
915 new_col = ct->columns - 1;
922 if (new_col >= ct->columns)
924 if (new_row < ct->rows - 1)
931 new_col = ct->columns - 1;
941 if (new_row >= ct->rows)
944 new_row = ct->rows - 1;
947 new_col = ct->columns - 1;
949 if (new_col >= ct->columns) new_col = ct->columns - 1;
952 if (new_row == ct->rows - 1)
956 /* if we moved beyond the last image, go to the last image */
958 l = g_list_length(ct->cd->list);
959 if (ct->rows > 1) l -= (ct->rows - 1) * ct->columns;
960 if (new_col >= l) new_col = l - 1;
963 if (new_row == -1 || new_col == -1)
965 if (!ct->cd->list) return;
966 new_row = new_col = 0;
969 collection_table_set_focus(ct, collection_table_find_data(ct, new_row, new_col, NULL));
972 static void collection_table_update_focus(CollectTable *ct)
977 if (ct->focus_info && collection_table_find_position(ct, ct->focus_info, &new_row, &new_col))
979 /* first find the old focus, if it exists and is valid */
983 /* (try to) stay where we were */
984 new_row = ct->focus_row;
985 new_col = ct->focus_column;
988 collection_table_move_focus(ct, new_row, new_col, FALSE);
991 /* used to figure the page up/down distances */
992 static gint page_height(CollectTable *ct)
999 adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
1000 page_size = (gint)adj->page_increment;
1002 row_height = options->thumbnails.max_height + THUMB_BORDER_PADDING * 2;
1003 if (ct->show_text) row_height += options->thumbnails.max_height / 3;
1005 ret = page_size / row_height;
1006 if (ret < 1) ret = 1;
1011 static void collection_table_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
1013 CollectTable *ct = data;
1014 GtkTreeModel *store;
1020 if (!collection_table_find_iter(ct, ct->click_info, &iter, &column)) return;
1021 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1022 tpath = gtk_tree_model_get_path(store, &iter);
1023 tree_view_get_cell_clamped(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE, x, y, &cw, &ch);
1024 gtk_tree_path_free(tpath);
1026 popup_menu_position_clamp(menu, x, y, 0);
1029 static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
1031 CollectTable *ct = data;
1038 switch (event->keyval)
1040 case GDK_Left: case GDK_KP_Left:
1043 case GDK_Right: case GDK_KP_Right:
1046 case GDK_Up: case GDK_KP_Up:
1049 case GDK_Down: case GDK_KP_Down:
1052 case GDK_Page_Up: case GDK_KP_Page_Up:
1053 focus_row = -page_height(ct);
1055 case GDK_Page_Down: case GDK_KP_Page_Down:
1056 focus_row = page_height(ct);
1058 case GDK_Home: case GDK_KP_Home:
1059 focus_row = -ct->focus_row;
1060 focus_col = -ct->focus_column;
1062 case GDK_End: case GDK_KP_End:
1063 focus_row = ct->rows - 1 - ct->focus_row;
1064 focus_col = ct->columns - 1 - ct->focus_column;
1067 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1070 ct->click_info = info;
1071 if (event->state & GDK_CONTROL_MASK)
1073 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1077 collection_table_unselect_all(ct);
1078 collection_table_select(ct, info);
1083 if (event->state & GDK_CONTROL_MASK) collection_table_toggle_filenames(ct);
1087 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1088 ct->click_info = info;
1090 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1093 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1094 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, collection_table_menu_pos_cb, ct, 0, GDK_CURRENT_TIME);
1097 stop_signal = FALSE;
1101 if (focus_row != 0 || focus_col != 0)
1103 CollectInfo *new_info;
1104 CollectInfo *old_info;
1106 old_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1107 collection_table_move_focus(ct, focus_row, focus_col, TRUE);
1108 new_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1110 if (new_info != old_info)
1112 if (event->state & GDK_SHIFT_MASK)
1114 if (!options->collections.rectangular_selection)
1116 collection_table_select_region_util(ct, old_info, new_info, FALSE);
1120 collection_table_select_region_util(ct, ct->click_info, old_info, FALSE);
1122 collection_table_select_region_util(ct, ct->click_info, new_info, TRUE);
1124 else if (event->state & GDK_CONTROL_MASK)
1126 ct->click_info = new_info;
1130 ct->click_info = new_info;
1131 collection_table_unselect_all(ct);
1132 collection_table_select(ct, new_info);
1140 g_signal_stop_emission_by_name(GTK_OBJECT(widget), "key_press_event");
1149 *-------------------------------------------------------------------
1151 *-------------------------------------------------------------------
1154 static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gint *after, GdkRectangle *cell,
1155 gint use_coord, gint x, gint y)
1157 CollectInfo *info = NULL;
1158 GtkTreeModel *store;
1161 GtkTreeViewColumn *column;
1163 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1165 if (!use_coord) gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
1170 if (collection_table_find_iter(ct, source, &iter, &col))
1172 tpath = gtk_tree_model_get_path(store, &iter);
1173 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1174 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1175 gtk_tree_path_free(tpath);
1178 *after = (x > cell->x + (cell->width / 2));
1183 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
1184 &tpath, &column, NULL, NULL))
1189 gtk_tree_model_get_iter(store, &iter, tpath);
1190 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1192 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
1193 info = g_list_nth_data(list, n);
1197 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1198 *after = (x > cell->x + (cell->width / 2));
1201 gtk_tree_path_free(tpath);
1208 work = g_list_last(ct->cd->list);
1216 if (collection_table_find_iter(ct, info, &iter, &col))
1218 tpath = gtk_tree_model_get_path(store, &iter);
1219 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1220 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1221 gtk_tree_path_free(tpath);
1229 static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint y)
1235 info = collection_table_insert_find(ct, NULL, &after, &cell, TRUE, x, y);
1241 work = g_list_find(ct->cd->list, info);
1242 if (work && work->next)
1244 info = work->next->data;
1255 static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gint enable)
1263 if (ct->marker_window) gdk_window_destroy(ct->marker_window);
1264 ct->marker_window = NULL;
1269 info = collection_table_insert_find(ct, info, &after, &cell, FALSE, 0, 0);
1271 /* this setting does not take into account (after), but since it is not really used... */
1272 ct->marker_info = info;
1277 if (!ct->marker_window)
1280 GdkWindowAttr attributes;
1281 gint attributes_mask;
1287 parent = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(ct->listview));
1289 pb = gdk_pixbuf_new_from_xpm_data((const char **)marker_xpm);
1290 gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128);
1291 gdk_pixbuf_unref(pb);
1293 gdk_drawable_get_size(pixmap, &w, &h);
1295 attributes.window_type = GDK_WINDOW_CHILD;
1296 attributes.wclass = GDK_INPUT_OUTPUT;
1297 attributes.width = w;
1298 attributes.height = h;
1299 attributes.event_mask = gtk_widget_get_events(ct->listview);
1300 attributes_mask = 0;
1302 ct->marker_window = gdk_window_new(parent, &attributes, attributes_mask);
1303 gdk_window_set_back_pixmap(ct->marker_window, pixmap, FALSE);
1304 gdk_window_shape_combine_mask(ct->marker_window, mask, 0, 0);
1306 g_object_unref(pixmap);
1307 if (mask) g_object_unref(mask);
1315 gdk_drawable_get_size(ct->marker_window, &w, &h);
1323 x = cell.x + cell.width;
1326 y = cell.y + (cell.height / 2) - (h / 2);
1328 gdk_window_move(ct->marker_window, x, y);
1329 gdk_window_clear(ct->marker_window);
1330 if (!gdk_window_is_visible(ct->marker_window)) gdk_window_show(ct->marker_window);
1334 if (gdk_window_is_visible(ct->marker_window)) gdk_window_hide(ct->marker_window);
1339 *-------------------------------------------------------------------
1340 * mouse drag auto-scroll
1341 *-------------------------------------------------------------------
1344 static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gint drop_event)
1348 info = collection_table_find_data_by_coord(ct, x, y, NULL);
1353 collection_table_insert_marker(ct, info, TRUE);
1357 tip_update(ct, info);
1361 static gint collection_table_auto_scroll_idle_cb(gpointer data)
1363 CollectTable *ct = data;
1368 if (ct->drop_idle_id == -1) return FALSE;
1370 window = ct->listview->window;
1371 gdk_window_get_pointer(window, &x, &y, NULL);
1372 gdk_drawable_get_size(window, &w, &h);
1373 if (x >= 0 && x < w && y >= 0 && y < h)
1375 collection_table_motion_update(ct, x, y, TRUE);
1378 ct->drop_idle_id = -1;
1382 static gint collection_table_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data)
1384 CollectTable *ct = data;
1386 if (ct->drop_idle_id == -1) ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
1391 static void collection_table_scroll(CollectTable *ct, gint scroll)
1395 if (ct->drop_idle_id != -1)
1397 g_source_remove(ct->drop_idle_id);
1398 ct->drop_idle_id = -1;
1400 widget_auto_scroll_stop(ct->listview);
1401 collection_table_insert_marker(ct, NULL, FALSE);
1405 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
1406 widget_auto_scroll_start(ct->listview, adj, -1, options->thumbnails.max_height / 2,
1407 collection_table_auto_scroll_notify_cb, ct);
1412 *-------------------------------------------------------------------
1414 *-------------------------------------------------------------------
1417 static gint collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1419 CollectTable *ct = data;
1421 collection_table_motion_update(ct, (gint)bevent->x, (gint)bevent->y, FALSE);
1426 static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1428 CollectTable *ct = data;
1434 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1436 ct->click_info = info;
1437 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, &iter);
1439 switch (bevent->button)
1441 case MOUSE_BUTTON_LEFT:
1442 if (bevent->type == GDK_2BUTTON_PRESS)
1446 layout_image_set_collection(NULL, ct->cd, info);
1449 else if (!GTK_WIDGET_HAS_FOCUS(ct->listview))
1451 gtk_widget_grab_focus(ct->listview);
1454 case MOUSE_BUTTON_RIGHT:
1455 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1456 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
1465 static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1467 CollectTable *ct = data;
1469 CollectInfo *info = NULL;
1473 if ((gint)bevent->x != 0 || (gint) bevent->y != 0)
1475 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1480 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1483 if (bevent->button == MOUSE_BUTTON_LEFT &&
1484 info && ct->click_info == info)
1486 collection_table_set_focus(ct, info);
1488 if (bevent->state & GDK_CONTROL_MASK)
1492 select = !INFO_SELECTED(info);
1493 if ((bevent->state & GDK_SHIFT_MASK) && ct->prev_selection)
1495 collection_table_select_region_util(ct, ct->prev_selection, info, select);
1499 collection_table_select_util(ct, info, select);
1504 collection_table_unselect_all(ct);
1506 if ((bevent->state & GDK_SHIFT_MASK) &&
1509 collection_table_select_region_util(ct, ct->prev_selection, info, TRUE);
1513 collection_table_select_util(ct, info, TRUE);
1517 else if (bevent->button == MOUSE_BUTTON_MIDDLE &&
1518 info && ct->click_info == info)
1520 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1526 static gint collection_table_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
1528 CollectTable *ct = data;
1535 *-------------------------------------------------------------------
1536 * populate, add, insert, etc.
1537 *-------------------------------------------------------------------
1540 static gboolean collection_table_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data)
1544 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
1550 static void collection_table_clear_store(CollectTable *ct)
1552 GtkTreeModel *store;
1554 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1555 gtk_tree_model_foreach(store, collection_table_destroy_node_cb, NULL);
1557 gtk_list_store_clear(GTK_LIST_STORE(store));
1560 static GList *collection_table_add_row(CollectTable *ct, GtkTreeIter *iter)
1562 GtkListStore *store;
1566 for (i = 0; i < ct->columns; i++) list = g_list_prepend(list, NULL);
1568 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)));
1569 gtk_list_store_append(store, iter);
1570 gtk_list_store_set(store, iter, CTABLE_COLUMN_POINTER, list, -1);
1575 static void collection_table_populate(CollectTable *ct, gint resize)
1580 collection_table_verify_selections(ct);
1582 collection_table_clear_store(ct);
1589 thumb_width = collection_table_get_icon_width(ct);
1591 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
1593 GtkTreeViewColumn *column;
1594 GtkCellRenderer *cell;
1597 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), i);
1598 gtk_tree_view_column_set_visible(column, (i < ct->columns));
1599 gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6));
1601 list = gtk_tree_view_column_get_cell_renderers(column);
1602 cell = (list) ? list->data : NULL;
1605 if (cell && GQV_IS_CELL_RENDERER_ICON(cell))
1607 g_object_set(G_OBJECT(cell), "fixed_width", thumb_width,
1608 "fixed_height", options->thumbnails.max_height,
1609 "show_text", ct->show_text, NULL);
1612 if (GTK_WIDGET_REALIZED(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
1616 work = ct->cd->list;
1624 list = collection_table_add_row(ct, &iter);
1625 while (work && list)
1627 list->data = work->data;
1635 collection_table_update_focus(ct);
1636 collection_table_update_status(ct);
1639 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force)
1644 thumb_width = collection_table_get_icon_width(ct);
1646 new_cols = w / (thumb_width + (THUMB_BORDER_PADDING * 6));
1647 if (new_cols < 1) new_cols = 1;
1649 if (!force && new_cols == ct->columns) return;
1651 ct->columns = new_cols;
1653 collection_table_populate(ct, TRUE);
1655 DEBUG_1("col tab pop cols=%d rows=%d", ct->columns, ct->rows);
1658 static void collection_table_sync(CollectTable *ct)
1660 GtkTreeModel *store;
1665 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1670 work = ct->cd->list;
1676 if (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1678 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1679 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1683 list = collection_table_add_row(ct, &iter);
1708 while (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1712 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1713 gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
1719 collection_table_update_focus(ct);
1720 collection_table_update_status(ct);
1723 static gint collection_table_sync_idle_cb(gpointer data)
1725 CollectTable *ct = data;
1727 if (ct->sync_idle_id == -1) return FALSE;
1728 ct->sync_idle_id = -1;
1730 collection_table_sync(ct);
1734 static void collection_table_sync_idle(CollectTable *ct)
1736 if (ct->sync_idle_id == -1)
1738 /* high priority, the view needs to be resynced before a redraw
1739 * may contain invalid pointers at this time
1741 ct->sync_idle_id = g_idle_add_full(G_PRIORITY_HIGH, collection_table_sync_idle_cb, ct, NULL);
1745 void collection_table_add_filelist(CollectTable *ct, GList *list)
1754 collection_add(ct->cd, (FileData *)work->data, FALSE);
1759 static void collection_table_insert_filelist(CollectTable *ct, GList *list, CollectInfo *insert_info)
1768 collection_insert(ct->cd, (FileData *)work->data, insert_info, FALSE);
1772 collection_table_sync_idle(ct);
1775 static void collection_table_move_by_info_list(CollectTable *ct, GList *info_list, gint row, gint col)
1778 GList *insert_pos = NULL;
1782 if (!info_list) return;
1784 info = collection_table_find_data(ct, row, col, NULL);
1786 if (!info_list->next && info_list->data == info) return;
1788 if (info) insert_pos = g_list_find(ct->cd->list, info);
1790 /* FIXME: this may get slow for large lists */
1792 while (insert_pos && work)
1794 if (insert_pos->data == work->data)
1796 insert_pos = insert_pos->next;
1808 ct->cd->list = g_list_remove(ct->cd->list, work->data);
1812 /* place them back in */
1813 temp = g_list_copy(info_list);
1817 ct->cd->list = uig_list_insert_list(ct->cd->list, insert_pos, temp);
1821 ct->cd->list = g_list_concat(temp, ct->cd->list);
1825 ct->cd->list = g_list_concat(ct->cd->list, temp);
1828 ct->cd->changed = TRUE;
1830 collection_table_sync_idle(ct);
1835 *-------------------------------------------------------------------
1837 *-------------------------------------------------------------------
1840 void collection_table_file_update(CollectTable *ct, CollectInfo *info)
1848 collection_table_update_extras(ct, FALSE, 0.0);
1852 if (!collection_table_find_position(ct, info, &row, &col)) return;
1854 if (ct->columns != 0 && ct->rows != 0)
1856 value = (gdouble)(row * ct->columns + col) / (ct->columns * ct->rows);
1863 collection_table_update_extras(ct, TRUE, value);
1865 if (collection_table_find_iter(ct, info, &iter, NULL))
1867 GtkTreeModel *store;
1870 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1871 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1872 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1876 void collection_table_file_add(CollectTable *ct, CollectInfo *info)
1878 collection_table_sync_idle(ct);
1881 void collection_table_file_insert(CollectTable *ct, CollectInfo *ci)
1883 collection_table_sync_idle(ct);
1886 void collection_table_file_remove(CollectTable *ct, CollectInfo *ci)
1888 if (ci && INFO_SELECTED(ci))
1890 ct->selection = g_list_remove(ct->selection, ci);
1893 collection_table_sync_idle(ct);
1896 void collection_table_refresh(CollectTable *ct)
1898 collection_table_populate(ct, FALSE);
1902 *-------------------------------------------------------------------
1904 *-------------------------------------------------------------------
1907 static void collection_table_add_dir_recursive(CollectTable *ct, gchar *path, gint recursive)
1912 if (filelist_read(path, &f, recursive ? &d : NULL))
1916 f = filelist_filter(f, FALSE);
1917 d = filelist_filter(d, TRUE);
1919 f = filelist_sort_path(f);
1920 d = filelist_sort_path(d);
1922 collection_table_insert_filelist(ct, f, ct->marker_info);
1924 work = g_list_last(d);
1927 collection_table_add_dir_recursive(ct, ((FileData *)work->data)->path, TRUE);
1935 static void confirm_dir_list_do(CollectTable *ct, GList *list, gint recursive)
1940 FileData *fd = work->data;
1942 if (isdir(fd->path)) collection_table_add_dir_recursive(ct, fd->path, recursive);
1944 collection_table_insert_filelist(ct, list, ct->marker_info);
1948 static void confirm_dir_list_add(GtkWidget *widget, gpointer data)
1950 CollectTable *ct = data;
1952 confirm_dir_list_do(ct, ct->drop_list, FALSE);
1955 static void confirm_dir_list_recurse(GtkWidget *widget, gpointer data)
1957 CollectTable *ct = data;
1959 confirm_dir_list_do(ct, ct->drop_list, TRUE);
1962 static void confirm_dir_list_skip(GtkWidget *widget, gpointer data)
1964 CollectTable *ct = data;
1966 collection_table_insert_filelist(ct, ct->drop_list, ct->marker_info);
1969 static GtkWidget *collection_table_drop_menu(CollectTable *ct)
1973 menu = popup_menu_short_lived();
1974 g_signal_connect(G_OBJECT(menu), "destroy",
1975 G_CALLBACK(collection_table_popup_destroy_cb), ct);
1977 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL);
1978 menu_item_add_divider(menu);
1979 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK,
1980 G_CALLBACK(confirm_dir_list_add), ct);
1981 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD,
1982 G_CALLBACK(confirm_dir_list_recurse), ct);
1983 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE,
1984 G_CALLBACK(confirm_dir_list_skip), ct);
1985 menu_item_add_divider(menu);
1986 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, ct);
1992 *-------------------------------------------------------------------
1994 *-------------------------------------------------------------------
1997 static GtkTargetEntry collection_drag_types[] = {
1998 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
1999 { "text/uri-list", 0, TARGET_URI_LIST },
2000 { "text/plain", 0, TARGET_TEXT_PLAIN }
2002 static gint n_collection_drag_types = 3;
2004 static GtkTargetEntry collection_drop_types[] = {
2005 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
2006 { "text/uri-list", 0, TARGET_URI_LIST }
2008 static gint n_collection_drop_types = 2;
2011 static void collection_table_dnd_get(GtkWidget *widget, GdkDragContext *context,
2012 GtkSelectionData *selection_data, guint info,
2013 guint time, gpointer data)
2015 CollectTable *ct = data;
2018 gchar *uri_text = NULL;
2021 if (!ct->click_info) return;
2023 selected = INFO_SELECTED(ct->click_info);
2027 case TARGET_APP_COLLECTION_MEMBER:
2030 uri_text = collection_info_list_to_dnd_data(ct->cd, ct->selection, &total);
2034 list = g_list_append(NULL, ct->click_info);
2035 uri_text = collection_info_list_to_dnd_data(ct->cd, list, &total);
2039 case TARGET_URI_LIST:
2040 case TARGET_TEXT_PLAIN:
2044 list = collection_table_selection_get_list(ct);
2048 list = g_list_append(NULL, file_data_ref(ct->click_info->fd));
2052 uri_text = uri_text_from_filelist(list, &total, (info == TARGET_TEXT_PLAIN));
2053 filelist_free(list);
2057 gtk_selection_data_set(selection_data, selection_data->target,
2058 8, (guchar *)uri_text, total);
2063 static void collection_table_dnd_receive(GtkWidget *widget, GdkDragContext *context,
2065 GtkSelectionData *selection_data, guint info,
2066 guint time, gpointer data)
2068 CollectTable *ct = data;
2070 GList *info_list = NULL;
2071 CollectionData *source;
2072 CollectInfo *drop_info;
2075 DEBUG_1("%s", selection_data->data);
2077 collection_table_scroll(ct, FALSE);
2078 collection_table_insert_marker(ct, NULL, FALSE);
2080 drop_info = collection_table_insert_point(ct, x, y);
2084 case TARGET_APP_COLLECTION_MEMBER:
2085 source = collection_from_dnd_data((gchar *)selection_data->data, &list, &info_list);
2088 if (source == ct->cd)
2093 /* it is a move within a collection */
2094 filelist_free(list);
2099 collection_table_move_by_info_list(ct, info_list, -1, -1);
2101 else if (collection_table_find_position(ct, drop_info, &row, &col))
2103 collection_table_move_by_info_list(ct, info_list, row, col);
2108 /* it is a move/copy across collections */
2109 if (context->action == GDK_ACTION_MOVE)
2111 collection_remove_by_info_list(source, info_list);
2114 g_list_free(info_list);
2117 case TARGET_URI_LIST:
2118 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE);
2122 FileData *fd = work->data;
2123 if (isdir(fd->path))
2127 ct->drop_list = list;
2128 ct->drop_info = drop_info;
2129 menu = collection_table_drop_menu(ct);
2130 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time);
2143 collection_table_insert_filelist(ct, list, drop_info);
2144 filelist_free(list);
2148 static void collection_table_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
2150 CollectTable *ct = data;
2152 if (ct->click_info && ct->click_info->pixbuf)
2156 if (INFO_SELECTED(ct->click_info))
2157 items = g_list_length(ct->selection);
2160 dnd_set_drag_icon(widget, context, ct->click_info->pixbuf, items);
2164 static void collection_table_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
2166 CollectTable *ct = data;
2168 /* apparently a leave event is not generated on a drop */
2171 collection_table_scroll(ct, FALSE);
2174 static gint collection_table_dnd_motion(GtkWidget *widget, GdkDragContext *context,
2175 gint x, gint y, guint time, gpointer data)
2177 CollectTable *ct = data;
2179 collection_table_motion_update(ct, x, y, TRUE);
2180 collection_table_scroll(ct, TRUE);
2185 static void collection_table_dnd_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data)
2187 CollectTable *ct = data;
2189 collection_table_scroll(ct, FALSE);
2192 static void collection_table_dnd_init(CollectTable *ct)
2194 gtk_drag_source_set(ct->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
2195 collection_drag_types, n_collection_drag_types,
2196 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
2197 g_signal_connect(G_OBJECT(ct->listview), "drag_data_get",
2198 G_CALLBACK(collection_table_dnd_get), ct);
2199 g_signal_connect(G_OBJECT(ct->listview), "drag_begin",
2200 G_CALLBACK(collection_table_dnd_begin), ct);
2201 g_signal_connect(G_OBJECT(ct->listview), "drag_end",
2202 G_CALLBACK(collection_table_dnd_end), ct);
2204 gtk_drag_dest_set(ct->listview,
2205 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
2206 collection_drop_types, n_collection_drop_types,
2207 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK);
2208 g_signal_connect(G_OBJECT(ct->listview), "drag_motion",
2209 G_CALLBACK(collection_table_dnd_motion), ct);
2210 g_signal_connect(G_OBJECT(ct->listview), "drag_leave",
2211 G_CALLBACK(collection_table_dnd_leave), ct);
2212 g_signal_connect(G_OBJECT(ct->listview), "drag_data_received",
2213 G_CALLBACK(collection_table_dnd_receive), ct);
2217 *-----------------------------------------------------------------------------
2219 *-----------------------------------------------------------------------------
2222 typedef struct _ColumnData ColumnData;
2229 static void collection_table_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
2230 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
2232 ColumnData *cd = data;
2242 gtk_tree_model_get(tree_model, iter, CTABLE_COLUMN_POINTER, &list, -1);
2243 info = g_list_nth_data(list, cd->number);
2245 style = gtk_widget_get_style(ct->listview);
2246 if (info && (info->flag_mask & SELECTION_SELECTED) )
2248 memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg));
2249 memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg));
2253 memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg));
2254 memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg));
2257 if (info && (info->flag_mask & SELECTION_PRELIGHT))
2260 shift_color(&color_fg, -1, 0);
2262 shift_color(&color_bg, -1, 0);
2265 if (GQV_IS_CELL_RENDERER_ICON(cell))
2269 g_object_set(cell, "pixbuf", info->pixbuf,
2270 "text", info->fd->name,
2271 "cell-background-gdk", &color_bg,
2272 "cell-background-set", TRUE,
2273 "foreground-gdk", &color_fg,
2274 "foreground-set", TRUE,
2275 "has-focus", (ct->focus_info == info), NULL);
2279 g_object_set(cell, "pixbuf", NULL,
2281 "cell-background-set", FALSE,
2282 "foreground-set", FALSE,
2283 "has-focus", FALSE, NULL);
2288 static void collection_table_append_column(CollectTable *ct, gint n)
2291 GtkTreeViewColumn *column;
2292 GtkCellRenderer *renderer;
2294 column = gtk_tree_view_column_new();
2295 gtk_tree_view_column_set_min_width(column, 0);
2297 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
2298 gtk_tree_view_column_set_alignment(column, 0.5);
2300 renderer = gqv_cell_renderer_icon_new();
2301 gtk_tree_view_column_pack_start(column, renderer, FALSE);
2302 g_object_set(G_OBJECT(renderer), "xpad", THUMB_BORDER_PADDING * 2,
2303 "ypad", THUMB_BORDER_PADDING,
2304 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
2306 g_object_set_data(G_OBJECT(column), "column_number", GINT_TO_POINTER(n));
2308 cd = g_new0(ColumnData, 1);
2311 gtk_tree_view_column_set_cell_data_func(column, renderer, collection_table_cell_data_cb, cd, g_free);
2313 gtk_tree_view_append_column(GTK_TREE_VIEW(ct->listview), column);
2317 *-------------------------------------------------------------------
2319 *-------------------------------------------------------------------
2322 static void collection_table_destroy(GtkWidget *widget, gpointer data)
2324 CollectTable *ct = data;
2328 g_signal_handlers_disconnect_matched(GTK_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA,
2330 gtk_widget_destroy(ct->popup);
2333 if (ct->sync_idle_id != -1) g_source_remove(ct->sync_idle_id);
2336 collection_table_scroll(ct, FALSE);
2341 static void collection_table_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
2343 CollectTable *ct = data;
2345 collection_table_populate_at_new_size(ct, allocation->width, allocation->height, FALSE);
2348 CollectTable *collection_table_new(CollectionData *cd)
2351 GtkListStore *store;
2352 GtkTreeSelection *selection;
2355 ct = g_new0(CollectTable, 1);
2360 ct->selection = NULL;
2361 ct->prev_selection = NULL;
2363 ct->tip_window = NULL;
2364 ct->tip_delay_id = -1;
2366 ct->marker_window = NULL;
2367 ct->marker_info = NULL;
2369 ct->status_label = NULL;
2370 ct->extra_label = NULL;
2373 ct->focus_column = 0;
2374 ct->focus_info = NULL;
2376 ct->show_text = options->show_icon_names;
2378 ct->sync_idle_id = -1;
2379 ct->drop_idle_id = -1;
2382 ct->drop_info = NULL;
2383 ct->drop_list = NULL;
2385 ct->scrolled = gtk_scrolled_window_new(NULL, NULL);
2386 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN);
2387 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ct->scrolled),
2388 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2390 store = gtk_list_store_new(1, G_TYPE_POINTER);
2391 ct->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
2392 g_object_unref(store);
2394 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ct->listview));
2395 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_NONE);
2397 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ct->listview), FALSE);
2398 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ct->listview), FALSE);
2400 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
2402 collection_table_append_column(ct, i);
2405 /* zero width column to hide tree view focus, we draw it ourselves */
2406 collection_table_append_column(ct, i);
2407 /* end column to fill white space */
2408 collection_table_append_column(ct, i);
2410 g_signal_connect(G_OBJECT(ct->listview), "destroy",
2411 G_CALLBACK(collection_table_destroy), ct);
2412 g_signal_connect(G_OBJECT(ct->listview), "size_allocate",
2413 G_CALLBACK(collection_table_sized), ct);
2414 g_signal_connect(G_OBJECT(ct->listview), "key_press_event",
2415 G_CALLBACK(collection_table_press_key_cb), ct);
2417 gtk_container_add(GTK_CONTAINER(ct->scrolled), ct->listview);
2418 gtk_widget_show(ct->listview);
2420 collection_table_dnd_init(ct);
2422 gtk_widget_set_events(ct->listview, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK |
2423 GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK);
2424 g_signal_connect(G_OBJECT(ct->listview),"button_press_event",
2425 G_CALLBACK(collection_table_press_cb), ct);
2426 g_signal_connect(G_OBJECT(ct->listview),"button_release_event",
2427 G_CALLBACK(collection_table_release_cb), ct);
2428 g_signal_connect(G_OBJECT(ct->listview),"motion_notify_event",
2429 G_CALLBACK(collection_table_motion_cb), ct);
2430 g_signal_connect(G_OBJECT(ct->listview), "leave_notify_event",
2431 G_CALLBACK(collection_table_leave_cb), ct);
2436 void collection_table_set_labels(CollectTable *ct, GtkWidget *status, GtkWidget *extra)
2438 ct->status_label = status;
2439 ct->extra_label = extra;
2440 collection_table_update_status(ct);
2441 collection_table_update_extras(ct, FALSE, 0.0);
2444 CollectInfo *collection_table_get_focus_info(CollectTable *ct)
2446 return collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);