dc141ae2748540cfb03e0fa709bac74d574f2767
[geeqie.git] / src / layout_image.c
1 /*
2  * Copyright (C) 2006 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
6  *
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.
11  *
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.
16  *
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.
20  */
21
22 #include "main.h"
23 #include "layout_image.h"
24
25 #include "collect.h"
26 #include "color-man.h"
27 #include "dnd.h"
28 #include "editors.h"
29 #include "exif.h"
30 #include "filedata.h"
31 #include "fullscreen.h"
32 #include "image.h"
33 #include "image-overlay.h"
34 #include "img-view.h"
35 #include "layout.h"
36 #include "layout_util.h"
37 #include "menu.h"
38 #include "metadata.h"
39 #include "misc.h"
40 #include "pixbuf_util.h"
41 #include "pixbuf-renderer.h"
42 #include "slideshow.h"
43 #include "ui_fileops.h"
44 #include "ui_menu.h"
45 #include "uri_utils.h"
46 #include "utilops.h"
47 #include "view_file.h"
48
49 #include <gdk/gdkkeysyms.h> /* for keyboard values */
50
51 #define FILE_COLUMN_POINTER 0
52
53 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw);
54 static void layout_image_set_buttons(LayoutWindow *lw);
55 static void layout_image_animate_stop(LayoutWindow *lw);
56 static gboolean layout_image_animate_new_file(LayoutWindow *lw);
57 static void layout_image_animate_update_image(LayoutWindow *lw);
58
59 /*
60  *----------------------------------------------------------------------------
61  * full screen overlay
62  *----------------------------------------------------------------------------
63  */
64
65 void layout_image_overlay_toggle(LayoutWindow *lw)
66 {
67         if (!lw) return;
68         image_osd_toggle(lw->image);
69 }
70
71 /*
72  *----------------------------------------------------------------------------
73  * full screen
74  *----------------------------------------------------------------------------
75  */
76
77 static void layout_image_full_screen_stop_func(FullScreenData *fs, gpointer data)
78 {
79         LayoutWindow *lw = data;
80
81         /* restore image window */
82         if (lw->image == fs->imd)
83                 lw->image = fs->normal_imd;
84
85         lw->full_screen = NULL;
86 }
87
88 void layout_image_full_screen_start(LayoutWindow *lw)
89 {
90         if (!layout_valid(&lw)) return;
91
92         if (lw->full_screen) return;
93
94         lw->full_screen = fullscreen_start(lw->window, lw->image,
95                                            layout_image_full_screen_stop_func, lw);
96
97         /* set to new image window */
98         if (lw->full_screen->same_region)
99                 lw->image = lw->full_screen->imd;
100
101         layout_image_set_buttons(lw);
102
103         g_signal_connect(G_OBJECT(lw->full_screen->window), "key_press_event",
104                          G_CALLBACK(layout_key_press_cb), lw);
105
106         layout_actions_add_window(lw, lw->full_screen->window);
107
108         image_osd_copy_status(lw->full_screen->normal_imd, lw->image);
109         layout_image_animate_update_image(lw);
110 }
111
112 void layout_image_full_screen_stop(LayoutWindow *lw)
113 {
114         if (!layout_valid(&lw)) return;
115         if (!lw->full_screen) return;
116
117         if (lw->image == lw->full_screen->imd)
118                 image_osd_copy_status(lw->image, lw->full_screen->normal_imd);
119
120         fullscreen_stop(lw->full_screen);
121
122         layout_image_animate_update_image(lw);
123 }
124
125 void layout_image_full_screen_toggle(LayoutWindow *lw)
126 {
127         if (!layout_valid(&lw)) return;
128         if (lw->full_screen)
129                 {
130                 layout_image_full_screen_stop(lw);
131                 }
132         else
133                 {
134                 layout_image_full_screen_start(lw);
135                 }
136 }
137
138 gboolean layout_image_full_screen_active(LayoutWindow *lw)
139 {
140         if (!layout_valid(&lw)) return FALSE;
141
142         return (lw->full_screen != NULL);
143 }
144
145 /*
146  *----------------------------------------------------------------------------
147  * slideshow
148  *----------------------------------------------------------------------------
149  */
150
151 static void layout_image_slideshow_next(LayoutWindow *lw)
152 {
153         if (lw->slideshow) slideshow_next(lw->slideshow);
154 }
155
156 static void layout_image_slideshow_prev(LayoutWindow *lw)
157 {
158         if (lw->slideshow) slideshow_prev(lw->slideshow);
159 }
160
161 static void layout_image_slideshow_stop_func(SlideShowData *ss, gpointer data)
162 {
163         LayoutWindow *lw = data;
164
165         lw->slideshow = NULL;
166         layout_status_update_info(lw, NULL);
167 }
168
169 void layout_image_slideshow_start(LayoutWindow *lw)
170 {
171         CollectionData *cd;
172         CollectInfo *info;
173
174         if (!layout_valid(&lw)) return;
175         if (lw->slideshow) return;
176
177         cd = image_get_collection(lw->image, &info);
178
179         if (cd && info)
180                 {
181                 lw->slideshow = slideshow_start_from_collection(lw, NULL, cd,
182                                 layout_image_slideshow_stop_func, lw, info);
183                 }
184         else
185                 {
186                 lw->slideshow = slideshow_start(lw,
187                                 layout_list_get_index(lw, layout_image_get_fd(lw)),
188                                 layout_image_slideshow_stop_func, lw);
189                 }
190
191         layout_status_update_info(lw, NULL);
192 }
193
194 /* note that slideshow will take ownership of the list, do not free it */
195 void layout_image_slideshow_start_from_list(LayoutWindow *lw, GList *list)
196 {
197         if (!layout_valid(&lw)) return;
198
199         if (lw->slideshow || !list)
200                 {
201                 filelist_free(list);
202                 return;
203                 }
204
205         lw->slideshow = slideshow_start_from_filelist(lw, NULL, list,
206                                                        layout_image_slideshow_stop_func, lw);
207
208         layout_status_update_info(lw, NULL);
209 }
210
211 void layout_image_slideshow_stop(LayoutWindow *lw)
212 {
213         if (!layout_valid(&lw)) return;
214
215         if (!lw->slideshow) return;
216
217         slideshow_free(lw->slideshow);
218         /* the stop_func sets lw->slideshow to NULL for us */
219 }
220
221 void layout_image_slideshow_toggle(LayoutWindow *lw)
222 {
223         if (!layout_valid(&lw)) return;
224
225         if (lw->slideshow)
226                 {
227                 layout_image_slideshow_stop(lw);
228                 }
229         else
230                 {
231                 layout_image_slideshow_start(lw);
232                 }
233 }
234
235 gboolean layout_image_slideshow_active(LayoutWindow *lw)
236 {
237         if (!layout_valid(&lw)) return FALSE;
238
239         return (lw->slideshow != NULL);
240 }
241
242 gboolean layout_image_slideshow_pause_toggle(LayoutWindow *lw)
243 {
244         gboolean ret;
245
246         if (!layout_valid(&lw)) return FALSE;
247
248         ret = slideshow_pause_toggle(lw->slideshow);
249
250         layout_status_update_info(lw, NULL);
251
252         return ret;
253 }
254
255 gboolean layout_image_slideshow_paused(LayoutWindow *lw)
256 {
257         if (!layout_valid(&lw)) return FALSE;
258
259         return (slideshow_paused(lw->slideshow));
260 }
261
262 static gboolean layout_image_slideshow_continue_check(LayoutWindow *lw)
263 {
264         if (!lw->slideshow) return FALSE;
265
266         if (!slideshow_should_continue(lw->slideshow))
267                 {
268                 layout_image_slideshow_stop(lw);
269                 return FALSE;
270                 }
271
272         return TRUE;
273 }
274
275 /*
276  *----------------------------------------------------------------------------
277  * Animation
278  *----------------------------------------------------------------------------
279  */
280
281 static void image_animation_data_free(AnimationData *fd)
282 {
283         if(!fd) return;
284         if(fd->iter) g_object_unref(fd->iter);
285         if(fd->gpa) g_object_unref(fd->gpa);
286         g_free(fd);
287 }
288
289 static gboolean animation_should_continue(AnimationData *fd)
290 {
291         if (!fd->valid)
292                 return FALSE;
293
294         return TRUE;
295 }
296
297 static gboolean show_next_frame(gpointer data)
298 {
299         AnimationData *fd = (AnimationData*)data;
300         int delay;
301         PixbufRenderer *pr;
302
303         if(animation_should_continue(fd)==FALSE)
304                 {
305                 image_animation_data_free(fd);
306                 return FALSE;
307                 }
308
309         pr = (PixbufRenderer*)fd->iw->pr;
310
311         if (gdk_pixbuf_animation_iter_advance(fd->iter,NULL)==FALSE)
312                 {
313                 /* This indicates the animation is complete.
314                    Return FALSE here to disable looping. */
315                 }
316
317         fd->gpb = gdk_pixbuf_animation_iter_get_pixbuf(fd->iter);
318         image_change_pixbuf(fd->iw,fd->gpb,pr->zoom,FALSE);
319
320         if (fd->iw->func_update)
321                 fd->iw->func_update(fd->iw, fd->iw->data_update);
322
323         delay = gdk_pixbuf_animation_iter_get_delay_time(fd->iter);
324         if (delay!=fd->delay)
325                 {
326                 if (delay>0) /* Current frame not static. */
327                         {
328                         fd->delay=delay;
329                         g_timeout_add(delay,show_next_frame,fd);
330                         }
331                 else
332                         {
333                         image_animation_data_free(fd);
334                         }
335                 return FALSE;
336                 }
337
338         return TRUE;
339 }
340
341 static gboolean layout_image_animate_check(LayoutWindow *lw)
342 {
343         if (!layout_valid(&lw)) return FALSE;
344
345         if(!lw->options.animate || lw->image->image_fd == NULL)
346                 {
347                 if(lw->animation)
348                         {
349                         lw->animation->valid = FALSE;
350                         lw->animation = NULL;
351                         }
352                 return FALSE;
353                 }
354
355         return TRUE;
356 }
357
358 static void layout_image_animate_stop(LayoutWindow *lw)
359 {
360         if (!layout_valid(&lw)) return;
361
362         if(lw->options.animate && lw->animation)
363                 {
364                 lw->animation->valid = FALSE;
365                 lw->animation = NULL;
366                 }
367 }
368
369 static void layout_image_animate_update_image(LayoutWindow *lw)
370 {
371         if (!layout_valid(&lw)) return;
372
373         if(lw->options.animate && lw->animation)
374                 {
375                 if (lw->full_screen && lw->image != lw->full_screen->imd)
376                         lw->animation->iw = lw->full_screen->imd;
377                 else
378                         lw->animation->iw = lw->image;
379                 }
380 }
381
382 static gboolean layout_image_animate_new_file(LayoutWindow *lw)
383 {
384         GError *err=NULL;
385
386         if(!layout_image_animate_check(lw)) return FALSE;
387
388         if(lw->animation) lw->animation->valid = FALSE;
389
390         lw->animation = g_malloc0(sizeof(AnimationData));
391
392         if(!(lw->animation->gpa = gdk_pixbuf_animation_new_from_file(lw->image->image_fd->path,&err)) || err ||
393                 gdk_pixbuf_animation_is_static_image(lw->animation->gpa) ||
394                 !(lw->animation->iter = gdk_pixbuf_animation_get_iter(lw->animation->gpa,NULL)))
395                 {
396                 image_animation_data_free(lw->animation);
397                 lw->animation = NULL;
398                 return FALSE;
399                 }
400
401         lw->animation->data_adr = lw->image->image_fd;
402         lw->animation->delay = gdk_pixbuf_animation_iter_get_delay_time(lw->animation->iter);
403         lw->animation->valid = TRUE;
404
405         layout_image_animate_update_image(lw);
406
407         g_timeout_add(lw->animation->delay, show_next_frame, lw->animation);
408
409         return TRUE;
410 }
411
412 void layout_image_animate_toggle(LayoutWindow *lw)
413 {
414         GtkAction *action;
415
416         if (!lw) return;
417
418         lw->options.animate = !lw->options.animate;
419
420         action = gtk_action_group_get_action(lw->action_group, "Animate");
421         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.animate);
422
423         layout_image_animate_new_file(lw);
424 }
425
426 /*
427  *----------------------------------------------------------------------------
428  * pop-up menus
429  *----------------------------------------------------------------------------
430  */
431
432 static void li_pop_menu_zoom_in_cb(GtkWidget *widget, gpointer data)
433 {
434         LayoutWindow *lw = data;
435
436         layout_image_zoom_adjust(lw, get_zoom_increment(), FALSE);
437 }
438
439 static void li_pop_menu_zoom_out_cb(GtkWidget *widget, gpointer data)
440 {
441         LayoutWindow *lw = data;
442         layout_image_zoom_adjust(lw, -get_zoom_increment(), FALSE);
443 }
444
445 static void li_pop_menu_zoom_1_1_cb(GtkWidget *widget, gpointer data)
446 {
447         LayoutWindow *lw = data;
448
449         layout_image_zoom_set(lw, 1.0, FALSE);
450 }
451
452 static void li_pop_menu_zoom_fit_cb(GtkWidget *widget, gpointer data)
453 {
454         LayoutWindow *lw = data;
455
456         layout_image_zoom_set(lw, 0.0, FALSE);
457 }
458
459 static void li_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
460 {
461         LayoutWindow *lw;
462         const gchar *key = data;
463
464         lw = submenu_item_get_data(widget);
465
466         if (!editor_window_flag_set(key))
467                 {
468                 layout_image_full_screen_stop(lw);
469                 }
470         file_util_start_editor_from_file(key, layout_image_get_fd(lw), lw->window);
471 }
472
473 static void li_pop_menu_wallpaper_cb(GtkWidget *widget, gpointer data)
474 {
475         LayoutWindow *lw = data;
476
477         layout_image_to_root(lw);
478 }
479
480 static void li_pop_menu_alter_cb(GtkWidget *widget, gpointer data)
481 {
482         LayoutWindow *lw = data;
483         AlterType type;
484
485         lw = submenu_item_get_data(widget);
486         type = (AlterType)GPOINTER_TO_INT(data);
487
488         image_alter_orientation(lw->image, lw->image->image_fd, type);
489 }
490
491 static void li_pop_menu_new_cb(GtkWidget *widget, gpointer data)
492 {
493         LayoutWindow *lw = data;
494
495         view_window_new(layout_image_get_fd(lw));
496 }
497
498 static GtkWidget *li_pop_menu_click_parent(GtkWidget *widget, LayoutWindow *lw)
499 {
500         GtkWidget *menu;
501         GtkWidget *parent;
502
503         menu = gtk_widget_get_toplevel(widget);
504         if (!menu) return NULL;
505
506         parent = g_object_get_data(G_OBJECT(menu), "click_parent");
507
508         if (!parent && lw->full_screen)
509                 {
510                 parent = lw->full_screen->imd->widget;
511                 }
512
513         return parent;
514 }
515
516 static void li_pop_menu_copy_cb(GtkWidget *widget, gpointer data)
517 {
518         LayoutWindow *lw = data;
519
520         file_util_copy(layout_image_get_fd(lw), NULL, NULL,
521                        li_pop_menu_click_parent(widget, lw));
522 }
523
524 static void li_pop_menu_copy_path_cb(GtkWidget *widget, gpointer data)
525 {
526         LayoutWindow *lw = data;
527
528         file_util_copy_path_to_clipboard(layout_image_get_fd(lw));
529 }
530
531 static void li_pop_menu_move_cb(GtkWidget *widget, gpointer data)
532 {
533         LayoutWindow *lw = data;
534
535         file_util_move(layout_image_get_fd(lw), NULL, NULL,
536                        li_pop_menu_click_parent(widget, lw));
537 }
538
539 static void li_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
540 {
541         LayoutWindow *lw = data;
542
543         file_util_rename(layout_image_get_fd(lw), NULL,
544                          li_pop_menu_click_parent(widget, lw));
545 }
546
547 static void li_pop_menu_delete_cb(GtkWidget *widget, gpointer data)
548 {
549         LayoutWindow *lw = data;
550
551         file_util_delete(layout_image_get_fd(lw), NULL,
552                          li_pop_menu_click_parent(widget, lw));
553 }
554
555 static void li_pop_menu_slide_start_cb(GtkWidget *widget, gpointer data)
556 {
557         LayoutWindow *lw = data;
558
559         layout_image_slideshow_start(lw);
560 }
561
562 static void li_pop_menu_slide_stop_cb(GtkWidget *widget, gpointer data)
563 {
564         LayoutWindow *lw = data;
565
566         layout_image_slideshow_stop(lw);
567 }
568
569 static void li_pop_menu_slide_pause_cb(GtkWidget *widget, gpointer data)
570 {
571         LayoutWindow *lw = data;
572
573         layout_image_slideshow_pause_toggle(lw);
574 }
575
576 static void li_pop_menu_full_screen_cb(GtkWidget *widget, gpointer data)
577 {
578         LayoutWindow *lw = data;
579
580         layout_image_full_screen_toggle(lw);
581 }
582
583 static void li_pop_menu_animate_cb(GtkWidget *widget, gpointer data)
584 {
585         LayoutWindow *lw = data;
586
587         layout_image_animate_toggle(lw);
588 }
589
590 static void li_pop_menu_hide_cb(GtkWidget *widget, gpointer data)
591 {
592         LayoutWindow *lw = data;
593
594         layout_tools_hide_toggle(lw);
595 }
596
597 static void li_set_layout_path_cb(GtkWidget *widget, gpointer data)
598 {
599         LayoutWindow *lw = data;
600         FileData *fd;
601
602         if (!layout_valid(&lw)) return;
603
604         fd = layout_image_get_fd(lw);
605         if (fd) layout_set_fd(lw, fd);
606 }
607
608 static gboolean li_check_if_current_path(LayoutWindow *lw, const gchar *path)
609 {
610         gchar *dirname;
611         gboolean ret;
612
613         if (!path || !layout_valid(&lw) || !lw->dir_fd) return FALSE;
614
615         dirname = g_path_get_dirname(path);
616         ret = (strcmp(lw->dir_fd->path, dirname) == 0);
617         g_free(dirname);
618         return ret;
619 }
620
621 static void layout_image_popup_menu_destroy_cb(GtkWidget *widget, gpointer data)
622 {
623         GList *editmenu_fd_list = data;
624
625         filelist_free(editmenu_fd_list);
626 }
627
628 static GList *layout_image_get_fd_list(LayoutWindow *lw)
629 {
630         GList *list = NULL;
631         FileData *fd = layout_image_get_fd(lw);
632
633         if (fd)
634                 {
635                 if (lw->vf)
636                         /* optionally include sidecars if the filelist entry is not expanded */
637                         list = vf_selection_get_one(lw->vf, fd);
638                 else
639                         list = g_list_append(NULL, file_data_ref(fd));
640                 }
641
642         return list;
643 }
644
645 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
646 {
647         GtkWidget *menu;
648         GtkWidget *item;
649         GtkWidget *submenu;
650         const gchar *path;
651         gboolean fullscreen;
652         GList *editmenu_fd_list;
653
654         path = layout_image_get_path(lw);
655         fullscreen = layout_image_full_screen_active(lw);
656
657         menu = popup_menu_short_lived();
658
659         menu_item_add_stock(menu, _("Zoom _in"), GTK_STOCK_ZOOM_IN, G_CALLBACK(li_pop_menu_zoom_in_cb), lw);
660         menu_item_add_stock(menu, _("Zoom _out"), GTK_STOCK_ZOOM_OUT, G_CALLBACK(li_pop_menu_zoom_out_cb), lw);
661         menu_item_add_stock(menu, _("Zoom _1:1"), GTK_STOCK_ZOOM_100, G_CALLBACK(li_pop_menu_zoom_1_1_cb), lw);
662         menu_item_add_stock(menu, _("Fit image to _window"), GTK_STOCK_ZOOM_FIT, G_CALLBACK(li_pop_menu_zoom_fit_cb), lw);
663         menu_item_add_divider(menu);
664
665         editmenu_fd_list = layout_image_get_fd_list(lw);
666         g_signal_connect(G_OBJECT(menu), "destroy",
667                          G_CALLBACK(layout_image_popup_menu_destroy_cb), editmenu_fd_list);
668         submenu = submenu_add_edit(menu, &item, G_CALLBACK(li_pop_menu_edit_cb), lw, editmenu_fd_list);
669         if (!path) gtk_widget_set_sensitive(item, FALSE);
670         menu_item_add_divider(submenu);
671         menu_item_add(submenu, _("Set as _wallpaper"), G_CALLBACK(li_pop_menu_wallpaper_cb), lw);
672
673         item = submenu_add_alter(menu, G_CALLBACK(li_pop_menu_alter_cb), lw);
674
675         item = menu_item_add_stock(menu, _("View in _new window"), GTK_STOCK_NEW, G_CALLBACK(li_pop_menu_new_cb), lw);
676         if (!path || fullscreen) gtk_widget_set_sensitive(item, FALSE);
677
678         item = menu_item_add(menu, _("_Go to directory view"), G_CALLBACK(li_set_layout_path_cb), lw);
679         if (!path || li_check_if_current_path(lw, path)) gtk_widget_set_sensitive(item, FALSE);
680
681         menu_item_add_divider(menu);
682
683         item = menu_item_add_stock(menu, _("_Copy..."), GTK_STOCK_COPY, G_CALLBACK(li_pop_menu_copy_cb), lw);
684         if (!path) gtk_widget_set_sensitive(item, FALSE);
685         item = menu_item_add(menu, _("_Move..."), G_CALLBACK(li_pop_menu_move_cb), lw);
686         if (!path) gtk_widget_set_sensitive(item, FALSE);
687         item = menu_item_add(menu, _("_Rename..."), G_CALLBACK(li_pop_menu_rename_cb), lw);
688         if (!path) gtk_widget_set_sensitive(item, FALSE);
689         item = menu_item_add_stock(menu, _("_Delete..."), GTK_STOCK_DELETE, G_CALLBACK(li_pop_menu_delete_cb), lw);
690         if (!path) gtk_widget_set_sensitive(item, FALSE);
691
692         item = menu_item_add(menu, _("_Copy path"), G_CALLBACK(li_pop_menu_copy_path_cb), lw);
693         if (!path) gtk_widget_set_sensitive(item, FALSE);
694
695         menu_item_add_divider(menu);
696
697         if (layout_image_slideshow_active(lw))
698                 {
699                 menu_item_add(menu, _("_Stop slideshow"), G_CALLBACK(li_pop_menu_slide_stop_cb), lw);
700                 if (layout_image_slideshow_paused(lw))
701                         {
702                         item = menu_item_add(menu, _("Continue slides_how"),
703                                              G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
704                         }
705                 else
706                         {
707                         item = menu_item_add(menu, _("Pause slides_how"),
708                                              G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
709                         }
710                 }
711         else
712                 {
713                 menu_item_add(menu, _("_Start slideshow"), G_CALLBACK(li_pop_menu_slide_start_cb), lw);
714                 item = menu_item_add(menu, _("Pause slides_how"), G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
715                 gtk_widget_set_sensitive(item, FALSE);
716                 }
717
718         if (!fullscreen)
719                 {
720                 menu_item_add(menu, _("_Full screen"), G_CALLBACK(li_pop_menu_full_screen_cb), lw);
721                 }
722         else
723                 {
724                 menu_item_add(menu, _("Exit _full screen"), G_CALLBACK(li_pop_menu_full_screen_cb), lw);
725                 }
726
727         menu_item_add_check(menu, _("_Animate"), lw->options.animate, G_CALLBACK(li_pop_menu_animate_cb), lw);
728
729         menu_item_add_divider(menu);
730
731         item = menu_item_add_check(menu, _("Hide file _list"), lw->options.tools_hidden,
732                                    G_CALLBACK(li_pop_menu_hide_cb), lw);
733         if (fullscreen) gtk_widget_set_sensitive(item, FALSE);
734
735         return menu;
736 }
737
738 static void layout_image_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
739 {
740         LayoutWindow *lw = data;
741
742         gdk_window_get_origin(gtk_widget_get_window(lw->image->pr), x, y);
743         popup_menu_position_clamp(menu, x, y, 0);
744 }
745
746 void layout_image_menu_popup(LayoutWindow *lw)
747 {
748         GtkWidget *menu;
749
750         menu = layout_image_pop_menu(lw);
751         gtk_menu_popup(GTK_MENU(menu), NULL, NULL, layout_image_menu_pos_cb, lw, 0, GDK_CURRENT_TIME);
752 }
753
754 /*
755  *----------------------------------------------------------------------------
756  * dnd
757  *----------------------------------------------------------------------------
758  */
759
760 static void layout_image_dnd_receive(GtkWidget *widget, GdkDragContext *context,
761                                      gint x, gint y,
762                                      GtkSelectionData *selection_data, guint info,
763                                      guint time, gpointer data)
764 {
765         LayoutWindow *lw = data;
766         gint i;
767
768
769         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
770                 {
771                 if (lw->split_images[i] && lw->split_images[i]->pr == widget)
772                         break;
773                 }
774         if (i < MAX_SPLIT_IMAGES)
775                 {
776                 DEBUG_1("dnd image activate %d", i);
777                 layout_image_activate(lw, i, FALSE);
778                 }
779
780
781         if (info == TARGET_URI_LIST || info == TARGET_APP_COLLECTION_MEMBER)
782                 {
783                 CollectionData *source;
784                 GList *list;
785                 GList *info_list;
786
787                 if (info == TARGET_URI_LIST)
788                         {
789                         list = uri_filelist_from_gtk_selection_data(selection_data);
790                         source = NULL;
791                         info_list = NULL;
792                         }
793                 else
794                         {
795                         source = collection_from_dnd_data((gchar *)gtk_selection_data_get_data(selection_data), &list, &info_list);
796                         }
797
798                 if (list)
799                         {
800                         FileData *fd = list->data;
801
802                         if (isfile(fd->path))
803                                 {
804                                 gchar *base;
805                                 gint row;
806                                 FileData *dir_fd;
807
808                                 base = remove_level_from_path(fd->path);
809                                 dir_fd = file_data_new_dir(base);
810                                 if (dir_fd != lw->dir_fd)
811                                         {
812                                         layout_set_fd(lw, dir_fd);
813                                         }
814                                 file_data_unref(dir_fd);
815                                 g_free(base);
816
817                                 row = layout_list_get_index(lw, fd);
818                                 if (source && info_list)
819                                         {
820                                         layout_image_set_collection(lw, source, info_list->data);
821                                         }
822                                 else if (row == -1)
823                                         {
824                                         layout_image_set_fd(lw, fd);
825                                         }
826                                 else
827                                         {
828                                         layout_image_set_index(lw, row);
829                                         }
830                                 }
831                         else if (isdir(fd->path))
832                                 {
833                                 layout_set_fd(lw, fd);
834                                 layout_image_set_fd(lw, NULL);
835                                 }
836                         }
837
838                 filelist_free(list);
839                 g_list_free(info_list);
840                 }
841 }
842
843 static void layout_image_dnd_get(GtkWidget *widget, GdkDragContext *context,
844                                  GtkSelectionData *selection_data, guint info,
845                                  guint time, gpointer data)
846 {
847         LayoutWindow *lw = data;
848         FileData *fd;
849         gint i;
850
851
852         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
853                 {
854                 if (lw->split_images[i] && lw->split_images[i]->pr == widget)
855                         break;
856                 }
857         if (i < MAX_SPLIT_IMAGES)
858                 {
859                 DEBUG_1("dnd get from %d", i);
860                 fd = image_get_fd(lw->split_images[i]);
861                 }
862         else
863                 fd = layout_image_get_fd(lw);
864
865         if (fd)
866                 {
867                 GList *list;
868
869                 list = g_list_append(NULL, fd);
870                 uri_selection_data_set_uris_from_filelist(selection_data, list);
871                 g_list_free(list);
872                 }
873         else
874                 {
875                 gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
876                                        8, NULL, 0);
877                 }
878 }
879
880 static void layout_image_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
881 {
882         LayoutWindow *lw = data;
883         if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
884                 {
885                 FileData *fd;
886                 gint row;
887
888                 fd = layout_image_get_fd(lw);
889                 row = layout_list_get_index(lw, fd);
890                 if (row < 0) return;
891
892                 if (!isfile(fd->path))
893                         {
894                         if ((guint) row < layout_list_count(lw, NULL) - 1)
895                                 {
896                                 layout_image_next(lw);
897                                 }
898                         else
899                                 {
900                                 layout_image_prev(lw);
901                                 }
902                         }
903                 layout_refresh(lw);
904                 }
905 }
906
907 static void layout_image_dnd_init(LayoutWindow *lw, gint i)
908 {
909         ImageWindow *imd = lw->split_images[i];
910
911         gtk_drag_source_set(imd->pr, GDK_BUTTON2_MASK,
912                             dnd_file_drag_types, dnd_file_drag_types_count,
913                             GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
914         g_signal_connect(G_OBJECT(imd->pr), "drag_data_get",
915                          G_CALLBACK(layout_image_dnd_get), lw);
916         g_signal_connect(G_OBJECT(imd->pr), "drag_end",
917                          G_CALLBACK(layout_image_dnd_end), lw);
918
919         gtk_drag_dest_set(imd->pr,
920                           GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
921                           dnd_file_drop_types, dnd_file_drop_types_count,
922                           GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
923         g_signal_connect(G_OBJECT(imd->pr), "drag_data_received",
924                          G_CALLBACK(layout_image_dnd_receive), lw);
925 }
926
927
928 /*
929  *----------------------------------------------------------------------------
930  * misc
931  *----------------------------------------------------------------------------
932  */
933
934 void layout_image_to_root(LayoutWindow *lw)
935 {
936         image_to_root_window(lw->image, (image_zoom_get(lw->image) == 0));
937 }
938
939 /*
940  *----------------------------------------------------------------------------
941  * manipulation + accessors
942  *----------------------------------------------------------------------------
943  */
944
945 void layout_image_scroll(LayoutWindow *lw, gint x, gint y, gboolean connect_scroll)
946 {
947         gdouble dx, dy;
948         gint width, height, i;
949         if (!layout_valid(&lw)) return;
950
951         image_scroll(lw->image, x, y);
952
953         if (lw->full_screen && lw->image != lw->full_screen->imd)
954                 {
955                 image_scroll(lw->full_screen->imd, x, y);
956                 }
957
958         if (!connect_scroll) return;
959
960         image_get_image_size(lw->image, &width, &height);
961         dx = (gdouble) x / width;
962         dy = (gdouble) y / height;
963
964         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
965                 {
966                 if (lw->split_images[i] && lw->split_images[i] != lw->image)
967                         {
968                         gdouble sx, sy;
969                         image_get_scroll_center(lw->split_images[i], &sx, &sy);
970                         sx += dx;
971                         sy += dy;
972                         image_set_scroll_center(lw->split_images[i], sx, sy);
973                         }
974                 }
975
976 }
977
978 void layout_image_zoom_adjust(LayoutWindow *lw, gdouble increment, gboolean connect_zoom)
979 {
980         gint i;
981         if (!layout_valid(&lw)) return;
982
983         image_zoom_adjust(lw->image, increment);
984
985         if (lw->full_screen && lw->image != lw->full_screen->imd)
986                 {
987                 image_zoom_adjust(lw->full_screen->imd, increment);
988                 }
989
990         if (!connect_zoom) return;
991
992         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
993                 {
994                 if (lw->split_images[i] && lw->split_images[i] != lw->image)
995                         image_zoom_adjust(lw->split_images[i], increment); ;
996                 }
997 }
998
999 void layout_image_zoom_adjust_at_point(LayoutWindow *lw, gdouble increment, gint x, gint y, gboolean connect_zoom)
1000 {
1001         gint i;
1002         if (!layout_valid(&lw)) return;
1003
1004         image_zoom_adjust_at_point(lw->image, increment, x, y);
1005
1006         if (lw->full_screen && lw->image != lw->full_screen->imd)
1007                 {
1008                 image_zoom_adjust_at_point(lw->full_screen->imd, increment, x, y);
1009                 }
1010         if (!connect_zoom && !lw->split_mode) return;
1011
1012         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1013                 {
1014                 if (lw->split_images[i] && lw->split_images[i] != lw->image &&
1015                                                 lw->split_images[i]->mouse_wheel_mode)
1016                         image_zoom_adjust_at_point(lw->split_images[i], increment, x, y);
1017                 }
1018 }
1019
1020 void layout_image_zoom_set(LayoutWindow *lw, gdouble zoom, gboolean connect_zoom)
1021 {
1022         gint i;
1023         if (!layout_valid(&lw)) return;
1024
1025         image_zoom_set(lw->image, zoom);
1026
1027         if (lw->full_screen && lw->image != lw->full_screen->imd)
1028                 {
1029                 image_zoom_set(lw->full_screen->imd, zoom);
1030                 }
1031
1032         if (!connect_zoom) return;
1033
1034         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1035                 {
1036                 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1037                         image_zoom_set(lw->split_images[i], zoom);
1038                 }
1039 }
1040
1041 void layout_image_zoom_set_fill_geometry(LayoutWindow *lw, gboolean vertical, gboolean connect_zoom)
1042 {
1043         gint i;
1044         if (!layout_valid(&lw)) return;
1045
1046         image_zoom_set_fill_geometry(lw->image, vertical);
1047
1048         if (lw->full_screen && lw->image != lw->full_screen->imd)
1049                 {
1050                 image_zoom_set_fill_geometry(lw->full_screen->imd, vertical);
1051                 }
1052
1053         if (!connect_zoom) return;
1054
1055         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1056                 {
1057                 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1058                         image_zoom_set_fill_geometry(lw->split_images[i], vertical);
1059                 }
1060 }
1061
1062 void layout_image_alter_orientation(LayoutWindow *lw, AlterType type)
1063 {
1064         if (!layout_valid(&lw)) return;
1065
1066         GtkTreeModel *store;
1067         GList *work;
1068         GtkTreeSelection *selection;
1069         GtkTreePath *tpath;
1070         FileData *fd_n;
1071         GtkTreeIter iter;
1072         IconData *id;
1073
1074         if (!lw || !lw->vf) return;
1075
1076         if (lw->vf->type == FILEVIEW_ICON)
1077                 {
1078                 if (!VFICON(lw->vf)->selection) return;
1079                 work = VFICON(lw->vf)->selection;
1080                 }
1081         else
1082                 {
1083                 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
1084                 work = gtk_tree_selection_get_selected_rows(selection, &store);
1085                 }
1086
1087         while (work)
1088                 {
1089                 if (lw->vf->type == FILEVIEW_ICON)
1090                         {
1091                         id = work->data;
1092                         fd_n = id->fd;
1093                         work = work->next;
1094                         }
1095                 else
1096                         {
1097                         tpath = work->data;
1098                         gtk_tree_model_get_iter(store, &iter, tpath);
1099                         gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
1100                         work = work->next;
1101                         }
1102
1103                 image_alter_orientation(lw->image, fd_n, type);
1104                 }
1105 }
1106
1107 void layout_image_reset_orientation(LayoutWindow *lw)
1108 {
1109         ImageWindow *imd= lw->image;
1110
1111         if (!layout_valid(&lw)) return;
1112         if (!imd || !imd->pr || !imd->image_fd) return;
1113
1114         if (imd->orientation < 1 || imd->orientation > 8) imd->orientation = 1;
1115
1116         if (options->image.exif_rotate_enable)
1117                 {
1118                 imd->orientation = metadata_read_int(imd->image_fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
1119                 }
1120         else
1121                 {
1122                 imd->orientation = 1;
1123                 }
1124
1125         if (imd->image_fd->user_orientation != 0)
1126                 {
1127                  imd->orientation = imd->image_fd->user_orientation;
1128                 }
1129
1130         pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation);
1131 }
1132
1133 void layout_image_set_desaturate(LayoutWindow *lw, gboolean desaturate)
1134 {
1135         if (!layout_valid(&lw)) return;
1136
1137         image_set_desaturate(lw->image, desaturate);
1138 }
1139
1140 gboolean layout_image_get_desaturate(LayoutWindow *lw)
1141 {
1142         if (!layout_valid(&lw)) return FALSE;
1143
1144         return image_get_desaturate(lw->image);
1145 }
1146
1147 /* stereo */
1148 /*
1149 gint layout_image_stereo_get(LayoutWindow *lw)
1150 {
1151         if (!layout_valid(&lw)) return 0;
1152
1153         return image_stereo_get(lw->image);
1154 }
1155
1156 void layout_image_stereo_set(LayoutWindow *lw, gint stereo_mode)
1157 {
1158         if (!layout_valid(&lw)) return;
1159
1160         image_stereo_set(lw->image, stereo_mode);
1161 }
1162 void layout_image_stereo_swap(LayoutWindow *lw)
1163 {
1164         if (!layout_valid(&lw)) return;
1165
1166         image_stereo_swap(lw->image);
1167 }
1168 */
1169
1170 gint layout_image_stereo_pixbuf_get(LayoutWindow *lw)
1171 {
1172         if (!layout_valid(&lw)) return 0;
1173
1174         return image_stereo_pixbuf_get(lw->image);
1175 }
1176
1177 void layout_image_stereo_pixbuf_set(LayoutWindow *lw, gint stereo_mode)
1178 {
1179         if (!layout_valid(&lw)) return;
1180
1181         image_stereo_pixbuf_set(lw->image, stereo_mode);
1182 }
1183
1184 const gchar *layout_image_get_path(LayoutWindow *lw)
1185 {
1186         if (!layout_valid(&lw)) return NULL;
1187
1188         return image_get_path(lw->image);
1189 }
1190
1191 const gchar *layout_image_get_name(LayoutWindow *lw)
1192 {
1193         if (!layout_valid(&lw)) return NULL;
1194
1195         return image_get_name(lw->image);
1196 }
1197
1198 FileData *layout_image_get_fd(LayoutWindow *lw)
1199 {
1200         if (!layout_valid(&lw)) return NULL;
1201
1202         return image_get_fd(lw->image);
1203 }
1204
1205 CollectionData *layout_image_get_collection(LayoutWindow *lw, CollectInfo **info)
1206 {
1207         if (!layout_valid(&lw)) return NULL;
1208
1209         return image_get_collection(lw->image, info);
1210 }
1211
1212 gint layout_image_get_index(LayoutWindow *lw)
1213 {
1214         return layout_list_get_index(lw, image_get_fd(lw->image));
1215 }
1216
1217 /*
1218  *----------------------------------------------------------------------------
1219  * image changers
1220  *----------------------------------------------------------------------------
1221  */
1222
1223 void layout_image_set_fd(LayoutWindow *lw, FileData *fd)
1224 {
1225         if (!layout_valid(&lw)) return;
1226
1227         image_change_fd(lw->image, fd, image_zoom_get_default(lw->image));
1228
1229         if (lw->full_screen && lw->image != lw->full_screen->imd)
1230                 {
1231                 image_change_fd(lw->full_screen->imd, fd, image_zoom_get_default(lw->full_screen->imd));
1232                 }
1233
1234
1235         layout_list_sync_fd(lw, fd);
1236         layout_image_slideshow_continue_check(lw);
1237         layout_bars_new_image(lw);
1238         layout_image_animate_new_file(lw);
1239 }
1240
1241 void layout_image_set_with_ahead(LayoutWindow *lw, FileData *fd, FileData *read_ahead_fd)
1242 {
1243         if (!layout_valid(&lw)) return;
1244
1245 /*
1246 This should be handled at the caller: in vflist_select_image
1247         if (path)
1248                 {
1249                 const gchar *old_path;
1250
1251                 old_path = layout_image_get_path(lw);
1252                 if (old_path && strcmp(path, old_path) == 0) return;
1253                 }
1254 */
1255         layout_image_set_fd(lw, fd);
1256         if (options->image.enable_read_ahead) image_prebuffer_set(lw->image, read_ahead_fd);
1257 }
1258
1259 void layout_image_set_index(LayoutWindow *lw, gint index)
1260 {
1261         FileData *fd;
1262         FileData *read_ahead_fd;
1263         gint old;
1264
1265         if (!layout_valid(&lw)) return;
1266
1267         old = layout_list_get_index(lw, layout_image_get_fd(lw));
1268         fd = layout_list_get_fd(lw, index);
1269
1270         if (old > index)
1271                 {
1272                 read_ahead_fd = layout_list_get_fd(lw, index - 1);
1273                 }
1274         else
1275                 {
1276                 read_ahead_fd = layout_list_get_fd(lw, index + 1);
1277                 }
1278
1279         if (layout_selection_count(lw, 0) > 1)
1280                 {
1281                 GList *x = layout_selection_list_by_index(lw);
1282                 GList *y;
1283                 GList *last;
1284
1285                 for (last = y = x; y; y = y->next)
1286                         last = y;
1287                 for (y = x; y && (GPOINTER_TO_INT(y->data)) != index; y = y->next)
1288                         ;
1289
1290                 if (y)
1291                         {
1292                         gint newindex;
1293
1294                         if ((index > old && (index != GPOINTER_TO_INT(last->data) || old != GPOINTER_TO_INT(x->data)))
1295                             || (old == GPOINTER_TO_INT(last->data) && index == GPOINTER_TO_INT(x->data)))
1296                                 {
1297                                 if (y->next)
1298                                         newindex = GPOINTER_TO_INT(y->next->data);
1299                                 else
1300                                         newindex = GPOINTER_TO_INT(x->data);
1301                                 }
1302                         else
1303                                 {
1304                                 if (y->prev)
1305                                         newindex = GPOINTER_TO_INT(y->prev->data);
1306                                 else
1307                                         newindex = GPOINTER_TO_INT(last->data);
1308                                 }
1309
1310                         read_ahead_fd = layout_list_get_fd(lw, newindex);
1311                         }
1312
1313                 while (x)
1314                         x = g_list_remove(x, x->data);
1315                 }
1316
1317         layout_image_set_with_ahead(lw, fd, read_ahead_fd);
1318 }
1319
1320 static void layout_image_set_collection_real(LayoutWindow *lw, CollectionData *cd, CollectInfo *info, gboolean forward)
1321 {
1322         if (!layout_valid(&lw)) return;
1323
1324         image_change_from_collection(lw->image, cd, info, image_zoom_get_default(lw->image));
1325         if (options->image.enable_read_ahead)
1326                 {
1327                 CollectInfo *r_info;
1328                 if (forward)
1329                         {
1330                         r_info = collection_next_by_info(cd, info);
1331                         if (!r_info) r_info = collection_prev_by_info(cd, info);
1332                         }
1333                 else
1334                         {
1335                         r_info = collection_prev_by_info(cd, info);
1336                         if (!r_info) r_info = collection_next_by_info(cd, info);
1337                         }
1338                 if (r_info) image_prebuffer_set(lw->image, r_info->fd);
1339                 }
1340
1341         layout_image_slideshow_continue_check(lw);
1342         layout_bars_new_image(lw);
1343 }
1344
1345 void layout_image_set_collection(LayoutWindow *lw, CollectionData *cd, CollectInfo *info)
1346 {
1347         layout_image_set_collection_real(lw, cd, info, TRUE);
1348         layout_list_sync_fd(lw, layout_image_get_fd(lw));
1349 }
1350
1351 void layout_image_refresh(LayoutWindow *lw)
1352 {
1353         if (!layout_valid(&lw)) return;
1354
1355         image_reload(lw->image);
1356 }
1357
1358 void layout_image_color_profile_set(LayoutWindow *lw,
1359                                     gint input_type,
1360                                     gboolean use_image)
1361 {
1362         if (!layout_valid(&lw)) return;
1363
1364         image_color_profile_set(lw->image, input_type, use_image);
1365 }
1366
1367 gboolean layout_image_color_profile_get(LayoutWindow *lw,
1368                                         gint *input_type,
1369                                         gboolean *use_image)
1370 {
1371         if (!layout_valid(&lw)) return FALSE;
1372
1373         return image_color_profile_get(lw->image, input_type, use_image);
1374 }
1375
1376 void layout_image_color_profile_set_use(LayoutWindow *lw, gboolean enable)
1377 {
1378         if (!layout_valid(&lw)) return;
1379
1380         image_color_profile_set_use(lw->image, enable);
1381 }
1382
1383 gboolean layout_image_color_profile_get_use(LayoutWindow *lw)
1384 {
1385         if (!layout_valid(&lw)) return FALSE;
1386
1387         return image_color_profile_get_use(lw->image);
1388 }
1389
1390 gboolean layout_image_color_profile_get_status(LayoutWindow *lw, gchar **image_profile, gchar **screen_profile)
1391 {
1392         if (!layout_valid(&lw)) return FALSE;
1393
1394         return image_color_profile_get_status(lw->image, image_profile, screen_profile);
1395 }
1396
1397 /*
1398  *----------------------------------------------------------------------------
1399  * list walkers
1400  *----------------------------------------------------------------------------
1401  */
1402
1403 void layout_image_next(LayoutWindow *lw)
1404 {
1405         gint current;
1406         CollectionData *cd;
1407         CollectInfo *info;
1408
1409         if (!layout_valid(&lw)) return;
1410
1411         if (layout_image_slideshow_active(lw))
1412                 {
1413                 layout_image_slideshow_next(lw);
1414                 return;
1415                 }
1416
1417         if (layout_selection_count(lw, 0) > 1)
1418                 {
1419                 GList *x = layout_selection_list_by_index(lw);
1420                 gint old = layout_list_get_index(lw, layout_image_get_fd(lw));
1421                 GList *y;
1422
1423                 for (y = x; y && (GPOINTER_TO_INT(y->data)) != old; y = y->next)
1424                         ;
1425                 if (y)
1426                         {
1427                         if (y->next)
1428                                 layout_image_set_index(lw, GPOINTER_TO_INT(y->next->data));
1429                         else
1430                                 layout_image_set_index(lw, GPOINTER_TO_INT(x->data));
1431                         }
1432                 while (x)
1433                         x = g_list_remove(x, x->data);
1434                 if (y) /* not dereferenced */
1435                         return;
1436                 }
1437
1438         cd = image_get_collection(lw->image, &info);
1439
1440         if (cd && info)
1441                 {
1442                 info = collection_next_by_info(cd, info);
1443                 if (info)
1444                         {
1445                         layout_image_set_collection_real(lw, cd, info, TRUE);
1446                         }
1447                 else
1448                         {
1449                         image_osd_icon(lw->image, IMAGE_OSD_LAST, -1);
1450                         }
1451                 return;
1452                 }
1453
1454         current = layout_image_get_index(lw);
1455
1456         if (current >= 0)
1457                 {
1458                 if ((guint) current < layout_list_count(lw, NULL) - 1)
1459                         {
1460                         layout_image_set_index(lw, current + 1);
1461                         }
1462                 else
1463                         {
1464                         image_osd_icon(lw->image, IMAGE_OSD_LAST, -1);
1465                         }
1466                 }
1467         else
1468                 {
1469                 layout_image_set_index(lw, 0);
1470                 }
1471 }
1472
1473 void layout_image_prev(LayoutWindow *lw)
1474 {
1475         gint current;
1476         CollectionData *cd;
1477         CollectInfo *info;
1478
1479         if (!layout_valid(&lw)) return;
1480
1481         if (layout_image_slideshow_active(lw))
1482                 {
1483                 layout_image_slideshow_prev(lw);
1484                 return;
1485                 }
1486
1487         if (layout_selection_count(lw, 0) > 1)
1488                 {
1489                 GList *x = layout_selection_list_by_index(lw);
1490                 gint old = layout_list_get_index(lw, layout_image_get_fd(lw));
1491                 GList *y;
1492                 GList *last;
1493
1494                 for (last = y = x; y; y = y->next)
1495                         last = y;
1496                 for (y = x; y && (GPOINTER_TO_INT(y->data)) != old; y = y->next)
1497                         ;
1498                 if (y)
1499                         {
1500                         if (y->prev)
1501                                 layout_image_set_index(lw, GPOINTER_TO_INT(y->prev->data));
1502                         else
1503                                 layout_image_set_index(lw, GPOINTER_TO_INT(last->data));
1504                         }
1505                 while (x)
1506                         x = g_list_remove(x, x->data);
1507                 if (y) /* not dereferenced */
1508                         return;
1509                 }
1510
1511         cd = image_get_collection(lw->image, &info);
1512
1513         if (cd && info)
1514                 {
1515                 info = collection_prev_by_info(cd, info);
1516                 if (info)
1517                         {
1518                         layout_image_set_collection_real(lw, cd, info, FALSE);
1519                         }
1520                 else
1521                         {
1522                         image_osd_icon(lw->image, IMAGE_OSD_FIRST, -1);
1523                         }
1524                 return;
1525                 }
1526
1527         current = layout_image_get_index(lw);
1528
1529         if (current >= 0)
1530                 {
1531                 if (current > 0)
1532                         {
1533                         layout_image_set_index(lw, current - 1);
1534                         }
1535                 else
1536                         {
1537                         image_osd_icon(lw->image, IMAGE_OSD_FIRST, -1);
1538                         }
1539                 }
1540         else
1541                 {
1542                 layout_image_set_index(lw, layout_list_count(lw, NULL) - 1);
1543                 }
1544 }
1545
1546 void layout_image_first(LayoutWindow *lw)
1547 {
1548         gint current;
1549         CollectionData *cd;
1550         CollectInfo *info;
1551
1552         if (!layout_valid(&lw)) return;
1553
1554         cd = image_get_collection(lw->image, &info);
1555
1556         if (cd && info)
1557                 {
1558                 CollectInfo *new;
1559                 new = collection_get_first(cd);
1560                 if (new != info) layout_image_set_collection_real(lw, cd, new, TRUE);
1561                 return;
1562                 }
1563
1564         current = layout_image_get_index(lw);
1565         if (current != 0 && layout_list_count(lw, NULL) > 0)
1566                 {
1567                 layout_image_set_index(lw, 0);
1568                 }
1569 }
1570
1571 void layout_image_last(LayoutWindow *lw)
1572 {
1573         gint current;
1574         gint count;
1575         CollectionData *cd;
1576         CollectInfo *info;
1577
1578         if (!layout_valid(&lw)) return;
1579
1580         cd = image_get_collection(lw->image, &info);
1581
1582         if (cd && info)
1583                 {
1584                 CollectInfo *new;
1585                 new = collection_get_last(cd);
1586                 if (new != info) layout_image_set_collection_real(lw, cd, new, FALSE);
1587                 return;
1588                 }
1589
1590         current = layout_image_get_index(lw);
1591         count = layout_list_count(lw, NULL);
1592         if (current != count - 1 && count > 0)
1593                 {
1594                 layout_image_set_index(lw, count - 1);
1595                 }
1596 }
1597
1598 /*
1599  *----------------------------------------------------------------------------
1600  * mouse callbacks
1601  *----------------------------------------------------------------------------
1602  */
1603
1604 static gint image_idx(LayoutWindow *lw, ImageWindow *imd)
1605 {
1606         gint i;
1607
1608         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1609                 {
1610                 if (lw->split_images[i] == imd)
1611                         break;
1612                 }
1613         if (i < MAX_SPLIT_IMAGES)
1614                 {
1615                 return i;
1616                 }
1617         return -1;
1618 }
1619
1620 static void layout_image_focus_in_cb(ImageWindow *imd, gpointer data)
1621 {
1622         LayoutWindow *lw = data;
1623
1624         gint i = image_idx(lw, imd);
1625
1626         if (i != -1)
1627                 {
1628                 DEBUG_1("image activate focus_in %d", i);
1629                 layout_image_activate(lw, i, FALSE);
1630                 }
1631 }
1632
1633
1634 static void layout_image_button_cb(ImageWindow *imd, GdkEventButton *event, gpointer data)
1635 {
1636         LayoutWindow *lw = data;
1637         GtkWidget *menu;
1638
1639         switch (event->button)
1640                 {
1641                 case MOUSE_BUTTON_LEFT:
1642                         if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
1643                                 layout_image_next(lw);
1644                         break;
1645                 case MOUSE_BUTTON_MIDDLE:
1646                         if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
1647                                 layout_image_prev(lw);
1648                         break;
1649                 case MOUSE_BUTTON_RIGHT:
1650                         menu = layout_image_pop_menu(lw);
1651                         if (imd == lw->image)
1652                                 {
1653                                 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
1654                                 }
1655                         gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time);
1656                         break;
1657                 default:
1658                         break;
1659                 }
1660 }
1661
1662 static void layout_image_scroll_cb(ImageWindow *imd, GdkEventScroll *event, gpointer data)
1663 {
1664         LayoutWindow *lw = data;
1665
1666         gint i = image_idx(lw, imd);
1667
1668         if (i != -1)
1669                 {
1670                 DEBUG_1("image activate scroll %d", i);
1671                 layout_image_activate(lw, i, FALSE);
1672                 }
1673
1674
1675         if ((event->state & GDK_CONTROL_MASK) ||
1676                                 (imd->mouse_wheel_mode && !options->image_lm_click_nav))
1677                 {
1678                 switch (event->direction)
1679                         {
1680                         case GDK_SCROLL_UP:
1681                                 layout_image_zoom_adjust_at_point(lw, get_zoom_increment(), event->x, event->y, event->state & GDK_SHIFT_MASK);
1682                                 break;
1683                         case GDK_SCROLL_DOWN:
1684                                 layout_image_zoom_adjust_at_point(lw, -get_zoom_increment(), event->x, event->y, event->state & GDK_SHIFT_MASK);
1685                                 break;
1686                         default:
1687                                 break;
1688                         }
1689                 }
1690         else if (options->mousewheel_scrolls)
1691                 {
1692                 switch (event->direction)
1693                         {
1694                         case GDK_SCROLL_UP:
1695                                 image_scroll(imd, 0, -MOUSEWHEEL_SCROLL_SIZE);
1696                                 break;
1697                         case GDK_SCROLL_DOWN:
1698                                 image_scroll(imd, 0, MOUSEWHEEL_SCROLL_SIZE);
1699                                 break;
1700                         case GDK_SCROLL_LEFT:
1701                                 image_scroll(imd, -MOUSEWHEEL_SCROLL_SIZE, 0);
1702                                 break;
1703                         case GDK_SCROLL_RIGHT:
1704                                 image_scroll(imd, MOUSEWHEEL_SCROLL_SIZE, 0);
1705                                 break;
1706                         default:
1707                                 break;
1708                         }
1709                 }
1710         else
1711                 {
1712                 switch (event->direction)
1713                         {
1714                         case GDK_SCROLL_UP:
1715                                 layout_image_prev(lw);
1716                                 break;
1717                         case GDK_SCROLL_DOWN:
1718                                 layout_image_next(lw);
1719                                 break;
1720                         default:
1721                                 break;
1722                         }
1723                 }
1724 }
1725
1726 static void layout_image_drag_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
1727 {
1728         gint i;
1729         LayoutWindow *lw = data;
1730         gdouble sx, sy;
1731
1732         if (lw->full_screen && lw->image != lw->full_screen->imd &&
1733             imd != lw->full_screen->imd)
1734                 {
1735                 if (event->state & GDK_CONTROL_MASK)
1736                         {
1737                         image_get_scroll_center(imd, &sx, &sy);
1738                         }
1739                 else
1740                         {
1741                         image_get_scroll_center(lw->full_screen->imd, &sx, &sy);
1742                         sx += dx;
1743                         sy += dy;
1744                         }
1745                 image_set_scroll_center(lw->full_screen->imd, sx, sy);
1746                 }
1747
1748         if (!(event->state & GDK_SHIFT_MASK)) return;
1749
1750         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1751                 {
1752                 if (lw->split_images[i] && lw->split_images[i] != imd)
1753                         {
1754
1755                         if (event->state & GDK_CONTROL_MASK)
1756                                 {
1757                                 image_get_scroll_center(imd, &sx, &sy);
1758                                 }
1759                         else
1760                                 {
1761                                 image_get_scroll_center(lw->split_images[i], &sx, &sy);
1762                                 sx += dx;
1763                                 sy += dy;
1764                                 }
1765                         image_set_scroll_center(lw->split_images[i], sx, sy);
1766                         }
1767                 }
1768 }
1769
1770 static void layout_image_button_inactive_cb(ImageWindow *imd, GdkEventButton *event, gpointer data)
1771 {
1772         LayoutWindow *lw = data;
1773         GtkWidget *menu;
1774         gint i = image_idx(lw, imd);
1775
1776         if (i != -1)
1777                 {
1778                 layout_image_activate(lw, i, FALSE);
1779                 }
1780
1781         switch (event->button)
1782                 {
1783                 case MOUSE_BUTTON_RIGHT:
1784                         menu = layout_image_pop_menu(lw);
1785                         if (imd == lw->image)
1786                                 {
1787                                 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
1788                                 }
1789                         gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time);
1790                         break;
1791                 default:
1792                         break;
1793                 }
1794
1795 }
1796
1797 static void layout_image_drag_inactive_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
1798 {
1799         LayoutWindow *lw = data;
1800         gint i = image_idx(lw, imd);
1801
1802         if (i != -1)
1803                 {
1804                 layout_image_activate(lw, i, FALSE);
1805                 }
1806
1807         /* continue as with active image */
1808         layout_image_drag_cb(imd, event, dx, dy, data);
1809 }
1810
1811
1812 static void layout_image_set_buttons(LayoutWindow *lw)
1813 {
1814         image_set_button_func(lw->image, layout_image_button_cb, lw);
1815         image_set_scroll_func(lw->image, layout_image_scroll_cb, lw);
1816 }
1817
1818 static void layout_image_set_buttons_inactive(LayoutWindow *lw, gint i)
1819 {
1820         image_set_button_func(lw->split_images[i], layout_image_button_inactive_cb, lw);
1821         image_set_scroll_func(lw->split_images[i], layout_image_scroll_cb, lw);
1822 }
1823
1824 /* Returns the length of an integer */
1825 static gint num_length(gint num)
1826 {
1827         gint len = 0;
1828         if (num < 0) num = -num;
1829         while (num)
1830                 {
1831                 num /= 10;
1832                 len++;
1833                 }
1834         return len;
1835 }
1836
1837 void layout_status_update_pixel_cb(PixbufRenderer *pr, gpointer data)
1838 {
1839         LayoutWindow *lw = data;
1840         gint x_pixel, y_pixel;
1841         gint width, height;
1842         gchar *text;
1843         PangoAttrList *attrs;
1844
1845         if (!data || !layout_valid(&lw) || !lw->image
1846             || !lw->options.show_info_pixel || lw->image->unknown) return;
1847
1848         pixbuf_renderer_get_image_size(pr, &width, &height);
1849         if (width < 1 || height < 1) return;
1850
1851         pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
1852
1853         if(x_pixel >= 0 && y_pixel >= 0)
1854                 {
1855                 gint r_mouse, g_mouse, b_mouse;
1856
1857                 pixbuf_renderer_get_pixel_colors(pr, x_pixel, y_pixel,
1858                                                  &r_mouse, &g_mouse, &b_mouse);
1859
1860                 text = g_strdup_printf(_("[%*d,%*d]: RGB(%3d,%3d,%3d)"),
1861                                          num_length(width - 1), x_pixel,
1862                                          num_length(height - 1), y_pixel,
1863                                          r_mouse, g_mouse, b_mouse);
1864
1865                 }
1866         else
1867                 {
1868                 text = g_strdup_printf(_("[%*s,%*s]: RGB(---,---,---)"),
1869                                          num_length(width - 1), " ",
1870                                          num_length(height - 1), " ");
1871                 }
1872
1873         attrs = pango_attr_list_new();
1874         pango_attr_list_insert(attrs, pango_attr_family_new("Monospace"));
1875         gtk_label_set_text(GTK_LABEL(lw->info_pixel), text);
1876         gtk_label_set_attributes(GTK_LABEL(lw->info_pixel), attrs);
1877         pango_attr_list_unref(attrs);
1878         g_free(text);
1879 }
1880
1881
1882 /*
1883  *----------------------------------------------------------------------------
1884  * setup
1885  *----------------------------------------------------------------------------
1886  */
1887
1888 static void layout_image_update_cb(ImageWindow *imd, gpointer data)
1889 {
1890         LayoutWindow *lw = data;
1891         layout_status_update_image(lw);
1892 }
1893
1894 GtkWidget *layout_image_new(LayoutWindow *lw, gint i)
1895 {
1896         if (!lw->split_image_sizegroup) lw->split_image_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
1897
1898         if (!lw->split_images[i])
1899                 {
1900                 lw->split_images[i] = image_new(TRUE);
1901
1902                 g_object_ref(lw->split_images[i]->widget);
1903
1904                 g_signal_connect(G_OBJECT(lw->split_images[i]->pr), "update-pixel",
1905                                  G_CALLBACK(layout_status_update_pixel_cb), lw);
1906
1907                 image_background_set_color_from_options(lw->split_images[i], FALSE);
1908
1909                 image_auto_refresh_enable(lw->split_images[i], TRUE);
1910
1911                 layout_image_dnd_init(lw, i);
1912                 image_color_profile_set(lw->split_images[i],
1913                                         options->color_profile.input_type,
1914                                         options->color_profile.use_image);
1915                 image_color_profile_set_use(lw->split_images[i], options->color_profile.enabled);
1916
1917                 gtk_size_group_add_widget(lw->split_image_sizegroup, lw->split_images[i]->widget);
1918                 gtk_widget_set_size_request(lw->split_images[i]->widget, IMAGE_MIN_WIDTH, -1);
1919
1920                 image_set_focus_in_func(lw->split_images[i], layout_image_focus_in_cb, lw);
1921
1922                 }
1923
1924         return lw->split_images[i]->widget;
1925 }
1926
1927 void layout_image_deactivate(LayoutWindow *lw, gint i)
1928 {
1929         if (!lw->split_images[i]) return;
1930         image_set_update_func(lw->split_images[i], NULL, NULL);
1931         layout_image_set_buttons_inactive(lw, i);
1932         image_set_drag_func(lw->split_images[i], layout_image_drag_inactive_cb, lw);
1933
1934         image_attach_window(lw->split_images[i], NULL, NULL, NULL, FALSE);
1935         image_select(lw->split_images[i], FALSE);
1936 }
1937
1938 /* force should be set after change of lw->split_mode */
1939 void layout_image_activate(LayoutWindow *lw, gint i, gboolean force)
1940 {
1941         FileData *fd;
1942
1943         if (!lw->split_images[i]) return;
1944         if (!force && lw->active_split_image == i) return;
1945
1946         /* deactivate currently active */
1947         if (lw->active_split_image != i)
1948                 layout_image_deactivate(lw, lw->active_split_image);
1949
1950         lw->image = lw->split_images[i];
1951         lw->active_split_image = i;
1952
1953         image_set_update_func(lw->image, layout_image_update_cb, lw);
1954         layout_image_set_buttons(lw);
1955         image_set_drag_func(lw->image, layout_image_drag_cb, lw);
1956
1957         image_attach_window(lw->image, lw->window, NULL, GQ_APPNAME, FALSE);
1958
1959         /* do not hilight selected image in SPLIT_NONE */
1960         /* maybe the image should be selected always and hilight should be controled by
1961            another image option */
1962         if (lw->split_mode != SPLIT_NONE)
1963                 image_select(lw->split_images[i], TRUE);
1964         else
1965                 image_select(lw->split_images[i], FALSE);
1966
1967         fd = image_get_fd(lw->image);
1968
1969         if (fd)
1970                 {
1971 //              layout_list_sync_path(lw, path);
1972                 layout_set_fd(lw, fd);
1973                 }
1974         layout_status_update_image(lw);
1975 }
1976
1977
1978 static void layout_image_setup_split_common(LayoutWindow *lw, gint n)
1979 {
1980         gboolean frame = (n > 1) || (!lw->options.tools_float && !lw->options.tools_hidden);
1981         gint i;
1982
1983         for (i = 0; i < n; i++)
1984                 if (!lw->split_images[i])
1985                         {
1986                         FileData *img_fd = NULL;
1987                         double zoom = 0.0;
1988
1989                         layout_image_new(lw, i);
1990                         image_set_frame(lw->split_images[i], frame);
1991                         image_set_selectable(lw->split_images[i], (n > 1));
1992
1993                         if (lw->image)
1994                                 {
1995                                 image_osd_copy_status(lw->image, lw->split_images[i]);
1996                                 }
1997
1998                         if (layout_selection_count(lw, 0) > 1)
1999                                 {
2000                                 GList *work = g_list_last(layout_selection_list(lw));
2001                                 gint j = 0;
2002
2003                                 while (work && j < i)
2004                                         {
2005                                         FileData *fd = work->data;
2006                                         work = work->prev;
2007
2008                                         if (!fd || !*fd->path || fd->parent ||
2009                                                                                 fd == lw->split_images[0]->image_fd)
2010                                                 {
2011                                                 continue;
2012                                                 }
2013                                         img_fd = fd;
2014
2015                                         j++;
2016                                         }
2017                                 }
2018
2019                         if (!img_fd && lw->image)
2020                                 {
2021                                 img_fd = image_get_fd(lw->image);
2022                                 zoom = image_zoom_get(lw->image);
2023                                 }
2024
2025                         if (img_fd)
2026                                 {
2027                                 gdouble sx, sy;
2028                                 image_change_fd(lw->split_images[i], img_fd, zoom);
2029                                 image_get_scroll_center(lw->image, &sx, &sy);
2030                                 image_set_scroll_center(lw->split_images[i], sx, sy);
2031                                 }
2032                         layout_image_deactivate(lw, i);
2033                         }
2034                 else
2035                         {
2036                         image_set_frame(lw->split_images[i], frame);
2037                         image_set_selectable(lw->split_images[i], (n > 1));
2038                         }
2039
2040         for (i = n; i < MAX_SPLIT_IMAGES; i++)
2041                 {
2042                 if (lw->split_images[i])
2043                         {
2044                         g_object_unref(lw->split_images[i]->widget);
2045                         lw->split_images[i] = NULL;
2046                         }
2047                 }
2048
2049         if (!lw->image || lw->active_split_image < 0 || lw->active_split_image >= n)
2050                 {
2051                 layout_image_activate(lw, 0, TRUE);
2052                 }
2053         else
2054                 {
2055                 /* this will draw the frame around selected image (image_select)
2056                    on switch from single to split images */
2057                 layout_image_activate(lw, lw->active_split_image, TRUE);
2058                 }
2059 }
2060
2061 GtkWidget *layout_image_setup_split_none(LayoutWindow *lw)
2062 {
2063         lw->split_mode = SPLIT_NONE;
2064
2065         layout_image_setup_split_common(lw, 1);
2066
2067         lw->split_image_widget = lw->split_images[0]->widget;
2068
2069         return lw->split_image_widget;
2070 }
2071
2072
2073 GtkWidget *layout_image_setup_split_hv(LayoutWindow *lw, gboolean horizontal)
2074 {
2075         GtkWidget *paned;
2076
2077         lw->split_mode = horizontal ? SPLIT_HOR : SPLIT_VERT;
2078
2079         layout_image_setup_split_common(lw, 2);
2080
2081         /* horizontal split means vpaned and vice versa */
2082         if (horizontal)
2083                 paned = gtk_vpaned_new();
2084         else
2085                 paned = gtk_hpaned_new();
2086
2087         gtk_paned_pack1(GTK_PANED(paned), lw->split_images[0]->widget, TRUE, TRUE);
2088         gtk_paned_pack2(GTK_PANED(paned), lw->split_images[1]->widget, TRUE, TRUE);
2089
2090         gtk_widget_show(lw->split_images[0]->widget);
2091         gtk_widget_show(lw->split_images[1]->widget);
2092
2093         lw->split_image_widget = paned;
2094
2095         return lw->split_image_widget;
2096
2097 }
2098
2099 GtkWidget *layout_image_setup_split_quad(LayoutWindow *lw)
2100 {
2101         GtkWidget *hpaned;
2102         GtkWidget *vpaned1;
2103         GtkWidget *vpaned2;
2104         gint i;
2105
2106         lw->split_mode = SPLIT_QUAD;
2107
2108         layout_image_setup_split_common(lw, 4);
2109
2110         hpaned = gtk_hpaned_new();
2111         vpaned1 = gtk_vpaned_new();
2112         vpaned2 = gtk_vpaned_new();
2113
2114         gtk_paned_pack1(GTK_PANED(vpaned1), lw->split_images[0]->widget, TRUE, TRUE);
2115         gtk_paned_pack2(GTK_PANED(vpaned1), lw->split_images[2]->widget, TRUE, TRUE);
2116
2117         gtk_paned_pack1(GTK_PANED(vpaned2), lw->split_images[1]->widget, TRUE, TRUE);
2118         gtk_paned_pack2(GTK_PANED(vpaned2), lw->split_images[3]->widget, TRUE, TRUE);
2119
2120         gtk_paned_pack1(GTK_PANED(hpaned), vpaned1, TRUE, TRUE);
2121         gtk_paned_pack2(GTK_PANED(hpaned), vpaned2, TRUE, TRUE);
2122
2123         for (i = 0; i < 4; i++)
2124                 gtk_widget_show(lw->split_images[i]->widget);
2125
2126         gtk_widget_show(vpaned1);
2127         gtk_widget_show(vpaned2);
2128
2129         lw->split_image_widget = hpaned;
2130
2131         return lw->split_image_widget;
2132
2133 }
2134
2135 GtkWidget *layout_image_setup_split(LayoutWindow *lw, ImageSplitMode mode)
2136 {
2137         switch (mode)
2138                 {
2139                 case SPLIT_HOR:
2140                         return layout_image_setup_split_hv(lw, TRUE);
2141                 case SPLIT_VERT:
2142                         return layout_image_setup_split_hv(lw, FALSE);
2143                 case SPLIT_QUAD:
2144                         return layout_image_setup_split_quad(lw);
2145                 case SPLIT_NONE:
2146                 default:
2147                         return layout_image_setup_split_none(lw);
2148                 }
2149 }
2150
2151
2152 /*
2153  *-----------------------------------------------------------------------------
2154  * maintenance (for rename, move, remove)
2155  *-----------------------------------------------------------------------------
2156  */
2157
2158 static void layout_image_maint_renamed(LayoutWindow *lw, FileData *fd)
2159 {
2160         if (fd == layout_image_get_fd(lw))
2161                 {
2162                 image_set_fd(lw->image, fd);
2163                 }
2164 }
2165
2166 static void layout_image_maint_removed(LayoutWindow *lw, FileData *fd)
2167 {
2168         if (fd == layout_image_get_fd(lw))
2169                 {
2170                 CollectionData *cd;
2171                 CollectInfo *info;
2172
2173                 cd = image_get_collection(lw->image, &info);
2174                 if (cd && info)
2175                         {
2176                         CollectInfo *new;
2177
2178                         new = collection_next_by_info(cd, info);
2179                         if (!new) new = collection_prev_by_info(cd, info);
2180
2181                         if (new)
2182                                 {
2183                                 layout_image_set_collection(lw, cd, new);
2184                                 return;
2185                                 }
2186                         layout_image_set_fd(lw, NULL);
2187                         }
2188
2189                 /* the image will be set to the next image from the list soon,
2190                    setting it to NULL here is not necessary*/
2191                 }
2192 }
2193
2194
2195 void layout_image_notify_cb(FileData *fd, NotifyType type, gpointer data)
2196 {
2197         LayoutWindow *lw = data;
2198
2199         if (!(type & NOTIFY_CHANGE) || !fd->change) return;
2200
2201         DEBUG_1("Notify layout_image: %s %04x", fd->path, type);
2202
2203         switch (fd->change->type)
2204                 {
2205                 case FILEDATA_CHANGE_MOVE:
2206                 case FILEDATA_CHANGE_RENAME:
2207                         layout_image_maint_renamed(lw, fd);
2208                         break;
2209                 case FILEDATA_CHANGE_DELETE:
2210                         layout_image_maint_removed(lw, fd);
2211                         break;
2212                 case FILEDATA_CHANGE_COPY:
2213                 case FILEDATA_CHANGE_UNSPECIFIED:
2214                 case FILEDATA_CHANGE_WRITE_METADATA:
2215                         break;
2216                 }
2217
2218 }
2219 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */