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"
63 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw);
64 static void layout_image_set_buttons(LayoutWindow *lw);
65 static gboolean layout_image_animate_new_file(LayoutWindow *lw);
66 static void layout_image_animate_update_image(LayoutWindow *lw);
69 *----------------------------------------------------------------------------
71 *----------------------------------------------------------------------------
73 #pragma GCC diagnostic push
74 #pragma GCC diagnostic ignored "-Wunused-function"
75 static void layout_image_overlay_toggle_unused(LayoutWindow *lw)
78 image_osd_toggle(lw->image);
80 #pragma GCC diagnostic pop
83 *----------------------------------------------------------------------------
85 *----------------------------------------------------------------------------
88 static void layout_image_full_screen_stop_func(FullScreenData *fs, gpointer data)
90 auto lw = static_cast<LayoutWindow *>(data);
92 /* restore image window */
93 if (lw->image == fs->imd)
94 lw->image = fs->normal_imd;
96 lw->full_screen = nullptr;
99 void layout_image_full_screen_start(LayoutWindow *lw)
101 if (!layout_valid(&lw)) return;
103 if (lw->full_screen) return;
105 lw->full_screen = fullscreen_start(lw->window, lw->image,
106 layout_image_full_screen_stop_func, lw);
108 /* set to new image window */
109 if (lw->full_screen->same_region)
110 lw->image = lw->full_screen->imd;
112 layout_image_set_buttons(lw);
114 g_signal_connect(G_OBJECT(lw->full_screen->window), "key_press_event",
115 G_CALLBACK(layout_key_press_cb), lw);
117 layout_actions_add_window(lw, lw->full_screen->window);
119 image_osd_copy_status(lw->full_screen->normal_imd, lw->image);
120 layout_image_animate_update_image(lw);
122 /** @FIXME This is a hack to fix #1037 Fullscreen loads black
123 * The problem occurs when zoom is set to Original Size.
124 * An extra reload is required to force the image to be displayed.
125 * See also image-view.cc real_view_window_new()
126 * This is probably not the correct solution.
128 image_reload(lw->image);
131 void layout_image_full_screen_stop(LayoutWindow *lw)
133 if (!layout_valid(&lw)) return;
134 if (!lw->full_screen) return;
136 if (lw->image == lw->full_screen->imd)
137 image_osd_copy_status(lw->image, lw->full_screen->normal_imd);
139 fullscreen_stop(lw->full_screen);
141 layout_image_animate_update_image(lw);
144 void layout_image_full_screen_toggle(LayoutWindow *lw)
146 if (!layout_valid(&lw)) return;
149 layout_image_full_screen_stop(lw);
153 layout_image_full_screen_start(lw);
157 gboolean layout_image_full_screen_active(LayoutWindow *lw)
159 if (!layout_valid(&lw)) return FALSE;
161 return (lw->full_screen != nullptr);
165 *----------------------------------------------------------------------------
167 *----------------------------------------------------------------------------
170 static void layout_image_slideshow_next(LayoutWindow *lw)
172 if (lw->slideshow) slideshow_next(lw->slideshow);
175 static void layout_image_slideshow_prev(LayoutWindow *lw)
177 if (lw->slideshow) slideshow_prev(lw->slideshow);
180 static void layout_image_slideshow_stop_func(SlideShowData *, gpointer data)
182 auto lw = static_cast<LayoutWindow *>(data);
184 lw->slideshow = nullptr;
185 layout_status_update_info(lw, nullptr);
188 void layout_image_slideshow_start(LayoutWindow *lw)
193 if (!layout_valid(&lw)) return;
194 if (lw->slideshow) return;
196 cd = image_get_collection(lw->image, &info);
200 lw->slideshow = slideshow_start_from_collection(lw, nullptr, cd,
201 layout_image_slideshow_stop_func, lw, info);
205 lw->slideshow = slideshow_start(lw,
206 layout_list_get_index(lw, layout_image_get_fd(lw)),
207 layout_image_slideshow_stop_func, lw);
210 layout_status_update_info(lw, nullptr);
213 /* note that slideshow will take ownership of the list, do not free it */
214 void layout_image_slideshow_start_from_list(LayoutWindow *lw, GList *list)
216 if (!layout_valid(&lw)) return;
218 if (lw->slideshow || !list)
224 lw->slideshow = slideshow_start_from_filelist(lw, nullptr, list,
225 layout_image_slideshow_stop_func, lw);
227 layout_status_update_info(lw, nullptr);
230 void layout_image_slideshow_stop(LayoutWindow *lw)
232 if (!layout_valid(&lw)) return;
234 if (!lw->slideshow) return;
236 slideshow_free(lw->slideshow);
237 /* the stop_func sets lw->slideshow to NULL for us */
240 void layout_image_slideshow_toggle(LayoutWindow *lw)
242 if (!layout_valid(&lw)) return;
246 layout_image_slideshow_stop(lw);
250 layout_image_slideshow_start(lw);
254 gboolean layout_image_slideshow_active(LayoutWindow *lw)
256 if (!layout_valid(&lw)) return FALSE;
258 return (lw->slideshow != nullptr);
261 gboolean layout_image_slideshow_pause_toggle(LayoutWindow *lw)
265 if (!layout_valid(&lw)) return FALSE;
267 ret = slideshow_pause_toggle(lw->slideshow);
269 layout_status_update_info(lw, nullptr);
274 gboolean layout_image_slideshow_paused(LayoutWindow *lw)
276 if (!layout_valid(&lw)) return FALSE;
278 return (slideshow_paused(lw->slideshow));
281 static gboolean layout_image_slideshow_continue_check(LayoutWindow *lw)
283 if (!lw->slideshow) return FALSE;
285 if (!slideshow_should_continue(lw->slideshow))
287 layout_image_slideshow_stop(lw);
295 *----------------------------------------------------------------------------
297 *----------------------------------------------------------------------------
304 GdkPixbufAnimation *gpa;
305 GdkPixbufAnimationIter *iter;
310 GCancellable *cancellable;
312 GFileInputStream *gfstream;
315 static void image_animation_data_free(AnimationData *fd)
318 if(fd->iter) g_object_unref(fd->iter);
319 if(fd->gpa) g_object_unref(fd->gpa);
320 if(fd->cancellable) g_object_unref(fd->cancellable);
324 static gboolean animation_should_continue(AnimationData *fd)
332 static gboolean show_next_frame(gpointer data)
334 auto fd = static_cast<AnimationData*>(data);
338 if(animation_should_continue(fd)==FALSE)
340 image_animation_data_free(fd);
344 pr = reinterpret_cast<PixbufRenderer*>(fd->iw->pr);
346 if (gdk_pixbuf_animation_iter_advance(fd->iter,nullptr)==FALSE)
348 /* This indicates the animation is complete.
349 Return FALSE here to disable looping. */
352 fd->gpb = gdk_pixbuf_animation_iter_get_pixbuf(fd->iter);
353 image_change_pixbuf(fd->iw,fd->gpb,pr->zoom,FALSE);
355 if (fd->iw->func_update)
356 fd->iw->func_update(fd->iw, fd->iw->data_update);
358 delay = gdk_pixbuf_animation_iter_get_delay_time(fd->iter);
359 if (delay!=fd->delay)
361 if (delay>0) /* Current frame not static. */
364 g_timeout_add(delay,show_next_frame,fd);
368 image_animation_data_free(fd);
376 static gboolean layout_image_animate_check(LayoutWindow *lw)
378 if (!layout_valid(&lw)) return FALSE;
380 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))
384 lw->animation->valid = FALSE;
385 if (lw->animation->cancellable)
387 g_cancellable_cancel(lw->animation->cancellable);
389 lw->animation = nullptr;
397 static void layout_image_animate_update_image(LayoutWindow *lw)
399 if (!layout_valid(&lw)) return;
401 if(lw->options.animate && lw->animation)
403 if (lw->full_screen && lw->image != lw->full_screen->imd)
404 lw->animation->iw = lw->full_screen->imd;
406 lw->animation->iw = lw->image;
411 static void animation_async_ready_cb(GObject *, GAsyncResult *res, gpointer data)
413 GError *error = nullptr;
414 auto animation = static_cast<AnimationData *>(data);
418 if (g_cancellable_is_cancelled(animation->cancellable))
420 gdk_pixbuf_animation_new_from_stream_finish(res, nullptr);
421 g_object_unref(animation->in_file);
422 g_object_unref(animation->gfstream);
423 image_animation_data_free(animation);
427 animation->gpa = gdk_pixbuf_animation_new_from_stream_finish(res, &error);
430 if (!gdk_pixbuf_animation_is_static_image(animation->gpa))
432 animation->iter = gdk_pixbuf_animation_get_iter(animation->gpa, nullptr);
435 animation->data_adr = animation->lw->image->image_fd;
436 animation->delay = gdk_pixbuf_animation_iter_get_delay_time(animation->iter);
437 animation->valid = TRUE;
439 layout_image_animate_update_image(animation->lw);
441 g_timeout_add(animation->delay, show_next_frame, animation);
447 log_printf("Error reading GIF file: %s\n", error->message);
450 g_object_unref(animation->in_file);
451 g_object_unref(animation->gfstream);
455 static gboolean layout_image_animate_new_file(LayoutWindow *lw)
457 GFileInputStream *gfstream;
458 GError *error = nullptr;
459 AnimationData *animation;
462 if(!layout_image_animate_check(lw)) return FALSE;
464 if(lw->animation) lw->animation->valid = FALSE;
468 g_cancellable_cancel(lw->animation->cancellable);
471 animation = g_new0(AnimationData, 1);
472 lw->animation = animation;
474 animation->cancellable = g_cancellable_new();
476 in_file = g_file_new_for_path(lw->image->image_fd->path);
477 animation->in_file = in_file;
478 gfstream = g_file_read(in_file, nullptr, &error);
481 animation->gfstream = gfstream;
482 gdk_pixbuf_animation_new_from_stream_async(reinterpret_cast<GInputStream*>(gfstream), animation->cancellable, animation_async_ready_cb, animation);
486 log_printf("Error reading animation file: %s\nError: %s\n", lw->image->image_fd->path, error->message);
492 void layout_image_animate_toggle(LayoutWindow *lw)
498 lw->options.animate = !lw->options.animate;
500 action = gtk_action_group_get_action(lw->action_group, "Animate");
501 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.animate);
503 layout_image_animate_new_file(lw);
507 *----------------------------------------------------------------------------
509 *----------------------------------------------------------------------------
512 static void li_pop_menu_zoom_in_cb(GtkWidget *, gpointer data)
514 auto lw = static_cast<LayoutWindow *>(data);
516 layout_image_zoom_adjust(lw, get_zoom_increment(), FALSE);
519 static void li_pop_menu_zoom_out_cb(GtkWidget *, gpointer data)
521 auto lw = static_cast<LayoutWindow *>(data);
522 layout_image_zoom_adjust(lw, -get_zoom_increment(), FALSE);
525 static void li_pop_menu_zoom_1_1_cb(GtkWidget *, gpointer data)
527 auto lw = static_cast<LayoutWindow *>(data);
529 layout_image_zoom_set(lw, 1.0, FALSE);
532 static void li_pop_menu_zoom_fit_cb(GtkWidget *, gpointer data)
534 auto lw = static_cast<LayoutWindow *>(data);
536 layout_image_zoom_set(lw, 0.0, FALSE);
539 static void li_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
542 auto key = static_cast<const gchar *>(data);
544 lw = static_cast<LayoutWindow *>(submenu_item_get_data(widget));
546 if (!editor_window_flag_set(key))
548 layout_image_full_screen_stop(lw);
550 file_util_start_editor_from_file(key, layout_image_get_fd(lw), lw->window);
553 static void li_pop_menu_alter_cb(GtkWidget *widget, gpointer data)
555 auto lw = static_cast<LayoutWindow *>(data);
558 lw = static_cast<LayoutWindow *>(submenu_item_get_data(widget));
559 type = static_cast<AlterType>GPOINTER_TO_INT(data);
561 image_alter_orientation(lw->image, lw->image->image_fd, type);
564 static void li_pop_menu_new_cb(GtkWidget *, gpointer data)
566 auto lw = static_cast<LayoutWindow *>(data);
568 view_window_new(layout_image_get_fd(lw));
571 static GtkWidget *li_pop_menu_click_parent(GtkWidget *widget, LayoutWindow *lw)
576 menu = gtk_widget_get_toplevel(widget);
577 if (!menu) return nullptr;
579 parent = static_cast<GtkWidget *>(g_object_get_data(G_OBJECT(menu), "click_parent"));
581 if (!parent && lw->full_screen)
583 parent = lw->full_screen->imd->widget;
589 static void li_pop_menu_copy_cb(GtkWidget *widget, gpointer data)
591 auto lw = static_cast<LayoutWindow *>(data);
593 file_util_copy(layout_image_get_fd(lw), nullptr, nullptr,
594 li_pop_menu_click_parent(widget, lw));
597 static void li_pop_menu_copy_path_cb(GtkWidget *, gpointer data)
599 auto lw = static_cast<LayoutWindow *>(data);
601 file_util_copy_path_to_clipboard(layout_image_get_fd(lw), TRUE, TRUE);
604 static void li_pop_menu_copy_path_unquoted_cb(GtkWidget *, gpointer data)
606 auto lw = static_cast<LayoutWindow *>(data);
608 file_util_copy_path_to_clipboard(layout_image_get_fd(lw), FALSE, TRUE);
611 static void li_pop_menu_cut_path_cb(GtkWidget *, gpointer data)
613 auto lw = static_cast<LayoutWindow *>(data);
615 file_util_copy_path_to_clipboard(layout_image_get_fd(lw), FALSE, FALSE);
619 static void li_pop_menu_copy_image_cb(GtkWidget *, gpointer data)
621 /* @FIXME GTK4 stub */
624 static void li_pop_menu_copy_image_cb(GtkWidget *, gpointer data)
626 auto lw = static_cast<LayoutWindow *>(data);
627 ImageWindow *imd = lw->image;
630 pixbuf = image_get_pixbuf(imd);
632 gtk_clipboard_set_image(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), pixbuf);
636 static void li_pop_menu_move_cb(GtkWidget *widget, gpointer data)
638 auto lw = static_cast<LayoutWindow *>(data);
640 file_util_move(layout_image_get_fd(lw), nullptr, nullptr,
641 li_pop_menu_click_parent(widget, lw));
644 static void li_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
646 auto lw = static_cast<LayoutWindow *>(data);
648 file_util_rename(layout_image_get_fd(lw), nullptr,
649 li_pop_menu_click_parent(widget, lw));
652 static void li_pop_menu_delete_cb(GtkWidget *widget, gpointer data)
654 auto lw = static_cast<LayoutWindow *>(data);
656 options->file_ops.safe_delete_enable = FALSE;
657 file_util_delete(layout_image_get_fd(lw), nullptr,
658 li_pop_menu_click_parent(widget, lw));
661 static void li_pop_menu_move_to_trash_cb(GtkWidget *widget, gpointer data)
663 auto lw = static_cast<LayoutWindow *>(data);
665 options->file_ops.safe_delete_enable = TRUE;
666 file_util_delete(layout_image_get_fd(lw), nullptr,
667 li_pop_menu_click_parent(widget, lw));
670 static void li_pop_menu_slide_start_cb(GtkWidget *, gpointer data)
672 auto lw = static_cast<LayoutWindow *>(data);
674 layout_image_slideshow_start(lw);
677 static void li_pop_menu_slide_stop_cb(GtkWidget *, gpointer data)
679 auto lw = static_cast<LayoutWindow *>(data);
681 layout_image_slideshow_stop(lw);
684 static void li_pop_menu_slide_pause_cb(GtkWidget *, gpointer data)
686 auto lw = static_cast<LayoutWindow *>(data);
688 layout_image_slideshow_pause_toggle(lw);
691 static void li_pop_menu_full_screen_cb(GtkWidget *, gpointer data)
693 auto lw = static_cast<LayoutWindow *>(data);
695 layout_image_full_screen_toggle(lw);
698 static void li_pop_menu_animate_cb(GtkWidget *, gpointer data)
700 auto lw = static_cast<LayoutWindow *>(data);
702 layout_image_animate_toggle(lw);
705 static void li_pop_menu_hide_cb(GtkWidget *, gpointer data)
707 auto lw = static_cast<LayoutWindow *>(data);
709 layout_tools_hide_toggle(lw);
712 static void li_set_layout_path_cb(GtkWidget *, gpointer data)
714 auto lw = static_cast<LayoutWindow *>(data);
717 if (!layout_valid(&lw)) return;
719 fd = layout_image_get_fd(lw);
720 if (fd) layout_set_fd(lw, fd);
723 static void li_open_archive_cb(GtkWidget *, gpointer data)
725 auto lw = static_cast<LayoutWindow *>(data);
726 LayoutWindow *lw_new;
729 if (!layout_valid(&lw)) return;
731 dest_dir = open_archive(layout_image_get_fd(lw));
734 lw_new = layout_new_from_default();
735 layout_set_path(lw_new, dest_dir);
740 warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GQ_ICON_DIALOG_WARNING, nullptr);
744 static gboolean li_check_if_current_path(LayoutWindow *lw, const gchar *path)
749 if (!path || !layout_valid(&lw) || !lw->dir_fd) return FALSE;
751 dirname = g_path_get_dirname(path);
752 ret = (strcmp(lw->dir_fd->path, dirname) == 0);
757 static void layout_image_popup_menu_destroy_cb(GtkWidget *, gpointer data)
759 auto editmenu_fd_list = static_cast<GList *>(data);
761 filelist_free(editmenu_fd_list);
764 static GList *layout_image_get_fd_list(LayoutWindow *lw)
766 GList *list = nullptr;
767 FileData *fd = layout_image_get_fd(lw);
772 /* optionally include sidecars if the filelist entry is not expanded */
773 list = vf_selection_get_one(lw->vf, fd);
775 list = g_list_append(nullptr, file_data_ref(fd));
782 * @brief Add file selection list to a collection
784 * @param[in] data Index to the collection list menu item selected, or -1 for new collection
788 static void layout_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
791 GList *selection_list = nullptr;
793 lw = static_cast<LayoutWindow *>(submenu_item_get_data(widget));
794 selection_list = g_list_append(selection_list, layout_image_get_fd(lw));
795 pop_menu_collections(selection_list, data);
797 filelist_free(selection_list);
800 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
807 GList *editmenu_fd_list;
808 GtkAccelGroup *accel_group;
810 path = layout_image_get_path(lw);
811 fullscreen = layout_image_full_screen_active(lw);
813 menu = popup_menu_short_lived();
815 accel_group = gtk_accel_group_new();
816 gtk_menu_set_accel_group(GTK_MENU(menu), accel_group);
818 g_object_set_data(G_OBJECT(menu), "window_keys", nullptr);
819 g_object_set_data(G_OBJECT(menu), "accel_group", accel_group);
821 menu_item_add_icon(menu, _("Zoom _in"), GQ_ICON_ZOOM_IN, G_CALLBACK(li_pop_menu_zoom_in_cb), lw);
822 menu_item_add_icon(menu, _("Zoom _out"), GQ_ICON_ZOOM_OUT, G_CALLBACK(li_pop_menu_zoom_out_cb), lw);
823 menu_item_add_icon(menu, _("Zoom _1:1"), GQ_ICON_ZOOM_100, G_CALLBACK(li_pop_menu_zoom_1_1_cb), lw);
824 menu_item_add_icon(menu, _("Zoom to fit"), GQ_ICON_ZOOM_FIT, G_CALLBACK(li_pop_menu_zoom_fit_cb), lw);
825 menu_item_add_divider(menu);
827 editmenu_fd_list = layout_image_get_fd_list(lw);
828 g_signal_connect(G_OBJECT(menu), "destroy",
829 G_CALLBACK(layout_image_popup_menu_destroy_cb), editmenu_fd_list);
830 submenu = submenu_add_edit(menu, &item, G_CALLBACK(li_pop_menu_edit_cb), lw, editmenu_fd_list);
831 if (!path) gtk_widget_set_sensitive(item, FALSE);
832 menu_item_add_divider(submenu);
833 item = submenu_add_alter(menu, G_CALLBACK(li_pop_menu_alter_cb), lw);
835 item = menu_item_add_icon(menu, _("View in _new window"), GQ_ICON_NEW, G_CALLBACK(li_pop_menu_new_cb), lw);
836 if (!path || fullscreen) gtk_widget_set_sensitive(item, FALSE);
838 item = menu_item_add(menu, _("_Go to directory view"), G_CALLBACK(li_set_layout_path_cb), lw);
839 if (!path || li_check_if_current_path(lw, path)) gtk_widget_set_sensitive(item, FALSE);
841 item = menu_item_add_icon(menu, _("Open archive"), GQ_ICON_OPEN, G_CALLBACK(li_open_archive_cb), lw);
842 if (!path || lw->image->image_fd->format_class != FORMAT_CLASS_ARCHIVE)
844 gtk_widget_set_sensitive(item, FALSE);
847 menu_item_add_divider(menu);
849 item = menu_item_add_icon(menu, _("_Copy..."), GQ_ICON_COPY, G_CALLBACK(li_pop_menu_copy_cb), lw);
850 if (!path) gtk_widget_set_sensitive(item, FALSE);
851 item = menu_item_add(menu, _("_Move..."), G_CALLBACK(li_pop_menu_move_cb), lw);
852 if (!path) gtk_widget_set_sensitive(item, FALSE);
853 item = menu_item_add(menu, _("_Rename..."), G_CALLBACK(li_pop_menu_rename_cb), lw);
854 if (!path) gtk_widget_set_sensitive(item, FALSE);
855 item = menu_item_add(menu, _("_Copy to clipboard"), G_CALLBACK(li_pop_menu_copy_path_cb), lw);
856 item = menu_item_add(menu, _("_Copy to clipboard (unquoted)"), G_CALLBACK(li_pop_menu_copy_path_unquoted_cb), lw);
857 item = menu_item_add(menu, _("Copy _image to clipboard"), G_CALLBACK(li_pop_menu_copy_image_cb), lw);
858 item = menu_item_add(menu, _("Cut to clipboard"), G_CALLBACK(li_pop_menu_cut_path_cb), lw);
859 if (!path) gtk_widget_set_sensitive(item, FALSE);
860 menu_item_add_divider(menu);
862 item = menu_item_add_icon(menu,
863 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
864 _("Move to Trash"), GQ_ICON_DELETE,
865 G_CALLBACK(li_pop_menu_move_to_trash_cb), lw);
866 if (!path) gtk_widget_set_sensitive(item, FALSE);
867 item = menu_item_add_icon(menu,
868 options->file_ops.confirm_delete ? _("_Delete...") :
869 _("_Delete"), GQ_ICON_DELETE_SHRED,
870 G_CALLBACK(li_pop_menu_delete_cb), lw);
871 if (!path) gtk_widget_set_sensitive(item, FALSE);
872 menu_item_add_divider(menu);
874 submenu = submenu_add_collections(menu, &item,
875 G_CALLBACK(layout_pop_menu_collections_cb), lw);
876 gtk_widget_set_sensitive(item, TRUE);
877 menu_item_add_divider(menu);
879 if (layout_image_slideshow_active(lw))
881 menu_item_add(menu, _("Toggle _slideshow"), G_CALLBACK(li_pop_menu_slide_stop_cb), lw);
882 if (layout_image_slideshow_paused(lw))
884 item = menu_item_add(menu, _("Continue slides_how"),
885 G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
889 item = menu_item_add(menu, _("Pause slides_how"),
890 G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
895 menu_item_add(menu, _("Toggle _slideshow"), G_CALLBACK(li_pop_menu_slide_start_cb), lw);
896 item = menu_item_add(menu, _("Pause slides_how"), G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
897 gtk_widget_set_sensitive(item, FALSE);
902 menu_item_add_icon(menu, _("_Full screen"), GQ_ICON_FULLSCREEN, G_CALLBACK(li_pop_menu_full_screen_cb), lw);
906 menu_item_add_icon(menu, _("Exit _full screen"), GQ_ICON_LEAVE_FULLSCREEN, G_CALLBACK(li_pop_menu_full_screen_cb), lw);
909 menu_item_add_check(menu, _("GIF _animation"), lw->options.animate, G_CALLBACK(li_pop_menu_animate_cb), lw);
911 menu_item_add_divider(menu);
913 item = menu_item_add_check(menu, _("Hide file _list"), lw->options.tools_hidden,
914 G_CALLBACK(li_pop_menu_hide_cb), lw);
916 item = menu_item_add_check(menu, _("Hide Selectable Bars"), lw->options.selectable_toolbars_hidden, G_CALLBACK(layout_selectable_toolbars_toggle), lw);
917 if (fullscreen) gtk_widget_set_sensitive(item, FALSE);
922 void layout_image_menu_popup(LayoutWindow *lw)
926 menu = layout_image_pop_menu(lw);
927 gtk_menu_popup_at_widget(GTK_MENU(menu), lw->image->widget, GDK_GRAVITY_EAST, GDK_GRAVITY_CENTER, nullptr);
931 *----------------------------------------------------------------------------
933 *----------------------------------------------------------------------------
936 static void layout_image_dnd_receive(GtkWidget *widget, GdkDragContext *,
938 GtkSelectionData *selection_data, guint info,
939 guint, gpointer data)
941 auto lw = static_cast<LayoutWindow *>(data);
946 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
948 if (lw->split_images[i] && lw->split_images[i]->pr == widget)
951 if (i < MAX_SPLIT_IMAGES)
953 DEBUG_1("dnd image activate %d", i);
954 layout_image_activate(lw, i, FALSE);
957 if (info == TARGET_TEXT_PLAIN)
959 url = g_strdup(reinterpret_cast<const gchar *>(gtk_selection_data_get_data(selection_data)));
960 download_web_file(url, FALSE, lw);
963 else if (info == TARGET_URI_LIST || info == TARGET_APP_COLLECTION_MEMBER)
965 CollectionData *source;
969 if (info == TARGET_URI_LIST)
971 list = uri_filelist_from_gtk_selection_data(selection_data);
977 source = collection_from_dnd_data(reinterpret_cast<const gchar *>(gtk_selection_data_get_data(selection_data)), &list, &info_list);
982 auto fd = static_cast<FileData *>(list->data);
984 if (isfile(fd->path))
990 base = remove_level_from_path(fd->path);
991 dir_fd = file_data_new_dir(base);
992 if (dir_fd != lw->dir_fd)
994 layout_set_fd(lw, dir_fd);
996 file_data_unref(dir_fd);
999 row = layout_list_get_index(lw, fd);
1000 if (source && info_list)
1002 layout_image_set_collection(lw, source, static_cast<CollectInfo *>(info_list->data));
1006 layout_image_set_fd(lw, fd);
1010 layout_image_set_index(lw, row);
1013 else if (isdir(fd->path))
1015 layout_set_fd(lw, fd);
1016 layout_image_set_fd(lw, nullptr);
1020 filelist_free(list);
1021 g_list_free(info_list);
1025 static void layout_image_dnd_get(GtkWidget *widget, GdkDragContext *,
1026 GtkSelectionData *selection_data, guint,
1027 guint, gpointer data)
1029 auto lw = static_cast<LayoutWindow *>(data);
1034 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1036 if (lw->split_images[i] && lw->split_images[i]->pr == widget)
1039 if (i < MAX_SPLIT_IMAGES)
1041 DEBUG_1("dnd get from %d", i);
1042 fd = image_get_fd(lw->split_images[i]);
1045 fd = layout_image_get_fd(lw);
1051 list = g_list_append(nullptr, fd);
1052 uri_selection_data_set_uris_from_filelist(selection_data, list);
1057 gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
1062 static void layout_image_dnd_end(GtkWidget *, GdkDragContext *context, gpointer data)
1064 auto lw = static_cast<LayoutWindow *>(data);
1065 if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
1070 fd = layout_image_get_fd(lw);
1071 row = layout_list_get_index(lw, fd);
1072 if (row < 0) return;
1074 if (!isfile(fd->path))
1076 if (static_cast<guint>(row) < layout_list_count(lw, nullptr) - 1)
1078 layout_image_next(lw);
1082 layout_image_prev(lw);
1089 static void layout_image_dnd_init(LayoutWindow *lw, gint i)
1091 ImageWindow *imd = lw->split_images[i];
1093 gtk_drag_source_set(imd->pr, GDK_BUTTON2_MASK,
1094 dnd_file_drag_types, dnd_file_drag_types_count,
1095 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
1096 g_signal_connect(G_OBJECT(imd->pr), "drag_data_get",
1097 G_CALLBACK(layout_image_dnd_get), lw);
1098 g_signal_connect(G_OBJECT(imd->pr), "drag_end",
1099 G_CALLBACK(layout_image_dnd_end), lw);
1101 gtk_drag_dest_set(imd->pr,
1102 static_cast<GtkDestDefaults>(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP),
1103 dnd_file_drop_types, dnd_file_drop_types_count,
1104 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
1105 g_signal_connect(G_OBJECT(imd->pr), "drag_data_received",
1106 G_CALLBACK(layout_image_dnd_receive), lw);
1111 *----------------------------------------------------------------------------
1113 *----------------------------------------------------------------------------
1116 void layout_image_to_root(LayoutWindow *lw)
1118 image_to_root_window(lw->image, (image_zoom_get(lw->image) == 0));
1122 *----------------------------------------------------------------------------
1123 * manipulation + accessors
1124 *----------------------------------------------------------------------------
1127 void layout_image_scroll(LayoutWindow *lw, gint x, gint y, gboolean connect_scroll)
1130 if (!layout_valid(&lw)) return;
1132 image_scroll(lw->image, x, y);
1134 if (lw->full_screen && lw->image != lw->full_screen->imd)
1136 image_scroll(lw->full_screen->imd, x, y);
1139 if (!connect_scroll) return;
1141 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1143 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1145 image_scroll(lw->split_images[i], x, y);
1151 void layout_image_zoom_adjust(LayoutWindow *lw, gdouble increment, gboolean connect_zoom)
1154 if (!layout_valid(&lw)) return;
1156 image_zoom_adjust(lw->image, increment);
1158 if (lw->full_screen && lw->image != lw->full_screen->imd)
1160 image_zoom_adjust(lw->full_screen->imd, increment);
1163 if (!connect_zoom) return;
1165 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1167 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1168 image_zoom_adjust(lw->split_images[i], increment); ;
1172 void layout_image_zoom_adjust_at_point(LayoutWindow *lw, gdouble increment, gint x, gint y, gboolean connect_zoom)
1175 if (!layout_valid(&lw)) return;
1177 image_zoom_adjust_at_point(lw->image, increment, x, y);
1179 if (lw->full_screen && lw->image != lw->full_screen->imd)
1181 image_zoom_adjust_at_point(lw->full_screen->imd, increment, x, y);
1183 if (!connect_zoom && !lw->split_mode) return;
1185 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1187 if (lw->split_images[i] && lw->split_images[i] != lw->image &&
1188 lw->split_images[i]->mouse_wheel_mode)
1189 image_zoom_adjust_at_point(lw->split_images[i], increment, x, y);
1193 void layout_image_zoom_set(LayoutWindow *lw, gdouble zoom, gboolean connect_zoom)
1196 if (!layout_valid(&lw)) return;
1198 image_zoom_set(lw->image, zoom);
1200 if (lw->full_screen && lw->image != lw->full_screen->imd)
1202 image_zoom_set(lw->full_screen->imd, zoom);
1205 if (!connect_zoom) return;
1207 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1209 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1210 image_zoom_set(lw->split_images[i], zoom);
1214 void layout_image_zoom_set_fill_geometry(LayoutWindow *lw, gboolean vertical, gboolean connect_zoom)
1217 if (!layout_valid(&lw)) return;
1219 image_zoom_set_fill_geometry(lw->image, vertical);
1221 if (lw->full_screen && lw->image != lw->full_screen->imd)
1223 image_zoom_set_fill_geometry(lw->full_screen->imd, vertical);
1226 if (!connect_zoom) return;
1228 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1230 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1231 image_zoom_set_fill_geometry(lw->split_images[i], vertical);
1235 void layout_image_alter_orientation(LayoutWindow *lw, AlterType type)
1237 if (!layout_valid(&lw)) return;
1239 GtkTreeModel *store;
1241 GtkTreeSelection *selection;
1246 if (!lw || !lw->vf) return;
1248 if (lw->vf->type == FILEVIEW_ICON)
1250 if (!VFICON(lw->vf)->selection) return;
1251 work = VFICON(lw->vf)->selection;
1255 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
1256 work = gtk_tree_selection_get_selected_rows(selection, &store);
1261 if (lw->vf->type == FILEVIEW_ICON)
1263 fd_n = static_cast<FileData *>(work->data);
1268 tpath = static_cast<GtkTreePath *>(work->data);
1269 gtk_tree_model_get_iter(store, &iter, tpath);
1270 gtk_tree_model_get(store, &iter, VIEW_FILE_COLUMN_POINTER, &fd_n, -1);
1274 image_alter_orientation(lw->image, fd_n, type);
1278 static void image_alter_rating(FileData *fd_n, const gchar *rating)
1280 metadata_write_string(fd_n, RATING_KEY, rating);
1281 read_rating_data(fd_n);
1284 void layout_image_rating(LayoutWindow *lw, const gchar *rating)
1286 if (!layout_valid(&lw)) return;
1288 GtkTreeModel *store;
1290 GtkTreeSelection *selection;
1295 if (!lw || !lw->vf) return;
1297 if (lw->vf->type == FILEVIEW_ICON)
1299 if (!VFICON(lw->vf)->selection) return;
1300 work = VFICON(lw->vf)->selection;
1304 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
1305 work = gtk_tree_selection_get_selected_rows(selection, &store);
1310 if (lw->vf->type == FILEVIEW_ICON)
1312 fd_n = static_cast<FileData *>(work->data);
1317 tpath = static_cast<GtkTreePath *>(work->data);
1318 gtk_tree_model_get_iter(store, &iter, tpath);
1319 gtk_tree_model_get(store, &iter, VIEW_FILE_COLUMN_POINTER, &fd_n, -1);
1323 image_alter_rating(fd_n, rating);
1327 void layout_image_reset_orientation(LayoutWindow *lw)
1329 ImageWindow *imd= lw->image;
1331 if (!layout_valid(&lw)) return;
1332 if (!imd || !imd->pr || !imd->image_fd) return;
1334 if (imd->orientation < 1 || imd->orientation > 8) imd->orientation = 1;
1336 if (options->image.exif_rotate_enable)
1338 if (g_strcmp0(imd->image_fd->format_name, "heif") != 0)
1340 imd->orientation = metadata_read_int(imd->image_fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
1344 imd->orientation = EXIF_ORIENTATION_TOP_LEFT;
1349 imd->orientation = 1;
1352 if (imd->image_fd->user_orientation != 0)
1354 imd->orientation = imd->image_fd->user_orientation;
1357 pixbuf_renderer_set_orientation(reinterpret_cast<PixbufRenderer *>(imd->pr), imd->orientation);
1360 void layout_image_set_desaturate(LayoutWindow *lw, gboolean desaturate)
1362 if (!layout_valid(&lw)) return;
1364 image_set_desaturate(lw->image, desaturate);
1367 gboolean layout_image_get_desaturate(LayoutWindow *lw)
1369 if (!layout_valid(&lw)) return FALSE;
1371 return image_get_desaturate(lw->image);
1374 void layout_image_set_overunderexposed(LayoutWindow *lw, gboolean overunderexposed)
1376 if (!layout_valid(&lw)) return;
1378 image_set_overunderexposed(lw->image, overunderexposed);
1381 #pragma GCC diagnostic push
1382 #pragma GCC diagnostic ignored "-Wunused-function"
1383 gboolean layout_image_get_overunderexposed_unused(LayoutWindow *lw)
1385 if (!layout_valid(&lw)) return FALSE;
1387 // return image_get_overunderexposed(lw->image);
1390 #pragma GCC diagnostic pop
1392 void layout_image_set_ignore_alpha(LayoutWindow *lw, gboolean ignore_alpha)
1394 if (!layout_valid(&lw)) return;
1396 lw->options.ignore_alpha = ignore_alpha;
1397 image_set_ignore_alpha(lw->image, ignore_alpha);
1401 #pragma GCC diagnostic push
1402 #pragma GCC diagnostic ignored "-Wunused-function"
1403 gint layout_image_stereo_get_unused(LayoutWindow *lw)
1405 if (!layout_valid(&lw)) return 0;
1407 // return image_stereo_get(lw->image);
1411 void layout_image_stereo_set_unused(LayoutWindow *lw, gint stereo_mode)
1413 if (!layout_valid(&lw)) return;
1415 image_stereo_set(lw->image, stereo_mode);
1417 void layout_image_stereo_swap_unused(LayoutWindow *lw)
1419 if (!layout_valid(&lw)) return;
1421 // image_stereo_swap(lw->image);
1423 #pragma GCC diagnostic pop
1425 gint layout_image_stereo_pixbuf_get(LayoutWindow *lw)
1427 if (!layout_valid(&lw)) return 0;
1429 return image_stereo_pixbuf_get(lw->image);
1432 void layout_image_stereo_pixbuf_set(LayoutWindow *lw, gint stereo_mode)
1434 if (!layout_valid(&lw)) return;
1436 image_stereo_pixbuf_set(lw->image, static_cast<StereoPixbufData>(stereo_mode));
1439 const gchar *layout_image_get_path(LayoutWindow *lw)
1441 if (!layout_valid(&lw)) return nullptr;
1443 return image_get_path(lw->image);
1446 #pragma GCC diagnostic push
1447 #pragma GCC diagnostic ignored "-Wunused-function"
1448 const gchar *layout_image_get_name_unused(LayoutWindow *lw)
1450 if (!layout_valid(&lw)) return nullptr;
1452 return image_get_name(lw->image);
1454 #pragma GCC diagnostic pop
1456 FileData *layout_image_get_fd(LayoutWindow *lw)
1458 if (!layout_valid(&lw)) return nullptr;
1460 return image_get_fd(lw->image);
1463 CollectionData *layout_image_get_collection(LayoutWindow *lw, CollectInfo **info)
1465 if (!layout_valid(&lw)) return nullptr;
1467 return image_get_collection(lw->image, info);
1470 gint layout_image_get_index(LayoutWindow *lw)
1472 return layout_list_get_index(lw, image_get_fd(lw->image));
1476 *----------------------------------------------------------------------------
1478 *----------------------------------------------------------------------------
1481 void layout_image_set_fd(LayoutWindow *lw, FileData *fd)
1483 if (!layout_valid(&lw)) return;
1485 image_change_fd(lw->image, fd, image_zoom_get_default(lw->image));
1487 if (lw->full_screen && lw->image != lw->full_screen->imd)
1489 image_change_fd(lw->full_screen->imd, fd, image_zoom_get_default(lw->full_screen->imd));
1493 layout_list_sync_fd(lw, fd);
1494 layout_image_slideshow_continue_check(lw);
1495 layout_bars_new_image(lw);
1496 layout_image_animate_new_file(lw);
1500 image_chain_append_end(fd->path);
1504 void layout_image_set_with_ahead(LayoutWindow *lw, FileData *fd, FileData *read_ahead_fd)
1506 if (!layout_valid(&lw)) return;
1508 /** @FIXME This should be handled at the caller: in vflist_select_image
1511 const gchar *old_path;
1513 old_path = layout_image_get_path(lw);
1514 if (old_path && strcmp(path, old_path) == 0) return;
1517 layout_image_set_fd(lw, fd);
1518 if (options->image.enable_read_ahead) image_prebuffer_set(lw->image, read_ahead_fd);
1521 void layout_image_set_index(LayoutWindow *lw, gint index)
1524 FileData *read_ahead_fd;
1527 if (!layout_valid(&lw)) return;
1529 old = layout_list_get_index(lw, layout_image_get_fd(lw));
1530 fd = layout_list_get_fd(lw, index);
1534 read_ahead_fd = layout_list_get_fd(lw, index - 1);
1538 read_ahead_fd = layout_list_get_fd(lw, index + 1);
1541 if (layout_selection_count(lw, nullptr) > 1)
1543 GList *x = layout_selection_list_by_index(lw);
1547 for (last = y = x; y; y = y->next)
1549 for (y = x; y && (GPOINTER_TO_INT(y->data)) != index; y = y->next)
1556 if ((index > old && (index != GPOINTER_TO_INT(last->data) || old != GPOINTER_TO_INT(x->data)))
1557 || (old == GPOINTER_TO_INT(last->data) && index == GPOINTER_TO_INT(x->data)))
1560 newindex = GPOINTER_TO_INT(y->next->data);
1562 newindex = GPOINTER_TO_INT(x->data);
1567 newindex = GPOINTER_TO_INT(y->prev->data);
1569 newindex = GPOINTER_TO_INT(last->data);
1572 read_ahead_fd = layout_list_get_fd(lw, newindex);
1576 x = g_list_remove(x, x->data);
1579 layout_image_set_with_ahead(lw, fd, read_ahead_fd);
1582 static void layout_image_set_collection_real(LayoutWindow *lw, CollectionData *cd, CollectInfo *info, gboolean forward)
1584 if (!layout_valid(&lw)) return;
1586 image_change_from_collection(lw->image, cd, info, image_zoom_get_default(lw->image));
1587 if (options->image.enable_read_ahead)
1589 CollectInfo *r_info;
1592 r_info = collection_next_by_info(cd, info);
1593 if (!r_info) r_info = collection_prev_by_info(cd, info);
1597 r_info = collection_prev_by_info(cd, info);
1598 if (!r_info) r_info = collection_next_by_info(cd, info);
1600 if (r_info) image_prebuffer_set(lw->image, r_info->fd);
1603 layout_image_slideshow_continue_check(lw);
1604 layout_bars_new_image(lw);
1607 void layout_image_set_collection(LayoutWindow *lw, CollectionData *cd, CollectInfo *info)
1609 layout_image_set_collection_real(lw, cd, info, TRUE);
1610 layout_list_sync_fd(lw, layout_image_get_fd(lw));
1613 void layout_image_refresh(LayoutWindow *lw)
1615 if (!layout_valid(&lw)) return;
1617 image_reload(lw->image);
1620 void layout_image_color_profile_set(LayoutWindow *lw,
1624 if (!layout_valid(&lw)) return;
1626 image_color_profile_set(lw->image, input_type, use_image);
1629 gboolean layout_image_color_profile_get(LayoutWindow *lw,
1631 gboolean *use_image)
1633 if (!layout_valid(&lw)) return FALSE;
1635 return image_color_profile_get(lw->image, input_type, use_image);
1638 void layout_image_color_profile_set_use(LayoutWindow *lw, gboolean enable)
1640 if (!layout_valid(&lw)) return;
1642 image_color_profile_set_use(lw->image, enable);
1645 gboolean layout_image_color_profile_get_use(LayoutWindow *lw)
1647 if (!layout_valid(&lw)) return FALSE;
1649 return image_color_profile_get_use(lw->image);
1652 gboolean layout_image_color_profile_get_status(LayoutWindow *lw, gchar **image_profile, gchar **screen_profile)
1654 if (!layout_valid(&lw)) return FALSE;
1656 return image_color_profile_get_status(lw->image, image_profile, screen_profile);
1660 *----------------------------------------------------------------------------
1662 *----------------------------------------------------------------------------
1665 void layout_image_next(LayoutWindow *lw)
1671 if (!layout_valid(&lw)) return;
1673 if (layout_image_slideshow_active(lw))
1675 layout_image_slideshow_next(lw);
1679 if (layout_selection_count(lw, nullptr) > 1)
1681 GList *x = layout_selection_list_by_index(lw);
1682 gint old = layout_list_get_index(lw, layout_image_get_fd(lw));
1685 for (y = x; y && (GPOINTER_TO_INT(y->data)) != old; y = y->next)
1690 layout_image_set_index(lw, GPOINTER_TO_INT(y->next->data));
1693 if (options->circular_selection_lists)
1695 layout_image_set_index(lw, GPOINTER_TO_INT(x->data));
1700 x = g_list_remove(x, x->data);
1701 if (y) /* not dereferenced */
1705 cd = image_get_collection(lw->image, &info);
1709 info = collection_next_by_info(cd, info);
1712 layout_image_set_collection_real(lw, cd, info, TRUE);
1716 image_osd_icon(lw->image, IMAGE_OSD_LAST, -1);
1721 current = layout_image_get_index(lw);
1725 if (static_cast<guint>(current) < layout_list_count(lw, nullptr) - 1)
1727 layout_image_set_index(lw, current + 1);
1731 image_osd_icon(lw->image, IMAGE_OSD_LAST, -1);
1736 layout_image_set_index(lw, 0);
1740 void layout_image_prev(LayoutWindow *lw)
1746 if (!layout_valid(&lw)) return;
1748 if (layout_image_slideshow_active(lw))
1750 layout_image_slideshow_prev(lw);
1754 if (layout_selection_count(lw, nullptr) > 1)
1756 GList *x = layout_selection_list_by_index(lw);
1757 gint old = layout_list_get_index(lw, layout_image_get_fd(lw));
1761 for (last = y = x; y; y = y->next)
1763 for (y = x; y && (GPOINTER_TO_INT(y->data)) != old; y = y->next)
1768 layout_image_set_index(lw, GPOINTER_TO_INT(y->prev->data));
1771 if (options->circular_selection_lists)
1773 layout_image_set_index(lw, GPOINTER_TO_INT(last->data));
1778 x = g_list_remove(x, x->data);
1779 if (y) /* not dereferenced */
1783 cd = image_get_collection(lw->image, &info);
1787 info = collection_prev_by_info(cd, info);
1790 layout_image_set_collection_real(lw, cd, info, FALSE);
1794 image_osd_icon(lw->image, IMAGE_OSD_FIRST, -1);
1799 current = layout_image_get_index(lw);
1805 layout_image_set_index(lw, current - 1);
1809 image_osd_icon(lw->image, IMAGE_OSD_FIRST, -1);
1814 layout_image_set_index(lw, layout_list_count(lw, nullptr) - 1);
1818 void layout_image_first(LayoutWindow *lw)
1824 if (!layout_valid(&lw)) return;
1826 cd = image_get_collection(lw->image, &info);
1830 CollectInfo *first_collection;
1831 first_collection = collection_get_first(cd);
1832 if (first_collection != info)
1834 layout_image_set_collection_real(lw, cd, first_collection, TRUE);
1839 current = layout_image_get_index(lw);
1840 if (current != 0 && layout_list_count(lw, nullptr) > 0)
1842 layout_image_set_index(lw, 0);
1846 void layout_image_last(LayoutWindow *lw)
1853 if (!layout_valid(&lw)) return;
1855 cd = image_get_collection(lw->image, &info);
1859 CollectInfo *last_collection;
1860 last_collection = collection_get_last(cd);
1861 if (last_collection != info)
1863 layout_image_set_collection_real(lw, cd, last_collection, FALSE);
1868 current = layout_image_get_index(lw);
1869 count = layout_list_count(lw, nullptr);
1870 if (current != count - 1 && count > 0)
1872 layout_image_set_index(lw, count - 1);
1877 *----------------------------------------------------------------------------
1879 *----------------------------------------------------------------------------
1882 static gint image_idx(LayoutWindow *lw, ImageWindow *imd)
1886 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1888 if (lw->split_images[i] == imd)
1891 if (i < MAX_SPLIT_IMAGES)
1898 static void layout_image_focus_in_cb(ImageWindow *imd, gpointer data)
1900 auto lw = static_cast<LayoutWindow *>(data);
1902 gint i = image_idx(lw, imd);
1906 DEBUG_1("image activate focus_in %d", i);
1907 layout_image_activate(lw, i, FALSE);
1912 static void layout_image_button_cb(ImageWindow *imd, GdkEventButton *event, gpointer data)
1914 auto lw = static_cast<LayoutWindow *>(data);
1916 LayoutWindow *lw_new;
1919 switch (event->button)
1921 case MOUSE_BUTTON_LEFT:
1922 if (event->button == MOUSE_BUTTON_LEFT && event->type == GDK_2BUTTON_PRESS)
1924 layout_image_full_screen_toggle(lw);
1927 else if (options->image_l_click_archive && imd-> image_fd && imd->image_fd->format_class == FORMAT_CLASS_ARCHIVE)
1929 dest_dir = open_archive(imd->image_fd);
1932 lw_new = layout_new_from_default();
1933 layout_set_path(lw_new, dest_dir);
1938 warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GQ_ICON_DIALOG_WARNING, nullptr);
1941 else if (options->image_l_click_video && options->image_l_click_video_editor && imd-> image_fd && imd->image_fd->format_class == FORMAT_CLASS_VIDEO)
1943 start_editor_from_file(options->image_l_click_video_editor, imd->image_fd);
1945 else if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
1946 layout_image_next(lw);
1948 case MOUSE_BUTTON_MIDDLE:
1949 if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
1950 layout_image_prev(lw);
1952 case MOUSE_BUTTON_RIGHT:
1953 menu = layout_image_pop_menu(lw);
1954 if (imd == lw->image)
1956 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
1958 gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr);
1965 static void layout_image_scroll_cb(ImageWindow *imd, GdkEventScroll *event, gpointer data)
1967 auto lw = static_cast<LayoutWindow *>(data);
1969 gint i = image_idx(lw, imd);
1973 DEBUG_1("image activate scroll %d", i);
1974 layout_image_activate(lw, i, FALSE);
1978 if ((event->state & GDK_CONTROL_MASK) ||
1979 (imd->mouse_wheel_mode && !options->image_lm_click_nav))
1981 switch (event->direction)
1984 layout_image_zoom_adjust_at_point(lw, get_zoom_increment(), event->x, event->y, event->state & GDK_SHIFT_MASK);
1986 case GDK_SCROLL_DOWN:
1987 layout_image_zoom_adjust_at_point(lw, -get_zoom_increment(), event->x, event->y, event->state & GDK_SHIFT_MASK);
1993 else if (options->mousewheel_scrolls)
1995 switch (event->direction)
1998 image_scroll(imd, 0, -MOUSEWHEEL_SCROLL_SIZE);
2000 case GDK_SCROLL_DOWN:
2001 image_scroll(imd, 0, MOUSEWHEEL_SCROLL_SIZE);
2003 case GDK_SCROLL_LEFT:
2004 image_scroll(imd, -MOUSEWHEEL_SCROLL_SIZE, 0);
2006 case GDK_SCROLL_RIGHT:
2007 image_scroll(imd, MOUSEWHEEL_SCROLL_SIZE, 0);
2015 switch (event->direction)
2018 layout_image_prev(lw);
2020 case GDK_SCROLL_DOWN:
2021 layout_image_next(lw);
2029 static void layout_image_drag_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
2032 auto lw = static_cast<LayoutWindow *>(data);
2036 if (lw->full_screen && lw->image != lw->full_screen->imd &&
2037 imd != lw->full_screen->imd)
2039 if (event->state & GDK_CONTROL_MASK)
2041 image_get_scroll_center(imd, &sx, &sy);
2045 image_get_scroll_center(lw->full_screen->imd, &sx, &sy);
2049 image_set_scroll_center(lw->full_screen->imd, sx, sy);
2052 if (!(event->state & GDK_SHIFT_MASK)) return;
2054 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
2056 if (lw->split_images[i] && lw->split_images[i] != imd)
2059 if (event->state & GDK_CONTROL_MASK)
2061 image_get_scroll_center(imd, &sx, &sy);
2065 image_get_scroll_center(lw->split_images[i], &sx, &sy);
2069 image_set_scroll_center(lw->split_images[i], sx, sy);
2074 static void layout_image_button_inactive_cb(ImageWindow *imd, GdkEventButton *event, gpointer data)
2076 auto lw = static_cast<LayoutWindow *>(data);
2078 gint i = image_idx(lw, imd);
2082 layout_image_activate(lw, i, FALSE);
2085 switch (event->button)
2087 case MOUSE_BUTTON_RIGHT:
2088 menu = layout_image_pop_menu(lw);
2089 if (imd == lw->image)
2091 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
2093 gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr);
2101 static void layout_image_drag_inactive_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
2103 auto lw = static_cast<LayoutWindow *>(data);
2104 gint i = image_idx(lw, imd);
2108 layout_image_activate(lw, i, FALSE);
2111 /* continue as with active image */
2112 layout_image_drag_cb(imd, event, dx, dy, data);
2116 static void layout_image_set_buttons(LayoutWindow *lw)
2118 image_set_button_func(lw->image, layout_image_button_cb, lw);
2119 image_set_scroll_func(lw->image, layout_image_scroll_cb, lw);
2122 static void layout_image_set_buttons_inactive(LayoutWindow *lw, gint i)
2124 image_set_button_func(lw->split_images[i], layout_image_button_inactive_cb, lw);
2125 image_set_scroll_func(lw->split_images[i], layout_image_scroll_cb, lw);
2128 /* Returns the length of an integer */
2129 static gint num_length(gint num)
2132 if (num < 0) num = -num;
2141 void layout_status_update_pixel_cb(PixbufRenderer *pr, gpointer data)
2143 auto lw = static_cast<LayoutWindow *>(data);
2149 PangoAttrList *attrs;
2151 if (!data || !layout_valid(&lw) || !lw->image
2152 || !lw->options.show_info_pixel || lw->image->unknown) return;
2154 pixbuf_renderer_get_image_size(pr, &width, &height);
2155 if (width < 1 || height < 1) return;
2157 pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
2159 if(x_pixel >= 0 && y_pixel >= 0)
2165 pixbuf_renderer_get_pixel_colors(pr, x_pixel, y_pixel,
2166 &r_mouse, &g_mouse, &b_mouse);
2168 text = g_strdup_printf(_("[%*d,%*d]: RGB(%3d,%3d,%3d)"),
2169 num_length(width - 1), x_pixel,
2170 num_length(height - 1), y_pixel,
2171 r_mouse, g_mouse, b_mouse);
2176 text = g_strdup_printf(_("[%*s,%*s]: RGB(---,---,---)"),
2177 num_length(width - 1), " ",
2178 num_length(height - 1), " ");
2181 attrs = pango_attr_list_new();
2182 pango_attr_list_insert(attrs, pango_attr_family_new("Monospace"));
2183 gtk_label_set_text(GTK_LABEL(lw->info_pixel), text);
2184 gtk_label_set_attributes(GTK_LABEL(lw->info_pixel), attrs);
2185 pango_attr_list_unref(attrs);
2191 *----------------------------------------------------------------------------
2193 *----------------------------------------------------------------------------
2196 static void layout_image_update_cb(ImageWindow *, gpointer data)
2198 auto lw = static_cast<LayoutWindow *>(data);
2199 layout_status_update_image(lw);
2202 GtkWidget *layout_image_new(LayoutWindow *lw, gint i)
2204 if (!lw->split_image_sizegroup) lw->split_image_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
2206 if (!lw->split_images[i])
2208 lw->split_images[i] = image_new(TRUE);
2210 g_object_ref(lw->split_images[i]->widget);
2212 g_signal_connect(G_OBJECT(lw->split_images[i]->pr), "update-pixel",
2213 G_CALLBACK(layout_status_update_pixel_cb), lw);
2215 image_background_set_color_from_options(lw->split_images[i], FALSE);
2217 image_auto_refresh_enable(lw->split_images[i], TRUE);
2219 layout_image_dnd_init(lw, i);
2220 image_color_profile_set(lw->split_images[i],
2221 options->color_profile.input_type,
2222 options->color_profile.use_image);
2223 image_color_profile_set_use(lw->split_images[i], options->color_profile.enabled);
2225 gtk_size_group_add_widget(lw->split_image_sizegroup, lw->split_images[i]->widget);
2226 gtk_widget_set_size_request(lw->split_images[i]->widget, IMAGE_MIN_WIDTH, -1);
2228 image_set_focus_in_func(lw->split_images[i], layout_image_focus_in_cb, lw);
2232 return lw->split_images[i]->widget;
2235 void layout_image_deactivate(LayoutWindow *lw, gint i)
2237 if (!lw->split_images[i]) return;
2238 image_set_update_func(lw->split_images[i], nullptr, nullptr);
2239 layout_image_set_buttons_inactive(lw, i);
2240 image_set_drag_func(lw->split_images[i], layout_image_drag_inactive_cb, lw);
2242 image_attach_window(lw->split_images[i], nullptr, nullptr, nullptr, FALSE);
2243 image_select(lw->split_images[i], FALSE);
2246 /* force should be set after change of lw->split_mode */
2247 void layout_image_activate(LayoutWindow *lw, gint i, gboolean force)
2251 if (!lw->split_images[i]) return;
2252 if (!force && lw->active_split_image == i) return;
2254 /* deactivate currently active */
2255 if (lw->active_split_image != i)
2256 layout_image_deactivate(lw, lw->active_split_image);
2258 lw->image = lw->split_images[i];
2259 lw->active_split_image = i;
2261 image_set_update_func(lw->image, layout_image_update_cb, lw);
2262 layout_image_set_buttons(lw);
2263 image_set_drag_func(lw->image, layout_image_drag_cb, lw);
2265 image_attach_window(lw->image, lw->window, nullptr, GQ_APPNAME, FALSE);
2267 /* do not highlight selected image in SPLIT_NONE */
2268 /* maybe the image should be selected always and highlight should be controlled by
2269 another image option */
2270 if (lw->split_mode != SPLIT_NONE)
2271 image_select(lw->split_images[i], TRUE);
2273 image_select(lw->split_images[i], FALSE);
2275 fd = image_get_fd(lw->image);
2279 layout_set_fd(lw, fd);
2281 layout_status_update_image(lw);
2285 static void layout_image_setup_split_common(LayoutWindow *lw, gint n)
2287 gboolean frame = (n > 1) || (!lw->options.tools_float && !lw->options.tools_hidden);
2290 for (i = 0; i < n; i++)
2291 if (!lw->split_images[i])
2293 FileData *img_fd = nullptr;
2296 layout_image_new(lw, i);
2297 image_set_frame(lw->split_images[i], frame);
2298 image_set_selectable(lw->split_images[i], (n > 1));
2302 image_osd_copy_status(lw->image, lw->split_images[i]);
2305 if (layout_selection_count(lw, nullptr) > 1)
2307 GList *work = g_list_last(layout_selection_list(lw));
2310 while (work && j < i)
2312 auto fd = static_cast<FileData *>(work->data);
2315 if (!fd || !*fd->path || fd->parent ||
2316 fd == lw->split_images[0]->image_fd)
2326 if (!img_fd && lw->image)
2328 img_fd = image_get_fd(lw->image);
2329 zoom = image_zoom_get(lw->image);
2336 image_change_fd(lw->split_images[i], img_fd, zoom);
2337 image_get_scroll_center(lw->image, &sx, &sy);
2338 image_set_scroll_center(lw->split_images[i], sx, sy);
2340 layout_image_deactivate(lw, i);
2344 image_set_frame(lw->split_images[i], frame);
2345 image_set_selectable(lw->split_images[i], (n > 1));
2348 for (i = n; i < MAX_SPLIT_IMAGES; i++)
2350 if (lw->split_images[i])
2352 g_object_unref(lw->split_images[i]->widget);
2353 lw->split_images[i] = nullptr;
2357 if (!lw->image || lw->active_split_image < 0 || lw->active_split_image >= n)
2359 layout_image_activate(lw, 0, TRUE);
2363 /* this will draw the frame around selected image (image_select)
2364 on switch from single to split images */
2365 layout_image_activate(lw, lw->active_split_image, TRUE);
2369 GtkWidget *layout_image_setup_split_none(LayoutWindow *lw)
2371 lw->split_mode = SPLIT_NONE;
2373 layout_image_setup_split_common(lw, 1);
2375 lw->split_image_widget = lw->split_images[0]->widget;
2377 return lw->split_image_widget;
2381 GtkWidget *layout_image_setup_split_hv(LayoutWindow *lw, gboolean horizontal)
2385 lw->split_mode = horizontal ? SPLIT_HOR : SPLIT_VERT;
2387 layout_image_setup_split_common(lw, 2);
2389 /* horizontal split means vpaned and vice versa */
2390 paned = gtk_paned_new(horizontal ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
2393 gtk_paned_pack1(GTK_PANED(paned), lw->split_images[0]->widget, TRUE, TRUE);
2394 gtk_paned_pack2(GTK_PANED(paned), lw->split_images[1]->widget, TRUE, TRUE);
2396 gtk_widget_show(lw->split_images[0]->widget);
2397 gtk_widget_show(lw->split_images[1]->widget);
2399 lw->split_image_widget = paned;
2401 return lw->split_image_widget;
2405 static GtkWidget *layout_image_setup_split_triple(LayoutWindow *lw)
2409 GtkAllocation allocation;
2413 lw->split_mode = SPLIT_TRIPLE;
2415 layout_image_setup_split_common(lw, 3);
2417 gtk_widget_get_allocation(lw->utility_paned, &allocation);
2419 hpaned1 = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2420 DEBUG_NAME(hpaned1);
2421 hpaned2 = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2422 DEBUG_NAME(hpaned2);
2424 if (lw->bar && gtk_widget_get_visible(lw->bar))
2426 pane_pos = (gtk_paned_get_position(GTK_PANED(lw->utility_paned))) / 3;
2430 pane_pos = allocation.width / 3;
2433 gtk_paned_set_position(GTK_PANED(hpaned1), pane_pos);
2434 gtk_paned_set_position(GTK_PANED(hpaned2), pane_pos);
2436 gtk_paned_pack1(GTK_PANED(hpaned1), lw->split_images[0]->widget, TRUE, TRUE);
2437 gtk_paned_pack1(GTK_PANED(hpaned2), lw->split_images[1]->widget, TRUE, TRUE);
2438 gtk_paned_pack2(GTK_PANED(hpaned2), lw->split_images[2]->widget, TRUE, TRUE);
2439 gtk_paned_pack2(GTK_PANED(hpaned1), hpaned2, TRUE, TRUE);
2441 for (i = 0; i < 3; i++)
2443 gtk_widget_show(lw->split_images[i]->widget);
2446 gtk_widget_show(hpaned1);
2447 gtk_widget_show(hpaned2);
2449 lw->split_image_widget = hpaned1;
2451 return lw->split_image_widget;
2454 GtkWidget *layout_image_setup_split_quad(LayoutWindow *lw)
2461 lw->split_mode = SPLIT_QUAD;
2463 layout_image_setup_split_common(lw, 4);
2465 hpaned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2467 vpaned1 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
2468 DEBUG_NAME(vpaned1);
2469 vpaned2 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
2470 DEBUG_NAME(vpaned2);
2472 gtk_paned_pack1(GTK_PANED(vpaned1), lw->split_images[0]->widget, TRUE, TRUE);
2473 gtk_paned_pack2(GTK_PANED(vpaned1), lw->split_images[2]->widget, TRUE, TRUE);
2475 gtk_paned_pack1(GTK_PANED(vpaned2), lw->split_images[1]->widget, TRUE, TRUE);
2476 gtk_paned_pack2(GTK_PANED(vpaned2), lw->split_images[3]->widget, TRUE, TRUE);
2478 gtk_paned_pack1(GTK_PANED(hpaned), vpaned1, TRUE, TRUE);
2479 gtk_paned_pack2(GTK_PANED(hpaned), vpaned2, TRUE, TRUE);
2481 for (i = 0; i < 4; i++)
2482 gtk_widget_show(lw->split_images[i]->widget);
2484 gtk_widget_show(vpaned1);
2485 gtk_widget_show(vpaned2);
2487 lw->split_image_widget = hpaned;
2489 return lw->split_image_widget;
2493 GtkWidget *layout_image_setup_split(LayoutWindow *lw, ImageSplitMode mode)
2498 return layout_image_setup_split_hv(lw, TRUE);
2500 return layout_image_setup_split_hv(lw, FALSE);
2502 return layout_image_setup_split_triple(lw);
2504 return layout_image_setup_split_quad(lw);
2507 return layout_image_setup_split_none(lw);
2513 *-----------------------------------------------------------------------------
2514 * maintenance (for rename, move, remove)
2515 *-----------------------------------------------------------------------------
2518 static void layout_image_maint_renamed(LayoutWindow *lw, FileData *fd)
2520 if (fd == layout_image_get_fd(lw))
2522 image_set_fd(lw->image, fd);
2526 static void layout_image_maint_removed(LayoutWindow *lw, FileData *fd)
2528 if (fd == layout_image_get_fd(lw))
2533 cd = image_get_collection(lw->image, &info);
2536 CollectInfo *next_collection;
2538 next_collection = collection_next_by_info(cd, info);
2539 if (!next_collection) next_collection = collection_prev_by_info(cd, info);
2541 if (next_collection)
2543 layout_image_set_collection(lw, cd, next_collection);
2546 layout_image_set_fd(lw, nullptr);
2549 /* the image will be set to the next image from the list soon,
2550 setting it to NULL here is not necessary*/
2555 void layout_image_notify_cb(FileData *fd, NotifyType type, gpointer data)
2557 auto lw = static_cast<LayoutWindow *>(data);
2559 if (!(type & NOTIFY_CHANGE) || !fd->change) return;
2561 DEBUG_1("Notify layout_image: %s %04x", fd->path, type);
2563 switch (fd->change->type)
2565 case FILEDATA_CHANGE_MOVE:
2566 case FILEDATA_CHANGE_RENAME:
2567 layout_image_maint_renamed(lw, fd);
2569 case FILEDATA_CHANGE_DELETE:
2570 layout_image_maint_removed(lw, fd);
2572 case FILEDATA_CHANGE_COPY:
2573 case FILEDATA_CHANGE_UNSPECIFIED:
2574 case FILEDATA_CHANGE_WRITE_METADATA:
2579 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */