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
49 #define COLLECT_TABLE_TIP_DELAY_PATH (COLLECT_TABLE_TIP_DELAY * 1.7)
53 CTABLE_COLUMN_POINTER = 0,
59 SELECTION_SELECTED = 1 << 0,
60 SELECTION_PRELIGHT = 1 << 1,
61 SELECTION_FOCUS = 1 << 2
65 #define INFO_SELECTED(x) (x->flag_mask & SELECTION_SELECTED)
68 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force);
72 *-------------------------------------------------------------------
74 *-------------------------------------------------------------------
77 static gint collection_table_find_position(CollectTable *ct, CollectInfo *info, gint *row, gint *col)
81 n = g_list_index(ct->cd->list, info);
83 if (n < 0) return FALSE;
85 *row = n / ct->columns;
86 *col = n - (*row * ct->columns);
91 static gint collection_table_find_iter(CollectTable *ct, CollectInfo *info, GtkTreeIter *iter, gint *column)
96 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
97 if (!collection_table_find_position(ct, info, &row, &col)) return FALSE;
98 if (!gtk_tree_model_iter_nth_child(store, iter, NULL, row)) return FALSE;
99 if (column) *column = col;
104 static CollectInfo *collection_table_find_data(CollectTable *ct, gint row, gint col, GtkTreeIter *iter)
109 if (row < 0 || col < 0) return NULL;
111 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
112 if (gtk_tree_model_iter_nth_child(store, &p, NULL, row))
116 gtk_tree_model_get(store, &p, CTABLE_COLUMN_POINTER, &list, -1);
117 if (!list) return NULL;
121 return g_list_nth_data(list, col);
127 static CollectInfo *collection_table_find_data_by_coord(CollectTable *ct, gint x, gint y, GtkTreeIter *iter)
130 GtkTreeViewColumn *column;
132 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
133 &tpath, &column, NULL, NULL))
140 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
141 gtk_tree_model_get_iter(store, &row, tpath);
142 gtk_tree_path_free(tpath);
144 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
146 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
149 if (iter) *iter = row;
150 return g_list_nth_data(list, n);
157 static void collection_table_update_status(CollectTable *ct)
159 if (ct->status_label)
165 buf = g_strdup(_("Empty"));
167 else if (ct->selection)
169 buf = g_strdup_printf(_("%d images (%d)"), g_list_length(ct->cd->list), g_list_length(ct->selection));
173 buf = g_strdup_printf(_("%d images"), g_list_length(ct->cd->list));
176 gtk_label_set_text(GTK_LABEL(ct->status_label), buf);
181 static void collection_table_update_extras(CollectTable *ct, gint loading, gdouble value)
187 text = _("Loading thumbs...");
191 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ct->extra_label), value);
192 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ct->extra_label), text);
196 static void collection_table_toggle_filenames(CollectTable *ct)
198 ct->show_text = !ct->show_text;
199 show_icon_names = ct->show_text;
201 collection_table_populate_at_new_size(ct, ct->listview->allocation.width, ct->listview->allocation.height, TRUE);
204 static gint collection_table_get_icon_width(CollectTable *ct)
208 if (!ct->show_text) return thumb_max_width;
210 width = thumb_max_width + thumb_max_width / 2;
211 if (width < THUMB_MIN_ICON_WIDTH) width = THUMB_MIN_ICON_WIDTH;
212 if (width > THUMB_MAX_ICON_WIDTH) width = thumb_max_width;
218 *-------------------------------------------------------------------
220 *-------------------------------------------------------------------
223 static void collection_table_selection_set(CollectTable *ct, CollectInfo *info, SelectionType value, GtkTreeIter *iter)
230 if (info->flag_mask == value) return;
231 info->flag_mask = value;
233 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
236 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
237 if (list) gtk_list_store_set(GTK_LIST_STORE(store), iter, CTABLE_COLUMN_POINTER, list, -1);
243 if (collection_table_find_iter(ct, info, &row, NULL))
245 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
246 if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, CTABLE_COLUMN_POINTER, list, -1);
251 static void collection_table_selection_add(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
255 collection_table_selection_set(ct, info, info->flag_mask | mask, iter);
258 static void collection_table_selection_remove(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
262 collection_table_selection_set(ct, info, info->flag_mask & ~mask, iter);
265 *-------------------------------------------------------------------
267 *-------------------------------------------------------------------
270 static void collection_table_verify_selections(CollectTable *ct)
274 work = ct->selection;
277 CollectInfo *info = work->data;
279 if (!g_list_find(ct->cd->list, info))
281 ct->selection = g_list_remove(ct->selection, info);
286 void collection_table_select_all(CollectTable *ct)
290 g_list_free(ct->selection);
291 ct->selection = NULL;
296 ct->selection = g_list_append(ct->selection, work->data);
297 collection_table_selection_add(ct, work->data, SELECTION_SELECTED, NULL);
301 collection_table_update_status(ct);
304 void collection_table_unselect_all(CollectTable *ct)
308 work = ct->selection;
311 collection_table_selection_remove(ct, work->data, SELECTION_SELECTED, NULL);
315 g_list_free(ct->selection);
316 ct->selection = NULL;
318 collection_table_update_status(ct);
321 static void collection_table_select(CollectTable *ct, CollectInfo *info)
323 ct->prev_selection = info;
325 if (!info || INFO_SELECTED(info)) return;
327 ct->selection = g_list_append(ct->selection, info);
328 collection_table_selection_add(ct, info, SELECTION_SELECTED, NULL);
330 collection_table_update_status(ct);
333 static void collection_table_unselect(CollectTable *ct, CollectInfo *info)
335 ct->prev_selection = info;
337 if (!info || !INFO_SELECTED(info) ) return;
339 ct->selection = g_list_remove(ct->selection, info);
340 collection_table_selection_remove(ct, info, SELECTION_SELECTED, NULL);
342 collection_table_update_status(ct);
345 static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gint select)
349 collection_table_select(ct, info);
353 collection_table_unselect(ct, info);
357 static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gint select)
364 if (!collection_table_find_position(ct, start, &row1, &col1) ||
365 !collection_table_find_position(ct, end, &row2, &col2) ) return;
367 ct->prev_selection = end;
369 if (!collection_rectangular_selection)
374 if (g_list_index(ct->cd->list, start) > g_list_index(ct->cd->list, end))
381 work = g_list_find(ct->cd->list, start);
385 collection_table_select_util(ct, info, select);
387 if (work->data != end)
408 if (debug) printf("table: %d x %d to %d x %d\n", row1, col1, row2, col2);
410 for (i = row1; i <= row2; i++)
412 for (j = col1; j <= col2; j++)
414 CollectInfo *info = collection_table_find_data(ct, i, j, NULL);
415 if (info) collection_table_select_util(ct, info, select);
420 GList *collection_table_selection_get_list(CollectTable *ct)
422 return collection_list_to_filelist(ct->selection);
425 static GList *collection_table_get_list(CollectTable *ct)
427 return collection_list_to_filelist(ct->cd->list);
431 *-------------------------------------------------------------------
432 * tooltip type window
433 *-------------------------------------------------------------------
436 static void tip_show(CollectTable *ct)
441 if (ct->tip_window) return;
443 gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
445 ct->tip_info = collection_table_find_data_by_coord(ct, x, y, NULL);
446 if (!ct->tip_info) return;
448 ct->tip_window = gtk_window_new(GTK_WINDOW_POPUP);
449 gtk_window_set_resizable(GTK_WINDOW(ct->tip_window), FALSE);
450 gtk_container_set_border_width(GTK_CONTAINER(ct->tip_window), 2);
452 label = gtk_label_new(ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
454 g_object_set_data(G_OBJECT(ct->tip_window), "tip_label", label);
455 gtk_container_add(GTK_CONTAINER(ct->tip_window), label);
456 gtk_widget_show(label);
458 gdk_window_get_pointer(NULL, &x, &y, NULL);
460 if (!GTK_WIDGET_REALIZED(ct->tip_window)) gtk_widget_realize(ct->tip_window);
461 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
462 gtk_widget_show(ct->tip_window);
465 static void tip_hide(CollectTable *ct)
467 if (ct->tip_window) gtk_widget_destroy(ct->tip_window);
468 ct->tip_window = NULL;
471 static gint tip_schedule_cb(gpointer data)
473 CollectTable *ct = data;
475 if (ct->tip_delay_id == -1) return FALSE;
479 ct->tip_delay_id = -1;
483 static void tip_schedule(CollectTable *ct)
487 if (ct->tip_delay_id != -1)
489 g_source_remove(ct->tip_delay_id);
490 ct->tip_delay_id = -1;
493 ct->tip_delay_id = g_timeout_add(ct->show_text ? COLLECT_TABLE_TIP_DELAY_PATH : COLLECT_TABLE_TIP_DELAY, tip_schedule_cb, ct);
496 static void tip_unschedule(CollectTable *ct)
500 if (ct->tip_delay_id != -1) g_source_remove(ct->tip_delay_id);
501 ct->tip_delay_id = -1;
504 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)
526 label = g_object_get_data(G_OBJECT(ct->tip_window), "tip_label");
527 gtk_label_set_text(GTK_LABEL(label), ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
533 *-------------------------------------------------------------------
535 *-------------------------------------------------------------------
538 static void collection_table_popup_save_as_cb(GtkWidget *widget, gpointer data)
540 CollectTable *ct = data;
542 collection_dialog_save_as(NULL, ct->cd);
545 static void collection_table_popup_save_cb(GtkWidget *widget, gpointer data)
547 CollectTable *ct = data;
551 collection_table_popup_save_as_cb(widget, data);
555 if (!collection_save(ct->cd, ct->cd->path))
557 printf("failed saving to collection path: %s\n", ct->cd->path);
561 static GList *collection_table_popup_file_list(CollectTable *ct)
563 if (!ct->click_info) return NULL;
565 if (INFO_SELECTED(ct->click_info))
567 return collection_table_selection_get_list(ct);
570 return g_list_append(NULL, g_strdup(ct->click_info->fd->path));
573 static void collection_table_popup_edit_cb(GtkWidget *widget, gpointer data)
579 ct = submenu_item_get_data(widget);
582 n = GPOINTER_TO_INT(data);
584 list = collection_table_popup_file_list(ct);
587 start_editor_from_filelist(n, list);
592 static void collection_table_popup_info_cb(GtkWidget *widget, gpointer data)
594 CollectTable *ct = data;
596 info_window_new(NULL, collection_table_popup_file_list(ct));
599 static void collection_table_popup_copy_cb(GtkWidget *widget, gpointer data)
601 CollectTable *ct = data;
603 file_util_copy(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);
606 static void collection_table_popup_move_cb(GtkWidget *widget, gpointer data)
608 CollectTable *ct = data;
610 file_util_move(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);
613 static void collection_table_popup_rename_cb(GtkWidget *widget, gpointer data)
615 CollectTable *ct = data;
617 file_util_rename(NULL, collection_table_popup_file_list(ct), ct->listview);
620 static void collection_table_popup_delete_cb(GtkWidget *widget, gpointer data)
622 CollectTable *ct = data;
624 file_util_delete(NULL, collection_table_popup_file_list(ct), ct->listview);
627 static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data)
632 ct = submenu_item_get_data(widget);
636 type = (SortType)GPOINTER_TO_INT(data);
638 collection_set_sort_method(ct->cd, type);
641 static void collection_table_popup_view_new_cb(GtkWidget *widget, gpointer data)
643 CollectTable *ct = data;
645 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
647 view_window_new_from_collection(ct->cd, ct->click_info);
651 static void collection_table_popup_view_cb(GtkWidget *widget, gpointer data)
653 CollectTable *ct = data;
655 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
657 layout_image_set_collection(NULL, ct->cd, ct->click_info);
661 static void collection_table_popup_selectall_cb(GtkWidget *widget, gpointer data)
663 CollectTable *ct = data;
665 collection_table_select_all(ct);
666 ct->prev_selection= ct->click_info;
669 static void collection_table_popup_unselectall_cb(GtkWidget *widget, gpointer data)
671 CollectTable *ct = data;
673 collection_table_unselect_all(ct);
674 ct->prev_selection= ct->click_info;
677 static void collection_table_popup_remove_cb(GtkWidget *widget, gpointer data)
679 CollectTable *ct = data;
682 if (!ct->click_info) return;
684 if (INFO_SELECTED(ct->click_info))
686 list = g_list_copy(ct->selection);
690 list = g_list_append(NULL, ct->click_info);
693 collection_remove_by_info_list(ct->cd, list);
697 static void collection_table_popup_add_filelist_cb(GtkWidget *widget, gpointer data)
699 CollectTable *ct = data;
702 list = layout_list(NULL);
706 collection_table_add_filelist(ct, list);
711 static void collection_table_popup_add_collection_cb(GtkWidget *widget, gpointer data)
713 CollectTable *ct = data;
715 collection_dialog_append(NULL, ct->cd);
718 static void collection_table_popup_find_dupes_cb(GtkWidget *widget, gpointer data)
720 CollectTable *ct = data;
723 dw = dupe_window_new(DUPE_MATCH_NAME);
724 dupe_window_add_collection(dw, ct->cd);
727 static void collection_table_popup_print_cb(GtkWidget *widget, gpointer data)
729 CollectTable *ct = data;
732 fd = (ct->click_info) ? ct->click_info->fd : NULL;
734 print_window_new(fd, collection_table_selection_get_list(ct), collection_table_get_list(ct), ct->listview);
737 static void collection_table_popup_show_names_cb(GtkWidget *widget, gpointer data)
739 CollectTable *ct = data;
741 collection_table_toggle_filenames(ct);
744 static void collection_table_popup_destroy_cb(GtkWidget *widget, gpointer data)
746 CollectTable *ct = data;
748 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
749 ct->click_info = NULL;
752 path_list_free(ct->drop_list);
753 ct->drop_list = NULL;
754 ct->drop_info = NULL;
757 static GtkWidget *collection_table_popup_menu(CollectTable *ct, gint over_icon)
762 menu = popup_menu_short_lived();
764 g_signal_connect(G_OBJECT(menu), "destroy",
765 G_CALLBACK(collection_table_popup_destroy_cb), ct);
767 menu_item_add_sensitive(menu, _("_View"), over_icon,
768 G_CALLBACK(collection_table_popup_view_cb), ct);
769 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, over_icon,
770 G_CALLBACK(collection_table_popup_view_new_cb), ct);
771 menu_item_add_divider(menu);
772 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, over_icon,
773 G_CALLBACK(collection_table_popup_remove_cb), ct);
775 menu_item_add_stock(menu, _("Append from file list"), GTK_STOCK_ADD,
776 G_CALLBACK(collection_table_popup_add_filelist_cb), ct);
777 menu_item_add_stock(menu, _("Append from collection..."), GTK_STOCK_OPEN,
778 G_CALLBACK(collection_table_popup_add_collection_cb), ct);
779 menu_item_add_divider(menu);
780 menu_item_add(menu, _("Select all"),
781 G_CALLBACK(collection_table_popup_selectall_cb), ct);
782 menu_item_add(menu, _("Select none"),
783 G_CALLBACK(collection_table_popup_unselectall_cb), ct);
784 menu_item_add_divider(menu);
786 submenu_add_edit(menu, &item,
787 G_CALLBACK(collection_table_popup_edit_cb), ct);
788 gtk_widget_set_sensitive(item, over_icon);
790 menu_item_add_sensitive(menu, _("_Properties"), over_icon,
791 G_CALLBACK(collection_table_popup_info_cb), ct);
792 menu_item_add_divider(menu);
793 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, over_icon,
794 G_CALLBACK(collection_table_popup_copy_cb), ct);
795 menu_item_add_sensitive(menu, _("_Move..."), over_icon,
796 G_CALLBACK(collection_table_popup_move_cb), ct);
797 menu_item_add_sensitive(menu, _("_Rename..."), over_icon,
798 G_CALLBACK(collection_table_popup_rename_cb), ct);
799 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, over_icon,
800 G_CALLBACK(collection_table_popup_delete_cb), ct);
801 menu_item_add_divider(menu);
803 submenu_add_sort(menu, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, 0);
804 menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
805 G_CALLBACK(collection_table_popup_show_names_cb), ct);
806 menu_item_add_divider(menu);
807 menu_item_add_stock(menu, _("_Save collection"), GTK_STOCK_SAVE,
808 G_CALLBACK(collection_table_popup_save_cb), ct);
809 menu_item_add_stock(menu, _("Save collection _as..."), GTK_STOCK_SAVE_AS,
810 G_CALLBACK(collection_table_popup_save_as_cb), ct);
811 menu_item_add_divider(menu);
812 menu_item_add_stock(menu, _("_Find duplicates..."), GTK_STOCK_FIND,
813 G_CALLBACK(collection_table_popup_find_dupes_cb), ct);
814 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, over_icon,
815 G_CALLBACK(collection_table_popup_print_cb), ct);
820 *-------------------------------------------------------------------
822 *-------------------------------------------------------------------
825 static void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
830 if (g_list_find(ct->cd->list, ct->focus_info))
832 if (info == ct->focus_info)
834 /* ensure focus row col are correct */
835 collection_table_find_position(ct, ct->focus_info,
836 &ct->focus_row, &ct->focus_column);
839 collection_table_selection_remove(ct, ct->focus_info, SELECTION_FOCUS, NULL);
842 if (!collection_table_find_position(ct, info, &row, &col))
844 ct->focus_info = NULL;
846 ct->focus_column = -1;
850 ct->focus_info = info;
852 ct->focus_column = col;
853 collection_table_selection_add(ct, ct->focus_info, SELECTION_FOCUS, NULL);
855 if (collection_table_find_iter(ct, ct->focus_info, &iter, NULL))
858 GtkTreeViewColumn *column;
861 tree_view_row_make_visible(GTK_TREE_VIEW(ct->listview), &iter, FALSE);
863 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
864 tpath = gtk_tree_model_get_path(store, &iter);
865 /* focus is set to an extra column with 0 width to hide focus, we draw it ourself */
866 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), COLLECT_TABLE_MAX_COLUMNS);
867 gtk_tree_view_set_cursor(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE);
868 gtk_tree_path_free(tpath);
872 static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gint relative)
879 new_row = ct->focus_row;
880 new_col = ct->focus_column;
883 if (new_row < 0) new_row = 0;
884 if (new_row >= ct->rows) new_row = ct->rows - 1;
904 new_col = ct->columns - 1;
911 if (new_col >= ct->columns)
913 if (new_row < ct->rows - 1)
920 new_col = ct->columns - 1;
930 if (new_row >= ct->rows)
933 new_row = ct->rows - 1;
936 new_col = ct->columns - 1;
938 if (new_col >= ct->columns) new_col = ct->columns - 1;
941 if (new_row == ct->rows - 1)
945 /* if we moved beyond the last image, go to the last image */
947 l = g_list_length(ct->cd->list);
948 if (ct->rows > 1) l -= (ct->rows - 1) * ct->columns;
949 if (new_col >= l) new_col = l - 1;
952 if (new_row == -1 || new_col == -1)
954 if (!ct->cd->list) return;
955 new_row = new_col = 0;
958 collection_table_set_focus(ct, collection_table_find_data(ct, new_row, new_col, NULL));
961 static void collection_table_update_focus(CollectTable *ct)
966 if (ct->focus_info && collection_table_find_position(ct, ct->focus_info, &new_row, &new_col))
968 /* first find the old focus, if it exists and is valid */
972 /* (try to) stay where we were */
973 new_row = ct->focus_row;
974 new_col = ct->focus_column;
977 collection_table_move_focus(ct, new_row, new_col, FALSE);
980 /* used to figure the page up/down distances */
981 static gint page_height(CollectTable *ct)
988 adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
989 page_size = (gint)adj->page_increment;
991 row_height = thumb_max_height + THUMB_BORDER_PADDING * 2;
992 if (ct->show_text) row_height += thumb_max_height / 3;
994 ret = page_size / row_height;
995 if (ret < 1) ret = 1;
1000 static void collection_table_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
1002 CollectTable *ct = data;
1003 GtkTreeModel *store;
1009 if (!collection_table_find_iter(ct, ct->click_info, &iter, &column)) return;
1010 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1011 tpath = gtk_tree_model_get_path(store, &iter);
1012 tree_view_get_cell_clamped(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE, x, y, &cw, &ch);
1013 gtk_tree_path_free(tpath);
1015 popup_menu_position_clamp(menu, x, y, 0);
1018 static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
1020 CollectTable *ct = data;
1027 switch (event->keyval)
1029 case GDK_Left: case GDK_KP_Left:
1032 case GDK_Right: case GDK_KP_Right:
1035 case GDK_Up: case GDK_KP_Up:
1038 case GDK_Down: case GDK_KP_Down:
1041 case GDK_Page_Up: case GDK_KP_Page_Up:
1042 focus_row = -page_height(ct);
1044 case GDK_Page_Down: case GDK_KP_Page_Down:
1045 focus_row = page_height(ct);
1047 case GDK_Home: case GDK_KP_Home:
1048 focus_row = -ct->focus_row;
1049 focus_col = -ct->focus_column;
1051 case GDK_End: case GDK_KP_End:
1052 focus_row = ct->rows - 1 - ct->focus_row;
1053 focus_col = ct->columns - 1 - ct->focus_column;
1056 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1059 ct->click_info = info;
1060 if (event->state & GDK_CONTROL_MASK)
1062 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1066 collection_table_unselect_all(ct);
1067 collection_table_select(ct, info);
1072 if (event->state & GDK_CONTROL_MASK) collection_table_toggle_filenames(ct);
1076 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1077 ct->click_info = info;
1079 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1082 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1083 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, collection_table_menu_pos_cb, ct, 0, GDK_CURRENT_TIME);
1086 stop_signal = FALSE;
1090 if (focus_row != 0 || focus_col != 0)
1092 CollectInfo *new_info;
1093 CollectInfo *old_info;
1095 old_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1096 collection_table_move_focus(ct, focus_row, focus_col, TRUE);
1097 new_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1099 if (new_info != old_info)
1101 if (event->state & GDK_SHIFT_MASK)
1103 if (!collection_rectangular_selection)
1105 collection_table_select_region_util(ct, old_info, new_info, FALSE);
1109 collection_table_select_region_util(ct, ct->click_info, old_info, FALSE);
1111 collection_table_select_region_util(ct, ct->click_info, new_info, TRUE);
1113 else if (event->state & GDK_CONTROL_MASK)
1115 ct->click_info = new_info;
1119 ct->click_info = new_info;
1120 collection_table_unselect_all(ct);
1121 collection_table_select(ct, new_info);
1129 g_signal_stop_emission_by_name(GTK_OBJECT(widget), "key_press_event");
1138 *-------------------------------------------------------------------
1140 *-------------------------------------------------------------------
1143 static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gint *after, GdkRectangle *cell,
1144 gint use_coord, gint x, gint y)
1146 CollectInfo *info = NULL;
1147 GtkTreeModel *store;
1150 GtkTreeViewColumn *column;
1152 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1154 if (!use_coord) gdk_window_get_pointer(ct->listview->window, &x, &y, NULL);
1159 if (collection_table_find_iter(ct, source, &iter, &col))
1161 tpath = gtk_tree_model_get_path(store, &iter);
1162 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1163 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1164 gtk_tree_path_free(tpath);
1167 *after = (x > cell->x + (cell->width / 2));
1172 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
1173 &tpath, &column, NULL, NULL))
1178 gtk_tree_model_get_iter(store, &iter, tpath);
1179 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1181 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
1182 info = g_list_nth_data(list, n);
1186 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1187 *after = (x > cell->x + (cell->width / 2));
1190 gtk_tree_path_free(tpath);
1197 work = g_list_last(ct->cd->list);
1205 if (collection_table_find_iter(ct, info, &iter, &col))
1207 tpath = gtk_tree_model_get_path(store, &iter);
1208 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1209 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1210 gtk_tree_path_free(tpath);
1218 static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint y)
1224 info = collection_table_insert_find(ct, NULL, &after, &cell, TRUE, x, y);
1230 work = g_list_find(ct->cd->list, info);
1231 if (work && work->next)
1233 info = work->next->data;
1244 static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gint enable)
1252 if (ct->marker_window) gdk_window_destroy(ct->marker_window);
1253 ct->marker_window = NULL;
1258 info = collection_table_insert_find(ct, info, &after, &cell, FALSE, 0, 0);
1260 /* this setting does not take into account (after), but since it is not really used... */
1261 ct->marker_info = info;
1266 if (!ct->marker_window)
1269 GdkWindowAttr attributes;
1270 gint attributes_mask;
1276 parent = gtk_tree_view_get_bin_window(GTK_TREE_VIEW(ct->listview));
1278 pb = gdk_pixbuf_new_from_xpm_data((const char **)marker_xpm);
1279 gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128);
1280 gdk_pixbuf_unref(pb);
1282 gdk_drawable_get_size(pixmap, &w, &h);
1284 attributes.window_type = GDK_WINDOW_CHILD;
1285 attributes.wclass = GDK_INPUT_OUTPUT;
1286 attributes.width = w;
1287 attributes.height = h;
1288 attributes.event_mask = gtk_widget_get_events(ct->listview);
1289 attributes_mask = 0;
1291 ct->marker_window = gdk_window_new(parent, &attributes, attributes_mask);
1292 gdk_window_set_back_pixmap(ct->marker_window, pixmap, FALSE);
1293 gdk_window_shape_combine_mask(ct->marker_window, mask, 0, 0);
1295 g_object_unref(pixmap);
1296 if (mask) g_object_unref(mask);
1304 gdk_drawable_get_size(ct->marker_window, &w, &h);
1312 x = cell.x + cell.width;
1315 y = cell.y + (cell.height / 2) - (h / 2);
1317 gdk_window_move(ct->marker_window, x, y);
1318 gdk_window_clear(ct->marker_window);
1319 if (!gdk_window_is_visible(ct->marker_window)) gdk_window_show(ct->marker_window);
1323 if (gdk_window_is_visible(ct->marker_window)) gdk_window_hide(ct->marker_window);
1328 *-------------------------------------------------------------------
1329 * mouse drag auto-scroll
1330 *-------------------------------------------------------------------
1333 static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gint drop_event)
1337 info = collection_table_find_data_by_coord(ct, x, y, NULL);
1342 collection_table_insert_marker(ct, info, TRUE);
1346 tip_update(ct, info);
1350 static gint collection_table_auto_scroll_idle_cb(gpointer data)
1352 CollectTable *ct = data;
1357 if (ct->drop_idle_id == -1) return FALSE;
1359 window = ct->listview->window;
1360 gdk_window_get_pointer(window, &x, &y, NULL);
1361 gdk_drawable_get_size(window, &w, &h);
1362 if (x >= 0 && x < w && y >= 0 && y < h)
1364 collection_table_motion_update(ct, x, y, TRUE);
1367 ct->drop_idle_id = -1;
1371 static gint collection_table_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data)
1373 CollectTable *ct = data;
1375 if (ct->drop_idle_id == -1) ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
1380 static void collection_table_scroll(CollectTable *ct, gint scroll)
1384 if (ct->drop_idle_id != -1)
1386 g_source_remove(ct->drop_idle_id);
1387 ct->drop_idle_id = -1;
1389 widget_auto_scroll_stop(ct->listview);
1390 collection_table_insert_marker(ct, NULL, FALSE);
1394 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
1395 widget_auto_scroll_start(ct->listview, adj, -1, thumb_max_height / 2,
1396 collection_table_auto_scroll_notify_cb, ct);
1401 *-------------------------------------------------------------------
1403 *-------------------------------------------------------------------
1406 static gint collection_table_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1408 CollectTable *ct = data;
1410 collection_table_motion_update(ct, (gint)bevent->x, (gint)bevent->y, FALSE);
1415 static gint collection_table_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1417 CollectTable *ct = data;
1423 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1425 ct->click_info = info;
1426 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, &iter);
1428 switch (bevent->button)
1431 if (bevent->type == GDK_2BUTTON_PRESS)
1435 layout_image_set_collection(NULL, ct->cd, info);
1438 else if (!GTK_WIDGET_HAS_FOCUS(ct->listview))
1440 gtk_widget_grab_focus(ct->listview);
1444 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1445 gtk_menu_popup(GTK_MENU(ct->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
1454 static gint collection_table_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1456 CollectTable *ct = data;
1458 CollectInfo *info = NULL;
1462 if ((gint)bevent->x != 0 || (gint) bevent->y != 0)
1464 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1469 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1472 if (bevent->button == 1 &&
1473 info && ct->click_info == info)
1475 collection_table_set_focus(ct, info);
1477 if (bevent->state & GDK_CONTROL_MASK)
1481 select = !INFO_SELECTED(info);
1482 if ((bevent->state & GDK_SHIFT_MASK) && ct->prev_selection)
1484 collection_table_select_region_util(ct, ct->prev_selection, info, select);
1488 collection_table_select_util(ct, info, select);
1493 collection_table_unselect_all(ct);
1495 if ((bevent->state & GDK_SHIFT_MASK) &&
1498 collection_table_select_region_util(ct, ct->prev_selection, info, TRUE);
1502 collection_table_select_util(ct, info, TRUE);
1506 else if (bevent->button == 2 &&
1507 info && ct->click_info == info)
1509 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1515 static gint collection_table_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
1517 CollectTable *ct = data;
1524 *-------------------------------------------------------------------
1525 * populate, add, insert, etc.
1526 *-------------------------------------------------------------------
1529 static gboolean collection_table_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data)
1533 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
1539 static void collection_table_clear_store(CollectTable *ct)
1541 GtkTreeModel *store;
1543 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1544 gtk_tree_model_foreach(store, collection_table_destroy_node_cb, NULL);
1546 gtk_list_store_clear(GTK_LIST_STORE(store));
1549 static GList *collection_table_add_row(CollectTable *ct, GtkTreeIter *iter)
1551 GtkListStore *store;
1555 for (i = 0; i < ct->columns; i++) list = g_list_prepend(list, NULL);
1557 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)));
1558 gtk_list_store_append(store, iter);
1559 gtk_list_store_set(store, iter, CTABLE_COLUMN_POINTER, list, -1);
1564 static void collection_table_populate(CollectTable *ct, gint resize)
1569 collection_table_verify_selections(ct);
1571 collection_table_clear_store(ct);
1578 thumb_width = collection_table_get_icon_width(ct);
1580 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
1582 GtkTreeViewColumn *column;
1583 GtkCellRenderer *cell;
1586 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), i);
1587 gtk_tree_view_column_set_visible(column, (i < ct->columns));
1588 gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6));
1590 list = gtk_tree_view_column_get_cell_renderers(column);
1591 cell = (list) ? list->data : NULL;
1594 if (cell && GQV_IS_CELL_RENDERER_ICON(cell))
1596 g_object_set(G_OBJECT(cell), "fixed_width", thumb_width,
1597 "fixed_height", thumb_max_height,
1598 "show_text", ct->show_text, NULL);
1601 if (GTK_WIDGET_REALIZED(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
1605 work = ct->cd->list;
1613 list = collection_table_add_row(ct, &iter);
1614 while (work && list)
1616 list->data = work->data;
1624 collection_table_update_focus(ct);
1625 collection_table_update_status(ct);
1628 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gint force)
1633 thumb_width = collection_table_get_icon_width(ct);
1635 new_cols = w / (thumb_width + (THUMB_BORDER_PADDING * 6));
1636 if (new_cols < 1) new_cols = 1;
1638 if (!force && new_cols == ct->columns) return;
1640 ct->columns = new_cols;
1642 collection_table_populate(ct, TRUE);
1644 if (debug) printf("col tab pop cols=%d rows=%d\n", ct->columns, ct->rows);
1647 static void collection_table_sync(CollectTable *ct)
1649 GtkTreeModel *store;
1654 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1659 work = ct->cd->list;
1665 if (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1667 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1668 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1672 list = collection_table_add_row(ct, &iter);
1697 while (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1701 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1702 gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
1708 collection_table_update_focus(ct);
1709 collection_table_update_status(ct);
1712 static gint collection_table_sync_idle_cb(gpointer data)
1714 CollectTable *ct = data;
1716 if (ct->sync_idle_id == -1) return FALSE;
1717 ct->sync_idle_id = -1;
1719 collection_table_sync(ct);
1723 static void collection_table_sync_idle(CollectTable *ct)
1725 if (ct->sync_idle_id == -1)
1727 /* high priority, the view needs to be resynced before a redraw
1728 * may contain invalid pointers at this time
1730 ct->sync_idle_id = g_idle_add_full(G_PRIORITY_HIGH, collection_table_sync_idle_cb, ct, NULL);
1734 void collection_table_add_filelist(CollectTable *ct, GList *list)
1743 collection_add(ct->cd, (FileData *)work->data, FALSE);
1748 static void collection_table_insert_filelist(CollectTable *ct, GList *list, CollectInfo *insert_info)
1757 collection_insert(ct->cd, (FileData *)work->data, insert_info, FALSE);
1761 collection_table_sync_idle(ct);
1764 static void collection_table_move_by_info_list(CollectTable *ct, GList *info_list, gint row, gint col)
1767 GList *insert_pos = NULL;
1771 if (!info_list) return;
1773 info = collection_table_find_data(ct, row, col, NULL);
1775 if (!info_list->next && info_list->data == info) return;
1777 if (info) insert_pos = g_list_find(ct->cd->list, info);
1779 /* FIXME: this may get slow for large lists */
1781 while (insert_pos && work)
1783 if (insert_pos->data == work->data)
1785 insert_pos = insert_pos->next;
1797 ct->cd->list = g_list_remove(ct->cd->list, work->data);
1801 /* place them back in */
1802 temp = g_list_copy(info_list);
1806 ct->cd->list = uig_list_insert_list(ct->cd->list, insert_pos, temp);
1810 ct->cd->list = g_list_concat(temp, ct->cd->list);
1814 ct->cd->list = g_list_concat(ct->cd->list, temp);
1817 ct->cd->changed = TRUE;
1819 collection_table_sync_idle(ct);
1824 *-------------------------------------------------------------------
1826 *-------------------------------------------------------------------
1829 void collection_table_file_update(CollectTable *ct, CollectInfo *info)
1837 collection_table_update_extras(ct, FALSE, 0.0);
1841 if (!collection_table_find_position(ct, info, &row, &col)) return;
1843 if (ct->columns != 0 && ct->rows != 0)
1845 value = (gdouble)(row * ct->columns + col) / (ct->columns * ct->rows);
1852 collection_table_update_extras(ct, TRUE, value);
1854 if (collection_table_find_iter(ct, info, &iter, NULL))
1856 GtkTreeModel *store;
1859 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1860 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1861 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1865 void collection_table_file_add(CollectTable *ct, CollectInfo *info)
1867 collection_table_sync_idle(ct);
1870 void collection_table_file_insert(CollectTable *ct, CollectInfo *ci)
1872 collection_table_sync_idle(ct);
1875 void collection_table_file_remove(CollectTable *ct, CollectInfo *ci)
1877 if (ci && INFO_SELECTED(ci))
1879 ct->selection = g_list_remove(ct->selection, ci);
1882 collection_table_sync_idle(ct);
1885 void collection_table_refresh(CollectTable *ct)
1887 collection_table_populate(ct, FALSE);
1891 *-------------------------------------------------------------------
1893 *-------------------------------------------------------------------
1896 static void collection_table_add_dir_recursive(CollectTable *ct, gchar *path, gint recursive)
1901 if (filelist_read(path, &f, recursive ? &d : NULL))
1905 f = filelist_filter(f, FALSE);
1906 d = filelist_filter(d, TRUE);
1908 f = filelist_sort_path(f);
1909 d = filelist_sort_path(d);
1911 collection_table_insert_filelist(ct, f, ct->marker_info);
1913 work = g_list_last(d);
1916 collection_table_add_dir_recursive(ct, ((FileData *)work->data)->path, TRUE);
1924 static void confirm_dir_list_do(CollectTable *ct, GList *list, gint recursive)
1929 FileData *fd = work->data;
1931 if (isdir(fd->path)) collection_table_add_dir_recursive(ct, fd->path, recursive);
1933 collection_table_insert_filelist(ct, list, ct->marker_info);
1937 static void confirm_dir_list_add(GtkWidget *widget, gpointer data)
1939 CollectTable *ct = data;
1941 confirm_dir_list_do(ct, ct->drop_list, FALSE);
1944 static void confirm_dir_list_recurse(GtkWidget *widget, gpointer data)
1946 CollectTable *ct = data;
1948 confirm_dir_list_do(ct, ct->drop_list, TRUE);
1951 static void confirm_dir_list_skip(GtkWidget *widget, gpointer data)
1953 CollectTable *ct = data;
1955 collection_table_insert_filelist(ct, ct->drop_list, ct->marker_info);
1958 static GtkWidget *collection_table_drop_menu(CollectTable *ct)
1962 menu = popup_menu_short_lived();
1963 g_signal_connect(G_OBJECT(menu), "destroy",
1964 G_CALLBACK(collection_table_popup_destroy_cb), ct);
1966 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL);
1967 menu_item_add_divider(menu);
1968 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK,
1969 G_CALLBACK(confirm_dir_list_add), ct);
1970 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD,
1971 G_CALLBACK(confirm_dir_list_recurse), ct);
1972 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE,
1973 G_CALLBACK(confirm_dir_list_skip), ct);
1974 menu_item_add_divider(menu);
1975 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, ct);
1981 *-------------------------------------------------------------------
1983 *-------------------------------------------------------------------
1986 static GtkTargetEntry collection_drag_types[] = {
1987 { "application/x-gqview-collection-member", 0, TARGET_APP_COLLECTION_MEMBER },
1988 { "text/uri-list", 0, TARGET_URI_LIST },
1989 { "text/plain", 0, TARGET_TEXT_PLAIN }
1991 static gint n_collection_drag_types = 3;
1993 static GtkTargetEntry collection_drop_types[] = {
1994 { "application/x-gqview-collection-member", 0, TARGET_APP_COLLECTION_MEMBER },
1995 { "text/uri-list", 0, TARGET_URI_LIST }
1997 static gint n_collection_drop_types = 2;
2000 static void collection_table_dnd_get(GtkWidget *widget, GdkDragContext *context,
2001 GtkSelectionData *selection_data, guint info,
2002 guint time, gpointer data)
2004 CollectTable *ct = data;
2007 gchar *uri_text = NULL;
2010 if (!ct->click_info) return;
2012 selected = INFO_SELECTED(ct->click_info);
2016 case TARGET_APP_COLLECTION_MEMBER:
2019 uri_text = collection_info_list_to_dnd_data(ct->cd, ct->selection, &total);
2023 list = g_list_append(NULL, ct->click_info);
2024 uri_text = collection_info_list_to_dnd_data(ct->cd, list, &total);
2028 case TARGET_URI_LIST:
2029 case TARGET_TEXT_PLAIN:
2033 list = collection_table_selection_get_list(ct);
2037 list = g_list_append(NULL, file_data_ref(ct->click_info->fd));
2041 uri_text = uri_text_from_filelist(list, &total, (info == TARGET_TEXT_PLAIN));
2042 filelist_free(list);
2046 gtk_selection_data_set(selection_data, selection_data->target,
2047 8, (guchar *)uri_text, total);
2052 static void collection_table_dnd_receive(GtkWidget *widget, GdkDragContext *context,
2054 GtkSelectionData *selection_data, guint info,
2055 guint time, gpointer data)
2057 CollectTable *ct = data;
2059 GList *info_list = NULL;
2060 CollectionData *source;
2061 CollectInfo *drop_info;
2064 if (debug) printf("%s\n", selection_data->data);
2066 collection_table_scroll(ct, FALSE);
2067 collection_table_insert_marker(ct, NULL, FALSE);
2069 drop_info = collection_table_insert_point(ct, x, y);
2073 case TARGET_APP_COLLECTION_MEMBER:
2074 source = collection_from_dnd_data((gchar *)selection_data->data, &list, &info_list);
2077 if (source == ct->cd)
2082 /* it is a move within a collection */
2083 filelist_free(list);
2088 collection_table_move_by_info_list(ct, info_list, -1, -1);
2090 else if (collection_table_find_position(ct, drop_info, &row, &col))
2092 collection_table_move_by_info_list(ct, info_list, row, col);
2097 /* it is a move/copy across collections */
2098 if (context->action == GDK_ACTION_MOVE)
2100 collection_remove_by_info_list(source, info_list);
2103 g_list_free(info_list);
2106 case TARGET_URI_LIST:
2107 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE);
2111 FileData *fd = work->data;
2112 if (isdir(fd->path))
2116 ct->drop_list = list;
2117 ct->drop_info = drop_info;
2118 menu = collection_table_drop_menu(ct);
2119 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time);
2132 collection_table_insert_filelist(ct, list, drop_info);
2133 filelist_free(list);
2137 static void collection_table_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
2139 CollectTable *ct = data;
2141 if (ct->click_info && ct->click_info->pixbuf)
2145 if (INFO_SELECTED(ct->click_info))
2146 items = g_list_length(ct->selection);
2149 dnd_set_drag_icon(widget, context, ct->click_info->pixbuf, items);
2153 static void collection_table_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
2155 CollectTable *ct = data;
2157 /* apparently a leave event is not generated on a drop */
2160 collection_table_scroll(ct, FALSE);
2163 static gint collection_table_dnd_motion(GtkWidget *widget, GdkDragContext *context,
2164 gint x, gint y, guint time, gpointer data)
2166 CollectTable *ct = data;
2168 collection_table_motion_update(ct, x, y, TRUE);
2169 collection_table_scroll(ct, TRUE);
2174 static void collection_table_dnd_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data)
2176 CollectTable *ct = data;
2178 collection_table_scroll(ct, FALSE);
2181 static void collection_table_dnd_init(CollectTable *ct)
2183 gtk_drag_source_set(ct->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
2184 collection_drag_types, n_collection_drag_types,
2185 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
2186 g_signal_connect(G_OBJECT(ct->listview), "drag_data_get",
2187 G_CALLBACK(collection_table_dnd_get), ct);
2188 g_signal_connect(G_OBJECT(ct->listview), "drag_begin",
2189 G_CALLBACK(collection_table_dnd_begin), ct);
2190 g_signal_connect(G_OBJECT(ct->listview), "drag_end",
2191 G_CALLBACK(collection_table_dnd_end), ct);
2193 gtk_drag_dest_set(ct->listview,
2194 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
2195 collection_drop_types, n_collection_drop_types,
2196 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK);
2197 g_signal_connect(G_OBJECT(ct->listview), "drag_motion",
2198 G_CALLBACK(collection_table_dnd_motion), ct);
2199 g_signal_connect(G_OBJECT(ct->listview), "drag_leave",
2200 G_CALLBACK(collection_table_dnd_leave), ct);
2201 g_signal_connect(G_OBJECT(ct->listview), "drag_data_received",
2202 G_CALLBACK(collection_table_dnd_receive), ct);
2206 *-----------------------------------------------------------------------------
2208 *-----------------------------------------------------------------------------
2211 typedef struct _ColumnData ColumnData;
2218 static void collection_table_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
2219 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
2221 ColumnData *cd = data;
2231 gtk_tree_model_get(tree_model, iter, CTABLE_COLUMN_POINTER, &list, -1);
2232 info = g_list_nth_data(list, cd->number);
2234 style = gtk_widget_get_style(ct->listview);
2235 if (info && (info->flag_mask & SELECTION_SELECTED) )
2237 memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg));
2238 memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg));
2242 memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg));
2243 memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg));
2246 if (info && (info->flag_mask & SELECTION_PRELIGHT))
2249 shift_color(&color_fg, -1, 0);
2251 shift_color(&color_bg, -1, 0);
2254 if (GQV_IS_CELL_RENDERER_ICON(cell))
2258 g_object_set(cell, "pixbuf", info->pixbuf,
2259 "text", info->fd->name,
2260 "cell-background-gdk", &color_bg,
2261 "cell-background-set", TRUE,
2262 "foreground-gdk", &color_fg,
2263 "foreground-set", TRUE,
2264 "has-focus", (ct->focus_info == info), NULL);
2268 g_object_set(cell, "pixbuf", NULL,
2270 "cell-background-set", FALSE,
2271 "foreground-set", FALSE,
2272 "has-focus", FALSE, NULL);
2277 static void collection_table_append_column(CollectTable *ct, gint n)
2280 GtkTreeViewColumn *column;
2281 GtkCellRenderer *renderer;
2283 column = gtk_tree_view_column_new();
2284 gtk_tree_view_column_set_min_width(column, 0);
2286 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
2287 gtk_tree_view_column_set_alignment(column, 0.5);
2289 renderer = gqv_cell_renderer_icon_new();
2290 gtk_tree_view_column_pack_start(column, renderer, FALSE);
2291 g_object_set(G_OBJECT(renderer), "xpad", THUMB_BORDER_PADDING * 2,
2292 "ypad", THUMB_BORDER_PADDING,
2293 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
2295 g_object_set_data(G_OBJECT(column), "column_number", GINT_TO_POINTER(n));
2297 cd = g_new0(ColumnData, 1);
2300 gtk_tree_view_column_set_cell_data_func(column, renderer, collection_table_cell_data_cb, cd, g_free);
2302 gtk_tree_view_append_column(GTK_TREE_VIEW(ct->listview), column);
2306 *-------------------------------------------------------------------
2308 *-------------------------------------------------------------------
2311 static void collection_table_destroy(GtkWidget *widget, gpointer data)
2313 CollectTable *ct = data;
2317 g_signal_handlers_disconnect_matched(GTK_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA,
2319 gtk_widget_destroy(ct->popup);
2322 if (ct->sync_idle_id != -1) g_source_remove(ct->sync_idle_id);
2325 collection_table_scroll(ct, FALSE);
2330 static void collection_table_sized(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
2332 CollectTable *ct = data;
2334 collection_table_populate_at_new_size(ct, allocation->width, allocation->height, FALSE);
2337 CollectTable *collection_table_new(CollectionData *cd)
2340 GtkListStore *store;
2341 GtkTreeSelection *selection;
2344 ct = g_new0(CollectTable, 1);
2349 ct->selection = NULL;
2350 ct->prev_selection = NULL;
2352 ct->tip_window = NULL;
2353 ct->tip_delay_id = -1;
2355 ct->marker_window = NULL;
2356 ct->marker_info = NULL;
2358 ct->status_label = NULL;
2359 ct->extra_label = NULL;
2362 ct->focus_column = 0;
2363 ct->focus_info = NULL;
2365 ct->show_text = show_icon_names;
2367 ct->sync_idle_id = -1;
2368 ct->drop_idle_id = -1;
2371 ct->drop_info = NULL;
2372 ct->drop_list = NULL;
2374 ct->scrolled = gtk_scrolled_window_new(NULL, NULL);
2375 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN);
2376 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (ct->scrolled),
2377 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2379 store = gtk_list_store_new(1, G_TYPE_POINTER);
2380 ct->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
2381 g_object_unref(store);
2383 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ct->listview));
2384 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_NONE);
2386 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ct->listview), FALSE);
2387 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ct->listview), FALSE);
2389 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
2391 collection_table_append_column(ct, i);
2394 /* zero width column to hide tree view focus, we draw it ourselves */
2395 collection_table_append_column(ct, i);
2396 /* end column to fill white space */
2397 collection_table_append_column(ct, i);
2399 g_signal_connect(G_OBJECT(ct->listview), "destroy",
2400 G_CALLBACK(collection_table_destroy), ct);
2401 g_signal_connect(G_OBJECT(ct->listview), "size_allocate",
2402 G_CALLBACK(collection_table_sized), ct);
2403 g_signal_connect(G_OBJECT(ct->listview), "key_press_event",
2404 G_CALLBACK(collection_table_press_key_cb), ct);
2406 gtk_container_add(GTK_CONTAINER(ct->scrolled), ct->listview);
2407 gtk_widget_show(ct->listview);
2409 collection_table_dnd_init(ct);
2411 gtk_widget_set_events(ct->listview, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK |
2412 GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK);
2413 g_signal_connect(G_OBJECT(ct->listview),"button_press_event",
2414 G_CALLBACK(collection_table_press_cb), ct);
2415 g_signal_connect(G_OBJECT(ct->listview),"button_release_event",
2416 G_CALLBACK(collection_table_release_cb), ct);
2417 g_signal_connect(G_OBJECT(ct->listview),"motion_notify_event",
2418 G_CALLBACK(collection_table_motion_cb), ct);
2419 g_signal_connect(G_OBJECT(ct->listview), "leave_notify_event",
2420 G_CALLBACK(collection_table_leave_cb), ct);
2425 void collection_table_set_labels(CollectTable *ct, GtkWidget *status, GtkWidget *extra)
2427 ct->status_label = status;
2428 ct->extra_label = extra;
2429 collection_table_update_status(ct);
2430 collection_table_update_extras(ct, FALSE, 0.0);
2433 CollectInfo *collection_table_get_focus_info(CollectTable *ct)
2435 return collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);