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