2 * Copyright (C) 2006 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "layout-image.h"
30 #include "fullscreen.h"
31 #include "history-list.h"
33 #include "image-overlay.h"
35 #include "layout-util.h"
39 #include "pixbuf-util.h"
40 #include "pixbuf-renderer.h"
41 #include "slideshow.h"
42 #include "ui-fileops.h"
44 #include "uri-utils.h"
46 #include "view-file.h"
48 #define FILE_COLUMN_POINTER 0
50 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw);
51 static void layout_image_set_buttons(LayoutWindow *lw);
52 static gboolean layout_image_animate_new_file(LayoutWindow *lw);
53 static void layout_image_animate_update_image(LayoutWindow *lw);
56 *----------------------------------------------------------------------------
58 *----------------------------------------------------------------------------
60 #pragma GCC diagnostic push
61 #pragma GCC diagnostic ignored "-Wunused-function"
62 static void layout_image_overlay_toggle_unused(LayoutWindow *lw)
65 image_osd_toggle(lw->image);
67 #pragma GCC diagnostic pop
70 *----------------------------------------------------------------------------
72 *----------------------------------------------------------------------------
75 static void layout_image_full_screen_stop_func(FullScreenData *fs, gpointer data)
77 auto lw = static_cast<LayoutWindow *>(data);
79 /* restore image window */
80 if (lw->image == fs->imd)
81 lw->image = fs->normal_imd;
83 lw->full_screen = nullptr;
86 void layout_image_full_screen_start(LayoutWindow *lw)
88 if (!layout_valid(&lw)) return;
90 if (lw->full_screen) return;
92 lw->full_screen = fullscreen_start(lw->window, lw->image,
93 layout_image_full_screen_stop_func, lw);
95 /* set to new image window */
96 if (lw->full_screen->same_region)
97 lw->image = lw->full_screen->imd;
99 layout_image_set_buttons(lw);
101 g_signal_connect(G_OBJECT(lw->full_screen->window), "key_press_event",
102 G_CALLBACK(layout_key_press_cb), lw);
104 layout_actions_add_window(lw, lw->full_screen->window);
106 image_osd_copy_status(lw->full_screen->normal_imd, lw->image);
107 layout_image_animate_update_image(lw);
109 /** @FIXME This is a hack to fix #1037 Fullscreen loads black
110 * The problem occurs when zoom is set to Original Size.
111 * An extra reload is required to force the image to be displayed.
112 * See also image-view.cc real_view_window_new()
113 * This is probably not the correct solution.
115 image_reload(lw->image);
118 void layout_image_full_screen_stop(LayoutWindow *lw)
120 if (!layout_valid(&lw)) return;
121 if (!lw->full_screen) return;
123 if (lw->image == lw->full_screen->imd)
124 image_osd_copy_status(lw->image, lw->full_screen->normal_imd);
126 fullscreen_stop(lw->full_screen);
128 layout_image_animate_update_image(lw);
131 void layout_image_full_screen_toggle(LayoutWindow *lw)
133 if (!layout_valid(&lw)) return;
136 layout_image_full_screen_stop(lw);
140 layout_image_full_screen_start(lw);
144 gboolean layout_image_full_screen_active(LayoutWindow *lw)
146 if (!layout_valid(&lw)) return FALSE;
148 return (lw->full_screen != nullptr);
152 *----------------------------------------------------------------------------
154 *----------------------------------------------------------------------------
157 static void layout_image_slideshow_next(LayoutWindow *lw)
159 if (lw->slideshow) slideshow_next(lw->slideshow);
162 static void layout_image_slideshow_prev(LayoutWindow *lw)
164 if (lw->slideshow) slideshow_prev(lw->slideshow);
167 static void layout_image_slideshow_stop_func(SlideShowData *, gpointer data)
169 auto lw = static_cast<LayoutWindow *>(data);
171 lw->slideshow = nullptr;
172 layout_status_update_info(lw, nullptr);
175 void layout_image_slideshow_start(LayoutWindow *lw)
180 if (!layout_valid(&lw)) return;
181 if (lw->slideshow) return;
183 cd = image_get_collection(lw->image, &info);
187 lw->slideshow = slideshow_start_from_collection(lw, nullptr, cd,
188 layout_image_slideshow_stop_func, lw, info);
192 lw->slideshow = slideshow_start(lw,
193 layout_list_get_index(lw, layout_image_get_fd(lw)),
194 layout_image_slideshow_stop_func, lw);
197 layout_status_update_info(lw, nullptr);
200 /* note that slideshow will take ownership of the list, do not free it */
201 void layout_image_slideshow_start_from_list(LayoutWindow *lw, GList *list)
203 if (!layout_valid(&lw)) return;
205 if (lw->slideshow || !list)
211 lw->slideshow = slideshow_start_from_filelist(lw, nullptr, list,
212 layout_image_slideshow_stop_func, lw);
214 layout_status_update_info(lw, nullptr);
217 void layout_image_slideshow_stop(LayoutWindow *lw)
219 if (!layout_valid(&lw)) return;
221 if (!lw->slideshow) return;
223 slideshow_free(lw->slideshow);
224 /* the stop_func sets lw->slideshow to NULL for us */
227 void layout_image_slideshow_toggle(LayoutWindow *lw)
229 if (!layout_valid(&lw)) return;
233 layout_image_slideshow_stop(lw);
237 layout_image_slideshow_start(lw);
241 gboolean layout_image_slideshow_active(LayoutWindow *lw)
243 if (!layout_valid(&lw)) return FALSE;
245 return (lw->slideshow != nullptr);
248 gboolean layout_image_slideshow_pause_toggle(LayoutWindow *lw)
252 if (!layout_valid(&lw)) return FALSE;
254 ret = slideshow_pause_toggle(lw->slideshow);
256 layout_status_update_info(lw, nullptr);
261 gboolean layout_image_slideshow_paused(LayoutWindow *lw)
263 if (!layout_valid(&lw)) return FALSE;
265 return (slideshow_paused(lw->slideshow));
268 static gboolean layout_image_slideshow_continue_check(LayoutWindow *lw)
270 if (!lw->slideshow) return FALSE;
272 if (!slideshow_should_continue(lw->slideshow))
274 layout_image_slideshow_stop(lw);
282 *----------------------------------------------------------------------------
284 *----------------------------------------------------------------------------
291 GdkPixbufAnimation *gpa;
292 GdkPixbufAnimationIter *iter;
297 GCancellable *cancellable;
299 GFileInputStream *gfstream;
302 static void image_animation_data_free(AnimationData *fd)
305 if(fd->iter) g_object_unref(fd->iter);
306 if(fd->gpa) g_object_unref(fd->gpa);
307 if(fd->cancellable) g_object_unref(fd->cancellable);
311 static gboolean animation_should_continue(AnimationData *fd)
319 static gboolean show_next_frame(gpointer data)
321 auto fd = static_cast<AnimationData*>(data);
325 if(animation_should_continue(fd)==FALSE)
327 image_animation_data_free(fd);
331 pr = reinterpret_cast<PixbufRenderer*>(fd->iw->pr);
333 if (gdk_pixbuf_animation_iter_advance(fd->iter,nullptr)==FALSE)
335 /* This indicates the animation is complete.
336 Return FALSE here to disable looping. */
339 fd->gpb = gdk_pixbuf_animation_iter_get_pixbuf(fd->iter);
340 image_change_pixbuf(fd->iw,fd->gpb,pr->zoom,FALSE);
342 if (fd->iw->func_update)
343 fd->iw->func_update(fd->iw, fd->iw->data_update);
345 delay = gdk_pixbuf_animation_iter_get_delay_time(fd->iter);
346 if (delay!=fd->delay)
348 if (delay>0) /* Current frame not static. */
351 g_timeout_add(delay,show_next_frame,fd);
355 image_animation_data_free(fd);
363 static gboolean layout_image_animate_check(LayoutWindow *lw)
365 if (!layout_valid(&lw)) return FALSE;
367 if(!lw->options.animate || lw->image->image_fd == nullptr || lw->image->image_fd->extension == nullptr || (g_ascii_strcasecmp(lw->image->image_fd->extension,".GIF")!=0 && g_ascii_strcasecmp(lw->image->image_fd->extension,".WEBP")!=0))
371 lw->animation->valid = FALSE;
372 if (lw->animation->cancellable)
374 g_cancellable_cancel(lw->animation->cancellable);
376 lw->animation = nullptr;
384 static void layout_image_animate_update_image(LayoutWindow *lw)
386 if (!layout_valid(&lw)) return;
388 if(lw->options.animate && lw->animation)
390 if (lw->full_screen && lw->image != lw->full_screen->imd)
391 lw->animation->iw = lw->full_screen->imd;
393 lw->animation->iw = lw->image;
398 static void animation_async_ready_cb(GObject *, GAsyncResult *res, gpointer data)
400 GError *error = nullptr;
401 auto animation = static_cast<AnimationData *>(data);
405 if (g_cancellable_is_cancelled(animation->cancellable))
407 gdk_pixbuf_animation_new_from_stream_finish(res, nullptr);
408 g_object_unref(animation->in_file);
409 g_object_unref(animation->gfstream);
410 image_animation_data_free(animation);
414 animation->gpa = gdk_pixbuf_animation_new_from_stream_finish(res, &error);
417 if (!gdk_pixbuf_animation_is_static_image(animation->gpa))
419 animation->iter = gdk_pixbuf_animation_get_iter(animation->gpa, nullptr);
422 animation->data_adr = animation->lw->image->image_fd;
423 animation->delay = gdk_pixbuf_animation_iter_get_delay_time(animation->iter);
424 animation->valid = TRUE;
426 layout_image_animate_update_image(animation->lw);
428 g_timeout_add(animation->delay, show_next_frame, animation);
434 log_printf("Error reading GIF file: %s\n", error->message);
437 g_object_unref(animation->in_file);
438 g_object_unref(animation->gfstream);
442 static gboolean layout_image_animate_new_file(LayoutWindow *lw)
444 GFileInputStream *gfstream;
445 GError *error = nullptr;
446 AnimationData *animation;
449 if(!layout_image_animate_check(lw)) return FALSE;
451 if(lw->animation) lw->animation->valid = FALSE;
455 g_cancellable_cancel(lw->animation->cancellable);
458 animation = g_new0(AnimationData, 1);
459 lw->animation = animation;
461 animation->cancellable = g_cancellable_new();
463 in_file = g_file_new_for_path(lw->image->image_fd->path);
464 animation->in_file = in_file;
465 gfstream = g_file_read(in_file, nullptr, &error);
468 animation->gfstream = gfstream;
469 gdk_pixbuf_animation_new_from_stream_async(reinterpret_cast<GInputStream*>(gfstream), animation->cancellable, animation_async_ready_cb, animation);
473 log_printf("Error reading animation file: %s\nError: %s\n", lw->image->image_fd->path, error->message);
479 void layout_image_animate_toggle(LayoutWindow *lw)
485 lw->options.animate = !lw->options.animate;
487 action = gtk_action_group_get_action(lw->action_group, "Animate");
488 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.animate);
490 layout_image_animate_new_file(lw);
494 *----------------------------------------------------------------------------
496 *----------------------------------------------------------------------------
499 static void li_pop_menu_zoom_in_cb(GtkWidget *, gpointer data)
501 auto lw = static_cast<LayoutWindow *>(data);
503 layout_image_zoom_adjust(lw, get_zoom_increment(), FALSE);
506 static void li_pop_menu_zoom_out_cb(GtkWidget *, gpointer data)
508 auto lw = static_cast<LayoutWindow *>(data);
509 layout_image_zoom_adjust(lw, -get_zoom_increment(), FALSE);
512 static void li_pop_menu_zoom_1_1_cb(GtkWidget *, gpointer data)
514 auto lw = static_cast<LayoutWindow *>(data);
516 layout_image_zoom_set(lw, 1.0, FALSE);
519 static void li_pop_menu_zoom_fit_cb(GtkWidget *, gpointer data)
521 auto lw = static_cast<LayoutWindow *>(data);
523 layout_image_zoom_set(lw, 0.0, FALSE);
526 static void li_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
529 auto key = static_cast<const gchar *>(data);
531 lw = static_cast<LayoutWindow *>(submenu_item_get_data(widget));
533 if (!editor_window_flag_set(key))
535 layout_image_full_screen_stop(lw);
537 file_util_start_editor_from_file(key, layout_image_get_fd(lw), lw->window);
540 static void li_pop_menu_alter_cb(GtkWidget *widget, gpointer data)
542 auto lw = static_cast<LayoutWindow *>(data);
545 lw = static_cast<LayoutWindow *>(submenu_item_get_data(widget));
546 type = static_cast<AlterType>GPOINTER_TO_INT(data);
548 image_alter_orientation(lw->image, lw->image->image_fd, type);
551 static void li_pop_menu_new_cb(GtkWidget *, gpointer data)
553 auto lw = static_cast<LayoutWindow *>(data);
555 view_window_new(layout_image_get_fd(lw));
558 static GtkWidget *li_pop_menu_click_parent(GtkWidget *widget, LayoutWindow *lw)
563 menu = gtk_widget_get_toplevel(widget);
564 if (!menu) return nullptr;
566 parent = static_cast<GtkWidget *>(g_object_get_data(G_OBJECT(menu), "click_parent"));
568 if (!parent && lw->full_screen)
570 parent = lw->full_screen->imd->widget;
576 static void li_pop_menu_copy_cb(GtkWidget *widget, gpointer data)
578 auto lw = static_cast<LayoutWindow *>(data);
580 file_util_copy(layout_image_get_fd(lw), nullptr, nullptr,
581 li_pop_menu_click_parent(widget, lw));
584 static void li_pop_menu_copy_path_cb(GtkWidget *, gpointer data)
586 auto lw = static_cast<LayoutWindow *>(data);
588 file_util_copy_path_to_clipboard(layout_image_get_fd(lw), TRUE);
591 static void li_pop_menu_copy_path_unquoted_cb(GtkWidget *, gpointer data)
593 auto lw = static_cast<LayoutWindow *>(data);
595 file_util_copy_path_to_clipboard(layout_image_get_fd(lw), FALSE);
598 static void li_pop_menu_copy_image_cb(GtkWidget *, gpointer data)
600 auto lw = static_cast<LayoutWindow *>(data);
601 ImageWindow *imd = lw->image;
604 pixbuf = image_get_pixbuf(imd);
606 gtk_clipboard_set_image(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), pixbuf);
609 static void li_pop_menu_move_cb(GtkWidget *widget, gpointer data)
611 auto lw = static_cast<LayoutWindow *>(data);
613 file_util_move(layout_image_get_fd(lw), nullptr, nullptr,
614 li_pop_menu_click_parent(widget, lw));
617 static void li_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
619 auto lw = static_cast<LayoutWindow *>(data);
621 file_util_rename(layout_image_get_fd(lw), nullptr,
622 li_pop_menu_click_parent(widget, lw));
625 static void li_pop_menu_delete_cb(GtkWidget *widget, gpointer data)
627 auto lw = static_cast<LayoutWindow *>(data);
629 options->file_ops.safe_delete_enable = FALSE;
630 file_util_delete(layout_image_get_fd(lw), nullptr,
631 li_pop_menu_click_parent(widget, lw));
634 static void li_pop_menu_move_to_trash_cb(GtkWidget *widget, gpointer data)
636 auto lw = static_cast<LayoutWindow *>(data);
638 options->file_ops.safe_delete_enable = TRUE;
639 file_util_delete(layout_image_get_fd(lw), nullptr,
640 li_pop_menu_click_parent(widget, lw));
643 static void li_pop_menu_slide_start_cb(GtkWidget *, gpointer data)
645 auto lw = static_cast<LayoutWindow *>(data);
647 layout_image_slideshow_start(lw);
650 static void li_pop_menu_slide_stop_cb(GtkWidget *, gpointer data)
652 auto lw = static_cast<LayoutWindow *>(data);
654 layout_image_slideshow_stop(lw);
657 static void li_pop_menu_slide_pause_cb(GtkWidget *, gpointer data)
659 auto lw = static_cast<LayoutWindow *>(data);
661 layout_image_slideshow_pause_toggle(lw);
664 static void li_pop_menu_full_screen_cb(GtkWidget *, gpointer data)
666 auto lw = static_cast<LayoutWindow *>(data);
668 layout_image_full_screen_toggle(lw);
671 static void li_pop_menu_animate_cb(GtkWidget *, gpointer data)
673 auto lw = static_cast<LayoutWindow *>(data);
675 layout_image_animate_toggle(lw);
678 static void li_pop_menu_hide_cb(GtkWidget *, gpointer data)
680 auto lw = static_cast<LayoutWindow *>(data);
682 layout_tools_hide_toggle(lw);
685 static void li_set_layout_path_cb(GtkWidget *, gpointer data)
687 auto lw = static_cast<LayoutWindow *>(data);
690 if (!layout_valid(&lw)) return;
692 fd = layout_image_get_fd(lw);
693 if (fd) layout_set_fd(lw, fd);
696 static void li_open_archive_cb(GtkWidget *, gpointer data)
698 auto lw = static_cast<LayoutWindow *>(data);
699 LayoutWindow *lw_new;
702 if (!layout_valid(&lw)) return;
704 dest_dir = open_archive(layout_image_get_fd(lw));
707 lw_new = layout_new_from_default();
708 layout_set_path(lw_new, dest_dir);
713 warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GQ_ICON_DIALOG_WARNING, nullptr);
717 static gboolean li_check_if_current_path(LayoutWindow *lw, const gchar *path)
722 if (!path || !layout_valid(&lw) || !lw->dir_fd) return FALSE;
724 dirname = g_path_get_dirname(path);
725 ret = (strcmp(lw->dir_fd->path, dirname) == 0);
730 static void layout_image_popup_menu_destroy_cb(GtkWidget *, gpointer data)
732 auto editmenu_fd_list = static_cast<GList *>(data);
734 filelist_free(editmenu_fd_list);
737 static GList *layout_image_get_fd_list(LayoutWindow *lw)
739 GList *list = nullptr;
740 FileData *fd = layout_image_get_fd(lw);
745 /* optionally include sidecars if the filelist entry is not expanded */
746 list = vf_selection_get_one(lw->vf, fd);
748 list = g_list_append(nullptr, file_data_ref(fd));
755 * @brief Add file selection list to a collection
757 * @param[in] data Index to the collection list menu item selected, or -1 for new collection
761 static void layout_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
764 GList *selection_list = nullptr;
766 lw = static_cast<LayoutWindow *>(submenu_item_get_data(widget));
767 selection_list = g_list_append(selection_list, layout_image_get_fd(lw));
768 pop_menu_collections(selection_list, data);
770 filelist_free(selection_list);
773 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
780 GList *editmenu_fd_list;
781 GtkAccelGroup *accel_group;
783 path = layout_image_get_path(lw);
784 fullscreen = layout_image_full_screen_active(lw);
786 menu = popup_menu_short_lived();
788 accel_group = gtk_accel_group_new();
789 gtk_menu_set_accel_group(GTK_MENU(menu), accel_group);
791 g_object_set_data(G_OBJECT(menu), "window_keys", nullptr);
792 g_object_set_data(G_OBJECT(menu), "accel_group", accel_group);
794 menu_item_add_icon(menu, _("Zoom _in"), GQ_ICON_ZOOM_IN, G_CALLBACK(li_pop_menu_zoom_in_cb), lw);
795 menu_item_add_icon(menu, _("Zoom _out"), GQ_ICON_ZOOM_OUT, G_CALLBACK(li_pop_menu_zoom_out_cb), lw);
796 menu_item_add_icon(menu, _("Zoom _1:1"), GQ_ICON_ZOOM_100, G_CALLBACK(li_pop_menu_zoom_1_1_cb), lw);
797 menu_item_add_icon(menu, _("Zoom to fit"), GQ_ICON_ZOOM_FIT, G_CALLBACK(li_pop_menu_zoom_fit_cb), lw);
798 menu_item_add_divider(menu);
800 editmenu_fd_list = layout_image_get_fd_list(lw);
801 g_signal_connect(G_OBJECT(menu), "destroy",
802 G_CALLBACK(layout_image_popup_menu_destroy_cb), editmenu_fd_list);
803 submenu = submenu_add_edit(menu, &item, G_CALLBACK(li_pop_menu_edit_cb), lw, editmenu_fd_list);
804 if (!path) gtk_widget_set_sensitive(item, FALSE);
805 menu_item_add_divider(submenu);
806 item = submenu_add_alter(menu, G_CALLBACK(li_pop_menu_alter_cb), lw);
808 item = menu_item_add_icon(menu, _("View in _new window"), GQ_ICON_NEW, G_CALLBACK(li_pop_menu_new_cb), lw);
809 if (!path || fullscreen) gtk_widget_set_sensitive(item, FALSE);
811 item = menu_item_add(menu, _("_Go to directory view"), G_CALLBACK(li_set_layout_path_cb), lw);
812 if (!path || li_check_if_current_path(lw, path)) gtk_widget_set_sensitive(item, FALSE);
814 item = menu_item_add_icon(menu, _("Open archive"), GQ_ICON_OPEN, G_CALLBACK(li_open_archive_cb), lw);
815 if (!path || lw->image->image_fd->format_class != FORMAT_CLASS_ARCHIVE)
817 gtk_widget_set_sensitive(item, FALSE);
820 menu_item_add_divider(menu);
822 item = menu_item_add_icon(menu, _("_Copy..."), GQ_ICON_COPY, G_CALLBACK(li_pop_menu_copy_cb), lw);
823 if (!path) gtk_widget_set_sensitive(item, FALSE);
824 item = menu_item_add(menu, _("_Move..."), G_CALLBACK(li_pop_menu_move_cb), lw);
825 if (!path) gtk_widget_set_sensitive(item, FALSE);
826 item = menu_item_add(menu, _("_Rename..."), G_CALLBACK(li_pop_menu_rename_cb), lw);
827 if (!path) gtk_widget_set_sensitive(item, FALSE);
828 item = menu_item_add(menu, _("_Copy path to clipboard"), G_CALLBACK(li_pop_menu_copy_path_cb), lw);
829 item = menu_item_add(menu, _("_Copy path unquoted to clipboard"), G_CALLBACK(li_pop_menu_copy_path_unquoted_cb), lw);
830 item = menu_item_add(menu, _("Copy _image to clipboard"), G_CALLBACK(li_pop_menu_copy_image_cb), lw);
831 if (!path) gtk_widget_set_sensitive(item, FALSE);
832 menu_item_add_divider(menu);
834 item = menu_item_add_icon(menu,
835 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
836 _("Move to Trash"), GQ_ICON_DELETE,
837 G_CALLBACK(li_pop_menu_move_to_trash_cb), lw);
838 if (!path) gtk_widget_set_sensitive(item, FALSE);
839 item = menu_item_add_icon(menu,
840 options->file_ops.confirm_delete ? _("_Delete...") :
841 _("_Delete"), GQ_ICON_DELETE_SHRED,
842 G_CALLBACK(li_pop_menu_delete_cb), lw);
843 if (!path) gtk_widget_set_sensitive(item, FALSE);
844 menu_item_add_divider(menu);
846 submenu = submenu_add_collections(menu, &item,
847 G_CALLBACK(layout_pop_menu_collections_cb), lw);
848 gtk_widget_set_sensitive(item, TRUE);
849 menu_item_add_divider(menu);
851 if (layout_image_slideshow_active(lw))
853 menu_item_add(menu, _("Toggle _slideshow"), G_CALLBACK(li_pop_menu_slide_stop_cb), lw);
854 if (layout_image_slideshow_paused(lw))
856 item = menu_item_add(menu, _("Continue slides_how"),
857 G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
861 item = menu_item_add(menu, _("Pause slides_how"),
862 G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
867 menu_item_add(menu, _("Toggle _slideshow"), G_CALLBACK(li_pop_menu_slide_start_cb), lw);
868 item = menu_item_add(menu, _("Pause slides_how"), G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
869 gtk_widget_set_sensitive(item, FALSE);
874 menu_item_add_icon(menu, _("_Full screen"), GQ_ICON_FULLSCREEN, G_CALLBACK(li_pop_menu_full_screen_cb), lw);
878 menu_item_add_icon(menu, _("Exit _full screen"), GQ_ICON_LEAVE_FULLSCREEN, G_CALLBACK(li_pop_menu_full_screen_cb), lw);
881 menu_item_add_check(menu, _("GIF _animation"), lw->options.animate, G_CALLBACK(li_pop_menu_animate_cb), lw);
883 menu_item_add_divider(menu);
885 item = menu_item_add_check(menu, _("Hide file _list"), lw->options.tools_hidden,
886 G_CALLBACK(li_pop_menu_hide_cb), lw);
887 if (fullscreen) gtk_widget_set_sensitive(item, FALSE);
892 void layout_image_menu_popup(LayoutWindow *lw)
896 menu = layout_image_pop_menu(lw);
897 gtk_menu_popup_at_widget(GTK_MENU(menu), lw->image->widget, GDK_GRAVITY_EAST, GDK_GRAVITY_CENTER, nullptr);
901 *----------------------------------------------------------------------------
903 *----------------------------------------------------------------------------
906 static void layout_image_dnd_receive(GtkWidget *widget, GdkDragContext *,
908 GtkSelectionData *selection_data, guint info,
909 guint, gpointer data)
911 auto lw = static_cast<LayoutWindow *>(data);
916 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
918 if (lw->split_images[i] && lw->split_images[i]->pr == widget)
921 if (i < MAX_SPLIT_IMAGES)
923 DEBUG_1("dnd image activate %d", i);
924 layout_image_activate(lw, i, FALSE);
927 if (info == TARGET_TEXT_PLAIN)
929 url = g_strdup(reinterpret_cast<const gchar *>(gtk_selection_data_get_data(selection_data)));
930 download_web_file(url, FALSE, lw);
933 else if (info == TARGET_URI_LIST || info == TARGET_APP_COLLECTION_MEMBER)
935 CollectionData *source;
939 if (info == TARGET_URI_LIST)
941 list = uri_filelist_from_gtk_selection_data(selection_data);
947 source = collection_from_dnd_data(reinterpret_cast<const gchar *>(gtk_selection_data_get_data(selection_data)), &list, &info_list);
952 auto fd = static_cast<FileData *>(list->data);
954 if (isfile(fd->path))
960 base = remove_level_from_path(fd->path);
961 dir_fd = file_data_new_dir(base);
962 if (dir_fd != lw->dir_fd)
964 layout_set_fd(lw, dir_fd);
966 file_data_unref(dir_fd);
969 row = layout_list_get_index(lw, fd);
970 if (source && info_list)
972 layout_image_set_collection(lw, source, static_cast<CollectInfo *>(info_list->data));
976 layout_image_set_fd(lw, fd);
980 layout_image_set_index(lw, row);
983 else if (isdir(fd->path))
985 layout_set_fd(lw, fd);
986 layout_image_set_fd(lw, nullptr);
991 g_list_free(info_list);
995 static void layout_image_dnd_get(GtkWidget *widget, GdkDragContext *,
996 GtkSelectionData *selection_data, guint,
997 guint, gpointer data)
999 auto lw = static_cast<LayoutWindow *>(data);
1004 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1006 if (lw->split_images[i] && lw->split_images[i]->pr == widget)
1009 if (i < MAX_SPLIT_IMAGES)
1011 DEBUG_1("dnd get from %d", i);
1012 fd = image_get_fd(lw->split_images[i]);
1015 fd = layout_image_get_fd(lw);
1021 list = g_list_append(nullptr, fd);
1022 uri_selection_data_set_uris_from_filelist(selection_data, list);
1027 gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
1032 static void layout_image_dnd_end(GtkWidget *, GdkDragContext *context, gpointer data)
1034 auto lw = static_cast<LayoutWindow *>(data);
1035 if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
1040 fd = layout_image_get_fd(lw);
1041 row = layout_list_get_index(lw, fd);
1042 if (row < 0) return;
1044 if (!isfile(fd->path))
1046 if (static_cast<guint>(row) < layout_list_count(lw, nullptr) - 1)
1048 layout_image_next(lw);
1052 layout_image_prev(lw);
1059 static void layout_image_dnd_init(LayoutWindow *lw, gint i)
1061 ImageWindow *imd = lw->split_images[i];
1063 gtk_drag_source_set(imd->pr, GDK_BUTTON2_MASK,
1064 dnd_file_drag_types, dnd_file_drag_types_count,
1065 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
1066 g_signal_connect(G_OBJECT(imd->pr), "drag_data_get",
1067 G_CALLBACK(layout_image_dnd_get), lw);
1068 g_signal_connect(G_OBJECT(imd->pr), "drag_end",
1069 G_CALLBACK(layout_image_dnd_end), lw);
1071 gtk_drag_dest_set(imd->pr,
1072 static_cast<GtkDestDefaults>(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP),
1073 dnd_file_drop_types, dnd_file_drop_types_count,
1074 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
1075 g_signal_connect(G_OBJECT(imd->pr), "drag_data_received",
1076 G_CALLBACK(layout_image_dnd_receive), lw);
1081 *----------------------------------------------------------------------------
1083 *----------------------------------------------------------------------------
1086 void layout_image_to_root(LayoutWindow *lw)
1088 image_to_root_window(lw->image, (image_zoom_get(lw->image) == 0));
1092 *----------------------------------------------------------------------------
1093 * manipulation + accessors
1094 *----------------------------------------------------------------------------
1097 void layout_image_scroll(LayoutWindow *lw, gint x, gint y, gboolean connect_scroll)
1100 if (!layout_valid(&lw)) return;
1102 image_scroll(lw->image, x, y);
1104 if (lw->full_screen && lw->image != lw->full_screen->imd)
1106 image_scroll(lw->full_screen->imd, x, y);
1109 if (!connect_scroll) return;
1111 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1113 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1115 image_scroll(lw->split_images[i], x, y);
1121 void layout_image_zoom_adjust(LayoutWindow *lw, gdouble increment, gboolean connect_zoom)
1124 if (!layout_valid(&lw)) return;
1126 image_zoom_adjust(lw->image, increment);
1128 if (lw->full_screen && lw->image != lw->full_screen->imd)
1130 image_zoom_adjust(lw->full_screen->imd, increment);
1133 if (!connect_zoom) return;
1135 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1137 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1138 image_zoom_adjust(lw->split_images[i], increment); ;
1142 void layout_image_zoom_adjust_at_point(LayoutWindow *lw, gdouble increment, gint x, gint y, gboolean connect_zoom)
1145 if (!layout_valid(&lw)) return;
1147 image_zoom_adjust_at_point(lw->image, increment, x, y);
1149 if (lw->full_screen && lw->image != lw->full_screen->imd)
1151 image_zoom_adjust_at_point(lw->full_screen->imd, increment, x, y);
1153 if (!connect_zoom && !lw->split_mode) return;
1155 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1157 if (lw->split_images[i] && lw->split_images[i] != lw->image &&
1158 lw->split_images[i]->mouse_wheel_mode)
1159 image_zoom_adjust_at_point(lw->split_images[i], increment, x, y);
1163 void layout_image_zoom_set(LayoutWindow *lw, gdouble zoom, gboolean connect_zoom)
1166 if (!layout_valid(&lw)) return;
1168 image_zoom_set(lw->image, zoom);
1170 if (lw->full_screen && lw->image != lw->full_screen->imd)
1172 image_zoom_set(lw->full_screen->imd, zoom);
1175 if (!connect_zoom) return;
1177 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1179 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1180 image_zoom_set(lw->split_images[i], zoom);
1184 void layout_image_zoom_set_fill_geometry(LayoutWindow *lw, gboolean vertical, gboolean connect_zoom)
1187 if (!layout_valid(&lw)) return;
1189 image_zoom_set_fill_geometry(lw->image, vertical);
1191 if (lw->full_screen && lw->image != lw->full_screen->imd)
1193 image_zoom_set_fill_geometry(lw->full_screen->imd, vertical);
1196 if (!connect_zoom) return;
1198 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1200 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1201 image_zoom_set_fill_geometry(lw->split_images[i], vertical);
1205 void layout_image_alter_orientation(LayoutWindow *lw, AlterType type)
1207 if (!layout_valid(&lw)) return;
1209 GtkTreeModel *store;
1211 GtkTreeSelection *selection;
1216 if (!lw || !lw->vf) return;
1218 if (lw->vf->type == FILEVIEW_ICON)
1220 if (!VFICON(lw->vf)->selection) return;
1221 work = VFICON(lw->vf)->selection;
1225 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
1226 work = gtk_tree_selection_get_selected_rows(selection, &store);
1231 if (lw->vf->type == FILEVIEW_ICON)
1233 fd_n = static_cast<FileData *>(work->data);
1238 tpath = static_cast<GtkTreePath *>(work->data);
1239 gtk_tree_model_get_iter(store, &iter, tpath);
1240 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
1244 image_alter_orientation(lw->image, fd_n, type);
1248 static void image_alter_rating(FileData *fd_n, const gchar *rating)
1250 metadata_write_string(fd_n, RATING_KEY, rating);
1251 read_rating_data(fd_n);
1254 void layout_image_rating(LayoutWindow *lw, const gchar *rating)
1256 if (!layout_valid(&lw)) return;
1258 GtkTreeModel *store;
1260 GtkTreeSelection *selection;
1265 if (!lw || !lw->vf) return;
1267 if (lw->vf->type == FILEVIEW_ICON)
1269 if (!VFICON(lw->vf)->selection) return;
1270 work = VFICON(lw->vf)->selection;
1274 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
1275 work = gtk_tree_selection_get_selected_rows(selection, &store);
1280 if (lw->vf->type == FILEVIEW_ICON)
1282 fd_n = static_cast<FileData *>(work->data);
1287 tpath = static_cast<GtkTreePath *>(work->data);
1288 gtk_tree_model_get_iter(store, &iter, tpath);
1289 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
1293 image_alter_rating(fd_n, rating);
1297 void layout_image_reset_orientation(LayoutWindow *lw)
1299 ImageWindow *imd= lw->image;
1301 if (!layout_valid(&lw)) return;
1302 if (!imd || !imd->pr || !imd->image_fd) return;
1304 if (imd->orientation < 1 || imd->orientation > 8) imd->orientation = 1;
1306 if (options->image.exif_rotate_enable)
1308 if (g_strcmp0(imd->image_fd->format_name, "heif") != 0)
1310 imd->orientation = metadata_read_int(imd->image_fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
1314 imd->orientation = EXIF_ORIENTATION_TOP_LEFT;
1319 imd->orientation = 1;
1322 if (imd->image_fd->user_orientation != 0)
1324 imd->orientation = imd->image_fd->user_orientation;
1327 pixbuf_renderer_set_orientation(reinterpret_cast<PixbufRenderer *>(imd->pr), imd->orientation);
1330 void layout_image_set_desaturate(LayoutWindow *lw, gboolean desaturate)
1332 if (!layout_valid(&lw)) return;
1334 image_set_desaturate(lw->image, desaturate);
1337 gboolean layout_image_get_desaturate(LayoutWindow *lw)
1339 if (!layout_valid(&lw)) return FALSE;
1341 return image_get_desaturate(lw->image);
1344 void layout_image_set_overunderexposed(LayoutWindow *lw, gboolean overunderexposed)
1346 if (!layout_valid(&lw)) return;
1348 image_set_overunderexposed(lw->image, overunderexposed);
1351 #pragma GCC diagnostic push
1352 #pragma GCC diagnostic ignored "-Wunused-function"
1353 gboolean layout_image_get_overunderexposed_unused(LayoutWindow *lw)
1355 if (!layout_valid(&lw)) return FALSE;
1357 // return image_get_overunderexposed(lw->image);
1360 #pragma GCC diagnostic pop
1362 void layout_image_set_ignore_alpha(LayoutWindow *lw, gboolean ignore_alpha)
1364 if (!layout_valid(&lw)) return;
1366 lw->options.ignore_alpha = ignore_alpha;
1367 image_set_ignore_alpha(lw->image, ignore_alpha);
1371 #pragma GCC diagnostic push
1372 #pragma GCC diagnostic ignored "-Wunused-function"
1373 gint layout_image_stereo_get_unused(LayoutWindow *lw)
1375 if (!layout_valid(&lw)) return 0;
1377 // return image_stereo_get(lw->image);
1381 void layout_image_stereo_set_unused(LayoutWindow *lw, gint stereo_mode)
1383 if (!layout_valid(&lw)) return;
1385 image_stereo_set(lw->image, stereo_mode);
1387 void layout_image_stereo_swap_unused(LayoutWindow *lw)
1389 if (!layout_valid(&lw)) return;
1391 // image_stereo_swap(lw->image);
1393 #pragma GCC diagnostic pop
1395 gint layout_image_stereo_pixbuf_get(LayoutWindow *lw)
1397 if (!layout_valid(&lw)) return 0;
1399 return image_stereo_pixbuf_get(lw->image);
1402 void layout_image_stereo_pixbuf_set(LayoutWindow *lw, gint stereo_mode)
1404 if (!layout_valid(&lw)) return;
1406 image_stereo_pixbuf_set(lw->image, static_cast<StereoPixbufData>(stereo_mode));
1409 const gchar *layout_image_get_path(LayoutWindow *lw)
1411 if (!layout_valid(&lw)) return nullptr;
1413 return image_get_path(lw->image);
1416 #pragma GCC diagnostic push
1417 #pragma GCC diagnostic ignored "-Wunused-function"
1418 const gchar *layout_image_get_name_unused(LayoutWindow *lw)
1420 if (!layout_valid(&lw)) return NULL;
1422 return image_get_name(lw->image);
1424 #pragma GCC diagnostic pop
1426 FileData *layout_image_get_fd(LayoutWindow *lw)
1428 if (!layout_valid(&lw)) return nullptr;
1430 return image_get_fd(lw->image);
1433 CollectionData *layout_image_get_collection(LayoutWindow *lw, CollectInfo **info)
1435 if (!layout_valid(&lw)) return nullptr;
1437 return image_get_collection(lw->image, info);
1440 gint layout_image_get_index(LayoutWindow *lw)
1442 return layout_list_get_index(lw, image_get_fd(lw->image));
1446 *----------------------------------------------------------------------------
1448 *----------------------------------------------------------------------------
1451 void layout_image_set_fd(LayoutWindow *lw, FileData *fd)
1453 if (!layout_valid(&lw)) return;
1455 image_change_fd(lw->image, fd, image_zoom_get_default(lw->image));
1457 if (lw->full_screen && lw->image != lw->full_screen->imd)
1459 image_change_fd(lw->full_screen->imd, fd, image_zoom_get_default(lw->full_screen->imd));
1463 layout_list_sync_fd(lw, fd);
1464 layout_image_slideshow_continue_check(lw);
1465 layout_bars_new_image(lw);
1466 layout_image_animate_new_file(lw);
1470 image_chain_append_end(fd->path);
1474 void layout_image_set_with_ahead(LayoutWindow *lw, FileData *fd, FileData *read_ahead_fd)
1476 if (!layout_valid(&lw)) return;
1478 /** @FIXME This should be handled at the caller: in vflist_select_image
1481 const gchar *old_path;
1483 old_path = layout_image_get_path(lw);
1484 if (old_path && strcmp(path, old_path) == 0) return;
1487 layout_image_set_fd(lw, fd);
1488 if (options->image.enable_read_ahead) image_prebuffer_set(lw->image, read_ahead_fd);
1491 void layout_image_set_index(LayoutWindow *lw, gint index)
1494 FileData *read_ahead_fd;
1497 if (!layout_valid(&lw)) return;
1499 old = layout_list_get_index(lw, layout_image_get_fd(lw));
1500 fd = layout_list_get_fd(lw, index);
1504 read_ahead_fd = layout_list_get_fd(lw, index - 1);
1508 read_ahead_fd = layout_list_get_fd(lw, index + 1);
1511 if (layout_selection_count(lw, nullptr) > 1)
1513 GList *x = layout_selection_list_by_index(lw);
1517 for (last = y = x; y; y = y->next)
1519 for (y = x; y && (GPOINTER_TO_INT(y->data)) != index; y = y->next)
1526 if ((index > old && (index != GPOINTER_TO_INT(last->data) || old != GPOINTER_TO_INT(x->data)))
1527 || (old == GPOINTER_TO_INT(last->data) && index == GPOINTER_TO_INT(x->data)))
1530 newindex = GPOINTER_TO_INT(y->next->data);
1532 newindex = GPOINTER_TO_INT(x->data);
1537 newindex = GPOINTER_TO_INT(y->prev->data);
1539 newindex = GPOINTER_TO_INT(last->data);
1542 read_ahead_fd = layout_list_get_fd(lw, newindex);
1546 x = g_list_remove(x, x->data);
1549 layout_image_set_with_ahead(lw, fd, read_ahead_fd);
1552 static void layout_image_set_collection_real(LayoutWindow *lw, CollectionData *cd, CollectInfo *info, gboolean forward)
1554 if (!layout_valid(&lw)) return;
1556 image_change_from_collection(lw->image, cd, info, image_zoom_get_default(lw->image));
1557 if (options->image.enable_read_ahead)
1559 CollectInfo *r_info;
1562 r_info = collection_next_by_info(cd, info);
1563 if (!r_info) r_info = collection_prev_by_info(cd, info);
1567 r_info = collection_prev_by_info(cd, info);
1568 if (!r_info) r_info = collection_next_by_info(cd, info);
1570 if (r_info) image_prebuffer_set(lw->image, r_info->fd);
1573 layout_image_slideshow_continue_check(lw);
1574 layout_bars_new_image(lw);
1577 void layout_image_set_collection(LayoutWindow *lw, CollectionData *cd, CollectInfo *info)
1579 layout_image_set_collection_real(lw, cd, info, TRUE);
1580 layout_list_sync_fd(lw, layout_image_get_fd(lw));
1583 void layout_image_refresh(LayoutWindow *lw)
1585 if (!layout_valid(&lw)) return;
1587 image_reload(lw->image);
1590 void layout_image_color_profile_set(LayoutWindow *lw,
1594 if (!layout_valid(&lw)) return;
1596 image_color_profile_set(lw->image, input_type, use_image);
1599 gboolean layout_image_color_profile_get(LayoutWindow *lw,
1601 gboolean *use_image)
1603 if (!layout_valid(&lw)) return FALSE;
1605 return image_color_profile_get(lw->image, input_type, use_image);
1608 void layout_image_color_profile_set_use(LayoutWindow *lw, gboolean enable)
1610 if (!layout_valid(&lw)) return;
1612 image_color_profile_set_use(lw->image, enable);
1615 gboolean layout_image_color_profile_get_use(LayoutWindow *lw)
1617 if (!layout_valid(&lw)) return FALSE;
1619 return image_color_profile_get_use(lw->image);
1622 gboolean layout_image_color_profile_get_status(LayoutWindow *lw, gchar **image_profile, gchar **screen_profile)
1624 if (!layout_valid(&lw)) return FALSE;
1626 return image_color_profile_get_status(lw->image, image_profile, screen_profile);
1630 *----------------------------------------------------------------------------
1632 *----------------------------------------------------------------------------
1635 void layout_image_next(LayoutWindow *lw)
1641 if (!layout_valid(&lw)) return;
1643 if (layout_image_slideshow_active(lw))
1645 layout_image_slideshow_next(lw);
1649 if (layout_selection_count(lw, nullptr) > 1)
1651 GList *x = layout_selection_list_by_index(lw);
1652 gint old = layout_list_get_index(lw, layout_image_get_fd(lw));
1655 for (y = x; y && (GPOINTER_TO_INT(y->data)) != old; y = y->next)
1660 layout_image_set_index(lw, GPOINTER_TO_INT(y->next->data));
1663 if (options->circular_selection_lists)
1665 layout_image_set_index(lw, GPOINTER_TO_INT(x->data));
1670 x = g_list_remove(x, x->data);
1671 if (y) /* not dereferenced */
1675 cd = image_get_collection(lw->image, &info);
1679 info = collection_next_by_info(cd, info);
1682 layout_image_set_collection_real(lw, cd, info, TRUE);
1686 image_osd_icon(lw->image, IMAGE_OSD_LAST, -1);
1691 current = layout_image_get_index(lw);
1695 if (static_cast<guint>(current) < layout_list_count(lw, nullptr) - 1)
1697 layout_image_set_index(lw, current + 1);
1701 image_osd_icon(lw->image, IMAGE_OSD_LAST, -1);
1706 layout_image_set_index(lw, 0);
1710 void layout_image_prev(LayoutWindow *lw)
1716 if (!layout_valid(&lw)) return;
1718 if (layout_image_slideshow_active(lw))
1720 layout_image_slideshow_prev(lw);
1724 if (layout_selection_count(lw, nullptr) > 1)
1726 GList *x = layout_selection_list_by_index(lw);
1727 gint old = layout_list_get_index(lw, layout_image_get_fd(lw));
1731 for (last = y = x; y; y = y->next)
1733 for (y = x; y && (GPOINTER_TO_INT(y->data)) != old; y = y->next)
1738 layout_image_set_index(lw, GPOINTER_TO_INT(y->prev->data));
1741 if (options->circular_selection_lists)
1743 layout_image_set_index(lw, GPOINTER_TO_INT(last->data));
1748 x = g_list_remove(x, x->data);
1749 if (y) /* not dereferenced */
1753 cd = image_get_collection(lw->image, &info);
1757 info = collection_prev_by_info(cd, info);
1760 layout_image_set_collection_real(lw, cd, info, FALSE);
1764 image_osd_icon(lw->image, IMAGE_OSD_FIRST, -1);
1769 current = layout_image_get_index(lw);
1775 layout_image_set_index(lw, current - 1);
1779 image_osd_icon(lw->image, IMAGE_OSD_FIRST, -1);
1784 layout_image_set_index(lw, layout_list_count(lw, nullptr) - 1);
1788 void layout_image_first(LayoutWindow *lw)
1794 if (!layout_valid(&lw)) return;
1796 cd = image_get_collection(lw->image, &info);
1800 CollectInfo *first_collection;
1801 first_collection = collection_get_first(cd);
1802 if (first_collection != info)
1804 layout_image_set_collection_real(lw, cd, first_collection, TRUE);
1809 current = layout_image_get_index(lw);
1810 if (current != 0 && layout_list_count(lw, nullptr) > 0)
1812 layout_image_set_index(lw, 0);
1816 void layout_image_last(LayoutWindow *lw)
1823 if (!layout_valid(&lw)) return;
1825 cd = image_get_collection(lw->image, &info);
1829 CollectInfo *last_collection;
1830 last_collection = collection_get_last(cd);
1831 if (last_collection != info)
1833 layout_image_set_collection_real(lw, cd, last_collection, FALSE);
1838 current = layout_image_get_index(lw);
1839 count = layout_list_count(lw, nullptr);
1840 if (current != count - 1 && count > 0)
1842 layout_image_set_index(lw, count - 1);
1847 *----------------------------------------------------------------------------
1849 *----------------------------------------------------------------------------
1852 static gint image_idx(LayoutWindow *lw, ImageWindow *imd)
1856 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1858 if (lw->split_images[i] == imd)
1861 if (i < MAX_SPLIT_IMAGES)
1868 static void layout_image_focus_in_cb(ImageWindow *imd, gpointer data)
1870 auto lw = static_cast<LayoutWindow *>(data);
1872 gint i = image_idx(lw, imd);
1876 DEBUG_1("image activate focus_in %d", i);
1877 layout_image_activate(lw, i, FALSE);
1882 static void layout_image_button_cb(ImageWindow *imd, GdkEventButton *event, gpointer data)
1884 auto lw = static_cast<LayoutWindow *>(data);
1886 LayoutWindow *lw_new;
1889 switch (event->button)
1891 case MOUSE_BUTTON_LEFT:
1892 if (event->button == MOUSE_BUTTON_LEFT && event->type == GDK_2BUTTON_PRESS)
1894 layout_image_full_screen_toggle(lw);
1897 else if (options->image_l_click_archive && imd-> image_fd && imd->image_fd->format_class == FORMAT_CLASS_ARCHIVE)
1899 dest_dir = open_archive(imd->image_fd);
1902 lw_new = layout_new_from_default();
1903 layout_set_path(lw_new, dest_dir);
1908 warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GQ_ICON_DIALOG_WARNING, nullptr);
1911 else if (options->image_l_click_video && options->image_l_click_video_editor && imd-> image_fd && imd->image_fd->format_class == FORMAT_CLASS_VIDEO)
1913 start_editor_from_file(options->image_l_click_video_editor, imd->image_fd);
1915 else if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
1916 layout_image_next(lw);
1918 case MOUSE_BUTTON_MIDDLE:
1919 if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
1920 layout_image_prev(lw);
1922 case MOUSE_BUTTON_RIGHT:
1923 menu = layout_image_pop_menu(lw);
1924 if (imd == lw->image)
1926 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
1928 gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr);
1935 static void layout_image_scroll_cb(ImageWindow *imd, GdkEventScroll *event, gpointer data)
1937 auto lw = static_cast<LayoutWindow *>(data);
1939 gint i = image_idx(lw, imd);
1943 DEBUG_1("image activate scroll %d", i);
1944 layout_image_activate(lw, i, FALSE);
1948 if ((event->state & GDK_CONTROL_MASK) ||
1949 (imd->mouse_wheel_mode && !options->image_lm_click_nav))
1951 switch (event->direction)
1954 layout_image_zoom_adjust_at_point(lw, get_zoom_increment(), event->x, event->y, event->state & GDK_SHIFT_MASK);
1956 case GDK_SCROLL_DOWN:
1957 layout_image_zoom_adjust_at_point(lw, -get_zoom_increment(), event->x, event->y, event->state & GDK_SHIFT_MASK);
1963 else if (options->mousewheel_scrolls)
1965 switch (event->direction)
1968 image_scroll(imd, 0, -MOUSEWHEEL_SCROLL_SIZE);
1970 case GDK_SCROLL_DOWN:
1971 image_scroll(imd, 0, MOUSEWHEEL_SCROLL_SIZE);
1973 case GDK_SCROLL_LEFT:
1974 image_scroll(imd, -MOUSEWHEEL_SCROLL_SIZE, 0);
1976 case GDK_SCROLL_RIGHT:
1977 image_scroll(imd, MOUSEWHEEL_SCROLL_SIZE, 0);
1985 switch (event->direction)
1988 layout_image_prev(lw);
1990 case GDK_SCROLL_DOWN:
1991 layout_image_next(lw);
1999 static void layout_image_drag_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
2002 auto lw = static_cast<LayoutWindow *>(data);
2005 if (lw->full_screen && lw->image != lw->full_screen->imd &&
2006 imd != lw->full_screen->imd)
2008 if (event->state & GDK_CONTROL_MASK)
2010 image_get_scroll_center(imd, &sx, &sy);
2014 image_get_scroll_center(lw->full_screen->imd, &sx, &sy);
2018 image_set_scroll_center(lw->full_screen->imd, sx, sy);
2021 if (!(event->state & GDK_SHIFT_MASK)) return;
2023 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
2025 if (lw->split_images[i] && lw->split_images[i] != imd)
2028 if (event->state & GDK_CONTROL_MASK)
2030 image_get_scroll_center(imd, &sx, &sy);
2034 image_get_scroll_center(lw->split_images[i], &sx, &sy);
2038 image_set_scroll_center(lw->split_images[i], sx, sy);
2043 static void layout_image_button_inactive_cb(ImageWindow *imd, GdkEventButton *event, gpointer data)
2045 auto lw = static_cast<LayoutWindow *>(data);
2047 gint i = image_idx(lw, imd);
2051 layout_image_activate(lw, i, FALSE);
2054 switch (event->button)
2056 case MOUSE_BUTTON_RIGHT:
2057 menu = layout_image_pop_menu(lw);
2058 if (imd == lw->image)
2060 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
2062 gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr);
2070 static void layout_image_drag_inactive_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
2072 auto lw = static_cast<LayoutWindow *>(data);
2073 gint i = image_idx(lw, imd);
2077 layout_image_activate(lw, i, FALSE);
2080 /* continue as with active image */
2081 layout_image_drag_cb(imd, event, dx, dy, data);
2085 static void layout_image_set_buttons(LayoutWindow *lw)
2087 image_set_button_func(lw->image, layout_image_button_cb, lw);
2088 image_set_scroll_func(lw->image, layout_image_scroll_cb, lw);
2091 static void layout_image_set_buttons_inactive(LayoutWindow *lw, gint i)
2093 image_set_button_func(lw->split_images[i], layout_image_button_inactive_cb, lw);
2094 image_set_scroll_func(lw->split_images[i], layout_image_scroll_cb, lw);
2097 /* Returns the length of an integer */
2098 static gint num_length(gint num)
2101 if (num < 0) num = -num;
2110 void layout_status_update_pixel_cb(PixbufRenderer *pr, gpointer data)
2112 auto lw = static_cast<LayoutWindow *>(data);
2113 gint x_pixel, y_pixel;
2116 PangoAttrList *attrs;
2118 if (!data || !layout_valid(&lw) || !lw->image
2119 || !lw->options.show_info_pixel || lw->image->unknown) return;
2121 pixbuf_renderer_get_image_size(pr, &width, &height);
2122 if (width < 1 || height < 1) return;
2124 pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
2126 if(x_pixel >= 0 && y_pixel >= 0)
2128 gint r_mouse, g_mouse, b_mouse;
2130 pixbuf_renderer_get_pixel_colors(pr, x_pixel, y_pixel,
2131 &r_mouse, &g_mouse, &b_mouse);
2133 text = g_strdup_printf(_("[%*d,%*d]: RGB(%3d,%3d,%3d)"),
2134 num_length(width - 1), x_pixel,
2135 num_length(height - 1), y_pixel,
2136 r_mouse, g_mouse, b_mouse);
2141 text = g_strdup_printf(_("[%*s,%*s]: RGB(---,---,---)"),
2142 num_length(width - 1), " ",
2143 num_length(height - 1), " ");
2146 attrs = pango_attr_list_new();
2147 pango_attr_list_insert(attrs, pango_attr_family_new("Monospace"));
2148 gtk_label_set_text(GTK_LABEL(lw->info_pixel), text);
2149 gtk_label_set_attributes(GTK_LABEL(lw->info_pixel), attrs);
2150 pango_attr_list_unref(attrs);
2156 *----------------------------------------------------------------------------
2158 *----------------------------------------------------------------------------
2161 static void layout_image_update_cb(ImageWindow *, gpointer data)
2163 auto lw = static_cast<LayoutWindow *>(data);
2164 layout_status_update_image(lw);
2167 GtkWidget *layout_image_new(LayoutWindow *lw, gint i)
2169 if (!lw->split_image_sizegroup) lw->split_image_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
2171 if (!lw->split_images[i])
2173 lw->split_images[i] = image_new(TRUE);
2175 g_object_ref(lw->split_images[i]->widget);
2177 g_signal_connect(G_OBJECT(lw->split_images[i]->pr), "update-pixel",
2178 G_CALLBACK(layout_status_update_pixel_cb), lw);
2180 image_background_set_color_from_options(lw->split_images[i], FALSE);
2182 image_auto_refresh_enable(lw->split_images[i], TRUE);
2184 layout_image_dnd_init(lw, i);
2185 image_color_profile_set(lw->split_images[i],
2186 options->color_profile.input_type,
2187 options->color_profile.use_image);
2188 image_color_profile_set_use(lw->split_images[i], options->color_profile.enabled);
2190 gtk_size_group_add_widget(lw->split_image_sizegroup, lw->split_images[i]->widget);
2191 gtk_widget_set_size_request(lw->split_images[i]->widget, IMAGE_MIN_WIDTH, -1);
2193 image_set_focus_in_func(lw->split_images[i], layout_image_focus_in_cb, lw);
2197 return lw->split_images[i]->widget;
2200 void layout_image_deactivate(LayoutWindow *lw, gint i)
2202 if (!lw->split_images[i]) return;
2203 image_set_update_func(lw->split_images[i], nullptr, nullptr);
2204 layout_image_set_buttons_inactive(lw, i);
2205 image_set_drag_func(lw->split_images[i], layout_image_drag_inactive_cb, lw);
2207 image_attach_window(lw->split_images[i], nullptr, nullptr, nullptr, FALSE);
2208 image_select(lw->split_images[i], FALSE);
2211 /* force should be set after change of lw->split_mode */
2212 void layout_image_activate(LayoutWindow *lw, gint i, gboolean force)
2216 if (!lw->split_images[i]) return;
2217 if (!force && lw->active_split_image == i) return;
2219 /* deactivate currently active */
2220 if (lw->active_split_image != i)
2221 layout_image_deactivate(lw, lw->active_split_image);
2223 lw->image = lw->split_images[i];
2224 lw->active_split_image = i;
2226 image_set_update_func(lw->image, layout_image_update_cb, lw);
2227 layout_image_set_buttons(lw);
2228 image_set_drag_func(lw->image, layout_image_drag_cb, lw);
2230 image_attach_window(lw->image, lw->window, nullptr, GQ_APPNAME, FALSE);
2232 /* do not highlight selected image in SPLIT_NONE */
2233 /* maybe the image should be selected always and highlight should be controlled by
2234 another image option */
2235 if (lw->split_mode != SPLIT_NONE)
2236 image_select(lw->split_images[i], TRUE);
2238 image_select(lw->split_images[i], FALSE);
2240 fd = image_get_fd(lw->image);
2244 layout_set_fd(lw, fd);
2246 layout_status_update_image(lw);
2250 static void layout_image_setup_split_common(LayoutWindow *lw, gint n)
2252 gboolean frame = (n > 1) || (!lw->options.tools_float && !lw->options.tools_hidden);
2255 for (i = 0; i < n; i++)
2256 if (!lw->split_images[i])
2258 FileData *img_fd = nullptr;
2261 layout_image_new(lw, i);
2262 image_set_frame(lw->split_images[i], frame);
2263 image_set_selectable(lw->split_images[i], (n > 1));
2267 image_osd_copy_status(lw->image, lw->split_images[i]);
2270 if (layout_selection_count(lw, nullptr) > 1)
2272 GList *work = g_list_last(layout_selection_list(lw));
2275 while (work && j < i)
2277 auto fd = static_cast<FileData *>(work->data);
2280 if (!fd || !*fd->path || fd->parent ||
2281 fd == lw->split_images[0]->image_fd)
2291 if (!img_fd && lw->image)
2293 img_fd = image_get_fd(lw->image);
2294 zoom = image_zoom_get(lw->image);
2300 image_change_fd(lw->split_images[i], img_fd, zoom);
2301 image_get_scroll_center(lw->image, &sx, &sy);
2302 image_set_scroll_center(lw->split_images[i], sx, sy);
2304 layout_image_deactivate(lw, i);
2308 image_set_frame(lw->split_images[i], frame);
2309 image_set_selectable(lw->split_images[i], (n > 1));
2312 for (i = n; i < MAX_SPLIT_IMAGES; i++)
2314 if (lw->split_images[i])
2316 g_object_unref(lw->split_images[i]->widget);
2317 lw->split_images[i] = nullptr;
2321 if (!lw->image || lw->active_split_image < 0 || lw->active_split_image >= n)
2323 layout_image_activate(lw, 0, TRUE);
2327 /* this will draw the frame around selected image (image_select)
2328 on switch from single to split images */
2329 layout_image_activate(lw, lw->active_split_image, TRUE);
2333 GtkWidget *layout_image_setup_split_none(LayoutWindow *lw)
2335 lw->split_mode = SPLIT_NONE;
2337 layout_image_setup_split_common(lw, 1);
2339 lw->split_image_widget = lw->split_images[0]->widget;
2341 return lw->split_image_widget;
2345 GtkWidget *layout_image_setup_split_hv(LayoutWindow *lw, gboolean horizontal)
2349 lw->split_mode = horizontal ? SPLIT_HOR : SPLIT_VERT;
2351 layout_image_setup_split_common(lw, 2);
2353 /* horizontal split means vpaned and vice versa */
2354 paned = gtk_paned_new(horizontal ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
2357 gtk_paned_pack1(GTK_PANED(paned), lw->split_images[0]->widget, TRUE, TRUE);
2358 gtk_paned_pack2(GTK_PANED(paned), lw->split_images[1]->widget, TRUE, TRUE);
2360 gtk_widget_show(lw->split_images[0]->widget);
2361 gtk_widget_show(lw->split_images[1]->widget);
2363 lw->split_image_widget = paned;
2365 return lw->split_image_widget;
2369 static GtkWidget *layout_image_setup_split_triple(LayoutWindow *lw)
2373 GtkAllocation allocation;
2377 lw->split_mode = SPLIT_TRIPLE;
2379 layout_image_setup_split_common(lw, 3);
2381 gtk_widget_get_allocation(lw->utility_paned, &allocation);
2383 hpaned1 = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2384 DEBUG_NAME(hpaned1);
2385 hpaned2 = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2386 DEBUG_NAME(hpaned2);
2388 if (lw->bar && gtk_widget_get_visible(lw->bar))
2390 pane_pos = (gtk_paned_get_position(GTK_PANED(lw->utility_paned))) / 3;
2394 pane_pos = allocation.width / 3;
2397 gtk_paned_set_position(GTK_PANED(hpaned1), pane_pos);
2398 gtk_paned_set_position(GTK_PANED(hpaned2), pane_pos);
2400 gtk_paned_pack1(GTK_PANED(hpaned1), lw->split_images[0]->widget, TRUE, TRUE);
2401 gtk_paned_pack1(GTK_PANED(hpaned2), lw->split_images[1]->widget, TRUE, TRUE);
2402 gtk_paned_pack2(GTK_PANED(hpaned2), lw->split_images[2]->widget, TRUE, TRUE);
2403 gtk_paned_pack2(GTK_PANED(hpaned1), hpaned2, TRUE, TRUE);
2405 for (i = 0; i < 3; i++)
2407 gtk_widget_show(lw->split_images[i]->widget);
2410 gtk_widget_show(hpaned1);
2411 gtk_widget_show(hpaned2);
2413 lw->split_image_widget = hpaned1;
2415 return lw->split_image_widget;
2418 GtkWidget *layout_image_setup_split_quad(LayoutWindow *lw)
2425 lw->split_mode = SPLIT_QUAD;
2427 layout_image_setup_split_common(lw, 4);
2429 hpaned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2431 vpaned1 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
2432 DEBUG_NAME(vpaned1);
2433 vpaned2 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
2434 DEBUG_NAME(vpaned2);
2436 gtk_paned_pack1(GTK_PANED(vpaned1), lw->split_images[0]->widget, TRUE, TRUE);
2437 gtk_paned_pack2(GTK_PANED(vpaned1), lw->split_images[2]->widget, TRUE, TRUE);
2439 gtk_paned_pack1(GTK_PANED(vpaned2), lw->split_images[1]->widget, TRUE, TRUE);
2440 gtk_paned_pack2(GTK_PANED(vpaned2), lw->split_images[3]->widget, TRUE, TRUE);
2442 gtk_paned_pack1(GTK_PANED(hpaned), vpaned1, TRUE, TRUE);
2443 gtk_paned_pack2(GTK_PANED(hpaned), vpaned2, TRUE, TRUE);
2445 for (i = 0; i < 4; i++)
2446 gtk_widget_show(lw->split_images[i]->widget);
2448 gtk_widget_show(vpaned1);
2449 gtk_widget_show(vpaned2);
2451 lw->split_image_widget = hpaned;
2453 return lw->split_image_widget;
2457 GtkWidget *layout_image_setup_split(LayoutWindow *lw, ImageSplitMode mode)
2462 return layout_image_setup_split_hv(lw, TRUE);
2464 return layout_image_setup_split_hv(lw, FALSE);
2466 return layout_image_setup_split_triple(lw);
2468 return layout_image_setup_split_quad(lw);
2471 return layout_image_setup_split_none(lw);
2477 *-----------------------------------------------------------------------------
2478 * maintenance (for rename, move, remove)
2479 *-----------------------------------------------------------------------------
2482 static void layout_image_maint_renamed(LayoutWindow *lw, FileData *fd)
2484 if (fd == layout_image_get_fd(lw))
2486 image_set_fd(lw->image, fd);
2490 static void layout_image_maint_removed(LayoutWindow *lw, FileData *fd)
2492 if (fd == layout_image_get_fd(lw))
2497 cd = image_get_collection(lw->image, &info);
2500 CollectInfo *next_collection;
2502 next_collection = collection_next_by_info(cd, info);
2503 if (!next_collection) next_collection = collection_prev_by_info(cd, info);
2505 if (next_collection)
2507 layout_image_set_collection(lw, cd, next_collection);
2510 layout_image_set_fd(lw, nullptr);
2513 /* the image will be set to the next image from the list soon,
2514 setting it to NULL here is not necessary*/
2519 void layout_image_notify_cb(FileData *fd, NotifyType type, gpointer data)
2521 auto lw = static_cast<LayoutWindow *>(data);
2523 if (!(type & NOTIFY_CHANGE) || !fd->change) return;
2525 DEBUG_1("Notify layout_image: %s %04x", fd->path, type);
2527 switch (fd->change->type)
2529 case FILEDATA_CHANGE_MOVE:
2530 case FILEDATA_CHANGE_RENAME:
2531 layout_image_maint_renamed(lw, fd);
2533 case FILEDATA_CHANGE_DELETE:
2534 layout_image_maint_removed(lw, fd);
2536 case FILEDATA_CHANGE_COPY:
2537 case FILEDATA_CHANGE_UNSPECIFIED:
2538 case FILEDATA_CHANGE_WRITE_METADATA:
2543 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */