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