Right-click menus - collections
[geeqie.git] / src / layout_image.c
1 /*
2  * Copyright (C) 2006 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include "main.h"
23 #include "layout_image.h"
24
25 #include "collect.h"
26 #include "color-man.h"
27 #include "dnd.h"
28 #include "editors.h"
29 #include "exif.h"
30 #include "filedata.h"
31 #include "fullscreen.h"
32 #include "image.h"
33 #include "image-overlay.h"
34 #include "img-view.h"
35 #include "layout.h"
36 #include "layout_util.h"
37 #include "menu.h"
38 #include "metadata.h"
39 #include "misc.h"
40 #include "pixbuf_util.h"
41 #include "pixbuf-renderer.h"
42 #include "slideshow.h"
43 #include "ui_fileops.h"
44 #include "ui_menu.h"
45 #include "uri_utils.h"
46 #include "utilops.h"
47 #include "view_file.h"
48
49 #include <gdk/gdkkeysyms.h> /* for keyboard values */
50
51 #define FILE_COLUMN_POINTER 0
52
53 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw);
54 static void layout_image_set_buttons(LayoutWindow *lw);
55 static void layout_image_animate_stop(LayoutWindow *lw);
56 static gboolean layout_image_animate_new_file(LayoutWindow *lw);
57 static void layout_image_animate_update_image(LayoutWindow *lw);
58
59 /*
60  *----------------------------------------------------------------------------
61  * full screen overlay
62  *----------------------------------------------------------------------------
63  */
64
65 void layout_image_overlay_toggle(LayoutWindow *lw)
66 {
67         if (!lw) return;
68         image_osd_toggle(lw->image);
69 }
70
71 /*
72  *----------------------------------------------------------------------------
73  * full screen
74  *----------------------------------------------------------------------------
75  */
76
77 static void layout_image_full_screen_stop_func(FullScreenData *fs, gpointer data)
78 {
79         LayoutWindow *lw = data;
80
81         /* restore image window */
82         if (lw->image == fs->imd)
83                 lw->image = fs->normal_imd;
84
85         lw->full_screen = NULL;
86 }
87
88 void layout_image_full_screen_start(LayoutWindow *lw)
89 {
90         if (!layout_valid(&lw)) return;
91
92         if (lw->full_screen) return;
93
94         lw->full_screen = fullscreen_start(lw->window, lw->image,
95                                            layout_image_full_screen_stop_func, lw);
96
97         /* set to new image window */
98         if (lw->full_screen->same_region)
99                 lw->image = lw->full_screen->imd;
100
101         layout_image_set_buttons(lw);
102
103         g_signal_connect(G_OBJECT(lw->full_screen->window), "key_press_event",
104                          G_CALLBACK(layout_key_press_cb), lw);
105
106         layout_actions_add_window(lw, lw->full_screen->window);
107
108         image_osd_copy_status(lw->full_screen->normal_imd, lw->image);
109         layout_image_animate_update_image(lw);
110 }
111
112 void layout_image_full_screen_stop(LayoutWindow *lw)
113 {
114         if (!layout_valid(&lw)) return;
115         if (!lw->full_screen) return;
116
117         if (lw->image == lw->full_screen->imd)
118                 image_osd_copy_status(lw->image, lw->full_screen->normal_imd);
119
120         fullscreen_stop(lw->full_screen);
121
122         layout_image_animate_update_image(lw);
123 }
124
125 void layout_image_full_screen_toggle(LayoutWindow *lw)
126 {
127         if (!layout_valid(&lw)) return;
128         if (lw->full_screen)
129                 {
130                 layout_image_full_screen_stop(lw);
131                 }
132         else
133                 {
134                 layout_image_full_screen_start(lw);
135                 }
136 }
137
138 gboolean layout_image_full_screen_active(LayoutWindow *lw)
139 {
140         if (!layout_valid(&lw)) return FALSE;
141
142         return (lw->full_screen != NULL);
143 }
144
145 /*
146  *----------------------------------------------------------------------------
147  * slideshow
148  *----------------------------------------------------------------------------
149  */
150
151 static void layout_image_slideshow_next(LayoutWindow *lw)
152 {
153         if (lw->slideshow) slideshow_next(lw->slideshow);
154 }
155
156 static void layout_image_slideshow_prev(LayoutWindow *lw)
157 {
158         if (lw->slideshow) slideshow_prev(lw->slideshow);
159 }
160
161 static void layout_image_slideshow_stop_func(SlideShowData *ss, gpointer data)
162 {
163         LayoutWindow *lw = data;
164
165         lw->slideshow = NULL;
166         layout_status_update_info(lw, NULL);
167 }
168
169 void layout_image_slideshow_start(LayoutWindow *lw)
170 {
171         CollectionData *cd;
172         CollectInfo *info;
173
174         if (!layout_valid(&lw)) return;
175         if (lw->slideshow) return;
176
177         cd = image_get_collection(lw->image, &info);
178
179         if (cd && info)
180                 {
181                 lw->slideshow = slideshow_start_from_collection(lw, NULL, cd,
182                                 layout_image_slideshow_stop_func, lw, info);
183                 }
184         else
185                 {
186                 lw->slideshow = slideshow_start(lw,
187                                 layout_list_get_index(lw, layout_image_get_fd(lw)),
188                                 layout_image_slideshow_stop_func, lw);
189                 }
190
191         layout_status_update_info(lw, NULL);
192 }
193
194 /* note that slideshow will take ownership of the list, do not free it */
195 void layout_image_slideshow_start_from_list(LayoutWindow *lw, GList *list)
196 {
197         if (!layout_valid(&lw)) return;
198
199         if (lw->slideshow || !list)
200                 {
201                 filelist_free(list);
202                 return;
203                 }
204
205         lw->slideshow = slideshow_start_from_filelist(lw, NULL, list,
206                                                        layout_image_slideshow_stop_func, lw);
207
208         layout_status_update_info(lw, NULL);
209 }
210
211 void layout_image_slideshow_stop(LayoutWindow *lw)
212 {
213         if (!layout_valid(&lw)) return;
214
215         if (!lw->slideshow) return;
216
217         slideshow_free(lw->slideshow);
218         /* the stop_func sets lw->slideshow to NULL for us */
219 }
220
221 void layout_image_slideshow_toggle(LayoutWindow *lw)
222 {
223         if (!layout_valid(&lw)) return;
224
225         if (lw->slideshow)
226                 {
227                 layout_image_slideshow_stop(lw);
228                 }
229         else
230                 {
231                 layout_image_slideshow_start(lw);
232                 }
233 }
234
235 gboolean layout_image_slideshow_active(LayoutWindow *lw)
236 {
237         if (!layout_valid(&lw)) return FALSE;
238
239         return (lw->slideshow != NULL);
240 }
241
242 gboolean layout_image_slideshow_pause_toggle(LayoutWindow *lw)
243 {
244         gboolean ret;
245
246         if (!layout_valid(&lw)) return FALSE;
247
248         ret = slideshow_pause_toggle(lw->slideshow);
249
250         layout_status_update_info(lw, NULL);
251
252         return ret;
253 }
254
255 gboolean layout_image_slideshow_paused(LayoutWindow *lw)
256 {
257         if (!layout_valid(&lw)) return FALSE;
258
259         return (slideshow_paused(lw->slideshow));
260 }
261
262 static gboolean layout_image_slideshow_continue_check(LayoutWindow *lw)
263 {
264         if (!lw->slideshow) return FALSE;
265
266         if (!slideshow_should_continue(lw->slideshow))
267                 {
268                 layout_image_slideshow_stop(lw);
269                 return FALSE;
270                 }
271
272         return TRUE;
273 }
274
275 /*
276  *----------------------------------------------------------------------------
277  * Animation
278  *----------------------------------------------------------------------------
279  */
280
281 static void image_animation_data_free(AnimationData *fd)
282 {
283         if(!fd) return;
284         if(fd->iter) g_object_unref(fd->iter);
285         if(fd->gpa) g_object_unref(fd->gpa);
286         g_free(fd);
287 }
288
289 static gboolean animation_should_continue(AnimationData *fd)
290 {
291         if (!fd->valid)
292                 return FALSE;
293
294         return TRUE;
295 }
296
297 static gboolean show_next_frame(gpointer data)
298 {
299         AnimationData *fd = (AnimationData*)data;
300         int delay;
301         PixbufRenderer *pr;
302
303         if(animation_should_continue(fd)==FALSE)
304                 {
305                 image_animation_data_free(fd);
306                 return FALSE;
307                 }
308
309         pr = (PixbufRenderer*)fd->iw->pr;
310
311         if (gdk_pixbuf_animation_iter_advance(fd->iter,NULL)==FALSE)
312                 {
313                 /* This indicates the animation is complete.
314                    Return FALSE here to disable looping. */
315                 }
316
317         fd->gpb = gdk_pixbuf_animation_iter_get_pixbuf(fd->iter);
318         image_change_pixbuf(fd->iw,fd->gpb,pr->zoom,FALSE);
319
320         if (fd->iw->func_update)
321                 fd->iw->func_update(fd->iw, fd->iw->data_update);
322
323         delay = gdk_pixbuf_animation_iter_get_delay_time(fd->iter);
324         if (delay!=fd->delay)
325                 {
326                 if (delay>0) /* Current frame not static. */
327                         {
328                         fd->delay=delay;
329                         g_timeout_add(delay,show_next_frame,fd);
330                         }
331                 else
332                         {
333                         image_animation_data_free(fd);
334                         }
335                 return FALSE;
336                 }
337
338         return TRUE;
339 }
340
341 static gboolean layout_image_animate_check(LayoutWindow *lw)
342 {
343         if (!layout_valid(&lw)) return FALSE;
344
345         if(!lw->options.animate || lw->image->image_fd == NULL)
346                 {
347                 if(lw->animation)
348                         {
349                         lw->animation->valid = FALSE;
350                         lw->animation = NULL;
351                         }
352                 return FALSE;
353                 }
354
355         return TRUE;
356 }
357
358 static void layout_image_animate_stop(LayoutWindow *lw)
359 {
360         if (!layout_valid(&lw)) return;
361
362         if(lw->options.animate && lw->animation)
363                 {
364                 lw->animation->valid = FALSE;
365                 lw->animation = NULL;
366                 }
367 }
368
369 static void layout_image_animate_update_image(LayoutWindow *lw)
370 {
371         if (!layout_valid(&lw)) return;
372
373         if(lw->options.animate && lw->animation)
374                 {
375                 if (lw->full_screen && lw->image != lw->full_screen->imd)
376                         lw->animation->iw = lw->full_screen->imd;
377                 else
378                         lw->animation->iw = lw->image;
379                 }
380 }
381
382 static gboolean layout_image_animate_new_file(LayoutWindow *lw)
383 {
384         GError *err=NULL;
385
386         if(!layout_image_animate_check(lw)) return FALSE;
387
388         if(lw->animation) lw->animation->valid = FALSE;
389
390         lw->animation = g_malloc0(sizeof(AnimationData));
391
392         if(!(lw->animation->gpa = gdk_pixbuf_animation_new_from_file(lw->image->image_fd->path,&err)) || err ||
393                 gdk_pixbuf_animation_is_static_image(lw->animation->gpa) ||
394                 !(lw->animation->iter = gdk_pixbuf_animation_get_iter(lw->animation->gpa,NULL)))
395                 {
396                 image_animation_data_free(lw->animation);
397                 lw->animation = NULL;
398                 return FALSE;
399                 }
400
401         lw->animation->data_adr = lw->image->image_fd;
402         lw->animation->delay = gdk_pixbuf_animation_iter_get_delay_time(lw->animation->iter);
403         lw->animation->valid = TRUE;
404
405         layout_image_animate_update_image(lw);
406
407         g_timeout_add(lw->animation->delay, show_next_frame, lw->animation);
408
409         return TRUE;
410 }
411
412 void layout_image_animate_toggle(LayoutWindow *lw)
413 {
414         GtkAction *action;
415
416         if (!lw) return;
417
418         lw->options.animate = !lw->options.animate;
419
420         action = gtk_action_group_get_action(lw->action_group, "Animate");
421         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.animate);
422
423         layout_image_animate_new_file(lw);
424 }
425
426 /*
427  *----------------------------------------------------------------------------
428  * pop-up menus
429  *----------------------------------------------------------------------------
430  */
431
432 static void li_pop_menu_zoom_in_cb(GtkWidget *widget, gpointer data)
433 {
434         LayoutWindow *lw = data;
435
436         layout_image_zoom_adjust(lw, get_zoom_increment(), FALSE);
437 }
438
439 static void li_pop_menu_zoom_out_cb(GtkWidget *widget, gpointer data)
440 {
441         LayoutWindow *lw = data;
442         layout_image_zoom_adjust(lw, -get_zoom_increment(), FALSE);
443 }
444
445 static void li_pop_menu_zoom_1_1_cb(GtkWidget *widget, gpointer data)
446 {
447         LayoutWindow *lw = data;
448
449         layout_image_zoom_set(lw, 1.0, FALSE);
450 }
451
452 static void li_pop_menu_zoom_fit_cb(GtkWidget *widget, gpointer data)
453 {
454         LayoutWindow *lw = data;
455
456         layout_image_zoom_set(lw, 0.0, FALSE);
457 }
458
459 static void li_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
460 {
461         LayoutWindow *lw;
462         const gchar *key = data;
463
464         lw = submenu_item_get_data(widget);
465
466         if (!editor_window_flag_set(key))
467                 {
468                 layout_image_full_screen_stop(lw);
469                 }
470         file_util_start_editor_from_file(key, layout_image_get_fd(lw), lw->window);
471 }
472
473 static void li_pop_menu_wallpaper_cb(GtkWidget *widget, gpointer data)
474 {
475         LayoutWindow *lw = data;
476
477         layout_image_to_root(lw);
478 }
479
480 static void li_pop_menu_alter_cb(GtkWidget *widget, gpointer data)
481 {
482         LayoutWindow *lw = data;
483         AlterType type;
484
485         lw = submenu_item_get_data(widget);
486         type = (AlterType)GPOINTER_TO_INT(data);
487
488         image_alter_orientation(lw->image, lw->image->image_fd, type);
489 }
490
491 static void li_pop_menu_new_cb(GtkWidget *widget, gpointer data)
492 {
493         LayoutWindow *lw = data;
494
495         view_window_new(layout_image_get_fd(lw));
496 }
497
498 static GtkWidget *li_pop_menu_click_parent(GtkWidget *widget, LayoutWindow *lw)
499 {
500         GtkWidget *menu;
501         GtkWidget *parent;
502
503         menu = gtk_widget_get_toplevel(widget);
504         if (!menu) return NULL;
505
506         parent = g_object_get_data(G_OBJECT(menu), "click_parent");
507
508         if (!parent && lw->full_screen)
509                 {
510                 parent = lw->full_screen->imd->widget;
511                 }
512
513         return parent;
514 }
515
516 static void li_pop_menu_copy_cb(GtkWidget *widget, gpointer data)
517 {
518         LayoutWindow *lw = data;
519
520         file_util_copy(layout_image_get_fd(lw), NULL, NULL,
521                        li_pop_menu_click_parent(widget, lw));
522 }
523
524 static void li_pop_menu_copy_path_cb(GtkWidget *widget, gpointer data)
525 {
526         LayoutWindow *lw = data;
527
528         file_util_copy_path_to_clipboard(layout_image_get_fd(lw));
529 }
530
531 static void li_pop_menu_move_cb(GtkWidget *widget, gpointer data)
532 {
533         LayoutWindow *lw = data;
534
535         file_util_move(layout_image_get_fd(lw), NULL, NULL,
536                        li_pop_menu_click_parent(widget, lw));
537 }
538
539 static void li_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
540 {
541         LayoutWindow *lw = data;
542
543         file_util_rename(layout_image_get_fd(lw), NULL,
544                          li_pop_menu_click_parent(widget, lw));
545 }
546
547 static void li_pop_menu_delete_cb(GtkWidget *widget, gpointer data)
548 {
549         LayoutWindow *lw = data;
550
551         file_util_delete(layout_image_get_fd(lw), NULL,
552                          li_pop_menu_click_parent(widget, lw));
553 }
554
555 static void li_pop_menu_slide_start_cb(GtkWidget *widget, gpointer data)
556 {
557         LayoutWindow *lw = data;
558
559         layout_image_slideshow_start(lw);
560 }
561
562 static void li_pop_menu_slide_stop_cb(GtkWidget *widget, gpointer data)
563 {
564         LayoutWindow *lw = data;
565
566         layout_image_slideshow_stop(lw);
567 }
568
569 static void li_pop_menu_slide_pause_cb(GtkWidget *widget, gpointer data)
570 {
571         LayoutWindow *lw = data;
572
573         layout_image_slideshow_pause_toggle(lw);
574 }
575
576 static void li_pop_menu_full_screen_cb(GtkWidget *widget, gpointer data)
577 {
578         LayoutWindow *lw = data;
579
580         layout_image_full_screen_toggle(lw);
581 }
582
583 static void li_pop_menu_animate_cb(GtkWidget *widget, gpointer data)
584 {
585         LayoutWindow *lw = data;
586
587         layout_image_animate_toggle(lw);
588 }
589
590 static void li_pop_menu_hide_cb(GtkWidget *widget, gpointer data)
591 {
592         LayoutWindow *lw = data;
593
594         layout_tools_hide_toggle(lw);
595 }
596
597 static void li_set_layout_path_cb(GtkWidget *widget, gpointer data)
598 {
599         LayoutWindow *lw = data;
600         FileData *fd;
601
602         if (!layout_valid(&lw)) return;
603
604         fd = layout_image_get_fd(lw);
605         if (fd) layout_set_fd(lw, fd);
606 }
607
608 static gboolean li_check_if_current_path(LayoutWindow *lw, const gchar *path)
609 {
610         gchar *dirname;
611         gboolean ret;
612
613         if (!path || !layout_valid(&lw) || !lw->dir_fd) return FALSE;
614
615         dirname = g_path_get_dirname(path);
616         ret = (strcmp(lw->dir_fd->path, dirname) == 0);
617         g_free(dirname);
618         return ret;
619 }
620
621 static void layout_image_popup_menu_destroy_cb(GtkWidget *widget, gpointer data)
622 {
623         GList *editmenu_fd_list = data;
624
625         filelist_free(editmenu_fd_list);
626 }
627
628 static GList *layout_image_get_fd_list(LayoutWindow *lw)
629 {
630         GList *list = NULL;
631         FileData *fd = layout_image_get_fd(lw);
632
633         if (fd)
634                 {
635                 if (lw->vf)
636                         /* optionally include sidecars if the filelist entry is not expanded */
637                         list = vf_selection_get_one(lw->vf, fd);
638                 else
639                         list = g_list_append(NULL, file_data_ref(fd));
640                 }
641
642         return list;
643 }
644
645 /* Add file selection list to a collection
646  * Called from a right-click submenu
647  * Inputs:
648  * data: index to the collection list menu item selected, or -1 for new collection
649  */
650 static void layout_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
651 {
652         LayoutWindow *lw;
653         GList *selection_list = NULL;
654
655         lw = submenu_item_get_data(widget);
656         selection_list = g_list_append(selection_list, layout_image_get_fd(lw));
657         pop_menu_collections(selection_list, data);
658
659         filelist_free(selection_list);
660 }
661
662 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
663 {
664         GtkWidget *menu;
665         GtkWidget *item;
666         GtkWidget *submenu;
667         const gchar *path;
668         gboolean fullscreen;
669         GList *editmenu_fd_list;
670
671         path = layout_image_get_path(lw);
672         fullscreen = layout_image_full_screen_active(lw);
673
674         menu = popup_menu_short_lived();
675
676         menu_item_add_stock(menu, _("Zoom _in"), GTK_STOCK_ZOOM_IN, G_CALLBACK(li_pop_menu_zoom_in_cb), lw);
677         menu_item_add_stock(menu, _("Zoom _out"), GTK_STOCK_ZOOM_OUT, G_CALLBACK(li_pop_menu_zoom_out_cb), lw);
678         menu_item_add_stock(menu, _("Zoom _1:1"), GTK_STOCK_ZOOM_100, G_CALLBACK(li_pop_menu_zoom_1_1_cb), lw);
679         menu_item_add_stock(menu, _("Fit image to _window"), GTK_STOCK_ZOOM_FIT, G_CALLBACK(li_pop_menu_zoom_fit_cb), lw);
680         menu_item_add_divider(menu);
681
682         editmenu_fd_list = layout_image_get_fd_list(lw);
683         g_signal_connect(G_OBJECT(menu), "destroy",
684                          G_CALLBACK(layout_image_popup_menu_destroy_cb), editmenu_fd_list);
685         submenu = submenu_add_edit(menu, &item, G_CALLBACK(li_pop_menu_edit_cb), lw, editmenu_fd_list);
686         if (!path) gtk_widget_set_sensitive(item, FALSE);
687         menu_item_add_divider(submenu);
688 #if !GTK_CHECK_VERSION(3,0,0)
689         menu_item_add(submenu, _("Set as _wallpaper"), G_CALLBACK(li_pop_menu_wallpaper_cb), lw);
690 #endif
691         item = submenu_add_alter(menu, G_CALLBACK(li_pop_menu_alter_cb), lw);
692
693         item = menu_item_add_stock(menu, _("View in _new window"), GTK_STOCK_NEW, G_CALLBACK(li_pop_menu_new_cb), lw);
694         if (!path || fullscreen) gtk_widget_set_sensitive(item, FALSE);
695
696         item = menu_item_add(menu, _("_Go to directory view"), G_CALLBACK(li_set_layout_path_cb), lw);
697         if (!path || li_check_if_current_path(lw, path)) gtk_widget_set_sensitive(item, FALSE);
698
699         menu_item_add_divider(menu);
700
701         item = menu_item_add_stock(menu, _("_Copy..."), GTK_STOCK_COPY, G_CALLBACK(li_pop_menu_copy_cb), lw);
702         if (!path) gtk_widget_set_sensitive(item, FALSE);
703         item = menu_item_add(menu, _("_Move..."), G_CALLBACK(li_pop_menu_move_cb), lw);
704         if (!path) gtk_widget_set_sensitive(item, FALSE);
705         item = menu_item_add(menu, _("_Rename..."), G_CALLBACK(li_pop_menu_rename_cb), lw);
706         if (!path) gtk_widget_set_sensitive(item, FALSE);
707         item = menu_item_add(menu, _("_Copy path"), G_CALLBACK(li_pop_menu_copy_path_cb), lw);
708         if (!path) gtk_widget_set_sensitive(item, FALSE);
709         item = menu_item_add_stock(menu, _("_Delete..."), GTK_STOCK_DELETE, G_CALLBACK(li_pop_menu_delete_cb), lw);
710         if (!path) gtk_widget_set_sensitive(item, FALSE);
711         menu_item_add_divider(menu);
712
713         submenu = submenu_add_collections(menu, &item,
714                                 G_CALLBACK(layout_pop_menu_collections_cb), lw);
715         gtk_widget_set_sensitive(item, TRUE);
716         menu_item_add_divider(menu);
717
718         if (layout_image_slideshow_active(lw))
719                 {
720                 menu_item_add(menu, _("_Stop slideshow"), G_CALLBACK(li_pop_menu_slide_stop_cb), lw);
721                 if (layout_image_slideshow_paused(lw))
722                         {
723                         item = menu_item_add(menu, _("Continue slides_how"),
724                                              G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
725                         }
726                 else
727                         {
728                         item = menu_item_add(menu, _("Pause slides_how"),
729                                              G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
730                         }
731                 }
732         else
733                 {
734                 menu_item_add(menu, _("_Start slideshow"), G_CALLBACK(li_pop_menu_slide_start_cb), lw);
735                 item = menu_item_add(menu, _("Pause slides_how"), G_CALLBACK(li_pop_menu_slide_pause_cb), lw);
736                 gtk_widget_set_sensitive(item, FALSE);
737                 }
738
739         if (!fullscreen)
740                 {
741                 menu_item_add(menu, _("_Full screen"), G_CALLBACK(li_pop_menu_full_screen_cb), lw);
742                 }
743         else
744                 {
745                 menu_item_add(menu, _("Exit _full screen"), G_CALLBACK(li_pop_menu_full_screen_cb), lw);
746                 }
747
748         menu_item_add_check(menu, _("_Animate"), lw->options.animate, G_CALLBACK(li_pop_menu_animate_cb), lw);
749
750         menu_item_add_divider(menu);
751
752         item = menu_item_add_check(menu, _("Hide file _list"), lw->options.tools_hidden,
753                                    G_CALLBACK(li_pop_menu_hide_cb), lw);
754         if (fullscreen) gtk_widget_set_sensitive(item, FALSE);
755
756         return menu;
757 }
758
759 static void layout_image_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
760 {
761         LayoutWindow *lw = data;
762
763         gdk_window_get_origin(gtk_widget_get_window(lw->image->pr), x, y);
764         popup_menu_position_clamp(menu, x, y, 0);
765 }
766
767 void layout_image_menu_popup(LayoutWindow *lw)
768 {
769         GtkWidget *menu;
770
771         menu = layout_image_pop_menu(lw);
772         gtk_menu_popup(GTK_MENU(menu), NULL, NULL, layout_image_menu_pos_cb, lw, 0, GDK_CURRENT_TIME);
773 }
774
775 /*
776  *----------------------------------------------------------------------------
777  * dnd
778  *----------------------------------------------------------------------------
779  */
780
781 static void layout_image_dnd_receive(GtkWidget *widget, GdkDragContext *context,
782                                      gint x, gint y,
783                                      GtkSelectionData *selection_data, guint info,
784                                      guint time, gpointer data)
785 {
786         LayoutWindow *lw = data;
787         gint i;
788
789
790         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
791                 {
792                 if (lw->split_images[i] && lw->split_images[i]->pr == widget)
793                         break;
794                 }
795         if (i < MAX_SPLIT_IMAGES)
796                 {
797                 DEBUG_1("dnd image activate %d", i);
798                 layout_image_activate(lw, i, FALSE);
799                 }
800
801
802         if (info == TARGET_URI_LIST || info == TARGET_APP_COLLECTION_MEMBER)
803                 {
804                 CollectionData *source;
805                 GList *list;
806                 GList *info_list;
807
808                 if (info == TARGET_URI_LIST)
809                         {
810                         list = uri_filelist_from_gtk_selection_data(selection_data);
811                         source = NULL;
812                         info_list = NULL;
813                         }
814                 else
815                         {
816                         source = collection_from_dnd_data((gchar *)gtk_selection_data_get_data(selection_data), &list, &info_list);
817                         }
818
819                 if (list)
820                         {
821                         FileData *fd = list->data;
822
823                         if (isfile(fd->path))
824                                 {
825                                 gchar *base;
826                                 gint row;
827                                 FileData *dir_fd;
828
829                                 base = remove_level_from_path(fd->path);
830                                 dir_fd = file_data_new_dir(base);
831                                 if (dir_fd != lw->dir_fd)
832                                         {
833                                         layout_set_fd(lw, dir_fd);
834                                         }
835                                 file_data_unref(dir_fd);
836                                 g_free(base);
837
838                                 row = layout_list_get_index(lw, fd);
839                                 if (source && info_list)
840                                         {
841                                         layout_image_set_collection(lw, source, info_list->data);
842                                         }
843                                 else if (row == -1)
844                                         {
845                                         layout_image_set_fd(lw, fd);
846                                         }
847                                 else
848                                         {
849                                         layout_image_set_index(lw, row);
850                                         }
851                                 }
852                         else if (isdir(fd->path))
853                                 {
854                                 layout_set_fd(lw, fd);
855                                 layout_image_set_fd(lw, NULL);
856                                 }
857                         }
858
859                 filelist_free(list);
860                 g_list_free(info_list);
861                 }
862 }
863
864 static void layout_image_dnd_get(GtkWidget *widget, GdkDragContext *context,
865                                  GtkSelectionData *selection_data, guint info,
866                                  guint time, gpointer data)
867 {
868         LayoutWindow *lw = data;
869         FileData *fd;
870         gint i;
871
872
873         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
874                 {
875                 if (lw->split_images[i] && lw->split_images[i]->pr == widget)
876                         break;
877                 }
878         if (i < MAX_SPLIT_IMAGES)
879                 {
880                 DEBUG_1("dnd get from %d", i);
881                 fd = image_get_fd(lw->split_images[i]);
882                 }
883         else
884                 fd = layout_image_get_fd(lw);
885
886         if (fd)
887                 {
888                 GList *list;
889
890                 list = g_list_append(NULL, fd);
891                 uri_selection_data_set_uris_from_filelist(selection_data, list);
892                 g_list_free(list);
893                 }
894         else
895                 {
896                 gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
897                                        8, NULL, 0);
898                 }
899 }
900
901 static void layout_image_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
902 {
903         LayoutWindow *lw = data;
904         if (gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
905                 {
906                 FileData *fd;
907                 gint row;
908
909                 fd = layout_image_get_fd(lw);
910                 row = layout_list_get_index(lw, fd);
911                 if (row < 0) return;
912
913                 if (!isfile(fd->path))
914                         {
915                         if ((guint) row < layout_list_count(lw, NULL) - 1)
916                                 {
917                                 layout_image_next(lw);
918                                 }
919                         else
920                                 {
921                                 layout_image_prev(lw);
922                                 }
923                         }
924                 layout_refresh(lw);
925                 }
926 }
927
928 static void layout_image_dnd_init(LayoutWindow *lw, gint i)
929 {
930         ImageWindow *imd = lw->split_images[i];
931
932         gtk_drag_source_set(imd->pr, GDK_BUTTON2_MASK,
933                             dnd_file_drag_types, dnd_file_drag_types_count,
934                             GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
935         g_signal_connect(G_OBJECT(imd->pr), "drag_data_get",
936                          G_CALLBACK(layout_image_dnd_get), lw);
937         g_signal_connect(G_OBJECT(imd->pr), "drag_end",
938                          G_CALLBACK(layout_image_dnd_end), lw);
939
940         gtk_drag_dest_set(imd->pr,
941                           GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
942                           dnd_file_drop_types, dnd_file_drop_types_count,
943                           GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
944         g_signal_connect(G_OBJECT(imd->pr), "drag_data_received",
945                          G_CALLBACK(layout_image_dnd_receive), lw);
946 }
947
948
949 /*
950  *----------------------------------------------------------------------------
951  * misc
952  *----------------------------------------------------------------------------
953  */
954
955 void layout_image_to_root(LayoutWindow *lw)
956 {
957         image_to_root_window(lw->image, (image_zoom_get(lw->image) == 0));
958 }
959
960 /*
961  *----------------------------------------------------------------------------
962  * manipulation + accessors
963  *----------------------------------------------------------------------------
964  */
965
966 void layout_image_scroll(LayoutWindow *lw, gint x, gint y, gboolean connect_scroll)
967 {
968         gdouble dx, dy;
969         gint width, height, i;
970         if (!layout_valid(&lw)) return;
971
972         image_scroll(lw->image, x, y);
973
974         if (lw->full_screen && lw->image != lw->full_screen->imd)
975                 {
976                 image_scroll(lw->full_screen->imd, x, y);
977                 }
978
979         if (!connect_scroll) return;
980
981         image_get_image_size(lw->image, &width, &height);
982         dx = (gdouble) x / width;
983         dy = (gdouble) y / height;
984
985         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
986                 {
987                 if (lw->split_images[i] && lw->split_images[i] != lw->image)
988                         {
989                         gdouble sx, sy;
990                         image_get_scroll_center(lw->split_images[i], &sx, &sy);
991                         sx += dx;
992                         sy += dy;
993                         image_set_scroll_center(lw->split_images[i], sx, sy);
994                         }
995                 }
996
997 }
998
999 void layout_image_zoom_adjust(LayoutWindow *lw, gdouble increment, gboolean connect_zoom)
1000 {
1001         gint i;
1002         if (!layout_valid(&lw)) return;
1003
1004         image_zoom_adjust(lw->image, increment);
1005
1006         if (lw->full_screen && lw->image != lw->full_screen->imd)
1007                 {
1008                 image_zoom_adjust(lw->full_screen->imd, increment);
1009                 }
1010
1011         if (!connect_zoom) return;
1012
1013         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1014                 {
1015                 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1016                         image_zoom_adjust(lw->split_images[i], increment); ;
1017                 }
1018 }
1019
1020 void layout_image_zoom_adjust_at_point(LayoutWindow *lw, gdouble increment, gint x, gint y, gboolean connect_zoom)
1021 {
1022         gint i;
1023         if (!layout_valid(&lw)) return;
1024
1025         image_zoom_adjust_at_point(lw->image, increment, x, y);
1026
1027         if (lw->full_screen && lw->image != lw->full_screen->imd)
1028                 {
1029                 image_zoom_adjust_at_point(lw->full_screen->imd, increment, x, y);
1030                 }
1031         if (!connect_zoom && !lw->split_mode) return;
1032
1033         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1034                 {
1035                 if (lw->split_images[i] && lw->split_images[i] != lw->image &&
1036                                                 lw->split_images[i]->mouse_wheel_mode)
1037                         image_zoom_adjust_at_point(lw->split_images[i], increment, x, y);
1038                 }
1039 }
1040
1041 void layout_image_zoom_set(LayoutWindow *lw, gdouble zoom, gboolean connect_zoom)
1042 {
1043         gint i;
1044         if (!layout_valid(&lw)) return;
1045
1046         image_zoom_set(lw->image, zoom);
1047
1048         if (lw->full_screen && lw->image != lw->full_screen->imd)
1049                 {
1050                 image_zoom_set(lw->full_screen->imd, zoom);
1051                 }
1052
1053         if (!connect_zoom) return;
1054
1055         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1056                 {
1057                 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1058                         image_zoom_set(lw->split_images[i], zoom);
1059                 }
1060 }
1061
1062 void layout_image_zoom_set_fill_geometry(LayoutWindow *lw, gboolean vertical, gboolean connect_zoom)
1063 {
1064         gint i;
1065         if (!layout_valid(&lw)) return;
1066
1067         image_zoom_set_fill_geometry(lw->image, vertical);
1068
1069         if (lw->full_screen && lw->image != lw->full_screen->imd)
1070                 {
1071                 image_zoom_set_fill_geometry(lw->full_screen->imd, vertical);
1072                 }
1073
1074         if (!connect_zoom) return;
1075
1076         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1077                 {
1078                 if (lw->split_images[i] && lw->split_images[i] != lw->image)
1079                         image_zoom_set_fill_geometry(lw->split_images[i], vertical);
1080                 }
1081 }
1082
1083 void layout_image_alter_orientation(LayoutWindow *lw, AlterType type)
1084 {
1085         if (!layout_valid(&lw)) return;
1086
1087         GtkTreeModel *store;
1088         GList *work;
1089         GtkTreeSelection *selection;
1090         GtkTreePath *tpath;
1091         FileData *fd_n;
1092         GtkTreeIter iter;
1093
1094         if (!lw || !lw->vf) return;
1095
1096         if (lw->vf->type == FILEVIEW_ICON)
1097                 {
1098                 if (!VFICON(lw->vf)->selection) return;
1099                 work = VFICON(lw->vf)->selection;
1100                 }
1101         else
1102                 {
1103                 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
1104                 work = gtk_tree_selection_get_selected_rows(selection, &store);
1105                 }
1106
1107         while (work)
1108                 {
1109                 if (lw->vf->type == FILEVIEW_ICON)
1110                         {
1111                         fd_n = work->data;
1112                         work = work->next;
1113                         }
1114                 else
1115                         {
1116                         tpath = work->data;
1117                         gtk_tree_model_get_iter(store, &iter, tpath);
1118                         gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
1119                         work = work->next;
1120                         }
1121
1122                 image_alter_orientation(lw->image, fd_n, type);
1123                 }
1124 }
1125
1126 static void image_alter_rating(FileData *fd_n, const gchar *rating)
1127 {
1128         metadata_write_string(fd_n, RATING_KEY, rating);
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
1706         switch (event->button)
1707                 {
1708                 case MOUSE_BUTTON_LEFT:
1709                         if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
1710                                 layout_image_next(lw);
1711                         break;
1712                 case MOUSE_BUTTON_MIDDLE:
1713                         if (options->image_lm_click_nav && lw->split_mode == SPLIT_NONE)
1714                                 layout_image_prev(lw);
1715                         break;
1716                 case MOUSE_BUTTON_RIGHT:
1717                         menu = layout_image_pop_menu(lw);
1718                         if (imd == lw->image)
1719                                 {
1720                                 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
1721                                 }
1722                         gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time);
1723                         break;
1724                 default:
1725                         break;
1726                 }
1727 }
1728
1729 static void layout_image_scroll_cb(ImageWindow *imd, GdkEventScroll *event, gpointer data)
1730 {
1731         LayoutWindow *lw = data;
1732
1733         gint i = image_idx(lw, imd);
1734
1735         if (i != -1)
1736                 {
1737                 DEBUG_1("image activate scroll %d", i);
1738                 layout_image_activate(lw, i, FALSE);
1739                 }
1740
1741
1742         if ((event->state & GDK_CONTROL_MASK) ||
1743                                 (imd->mouse_wheel_mode && !options->image_lm_click_nav))
1744                 {
1745                 switch (event->direction)
1746                         {
1747                         case GDK_SCROLL_UP:
1748                                 layout_image_zoom_adjust_at_point(lw, get_zoom_increment(), event->x, event->y, event->state & GDK_SHIFT_MASK);
1749                                 break;
1750                         case GDK_SCROLL_DOWN:
1751                                 layout_image_zoom_adjust_at_point(lw, -get_zoom_increment(), event->x, event->y, event->state & GDK_SHIFT_MASK);
1752                                 break;
1753                         default:
1754                                 break;
1755                         }
1756                 }
1757         else if (options->mousewheel_scrolls)
1758                 {
1759                 switch (event->direction)
1760                         {
1761                         case GDK_SCROLL_UP:
1762                                 image_scroll(imd, 0, -MOUSEWHEEL_SCROLL_SIZE);
1763                                 break;
1764                         case GDK_SCROLL_DOWN:
1765                                 image_scroll(imd, 0, MOUSEWHEEL_SCROLL_SIZE);
1766                                 break;
1767                         case GDK_SCROLL_LEFT:
1768                                 image_scroll(imd, -MOUSEWHEEL_SCROLL_SIZE, 0);
1769                                 break;
1770                         case GDK_SCROLL_RIGHT:
1771                                 image_scroll(imd, MOUSEWHEEL_SCROLL_SIZE, 0);
1772                                 break;
1773                         default:
1774                                 break;
1775                         }
1776                 }
1777         else
1778                 {
1779                 switch (event->direction)
1780                         {
1781                         case GDK_SCROLL_UP:
1782                                 layout_image_prev(lw);
1783                                 break;
1784                         case GDK_SCROLL_DOWN:
1785                                 layout_image_next(lw);
1786                                 break;
1787                         default:
1788                                 break;
1789                         }
1790                 }
1791 }
1792
1793 static void layout_image_drag_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
1794 {
1795         gint i;
1796         LayoutWindow *lw = data;
1797         gdouble sx, sy;
1798
1799         if (lw->full_screen && lw->image != lw->full_screen->imd &&
1800             imd != lw->full_screen->imd)
1801                 {
1802                 if (event->state & GDK_CONTROL_MASK)
1803                         {
1804                         image_get_scroll_center(imd, &sx, &sy);
1805                         }
1806                 else
1807                         {
1808                         image_get_scroll_center(lw->full_screen->imd, &sx, &sy);
1809                         sx += dx;
1810                         sy += dy;
1811                         }
1812                 image_set_scroll_center(lw->full_screen->imd, sx, sy);
1813                 }
1814
1815         if (!(event->state & GDK_SHIFT_MASK)) return;
1816
1817         for (i = 0; i < MAX_SPLIT_IMAGES; i++)
1818                 {
1819                 if (lw->split_images[i] && lw->split_images[i] != imd)
1820                         {
1821
1822                         if (event->state & GDK_CONTROL_MASK)
1823                                 {
1824                                 image_get_scroll_center(imd, &sx, &sy);
1825                                 }
1826                         else
1827                                 {
1828                                 image_get_scroll_center(lw->split_images[i], &sx, &sy);
1829                                 sx += dx;
1830                                 sy += dy;
1831                                 }
1832                         image_set_scroll_center(lw->split_images[i], sx, sy);
1833                         }
1834                 }
1835 }
1836
1837 static void layout_image_button_inactive_cb(ImageWindow *imd, GdkEventButton *event, gpointer data)
1838 {
1839         LayoutWindow *lw = data;
1840         GtkWidget *menu;
1841         gint i = image_idx(lw, imd);
1842
1843         if (i != -1)
1844                 {
1845                 layout_image_activate(lw, i, FALSE);
1846                 }
1847
1848         switch (event->button)
1849                 {
1850                 case MOUSE_BUTTON_RIGHT:
1851                         menu = layout_image_pop_menu(lw);
1852                         if (imd == lw->image)
1853                                 {
1854                                 g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
1855                                 }
1856                         gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->time);
1857                         break;
1858                 default:
1859                         break;
1860                 }
1861
1862 }
1863
1864 static void layout_image_drag_inactive_cb(ImageWindow *imd, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer data)
1865 {
1866         LayoutWindow *lw = data;
1867         gint i = image_idx(lw, imd);
1868
1869         if (i != -1)
1870                 {
1871                 layout_image_activate(lw, i, FALSE);
1872                 }
1873
1874         /* continue as with active image */
1875         layout_image_drag_cb(imd, event, dx, dy, data);
1876 }
1877
1878
1879 static void layout_image_set_buttons(LayoutWindow *lw)
1880 {
1881         image_set_button_func(lw->image, layout_image_button_cb, lw);
1882         image_set_scroll_func(lw->image, layout_image_scroll_cb, lw);
1883 }
1884
1885 static void layout_image_set_buttons_inactive(LayoutWindow *lw, gint i)
1886 {
1887         image_set_button_func(lw->split_images[i], layout_image_button_inactive_cb, lw);
1888         image_set_scroll_func(lw->split_images[i], layout_image_scroll_cb, lw);
1889 }
1890
1891 /* Returns the length of an integer */
1892 static gint num_length(gint num)
1893 {
1894         gint len = 0;
1895         if (num < 0) num = -num;
1896         while (num)
1897                 {
1898                 num /= 10;
1899                 len++;
1900                 }
1901         return len;
1902 }
1903
1904 void layout_status_update_pixel_cb(PixbufRenderer *pr, gpointer data)
1905 {
1906         LayoutWindow *lw = data;
1907         gint x_pixel, y_pixel;
1908         gint width, height;
1909         gchar *text;
1910         PangoAttrList *attrs;
1911
1912         if (!data || !layout_valid(&lw) || !lw->image
1913             || !lw->options.show_info_pixel || lw->image->unknown) return;
1914
1915         pixbuf_renderer_get_image_size(pr, &width, &height);
1916         if (width < 1 || height < 1) return;
1917
1918         pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
1919
1920         if(x_pixel >= 0 && y_pixel >= 0)
1921                 {
1922                 gint r_mouse, g_mouse, b_mouse;
1923
1924                 pixbuf_renderer_get_pixel_colors(pr, x_pixel, y_pixel,
1925                                                  &r_mouse, &g_mouse, &b_mouse);
1926
1927                 text = g_strdup_printf(_("[%*d,%*d]: RGB(%3d,%3d,%3d)"),
1928                                          num_length(width - 1), x_pixel,
1929                                          num_length(height - 1), y_pixel,
1930                                          r_mouse, g_mouse, b_mouse);
1931
1932                 }
1933         else
1934                 {
1935                 text = g_strdup_printf(_("[%*s,%*s]: RGB(---,---,---)"),
1936                                          num_length(width - 1), " ",
1937                                          num_length(height - 1), " ");
1938                 }
1939
1940         attrs = pango_attr_list_new();
1941         pango_attr_list_insert(attrs, pango_attr_family_new("Monospace"));
1942         gtk_label_set_text(GTK_LABEL(lw->info_pixel), text);
1943         gtk_label_set_attributes(GTK_LABEL(lw->info_pixel), attrs);
1944         pango_attr_list_unref(attrs);
1945         g_free(text);
1946 }
1947
1948
1949 /*
1950  *----------------------------------------------------------------------------
1951  * setup
1952  *----------------------------------------------------------------------------
1953  */
1954
1955 static void layout_image_update_cb(ImageWindow *imd, gpointer data)
1956 {
1957         LayoutWindow *lw = data;
1958         layout_status_update_image(lw);
1959 }
1960
1961 GtkWidget *layout_image_new(LayoutWindow *lw, gint i)
1962 {
1963         if (!lw->split_image_sizegroup) lw->split_image_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
1964
1965         if (!lw->split_images[i])
1966                 {
1967                 lw->split_images[i] = image_new(TRUE);
1968
1969                 g_object_ref(lw->split_images[i]->widget);
1970
1971                 g_signal_connect(G_OBJECT(lw->split_images[i]->pr), "update-pixel",
1972                                  G_CALLBACK(layout_status_update_pixel_cb), lw);
1973
1974                 image_background_set_color_from_options(lw->split_images[i], FALSE);
1975
1976                 image_auto_refresh_enable(lw->split_images[i], TRUE);
1977
1978                 layout_image_dnd_init(lw, i);
1979                 image_color_profile_set(lw->split_images[i],
1980                                         options->color_profile.input_type,
1981                                         options->color_profile.use_image);
1982                 image_color_profile_set_use(lw->split_images[i], options->color_profile.enabled);
1983
1984                 gtk_size_group_add_widget(lw->split_image_sizegroup, lw->split_images[i]->widget);
1985                 gtk_widget_set_size_request(lw->split_images[i]->widget, IMAGE_MIN_WIDTH, -1);
1986
1987                 image_set_focus_in_func(lw->split_images[i], layout_image_focus_in_cb, lw);
1988
1989                 }
1990
1991         return lw->split_images[i]->widget;
1992 }
1993
1994 void layout_image_deactivate(LayoutWindow *lw, gint i)
1995 {
1996         if (!lw->split_images[i]) return;
1997         image_set_update_func(lw->split_images[i], NULL, NULL);
1998         layout_image_set_buttons_inactive(lw, i);
1999         image_set_drag_func(lw->split_images[i], layout_image_drag_inactive_cb, lw);
2000
2001         image_attach_window(lw->split_images[i], NULL, NULL, NULL, FALSE);
2002         image_select(lw->split_images[i], FALSE);
2003 }
2004
2005 /* force should be set after change of lw->split_mode */
2006 void layout_image_activate(LayoutWindow *lw, gint i, gboolean force)
2007 {
2008         FileData *fd;
2009
2010         if (!lw->split_images[i]) return;
2011         if (!force && lw->active_split_image == i) return;
2012
2013         /* deactivate currently active */
2014         if (lw->active_split_image != i)
2015                 layout_image_deactivate(lw, lw->active_split_image);
2016
2017         lw->image = lw->split_images[i];
2018         lw->active_split_image = i;
2019
2020         image_set_update_func(lw->image, layout_image_update_cb, lw);
2021         layout_image_set_buttons(lw);
2022         image_set_drag_func(lw->image, layout_image_drag_cb, lw);
2023
2024         image_attach_window(lw->image, lw->window, NULL, GQ_APPNAME, FALSE);
2025
2026         /* do not hilight selected image in SPLIT_NONE */
2027         /* maybe the image should be selected always and hilight should be controled by
2028            another image option */
2029         if (lw->split_mode != SPLIT_NONE)
2030                 image_select(lw->split_images[i], TRUE);
2031         else
2032                 image_select(lw->split_images[i], FALSE);
2033
2034         fd = image_get_fd(lw->image);
2035
2036         if (fd)
2037                 {
2038 //              layout_list_sync_path(lw, path);
2039                 layout_set_fd(lw, fd);
2040                 }
2041         layout_status_update_image(lw);
2042 }
2043
2044
2045 static void layout_image_setup_split_common(LayoutWindow *lw, gint n)
2046 {
2047         gboolean frame = (n > 1) || (!lw->options.tools_float && !lw->options.tools_hidden);
2048         gint i;
2049
2050         for (i = 0; i < n; i++)
2051                 if (!lw->split_images[i])
2052                         {
2053                         FileData *img_fd = NULL;
2054                         double zoom = 0.0;
2055
2056                         layout_image_new(lw, i);
2057                         image_set_frame(lw->split_images[i], frame);
2058                         image_set_selectable(lw->split_images[i], (n > 1));
2059
2060                         if (lw->image)
2061                                 {
2062                                 image_osd_copy_status(lw->image, lw->split_images[i]);
2063                                 }
2064
2065                         if (layout_selection_count(lw, 0) > 1)
2066                                 {
2067                                 GList *work = g_list_last(layout_selection_list(lw));
2068                                 gint j = 0;
2069
2070                                 while (work && j < i)
2071                                         {
2072                                         FileData *fd = work->data;
2073                                         work = work->prev;
2074
2075                                         if (!fd || !*fd->path || fd->parent ||
2076                                                                                 fd == lw->split_images[0]->image_fd)
2077                                                 {
2078                                                 continue;
2079                                                 }
2080                                         img_fd = fd;
2081
2082                                         j++;
2083                                         }
2084                                 }
2085
2086                         if (!img_fd && lw->image)
2087                                 {
2088                                 img_fd = image_get_fd(lw->image);
2089                                 zoom = image_zoom_get(lw->image);
2090                                 }
2091
2092                         if (img_fd)
2093                                 {
2094                                 gdouble sx, sy;
2095                                 image_change_fd(lw->split_images[i], img_fd, zoom);
2096                                 image_get_scroll_center(lw->image, &sx, &sy);
2097                                 image_set_scroll_center(lw->split_images[i], sx, sy);
2098                                 }
2099                         layout_image_deactivate(lw, i);
2100                         }
2101                 else
2102                         {
2103                         image_set_frame(lw->split_images[i], frame);
2104                         image_set_selectable(lw->split_images[i], (n > 1));
2105                         }
2106
2107         for (i = n; i < MAX_SPLIT_IMAGES; i++)
2108                 {
2109                 if (lw->split_images[i])
2110                         {
2111                         g_object_unref(lw->split_images[i]->widget);
2112                         lw->split_images[i] = NULL;
2113                         }
2114                 }
2115
2116         if (!lw->image || lw->active_split_image < 0 || lw->active_split_image >= n)
2117                 {
2118                 layout_image_activate(lw, 0, TRUE);
2119                 }
2120         else
2121                 {
2122                 /* this will draw the frame around selected image (image_select)
2123                    on switch from single to split images */
2124                 layout_image_activate(lw, lw->active_split_image, TRUE);
2125                 }
2126 }
2127
2128 GtkWidget *layout_image_setup_split_none(LayoutWindow *lw)
2129 {
2130         lw->split_mode = SPLIT_NONE;
2131
2132         layout_image_setup_split_common(lw, 1);
2133
2134         lw->split_image_widget = lw->split_images[0]->widget;
2135
2136         return lw->split_image_widget;
2137 }
2138
2139
2140 GtkWidget *layout_image_setup_split_hv(LayoutWindow *lw, gboolean horizontal)
2141 {
2142         GtkWidget *paned;
2143
2144         lw->split_mode = horizontal ? SPLIT_HOR : SPLIT_VERT;
2145
2146         layout_image_setup_split_common(lw, 2);
2147
2148         /* horizontal split means vpaned and vice versa */
2149         if (horizontal)
2150                 paned = gtk_vpaned_new();
2151         else
2152                 paned = gtk_hpaned_new();
2153
2154         gtk_paned_pack1(GTK_PANED(paned), lw->split_images[0]->widget, TRUE, TRUE);
2155         gtk_paned_pack2(GTK_PANED(paned), lw->split_images[1]->widget, TRUE, TRUE);
2156
2157         gtk_widget_show(lw->split_images[0]->widget);
2158         gtk_widget_show(lw->split_images[1]->widget);
2159
2160         lw->split_image_widget = paned;
2161
2162         return lw->split_image_widget;
2163
2164 }
2165
2166 GtkWidget *layout_image_setup_split_quad(LayoutWindow *lw)
2167 {
2168         GtkWidget *hpaned;
2169         GtkWidget *vpaned1;
2170         GtkWidget *vpaned2;
2171         gint i;
2172
2173         lw->split_mode = SPLIT_QUAD;
2174
2175         layout_image_setup_split_common(lw, 4);
2176
2177         hpaned = gtk_hpaned_new();
2178         vpaned1 = gtk_vpaned_new();
2179         vpaned2 = gtk_vpaned_new();
2180
2181         gtk_paned_pack1(GTK_PANED(vpaned1), lw->split_images[0]->widget, TRUE, TRUE);
2182         gtk_paned_pack2(GTK_PANED(vpaned1), lw->split_images[2]->widget, TRUE, TRUE);
2183
2184         gtk_paned_pack1(GTK_PANED(vpaned2), lw->split_images[1]->widget, TRUE, TRUE);
2185         gtk_paned_pack2(GTK_PANED(vpaned2), lw->split_images[3]->widget, TRUE, TRUE);
2186
2187         gtk_paned_pack1(GTK_PANED(hpaned), vpaned1, TRUE, TRUE);
2188         gtk_paned_pack2(GTK_PANED(hpaned), vpaned2, TRUE, TRUE);
2189
2190         for (i = 0; i < 4; i++)
2191                 gtk_widget_show(lw->split_images[i]->widget);
2192
2193         gtk_widget_show(vpaned1);
2194         gtk_widget_show(vpaned2);
2195
2196         lw->split_image_widget = hpaned;
2197
2198         return lw->split_image_widget;
2199
2200 }
2201
2202 GtkWidget *layout_image_setup_split(LayoutWindow *lw, ImageSplitMode mode)
2203 {
2204         switch (mode)
2205                 {
2206                 case SPLIT_HOR:
2207                         return layout_image_setup_split_hv(lw, TRUE);
2208                 case SPLIT_VERT:
2209                         return layout_image_setup_split_hv(lw, FALSE);
2210                 case SPLIT_QUAD:
2211                         return layout_image_setup_split_quad(lw);
2212                 case SPLIT_NONE:
2213                 default:
2214                         return layout_image_setup_split_none(lw);
2215                 }
2216 }
2217
2218
2219 /*
2220  *-----------------------------------------------------------------------------
2221  * maintenance (for rename, move, remove)
2222  *-----------------------------------------------------------------------------
2223  */
2224
2225 static void layout_image_maint_renamed(LayoutWindow *lw, FileData *fd)
2226 {
2227         if (fd == layout_image_get_fd(lw))
2228                 {
2229                 image_set_fd(lw->image, fd);
2230                 }
2231 }
2232
2233 static void layout_image_maint_removed(LayoutWindow *lw, FileData *fd)
2234 {
2235         if (fd == layout_image_get_fd(lw))
2236                 {
2237                 CollectionData *cd;
2238                 CollectInfo *info;
2239
2240                 cd = image_get_collection(lw->image, &info);
2241                 if (cd && info)
2242                         {
2243                         CollectInfo *new;
2244
2245                         new = collection_next_by_info(cd, info);
2246                         if (!new) new = collection_prev_by_info(cd, info);
2247
2248                         if (new)
2249                                 {
2250                                 layout_image_set_collection(lw, cd, new);
2251                                 return;
2252                                 }
2253                         layout_image_set_fd(lw, NULL);
2254                         }
2255
2256                 /* the image will be set to the next image from the list soon,
2257                    setting it to NULL here is not necessary*/
2258                 }
2259 }
2260
2261
2262 void layout_image_notify_cb(FileData *fd, NotifyType type, gpointer data)
2263 {
2264         LayoutWindow *lw = data;
2265
2266         if (!(type & NOTIFY_CHANGE) || !fd->change) return;
2267
2268         DEBUG_1("Notify layout_image: %s %04x", fd->path, type);
2269
2270         switch (fd->change->type)
2271                 {
2272                 case FILEDATA_CHANGE_MOVE:
2273                 case FILEDATA_CHANGE_RENAME:
2274                         layout_image_maint_renamed(lw, fd);
2275                         break;
2276                 case FILEDATA_CHANGE_DELETE:
2277                         layout_image_maint_removed(lw, fd);
2278                         break;
2279                 case FILEDATA_CHANGE_COPY:
2280                 case FILEDATA_CHANGE_UNSPECIFIED:
2281                 case FILEDATA_CHANGE_WRITE_METADATA:
2282                         break;
2283                 }
2284
2285 }
2286 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */