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