7 * This software is released under the GNU General Public License (GNU GPL).
8 * Please read the included file COPYING for more information.
9 * This software comes with no warranty of any kind, use at your own risk!
14 #include "collect-table.h"
16 #include "cellrenderericon.h"
17 #include "collect-dlg.h"
18 #include "collect-io.h"
26 #include "layout_image.h"
30 #include "ui_bookmark.h"
31 #include "ui_fileops.h"
33 #include "ui_tree_edit.h"
35 #include "icons/marker.xpm"
36 #define MARKER_WIDTH 26
37 #define MARKER_HEIGHT 32
39 #include <gdk/gdkkeysyms.h> /* for keyboard values */
41 /* between these, the icon width is increased by thumb_max_width / 2 */
42 #define THUMB_MIN_ICON_WIDTH 128
43 #define THUMB_MAX_ICON_WIDTH 150
45 #define COLLECT_TABLE_MAX_COLUMNS 32
46 #define THUMB_BORDER_PADDING 2
48 #define COLLECT_TABLE_TIP_DELAY 500
52 CTABLE_COLUMN_POINTER = 0,
58 SELECTION_SELECTED = 1 << 0,
59 SELECTION_PRELIGHT = 1 << 1,
60 SELECTION_FOCUS = 1 << 2
64 #define INFO_SELECTED(x) (x->flag_mask & SELECTION_SELECTED)
67 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force);
71 *-------------------------------------------------------------------
73 *-------------------------------------------------------------------
76 static gint collection_table_find_position(CollectTable *ct, CollectInfo *info, gint *row, gint *col)
80 n = g_list_index(ct->cd->list, info);
82 if (n < 0) return FALSE;
84 *row = n / ct->columns;
85 *col = n - (*row * ct->columns);
90 static gint collection_table_find_iter(CollectTable *ct, CollectInfo *info, GtkTreeIter *iter, gint *column)
95 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
96 if (!collection_table_find_position(ct, info, &row, &col)) return FALSE;
97 if (!gtk_tree_model_iter_nth_child(store, iter, NULL, row)) return FALSE;
98 if (column) *column = col;
103 static CollectInfo *collection_table_find_data(CollectTable *ct, gint row, gint col, GtkTreeIter *iter)
108 if (row < 0 || col < 0) return NULL;
110 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
111 if (gtk_tree_model_iter_nth_child(store, &p, NULL, row))
115 gtk_tree_model_get(store, &p, CTABLE_COLUMN_POINTER, &list, -1);
116 if (!list) return NULL;
120 return g_list_nth_data(list, col);
126 static CollectInfo *collection_table_find_data_by_coord(CollectTable *ct, gint x, gint y, GtkTreeIter *iter)
129 GtkTreeViewColumn *column;
131 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
132 &tpath, &column, NULL, NULL))
139 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
140 gtk_tree_model_get_iter(store, &row, tpath);
141 gtk_tree_path_free(tpath);
143 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
145 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
148 if (iter) *iter = row;
149 return g_list_nth_data(list, n);
156 static void collection_table_update_status(CollectTable *ct)
158 if (ct->status_label)
164 buf = g_strdup(_("Empty"));
166 else if (ct->selection)
168 buf = g_strdup_printf(_("%d images (%d)"), g_list_length(ct->cd->list), g_list_length(ct->selection));
172 buf = g_strdup_printf(_("%d images"), g_list_length(ct->cd->list));
175 gtk_label_set_text(GTK_LABEL(ct->status_label), buf);
180 static void collection_table_update_extras(CollectTable *ct, gint loading, gdouble value)
186 text = _("Loading thumbs...");
190 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ct->extra_label), value);
191 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ct->extra_label), text);
195 static void collection_table_toggle_filenames(CollectTable *ct)
197 ct->show_text = !ct->show_text;
198 show_icon_names = ct->show_text;
200 collection_table_populate_at_new_size(ct, ct->listview->allocation.width, ct->listview->allocation.height, TRUE);
203 static gint collection_table_get_icon_width(CollectTable *ct)
207 if (!ct->show_text) return thumb_max_width;
209 width = thumb_max_width + thumb_max_width / 2;
210 if (width < THUMB_MIN_ICON_WIDTH) width = THUMB_MIN_ICON_WIDTH;
211 if (width > THUMB_MAX_ICON_WIDTH) width = thumb_max_width;
217 *-------------------------------------------------------------------
219 *-------------------------------------------------------------------
222 static void collection_table_selection_set(CollectTable *ct, CollectInfo *info, SelectionType value, GtkTreeIter *iter)
229 if (info->flag_mask == value) return;
230 info->flag_mask = value;
232 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
235 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
236 if (list) gtk_list_store_set(GTK_LIST_STORE(store), iter, CTABLE_COLUMN_POINTER, list, -1);
242 if (collection_table_find_iter(ct, info, &row, NULL))
244 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
245 if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, CTABLE_COLUMN_POINTER, list, -1);
250 static void collection_table_selection_add(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
254 collection_table_selection_set(ct, info, info->flag_mask | mask, iter);
257 static void collection_table_selection_remove(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
261 collection_table_selection_set(ct, info, info->flag_mask & ~mask, iter);
264 *-------------------------------------------------------------------
266 *-------------------------------------------------------------------
269 static void collection_table_verify_selections(CollectTable *ct)
273 work = ct->selection;
276 CollectInfo *info = work->data;
278 if (!g_list_find(ct->cd->list, info))
280 ct->selection = g_list_remove(ct->selection, info);
285 void collection_table_select_all(CollectTable *ct)
289 g_list_free(ct->selection);
290 ct->selection = NULL;
295 ct->selection = g_list_append(ct->selection, work->data);
296 collection_table_selection_add(ct, work->data, SELECTION_SELECTED, NULL);
300 collection_table_update_status(ct);
303 void collection_table_unselect_all(CollectTable *ct)
307 work = ct->selection;
310 collection_table_selection_remove(ct, work->data, SELECTION_SELECTED, NULL);
314 g_list_free(ct->selection);
315 ct->selection = NULL;
317 collection_table_update_status(ct);
320 static void collection_table_select(CollectTable *ct, CollectInfo *info)
322 ct->prev_selection = info;
324 if (!info || INFO_SELECTED(info)) return;
326 ct->selection = g_list_append(ct->selection, info);
327 collection_table_selection_add(ct, info, SELECTION_SELECTED, NULL);
329 collection_table_update_status(ct);
332 static void collection_table_unselect(CollectTable *ct, CollectInfo *info)
334 ct->prev_selection = info;
336 if (!info || !INFO_SELECTED(info) ) return;
338 ct->selection = g_list_remove(ct->selection, info);
339 collection_table_selection_remove(ct, info, SELECTION_SELECTED, NULL);
341 collection_table_update_status(ct);
344 static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gint select)
348 collection_table_select(ct, info);
352 collection_table_unselect(ct, info);
356 static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gint select)
363 if (!collection_table_find_position(ct, start, &row1, &col1) ||
364 !collection_table_find_position(ct, end, &row2, &col2) ) return;
366 ct->prev_selection = end;
368 if (!collection_rectangular_selection)
373 if (g_list_index(ct->cd->list, start) > g_list_index(ct->cd->list, end))
380 work = g_list_find(ct->cd->list, start);
384 collection_table_select_util(ct, info, select);
386 if (work->data != end)
407 if (debug) printf("table: %d x %d to %d x %d\n", row1, col1, row2, col2);
409 for (i = row1; i <= row2; i++)
411 for (j = col1; j <= col2; j++)
413 CollectInfo *info = collection_table_find_data(ct, i, j, NULL);
414 if (info) collection_table_select_util(ct, info, select);
419 GList *collection_table_selection_get_list(CollectTable *ct)
421 return collection_list_to_path_list(ct->selection);
424 static GList *collection_table_get_list(CollectTable *ct)
426 return collection_list_to_path_list(ct->cd->list);
430 *-------------------------------------------------------------------
431 * tooltip type window
432 *-------------------------------------------------------------------
435 static void tip_show(CollectTable *ct)
440 if (ct->tip_window) return;
442 gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
444 ct->tip_info = collection_table_find_data_by_coord(ct, x, y, NULL);
445 if (!ct->tip_info) return;
447 ct->tip_window = gtk_window_new(GTK_WINDOW_POPUP);
448 gtk_window_set_resizable(GTK_WINDOW(ct->tip_window), FALSE);
449 gtk_container_set_border_width(GTK_CONTAINER(ct->tip_window), 2);
451 label = gtk_label_new(filename_from_path(ct->tip_info->path));
453 g_object_set_data(G_OBJECT(ct->tip_window), "tip_label", label);
454 gtk_container_add(GTK_CONTAINER(ct->tip_window), label);
455 gtk_widget_show(label);
457 gdk_window_get_pointer(NULL, &x, &y, NULL);
459 if (!GTK_WIDGET_REALIZED(ct->tip_window)) gtk_widget_realize(ct->tip_window);
460 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
461 gtk_widget_show(ct->tip_window);
464 static void tip_hide(CollectTable *ct)
466 if (ct->tip_window) gtk_widget_destroy(ct->tip_window);
467 ct->tip_window = NULL;
470 static gint tip_schedule_cb(gpointer data)
472 CollectTable *ct = data;
474 if (ct->tip_delay_id == -1) return FALSE;
478 ct->tip_delay_id = -1;
482 static void tip_schedule(CollectTable *ct)
486 if (ct->tip_delay_id != -1)
488 g_source_remove(ct->tip_delay_id);
489 ct->tip_delay_id = -1;
494 ct->tip_delay_id = g_timeout_add(COLLECT_TABLE_TIP_DELAY, tip_schedule_cb, ct);
498 static void tip_unschedule(CollectTable *ct)
502 if (ct->tip_delay_id != -1) g_source_remove(ct->tip_delay_id);
503 ct->tip_delay_id = -1;
506 static void tip_update(CollectTable *ct, CollectInfo *info)
512 gdk_window_get_pointer(NULL, &x, &y, NULL);
513 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
515 if (info != ct->tip_info)
528 label = g_object_get_data(G_OBJECT(ct->tip_window), "tip_label");
529 gtk_label_set_text(GTK_LABEL(label), filename_from_path(ct->tip_info->path));
539 *-------------------------------------------------------------------
541 *-------------------------------------------------------------------
544 static void collection_table_popup_save_as_cb(GtkWidget *widget, gpointer data)
546 CollectTable *ct = data;
548 collection_dialog_save_as(NULL, ct->cd);
551 static void collection_table_popup_save_cb(GtkWidget *widget, gpointer data)
553 CollectTable *ct = data;
557 collection_table_popup_save_as_cb(widget, data);
561 if (!collection_save(ct->cd, ct->cd->path))
563 printf("failed saving to collection path: %s\n", ct->cd->path);
567 static GList *collection_table_popup_file_list(CollectTable *ct)
569 if (!ct->click_info) return NULL;
571 if (INFO_SELECTED(ct->click_info))
573 return collection_table_selection_get_list(ct);
576 return g_list_append(NULL, g_strdup(ct->click_info->path));
579 static void collection_table_popup_edit_cb(GtkWidget *widget, gpointer data)
585 ct = submenu_item_get_data(widget);
588 n = GPOINTER_TO_INT(data);
590 list = collection_table_popup_file_list(ct);
593 start_editor_from_path_list(n, list);
594 path_list_free(list);
598 static void collection_table_popup_info_cb(GtkWidget *widget, gpointer data)
600 CollectTable *ct = data;
602 info_window_new(NULL, collection_table_popup_file_list(ct));
605 static void collection_table_popup_copy_cb(GtkWidget *widget, gpointer data)
607 CollectTable *ct = data;
609 file_util_copy(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);
612 static void collection_table_popup_move_cb(GtkWidget *widget, gpointer data)
614 CollectTable *ct = data;
616 file_util_move(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);
619 static void collection_table_popup_rename_cb(GtkWidget *widget, gpointer data)
621 CollectTable *ct = data;
623 file_util_rename(NULL, collection_table_popup_file_list(ct), ct->listview);
626 static void collection_table_popup_delete_cb(GtkWidget *widget, gpointer data)
628 CollectTable *ct = data;
630 file_util_delete(NULL, collection_table_popup_file_list(ct), ct->listview);
633 static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data)
638 ct = submenu_item_get_data(widget);
642 type = (SortType)GPOINTER_TO_INT(data);
644 collection_set_sort_method(ct->cd, type);
647 static void collection_table_popup_view_new_cb(GtkWidget *widget, gpointer data)
649 CollectTable *ct = data;
651 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
653 view_window_new_from_collection(ct->cd, ct->click_info);
657 static void collection_table_popup_view_cb(GtkWidget *widget, gpointer data)
659 CollectTable *ct = data;
661 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
663 layout_image_set_collection(NULL, ct->cd, ct->click_info);
667 static void collection_table_popup_selectall_cb(GtkWidget *widget, gpointer data)
669 CollectTable *ct = data;
671 collection_table_select_all(ct);
672 ct->prev_selection= ct->click_info;
675 static void collection_table_popup_unselectall_cb(GtkWidget *widget, gpointer data)
677 CollectTable *ct = data;
679 collection_table_unselect_all(ct);
680 ct->prev_selection= ct->click_info;
683 static void collection_table_popup_remove_cb(GtkWidget *widget, gpointer data)
685 CollectTable *ct = data;
688 if (!ct->click_info) return;
690 if (INFO_SELECTED(ct->click_info))
692 list = g_list_copy(ct->selection);
696 list = g_list_append(NULL, ct->click_info);
699 collection_remove_by_info_list(ct->cd, list);
703 static void collection_table_popup_add_filelist_cb(GtkWidget *widget, gpointer data)
705 CollectTable *ct = data;
708 list = layout_list(NULL);
712 collection_table_add_path_list(ct, list);
713 path_list_free(list);
717 static void collection_table_popup_add_collection_cb(GtkWidget *widget, gpointer data)
719 CollectTable *ct = data;
721 collection_dialog_append(NULL, ct->cd);
724 static void collection_table_popup_find_dupes_cb(GtkWidget *widget, gpointer data)
726 CollectTable *ct = data;
729 dw = dupe_window_new(DUPE_MATCH_NAME);
730 dupe_window_add_collection(dw, ct->cd);
733 static void collection_table_popup_print_cb(GtkWidget *widget, gpointer data)
735 CollectTable *ct = data;
738 path = (ct->click_info) ? ct->click_info->path : NULL;
740 print_window_new(path, collection_table_selection_get_list(ct), collection_table_get_list(ct), ct->listview);
743 static void collection_table_popup_show_names_cb(GtkWidget *widget, gpointer data)
745 CollectTable *ct = data;
747 collection_table_toggle_filenames(ct);
750 static void collection_table_popup_destroy_cb(GtkWidget *widget, gpointer data)
752 CollectTable *ct = data;
754 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
755 ct->click_info = NULL;
758 path_list_free(ct->drop_list);
759 ct->drop_list = NULL;
760 ct->drop_info = NULL;
763 static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon)
768 menu = popup_menu_short_lived();
770 g_signal_connect(G_OBJECT(menu), "destroy",
771 G_CALLBACK(collection_table_popup_destroy_cb), ct);
773 menu_item_add_sensitive(menu, _("_View"), over_icon,
774 G_CALLBACK(collection_table_popup_view_cb), ct);
775 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, over_icon,
776 G_CALLBACK(collection_table_popup_view_new_cb), ct);
777 menu_item_add_divider(menu);
778 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, over_icon,
779 G_CALLBACK(collection_table_popup_remove_cb), ct);
781 menu_item_add_stock(menu, _("Append from file list"), GTK_STOCK_ADD,
782 G_CALLBACK(collection_table_popup_add_filelist_cb), ct);
783 menu_item_add_stock(menu, _("Append from collection..."), GTK_STOCK_OPEN,
784 G_CALLBACK(collection_table_popup_add_collection_cb), ct);
785 menu_item_add_divider(menu);
786 menu_item_add(menu, _("Select all"),
787 G_CALLBACK(collection_table_popup_selectall_cb), ct);
788 menu_item_add(menu, _("Select none"),
789 G_CALLBACK(collection_table_popup_unselectall_cb), ct);
790 menu_item_add_divider(menu);
792 submenu_add_edit(menu, &item,
793 G_CALLBACK(collection_table_popup_edit_cb), ct);
794 gtk_widget_set_sensitive(item, over_icon);
796 menu_item_add_sensitive(menu, _("_Properties"), over_icon,
797 G_CALLBACK(collection_table_popup_info_cb), ct);
798 menu_item_add_divider(menu);
799 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, over_icon,
800 G_CALLBACK(collection_table_popup_copy_cb), ct);
801 menu_item_add_sensitive(menu, _("_Move..."), over_icon,
802 G_CALLBACK(collection_table_popup_move_cb), ct);
803 menu_item_add_sensitive(menu, _("_Rename..."), over_icon,
804 G_CALLBACK(collection_table_popup_rename_cb), ct);
805 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, over_icon,
806 G_CALLBACK(collection_table_popup_delete_cb), ct);
807 menu_item_add_divider(menu);
809 submenu_add_sort(menu, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0);
810 menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
811 G_CALLBACK(collection_table_popup_show_names_cb), ct);
812 menu_item_add_divider(menu);
813 menu_item_add_stock(menu, _("_Save collection"), GTK_STOCK_SAVE,
814 G_CALLBACK(collection_table_popup_save_cb), ct);
815 menu_item_add_stock(menu, _("Save collection _as..."), GTK_STOCK_SAVE_AS,
816 G_CALLBACK(collection_table_popup_save_as_cb), ct);
817 menu_item_add_divider(menu);
818 menu_item_add_stock(menu, _("_Find duplicates..."), GTK_STOCK_FIND,
819 G_CALLBACK(collection_table_popup_find_dupes_cb), ct);
820 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, over_icon,
821 G_CALLBACK(collection_table_popup_print_cb), ct);
826 *-------------------------------------------------------------------
828 *-------------------------------------------------------------------
831 static void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
836 if (g_list_find(ct->cd->list, ct->focus_info))
838 if (info == ct->focus_info)
840 /* ensure focus row col are correct */
841 collection_table_find_position(ct, ct->focus_info,
842 &ct->focus_row, &ct->focus_column);
845 collection_table_selection_remove(ct, ct->focus_info, SELECTION_FOCUS, NULL);
848 if (!collection_table_find_position(ct, info, &row, &col))
850 ct->focus_info = NULL;
852 ct->focus_column = -1;
856 ct->focus_info = info;
858 ct->focus_column = col;
859 collection_table_selection_add(ct, ct->focus_info, SELECTION_FOCUS, NULL);
861 if (collection_table_find_iter(ct, ct->focus_info, &iter, NULL))
864 GtkTreeViewColumn *column;
867 tree_view_row_make_visible(GTK_TREE_VIEW(ct->listview), &iter, FALSE);
869 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
870 tpath = gtk_tree_model_get_path(store, &iter);
871 /* focus is set to an extra column with 0 width to hide focus, we draw it ourself */
872 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), COLLECT_TABLE_MAX_COLUMNS);
873 gtk_tree_view_set_cursor(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE);
874 gtk_tree_path_free(tpath);
878 static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gint relative)
885 new_row = ct->focus_row;
886 new_col = ct->focus_column;
889 if (new_row < 0) new_row = 0;
890 if (new_row >= ct->rows) new_row = ct->rows - 1;
910 new_col = ct->columns - 1;
917 if (new_col >= ct->columns)
919 if (new_row < ct->rows - 1)
926 new_col = ct->columns - 1;
936 if (new_row >= ct->rows)
939 new_row = ct->rows - 1;
942 new_col = ct->columns - 1;
944 if (new_col >= ct->columns) new_col = ct->columns - 1;
947 if (new_row == ct->rows - 1)
951 /* if we moved beyond the last image, go to the last image */
953 l = g_list_length(ct->cd->list);
954 if (ct->rows > 1) l -= (ct->rows - 1) * ct->columns;
955 if (new_col >= l) new_col = l - 1;
958 if (new_row == -1 || new_col == -1)
960 if (!ct->cd->list) return;
961 new_row = new_col = 0;
964 collection_table_set_focus(ct, collection_table_find_data(ct, new_row, new_col, NULL));
967 static void collection_table_update_focus(CollectTable *ct)
972 if (ct->focus_info && collection_table_find_position(ct, ct->focus_info, &new_row, &new_col))
974 /* first find the old focus, if it exists and is valid */
978 /* (try to) stay where we were */
979 new_row = ct->focus_row;
980 new_col = ct->focus_column;
983 collection_table_move_focus(ct, new_row, new_col, FALSE);
986 /* used to figure the page up/down distances */
987 static gint page_height(CollectTable *ct)
994 adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
995 page_size = (gint)adj->page_increment;
997 row_height = thumb_max_height + THUMB_BORDER_PADDING * 2;
998 if (ct->show_text) row_height += thumb_max_height / 3;
1000 ret = page_size / row_height;
1001 if (ret < 1) ret = 1;
1006 static void collection_table_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
1008 CollectTable *ct = data;
1009 GtkTreeModel *store;
1015 if (!collection_table_find_iter(ct, ct->click_info, &iter, &column)) return;
1016 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1017 tpath = gtk_tree_model_get_path(store, &iter);
1018 tree_view_get_cell_clamped(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE, x, y, &cw, &ch);
1019 gtk_tree_path_free(tpath);
1021 popup_menu_position_clamp(menu, x, y, 0);
1024 static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
1026 CollectTable *ct = data;
1027 gint stop_signal = FALSE;
1032 switch (event->keyval)
1034 case GDK_Left: case GDK_KP_Left:
1038 case GDK_Right: case GDK_KP_Right:
1042 case GDK_Up: case GDK_KP_Up:
1046 case GDK_Down: case GDK_KP_Down:
1050 case GDK_Page_Up: case GDK_KP_Page_Up:
1051 focus_row = -page_height(ct);
1054 case GDK_Page_Down: case GDK_KP_Page_Down:
1055 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;
1063 case GDK_End: case GDK_KP_End:
1064 focus_row = ct->rows - 1 - ct->focus_row;
1065 focus_col = ct->columns - 1 - ct->focus_column;
1069 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1072 ct->click_info = info;
1073 if (event->state & GDK_CONTROL_MASK)
1075 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1079 collection_table_unselect_all(ct);
1080 collection_table_select(ct, info);
1086 if (event->state & GDK_CONTROL_MASK) collection_table_toggle_filenames(ct);
1090 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1091 ct->click_info = info;
1093 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1096 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1097 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, collection_table_menu_pos_cb, ct, 0, GDK_CURRENT_TIME);
1104 if (focus_row != 0 || focus_col != 0)
1106 CollectInfo *new_info;
1107 CollectInfo *old_info;
1109 old_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1110 collection_table_move_focus(ct, focus_row, focus_col, TRUE);
1111 new_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1113 if (new_info != old_info)
1115 if (event->state & GDK_SHIFT_MASK)
1117 if (!collection_rectangular_selection)
1119 collection_table_select_region_util(ct, old_info, new_info, FALSE);
1123 collection_table_select_region_util(ct, ct->click_info, old_info, FALSE);
1125 collection_table_select_region_util(ct, ct->click_info, new_info, TRUE);
1127 else if (event->state & GDK_CONTROL_MASK)
1129 ct->click_info = new_info;
1133 ct->click_info = new_info;
1134 collection_table_unselect_all(ct);
1135 collection_table_select(ct, new_info);
1142 g_signal_stop_emission_by_name(GTK_OBJECT(widget), "key_press_event");
1150 *-------------------------------------------------------------------
1152 *-------------------------------------------------------------------
1155 static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gint *after, GdkRectangle *cell,
1156 gint use_coord, gint x, gint y)
1158 CollectInfo *info = NULL;
1159 GtkTreeModel *store;
1162 GtkTreeViewColumn *column;
1164 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1166 if (!use_coord) gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
1171 if (collection_table_find_iter(ct, source, &iter, &col))
1173 tpath = gtk_tree_model_get_path(store, &iter);
1174 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1175 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1176 gtk_tree_path_free(tpath);
1179 *after = (x > cell->x + (cell->width / 2));
1184 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
1185 &tpath, &column, NULL, NULL))
1190 gtk_tree_model_get_iter(store, &iter, tpath);
1191 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1193 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
1194 info = g_list_nth_data(list, n);
1198 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1199 *after = (x > cell->x + (cell->width / 2));
1202 gtk_tree_path_free(tpath);
1209 work = g_list_last(ct->cd->list);
1217 if (collection_table_find_iter(ct, info, &iter, &col))
1219 tpath = gtk_tree_model_get_path(store, &iter);
1220 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1221 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1222 gtk_tree_path_free(tpath);
1230 static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint y)
1236 info = collection_table_insert_find(ct, NULL, &after, &cell, TRUE, x, y);
1242 work = g_list_find(ct->cd->list, info);
1243 if (work && work->next)
1245 info = work->next->data;
1256 static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gint enable)
1264 if (ct->marker_window) gdk_window_destroy(ct->marker_window);
1265 ct->marker_window = NULL;
1270 info = collection_table_insert_find(ct, info, &after, &cell, FALSE, 0, 0);
1272 /* this setting does not take into account (after), but since it is not really used... */
1273 ct->marker_info = info;
1278 if (!ct->marker_window)
1281 GdkWindowAttr attributes;
1282 gint attributes_mask;
1288 parent = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(ct->listview));
1290 pb = gdk_pixbuf_new_from_xpm_data((const char **)marker_xpm);
1291 gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128);
1292 gdk_pixbuf_unref(pb);
1294 gdk_drawable_get_size(pixmap, &w, &h);
1296 attributes.window_type = GDK_WINDOW_CHILD;
1297 attributes.wclass = GDK_INPUT_OUTPUT;
1298 attributes.width = w;
1299 attributes.height = h;
1300 attributes.event_mask = gtk_widget_get_events(ct->listview);
1301 attributes_mask = 0;
1303 ct->marker_window = gdk_window_new(parent, &attributes, attributes_mask);
1304 gdk_window_set_back_pixmap(ct->marker_window, pixmap, FALSE);
1305 gdk_window_shape_combine_mask(ct->marker_window, mask, 0, 0);
1307 g_object_unref(pixmap);
1308 if (mask) g_object_unref(mask);
1316 gdk_drawable_get_size(ct->marker_window, &w, &h);
1324 x = cell.x + cell.width;
1327 y = cell.y + (cell.height / 2) - (h / 2);
1329 gdk_window_move(ct->marker_window, x, y);
1330 gdk_window_clear(ct->marker_window);
1331 if (!gdk_window_is_visible(ct->marker_window)) gdk_window_show(ct->marker_window);
1335 if (gdk_window_is_visible(ct->marker_window)) gdk_window_hide(ct->marker_window);
1340 *-------------------------------------------------------------------
1341 * mouse drag auto-scroll
1342 *-------------------------------------------------------------------
1345 static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gint drop_event)
1349 info = collection_table_find_data_by_coord(ct, x, y, NULL);
1354 collection_table_insert_marker(ct, info, TRUE);
1358 tip_update(ct, info);
1362 static gint collection_table_auto_scroll_idle_cb(gpointer data)
1364 CollectTable *ct = data;
1369 if (ct->drop_idle_id == -1) return FALSE;
1371 window = ct->listview->window;
1372 gdk_window_get_pointer(window, &x, &y, NULL);
1373 gdk_drawable_get_size(window, &w, &h);
1374 if (x >= 0 && x < w && y >= 0 && y < h)
1376 collection_table_motion_update(ct, x, y, TRUE);
1379 ct->drop_idle_id = -1;
1383 static gint collection_table_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data)
1385 CollectTable *ct = data;
1387 if (ct->drop_idle_id == -1) ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
1392 static void collection_table_scroll(CollectTable *ct, gint scroll)
1396 if (ct->drop_idle_id != -1)
1398 g_source_remove(ct->drop_idle_id);
1399 ct->drop_idle_id = -1;
1401 widget_auto_scroll_stop(ct->listview);
1402 collection_table_insert_marker(ct, NULL, FALSE);
1406 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
1407 widget_auto_scroll_start(ct->listview, adj, -1, thumb_max_height / 2,
1408 collection_table_auto_scroll_notify_cb, ct);
1413 *-------------------------------------------------------------------
1415 *-------------------------------------------------------------------
1418 static gint collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1420 CollectTable *ct = data;
1422 collection_table_motion_update(ct, (gint)bevent->x, (gint)bevent->y, FALSE);
1427 static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1429 CollectTable *ct = data;
1435 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1437 ct->click_info = info;
1438 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, &iter);
1440 switch (bevent->button)
1443 if (bevent->type == GDK_2BUTTON_PRESS)
1447 layout_image_set_collection(NULL, ct->cd, info);
1450 else if (!GTK_WIDGET_HAS_FOCUS(ct->listview))
1452 gtk_widget_grab_focus(ct->listview);
1456 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1457 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
1466 static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1468 CollectTable *ct = data;
1470 CollectInfo *info = NULL;
1474 if ((gint)bevent->x != 0 || (gint) bevent->y != 0)
1476 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1481 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1484 if (bevent->button == 1 &&
1485 info && ct->click_info == info)
1487 collection_table_set_focus(ct, info);
1489 if (bevent->state & GDK_CONTROL_MASK)
1493 select = !INFO_SELECTED(info);
1494 if ((bevent->state & GDK_SHIFT_MASK) && ct->prev_selection)
1496 collection_table_select_region_util(ct, ct->prev_selection, info, select);
1500 collection_table_select_util(ct, info, select);
1505 collection_table_unselect_all(ct);
1507 if ((bevent->state & GDK_SHIFT_MASK) &&
1510 collection_table_select_region_util(ct, ct->prev_selection, info, TRUE);
1514 collection_table_select_util(ct, info, TRUE);
1518 else if (bevent->button == 2 &&
1519 info && ct->click_info == info)
1521 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1527 static gint collection_table_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
1529 CollectTable *ct = data;
1536 *-------------------------------------------------------------------
1537 * populate, add, insert, etc.
1538 *-------------------------------------------------------------------
1541 static gboolean collection_table_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data)
1545 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
1551 static void collection_table_clear_store(CollectTable *ct)
1553 GtkTreeModel *store;
1555 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1556 gtk_tree_model_foreach(store, collection_table_destroy_node_cb, NULL);
1558 gtk_list_store_clear(GTK_LIST_STORE(store));
1561 static GList *collection_table_add_row(CollectTable *ct, GtkTreeIter *iter)
1563 GtkListStore *store;
1567 for (i = 0; i < ct->columns; i++) list = g_list_prepend(list, NULL);
1569 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)));
1570 gtk_list_store_append(store, iter);
1571 gtk_list_store_set(store, iter, CTABLE_COLUMN_POINTER, list, -1);
1576 static void collection_table_populate(CollectTable *ct, gint resize)
1581 collection_table_verify_selections(ct);
1583 collection_table_clear_store(ct);
1590 thumb_width = collection_table_get_icon_width(ct);
1592 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
1594 GtkTreeViewColumn *column;
1595 GtkCellRenderer *cell;
1598 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), i);
1599 gtk_tree_view_column_set_visible(column, (i < ct->columns));
1600 gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6));
1602 list = gtk_tree_view_column_get_cell_renderers(column);
1603 cell = (list) ? list->data : NULL;
1606 if (cell && GQV_IS_CELL_RENDERER_ICON(cell))
1608 g_object_set(G_OBJECT(cell), "fixed_width", thumb_width,
1609 "fixed_height", thumb_max_height,
1610 "show_text", ct->show_text, NULL);
1613 if (GTK_WIDGET_REALIZED(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
1617 work = ct->cd->list;
1625 list = collection_table_add_row(ct, &iter);
1626 while (work && list)
1628 list->data = work->data;
1636 collection_table_update_focus(ct);
1637 collection_table_update_status(ct);
1640 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force)
1645 thumb_width = collection_table_get_icon_width(ct);
1647 new_cols = w / (thumb_width + (THUMB_BORDER_PADDING * 6));
1648 if (new_cols < 1) new_cols = 1;
1650 if (!force && new_cols == ct->columns) return;
1652 ct->columns = new_cols;
1654 collection_table_populate(ct, TRUE);
1656 if (debug) printf("col tab pop cols=%d rows=%d\n", ct->columns, ct->rows);
1659 static void collection_table_sync(CollectTable *ct)
1661 GtkTreeModel *store;
1666 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1671 work = ct->cd->list;
1677 if (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1679 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1680 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1684 list = collection_table_add_row(ct, &iter);
1709 while (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1713 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1714 gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
1720 collection_table_update_focus(ct);
1721 collection_table_update_status(ct);
1724 static gint collection_table_sync_idle_cb(gpointer data)
1726 CollectTable *ct = data;
1728 if (ct->sync_idle_id == -1) return FALSE;
1729 ct->sync_idle_id = -1;
1731 collection_table_sync(ct);
1735 static void collection_table_sync_idle(CollectTable *ct)
1737 if (ct->sync_idle_id == -1)
1739 /* high priority, the view needs to be resynced before a redraw
1740 * may contain invalid pointers at this time
1742 ct->sync_idle_id = g_idle_add_full(G_PRIORITY_HIGH, collection_table_sync_idle_cb, ct, NULL);
1746 void collection_table_add_path_list(CollectTable *ct, GList *list)
1755 collection_add(ct->cd, (gchar *)work->data, FALSE);
1760 static void collection_table_insert_path_list(CollectTable *ct, GList *list, CollectInfo *insert_info)
1769 collection_insert(ct->cd, (gchar *)work->data, insert_info, FALSE);
1773 collection_table_sync_idle(ct);
1776 static void collection_table_move_by_info_list(CollectTable *ct, GList *info_list, gint row, gint col)
1779 GList *insert_pos = NULL;
1783 if (!info_list) return;
1785 info = collection_table_find_data(ct, row, col, NULL);
1787 if (!info_list->next && info_list->data == info) return;
1789 if (info) insert_pos = g_list_find(ct->cd->list, info);
1791 /* FIXME: this may get slow for large lists */
1793 while (insert_pos && work)
1795 if (insert_pos->data == work->data)
1797 insert_pos = insert_pos->next;
1809 ct->cd->list = g_list_remove(ct->cd->list, work->data);
1813 /* place them back in */
1814 temp = g_list_copy(info_list);
1818 ct->cd->list = uig_list_insert_list(ct->cd->list, insert_pos, temp);
1822 ct->cd->list = g_list_concat(temp, ct->cd->list);
1826 ct->cd->list = g_list_concat(ct->cd->list, temp);
1829 ct->cd->changed = TRUE;
1831 collection_table_sync_idle(ct);
1836 *-------------------------------------------------------------------
1838 *-------------------------------------------------------------------
1841 void collection_table_file_update(CollectTable *ct, CollectInfo *info)
1849 collection_table_update_extras(ct, FALSE, 0.0);
1853 if (!collection_table_find_position(ct, info, &row, &col)) return;
1855 if (ct->columns != 0 && ct->rows != 0)
1857 value = (gdouble)(row * ct->columns + col) / (ct->columns * ct->rows);
1864 collection_table_update_extras(ct, TRUE, value);
1866 if (collection_table_find_iter(ct, info, &iter, NULL))
1868 GtkTreeModel *store;
1871 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1872 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1873 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1877 void collection_table_file_add(CollectTable *ct, CollectInfo *info)
1879 collection_table_sync_idle(ct);
1882 void collection_table_file_insert(CollectTable *ct, CollectInfo *ci)
1884 collection_table_sync_idle(ct);
1887 void collection_table_file_remove(CollectTable *ct, CollectInfo *ci)
1889 if (ci && INFO_SELECTED(ci))
1891 ct->selection = g_list_remove(ct->selection, ci);
1894 collection_table_sync_idle(ct);
1897 void collection_table_refresh(CollectTable *ct)
1899 collection_table_populate(ct, FALSE);
1903 *-------------------------------------------------------------------
1905 *-------------------------------------------------------------------
1908 static void collection_table_add_dir_recursive(CollectTable *ct, gchar *path, gint recursive)
1913 if (path_list(path, &f, recursive ? &d : NULL))
1917 f = path_list_filter(f, FALSE);
1918 d = path_list_filter(d, TRUE);
1920 f = path_list_sort(f);
1921 d = path_list_sort(d);
1923 collection_table_insert_path_list(ct, f, ct->marker_info);
1925 work = g_list_last(d);
1928 collection_table_add_dir_recursive(ct, (gchar *)work->data, TRUE);
1936 static void confirm_dir_list_do(CollectTable *ct, GList *list, gint recursive)
1941 gchar *path = work->data;
1943 if (isdir(path)) collection_table_add_dir_recursive(ct, path, recursive);
1945 collection_table_insert_path_list(ct, list, ct->marker_info);
1949 static void confirm_dir_list_add(GtkWidget *widget, gpointer data)
1951 CollectTable *ct = data;
1953 confirm_dir_list_do(ct, ct->drop_list, FALSE);
1956 static void confirm_dir_list_recurse(GtkWidget *widget, gpointer data)
1958 CollectTable *ct = data;
1960 confirm_dir_list_do(ct, ct->drop_list, TRUE);
1963 static void confirm_dir_list_skip(GtkWidget *widget, gpointer data)
1965 CollectTable *ct = data;
1967 collection_table_insert_path_list(ct, ct->drop_list, ct->marker_info);
1970 static GtkWidget *collection_table_drop_menu(CollectTable *ct)
1974 menu = popup_menu_short_lived();
1975 g_signal_connect(G_OBJECT(menu), "destroy",
1976 G_CALLBACK(collection_table_popup_destroy_cb), ct);
1978 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL);
1979 menu_item_add_divider(menu);
1980 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK,
1981 G_CALLBACK(confirm_dir_list_add), ct);
1982 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD,
1983 G_CALLBACK(confirm_dir_list_recurse), ct);
1984 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE,
1985 G_CALLBACK(confirm_dir_list_skip), ct);
1986 menu_item_add_divider(menu);
1987 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, ct);
1993 *-------------------------------------------------------------------
1995 *-------------------------------------------------------------------
1998 static GtkTargetEntry collection_drag_types[] = {
1999 { "application/x-gqview-collection-member", 0, TARGET_APP_COLLECTION_MEMBER },
2000 { "text/uri-list", 0, TARGET_URI_LIST },
2001 { "text/plain", 0, TARGET_TEXT_PLAIN }
2003 static gint n_collection_drag_types = 3;
2005 static GtkTargetEntry collection_drop_types[] = {
2006 { "application/x-gqview-collection-member", 0, TARGET_APP_COLLECTION_MEMBER },
2007 { "text/uri-list", 0, TARGET_URI_LIST }
2009 static gint n_collection_drop_types = 2;
2012 static void collection_table_dnd_get(GtkWidget *widget, GdkDragContext *context,
2013 GtkSelectionData *selection_data, guint info,
2014 guint time, gpointer data)
2016 CollectTable *ct = data;
2019 gchar *uri_text = NULL;
2022 if (!ct->click_info) return;
2024 selected = INFO_SELECTED(ct->click_info);
2028 case TARGET_APP_COLLECTION_MEMBER:
2031 uri_text = collection_info_list_to_dnd_data(ct->cd, ct->selection, &total);
2035 list = g_list_append(NULL, ct->click_info);
2036 uri_text = collection_info_list_to_dnd_data(ct->cd, list, &total);
2040 case TARGET_URI_LIST:
2041 case TARGET_TEXT_PLAIN:
2045 list = collection_table_selection_get_list(ct);
2049 const gchar *path = ct->click_info->path;
2051 list = g_list_append(NULL, g_strdup(path));
2055 uri_text = uri_text_from_list(list, &total, (info == TARGET_TEXT_PLAIN));
2056 path_list_free(list);
2060 gtk_selection_data_set(selection_data, selection_data->target,
2061 8, (guchar *)uri_text, total);
2066 static void collection_table_dnd_receive(GtkWidget *widget, GdkDragContext *context,
2068 GtkSelectionData *selection_data, guint info,
2069 guint time, gpointer data)
2071 CollectTable *ct = data;
2073 GList *info_list = NULL;
2074 CollectionData *source;
2075 CollectInfo *drop_info;
2078 if (debug) printf("%s\n", selection_data->data);
2080 collection_table_scroll(ct, FALSE);
2081 collection_table_insert_marker(ct, NULL, FALSE);
2083 drop_info = collection_table_insert_point(ct, x, y);
2087 case TARGET_APP_COLLECTION_MEMBER:
2088 source = collection_from_dnd_data((gchar *)selection_data->data, &list, &info_list);
2091 if (source == ct->cd)
2096 /* it is a move within a collection */
2097 path_list_free(list);
2102 collection_table_move_by_info_list(ct, info_list, -1, -1);
2104 else if (collection_table_find_position(ct, drop_info, &row, &col))
2106 collection_table_move_by_info_list(ct, info_list, row, col);
2111 /* it is a move/copy across collections */
2112 if (context->action == GDK_ACTION_MOVE)
2114 collection_remove_by_info_list(source, info_list);
2117 g_list_free(info_list);
2120 case TARGET_URI_LIST:
2121 list = uri_list_from_text((gchar *)selection_data->data, TRUE);
2125 if (isdir((gchar *)work->data))
2129 ct->drop_list = list;
2130 ct->drop_info = drop_info;
2131 menu = collection_table_drop_menu(ct);
2132 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time);
2145 collection_table_insert_path_list(ct, list, drop_info);
2146 path_list_free(list);
2150 static void collection_table_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
2152 CollectTable *ct = data;
2154 if (ct->click_info && ct->click_info->pixbuf)
2158 if (INFO_SELECTED(ct->click_info))
2159 items = g_list_length(ct->selection);
2162 dnd_set_drag_icon(widget, context, ct->click_info->pixbuf, items);
2166 static void collection_table_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
2168 CollectTable *ct = data;
2170 /* apparently a leave event is not generated on a drop */
2173 collection_table_scroll(ct, FALSE);
2176 static gint collection_table_dnd_motion(GtkWidget *widget, GdkDragContext *context,
2177 gint x, gint y, guint time, gpointer data)
2179 CollectTable *ct = data;
2181 collection_table_motion_update(ct, x, y, TRUE);
2182 collection_table_scroll(ct, TRUE);
2187 static void collection_table_dnd_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data)
2189 CollectTable *ct = data;
2191 collection_table_scroll(ct, FALSE);
2194 static void collection_table_dnd_init(CollectTable *ct)
2196 gtk_drag_source_set(ct->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
2197 collection_drag_types, n_collection_drag_types,
2198 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
2199 g_signal_connect(G_OBJECT(ct->listview), "drag_data_get",
2200 G_CALLBACK(collection_table_dnd_get), ct);
2201 g_signal_connect(G_OBJECT(ct->listview), "drag_begin",
2202 G_CALLBACK(collection_table_dnd_begin), ct);
2203 g_signal_connect(G_OBJECT(ct->listview), "drag_end",
2204 G_CALLBACK(collection_table_dnd_end), ct);
2206 gtk_drag_dest_set(ct->listview,
2207 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
2208 collection_drop_types, n_collection_drop_types,
2209 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK);
2210 g_signal_connect(G_OBJECT(ct->listview), "drag_motion",
2211 G_CALLBACK(collection_table_dnd_motion), ct);
2212 g_signal_connect(G_OBJECT(ct->listview), "drag_leave",
2213 G_CALLBACK(collection_table_dnd_leave), ct);
2214 g_signal_connect(G_OBJECT(ct->listview), "drag_data_received",
2215 G_CALLBACK(collection_table_dnd_receive), ct);
2219 *-----------------------------------------------------------------------------
2221 *-----------------------------------------------------------------------------
2224 typedef struct _ColumnData ColumnData;
2231 static void collection_table_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
2232 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
2234 ColumnData *cd = data;
2244 gtk_tree_model_get(tree_model, iter, CTABLE_COLUMN_POINTER, &list, -1);
2245 info = g_list_nth_data(list, cd->number);
2247 style = gtk_widget_get_style(ct->listview);
2248 if (info && (info->flag_mask & SELECTION_SELECTED) )
2250 memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg));
2251 memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg));
2255 memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg));
2256 memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg));
2259 if (info && (info->flag_mask & SELECTION_PRELIGHT))
2262 shift_color(&color_fg, -1, 0);
2264 shift_color(&color_bg, -1, 0);
2267 if (GQV_IS_CELL_RENDERER_ICON(cell))
2271 g_object_set(cell, "pixbuf", info->pixbuf,
2272 "text", filename_from_path(info->path),
2273 "cell-background-gdk", &color_bg,
2274 "cell-background-set", TRUE,
2275 "foreground-gdk", &color_fg,
2276 "foreground-set", TRUE,
2277 "has-focus", (ct->focus_info == info), NULL);
2281 g_object_set(cell, "pixbuf", NULL,
2283 "cell-background-set", FALSE,
2284 "foreground-set", FALSE,
2285 "has-focus", FALSE, NULL);
2290 static void collection_table_append_column(CollectTable *ct, gint n)
2293 GtkTreeViewColumn *column;
2294 GtkCellRenderer *renderer;
2296 column = gtk_tree_view_column_new();
2297 gtk_tree_view_column_set_min_width(column, 0);
2299 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
2300 gtk_tree_view_column_set_alignment(column, 0.5);
2302 renderer = gqv_cell_renderer_icon_new();
2303 gtk_tree_view_column_pack_start(column, renderer, FALSE);
2304 g_object_set(G_OBJECT(renderer), "xpad", THUMB_BORDER_PADDING * 2,
2305 "ypad", THUMB_BORDER_PADDING,
2306 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
2308 g_object_set_data(G_OBJECT(column), "column_number", GINT_TO_POINTER(n));
2310 cd = g_new0(ColumnData, 1);
2313 gtk_tree_view_column_set_cell_data_func(column, renderer, collection_table_cell_data_cb, cd, g_free);
2315 gtk_tree_view_append_column(GTK_TREE_VIEW(ct->listview), column);
2319 *-------------------------------------------------------------------
2321 *-------------------------------------------------------------------
2324 static void collection_table_destroy(GtkWidget *widget, gpointer data)
2326 CollectTable *ct = data;
2330 g_signal_handlers_disconnect_matched(GTK_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA,
2332 gtk_widget_destroy(ct->popup);
2335 if (ct->sync_idle_id != -1) g_source_remove(ct->sync_idle_id);
2338 collection_table_scroll(ct, FALSE);
2343 static void collection_table_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
2345 CollectTable *ct = data;
2347 collection_table_populate_at_new_size(ct, allocation->width, allocation->height, FALSE);
2350 CollectTable *collection_table_new(CollectionData *cd)
2353 GtkListStore *store;
2354 GtkTreeSelection *selection;
2357 ct = g_new0(CollectTable, 1);
2362 ct->selection = NULL;
2363 ct->prev_selection = NULL;
2365 ct->tip_window = NULL;
2366 ct->tip_delay_id = -1;
2368 ct->marker_window = NULL;
2369 ct->marker_info = NULL;
2371 ct->status_label = NULL;
2372 ct->extra_label = NULL;
2375 ct->focus_column = 0;
2376 ct->focus_info = NULL;
2378 ct->show_text = show_icon_names;
2380 ct->sync_idle_id = -1;
2381 ct->drop_idle_id = -1;
2384 ct->drop_info = NULL;
2385 ct->drop_list = NULL;
2387 ct->scrolled = gtk_scrolled_window_new(NULL, NULL);
2388 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN);
2389 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ct->scrolled),
2390 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2392 store = gtk_list_store_new(1, G_TYPE_POINTER);
2393 ct->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
2394 g_object_unref(store);
2396 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ct->listview));
2397 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_NONE);
2399 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ct->listview), FALSE);
2400 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ct->listview), FALSE);
2402 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
2404 collection_table_append_column(ct, i);
2407 /* zero width column to hide tree view focus, we draw it ourselves */
2408 collection_table_append_column(ct, i);
2409 /* end column to fill white space */
2410 collection_table_append_column(ct, i);
2412 g_signal_connect(G_OBJECT(ct->listview), "destroy",
2413 G_CALLBACK(collection_table_destroy), ct);
2414 g_signal_connect(G_OBJECT(ct->listview), "size_allocate",
2415 G_CALLBACK(collection_table_sized), ct);
2416 g_signal_connect(G_OBJECT(ct->listview), "key_press_event",
2417 G_CALLBACK(collection_table_press_key_cb), ct);
2419 gtk_container_add(GTK_CONTAINER(ct->scrolled), ct->listview);
2420 gtk_widget_show(ct->listview);
2422 collection_table_dnd_init(ct);
2424 gtk_widget_set_events(ct->listview, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK |
2425 GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK);
2426 g_signal_connect(G_OBJECT(ct->listview),"button_press_event",
2427 G_CALLBACK(collection_table_press_cb), ct);
2428 g_signal_connect(G_OBJECT(ct->listview),"button_release_event",
2429 G_CALLBACK(collection_table_release_cb), ct);
2430 g_signal_connect(G_OBJECT(ct->listview),"motion_notify_event",
2431 G_CALLBACK(collection_table_motion_cb), ct);
2432 g_signal_connect(G_OBJECT(ct->listview), "leave_notify_event",
2433 G_CALLBACK(collection_table_leave_cb), ct);
2438 void collection_table_set_labels(CollectTable *ct, GtkWidget *status, GtkWidget *extra)
2440 ct->status_label = status;
2441 ct->extra_label = extra;
2442 collection_table_update_status(ct);
2443 collection_table_update_extras(ct, FALSE, 0.0);
2446 CollectInfo *collection_table_get_focus_info(CollectTable *ct)
2448 return collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);