Deduplicate cell_renderer_height_override()
[geeqie.git] / src / collect-table.cc
1 /*
2  * Copyright (C) 2004 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
6  *
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.
11  *
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.
16  *
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.
20  */
21
22 #include "collect-table.h"
23
24 #include <cstddef>
25
26 #include <cairo.h>
27 #include <gdk-pixbuf/gdk-pixbuf.h>
28 #include <gio/gio.h>
29 #include <glib-object.h>
30
31 #include "cellrenderericon.h"
32 #include "collect-dlg.h"
33 #include "collect-io.h"
34 #include "collect.h"
35 #include "compat.h"
36 #include "debug.h"
37 #include "dnd.h"
38 #include "dupe.h"
39 #include "filedata.h"
40 #include "img-view.h"
41 #include "intl.h"
42 #include "layout-image.h"
43 #include "layout.h"
44 #include "main-defines.h"
45 #include "menu.h"
46 #include "metadata.h"
47 #include "misc.h"
48 #include "options.h"
49 #include "print.h"
50 #include "typedefs.h"
51 #include "ui-fileops.h"
52 #include "ui-menu.h"
53 #include "ui-tree-edit.h"
54 #include "uri-utils.h"
55 #include "utilops.h"
56 #include "view-file.h"
57
58 namespace
59 {
60
61 /* between these, the icon width is increased by thumb_max_width / 2 */
62 constexpr gint THUMB_MIN_ICON_WIDTH = 128;
63 constexpr gint THUMB_MAX_ICON_WIDTH = 150;
64
65 constexpr gint COLLECT_TABLE_MAX_COLUMNS = 32;
66
67 constexpr gint THUMB_BORDER_PADDING = 2;
68
69 constexpr gint COLLECT_TABLE_TIP_DELAY = 500;
70 constexpr gint COLLECT_TABLE_TIP_DELAY_PATH = 850;
71
72 enum {
73         CTABLE_COLUMN_POINTER = 0,
74         CTABLE_COLUMN_COUNT
75 };
76
77 struct ColumnData
78 {
79         CollectTable *ct;
80         gint number;
81 };
82
83 inline gboolean info_selected(const CollectInfo *info)
84 {
85         return info->flag_mask & SELECTION_SELECTED;
86 }
87
88 } // namespace
89
90 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint h, gboolean force);
91
92 /**
93  * This array must be kept in sync with the contents of:\n
94  * @link collection_table_press_key_cb @endlink \n
95  * @link collection_window_keypress @endlink \n
96  * @link collection_table_popup_menu @endlink
97  *
98  * See also @link hard_coded_window_keys @endlink
99  **/
100 hard_coded_window_keys collection_window_keys[] = {
101         {GDK_CONTROL_MASK, 'C', N_("Copy")},
102         {GDK_CONTROL_MASK, 'M', N_("Move")},
103         {GDK_CONTROL_MASK, 'R', N_("Rename")},
104         {GDK_CONTROL_MASK, 'D', N_("Move to Trash")},
105         {GDK_CONTROL_MASK, 'W', N_("Close window")},
106         {static_cast<GdkModifierType>(0), GDK_KEY_Delete, N_("Remove")},
107         {static_cast<GdkModifierType>(0), GDK_KEY_Return, N_("View")},
108         {static_cast<GdkModifierType>(0), 'V', N_("View in new window")},
109         {GDK_CONTROL_MASK, 'A', N_("Select all")},
110         {static_cast<GdkModifierType>(GDK_CONTROL_MASK + GDK_SHIFT_MASK), 'A', N_("Select none")},
111         {GDK_MOD1_MASK, 'R', N_("Rectangular selection")},
112         {static_cast<GdkModifierType>(0), GDK_KEY_space, N_("Select single file")},
113         {GDK_CONTROL_MASK, GDK_KEY_space, N_("Toggle select image")},
114         {GDK_CONTROL_MASK, 'L', N_("Append from file selection")},
115         {static_cast<GdkModifierType>(0), 'A', N_("Append from collection")},
116         {static_cast<GdkModifierType>(0), 'S', N_("Save collection")},
117         {GDK_CONTROL_MASK, 'S', N_("Save collection as")},
118         {GDK_CONTROL_MASK, 'T', N_("Show filename text")},
119         {static_cast<GdkModifierType>(0), 'N', N_("Sort by name")},
120         {static_cast<GdkModifierType>(0), 'D', N_("Sort by date")},
121         {static_cast<GdkModifierType>(0), 'B', N_("Sort by size")},
122         {static_cast<GdkModifierType>(0), 'P', N_("Sort by path")},
123         {GDK_SHIFT_MASK, 'P', N_("Print")},
124         {GDK_MOD1_MASK, 'A', N_("Append (Append collection dialog)")},
125         {GDK_MOD1_MASK, 'D', N_("Discard (Close modified collection dialog)")},
126         {static_cast<GdkModifierType>(0), 0, nullptr}
127 };
128
129 /*
130  *-------------------------------------------------------------------
131  * more misc
132  *-------------------------------------------------------------------
133  */
134
135 static gboolean collection_table_find_position(CollectTable *ct, CollectInfo *info, gint *row, gint *col)
136 {
137         gint n;
138
139         n = g_list_index(ct->cd->list, info);
140
141         if (n < 0) return FALSE;
142
143         *row = n / ct->columns;
144         *col = n - (*row * ct->columns);
145
146         return TRUE;
147 }
148
149 static gboolean collection_table_find_iter(CollectTable *ct, CollectInfo *info, GtkTreeIter *iter, gint *column)
150 {
151         GtkTreeModel *store;
152         gint row;
153         gint col;
154
155         store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
156         if (!collection_table_find_position(ct, info, &row, &col)) return FALSE;
157         if (!gtk_tree_model_iter_nth_child(store, iter, nullptr, row)) return FALSE;
158         if (column) *column = col;
159
160         return TRUE;
161 }
162
163 static CollectInfo *collection_table_find_data(CollectTable *ct, gint row, gint col, GtkTreeIter *iter)
164 {
165         GtkTreeModel *store;
166         GtkTreeIter p;
167
168         if (row < 0 || col < 0) return nullptr;
169
170         store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
171         if (gtk_tree_model_iter_nth_child(store, &p, nullptr, row))
172                 {
173                 GList *list;
174
175                 gtk_tree_model_get(store, &p, CTABLE_COLUMN_POINTER, &list, -1);
176                 if (!list) return nullptr;
177
178                 if (iter) *iter = p;
179
180                 return static_cast<CollectInfo *>(g_list_nth_data(list, col));
181                 }
182
183         return nullptr;
184 }
185
186 static CollectInfo *collection_table_find_data_by_coord(CollectTable *ct, gint x, gint y, GtkTreeIter *iter)
187 {
188         GtkTreePath *tpath;
189         GtkTreeViewColumn *column;
190         GtkTreeModel *store;
191         GtkTreeIter row;
192         GList *list;
193         gint n;
194
195         if (!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
196                                            &tpath, &column, nullptr, nullptr))
197                 return nullptr;
198
199         store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
200         gtk_tree_model_get_iter(store, &row, tpath);
201         gtk_tree_path_free(tpath);
202
203         gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
204         if (!list) return nullptr;
205
206         n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
207         if (iter) *iter = row;
208         return static_cast<CollectInfo *>(g_list_nth_data(list, n));
209 }
210
211 static guint collection_table_list_count(CollectTable *ct, gint64 *bytes)
212 {
213         if (bytes)
214                 {
215                 gint64 b = 0;
216                 GList *work;
217
218                 work = ct->cd->list;
219                 while (work)
220                         {
221                         auto ci = static_cast<CollectInfo *>(work->data);
222                         work = work->next;
223                         b += ci->fd->size;
224                         }
225
226                 *bytes = b;
227                 }
228
229         return g_list_length(ct->cd->list);
230 }
231
232 static guint collection_table_selection_count(CollectTable *ct, gint64 *bytes)
233 {
234         if (bytes)
235                 {
236                 gint64 b = 0;
237                 GList *work;
238
239                 work = ct->selection;
240                 while (work)
241                         {
242                         auto ci = static_cast<CollectInfo *>(work->data);
243                         work = work->next;
244                         b += ci->fd->size;
245                         }
246
247                 *bytes = b;
248                 }
249
250         return g_list_length(ct->selection);
251 }
252
253 static void collection_table_update_status(CollectTable *ct)
254 {
255         gchar *buf;
256         guint n;
257         gint64 n_bytes = 0;
258         guint s;
259         gint64 s_bytes = 0;
260
261         if (!ct->status_label) return;
262
263         n = collection_table_list_count(ct, &n_bytes);
264         s = collection_table_selection_count(ct, &s_bytes);
265
266         if (s > 0)
267                 {
268                 gchar *b = text_from_size_abrev(n_bytes);
269                 gchar *sb = text_from_size_abrev(s_bytes);
270                 buf = g_strdup_printf(_("%s, %d images (%s, %d)"), b, n, sb, s);
271                 g_free(b);
272                 g_free(sb);
273                 }
274         else if (n > 0)
275                 {
276                 gchar *b = text_from_size_abrev(n_bytes);
277                 buf = g_strdup_printf(_("%s, %d images"), b, n);
278                 g_free(b);
279                 }
280         else
281                 {
282                 buf = g_strdup(_("Empty"));
283                 }
284
285         gtk_label_set_text(GTK_LABEL(ct->status_label), buf);
286         g_free(buf);
287 }
288
289 static void collection_table_update_extras(CollectTable *ct, gboolean loading, gdouble value)
290 {
291         const gchar *text;
292
293         if (!ct->extra_label) return;
294
295         if (loading)
296                 text = _("Loading thumbs...");
297         else
298                 text = " ";
299
300         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ct->extra_label), value);
301         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ct->extra_label), text);
302 }
303
304 static void collection_table_toggle_filenames(CollectTable *ct)
305 {
306         GtkAllocation allocation;
307         ct->show_text = !ct->show_text;
308         options->show_icon_names = ct->show_text;
309
310         gtk_widget_get_allocation(ct->listview, &allocation);
311         collection_table_populate_at_new_size(ct, allocation.width, allocation.height, TRUE);
312 }
313
314 static void collection_table_toggle_stars(CollectTable *ct)
315 {
316         GtkAllocation allocation;
317         ct->show_stars = !ct->show_stars;
318         options->show_star_rating = ct->show_stars;
319
320         gtk_widget_get_allocation(ct->listview, &allocation);
321         collection_table_populate_at_new_size(ct, allocation.width, allocation.height, TRUE);
322 }
323
324 static gint collection_table_get_icon_width(CollectTable *ct)
325 {
326         gint width;
327
328         if (!ct->show_text) return options->thumbnails.max_width;
329
330         width = options->thumbnails.max_width + options->thumbnails.max_width / 2;
331         if (width < THUMB_MIN_ICON_WIDTH) width = THUMB_MIN_ICON_WIDTH;
332         if (width > THUMB_MAX_ICON_WIDTH) width = options->thumbnails.max_width;
333
334         return width;
335 }
336
337 /*
338  *-------------------------------------------------------------------
339  * cell updates
340  *-------------------------------------------------------------------
341  */
342
343 static void collection_table_selection_set(CollectTable *ct, CollectInfo *info, SelectionType value, GtkTreeIter *iter)
344 {
345         GtkTreeModel *store;
346         GList *list;
347
348         if (!info) return;
349
350         if (info->flag_mask == value) return;
351         info->flag_mask = value;
352
353         store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
354         if (iter)
355                 {
356                 gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
357                 if (list) gtk_list_store_set(GTK_LIST_STORE(store), iter, CTABLE_COLUMN_POINTER, list, -1);
358                 }
359         else
360                 {
361                 GtkTreeIter row;
362
363                 if (collection_table_find_iter(ct, info, &row, nullptr))
364                         {
365                         gtk_tree_model_get(store, &row, CTABLE_COLUMN_POINTER, &list, -1);
366                         if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, CTABLE_COLUMN_POINTER, list, -1);
367                         }
368                 }
369 }
370
371 static void collection_table_selection_add(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
372 {
373         if (!info) return;
374
375         collection_table_selection_set(ct, info, static_cast<SelectionType>(info->flag_mask | mask), iter);
376 }
377
378 static void collection_table_selection_remove(CollectTable *ct, CollectInfo *info, SelectionType mask, GtkTreeIter *iter)
379 {
380         if (!info) return;
381
382         collection_table_selection_set(ct, info, static_cast<SelectionType>(info->flag_mask & ~mask), iter);
383 }
384 /*
385  *-------------------------------------------------------------------
386  * selections
387  *-------------------------------------------------------------------
388  */
389
390 static void collection_table_verify_selections(CollectTable *ct)
391 {
392         GList *work;
393
394         work = ct->selection;
395         while (work)
396                 {
397                 auto info = static_cast<CollectInfo *>(work->data);
398                 work = work->next;
399                 if (!g_list_find(ct->cd->list, info))
400                         {
401                         ct->selection = g_list_remove(ct->selection, info);
402                         }
403                 }
404 }
405
406 void collection_table_select_all(CollectTable *ct)
407 {
408         GList *work;
409
410         g_list_free(ct->selection);
411         ct->selection = nullptr;
412
413         work = ct->cd->list;
414         while (work)
415                 {
416                 ct->selection = g_list_append(ct->selection, work->data);
417                 collection_table_selection_add(ct, static_cast<CollectInfo *>(work->data), SELECTION_SELECTED, nullptr);
418                 work = work->next;
419                 }
420
421         collection_table_update_status(ct);
422 }
423
424 void collection_table_unselect_all(CollectTable *ct)
425 {
426         GList *work;
427
428         work = ct->selection;
429         while (work)
430                 {
431                 collection_table_selection_remove(ct, static_cast<CollectInfo *>(work->data), SELECTION_SELECTED, nullptr);
432                 work = work->next;
433                 }
434
435         g_list_free(ct->selection);
436         ct->selection = nullptr;
437
438         collection_table_update_status(ct);
439 }
440
441 /* Invert the current collection's selection */
442 static void collection_table_select_invert_all(CollectTable *ct)
443 {
444         GList *work;
445         GList *new_selection = nullptr;
446
447         work = ct->cd->list;
448         while (work)
449                 {
450                 auto info = static_cast<CollectInfo *>(work->data);
451
452                 if (info_selected(info))
453                         {
454                         collection_table_selection_remove(ct, info, SELECTION_SELECTED, nullptr);
455                         }
456                 else
457                         {
458                         new_selection = g_list_append(new_selection, info);
459                         collection_table_selection_add(ct, info, SELECTION_SELECTED, nullptr);
460
461                         }
462
463                 work = work->next;
464                 }
465
466         g_list_free(ct->selection);
467         ct->selection = new_selection;
468
469         collection_table_update_status(ct);
470 }
471
472 void collection_table_select(CollectTable *ct, CollectInfo *info)
473 {
474         ct->prev_selection = info;
475
476         if (!info || info_selected(info)) return;
477
478         ct->selection = g_list_append(ct->selection, info);
479         collection_table_selection_add(ct, info, SELECTION_SELECTED, nullptr);
480
481         collection_table_update_status(ct);
482 }
483
484 static void collection_table_unselect(CollectTable *ct, CollectInfo *info)
485 {
486         ct->prev_selection = info;
487
488         if (!info || !info_selected(info) ) return;
489
490         ct->selection = g_list_remove(ct->selection, info);
491         collection_table_selection_remove(ct, info, SELECTION_SELECTED, nullptr);
492
493         collection_table_update_status(ct);
494 }
495
496 static void collection_table_select_util(CollectTable *ct, CollectInfo *info, gboolean select)
497 {
498         if (select)
499                 {
500                 collection_table_select(ct, info);
501                 }
502         else
503                 {
504                 collection_table_unselect(ct, info);
505                 }
506 }
507
508 static void collection_table_select_region_util(CollectTable *ct, CollectInfo *start, CollectInfo *end, gboolean select)
509 {
510         gint row1;
511         gint col1;
512         gint row2;
513         gint col2;
514         gint t;
515         gint i;
516         gint j;
517
518         if (!collection_table_find_position(ct, start, &row1, &col1) ||
519             !collection_table_find_position(ct, end, &row2, &col2) ) return;
520
521         ct->prev_selection = end;
522
523         if (!options->collections.rectangular_selection)
524                 {
525                 GList *work;
526                 CollectInfo *info;
527
528                 if (g_list_index(ct->cd->list, start) > g_list_index(ct->cd->list, end))
529                         {
530                         info = start;
531                         start = end;
532                         end = info;
533                         }
534
535                 work = g_list_find(ct->cd->list, start);
536                 while (work)
537                         {
538                         info = static_cast<CollectInfo *>(work->data);
539                         collection_table_select_util(ct, info, select);
540
541                         if (work->data != end)
542                                 work = work->next;
543                         else
544                                 work = nullptr;
545                         }
546                 return;
547                 }
548
549         if (row2 < row1)
550                 {
551                 t = row1;
552                 row1 = row2;
553                 row2 = t;
554                 }
555         if (col2 < col1)
556                 {
557                 t = col1;
558                 col1 = col2;
559                 col2 = t;
560                 }
561
562         DEBUG_1("table: %d x %d to %d x %d", row1, col1, row2, col2);
563
564         for (i = row1; i <= row2; i++)
565                 {
566                 for (j = col1; j <= col2; j++)
567                         {
568                         CollectInfo *info = collection_table_find_data(ct, i, j, nullptr);
569                         if (info) collection_table_select_util(ct, info, select);
570                         }
571                 }
572 }
573
574 GList *collection_table_selection_get_list(CollectTable *ct)
575 {
576         return collection_list_to_filelist(ct->selection);
577 }
578
579 static GList *collection_table_get_list(CollectTable *ct)
580 {
581         return collection_list_to_filelist(ct->cd->list);
582 }
583
584 /*
585  *-------------------------------------------------------------------
586  * tooltip type window
587  *-------------------------------------------------------------------
588  */
589
590 static void tip_show(CollectTable *ct)
591 {
592         GtkWidget *label;
593         gint x;
594         gint y;
595         GdkDisplay *display;
596         GdkSeat *seat;
597         GdkDevice *device;
598
599         if (ct->tip_window) return;
600
601         seat = gdk_display_get_default_seat(gdk_window_get_display(gtk_widget_get_window(ct->listview)));
602         device = gdk_seat_get_pointer(seat);
603         gdk_window_get_device_position(gtk_widget_get_window(ct->listview),
604                                                                 device, &x, &y, nullptr);
605
606         ct->tip_info = collection_table_find_data_by_coord(ct, x, y, nullptr);
607         if (!ct->tip_info) return;
608
609         ct->tip_window = gtk_window_new(GTK_WINDOW_POPUP);
610         gtk_window_set_resizable(GTK_WINDOW(ct->tip_window), FALSE);
611         gtk_container_set_border_width(GTK_CONTAINER(ct->tip_window), 2);
612
613         label = gtk_label_new(ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
614
615         g_object_set_data(G_OBJECT(ct->tip_window), "tip_label", label);
616         gq_gtk_container_add(GTK_WIDGET(ct->tip_window), label);
617         gtk_widget_show(label);
618
619         display = gdk_display_get_default();
620         seat = gdk_display_get_default_seat(display);
621         device = gdk_seat_get_pointer(seat);
622         gdk_device_get_position(device, nullptr, &x, &y);
623
624         if (!gtk_widget_get_realized(ct->tip_window)) gtk_widget_realize(ct->tip_window);
625         gq_gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
626         gtk_widget_show(ct->tip_window);
627 }
628
629 static void tip_hide(CollectTable *ct)
630 {
631         if (ct->tip_window) gq_gtk_widget_destroy(ct->tip_window);
632         ct->tip_window = nullptr;
633 }
634
635 static gboolean tip_schedule_cb(gpointer data)
636 {
637         auto ct = static_cast<CollectTable *>(data);
638
639         if (!ct->tip_delay_id) return FALSE;
640
641         tip_show(ct);
642
643         ct->tip_delay_id = 0;
644         return FALSE;
645 }
646
647 static void tip_schedule(CollectTable *ct)
648 {
649         tip_hide(ct);
650
651         if (ct->tip_delay_id)
652                 {
653                 g_source_remove(ct->tip_delay_id);
654                 ct->tip_delay_id = 0;
655                 }
656
657         ct->tip_delay_id = g_timeout_add(ct->show_text ? COLLECT_TABLE_TIP_DELAY_PATH : COLLECT_TABLE_TIP_DELAY, tip_schedule_cb, ct);
658 }
659
660 static void tip_unschedule(CollectTable *ct)
661 {
662         tip_hide(ct);
663
664         if (ct->tip_delay_id)
665                 {
666                 g_source_remove(ct->tip_delay_id);
667                 ct->tip_delay_id = 0;
668                 }
669 }
670
671 static void tip_update(CollectTable *ct, CollectInfo *info)
672 {
673         GdkDisplay *display = gdk_display_get_default();
674         GdkSeat *seat = gdk_display_get_default_seat(display);
675         GdkDevice *device = gdk_seat_get_pointer(seat);
676
677         tip_schedule(ct);
678
679         if (ct->tip_window)
680                 {
681                 gint x;
682                 gint y;
683                 gdk_device_get_position(device, nullptr, &x, &y);
684
685                 gq_gtk_window_move(GTK_WINDOW(ct->tip_window), x + 16, y + 16);
686
687                 if (info != ct->tip_info)
688                         {
689                         GtkWidget *label;
690
691                         ct->tip_info = info;
692
693                         if (!ct->tip_info)
694                                 {
695                                 return;
696                                 }
697
698                         label = static_cast<GtkWidget *>(g_object_get_data(G_OBJECT(ct->tip_window), "tip_label"));
699                         gtk_label_set_text(GTK_LABEL(label), ct->show_text ? ct->tip_info->fd->path : ct->tip_info->fd->name);
700                         }
701                 }
702 }
703
704 /*
705  *-------------------------------------------------------------------
706  * popup menus
707  *-------------------------------------------------------------------
708  */
709
710 static void collection_table_popup_save_as_cb(GtkWidget *, gpointer data)
711 {
712         auto ct = static_cast<CollectTable *>(data);
713
714         collection_dialog_save_as(ct->cd);
715 }
716
717 static void collection_table_popup_save_cb(GtkWidget *widget, gpointer data)
718 {
719         auto ct = static_cast<CollectTable *>(data);
720
721         if (!ct->cd->path)
722                 {
723                 collection_table_popup_save_as_cb(widget, data);
724                 return;
725                 }
726
727         if (!collection_save(ct->cd, ct->cd->path))
728                 {
729                 log_printf("failed saving to collection path: %s\n", ct->cd->path);
730                 }
731 }
732
733 static GList *collection_table_popup_file_list(CollectTable *ct)
734 {
735         if (!ct->click_info) return nullptr;
736
737         if (info_selected(ct->click_info))
738                 {
739                 return collection_table_selection_get_list(ct);
740                 }
741
742         return g_list_append(nullptr, file_data_ref(ct->click_info->fd));
743 }
744
745 static void collection_table_popup_edit_cb(GtkWidget *widget, gpointer data)
746 {
747         CollectTable *ct;
748         auto key = static_cast<const gchar *>(data);
749
750         ct = static_cast<CollectTable *>(submenu_item_get_data(widget));
751
752         if (!ct) return;
753
754         file_util_start_editor_from_filelist(key, collection_table_popup_file_list(ct), nullptr, ct->listview);
755 }
756
757 static void collection_table_popup_copy_cb(GtkWidget *, gpointer data)
758 {
759         auto ct = static_cast<CollectTable *>(data);
760
761         file_util_copy(nullptr, collection_table_popup_file_list(ct), nullptr, ct->listview);
762 }
763
764 static void collection_table_popup_move_cb(GtkWidget *, gpointer data)
765 {
766         auto ct = static_cast<CollectTable *>(data);
767
768         file_util_move(nullptr, collection_table_popup_file_list(ct), nullptr, ct->listview);
769 }
770
771 static void collection_table_popup_rename_cb(GtkWidget *, gpointer data)
772 {
773         auto ct = static_cast<CollectTable *>(data);
774
775         file_util_rename(nullptr, collection_table_popup_file_list(ct), ct->listview);
776 }
777
778 static void collection_table_popup_delete_cb(GtkWidget *, gpointer data)
779 {
780         auto ct = static_cast<CollectTable *>(data);
781
782         options->file_ops.safe_delete_enable = FALSE;
783         file_util_delete(nullptr, collection_table_popup_file_list(ct), ct->listview);
784 }
785
786 static void collection_table_popup_move_to_trash_cb(GtkWidget *, gpointer data)
787 {
788         auto ct = static_cast<CollectTable *>(data);
789
790         options->file_ops.safe_delete_enable = TRUE;
791         file_util_delete(nullptr, collection_table_popup_file_list(ct), ct->listview);
792 }
793
794 static void collection_table_popup_copy_path_cb(GtkWidget *, gpointer data)
795 {
796         auto ct = static_cast<CollectTable *>(data);
797
798         file_util_copy_path_list_to_clipboard(collection_table_popup_file_list(ct), TRUE);
799 }
800
801 static void collection_table_popup_copy_path_unquoted_cb(GtkWidget *, gpointer data)
802 {
803         auto ct = static_cast<CollectTable *>(data);
804
805         file_util_copy_path_list_to_clipboard(collection_table_popup_file_list(ct), FALSE);
806 }
807
808 static void collection_table_popup_sort_cb(GtkWidget *widget, gpointer data)
809 {
810         CollectTable *ct;
811         SortType type;
812
813         ct = static_cast<CollectTable *>(submenu_item_get_data(widget));
814
815         if (!ct) return;
816
817         type = static_cast<SortType>GPOINTER_TO_INT(data);
818
819         collection_set_sort_method(ct->cd, type);
820 }
821
822 static void collection_table_popup_randomize_cb(GtkWidget *widget, gpointer)
823 {
824         CollectTable *ct;
825
826         ct = static_cast<CollectTable *>(submenu_item_get_data(widget));
827
828         if (!ct) return;
829
830         collection_randomize(ct->cd);
831 }
832
833 static void collection_table_popup_view_new_cb(GtkWidget *, gpointer data)
834 {
835         auto ct = static_cast<CollectTable *>(data);
836
837         if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
838                 {
839                 view_window_new_from_collection(ct->cd, ct->click_info);
840                 }
841 }
842
843 static void collection_table_popup_view_cb(GtkWidget *, gpointer data)
844 {
845         auto ct = static_cast<CollectTable *>(data);
846
847         if (ct->click_info && g_list_find(ct->cd->list, ct->click_info))
848                 {
849                 layout_image_set_collection(nullptr, ct->cd, ct->click_info);
850                 }
851 }
852
853 static void collection_table_popup_selectall_cb(GtkWidget *, gpointer data)
854 {
855         auto ct = static_cast<CollectTable *>(data);
856
857         collection_table_select_all(ct);
858         ct->prev_selection= ct->click_info;
859 }
860
861 static void collection_table_popup_unselectall_cb(GtkWidget *, gpointer data)
862 {
863         auto ct = static_cast<CollectTable *>(data);
864
865         collection_table_unselect_all(ct);
866         ct->prev_selection= ct->click_info;
867 }
868
869 static void collection_table_popup_select_invert_cb(GtkWidget *, gpointer data)
870 {
871         auto ct = static_cast<CollectTable *>(data);
872
873         collection_table_select_invert_all(ct);
874         ct->prev_selection= ct->click_info;
875 }
876
877 static void collection_table_popup_rectangular_selection_cb(GtkWidget *, gpointer)
878 {
879         options->collections.rectangular_selection = !(options->collections.rectangular_selection);
880 }
881
882 static void collection_table_popup_remove_cb(GtkWidget *, gpointer data)
883 {
884         auto ct = static_cast<CollectTable *>(data);
885         GList *list;
886
887         if (!ct->click_info) return;
888
889         if (info_selected(ct->click_info))
890                 {
891                 list = g_list_copy(ct->selection);
892                 }
893         else
894                 {
895                 list = g_list_append(nullptr, ct->click_info);
896                 }
897
898         collection_remove_by_info_list(ct->cd, list);
899         collection_table_refresh(ct);
900         g_list_free(list);
901 }
902
903 static void collection_table_popup_add_file_selection_cb(GtkWidget *, gpointer data)
904 {
905         auto ct = static_cast<CollectTable *>(data);
906         GList *list;
907         LayoutWindow *lw = nullptr;
908
909         if (!layout_valid(&lw)) return;
910
911         list = vf_selection_get_list(lw->vf);
912
913         if (list)
914                 {
915                 collection_table_add_filelist(ct, list);
916                 filelist_free(list);
917                 }
918 }
919
920 static void collection_table_popup_add_collection_cb(GtkWidget *, gpointer data)
921 {
922         auto ct = static_cast<CollectTable *>(data);
923
924         collection_dialog_append(ct->cd);
925 }
926
927 static void collection_table_popup_goto_original_cb(GtkWidget *, gpointer data)
928 {
929         auto ct = static_cast<CollectTable *>(data);
930         GList *list;
931         LayoutWindow *lw = nullptr;
932         FileData *fd;
933
934         if (!layout_valid(&lw)) return;
935         list = collection_table_selection_get_list(ct);
936         if (list)
937                 {
938                 fd = static_cast<FileData *>(list->data);
939                 if (fd)
940                         {
941                         layout_set_fd(lw, fd);
942                         }
943                 }
944         g_list_free(list);
945 }
946
947 static void collection_table_popup_find_dupes_cb(GtkWidget *, gpointer data)
948 {
949         auto ct = static_cast<CollectTable *>(data);
950         DupeWindow *dw;
951
952         dw = dupe_window_new();
953         dupe_window_add_collection(dw, ct->cd);
954 }
955
956 static void collection_table_popup_print_cb(GtkWidget *, gpointer data)
957 {
958         auto ct = static_cast<CollectTable *>(data);
959         FileData *fd;
960
961         fd = (ct->click_info) ? ct->click_info->fd : nullptr;
962
963         print_window_new(fd, collection_table_selection_get_list(ct), collection_table_get_list(ct), gtk_widget_get_toplevel(ct->listview));
964 }
965
966 static void collection_table_popup_show_names_cb(GtkWidget *, gpointer data)
967 {
968         auto ct = static_cast<CollectTable *>(data);
969
970         collection_table_toggle_filenames(ct);
971 }
972
973 static void collection_table_popup_show_stars_cb(GtkWidget *, gpointer data)
974 {
975         auto ct = static_cast<CollectTable *>(data);
976
977         collection_table_toggle_stars(ct);
978 }
979
980 static void collection_table_popup_destroy_cb(GtkWidget *, gpointer data)
981 {
982         auto ct = static_cast<CollectTable *>(data);
983
984         collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, nullptr);
985         ct->click_info = nullptr;
986         ct->popup = nullptr;
987
988         filelist_free(ct->drop_list);
989         ct->drop_list = nullptr;
990         ct->drop_info = nullptr;
991
992         filelist_free(ct->editmenu_fd_list);
993         ct->editmenu_fd_list = nullptr;
994 }
995
996 static GtkWidget *collection_table_popup_menu(CollectTable *ct, gboolean over_icon)
997 {
998         GtkWidget *menu;
999         GtkWidget *item;
1000         GtkWidget *submenu;
1001         GtkAccelGroup *accel_group;
1002
1003         menu = popup_menu_short_lived();
1004
1005         accel_group = gtk_accel_group_new();
1006         gtk_menu_set_accel_group(GTK_MENU(menu), accel_group);
1007
1008         g_object_set_data(G_OBJECT(menu), "window_keys", collection_window_keys);
1009         g_object_set_data(G_OBJECT(menu), "accel_group", accel_group);
1010
1011         g_signal_connect(G_OBJECT(menu), "destroy",
1012                          G_CALLBACK(collection_table_popup_destroy_cb), ct);
1013
1014         menu_item_add_sensitive(menu, _("_View"), over_icon,
1015                         G_CALLBACK(collection_table_popup_view_cb), ct);
1016         menu_item_add_icon_sensitive(menu, _("View in _new window"), GQ_ICON_NEW, over_icon,
1017                         G_CALLBACK(collection_table_popup_view_new_cb), ct);
1018         menu_item_add_icon(menu, _("Go to original"), GQ_ICON_FIND,
1019                         G_CALLBACK(collection_table_popup_goto_original_cb), ct);
1020         menu_item_add_divider(menu);
1021         menu_item_add_icon_sensitive(menu, _("Rem_ove"), GQ_ICON_REMOVE, over_icon,
1022                         G_CALLBACK(collection_table_popup_remove_cb), ct);
1023
1024         menu_item_add_icon(menu, _("Append from file selection"), GQ_ICON_ADD,
1025                         G_CALLBACK(collection_table_popup_add_file_selection_cb), ct);
1026         menu_item_add_icon(menu, _("Append from collection..."), GQ_ICON_OPEN,
1027                         G_CALLBACK(collection_table_popup_add_collection_cb), ct);
1028         menu_item_add_divider(menu);
1029
1030         item = menu_item_add(menu, _("_Selection"), nullptr, nullptr);
1031         submenu = gtk_menu_new();
1032         menu_item_add(submenu, _("Select all"),
1033                         G_CALLBACK(collection_table_popup_selectall_cb), ct);
1034         menu_item_add(submenu, _("Select none"),
1035                         G_CALLBACK(collection_table_popup_unselectall_cb), ct);
1036         menu_item_add(submenu, _("Invert selection"),
1037                         G_CALLBACK(collection_table_popup_select_invert_cb), ct);
1038         menu_item_add_check(submenu, _("Rectangular selection"), (options->collections.rectangular_selection != FALSE),
1039                         G_CALLBACK(collection_table_popup_rectangular_selection_cb), ct);
1040         gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1041         menu_item_add_divider(menu);
1042
1043
1044         ct->editmenu_fd_list = collection_table_selection_get_list(ct);
1045         submenu_add_edit(menu, &item,
1046                         G_CALLBACK(collection_table_popup_edit_cb), ct, ct->editmenu_fd_list);
1047         gtk_widget_set_sensitive(item, over_icon);
1048
1049         menu_item_add_divider(menu);
1050         menu_item_add_icon_sensitive(menu, _("_Copy..."), GQ_ICON_COPY, over_icon,
1051                         G_CALLBACK(collection_table_popup_copy_cb), ct);
1052         menu_item_add_sensitive(menu, _("_Move..."), over_icon,
1053                         G_CALLBACK(collection_table_popup_move_cb), ct);
1054         menu_item_add_sensitive(menu, _("_Rename..."), over_icon,
1055                         G_CALLBACK(collection_table_popup_rename_cb), ct);
1056         menu_item_add_sensitive(menu, _("_Copy path"), over_icon,
1057                                 G_CALLBACK(collection_table_popup_copy_path_cb), ct);
1058         menu_item_add_sensitive(menu, _("_Copy path unquoted"), over_icon,
1059                                 G_CALLBACK(collection_table_popup_copy_path_unquoted_cb), ct);
1060
1061         menu_item_add_divider(menu);
1062         menu_item_add_icon_sensitive(menu,
1063                                 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
1064                                         _("Move to Trash"), GQ_ICON_DELETE, over_icon,
1065                                 G_CALLBACK(collection_table_popup_move_to_trash_cb), ct);
1066         menu_item_add_icon_sensitive(menu,
1067                                 options->file_ops.confirm_delete ? _("_Delete...") :
1068                                         _("_Delete"), GQ_ICON_DELETE_SHRED, over_icon,
1069                                 G_CALLBACK(collection_table_popup_delete_cb), ct);
1070
1071         menu_item_add_divider(menu);
1072         submenu = submenu_add_sort(nullptr, G_CALLBACK(collection_table_popup_sort_cb), ct, FALSE, TRUE, FALSE, SORT_NONE);
1073         menu_item_add_divider(submenu);
1074         menu_item_add(submenu, _("Randomize"),
1075                         G_CALLBACK(collection_table_popup_randomize_cb), ct);
1076         item = menu_item_add(menu, _("_Sort"), nullptr, nullptr);
1077         gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1078
1079         menu_item_add_check(menu, _("Show filename _text"), ct->show_text,
1080                         G_CALLBACK(collection_table_popup_show_names_cb), ct);
1081         menu_item_add_check(menu, _("Show star rating"), ct->show_stars,
1082                                 G_CALLBACK(collection_table_popup_show_stars_cb), ct);
1083         menu_item_add_divider(menu);
1084         menu_item_add_icon(menu, _("_Save collection"), GQ_ICON_SAVE,
1085                         G_CALLBACK(collection_table_popup_save_cb), ct);
1086         menu_item_add_icon(menu, _("Save collection _as..."), GQ_ICON_SAVE_AS,
1087                         G_CALLBACK(collection_table_popup_save_as_cb), ct);
1088         menu_item_add_divider(menu);
1089         menu_item_add_icon(menu, _("_Find duplicates..."), GQ_ICON_FIND,
1090                         G_CALLBACK(collection_table_popup_find_dupes_cb), ct);
1091         menu_item_add_icon_sensitive(menu, _("Print..."), GQ_ICON_PRINT, over_icon,
1092                         G_CALLBACK(collection_table_popup_print_cb), ct);
1093
1094         return menu;
1095 }
1096 /*
1097  *-------------------------------------------------------------------
1098  * keyboard callbacks
1099  *-------------------------------------------------------------------
1100  */
1101
1102 void collection_table_set_focus(CollectTable *ct, CollectInfo *info)
1103 {
1104         GtkTreeIter iter;
1105         gint row;
1106         gint col;
1107
1108         if (g_list_find(ct->cd->list, ct->focus_info))
1109                 {
1110                 if (info == ct->focus_info)
1111                         {
1112                         /* ensure focus row col are correct */
1113                         collection_table_find_position(ct, ct->focus_info,
1114                                                        &ct->focus_row, &ct->focus_column);
1115                         return;
1116                         }
1117                 collection_table_selection_remove(ct, ct->focus_info, SELECTION_FOCUS, nullptr);
1118                 }
1119
1120         if (!collection_table_find_position(ct, info, &row, &col))
1121                 {
1122                 ct->focus_info = nullptr;
1123                 ct->focus_row = -1;
1124                 ct->focus_column = -1;
1125                 return;
1126                 }
1127
1128         ct->focus_info = info;
1129         ct->focus_row = row;
1130         ct->focus_column = col;
1131         collection_table_selection_add(ct, ct->focus_info, SELECTION_FOCUS, nullptr);
1132
1133         if (collection_table_find_iter(ct, ct->focus_info, &iter, nullptr))
1134                 {
1135                 GtkTreePath *tpath;
1136                 GtkTreeViewColumn *column;
1137                 GtkTreeModel *store;
1138
1139                 tree_view_row_make_visible(GTK_TREE_VIEW(ct->listview), &iter, FALSE);
1140
1141                 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1142                 tpath = gtk_tree_model_get_path(store, &iter);
1143                 /* focus is set to an extra column with 0 width to hide focus, we draw it ourself */
1144                 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), COLLECT_TABLE_MAX_COLUMNS);
1145                 gtk_tree_view_set_cursor(GTK_TREE_VIEW(ct->listview), tpath, column, FALSE);
1146                 gtk_tree_path_free(tpath);
1147                 }
1148 }
1149
1150 static void collection_table_move_focus(CollectTable *ct, gint row, gint col, gboolean relative)
1151 {
1152         gint new_row;
1153         gint new_col;
1154
1155         if (relative)
1156                 {
1157                 new_row = ct->focus_row;
1158                 new_col = ct->focus_column;
1159
1160                 new_row += row;
1161                 if (new_row < 0) new_row = 0;
1162                 if (new_row >= ct->rows) new_row = ct->rows - 1;
1163
1164                 while (col != 0)
1165                         {
1166                         if (col < 0)
1167                                 {
1168                                 new_col--;
1169                                 col++;
1170                                 }
1171                         else
1172                                 {
1173                                 new_col++;
1174                                 col--;
1175                                 }
1176
1177                         if (new_col < 0)
1178                                 {
1179                                 if (new_row > 0)
1180                                         {
1181                                         new_row--;
1182                                         new_col = ct->columns - 1;
1183                                         }
1184                                 else
1185                                         {
1186                                         new_col = 0;
1187                                         }
1188                                 }
1189                         if (new_col >= ct->columns)
1190                                 {
1191                                 if (new_row < ct->rows - 1)
1192                                         {
1193                                         new_row++;
1194                                         new_col = 0;
1195                                         }
1196                                 else
1197                                         {
1198                                         new_col = ct->columns - 1;
1199                                         }
1200                                 }
1201                         }
1202                 }
1203         else
1204                 {
1205                 new_row = row;
1206                 new_col = col;
1207
1208                 if (new_row >= ct->rows)
1209                         {
1210                         if (ct->rows > 0)
1211                                 new_row = ct->rows - 1;
1212                         else
1213                                 new_row = 0;
1214                         new_col = ct->columns - 1;
1215                         }
1216                 if (new_col >= ct->columns) new_col = ct->columns - 1;
1217                 }
1218
1219         if (new_row == ct->rows - 1)
1220                 {
1221                 gint l;
1222
1223                 /* if we moved beyond the last image, go to the last image */
1224
1225                 l = g_list_length(ct->cd->list);
1226                 if (ct->rows > 1) l -= (ct->rows - 1) * ct->columns;
1227                 if (new_col >= l) new_col = l - 1;
1228                 }
1229
1230         if (new_row == -1 || new_col == -1)
1231                 {
1232                 if (!ct->cd->list) return;
1233                 new_row = new_col = 0;
1234                 }
1235
1236         collection_table_set_focus(ct, collection_table_find_data(ct, new_row, new_col, nullptr));
1237 }
1238
1239 static void collection_table_update_focus(CollectTable *ct)
1240 {
1241         gint new_row = 0;
1242         gint new_col = 0;
1243
1244         if (ct->focus_info && collection_table_find_position(ct, ct->focus_info, &new_row, &new_col))
1245                 {
1246                 /* first find the old focus, if it exists and is valid */
1247                 }
1248         else
1249                 {
1250                 /* (try to) stay where we were */
1251                 new_row = ct->focus_row;
1252                 new_col = ct->focus_column;
1253                 }
1254
1255         collection_table_move_focus(ct, new_row, new_col, FALSE);
1256 }
1257
1258 /* used to figure the page up/down distances */
1259 static gint page_height(CollectTable *ct)
1260 {
1261         GtkAdjustment *adj;
1262         gint page_size;
1263         gint row_height;
1264         gint ret;
1265
1266         adj = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(ct->listview));
1267         page_size = static_cast<gint>(gtk_adjustment_get_page_increment(adj));
1268
1269         row_height = options->thumbnails.max_height + THUMB_BORDER_PADDING * 2;
1270         if (ct->show_text) row_height += options->thumbnails.max_height / 3;
1271
1272         ret = page_size / row_height;
1273         if (ret < 1) ret = 1;
1274
1275         return ret;
1276 }
1277
1278 static gboolean collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
1279 {
1280         auto ct = static_cast<CollectTable *>(data);
1281         gint focus_row = 0;
1282         gint focus_col = 0;
1283         CollectInfo *info;
1284         gboolean stop_signal = TRUE;
1285
1286         switch (event->keyval)
1287                 {
1288                 case GDK_KEY_Left: case GDK_KEY_KP_Left:
1289                         focus_col = -1;
1290                         break;
1291                 case GDK_KEY_Right: case GDK_KEY_KP_Right:
1292                         focus_col = 1;
1293                         break;
1294                 case GDK_KEY_Up: case GDK_KEY_KP_Up:
1295                         focus_row = -1;
1296                         break;
1297                 case GDK_KEY_Down: case GDK_KEY_KP_Down:
1298                         focus_row = 1;
1299                         break;
1300                 case GDK_KEY_Page_Up: case GDK_KEY_KP_Page_Up:
1301                         focus_row = -page_height(ct);
1302                         break;
1303                 case GDK_KEY_Page_Down: case GDK_KEY_KP_Page_Down:
1304                         focus_row = page_height(ct);
1305                         break;
1306                 case GDK_KEY_Home: case GDK_KEY_KP_Home:
1307                         focus_row = -ct->focus_row;
1308                         focus_col = -ct->focus_column;
1309                         break;
1310                 case GDK_KEY_End: case GDK_KEY_KP_End:
1311                         focus_row = ct->rows - 1 - ct->focus_row;
1312                         focus_col = ct->columns - 1 - ct->focus_column;
1313                         break;
1314                 case GDK_KEY_space:
1315                         info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, nullptr);
1316                         if (info)
1317                                 {
1318                                 ct->click_info = info;
1319                                 if (event->state & GDK_CONTROL_MASK)
1320                                         {
1321                                         collection_table_select_util(ct, info, !info_selected(info));
1322                                         }
1323                                 else
1324                                         {
1325                                         collection_table_unselect_all(ct);
1326                                         collection_table_select(ct, info);
1327                                         }
1328                                 }
1329                         break;
1330                 case 'T': case 't':
1331                         if (event->state & GDK_CONTROL_MASK) collection_table_toggle_filenames(ct);
1332                         break;
1333                 case GDK_KEY_Menu:
1334                 case GDK_KEY_F10:
1335                         info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, nullptr);
1336                         ct->click_info = info;
1337
1338                         collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, nullptr);
1339                         tip_unschedule(ct);
1340
1341                         ct->popup = collection_table_popup_menu(ct, (info != nullptr));
1342                         gtk_menu_popup_at_widget(GTK_MENU(ct->popup), widget, GDK_GRAVITY_SOUTH, GDK_GRAVITY_CENTER, nullptr);
1343
1344                         break;
1345                 default:
1346                         stop_signal = FALSE;
1347                         break;
1348                 }
1349
1350         if (focus_row != 0 || focus_col != 0)
1351                 {
1352                 CollectInfo *new_info;
1353                 CollectInfo *old_info;
1354
1355                 old_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, nullptr);
1356                 collection_table_move_focus(ct, focus_row, focus_col, TRUE);
1357                 new_info = collection_table_find_data(ct, ct->focus_row, ct->focus_column, nullptr);
1358
1359                 if (new_info != old_info)
1360                         {
1361                         if (event->state & GDK_SHIFT_MASK)
1362                                 {
1363                                 if (!options->collections.rectangular_selection)
1364                                         {
1365                                         collection_table_select_region_util(ct, old_info, new_info, FALSE);
1366                                         }
1367                                 else
1368                                         {
1369                                         collection_table_select_region_util(ct, ct->click_info, old_info, FALSE);
1370                                         }
1371                                 collection_table_select_region_util(ct, ct->click_info, new_info, TRUE);
1372                                 }
1373                         else if (event->state & GDK_CONTROL_MASK)
1374                                 {
1375                                 ct->click_info = new_info;
1376                                 }
1377                         else
1378                                 {
1379                                 ct->click_info = new_info;
1380                                 collection_table_unselect_all(ct);
1381                                 collection_table_select(ct, new_info);
1382                                 }
1383                         }
1384                 }
1385
1386         if (stop_signal)
1387                 {
1388                 tip_unschedule(ct);
1389                 }
1390
1391         return stop_signal;
1392 }
1393
1394 /*
1395  *-------------------------------------------------------------------
1396  * insert marker
1397  *-------------------------------------------------------------------
1398  */
1399
1400 static CollectInfo *collection_table_insert_find(CollectTable *ct, CollectInfo *source, gboolean *after, GdkRectangle *cell,
1401                                                  gboolean use_coord, gint x, gint y)
1402 {
1403         CollectInfo *info = nullptr;
1404         GtkTreeModel *store;
1405         GtkTreeIter iter;
1406         GtkTreePath *tpath;
1407         GtkTreeViewColumn *column;
1408         GdkSeat *seat;
1409         GdkDevice *device;
1410
1411         store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1412
1413         if (!use_coord)
1414                 {
1415                 seat = gdk_display_get_default_seat(gdk_window_get_display(gtk_widget_get_window(ct->listview)));
1416                 device = gdk_seat_get_pointer(seat);
1417                 gdk_window_get_device_position(gtk_widget_get_window(ct->listview),
1418                                                                         device, &x, &y, nullptr);
1419                 }
1420
1421         if (source)
1422                 {
1423                 gint col;
1424                 if (collection_table_find_iter(ct, source, &iter, &col))
1425                         {
1426                         tpath = gtk_tree_model_get_path(store, &iter);
1427                         column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1428                         gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1429                         gtk_tree_path_free(tpath);
1430
1431                         info = source;
1432                         *after = !!(x > cell->x + (cell->width / 2));
1433                         }
1434                 return info;
1435                 }
1436
1437         if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(ct->listview), x, y,
1438                                           &tpath, &column, nullptr, nullptr))
1439                 {
1440                 GList *list;
1441                 gint n;
1442
1443                 gtk_tree_model_get_iter(store, &iter, tpath);
1444                 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1445
1446                 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
1447                 info = static_cast<CollectInfo *>(g_list_nth_data(list, n));
1448
1449                 if (info)
1450                         {
1451                         gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1452                         *after = !!(x > cell->x + (cell->width / 2));
1453                         }
1454
1455                 gtk_tree_path_free(tpath);
1456                 }
1457
1458         if (info == nullptr)
1459                 {
1460                 GList *work;
1461
1462                 work = g_list_last(ct->cd->list);
1463                 if (work)
1464                         {
1465                         gint col;
1466
1467                         info = static_cast<CollectInfo *>(work->data);
1468                         *after = TRUE;
1469
1470                         if (collection_table_find_iter(ct, info, &iter, &col))
1471                                 {
1472                                 tpath = gtk_tree_model_get_path(store, &iter);
1473                                 column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), col);
1474                                 gtk_tree_view_get_background_area(GTK_TREE_VIEW(ct->listview), tpath, column, cell);
1475                                 gtk_tree_path_free(tpath);
1476                                 }
1477                         }
1478                 }
1479
1480         return info;
1481 }
1482
1483 static CollectInfo *collection_table_insert_point(CollectTable *ct, gint x, gint y)
1484 {
1485         CollectInfo *info;
1486         GdkRectangle cell;
1487         gboolean after = FALSE;
1488
1489         info = collection_table_insert_find(ct, nullptr, &after, &cell, TRUE, x, y);
1490
1491         if (info && after)
1492                 {
1493                 GList *work;
1494
1495                 work = g_list_find(ct->cd->list, info);
1496                 if (work && work->next)
1497                         {
1498                         info = static_cast<CollectInfo *>(work->next->data);
1499                         }
1500                 else
1501                         {
1502                         info = nullptr;
1503                         }
1504                 }
1505
1506         return info;
1507 }
1508
1509 static void collection_table_insert_marker(CollectTable *ct, CollectInfo *info, gboolean enable)
1510 {
1511         gboolean after = FALSE;
1512         GdkRectangle cell;
1513         GdkWindow *parent;
1514         gint x_parent;
1515         gint y_parent;
1516         GError *error = nullptr;
1517         GInputStream *in_stream;
1518         GdkPixbuf *pb;
1519
1520         parent = gtk_widget_get_window(gtk_widget_get_toplevel(ct->listview));
1521         gdk_window_get_position(parent, &x_parent, &y_parent);
1522
1523         if (!enable)
1524                 {
1525                 if (ct->marker_window) gdk_window_destroy(ct->marker_window);
1526                 ct->marker_window = nullptr;
1527
1528                 return;
1529                 }
1530
1531         info = collection_table_insert_find(ct, info, &after, &cell, FALSE, 0, 0);
1532
1533         /* this setting does not take into account (after), but since it is not really used... */
1534         ct->marker_info = info;
1535
1536         if (!ct->marker_window)
1537                 {
1538                 GdkWindowAttr attributes;
1539                 gint attributes_mask;
1540
1541                 in_stream = g_resources_open_stream(GQ_RESOURCE_PATH_ICONS "/gq-marker.xpm", G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
1542                 pb = gdk_pixbuf_new_from_stream(in_stream, nullptr, &error);
1543                 g_object_unref(in_stream);
1544
1545                 if (error)
1546                         {
1547                         log_printf("warning: collection marker error: %s", error->message);
1548                         g_error_free(error);
1549                         return;
1550                         }
1551
1552                 gint w = gdk_pixbuf_get_width(pb);
1553                 gint h = gdk_pixbuf_get_height(pb);
1554
1555                 attributes.window_type = GDK_WINDOW_CHILD;
1556                 attributes.wclass = GDK_INPUT_OUTPUT;
1557                 attributes.width = w;
1558                 attributes.height = h;
1559                 attributes.event_mask = gtk_widget_get_events(ct->listview);
1560                 attributes_mask = 0;
1561
1562                 ct->marker_window = gdk_window_new(nullptr, &attributes, attributes_mask);
1563
1564                 cairo_region_t *mask;
1565                 cairo_pattern_t *pattern;
1566                 cairo_surface_t *img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
1567                 cairo_t *cr = cairo_create(img);
1568                 gdk_cairo_set_source_pixbuf(cr, pb, 0, 0);
1569                 cairo_paint(cr);
1570                 /** @FIXME this is a hack to get the background color
1571                  * pattern = cairo_pattern_create_for_surface(img);
1572                  */
1573                 pattern = cairo_pattern_create_rgb (1.0, 0.0, 0.0);
1574                 mask = gdk_cairo_region_create_from_surface(img);
1575                 gdk_window_shape_combine_region(ct->marker_window, mask, 0, 0);
1576                 gdk_window_set_background_pattern(ct->marker_window, pattern);
1577                 cairo_region_destroy(mask);
1578                 cairo_pattern_destroy(pattern);
1579                 cairo_destroy(cr);
1580                 cairo_surface_destroy(img);
1581                 g_object_unref(pb);
1582                 }
1583
1584         if (info)
1585                 {
1586                 gint x;
1587                 gint y;
1588                 gint w;
1589                 gint h;
1590
1591                 w = gdk_window_get_width(ct->marker_window);
1592                 h = gdk_window_get_height(ct->marker_window);
1593
1594                 if (!after)
1595                         {
1596                         x = cell.x;
1597                         }
1598                 else
1599                         {
1600                         x = cell.x + cell.width;
1601                         }
1602                 x -= (w / 2);
1603                 y = cell.y + (cell.height / 2) - (h / 2);
1604
1605                 x = x + x_parent;
1606                 y = y + y_parent;
1607
1608                 gdk_window_move(ct->marker_window, x, y);
1609
1610                 if (!gdk_window_is_visible(ct->marker_window)) gdk_window_show(ct->marker_window);
1611                 }
1612         else
1613                 {
1614                 if (gdk_window_is_visible(ct->marker_window)) gdk_window_hide(ct->marker_window);
1615                 }
1616 }
1617
1618 /*
1619  *-------------------------------------------------------------------
1620  * mouse drag auto-scroll
1621  *-------------------------------------------------------------------
1622  */
1623
1624 static void collection_table_motion_update(CollectTable *ct, gint x, gint y, gboolean drop_event)
1625 {
1626         CollectInfo *info;
1627
1628         info = collection_table_find_data_by_coord(ct, x, y, nullptr);
1629
1630         if (drop_event)
1631                 {
1632                 tip_unschedule(ct);
1633                 collection_table_insert_marker(ct, info, TRUE);
1634                 }
1635         else
1636                 {
1637                 tip_update(ct, info);
1638                 }
1639 }
1640
1641 static gboolean collection_table_auto_scroll_idle_cb(gpointer data)
1642 {
1643         auto ct = static_cast<CollectTable *>(data);
1644         GdkWindow *window;
1645         gint x;
1646         gint y;
1647         gint w;
1648         gint h;
1649         GdkSeat *seat;
1650         GdkDevice *device;
1651
1652         if (!ct->drop_idle_id) return G_SOURCE_REMOVE;
1653
1654         window = gtk_widget_get_window(ct->listview);
1655         seat = gdk_display_get_default_seat(gdk_window_get_display(window));
1656         device = gdk_seat_get_pointer(seat);
1657         gdk_window_get_device_position(window, device, &x, &y, nullptr);
1658
1659         w = gdk_window_get_width(window);
1660         h = gdk_window_get_height(window);
1661         if (x >= 0 && x < w && y >= 0 && y < h)
1662                 {
1663                 collection_table_motion_update(ct, x, y, TRUE);
1664                 }
1665
1666         ct->drop_idle_id = 0;
1667         return G_SOURCE_REMOVE;
1668 }
1669
1670 static gboolean collection_table_auto_scroll_notify_cb(GtkWidget *, gint, gint, gpointer data)
1671 {
1672         auto ct = static_cast<CollectTable *>(data);
1673
1674         if (!ct->drop_idle_id)
1675                 {
1676                 ct->drop_idle_id = g_idle_add(collection_table_auto_scroll_idle_cb, ct);
1677                 }
1678
1679         return TRUE;
1680 }
1681
1682 static void collection_table_scroll(CollectTable *ct, gboolean scroll)
1683 {
1684         if (!scroll)
1685                 {
1686                 if (ct->drop_idle_id)
1687                         {
1688                         g_source_remove(ct->drop_idle_id);
1689                         ct->drop_idle_id = 0;
1690                         }
1691                 widget_auto_scroll_stop(ct->listview);
1692                 collection_table_insert_marker(ct, nullptr, FALSE);
1693                 }
1694         else
1695                 {
1696                 GtkAdjustment *adj = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(ct->listview));
1697                 widget_auto_scroll_start(ct->listview, adj, -1, options->thumbnails.max_height / 2,
1698                                          collection_table_auto_scroll_notify_cb, ct);
1699                 }
1700 }
1701
1702 /*
1703  *-------------------------------------------------------------------
1704  * mouse callbacks
1705  *-------------------------------------------------------------------
1706  */
1707
1708 static gboolean collection_table_motion_cb(GtkWidget *, GdkEventMotion *event, gpointer data)
1709 {
1710         auto ct = static_cast<CollectTable *>(data);
1711
1712         collection_table_motion_update(ct, static_cast<gint>(event->x), static_cast<gint>(event->y), FALSE);
1713
1714         return FALSE;
1715 }
1716
1717 static gboolean collection_table_press_cb(GtkWidget *, GdkEventButton *bevent, gpointer data)
1718 {
1719         auto ct = static_cast<CollectTable *>(data);
1720         GtkTreeIter iter;
1721         CollectInfo *info;
1722
1723         tip_unschedule(ct);
1724
1725         info = collection_table_find_data_by_coord(ct, static_cast<gint>(bevent->x), static_cast<gint>(bevent->y), &iter);
1726
1727         ct->click_info = info;
1728         collection_table_selection_add(ct, ct->click_info, SELECTION_PRELIGHT, &iter);
1729
1730         switch (bevent->button)
1731                 {
1732                 case MOUSE_BUTTON_LEFT:
1733                         if (bevent->type == GDK_2BUTTON_PRESS)
1734                                 {
1735                                 if (info)
1736                                         {
1737                                         layout_image_set_collection(nullptr, ct->cd, info);
1738                                         }
1739                                 }
1740                         else if (!gtk_widget_has_focus(ct->listview))
1741                                 {
1742                                 gtk_widget_grab_focus(ct->listview);
1743                                 }
1744                         break;
1745                 case MOUSE_BUTTON_RIGHT:
1746                         ct->popup = collection_table_popup_menu(ct, (info != nullptr));
1747                         gtk_menu_popup_at_pointer(GTK_MENU(ct->popup), nullptr);
1748                         break;
1749                 default:
1750                         break;
1751                 }
1752
1753         return TRUE;
1754 }
1755
1756 static gboolean collection_table_release_cb(GtkWidget *, GdkEventButton *bevent, gpointer data)
1757 {
1758         auto ct = static_cast<CollectTable *>(data);
1759         GtkTreeIter iter;
1760         CollectInfo *info = nullptr;
1761
1762         tip_schedule(ct);
1763
1764         if (static_cast<gint>(bevent->x) != 0 || static_cast<gint>(bevent->y) != 0)
1765                 {
1766                 info = collection_table_find_data_by_coord(ct, static_cast<gint>(bevent->x), static_cast<gint>(bevent->y), &iter);
1767                 }
1768
1769         if (ct->click_info)
1770                 {
1771                 collection_table_selection_remove(ct, ct->click_info, SELECTION_PRELIGHT, nullptr);
1772                 }
1773
1774         if (bevent->button == MOUSE_BUTTON_LEFT &&
1775             info && ct->click_info == info)
1776                 {
1777                 collection_table_set_focus(ct, info);
1778
1779                 if (bevent->state & GDK_CONTROL_MASK)
1780                         {
1781                         gboolean select = !info_selected(info);
1782
1783                         if ((bevent->state & GDK_SHIFT_MASK) && ct->prev_selection)
1784                                 {
1785                                 collection_table_select_region_util(ct, ct->prev_selection, info, select);
1786                                 }
1787                         else
1788                                 {
1789                                 collection_table_select_util(ct, info, select);
1790                                 }
1791                         }
1792                 else
1793                         {
1794                         collection_table_unselect_all(ct);
1795
1796                         if ((bevent->state & GDK_SHIFT_MASK) &&
1797                             ct->prev_selection)
1798                                 {
1799                                 collection_table_select_region_util(ct, ct->prev_selection, info, TRUE);
1800                                 }
1801                         else
1802                                 {
1803                                 collection_table_select_util(ct, info, TRUE);
1804                                 }
1805                         }
1806                 }
1807         else if (bevent->button == MOUSE_BUTTON_MIDDLE &&
1808                  info && ct->click_info == info)
1809                 {
1810                 collection_table_select_util(ct, info, !info_selected(info));
1811                 }
1812
1813         return TRUE;
1814 }
1815
1816 static gboolean collection_table_leave_cb(GtkWidget *, GdkEventCrossing *, gpointer data)
1817 {
1818         auto ct = static_cast<CollectTable *>(data);
1819
1820         tip_unschedule(ct);
1821         return FALSE;
1822 }
1823
1824 /*
1825  *-------------------------------------------------------------------
1826  * populate, add, insert, etc.
1827  *-------------------------------------------------------------------
1828  */
1829
1830 static gboolean collection_table_destroy_node_cb(GtkTreeModel *store, GtkTreePath *, GtkTreeIter *iter, gpointer)
1831 {
1832         GList *list;
1833
1834         gtk_tree_model_get(store, iter, CTABLE_COLUMN_POINTER, &list, -1);
1835         g_list_free(list);
1836
1837         return FALSE;
1838 }
1839
1840 static void collection_table_clear_store(CollectTable *ct)
1841 {
1842         GtkTreeModel *store;
1843
1844         store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1845         gtk_tree_model_foreach(store, collection_table_destroy_node_cb, nullptr);
1846
1847         gtk_list_store_clear(GTK_LIST_STORE(store));
1848 }
1849
1850 static GList *collection_table_add_row(CollectTable *ct, GtkTreeIter *iter)
1851 {
1852         GtkListStore *store;
1853         GList *list = nullptr;
1854         gint i;
1855
1856         for (i = 0; i < ct->columns; i++) list = g_list_prepend(list, nullptr);
1857
1858         store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview)));
1859         gtk_list_store_append(store, iter);
1860         gtk_list_store_set(store, iter, CTABLE_COLUMN_POINTER, list, -1);
1861
1862         return list;
1863 }
1864
1865 static void collection_table_populate(CollectTable *ct, gboolean resize)
1866 {
1867         gint row;
1868         GList *work;
1869
1870         collection_table_verify_selections(ct);
1871
1872         collection_table_clear_store(ct);
1873
1874         if (resize)
1875                 {
1876                 gint i;
1877                 gint thumb_width;
1878
1879                 thumb_width = collection_table_get_icon_width(ct);
1880
1881                 for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
1882                         {
1883                         GtkTreeViewColumn *column;
1884                         GtkCellRenderer *cell;
1885                         GList *list;
1886
1887                         column = gtk_tree_view_get_column(GTK_TREE_VIEW(ct->listview), i);
1888                         gtk_tree_view_column_set_visible(column, (i < ct->columns));
1889                         gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6));
1890
1891                         list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
1892                         cell = static_cast<GtkCellRenderer *>((list) ? list->data : nullptr);
1893                         g_list_free(list);
1894
1895                         if (cell && GQV_IS_CELL_RENDERER_ICON(cell))
1896                                 {
1897                                 g_object_set(G_OBJECT(cell), "fixed_width", thumb_width,
1898                                                              "fixed_height", options->thumbnails.max_height,
1899                                                              "show_text", ct->show_text || ct->show_stars, NULL);
1900                                 }
1901                         }
1902                 if (gtk_widget_get_realized(ct->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(ct->listview));
1903                 }
1904
1905         row = -1;
1906         work = ct->cd->list;
1907         while (work)
1908                 {
1909                 GList *list;
1910                 GtkTreeIter iter;
1911
1912                 row++;
1913
1914                 list = collection_table_add_row(ct, &iter);
1915                 while (work && list)
1916                         {
1917                         list->data = work->data;
1918                         list = list->next;
1919                         work = work->next;
1920                         }
1921                 }
1922
1923         ct->rows = row + 1;
1924
1925         collection_table_update_focus(ct);
1926         collection_table_update_status(ct);
1927 }
1928
1929 static void collection_table_populate_at_new_size(CollectTable *ct, gint w, gint, gboolean force)
1930 {
1931         gint new_cols;
1932         gint thumb_width;
1933
1934         thumb_width = collection_table_get_icon_width(ct);
1935
1936         new_cols = w / (thumb_width + (THUMB_BORDER_PADDING * 6));
1937         if (new_cols < 1) new_cols = 1;
1938
1939         if (!force && new_cols == ct->columns) return;
1940
1941         ct->columns = new_cols;
1942
1943         collection_table_populate(ct, TRUE);
1944
1945         DEBUG_1("col tab pop cols=%d rows=%d", ct->columns, ct->rows);
1946 }
1947
1948 static void collection_table_sync(CollectTable *ct)
1949 {
1950         GtkTreeModel *store;
1951         GtkTreeIter iter;
1952         GList *work;
1953         gint r;
1954
1955         store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
1956
1957         r = -1;
1958
1959         work = ct->cd->list;
1960         while (work)
1961                 {
1962                 GList *list;
1963                 r++;
1964                 if (gtk_tree_model_iter_nth_child(store, &iter, nullptr, r))
1965                         {
1966                         gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
1967                         gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
1968                         }
1969                 else
1970                         {
1971                         list = collection_table_add_row(ct, &iter);
1972                         }
1973
1974                 while (list)
1975                         {
1976                         CollectInfo *info;
1977                         if (work)
1978                                 {
1979                                 info = static_cast<CollectInfo *>(work->data);
1980                                 work = work->next;
1981                                 }
1982                         else
1983                                 {
1984                                 info = nullptr;
1985                                 }
1986                         if (list)
1987                                 {
1988                                 list->data = info;
1989                                 list = list->next;
1990                                 }
1991                         }
1992                 }
1993
1994         r++;
1995         while (gtk_tree_model_iter_nth_child(store, &iter, nullptr, r))
1996                 {
1997                 GList *list;
1998
1999                 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
2000                 gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
2001                 g_list_free(list);
2002                 }
2003
2004         ct->rows = r;
2005
2006         collection_table_update_focus(ct);
2007         collection_table_update_status(ct);
2008 }
2009
2010 static gboolean collection_table_sync_idle_cb(gpointer data)
2011 {
2012         auto ct = static_cast<CollectTable *>(data);
2013
2014         if (!ct->sync_idle_id) return G_SOURCE_REMOVE;
2015         g_source_remove(ct->sync_idle_id);
2016         ct->sync_idle_id = 0;
2017
2018         collection_table_sync(ct);
2019         return G_SOURCE_REMOVE;
2020 }
2021
2022 static void collection_table_sync_idle(CollectTable *ct)
2023 {
2024         if (!ct->sync_idle_id)
2025                 {
2026                 /* high priority, the view needs to be resynced before a redraw
2027                  * may contain invalid pointers at this time
2028                  */
2029                 ct->sync_idle_id = g_idle_add_full(G_PRIORITY_HIGH, collection_table_sync_idle_cb, ct, nullptr);
2030                 }
2031 }
2032
2033 void collection_table_add_filelist(CollectTable *ct, GList *list)
2034 {
2035         GList *work;
2036
2037         if (!list) return;
2038
2039         work = list;
2040         while (work)
2041                 {
2042                 collection_add(ct->cd, static_cast<FileData *>(work->data), FALSE);
2043                 work = work->next;
2044                 }
2045 }
2046
2047 static void collection_table_insert_filelist(CollectTable *ct, GList *list, CollectInfo *insert_info)
2048 {
2049         GList *work;
2050
2051         if (!list) return;
2052
2053         work = list;
2054         while (work)
2055                 {
2056                 collection_insert(ct->cd, static_cast<FileData *>(work->data), insert_info, FALSE);
2057                 work = work->next;
2058                 }
2059
2060         collection_table_sync_idle(ct);
2061 }
2062
2063 static void collection_table_move_by_info_list(CollectTable *ct, GList *info_list, gint row, gint col)
2064 {
2065         GList *work;
2066         GList *insert_pos = nullptr;
2067         GList *temp;
2068         CollectInfo *info;
2069
2070         if (!info_list) return;
2071
2072         info = collection_table_find_data(ct, row, col, nullptr);
2073
2074         if (!info_list->next && info_list->data == info) return;
2075
2076         if (info) insert_pos = g_list_find(ct->cd->list, info);
2077
2078         /** @FIXME this may get slow for large lists */
2079         work = info_list;
2080         while (insert_pos && work)
2081                 {
2082                 if (insert_pos->data == work->data)
2083                         {
2084                         insert_pos = insert_pos->next;
2085                         work = info_list;
2086                         }
2087                 else
2088                         {
2089                         work = work->next;
2090                         }
2091                 }
2092
2093         work = info_list;
2094         while (work)
2095                 {
2096                 ct->cd->list = g_list_remove(ct->cd->list, work->data);
2097                 work = work->next;
2098                 }
2099
2100         /* place them back in */
2101         temp = g_list_copy(info_list);
2102
2103         if (insert_pos)
2104                 {
2105                 ct->cd->list = uig_list_insert_list(ct->cd->list, insert_pos, temp);
2106                 }
2107         else if (info)
2108                 {
2109                 ct->cd->list = g_list_concat(temp, ct->cd->list);
2110                 }
2111         else
2112                 {
2113                 ct->cd->list = g_list_concat(ct->cd->list, temp);
2114                 }
2115
2116         ct->cd->changed = TRUE;
2117
2118         collection_table_sync_idle(ct);
2119 }
2120
2121
2122 /*
2123  *-------------------------------------------------------------------
2124  * updating
2125  *-------------------------------------------------------------------
2126  */
2127
2128 void collection_table_file_update(CollectTable *ct, CollectInfo *info)
2129 {
2130         GtkTreeIter iter;
2131         gint row;
2132         gint col;
2133         gdouble value;
2134
2135         if (!info)
2136                 {
2137                 collection_table_update_extras(ct, FALSE, 0.0);
2138                 return;
2139                 }
2140
2141         if (!collection_table_find_position(ct, info, &row, &col)) return;
2142
2143         if (ct->columns != 0 && ct->rows != 0)
2144                 {
2145                 value = static_cast<gdouble>(row * ct->columns + col) / (ct->columns * ct->rows);
2146                 }
2147         else
2148                 {
2149                 value = 0.0;
2150                 }
2151
2152         collection_table_update_extras(ct, TRUE, value);
2153
2154         if (collection_table_find_iter(ct, info, &iter, nullptr))
2155                 {
2156                 GtkTreeModel *store;
2157                 GList *list;
2158
2159                 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ct->listview));
2160                 gtk_tree_model_get(store, &iter, CTABLE_COLUMN_POINTER, &list, -1);
2161                 gtk_list_store_set(GTK_LIST_STORE(store), &iter, CTABLE_COLUMN_POINTER, list, -1);
2162                 }
2163 }
2164
2165 void collection_table_file_add(CollectTable *ct, CollectInfo *)
2166 {
2167         collection_table_sync_idle(ct);
2168 }
2169
2170 void collection_table_file_insert(CollectTable *ct, CollectInfo *)
2171 {
2172         collection_table_sync_idle(ct);
2173 }
2174
2175 void collection_table_file_remove(CollectTable *ct, CollectInfo *ci)
2176 {
2177         if (ci && info_selected(ci))
2178                 {
2179                 ct->selection = g_list_remove(ct->selection, ci);
2180                 }
2181
2182         collection_table_sync_idle(ct);
2183 }
2184
2185 void collection_table_refresh(CollectTable *ct)
2186 {
2187         collection_table_populate(ct, FALSE);
2188 }
2189
2190 /*
2191  *-------------------------------------------------------------------
2192  * dnd
2193  *-------------------------------------------------------------------
2194  */
2195
2196 static void collection_table_add_dir_recursive(CollectTable *ct, FileData *dir_fd, gboolean recursive)
2197 {
2198         GList *d;
2199         GList *f;
2200         GList *work;
2201
2202         if (!filelist_read(dir_fd, &f, recursive ? &d : nullptr))
2203                 return;
2204
2205         f = filelist_filter(f, FALSE);
2206         d = filelist_filter(d, TRUE);
2207
2208         f = filelist_sort_path(f);
2209         d = filelist_sort_path(d);
2210
2211         collection_table_insert_filelist(ct, f, ct->marker_info);
2212
2213         work = g_list_last(d);
2214         while (work)
2215                 {
2216                 collection_table_add_dir_recursive(ct, static_cast<FileData *>(work->data), TRUE);
2217                 work = work->prev;
2218                 }
2219
2220         filelist_free(f);
2221         filelist_free(d);
2222 }
2223
2224 static void confirm_dir_list_do(CollectTable *ct, GList *list, gboolean recursive)
2225 {
2226         GList *work = list;
2227         while (work)
2228                 {
2229                 auto fd = static_cast<FileData *>(work->data);
2230                 work = work->next;
2231                 if (isdir(fd->path)) collection_table_add_dir_recursive(ct, fd, recursive);
2232                 }
2233         collection_table_insert_filelist(ct, list, ct->marker_info);
2234 }
2235
2236
2237 static void confirm_dir_list_add(GtkWidget *, gpointer data)
2238 {
2239         auto ct = static_cast<CollectTable *>(data);
2240
2241         confirm_dir_list_do(ct, ct->drop_list, FALSE);
2242 }
2243
2244 static void confirm_dir_list_recurse(GtkWidget *, gpointer data)
2245 {
2246         auto ct = static_cast<CollectTable *>(data);
2247
2248         confirm_dir_list_do(ct, ct->drop_list, TRUE);
2249 }
2250
2251 static void confirm_dir_list_skip(GtkWidget *, gpointer data)
2252 {
2253         auto ct = static_cast<CollectTable *>(data);
2254
2255         collection_table_insert_filelist(ct, ct->drop_list, ct->marker_info);
2256 }
2257
2258 static GtkWidget *collection_table_drop_menu(CollectTable *ct)
2259 {
2260         GtkWidget *menu;
2261
2262         menu = popup_menu_short_lived();
2263         g_signal_connect(G_OBJECT(menu), "destroy",
2264                          G_CALLBACK(collection_table_popup_destroy_cb), ct);
2265
2266         menu_item_add_stock(menu, _("Dropped list includes folders."), GQ_ICON_DND, nullptr, nullptr);
2267         menu_item_add_divider(menu);
2268         menu_item_add_icon(menu, _("_Add contents"), GQ_ICON_OK,
2269                             G_CALLBACK(confirm_dir_list_add), ct);
2270         menu_item_add_icon(menu, _("Add contents _recursive"), GQ_ICON_ADD,
2271                             G_CALLBACK(confirm_dir_list_recurse), ct);
2272         menu_item_add_icon(menu, _("_Skip folders"), GQ_ICON_REMOVE,
2273                             G_CALLBACK(confirm_dir_list_skip), ct);
2274         menu_item_add_divider(menu);
2275         menu_item_add_icon(menu, _("Cancel"), GQ_ICON_CANCEL, nullptr, ct);
2276
2277         return menu;
2278 }
2279
2280 /*
2281  *-------------------------------------------------------------------
2282  * dnd
2283  *-------------------------------------------------------------------
2284  */
2285
2286 static GtkTargetEntry collection_drag_types[] = {
2287         { const_cast<gchar *>(TARGET_APP_COLLECTION_MEMBER_STRING), 0, TARGET_APP_COLLECTION_MEMBER },
2288         { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST },
2289         { const_cast<gchar *>("text/plain"), 0, TARGET_TEXT_PLAIN }
2290 };
2291 static gint n_collection_drag_types = 3;
2292
2293 static GtkTargetEntry collection_drop_types[] = {
2294         { const_cast<gchar *>(TARGET_APP_COLLECTION_MEMBER_STRING), 0, TARGET_APP_COLLECTION_MEMBER },
2295         { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST }
2296 };
2297 static gint n_collection_drop_types = 2;
2298
2299
2300 static void collection_table_dnd_get(GtkWidget *, GdkDragContext *,
2301                                      GtkSelectionData *selection_data, guint info,
2302                                      guint, gpointer data)
2303 {
2304         auto ct = static_cast<CollectTable *>(data);
2305         gboolean selected;
2306         GList *list = nullptr;
2307         gchar *uri_text = nullptr;
2308         gint total;
2309
2310         if (!ct->click_info) return;
2311
2312         selected = info_selected(ct->click_info);
2313
2314         switch (info)
2315                 {
2316                 case TARGET_APP_COLLECTION_MEMBER:
2317                         if (selected)
2318                                 {
2319                                 uri_text = collection_info_list_to_dnd_data(ct->cd, ct->selection, &total);
2320                                 }
2321                         else
2322                                 {
2323                                 list = g_list_append(nullptr, ct->click_info);
2324                                 uri_text = collection_info_list_to_dnd_data(ct->cd, list, &total);
2325                                 g_list_free(list);
2326                                 }
2327                         gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
2328                                                 8, reinterpret_cast<guchar *>(uri_text), total);
2329                         g_free(uri_text);
2330                         break;
2331                 case TARGET_URI_LIST:
2332                 case TARGET_TEXT_PLAIN:
2333                 default:
2334                         if (selected)
2335                                 {
2336                                 list = collection_table_selection_get_list(ct);
2337                                 }
2338                         else
2339                                 {
2340                                 list = g_list_append(nullptr, file_data_ref(ct->click_info->fd));
2341                                 }
2342                         if (!list) return;
2343
2344                         uri_selection_data_set_uris_from_filelist(selection_data, list);
2345                         filelist_free(list);
2346                         break;
2347                 }
2348 }
2349
2350
2351 static void collection_table_dnd_receive(GtkWidget *, GdkDragContext *context,
2352                                           gint x, gint y,
2353                                           GtkSelectionData *selection_data, guint info,
2354                                           guint, gpointer data)
2355 {
2356         auto ct = static_cast<CollectTable *>(data);
2357         GList *list = nullptr;
2358         GList *info_list = nullptr;
2359         CollectionData *source;
2360         CollectInfo *drop_info;
2361         GList *work;
2362
2363         DEBUG_1("%s", gtk_selection_data_get_data(selection_data));
2364
2365         collection_table_scroll(ct, FALSE);
2366         collection_table_insert_marker(ct, nullptr, FALSE);
2367
2368         drop_info = collection_table_insert_point(ct, x, y);
2369
2370         switch (info)
2371                 {
2372                 case TARGET_APP_COLLECTION_MEMBER:
2373                         source = collection_from_dnd_data(reinterpret_cast<const gchar *>(gtk_selection_data_get_data(selection_data)), &list, &info_list);
2374                         if (source)
2375                                 {
2376                                 if (source == ct->cd)
2377                                         {
2378                                         gint row = -1;
2379                                         gint col = -1;
2380
2381                                         /* it is a move within a collection */
2382                                         filelist_free(list);
2383                                         list = nullptr;
2384
2385                                         if (!drop_info)
2386                                                 {
2387                                                 collection_table_move_by_info_list(ct, info_list, -1, -1);
2388                                                 }
2389                                         else if (collection_table_find_position(ct, drop_info, &row, &col))
2390                                                 {
2391                                                 collection_table_move_by_info_list(ct, info_list, row, col);
2392                                                 }
2393                                         }
2394                                 else
2395                                         {
2396                                         /* it is a move/copy across collections */
2397                                         if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
2398                                                 {
2399                                                 collection_remove_by_info_list(source, info_list);
2400                                                 }
2401                                         }
2402                                 g_list_free(info_list);
2403                                 }
2404                         break;
2405                 case TARGET_URI_LIST:
2406                         list = uri_filelist_from_gtk_selection_data(selection_data);
2407                         work = list;
2408                         while (work)
2409                                 {
2410                                 auto fd = static_cast<FileData *>(work->data);
2411                                 if (isdir(fd->path))
2412                                         {
2413                                         GtkWidget *menu;
2414
2415                                         ct->drop_list = list;
2416                                         ct->drop_info = drop_info;
2417                                         menu = collection_table_drop_menu(ct);
2418                                         gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr);
2419                                         return;
2420                                         }
2421                                 work = work->next;
2422                                 }
2423                         break;
2424                 default:
2425                         list = nullptr;
2426                         break;
2427                 }
2428
2429         if (list)
2430                 {
2431                 collection_table_insert_filelist(ct, list, drop_info);
2432                 filelist_free(list);
2433                 }
2434 }
2435
2436 static void collection_table_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
2437 {
2438         auto ct = static_cast<CollectTable *>(data);
2439
2440         if (ct->click_info && ct->click_info->pixbuf)
2441                 {
2442                 gint items;
2443
2444                 if (info_selected(ct->click_info))
2445                         items = g_list_length(ct->selection);
2446                 else
2447                         items = 1;
2448                 dnd_set_drag_icon(widget, context, ct->click_info->pixbuf, items);
2449                 }
2450 }
2451
2452 static void collection_table_dnd_end(GtkWidget *, GdkDragContext *, gpointer data)
2453 {
2454         auto ct = static_cast<CollectTable *>(data);
2455
2456         /* apparently a leave event is not generated on a drop */
2457         tip_unschedule(ct);
2458
2459         collection_table_scroll(ct, FALSE);
2460 }
2461
2462 static gint collection_table_dnd_motion(GtkWidget *, GdkDragContext *, gint x, gint y, guint, gpointer data)
2463 {
2464         auto ct = static_cast<CollectTable *>(data);
2465
2466         collection_table_motion_update(ct, x, y, TRUE);
2467         collection_table_scroll(ct, TRUE);
2468
2469         return FALSE;
2470 }
2471
2472 static void collection_table_dnd_leave(GtkWidget *, GdkDragContext *, guint, gpointer data)
2473 {
2474         auto ct = static_cast<CollectTable *>(data);
2475
2476         collection_table_scroll(ct, FALSE);
2477 }
2478
2479 static void collection_table_dnd_init(CollectTable *ct)
2480 {
2481         gtk_drag_source_set(ct->listview, static_cast<GdkModifierType>(GDK_BUTTON1_MASK | GDK_BUTTON2_MASK),
2482                             collection_drag_types, n_collection_drag_types,
2483                             static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
2484         g_signal_connect(G_OBJECT(ct->listview), "drag_data_get",
2485                          G_CALLBACK(collection_table_dnd_get), ct);
2486         g_signal_connect(G_OBJECT(ct->listview), "drag_begin",
2487                          G_CALLBACK(collection_table_dnd_begin), ct);
2488         g_signal_connect(G_OBJECT(ct->listview), "drag_end",
2489                          G_CALLBACK(collection_table_dnd_end), ct);
2490
2491         gtk_drag_dest_set(ct->listview,
2492                           static_cast<GtkDestDefaults>(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP),
2493                           collection_drop_types, n_collection_drop_types,
2494                           static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK));
2495         g_signal_connect(G_OBJECT(ct->listview), "drag_motion",
2496                          G_CALLBACK(collection_table_dnd_motion), ct);
2497         g_signal_connect(G_OBJECT(ct->listview), "drag_leave",
2498                          G_CALLBACK(collection_table_dnd_leave), ct);
2499         g_signal_connect(G_OBJECT(ct->listview), "drag_data_received",
2500                          G_CALLBACK(collection_table_dnd_receive), ct);
2501 }
2502
2503 /*
2504  *-----------------------------------------------------------------------------
2505  * draw, etc.
2506  *-----------------------------------------------------------------------------
2507  */
2508
2509 static void collection_table_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
2510                                           GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
2511 {
2512         auto cd = static_cast<ColumnData *>(data);
2513         CollectInfo *info;
2514         CollectTable *ct;
2515         gchar *display_text = nullptr;
2516         gchar *star_rating = nullptr;
2517         GdkRGBA color_bg;
2518         GdkRGBA color_fg;
2519         GList *list;
2520         GtkStyle *style;
2521
2522         ct = cd->ct;
2523
2524         gtk_tree_model_get(tree_model, iter, CTABLE_COLUMN_POINTER, &list, -1);
2525
2526         /** @FIXME this is a primitive hack to stop a crash.
2527          * When compiled with GTK3, if a Collection window containing
2528          * say, 50 or so, images has its width changed, there is a segfault
2529          * https://github.com/BestImageViewer/geeqie/issues/531
2530          */
2531         if (cd->number == COLLECT_TABLE_MAX_COLUMNS) return;
2532
2533         info = static_cast<CollectInfo *>(g_list_nth_data(list, cd->number));
2534
2535         style = gtk_widget_get_style(ct->listview);
2536         if (info && (info->flag_mask & SELECTION_SELECTED) )
2537                 {
2538                 convert_gdkcolor_to_gdkrgba(&style->text[GTK_STATE_SELECTED], &color_fg);
2539                 convert_gdkcolor_to_gdkrgba(&style->base[GTK_STATE_SELECTED], &color_bg);
2540                 }
2541         else
2542                 {
2543                 convert_gdkcolor_to_gdkrgba(&style->text[GTK_STATE_NORMAL], &color_fg);
2544                 convert_gdkcolor_to_gdkrgba(&style->base[GTK_STATE_NORMAL], &color_bg);
2545                 }
2546
2547         if (info && (info->flag_mask & SELECTION_PRELIGHT))
2548                 {
2549                 shift_color(&color_bg, -1, 0);
2550                 }
2551
2552         if (ct->show_stars && info && info->fd)
2553                 {
2554                 star_rating = metadata_read_rating_stars(info->fd);
2555                 }
2556         else
2557                 {
2558                 star_rating = g_strdup("");
2559                 }
2560
2561         if (info && info->fd)
2562                 {
2563                 if (ct->show_text && ct->show_stars)
2564                         {
2565                         display_text = g_strconcat(info->fd->name, "\n", star_rating, NULL);
2566                         }
2567                 else if (ct->show_text)
2568                         {
2569                         display_text = g_strdup(info->fd->name);
2570                         }
2571                 else if (ct->show_stars)
2572                         {
2573                         display_text = g_strdup(star_rating);
2574                         }
2575                 else
2576                         {
2577                         display_text = g_strdup("");
2578                         }
2579                 }
2580         else
2581                 {
2582                 display_text = g_strdup("");
2583                 }
2584
2585         if (GQV_IS_CELL_RENDERER_ICON(cell))
2586                 {
2587                 if (info)
2588                         {
2589                         g_object_set(cell,      "pixbuf", info->pixbuf,
2590                                                 "text",  display_text,
2591                                                 "cell-background-rgba", &color_bg,
2592                                                 "cell-background-set", TRUE,
2593                                                 "foreground-rgba", &color_fg,
2594                                                 "foreground-set", TRUE,
2595                                                 "has-focus", (ct->focus_info == info), NULL);
2596                         }
2597                 else
2598                         {
2599                         g_object_set(cell,      "pixbuf", NULL,
2600                                                 "text", NULL,
2601                                                 "cell-background-set", FALSE,
2602                                                 "foreground-set", FALSE,
2603                                                 "has-focus", FALSE,  NULL);
2604                         }
2605                 }
2606
2607         g_free(display_text);
2608         g_free(star_rating);
2609 }
2610
2611 static void collection_table_append_column(CollectTable *ct, gint n)
2612 {
2613         ColumnData *cd;
2614         GtkTreeViewColumn *column;
2615         GtkCellRenderer *renderer;
2616
2617         column = gtk_tree_view_column_new();
2618         gtk_tree_view_column_set_min_width(column, 0);
2619
2620         gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
2621         gtk_tree_view_column_set_alignment(column, 0.5);
2622
2623         renderer = gqv_cell_renderer_icon_new();
2624         gtk_tree_view_column_pack_start(column, renderer, FALSE);
2625         g_object_set(G_OBJECT(renderer), "xpad", THUMB_BORDER_PADDING * 2,
2626                                          "ypad", THUMB_BORDER_PADDING,
2627                                          "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
2628
2629         g_object_set_data(G_OBJECT(column), "column_number", GINT_TO_POINTER(n));
2630
2631         cd = g_new0(ColumnData, 1);
2632         cd->ct = ct;
2633         cd->number = n;
2634         gtk_tree_view_column_set_cell_data_func(column, renderer, collection_table_cell_data_cb, cd, g_free);
2635
2636         gtk_tree_view_append_column(GTK_TREE_VIEW(ct->listview), column);
2637 }
2638
2639 /*
2640  *-------------------------------------------------------------------
2641  * init, destruction
2642  *-------------------------------------------------------------------
2643  */
2644
2645 static void collection_table_destroy(GtkWidget *, gpointer data)
2646 {
2647         auto ct = static_cast<CollectTable *>(data);
2648
2649         /* If there is no unsaved data, save the window geometry
2650          */
2651         if (!ct->cd->changed)
2652                 {
2653                 if (!collection_save(ct->cd, ct->cd->path))
2654                         {
2655                         log_printf("failed saving to collection path: %s\n", ct->cd->path);
2656                         }
2657                 }
2658
2659         if (ct->popup)
2660                 {
2661                 g_signal_handlers_disconnect_matched(G_OBJECT(ct->popup), G_SIGNAL_MATCH_DATA,
2662                                                      0, 0, nullptr, nullptr, ct);
2663                 gq_gtk_widget_destroy(ct->popup);
2664                 }
2665
2666         if (ct->sync_idle_id) g_source_remove(ct->sync_idle_id);
2667
2668         tip_unschedule(ct);
2669         collection_table_scroll(ct, FALSE);
2670
2671         g_free(ct);
2672 }
2673
2674 static void collection_table_sized(GtkWidget *, GtkAllocation *allocation, gpointer data)
2675 {
2676         auto ct = static_cast<CollectTable *>(data);
2677
2678         collection_table_populate_at_new_size(ct, allocation->width, allocation->height, FALSE);
2679 }
2680
2681 CollectTable *collection_table_new(CollectionData *cd)
2682 {
2683         CollectTable *ct;
2684         GtkListStore *store;
2685         GtkTreeSelection *selection;
2686         gint i;
2687
2688         ct = g_new0(CollectTable, 1);
2689
2690         ct->cd = cd;
2691         ct->show_text = options->show_icon_names;
2692         ct->show_stars = options->show_star_rating;
2693
2694         ct->scrolled = gq_gtk_scrolled_window_new(nullptr, nullptr);
2695         gq_gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ct->scrolled), GTK_SHADOW_IN);
2696         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ct->scrolled),
2697                                        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2698
2699         store = gtk_list_store_new(1, G_TYPE_POINTER);
2700         ct->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
2701         g_object_unref(store);
2702
2703         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ct->listview));
2704         gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_NONE);
2705
2706         gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(ct->listview), FALSE);
2707         gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ct->listview), FALSE);
2708
2709         for (i = 0; i < COLLECT_TABLE_MAX_COLUMNS; i++)
2710                 {
2711                 collection_table_append_column(ct, i);
2712                 }
2713
2714         /* zero width column to hide tree view focus, we draw it ourselves */
2715         collection_table_append_column(ct, i);
2716         /* end column to fill white space */
2717         collection_table_append_column(ct, i);
2718
2719         g_signal_connect(G_OBJECT(ct->listview), "destroy",
2720                          G_CALLBACK(collection_table_destroy), ct);
2721         g_signal_connect(G_OBJECT(ct->listview), "size_allocate",
2722                          G_CALLBACK(collection_table_sized), ct);
2723         g_signal_connect(G_OBJECT(ct->listview), "key_press_event",
2724                          G_CALLBACK(collection_table_press_key_cb), ct);
2725
2726         gq_gtk_container_add(GTK_WIDGET(ct->scrolled), ct->listview);
2727         gtk_widget_show(ct->listview);
2728
2729         collection_table_dnd_init(ct);
2730
2731         gtk_widget_set_events(ct->listview, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK |
2732                               static_cast<GdkEventMask>(GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK));
2733         g_signal_connect(G_OBJECT(ct->listview),"button_press_event",
2734                          G_CALLBACK(collection_table_press_cb), ct);
2735         g_signal_connect(G_OBJECT(ct->listview),"button_release_event",
2736                          G_CALLBACK(collection_table_release_cb), ct);
2737         g_signal_connect(G_OBJECT(ct->listview),"motion_notify_event",
2738                          G_CALLBACK(collection_table_motion_cb), ct);
2739         g_signal_connect(G_OBJECT(ct->listview), "leave_notify_event",
2740                          G_CALLBACK(collection_table_leave_cb), ct);
2741
2742         return ct;
2743 }
2744
2745 void collection_table_set_labels(CollectTable *ct, GtkWidget *status, GtkWidget *extra)
2746 {
2747         ct->status_label = status;
2748         ct->extra_label = extra;
2749         collection_table_update_status(ct);
2750         collection_table_update_extras(ct, FALSE, 0.0);
2751 }
2752
2753 CollectInfo *collection_table_get_focus_info(CollectTable *ct)
2754 {
2755         return collection_table_find_data(ct, ct->focus_row, ct->focus_column, nullptr);
2756 }
2757
2758 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */