2 * Copyright (C) 2004 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "collect-table.h"
25 #include "cellrenderericon.h"
26 #include "collect-dlg.h"
27 #include "collect-io.h"
33 #include "layout-image.h"
36 #include "pixbuf-util.h"
39 #include "ui-fileops.h"
41 #include "ui-tree-edit.h"
42 #include "uri-utils.h"
43 #include "view-file.h"
45 /* between these, the icon width is increased by thumb_max_width / 2 */
46 #define THUMB_MIN_ICON_WIDTH 128
47 #define THUMB_MAX_ICON_WIDTH 150
49 #define COLLECT_TABLE_MAX_COLUMNS 32
50 #define THUMB_BORDER_PADDING 2
52 #define COLLECT_TABLE_TIP_DELAY 500
53 #define COLLECT_TABLE_TIP_DELAY_PATH (COLLECT_TABLE_TIP_DELAY * 1.7)
57 CTABLE_COLUMN_POINTER = 0,
61 #define INFO_SELECTED(x) (x->flag_mask & SELECTION_SELECTED)
64 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gboolean force);
67 * This array must be kept in sync with the contents of:\n
68 * @link collection_table_press_key_cb @endlink \n
69 * @link collection_window_keypress @endlink \n
70 * @link collection_table_popup_menu @endlink
72 * See also @link hard_coded_window_keys @endlink
74 hard_coded_window_keys collection_window_keys[] = {
75 {GDK_CONTROL_MASK, 'C', N_("Copy")},
76 {GDK_CONTROL_MASK, 'M', N_("Move")},
77 {GDK_CONTROL_MASK, 'R', N_("Rename")},
78 {GDK_CONTROL_MASK, 'D', N_("Move to Trash")},
79 {GDK_CONTROL_MASK, 'W', N_("Close window")},
80 {static_cast<GdkModifierType>(0), GDK_KEY_Delete, N_("Remove")},
81 {static_cast<GdkModifierType>(0), GDK_KEY_Return, N_("View")},
82 {static_cast<GdkModifierType>(0), 'V', N_("View in new window")},
83 {GDK_CONTROL_MASK, 'A', N_("Select all")},
84 {static_cast<GdkModifierType>(GDK_CONTROL_MASK + GDK_SHIFT_MASK), 'A', N_("Select none")},
85 {GDK_MOD1_MASK, 'R', N_("Rectangular selection")},
86 {static_cast<GdkModifierType>(0), GDK_KEY_space, N_("Select single file")},
87 {GDK_CONTROL_MASK, GDK_KEY_space, N_("Toggle select image")},
88 {GDK_CONTROL_MASK, 'L', N_("Append from file selection")},
89 {static_cast<GdkModifierType>(0), 'A', N_("Append from collection")},
90 {static_cast<GdkModifierType>(0), 'S', N_("Save collection")},
91 {GDK_CONTROL_MASK, 'S', N_("Save collection as")},
92 {GDK_CONTROL_MASK, 'T', N_("Show filename text")},
93 {static_cast<GdkModifierType>(0), 'N', N_("Sort by name")},
94 {static_cast<GdkModifierType>(0), 'D', N_("Sort by date")},
95 {static_cast<GdkModifierType>(0), 'B', N_("Sort by size")},
96 {static_cast<GdkModifierType>(0), 'P', N_("Sort by path")},
97 {GDK_SHIFT_MASK, 'P', N_("Print")},
98 {static_cast<GdkModifierType>(0), 0, NULL}
102 *-------------------------------------------------------------------
104 *-------------------------------------------------------------------
107 static gboolean collection_table_find_position(CollectTable *ct, CollectInfo *info, gint *row, gint *col)
111 n = g_list_index(ct->cd->list, info);
113 if (n < 0) return FALSE;
115 *row = n / ct->columns;
116 *col = n - (*row * ct->columns);
121 static gboolean collection_table_find_iter(CollectTable *ct, CollectInfo *info, GtkTreeIter *iter, gint *column)
126 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
127 if (!collection_table_find_position(ct, info, &row, &col)) return FALSE;
128 if (!gtk_tree_model_iter_nth_child(store, iter, NULL, row)) return FALSE;
129 if (column) *column = col;
134 static CollectInfo *collection_table_find_data(CollectTable *ct, gint row, gint col, GtkTreeIter *iter)
139 if (row < 0 || col < 0) return NULL;
141 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
142 if (gtk_tree_model_iter_nth_child(store, &p, NULL, row))
146 gtk_tree_model_get(store, &p, CTABLE_COLUMN_POINTER, &list, -1);
147 if (!list) return NULL;
151 return static_cast<CollectInfo *>(g_list_nth_data(list, col));
157 static CollectInfo *collection_table_find_data_by_coord(CollectTable *ct, gint x, gint y, GtkTreeIter *iter)
160 GtkTreeViewColumn *column;
166 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
167 &tpath, &column, NULL, NULL))
170 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
171 gtk_tree_model_get_iter(store, &row, tpath);
172 gtk_tree_path_free(tpath);
174 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
175 if (!list) return NULL;
177 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
178 if (iter) *iter = row;
179 return static_cast<CollectInfo *>(g_list_nth_data(list, n));
182 static guint collection_table_list_count(CollectTable *ct, gint64 *bytes)
192 CollectInfo *ci = static_cast<CollectInfo *>(work->data);
200 return g_list_length(ct->cd->list);
203 static guint collection_table_selection_count(CollectTable *ct, gint64 *bytes)
210 work = ct->selection;
213 CollectInfo *ci = static_cast<CollectInfo *>(work->data);
221 return g_list_length(ct->selection);
224 static void collection_table_update_status(CollectTable *ct)
232 if (!ct->status_label) return;
234 n = collection_table_list_count(ct, &n_bytes);
235 s = collection_table_selection_count(ct, &s_bytes);
239 gchar *b = text_from_size_abrev(n_bytes);
240 gchar *sb = text_from_size_abrev(s_bytes);
241 buf = g_strdup_printf(_("%s, %d images (%s, %d)"), b, n, sb, s);
247 gchar *b = text_from_size_abrev(n_bytes);
248 buf = g_strdup_printf(_("%s, %d images"), b, n);
253 buf = g_strdup(_("Empty"));
256 gtk_label_set_text(GTK_LABEL(ct->status_label), buf);
260 static void collection_table_update_extras(CollectTable *ct, gboolean loading, gdouble value)
264 if (!ct->extra_label) return;
267 text = _("Loading thumbs...");
271 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ct->extra_label), value);
272 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ct->extra_label), text);
275 static void collection_table_toggle_filenames(CollectTable *ct)
277 GtkAllocation allocation;
278 ct->show_text = !ct->show_text;
279 options->show_icon_names = ct->show_text;
281 gtk_widget_get_allocation(ct->listview, &allocation);
282 collection_table_populate_at_new_size(ct, allocation.width, allocation.height, TRUE);
285 static void collection_table_toggle_stars(CollectTable *ct)
287 GtkAllocation allocation;
288 ct->show_stars = !ct->show_stars;
289 options->show_star_rating = ct->show_stars;
291 gtk_widget_get_allocation(ct->listview, &allocation);
292 collection_table_populate_at_new_size(ct, allocation.width, allocation.height, TRUE);
295 static gint collection_table_get_icon_width(CollectTable *ct)
299 if (!ct->show_text) return options->thumbnails.max_width;
301 width = options->thumbnails.max_width + options->thumbnails.max_width / 2;
302 if (width < THUMB_MIN_ICON_WIDTH) width = THUMB_MIN_ICON_WIDTH;
303 if (width > THUMB_MAX_ICON_WIDTH) width = options->thumbnails.max_width;
309 *-------------------------------------------------------------------
311 *-------------------------------------------------------------------
314 static void collection_table_selection_set(CollectTable *ct, CollectInfo *info, SelectionType value, GtkTreeIter *iter)
321 if (info->flag_mask == value) return;
322 info->flag_mask = value;
324 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
327 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
328 if (list) gtk_list_store_set(GTK_LIST_STORE(store), iter, CTABLE_COLUMN_POINTER, list, -1);
334 if (collection_table_find_iter(ct, info, &row, NULL))
336 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
337 if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, CTABLE_COLUMN_POINTER, list, -1);
342 static void collection_table_selection_add(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
346 collection_table_selection_set(ct, info, static_cast<SelectionType>(info->flag_mask | mask), iter);
349 static void collection_table_selection_remove(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
353 collection_table_selection_set(ct, info, static_cast<SelectionType>(info->flag_mask & ~mask), iter);
356 *-------------------------------------------------------------------
358 *-------------------------------------------------------------------
361 static void collection_table_verify_selections(CollectTable *ct)
365 work = ct->selection;
368 CollectInfo *info = static_cast<CollectInfo *>(work->data);
370 if (!g_list_find(ct->cd->list, info))
372 ct->selection = g_list_remove(ct->selection, info);
377 void collection_table_select_all(CollectTable *ct)
381 g_list_free(ct->selection);
382 ct->selection = NULL;
387 ct->selection = g_list_append(ct->selection, work->data);
388 collection_table_selection_add(ct, static_cast<CollectInfo *>(work->data), SELECTION_SELECTED, NULL);
392 collection_table_update_status(ct);
395 void collection_table_unselect_all(CollectTable *ct)
399 work = ct->selection;
402 collection_table_selection_remove(ct, static_cast<CollectInfo *>(work->data), SELECTION_SELECTED, NULL);
406 g_list_free(ct->selection);
407 ct->selection = NULL;
409 collection_table_update_status(ct);
412 /* Invert the current collection's selection */
413 static void collection_table_select_invert_all(CollectTable *ct)
416 GList *new_selection = NULL;
421 CollectInfo *info = static_cast<CollectInfo *>(work->data);
423 if (INFO_SELECTED(info))
425 collection_table_selection_remove(ct, info, SELECTION_SELECTED, NULL);
429 new_selection = g_list_append(new_selection, info);
430 collection_table_selection_add(ct, info, SELECTION_SELECTED, NULL);
437 g_list_free(ct->selection);
438 ct->selection = new_selection;
440 collection_table_update_status(ct);
443 void collection_table_select(CollectTable *ct, CollectInfo *info)
445 ct->prev_selection = info;
447 if (!info || INFO_SELECTED(info)) return;
449 ct->selection = g_list_append(ct->selection, info);
450 collection_table_selection_add(ct, info, SELECTION_SELECTED, NULL);
452 collection_table_update_status(ct);
455 static void collection_table_unselect(CollectTable *ct, CollectInfo *info)
457 ct->prev_selection = info;
459 if (!info || !INFO_SELECTED(info) ) return;
461 ct->selection = g_list_remove(ct->selection, info);
462 collection_table_selection_remove(ct, info, SELECTION_SELECTED, NULL);
464 collection_table_update_status(ct);
467 static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gboolean select)
471 collection_table_select(ct, info);
475 collection_table_unselect(ct, info);
479 static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gboolean select)
486 if (!collection_table_find_position(ct, start, &row1, &col1) ||
487 !collection_table_find_position(ct, end, &row2, &col2) ) return;
489 ct->prev_selection = end;
491 if (!options->collections.rectangular_selection)
496 if (g_list_index(ct->cd->list, start) > g_list_index(ct->cd->list, end))
503 work = g_list_find(ct->cd->list, start);
506 info = static_cast<CollectInfo *>(work->data);
507 collection_table_select_util(ct, info, select);
509 if (work->data != end)
530 DEBUG_1("table: %d x %d to %d x %d", row1, col1, row2, col2);
532 for (i = row1; i <= row2; i++)
534 for (j = col1; j <= col2; j++)
536 CollectInfo *info = collection_table_find_data(ct, i, j, NULL);
537 if (info) collection_table_select_util(ct, info, select);
542 GList *collection_table_selection_get_list(CollectTable *ct)
544 return collection_list_to_filelist(ct->selection);
547 static GList *collection_table_get_list(CollectTable *ct)
549 return collection_list_to_filelist(ct->cd->list);
553 *-------------------------------------------------------------------
554 * tooltip type window
555 *-------------------------------------------------------------------
558 static void tip_show(CollectTable *ct)
566 if (ct->tip_window) return;
568 seat = gdk_display_get_default_seat(gdk_window_get_display(gtk_widget_get_window(ct->listview)));
569 device = gdk_seat_get_pointer(seat);
570 gdk_window_get_device_position(gtk_widget_get_window(ct->listview),
571 device, &x, &y, NULL);
573 ct->tip_info = collection_table_find_data_by_coord(ct, x, y, NULL);
574 if (!ct->tip_info) return;
576 ct->tip_window = gtk_window_new(GTK_WINDOW_POPUP);
577 gtk_window_set_resizable(GTK_WINDOW(ct->tip_window), FALSE);
578 gtk_container_set_border_width(GTK_CONTAINER(ct->tip_window), 2);
580 label = gtk_label_new(ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
582 g_object_set_data(G_OBJECT(ct->tip_window), "tip_label", label);
583 gtk_container_add(GTK_CONTAINER(ct->tip_window), label);
584 gtk_widget_show(label);
586 display = gdk_display_get_default();
587 seat = gdk_display_get_default_seat(display);
588 device = gdk_seat_get_pointer(seat);
589 gdk_device_get_position(device, NULL, &x, &y);
591 if (!gtk_widget_get_realized(ct->tip_window)) gtk_widget_realize(ct->tip_window);
592 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
593 gtk_widget_show(ct->tip_window);
596 static void tip_hide(CollectTable *ct)
598 if (ct->tip_window) gtk_widget_destroy(ct->tip_window);
599 ct->tip_window = NULL;
602 static gboolean tip_schedule_cb(gpointer data)
604 CollectTable *ct = static_cast<CollectTable *>(data);
606 if (!ct->tip_delay_id) return FALSE;
610 ct->tip_delay_id = 0;
614 static void tip_schedule(CollectTable *ct)
618 if (ct->tip_delay_id)
620 g_source_remove(ct->tip_delay_id);
621 ct->tip_delay_id = 0;
624 ct->tip_delay_id = g_timeout_add(ct->show_text ? COLLECT_TABLE_TIP_DELAY_PATH : COLLECT_TABLE_TIP_DELAY, tip_schedule_cb, ct);
627 static void tip_unschedule(CollectTable *ct)
631 if (ct->tip_delay_id)
633 g_source_remove(ct->tip_delay_id);
634 ct->tip_delay_id = 0;
638 static void tip_update(CollectTable *ct, CollectInfo *info)
640 GdkDisplay *display = gdk_display_get_default();
641 GdkSeat *seat = gdk_display_get_default_seat(display);
642 GdkDevice *device = gdk_seat_get_pointer(seat);
649 gdk_device_get_position(device, NULL, &x, &y);
651 gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
653 if (info != ct->tip_info)
664 label = static_cast<GtkWidget *>(g_object_get_data(G_OBJECT(ct->tip_window), "tip_label"));
665 gtk_label_set_text(GTK_LABEL(label), ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
671 *-------------------------------------------------------------------
673 *-------------------------------------------------------------------
676 static void collection_table_popup_save_as_cb(GtkWidget *UNUSED(widget), gpointer data)
678 CollectTable *ct = static_cast<CollectTable *>(data);
680 collection_dialog_save_as(NULL, ct->cd);
683 static void collection_table_popup_save_cb(GtkWidget *widget, gpointer data)
685 CollectTable *ct = static_cast<CollectTable *>(data);
689 collection_table_popup_save_as_cb(widget, data);
693 if (!collection_save(ct->cd, ct->cd->path))
695 log_printf("failed saving to collection path: %s\n", ct->cd->path);
699 static GList *collection_table_popup_file_list(CollectTable *ct)
701 if (!ct->click_info) return NULL;
703 if (INFO_SELECTED(ct->click_info))
705 return collection_table_selection_get_list(ct);
708 return g_list_append(NULL, file_data_ref(ct->click_info->fd));
711 static void collection_table_popup_edit_cb(GtkWidget *widget, gpointer data)
714 const gchar *key = static_cast<const gchar *>(data);
716 ct = static_cast<CollectTable *>(submenu_item_get_data(widget));
720 file_util_start_editor_from_filelist(key, collection_table_popup_file_list(ct), NULL, ct->listview);
723 static void collection_table_popup_copy_cb(GtkWidget *UNUSED(widget), gpointer data)
725 CollectTable *ct = static_cast<CollectTable *>(data);
727 file_util_copy(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);
730 static void collection_table_popup_move_cb(GtkWidget *UNUSED(widget), gpointer data)
732 CollectTable *ct = static_cast<CollectTable *>(data);
734 file_util_move(NULL, collection_table_popup_file_list(ct), NULL, ct->listview);
737 static void collection_table_popup_rename_cb(GtkWidget *UNUSED(widget), gpointer data)
739 CollectTable *ct = static_cast<CollectTable *>(data);
741 file_util_rename(NULL, collection_table_popup_file_list(ct), ct->listview);
744 static void collection_table_popup_delete_cb(GtkWidget *UNUSED(widget), gpointer data)
746 CollectTable *ct = static_cast<CollectTable *>(data);
748 options->file_ops.safe_delete_enable = FALSE;
749 file_util_delete(NULL, collection_table_popup_file_list(ct), ct->listview);
752 static void collection_table_popup_move_to_trash_cb(GtkWidget *UNUSED(widget), gpointer data)
754 CollectTable *ct = static_cast<CollectTable *>(data);
756 options->file_ops.safe_delete_enable = TRUE;
757 file_util_delete(NULL, collection_table_popup_file_list(ct), ct->listview);
760 static void collection_table_popup_copy_path_cb(GtkWidget *UNUSED(widget), gpointer data)
762 CollectTable *ct = static_cast<CollectTable *>(data);
764 file_util_copy_path_list_to_clipboard(collection_table_popup_file_list(ct), TRUE);
767 static void collection_table_popup_copy_path_unquoted_cb(GtkWidget *UNUSED(widget), gpointer data)
769 CollectTable *ct = static_cast<CollectTable *>(data);
771 file_util_copy_path_list_to_clipboard(collection_table_popup_file_list(ct), FALSE);
774 static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data)
779 ct = static_cast<CollectTable *>(submenu_item_get_data(widget));
783 type = (SortType)GPOINTER_TO_INT(data);
785 collection_set_sort_method(ct->cd, type);
788 static void collection_table_popup_randomize_cb(GtkWidget *widget, gpointer UNUSED(data))
792 ct = static_cast<CollectTable *>(submenu_item_get_data(widget));
796 collection_randomize(ct->cd);
799 static void collection_table_popup_view_new_cb(GtkWidget *UNUSED(widget), gpointer data)
801 CollectTable *ct = static_cast<CollectTable *>(data);
803 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
805 view_window_new_from_collection(ct->cd, ct->click_info);
809 static void collection_table_popup_view_cb(GtkWidget *UNUSED(widget), gpointer data)
811 CollectTable *ct = static_cast<CollectTable *>(data);
813 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
815 layout_image_set_collection(NULL, ct->cd, ct->click_info);
819 static void collection_table_popup_selectall_cb(GtkWidget *UNUSED(widget), gpointer data)
821 CollectTable *ct = static_cast<CollectTable *>(data);
823 collection_table_select_all(ct);
824 ct->prev_selection= ct->click_info;
827 static void collection_table_popup_unselectall_cb(GtkWidget *UNUSED(widget), gpointer data)
829 CollectTable *ct = static_cast<CollectTable *>(data);
831 collection_table_unselect_all(ct);
832 ct->prev_selection= ct->click_info;
835 static void collection_table_popup_select_invert_cb(GtkWidget *UNUSED(widget), gpointer data)
837 CollectTable *ct = static_cast<CollectTable *>(data);
839 collection_table_select_invert_all(ct);
840 ct->prev_selection= ct->click_info;
843 static void collection_table_popup_rectangular_selection_cb(GtkWidget *UNUSED(widget), gpointer UNUSED(data))
845 options->collections.rectangular_selection = !(options->collections.rectangular_selection);
848 static void collection_table_popup_remove_cb(GtkWidget *UNUSED(widget), gpointer data)
850 CollectTable *ct = static_cast<CollectTable *>(data);
853 if (!ct->click_info) return;
855 if (INFO_SELECTED(ct->click_info))
857 list = g_list_copy(ct->selection);
861 list = g_list_append(NULL, ct->click_info);
864 collection_remove_by_info_list(ct->cd, list);
868 static void collection_table_popup_add_file_selection_cb(GtkWidget *UNUSED(widget), gpointer data)
870 CollectTable *ct = static_cast<CollectTable *>(data);
872 LayoutWindow *lw = NULL;
874 if (!layout_valid(&lw)) return;
876 list = vf_selection_get_list(lw->vf);
880 collection_table_add_filelist(ct, list);
885 static void collection_table_popup_add_collection_cb(GtkWidget *UNUSED(widget), gpointer data)
887 CollectTable *ct = static_cast<CollectTable *>(data);
889 collection_dialog_append(NULL, ct->cd);
892 static void collection_table_popup_goto_original_cb(GtkWidget *UNUSED(widget), gpointer data)
894 CollectTable *ct = static_cast<CollectTable *>(data);
896 LayoutWindow *lw = NULL;
899 if (!layout_valid(&lw)) return;
900 list = collection_table_selection_get_list(ct);
903 fd = static_cast<FileData *>(list->data);
906 layout_set_fd(lw, fd);
912 static void collection_table_popup_find_dupes_cb(GtkWidget *UNUSED(widget), gpointer data)
914 CollectTable *ct = static_cast<CollectTable *>(data);
917 dw = dupe_window_new();
918 dupe_window_add_collection(dw, ct->cd);
921 static void collection_table_popup_print_cb(GtkWidget *UNUSED(widget), gpointer data)
923 CollectTable *ct = static_cast<CollectTable *>(data);
926 fd = (ct->click_info) ? ct->click_info->fd : NULL;
928 print_window_new(fd, collection_table_selection_get_list(ct), collection_table_get_list(ct), gtk_widget_get_toplevel(ct->listview));
931 static void collection_table_popup_show_names_cb(GtkWidget *UNUSED(widget), gpointer data)
933 CollectTable *ct = static_cast<CollectTable *>(data);
935 collection_table_toggle_filenames(ct);
938 static void collection_table_popup_show_stars_cb(GtkWidget *UNUSED(widget), gpointer data)
940 CollectTable *ct = static_cast<CollectTable *>(data);
942 collection_table_toggle_stars(ct);
945 static void collection_table_popup_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
947 CollectTable *ct = static_cast<CollectTable *>(data);
949 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
950 ct->click_info = NULL;
953 filelist_free(ct->drop_list);
954 ct->drop_list = NULL;
955 ct->drop_info = NULL;
957 filelist_free(ct->editmenu_fd_list);
958 ct->editmenu_fd_list = NULL;
961 static GtkWidget *collection_table_popup_menu(CollectTable *ct, gboolean over_icon)
966 GtkAccelGroup *accel_group;
968 menu = popup_menu_short_lived();
970 accel_group = gtk_accel_group_new();
971 gtk_menu_set_accel_group(GTK_MENU(menu), accel_group);
973 g_object_set_data(G_OBJECT(menu), "window_keys", collection_window_keys);
974 g_object_set_data(G_OBJECT(menu), "accel_group", accel_group);
976 g_signal_connect(G_OBJECT(menu), "destroy",
977 G_CALLBACK(collection_table_popup_destroy_cb), ct);
979 menu_item_add_sensitive(menu, _("_View"), over_icon,
980 G_CALLBACK(collection_table_popup_view_cb), ct);
981 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, over_icon,
982 G_CALLBACK(collection_table_popup_view_new_cb), ct);
983 menu_item_add_stock(menu, _("Go to original"), GTK_STOCK_FIND,
984 G_CALLBACK(collection_table_popup_goto_original_cb), ct);
985 menu_item_add_divider(menu);
986 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, over_icon,
987 G_CALLBACK(collection_table_popup_remove_cb), ct);
989 menu_item_add_stock(menu, _("Append from file selection"), GTK_STOCK_ADD,
990 G_CALLBACK(collection_table_popup_add_file_selection_cb), ct);
991 menu_item_add_stock(menu, _("Append from collection..."), GTK_STOCK_OPEN,
992 G_CALLBACK(collection_table_popup_add_collection_cb), ct);
993 menu_item_add_divider(menu);
995 item = menu_item_add(menu, _("_Selection"), NULL, NULL);
996 submenu = gtk_menu_new();
997 menu_item_add(submenu, _("Select all"),
998 G_CALLBACK(collection_table_popup_selectall_cb), ct);
999 menu_item_add(submenu, _("Select none"),
1000 G_CALLBACK(collection_table_popup_unselectall_cb), ct);
1001 menu_item_add(submenu, _("Invert selection"),
1002 G_CALLBACK(collection_table_popup_select_invert_cb), ct);
1003 menu_item_add_check(submenu, _("Rectangular selection"), (options->collections.rectangular_selection != FALSE),
1004 G_CALLBACK(collection_table_popup_rectangular_selection_cb), ct);
1005 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1006 menu_item_add_divider(menu);
1009 ct->editmenu_fd_list = collection_table_selection_get_list(ct);
1010 submenu_add_edit(menu, &item,
1011 G_CALLBACK(collection_table_popup_edit_cb), ct, ct->editmenu_fd_list);
1012 gtk_widget_set_sensitive(item, over_icon);
1014 menu_item_add_divider(menu);
1015 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, over_icon,
1016 G_CALLBACK(collection_table_popup_copy_cb), ct);
1017 menu_item_add_sensitive(menu, _("_Move..."), over_icon,
1018 G_CALLBACK(collection_table_popup_move_cb), ct);
1019 menu_item_add_sensitive(menu, _("_Rename..."), over_icon,
1020 G_CALLBACK(collection_table_popup_rename_cb), ct);
1021 menu_item_add_sensitive(menu, _("_Copy path"), over_icon,
1022 G_CALLBACK(collection_table_popup_copy_path_cb), ct);
1023 menu_item_add_sensitive(menu, _("_Copy path unquoted"), over_icon,
1024 G_CALLBACK(collection_table_popup_copy_path_unquoted_cb), ct);
1026 menu_item_add_divider(menu);
1027 menu_item_add_stock_sensitive(menu,
1028 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
1029 _("Move to Trash"), PIXBUF_INLINE_ICON_TRASH, over_icon,
1030 G_CALLBACK(collection_table_popup_move_to_trash_cb), ct);
1031 menu_item_add_stock_sensitive(menu,
1032 options->file_ops.confirm_delete ? _("_Delete...") :
1033 _("_Delete"), GTK_STOCK_DELETE, over_icon,
1034 G_CALLBACK(collection_table_popup_delete_cb), ct);
1036 menu_item_add_divider(menu);
1037 submenu = submenu_add_sort(NULL, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, SORT_NONE);
1038 menu_item_add_divider(submenu);
1039 menu_item_add(submenu, _("Randomize"),
1040 G_CALLBACK(collection_table_popup_randomize_cb), ct);
1041 item = menu_item_add(menu, _("_Sort"), NULL, NULL);
1042 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1044 menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
1045 G_CALLBACK(collection_table_popup_show_names_cb), ct);
1046 menu_item_add_check(menu, _("Show star rating"), ct->show_stars,
1047 G_CALLBACK(collection_table_popup_show_stars_cb), ct);
1048 menu_item_add_divider(menu);
1049 menu_item_add_stock(menu, _("_Save collection"), GTK_STOCK_SAVE,
1050 G_CALLBACK(collection_table_popup_save_cb), ct);
1051 menu_item_add_stock(menu, _("Save collection _as..."), GTK_STOCK_SAVE_AS,
1052 G_CALLBACK(collection_table_popup_save_as_cb), ct);
1053 menu_item_add_divider(menu);
1054 menu_item_add_stock(menu, _("_Find duplicates..."), GTK_STOCK_FIND,
1055 G_CALLBACK(collection_table_popup_find_dupes_cb), ct);
1056 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, over_icon,
1057 G_CALLBACK(collection_table_popup_print_cb), ct);
1062 *-------------------------------------------------------------------
1063 * keyboard callbacks
1064 *-------------------------------------------------------------------
1067 void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
1072 if (g_list_find(ct->cd->list, ct->focus_info))
1074 if (info == ct->focus_info)
1076 /* ensure focus row col are correct */
1077 collection_table_find_position(ct, ct->focus_info,
1078 &ct->focus_row, &ct->focus_column);
1081 collection_table_selection_remove(ct, ct->focus_info, SELECTION_FOCUS, NULL);
1084 if (!collection_table_find_position(ct, info, &row, &col))
1086 ct->focus_info = NULL;
1088 ct->focus_column = -1;
1092 ct->focus_info = info;
1093 ct->focus_row = row;
1094 ct->focus_column = col;
1095 collection_table_selection_add(ct, ct->focus_info, SELECTION_FOCUS, NULL);
1097 if (collection_table_find_iter(ct, ct->focus_info, &iter, NULL))
1100 GtkTreeViewColumn *column;
1101 GtkTreeModel *store;
1103 tree_view_row_make_visible(GTK_TREE_VIEW(ct->listview), &iter, FALSE);
1105 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1106 tpath = gtk_tree_model_get_path(store, &iter);
1107 /* focus is set to an extra column with 0 width to hide focus, we draw it ourself */
1108 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), COLLECT_TABLE_MAX_COLUMNS);
1109 gtk_tree_view_set_cursor(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE);
1110 gtk_tree_path_free(tpath);
1114 static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gboolean relative)
1121 new_row = ct->focus_row;
1122 new_col = ct->focus_column;
1125 if (new_row < 0) new_row = 0;
1126 if (new_row >= ct->rows) new_row = ct->rows - 1;
1146 new_col = ct->columns - 1;
1153 if (new_col >= ct->columns)
1155 if (new_row < ct->rows - 1)
1162 new_col = ct->columns - 1;
1172 if (new_row >= ct->rows)
1175 new_row = ct->rows - 1;
1178 new_col = ct->columns - 1;
1180 if (new_col >= ct->columns) new_col = ct->columns - 1;
1183 if (new_row == ct->rows - 1)
1187 /* if we moved beyond the last image, go to the last image */
1189 l = g_list_length(ct->cd->list);
1190 if (ct->rows > 1) l -= (ct->rows - 1) * ct->columns;
1191 if (new_col >= l) new_col = l - 1;
1194 if (new_row == -1 || new_col == -1)
1196 if (!ct->cd->list) return;
1197 new_row = new_col = 0;
1200 collection_table_set_focus(ct, collection_table_find_data(ct, new_row, new_col, NULL));
1203 static void collection_table_update_focus(CollectTable *ct)
1208 if (ct->focus_info && collection_table_find_position(ct, ct->focus_info, &new_row, &new_col))
1210 /* first find the old focus, if it exists and is valid */
1214 /* (try to) stay where we were */
1215 new_row = ct->focus_row;
1216 new_col = ct->focus_column;
1219 collection_table_move_focus(ct, new_row, new_col, FALSE);
1222 /* used to figure the page up/down distances */
1223 static gint page_height(CollectTable *ct)
1230 adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
1231 page_size = (gint)gtk_adjustment_get_page_increment(adj);
1233 row_height = options->thumbnails.max_height + THUMB_BORDER_PADDING * 2;
1234 if (ct->show_text) row_height += options->thumbnails.max_height / 3;
1236 ret = page_size / row_height;
1237 if (ret < 1) ret = 1;
1242 static gboolean collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
1244 CollectTable *ct = static_cast<CollectTable *>(data);
1248 gboolean stop_signal = TRUE;
1250 switch (event->keyval)
1252 case GDK_KEY_Left: case GDK_KEY_KP_Left:
1255 case GDK_KEY_Right: case GDK_KEY_KP_Right:
1258 case GDK_KEY_Up: case GDK_KEY_KP_Up:
1261 case GDK_KEY_Down: case GDK_KEY_KP_Down:
1264 case GDK_KEY_Page_Up: case GDK_KEY_KP_Page_Up:
1265 focus_row = -page_height(ct);
1267 case GDK_KEY_Page_Down: case GDK_KEY_KP_Page_Down:
1268 focus_row = page_height(ct);
1270 case GDK_KEY_Home: case GDK_KEY_KP_Home:
1271 focus_row = -ct->focus_row;
1272 focus_col = -ct->focus_column;
1274 case GDK_KEY_End: case GDK_KEY_KP_End:
1275 focus_row = ct->rows - 1 - ct->focus_row;
1276 focus_col = ct->columns - 1 - ct->focus_column;
1279 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1282 ct->click_info = info;
1283 if (event->state & GDK_CONTROL_MASK)
1285 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1289 collection_table_unselect_all(ct);
1290 collection_table_select(ct, info);
1295 if (event->state & GDK_CONTROL_MASK) collection_table_toggle_filenames(ct);
1299 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1300 ct->click_info = info;
1302 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1305 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1306 gtk_menu_popup_at_widget(GTK_MENU(ct->popup), widget, GDK_GRAVITY_SOUTH, GDK_GRAVITY_CENTER, NULL);
1310 stop_signal = FALSE;
1314 if (focus_row != 0 || focus_col != 0)
1316 CollectInfo *new_info;
1317 CollectInfo *old_info;
1319 old_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1320 collection_table_move_focus(ct, focus_row, focus_col, TRUE);
1321 new_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
1323 if (new_info != old_info)
1325 if (event->state & GDK_SHIFT_MASK)
1327 if (!options->collections.rectangular_selection)
1329 collection_table_select_region_util(ct, old_info, new_info, FALSE);
1333 collection_table_select_region_util(ct, ct->click_info, old_info, FALSE);
1335 collection_table_select_region_util(ct, ct->click_info, new_info, TRUE);
1337 else if (event->state & GDK_CONTROL_MASK)
1339 ct->click_info = new_info;
1343 ct->click_info = new_info;
1344 collection_table_unselect_all(ct);
1345 collection_table_select(ct, new_info);
1359 *-------------------------------------------------------------------
1361 *-------------------------------------------------------------------
1364 static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gboolean *after, GdkRectangle *cell,
1365 gboolean use_coord, gint x, gint y)
1367 CollectInfo *info = NULL;
1368 GtkTreeModel *store;
1371 GtkTreeViewColumn *column;
1375 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1379 seat = gdk_display_get_default_seat(gdk_window_get_display(gtk_widget_get_window(ct->listview)));
1380 device = gdk_seat_get_pointer(seat);
1381 gdk_window_get_device_position(gtk_widget_get_window(ct->listview),
1382 device, &x, &y, NULL);
1388 if (collection_table_find_iter(ct, source, &iter, &col))
1390 tpath = gtk_tree_model_get_path(store, &iter);
1391 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1392 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1393 gtk_tree_path_free(tpath);
1396 *after = !!(x > cell->x + (cell->width / 2));
1401 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
1402 &tpath, &column, NULL, NULL))
1407 gtk_tree_model_get_iter(store, &iter, tpath);
1408 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1410 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
1411 info = static_cast<CollectInfo *>(g_list_nth_data(list, n));
1415 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1416 *after = !!(x > cell->x + (cell->width / 2));
1419 gtk_tree_path_free(tpath);
1426 work = g_list_last(ct->cd->list);
1431 info = static_cast<CollectInfo *>(work->data);
1434 if (collection_table_find_iter(ct, info, &iter, &col))
1436 tpath = gtk_tree_model_get_path(store, &iter);
1437 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1438 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1439 gtk_tree_path_free(tpath);
1447 static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint y)
1451 gboolean after = FALSE;
1453 info = collection_table_insert_find(ct, NULL, &after, &cell, TRUE, x, y);
1459 work = g_list_find(ct->cd->list, info);
1460 if (work && work->next)
1462 info = static_cast<CollectInfo *>(work->next->data);
1473 static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gboolean enable)
1475 gboolean after = FALSE;
1478 gint x_parent, y_parent;
1479 GError *error = NULL;
1480 GInputStream *in_stream;
1484 parent = gtk_widget_get_window(gtk_widget_get_toplevel(ct->listview));
1485 gdk_window_get_position(parent, &x_parent, &y_parent);
1489 if (ct->marker_window) gdk_window_destroy(ct->marker_window);
1490 ct->marker_window = NULL;
1495 info = collection_table_insert_find(ct, info, &after, &cell, FALSE, 0, 0);
1497 /* this setting does not take into account (after), but since it is not really used... */
1498 ct->marker_info = info;
1500 if (!ct->marker_window)
1502 GdkWindowAttr attributes;
1503 gint attributes_mask;
1505 path = g_build_filename(GQ_RESOURCE_PATH_ICONS, "gq-marker.xpm", NULL);
1506 in_stream = g_resources_open_stream(path, G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
1509 pb = gdk_pixbuf_new_from_stream(in_stream, NULL, &error);
1510 g_object_unref(in_stream);
1514 log_printf("warning: collection marker error: %s", error->message);
1515 g_error_free(error);
1519 gint w = gdk_pixbuf_get_width(pb);
1520 gint h = gdk_pixbuf_get_height(pb);
1522 attributes.window_type = GDK_WINDOW_CHILD;
1523 attributes.wclass = GDK_INPUT_OUTPUT;
1524 attributes.width = w;
1525 attributes.height = h;
1526 attributes.event_mask = gtk_widget_get_events(ct->listview);
1527 attributes_mask = 0;
1529 ct->marker_window = gdk_window_new(NULL, &attributes, attributes_mask);
1531 cairo_region_t *mask;
1532 cairo_pattern_t *pattern;
1533 cairo_surface_t *img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
1534 cairo_t *cr = cairo_create(img);
1535 gdk_cairo_set_source_pixbuf(cr, pb, 0, 0);
1537 /** @FIXME this is a hack to get the background color */
1538 //~ pattern = cairo_pattern_create_for_surface(img);
1539 pattern = cairo_pattern_create_rgb (1.0, 0.0, 0.0);
1540 mask = gdk_cairo_region_create_from_surface(img);
1541 gdk_window_shape_combine_region(ct->marker_window, mask, 0, 0);
1542 gdk_window_set_background_pattern(ct->marker_window, pattern);
1543 cairo_region_destroy(mask);
1544 cairo_pattern_destroy(pattern);
1546 cairo_surface_destroy(img);
1555 w = gdk_window_get_width(ct->marker_window);
1556 h = gdk_window_get_height(ct->marker_window);
1564 x = cell.x + cell.width;
1567 y = cell.y + (cell.height / 2) - (h / 2);
1572 gdk_window_move(ct->marker_window, x, y);
1574 if (!gdk_window_is_visible(ct->marker_window)) gdk_window_show(ct->marker_window);
1578 if (gdk_window_is_visible(ct->marker_window)) gdk_window_hide(ct->marker_window);
1583 *-------------------------------------------------------------------
1584 * mouse drag auto-scroll
1585 *-------------------------------------------------------------------
1588 static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gboolean drop_event)
1592 info = collection_table_find_data_by_coord(ct, x, y, NULL);
1597 collection_table_insert_marker(ct, info, TRUE);
1601 tip_update(ct, info);
1605 static gboolean collection_table_auto_scroll_idle_cb(gpointer data)
1607 CollectTable *ct = static_cast<CollectTable *>(data);
1614 if (!ct->drop_idle_id) return G_SOURCE_REMOVE;
1616 window = gtk_widget_get_window(ct->listview);
1617 seat = gdk_display_get_default_seat(gdk_window_get_display(window));
1618 device = gdk_seat_get_pointer(seat);
1619 gdk_window_get_device_position(window, device, &x, &y, NULL);
1621 w = gdk_window_get_width(window);
1622 h = gdk_window_get_height(window);
1623 if (x >= 0 && x < w && y >= 0 && y < h)
1625 collection_table_motion_update(ct, x, y, TRUE);
1628 ct->drop_idle_id = 0;
1629 return G_SOURCE_REMOVE;
1632 static gboolean collection_table_auto_scroll_notify_cb(GtkWidget *UNUSED(widget), gint UNUSED(x), gint UNUSED(y), gpointer data)
1634 CollectTable *ct = static_cast<CollectTable *>(data);
1636 if (!ct->drop_idle_id)
1638 ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
1644 static void collection_table_scroll(CollectTable *ct, gboolean scroll)
1648 if (ct->drop_idle_id)
1650 g_source_remove(ct->drop_idle_id);
1651 ct->drop_idle_id = 0;
1653 widget_auto_scroll_stop(ct->listview);
1654 collection_table_insert_marker(ct, NULL, FALSE);
1658 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
1659 widget_auto_scroll_start(ct->listview, adj, -1, options->thumbnails.max_height / 2,
1660 collection_table_auto_scroll_notify_cb, ct);
1665 *-------------------------------------------------------------------
1667 *-------------------------------------------------------------------
1670 static gboolean collection_table_motion_cb(GtkWidget *UNUSED(widget), GdkEventMotion *event, gpointer data)
1672 CollectTable *ct = static_cast<CollectTable *>(data);
1674 collection_table_motion_update(ct, (gint)event->x, (gint)event->y, FALSE);
1679 static gboolean collection_table_press_cb(GtkWidget *UNUSED(widget), GdkEventButton *bevent, gpointer data)
1681 CollectTable *ct = static_cast<CollectTable *>(data);
1687 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1689 ct->click_info = info;
1690 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, &iter);
1692 switch (bevent->button)
1694 case MOUSE_BUTTON_LEFT:
1695 if (bevent->type == GDK_2BUTTON_PRESS)
1699 layout_image_set_collection(NULL, ct->cd, info);
1702 else if (!gtk_widget_has_focus(ct->listview))
1704 gtk_widget_grab_focus(ct->listview);
1707 case MOUSE_BUTTON_RIGHT:
1708 ct->popup = collection_table_popup_menu(ct, (info != NULL));
1709 gtk_menu_popup_at_pointer(GTK_MENU(ct->popup), NULL);
1718 static gboolean collection_table_release_cb(GtkWidget *UNUSED(widget), GdkEventButton *bevent, gpointer data)
1720 CollectTable *ct = static_cast<CollectTable *>(data);
1722 CollectInfo *info = NULL;
1726 if ((gint)bevent->x != 0 || (gint)bevent->y != 0)
1728 info = collection_table_find_data_by_coord(ct, (gint)bevent->x, (gint)bevent->y, &iter);
1733 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, NULL);
1736 if (bevent->button == MOUSE_BUTTON_LEFT &&
1737 info && ct->click_info == info)
1739 collection_table_set_focus(ct, info);
1741 if (bevent->state & GDK_CONTROL_MASK)
1743 gboolean select = !INFO_SELECTED(info);
1745 if ((bevent->state & GDK_SHIFT_MASK) && ct->prev_selection)
1747 collection_table_select_region_util(ct, ct->prev_selection, info, select);
1751 collection_table_select_util(ct, info, select);
1756 collection_table_unselect_all(ct);
1758 if ((bevent->state & GDK_SHIFT_MASK) &&
1761 collection_table_select_region_util(ct, ct->prev_selection, info, TRUE);
1765 collection_table_select_util(ct, info, TRUE);
1769 else if (bevent->button == MOUSE_BUTTON_MIDDLE &&
1770 info && ct->click_info == info)
1772 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1778 static gboolean collection_table_leave_cb(GtkWidget *UNUSED(widget), GdkEventCrossing *UNUSED(event), gpointer data)
1780 CollectTable *ct = static_cast<CollectTable *>(data);
1787 *-------------------------------------------------------------------
1788 * populate, add, insert, etc.
1789 *-------------------------------------------------------------------
1792 static gboolean collection_table_destroy_node_cb(GtkTreeModel *store, GtkTreePath *UNUSED(tpath), GtkTreeIter *iter, gpointer UNUSED(data))
1796 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
1802 static void collection_table_clear_store(CollectTable *ct)
1804 GtkTreeModel *store;
1806 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1807 gtk_tree_model_foreach(store, collection_table_destroy_node_cb, NULL);
1809 gtk_list_store_clear(GTK_LIST_STORE(store));
1812 static GList *collection_table_add_row(CollectTable *ct, GtkTreeIter *iter)
1814 GtkListStore *store;
1818 for (i = 0; i < ct->columns; i++) list = g_list_prepend(list, NULL);
1820 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)));
1821 gtk_list_store_append(store, iter);
1822 gtk_list_store_set(store, iter, CTABLE_COLUMN_POINTER, list, -1);
1827 static void collection_table_populate(CollectTable *ct, gboolean resize)
1832 collection_table_verify_selections(ct);
1834 collection_table_clear_store(ct);
1841 thumb_width = collection_table_get_icon_width(ct);
1843 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
1845 GtkTreeViewColumn *column;
1846 GtkCellRenderer *cell;
1849 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), i);
1850 gtk_tree_view_column_set_visible(column, (i < ct->columns));
1851 gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6));
1853 list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
1854 cell = static_cast<GtkCellRenderer *>((list) ? list->data : NULL);
1857 if (cell && GQV_IS_CELL_RENDERER_ICON(cell))
1859 g_object_set(G_OBJECT(cell), "fixed_width", thumb_width,
1860 "fixed_height", options->thumbnails.max_height,
1861 "show_text", ct->show_text || ct->show_stars, NULL);
1864 if (gtk_widget_get_realized(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
1868 work = ct->cd->list;
1876 list = collection_table_add_row(ct, &iter);
1877 while (work && list)
1879 list->data = work->data;
1887 collection_table_update_focus(ct);
1888 collection_table_update_status(ct);
1891 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint UNUSED(h), gboolean force)
1896 thumb_width = collection_table_get_icon_width(ct);
1898 new_cols = w / (thumb_width + (THUMB_BORDER_PADDING * 6));
1899 if (new_cols < 1) new_cols = 1;
1901 if (!force && new_cols == ct->columns) return;
1903 ct->columns = new_cols;
1905 collection_table_populate(ct, TRUE);
1907 DEBUG_1("col tab pop cols=%d rows=%d", ct->columns, ct->rows);
1910 static void collection_table_sync(CollectTable *ct)
1912 GtkTreeModel *store;
1917 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1922 work = ct->cd->list;
1928 if (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1930 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1931 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1935 list = collection_table_add_row(ct, &iter);
1943 info = static_cast<CollectInfo *>(work->data);
1960 while (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1964 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1965 gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
1971 collection_table_update_focus(ct);
1972 collection_table_update_status(ct);
1975 static gboolean collection_table_sync_idle_cb(gpointer data)
1977 CollectTable *ct = static_cast<CollectTable *>(data);
1979 if (!ct->sync_idle_id) return G_SOURCE_REMOVE;
1980 g_source_remove(ct->sync_idle_id);
1981 ct->sync_idle_id = 0;
1983 collection_table_sync(ct);
1984 return G_SOURCE_REMOVE;
1987 static void collection_table_sync_idle(CollectTable *ct)
1989 if (!ct->sync_idle_id)
1991 /* high priority, the view needs to be resynced before a redraw
1992 * may contain invalid pointers at this time
1994 ct->sync_idle_id = g_idle_add_full(G_PRIORITY_HIGH, collection_table_sync_idle_cb, ct, NULL);
1998 void collection_table_add_filelist(CollectTable *ct, GList *list)
2007 collection_add(ct->cd, (FileData *)work->data, FALSE);
2012 static void collection_table_insert_filelist(CollectTable *ct, GList *list, CollectInfo *insert_info)
2021 collection_insert(ct->cd, (FileData *)work->data, insert_info, FALSE);
2025 collection_table_sync_idle(ct);
2028 static void collection_table_move_by_info_list(CollectTable *ct, GList *info_list, gint row, gint col)
2031 GList *insert_pos = NULL;
2035 if (!info_list) return;
2037 info = collection_table_find_data(ct, row, col, NULL);
2039 if (!info_list->next && info_list->data == info) return;
2041 if (info) insert_pos = g_list_find(ct->cd->list, info);
2043 /** @FIXME this may get slow for large lists */
2045 while (insert_pos && work)
2047 if (insert_pos->data == work->data)
2049 insert_pos = insert_pos->next;
2061 ct->cd->list = g_list_remove(ct->cd->list, work->data);
2065 /* place them back in */
2066 temp = g_list_copy(info_list);
2070 ct->cd->list = uig_list_insert_list(ct->cd->list, insert_pos, temp);
2074 ct->cd->list = g_list_concat(temp, ct->cd->list);
2078 ct->cd->list = g_list_concat(ct->cd->list, temp);
2081 ct->cd->changed = TRUE;
2083 collection_table_sync_idle(ct);
2088 *-------------------------------------------------------------------
2090 *-------------------------------------------------------------------
2093 void collection_table_file_update(CollectTable *ct, CollectInfo *info)
2101 collection_table_update_extras(ct, FALSE, 0.0);
2105 if (!collection_table_find_position(ct, info, &row, &col)) return;
2107 if (ct->columns != 0 && ct->rows != 0)
2109 value = (gdouble)(row * ct->columns + col) / (ct->columns * ct->rows);
2116 collection_table_update_extras(ct, TRUE, value);
2118 if (collection_table_find_iter(ct, info, &iter, NULL))
2120 GtkTreeModel *store;
2123 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
2124 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
2125 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
2129 void collection_table_file_add(CollectTable *ct, CollectInfo *UNUSED(info))
2131 collection_table_sync_idle(ct);
2134 void collection_table_file_insert(CollectTable *ct, CollectInfo *UNUSED(ci))
2136 collection_table_sync_idle(ct);
2139 void collection_table_file_remove(CollectTable *ct, CollectInfo *ci)
2141 if (ci && INFO_SELECTED(ci))
2143 ct->selection = g_list_remove(ct->selection, ci);
2146 collection_table_sync_idle(ct);
2149 void collection_table_refresh(CollectTable *ct)
2151 collection_table_populate(ct, FALSE);
2155 *-------------------------------------------------------------------
2157 *-------------------------------------------------------------------
2160 static void collection_table_add_dir_recursive(CollectTable *ct, FileData *dir_fd, gboolean recursive)
2166 if (!filelist_read(dir_fd, &f, recursive ? &d : NULL))
2169 f = filelist_filter(f, FALSE);
2170 d = filelist_filter(d, TRUE);
2172 f = filelist_sort_path(f);
2173 d = filelist_sort_path(d);
2175 collection_table_insert_filelist(ct, f, ct->marker_info);
2177 work = g_list_last(d);
2180 collection_table_add_dir_recursive(ct, (FileData *)work->data, TRUE);
2188 static void confirm_dir_list_do(CollectTable *ct, GList *list, gboolean recursive)
2193 FileData *fd = static_cast<FileData *>(work->data);
2195 if (isdir(fd->path)) collection_table_add_dir_recursive(ct, fd, recursive);
2197 collection_table_insert_filelist(ct, list, ct->marker_info);
2201 static void confirm_dir_list_add(GtkWidget *UNUSED(widget), gpointer data)
2203 CollectTable *ct = static_cast<CollectTable *>(data);
2205 confirm_dir_list_do(ct, ct->drop_list, FALSE);
2208 static void confirm_dir_list_recurse(GtkWidget *UNUSED(widget), gpointer data)
2210 CollectTable *ct = static_cast<CollectTable *>(data);
2212 confirm_dir_list_do(ct, ct->drop_list, TRUE);
2215 static void confirm_dir_list_skip(GtkWidget *UNUSED(widget), gpointer data)
2217 CollectTable *ct = static_cast<CollectTable *>(data);
2219 collection_table_insert_filelist(ct, ct->drop_list, ct->marker_info);
2222 static GtkWidget *collection_table_drop_menu(CollectTable *ct)
2226 menu = popup_menu_short_lived();
2227 g_signal_connect(G_OBJECT(menu), "destroy",
2228 G_CALLBACK(collection_table_popup_destroy_cb), ct);
2230 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL);
2231 menu_item_add_divider(menu);
2232 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK,
2233 G_CALLBACK(confirm_dir_list_add), ct);
2234 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD,
2235 G_CALLBACK(confirm_dir_list_recurse), ct);
2236 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE,
2237 G_CALLBACK(confirm_dir_list_skip), ct);
2238 menu_item_add_divider(menu);
2239 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, ct);
2245 *-------------------------------------------------------------------
2247 *-------------------------------------------------------------------
2250 static GtkTargetEntry collection_drag_types[] = {
2251 { const_cast<gchar *>(TARGET_APP_COLLECTION_MEMBER_STRING), 0, TARGET_APP_COLLECTION_MEMBER },
2252 { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST },
2253 { const_cast<gchar *>("text/plain"), 0, TARGET_TEXT_PLAIN }
2255 static gint n_collection_drag_types = 3;
2257 static GtkTargetEntry collection_drop_types[] = {
2258 { const_cast<gchar *>(TARGET_APP_COLLECTION_MEMBER_STRING), 0, TARGET_APP_COLLECTION_MEMBER },
2259 { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST }
2261 static gint n_collection_drop_types = 2;
2264 static void collection_table_dnd_get(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(context),
2265 GtkSelectionData *selection_data, guint info,
2266 guint UNUSED(time), gpointer data)
2268 CollectTable *ct = static_cast<CollectTable *>(data);
2271 gchar *uri_text = NULL;
2274 if (!ct->click_info) return;
2276 selected = INFO_SELECTED(ct->click_info);
2280 case TARGET_APP_COLLECTION_MEMBER:
2283 uri_text = collection_info_list_to_dnd_data(ct->cd, ct->selection, &total);
2287 list = g_list_append(NULL, ct->click_info);
2288 uri_text = collection_info_list_to_dnd_data(ct->cd, list, &total);
2291 gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
2292 8, (guchar *)uri_text, total);
2295 case TARGET_URI_LIST:
2296 case TARGET_TEXT_PLAIN:
2300 list = collection_table_selection_get_list(ct);
2304 list = g_list_append(NULL, file_data_ref(ct->click_info->fd));
2308 uri_selection_data_set_uris_from_filelist(selection_data, list);
2309 filelist_free(list);
2315 static void collection_table_dnd_receive(GtkWidget *UNUSED(widget), GdkDragContext *context,
2317 GtkSelectionData *selection_data, guint info,
2318 guint UNUSED(time), gpointer data)
2320 CollectTable *ct = static_cast<CollectTable *>(data);
2322 GList *info_list = NULL;
2323 CollectionData *source;
2324 CollectInfo *drop_info;
2327 DEBUG_1("%s", gtk_selection_data_get_data(selection_data));
2329 collection_table_scroll(ct, FALSE);
2330 collection_table_insert_marker(ct, NULL, FALSE);
2332 drop_info = collection_table_insert_point(ct, x, y);
2336 case TARGET_APP_COLLECTION_MEMBER:
2337 source = collection_from_dnd_data((gchar *)gtk_selection_data_get_data(selection_data), &list, &info_list);
2340 if (source == ct->cd)
2345 /* it is a move within a collection */
2346 filelist_free(list);
2351 collection_table_move_by_info_list(ct, info_list, -1, -1);
2353 else if (collection_table_find_position(ct, drop_info, &row, &col))
2355 collection_table_move_by_info_list(ct, info_list, row, col);
2360 /* it is a move/copy across collections */
2361 if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
2363 collection_remove_by_info_list(source, info_list);
2366 g_list_free(info_list);
2369 case TARGET_URI_LIST:
2370 list = uri_filelist_from_gtk_selection_data(selection_data);
2374 FileData *fd = static_cast<FileData *>(work->data);
2375 if (isdir(fd->path))
2379 ct->drop_list = list;
2380 ct->drop_info = drop_info;
2381 menu = collection_table_drop_menu(ct);
2382 gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL);
2395 collection_table_insert_filelist(ct, list, drop_info);
2396 filelist_free(list);
2400 static void collection_table_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
2402 CollectTable *ct = static_cast<CollectTable *>(data);
2404 if (ct->click_info && ct->click_info->pixbuf)
2408 if (INFO_SELECTED(ct->click_info))
2409 items = g_list_length(ct->selection);
2412 dnd_set_drag_icon(widget, context, ct->click_info->pixbuf, items);
2416 static void collection_table_dnd_end(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(context), gpointer data)
2418 CollectTable *ct = static_cast<CollectTable *>(data);
2420 /* apparently a leave event is not generated on a drop */
2423 collection_table_scroll(ct, FALSE);
2426 static gint collection_table_dnd_motion(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(context),
2427 gint x, gint y, guint UNUSED(time), gpointer data)
2429 CollectTable *ct = static_cast<CollectTable *>(data);
2431 collection_table_motion_update(ct, x, y, TRUE);
2432 collection_table_scroll(ct, TRUE);
2437 static void collection_table_dnd_leave(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(context), guint UNUSED(time), gpointer data)
2439 CollectTable *ct = static_cast<CollectTable *>(data);
2441 collection_table_scroll(ct, FALSE);
2444 static void collection_table_dnd_init(CollectTable *ct)
2446 gtk_drag_source_set(ct->listview, static_cast<GdkModifierType>(GDK_BUTTON1_MASK | GDK_BUTTON2_MASK),
2447 collection_drag_types, n_collection_drag_types,
2448 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
2449 g_signal_connect(G_OBJECT(ct->listview), "drag_data_get",
2450 G_CALLBACK(collection_table_dnd_get), ct);
2451 g_signal_connect(G_OBJECT(ct->listview), "drag_begin",
2452 G_CALLBACK(collection_table_dnd_begin), ct);
2453 g_signal_connect(G_OBJECT(ct->listview), "drag_end",
2454 G_CALLBACK(collection_table_dnd_end), ct);
2456 gtk_drag_dest_set(ct->listview,
2457 static_cast<GtkDestDefaults>(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP),
2458 collection_drop_types, n_collection_drop_types,
2459 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK));
2460 g_signal_connect(G_OBJECT(ct->listview), "drag_motion",
2461 G_CALLBACK(collection_table_dnd_motion), ct);
2462 g_signal_connect(G_OBJECT(ct->listview), "drag_leave",
2463 G_CALLBACK(collection_table_dnd_leave), ct);
2464 g_signal_connect(G_OBJECT(ct->listview), "drag_data_received",
2465 G_CALLBACK(collection_table_dnd_receive), ct);
2469 *-----------------------------------------------------------------------------
2471 *-----------------------------------------------------------------------------
2474 typedef struct _ColumnData ColumnData;
2481 static void collection_table_cell_data_cb(GtkTreeViewColumn *UNUSED(tree_column), GtkCellRenderer *cell,
2482 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
2484 ColumnData *cd = static_cast<ColumnData *>(data);
2491 gchar *star_rating = NULL;
2492 gchar *display_text = NULL;
2496 gtk_tree_model_get(tree_model, iter, CTABLE_COLUMN_POINTER, &list, -1);
2498 /** @FIXME this is a primitive hack to stop a crash.
2499 * When compiled with GTK3, if a Collection window containing
2500 * say, 50 or so, images has its width changed, there is a segfault
2501 * https://github.com/BestImageViewer/geeqie/issues/531
2503 if (cd->number == COLLECT_TABLE_MAX_COLUMNS) return;
2505 info = static_cast<CollectInfo *>(g_list_nth_data(list, cd->number));
2507 style = gtk_widget_get_style(ct->listview);
2508 if (info && (info->flag_mask & SELECTION_SELECTED) )
2510 memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg));
2511 memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg));
2515 memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg));
2516 memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg));
2519 if (info && (info->flag_mask & SELECTION_PRELIGHT))
2521 shift_color(&color_bg, -1, 0);
2524 if (ct->show_stars && info && info->fd)
2526 star_rating = metadata_read_rating_stars(info->fd);
2530 star_rating = g_strdup("");
2533 if (info && info->fd)
2535 if (ct->show_text && ct->show_stars)
2537 display_text = g_strconcat(info->fd->name, "\n", star_rating, NULL);
2539 else if (ct->show_text)
2541 display_text = g_strdup(info->fd->name);
2543 else if (ct->show_stars)
2545 display_text = g_strdup(star_rating);
2549 display_text = g_strdup("");
2554 display_text = g_strdup("");
2557 if (GQV_IS_CELL_RENDERER_ICON(cell))
2561 g_object_set(cell, "pixbuf", info->pixbuf,
2562 "text", display_text,
2563 "cell-background-gdk", &color_bg,
2564 "cell-background-set", TRUE,
2565 "foreground-gdk", &color_fg,
2566 "foreground-set", TRUE,
2567 "has-focus", (ct->focus_info == info), NULL);
2571 g_object_set(cell, "pixbuf", NULL,
2573 "cell-background-set", FALSE,
2574 "foreground-set", FALSE,
2575 "has-focus", FALSE, NULL);
2579 g_free(display_text);
2580 g_free(star_rating);
2583 static void collection_table_append_column(CollectTable *ct, gint n)
2586 GtkTreeViewColumn *column;
2587 GtkCellRenderer *renderer;
2589 column = gtk_tree_view_column_new();
2590 gtk_tree_view_column_set_min_width(column, 0);
2592 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
2593 gtk_tree_view_column_set_alignment(column, 0.5);
2595 renderer = gqv_cell_renderer_icon_new();
2596 gtk_tree_view_column_pack_start(column, renderer, FALSE);
2597 g_object_set(G_OBJECT(renderer), "xpad", THUMB_BORDER_PADDING * 2,
2598 "ypad", THUMB_BORDER_PADDING,
2599 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
2601 g_object_set_data(G_OBJECT(column), "column_number", GINT_TO_POINTER(n));
2603 cd = g_new0(ColumnData, 1);
2606 gtk_tree_view_column_set_cell_data_func(column, renderer, collection_table_cell_data_cb, cd, g_free);
2608 gtk_tree_view_append_column(GTK_TREE_VIEW(ct->listview), column);
2612 *-------------------------------------------------------------------
2614 *-------------------------------------------------------------------
2617 static void collection_table_destroy(GtkWidget *UNUSED(widget), gpointer data)
2619 CollectTable *ct = static_cast<CollectTable *>(data);
2621 /* If there is no unsaved data, save the window geometry
2623 if (!ct->cd->changed)
2625 if (!collection_save(ct->cd, ct->cd->path))
2627 log_printf("failed saving to collection path: %s\n", ct->cd->path);
2633 g_signal_handlers_disconnect_matched(G_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA,
2635 gtk_widget_destroy(ct->popup);
2638 if (ct->sync_idle_id) g_source_remove(ct->sync_idle_id);
2641 collection_table_scroll(ct, FALSE);
2646 static void collection_table_sized(GtkWidget *UNUSED(widget), GtkAllocation *allocation, gpointer data)
2648 CollectTable *ct = static_cast<CollectTable *>(data);
2650 collection_table_populate_at_new_size(ct, allocation->width, allocation->height, FALSE);
2653 CollectTable *collection_table_new(CollectionData *cd)
2656 GtkListStore *store;
2657 GtkTreeSelection *selection;
2660 ct = g_new0(CollectTable, 1);
2663 ct->show_text = options->show_icon_names;
2664 ct->show_stars = options->show_star_rating;
2666 ct->scrolled = gtk_scrolled_window_new(NULL, NULL);
2667 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN);
2668 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ct->scrolled),
2669 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2671 store = gtk_list_store_new(1, G_TYPE_POINTER);
2672 ct->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
2673 g_object_unref(store);
2675 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ct->listview));
2676 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_NONE);
2678 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ct->listview), FALSE);
2679 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ct->listview), FALSE);
2681 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
2683 collection_table_append_column(ct, i);
2686 /* zero width column to hide tree view focus, we draw it ourselves */
2687 collection_table_append_column(ct, i);
2688 /* end column to fill white space */
2689 collection_table_append_column(ct, i);
2691 g_signal_connect(G_OBJECT(ct->listview), "destroy",
2692 G_CALLBACK(collection_table_destroy), ct);
2693 g_signal_connect(G_OBJECT(ct->listview), "size_allocate",
2694 G_CALLBACK(collection_table_sized), ct);
2695 g_signal_connect(G_OBJECT(ct->listview), "key_press_event",
2696 G_CALLBACK(collection_table_press_key_cb), ct);
2698 gtk_container_add(GTK_CONTAINER(ct->scrolled), ct->listview);
2699 gtk_widget_show(ct->listview);
2701 collection_table_dnd_init(ct);
2703 gtk_widget_set_events(ct->listview, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK |
2704 static_cast<GdkEventMask>(GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK));
2705 g_signal_connect(G_OBJECT(ct->listview),"button_press_event",
2706 G_CALLBACK(collection_table_press_cb), ct);
2707 g_signal_connect(G_OBJECT(ct->listview),"button_release_event",
2708 G_CALLBACK(collection_table_release_cb), ct);
2709 g_signal_connect(G_OBJECT(ct->listview),"motion_notify_event",
2710 G_CALLBACK(collection_table_motion_cb), ct);
2711 g_signal_connect(G_OBJECT(ct->listview), "leave_notify_event",
2712 G_CALLBACK(collection_table_leave_cb), ct);
2717 void collection_table_set_labels(CollectTable *ct, GtkWidget *status, GtkWidget *extra)
2719 ct->status_label = status;
2720 ct->extra_label = extra;
2721 collection_table_update_status(ct);
2722 collection_table_update_extras(ct, FALSE, 0.0);
2725 CollectInfo *collection_table_get_focus_info(CollectTable *ct)
2727 return collection_table_find_data(ct, ct->focus_row, ct->focus_column, NULL);
2730 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */