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"
37 #include "pixbuf-util.h"
40 #include "ui-fileops.h"
42 #include "ui-tree-edit.h"
43 #include "uri-utils.h"
44 #include "view-file.h"
46 /* between these, the icon width is increased by thumb_max_width / 2 */
48 THUMB_MIN_ICON_WIDTH = 128,
49 THUMB_MAX_ICON_WIDTH = 150
53 COLLECT_TABLE_MAX_COLUMNS = 32,
54 THUMB_BORDER_PADDING = 2
58 COLLECT_TABLE_TIP_DELAY = 500,
59 COLLECT_TABLE_TIP_DELAY_PATH = 850
63 CTABLE_COLUMN_POINTER = 0,
67 #define INFO_SELECTED(x) ((x)->flag_mask & SELECTION_SELECTED)
70 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gboolean force);
73 * This array must be kept in sync with the contents of:\n
74 * @link collection_table_press_key_cb @endlink \n
75 * @link collection_window_keypress @endlink \n
76 * @link collection_table_popup_menu @endlink
78 * See also @link hard_coded_window_keys @endlink
80 hard_coded_window_keys collection_window_keys[] = {
81 {GDK_CONTROL_MASK, 'C', N_("Copy")},
82 {GDK_CONTROL_MASK, 'M', N_("Move")},
83 {GDK_CONTROL_MASK, 'R', N_("Rename")},
84 {GDK_CONTROL_MASK, 'D', N_("Move to Trash")},
85 {GDK_CONTROL_MASK, 'W', N_("Close window")},
86 {static_cast<GdkModifierType>(0), GDK_KEY_Delete, N_("Remove")},
87 {static_cast<GdkModifierType>(0), GDK_KEY_Return, N_("View")},
88 {static_cast<GdkModifierType>(0), 'V', N_("View in new window")},
89 {GDK_CONTROL_MASK, 'A', N_("Select all")},
90 {static_cast<GdkModifierType>(GDK_CONTROL_MASK + GDK_SHIFT_MASK), 'A', N_("Select none")},
91 {GDK_MOD1_MASK, 'R', N_("Rectangular selection")},
92 {static_cast<GdkModifierType>(0), GDK_KEY_space, N_("Select single file")},
93 {GDK_CONTROL_MASK, GDK_KEY_space, N_("Toggle select image")},
94 {GDK_CONTROL_MASK, 'L', N_("Append from file selection")},
95 {static_cast<GdkModifierType>(0), 'A', N_("Append from collection")},
96 {static_cast<GdkModifierType>(0), 'S', N_("Save collection")},
97 {GDK_CONTROL_MASK, 'S', N_("Save collection as")},
98 {GDK_CONTROL_MASK, 'T', N_("Show filename text")},
99 {static_cast<GdkModifierType>(0), 'N', N_("Sort by name")},
100 {static_cast<GdkModifierType>(0), 'D', N_("Sort by date")},
101 {static_cast<GdkModifierType>(0), 'B', N_("Sort by size")},
102 {static_cast<GdkModifierType>(0), 'P', N_("Sort by path")},
103 {GDK_SHIFT_MASK, 'P', N_("Print")},
104 {GDK_MOD1_MASK, 'A', N_("Append (Append collection dialog)")},
105 {GDK_MOD1_MASK, 'D', N_("Discard (Close modified collection dialog)")},
106 {static_cast<GdkModifierType>(0), 0, nullptr}
110 *-------------------------------------------------------------------
112 *-------------------------------------------------------------------
115 static gboolean collection_table_find_position(CollectTable *ct, CollectInfo *info, gint *row, gint *col)
119 n = g_list_index(ct->cd->list, info);
121 if (n < 0) return FALSE;
123 *row = n / ct->columns;
124 *col = n - (*row * ct->columns);
129 static gboolean collection_table_find_iter(CollectTable *ct, CollectInfo *info, GtkTreeIter *iter, gint *column)
134 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
135 if (!collection_table_find_position(ct, info, &row, &col)) return FALSE;
136 if (!gtk_tree_model_iter_nth_child(store, iter, nullptr, row)) return FALSE;
137 if (column) *column = col;
142 static CollectInfo *collection_table_find_data(CollectTable *ct, gint row, gint col, GtkTreeIter *iter)
147 if (row < 0 || col < 0) return nullptr;
149 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
150 if (gtk_tree_model_iter_nth_child(store, &p, nullptr, row))
154 gtk_tree_model_get(store, &p, CTABLE_COLUMN_POINTER, &list, -1);
155 if (!list) return nullptr;
159 return static_cast<CollectInfo *>(g_list_nth_data(list, col));
165 static CollectInfo *collection_table_find_data_by_coord(CollectTable *ct, gint x, gint y, GtkTreeIter *iter)
168 GtkTreeViewColumn *column;
174 if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
175 &tpath, &column, nullptr, nullptr))
178 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
179 gtk_tree_model_get_iter(store, &row, tpath);
180 gtk_tree_path_free(tpath);
182 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
183 if (!list) return nullptr;
185 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
186 if (iter) *iter = row;
187 return static_cast<CollectInfo *>(g_list_nth_data(list, n));
190 static guint collection_table_list_count(CollectTable *ct, gint64 *bytes)
200 auto ci = static_cast<CollectInfo *>(work->data);
208 return g_list_length(ct->cd->list);
211 static guint collection_table_selection_count(CollectTable *ct, gint64 *bytes)
218 work = ct->selection;
221 auto ci = static_cast<CollectInfo *>(work->data);
229 return g_list_length(ct->selection);
232 static void collection_table_update_status(CollectTable *ct)
240 if (!ct->status_label) return;
242 n = collection_table_list_count(ct, &n_bytes);
243 s = collection_table_selection_count(ct, &s_bytes);
247 gchar *b = text_from_size_abrev(n_bytes);
248 gchar *sb = text_from_size_abrev(s_bytes);
249 buf = g_strdup_printf(_("%s, %d images (%s, %d)"), b, n, sb, s);
255 gchar *b = text_from_size_abrev(n_bytes);
256 buf = g_strdup_printf(_("%s, %d images"), b, n);
261 buf = g_strdup(_("Empty"));
264 gtk_label_set_text(GTK_LABEL(ct->status_label), buf);
268 static void collection_table_update_extras(CollectTable *ct, gboolean loading, gdouble value)
272 if (!ct->extra_label) return;
275 text = _("Loading thumbs...");
279 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ct->extra_label), value);
280 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ct->extra_label), text);
283 static void collection_table_toggle_filenames(CollectTable *ct)
285 GtkAllocation allocation;
286 ct->show_text = !ct->show_text;
287 options->show_icon_names = ct->show_text;
289 gtk_widget_get_allocation(ct->listview, &allocation);
290 collection_table_populate_at_new_size(ct, allocation.width, allocation.height, TRUE);
293 static void collection_table_toggle_stars(CollectTable *ct)
295 GtkAllocation allocation;
296 ct->show_stars = !ct->show_stars;
297 options->show_star_rating = ct->show_stars;
299 gtk_widget_get_allocation(ct->listview, &allocation);
300 collection_table_populate_at_new_size(ct, allocation.width, allocation.height, TRUE);
303 static gint collection_table_get_icon_width(CollectTable *ct)
307 if (!ct->show_text) return options->thumbnails.max_width;
309 width = options->thumbnails.max_width + options->thumbnails.max_width / 2;
310 if (width < THUMB_MIN_ICON_WIDTH) width = THUMB_MIN_ICON_WIDTH;
311 if (width > THUMB_MAX_ICON_WIDTH) width = options->thumbnails.max_width;
317 *-------------------------------------------------------------------
319 *-------------------------------------------------------------------
322 static void collection_table_selection_set(CollectTable *ct, CollectInfo *info, SelectionType value, GtkTreeIter *iter)
329 if (info->flag_mask == value) return;
330 info->flag_mask = value;
332 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
335 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
336 if (list) gtk_list_store_set(GTK_LIST_STORE(store), iter, CTABLE_COLUMN_POINTER, list, -1);
342 if (collection_table_find_iter(ct, info, &row, nullptr))
344 gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
345 if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, CTABLE_COLUMN_POINTER, list, -1);
350 static void collection_table_selection_add(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
354 collection_table_selection_set(ct, info, static_cast<SelectionType>(info->flag_mask | mask), iter);
357 static void collection_table_selection_remove(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
361 collection_table_selection_set(ct, info, static_cast<SelectionType>(info->flag_mask & ~mask), iter);
364 *-------------------------------------------------------------------
366 *-------------------------------------------------------------------
369 static void collection_table_verify_selections(CollectTable *ct)
373 work = ct->selection;
376 auto info = static_cast<CollectInfo *>(work->data);
378 if (!g_list_find(ct->cd->list, info))
380 ct->selection = g_list_remove(ct->selection, info);
385 void collection_table_select_all(CollectTable *ct)
389 g_list_free(ct->selection);
390 ct->selection = nullptr;
395 ct->selection = g_list_append(ct->selection, work->data);
396 collection_table_selection_add(ct, static_cast<CollectInfo *>(work->data), SELECTION_SELECTED, nullptr);
400 collection_table_update_status(ct);
403 void collection_table_unselect_all(CollectTable *ct)
407 work = ct->selection;
410 collection_table_selection_remove(ct, static_cast<CollectInfo *>(work->data), SELECTION_SELECTED, nullptr);
414 g_list_free(ct->selection);
415 ct->selection = nullptr;
417 collection_table_update_status(ct);
420 /* Invert the current collection's selection */
421 static void collection_table_select_invert_all(CollectTable *ct)
424 GList *new_selection = nullptr;
429 auto info = static_cast<CollectInfo *>(work->data);
431 if (INFO_SELECTED(info))
433 collection_table_selection_remove(ct, info, SELECTION_SELECTED, nullptr);
437 new_selection = g_list_append(new_selection, info);
438 collection_table_selection_add(ct, info, SELECTION_SELECTED, nullptr);
445 g_list_free(ct->selection);
446 ct->selection = new_selection;
448 collection_table_update_status(ct);
451 void collection_table_select(CollectTable *ct, CollectInfo *info)
453 ct->prev_selection = info;
455 if (!info || INFO_SELECTED(info)) return;
457 ct->selection = g_list_append(ct->selection, info);
458 collection_table_selection_add(ct, info, SELECTION_SELECTED, nullptr);
460 collection_table_update_status(ct);
463 static void collection_table_unselect(CollectTable *ct, CollectInfo *info)
465 ct->prev_selection = info;
467 if (!info || !INFO_SELECTED(info) ) return;
469 ct->selection = g_list_remove(ct->selection, info);
470 collection_table_selection_remove(ct, info, SELECTION_SELECTED, nullptr);
472 collection_table_update_status(ct);
475 static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gboolean select)
479 collection_table_select(ct, info);
483 collection_table_unselect(ct, info);
487 static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gboolean select)
494 if (!collection_table_find_position(ct, start, &row1, &col1) ||
495 !collection_table_find_position(ct, end, &row2, &col2) ) return;
497 ct->prev_selection = end;
499 if (!options->collections.rectangular_selection)
504 if (g_list_index(ct->cd->list, start) > g_list_index(ct->cd->list, end))
511 work = g_list_find(ct->cd->list, start);
514 info = static_cast<CollectInfo *>(work->data);
515 collection_table_select_util(ct, info, select);
517 if (work->data != end)
538 DEBUG_1("table: %d x %d to %d x %d", row1, col1, row2, col2);
540 for (i = row1; i <= row2; i++)
542 for (j = col1; j <= col2; j++)
544 CollectInfo *info = collection_table_find_data(ct, i, j, nullptr);
545 if (info) collection_table_select_util(ct, info, select);
550 GList *collection_table_selection_get_list(CollectTable *ct)
552 return collection_list_to_filelist(ct->selection);
555 static GList *collection_table_get_list(CollectTable *ct)
557 return collection_list_to_filelist(ct->cd->list);
561 *-------------------------------------------------------------------
562 * tooltip type window
563 *-------------------------------------------------------------------
566 static void tip_show(CollectTable *ct)
574 if (ct->tip_window) return;
576 seat = gdk_display_get_default_seat(gdk_window_get_display(gtk_widget_get_window(ct->listview)));
577 device = gdk_seat_get_pointer(seat);
578 gdk_window_get_device_position(gtk_widget_get_window(ct->listview),
579 device, &x, &y, nullptr);
581 ct->tip_info = collection_table_find_data_by_coord(ct, x, y, nullptr);
582 if (!ct->tip_info) return;
584 ct->tip_window = gtk_window_new(GTK_WINDOW_POPUP);
585 gtk_window_set_resizable(GTK_WINDOW(ct->tip_window), FALSE);
586 gtk_container_set_border_width(GTK_CONTAINER(ct->tip_window), 2);
588 label = gtk_label_new(ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
590 g_object_set_data(G_OBJECT(ct->tip_window), "tip_label", label);
591 gq_gtk_container_add(GTK_WIDGET(ct->tip_window), label);
592 gtk_widget_show(label);
594 display = gdk_display_get_default();
595 seat = gdk_display_get_default_seat(display);
596 device = gdk_seat_get_pointer(seat);
597 gdk_device_get_position(device, nullptr, &x, &y);
599 if (!gtk_widget_get_realized(ct->tip_window)) gtk_widget_realize(ct->tip_window);
600 gq_gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
601 gtk_widget_show(ct->tip_window);
604 static void tip_hide(CollectTable *ct)
606 if (ct->tip_window) gq_gtk_widget_destroy(ct->tip_window);
607 ct->tip_window = nullptr;
610 static gboolean tip_schedule_cb(gpointer data)
612 auto ct = static_cast<CollectTable *>(data);
614 if (!ct->tip_delay_id) return FALSE;
618 ct->tip_delay_id = 0;
622 static void tip_schedule(CollectTable *ct)
626 if (ct->tip_delay_id)
628 g_source_remove(ct->tip_delay_id);
629 ct->tip_delay_id = 0;
632 ct->tip_delay_id = g_timeout_add(ct->show_text ? COLLECT_TABLE_TIP_DELAY_PATH : COLLECT_TABLE_TIP_DELAY, tip_schedule_cb, ct);
635 static void tip_unschedule(CollectTable *ct)
639 if (ct->tip_delay_id)
641 g_source_remove(ct->tip_delay_id);
642 ct->tip_delay_id = 0;
646 static void tip_update(CollectTable *ct, CollectInfo *info)
648 GdkDisplay *display = gdk_display_get_default();
649 GdkSeat *seat = gdk_display_get_default_seat(display);
650 GdkDevice *device = gdk_seat_get_pointer(seat);
657 gdk_device_get_position(device, nullptr, &x, &y);
659 gq_gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
661 if (info != ct->tip_info)
672 label = static_cast<GtkWidget *>(g_object_get_data(G_OBJECT(ct->tip_window), "tip_label"));
673 gtk_label_set_text(GTK_LABEL(label), ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
679 *-------------------------------------------------------------------
681 *-------------------------------------------------------------------
684 static void collection_table_popup_save_as_cb(GtkWidget *, gpointer data)
686 auto ct = static_cast<CollectTable *>(data);
688 collection_dialog_save_as(ct->cd);
691 static void collection_table_popup_save_cb(GtkWidget *widget, gpointer data)
693 auto ct = static_cast<CollectTable *>(data);
697 collection_table_popup_save_as_cb(widget, data);
701 if (!collection_save(ct->cd, ct->cd->path))
703 log_printf("failed saving to collection path: %s\n", ct->cd->path);
707 static GList *collection_table_popup_file_list(CollectTable *ct)
709 if (!ct->click_info) return nullptr;
711 if (INFO_SELECTED(ct->click_info))
713 return collection_table_selection_get_list(ct);
716 return g_list_append(nullptr, file_data_ref(ct->click_info->fd));
719 static void collection_table_popup_edit_cb(GtkWidget *widget, gpointer data)
722 auto key = static_cast<const gchar *>(data);
724 ct = static_cast<CollectTable *>(submenu_item_get_data(widget));
728 file_util_start_editor_from_filelist(key, collection_table_popup_file_list(ct), nullptr, ct->listview);
731 static void collection_table_popup_copy_cb(GtkWidget *, gpointer data)
733 auto ct = static_cast<CollectTable *>(data);
735 file_util_copy(nullptr, collection_table_popup_file_list(ct), nullptr, ct->listview);
738 static void collection_table_popup_move_cb(GtkWidget *, gpointer data)
740 auto ct = static_cast<CollectTable *>(data);
742 file_util_move(nullptr, collection_table_popup_file_list(ct), nullptr, ct->listview);
745 static void collection_table_popup_rename_cb(GtkWidget *, gpointer data)
747 auto ct = static_cast<CollectTable *>(data);
749 file_util_rename(nullptr, collection_table_popup_file_list(ct), ct->listview);
752 static void collection_table_popup_delete_cb(GtkWidget *, gpointer data)
754 auto ct = static_cast<CollectTable *>(data);
756 options->file_ops.safe_delete_enable = FALSE;
757 file_util_delete(nullptr, collection_table_popup_file_list(ct), ct->listview);
760 static void collection_table_popup_move_to_trash_cb(GtkWidget *, gpointer data)
762 auto ct = static_cast<CollectTable *>(data);
764 options->file_ops.safe_delete_enable = TRUE;
765 file_util_delete(nullptr, collection_table_popup_file_list(ct), ct->listview);
768 static void collection_table_popup_copy_path_cb(GtkWidget *, gpointer data)
770 auto ct = static_cast<CollectTable *>(data);
772 file_util_copy_path_list_to_clipboard(collection_table_popup_file_list(ct), TRUE);
775 static void collection_table_popup_copy_path_unquoted_cb(GtkWidget *, gpointer data)
777 auto ct = static_cast<CollectTable *>(data);
779 file_util_copy_path_list_to_clipboard(collection_table_popup_file_list(ct), FALSE);
782 static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data)
787 ct = static_cast<CollectTable *>(submenu_item_get_data(widget));
791 type = static_cast<SortType>GPOINTER_TO_INT(data);
793 collection_set_sort_method(ct->cd, type);
796 static void collection_table_popup_randomize_cb(GtkWidget *widget, gpointer)
800 ct = static_cast<CollectTable *>(submenu_item_get_data(widget));
804 collection_randomize(ct->cd);
807 static void collection_table_popup_view_new_cb(GtkWidget *, gpointer data)
809 auto ct = static_cast<CollectTable *>(data);
811 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
813 view_window_new_from_collection(ct->cd, ct->click_info);
817 static void collection_table_popup_view_cb(GtkWidget *, gpointer data)
819 auto ct = static_cast<CollectTable *>(data);
821 if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
823 layout_image_set_collection(nullptr, ct->cd, ct->click_info);
827 static void collection_table_popup_selectall_cb(GtkWidget *, gpointer data)
829 auto ct = static_cast<CollectTable *>(data);
831 collection_table_select_all(ct);
832 ct->prev_selection= ct->click_info;
835 static void collection_table_popup_unselectall_cb(GtkWidget *, gpointer data)
837 auto ct = static_cast<CollectTable *>(data);
839 collection_table_unselect_all(ct);
840 ct->prev_selection= ct->click_info;
843 static void collection_table_popup_select_invert_cb(GtkWidget *, gpointer data)
845 auto ct = static_cast<CollectTable *>(data);
847 collection_table_select_invert_all(ct);
848 ct->prev_selection= ct->click_info;
851 static void collection_table_popup_rectangular_selection_cb(GtkWidget *, gpointer)
853 options->collections.rectangular_selection = !(options->collections.rectangular_selection);
856 static void collection_table_popup_remove_cb(GtkWidget *, gpointer data)
858 auto ct = static_cast<CollectTable *>(data);
861 if (!ct->click_info) return;
863 if (INFO_SELECTED(ct->click_info))
865 list = g_list_copy(ct->selection);
869 list = g_list_append(nullptr, ct->click_info);
872 collection_remove_by_info_list(ct->cd, list);
873 collection_table_refresh(ct);
877 static void collection_table_popup_add_file_selection_cb(GtkWidget *, gpointer data)
879 auto ct = static_cast<CollectTable *>(data);
881 LayoutWindow *lw = nullptr;
883 if (!layout_valid(&lw)) return;
885 list = vf_selection_get_list(lw->vf);
889 collection_table_add_filelist(ct, list);
894 static void collection_table_popup_add_collection_cb(GtkWidget *, gpointer data)
896 auto ct = static_cast<CollectTable *>(data);
898 collection_dialog_append(ct->cd);
901 static void collection_table_popup_goto_original_cb(GtkWidget *, gpointer data)
903 auto ct = static_cast<CollectTable *>(data);
905 LayoutWindow *lw = nullptr;
908 if (!layout_valid(&lw)) return;
909 list = collection_table_selection_get_list(ct);
912 fd = static_cast<FileData *>(list->data);
915 layout_set_fd(lw, fd);
921 static void collection_table_popup_find_dupes_cb(GtkWidget *, gpointer data)
923 auto ct = static_cast<CollectTable *>(data);
926 dw = dupe_window_new();
927 dupe_window_add_collection(dw, ct->cd);
930 static void collection_table_popup_print_cb(GtkWidget *, gpointer data)
932 auto ct = static_cast<CollectTable *>(data);
935 fd = (ct->click_info) ? ct->click_info->fd : nullptr;
937 print_window_new(fd, collection_table_selection_get_list(ct), collection_table_get_list(ct), gtk_widget_get_toplevel(ct->listview));
940 static void collection_table_popup_show_names_cb(GtkWidget *, gpointer data)
942 auto ct = static_cast<CollectTable *>(data);
944 collection_table_toggle_filenames(ct);
947 static void collection_table_popup_show_stars_cb(GtkWidget *, gpointer data)
949 auto ct = static_cast<CollectTable *>(data);
951 collection_table_toggle_stars(ct);
954 static void collection_table_popup_destroy_cb(GtkWidget *, gpointer data)
956 auto ct = static_cast<CollectTable *>(data);
958 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, nullptr);
959 ct->click_info = nullptr;
962 filelist_free(ct->drop_list);
963 ct->drop_list = nullptr;
964 ct->drop_info = nullptr;
966 filelist_free(ct->editmenu_fd_list);
967 ct->editmenu_fd_list = nullptr;
970 static GtkWidget *collection_table_popup_menu(CollectTable *ct, gboolean over_icon)
975 GtkAccelGroup *accel_group;
977 menu = popup_menu_short_lived();
979 accel_group = gtk_accel_group_new();
980 gtk_menu_set_accel_group(GTK_MENU(menu), accel_group);
982 g_object_set_data(G_OBJECT(menu), "window_keys", collection_window_keys);
983 g_object_set_data(G_OBJECT(menu), "accel_group", accel_group);
985 g_signal_connect(G_OBJECT(menu), "destroy",
986 G_CALLBACK(collection_table_popup_destroy_cb), ct);
988 menu_item_add_sensitive(menu, _("_View"), over_icon,
989 G_CALLBACK(collection_table_popup_view_cb), ct);
990 menu_item_add_icon_sensitive(menu, _("View in _new window"), GQ_ICON_NEW, over_icon,
991 G_CALLBACK(collection_table_popup_view_new_cb), ct);
992 menu_item_add_icon(menu, _("Go to original"), GQ_ICON_FIND,
993 G_CALLBACK(collection_table_popup_goto_original_cb), ct);
994 menu_item_add_divider(menu);
995 menu_item_add_icon_sensitive(menu, _("Rem_ove"), GQ_ICON_REMOVE, over_icon,
996 G_CALLBACK(collection_table_popup_remove_cb), ct);
998 menu_item_add_icon(menu, _("Append from file selection"), GQ_ICON_ADD,
999 G_CALLBACK(collection_table_popup_add_file_selection_cb), ct);
1000 menu_item_add_icon(menu, _("Append from collection..."), GQ_ICON_OPEN,
1001 G_CALLBACK(collection_table_popup_add_collection_cb), ct);
1002 menu_item_add_divider(menu);
1004 item = menu_item_add(menu, _("_Selection"), nullptr, nullptr);
1005 submenu = gtk_menu_new();
1006 menu_item_add(submenu, _("Select all"),
1007 G_CALLBACK(collection_table_popup_selectall_cb), ct);
1008 menu_item_add(submenu, _("Select none"),
1009 G_CALLBACK(collection_table_popup_unselectall_cb), ct);
1010 menu_item_add(submenu, _("Invert selection"),
1011 G_CALLBACK(collection_table_popup_select_invert_cb), ct);
1012 menu_item_add_check(submenu, _("Rectangular selection"), (options->collections.rectangular_selection != FALSE),
1013 G_CALLBACK(collection_table_popup_rectangular_selection_cb), ct);
1014 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1015 menu_item_add_divider(menu);
1018 ct->editmenu_fd_list = collection_table_selection_get_list(ct);
1019 submenu_add_edit(menu, &item,
1020 G_CALLBACK(collection_table_popup_edit_cb), ct, ct->editmenu_fd_list);
1021 gtk_widget_set_sensitive(item, over_icon);
1023 menu_item_add_divider(menu);
1024 menu_item_add_icon_sensitive(menu, _("_Copy..."), GQ_ICON_COPY, over_icon,
1025 G_CALLBACK(collection_table_popup_copy_cb), ct);
1026 menu_item_add_sensitive(menu, _("_Move..."), over_icon,
1027 G_CALLBACK(collection_table_popup_move_cb), ct);
1028 menu_item_add_sensitive(menu, _("_Rename..."), over_icon,
1029 G_CALLBACK(collection_table_popup_rename_cb), ct);
1030 menu_item_add_sensitive(menu, _("_Copy path"), over_icon,
1031 G_CALLBACK(collection_table_popup_copy_path_cb), ct);
1032 menu_item_add_sensitive(menu, _("_Copy path unquoted"), over_icon,
1033 G_CALLBACK(collection_table_popup_copy_path_unquoted_cb), ct);
1035 menu_item_add_divider(menu);
1036 menu_item_add_icon_sensitive(menu,
1037 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
1038 _("Move to Trash"), GQ_ICON_DELETE, over_icon,
1039 G_CALLBACK(collection_table_popup_move_to_trash_cb), ct);
1040 menu_item_add_icon_sensitive(menu,
1041 options->file_ops.confirm_delete ? _("_Delete...") :
1042 _("_Delete"), GQ_ICON_DELETE_SHRED, over_icon,
1043 G_CALLBACK(collection_table_popup_delete_cb), ct);
1045 menu_item_add_divider(menu);
1046 submenu = submenu_add_sort(nullptr, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, SORT_NONE);
1047 menu_item_add_divider(submenu);
1048 menu_item_add(submenu, _("Randomize"),
1049 G_CALLBACK(collection_table_popup_randomize_cb), ct);
1050 item = menu_item_add(menu, _("_Sort"), nullptr, nullptr);
1051 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1053 menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
1054 G_CALLBACK(collection_table_popup_show_names_cb), ct);
1055 menu_item_add_check(menu, _("Show star rating"), ct->show_stars,
1056 G_CALLBACK(collection_table_popup_show_stars_cb), ct);
1057 menu_item_add_divider(menu);
1058 menu_item_add_icon(menu, _("_Save collection"), GQ_ICON_SAVE,
1059 G_CALLBACK(collection_table_popup_save_cb), ct);
1060 menu_item_add_icon(menu, _("Save collection _as..."), GQ_ICON_SAVE_AS,
1061 G_CALLBACK(collection_table_popup_save_as_cb), ct);
1062 menu_item_add_divider(menu);
1063 menu_item_add_icon(menu, _("_Find duplicates..."), GQ_ICON_FIND,
1064 G_CALLBACK(collection_table_popup_find_dupes_cb), ct);
1065 menu_item_add_icon_sensitive(menu, _("Print..."), GQ_ICON_PRINT, over_icon,
1066 G_CALLBACK(collection_table_popup_print_cb), ct);
1071 *-------------------------------------------------------------------
1072 * keyboard callbacks
1073 *-------------------------------------------------------------------
1076 void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
1081 if (g_list_find(ct->cd->list, ct->focus_info))
1083 if (info == ct->focus_info)
1085 /* ensure focus row col are correct */
1086 collection_table_find_position(ct, ct->focus_info,
1087 &ct->focus_row, &ct->focus_column);
1090 collection_table_selection_remove(ct, ct->focus_info, SELECTION_FOCUS, nullptr);
1093 if (!collection_table_find_position(ct, info, &row, &col))
1095 ct->focus_info = nullptr;
1097 ct->focus_column = -1;
1101 ct->focus_info = info;
1102 ct->focus_row = row;
1103 ct->focus_column = col;
1104 collection_table_selection_add(ct, ct->focus_info, SELECTION_FOCUS, nullptr);
1106 if (collection_table_find_iter(ct, ct->focus_info, &iter, nullptr))
1109 GtkTreeViewColumn *column;
1110 GtkTreeModel *store;
1112 tree_view_row_make_visible(GTK_TREE_VIEW(ct->listview), &iter, FALSE);
1114 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1115 tpath = gtk_tree_model_get_path(store, &iter);
1116 /* focus is set to an extra column with 0 width to hide focus, we draw it ourself */
1117 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), COLLECT_TABLE_MAX_COLUMNS);
1118 gtk_tree_view_set_cursor(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE);
1119 gtk_tree_path_free(tpath);
1123 static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gboolean relative)
1130 new_row = ct->focus_row;
1131 new_col = ct->focus_column;
1134 if (new_row < 0) new_row = 0;
1135 if (new_row >= ct->rows) new_row = ct->rows - 1;
1155 new_col = ct->columns - 1;
1162 if (new_col >= ct->columns)
1164 if (new_row < ct->rows - 1)
1171 new_col = ct->columns - 1;
1181 if (new_row >= ct->rows)
1184 new_row = ct->rows - 1;
1187 new_col = ct->columns - 1;
1189 if (new_col >= ct->columns) new_col = ct->columns - 1;
1192 if (new_row == ct->rows - 1)
1196 /* if we moved beyond the last image, go to the last image */
1198 l = g_list_length(ct->cd->list);
1199 if (ct->rows > 1) l -= (ct->rows - 1) * ct->columns;
1200 if (new_col >= l) new_col = l - 1;
1203 if (new_row == -1 || new_col == -1)
1205 if (!ct->cd->list) return;
1206 new_row = new_col = 0;
1209 collection_table_set_focus(ct, collection_table_find_data(ct, new_row, new_col, nullptr));
1212 static void collection_table_update_focus(CollectTable *ct)
1217 if (ct->focus_info && collection_table_find_position(ct, ct->focus_info, &new_row, &new_col))
1219 /* first find the old focus, if it exists and is valid */
1223 /* (try to) stay where we were */
1224 new_row = ct->focus_row;
1225 new_col = ct->focus_column;
1228 collection_table_move_focus(ct, new_row, new_col, FALSE);
1231 /* used to figure the page up/down distances */
1232 static gint page_height(CollectTable *ct)
1239 adj = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(ct->listview));
1240 page_size = static_cast<gint>(gtk_adjustment_get_page_increment(adj));
1242 row_height = options->thumbnails.max_height + THUMB_BORDER_PADDING * 2;
1243 if (ct->show_text) row_height += options->thumbnails.max_height / 3;
1245 ret = page_size / row_height;
1246 if (ret < 1) ret = 1;
1251 static gboolean collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
1253 auto ct = static_cast<CollectTable *>(data);
1257 gboolean stop_signal = TRUE;
1259 switch (event->keyval)
1261 case GDK_KEY_Left: case GDK_KEY_KP_Left:
1264 case GDK_KEY_Right: case GDK_KEY_KP_Right:
1267 case GDK_KEY_Up: case GDK_KEY_KP_Up:
1270 case GDK_KEY_Down: case GDK_KEY_KP_Down:
1273 case GDK_KEY_Page_Up: case GDK_KEY_KP_Page_Up:
1274 focus_row = -page_height(ct);
1276 case GDK_KEY_Page_Down: case GDK_KEY_KP_Page_Down:
1277 focus_row = page_height(ct);
1279 case GDK_KEY_Home: case GDK_KEY_KP_Home:
1280 focus_row = -ct->focus_row;
1281 focus_col = -ct->focus_column;
1283 case GDK_KEY_End: case GDK_KEY_KP_End:
1284 focus_row = ct->rows - 1 - ct->focus_row;
1285 focus_col = ct->columns - 1 - ct->focus_column;
1288 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, nullptr);
1291 ct->click_info = info;
1292 if (event->state & GDK_CONTROL_MASK)
1294 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1298 collection_table_unselect_all(ct);
1299 collection_table_select(ct, info);
1304 if (event->state & GDK_CONTROL_MASK) collection_table_toggle_filenames(ct);
1308 info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, nullptr);
1309 ct->click_info = info;
1311 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, nullptr);
1314 ct->popup = collection_table_popup_menu(ct, (info != nullptr));
1315 gtk_menu_popup_at_widget(GTK_MENU(ct->popup), widget, GDK_GRAVITY_SOUTH, GDK_GRAVITY_CENTER, nullptr);
1319 stop_signal = FALSE;
1323 if (focus_row != 0 || focus_col != 0)
1325 CollectInfo *new_info;
1326 CollectInfo *old_info;
1328 old_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, nullptr);
1329 collection_table_move_focus(ct, focus_row, focus_col, TRUE);
1330 new_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, nullptr);
1332 if (new_info != old_info)
1334 if (event->state & GDK_SHIFT_MASK)
1336 if (!options->collections.rectangular_selection)
1338 collection_table_select_region_util(ct, old_info, new_info, FALSE);
1342 collection_table_select_region_util(ct, ct->click_info, old_info, FALSE);
1344 collection_table_select_region_util(ct, ct->click_info, new_info, TRUE);
1346 else if (event->state & GDK_CONTROL_MASK)
1348 ct->click_info = new_info;
1352 ct->click_info = new_info;
1353 collection_table_unselect_all(ct);
1354 collection_table_select(ct, new_info);
1368 *-------------------------------------------------------------------
1370 *-------------------------------------------------------------------
1373 static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gboolean *after, GdkRectangle *cell,
1374 gboolean use_coord, gint x, gint y)
1376 CollectInfo *info = nullptr;
1377 GtkTreeModel *store;
1380 GtkTreeViewColumn *column;
1384 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1388 seat = gdk_display_get_default_seat(gdk_window_get_display(gtk_widget_get_window(ct->listview)));
1389 device = gdk_seat_get_pointer(seat);
1390 gdk_window_get_device_position(gtk_widget_get_window(ct->listview),
1391 device, &x, &y, nullptr);
1397 if (collection_table_find_iter(ct, source, &iter, &col))
1399 tpath = gtk_tree_model_get_path(store, &iter);
1400 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1401 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1402 gtk_tree_path_free(tpath);
1405 *after = !!(x > cell->x + (cell->width / 2));
1410 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
1411 &tpath, &column, nullptr, nullptr))
1416 gtk_tree_model_get_iter(store, &iter, tpath);
1417 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1419 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
1420 info = static_cast<CollectInfo *>(g_list_nth_data(list, n));
1424 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1425 *after = !!(x > cell->x + (cell->width / 2));
1428 gtk_tree_path_free(tpath);
1431 if (info == nullptr)
1435 work = g_list_last(ct->cd->list);
1440 info = static_cast<CollectInfo *>(work->data);
1443 if (collection_table_find_iter(ct, info, &iter, &col))
1445 tpath = gtk_tree_model_get_path(store, &iter);
1446 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1447 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1448 gtk_tree_path_free(tpath);
1456 static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint y)
1460 gboolean after = FALSE;
1462 info = collection_table_insert_find(ct, nullptr, &after, &cell, TRUE, x, y);
1468 work = g_list_find(ct->cd->list, info);
1469 if (work && work->next)
1471 info = static_cast<CollectInfo *>(work->next->data);
1482 static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gboolean enable)
1484 gboolean after = FALSE;
1487 gint x_parent, y_parent;
1488 GError *error = nullptr;
1489 GInputStream *in_stream;
1492 parent = gtk_widget_get_window(gtk_widget_get_toplevel(ct->listview));
1493 gdk_window_get_position(parent, &x_parent, &y_parent);
1497 if (ct->marker_window) gdk_window_destroy(ct->marker_window);
1498 ct->marker_window = nullptr;
1503 info = collection_table_insert_find(ct, info, &after, &cell, FALSE, 0, 0);
1505 /* this setting does not take into account (after), but since it is not really used... */
1506 ct->marker_info = info;
1508 if (!ct->marker_window)
1510 GdkWindowAttr attributes;
1511 gint attributes_mask;
1513 in_stream = g_resources_open_stream(GQ_RESOURCE_PATH_ICONS "/gq-marker.xpm", G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
1514 pb = gdk_pixbuf_new_from_stream(in_stream, nullptr, &error);
1515 g_object_unref(in_stream);
1519 log_printf("warning: collection marker error: %s", error->message);
1520 g_error_free(error);
1524 gint w = gdk_pixbuf_get_width(pb);
1525 gint h = gdk_pixbuf_get_height(pb);
1527 attributes.window_type = GDK_WINDOW_CHILD;
1528 attributes.wclass = GDK_INPUT_OUTPUT;
1529 attributes.width = w;
1530 attributes.height = h;
1531 attributes.event_mask = gtk_widget_get_events(ct->listview);
1532 attributes_mask = 0;
1534 ct->marker_window = gdk_window_new(nullptr, &attributes, attributes_mask);
1536 cairo_region_t *mask;
1537 cairo_pattern_t *pattern;
1538 cairo_surface_t *img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
1539 cairo_t *cr = cairo_create(img);
1540 gdk_cairo_set_source_pixbuf(cr, pb, 0, 0);
1542 /** @FIXME this is a hack to get the background color
1543 * pattern = cairo_pattern_create_for_surface(img);
1545 pattern = cairo_pattern_create_rgb (1.0, 0.0, 0.0);
1546 mask = gdk_cairo_region_create_from_surface(img);
1547 gdk_window_shape_combine_region(ct->marker_window, mask, 0, 0);
1548 gdk_window_set_background_pattern(ct->marker_window, pattern);
1549 cairo_region_destroy(mask);
1550 cairo_pattern_destroy(pattern);
1552 cairo_surface_destroy(img);
1561 w = gdk_window_get_width(ct->marker_window);
1562 h = gdk_window_get_height(ct->marker_window);
1570 x = cell.x + cell.width;
1573 y = cell.y + (cell.height / 2) - (h / 2);
1578 gdk_window_move(ct->marker_window, x, y);
1580 if (!gdk_window_is_visible(ct->marker_window)) gdk_window_show(ct->marker_window);
1584 if (gdk_window_is_visible(ct->marker_window)) gdk_window_hide(ct->marker_window);
1589 *-------------------------------------------------------------------
1590 * mouse drag auto-scroll
1591 *-------------------------------------------------------------------
1594 static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gboolean drop_event)
1598 info = collection_table_find_data_by_coord(ct, x, y, nullptr);
1603 collection_table_insert_marker(ct, info, TRUE);
1607 tip_update(ct, info);
1611 static gboolean collection_table_auto_scroll_idle_cb(gpointer data)
1613 auto ct = static_cast<CollectTable *>(data);
1620 if (!ct->drop_idle_id) return G_SOURCE_REMOVE;
1622 window = gtk_widget_get_window(ct->listview);
1623 seat = gdk_display_get_default_seat(gdk_window_get_display(window));
1624 device = gdk_seat_get_pointer(seat);
1625 gdk_window_get_device_position(window, device, &x, &y, nullptr);
1627 w = gdk_window_get_width(window);
1628 h = gdk_window_get_height(window);
1629 if (x >= 0 && x < w && y >= 0 && y < h)
1631 collection_table_motion_update(ct, x, y, TRUE);
1634 ct->drop_idle_id = 0;
1635 return G_SOURCE_REMOVE;
1638 static gboolean collection_table_auto_scroll_notify_cb(GtkWidget *, gint, gint, gpointer data)
1640 auto ct = static_cast<CollectTable *>(data);
1642 if (!ct->drop_idle_id)
1644 ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
1650 static void collection_table_scroll(CollectTable *ct, gboolean scroll)
1654 if (ct->drop_idle_id)
1656 g_source_remove(ct->drop_idle_id);
1657 ct->drop_idle_id = 0;
1659 widget_auto_scroll_stop(ct->listview);
1660 collection_table_insert_marker(ct, nullptr, FALSE);
1664 GtkAdjustment *adj = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(ct->listview));
1665 widget_auto_scroll_start(ct->listview, adj, -1, options->thumbnails.max_height / 2,
1666 collection_table_auto_scroll_notify_cb, ct);
1671 *-------------------------------------------------------------------
1673 *-------------------------------------------------------------------
1676 static gboolean collection_table_motion_cb(GtkWidget *, GdkEventMotion *event, gpointer data)
1678 auto ct = static_cast<CollectTable *>(data);
1680 collection_table_motion_update(ct, static_cast<gint>(event->x), static_cast<gint>(event->y), FALSE);
1685 static gboolean collection_table_press_cb(GtkWidget *, GdkEventButton *bevent, gpointer data)
1687 auto ct = static_cast<CollectTable *>(data);
1693 info = collection_table_find_data_by_coord(ct, static_cast<gint>(bevent->x), static_cast<gint>(bevent->y), &iter);
1695 ct->click_info = info;
1696 collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, &iter);
1698 switch (bevent->button)
1700 case MOUSE_BUTTON_LEFT:
1701 if (bevent->type == GDK_2BUTTON_PRESS)
1705 layout_image_set_collection(nullptr, ct->cd, info);
1708 else if (!gtk_widget_has_focus(ct->listview))
1710 gtk_widget_grab_focus(ct->listview);
1713 case MOUSE_BUTTON_RIGHT:
1714 ct->popup = collection_table_popup_menu(ct, (info != nullptr));
1715 gtk_menu_popup_at_pointer(GTK_MENU(ct->popup), nullptr);
1724 static gboolean collection_table_release_cb(GtkWidget *, GdkEventButton *bevent, gpointer data)
1726 auto ct = static_cast<CollectTable *>(data);
1728 CollectInfo *info = nullptr;
1732 if (static_cast<gint>(bevent->x) != 0 || static_cast<gint>(bevent->y) != 0)
1734 info = collection_table_find_data_by_coord(ct, static_cast<gint>(bevent->x), static_cast<gint>(bevent->y), &iter);
1739 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, nullptr);
1742 if (bevent->button == MOUSE_BUTTON_LEFT &&
1743 info && ct->click_info == info)
1745 collection_table_set_focus(ct, info);
1747 if (bevent->state & GDK_CONTROL_MASK)
1749 gboolean select = !INFO_SELECTED(info);
1751 if ((bevent->state & GDK_SHIFT_MASK) && ct->prev_selection)
1753 collection_table_select_region_util(ct, ct->prev_selection, info, select);
1757 collection_table_select_util(ct, info, select);
1762 collection_table_unselect_all(ct);
1764 if ((bevent->state & GDK_SHIFT_MASK) &&
1767 collection_table_select_region_util(ct, ct->prev_selection, info, TRUE);
1771 collection_table_select_util(ct, info, TRUE);
1775 else if (bevent->button == MOUSE_BUTTON_MIDDLE &&
1776 info && ct->click_info == info)
1778 collection_table_select_util(ct, info, !INFO_SELECTED(info));
1784 static gboolean collection_table_leave_cb(GtkWidget *, GdkEventCrossing *, gpointer data)
1786 auto ct = static_cast<CollectTable *>(data);
1793 *-------------------------------------------------------------------
1794 * populate, add, insert, etc.
1795 *-------------------------------------------------------------------
1798 static gboolean collection_table_destroy_node_cb(GtkTreeModel *store, GtkTreePath *, GtkTreeIter *iter, gpointer)
1802 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
1808 static void collection_table_clear_store(CollectTable *ct)
1810 GtkTreeModel *store;
1812 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1813 gtk_tree_model_foreach(store, collection_table_destroy_node_cb, nullptr);
1815 gtk_list_store_clear(GTK_LIST_STORE(store));
1818 static GList *collection_table_add_row(CollectTable *ct, GtkTreeIter *iter)
1820 GtkListStore *store;
1821 GList *list = nullptr;
1824 for (i = 0; i < ct->columns; i++) list = g_list_prepend(list, nullptr);
1826 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)));
1827 gtk_list_store_append(store, iter);
1828 gtk_list_store_set(store, iter, CTABLE_COLUMN_POINTER, list, -1);
1833 static void collection_table_populate(CollectTable *ct, gboolean resize)
1838 collection_table_verify_selections(ct);
1840 collection_table_clear_store(ct);
1847 thumb_width = collection_table_get_icon_width(ct);
1849 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
1851 GtkTreeViewColumn *column;
1852 GtkCellRenderer *cell;
1855 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), i);
1856 gtk_tree_view_column_set_visible(column, (i < ct->columns));
1857 gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6));
1859 list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
1860 cell = static_cast<GtkCellRenderer *>((list) ? list->data : nullptr);
1863 if (cell && GQV_IS_CELL_RENDERER_ICON(cell))
1865 g_object_set(G_OBJECT(cell), "fixed_width", thumb_width,
1866 "fixed_height", options->thumbnails.max_height,
1867 "show_text", ct->show_text || ct->show_stars, NULL);
1870 if (gtk_widget_get_realized(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
1874 work = ct->cd->list;
1882 list = collection_table_add_row(ct, &iter);
1883 while (work && list)
1885 list->data = work->data;
1893 collection_table_update_focus(ct);
1894 collection_table_update_status(ct);
1897 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint, gboolean force)
1902 thumb_width = collection_table_get_icon_width(ct);
1904 new_cols = w / (thumb_width + (THUMB_BORDER_PADDING * 6));
1905 if (new_cols < 1) new_cols = 1;
1907 if (!force && new_cols == ct->columns) return;
1909 ct->columns = new_cols;
1911 collection_table_populate(ct, TRUE);
1913 DEBUG_1("col tab pop cols=%d rows=%d", ct->columns, ct->rows);
1916 static void collection_table_sync(CollectTable *ct)
1918 GtkTreeModel *store;
1923 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1928 work = ct->cd->list;
1934 if (gtk_tree_model_iter_nth_child(store, &iter, nullptr, r))
1936 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1937 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1941 list = collection_table_add_row(ct, &iter);
1949 info = static_cast<CollectInfo *>(work->data);
1966 while (gtk_tree_model_iter_nth_child(store, &iter, nullptr, r))
1970 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1971 gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
1977 collection_table_update_focus(ct);
1978 collection_table_update_status(ct);
1981 static gboolean collection_table_sync_idle_cb(gpointer data)
1983 auto ct = static_cast<CollectTable *>(data);
1985 if (!ct->sync_idle_id) return G_SOURCE_REMOVE;
1986 g_source_remove(ct->sync_idle_id);
1987 ct->sync_idle_id = 0;
1989 collection_table_sync(ct);
1990 return G_SOURCE_REMOVE;
1993 static void collection_table_sync_idle(CollectTable *ct)
1995 if (!ct->sync_idle_id)
1997 /* high priority, the view needs to be resynced before a redraw
1998 * may contain invalid pointers at this time
2000 ct->sync_idle_id = g_idle_add_full(G_PRIORITY_HIGH, collection_table_sync_idle_cb, ct, nullptr);
2004 void collection_table_add_filelist(CollectTable *ct, GList *list)
2013 collection_add(ct->cd, static_cast<FileData *>(work->data), FALSE);
2018 static void collection_table_insert_filelist(CollectTable *ct, GList *list, CollectInfo *insert_info)
2027 collection_insert(ct->cd, static_cast<FileData *>(work->data), insert_info, FALSE);
2031 collection_table_sync_idle(ct);
2034 static void collection_table_move_by_info_list(CollectTable *ct, GList *info_list, gint row, gint col)
2037 GList *insert_pos = nullptr;
2041 if (!info_list) return;
2043 info = collection_table_find_data(ct, row, col, nullptr);
2045 if (!info_list->next && info_list->data == info) return;
2047 if (info) insert_pos = g_list_find(ct->cd->list, info);
2049 /** @FIXME this may get slow for large lists */
2051 while (insert_pos && work)
2053 if (insert_pos->data == work->data)
2055 insert_pos = insert_pos->next;
2067 ct->cd->list = g_list_remove(ct->cd->list, work->data);
2071 /* place them back in */
2072 temp = g_list_copy(info_list);
2076 ct->cd->list = uig_list_insert_list(ct->cd->list, insert_pos, temp);
2080 ct->cd->list = g_list_concat(temp, ct->cd->list);
2084 ct->cd->list = g_list_concat(ct->cd->list, temp);
2087 ct->cd->changed = TRUE;
2089 collection_table_sync_idle(ct);
2094 *-------------------------------------------------------------------
2096 *-------------------------------------------------------------------
2099 void collection_table_file_update(CollectTable *ct, CollectInfo *info)
2107 collection_table_update_extras(ct, FALSE, 0.0);
2111 if (!collection_table_find_position(ct, info, &row, &col)) return;
2113 if (ct->columns != 0 && ct->rows != 0)
2115 value = static_cast<gdouble>(row * ct->columns + col) / (ct->columns * ct->rows);
2122 collection_table_update_extras(ct, TRUE, value);
2124 if (collection_table_find_iter(ct, info, &iter, nullptr))
2126 GtkTreeModel *store;
2129 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
2130 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
2131 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
2135 void collection_table_file_add(CollectTable *ct, CollectInfo *)
2137 collection_table_sync_idle(ct);
2140 void collection_table_file_insert(CollectTable *ct, CollectInfo *)
2142 collection_table_sync_idle(ct);
2145 void collection_table_file_remove(CollectTable *ct, CollectInfo *ci)
2147 if (ci && INFO_SELECTED(ci))
2149 ct->selection = g_list_remove(ct->selection, ci);
2152 collection_table_sync_idle(ct);
2155 void collection_table_refresh(CollectTable *ct)
2157 collection_table_populate(ct, FALSE);
2161 *-------------------------------------------------------------------
2163 *-------------------------------------------------------------------
2166 static void collection_table_add_dir_recursive(CollectTable *ct, FileData *dir_fd, gboolean recursive)
2172 if (!filelist_read(dir_fd, &f, recursive ? &d : nullptr))
2175 f = filelist_filter(f, FALSE);
2176 d = filelist_filter(d, TRUE);
2178 f = filelist_sort_path(f);
2179 d = filelist_sort_path(d);
2181 collection_table_insert_filelist(ct, f, ct->marker_info);
2183 work = g_list_last(d);
2186 collection_table_add_dir_recursive(ct, static_cast<FileData *>(work->data), TRUE);
2194 static void confirm_dir_list_do(CollectTable *ct, GList *list, gboolean recursive)
2199 auto fd = static_cast<FileData *>(work->data);
2201 if (isdir(fd->path)) collection_table_add_dir_recursive(ct, fd, recursive);
2203 collection_table_insert_filelist(ct, list, ct->marker_info);
2207 static void confirm_dir_list_add(GtkWidget *, gpointer data)
2209 auto ct = static_cast<CollectTable *>(data);
2211 confirm_dir_list_do(ct, ct->drop_list, FALSE);
2214 static void confirm_dir_list_recurse(GtkWidget *, gpointer data)
2216 auto ct = static_cast<CollectTable *>(data);
2218 confirm_dir_list_do(ct, ct->drop_list, TRUE);
2221 static void confirm_dir_list_skip(GtkWidget *, gpointer data)
2223 auto ct = static_cast<CollectTable *>(data);
2225 collection_table_insert_filelist(ct, ct->drop_list, ct->marker_info);
2228 static GtkWidget *collection_table_drop_menu(CollectTable *ct)
2232 menu = popup_menu_short_lived();
2233 g_signal_connect(G_OBJECT(menu), "destroy",
2234 G_CALLBACK(collection_table_popup_destroy_cb), ct);
2236 menu_item_add_stock(menu, _("Dropped list includes folders."), GQ_ICON_DND, nullptr, nullptr);
2237 menu_item_add_divider(menu);
2238 menu_item_add_icon(menu, _("_Add contents"), GQ_ICON_OK,
2239 G_CALLBACK(confirm_dir_list_add), ct);
2240 menu_item_add_icon(menu, _("Add contents _recursive"), GQ_ICON_ADD,
2241 G_CALLBACK(confirm_dir_list_recurse), ct);
2242 menu_item_add_icon(menu, _("_Skip folders"), GQ_ICON_REMOVE,
2243 G_CALLBACK(confirm_dir_list_skip), ct);
2244 menu_item_add_divider(menu);
2245 menu_item_add_icon(menu, _("Cancel"), GQ_ICON_CANCEL, nullptr, ct);
2251 *-------------------------------------------------------------------
2253 *-------------------------------------------------------------------
2256 static GtkTargetEntry collection_drag_types[] = {
2257 { const_cast<gchar *>(TARGET_APP_COLLECTION_MEMBER_STRING), 0, TARGET_APP_COLLECTION_MEMBER },
2258 { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST },
2259 { const_cast<gchar *>("text/plain"), 0, TARGET_TEXT_PLAIN }
2261 static gint n_collection_drag_types = 3;
2263 static GtkTargetEntry collection_drop_types[] = {
2264 { const_cast<gchar *>(TARGET_APP_COLLECTION_MEMBER_STRING), 0, TARGET_APP_COLLECTION_MEMBER },
2265 { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST }
2267 static gint n_collection_drop_types = 2;
2270 static void collection_table_dnd_get(GtkWidget *, GdkDragContext *,
2271 GtkSelectionData *selection_data, guint info,
2272 guint, gpointer data)
2274 auto ct = static_cast<CollectTable *>(data);
2276 GList *list = nullptr;
2277 gchar *uri_text = nullptr;
2280 if (!ct->click_info) return;
2282 selected = INFO_SELECTED(ct->click_info);
2286 case TARGET_APP_COLLECTION_MEMBER:
2289 uri_text = collection_info_list_to_dnd_data(ct->cd, ct->selection, &total);
2293 list = g_list_append(nullptr, ct->click_info);
2294 uri_text = collection_info_list_to_dnd_data(ct->cd, list, &total);
2297 gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
2298 8, reinterpret_cast<guchar *>(uri_text), total);
2301 case TARGET_URI_LIST:
2302 case TARGET_TEXT_PLAIN:
2306 list = collection_table_selection_get_list(ct);
2310 list = g_list_append(nullptr, file_data_ref(ct->click_info->fd));
2314 uri_selection_data_set_uris_from_filelist(selection_data, list);
2315 filelist_free(list);
2321 static void collection_table_dnd_receive(GtkWidget *, GdkDragContext *context,
2323 GtkSelectionData *selection_data, guint info,
2324 guint, gpointer data)
2326 auto ct = static_cast<CollectTable *>(data);
2327 GList *list = nullptr;
2328 GList *info_list = nullptr;
2329 CollectionData *source;
2330 CollectInfo *drop_info;
2333 DEBUG_1("%s", gtk_selection_data_get_data(selection_data));
2335 collection_table_scroll(ct, FALSE);
2336 collection_table_insert_marker(ct, nullptr, FALSE);
2338 drop_info = collection_table_insert_point(ct, x, y);
2342 case TARGET_APP_COLLECTION_MEMBER:
2343 source = collection_from_dnd_data(reinterpret_cast<const gchar *>(gtk_selection_data_get_data(selection_data)), &list, &info_list);
2346 if (source == ct->cd)
2351 /* it is a move within a collection */
2352 filelist_free(list);
2357 collection_table_move_by_info_list(ct, info_list, -1, -1);
2359 else if (collection_table_find_position(ct, drop_info, &row, &col))
2361 collection_table_move_by_info_list(ct, info_list, row, col);
2366 /* it is a move/copy across collections */
2367 if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
2369 collection_remove_by_info_list(source, info_list);
2372 g_list_free(info_list);
2375 case TARGET_URI_LIST:
2376 list = uri_filelist_from_gtk_selection_data(selection_data);
2380 auto fd = static_cast<FileData *>(work->data);
2381 if (isdir(fd->path))
2385 ct->drop_list = list;
2386 ct->drop_info = drop_info;
2387 menu = collection_table_drop_menu(ct);
2388 gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr);
2401 collection_table_insert_filelist(ct, list, drop_info);
2402 filelist_free(list);
2406 static void collection_table_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
2408 auto ct = static_cast<CollectTable *>(data);
2410 if (ct->click_info && ct->click_info->pixbuf)
2414 if (INFO_SELECTED(ct->click_info))
2415 items = g_list_length(ct->selection);
2418 dnd_set_drag_icon(widget, context, ct->click_info->pixbuf, items);
2422 static void collection_table_dnd_end(GtkWidget *, GdkDragContext *, gpointer data)
2424 auto ct = static_cast<CollectTable *>(data);
2426 /* apparently a leave event is not generated on a drop */
2429 collection_table_scroll(ct, FALSE);
2432 static gint collection_table_dnd_motion(GtkWidget *, GdkDragContext *, gint x, gint y, guint, gpointer data)
2434 auto ct = static_cast<CollectTable *>(data);
2436 collection_table_motion_update(ct, x, y, TRUE);
2437 collection_table_scroll(ct, TRUE);
2442 static void collection_table_dnd_leave(GtkWidget *, GdkDragContext *, guint, gpointer data)
2444 auto ct = static_cast<CollectTable *>(data);
2446 collection_table_scroll(ct, FALSE);
2449 static void collection_table_dnd_init(CollectTable *ct)
2451 gtk_drag_source_set(ct->listview, static_cast<GdkModifierType>(GDK_BUTTON1_MASK | GDK_BUTTON2_MASK),
2452 collection_drag_types, n_collection_drag_types,
2453 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
2454 g_signal_connect(G_OBJECT(ct->listview), "drag_data_get",
2455 G_CALLBACK(collection_table_dnd_get), ct);
2456 g_signal_connect(G_OBJECT(ct->listview), "drag_begin",
2457 G_CALLBACK(collection_table_dnd_begin), ct);
2458 g_signal_connect(G_OBJECT(ct->listview), "drag_end",
2459 G_CALLBACK(collection_table_dnd_end), ct);
2461 gtk_drag_dest_set(ct->listview,
2462 static_cast<GtkDestDefaults>(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP),
2463 collection_drop_types, n_collection_drop_types,
2464 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK));
2465 g_signal_connect(G_OBJECT(ct->listview), "drag_motion",
2466 G_CALLBACK(collection_table_dnd_motion), ct);
2467 g_signal_connect(G_OBJECT(ct->listview), "drag_leave",
2468 G_CALLBACK(collection_table_dnd_leave), ct);
2469 g_signal_connect(G_OBJECT(ct->listview), "drag_data_received",
2470 G_CALLBACK(collection_table_dnd_receive), ct);
2474 *-----------------------------------------------------------------------------
2476 *-----------------------------------------------------------------------------
2485 static void collection_table_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
2486 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
2488 auto cd = static_cast<ColumnData *>(data);
2491 gchar *display_text = nullptr;
2492 gchar *star_rating = nullptr;
2494 GdkRGBA color_bg_style;
2496 GdkRGBA color_fg_style;
2502 gtk_tree_model_get(tree_model, iter, CTABLE_COLUMN_POINTER, &list, -1);
2504 /** @FIXME this is a primitive hack to stop a crash.
2505 * When compiled with GTK3, if a Collection window containing
2506 * say, 50 or so, images has its width changed, there is a segfault
2507 * https://github.com/BestImageViewer/geeqie/issues/531
2509 if (cd->number == COLLECT_TABLE_MAX_COLUMNS) return;
2511 info = static_cast<CollectInfo *>(g_list_nth_data(list, cd->number));
2513 style = gtk_widget_get_style(ct->listview);
2514 if (info && (info->flag_mask & SELECTION_SELECTED) )
2516 convert_gdkcolor_to_gdkrgba(&style->text[GTK_STATE_SELECTED], &color_fg_style);
2517 convert_gdkcolor_to_gdkrgba(&style->base[GTK_STATE_SELECTED], &color_bg_style);
2519 memcpy(&color_fg, &color_fg_style, sizeof(color_fg));
2520 memcpy(&color_bg, &color_bg_style, sizeof(color_bg));
2524 convert_gdkcolor_to_gdkrgba(&style->text[GTK_STATE_NORMAL], &color_fg_style);
2525 convert_gdkcolor_to_gdkrgba(&style->base[GTK_STATE_NORMAL], &color_bg_style);
2527 memcpy(&color_fg, &color_fg_style, sizeof(color_fg));
2528 memcpy(&color_bg, &color_bg_style, sizeof(color_bg));
2530 memcpy(&color_fg, &color_fg_style, sizeof(color_fg));
2531 memcpy(&color_bg, &color_bg_style, sizeof(color_bg));
2534 if (info && (info->flag_mask & SELECTION_PRELIGHT))
2536 shift_color(&color_bg, -1, 0);
2539 if (ct->show_stars && info && info->fd)
2541 star_rating = metadata_read_rating_stars(info->fd);
2545 star_rating = g_strdup("");
2548 if (info && info->fd)
2550 if (ct->show_text && ct->show_stars)
2552 display_text = g_strconcat(info->fd->name, "\n", star_rating, NULL);
2554 else if (ct->show_text)
2556 display_text = g_strdup(info->fd->name);
2558 else if (ct->show_stars)
2560 display_text = g_strdup(star_rating);
2564 display_text = g_strdup("");
2569 display_text = g_strdup("");
2572 if (GQV_IS_CELL_RENDERER_ICON(cell))
2576 g_object_set(cell, "pixbuf", info->pixbuf,
2577 "text", display_text,
2578 "cell-background-rgba", &color_bg,
2579 "cell-background-set", TRUE,
2580 "foreground-rgba", &color_fg,
2581 "foreground-set", TRUE,
2582 "has-focus", (ct->focus_info == info), NULL);
2586 g_object_set(cell, "pixbuf", NULL,
2588 "cell-background-set", FALSE,
2589 "foreground-set", FALSE,
2590 "has-focus", FALSE, NULL);
2594 g_free(display_text);
2595 g_free(star_rating);
2598 static void collection_table_append_column(CollectTable *ct, gint n)
2601 GtkTreeViewColumn *column;
2602 GtkCellRenderer *renderer;
2604 column = gtk_tree_view_column_new();
2605 gtk_tree_view_column_set_min_width(column, 0);
2607 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
2608 gtk_tree_view_column_set_alignment(column, 0.5);
2610 renderer = gqv_cell_renderer_icon_new();
2611 gtk_tree_view_column_pack_start(column, renderer, FALSE);
2612 g_object_set(G_OBJECT(renderer), "xpad", THUMB_BORDER_PADDING * 2,
2613 "ypad", THUMB_BORDER_PADDING,
2614 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
2616 g_object_set_data(G_OBJECT(column), "column_number", GINT_TO_POINTER(n));
2618 cd = g_new0(ColumnData, 1);
2621 gtk_tree_view_column_set_cell_data_func(column, renderer, collection_table_cell_data_cb, cd, g_free);
2623 gtk_tree_view_append_column(GTK_TREE_VIEW(ct->listview), column);
2627 *-------------------------------------------------------------------
2629 *-------------------------------------------------------------------
2632 static void collection_table_destroy(GtkWidget *, gpointer data)
2634 auto ct = static_cast<CollectTable *>(data);
2636 /* If there is no unsaved data, save the window geometry
2638 if (!ct->cd->changed)
2640 if (!collection_save(ct->cd, ct->cd->path))
2642 log_printf("failed saving to collection path: %s\n", ct->cd->path);
2648 g_signal_handlers_disconnect_matched(G_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA,
2649 0, 0, nullptr, nullptr, ct);
2650 g_object_unref(ct->popup);
2653 if (ct->sync_idle_id) g_source_remove(ct->sync_idle_id);
2656 collection_table_scroll(ct, FALSE);
2661 static void collection_table_sized(GtkWidget *, GtkAllocation *allocation, gpointer data)
2663 auto ct = static_cast<CollectTable *>(data);
2665 collection_table_populate_at_new_size(ct, allocation->width, allocation->height, FALSE);
2668 CollectTable *collection_table_new(CollectionData *cd)
2671 GtkListStore *store;
2672 GtkTreeSelection *selection;
2675 ct = g_new0(CollectTable, 1);
2678 ct->show_text = options->show_icon_names;
2679 ct->show_stars = options->show_star_rating;
2681 ct->scrolled = gq_gtk_scrolled_window_new(nullptr, nullptr);
2682 gq_gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN);
2683 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ct->scrolled),
2684 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2686 store = gtk_list_store_new(1, G_TYPE_POINTER);
2687 ct->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
2688 g_object_unref(store);
2690 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ct->listview));
2691 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_NONE);
2693 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ct->listview), FALSE);
2694 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ct->listview), FALSE);
2696 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
2698 collection_table_append_column(ct, i);
2701 /* zero width column to hide tree view focus, we draw it ourselves */
2702 collection_table_append_column(ct, i);
2703 /* end column to fill white space */
2704 collection_table_append_column(ct, i);
2706 g_signal_connect(G_OBJECT(ct->listview), "destroy",
2707 G_CALLBACK(collection_table_destroy), ct);
2708 g_signal_connect(G_OBJECT(ct->listview), "size_allocate",
2709 G_CALLBACK(collection_table_sized), ct);
2710 g_signal_connect(G_OBJECT(ct->listview), "key_press_event",
2711 G_CALLBACK(collection_table_press_key_cb), ct);
2713 gq_gtk_container_add(GTK_WIDGET(ct->scrolled), ct->listview);
2714 gtk_widget_show(ct->listview);
2716 collection_table_dnd_init(ct);
2718 gtk_widget_set_events(ct->listview, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK |
2719 static_cast<GdkEventMask>(GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK));
2720 g_signal_connect(G_OBJECT(ct->listview),"button_press_event",
2721 G_CALLBACK(collection_table_press_cb), ct);
2722 g_signal_connect(G_OBJECT(ct->listview),"button_release_event",
2723 G_CALLBACK(collection_table_release_cb), ct);
2724 g_signal_connect(G_OBJECT(ct->listview),"motion_notify_event",
2725 G_CALLBACK(collection_table_motion_cb), ct);
2726 g_signal_connect(G_OBJECT(ct->listview), "leave_notify_event",
2727 G_CALLBACK(collection_table_leave_cb), ct);
2732 void collection_table_set_labels(CollectTable *ct, GtkWidget *status, GtkWidget *extra)
2734 ct->status_label = status;
2735 ct->extra_label = extra;
2736 collection_table_update_status(ct);
2737 collection_table_update_extras(ct, FALSE, 0.0);
2740 CollectInfo *collection_table_get_focus_info(CollectTable *ct)
2742 return collection_table_find_data(ct, ct->focus_row, ct->focus_column, nullptr);
2745 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */