7 * This software is released under the GNU General Public License (GNU GPL).
8 * Please read the included file COPYING for more information.
9 * This software comes with no warranty of any kind, use at your own risk!
13 #include "layout_image.h"
19 #include "fullscreen.h"
21 #include "image-overlay.h"
25 #include "layout_util.h"
27 #include "pixbuf_util.h"
29 #include "slideshow.h"
30 #include "ui_bookmark.h"
31 #include "ui_fileops.h"
34 #include <gdk/gdkkeysyms.h> /* for keyboard values */
37 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw);
38 static void layout_image_set_buttons(LayoutWindow *lw);
41 *----------------------------------------------------------------------------
43 *----------------------------------------------------------------------------
46 static void layout_image_overlay_set(LayoutWindow *lw, gint enable)
48 lw->full_screen_overlay_on = enable;
50 if (!lw->full_screen) return;
52 image_osd_set(lw->image, enable, enable);
55 void layout_image_overlay_update(LayoutWindow *lw)
57 if (!lw || !lw->full_screen) return;
59 image_osd_update(lw->image);
63 *----------------------------------------------------------------------------
65 *----------------------------------------------------------------------------
68 static void layout_image_fullscreen_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
70 LayoutWindow *lw = data;
72 if (!lw->full_screen) return;
74 gdk_window_get_origin(lw->full_screen->imd->pr->window, x, y);
75 popup_menu_position_clamp(menu, x, y, 0);
78 static void layout_image_full_screen_menu_popup(LayoutWindow *lw)
82 menu = layout_image_pop_menu(lw);
83 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, layout_image_fullscreen_menu_pos_cb, lw, 0, GDK_CURRENT_TIME);
86 static gint layout_image_full_screen_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
88 LayoutWindow *lw = data;
94 switch (event->keyval)
96 case GDK_Left: case GDK_KP_Left:
99 case GDK_Right: case GDK_KP_Right:
102 case GDK_Up: case GDK_KP_Up:
105 case GDK_Down: case GDK_KP_Down:
115 if (event->state & GDK_SHIFT_MASK)
121 keyboard_scroll_calc(&x, &y, event);
122 layout_image_scroll(lw, x, y);
125 if (stop_signal) return stop_signal;
127 if (event->state & GDK_CONTROL_MASK)
132 switch (event->keyval)
165 file_util_copy(layout_image_get_path(lw), NULL, NULL, widget);
168 file_util_move(layout_image_get_path(lw), NULL, NULL, widget);
171 file_util_rename(layout_image_get_path(lw), NULL, widget);
174 file_util_delete(layout_image_get_path(lw), NULL, widget);
177 info_window_new(layout_image_get_path(lw), NULL);
189 if (!editor_window_flag_set(n))
191 layout_image_full_screen_stop(lw);
193 start_editor_from_file(n, layout_image_get_path(lw));
196 else if (event->state & GDK_SHIFT_MASK)
199 switch (event->keyval)
202 layout_image_alter(lw, ALTER_ROTATE_180);
205 layout_image_alter(lw, ALTER_MIRROR);
208 layout_image_alter(lw, ALTER_FLIP);
211 layout_image_alter(lw, ALTER_DESATURATE);
221 switch (event->keyval)
223 case '+': case '=': case GDK_KP_Add:
224 layout_image_zoom_adjust(lw, get_zoom_increment());
226 case '-': case GDK_KP_Subtract:
227 layout_image_zoom_adjust(lw, -get_zoom_increment());
229 case 'X': case 'x': case GDK_KP_Multiply:
230 layout_image_zoom_set(lw, 0.0);
232 case 'Z': case 'z': case GDK_KP_Divide:
234 layout_image_zoom_set(lw, 1.0);
237 layout_image_zoom_set(lw, 2.0);
240 layout_image_zoom_set(lw, 3.0);
243 layout_image_zoom_set(lw, 4.0);
246 layout_image_zoom_set(lw, -4.0);
249 layout_image_zoom_set(lw, -3.0);
252 layout_image_zoom_set(lw, -2.0);
255 layout_image_zoom_set_fill_geometry(lw, FALSE);
258 layout_image_zoom_set_fill_geometry(lw, TRUE);
260 case GDK_Page_Up: case GDK_KP_Page_Up:
263 layout_image_prev(lw);
265 case GDK_Page_Down: case GDK_KP_Page_Down:
268 layout_image_next(lw);
270 case GDK_Home: case GDK_KP_Home:
271 layout_image_first(lw);
273 case GDK_End: case GDK_KP_End:
274 layout_image_last(lw);
277 layout_image_alter(lw, ALTER_ROTATE_90);
280 layout_image_alter(lw, ALTER_ROTATE_90_CC);
282 case GDK_Delete: case GDK_KP_Delete:
283 if (enable_delete_key)
285 file_util_delete(layout_image_get_path(lw), NULL, widget);
289 layout_image_full_screen_stop(lw);
295 layout_image_slideshow_toggle(lw);
298 layout_image_slideshow_pause_toggle(lw);
303 layout_image_full_screen_stop(lw);
307 layout_image_full_screen_menu_popup(lw);
310 layout_image_overlay_set(lw, !(lw->full_screen_overlay_on));
321 static void layout_image_full_screen_stop_func(FullScreenData *fs, gpointer data)
323 LayoutWindow *lw = data;
325 /* restore image window */
326 lw->image = fs->normal_imd;
330 lw->slideshow->imd = lw->image;
333 lw->full_screen = NULL;
336 void layout_image_full_screen_start(LayoutWindow *lw)
338 if (!layout_valid(&lw)) return;
340 if (lw->full_screen) return;
342 lw->full_screen = fullscreen_start(lw->window, lw->image,
343 layout_image_full_screen_stop_func, lw);
345 /* set to new image window */
346 lw->image = lw->full_screen->imd;
350 lw->slideshow->imd = lw->image;
353 layout_image_set_buttons(lw);
355 g_signal_connect(G_OBJECT(lw->full_screen->window), "key_press_event",
356 G_CALLBACK(layout_image_full_screen_key_press_cb), lw);
359 gtk_widget_set_sensitive(lw->window, FALSE);
360 if (lw->tools) gtk_widget_set_sensitive(lw->tools, FALSE);
363 layout_image_overlay_set(lw, lw->full_screen_overlay_on);
366 void layout_image_full_screen_stop(LayoutWindow *lw)
368 if (!layout_valid(&lw)) return;
369 if (!lw->full_screen) return;
371 fullscreen_stop(lw->full_screen);
374 gtk_widget_set_sensitive(lw->window, TRUE);
375 if (lw->tools) gtk_widget_set_sensitive(lw->tools, TRUE);
379 void layout_image_full_screen_toggle(LayoutWindow *lw)
381 if (!layout_valid(&lw)) return;
384 layout_image_full_screen_stop(lw);
388 layout_image_full_screen_start(lw);
392 gint layout_image_full_screen_active(LayoutWindow *lw)
394 if (!layout_valid(&lw)) return FALSE;
396 return (lw->full_screen != NULL);
400 *----------------------------------------------------------------------------
402 *----------------------------------------------------------------------------
405 static void layout_image_slideshow_next(LayoutWindow *lw)
407 if (lw->slideshow) slideshow_next(lw->slideshow);
410 static void layout_image_slideshow_prev(LayoutWindow *lw)
412 if (lw->slideshow) slideshow_prev(lw->slideshow);
415 static void layout_image_slideshow_stop_func(SlideShowData *ss, gpointer data)
417 LayoutWindow *lw = data;
419 lw->slideshow = NULL;
420 layout_status_update_info(lw, NULL);
423 void layout_image_slideshow_start(LayoutWindow *lw)
428 if (!layout_valid(&lw)) return;
429 if (lw->slideshow) return;
431 cd = image_get_collection(lw->image, &info);
435 lw->slideshow = slideshow_start_from_collection(lw->image, cd,
436 layout_image_slideshow_stop_func, lw, info);
440 lw->slideshow = slideshow_start(lw->image, lw,
441 layout_list_get_index(lw, layout_image_get_path(lw)),
442 layout_image_slideshow_stop_func, lw);
445 layout_status_update_info(lw, NULL);
448 /* note that slideshow will take ownership of the list, do not free it */
449 void layout_image_slideshow_start_from_list(LayoutWindow *lw, GList *list)
451 if (!layout_valid(&lw)) return;
453 if (lw->slideshow || !list)
455 path_list_free(list);
459 lw->slideshow = slideshow_start_from_path_list(lw->image, list,
460 layout_image_slideshow_stop_func, lw);
462 layout_status_update_info(lw, NULL);
465 void layout_image_slideshow_stop(LayoutWindow *lw)
467 if (!layout_valid(&lw)) return;
469 if (!lw->slideshow) return;
471 slideshow_free(lw->slideshow);
472 /* the stop_func sets lw->slideshow to NULL for us */
475 void layout_image_slideshow_toggle(LayoutWindow *lw)
477 if (!layout_valid(&lw)) return;
481 layout_image_slideshow_stop(lw);
485 layout_image_slideshow_start(lw);
489 gint layout_image_slideshow_active(LayoutWindow *lw)
491 if (!layout_valid(&lw)) return FALSE;
493 return (lw->slideshow != NULL);
496 gint layout_image_slideshow_pause_toggle(LayoutWindow *lw)
500 if (!layout_valid(&lw)) return FALSE;
502 ret = slideshow_pause_toggle(lw->slideshow);
504 layout_status_update_info(lw, NULL);
509 gint layout_image_slideshow_paused(LayoutWindow *lw)
511 if (!layout_valid(&lw)) return FALSE;
513 return (slideshow_paused(lw->slideshow));
516 static gint layout_image_slideshow_continue_check(LayoutWindow *lw)
518 if (!lw->slideshow) return FALSE;
520 if (!slideshow_should_continue(lw->slideshow))
522 layout_image_slideshow_stop(lw);
530 *----------------------------------------------------------------------------
532 *----------------------------------------------------------------------------
535 static void li_pop_menu_zoom_in_cb(GtkWidget *widget, gpointer data)
537 LayoutWindow *lw = data;
539 image_zoom_adjust(lw->image, get_zoom_increment());
542 static void li_pop_menu_zoom_out_cb(GtkWidget *widget, gpointer data)
544 LayoutWindow *lw = data;
545 image_zoom_adjust(lw->image, -get_zoom_increment());
548 static void li_pop_menu_zoom_1_1_cb(GtkWidget *widget, gpointer data)
550 LayoutWindow *lw = data;
552 image_zoom_set(lw->image, 1.0);
555 static void li_pop_menu_zoom_fit_cb(GtkWidget *widget, gpointer data)
557 LayoutWindow *lw = data;
559 image_zoom_set(lw->image, 0.0);
562 static void li_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
567 lw = submenu_item_get_data(widget);
568 n = GPOINTER_TO_INT(data);
570 if (!editor_window_flag_set(n))
572 layout_image_full_screen_stop(lw);
574 start_editor_from_file(n, layout_image_get_path(lw));
577 static void li_pop_menu_wallpaper_cb(GtkWidget *widget, gpointer data)
579 LayoutWindow *lw = data;
581 layout_image_to_root(lw);
584 static void li_pop_menu_alter_cb(GtkWidget *widget, gpointer data)
586 LayoutWindow *lw = data;
589 lw = submenu_item_get_data(widget);
590 type = (AlterType)GPOINTER_TO_INT(data);
592 image_alter(lw->image, type);
595 static void li_pop_menu_info_cb(GtkWidget *widget, gpointer data)
597 LayoutWindow *lw = data;
599 info_window_new(layout_image_get_path(lw), NULL);
602 static void li_pop_menu_new_cb(GtkWidget *widget, gpointer data)
604 LayoutWindow *lw = data;
606 view_window_new(layout_image_get_path(lw));
609 static GtkWidget *li_pop_menu_click_parent(GtkWidget *widget, LayoutWindow *lw)
614 menu = gtk_widget_get_toplevel(widget);
615 if (!menu) return NULL;
617 parent = g_object_get_data(G_OBJECT(menu), "click_parent");
619 if (!parent && lw->full_screen)
621 parent = lw->full_screen->imd->widget;
627 static void li_pop_menu_copy_cb(GtkWidget *widget, gpointer data)
629 LayoutWindow *lw = data;
631 file_util_copy(layout_image_get_path(lw), NULL, NULL,
632 li_pop_menu_click_parent(widget, lw));
635 static void li_pop_menu_move_cb(GtkWidget *widget, gpointer data)
637 LayoutWindow *lw = data;
639 file_util_move(layout_image_get_path(lw), NULL, NULL,
640 li_pop_menu_click_parent(widget, lw));
643 static void li_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
645 LayoutWindow *lw = data;
647 file_util_rename(layout_image_get_path(lw), NULL,
648 li_pop_menu_click_parent(widget, lw));
651 static void li_pop_menu_delete_cb(GtkWidget *widget, gpointer data)
653 LayoutWindow *lw = data;
655 file_util_delete(layout_image_get_path(lw), NULL,
656 li_pop_menu_click_parent(widget, lw));
659 static void li_pop_menu_slide_start_cb(GtkWidget *widget, gpointer data)
661 LayoutWindow *lw = data;
663 layout_image_slideshow_start(lw);
666 static void li_pop_menu_slide_stop_cb(GtkWidget *widget, gpointer data)
668 LayoutWindow *lw = data;
670 layout_image_slideshow_stop(lw);
673 static void li_pop_menu_slide_pause_cb(GtkWidget *widget, gpointer data)
675 LayoutWindow *lw = data;
677 layout_image_slideshow_pause_toggle(lw);
680 static void li_pop_menu_full_screen_cb(GtkWidget *widget, gpointer data)
682 LayoutWindow *lw = data;
684 layout_image_full_screen_toggle(lw);
687 static void li_pop_menu_hide_cb(GtkWidget *widget, gpointer data)
689 LayoutWindow *lw = data;
691 layout_tools_hide_toggle(lw);
694 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
702 path = layout_image_get_path(lw);
703 fullscreen = layout_image_full_screen_active(lw);
705 menu = popup_menu_short_lived();
707 menu_item_add_stock(menu, _("Zoom _in"), GTK_STOCK_ZOOM_IN, G_CALLBACK(li_pop_menu_zoom_in_cb), lw);
708 menu_item_add_stock(menu, _("Zoom _out"), GTK_STOCK_ZOOM_OUT, G_CALLBACK(li_pop_menu_zoom_out_cb), lw);
709 menu_item_add_stock(menu, _("Zoom _1:1"), GTK_STOCK_ZOOM_100, G_CALLBACK(li_pop_menu_zoom_1_1_cb), lw);
710 menu_item_add_stock(menu, _("Fit image to _window"), GTK_STOCK_ZOOM_FIT, G_CALLBACK(li_pop_menu_zoom_fit_cb), lw);
711 menu_item_add_divider(menu);
713 submenu = submenu_add_edit(menu, &item, G_CALLBACK(li_pop_menu_edit_cb), lw);
714 if (!path) gtk_widget_set_sensitive(item, FALSE);
715 menu_item_add_divider(submenu);
716 menu_item_add(submenu, _("Set as _wallpaper"), G_CALLBACK(li_pop_menu_wallpaper_cb), lw);
718 item = submenu_add_alter(menu, G_CALLBACK(li_pop_menu_alter_cb), lw);
720 item = menu_item_add_stock(menu, _("_Properties"), GTK_STOCK_PROPERTIES, G_CALLBACK(li_pop_menu_info_cb), lw);
721 if (!path) gtk_widget_set_sensitive(item, FALSE);
723 item = menu_item_add_stock(menu, _("View in _new window"), GTK_STOCK_NEW, G_CALLBACK(li_pop_menu_new_cb), lw);
724 if (!path || fullscreen) gtk_widget_set_sensitive(item, FALSE);
726 menu_item_add_divider(menu);
728 item = menu_item_add_stock(menu, _("_Copy..."), GTK_STOCK_COPY, G_CALLBACK(li_pop_menu_copy_cb), lw);
729 if (!path) gtk_widget_set_sensitive(item, FALSE);
730 item = menu_item_add(menu, _("_Move..."), G_CALLBACK(li_pop_menu_move_cb), lw);
731 if (!path) gtk_widget_set_sensitive(item, FALSE);
732 item = menu_item_add(menu, _("_Rename..."), G_CALLBACK(li_pop_menu_rename_cb), lw);
733 if (!path) gtk_widget_set_sensitive(item, FALSE);
734 item = menu_item_add_stock(menu, _("_Delete..."), GTK_STOCK_DELETE, G_CALLBACK(li_pop_menu_delete_cb), lw);
735 if (!path) gtk_widget_set_sensitive(item, FALSE);
737 menu_item_add_divider(menu);
739 if (layout_image_slideshow_active(lw))
741 menu_item_add(menu, _("_Stop slideshow"), G_CALLBACK(li_pop_menu_slide_stop_cb), lw);
742 if (layout_image_slideshow_paused(lw))
744 item = menu_item_add(menu, _("Continue slides_how"),
745 G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
749 item = menu_item_add(menu, _("Pause slides_how"),
750 G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
755 menu_item_add(menu, _("_Start slideshow"), G_CALLBACK(li_pop_menu_slide_start_cb), lw);
756 item = menu_item_add(menu, _("Pause slides_how"), G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
757 gtk_widget_set_sensitive(item, FALSE);
762 menu_item_add(menu, _("_Full screen"), G_CALLBACK(li_pop_menu_full_screen_cb), lw);
766 menu_item_add(menu, _("Exit _full screen"), G_CALLBACK(li_pop_menu_full_screen_cb), lw);
769 menu_item_add_divider(menu);
771 item = menu_item_add_check(menu, _("Hide file _list"), lw->tools_hidden,
772 G_CALLBACK(li_pop_menu_hide_cb), lw);
773 if (fullscreen) gtk_widget_set_sensitive(item, FALSE);
778 static void layout_image_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
780 LayoutWindow *lw = data;
782 gdk_window_get_origin(lw->image->pr->window, x, y);
783 popup_menu_position_clamp(menu, x, y, 0);
786 void layout_image_menu_popup(LayoutWindow *lw)
790 menu = layout_image_pop_menu(lw);
791 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, layout_image_menu_pos_cb, lw, 0, GDK_CURRENT_TIME);
795 *----------------------------------------------------------------------------
797 *----------------------------------------------------------------------------
800 static void layout_image_dnd_receive(GtkWidget *widget, GdkDragContext *context,
802 GtkSelectionData *selection_data, guint info,
803 guint time, gpointer data)
805 LayoutWindow *lw = data;
807 if (info == TARGET_URI_LIST || info == TARGET_APP_COLLECTION_MEMBER)
809 CollectionData *source;
813 if (info == TARGET_URI_LIST)
815 list = uri_list_from_text((gchar *)selection_data->data, TRUE);
821 source = collection_from_dnd_data((gchar *)selection_data->data, &list, &info_list);
835 base = remove_level_from_path(path);
836 if (strcmp(base, layout_get_path(lw)) != 0)
838 layout_set_path(lw, base);
842 row = layout_list_get_index(lw, path);
843 if (source && info_list)
845 layout_image_set_collection(lw, source, info_list->data);
849 layout_image_set_path(lw, path);
853 layout_image_set_index(lw, row);
856 else if (isdir(path))
858 layout_set_path(lw, path);
859 layout_image_set_path(lw, NULL);
863 path_list_free(list);
864 g_list_free(info_list);
868 static void layout_image_dnd_get(GtkWidget *widget, GdkDragContext *context,
869 GtkSelectionData *selection_data, guint info,
870 guint time, gpointer data)
872 LayoutWindow *lw = data;
875 path = layout_image_get_path(lw);
886 case TARGET_URI_LIST:
889 case TARGET_TEXT_PLAIN:
894 list = g_list_append(NULL, (gchar *)path);
895 text = uri_text_from_list(list, &len, plain_text);
899 gtk_selection_data_set (selection_data, selection_data->target,
900 8, (guchar *)text, len);
906 gtk_selection_data_set (selection_data, selection_data->target,
911 static void layout_image_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
913 LayoutWindow *lw = data;
914 if (context->action == GDK_ACTION_MOVE)
919 path = layout_image_get_path(lw);
920 row = layout_list_get_index(lw, path);
925 if (row < layout_list_count(lw, NULL) - 1)
927 layout_image_next(lw);
931 layout_image_prev(lw);
938 static void layout_image_dnd_init(LayoutWindow *lw)
940 gtk_drag_source_set(lw->image->pr, GDK_BUTTON2_MASK,
941 dnd_file_drag_types, dnd_file_drag_types_count,
942 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
943 g_signal_connect(G_OBJECT(lw->image->pr), "drag_data_get",
944 G_CALLBACK(layout_image_dnd_get), lw);
945 g_signal_connect(G_OBJECT(lw->image->pr), "drag_end",
946 G_CALLBACK(layout_image_dnd_end), lw);
948 gtk_drag_dest_set(lw->image->pr,
949 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
950 dnd_file_drop_types, dnd_file_drop_types_count,
951 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
952 g_signal_connect(G_OBJECT(lw->image->pr), "drag_data_received",
953 G_CALLBACK(layout_image_dnd_receive), lw);
958 *----------------------------------------------------------------------------
960 *----------------------------------------------------------------------------
963 void layout_image_to_root(LayoutWindow *lw)
965 image_to_root_window(lw->image, (image_zoom_get(lw->image) == 0));
969 *----------------------------------------------------------------------------
970 * manipulation + accessors
971 *----------------------------------------------------------------------------
974 void layout_image_scroll(LayoutWindow *lw, gint x, gint y)
976 if (!layout_valid(&lw)) return;
978 image_scroll(lw->image, x, y);
981 void layout_image_zoom_adjust(LayoutWindow *lw, gdouble increment)
983 if (!layout_valid(&lw)) return;
985 image_zoom_adjust(lw->image, increment);
988 void layout_image_zoom_set(LayoutWindow *lw, gdouble zoom)
990 if (!layout_valid(&lw)) return;
992 image_zoom_set(lw->image, zoom);
995 void layout_image_zoom_set_fill_geometry(LayoutWindow *lw, gint vertical)
997 if (!layout_valid(&lw)) return;
999 image_zoom_set_fill_geometry(lw->image, vertical);
1002 void layout_image_alter(LayoutWindow *lw, AlterType type)
1004 if (!layout_valid(&lw)) return;
1006 image_alter(lw->image, type);
1009 const gchar *layout_image_get_path(LayoutWindow *lw)
1011 if (!layout_valid(&lw)) return NULL;
1013 return image_get_path(lw->image);
1016 const gchar *layout_image_get_name(LayoutWindow *lw)
1018 if (!layout_valid(&lw)) return NULL;
1020 return image_get_name(lw->image);
1023 CollectionData *layout_image_get_collection(LayoutWindow *lw, CollectInfo **info)
1025 if (!layout_valid(&lw)) return NULL;
1027 return image_get_collection(lw->image, info);
1030 gint layout_image_get_index(LayoutWindow *lw)
1032 return layout_list_get_index(lw, image_get_path(lw->image));
1036 *----------------------------------------------------------------------------
1038 *----------------------------------------------------------------------------
1041 void layout_image_set_path(LayoutWindow *lw, const gchar *path)
1043 if (!layout_valid(&lw)) return;
1045 image_change_path(lw->image, path, image_zoom_get_default(lw->image, zoom_mode));
1047 layout_list_sync_path(lw, path);
1048 layout_image_slideshow_continue_check(lw);
1049 layout_bars_new_image(lw);
1052 void layout_image_set_with_ahead(LayoutWindow *lw, const gchar *path, const gchar *read_ahead_path)
1054 if (!layout_valid(&lw)) return;
1058 const gchar *old_path;
1060 old_path = layout_image_get_path(lw);
1061 if (old_path && strcmp(path, old_path) == 0) return;
1064 layout_image_set_path(lw, path);
1065 if (enable_read_ahead) image_prebuffer_set(lw->image, read_ahead_path);
1068 void layout_image_set_index(LayoutWindow *lw, gint index)
1071 const gchar *read_ahead_path;
1074 if (!layout_valid(&lw)) return;
1076 old = layout_list_get_index(lw, layout_image_get_path(lw));
1077 path = layout_list_get_path(lw, index);
1081 read_ahead_path = layout_list_get_path(lw, index - 1);
1085 read_ahead_path = layout_list_get_path(lw, index + 1);
1088 layout_image_set_with_ahead(lw, path, read_ahead_path);
1091 static void layout_image_set_collection_real(LayoutWindow *lw, CollectionData *cd, CollectInfo *info, gint forward)
1093 if (!layout_valid(&lw)) return;
1095 image_change_from_collection(lw->image, cd, info, image_zoom_get_default(lw->image, zoom_mode));
1096 if (enable_read_ahead)
1098 CollectInfo *r_info;
1101 r_info = collection_next_by_info(cd, info);
1102 if (!r_info) r_info = collection_prev_by_info(cd, info);
1106 r_info = collection_prev_by_info(cd, info);
1107 if (!r_info) r_info = collection_next_by_info(cd, info);
1109 if (r_info) image_prebuffer_set(lw->image, r_info->path);
1112 layout_image_slideshow_continue_check(lw);
1113 layout_bars_new_image(lw);
1116 void layout_image_set_collection(LayoutWindow *lw, CollectionData *cd, CollectInfo *info)
1118 layout_image_set_collection_real(lw, cd, info, TRUE);
1119 layout_list_sync_path(lw, layout_image_get_path(lw));
1122 void layout_image_refresh(LayoutWindow *lw)
1124 if (!layout_valid(&lw)) return;
1126 image_reload(lw->image);
1129 void layout_image_color_profile_set(LayoutWindow *lw,
1130 gint input_type, gint screen_type,
1133 if (!layout_valid(&lw)) return;
1135 image_color_profile_set(lw->image, input_type, screen_type, use_image);
1138 gint layout_image_color_profile_get(LayoutWindow *lw,
1139 gint *input_type, gint *screen_type,
1142 if (!layout_valid(&lw)) return FALSE;
1144 return image_color_profile_get(lw->image, input_type, screen_type, use_image);
1147 void layout_image_color_profile_set_use(LayoutWindow *lw, gint enable)
1149 if (!layout_valid(&lw)) return;
1151 image_color_profile_set_use(lw->image, enable);
1158 gtk_widget_set_sensitive(GTK_BIN(lw->info_color)->child, enable);
1162 gint layout_image_color_profile_get_use(LayoutWindow *lw)
1164 if (!layout_valid(&lw)) return FALSE;
1166 return image_color_profile_get_use(lw->image);
1170 *----------------------------------------------------------------------------
1172 *----------------------------------------------------------------------------
1175 void layout_image_next(LayoutWindow *lw)
1181 if (!layout_valid(&lw)) return;
1183 if (layout_image_slideshow_active(lw))
1185 layout_image_slideshow_next(lw);
1189 cd = image_get_collection(lw->image, &info);
1193 info = collection_next_by_info(cd, info);
1194 if (info) layout_image_set_collection_real(lw, cd, info, TRUE);
1198 current = layout_image_get_index(lw);
1202 if (current < layout_list_count(lw, NULL) - 1)
1204 layout_image_set_index(lw, current + 1);
1209 layout_image_set_index(lw, 0);
1213 void layout_image_prev(LayoutWindow *lw)
1219 if (!layout_valid(&lw)) return;
1221 if (layout_image_slideshow_active(lw))
1223 layout_image_slideshow_prev(lw);
1227 cd = image_get_collection(lw->image, &info);
1231 info = collection_prev_by_info(cd, info);
1232 if (info) layout_image_set_collection_real(lw, cd, info, FALSE);
1236 current = layout_image_get_index(lw);
1242 layout_image_set_index(lw, current - 1);
1247 layout_image_set_index(lw, layout_list_count(lw, NULL) - 1);
1251 void layout_image_first(LayoutWindow *lw)
1257 if (!layout_valid(&lw)) return;
1259 cd = image_get_collection(lw->image, &info);
1264 new = collection_get_first(cd);
1265 if (new != info) layout_image_set_collection_real(lw, cd, new, TRUE);
1269 current = layout_image_get_index(lw);
1270 if (current != 0 && layout_list_count(lw, NULL) > 0)
1272 layout_image_set_index(lw, 0);
1276 void layout_image_last(LayoutWindow *lw)
1283 if (!layout_valid(&lw)) return;
1285 cd = image_get_collection(lw->image, &info);
1290 new = collection_get_last(cd);
1291 if (new != info) layout_image_set_collection_real(lw, cd, new, FALSE);
1295 current = layout_image_get_index(lw);
1296 count = layout_list_count(lw, NULL);
1297 if (current != count - 1 && count > 0)
1299 layout_image_set_index(lw, count - 1);
1304 *----------------------------------------------------------------------------
1306 *----------------------------------------------------------------------------
1309 static void layout_image_button_cb(ImageWindow *imd, gint button, guint32 time,
1310 gdouble x, gdouble y, guint state, gpointer data)
1312 LayoutWindow *lw = data;
1318 layout_image_next(lw);
1321 layout_image_prev(lw);
1324 menu = layout_image_pop_menu(lw);
1325 if (imd == lw->image)
1327 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
1329 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, time);
1336 static void layout_image_scroll_cb(ImageWindow *imd, GdkScrollDirection direction, guint32 time,
1337 gdouble x, gdouble y, guint state, gpointer data)
1339 LayoutWindow *lw = data;
1341 if (state & GDK_CONTROL_MASK)
1346 image_zoom_adjust_at_point(imd, get_zoom_increment(), x, y);
1348 case GDK_SCROLL_DOWN:
1349 image_zoom_adjust_at_point(imd, -get_zoom_increment(), x, y);
1355 else if ( (state & GDK_SHIFT_MASK) != (mousewheel_scrolls))
1360 image_scroll(imd, 0, -MOUSEWHEEL_SCROLL_SIZE);
1362 case GDK_SCROLL_DOWN:
1363 image_scroll(imd, 0, MOUSEWHEEL_SCROLL_SIZE);
1365 case GDK_SCROLL_LEFT:
1366 image_scroll(imd, -MOUSEWHEEL_SCROLL_SIZE, 0);
1368 case GDK_SCROLL_RIGHT:
1369 image_scroll(imd, MOUSEWHEEL_SCROLL_SIZE, 0);
1380 layout_image_prev(lw);
1382 case GDK_SCROLL_DOWN:
1383 layout_image_next(lw);
1391 static void layout_image_set_buttons(LayoutWindow *lw)
1393 image_set_button_func(lw->image, layout_image_button_cb, lw);
1394 image_set_scroll_func(lw->image, layout_image_scroll_cb, lw);
1398 *----------------------------------------------------------------------------
1400 *----------------------------------------------------------------------------
1403 static void layout_image_update_cb(ImageWindow *imd, gpointer data)
1405 LayoutWindow *lw = data;
1406 layout_status_update_image(lw);
1409 GtkWidget *layout_image_new(LayoutWindow *lw, const gchar *path)
1413 lw->image = image_new( (!lw->tools_float && !lw->tools_hidden) );
1414 if (black_window_background) image_background_set_black(lw->image, TRUE);
1415 image_set_update_func(lw->image, layout_image_update_cb, lw);
1416 layout_image_set_buttons(lw);
1417 layout_image_dnd_init(lw);
1419 image_attach_window(lw->image, lw->window, NULL, "GQview", FALSE);
1421 image_auto_refresh(lw->image, 0);
1423 image_color_profile_set(lw->image,
1424 color_profile_input_type, color_profile_screen_type,
1425 color_profile_use_image);
1426 image_color_profile_set_use(lw->image, color_profile_enabled);
1429 return lw->image->widget;
1433 *-----------------------------------------------------------------------------
1434 * maintenance (for rename, move, remove)
1435 *-----------------------------------------------------------------------------
1438 void layout_image_maint_renamed(LayoutWindow *lw, const gchar *source, const gchar *dest)
1440 const gchar *img_path;
1442 img_path = layout_image_get_path(lw);
1443 if (img_path && strcmp(img_path, source) == 0)
1445 image_set_path(lw->image, dest);
1446 layout_bars_maint_renamed(lw);
1450 void layout_image_maint_removed(LayoutWindow *lw, const gchar *path)
1452 const gchar *img_path;
1454 img_path = layout_image_get_path(lw);
1455 if (img_path && strcmp(img_path, path) == 0)
1460 cd = image_get_collection(lw->image, &info);
1465 new = collection_next_by_info(cd, info);
1466 if (!new) new = collection_prev_by_info(cd, info);
1470 layout_image_set_collection(lw, cd, new);
1475 layout_image_set_path(lw, NULL);
1479 void layout_image_maint_moved(LayoutWindow *lw, const gchar *source, const gchar *dest)
1481 layout_image_maint_renamed(lw, source, dest);