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