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.
22 #include "layout-image.h"
26 #include <gdk-pixbuf/gdk-pixbuf.h>
29 #include <glib-object.h>
30 #include <pango/pango.h>
41 #include "fullscreen.h"
42 #include "history-list.h"
43 #include "image-overlay.h"
47 #include "layout-util.h"
49 #include "main-defines.h"
54 #include "pixbuf-renderer.h"
55 #include "slideshow.h"
56 #include "ui-fileops.h"
58 #include "ui-utildlg.h"
59 #include "uri-utils.h"
61 #include "view-file.h"
66 constexpr gint IMAGE_MIN_WIDTH = 100;
70 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw);
71 static void layout_image_set_buttons(LayoutWindow *lw);
72 static gboolean layout_image_animate_new_file(LayoutWindow *lw);
73 static void layout_image_animate_update_image(LayoutWindow *lw);
76 *----------------------------------------------------------------------------
78 *----------------------------------------------------------------------------
80 #pragma GCC diagnostic push
81 #pragma GCC diagnostic ignored "-Wunused-function"
82 static void layout_image_overlay_toggle_unused(LayoutWindow *lw)
85 image_osd_toggle(lw->image);
87 #pragma GCC diagnostic pop
90 *----------------------------------------------------------------------------
92 *----------------------------------------------------------------------------
95 static void layout_image_full_screen_stop_func(FullScreenData *fs, gpointer data)
97 auto lw = static_cast<LayoutWindow *>(data);
99 /* restore image window */
100 if (lw->image == fs->imd)
101 lw->image = fs->normal_imd;
103 lw->full_screen = nullptr;
106 void layout_image_full_screen_start(LayoutWindow *lw)
108 if (!layout_valid(&lw)) return;
110 if (lw->full_screen) return;
112 lw->full_screen = fullscreen_start(lw->window, lw->image,
113 layout_image_full_screen_stop_func, lw);
115 /* set to new image window */
116 if (lw->full_screen->same_region)
117 lw->image = lw->full_screen->imd;
119 layout_image_set_buttons(lw);
121 g_signal_connect(G_OBJECT(lw->full_screen->window), "key_press_event",
122 G_CALLBACK(layout_key_press_cb), lw);
124 layout_actions_add_window(lw, lw->full_screen->window);
126 image_osd_copy_status(lw->full_screen->normal_imd, lw->image);
127 layout_image_animate_update_image(lw);
129 /** @FIXME This is a hack to fix #1037 Fullscreen loads black
130 * The problem occurs when zoom is set to Original Size.
131 * An extra reload is required to force the image to be displayed.
132 * See also image-view.cc real_view_window_new()
133 * This is probably not the correct solution.
135 image_reload(lw->image);
138 void layout_image_full_screen_stop(LayoutWindow *lw)
140 if (!layout_valid(&lw)) return;
141 if (!lw->full_screen) return;
143 if (lw->image == lw->full_screen->imd)
144 image_osd_copy_status(lw->image, lw->full_screen->normal_imd);
146 fullscreen_stop(lw->full_screen);
148 layout_image_animate_update_image(lw);
151 void layout_image_full_screen_toggle(LayoutWindow *lw)
153 if (!layout_valid(&lw)) return;
156 layout_image_full_screen_stop(lw);
160 layout_image_full_screen_start(lw);
164 gboolean layout_image_full_screen_active(LayoutWindow *lw)
166 if (!layout_valid(&lw)) return FALSE;
168 return (lw->full_screen != nullptr);
172 *----------------------------------------------------------------------------
174 *----------------------------------------------------------------------------
177 static void layout_image_slideshow_next(LayoutWindow *lw)
179 if (lw->slideshow) slideshow_next(lw->slideshow);
182 static void layout_image_slideshow_prev(LayoutWindow *lw)
184 if (lw->slideshow) slideshow_prev(lw->slideshow);
187 static void layout_image_slideshow_stop_func(SlideShowData *, gpointer data)
189 auto lw = static_cast<LayoutWindow *>(data);
191 lw->slideshow = nullptr;
192 layout_status_update_info(lw, nullptr);
195 void layout_image_slideshow_start(LayoutWindow *lw)
200 if (!layout_valid(&lw)) return;
201 if (lw->slideshow) return;
203 cd = image_get_collection(lw->image, &info);
207 lw->slideshow = slideshow_start_from_collection(lw, nullptr, cd,
208 layout_image_slideshow_stop_func, lw, info);
212 lw->slideshow = slideshow_start(lw,
213 layout_list_get_index(lw, layout_image_get_fd(lw)),
214 layout_image_slideshow_stop_func, lw);
217 layout_status_update_info(lw, nullptr);
220 /* note that slideshow will take ownership of the list, do not free it */
221 void layout_image_slideshow_start_from_list(LayoutWindow *lw, GList *list)
223 if (!layout_valid(&lw)) return;
225 if (lw->slideshow || !list)
231 lw->slideshow = slideshow_start_from_filelist(lw, nullptr, list,
232 layout_image_slideshow_stop_func, lw);
234 layout_status_update_info(lw, nullptr);
237 void layout_image_slideshow_stop(LayoutWindow *lw)
239 if (!layout_valid(&lw)) return;
241 if (!lw->slideshow) return;
243 slideshow_free(lw->slideshow);
244 /* the stop_func sets lw->slideshow to NULL for us */
247 void layout_image_slideshow_toggle(LayoutWindow *lw)
249 if (!layout_valid(&lw)) return;
253 layout_image_slideshow_stop(lw);
257 layout_image_slideshow_start(lw);
261 gboolean layout_image_slideshow_active(LayoutWindow *lw)
263 if (!layout_valid(&lw)) return FALSE;
265 return (lw->slideshow != nullptr);
268 gboolean layout_image_slideshow_pause_toggle(LayoutWindow *lw)
272 if (!layout_valid(&lw)) return FALSE;
274 ret = slideshow_pause_toggle(lw->slideshow);
276 layout_status_update_info(lw, nullptr);
281 gboolean layout_image_slideshow_paused(LayoutWindow *lw)
283 if (!layout_valid(&lw)) return FALSE;
285 return (slideshow_paused(lw->slideshow));
288 static gboolean layout_image_slideshow_continue_check(LayoutWindow *lw)
290 if (!lw->slideshow) return FALSE;
292 if (!slideshow_should_continue(lw->slideshow))
294 layout_image_slideshow_stop(lw);
302 *----------------------------------------------------------------------------
304 *----------------------------------------------------------------------------
311 GdkPixbufAnimation *gpa;
312 GdkPixbufAnimationIter *iter;
317 GCancellable *cancellable;
319 GFileInputStream *gfstream;
322 static void image_animation_data_free(AnimationData *fd)
325 if(fd->iter) g_object_unref(fd->iter);
326 if(fd->gpa) g_object_unref(fd->gpa);
327 if(fd->cancellable) g_object_unref(fd->cancellable);
331 static gboolean animation_should_continue(AnimationData *fd)
339 static gboolean show_next_frame(gpointer data)
341 auto fd = static_cast<AnimationData*>(data);
345 if(animation_should_continue(fd)==FALSE)
347 image_animation_data_free(fd);
351 pr = reinterpret_cast<PixbufRenderer*>(fd->iw->pr);
353 if (gdk_pixbuf_animation_iter_advance(fd->iter,nullptr)==FALSE)
355 /* This indicates the animation is complete.
356 Return FALSE here to disable looping. */
359 fd->gpb = gdk_pixbuf_animation_iter_get_pixbuf(fd->iter);
360 image_change_pixbuf(fd->iw,fd->gpb,pr->zoom,FALSE);
362 if (fd->iw->func_update)
363 fd->iw->func_update(fd->iw, fd->iw->data_update);
365 delay = gdk_pixbuf_animation_iter_get_delay_time(fd->iter);
366 if (delay!=fd->delay)
368 if (delay>0) /* Current frame not static. */
371 g_timeout_add(delay,show_next_frame,fd);
375 image_animation_data_free(fd);
383 static gboolean layout_image_animate_check(LayoutWindow *lw)
385 if (!layout_valid(&lw)) return FALSE;
387 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))
391 lw->animation->valid = FALSE;
392 if (lw->animation->cancellable)
394 g_cancellable_cancel(lw->animation->cancellable);
396 lw->animation = nullptr;
404 static void layout_image_animate_update_image(LayoutWindow *lw)
406 if (!layout_valid(&lw)) return;
408 if(lw->options.animate && lw->animation)
410 if (lw->full_screen && lw->image != lw->full_screen->imd)
411 lw->animation->iw = lw->full_screen->imd;
413 lw->animation->iw = lw->image;
418 static void animation_async_ready_cb(GObject *, GAsyncResult *res, gpointer data)
420 GError *error = nullptr;
421 auto animation = static_cast<AnimationData *>(data);
425 if (g_cancellable_is_cancelled(animation->cancellable))
427 gdk_pixbuf_animation_new_from_stream_finish(res, nullptr);
428 g_object_unref(animation->in_file);
429 g_object_unref(animation->gfstream);
430 image_animation_data_free(animation);
434 animation->gpa = gdk_pixbuf_animation_new_from_stream_finish(res, &error);
437 if (!gdk_pixbuf_animation_is_static_image(animation->gpa))
439 animation->iter = gdk_pixbuf_animation_get_iter(animation->gpa, nullptr);
442 animation->data_adr = animation->lw->image->image_fd;
443 animation->delay = gdk_pixbuf_animation_iter_get_delay_time(animation->iter);
444 animation->valid = TRUE;
446 layout_image_animate_update_image(animation->lw);
448 g_timeout_add(animation->delay, show_next_frame, animation);
454 log_printf("Error reading GIF file: %s\n", error->message);
457 g_object_unref(animation->in_file);
458 g_object_unref(animation->gfstream);
462 static gboolean layout_image_animate_new_file(LayoutWindow *lw)
464 GFileInputStream *gfstream;
465 GError *error = nullptr;
466 AnimationData *animation;
469 if(!layout_image_animate_check(lw)) return FALSE;
471 if(lw->animation) lw->animation->valid = FALSE;
475 g_cancellable_cancel(lw->animation->cancellable);
478 animation = g_new0(AnimationData, 1);
479 lw->animation = animation;
481 animation->cancellable = g_cancellable_new();
483 in_file = g_file_new_for_path(lw->image->image_fd->path);
484 animation->in_file = in_file;
485 gfstream = g_file_read(in_file, nullptr, &error);
488 animation->gfstream = gfstream;
489 gdk_pixbuf_animation_new_from_stream_async(reinterpret_cast<GInputStream*>(gfstream), animation->cancellable, animation_async_ready_cb, animation);
493 log_printf("Error reading animation file: %s\nError: %s\n", lw->image->image_fd->path, error->message);
499 void layout_image_animate_toggle(LayoutWindow *lw)
505 lw->options.animate = !lw->options.animate;
507 action = gtk_action_group_get_action(lw->action_group, "Animate");
508 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.animate);
510 layout_image_animate_new_file(lw);
514 *----------------------------------------------------------------------------
516 *----------------------------------------------------------------------------
519 static void li_pop_menu_zoom_in_cb(GtkWidget *, gpointer data)
521 auto lw = static_cast<LayoutWindow *>(data);
523 layout_image_zoom_adjust(lw, get_zoom_increment(), FALSE);
526 static void li_pop_menu_zoom_out_cb(GtkWidget *, gpointer data)
528 auto lw = static_cast<LayoutWindow *>(data);
529 layout_image_zoom_adjust(lw, -get_zoom_increment(), FALSE);
532 static void li_pop_menu_zoom_1_1_cb(GtkWidget *, gpointer data)
534 auto lw = static_cast<LayoutWindow *>(data);
536 layout_image_zoom_set(lw, 1.0, FALSE);
539 static void li_pop_menu_zoom_fit_cb(GtkWidget *, gpointer data)
541 auto lw = static_cast<LayoutWindow *>(data);
543 layout_image_zoom_set(lw, 0.0, FALSE);
546 static void li_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
549 auto key = static_cast<const gchar *>(data);
551 lw = static_cast<LayoutWindow *>(submenu_item_get_data(widget));
553 if (!editor_window_flag_set(key))
555 layout_image_full_screen_stop(lw);
557 file_util_start_editor_from_file(key, layout_image_get_fd(lw), lw->window);
560 static void li_pop_menu_alter_cb(GtkWidget *widget, gpointer data)
562 auto lw = static_cast<LayoutWindow *>(data);
565 lw = static_cast<LayoutWindow *>(submenu_item_get_data(widget));
566 type = static_cast<AlterType>GPOINTER_TO_INT(data);
568 image_alter_orientation(lw->image, lw->image->image_fd, type);
571 static void li_pop_menu_new_cb(GtkWidget *, gpointer data)
573 auto lw = static_cast<LayoutWindow *>(data);
575 view_window_new(layout_image_get_fd(lw));
578 static GtkWidget *li_pop_menu_click_parent(GtkWidget *widget, LayoutWindow *lw)
583 menu = gtk_widget_get_toplevel(widget);
584 if (!menu) return nullptr;
586 parent = static_cast<GtkWidget *>(g_object_get_data(G_OBJECT(menu), "click_parent"));
588 if (!parent && lw->full_screen)
590 parent = lw->full_screen->imd->widget;
596 static void li_pop_menu_copy_cb(GtkWidget *widget, gpointer data)
598 auto lw = static_cast<LayoutWindow *>(data);
600 file_util_copy(layout_image_get_fd(lw), nullptr, nullptr,
601 li_pop_menu_click_parent(widget, lw));
604 static void li_pop_menu_copy_path_cb(GtkWidget *, gpointer data)
606 auto lw = static_cast<LayoutWindow *>(data);
608 file_util_copy_path_to_clipboard(layout_image_get_fd(lw), TRUE, TRUE);
611 static void li_pop_menu_copy_path_unquoted_cb(GtkWidget *, gpointer data)
613 auto lw = static_cast<LayoutWindow *>(data);
615 file_util_copy_path_to_clipboard(layout_image_get_fd(lw), FALSE, TRUE);
618 static void li_pop_menu_cut_path_cb(GtkWidget *, gpointer data)
620 auto lw = static_cast<LayoutWindow *>(data);
622 file_util_copy_path_to_clipboard(layout_image_get_fd(lw), FALSE, FALSE);
626 static void li_pop_menu_copy_image_cb(GtkWidget *, gpointer data)
628 /* @FIXME GTK4 stub */
631 static void li_pop_menu_copy_image_cb(GtkWidget *, gpointer data)
633 auto lw = static_cast<LayoutWindow *>(data);
634 ImageWindow *imd = lw->image;
637 pixbuf = image_get_pixbuf(imd);
639 gtk_clipboard_set_image(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), pixbuf);
643 static void li_pop_menu_move_cb(GtkWidget *widget, gpointer data)
645 auto lw = static_cast<LayoutWindow *>(data);
647 file_util_move(layout_image_get_fd(lw), nullptr, nullptr,
648 li_pop_menu_click_parent(widget, lw));
651 static void li_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
653 auto lw = static_cast<LayoutWindow *>(data);
655 file_util_rename(layout_image_get_fd(lw), nullptr,
656 li_pop_menu_click_parent(widget, lw));
659 static void li_pop_menu_delete_cb(GtkWidget *widget, gpointer data)
661 auto lw = static_cast<LayoutWindow *>(data);
663 options->file_ops.safe_delete_enable = FALSE;
664 file_util_delete(layout_image_get_fd(lw), nullptr,
665 li_pop_menu_click_parent(widget, lw));
668 static void li_pop_menu_move_to_trash_cb(GtkWidget *widget, gpointer data)
670 auto lw = static_cast<LayoutWindow *>(data);
672 options->file_ops.safe_delete_enable = TRUE;
673 file_util_delete(layout_image_get_fd(lw), nullptr,
674 li_pop_menu_click_parent(widget, lw));
677 static void li_pop_menu_slide_start_cb(GtkWidget *, gpointer data)
679 auto lw = static_cast<LayoutWindow *>(data);
681 layout_image_slideshow_start(lw);
684 static void li_pop_menu_slide_stop_cb(GtkWidget *, gpointer data)
686 auto lw = static_cast<LayoutWindow *>(data);
688 layout_image_slideshow_stop(lw);
691 static void li_pop_menu_slide_pause_cb(GtkWidget *, gpointer data)
693 auto lw = static_cast<LayoutWindow *>(data);
695 layout_image_slideshow_pause_toggle(lw);
698 static void li_pop_menu_full_screen_cb(GtkWidget *, gpointer data)
700 auto lw = static_cast<LayoutWindow *>(data);
702 layout_image_full_screen_toggle(lw);
705 static void li_pop_menu_animate_cb(GtkWidget *, gpointer data)
707 auto lw = static_cast<LayoutWindow *>(data);
709 layout_image_animate_toggle(lw);
712 static void li_pop_menu_hide_cb(GtkWidget *, gpointer data)
714 auto lw = static_cast<LayoutWindow *>(data);
716 layout_tools_hide_toggle(lw);
719 static void li_set_layout_path_cb(GtkWidget *, gpointer data)
721 auto lw = static_cast<LayoutWindow *>(data);
724 if (!layout_valid(&lw)) return;
726 fd = layout_image_get_fd(lw);
727 if (fd) layout_set_fd(lw, fd);
730 static void li_open_archive_cb(GtkWidget *, gpointer data)
732 auto lw = static_cast<LayoutWindow *>(data);
733 LayoutWindow *lw_new;
736 if (!layout_valid(&lw)) return;
738 dest_dir = open_archive(layout_image_get_fd(lw));
741 lw_new = layout_new_from_default();
742 layout_set_path(lw_new, dest_dir);
747 warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GQ_ICON_DIALOG_WARNING, nullptr);
751 static gboolean li_check_if_current_path(LayoutWindow *lw, const gchar *path)
756 if (!path || !layout_valid(&lw) || !lw->dir_fd) return FALSE;
758 dirname = g_path_get_dirname(path);
759 ret = (strcmp(lw->dir_fd->path, dirname) == 0);
764 static void layout_image_popup_menu_destroy_cb(GtkWidget *, gpointer data)
766 auto editmenu_fd_list = static_cast<GList *>(data);
768 filelist_free(editmenu_fd_list);
771 static GList *layout_image_get_fd_list(LayoutWindow *lw)
773 GList *list = nullptr;
774 FileData *fd = layout_image_get_fd(lw);
779 /* optionally include sidecars if the filelist entry is not expanded */
780 list = vf_selection_get_one(lw->vf, fd);
782 list = g_list_append(nullptr, file_data_ref(fd));
789 * @brief Add file selection list to a collection
791 * @param[in] data Index to the collection list menu item selected, or -1 for new collection
795 static void layout_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
798 GList *selection_list = nullptr;
800 lw = static_cast<LayoutWindow *>(submenu_item_get_data(widget));
801 selection_list = g_list_append(selection_list, layout_image_get_fd(lw));
802 pop_menu_collections(selection_list, data);
804 filelist_free(selection_list);
807 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
814 GList *editmenu_fd_list;
815 GtkAccelGroup *accel_group;
817 path = layout_image_get_path(lw);
818 fullscreen = layout_image_full_screen_active(lw);
820 menu = popup_menu_short_lived();
822 accel_group = gtk_accel_group_new();
823 gtk_menu_set_accel_group(GTK_MENU(menu), accel_group);
825 g_object_set_data(G_OBJECT(menu), "window_keys", nullptr);
826 g_object_set_data(G_OBJECT(menu), "accel_group", accel_group);
828 menu_item_add_icon(menu, _("Zoom _in"), GQ_ICON_ZOOM_IN, G_CALLBACK(li_pop_menu_zoom_in_cb), lw);
829 menu_item_add_icon(menu, _("Zoom _out"), GQ_ICON_ZOOM_OUT, G_CALLBACK(li_pop_menu_zoom_out_cb), lw);
830 menu_item_add_icon(menu, _("Zoom _1:1"), GQ_ICON_ZOOM_100, G_CALLBACK(li_pop_menu_zoom_1_1_cb), lw);
831 menu_item_add_icon(menu, _("Zoom to fit"), GQ_ICON_ZOOM_FIT, G_CALLBACK(li_pop_menu_zoom_fit_cb), lw);
832 menu_item_add_divider(menu);
834 editmenu_fd_list = layout_image_get_fd_list(lw);
835 g_signal_connect(G_OBJECT(menu), "destroy",
836 G_CALLBACK(layout_image_popup_menu_destroy_cb), editmenu_fd_list);
837 submenu = submenu_add_edit(menu, &item, G_CALLBACK(li_pop_menu_edit_cb), lw, editmenu_fd_list);
838 if (!path) gtk_widget_set_sensitive(item, FALSE);
839 menu_item_add_divider(submenu);
840 item = submenu_add_alter(menu, G_CALLBACK(li_pop_menu_alter_cb), lw);
842 item = menu_item_add_icon(menu, _("View in _new window"), GQ_ICON_NEW, G_CALLBACK(li_pop_menu_new_cb), lw);
843 if (!path || fullscreen) gtk_widget_set_sensitive(item, FALSE);
845 item = menu_item_add(menu, _("_Go to directory view"), G_CALLBACK(li_set_layout_path_cb), lw);
846 if (!path || li_check_if_current_path(lw, path)) gtk_widget_set_sensitive(item, FALSE);
848 item = menu_item_add_icon(menu, _("Open archive"), GQ_ICON_OPEN, G_CALLBACK(li_open_archive_cb), lw);
849 if (!path || lw->image->image_fd->format_class != FORMAT_CLASS_ARCHIVE)
851 gtk_widget_set_sensitive(item, FALSE);
854 menu_item_add_divider(menu);
856 item = menu_item_add_icon(menu, _("_Copy..."), GQ_ICON_COPY, G_CALLBACK(li_pop_menu_copy_cb), lw);
857 if (!path) gtk_widget_set_sensitive(item, FALSE);
858 item = menu_item_add(menu, _("_Move..."), G_CALLBACK(li_pop_menu_move_cb), lw);
859 if (!path) gtk_widget_set_sensitive(item, FALSE);
860 item = menu_item_add(menu, _("_Rename..."), G_CALLBACK(li_pop_menu_rename_cb), lw);
861 if (!path) gtk_widget_set_sensitive(item, FALSE);
862 item = menu_item_add(menu, _("_Copy to clipboard"), G_CALLBACK(li_pop_menu_copy_path_cb), lw);
863 item = menu_item_add(menu, _("_Copy to clipboard (unquoted)"), G_CALLBACK(li_pop_menu_copy_path_unquoted_cb), lw);
864 item = menu_item_add(menu, _("Copy _image to clipboard"), G_CALLBACK(li_pop_menu_copy_image_cb), lw);
865 item = menu_item_add(menu, _("Cut to clipboard"), G_CALLBACK(li_pop_menu_cut_path_cb), lw);
866 if (!path) gtk_widget_set_sensitive(item, FALSE);
867 menu_item_add_divider(menu);
869 item = menu_item_add_icon(menu,
870 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
871 _("Move to Trash"), GQ_ICON_DELETE,
872 G_CALLBACK(li_pop_menu_move_to_trash_cb), lw);
873 if (!path) gtk_widget_set_sensitive(item, FALSE);
874 item = menu_item_add_icon(menu,
875 options->file_ops.confirm_delete ? _("_Delete...") :
876 _("_Delete"), GQ_ICON_DELETE_SHRED,
877 G_CALLBACK(li_pop_menu_delete_cb), lw);
878 if (!path) gtk_widget_set_sensitive(item, FALSE);
879 menu_item_add_divider(menu);
881 submenu = submenu_add_collections(menu, &item,
882 G_CALLBACK(layout_pop_menu_collections_cb), lw);
883 gtk_widget_set_sensitive(item, TRUE);
884 menu_item_add_divider(menu);
886 if (layout_image_slideshow_active(lw))
888 menu_item_add(menu, _("Toggle _slideshow"), G_CALLBACK(li_pop_menu_slide_stop_cb), lw);
889 if (layout_image_slideshow_paused(lw))
891 item = menu_item_add(menu, _("Continue slides_how"),
892 G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
896 item = menu_item_add(menu, _("Pause slides_how"),
897 G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
902 menu_item_add(menu, _("Toggle _slideshow"), G_CALLBACK(li_pop_menu_slide_start_cb), lw);
903 item = menu_item_add(menu, _("Pause slides_how"), G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
904 gtk_widget_set_sensitive(item, FALSE);
909 menu_item_add_icon(menu, _("_Full screen"), GQ_ICON_FULLSCREEN, G_CALLBACK(li_pop_menu_full_screen_cb), lw);
913 menu_item_add_icon(menu, _("Exit _full screen"), GQ_ICON_LEAVE_FULLSCREEN, G_CALLBACK(li_pop_menu_full_screen_cb), lw);
916 menu_item_add_check(menu, _("GIF _animation"), lw->options.animate, G_CALLBACK(li_pop_menu_animate_cb), lw);
918 menu_item_add_divider(menu);
920 item = menu_item_add_check(menu, _("Hide file _list"), lw->options.tools_hidden,
921 G_CALLBACK(li_pop_menu_hide_cb), lw);
923 item = menu_item_add_check(menu, _("Hide Selectable Bars"), lw->options.selectable_toolbars_hidden, G_CALLBACK(layout_selectable_toolbars_toggle), lw);
924 if (fullscreen) gtk_widget_set_sensitive(item, FALSE);
929 void layout_image_menu_popup(LayoutWindow *lw)
933 menu = layout_image_pop_menu(lw);
934 gtk_menu_popup_at_widget(GTK_MENU(menu), lw->image->widget, GDK_GRAVITY_EAST, GDK_GRAVITY_CENTER, nullptr);
938 *----------------------------------------------------------------------------
940 *----------------------------------------------------------------------------
943 static void layout_image_dnd_receive(GtkWidget *widget, GdkDragContext *,
945 GtkSelectionData *selection_data, guint info,
946 guint, gpointer data)
948 auto lw = static_cast<LayoutWindow *>(data);
953 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
955 if (lw->split_images[i] && lw->split_images[i]->pr == widget)
958 if (i < MAX_SPLIT_IMAGES)
960 DEBUG_1("dnd image activate %d", i);
961 layout_image_activate(lw, i, FALSE);
964 if (info == TARGET_TEXT_PLAIN)
966 url = g_strdup(reinterpret_cast<const gchar *>(gtk_selection_data_get_data(selection_data)));
967 download_web_file(url, FALSE, lw);
970 else if (info == TARGET_URI_LIST || info == TARGET_APP_COLLECTION_MEMBER)
972 CollectionData *source;
976 if (info == TARGET_URI_LIST)
978 list = uri_filelist_from_gtk_selection_data(selection_data);
984 source = collection_from_dnd_data(reinterpret_cast<const gchar *>(gtk_selection_data_get_data(selection_data)), &list, &info_list);
989 auto fd = static_cast<FileData *>(list->data);
991 if (isfile(fd->path))
997 base = remove_level_from_path(fd->path);
998 dir_fd = file_data_new_dir(base);
999 if (dir_fd != lw->dir_fd)
1001 layout_set_fd(lw, dir_fd);
1003 file_data_unref(dir_fd);
1006 row = layout_list_get_index(lw, fd);
1007 if (source && info_list)
1009 layout_image_set_collection(lw, source, static_cast<CollectInfo *>(info_list->data));
1013 layout_image_set_fd(lw, fd);
1017 layout_image_set_index(lw, row);
1020 else if (isdir(fd->path))
1022 layout_set_fd(lw, fd);
1023 layout_image_set_fd(lw, nullptr);
1027 filelist_free(list);
1028 g_list_free(info_list);
1032 static void layout_image_dnd_get(GtkWidget *widget, GdkDragContext *,
1033 GtkSelectionData *selection_data, guint,
1034 guint, gpointer data)
1036 auto lw = static_cast<LayoutWindow *>(data);
1041 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1043 if (lw->split_images[i] && lw->split_images[i]->pr == widget)
1046 if (i < MAX_SPLIT_IMAGES)
1048 DEBUG_1("dnd get from %d", i);
1049 fd = image_get_fd(lw->split_images[i]);
1052 fd = layout_image_get_fd(lw);
1058 list = g_list_append(nullptr, fd);
1059 uri_selection_data_set_uris_from_filelist(selection_data, list);
1064 gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
1069 static void layout_image_dnd_end(GtkWidget *, GdkDragContext *context, gpointer data)
1071 auto lw = static_cast<LayoutWindow *>(data);
1072 if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
1077 fd = layout_image_get_fd(lw);
1078 row = layout_list_get_index(lw, fd);
1079 if (row < 0) return;
1081 if (!isfile(fd->path))
1083 if (static_cast<guint>(row) < layout_list_count(lw, nullptr) - 1)
1085 layout_image_next(lw);
1089 layout_image_prev(lw);
1096 static void layout_image_dnd_init(LayoutWindow *lw, gint i)
1098 ImageWindow *imd = lw->split_images[i];
1100 gtk_drag_source_set(imd->pr, GDK_BUTTON2_MASK,
1101 dnd_file_drag_types, dnd_file_drag_types_count,
1102 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
1103 g_signal_connect(G_OBJECT(imd->pr), "drag_data_get",
1104 G_CALLBACK(layout_image_dnd_get), lw);
1105 g_signal_connect(G_OBJECT(imd->pr), "drag_end",
1106 G_CALLBACK(layout_image_dnd_end), lw);
1108 gtk_drag_dest_set(imd->pr,
1109 static_cast<GtkDestDefaults>(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP),
1110 dnd_file_drop_types, dnd_file_drop_types_count,
1111 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
1112 g_signal_connect(G_OBJECT(imd->pr), "drag_data_received",
1113 G_CALLBACK(layout_image_dnd_receive), lw);
1118 *----------------------------------------------------------------------------
1120 *----------------------------------------------------------------------------
1123 void layout_image_to_root(LayoutWindow *lw)
1125 image_to_root_window(lw->image, (image_zoom_get(lw->image) == 0));
1129 *----------------------------------------------------------------------------
1130 * manipulation + accessors
1131 *----------------------------------------------------------------------------
1134 void layout_image_scroll(LayoutWindow *lw, gint x, gint y, gboolean connect_scroll)
1137 if (!layout_valid(&lw)) return;
1139 image_scroll(lw->image, x, y);
1141 if (lw->full_screen && lw->image != lw->full_screen->imd)
1143 image_scroll(lw->full_screen->imd, x, y);
1146 if (!connect_scroll) return;
1148 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1150 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1152 image_scroll(lw->split_images[i], x, y);
1158 void layout_image_zoom_adjust(LayoutWindow *lw, gdouble increment, gboolean connect_zoom)
1161 if (!layout_valid(&lw)) return;
1163 image_zoom_adjust(lw->image, increment);
1165 if (lw->full_screen && lw->image != lw->full_screen->imd)
1167 image_zoom_adjust(lw->full_screen->imd, increment);
1170 if (!connect_zoom) return;
1172 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1174 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1175 image_zoom_adjust(lw->split_images[i], increment); ;
1179 void layout_image_zoom_adjust_at_point(LayoutWindow *lw, gdouble increment, gint x, gint y, gboolean connect_zoom)
1182 if (!layout_valid(&lw)) return;
1184 image_zoom_adjust_at_point(lw->image, increment, x, y);
1186 if (lw->full_screen && lw->image != lw->full_screen->imd)
1188 image_zoom_adjust_at_point(lw->full_screen->imd, increment, x, y);
1190 if (!connect_zoom && !lw->split_mode) return;
1192 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1194 if (lw->split_images[i] && lw->split_images[i] != lw->image &&
1195 lw->split_images[i]->mouse_wheel_mode)
1196 image_zoom_adjust_at_point(lw->split_images[i], increment, x, y);
1200 void layout_image_zoom_set(LayoutWindow *lw, gdouble zoom, gboolean connect_zoom)
1203 if (!layout_valid(&lw)) return;
1205 image_zoom_set(lw->image, zoom);
1207 if (lw->full_screen && lw->image != lw->full_screen->imd)
1209 image_zoom_set(lw->full_screen->imd, zoom);
1212 if (!connect_zoom) return;
1214 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1216 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1217 image_zoom_set(lw->split_images[i], zoom);
1221 void layout_image_zoom_set_fill_geometry(LayoutWindow *lw, gboolean vertical, gboolean connect_zoom)
1224 if (!layout_valid(&lw)) return;
1226 image_zoom_set_fill_geometry(lw->image, vertical);
1228 if (lw->full_screen && lw->image != lw->full_screen->imd)
1230 image_zoom_set_fill_geometry(lw->full_screen->imd, vertical);
1233 if (!connect_zoom) return;
1235 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1237 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1238 image_zoom_set_fill_geometry(lw->split_images[i], vertical);
1242 void layout_image_alter_orientation(LayoutWindow *lw, AlterType type)
1244 if (!layout_valid(&lw)) return;
1246 GtkTreeModel *store;
1248 GtkTreeSelection *selection;
1253 if (!lw || !lw->vf) return;
1255 if (lw->vf->type == FILEVIEW_ICON)
1257 if (!VFICON(lw->vf)->selection) return;
1258 work = VFICON(lw->vf)->selection;
1262 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
1263 work = gtk_tree_selection_get_selected_rows(selection, &store);
1268 if (lw->vf->type == FILEVIEW_ICON)
1270 fd_n = static_cast<FileData *>(work->data);
1275 tpath = static_cast<GtkTreePath *>(work->data);
1276 gtk_tree_model_get_iter(store, &iter, tpath);
1277 gtk_tree_model_get(store, &iter, VIEW_FILE_COLUMN_POINTER, &fd_n, -1);
1281 image_alter_orientation(lw->image, fd_n, type);
1285 static void image_alter_rating(FileData *fd_n, const gchar *rating)
1287 metadata_write_string(fd_n, RATING_KEY, rating);
1288 read_rating_data(fd_n);
1291 void layout_image_rating(LayoutWindow *lw, const gchar *rating)
1293 if (!layout_valid(&lw)) return;
1295 GtkTreeModel *store;
1297 GtkTreeSelection *selection;
1302 if (!lw || !lw->vf) return;
1304 if (lw->vf->type == FILEVIEW_ICON)
1306 if (!VFICON(lw->vf)->selection) return;
1307 work = VFICON(lw->vf)->selection;
1311 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
1312 work = gtk_tree_selection_get_selected_rows(selection, &store);
1317 if (lw->vf->type == FILEVIEW_ICON)
1319 fd_n = static_cast<FileData *>(work->data);
1324 tpath = static_cast<GtkTreePath *>(work->data);
1325 gtk_tree_model_get_iter(store, &iter, tpath);
1326 gtk_tree_model_get(store, &iter, VIEW_FILE_COLUMN_POINTER, &fd_n, -1);
1330 image_alter_rating(fd_n, rating);
1334 void layout_image_reset_orientation(LayoutWindow *lw)
1336 ImageWindow *imd= lw->image;
1338 if (!layout_valid(&lw)) return;
1339 if (!imd || !imd->pr || !imd->image_fd) return;
1341 if (imd->orientation < 1 || imd->orientation > 8) imd->orientation = 1;
1343 if (options->image.exif_rotate_enable)
1345 if (g_strcmp0(imd->image_fd->format_name, "heif") != 0)
1347 imd->orientation = metadata_read_int(imd->image_fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
1351 imd->orientation = EXIF_ORIENTATION_TOP_LEFT;
1356 imd->orientation = 1;
1359 if (imd->image_fd->user_orientation != 0)
1361 imd->orientation = imd->image_fd->user_orientation;
1364 pixbuf_renderer_set_orientation(reinterpret_cast<PixbufRenderer *>(imd->pr), imd->orientation);
1367 void layout_image_set_desaturate(LayoutWindow *lw, gboolean desaturate)
1369 if (!layout_valid(&lw)) return;
1371 image_set_desaturate(lw->image, desaturate);
1374 gboolean layout_image_get_desaturate(LayoutWindow *lw)
1376 if (!layout_valid(&lw)) return FALSE;
1378 return image_get_desaturate(lw->image);
1381 void layout_image_set_overunderexposed(LayoutWindow *lw, gboolean overunderexposed)
1383 if (!layout_valid(&lw)) return;
1385 image_set_overunderexposed(lw->image, overunderexposed);
1388 #pragma GCC diagnostic push
1389 #pragma GCC diagnostic ignored "-Wunused-function"
1390 gboolean layout_image_get_overunderexposed_unused(LayoutWindow *lw)
1392 if (!layout_valid(&lw)) return FALSE;
1394 // return image_get_overunderexposed(lw->image);
1397 #pragma GCC diagnostic pop
1399 void layout_image_set_ignore_alpha(LayoutWindow *lw, gboolean ignore_alpha)
1401 if (!layout_valid(&lw)) return;
1403 lw->options.ignore_alpha = ignore_alpha;
1404 image_set_ignore_alpha(lw->image, ignore_alpha);
1408 #pragma GCC diagnostic push
1409 #pragma GCC diagnostic ignored "-Wunused-function"
1410 gint layout_image_stereo_get_unused(LayoutWindow *lw)
1412 if (!layout_valid(&lw)) return 0;
1414 // return image_stereo_get(lw->image);
1418 void layout_image_stereo_set_unused(LayoutWindow *lw, gint stereo_mode)
1420 if (!layout_valid(&lw)) return;
1422 image_stereo_set(lw->image, stereo_mode);
1424 void layout_image_stereo_swap_unused(LayoutWindow *lw)
1426 if (!layout_valid(&lw)) return;
1428 // image_stereo_swap(lw->image);
1430 #pragma GCC diagnostic pop
1432 gint layout_image_stereo_pixbuf_get(LayoutWindow *lw)
1434 if (!layout_valid(&lw)) return 0;
1436 return image_stereo_pixbuf_get(lw->image);
1439 void layout_image_stereo_pixbuf_set(LayoutWindow *lw, gint stereo_mode)
1441 if (!layout_valid(&lw)) return;
1443 image_stereo_pixbuf_set(lw->image, static_cast<StereoPixbufData>(stereo_mode));
1446 const gchar *layout_image_get_path(LayoutWindow *lw)
1448 if (!layout_valid(&lw)) return nullptr;
1450 return image_get_path(lw->image);
1453 #pragma GCC diagnostic push
1454 #pragma GCC diagnostic ignored "-Wunused-function"
1455 const gchar *layout_image_get_name_unused(LayoutWindow *lw)
1457 if (!layout_valid(&lw)) return nullptr;
1459 return image_get_name(lw->image);
1461 #pragma GCC diagnostic pop
1463 FileData *layout_image_get_fd(LayoutWindow *lw)
1465 if (!layout_valid(&lw)) return nullptr;
1467 return image_get_fd(lw->image);
1470 CollectionData *layout_image_get_collection(LayoutWindow *lw, CollectInfo **info)
1472 if (!layout_valid(&lw)) return nullptr;
1474 return image_get_collection(lw->image, info);
1477 gint layout_image_get_index(LayoutWindow *lw)
1479 return layout_list_get_index(lw, image_get_fd(lw->image));
1483 *----------------------------------------------------------------------------
1485 *----------------------------------------------------------------------------
1488 void layout_image_set_fd(LayoutWindow *lw, FileData *fd)
1490 if (!layout_valid(&lw)) return;
1492 image_change_fd(lw->image, fd, image_zoom_get_default(lw->image));
1494 if (lw->full_screen && lw->image != lw->full_screen->imd)
1496 image_change_fd(lw->full_screen->imd, fd, image_zoom_get_default(lw->full_screen->imd));
1500 layout_list_sync_fd(lw, fd);
1501 layout_image_slideshow_continue_check(lw);
1502 layout_bars_new_image(lw);
1503 layout_image_animate_new_file(lw);
1507 image_chain_append_end(fd->path);
1511 void layout_image_set_with_ahead(LayoutWindow *lw, FileData *fd, FileData *read_ahead_fd)
1513 if (!layout_valid(&lw)) return;
1515 /** @FIXME This should be handled at the caller: in vflist_select_image
1518 const gchar *old_path;
1520 old_path = layout_image_get_path(lw);
1521 if (old_path && strcmp(path, old_path) == 0) return;
1524 layout_image_set_fd(lw, fd);
1525 if (options->image.enable_read_ahead) image_prebuffer_set(lw->image, read_ahead_fd);
1528 void layout_image_set_index(LayoutWindow *lw, gint index)
1531 FileData *read_ahead_fd;
1534 if (!layout_valid(&lw)) return;
1536 old = layout_list_get_index(lw, layout_image_get_fd(lw));
1537 fd = layout_list_get_fd(lw, index);
1541 read_ahead_fd = layout_list_get_fd(lw, index - 1);
1545 read_ahead_fd = layout_list_get_fd(lw, index + 1);
1548 if (layout_selection_count(lw, nullptr) > 1)
1550 GList *x = layout_selection_list_by_index(lw);
1554 for (last = y = x; y; y = y->next)
1556 for (y = x; y && (GPOINTER_TO_INT(y->data)) != index; y = y->next)
1563 if ((index > old && (index != GPOINTER_TO_INT(last->data) || old != GPOINTER_TO_INT(x->data)))
1564 || (old == GPOINTER_TO_INT(last->data) && index == GPOINTER_TO_INT(x->data)))
1567 newindex = GPOINTER_TO_INT(y->next->data);
1569 newindex = GPOINTER_TO_INT(x->data);
1574 newindex = GPOINTER_TO_INT(y->prev->data);
1576 newindex = GPOINTER_TO_INT(last->data);
1579 read_ahead_fd = layout_list_get_fd(lw, newindex);
1583 x = g_list_remove(x, x->data);
1586 layout_image_set_with_ahead(lw, fd, read_ahead_fd);
1589 static void layout_image_set_collection_real(LayoutWindow *lw, CollectionData *cd, CollectInfo *info, gboolean forward)
1591 if (!layout_valid(&lw)) return;
1593 image_change_from_collection(lw->image, cd, info, image_zoom_get_default(lw->image));
1594 if (options->image.enable_read_ahead)
1596 CollectInfo *r_info;
1599 r_info = collection_next_by_info(cd, info);
1600 if (!r_info) r_info = collection_prev_by_info(cd, info);
1604 r_info = collection_prev_by_info(cd, info);
1605 if (!r_info) r_info = collection_next_by_info(cd, info);
1607 if (r_info) image_prebuffer_set(lw->image, r_info->fd);
1610 layout_image_slideshow_continue_check(lw);
1611 layout_bars_new_image(lw);
1614 void layout_image_set_collection(LayoutWindow *lw, CollectionData *cd, CollectInfo *info)
1616 layout_image_set_collection_real(lw, cd, info, TRUE);
1617 layout_list_sync_fd(lw, layout_image_get_fd(lw));
1620 void layout_image_refresh(LayoutWindow *lw)
1622 if (!layout_valid(&lw)) return;
1624 image_reload(lw->image);
1627 void layout_image_color_profile_set(LayoutWindow *lw,
1631 if (!layout_valid(&lw)) return;
1633 image_color_profile_set(lw->image, input_type, use_image);
1636 gboolean layout_image_color_profile_get(LayoutWindow *lw,
1638 gboolean *use_image)
1640 if (!layout_valid(&lw)) return FALSE;
1642 return image_color_profile_get(lw->image, input_type, use_image);
1645 void layout_image_color_profile_set_use(LayoutWindow *lw, gboolean enable)
1647 if (!layout_valid(&lw)) return;
1649 image_color_profile_set_use(lw->image, enable);
1652 gboolean layout_image_color_profile_get_use(LayoutWindow *lw)
1654 if (!layout_valid(&lw)) return FALSE;
1656 return image_color_profile_get_use(lw->image);
1659 gboolean layout_image_color_profile_get_status(LayoutWindow *lw, gchar **image_profile, gchar **screen_profile)
1661 if (!layout_valid(&lw)) return FALSE;
1663 return image_color_profile_get_status(lw->image, image_profile, screen_profile);
1667 *----------------------------------------------------------------------------
1669 *----------------------------------------------------------------------------
1672 void layout_image_next(LayoutWindow *lw)
1678 if (!layout_valid(&lw)) return;
1680 if (layout_image_slideshow_active(lw))
1682 layout_image_slideshow_next(lw);
1686 if (layout_selection_count(lw, nullptr) > 1)
1688 GList *x = layout_selection_list_by_index(lw);
1689 gint old = layout_list_get_index(lw, layout_image_get_fd(lw));
1692 for (y = x; y && (GPOINTER_TO_INT(y->data)) != old; y = y->next)
1697 layout_image_set_index(lw, GPOINTER_TO_INT(y->next->data));
1700 if (options->circular_selection_lists)
1702 layout_image_set_index(lw, GPOINTER_TO_INT(x->data));
1707 x = g_list_remove(x, x->data);
1708 if (y) /* not dereferenced */
1712 cd = image_get_collection(lw->image, &info);
1716 info = collection_next_by_info(cd, info);
1719 layout_image_set_collection_real(lw, cd, info, TRUE);
1723 image_osd_icon(lw->image, IMAGE_OSD_LAST, -1);
1728 current = layout_image_get_index(lw);
1732 if (static_cast<guint>(current) < layout_list_count(lw, nullptr) - 1)
1734 layout_image_set_index(lw, current + 1);
1738 image_osd_icon(lw->image, IMAGE_OSD_LAST, -1);
1743 layout_image_set_index(lw, 0);
1747 void layout_image_prev(LayoutWindow *lw)
1753 if (!layout_valid(&lw)) return;
1755 if (layout_image_slideshow_active(lw))
1757 layout_image_slideshow_prev(lw);
1761 if (layout_selection_count(lw, nullptr) > 1)
1763 GList *x = layout_selection_list_by_index(lw);
1764 gint old = layout_list_get_index(lw, layout_image_get_fd(lw));
1768 for (last = y = x; y; y = y->next)
1770 for (y = x; y && (GPOINTER_TO_INT(y->data)) != old; y = y->next)
1775 layout_image_set_index(lw, GPOINTER_TO_INT(y->prev->data));
1778 if (options->circular_selection_lists)
1780 layout_image_set_index(lw, GPOINTER_TO_INT(last->data));
1785 x = g_list_remove(x, x->data);
1786 if (y) /* not dereferenced */
1790 cd = image_get_collection(lw->image, &info);
1794 info = collection_prev_by_info(cd, info);
1797 layout_image_set_collection_real(lw, cd, info, FALSE);
1801 image_osd_icon(lw->image, IMAGE_OSD_FIRST, -1);
1806 current = layout_image_get_index(lw);
1812 layout_image_set_index(lw, current - 1);
1816 image_osd_icon(lw->image, IMAGE_OSD_FIRST, -1);
1821 layout_image_set_index(lw, layout_list_count(lw, nullptr) - 1);
1825 void layout_image_first(LayoutWindow *lw)
1831 if (!layout_valid(&lw)) return;
1833 cd = image_get_collection(lw->image, &info);
1837 CollectInfo *first_collection;
1838 first_collection = collection_get_first(cd);
1839 if (first_collection != info)
1841 layout_image_set_collection_real(lw, cd, first_collection, TRUE);
1846 current = layout_image_get_index(lw);
1847 if (current != 0 && layout_list_count(lw, nullptr) > 0)
1849 layout_image_set_index(lw, 0);
1853 void layout_image_last(LayoutWindow *lw)
1860 if (!layout_valid(&lw)) return;
1862 cd = image_get_collection(lw->image, &info);
1866 CollectInfo *last_collection;
1867 last_collection = collection_get_last(cd);
1868 if (last_collection != info)
1870 layout_image_set_collection_real(lw, cd, last_collection, FALSE);
1875 current = layout_image_get_index(lw);
1876 count = layout_list_count(lw, nullptr);
1877 if (current != count - 1 && count > 0)
1879 layout_image_set_index(lw, count - 1);
1884 *----------------------------------------------------------------------------
1886 *----------------------------------------------------------------------------
1889 static gint image_idx(LayoutWindow *lw, ImageWindow *imd)
1893 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1895 if (lw->split_images[i] == imd)
1898 if (i < MAX_SPLIT_IMAGES)
1905 static void layout_image_focus_in_cb(ImageWindow *imd, gpointer data)
1907 auto lw = static_cast<LayoutWindow *>(data);
1909 gint i = image_idx(lw, imd);
1913 DEBUG_1("image activate focus_in %d", i);
1914 layout_image_activate(lw, i, FALSE);
1919 static void layout_image_button_cb(ImageWindow *imd, GdkEventButton *event, gpointer data)
1921 auto lw = static_cast<LayoutWindow *>(data);
1923 LayoutWindow *lw_new;
1926 switch (event->button)
1928 case MOUSE_BUTTON_LEFT:
1929 if (event->button == MOUSE_BUTTON_LEFT && event->type == GDK_2BUTTON_PRESS)
1931 layout_image_full_screen_toggle(lw);
1934 else if (options->image_l_click_archive && imd-> image_fd && imd->image_fd->format_class == FORMAT_CLASS_ARCHIVE)
1936 dest_dir = open_archive(imd->image_fd);
1939 lw_new = layout_new_from_default();
1940 layout_set_path(lw_new, dest_dir);
1945 warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GQ_ICON_DIALOG_WARNING, nullptr);
1948 else if (options->image_l_click_video && options->image_l_click_video_editor && imd-> image_fd && imd->image_fd->format_class == FORMAT_CLASS_VIDEO)
1950 start_editor_from_file(options->image_l_click_video_editor, imd->image_fd);
1952 else if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
1953 layout_image_next(lw);
1955 case MOUSE_BUTTON_MIDDLE:
1956 if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
1957 layout_image_prev(lw);
1959 case MOUSE_BUTTON_RIGHT:
1960 menu = layout_image_pop_menu(lw);
1961 if (imd == lw->image)
1963 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
1965 gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr);
1972 static void layout_image_scroll_cb(ImageWindow *imd, GdkEventScroll *event, gpointer data)
1974 auto lw = static_cast<LayoutWindow *>(data);
1976 gint i = image_idx(lw, imd);
1980 DEBUG_1("image activate scroll %d", i);
1981 layout_image_activate(lw, i, FALSE);
1985 if ((event->state & GDK_CONTROL_MASK) ||
1986 (imd->mouse_wheel_mode && !options->image_lm_click_nav))
1988 switch (event->direction)
1991 layout_image_zoom_adjust_at_point(lw, get_zoom_increment(), event->x, event->y, event->state & GDK_SHIFT_MASK);
1993 case GDK_SCROLL_DOWN:
1994 layout_image_zoom_adjust_at_point(lw, -get_zoom_increment(), event->x, event->y, event->state & GDK_SHIFT_MASK);
2000 else if (options->mousewheel_scrolls)
2002 switch (event->direction)
2005 image_scroll(imd, 0, -MOUSEWHEEL_SCROLL_SIZE);
2007 case GDK_SCROLL_DOWN:
2008 image_scroll(imd, 0, MOUSEWHEEL_SCROLL_SIZE);
2010 case GDK_SCROLL_LEFT:
2011 image_scroll(imd, -MOUSEWHEEL_SCROLL_SIZE, 0);
2013 case GDK_SCROLL_RIGHT:
2014 image_scroll(imd, MOUSEWHEEL_SCROLL_SIZE, 0);
2022 switch (event->direction)
2025 layout_image_prev(lw);
2027 case GDK_SCROLL_DOWN:
2028 layout_image_next(lw);
2036 static void layout_image_drag_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
2039 auto lw = static_cast<LayoutWindow *>(data);
2043 if (lw->full_screen && lw->image != lw->full_screen->imd &&
2044 imd != lw->full_screen->imd)
2046 if (event->state & GDK_CONTROL_MASK)
2048 image_get_scroll_center(imd, &sx, &sy);
2052 image_get_scroll_center(lw->full_screen->imd, &sx, &sy);
2056 image_set_scroll_center(lw->full_screen->imd, sx, sy);
2059 if (!(event->state & GDK_SHIFT_MASK)) return;
2061 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
2063 if (lw->split_images[i] && lw->split_images[i] != imd)
2066 if (event->state & GDK_CONTROL_MASK)
2068 image_get_scroll_center(imd, &sx, &sy);
2072 image_get_scroll_center(lw->split_images[i], &sx, &sy);
2076 image_set_scroll_center(lw->split_images[i], sx, sy);
2081 static void layout_image_button_inactive_cb(ImageWindow *imd, GdkEventButton *event, gpointer data)
2083 auto lw = static_cast<LayoutWindow *>(data);
2085 gint i = image_idx(lw, imd);
2089 layout_image_activate(lw, i, FALSE);
2092 switch (event->button)
2094 case MOUSE_BUTTON_RIGHT:
2095 menu = layout_image_pop_menu(lw);
2096 if (imd == lw->image)
2098 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
2100 gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr);
2108 static void layout_image_drag_inactive_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
2110 auto lw = static_cast<LayoutWindow *>(data);
2111 gint i = image_idx(lw, imd);
2115 layout_image_activate(lw, i, FALSE);
2118 /* continue as with active image */
2119 layout_image_drag_cb(imd, event, dx, dy, data);
2123 static void layout_image_set_buttons(LayoutWindow *lw)
2125 image_set_button_func(lw->image, layout_image_button_cb, lw);
2126 image_set_scroll_func(lw->image, layout_image_scroll_cb, lw);
2129 static void layout_image_set_buttons_inactive(LayoutWindow *lw, gint i)
2131 image_set_button_func(lw->split_images[i], layout_image_button_inactive_cb, lw);
2132 image_set_scroll_func(lw->split_images[i], layout_image_scroll_cb, lw);
2135 /* Returns the length of an integer */
2136 static gint num_length(gint num)
2139 if (num < 0) num = -num;
2148 void layout_status_update_pixel_cb(PixbufRenderer *pr, gpointer data)
2150 auto lw = static_cast<LayoutWindow *>(data);
2156 PangoAttrList *attrs;
2158 if (!data || !layout_valid(&lw) || !lw->image
2159 || !lw->options.show_info_pixel || lw->image->unknown) return;
2161 pixbuf_renderer_get_image_size(pr, &width, &height);
2162 if (width < 1 || height < 1) return;
2164 pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
2166 if(x_pixel >= 0 && y_pixel >= 0)
2172 pixbuf_renderer_get_pixel_colors(pr, x_pixel, y_pixel,
2173 &r_mouse, &g_mouse, &b_mouse);
2175 text = g_strdup_printf(_("[%*d,%*d]: RGB(%3d,%3d,%3d)"),
2176 num_length(width - 1), x_pixel,
2177 num_length(height - 1), y_pixel,
2178 r_mouse, g_mouse, b_mouse);
2183 text = g_strdup_printf(_("[%*s,%*s]: RGB(---,---,---)"),
2184 num_length(width - 1), " ",
2185 num_length(height - 1), " ");
2188 attrs = pango_attr_list_new();
2189 pango_attr_list_insert(attrs, pango_attr_family_new("Monospace"));
2190 gtk_label_set_text(GTK_LABEL(lw->info_pixel), text);
2191 gtk_label_set_attributes(GTK_LABEL(lw->info_pixel), attrs);
2192 pango_attr_list_unref(attrs);
2198 *----------------------------------------------------------------------------
2200 *----------------------------------------------------------------------------
2203 static void layout_image_update_cb(ImageWindow *, gpointer data)
2205 auto lw = static_cast<LayoutWindow *>(data);
2206 layout_status_update_image(lw);
2209 GtkWidget *layout_image_new(LayoutWindow *lw, gint i)
2211 if (!lw->split_image_sizegroup) lw->split_image_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
2213 if (!lw->split_images[i])
2215 lw->split_images[i] = image_new(TRUE);
2217 g_object_ref(lw->split_images[i]->widget);
2219 g_signal_connect(G_OBJECT(lw->split_images[i]->pr), "update-pixel",
2220 G_CALLBACK(layout_status_update_pixel_cb), lw);
2222 image_background_set_color_from_options(lw->split_images[i], FALSE);
2224 image_auto_refresh_enable(lw->split_images[i], TRUE);
2226 layout_image_dnd_init(lw, i);
2227 image_color_profile_set(lw->split_images[i],
2228 options->color_profile.input_type,
2229 options->color_profile.use_image);
2230 image_color_profile_set_use(lw->split_images[i], options->color_profile.enabled);
2232 gtk_size_group_add_widget(lw->split_image_sizegroup, lw->split_images[i]->widget);
2233 gtk_widget_set_size_request(lw->split_images[i]->widget, IMAGE_MIN_WIDTH, -1);
2235 image_set_focus_in_func(lw->split_images[i], layout_image_focus_in_cb, lw);
2239 return lw->split_images[i]->widget;
2242 void layout_image_deactivate(LayoutWindow *lw, gint i)
2244 if (!lw->split_images[i]) return;
2245 image_set_update_func(lw->split_images[i], nullptr, nullptr);
2246 layout_image_set_buttons_inactive(lw, i);
2247 image_set_drag_func(lw->split_images[i], layout_image_drag_inactive_cb, lw);
2249 image_attach_window(lw->split_images[i], nullptr, nullptr, nullptr, FALSE);
2250 image_select(lw->split_images[i], FALSE);
2253 /* force should be set after change of lw->split_mode */
2254 void layout_image_activate(LayoutWindow *lw, gint i, gboolean force)
2258 if (!lw->split_images[i]) return;
2259 if (!force && lw->active_split_image == i) return;
2261 /* deactivate currently active */
2262 if (lw->active_split_image != i)
2263 layout_image_deactivate(lw, lw->active_split_image);
2265 lw->image = lw->split_images[i];
2266 lw->active_split_image = i;
2268 image_set_update_func(lw->image, layout_image_update_cb, lw);
2269 layout_image_set_buttons(lw);
2270 image_set_drag_func(lw->image, layout_image_drag_cb, lw);
2272 image_attach_window(lw->image, lw->window, nullptr, GQ_APPNAME, FALSE);
2274 /* do not highlight selected image in SPLIT_NONE */
2275 /* maybe the image should be selected always and highlight should be controlled by
2276 another image option */
2277 if (lw->split_mode != SPLIT_NONE)
2278 image_select(lw->split_images[i], TRUE);
2280 image_select(lw->split_images[i], FALSE);
2282 fd = image_get_fd(lw->image);
2286 layout_set_fd(lw, fd);
2288 layout_status_update_image(lw);
2292 static void layout_image_setup_split_common(LayoutWindow *lw, gint n)
2294 gboolean frame = (n > 1) || (!lw->options.tools_float && !lw->options.tools_hidden);
2297 for (i = 0; i < n; i++)
2298 if (!lw->split_images[i])
2300 FileData *img_fd = nullptr;
2303 layout_image_new(lw, i);
2304 image_set_frame(lw->split_images[i], frame);
2305 image_set_selectable(lw->split_images[i], (n > 1));
2309 image_osd_copy_status(lw->image, lw->split_images[i]);
2312 if (layout_selection_count(lw, nullptr) > 1)
2314 GList *work = g_list_last(layout_selection_list(lw));
2317 while (work && j < i)
2319 auto fd = static_cast<FileData *>(work->data);
2322 if (!fd || !*fd->path || fd->parent ||
2323 fd == lw->split_images[0]->image_fd)
2333 if (!img_fd && lw->image)
2335 img_fd = image_get_fd(lw->image);
2336 zoom = image_zoom_get(lw->image);
2343 image_change_fd(lw->split_images[i], img_fd, zoom);
2344 image_get_scroll_center(lw->image, &sx, &sy);
2345 image_set_scroll_center(lw->split_images[i], sx, sy);
2347 layout_image_deactivate(lw, i);
2351 image_set_frame(lw->split_images[i], frame);
2352 image_set_selectable(lw->split_images[i], (n > 1));
2355 for (i = n; i < MAX_SPLIT_IMAGES; i++)
2357 if (lw->split_images[i])
2359 g_object_unref(lw->split_images[i]->widget);
2360 lw->split_images[i] = nullptr;
2364 if (!lw->image || lw->active_split_image < 0 || lw->active_split_image >= n)
2366 layout_image_activate(lw, 0, TRUE);
2370 /* this will draw the frame around selected image (image_select)
2371 on switch from single to split images */
2372 layout_image_activate(lw, lw->active_split_image, TRUE);
2376 GtkWidget *layout_image_setup_split_none(LayoutWindow *lw)
2378 lw->split_mode = SPLIT_NONE;
2380 layout_image_setup_split_common(lw, 1);
2382 lw->split_image_widget = lw->split_images[0]->widget;
2384 return lw->split_image_widget;
2388 GtkWidget *layout_image_setup_split_hv(LayoutWindow *lw, gboolean horizontal)
2392 lw->split_mode = horizontal ? SPLIT_HOR : SPLIT_VERT;
2394 layout_image_setup_split_common(lw, 2);
2396 /* horizontal split means vpaned and vice versa */
2397 paned = gtk_paned_new(horizontal ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
2400 gtk_paned_pack1(GTK_PANED(paned), lw->split_images[0]->widget, TRUE, TRUE);
2401 gtk_paned_pack2(GTK_PANED(paned), lw->split_images[1]->widget, TRUE, TRUE);
2403 gtk_widget_show(lw->split_images[0]->widget);
2404 gtk_widget_show(lw->split_images[1]->widget);
2406 lw->split_image_widget = paned;
2408 return lw->split_image_widget;
2412 static GtkWidget *layout_image_setup_split_triple(LayoutWindow *lw)
2416 GtkAllocation allocation;
2420 lw->split_mode = SPLIT_TRIPLE;
2422 layout_image_setup_split_common(lw, 3);
2424 gtk_widget_get_allocation(lw->utility_paned, &allocation);
2426 hpaned1 = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2427 DEBUG_NAME(hpaned1);
2428 hpaned2 = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2429 DEBUG_NAME(hpaned2);
2431 if (lw->bar && gtk_widget_get_visible(lw->bar))
2433 pane_pos = (gtk_paned_get_position(GTK_PANED(lw->utility_paned))) / 3;
2437 pane_pos = allocation.width / 3;
2440 gtk_paned_set_position(GTK_PANED(hpaned1), pane_pos);
2441 gtk_paned_set_position(GTK_PANED(hpaned2), pane_pos);
2443 gtk_paned_pack1(GTK_PANED(hpaned1), lw->split_images[0]->widget, TRUE, TRUE);
2444 gtk_paned_pack1(GTK_PANED(hpaned2), lw->split_images[1]->widget, TRUE, TRUE);
2445 gtk_paned_pack2(GTK_PANED(hpaned2), lw->split_images[2]->widget, TRUE, TRUE);
2446 gtk_paned_pack2(GTK_PANED(hpaned1), hpaned2, TRUE, TRUE);
2448 for (i = 0; i < 3; i++)
2450 gtk_widget_show(lw->split_images[i]->widget);
2453 gtk_widget_show(hpaned1);
2454 gtk_widget_show(hpaned2);
2456 lw->split_image_widget = hpaned1;
2458 return lw->split_image_widget;
2461 GtkWidget *layout_image_setup_split_quad(LayoutWindow *lw)
2468 lw->split_mode = SPLIT_QUAD;
2470 layout_image_setup_split_common(lw, 4);
2472 hpaned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2474 vpaned1 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
2475 DEBUG_NAME(vpaned1);
2476 vpaned2 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
2477 DEBUG_NAME(vpaned2);
2479 gtk_paned_pack1(GTK_PANED(vpaned1), lw->split_images[0]->widget, TRUE, TRUE);
2480 gtk_paned_pack2(GTK_PANED(vpaned1), lw->split_images[2]->widget, TRUE, TRUE);
2482 gtk_paned_pack1(GTK_PANED(vpaned2), lw->split_images[1]->widget, TRUE, TRUE);
2483 gtk_paned_pack2(GTK_PANED(vpaned2), lw->split_images[3]->widget, TRUE, TRUE);
2485 gtk_paned_pack1(GTK_PANED(hpaned), vpaned1, TRUE, TRUE);
2486 gtk_paned_pack2(GTK_PANED(hpaned), vpaned2, TRUE, TRUE);
2488 for (i = 0; i < 4; i++)
2489 gtk_widget_show(lw->split_images[i]->widget);
2491 gtk_widget_show(vpaned1);
2492 gtk_widget_show(vpaned2);
2494 lw->split_image_widget = hpaned;
2496 return lw->split_image_widget;
2500 GtkWidget *layout_image_setup_split(LayoutWindow *lw, ImageSplitMode mode)
2505 return layout_image_setup_split_hv(lw, TRUE);
2507 return layout_image_setup_split_hv(lw, FALSE);
2509 return layout_image_setup_split_triple(lw);
2511 return layout_image_setup_split_quad(lw);
2514 return layout_image_setup_split_none(lw);
2520 *-----------------------------------------------------------------------------
2521 * maintenance (for rename, move, remove)
2522 *-----------------------------------------------------------------------------
2525 static void layout_image_maint_renamed(LayoutWindow *lw, FileData *fd)
2527 if (fd == layout_image_get_fd(lw))
2529 image_set_fd(lw->image, fd);
2533 static void layout_image_maint_removed(LayoutWindow *lw, FileData *fd)
2535 if (fd == layout_image_get_fd(lw))
2540 cd = image_get_collection(lw->image, &info);
2543 CollectInfo *next_collection;
2545 next_collection = collection_next_by_info(cd, info);
2546 if (!next_collection) next_collection = collection_prev_by_info(cd, info);
2548 if (next_collection)
2550 layout_image_set_collection(lw, cd, next_collection);
2553 layout_image_set_fd(lw, nullptr);
2556 /* the image will be set to the next image from the list soon,
2557 setting it to NULL here is not necessary*/
2562 void layout_image_notify_cb(FileData *fd, NotifyType type, gpointer data)
2564 auto lw = static_cast<LayoutWindow *>(data);
2566 if (!(type & NOTIFY_CHANGE) || !fd->change) return;
2568 DEBUG_1("Notify layout_image: %s %04x", fd->path, type);
2570 switch (fd->change->type)
2572 case FILEDATA_CHANGE_MOVE:
2573 case FILEDATA_CHANGE_RENAME:
2574 layout_image_maint_renamed(lw, fd);
2576 case FILEDATA_CHANGE_DELETE:
2577 layout_image_maint_removed(lw, fd);
2579 case FILEDATA_CHANGE_COPY:
2580 case FILEDATA_CHANGE_UNSPECIFIED:
2581 case FILEDATA_CHANGE_WRITE_METADATA:
2586 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */