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\n", 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 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, g_strdup(ct->click_info->fd->path));
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_sort_cb(GtkWidget *widget, gpointer data)
633 ct = submenu_item_get_data(widget);
637 type = (SortType)GPOINTER_TO_INT(data);
639 collection_set_sort_method(ct->cd, type);
642 static void collection_table_popup_view_new_cb(GtkWidget *widget, gpointer data)
644 CollectTable *ct = data;
646 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
648 view_window_new_from_collection(ct->cd, ct->click_info);
652 static void collection_table_popup_view_cb(GtkWidget *widget, gpointer data)
654 CollectTable *ct = data;
656 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
658 layout_image_set_collection(NULL, ct->cd, ct->click_info);
662 static void collection_table_popup_selectall_cb(GtkWidget *widget, gpointer data)
664 CollectTable *ct = data;
666 collection_table_select_all(ct);
667 ct->prev_selection= ct->click_info;
670 static void collection_table_popup_unselectall_cb(GtkWidget *widget, gpointer data)
672 CollectTable *ct = data;
674 collection_table_unselect_all(ct);
675 ct->prev_selection= ct->click_info;
678 static void collection_table_popup_remove_cb(GtkWidget *widget, gpointer data)
680 CollectTable *ct = data;
683 if (!ct->click_info) return;
685 if (INFO_SELECTED(ct->click_info))
687 list = g_list_copy(ct->selection);
691 list = g_list_append(NULL, ct->click_info);
694 collection_remove_by_info_list(ct->cd, list);
698 static void collection_table_popup_add_filelist_cb(GtkWidget *widget, gpointer data)
700 CollectTable *ct = data;
703 list = layout_list(NULL);
707 collection_table_add_filelist(ct, list);
712 static void collection_table_popup_add_collection_cb(GtkWidget *widget, gpointer data)
714 CollectTable *ct = data;
716 collection_dialog_append(NULL, ct->cd);
719 static void collection_table_popup_find_dupes_cb(GtkWidget *widget, gpointer data)
721 CollectTable *ct = data;
724 dw = dupe_window_new(DUPE_MATCH_NAME);
725 dupe_window_add_collection(dw, ct->cd);
728 static void collection_table_popup_print_cb(GtkWidget *widget, gpointer data)
730 CollectTable *ct = data;
733 fd = (ct->click_info) ? ct->click_info->fd : NULL;
735 print_window_new(fd, collection_table_selection_get_list(ct), collection_table_get_list(ct), ct->listview);
738 static void collection_table_popup_show_names_cb(GtkWidget *widget, gpointer data)
740 CollectTable *ct = data;
742 collection_table_toggle_filenames(ct);
745 static void collection_table_popup_destroy_cb(GtkWidget *widget, gpointer data)
747 CollectTable *ct = data;
749 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
750 ct->click_info = NULL;
753 path_list_free(ct->drop_list);
754 ct->drop_list = NULL;
755 ct->drop_info = NULL;
758 static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon)
763 menu = popup_menu_short_lived();
765 g_signal_connect(G_OBJECT(menu), "destroy",
766 G_CALLBACK(collection_table_popup_destroy_cb), ct);
768 menu_item_add_sensitive(menu, _("_View"), over_icon,
769 G_CALLBACK(collection_table_popup_view_cb), ct);
770 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, over_icon,
771 G_CALLBACK(collection_table_popup_view_new_cb), ct);
772 menu_item_add_divider(menu);
773 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, over_icon,
774 G_CALLBACK(collection_table_popup_remove_cb), ct);
776 menu_item_add_stock(menu, _("Append from file list"), GTK_STOCK_ADD,
777 G_CALLBACK(collection_table_popup_add_filelist_cb), ct);
778 menu_item_add_stock(menu, _("Append from collection..."), GTK_STOCK_OPEN,
779 G_CALLBACK(collection_table_popup_add_collection_cb), ct);
780 menu_item_add_divider(menu);
781 menu_item_add(menu, _("Select all"),
782 G_CALLBACK(collection_table_popup_selectall_cb), ct);
783 menu_item_add(menu, _("Select none"),
784 G_CALLBACK(collection_table_popup_unselectall_cb), ct);
785 menu_item_add_divider(menu);
787 submenu_add_edit(menu, &item,
788 G_CALLBACK(collection_table_popup_edit_cb), ct);
789 gtk_widget_set_sensitive(item, over_icon);
791 menu_item_add_sensitive(menu, _("_Properties"), over_icon,
792 G_CALLBACK(collection_table_popup_info_cb), ct);
793 menu_item_add_divider(menu);
794 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, over_icon,
795 G_CALLBACK(collection_table_popup_copy_cb), ct);
796 menu_item_add_sensitive(menu, _("_Move..."), over_icon,
797 G_CALLBACK(collection_table_popup_move_cb), ct);
798 menu_item_add_sensitive(menu, _("_Rename..."), over_icon,
799 G_CALLBACK(collection_table_popup_rename_cb), ct);
800 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, over_icon,
801 G_CALLBACK(collection_table_popup_delete_cb), ct);
802 menu_item_add_divider(menu);
804 submenu_add_sort(menu, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0);
805 menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
806 G_CALLBACK(collection_table_popup_show_names_cb), ct);
807 menu_item_add_divider(menu);
808 menu_item_add_stock(menu, _("_Save collection"), GTK_STOCK_SAVE,
809 G_CALLBACK(collection_table_popup_save_cb), ct);
810 menu_item_add_stock(menu, _("Save collection _as..."), GTK_STOCK_SAVE_AS,
811 G_CALLBACK(collection_table_popup_save_as_cb), ct);
812 menu_item_add_divider(menu);
813 menu_item_add_stock(menu, _("_Find duplicates..."), GTK_STOCK_FIND,
814 G_CALLBACK(collection_table_popup_find_dupes_cb), ct);
815 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, over_icon,
816 G_CALLBACK(collection_table_popup_print_cb), ct);
821 *-------------------------------------------------------------------
823 *-------------------------------------------------------------------
826 static void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
831 if (g_list_find(ct->cd->list, ct->focus_info))
833 if (info == ct->focus_info)
835 /* ensure focus row col are correct */
836 collection_table_find_position(ct, ct->focus_info,
837 &ct->focus_row, &ct->focus_column);
840 collection_table_selection_remove(ct, ct->focus_info, SELECTION_FOCUS, NULL);
843 if (!collection_table_find_position(ct, info, &row, &col))
845 ct->focus_info = NULL;
847 ct->focus_column = -1;
851 ct->focus_info = info;
853 ct->focus_column = col;
854 collection_table_selection_add(ct, ct->focus_info, SELECTION_FOCUS, NULL);
856 if (collection_table_find_iter(ct, ct->focus_info, &iter, NULL))
859 GtkTreeViewColumn *column;
862 tree_view_row_make_visible(GTK_TREE_VIEW(ct->listview), &iter, FALSE);
864 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
865 tpath = gtk_tree_model_get_path(store, &iter);
866 /* focus is set to an extra column with 0 width to hide focus, we draw it ourself */
867 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), COLLECT_TABLE_MAX_COLUMNS);
868 gtk_tree_view_set_cursor(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE);
869 gtk_tree_path_free(tpath);
873 static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gint relative)
880 new_row = ct->focus_row;
881 new_col = ct->focus_column;
884 if (new_row < 0) new_row = 0;
885 if (new_row >= ct->rows) new_row = ct->rows - 1;
905 new_col = ct->columns - 1;
912 if (new_col >= ct->columns)
914 if (new_row < ct->rows - 1)
921 new_col = ct->columns - 1;
931 if (new_row >= ct->rows)
934 new_row = ct->rows - 1;
937 new_col = ct->columns - 1;
939 if (new_col >= ct->columns) new_col = ct->columns - 1;
942 if (new_row == ct->rows - 1)
946 /* if we moved beyond the last image, go to the last image */
948 l = g_list_length(ct->cd->list);
949 if (ct->rows > 1) l -= (ct->rows - 1) * ct->columns;
950 if (new_col >= l) new_col = l - 1;
953 if (new_row == -1 || new_col == -1)
955 if (!ct->cd->list) return;
956 new_row = new_col = 0;
959 collection_table_set_focus(ct, collection_table_find_data(ct, new_row, new_col, NULL));
962 static void collection_table_update_focus(CollectTable *ct)
967 if (ct->focus_info && collection_table_find_position(ct, ct->focus_info, &new_row, &new_col))
969 /* first find the old focus, if it exists and is valid */
973 /* (try to) stay where we were */
974 new_row = ct->focus_row;
975 new_col = ct->focus_column;
978 collection_table_move_focus(ct, new_row, new_col, FALSE);
981 /* used to figure the page up/down distances */
982 static gint page_height(CollectTable *ct)
989 adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
990 page_size = (gint)adj->page_increment;
992 row_height = options->thumbnails.max_height + THUMB_BORDER_PADDING * 2;
993 if (ct->show_text) row_height += options->thumbnails.max_height / 3;
995 ret = page_size / row_height;
996 if (ret < 1) ret = 1;
1001 static void collection_table_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
1003 CollectTable *ct = data;
1004 GtkTreeModel *store;
1010 if (!collection_table_find_iter(ct, ct->click_info, &iter, &column)) return;
1011 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1012 tpath = gtk_tree_model_get_path(store, &iter);
1013 tree_view_get_cell_clamped(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE, x, y, &cw, &ch);
1014 gtk_tree_path_free(tpath);
1016 popup_menu_position_clamp(menu, x, y, 0);
1019 static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
1021 CollectTable *ct = data;
1028 switch (event->keyval)
1030 case GDK_Left: case GDK_KP_Left:
1033 case GDK_Right: case GDK_KP_Right:
1036 case GDK_Up: case GDK_KP_Up:
1039 case GDK_Down: case GDK_KP_Down:
1042 case GDK_Page_Up: case GDK_KP_Page_Up:
1043 focus_row = -page_height(ct);
1045 case GDK_Page_Down: case GDK_KP_Page_Down:
1046 focus_row = page_height(ct);
1048 case GDK_Home: case GDK_KP_Home:
1049 focus_row = -ct->focus_row;
1050 focus_col = -ct->focus_column;
1052 case GDK_End: case GDK_KP_End:
1053 focus_row = ct->rows - 1 - ct->focus_row;
1054 focus_col = ct->columns - 1 - ct->focus_column;
1057 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1060 ct->click_info = info;
1061 if (event->state & GDK_CONTROL_MASK)
1063 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1067 collection_table_unselect_all(ct);
1068 collection_table_select(ct, info);
1073 if (event->state & GDK_CONTROL_MASK) collection_table_toggle_filenames(ct);
1077 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1078 ct->click_info = info;
1080 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1083 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1084 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, collection_table_menu_pos_cb, ct, 0, GDK_CURRENT_TIME);
1087 stop_signal = FALSE;
1091 if (focus_row != 0 || focus_col != 0)
1093 CollectInfo *new_info;
1094 CollectInfo *old_info;
1096 old_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1097 collection_table_move_focus(ct, focus_row, focus_col, TRUE);
1098 new_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1100 if (new_info != old_info)
1102 if (event->state & GDK_SHIFT_MASK)
1104 if (!options->collections.rectangular_selection)
1106 collection_table_select_region_util(ct, old_info, new_info, FALSE);
1110 collection_table_select_region_util(ct, ct->click_info, old_info, FALSE);
1112 collection_table_select_region_util(ct, ct->click_info, new_info, TRUE);
1114 else if (event->state & GDK_CONTROL_MASK)
1116 ct->click_info = new_info;
1120 ct->click_info = new_info;
1121 collection_table_unselect_all(ct);
1122 collection_table_select(ct, new_info);
1130 g_signal_stop_emission_by_name(GTK_OBJECT(widget), "key_press_event");
1139 *-------------------------------------------------------------------
1141 *-------------------------------------------------------------------
1144 static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gint *after, GdkRectangle *cell,
1145 gint use_coord, gint x, gint y)
1147 CollectInfo *info = NULL;
1148 GtkTreeModel *store;
1151 GtkTreeViewColumn *column;
1153 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1155 if (!use_coord) gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
1160 if (collection_table_find_iter(ct, source, &iter, &col))
1162 tpath = gtk_tree_model_get_path(store, &iter);
1163 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1164 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1165 gtk_tree_path_free(tpath);
1168 *after = (x > cell->x + (cell->width / 2));
1173 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
1174 &tpath, &column, NULL, NULL))
1179 gtk_tree_model_get_iter(store, &iter, tpath);
1180 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1182 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
1183 info = g_list_nth_data(list, n);
1187 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1188 *after = (x > cell->x + (cell->width / 2));
1191 gtk_tree_path_free(tpath);
1198 work = g_list_last(ct->cd->list);
1206 if (collection_table_find_iter(ct, info, &iter, &col))
1208 tpath = gtk_tree_model_get_path(store, &iter);
1209 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1210 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1211 gtk_tree_path_free(tpath);
1219 static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint y)
1225 info = collection_table_insert_find(ct, NULL, &after, &cell, TRUE, x, y);
1231 work = g_list_find(ct->cd->list, info);
1232 if (work && work->next)
1234 info = work->next->data;
1245 static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gint enable)
1253 if (ct->marker_window) gdk_window_destroy(ct->marker_window);
1254 ct->marker_window = NULL;
1259 info = collection_table_insert_find(ct, info, &after, &cell, FALSE, 0, 0);
1261 /* this setting does not take into account (after), but since it is not really used... */
1262 ct->marker_info = info;
1267 if (!ct->marker_window)
1270 GdkWindowAttr attributes;
1271 gint attributes_mask;
1277 parent = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(ct->listview));
1279 pb = gdk_pixbuf_new_from_xpm_data((const char **)marker_xpm);
1280 gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128);
1281 gdk_pixbuf_unref(pb);
1283 gdk_drawable_get_size(pixmap, &w, &h);
1285 attributes.window_type = GDK_WINDOW_CHILD;
1286 attributes.wclass = GDK_INPUT_OUTPUT;
1287 attributes.width = w;
1288 attributes.height = h;
1289 attributes.event_mask = gtk_widget_get_events(ct->listview);
1290 attributes_mask = 0;
1292 ct->marker_window = gdk_window_new(parent, &attributes, attributes_mask);
1293 gdk_window_set_back_pixmap(ct->marker_window, pixmap, FALSE);
1294 gdk_window_shape_combine_mask(ct->marker_window, mask, 0, 0);
1296 g_object_unref(pixmap);
1297 if (mask) g_object_unref(mask);
1305 gdk_drawable_get_size(ct->marker_window, &w, &h);
1313 x = cell.x + cell.width;
1316 y = cell.y + (cell.height / 2) - (h / 2);
1318 gdk_window_move(ct->marker_window, x, y);
1319 gdk_window_clear(ct->marker_window);
1320 if (!gdk_window_is_visible(ct->marker_window)) gdk_window_show(ct->marker_window);
1324 if (gdk_window_is_visible(ct->marker_window)) gdk_window_hide(ct->marker_window);
1329 *-------------------------------------------------------------------
1330 * mouse drag auto-scroll
1331 *-------------------------------------------------------------------
1334 static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gint drop_event)
1338 info = collection_table_find_data_by_coord(ct, x, y, NULL);
1343 collection_table_insert_marker(ct, info, TRUE);
1347 tip_update(ct, info);
1351 static gint collection_table_auto_scroll_idle_cb(gpointer data)
1353 CollectTable *ct = data;
1358 if (ct->drop_idle_id == -1) return FALSE;
1360 window = ct->listview->window;
1361 gdk_window_get_pointer(window, &x, &y, NULL);
1362 gdk_drawable_get_size(window, &w, &h);
1363 if (x >= 0 && x < w && y >= 0 && y < h)
1365 collection_table_motion_update(ct, x, y, TRUE);
1368 ct->drop_idle_id = -1;
1372 static gint collection_table_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data)
1374 CollectTable *ct = data;
1376 if (ct->drop_idle_id == -1) ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
1381 static void collection_table_scroll(CollectTable *ct, gint scroll)
1385 if (ct->drop_idle_id != -1)
1387 g_source_remove(ct->drop_idle_id);
1388 ct->drop_idle_id = -1;
1390 widget_auto_scroll_stop(ct->listview);
1391 collection_table_insert_marker(ct, NULL, FALSE);
1395 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
1396 widget_auto_scroll_start(ct->listview, adj, -1, options->thumbnails.max_height / 2,
1397 collection_table_auto_scroll_notify_cb, ct);
1402 *-------------------------------------------------------------------
1404 *-------------------------------------------------------------------
1407 static gint collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1409 CollectTable *ct = data;
1411 collection_table_motion_update(ct, (gint)bevent->x, (gint)bevent->y, FALSE);
1416 static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1418 CollectTable *ct = data;
1424 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1426 ct->click_info = info;
1427 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, &iter);
1429 switch (bevent->button)
1431 case MOUSE_BUTTON_LEFT:
1432 if (bevent->type == GDK_2BUTTON_PRESS)
1436 layout_image_set_collection(NULL, ct->cd, info);
1439 else if (!GTK_WIDGET_HAS_FOCUS(ct->listview))
1441 gtk_widget_grab_focus(ct->listview);
1444 case MOUSE_BUTTON_RIGHT:
1445 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1446 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
1455 static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1457 CollectTable *ct = data;
1459 CollectInfo *info = NULL;
1463 if ((gint)bevent->x != 0 || (gint) bevent->y != 0)
1465 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1470 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1473 if (bevent->button == MOUSE_BUTTON_LEFT &&
1474 info && ct->click_info == info)
1476 collection_table_set_focus(ct, info);
1478 if (bevent->state & GDK_CONTROL_MASK)
1482 select = !INFO_SELECTED(info);
1483 if ((bevent->state & GDK_SHIFT_MASK) && ct->prev_selection)
1485 collection_table_select_region_util(ct, ct->prev_selection, info, select);
1489 collection_table_select_util(ct, info, select);
1494 collection_table_unselect_all(ct);
1496 if ((bevent->state & GDK_SHIFT_MASK) &&
1499 collection_table_select_region_util(ct, ct->prev_selection, info, TRUE);
1503 collection_table_select_util(ct, info, TRUE);
1507 else if (bevent->button == MOUSE_BUTTON_MIDDLE &&
1508 info && ct->click_info == info)
1510 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1516 static gint collection_table_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
1518 CollectTable *ct = data;
1525 *-------------------------------------------------------------------
1526 * populate, add, insert, etc.
1527 *-------------------------------------------------------------------
1530 static gboolean collection_table_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data)
1534 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
1540 static void collection_table_clear_store(CollectTable *ct)
1542 GtkTreeModel *store;
1544 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1545 gtk_tree_model_foreach(store, collection_table_destroy_node_cb, NULL);
1547 gtk_list_store_clear(GTK_LIST_STORE(store));
1550 static GList *collection_table_add_row(CollectTable *ct, GtkTreeIter *iter)
1552 GtkListStore *store;
1556 for (i = 0; i < ct->columns; i++) list = g_list_prepend(list, NULL);
1558 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)));
1559 gtk_list_store_append(store, iter);
1560 gtk_list_store_set(store, iter, CTABLE_COLUMN_POINTER, list, -1);
1565 static void collection_table_populate(CollectTable *ct, gint resize)
1570 collection_table_verify_selections(ct);
1572 collection_table_clear_store(ct);
1579 thumb_width = collection_table_get_icon_width(ct);
1581 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
1583 GtkTreeViewColumn *column;
1584 GtkCellRenderer *cell;
1587 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), i);
1588 gtk_tree_view_column_set_visible(column, (i < ct->columns));
1589 gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6));
1591 list = gtk_tree_view_column_get_cell_renderers(column);
1592 cell = (list) ? list->data : NULL;
1595 if (cell && GQV_IS_CELL_RENDERER_ICON(cell))
1597 g_object_set(G_OBJECT(cell), "fixed_width", thumb_width,
1598 "fixed_height", options->thumbnails.max_height,
1599 "show_text", ct->show_text, NULL);
1602 if (GTK_WIDGET_REALIZED(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
1606 work = ct->cd->list;
1614 list = collection_table_add_row(ct, &iter);
1615 while (work && list)
1617 list->data = work->data;
1625 collection_table_update_focus(ct);
1626 collection_table_update_status(ct);
1629 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force)
1634 thumb_width = collection_table_get_icon_width(ct);
1636 new_cols = w / (thumb_width + (THUMB_BORDER_PADDING * 6));
1637 if (new_cols < 1) new_cols = 1;
1639 if (!force && new_cols == ct->columns) return;
1641 ct->columns = new_cols;
1643 collection_table_populate(ct, TRUE);
1645 DEBUG_1("col tab pop cols=%d rows=%d\n", ct->columns, ct->rows);
1648 static void collection_table_sync(CollectTable *ct)
1650 GtkTreeModel *store;
1655 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1660 work = ct->cd->list;
1666 if (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1668 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1669 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1673 list = collection_table_add_row(ct, &iter);
1698 while (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1702 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1703 gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
1709 collection_table_update_focus(ct);
1710 collection_table_update_status(ct);
1713 static gint collection_table_sync_idle_cb(gpointer data)
1715 CollectTable *ct = data;
1717 if (ct->sync_idle_id == -1) return FALSE;
1718 ct->sync_idle_id = -1;
1720 collection_table_sync(ct);
1724 static void collection_table_sync_idle(CollectTable *ct)
1726 if (ct->sync_idle_id == -1)
1728 /* high priority, the view needs to be resynced before a redraw
1729 * may contain invalid pointers at this time
1731 ct->sync_idle_id = g_idle_add_full(G_PRIORITY_HIGH, collection_table_sync_idle_cb, ct, NULL);
1735 void collection_table_add_filelist(CollectTable *ct, GList *list)
1744 collection_add(ct->cd, (FileData *)work->data, FALSE);
1749 static void collection_table_insert_filelist(CollectTable *ct, GList *list, CollectInfo *insert_info)
1758 collection_insert(ct->cd, (FileData *)work->data, insert_info, FALSE);
1762 collection_table_sync_idle(ct);
1765 static void collection_table_move_by_info_list(CollectTable *ct, GList *info_list, gint row, gint col)
1768 GList *insert_pos = NULL;
1772 if (!info_list) return;
1774 info = collection_table_find_data(ct, row, col, NULL);
1776 if (!info_list->next && info_list->data == info) return;
1778 if (info) insert_pos = g_list_find(ct->cd->list, info);
1780 /* FIXME: this may get slow for large lists */
1782 while (insert_pos && work)
1784 if (insert_pos->data == work->data)
1786 insert_pos = insert_pos->next;
1798 ct->cd->list = g_list_remove(ct->cd->list, work->data);
1802 /* place them back in */
1803 temp = g_list_copy(info_list);
1807 ct->cd->list = uig_list_insert_list(ct->cd->list, insert_pos, temp);
1811 ct->cd->list = g_list_concat(temp, ct->cd->list);
1815 ct->cd->list = g_list_concat(ct->cd->list, temp);
1818 ct->cd->changed = TRUE;
1820 collection_table_sync_idle(ct);
1825 *-------------------------------------------------------------------
1827 *-------------------------------------------------------------------
1830 void collection_table_file_update(CollectTable *ct, CollectInfo *info)
1838 collection_table_update_extras(ct, FALSE, 0.0);
1842 if (!collection_table_find_position(ct, info, &row, &col)) return;
1844 if (ct->columns != 0 && ct->rows != 0)
1846 value = (gdouble)(row * ct->columns + col) / (ct->columns * ct->rows);
1853 collection_table_update_extras(ct, TRUE, value);
1855 if (collection_table_find_iter(ct, info, &iter, NULL))
1857 GtkTreeModel *store;
1860 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1861 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1862 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1866 void collection_table_file_add(CollectTable *ct, CollectInfo *info)
1868 collection_table_sync_idle(ct);
1871 void collection_table_file_insert(CollectTable *ct, CollectInfo *ci)
1873 collection_table_sync_idle(ct);
1876 void collection_table_file_remove(CollectTable *ct, CollectInfo *ci)
1878 if (ci && INFO_SELECTED(ci))
1880 ct->selection = g_list_remove(ct->selection, ci);
1883 collection_table_sync_idle(ct);
1886 void collection_table_refresh(CollectTable *ct)
1888 collection_table_populate(ct, FALSE);
1892 *-------------------------------------------------------------------
1894 *-------------------------------------------------------------------
1897 static void collection_table_add_dir_recursive(CollectTable *ct, gchar *path, gint recursive)
1902 if (filelist_read(path, &f, recursive ? &d : NULL))
1906 f = filelist_filter(f, FALSE);
1907 d = filelist_filter(d, TRUE);
1909 f = filelist_sort_path(f);
1910 d = filelist_sort_path(d);
1912 collection_table_insert_filelist(ct, f, ct->marker_info);
1914 work = g_list_last(d);
1917 collection_table_add_dir_recursive(ct, ((FileData *)work->data)->path, TRUE);
1925 static void confirm_dir_list_do(CollectTable *ct, GList *list, gint recursive)
1930 FileData *fd = work->data;
1932 if (isdir(fd->path)) collection_table_add_dir_recursive(ct, fd->path, recursive);
1934 collection_table_insert_filelist(ct, list, ct->marker_info);
1938 static void confirm_dir_list_add(GtkWidget *widget, gpointer data)
1940 CollectTable *ct = data;
1942 confirm_dir_list_do(ct, ct->drop_list, FALSE);
1945 static void confirm_dir_list_recurse(GtkWidget *widget, gpointer data)
1947 CollectTable *ct = data;
1949 confirm_dir_list_do(ct, ct->drop_list, TRUE);
1952 static void confirm_dir_list_skip(GtkWidget *widget, gpointer data)
1954 CollectTable *ct = data;
1956 collection_table_insert_filelist(ct, ct->drop_list, ct->marker_info);
1959 static GtkWidget *collection_table_drop_menu(CollectTable *ct)
1963 menu = popup_menu_short_lived();
1964 g_signal_connect(G_OBJECT(menu), "destroy",
1965 G_CALLBACK(collection_table_popup_destroy_cb), ct);
1967 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL);
1968 menu_item_add_divider(menu);
1969 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK,
1970 G_CALLBACK(confirm_dir_list_add), ct);
1971 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD,
1972 G_CALLBACK(confirm_dir_list_recurse), ct);
1973 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE,
1974 G_CALLBACK(confirm_dir_list_skip), ct);
1975 menu_item_add_divider(menu);
1976 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, ct);
1982 *-------------------------------------------------------------------
1984 *-------------------------------------------------------------------
1987 static GtkTargetEntry collection_drag_types[] = {
1988 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
1989 { "text/uri-list", 0, TARGET_URI_LIST },
1990 { "text/plain", 0, TARGET_TEXT_PLAIN }
1992 static gint n_collection_drag_types = 3;
1994 static GtkTargetEntry collection_drop_types[] = {
1995 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
1996 { "text/uri-list", 0, TARGET_URI_LIST }
1998 static gint n_collection_drop_types = 2;
2001 static void collection_table_dnd_get(GtkWidget *widget, GdkDragContext *context,
2002 GtkSelectionData *selection_data, guint info,
2003 guint time, gpointer data)
2005 CollectTable *ct = data;
2008 gchar *uri_text = NULL;
2011 if (!ct->click_info) return;
2013 selected = INFO_SELECTED(ct->click_info);
2017 case TARGET_APP_COLLECTION_MEMBER:
2020 uri_text = collection_info_list_to_dnd_data(ct->cd, ct->selection, &total);
2024 list = g_list_append(NULL, ct->click_info);
2025 uri_text = collection_info_list_to_dnd_data(ct->cd, list, &total);
2029 case TARGET_URI_LIST:
2030 case TARGET_TEXT_PLAIN:
2034 list = collection_table_selection_get_list(ct);
2038 list = g_list_append(NULL, file_data_ref(ct->click_info->fd));
2042 uri_text = uri_text_from_filelist(list, &total, (info == TARGET_TEXT_PLAIN));
2043 filelist_free(list);
2047 gtk_selection_data_set(selection_data, selection_data->target,
2048 8, (guchar *)uri_text, total);
2053 static void collection_table_dnd_receive(GtkWidget *widget, GdkDragContext *context,
2055 GtkSelectionData *selection_data, guint info,
2056 guint time, gpointer data)
2058 CollectTable *ct = data;
2060 GList *info_list = NULL;
2061 CollectionData *source;
2062 CollectInfo *drop_info;
2065 DEBUG_1("%s\n", selection_data->data);
2067 collection_table_scroll(ct, FALSE);
2068 collection_table_insert_marker(ct, NULL, FALSE);
2070 drop_info = collection_table_insert_point(ct, x, y);
2074 case TARGET_APP_COLLECTION_MEMBER:
2075 source = collection_from_dnd_data((gchar *)selection_data->data, &list, &info_list);
2078 if (source == ct->cd)
2083 /* it is a move within a collection */
2084 filelist_free(list);
2089 collection_table_move_by_info_list(ct, info_list, -1, -1);
2091 else if (collection_table_find_position(ct, drop_info, &row, &col))
2093 collection_table_move_by_info_list(ct, info_list, row, col);
2098 /* it is a move/copy across collections */
2099 if (context->action == GDK_ACTION_MOVE)
2101 collection_remove_by_info_list(source, info_list);
2104 g_list_free(info_list);
2107 case TARGET_URI_LIST:
2108 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE);
2112 FileData *fd = work->data;
2113 if (isdir(fd->path))
2117 ct->drop_list = list;
2118 ct->drop_info = drop_info;
2119 menu = collection_table_drop_menu(ct);
2120 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time);
2133 collection_table_insert_filelist(ct, list, drop_info);
2134 filelist_free(list);
2138 static void collection_table_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
2140 CollectTable *ct = data;
2142 if (ct->click_info && ct->click_info->pixbuf)
2146 if (INFO_SELECTED(ct->click_info))
2147 items = g_list_length(ct->selection);
2150 dnd_set_drag_icon(widget, context, ct->click_info->pixbuf, items);
2154 static void collection_table_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
2156 CollectTable *ct = data;
2158 /* apparently a leave event is not generated on a drop */
2161 collection_table_scroll(ct, FALSE);
2164 static gint collection_table_dnd_motion(GtkWidget *widget, GdkDragContext *context,
2165 gint x, gint y, guint time, gpointer data)
2167 CollectTable *ct = data;
2169 collection_table_motion_update(ct, x, y, TRUE);
2170 collection_table_scroll(ct, TRUE);
2175 static void collection_table_dnd_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data)
2177 CollectTable *ct = data;
2179 collection_table_scroll(ct, FALSE);
2182 static void collection_table_dnd_init(CollectTable *ct)
2184 gtk_drag_source_set(ct->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
2185 collection_drag_types, n_collection_drag_types,
2186 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
2187 g_signal_connect(G_OBJECT(ct->listview), "drag_data_get",
2188 G_CALLBACK(collection_table_dnd_get), ct);
2189 g_signal_connect(G_OBJECT(ct->listview), "drag_begin",
2190 G_CALLBACK(collection_table_dnd_begin), ct);
2191 g_signal_connect(G_OBJECT(ct->listview), "drag_end",
2192 G_CALLBACK(collection_table_dnd_end), ct);
2194 gtk_drag_dest_set(ct->listview,
2195 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
2196 collection_drop_types, n_collection_drop_types,
2197 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK);
2198 g_signal_connect(G_OBJECT(ct->listview), "drag_motion",
2199 G_CALLBACK(collection_table_dnd_motion), ct);
2200 g_signal_connect(G_OBJECT(ct->listview), "drag_leave",
2201 G_CALLBACK(collection_table_dnd_leave), ct);
2202 g_signal_connect(G_OBJECT(ct->listview), "drag_data_received",
2203 G_CALLBACK(collection_table_dnd_receive), ct);
2207 *-----------------------------------------------------------------------------
2209 *-----------------------------------------------------------------------------
2212 typedef struct _ColumnData ColumnData;
2219 static void collection_table_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
2220 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
2222 ColumnData *cd = data;
2232 gtk_tree_model_get(tree_model, iter, CTABLE_COLUMN_POINTER, &list, -1);
2233 info = g_list_nth_data(list, cd->number);
2235 style = gtk_widget_get_style(ct->listview);
2236 if (info && (info->flag_mask & SELECTION_SELECTED) )
2238 memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg));
2239 memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg));
2243 memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg));
2244 memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg));
2247 if (info && (info->flag_mask & SELECTION_PRELIGHT))
2250 shift_color(&color_fg, -1, 0);
2252 shift_color(&color_bg, -1, 0);
2255 if (GQV_IS_CELL_RENDERER_ICON(cell))
2259 g_object_set(cell, "pixbuf", info->pixbuf,
2260 "text", info->fd->name,
2261 "cell-background-gdk", &color_bg,
2262 "cell-background-set", TRUE,
2263 "foreground-gdk", &color_fg,
2264 "foreground-set", TRUE,
2265 "has-focus", (ct->focus_info == info), NULL);
2269 g_object_set(cell, "pixbuf", NULL,
2271 "cell-background-set", FALSE,
2272 "foreground-set", FALSE,
2273 "has-focus", FALSE, NULL);
2278 static void collection_table_append_column(CollectTable *ct, gint n)
2281 GtkTreeViewColumn *column;
2282 GtkCellRenderer *renderer;
2284 column = gtk_tree_view_column_new();
2285 gtk_tree_view_column_set_min_width(column, 0);
2287 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
2288 gtk_tree_view_column_set_alignment(column, 0.5);
2290 renderer = gqv_cell_renderer_icon_new();
2291 gtk_tree_view_column_pack_start(column, renderer, FALSE);
2292 g_object_set(G_OBJECT(renderer), "xpad", THUMB_BORDER_PADDING * 2,
2293 "ypad", THUMB_BORDER_PADDING,
2294 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
2296 g_object_set_data(G_OBJECT(column), "column_number", GINT_TO_POINTER(n));
2298 cd = g_new0(ColumnData, 1);
2301 gtk_tree_view_column_set_cell_data_func(column, renderer, collection_table_cell_data_cb, cd, g_free);
2303 gtk_tree_view_append_column(GTK_TREE_VIEW(ct->listview), column);
2307 *-------------------------------------------------------------------
2309 *-------------------------------------------------------------------
2312 static void collection_table_destroy(GtkWidget *widget, gpointer data)
2314 CollectTable *ct = data;
2318 g_signal_handlers_disconnect_matched(GTK_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA,
2320 gtk_widget_destroy(ct->popup);
2323 if (ct->sync_idle_id != -1) g_source_remove(ct->sync_idle_id);
2326 collection_table_scroll(ct, FALSE);
2331 static void collection_table_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
2333 CollectTable *ct = data;
2335 collection_table_populate_at_new_size(ct, allocation->width, allocation->height, FALSE);
2338 CollectTable *collection_table_new(CollectionData *cd)
2341 GtkListStore *store;
2342 GtkTreeSelection *selection;
2345 ct = g_new0(CollectTable, 1);
2350 ct->selection = NULL;
2351 ct->prev_selection = NULL;
2353 ct->tip_window = NULL;
2354 ct->tip_delay_id = -1;
2356 ct->marker_window = NULL;
2357 ct->marker_info = NULL;
2359 ct->status_label = NULL;
2360 ct->extra_label = NULL;
2363 ct->focus_column = 0;
2364 ct->focus_info = NULL;
2366 ct->show_text = options->show_icon_names;
2368 ct->sync_idle_id = -1;
2369 ct->drop_idle_id = -1;
2372 ct->drop_info = NULL;
2373 ct->drop_list = NULL;
2375 ct->scrolled = gtk_scrolled_window_new(NULL, NULL);
2376 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN);
2377 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ct->scrolled),
2378 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2380 store = gtk_list_store_new(1, G_TYPE_POINTER);
2381 ct->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
2382 g_object_unref(store);
2384 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ct->listview));
2385 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_NONE);
2387 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ct->listview), FALSE);
2388 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ct->listview), FALSE);
2390 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
2392 collection_table_append_column(ct, i);
2395 /* zero width column to hide tree view focus, we draw it ourselves */
2396 collection_table_append_column(ct, i);
2397 /* end column to fill white space */
2398 collection_table_append_column(ct, i);
2400 g_signal_connect(G_OBJECT(ct->listview), "destroy",
2401 G_CALLBACK(collection_table_destroy), ct);
2402 g_signal_connect(G_OBJECT(ct->listview), "size_allocate",
2403 G_CALLBACK(collection_table_sized), ct);
2404 g_signal_connect(G_OBJECT(ct->listview), "key_press_event",
2405 G_CALLBACK(collection_table_press_key_cb), ct);
2407 gtk_container_add(GTK_CONTAINER(ct->scrolled), ct->listview);
2408 gtk_widget_show(ct->listview);
2410 collection_table_dnd_init(ct);
2412 gtk_widget_set_events(ct->listview, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK |
2413 GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK);
2414 g_signal_connect(G_OBJECT(ct->listview),"button_press_event",
2415 G_CALLBACK(collection_table_press_cb), ct);
2416 g_signal_connect(G_OBJECT(ct->listview),"button_release_event",
2417 G_CALLBACK(collection_table_release_cb), ct);
2418 g_signal_connect(G_OBJECT(ct->listview),"motion_notify_event",
2419 G_CALLBACK(collection_table_motion_cb), ct);
2420 g_signal_connect(G_OBJECT(ct->listview), "leave_notify_event",
2421 G_CALLBACK(collection_table_leave_cb), ct);
2426 void collection_table_set_labels(CollectTable *ct, GtkWidget *status, GtkWidget *extra)
2428 ct->status_label = status;
2429 ct->extra_label = extra;
2430 collection_table_update_status(ct);
2431 collection_table_update_extras(ct, FALSE, 0.0);
2434 CollectInfo *collection_table_get_focus_info(CollectTable *ct)
2436 return collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);