4 * Copyright (C) 2008 The Geeqie Team
8 * This software is released under the GNU General Public License (GNU GPL).
9 * Please read the included file COPYING for more information.
10 * This software comes with no warranty of any kind, use at your own risk!
14 #include "view_file_icon.h"
16 #include "cellrenderericon.h"
18 #include "collect-io.h"
19 #include "collect-table.h"
26 #include "layout_image.h"
30 #include "ui_bookmark.h"
31 #include "ui_fileops.h"
33 #include "ui_tree_edit.h"
34 #include "view_file.h"
36 #include <gdk/gdkkeysyms.h> /* for keyboard values */
39 /* between these, the icon width is increased by thumb_max_width / 2 */
40 #define THUMB_MIN_ICON_WIDTH 128
41 #define THUMB_MAX_ICON_WIDTH 150
43 #define VFICON_MAX_COLUMNS 32
44 #define THUMB_BORDER_PADDING 2
46 #define VFICON_TIP_DELAY 500
49 FILE_COLUMN_POINTER = 0,
55 SELECTION_SELECTED = 1 << 0,
56 SELECTION_PRELIGHT = 1 << 1,
57 SELECTION_FOCUS = 1 << 2
60 typedef struct _IconData IconData;
63 SelectionType selected;
68 static gint vficon_index_by_id(ViewFile *vf, IconData *in_id);
70 static IconData *vficon_icon_data(ViewFile *vf, FileData *fd)
79 IconData *chk = work->data;
81 if (chk->fd == fd) id = chk;
87 static gint iconlist_read(const gchar *path, GList **list)
92 if (!filelist_read(path, &temp, NULL)) return FALSE;
101 g_assert(fd->magick == 0x12345678);
102 id = g_new0(IconData, 1);
104 id->selected = SELECTION_NONE;
117 static void iconlist_free(GList *list)
122 IconData *id = work->data;
123 file_data_unref(id->fd);
132 gint iconlist_sort_file_cb(void *a, void *b)
136 return filelist_sort_compare_filedata(ida->fd, idb->fd);
139 GList *iconlist_sort(GList *list, SortType method, gint ascend)
141 return filelist_sort_full(list, method, ascend, (GCompareFunc) iconlist_sort_file_cb);
144 GList *iconlist_insert_sort(GList *list, IconData *id, SortType method, gint ascend)
146 return filelist_insert_sort_full(list, id, method, ascend, (GCompareFunc) iconlist_sort_file_cb);
150 static void vficon_toggle_filenames(ViewFile *vf);
151 static void vficon_selection_remove(ViewFile *vf, IconData *id, SelectionType mask, GtkTreeIter *iter);
152 static void vficon_move_focus(ViewFile *vf, gint row, gint col, gint relative);
153 static void vficon_set_focus(ViewFile *vf, IconData *id);
154 static void vficon_thumb_update(ViewFile *vf);
155 static void vficon_populate_at_new_size(ViewFile *vf, gint w, gint h, gint force);
159 *-----------------------------------------------------------------------------
161 *-----------------------------------------------------------------------------
164 GList *vficon_pop_menu_file_list(ViewFile *vf)
166 if (!VFICON_INFO(vf, click_id)) return NULL;
168 if (VFICON_INFO(vf, click_id)->selected & SELECTION_SELECTED)
170 return vf_selection_get_list(vf);
173 return g_list_append(NULL, file_data_ref(VFICON_INFO(vf, click_id)->fd));
176 void vficon_pop_menu_view_cb(GtkWidget *widget, gpointer data)
180 if (!VFICON_INFO(vf, click_id)) return;
182 if (VFICON_INFO(vf, click_id)->selected & SELECTION_SELECTED)
186 list = vf_selection_get_list(vf);
187 view_window_new_from_list(list);
192 view_window_new(VFICON_INFO(vf, click_id)->fd);
196 void vficon_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
200 file_util_rename(NULL, vf_pop_menu_file_list(vf), vf->listview);
203 void vficon_pop_menu_show_names_cb(GtkWidget *widget, gpointer data)
207 vficon_toggle_filenames(vf);
210 void vficon_pop_menu_refresh_cb(GtkWidget *widget, gpointer data)
217 void vficon_popup_destroy_cb(GtkWidget *widget, gpointer data)
220 vficon_selection_remove(vf, VFICON_INFO(vf, click_id), SELECTION_PRELIGHT, NULL);
221 VFICON_INFO(vf, click_id) = NULL;
226 *-------------------------------------------------------------------
228 *-------------------------------------------------------------------
231 static void vficon_send_layout_select(ViewFile *vf, IconData *id)
233 FileData *read_ahead_fd = NULL;
237 if (!vf->layout || !id || !id->fd) return;
241 cur_fd = layout_image_get_fd(vf->layout);
242 if (sel_fd == cur_fd) return; /* no change */
244 if (options->image.enable_read_ahead)
248 row = g_list_index(vf->list, id);
249 if (row > vficon_index_by_fd(vf, cur_fd) &&
250 (guint) (row + 1) < vf_count(vf, NULL))
252 read_ahead_fd = vf_index_get_data(vf, row + 1);
256 read_ahead_fd = vf_index_get_data(vf, row - 1);
260 layout_image_set_with_ahead(vf->layout, sel_fd, read_ahead_fd);
263 static void vficon_toggle_filenames(ViewFile *vf)
265 VFICON_INFO(vf, show_text) = !VFICON_INFO(vf, show_text);
266 options->show_icon_names = VFICON_INFO(vf, show_text);
268 vficon_populate_at_new_size(vf, vf->listview->allocation.width, vf->listview->allocation.height, TRUE);
271 static gint vficon_get_icon_width(ViewFile *vf)
275 if (!VFICON_INFO(vf, show_text)) return options->thumbnails.max_width;
277 width = options->thumbnails.max_width + options->thumbnails.max_width / 2;
278 if (width < THUMB_MIN_ICON_WIDTH) width = THUMB_MIN_ICON_WIDTH;
279 if (width > THUMB_MAX_ICON_WIDTH) width = options->thumbnails.max_width;
285 *-------------------------------------------------------------------
287 *-------------------------------------------------------------------
290 static gint vficon_find_position(ViewFile *vf, IconData *id, gint *row, gint *col)
294 n = g_list_index(vf->list, id);
296 if (n < 0) return FALSE;
298 *row = n / VFICON_INFO(vf, columns);
299 *col = n - (*row * VFICON_INFO(vf, columns));
304 static gint vficon_find_iter(ViewFile *vf, IconData *id, GtkTreeIter *iter, gint *column)
309 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
310 if (!vficon_find_position(vf, id, &row, &col)) return FALSE;
311 if (!gtk_tree_model_iter_nth_child(store, iter, NULL, row)) return FALSE;
312 if (column) *column = col;
317 static IconData *vficon_find_data(ViewFile *vf, gint row, gint col, GtkTreeIter *iter)
322 if (row < 0 || col < 0) return NULL;
324 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
325 if (gtk_tree_model_iter_nth_child(store, &p, NULL, row))
329 gtk_tree_model_get(store, &p, FILE_COLUMN_POINTER, &list, -1);
330 if (!list) return NULL;
334 return g_list_nth_data(list, col);
340 static IconData *vficon_find_data_by_coord(ViewFile *vf, gint x, gint y, GtkTreeIter *iter)
343 GtkTreeViewColumn *column;
345 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), x, y,
346 &tpath, &column, NULL, NULL))
353 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
354 gtk_tree_model_get_iter(store, &row, tpath);
355 gtk_tree_path_free(tpath);
357 gtk_tree_model_get(store, &row, FILE_COLUMN_POINTER, &list, -1);
359 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number"));
362 if (iter) *iter = row;
363 return g_list_nth_data(list, n);
371 *-------------------------------------------------------------------
372 * tooltip type window
373 *-------------------------------------------------------------------
376 static void tip_show(ViewFile *vf)
381 if (VFICON_INFO(vf, tip_window)) return;
383 gdk_window_get_pointer(gtk_tree_view_get_bin_window(GTK_TREE_VIEW(vf->listview)), &x, &y, NULL);
385 VFICON_INFO(vf, tip_id) = vficon_find_data_by_coord(vf, x, y, NULL);
386 if (!VFICON_INFO(vf, tip_id)) return;
388 VFICON_INFO(vf, tip_window) = gtk_window_new(GTK_WINDOW_POPUP);
389 gtk_window_set_resizable(GTK_WINDOW(VFICON_INFO(vf, tip_window)), FALSE);
390 gtk_container_set_border_width(GTK_CONTAINER(VFICON_INFO(vf, tip_window)), 2);
392 label = gtk_label_new(VFICON_INFO(vf, tip_id)->fd->name);
394 g_object_set_data(G_OBJECT(VFICON_INFO(vf, tip_window)), "tip_label", label);
395 gtk_container_add(GTK_CONTAINER(VFICON_INFO(vf, tip_window)), label);
396 gtk_widget_show(label);
398 gdk_window_get_pointer(NULL, &x, &y, NULL);
400 if (!GTK_WIDGET_REALIZED(VFICON_INFO(vf, tip_window))) gtk_widget_realize(VFICON_INFO(vf, tip_window));
401 gtk_window_move(GTK_WINDOW(VFICON_INFO(vf, tip_window)), x + 16, y + 16);
402 gtk_widget_show(VFICON_INFO(vf, tip_window));
405 static void tip_hide(ViewFile *vf)
407 if (VFICON_INFO(vf, tip_window)) gtk_widget_destroy(VFICON_INFO(vf, tip_window));
408 VFICON_INFO(vf, tip_window) = NULL;
411 static gint tip_schedule_cb(gpointer data)
416 if (VFICON_INFO(vf, tip_delay_id) == -1) return FALSE;
418 window = gtk_widget_get_toplevel(vf->listview);
420 if (GTK_WIDGET_SENSITIVE(window) &&
421 GTK_WINDOW(window)->has_focus)
426 VFICON_INFO(vf, tip_delay_id) = -1;
430 static void tip_schedule(ViewFile *vf)
434 if (VFICON_INFO(vf, tip_delay_id) != -1)
436 g_source_remove(VFICON_INFO(vf, tip_delay_id));
437 VFICON_INFO(vf, tip_delay_id) = -1;
440 if (!VFICON_INFO(vf, show_text))
442 VFICON_INFO(vf, tip_delay_id) = g_timeout_add(VFICON_TIP_DELAY, tip_schedule_cb, vf);
446 static void tip_unschedule(ViewFile *vf)
450 if (VFICON_INFO(vf, tip_delay_id) != -1) g_source_remove(VFICON_INFO(vf, tip_delay_id));
451 VFICON_INFO(vf, tip_delay_id) = -1;
454 static void tip_update(ViewFile *vf, IconData *id)
456 if (VFICON_INFO(vf, tip_window))
460 gdk_window_get_pointer(NULL, &x, &y, NULL);
461 gtk_window_move(GTK_WINDOW(VFICON_INFO(vf, tip_window)), x + 16, y + 16);
463 if (id != VFICON_INFO(vf, tip_id))
467 VFICON_INFO(vf, tip_id) = id;
469 if (!VFICON_INFO(vf, tip_id))
476 label = g_object_get_data(G_OBJECT(VFICON_INFO(vf, tip_window)), "tip_label");
477 gtk_label_set_text(GTK_LABEL(label), VFICON_INFO(vf, tip_id)->fd->name);
487 *-------------------------------------------------------------------
489 *-------------------------------------------------------------------
492 static void vficon_dnd_get(GtkWidget *widget, GdkDragContext *context,
493 GtkSelectionData *selection_data, guint info,
494 guint time, gpointer data)
498 gchar *uri_text = NULL;
501 if (!VFICON_INFO(vf, click_id)) return;
503 if (VFICON_INFO(vf, click_id)->selected & SELECTION_SELECTED)
505 list = vf_selection_get_list(vf);
509 list = g_list_append(NULL, file_data_ref(VFICON_INFO(vf, click_id)->fd));
513 uri_text = uri_text_from_filelist(list, &total, (info == TARGET_TEXT_PLAIN));
518 gtk_selection_data_set(selection_data, selection_data->target,
519 8, (guchar *)uri_text, total);
523 static void vficon_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
529 if (VFICON_INFO(vf, click_id) && VFICON_INFO(vf, click_id)->fd->pixbuf)
533 if (VFICON_INFO(vf, click_id)->selected & SELECTION_SELECTED)
534 items = g_list_length(VFICON_INFO(vf, selection));
538 dnd_set_drag_icon(widget, context, VFICON_INFO(vf, click_id)->fd->pixbuf, items);
542 static void vficon_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
546 vficon_selection_remove(vf, VFICON_INFO(vf, click_id), SELECTION_PRELIGHT, NULL);
548 if (context->action == GDK_ACTION_MOVE)
556 void vficon_dnd_init(ViewFile *vf)
558 gtk_drag_source_set(vf->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
559 dnd_file_drag_types, dnd_file_drag_types_count,
560 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
561 g_signal_connect(G_OBJECT(vf->listview), "drag_data_get",
562 G_CALLBACK(vficon_dnd_get), vf);
563 g_signal_connect(G_OBJECT(vf->listview), "drag_begin",
564 G_CALLBACK(vficon_dnd_begin), vf);
565 g_signal_connect(G_OBJECT(vf->listview), "drag_end",
566 G_CALLBACK(vficon_dnd_end), vf);
570 *-------------------------------------------------------------------
572 *-------------------------------------------------------------------
575 static void vficon_selection_set(ViewFile *vf, IconData *id, SelectionType value, GtkTreeIter *iter)
583 if (id->selected == value) return;
584 id->selected = value;
586 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
589 gtk_tree_model_get(store, iter, FILE_COLUMN_POINTER, &list, -1);
590 if (list) gtk_list_store_set(GTK_LIST_STORE(store), iter, FILE_COLUMN_POINTER, list, -1);
596 if (vficon_find_iter(vf, id, &row, NULL))
598 gtk_tree_model_get(store, &row, FILE_COLUMN_POINTER, &list, -1);
599 if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, FILE_COLUMN_POINTER, list, -1);
604 static void vficon_selection_add(ViewFile *vf, IconData *id, SelectionType mask, GtkTreeIter *iter)
608 vficon_selection_set(vf, id, id->selected | mask, iter);
611 static void vficon_selection_remove(ViewFile *vf, IconData *id, SelectionType mask, GtkTreeIter *iter)
615 vficon_selection_set(vf, id, id->selected & ~mask, iter);
619 *-------------------------------------------------------------------
621 *-------------------------------------------------------------------
624 static void vficon_verify_selections(ViewFile *vf)
628 work = VFICON_INFO(vf, selection);
631 IconData *id = work->data;
634 if (vficon_index_by_id(vf, id) >= 0) continue;
636 VFICON_INFO(vf, selection) = g_list_remove(VFICON_INFO(vf, selection), id);
640 void vficon_select_all(ViewFile *vf)
644 g_list_free(VFICON_INFO(vf, selection));
645 VFICON_INFO(vf, selection) = NULL;
650 IconData *id = work->data;
653 VFICON_INFO(vf, selection) = g_list_append(VFICON_INFO(vf, selection), id);
654 vficon_selection_add(vf, id, SELECTION_SELECTED, NULL);
660 void vficon_select_none(ViewFile *vf)
664 work = VFICON_INFO(vf, selection);
667 IconData *id = work->data;
670 vficon_selection_remove(vf, id, SELECTION_SELECTED, NULL);
673 g_list_free(VFICON_INFO(vf, selection));
674 VFICON_INFO(vf, selection) = NULL;
679 void vficon_select_invert(ViewFile *vf)
686 IconData *id = work->data;
689 if (id->selected & SELECTION_SELECTED)
691 VFICON_INFO(vf, selection) = g_list_remove(VFICON_INFO(vf, selection), id);
692 vficon_selection_remove(vf, id, SELECTION_SELECTED, NULL);
696 VFICON_INFO(vf, selection) = g_list_append(VFICON_INFO(vf, selection), id);
697 vficon_selection_add(vf, id, SELECTION_SELECTED, NULL);
704 static void vficon_select(ViewFile *vf, IconData *id)
706 VFICON_INFO(vf, prev_selection) = id;
708 if (!id || id->selected & SELECTION_SELECTED) return;
710 VFICON_INFO(vf, selection) = g_list_append(VFICON_INFO(vf, selection), id);
711 vficon_selection_add(vf, id, SELECTION_SELECTED, NULL);
716 static void vficon_unselect(ViewFile *vf, IconData *id)
718 VFICON_INFO(vf, prev_selection) = id;
720 if (!id || !(id->selected & SELECTION_SELECTED) ) return;
722 VFICON_INFO(vf, selection) = g_list_remove(VFICON_INFO(vf, selection), id);
723 vficon_selection_remove(vf, id, SELECTION_SELECTED, NULL);
728 static void vficon_select_util(ViewFile *vf, IconData *id, gint select)
732 vficon_select(vf, id);
736 vficon_unselect(vf, id);
740 static void vficon_select_region_util(ViewFile *vf, IconData *start, IconData *end, gint select)
747 if (!vficon_find_position(vf, start, &row1, &col1) ||
748 !vficon_find_position(vf, end, &row2, &col2) ) return;
750 VFICON_INFO(vf, prev_selection) = end;
752 if (!options->collections.rectangular_selection)
757 if (g_list_index(vf->list, start) > g_list_index(vf->list, end))
764 work = g_list_find(vf->list, start);
768 vficon_select_util(vf, id, select);
770 if (work->data != end)
791 DEBUG_1("table: %d x %d to %d x %d", row1, col1, row2, col2);
793 for (i = row1; i <= row2; i++)
795 for (j = col1; j <= col2; j++)
797 IconData *id = vficon_find_data(vf, i, j, NULL);
798 if (id) vficon_select_util(vf, id, select);
803 gint vficon_index_is_selected(ViewFile *vf, gint row)
805 IconData *id = g_list_nth_data(vf->list, row);
807 if (!id) return FALSE;
809 return (id->selected & SELECTION_SELECTED);
812 guint vficon_selection_count(ViewFile *vf, gint64 *bytes)
819 work = VFICON_INFO(vf, selection);
822 IconData *id = work->data;
823 FileData *fd = id->fd;
824 g_assert(fd->magick == 0x12345678);
833 return g_list_length(VFICON_INFO(vf, selection));
836 GList *vficon_selection_get_list(ViewFile *vf)
841 work = VFICON_INFO(vf, selection);
844 IconData *id = work->data;
845 FileData *fd = id->fd;
846 g_assert(fd->magick == 0x12345678);
848 list = g_list_prepend(list, file_data_ref(fd));
853 list = g_list_reverse(list);
858 GList *vficon_selection_get_list_by_index(ViewFile *vf)
863 work = VFICON_INFO(vf, selection);
866 list = g_list_prepend(list, GINT_TO_POINTER(g_list_index(vf->list, work->data)));
870 return g_list_reverse(list);
873 static void vficon_select_by_id(ViewFile *vf, IconData *id)
877 if (!(id->selected & SELECTION_SELECTED))
880 vficon_select(vf, id);
883 vficon_set_focus(vf, id);
886 void vficon_select_by_fd(ViewFile *vf, FileData *fd)
895 IconData *chk = work->data;
897 if (chk->fd == fd) id = chk;
899 vficon_select_by_id(vf, id);
902 void vficon_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
907 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
912 IconData *id = work->data;
913 FileData *fd = id->fd;
914 gboolean mark_val, selected;
916 g_assert(fd->magick == 0x12345678);
918 mark_val = fd->marks[n];
919 selected = (id->selected & SELECTION_SELECTED);
923 case MTS_MODE_SET: selected = mark_val;
925 case MTS_MODE_OR: selected = mark_val | selected;
927 case MTS_MODE_AND: selected = mark_val & selected;
929 case MTS_MODE_MINUS: selected = !mark_val & selected;
933 vficon_select_util(vf, id, selected);
939 void vficon_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode)
945 g_assert(mark >= 1 && mark <= FILEDATA_MARKS_SIZE);
947 slist = vf_selection_get_list(vf);
951 FileData *fd = work->data;
955 case STM_MODE_SET: fd->marks[n] = 1;
957 case STM_MODE_RESET: fd->marks[n] = 0;
959 case STM_MODE_TOGGLE: fd->marks[n] = !fd->marks[mark];
965 filelist_free(slist);
970 *-------------------------------------------------------------------
972 *-------------------------------------------------------------------
975 static void vficon_move_focus(ViewFile *vf, gint row, gint col, gint relative)
982 new_row = VFICON_INFO(vf, focus_row);
983 new_col = VFICON_INFO(vf, focus_column);
986 if (new_row < 0) new_row = 0;
987 if (new_row >= VFICON_INFO(vf, rows)) new_row = VFICON_INFO(vf, rows) - 1;
1007 new_col = VFICON_INFO(vf, columns) - 1;
1014 if (new_col >= VFICON_INFO(vf, columns))
1016 if (new_row < VFICON_INFO(vf, rows) - 1)
1023 new_col = VFICON_INFO(vf, columns) - 1;
1033 if (new_row >= VFICON_INFO(vf, rows))
1035 if (VFICON_INFO(vf, rows) > 0)
1036 new_row = VFICON_INFO(vf, rows) - 1;
1039 new_col = VFICON_INFO(vf, columns) - 1;
1041 if (new_col >= VFICON_INFO(vf, columns)) new_col = VFICON_INFO(vf, columns) - 1;
1044 if (new_row == VFICON_INFO(vf, rows) - 1)
1048 /* if we moved beyond the last image, go to the last image */
1050 l = g_list_length(vf->list);
1051 if (VFICON_INFO(vf, rows) > 1) l -= (VFICON_INFO(vf, rows) - 1) * VFICON_INFO(vf, columns);
1052 if (new_col >= l) new_col = l - 1;
1055 vficon_set_focus(vf, vficon_find_data(vf, new_row, new_col, NULL));
1058 static void vficon_set_focus(ViewFile *vf, IconData *id)
1063 if (g_list_find(vf->list, VFICON_INFO(vf, focus_id)))
1065 if (id == VFICON_INFO(vf, focus_id))
1067 /* ensure focus row col are correct */
1068 vficon_find_position(vf, VFICON_INFO(vf, focus_id), &VFICON_INFO(vf, focus_row), &VFICON_INFO(vf, focus_column));
1071 vficon_selection_remove(vf, VFICON_INFO(vf, focus_id), SELECTION_FOCUS, NULL);
1074 if (!vficon_find_position(vf, id, &row, &col))
1076 VFICON_INFO(vf, focus_id) = NULL;
1077 VFICON_INFO(vf, focus_row) = -1;
1078 VFICON_INFO(vf, focus_column) = -1;
1082 VFICON_INFO(vf, focus_id) = id;
1083 VFICON_INFO(vf, focus_row) = row;
1084 VFICON_INFO(vf, focus_column) = col;
1085 vficon_selection_add(vf, VFICON_INFO(vf, focus_id), SELECTION_FOCUS, NULL);
1087 if (vficon_find_iter(vf, VFICON_INFO(vf, focus_id), &iter, NULL))
1090 GtkTreeViewColumn *column;
1091 GtkTreeModel *store;
1093 tree_view_row_make_visible(GTK_TREE_VIEW(vf->listview), &iter, FALSE);
1095 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
1096 tpath = gtk_tree_model_get_path(store, &iter);
1097 /* focus is set to an extra column with 0 width to hide focus, we draw it ourself */
1098 column = gtk_tree_view_get_column(GTK_TREE_VIEW(vf->listview), VFICON_MAX_COLUMNS);
1099 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vf->listview), tpath, column, FALSE);
1100 gtk_tree_path_free(tpath);
1104 static void vficon_update_focus(ViewFile *vf)
1109 if (VFICON_INFO(vf, focus_id) && vficon_find_position(vf, VFICON_INFO(vf, focus_id), &new_row, &new_col))
1111 /* first find the old focus, if it exists and is valid */
1115 /* (try to) stay where we were */
1116 new_row = VFICON_INFO(vf, focus_row);
1117 new_col = VFICON_INFO(vf, focus_column);
1120 vficon_move_focus(vf, new_row, new_col, FALSE);
1123 /* used to figure the page up/down distances */
1124 static gint page_height(ViewFile *vf)
1131 adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(vf->listview));
1132 page_size = (gint)adj->page_increment;
1134 row_height = options->thumbnails.max_height + THUMB_BORDER_PADDING * 2;
1135 if (VFICON_INFO(vf, show_text)) row_height += options->thumbnails.max_height / 3;
1137 ret = page_size / row_height;
1138 if (ret < 1) ret = 1;
1144 *-------------------------------------------------------------------
1146 *-------------------------------------------------------------------
1149 static void vfi_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
1151 ViewFile *vf = data;
1152 GtkTreeModel *store;
1158 if (!vficon_find_iter(vf, VFICON_INFO(vf, click_id), &iter, &column)) return;
1159 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
1160 tpath = gtk_tree_model_get_path(store, &iter);
1161 tree_view_get_cell_clamped(GTK_TREE_VIEW(vf->listview), tpath, column, FALSE, x, y, &cw, &ch);
1162 gtk_tree_path_free(tpath);
1164 popup_menu_position_clamp(menu, x, y, 0);
1167 gint vficon_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
1169 ViewFile *vf = data;
1176 switch (event->keyval)
1178 case GDK_Left: case GDK_KP_Left:
1181 case GDK_Right: case GDK_KP_Right:
1184 case GDK_Up: case GDK_KP_Up:
1187 case GDK_Down: case GDK_KP_Down:
1190 case GDK_Page_Up: case GDK_KP_Page_Up:
1191 focus_row = -page_height(vf);
1193 case GDK_Page_Down: case GDK_KP_Page_Down:
1194 focus_row = page_height(vf);
1196 case GDK_Home: case GDK_KP_Home:
1197 focus_row = -VFICON_INFO(vf, focus_row);
1198 focus_col = -VFICON_INFO(vf, focus_column);
1200 case GDK_End: case GDK_KP_End:
1201 focus_row = VFICON_INFO(vf, rows) - 1 - VFICON_INFO(vf, focus_row);
1202 focus_col = VFICON_INFO(vf, columns) - 1 - VFICON_INFO(vf, focus_column);
1205 id = vficon_find_data(vf, VFICON_INFO(vf, focus_row), VFICON_INFO(vf, focus_column), NULL);
1208 VFICON_INFO(vf, click_id) = id;
1209 if (event->state & GDK_CONTROL_MASK)
1213 selected = id->selected & SELECTION_SELECTED;
1216 vficon_unselect(vf, id);
1220 vficon_select(vf, id);
1221 vficon_send_layout_select(vf, id);
1227 vficon_select(vf, id);
1228 vficon_send_layout_select(vf, id);
1233 id = vficon_find_data(vf, VFICON_INFO(vf, focus_row), VFICON_INFO(vf, focus_column), NULL);
1234 VFICON_INFO(vf, click_id) = id;
1236 vficon_selection_add(vf, VFICON_INFO(vf, click_id), SELECTION_PRELIGHT, NULL);
1239 vf->popup = vf_pop_menu(vf);
1240 gtk_menu_popup(GTK_MENU(vf->popup), NULL, NULL, vfi_menu_position_cb, vf, 0, GDK_CURRENT_TIME);
1243 stop_signal = FALSE;
1247 if (focus_row != 0 || focus_col != 0)
1252 old_id = vficon_find_data(vf, VFICON_INFO(vf, focus_row), VFICON_INFO(vf, focus_column), NULL);
1253 vficon_move_focus(vf, focus_row, focus_col, TRUE);
1254 new_id = vficon_find_data(vf, VFICON_INFO(vf, focus_row), VFICON_INFO(vf, focus_column), NULL);
1256 if (new_id != old_id)
1258 if (event->state & GDK_SHIFT_MASK)
1260 if (!options->collections.rectangular_selection)
1262 vficon_select_region_util(vf, old_id, new_id, FALSE);
1266 vficon_select_region_util(vf, VFICON_INFO(vf, click_id), old_id, FALSE);
1268 vficon_select_region_util(vf, VFICON_INFO(vf, click_id), new_id, TRUE);
1269 vficon_send_layout_select(vf, new_id);
1271 else if (event->state & GDK_CONTROL_MASK)
1273 VFICON_INFO(vf, click_id) = new_id;
1277 VFICON_INFO(vf, click_id) = new_id;
1279 vficon_select(vf, new_id);
1280 vficon_send_layout_select(vf, new_id);
1288 g_signal_stop_emission_by_name(GTK_OBJECT(widget), "key_press_event");
1297 *-------------------------------------------------------------------
1299 *-------------------------------------------------------------------
1302 static gint vficon_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1304 ViewFile *vf = data;
1307 id = vficon_find_data_by_coord(vf, (gint)bevent->x, (gint)bevent->y, NULL);
1313 gint vficon_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1315 ViewFile *vf = data;
1321 id = vficon_find_data_by_coord(vf, (gint)bevent->x, (gint)bevent->y, &iter);
1323 VFICON_INFO(vf, click_id) = id;
1324 vficon_selection_add(vf, VFICON_INFO(vf, click_id), SELECTION_PRELIGHT, &iter);
1326 switch (bevent->button)
1328 case MOUSE_BUTTON_LEFT:
1329 if (!GTK_WIDGET_HAS_FOCUS(vf->listview))
1331 gtk_widget_grab_focus(vf->listview);
1334 if (bevent->type == GDK_2BUTTON_PRESS &&
1337 vficon_selection_remove(vf, VFICON_INFO(vf, click_id), SELECTION_PRELIGHT, &iter);
1338 layout_image_full_screen_start(vf->layout);
1342 case MOUSE_BUTTON_RIGHT:
1343 vf->popup = vf_pop_menu(vf);
1344 gtk_menu_popup(GTK_MENU(vf->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
1353 gint vficon_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1355 ViewFile *vf = data;
1357 IconData *id = NULL;
1362 if ((gint)bevent->x != 0 || (gint)bevent->y != 0)
1364 id = vficon_find_data_by_coord(vf, (gint)bevent->x, (gint)bevent->y, &iter);
1367 if (VFICON_INFO(vf, click_id))
1369 vficon_selection_remove(vf, VFICON_INFO(vf, click_id), SELECTION_PRELIGHT, NULL);
1372 if (!id || VFICON_INFO(vf, click_id) != id) return TRUE;
1374 was_selected = (id->selected & SELECTION_SELECTED);
1376 switch (bevent->button)
1378 case MOUSE_BUTTON_LEFT:
1380 vficon_set_focus(vf, id);
1382 if (bevent->state & GDK_CONTROL_MASK)
1386 select = !(id->selected & SELECTION_SELECTED);
1387 if ((bevent->state & GDK_SHIFT_MASK) && VFICON_INFO(vf, prev_selection))
1389 vficon_select_region_util(vf, VFICON_INFO(vf, prev_selection), id, select);
1393 vficon_select_util(vf, id, select);
1400 if ((bevent->state & GDK_SHIFT_MASK) && VFICON_INFO(vf, prev_selection))
1402 vficon_select_region_util(vf, VFICON_INFO(vf, prev_selection), id, TRUE);
1406 vficon_select_util(vf, id, TRUE);
1407 was_selected = FALSE;
1412 case MOUSE_BUTTON_MIDDLE:
1414 vficon_select_util(vf, id, !(id->selected & SELECTION_SELECTED));
1421 if (!was_selected && (id->selected & SELECTION_SELECTED))
1423 vficon_send_layout_select(vf, id);
1429 static gint vficon_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
1431 ViewFile *vf = data;
1438 *-------------------------------------------------------------------
1440 *-------------------------------------------------------------------
1443 static gboolean vficon_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data)
1447 gtk_tree_model_get(store, iter, FILE_COLUMN_POINTER, &list, -1);
1453 static void vficon_clear_store(ViewFile *vf)
1455 GtkTreeModel *store;
1457 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
1458 gtk_tree_model_foreach(store, vficon_destroy_node_cb, NULL);
1460 gtk_list_store_clear(GTK_LIST_STORE(store));
1463 static void vficon_set_thumb(ViewFile *vf, FileData *fd, GdkPixbuf *pb)
1465 GtkTreeModel *store;
1469 if (!vficon_find_iter(vf, vficon_icon_data(vf, fd), &iter, NULL)) return;
1471 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
1473 if (pb) g_object_ref(pb);
1474 if (fd->pixbuf) g_object_unref(fd->pixbuf);
1477 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1);
1478 gtk_list_store_set(GTK_LIST_STORE(store), &iter, FILE_COLUMN_POINTER, list, -1);
1481 static GList *vficon_add_row(ViewFile *vf, GtkTreeIter *iter)
1483 GtkListStore *store;
1487 for (i = 0; i < VFICON_INFO(vf, columns); i++) list = g_list_prepend(list, NULL);
1489 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)));
1490 gtk_list_store_append(store, iter);
1491 gtk_list_store_set(store, iter, FILE_COLUMN_POINTER, list, -1);
1496 static void vficon_populate(ViewFile *vf, gint resize, gint keep_position)
1498 GtkTreeModel *store;
1502 IconData *visible_id = NULL;
1504 vficon_verify_selections(vf);
1506 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
1508 if (keep_position && GTK_WIDGET_REALIZED(vf->listview) &&
1509 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL))
1514 gtk_tree_model_get_iter(store, &iter, tpath);
1515 gtk_tree_path_free(tpath);
1517 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1);
1518 if (list) visible_id = list->data;
1521 vficon_clear_store(vf);
1528 thumb_width = vficon_get_icon_width(vf);
1530 for (i = 0; i < VFICON_MAX_COLUMNS; i++)
1532 GtkTreeViewColumn *column;
1533 GtkCellRenderer *cell;
1536 column = gtk_tree_view_get_column(GTK_TREE_VIEW(vf->listview), i);
1537 gtk_tree_view_column_set_visible(column, (i < VFICON_INFO(vf, columns)));
1538 gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6));
1540 list = gtk_tree_view_column_get_cell_renderers(column);
1541 cell = (list) ? list->data : NULL;
1544 if (cell && GQV_IS_CELL_RENDERER_ICON(cell))
1546 g_object_set(G_OBJECT(cell), "fixed_width", thumb_width,
1547 "fixed_height", options->thumbnails.max_height,
1548 "show_text", VFICON_INFO(vf, show_text), NULL);
1551 if (GTK_WIDGET_REALIZED(vf->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(vf->listview));
1563 list = vficon_add_row(vf, &iter);
1564 while (work && list)
1571 list->data = work->data;
1578 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL))
1583 gtk_tree_model_get_iter(store, &iter, tpath);
1584 gtk_tree_path_free(tpath);
1586 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1);
1587 if (g_list_find(list, visible_id) == NULL &&
1588 vficon_find_iter(vf, visible_id, &iter, NULL))
1590 tree_view_row_make_visible(GTK_TREE_VIEW(vf->listview), &iter, FALSE);
1594 VFICON_INFO(vf, rows) = row + 1;
1597 vficon_thumb_update(vf);
1600 static void vficon_populate_at_new_size(ViewFile *vf, gint w, gint h, gint force)
1605 thumb_width = vficon_get_icon_width(vf);
1607 new_cols = w / (thumb_width + (THUMB_BORDER_PADDING * 6));
1608 if (new_cols < 1) new_cols = 1;
1610 if (!force && new_cols == VFICON_INFO(vf, columns)) return;
1612 VFICON_INFO(vf, columns) = new_cols;
1614 vficon_populate(vf, TRUE, TRUE);
1616 DEBUG_1("col tab pop cols=%d rows=%d", VFICON_INFO(vf, columns), VFICON_INFO(vf, rows));
1619 static void vficon_sync(ViewFile *vf)
1621 GtkTreeModel *store;
1626 if (VFICON_INFO(vf, rows) == 0) return;
1628 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
1639 if (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1641 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1);
1642 gtk_list_store_set(GTK_LIST_STORE(store), &iter, FILE_COLUMN_POINTER, list, -1);
1646 list = vficon_add_row(vf, &iter);
1672 while (gtk_tree_model_iter_nth_child(store, &iter, NULL, r))
1676 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1);
1677 gtk_list_store_remove(GTK_LIST_STORE(store), &iter);
1681 VFICON_INFO(vf, rows) = r;
1683 vficon_update_focus(vf);
1686 static gint vficon_sync_idle_cb(gpointer data)
1688 ViewFile *vf = data;
1690 if (VFICON_INFO(vf, sync_idle_id) == -1) return FALSE;
1691 VFICON_INFO(vf, sync_idle_id) = -1;
1697 static void vficon_sync_idle(ViewFile *vf)
1699 if (VFICON_INFO(vf, sync_idle_id) == -1)
1701 /* high priority, the view needs to be resynced before a redraw
1702 * may contain invalid pointers at this time
1704 VFICON_INFO(vf, sync_idle_id) = g_idle_add_full(G_PRIORITY_HIGH, vficon_sync_idle_cb, vf, NULL);
1708 static void vficon_sized_cb(GtkWidget *widget, GtkAllocation *allocation, gpointer data)
1710 ViewFile *vf = data;
1712 vficon_populate_at_new_size(vf, allocation->width, allocation->height, FALSE);
1716 *-----------------------------------------------------------------------------
1718 *-----------------------------------------------------------------------------
1721 void vficon_sort_set(ViewFile *vf, SortType type, gint ascend)
1723 if (vf->sort_method == type && vf->sort_ascend == ascend) return;
1725 vf->sort_method = type;
1726 vf->sort_ascend = ascend;
1728 if (!vf->list) return;
1730 vf->list = iconlist_sort(vf->list, vf->sort_method, vf->sort_ascend);
1735 *-----------------------------------------------------------------------------
1737 *-----------------------------------------------------------------------------
1740 static gint vficon_thumb_next(ViewFile *vf);
1742 static void vficon_thumb_status(ViewFile *vf, gdouble val, const gchar *text)
1744 if (vf->func_thumb_status)
1746 vf->func_thumb_status(vf, val, text, vf->data_thumb_status);
1750 static void vficon_thumb_cleanup(ViewFile *vf)
1752 vficon_thumb_status(vf, 0.0, NULL);
1754 vf->thumbs_count = 0;
1755 vf->thumbs_running = FALSE;
1757 thumb_loader_free(vf->thumbs_loader);
1758 vf->thumbs_loader = NULL;
1760 vf->thumbs_filedata = NULL;
1763 static void vficon_thumb_stop(ViewFile *vf)
1765 if (vf->thumbs_running) vficon_thumb_cleanup(vf);
1768 static void vficon_thumb_do(ViewFile *vf, ThumbLoader *tl, FileData *fd)
1774 pixbuf = thumb_loader_get_pixbuf(tl, TRUE);
1775 vficon_set_thumb(vf, fd, pixbuf);
1776 g_object_unref(pixbuf);
1778 vficon_thumb_status(vf, (gdouble)(vf->thumbs_count) / g_list_length(vf->list), _("Loading thumbs..."));
1781 static void vficon_thumb_error_cb(ThumbLoader *tl, gpointer data)
1783 ViewFile *vf = data;
1785 if (vf->thumbs_filedata && vf->thumbs_loader == tl)
1787 vficon_thumb_do(vf, tl, vf->thumbs_filedata);
1790 while (vficon_thumb_next(vf));
1793 static void vficon_thumb_done_cb(ThumbLoader *tl, gpointer data)
1795 ViewFile *vf = data;
1797 if (vf->thumbs_filedata && vf->thumbs_loader == tl)
1799 vficon_thumb_do(vf, tl, vf->thumbs_filedata);
1802 while (vficon_thumb_next(vf));
1805 static gint vficon_thumb_next(ViewFile *vf)
1808 FileData *fd = NULL;
1810 if (!GTK_WIDGET_REALIZED(vf->listview))
1812 vficon_thumb_status(vf, 0.0, NULL);
1816 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL))
1818 GtkTreeModel *store;
1822 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
1823 gtk_tree_model_get_iter(store, &iter, tpath);
1824 gtk_tree_path_free(tpath);
1826 while (!fd && valid && tree_view_row_get_visibility(GTK_TREE_VIEW(vf->listview), &iter, FALSE) == 0)
1830 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1);
1834 IconData *id = list->data;
1835 if (id && !id->fd->pixbuf) fd = id->fd;
1839 valid = gtk_tree_model_iter_next(store, &iter);
1843 /* then find first undone */
1847 GList *work = vf->list;
1850 IconData *id = work->data;
1851 FileData *fd_p = id->fd;
1854 if (!fd_p->pixbuf) fd = fd_p;
1861 vficon_thumb_cleanup(vf);
1867 vf->thumbs_filedata = fd;
1869 thumb_loader_free(vf->thumbs_loader);
1871 vf->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
1872 thumb_loader_set_callbacks(vf->thumbs_loader,
1873 vficon_thumb_done_cb,
1874 vficon_thumb_error_cb,
1878 if (!thumb_loader_start(vf->thumbs_loader, fd->path))
1880 /* set icon to unknown, continue */
1881 DEBUG_1("thumb loader start failed %s", vf->thumbs_loader->path);
1882 vficon_thumb_do(vf, vf->thumbs_loader, fd);
1890 static void vficon_thumb_update(ViewFile *vf)
1892 vficon_thumb_stop(vf);
1894 vficon_thumb_status(vf, 0.0, _("Loading thumbs..."));
1895 vf->thumbs_running = TRUE;
1897 while (vficon_thumb_next(vf));
1901 *-----------------------------------------------------------------------------
1903 *-----------------------------------------------------------------------------
1906 FileData *vficon_index_get_data(ViewFile *vf, gint row)
1910 id = g_list_nth_data(vf->list, row);
1911 return id ? id->fd : NULL;
1914 gint vficon_index_by_path(ViewFile *vf, const gchar *path)
1919 if (!path) return -1;
1924 IconData *id = work->data;
1925 FileData *fd = id->fd;
1926 if (strcmp(path, fd->path) == 0) return p;
1934 gint vficon_index_by_fd(ViewFile *vf, FileData *in_fd)
1939 if (!in_fd) return -1;
1944 IconData *id = work->data;
1945 FileData *fd = id->fd;
1946 if (fd == in_fd) return p;
1954 static gint vficon_index_by_id(ViewFile *vf, IconData *in_id)
1959 if (!in_id) return -1;
1964 IconData *id = work->data;
1965 if (id == in_id) return p;
1973 guint vficon_count(ViewFile *vf, gint64 *bytes)
1983 IconData *id = work->data;
1984 FileData *fd = id->fd;
1993 return g_list_length(vf->list);
1996 GList *vficon_get_list(ViewFile *vf)
2004 IconData *id = work->data;
2005 FileData *fd = id->fd;
2008 list = g_list_prepend(list, file_data_ref(fd));
2011 return g_list_reverse(list);
2015 *-----------------------------------------------------------------------------
2017 *-----------------------------------------------------------------------------
2020 static gint vficon_refresh_real(ViewFile *vf, gint keep_position)
2027 focus_id = VFICON_INFO(vf, focus_id);
2029 old_list = vf->list;
2034 ret = iconlist_read(vf->path, &vf->list);
2037 /* check for same files from old_list */
2041 IconData *id = work->data;
2042 FileData *fd = id->fd;
2043 GList *needle = vf->list;
2047 IconData *idn = needle->data;
2048 FileData *fdn = idn->fd;
2052 /* swap, to retain old thumb, selection */
2059 needle = needle->next;
2066 vf->list = iconlist_sort(vf->list, vf->sort_method, vf->sort_ascend);
2071 IconData *id = work->data;
2074 if (id == VFICON_INFO(vf, prev_selection)) VFICON_INFO(vf, prev_selection) = NULL;
2075 if (id == VFICON_INFO(vf, click_id)) VFICON_INFO(vf, click_id) = NULL;
2078 vficon_populate(vf, TRUE, keep_position);
2080 /* attempt to keep focus on same icon when refreshing */
2081 if (focus_id && g_list_find(vf->list, focus_id))
2083 vficon_set_focus(vf, focus_id);
2086 iconlist_free(old_list);
2091 gint vficon_refresh(ViewFile *vf)
2093 return vficon_refresh_real(vf, TRUE);
2097 *-----------------------------------------------------------------------------
2099 *-----------------------------------------------------------------------------
2102 typedef struct _ColumnData ColumnData;
2109 static void vficon_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
2110 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
2112 ColumnData *cd = data;
2122 gtk_tree_model_get(tree_model, iter, FILE_COLUMN_POINTER, &list, -1);
2124 id = g_list_nth_data(list, cd->number);
2126 if (id) g_assert(id->fd->magick == 0x12345678);
2128 style = gtk_widget_get_style(vf->listview);
2129 if (id && id->selected & SELECTION_SELECTED)
2131 memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg));
2132 memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg));
2136 memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg));
2137 memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg));
2140 if (id && id->selected & SELECTION_PRELIGHT)
2143 shift_color(&color_fg, -1, 0);
2145 shift_color(&color_bg, -1, 0);
2148 if (GQV_IS_CELL_RENDERER_ICON(cell))
2152 g_object_set(cell, "pixbuf", id->fd->pixbuf,
2153 "text", id->fd->name,
2154 "cell-background-gdk", &color_bg,
2155 "cell-background-set", TRUE,
2156 "foreground-gdk", &color_fg,
2157 "foreground-set", TRUE,
2158 "has-focus", (VFICON_INFO(vf, focus_id) == id), NULL);
2162 g_object_set(cell, "pixbuf", NULL,
2164 "cell-background-set", FALSE,
2165 "foreground-set", FALSE,
2166 "has-focus", FALSE, NULL);
2171 static void vficon_append_column(ViewFile *vf, gint n)
2174 GtkTreeViewColumn *column;
2175 GtkCellRenderer *renderer;
2177 column = gtk_tree_view_column_new();
2178 gtk_tree_view_column_set_min_width(column, 0);
2180 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
2181 gtk_tree_view_column_set_alignment(column, 0.5);
2183 renderer = gqv_cell_renderer_icon_new();
2184 gtk_tree_view_column_pack_start(column, renderer, FALSE);
2185 g_object_set(G_OBJECT(renderer), "xpad", THUMB_BORDER_PADDING * 2,
2186 "ypad", THUMB_BORDER_PADDING,
2187 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
2189 g_object_set_data(G_OBJECT(column), "column_number", GINT_TO_POINTER(n));
2191 cd = g_new0(ColumnData, 1);
2194 gtk_tree_view_column_set_cell_data_func(column, renderer, vficon_cell_data_cb, cd, g_free);
2196 gtk_tree_view_append_column(GTK_TREE_VIEW(vf->listview), column);
2200 *-----------------------------------------------------------------------------
2202 *-----------------------------------------------------------------------------
2205 gint vficon_set_path(ViewFile *vf, const gchar *path)
2209 if (!path) return FALSE;
2210 if (vf->path && strcmp(path, vf->path) == 0) return TRUE;
2213 vf->path = g_strdup(path);
2215 g_list_free(VFICON_INFO(vf, selection));
2216 VFICON_INFO(vf, selection) = NULL;
2218 iconlist_free(vf->list);
2221 /* NOTE: populate will clear the store for us */
2222 ret = vficon_refresh_real(vf, FALSE);
2224 VFICON_INFO(vf, focus_id) = NULL;
2225 vficon_move_focus(vf, 0, 0, FALSE);
2230 void vficon_destroy_cb(GtkWidget *widget, gpointer data)
2232 ViewFile *vf = data;
2234 if (VFICON_INFO(vf, sync_idle_id) != -1) g_source_remove(VFICON_INFO(vf, sync_idle_id));
2238 vficon_thumb_cleanup(vf);
2240 iconlist_free(vf->list);
2241 g_list_free(VFICON_INFO(vf, selection));
2244 ViewFile *vficon_new(ViewFile *vf, const gchar *path)
2246 GtkListStore *store;
2247 GtkTreeSelection *selection;
2250 vf->info = g_new0(ViewFileInfoIcon, 1);
2252 VFICON_INFO(vf, selection) = NULL;
2253 VFICON_INFO(vf, prev_selection) = NULL;
2255 VFICON_INFO(vf, tip_window) = NULL;
2256 VFICON_INFO(vf, tip_delay_id) = -1;
2258 VFICON_INFO(vf, focus_row) = 0;
2259 VFICON_INFO(vf, focus_column) = 0;
2260 VFICON_INFO(vf, focus_id) = NULL;
2262 VFICON_INFO(vf, show_text) = options->show_icon_names;
2264 VFICON_INFO(vf, sync_idle_id) = -1;
2266 store = gtk_list_store_new(1, G_TYPE_POINTER);
2267 vf->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
2268 g_object_unref(store);
2270 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
2271 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_NONE);
2273 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vf->listview), FALSE);
2274 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vf->listview), FALSE);
2276 for (i = 0; i < VFICON_MAX_COLUMNS; i++)
2278 vficon_append_column(vf, i);
2281 /* zero width column to hide tree view focus, we draw it ourselves */
2282 vficon_append_column(vf, i);
2283 /* end column to fill white space */
2284 vficon_append_column(vf, i);
2286 g_signal_connect(G_OBJECT(vf->listview), "size_allocate",
2287 G_CALLBACK(vficon_sized_cb), vf);
2289 gtk_widget_set_events(vf->listview, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK |
2290 GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK);
2292 g_signal_connect(G_OBJECT(vf->listview),"motion_notify_event",
2293 G_CALLBACK(vficon_motion_cb), vf);
2294 g_signal_connect(G_OBJECT(vf->listview), "leave_notify_event",
2295 G_CALLBACK(vficon_leave_cb), vf);
2297 /* force VFICON_INFO(vf, columns) to be at least 1 (sane) - this will be corrected in the size_cb */
2298 vficon_populate_at_new_size(vf, 1, 1, FALSE);
2304 *-----------------------------------------------------------------------------
2305 * maintenance (for rename, move, remove)
2306 *-----------------------------------------------------------------------------
2309 static gint vficon_maint_find_closest(ViewFile *vf, gint row, gint count, GList *ignore_list)
2320 FileData *fd = work->data;
2321 gint f = vficon_index_by_fd(vf, fd);
2322 g_assert(fd->magick == 0x12345678);
2324 if (f >= 0) list = g_list_prepend(list, GINT_TO_POINTER(f));
2335 gpointer p = work->data;
2338 if (row == GPOINTER_TO_INT(p))
2343 if (rev == GPOINTER_TO_INT(p))
2348 if (!c) list = g_list_remove(list, p);
2358 if (row > count - 1)
2371 gint vficon_maint_renamed(ViewFile *vf, FileData *fd)
2377 IconData *id = vficon_icon_data(vf, fd);
2379 if (!id) return FALSE;
2381 row = vficon_index_by_id(vf, id);
2382 if (row < 0) return FALSE;
2384 source_base = remove_level_from_path(fd->change->source);
2385 dest_base = remove_level_from_path(fd->change->dest);
2387 if (strcmp(source_base, dest_base) == 0)
2389 vf->list = g_list_remove(vf->list, id);
2390 vf->list = iconlist_insert_sort(vf->list, id, vf->sort_method, vf->sort_ascend);
2392 vficon_sync_idle(vf);
2397 ret = vficon_maint_removed(vf, fd, NULL);
2400 g_free(source_base);
2406 gint vficon_maint_removed(ViewFile *vf, FileData *fd, GList *ignore_list)
2410 GtkTreeModel *store;
2412 IconData *id = vficon_icon_data(vf, fd);
2414 if (!id) return FALSE;
2416 row = g_list_index(vf->list, id);
2417 if (row < 0) return FALSE;
2419 if ((id->selected & SELECTION_SELECTED) &&
2420 layout_image_get_collection(vf->layout, NULL) == NULL)
2422 vficon_unselect(vf, id);
2424 if (!VFICON_INFO(vf, selection))
2428 n = vf_count(vf, NULL);
2431 new_row = vficon_maint_find_closest(vf, row, n, ignore_list);
2432 DEBUG_1("row = %d, closest is %d", row, new_row);
2446 else if (ignore_list)
2450 work = VFICON_INFO(vf, selection);
2453 IconData *ignore_id;
2454 FileData *ignore_fd;
2458 ignore_id = work->data;
2459 ignore_fd = ignore_id->fd;
2460 g_assert(ignore_fd->magick == 0x12345678);
2464 while (tmp && !match)
2466 FileData *ignore_list_fd = tmp->data;
2467 g_assert(ignore_list_fd->magick == 0x12345678);
2470 if (ignore_list_fd == ignore_fd)
2478 new_row = g_list_index(vf->list, ignore_id);
2485 /* selection all ignored, use closest */
2486 new_row = vficon_maint_find_closest(vf, row, vf_count(vf, NULL), ignore_list);
2491 new_row = g_list_index(vf->list, VFICON_INFO(vf, selection)->data);
2496 IconData *idn = g_list_nth_data(vf->list, new_row);
2498 vficon_select(vf, idn);
2499 vficon_send_layout_select(vf, idn);
2503 /* Thumb loader check */
2504 if (fd == vf->thumbs_filedata) vf->thumbs_filedata = NULL;
2505 if (vf->thumbs_count > 0) vf->thumbs_count--;
2507 if (VFICON_INFO(vf, prev_selection) == id) VFICON_INFO(vf, prev_selection) = NULL;
2508 if (VFICON_INFO(vf, click_id) == id) VFICON_INFO(vf, click_id) = NULL;
2510 /* remove pointer to this fd from grid */
2511 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
2513 gtk_tree_model_iter_nth_child(store, &iter, NULL, id->row))
2517 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1);
2518 list = g_list_find(list, id);
2519 if (list) list->data = NULL;
2522 vf->list = g_list_remove(vf->list, id);
2523 file_data_unref(fd);
2526 vficon_sync_idle(vf);
2532 gint vficon_maint_moved(ViewFile *vf, FileData *fd, GList *ignore_list)
2537 if (!fd->change->source || !vf->path) return FALSE;
2539 buf = remove_level_from_path(fd->change->source);
2541 if (strcmp(buf, vf->path) == 0)
2543 ret = vficon_maint_removed(vf, fd, ignore_list);