2 * Copyright (C) 2006 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "layout-image.h"
30 #include "fullscreen.h"
31 #include "history-list.h"
33 #include "image-overlay.h"
35 #include "layout-util.h"
39 #include "pixbuf-util.h"
40 #include "pixbuf-renderer.h"
41 #include "slideshow.h"
42 #include "ui-fileops.h"
44 #include "uri-utils.h"
46 #include "view-file.h"
48 #define FILE_COLUMN_POINTER 0
50 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw);
51 static void layout_image_set_buttons(LayoutWindow *lw);
52 static gboolean layout_image_animate_new_file(LayoutWindow *lw);
53 static void layout_image_animate_update_image(LayoutWindow *lw);
56 *----------------------------------------------------------------------------
58 *----------------------------------------------------------------------------
60 #pragma GCC diagnostic push
61 #pragma GCC diagnostic ignored "-Wunused-function"
62 static void layout_image_overlay_toggle_unused(LayoutWindow *lw)
65 image_osd_toggle(lw->image);
67 #pragma GCC diagnostic pop
70 *----------------------------------------------------------------------------
72 *----------------------------------------------------------------------------
75 static void layout_image_full_screen_stop_func(FullScreenData *fs, gpointer data)
77 auto lw = static_cast<LayoutWindow *>(data);
79 /* restore image window */
80 if (lw->image == fs->imd)
81 lw->image = fs->normal_imd;
83 lw->full_screen = nullptr;
86 void layout_image_full_screen_start(LayoutWindow *lw)
88 if (!layout_valid(&lw)) return;
90 if (lw->full_screen) return;
92 lw->full_screen = fullscreen_start(lw->window, lw->image,
93 layout_image_full_screen_stop_func, lw);
95 /* set to new image window */
96 if (lw->full_screen->same_region)
97 lw->image = lw->full_screen->imd;
99 layout_image_set_buttons(lw);
101 g_signal_connect(G_OBJECT(lw->full_screen->window), "key_press_event",
102 G_CALLBACK(layout_key_press_cb), lw);
104 layout_actions_add_window(lw, lw->full_screen->window);
106 image_osd_copy_status(lw->full_screen->normal_imd, lw->image);
107 layout_image_animate_update_image(lw);
109 /** @FIXME This is a hack to fix #1037 Fullscreen loads black
110 * The problem occurs when zoom is set to Original Size.
111 * An extra reload is required to force the image to be displayed.
112 * See also image-view.cc real_view_window_new()
113 * This is probably not the correct solution.
115 image_reload(lw->image);
118 void layout_image_full_screen_stop(LayoutWindow *lw)
120 if (!layout_valid(&lw)) return;
121 if (!lw->full_screen) return;
123 if (lw->image == lw->full_screen->imd)
124 image_osd_copy_status(lw->image, lw->full_screen->normal_imd);
126 fullscreen_stop(lw->full_screen);
128 layout_image_animate_update_image(lw);
131 void layout_image_full_screen_toggle(LayoutWindow *lw)
133 if (!layout_valid(&lw)) return;
136 layout_image_full_screen_stop(lw);
140 layout_image_full_screen_start(lw);
144 gboolean layout_image_full_screen_active(LayoutWindow *lw)
146 if (!layout_valid(&lw)) return FALSE;
148 return (lw->full_screen != nullptr);
152 *----------------------------------------------------------------------------
154 *----------------------------------------------------------------------------
157 static void layout_image_slideshow_next(LayoutWindow *lw)
159 if (lw->slideshow) slideshow_next(lw->slideshow);
162 static void layout_image_slideshow_prev(LayoutWindow *lw)
164 if (lw->slideshow) slideshow_prev(lw->slideshow);
167 static void layout_image_slideshow_stop_func(SlideShowData *, gpointer data)
169 auto lw = static_cast<LayoutWindow *>(data);
171 lw->slideshow = nullptr;
172 layout_status_update_info(lw, nullptr);
175 void layout_image_slideshow_start(LayoutWindow *lw)
180 if (!layout_valid(&lw)) return;
181 if (lw->slideshow) return;
183 cd = image_get_collection(lw->image, &info);
187 lw->slideshow = slideshow_start_from_collection(lw, nullptr, cd,
188 layout_image_slideshow_stop_func, lw, info);
192 lw->slideshow = slideshow_start(lw,
193 layout_list_get_index(lw, layout_image_get_fd(lw)),
194 layout_image_slideshow_stop_func, lw);
197 layout_status_update_info(lw, nullptr);
200 /* note that slideshow will take ownership of the list, do not free it */
201 void layout_image_slideshow_start_from_list(LayoutWindow *lw, GList *list)
203 if (!layout_valid(&lw)) return;
205 if (lw->slideshow || !list)
211 lw->slideshow = slideshow_start_from_filelist(lw, nullptr, list,
212 layout_image_slideshow_stop_func, lw);
214 layout_status_update_info(lw, nullptr);
217 void layout_image_slideshow_stop(LayoutWindow *lw)
219 if (!layout_valid(&lw)) return;
221 if (!lw->slideshow) return;
223 slideshow_free(lw->slideshow);
224 /* the stop_func sets lw->slideshow to NULL for us */
227 void layout_image_slideshow_toggle(LayoutWindow *lw)
229 if (!layout_valid(&lw)) return;
233 layout_image_slideshow_stop(lw);
237 layout_image_slideshow_start(lw);
241 gboolean layout_image_slideshow_active(LayoutWindow *lw)
243 if (!layout_valid(&lw)) return FALSE;
245 return (lw->slideshow != nullptr);
248 gboolean layout_image_slideshow_pause_toggle(LayoutWindow *lw)
252 if (!layout_valid(&lw)) return FALSE;
254 ret = slideshow_pause_toggle(lw->slideshow);
256 layout_status_update_info(lw, nullptr);
261 gboolean layout_image_slideshow_paused(LayoutWindow *lw)
263 if (!layout_valid(&lw)) return FALSE;
265 return (slideshow_paused(lw->slideshow));
268 static gboolean layout_image_slideshow_continue_check(LayoutWindow *lw)
270 if (!lw->slideshow) return FALSE;
272 if (!slideshow_should_continue(lw->slideshow))
274 layout_image_slideshow_stop(lw);
282 *----------------------------------------------------------------------------
284 *----------------------------------------------------------------------------
291 GdkPixbufAnimation *gpa;
292 GdkPixbufAnimationIter *iter;
297 GCancellable *cancellable;
299 GFileInputStream *gfstream;
302 static void image_animation_data_free(AnimationData *fd)
305 if(fd->iter) g_object_unref(fd->iter);
306 if(fd->gpa) g_object_unref(fd->gpa);
307 if(fd->cancellable) g_object_unref(fd->cancellable);
311 static gboolean animation_should_continue(AnimationData *fd)
319 static gboolean show_next_frame(gpointer data)
321 auto fd = static_cast<AnimationData*>(data);
325 if(animation_should_continue(fd)==FALSE)
327 image_animation_data_free(fd);
331 pr = reinterpret_cast<PixbufRenderer*>(fd->iw->pr);
333 if (gdk_pixbuf_animation_iter_advance(fd->iter,nullptr)==FALSE)
335 /* This indicates the animation is complete.
336 Return FALSE here to disable looping. */
339 fd->gpb = gdk_pixbuf_animation_iter_get_pixbuf(fd->iter);
340 image_change_pixbuf(fd->iw,fd->gpb,pr->zoom,FALSE);
342 if (fd->iw->func_update)
343 fd->iw->func_update(fd->iw, fd->iw->data_update);
345 delay = gdk_pixbuf_animation_iter_get_delay_time(fd->iter);
346 if (delay!=fd->delay)
348 if (delay>0) /* Current frame not static. */
351 g_timeout_add(delay,show_next_frame,fd);
355 image_animation_data_free(fd);
363 static gboolean layout_image_animate_check(LayoutWindow *lw)
365 if (!layout_valid(&lw)) return FALSE;
367 if(!lw->options.animate || lw->image->image_fd == nullptr || lw->image->image_fd->extension == nullptr || (g_ascii_strcasecmp(lw->image->image_fd->extension,".GIF")!=0 && g_ascii_strcasecmp(lw->image->image_fd->extension,".WEBP")!=0))
371 lw->animation->valid = FALSE;
372 if (lw->animation->cancellable)
374 g_cancellable_cancel(lw->animation->cancellable);
376 lw->animation = nullptr;
384 static void layout_image_animate_update_image(LayoutWindow *lw)
386 if (!layout_valid(&lw)) return;
388 if(lw->options.animate && lw->animation)
390 if (lw->full_screen && lw->image != lw->full_screen->imd)
391 lw->animation->iw = lw->full_screen->imd;
393 lw->animation->iw = lw->image;
398 static void animation_async_ready_cb(GObject *, GAsyncResult *res, gpointer data)
400 GError *error = nullptr;
401 auto animation = static_cast<AnimationData *>(data);
405 if (g_cancellable_is_cancelled(animation->cancellable))
407 gdk_pixbuf_animation_new_from_stream_finish(res, nullptr);
408 g_object_unref(animation->in_file);
409 g_object_unref(animation->gfstream);
410 image_animation_data_free(animation);
414 animation->gpa = gdk_pixbuf_animation_new_from_stream_finish(res, &error);
417 if (!gdk_pixbuf_animation_is_static_image(animation->gpa))
419 animation->iter = gdk_pixbuf_animation_get_iter(animation->gpa, nullptr);
422 animation->data_adr = animation->lw->image->image_fd;
423 animation->delay = gdk_pixbuf_animation_iter_get_delay_time(animation->iter);
424 animation->valid = TRUE;
426 layout_image_animate_update_image(animation->lw);
428 g_timeout_add(animation->delay, show_next_frame, animation);
434 log_printf("Error reading GIF file: %s\n", error->message);
437 g_object_unref(animation->in_file);
438 g_object_unref(animation->gfstream);
442 static gboolean layout_image_animate_new_file(LayoutWindow *lw)
444 GFileInputStream *gfstream;
445 GError *error = nullptr;
446 AnimationData *animation;
449 if(!layout_image_animate_check(lw)) return FALSE;
451 if(lw->animation) lw->animation->valid = FALSE;
455 g_cancellable_cancel(lw->animation->cancellable);
458 animation = g_new0(AnimationData, 1);
459 lw->animation = animation;
461 animation->cancellable = g_cancellable_new();
463 in_file = g_file_new_for_path(lw->image->image_fd->path);
464 animation->in_file = in_file;
465 gfstream = g_file_read(in_file, nullptr, &error);
468 animation->gfstream = gfstream;
469 gdk_pixbuf_animation_new_from_stream_async(reinterpret_cast<GInputStream*>(gfstream), animation->cancellable, animation_async_ready_cb, animation);
473 log_printf("Error reading animation file: %s\nError: %s\n", lw->image->image_fd->path, error->message);
479 void layout_image_animate_toggle(LayoutWindow *lw)
485 lw->options.animate = !lw->options.animate;
487 action = gtk_action_group_get_action(lw->action_group, "Animate");
488 gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.animate);
490 layout_image_animate_new_file(lw);
494 *----------------------------------------------------------------------------
496 *----------------------------------------------------------------------------
499 static void li_pop_menu_zoom_in_cb(GtkWidget *, gpointer data)
501 auto lw = static_cast<LayoutWindow *>(data);
503 layout_image_zoom_adjust(lw, get_zoom_increment(), FALSE);
506 static void li_pop_menu_zoom_out_cb(GtkWidget *, gpointer data)
508 auto lw = static_cast<LayoutWindow *>(data);
509 layout_image_zoom_adjust(lw, -get_zoom_increment(), FALSE);
512 static void li_pop_menu_zoom_1_1_cb(GtkWidget *, gpointer data)
514 auto lw = static_cast<LayoutWindow *>(data);
516 layout_image_zoom_set(lw, 1.0, FALSE);
519 static void li_pop_menu_zoom_fit_cb(GtkWidget *, gpointer data)
521 auto lw = static_cast<LayoutWindow *>(data);
523 layout_image_zoom_set(lw, 0.0, FALSE);
526 static void li_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
529 auto key = static_cast<const gchar *>(data);
531 lw = static_cast<LayoutWindow *>(submenu_item_get_data(widget));
533 if (!editor_window_flag_set(key))
535 layout_image_full_screen_stop(lw);
537 file_util_start_editor_from_file(key, layout_image_get_fd(lw), lw->window);
540 static void li_pop_menu_alter_cb(GtkWidget *widget, gpointer data)
542 auto lw = static_cast<LayoutWindow *>(data);
545 lw = static_cast<LayoutWindow *>(submenu_item_get_data(widget));
546 type = static_cast<AlterType>GPOINTER_TO_INT(data);
548 image_alter_orientation(lw->image, lw->image->image_fd, type);
551 static void li_pop_menu_new_cb(GtkWidget *, gpointer data)
553 auto lw = static_cast<LayoutWindow *>(data);
555 view_window_new(layout_image_get_fd(lw));
558 static GtkWidget *li_pop_menu_click_parent(GtkWidget *widget, LayoutWindow *lw)
563 menu = gtk_widget_get_toplevel(widget);
564 if (!menu) return nullptr;
566 parent = static_cast<GtkWidget *>(g_object_get_data(G_OBJECT(menu), "click_parent"));
568 if (!parent && lw->full_screen)
570 parent = lw->full_screen->imd->widget;
576 static void li_pop_menu_copy_cb(GtkWidget *widget, gpointer data)
578 auto lw = static_cast<LayoutWindow *>(data);
580 file_util_copy(layout_image_get_fd(lw), nullptr, nullptr,
581 li_pop_menu_click_parent(widget, lw));
584 static void li_pop_menu_copy_path_cb(GtkWidget *, gpointer data)
586 auto lw = static_cast<LayoutWindow *>(data);
588 file_util_copy_path_to_clipboard(layout_image_get_fd(lw), TRUE);
591 static void li_pop_menu_copy_path_unquoted_cb(GtkWidget *, gpointer data)
593 auto lw = static_cast<LayoutWindow *>(data);
595 file_util_copy_path_to_clipboard(layout_image_get_fd(lw), FALSE);
598 static void li_pop_menu_copy_image_cb(GtkWidget *, gpointer data)
600 auto lw = static_cast<LayoutWindow *>(data);
601 ImageWindow *imd = lw->image;
604 pixbuf = image_get_pixbuf(imd);
606 gtk_clipboard_set_image(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), pixbuf);
609 static void li_pop_menu_move_cb(GtkWidget *widget, gpointer data)
611 auto lw = static_cast<LayoutWindow *>(data);
613 file_util_move(layout_image_get_fd(lw), nullptr, nullptr,
614 li_pop_menu_click_parent(widget, lw));
617 static void li_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
619 auto lw = static_cast<LayoutWindow *>(data);
621 file_util_rename(layout_image_get_fd(lw), nullptr,
622 li_pop_menu_click_parent(widget, lw));
625 static void li_pop_menu_delete_cb(GtkWidget *widget, gpointer data)
627 auto lw = static_cast<LayoutWindow *>(data);
629 options->file_ops.safe_delete_enable = FALSE;
630 file_util_delete(layout_image_get_fd(lw), nullptr,
631 li_pop_menu_click_parent(widget, lw));
634 static void li_pop_menu_move_to_trash_cb(GtkWidget *widget, gpointer data)
636 auto lw = static_cast<LayoutWindow *>(data);
638 options->file_ops.safe_delete_enable = TRUE;
639 file_util_delete(layout_image_get_fd(lw), nullptr,
640 li_pop_menu_click_parent(widget, lw));
643 static void li_pop_menu_slide_start_cb(GtkWidget *, gpointer data)
645 auto lw = static_cast<LayoutWindow *>(data);
647 layout_image_slideshow_start(lw);
650 static void li_pop_menu_slide_stop_cb(GtkWidget *, gpointer data)
652 auto lw = static_cast<LayoutWindow *>(data);
654 layout_image_slideshow_stop(lw);
657 static void li_pop_menu_slide_pause_cb(GtkWidget *, gpointer data)
659 auto lw = static_cast<LayoutWindow *>(data);
661 layout_image_slideshow_pause_toggle(lw);
664 static void li_pop_menu_full_screen_cb(GtkWidget *, gpointer data)
666 auto lw = static_cast<LayoutWindow *>(data);
668 layout_image_full_screen_toggle(lw);
671 static void li_pop_menu_animate_cb(GtkWidget *, gpointer data)
673 auto lw = static_cast<LayoutWindow *>(data);
675 layout_image_animate_toggle(lw);
678 static void li_pop_menu_hide_cb(GtkWidget *, gpointer data)
680 auto lw = static_cast<LayoutWindow *>(data);
682 layout_tools_hide_toggle(lw);
685 static void li_set_layout_path_cb(GtkWidget *, gpointer data)
687 auto lw = static_cast<LayoutWindow *>(data);
690 if (!layout_valid(&lw)) return;
692 fd = layout_image_get_fd(lw);
693 if (fd) layout_set_fd(lw, fd);
696 static void li_open_archive_cb(GtkWidget *, gpointer data)
698 auto lw = static_cast<LayoutWindow *>(data);
699 LayoutWindow *lw_new;
702 if (!layout_valid(&lw)) return;
704 dest_dir = open_archive(layout_image_get_fd(lw));
707 lw_new = layout_new_from_default();
708 layout_set_path(lw_new, dest_dir);
713 warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GQ_ICON_DIALOG_WARNING, nullptr);
717 static gboolean li_check_if_current_path(LayoutWindow *lw, const gchar *path)
722 if (!path || !layout_valid(&lw) || !lw->dir_fd) return FALSE;
724 dirname = g_path_get_dirname(path);
725 ret = (strcmp(lw->dir_fd->path, dirname) == 0);
730 static void layout_image_popup_menu_destroy_cb(GtkWidget *, gpointer data)
732 auto editmenu_fd_list = static_cast<GList *>(data);
734 filelist_free(editmenu_fd_list);
737 static GList *layout_image_get_fd_list(LayoutWindow *lw)
739 GList *list = nullptr;
740 FileData *fd = layout_image_get_fd(lw);
745 /* optionally include sidecars if the filelist entry is not expanded */
746 list = vf_selection_get_one(lw->vf, fd);
748 list = g_list_append(nullptr, file_data_ref(fd));
755 * @brief Add file selection list to a collection
757 * @param[in] data Index to the collection list menu item selected, or -1 for new collection
761 static void layout_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
764 GList *selection_list = nullptr;
766 lw = static_cast<LayoutWindow *>(submenu_item_get_data(widget));
767 selection_list = g_list_append(selection_list, layout_image_get_fd(lw));
768 pop_menu_collections(selection_list, data);
770 filelist_free(selection_list);
773 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
780 GList *editmenu_fd_list;
781 GtkAccelGroup *accel_group;
783 path = layout_image_get_path(lw);
784 fullscreen = layout_image_full_screen_active(lw);
786 menu = popup_menu_short_lived();
788 accel_group = gtk_accel_group_new();
789 gtk_menu_set_accel_group(GTK_MENU(menu), accel_group);
791 g_object_set_data(G_OBJECT(menu), "window_keys", nullptr);
792 g_object_set_data(G_OBJECT(menu), "accel_group", accel_group);
794 menu_item_add_icon(menu, _("Zoom _in"), GQ_ICON_ZOOM_IN, G_CALLBACK(li_pop_menu_zoom_in_cb), lw);
795 menu_item_add_icon(menu, _("Zoom _out"), GQ_ICON_ZOOM_OUT, G_CALLBACK(li_pop_menu_zoom_out_cb), lw);
796 menu_item_add_icon(menu, _("Zoom _1:1"), GQ_ICON_ZOOM_100, G_CALLBACK(li_pop_menu_zoom_1_1_cb), lw);
797 menu_item_add_icon(menu, _("Zoom to fit"), GQ_ICON_ZOOM_FIT, G_CALLBACK(li_pop_menu_zoom_fit_cb), lw);
798 menu_item_add_divider(menu);
800 editmenu_fd_list = layout_image_get_fd_list(lw);
801 g_signal_connect(G_OBJECT(menu), "destroy",
802 G_CALLBACK(layout_image_popup_menu_destroy_cb), editmenu_fd_list);
803 submenu = submenu_add_edit(menu, &item, G_CALLBACK(li_pop_menu_edit_cb), lw, editmenu_fd_list);
804 if (!path) gtk_widget_set_sensitive(item, FALSE);
805 menu_item_add_divider(submenu);
806 item = submenu_add_alter(menu, G_CALLBACK(li_pop_menu_alter_cb), lw);
808 item = menu_item_add_icon(menu, _("View in _new window"), GQ_ICON_NEW, G_CALLBACK(li_pop_menu_new_cb), lw);
809 if (!path || fullscreen) gtk_widget_set_sensitive(item, FALSE);
811 item = menu_item_add(menu, _("_Go to directory view"), G_CALLBACK(li_set_layout_path_cb), lw);
812 if (!path || li_check_if_current_path(lw, path)) gtk_widget_set_sensitive(item, FALSE);
814 item = menu_item_add_icon(menu, _("Open archive"), GQ_ICON_OPEN, G_CALLBACK(li_open_archive_cb), lw);
815 if (!path || lw->image->image_fd->format_class != FORMAT_CLASS_ARCHIVE)
817 gtk_widget_set_sensitive(item, FALSE);
820 menu_item_add_divider(menu);
822 item = menu_item_add_icon(menu, _("_Copy..."), GQ_ICON_COPY, G_CALLBACK(li_pop_menu_copy_cb), lw);
823 if (!path) gtk_widget_set_sensitive(item, FALSE);
824 item = menu_item_add(menu, _("_Move..."), G_CALLBACK(li_pop_menu_move_cb), lw);
825 if (!path) gtk_widget_set_sensitive(item, FALSE);
826 item = menu_item_add(menu, _("_Rename..."), G_CALLBACK(li_pop_menu_rename_cb), lw);
827 if (!path) gtk_widget_set_sensitive(item, FALSE);
828 item = menu_item_add(menu, _("_Copy path to clipboard"), G_CALLBACK(li_pop_menu_copy_path_cb), lw);
829 item = menu_item_add(menu, _("_Copy path unquoted to clipboard"), G_CALLBACK(li_pop_menu_copy_path_unquoted_cb), lw);
830 item = menu_item_add(menu, _("Copy _image to clipboard"), G_CALLBACK(li_pop_menu_copy_image_cb), lw);
831 if (!path) gtk_widget_set_sensitive(item, FALSE);
832 menu_item_add_divider(menu);
834 item = menu_item_add_icon(menu,
835 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
836 _("Move to Trash"), GQ_ICON_DELETE,
837 G_CALLBACK(li_pop_menu_move_to_trash_cb), lw);
838 if (!path) gtk_widget_set_sensitive(item, FALSE);
839 item = menu_item_add_icon(menu,
840 options->file_ops.confirm_delete ? _("_Delete...") :
841 _("_Delete"), GQ_ICON_DELETE_SHRED,
842 G_CALLBACK(li_pop_menu_delete_cb), lw);
843 if (!path) gtk_widget_set_sensitive(item, FALSE);
844 menu_item_add_divider(menu);
846 submenu = submenu_add_collections(menu, &item,
847 G_CALLBACK(layout_pop_menu_collections_cb), lw);
848 gtk_widget_set_sensitive(item, TRUE);
849 menu_item_add_divider(menu);
851 if (layout_image_slideshow_active(lw))
853 menu_item_add(menu, _("Toggle _slideshow"), G_CALLBACK(li_pop_menu_slide_stop_cb), lw);
854 if (layout_image_slideshow_paused(lw))
856 item = menu_item_add(menu, _("Continue slides_how"),
857 G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
861 item = menu_item_add(menu, _("Pause slides_how"),
862 G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
867 menu_item_add(menu, _("Toggle _slideshow"), G_CALLBACK(li_pop_menu_slide_start_cb), lw);
868 item = menu_item_add(menu, _("Pause slides_how"), G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
869 gtk_widget_set_sensitive(item, FALSE);
874 menu_item_add_icon(menu, _("_Full screen"), GQ_ICON_FULLSCREEN, G_CALLBACK(li_pop_menu_full_screen_cb), lw);
878 menu_item_add_icon(menu, _("Exit _full screen"), GQ_ICON_LEAVE_FULLSCREEN, G_CALLBACK(li_pop_menu_full_screen_cb), lw);
881 menu_item_add_check(menu, _("GIF _animation"), lw->options.animate, G_CALLBACK(li_pop_menu_animate_cb), lw);
883 menu_item_add_divider(menu);
885 item = menu_item_add_check(menu, _("Hide file _list"), lw->options.tools_hidden,
886 G_CALLBACK(li_pop_menu_hide_cb), lw);
888 item = menu_item_add_check(menu, _("Hide Selectable Bars"), lw->options.selectable_toolbars_hidden, G_CALLBACK(layout_selectable_toolbars_toggle), lw);
889 if (fullscreen) gtk_widget_set_sensitive(item, FALSE);
894 void layout_image_menu_popup(LayoutWindow *lw)
898 menu = layout_image_pop_menu(lw);
899 gtk_menu_popup_at_widget(GTK_MENU(menu), lw->image->widget, GDK_GRAVITY_EAST, GDK_GRAVITY_CENTER, nullptr);
903 *----------------------------------------------------------------------------
905 *----------------------------------------------------------------------------
908 static void layout_image_dnd_receive(GtkWidget *widget, GdkDragContext *,
910 GtkSelectionData *selection_data, guint info,
911 guint, gpointer data)
913 auto lw = static_cast<LayoutWindow *>(data);
918 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
920 if (lw->split_images[i] && lw->split_images[i]->pr == widget)
923 if (i < MAX_SPLIT_IMAGES)
925 DEBUG_1("dnd image activate %d", i);
926 layout_image_activate(lw, i, FALSE);
929 if (info == TARGET_TEXT_PLAIN)
931 url = g_strdup(reinterpret_cast<const gchar *>(gtk_selection_data_get_data(selection_data)));
932 download_web_file(url, FALSE, lw);
935 else if (info == TARGET_URI_LIST || info == TARGET_APP_COLLECTION_MEMBER)
937 CollectionData *source;
941 if (info == TARGET_URI_LIST)
943 list = uri_filelist_from_gtk_selection_data(selection_data);
949 source = collection_from_dnd_data(reinterpret_cast<const gchar *>(gtk_selection_data_get_data(selection_data)), &list, &info_list);
954 auto fd = static_cast<FileData *>(list->data);
956 if (isfile(fd->path))
962 base = remove_level_from_path(fd->path);
963 dir_fd = file_data_new_dir(base);
964 if (dir_fd != lw->dir_fd)
966 layout_set_fd(lw, dir_fd);
968 file_data_unref(dir_fd);
971 row = layout_list_get_index(lw, fd);
972 if (source && info_list)
974 layout_image_set_collection(lw, source, static_cast<CollectInfo *>(info_list->data));
978 layout_image_set_fd(lw, fd);
982 layout_image_set_index(lw, row);
985 else if (isdir(fd->path))
987 layout_set_fd(lw, fd);
988 layout_image_set_fd(lw, nullptr);
993 g_list_free(info_list);
997 static void layout_image_dnd_get(GtkWidget *widget, GdkDragContext *,
998 GtkSelectionData *selection_data, guint,
999 guint, gpointer data)
1001 auto lw = static_cast<LayoutWindow *>(data);
1006 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1008 if (lw->split_images[i] && lw->split_images[i]->pr == widget)
1011 if (i < MAX_SPLIT_IMAGES)
1013 DEBUG_1("dnd get from %d", i);
1014 fd = image_get_fd(lw->split_images[i]);
1017 fd = layout_image_get_fd(lw);
1023 list = g_list_append(nullptr, fd);
1024 uri_selection_data_set_uris_from_filelist(selection_data, list);
1029 gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
1034 static void layout_image_dnd_end(GtkWidget *, GdkDragContext *context, gpointer data)
1036 auto lw = static_cast<LayoutWindow *>(data);
1037 if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
1042 fd = layout_image_get_fd(lw);
1043 row = layout_list_get_index(lw, fd);
1044 if (row < 0) return;
1046 if (!isfile(fd->path))
1048 if (static_cast<guint>(row) < layout_list_count(lw, nullptr) - 1)
1050 layout_image_next(lw);
1054 layout_image_prev(lw);
1061 static void layout_image_dnd_init(LayoutWindow *lw, gint i)
1063 ImageWindow *imd = lw->split_images[i];
1065 gtk_drag_source_set(imd->pr, GDK_BUTTON2_MASK,
1066 dnd_file_drag_types, dnd_file_drag_types_count,
1067 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
1068 g_signal_connect(G_OBJECT(imd->pr), "drag_data_get",
1069 G_CALLBACK(layout_image_dnd_get), lw);
1070 g_signal_connect(G_OBJECT(imd->pr), "drag_end",
1071 G_CALLBACK(layout_image_dnd_end), lw);
1073 gtk_drag_dest_set(imd->pr,
1074 static_cast<GtkDestDefaults>(GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP),
1075 dnd_file_drop_types, dnd_file_drop_types_count,
1076 static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
1077 g_signal_connect(G_OBJECT(imd->pr), "drag_data_received",
1078 G_CALLBACK(layout_image_dnd_receive), lw);
1083 *----------------------------------------------------------------------------
1085 *----------------------------------------------------------------------------
1088 void layout_image_to_root(LayoutWindow *lw)
1090 image_to_root_window(lw->image, (image_zoom_get(lw->image) == 0));
1094 *----------------------------------------------------------------------------
1095 * manipulation + accessors
1096 *----------------------------------------------------------------------------
1099 void layout_image_scroll(LayoutWindow *lw, gint x, gint y, gboolean connect_scroll)
1102 if (!layout_valid(&lw)) return;
1104 image_scroll(lw->image, x, y);
1106 if (lw->full_screen && lw->image != lw->full_screen->imd)
1108 image_scroll(lw->full_screen->imd, x, y);
1111 if (!connect_scroll) return;
1113 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1115 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1117 image_scroll(lw->split_images[i], x, y);
1123 void layout_image_zoom_adjust(LayoutWindow *lw, gdouble increment, gboolean connect_zoom)
1126 if (!layout_valid(&lw)) return;
1128 image_zoom_adjust(lw->image, increment);
1130 if (lw->full_screen && lw->image != lw->full_screen->imd)
1132 image_zoom_adjust(lw->full_screen->imd, increment);
1135 if (!connect_zoom) return;
1137 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1139 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1140 image_zoom_adjust(lw->split_images[i], increment); ;
1144 void layout_image_zoom_adjust_at_point(LayoutWindow *lw, gdouble increment, gint x, gint y, gboolean connect_zoom)
1147 if (!layout_valid(&lw)) return;
1149 image_zoom_adjust_at_point(lw->image, increment, x, y);
1151 if (lw->full_screen && lw->image != lw->full_screen->imd)
1153 image_zoom_adjust_at_point(lw->full_screen->imd, increment, x, y);
1155 if (!connect_zoom && !lw->split_mode) return;
1157 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1159 if (lw->split_images[i] && lw->split_images[i] != lw->image &&
1160 lw->split_images[i]->mouse_wheel_mode)
1161 image_zoom_adjust_at_point(lw->split_images[i], increment, x, y);
1165 void layout_image_zoom_set(LayoutWindow *lw, gdouble zoom, gboolean connect_zoom)
1168 if (!layout_valid(&lw)) return;
1170 image_zoom_set(lw->image, zoom);
1172 if (lw->full_screen && lw->image != lw->full_screen->imd)
1174 image_zoom_set(lw->full_screen->imd, zoom);
1177 if (!connect_zoom) return;
1179 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1181 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1182 image_zoom_set(lw->split_images[i], zoom);
1186 void layout_image_zoom_set_fill_geometry(LayoutWindow *lw, gboolean vertical, gboolean connect_zoom)
1189 if (!layout_valid(&lw)) return;
1191 image_zoom_set_fill_geometry(lw->image, vertical);
1193 if (lw->full_screen && lw->image != lw->full_screen->imd)
1195 image_zoom_set_fill_geometry(lw->full_screen->imd, vertical);
1198 if (!connect_zoom) return;
1200 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1202 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1203 image_zoom_set_fill_geometry(lw->split_images[i], vertical);
1207 void layout_image_alter_orientation(LayoutWindow *lw, AlterType type)
1209 if (!layout_valid(&lw)) return;
1211 GtkTreeModel *store;
1213 GtkTreeSelection *selection;
1218 if (!lw || !lw->vf) return;
1220 if (lw->vf->type == FILEVIEW_ICON)
1222 if (!VFICON(lw->vf)->selection) return;
1223 work = VFICON(lw->vf)->selection;
1227 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
1228 work = gtk_tree_selection_get_selected_rows(selection, &store);
1233 if (lw->vf->type == FILEVIEW_ICON)
1235 fd_n = static_cast<FileData *>(work->data);
1240 tpath = static_cast<GtkTreePath *>(work->data);
1241 gtk_tree_model_get_iter(store, &iter, tpath);
1242 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
1246 image_alter_orientation(lw->image, fd_n, type);
1250 static void image_alter_rating(FileData *fd_n, const gchar *rating)
1252 metadata_write_string(fd_n, RATING_KEY, rating);
1253 read_rating_data(fd_n);
1256 void layout_image_rating(LayoutWindow *lw, const gchar *rating)
1258 if (!layout_valid(&lw)) return;
1260 GtkTreeModel *store;
1262 GtkTreeSelection *selection;
1267 if (!lw || !lw->vf) return;
1269 if (lw->vf->type == FILEVIEW_ICON)
1271 if (!VFICON(lw->vf)->selection) return;
1272 work = VFICON(lw->vf)->selection;
1276 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
1277 work = gtk_tree_selection_get_selected_rows(selection, &store);
1282 if (lw->vf->type == FILEVIEW_ICON)
1284 fd_n = static_cast<FileData *>(work->data);
1289 tpath = static_cast<GtkTreePath *>(work->data);
1290 gtk_tree_model_get_iter(store, &iter, tpath);
1291 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
1295 image_alter_rating(fd_n, rating);
1299 void layout_image_reset_orientation(LayoutWindow *lw)
1301 ImageWindow *imd= lw->image;
1303 if (!layout_valid(&lw)) return;
1304 if (!imd || !imd->pr || !imd->image_fd) return;
1306 if (imd->orientation < 1 || imd->orientation > 8) imd->orientation = 1;
1308 if (options->image.exif_rotate_enable)
1310 if (g_strcmp0(imd->image_fd->format_name, "heif") != 0)
1312 imd->orientation = metadata_read_int(imd->image_fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
1316 imd->orientation = EXIF_ORIENTATION_TOP_LEFT;
1321 imd->orientation = 1;
1324 if (imd->image_fd->user_orientation != 0)
1326 imd->orientation = imd->image_fd->user_orientation;
1329 pixbuf_renderer_set_orientation(reinterpret_cast<PixbufRenderer *>(imd->pr), imd->orientation);
1332 void layout_image_set_desaturate(LayoutWindow *lw, gboolean desaturate)
1334 if (!layout_valid(&lw)) return;
1336 image_set_desaturate(lw->image, desaturate);
1339 gboolean layout_image_get_desaturate(LayoutWindow *lw)
1341 if (!layout_valid(&lw)) return FALSE;
1343 return image_get_desaturate(lw->image);
1346 void layout_image_set_overunderexposed(LayoutWindow *lw, gboolean overunderexposed)
1348 if (!layout_valid(&lw)) return;
1350 image_set_overunderexposed(lw->image, overunderexposed);
1353 #pragma GCC diagnostic push
1354 #pragma GCC diagnostic ignored "-Wunused-function"
1355 gboolean layout_image_get_overunderexposed_unused(LayoutWindow *lw)
1357 if (!layout_valid(&lw)) return FALSE;
1359 // return image_get_overunderexposed(lw->image);
1362 #pragma GCC diagnostic pop
1364 void layout_image_set_ignore_alpha(LayoutWindow *lw, gboolean ignore_alpha)
1366 if (!layout_valid(&lw)) return;
1368 lw->options.ignore_alpha = ignore_alpha;
1369 image_set_ignore_alpha(lw->image, ignore_alpha);
1373 #pragma GCC diagnostic push
1374 #pragma GCC diagnostic ignored "-Wunused-function"
1375 gint layout_image_stereo_get_unused(LayoutWindow *lw)
1377 if (!layout_valid(&lw)) return 0;
1379 // return image_stereo_get(lw->image);
1383 void layout_image_stereo_set_unused(LayoutWindow *lw, gint stereo_mode)
1385 if (!layout_valid(&lw)) return;
1387 image_stereo_set(lw->image, stereo_mode);
1389 void layout_image_stereo_swap_unused(LayoutWindow *lw)
1391 if (!layout_valid(&lw)) return;
1393 // image_stereo_swap(lw->image);
1395 #pragma GCC diagnostic pop
1397 gint layout_image_stereo_pixbuf_get(LayoutWindow *lw)
1399 if (!layout_valid(&lw)) return 0;
1401 return image_stereo_pixbuf_get(lw->image);
1404 void layout_image_stereo_pixbuf_set(LayoutWindow *lw, gint stereo_mode)
1406 if (!layout_valid(&lw)) return;
1408 image_stereo_pixbuf_set(lw->image, static_cast<StereoPixbufData>(stereo_mode));
1411 const gchar *layout_image_get_path(LayoutWindow *lw)
1413 if (!layout_valid(&lw)) return nullptr;
1415 return image_get_path(lw->image);
1418 #pragma GCC diagnostic push
1419 #pragma GCC diagnostic ignored "-Wunused-function"
1420 const gchar *layout_image_get_name_unused(LayoutWindow *lw)
1422 if (!layout_valid(&lw)) return NULL;
1424 return image_get_name(lw->image);
1426 #pragma GCC diagnostic pop
1428 FileData *layout_image_get_fd(LayoutWindow *lw)
1430 if (!layout_valid(&lw)) return nullptr;
1432 return image_get_fd(lw->image);
1435 CollectionData *layout_image_get_collection(LayoutWindow *lw, CollectInfo **info)
1437 if (!layout_valid(&lw)) return nullptr;
1439 return image_get_collection(lw->image, info);
1442 gint layout_image_get_index(LayoutWindow *lw)
1444 return layout_list_get_index(lw, image_get_fd(lw->image));
1448 *----------------------------------------------------------------------------
1450 *----------------------------------------------------------------------------
1453 void layout_image_set_fd(LayoutWindow *lw, FileData *fd)
1455 if (!layout_valid(&lw)) return;
1457 image_change_fd(lw->image, fd, image_zoom_get_default(lw->image));
1459 if (lw->full_screen && lw->image != lw->full_screen->imd)
1461 image_change_fd(lw->full_screen->imd, fd, image_zoom_get_default(lw->full_screen->imd));
1465 layout_list_sync_fd(lw, fd);
1466 layout_image_slideshow_continue_check(lw);
1467 layout_bars_new_image(lw);
1468 layout_image_animate_new_file(lw);
1472 image_chain_append_end(fd->path);
1476 void layout_image_set_with_ahead(LayoutWindow *lw, FileData *fd, FileData *read_ahead_fd)
1478 if (!layout_valid(&lw)) return;
1480 /** @FIXME This should be handled at the caller: in vflist_select_image
1483 const gchar *old_path;
1485 old_path = layout_image_get_path(lw);
1486 if (old_path && strcmp(path, old_path) == 0) return;
1489 layout_image_set_fd(lw, fd);
1490 if (options->image.enable_read_ahead) image_prebuffer_set(lw->image, read_ahead_fd);
1493 void layout_image_set_index(LayoutWindow *lw, gint index)
1496 FileData *read_ahead_fd;
1499 if (!layout_valid(&lw)) return;
1501 old = layout_list_get_index(lw, layout_image_get_fd(lw));
1502 fd = layout_list_get_fd(lw, index);
1506 read_ahead_fd = layout_list_get_fd(lw, index - 1);
1510 read_ahead_fd = layout_list_get_fd(lw, index + 1);
1513 if (layout_selection_count(lw, nullptr) > 1)
1515 GList *x = layout_selection_list_by_index(lw);
1519 for (last = y = x; y; y = y->next)
1521 for (y = x; y && (GPOINTER_TO_INT(y->data)) != index; y = y->next)
1528 if ((index > old && (index != GPOINTER_TO_INT(last->data) || old != GPOINTER_TO_INT(x->data)))
1529 || (old == GPOINTER_TO_INT(last->data) && index == GPOINTER_TO_INT(x->data)))
1532 newindex = GPOINTER_TO_INT(y->next->data);
1534 newindex = GPOINTER_TO_INT(x->data);
1539 newindex = GPOINTER_TO_INT(y->prev->data);
1541 newindex = GPOINTER_TO_INT(last->data);
1544 read_ahead_fd = layout_list_get_fd(lw, newindex);
1548 x = g_list_remove(x, x->data);
1551 layout_image_set_with_ahead(lw, fd, read_ahead_fd);
1554 static void layout_image_set_collection_real(LayoutWindow *lw, CollectionData *cd, CollectInfo *info, gboolean forward)
1556 if (!layout_valid(&lw)) return;
1558 image_change_from_collection(lw->image, cd, info, image_zoom_get_default(lw->image));
1559 if (options->image.enable_read_ahead)
1561 CollectInfo *r_info;
1564 r_info = collection_next_by_info(cd, info);
1565 if (!r_info) r_info = collection_prev_by_info(cd, info);
1569 r_info = collection_prev_by_info(cd, info);
1570 if (!r_info) r_info = collection_next_by_info(cd, info);
1572 if (r_info) image_prebuffer_set(lw->image, r_info->fd);
1575 layout_image_slideshow_continue_check(lw);
1576 layout_bars_new_image(lw);
1579 void layout_image_set_collection(LayoutWindow *lw, CollectionData *cd, CollectInfo *info)
1581 layout_image_set_collection_real(lw, cd, info, TRUE);
1582 layout_list_sync_fd(lw, layout_image_get_fd(lw));
1585 void layout_image_refresh(LayoutWindow *lw)
1587 if (!layout_valid(&lw)) return;
1589 image_reload(lw->image);
1592 void layout_image_color_profile_set(LayoutWindow *lw,
1596 if (!layout_valid(&lw)) return;
1598 image_color_profile_set(lw->image, input_type, use_image);
1601 gboolean layout_image_color_profile_get(LayoutWindow *lw,
1603 gboolean *use_image)
1605 if (!layout_valid(&lw)) return FALSE;
1607 return image_color_profile_get(lw->image, input_type, use_image);
1610 void layout_image_color_profile_set_use(LayoutWindow *lw, gboolean enable)
1612 if (!layout_valid(&lw)) return;
1614 image_color_profile_set_use(lw->image, enable);
1617 gboolean layout_image_color_profile_get_use(LayoutWindow *lw)
1619 if (!layout_valid(&lw)) return FALSE;
1621 return image_color_profile_get_use(lw->image);
1624 gboolean layout_image_color_profile_get_status(LayoutWindow *lw, gchar **image_profile, gchar **screen_profile)
1626 if (!layout_valid(&lw)) return FALSE;
1628 return image_color_profile_get_status(lw->image, image_profile, screen_profile);
1632 *----------------------------------------------------------------------------
1634 *----------------------------------------------------------------------------
1637 void layout_image_next(LayoutWindow *lw)
1643 if (!layout_valid(&lw)) return;
1645 if (layout_image_slideshow_active(lw))
1647 layout_image_slideshow_next(lw);
1651 if (layout_selection_count(lw, nullptr) > 1)
1653 GList *x = layout_selection_list_by_index(lw);
1654 gint old = layout_list_get_index(lw, layout_image_get_fd(lw));
1657 for (y = x; y && (GPOINTER_TO_INT(y->data)) != old; y = y->next)
1662 layout_image_set_index(lw, GPOINTER_TO_INT(y->next->data));
1665 if (options->circular_selection_lists)
1667 layout_image_set_index(lw, GPOINTER_TO_INT(x->data));
1672 x = g_list_remove(x, x->data);
1673 if (y) /* not dereferenced */
1677 cd = image_get_collection(lw->image, &info);
1681 info = collection_next_by_info(cd, info);
1684 layout_image_set_collection_real(lw, cd, info, TRUE);
1688 image_osd_icon(lw->image, IMAGE_OSD_LAST, -1);
1693 current = layout_image_get_index(lw);
1697 if (static_cast<guint>(current) < layout_list_count(lw, nullptr) - 1)
1699 layout_image_set_index(lw, current + 1);
1703 image_osd_icon(lw->image, IMAGE_OSD_LAST, -1);
1708 layout_image_set_index(lw, 0);
1712 void layout_image_prev(LayoutWindow *lw)
1718 if (!layout_valid(&lw)) return;
1720 if (layout_image_slideshow_active(lw))
1722 layout_image_slideshow_prev(lw);
1726 if (layout_selection_count(lw, nullptr) > 1)
1728 GList *x = layout_selection_list_by_index(lw);
1729 gint old = layout_list_get_index(lw, layout_image_get_fd(lw));
1733 for (last = y = x; y; y = y->next)
1735 for (y = x; y && (GPOINTER_TO_INT(y->data)) != old; y = y->next)
1740 layout_image_set_index(lw, GPOINTER_TO_INT(y->prev->data));
1743 if (options->circular_selection_lists)
1745 layout_image_set_index(lw, GPOINTER_TO_INT(last->data));
1750 x = g_list_remove(x, x->data);
1751 if (y) /* not dereferenced */
1755 cd = image_get_collection(lw->image, &info);
1759 info = collection_prev_by_info(cd, info);
1762 layout_image_set_collection_real(lw, cd, info, FALSE);
1766 image_osd_icon(lw->image, IMAGE_OSD_FIRST, -1);
1771 current = layout_image_get_index(lw);
1777 layout_image_set_index(lw, current - 1);
1781 image_osd_icon(lw->image, IMAGE_OSD_FIRST, -1);
1786 layout_image_set_index(lw, layout_list_count(lw, nullptr) - 1);
1790 void layout_image_first(LayoutWindow *lw)
1796 if (!layout_valid(&lw)) return;
1798 cd = image_get_collection(lw->image, &info);
1802 CollectInfo *first_collection;
1803 first_collection = collection_get_first(cd);
1804 if (first_collection != info)
1806 layout_image_set_collection_real(lw, cd, first_collection, TRUE);
1811 current = layout_image_get_index(lw);
1812 if (current != 0 && layout_list_count(lw, nullptr) > 0)
1814 layout_image_set_index(lw, 0);
1818 void layout_image_last(LayoutWindow *lw)
1825 if (!layout_valid(&lw)) return;
1827 cd = image_get_collection(lw->image, &info);
1831 CollectInfo *last_collection;
1832 last_collection = collection_get_last(cd);
1833 if (last_collection != info)
1835 layout_image_set_collection_real(lw, cd, last_collection, FALSE);
1840 current = layout_image_get_index(lw);
1841 count = layout_list_count(lw, nullptr);
1842 if (current != count - 1 && count > 0)
1844 layout_image_set_index(lw, count - 1);
1849 *----------------------------------------------------------------------------
1851 *----------------------------------------------------------------------------
1854 static gint image_idx(LayoutWindow *lw, ImageWindow *imd)
1858 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1860 if (lw->split_images[i] == imd)
1863 if (i < MAX_SPLIT_IMAGES)
1870 static void layout_image_focus_in_cb(ImageWindow *imd, gpointer data)
1872 auto lw = static_cast<LayoutWindow *>(data);
1874 gint i = image_idx(lw, imd);
1878 DEBUG_1("image activate focus_in %d", i);
1879 layout_image_activate(lw, i, FALSE);
1884 static void layout_image_button_cb(ImageWindow *imd, GdkEventButton *event, gpointer data)
1886 auto lw = static_cast<LayoutWindow *>(data);
1888 LayoutWindow *lw_new;
1891 switch (event->button)
1893 case MOUSE_BUTTON_LEFT:
1894 if (event->button == MOUSE_BUTTON_LEFT && event->type == GDK_2BUTTON_PRESS)
1896 layout_image_full_screen_toggle(lw);
1899 else if (options->image_l_click_archive && imd-> image_fd && imd->image_fd->format_class == FORMAT_CLASS_ARCHIVE)
1901 dest_dir = open_archive(imd->image_fd);
1904 lw_new = layout_new_from_default();
1905 layout_set_path(lw_new, dest_dir);
1910 warning_dialog(_("Cannot open archive file"), _("See the Log Window"), GQ_ICON_DIALOG_WARNING, nullptr);
1913 else if (options->image_l_click_video && options->image_l_click_video_editor && imd-> image_fd && imd->image_fd->format_class == FORMAT_CLASS_VIDEO)
1915 start_editor_from_file(options->image_l_click_video_editor, imd->image_fd);
1917 else if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
1918 layout_image_next(lw);
1920 case MOUSE_BUTTON_MIDDLE:
1921 if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
1922 layout_image_prev(lw);
1924 case MOUSE_BUTTON_RIGHT:
1925 menu = layout_image_pop_menu(lw);
1926 if (imd == lw->image)
1928 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
1930 gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr);
1937 static void layout_image_scroll_cb(ImageWindow *imd, GdkEventScroll *event, gpointer data)
1939 auto lw = static_cast<LayoutWindow *>(data);
1941 gint i = image_idx(lw, imd);
1945 DEBUG_1("image activate scroll %d", i);
1946 layout_image_activate(lw, i, FALSE);
1950 if ((event->state & GDK_CONTROL_MASK) ||
1951 (imd->mouse_wheel_mode && !options->image_lm_click_nav))
1953 switch (event->direction)
1956 layout_image_zoom_adjust_at_point(lw, get_zoom_increment(), event->x, event->y, event->state & GDK_SHIFT_MASK);
1958 case GDK_SCROLL_DOWN:
1959 layout_image_zoom_adjust_at_point(lw, -get_zoom_increment(), event->x, event->y, event->state & GDK_SHIFT_MASK);
1965 else if (options->mousewheel_scrolls)
1967 switch (event->direction)
1970 image_scroll(imd, 0, -MOUSEWHEEL_SCROLL_SIZE);
1972 case GDK_SCROLL_DOWN:
1973 image_scroll(imd, 0, MOUSEWHEEL_SCROLL_SIZE);
1975 case GDK_SCROLL_LEFT:
1976 image_scroll(imd, -MOUSEWHEEL_SCROLL_SIZE, 0);
1978 case GDK_SCROLL_RIGHT:
1979 image_scroll(imd, MOUSEWHEEL_SCROLL_SIZE, 0);
1987 switch (event->direction)
1990 layout_image_prev(lw);
1992 case GDK_SCROLL_DOWN:
1993 layout_image_next(lw);
2001 static void layout_image_drag_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
2004 auto lw = static_cast<LayoutWindow *>(data);
2007 if (lw->full_screen && lw->image != lw->full_screen->imd &&
2008 imd != lw->full_screen->imd)
2010 if (event->state & GDK_CONTROL_MASK)
2012 image_get_scroll_center(imd, &sx, &sy);
2016 image_get_scroll_center(lw->full_screen->imd, &sx, &sy);
2020 image_set_scroll_center(lw->full_screen->imd, sx, sy);
2023 if (!(event->state & GDK_SHIFT_MASK)) return;
2025 for (i = 0; i < MAX_SPLIT_IMAGES; i++)
2027 if (lw->split_images[i] && lw->split_images[i] != imd)
2030 if (event->state & GDK_CONTROL_MASK)
2032 image_get_scroll_center(imd, &sx, &sy);
2036 image_get_scroll_center(lw->split_images[i], &sx, &sy);
2040 image_set_scroll_center(lw->split_images[i], sx, sy);
2045 static void layout_image_button_inactive_cb(ImageWindow *imd, GdkEventButton *event, gpointer data)
2047 auto lw = static_cast<LayoutWindow *>(data);
2049 gint i = image_idx(lw, imd);
2053 layout_image_activate(lw, i, FALSE);
2056 switch (event->button)
2058 case MOUSE_BUTTON_RIGHT:
2059 menu = layout_image_pop_menu(lw);
2060 if (imd == lw->image)
2062 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
2064 gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr);
2072 static void layout_image_drag_inactive_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
2074 auto lw = static_cast<LayoutWindow *>(data);
2075 gint i = image_idx(lw, imd);
2079 layout_image_activate(lw, i, FALSE);
2082 /* continue as with active image */
2083 layout_image_drag_cb(imd, event, dx, dy, data);
2087 static void layout_image_set_buttons(LayoutWindow *lw)
2089 image_set_button_func(lw->image, layout_image_button_cb, lw);
2090 image_set_scroll_func(lw->image, layout_image_scroll_cb, lw);
2093 static void layout_image_set_buttons_inactive(LayoutWindow *lw, gint i)
2095 image_set_button_func(lw->split_images[i], layout_image_button_inactive_cb, lw);
2096 image_set_scroll_func(lw->split_images[i], layout_image_scroll_cb, lw);
2099 /* Returns the length of an integer */
2100 static gint num_length(gint num)
2103 if (num < 0) num = -num;
2112 void layout_status_update_pixel_cb(PixbufRenderer *pr, gpointer data)
2114 auto lw = static_cast<LayoutWindow *>(data);
2115 gint x_pixel, y_pixel;
2118 PangoAttrList *attrs;
2120 if (!data || !layout_valid(&lw) || !lw->image
2121 || !lw->options.show_info_pixel || lw->image->unknown) return;
2123 pixbuf_renderer_get_image_size(pr, &width, &height);
2124 if (width < 1 || height < 1) return;
2126 pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
2128 if(x_pixel >= 0 && y_pixel >= 0)
2130 gint r_mouse, g_mouse, b_mouse;
2132 pixbuf_renderer_get_pixel_colors(pr, x_pixel, y_pixel,
2133 &r_mouse, &g_mouse, &b_mouse);
2135 text = g_strdup_printf(_("[%*d,%*d]: RGB(%3d,%3d,%3d)"),
2136 num_length(width - 1), x_pixel,
2137 num_length(height - 1), y_pixel,
2138 r_mouse, g_mouse, b_mouse);
2143 text = g_strdup_printf(_("[%*s,%*s]: RGB(---,---,---)"),
2144 num_length(width - 1), " ",
2145 num_length(height - 1), " ");
2148 attrs = pango_attr_list_new();
2149 pango_attr_list_insert(attrs, pango_attr_family_new("Monospace"));
2150 gtk_label_set_text(GTK_LABEL(lw->info_pixel), text);
2151 gtk_label_set_attributes(GTK_LABEL(lw->info_pixel), attrs);
2152 pango_attr_list_unref(attrs);
2158 *----------------------------------------------------------------------------
2160 *----------------------------------------------------------------------------
2163 static void layout_image_update_cb(ImageWindow *, gpointer data)
2165 auto lw = static_cast<LayoutWindow *>(data);
2166 layout_status_update_image(lw);
2169 GtkWidget *layout_image_new(LayoutWindow *lw, gint i)
2171 if (!lw->split_image_sizegroup) lw->split_image_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
2173 if (!lw->split_images[i])
2175 lw->split_images[i] = image_new(TRUE);
2177 g_object_ref(lw->split_images[i]->widget);
2179 g_signal_connect(G_OBJECT(lw->split_images[i]->pr), "update-pixel",
2180 G_CALLBACK(layout_status_update_pixel_cb), lw);
2182 image_background_set_color_from_options(lw->split_images[i], FALSE);
2184 image_auto_refresh_enable(lw->split_images[i], TRUE);
2186 layout_image_dnd_init(lw, i);
2187 image_color_profile_set(lw->split_images[i],
2188 options->color_profile.input_type,
2189 options->color_profile.use_image);
2190 image_color_profile_set_use(lw->split_images[i], options->color_profile.enabled);
2192 gtk_size_group_add_widget(lw->split_image_sizegroup, lw->split_images[i]->widget);
2193 gtk_widget_set_size_request(lw->split_images[i]->widget, IMAGE_MIN_WIDTH, -1);
2195 image_set_focus_in_func(lw->split_images[i], layout_image_focus_in_cb, lw);
2199 return lw->split_images[i]->widget;
2202 void layout_image_deactivate(LayoutWindow *lw, gint i)
2204 if (!lw->split_images[i]) return;
2205 image_set_update_func(lw->split_images[i], nullptr, nullptr);
2206 layout_image_set_buttons_inactive(lw, i);
2207 image_set_drag_func(lw->split_images[i], layout_image_drag_inactive_cb, lw);
2209 image_attach_window(lw->split_images[i], nullptr, nullptr, nullptr, FALSE);
2210 image_select(lw->split_images[i], FALSE);
2213 /* force should be set after change of lw->split_mode */
2214 void layout_image_activate(LayoutWindow *lw, gint i, gboolean force)
2218 if (!lw->split_images[i]) return;
2219 if (!force && lw->active_split_image == i) return;
2221 /* deactivate currently active */
2222 if (lw->active_split_image != i)
2223 layout_image_deactivate(lw, lw->active_split_image);
2225 lw->image = lw->split_images[i];
2226 lw->active_split_image = i;
2228 image_set_update_func(lw->image, layout_image_update_cb, lw);
2229 layout_image_set_buttons(lw);
2230 image_set_drag_func(lw->image, layout_image_drag_cb, lw);
2232 image_attach_window(lw->image, lw->window, nullptr, GQ_APPNAME, FALSE);
2234 /* do not highlight selected image in SPLIT_NONE */
2235 /* maybe the image should be selected always and highlight should be controlled by
2236 another image option */
2237 if (lw->split_mode != SPLIT_NONE)
2238 image_select(lw->split_images[i], TRUE);
2240 image_select(lw->split_images[i], FALSE);
2242 fd = image_get_fd(lw->image);
2246 layout_set_fd(lw, fd);
2248 layout_status_update_image(lw);
2252 static void layout_image_setup_split_common(LayoutWindow *lw, gint n)
2254 gboolean frame = (n > 1) || (!lw->options.tools_float && !lw->options.tools_hidden);
2257 for (i = 0; i < n; i++)
2258 if (!lw->split_images[i])
2260 FileData *img_fd = nullptr;
2263 layout_image_new(lw, i);
2264 image_set_frame(lw->split_images[i], frame);
2265 image_set_selectable(lw->split_images[i], (n > 1));
2269 image_osd_copy_status(lw->image, lw->split_images[i]);
2272 if (layout_selection_count(lw, nullptr) > 1)
2274 GList *work = g_list_last(layout_selection_list(lw));
2277 while (work && j < i)
2279 auto fd = static_cast<FileData *>(work->data);
2282 if (!fd || !*fd->path || fd->parent ||
2283 fd == lw->split_images[0]->image_fd)
2293 if (!img_fd && lw->image)
2295 img_fd = image_get_fd(lw->image);
2296 zoom = image_zoom_get(lw->image);
2302 image_change_fd(lw->split_images[i], img_fd, zoom);
2303 image_get_scroll_center(lw->image, &sx, &sy);
2304 image_set_scroll_center(lw->split_images[i], sx, sy);
2306 layout_image_deactivate(lw, i);
2310 image_set_frame(lw->split_images[i], frame);
2311 image_set_selectable(lw->split_images[i], (n > 1));
2314 for (i = n; i < MAX_SPLIT_IMAGES; i++)
2316 if (lw->split_images[i])
2318 g_object_unref(lw->split_images[i]->widget);
2319 lw->split_images[i] = nullptr;
2323 if (!lw->image || lw->active_split_image < 0 || lw->active_split_image >= n)
2325 layout_image_activate(lw, 0, TRUE);
2329 /* this will draw the frame around selected image (image_select)
2330 on switch from single to split images */
2331 layout_image_activate(lw, lw->active_split_image, TRUE);
2335 GtkWidget *layout_image_setup_split_none(LayoutWindow *lw)
2337 lw->split_mode = SPLIT_NONE;
2339 layout_image_setup_split_common(lw, 1);
2341 lw->split_image_widget = lw->split_images[0]->widget;
2343 return lw->split_image_widget;
2347 GtkWidget *layout_image_setup_split_hv(LayoutWindow *lw, gboolean horizontal)
2351 lw->split_mode = horizontal ? SPLIT_HOR : SPLIT_VERT;
2353 layout_image_setup_split_common(lw, 2);
2355 /* horizontal split means vpaned and vice versa */
2356 paned = gtk_paned_new(horizontal ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
2359 gtk_paned_pack1(GTK_PANED(paned), lw->split_images[0]->widget, TRUE, TRUE);
2360 gtk_paned_pack2(GTK_PANED(paned), lw->split_images[1]->widget, TRUE, TRUE);
2362 gtk_widget_show(lw->split_images[0]->widget);
2363 gtk_widget_show(lw->split_images[1]->widget);
2365 lw->split_image_widget = paned;
2367 return lw->split_image_widget;
2371 static GtkWidget *layout_image_setup_split_triple(LayoutWindow *lw)
2375 GtkAllocation allocation;
2379 lw->split_mode = SPLIT_TRIPLE;
2381 layout_image_setup_split_common(lw, 3);
2383 gtk_widget_get_allocation(lw->utility_paned, &allocation);
2385 hpaned1 = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2386 DEBUG_NAME(hpaned1);
2387 hpaned2 = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2388 DEBUG_NAME(hpaned2);
2390 if (lw->bar && gtk_widget_get_visible(lw->bar))
2392 pane_pos = (gtk_paned_get_position(GTK_PANED(lw->utility_paned))) / 3;
2396 pane_pos = allocation.width / 3;
2399 gtk_paned_set_position(GTK_PANED(hpaned1), pane_pos);
2400 gtk_paned_set_position(GTK_PANED(hpaned2), pane_pos);
2402 gtk_paned_pack1(GTK_PANED(hpaned1), lw->split_images[0]->widget, TRUE, TRUE);
2403 gtk_paned_pack1(GTK_PANED(hpaned2), lw->split_images[1]->widget, TRUE, TRUE);
2404 gtk_paned_pack2(GTK_PANED(hpaned2), lw->split_images[2]->widget, TRUE, TRUE);
2405 gtk_paned_pack2(GTK_PANED(hpaned1), hpaned2, TRUE, TRUE);
2407 for (i = 0; i < 3; i++)
2409 gtk_widget_show(lw->split_images[i]->widget);
2412 gtk_widget_show(hpaned1);
2413 gtk_widget_show(hpaned2);
2415 lw->split_image_widget = hpaned1;
2417 return lw->split_image_widget;
2420 GtkWidget *layout_image_setup_split_quad(LayoutWindow *lw)
2427 lw->split_mode = SPLIT_QUAD;
2429 layout_image_setup_split_common(lw, 4);
2431 hpaned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
2433 vpaned1 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
2434 DEBUG_NAME(vpaned1);
2435 vpaned2 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
2436 DEBUG_NAME(vpaned2);
2438 gtk_paned_pack1(GTK_PANED(vpaned1), lw->split_images[0]->widget, TRUE, TRUE);
2439 gtk_paned_pack2(GTK_PANED(vpaned1), lw->split_images[2]->widget, TRUE, TRUE);
2441 gtk_paned_pack1(GTK_PANED(vpaned2), lw->split_images[1]->widget, TRUE, TRUE);
2442 gtk_paned_pack2(GTK_PANED(vpaned2), lw->split_images[3]->widget, TRUE, TRUE);
2444 gtk_paned_pack1(GTK_PANED(hpaned), vpaned1, TRUE, TRUE);
2445 gtk_paned_pack2(GTK_PANED(hpaned), vpaned2, TRUE, TRUE);
2447 for (i = 0; i < 4; i++)
2448 gtk_widget_show(lw->split_images[i]->widget);
2450 gtk_widget_show(vpaned1);
2451 gtk_widget_show(vpaned2);
2453 lw->split_image_widget = hpaned;
2455 return lw->split_image_widget;
2459 GtkWidget *layout_image_setup_split(LayoutWindow *lw, ImageSplitMode mode)
2464 return layout_image_setup_split_hv(lw, TRUE);
2466 return layout_image_setup_split_hv(lw, FALSE);
2468 return layout_image_setup_split_triple(lw);
2470 return layout_image_setup_split_quad(lw);
2473 return layout_image_setup_split_none(lw);
2479 *-----------------------------------------------------------------------------
2480 * maintenance (for rename, move, remove)
2481 *-----------------------------------------------------------------------------
2484 static void layout_image_maint_renamed(LayoutWindow *lw, FileData *fd)
2486 if (fd == layout_image_get_fd(lw))
2488 image_set_fd(lw->image, fd);
2492 static void layout_image_maint_removed(LayoutWindow *lw, FileData *fd)
2494 if (fd == layout_image_get_fd(lw))
2499 cd = image_get_collection(lw->image, &info);
2502 CollectInfo *next_collection;
2504 next_collection = collection_next_by_info(cd, info);
2505 if (!next_collection) next_collection = collection_prev_by_info(cd, info);
2507 if (next_collection)
2509 layout_image_set_collection(lw, cd, next_collection);
2512 layout_image_set_fd(lw, nullptr);
2515 /* the image will be set to the next image from the list soon,
2516 setting it to NULL here is not necessary*/
2521 void layout_image_notify_cb(FileData *fd, NotifyType type, gpointer data)
2523 auto lw = static_cast<LayoutWindow *>(data);
2525 if (!(type & NOTIFY_CHANGE) || !fd->change) return;
2527 DEBUG_1("Notify layout_image: %s %04x", fd->path, type);
2529 switch (fd->change->type)
2531 case FILEDATA_CHANGE_MOVE:
2532 case FILEDATA_CHANGE_RENAME:
2533 layout_image_maint_renamed(lw, fd);
2535 case FILEDATA_CHANGE_DELETE:
2536 layout_image_maint_removed(lw, fd);
2538 case FILEDATA_CHANGE_COPY:
2539 case FILEDATA_CHANGE_UNSPECIFIED:
2540 case FILEDATA_CHANGE_WRITE_METADATA:
2545 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */