Mercurial > geeqie
annotate src/img-view.c @ 77:44f2223541d1
Sun Oct 15 10:45:14 2006 John Ellis <johne@verizon.net>
* pan-view.c: Recalc the size of the layout when popping up new images
in the calendar so that all new images can be scrolled into view.
* pixbuf-renderer.[ch] (pixbuf_renderer_set_tiles_size): Add ability
to resize a tile canvas without the need for a complete reset/render.
author | gqview |
---|---|
date | Sun, 15 Oct 2006 14:49:25 +0000 |
parents | 04ff0df3ad2f |
children | a4c1b7014e6e |
rev | line source |
---|---|
1 | 1 /* |
9 | 2 * GQview |
3 * (C) 2004 John Ellis | |
1 | 4 * |
5 * Author: John Ellis | |
6 * | |
9 | 7 * This software is released under the GNU General Public License (GNU GPL). |
8 * Please read the included file COPYING for more information. | |
9 * This software comes with no warranty of any kind, use at your own risk! | |
1 | 10 */ |
11 | |
9 | 12 |
1 | 13 #include "gqview.h" |
9 | 14 #include "img-view.h" |
15 | |
16 #include "collect.h" | |
17 #include "collect-io.h" | |
18 #include "dnd.h" | |
19 #include "editors.h" | |
20 #include "filelist.h" | |
21 #include "fullscreen.h" | |
1 | 22 #include "image.h" |
9 | 23 #include "image-overlay.h" |
24 #include "info.h" | |
25 #include "menu.h" | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
26 #include "pixbuf-renderer.h" |
9 | 27 #include "slideshow.h" |
28 #include "utilops.h" | |
29 #include "ui_bookmark.h" | |
30 #include "ui_fileops.h" | |
31 #include "ui_menu.h" | |
32 | |
1 | 33 #include <gdk/gdkkeysyms.h> /* for keyboard values */ |
34 | |
9 | 35 #include "icons/view.xpm" |
36 | |
37 | |
38 typedef struct _ViewWindow ViewWindow; | |
39 struct _ViewWindow | |
40 { | |
41 GtkWidget *window; | |
42 ImageWindow *imd; | |
43 FullScreenData *fs; | |
44 SlideShowData *ss; | |
45 | |
46 GList *list; | |
47 GList *list_pointer; | |
48 | |
49 gint overlay_id; | |
50 }; | |
51 | |
52 | |
53 static GList *view_window_list = NULL; | |
54 | |
55 | |
56 static GtkWidget *view_popup_menu(ViewWindow *vw); | |
57 static void view_fullscreen_toggle(ViewWindow *vw, gint force_off); | |
58 static void view_overlay_toggle(ViewWindow *vw); | |
59 | |
60 static void view_slideshow_next(ViewWindow *vw); | |
61 static void view_slideshow_prev(ViewWindow *vw); | |
62 static void view_slideshow_start(ViewWindow *vw); | |
63 static void view_slideshow_stop(ViewWindow *vw); | |
64 | |
65 static void view_window_close(ViewWindow *vw); | |
66 | |
67 static void view_window_dnd_init(ViewWindow *vw); | |
68 | |
69 | |
70 /* | |
71 *----------------------------------------------------------------------------- | |
72 * misc | |
73 *----------------------------------------------------------------------------- | |
74 */ | |
75 | |
76 static ImageWindow *view_window_active_image(ViewWindow *vw) | |
77 { | |
78 if (vw->fs) return vw->fs->imd; | |
79 | |
80 return vw->imd; | |
81 } | |
82 | |
83 static void view_window_set_list(ViewWindow *vw, GList *list) | |
84 { | |
85 | |
86 path_list_free(vw->list); | |
87 vw->list = NULL; | |
88 vw->list_pointer = NULL; | |
89 | |
90 vw->list = path_list_copy(list); | |
91 } | |
92 | |
93 static gint view_window_contains_collection(ViewWindow *vw) | |
94 { | |
95 CollectionData *cd; | |
96 CollectInfo *info; | |
97 | |
98 cd = image_get_collection(view_window_active_image(vw), &info); | |
99 | |
100 return (cd && info); | |
101 } | |
102 | |
103 static void view_collection_step(ViewWindow *vw, gint next) | |
104 { | |
105 ImageWindow *imd = view_window_active_image(vw); | |
106 CollectionData *cd; | |
107 CollectInfo *info; | |
108 CollectInfo *read_ahead_info = NULL; | |
109 | |
110 cd = image_get_collection(imd, &info); | |
111 | |
112 if (!cd || !info) return; | |
113 | |
114 if (next) | |
115 { | |
116 info = collection_next_by_info(cd, info); | |
117 if (enable_read_ahead) | |
118 { | |
119 read_ahead_info = collection_next_by_info(cd, info); | |
120 if (!read_ahead_info) read_ahead_info = collection_prev_by_info(cd, info); | |
121 } | |
122 } | |
123 else | |
124 { | |
125 info = collection_prev_by_info(cd, info); | |
126 if (enable_read_ahead) | |
127 { | |
128 read_ahead_info = collection_prev_by_info(cd, info); | |
129 if (!read_ahead_info) read_ahead_info = collection_next_by_info(cd, info); | |
130 } | |
131 } | |
132 | |
133 if (info) | |
134 { | |
135 image_change_from_collection(imd, cd, info, image_zoom_get_default(imd, zoom_mode)); | |
136 | |
137 if (read_ahead_info) image_prebuffer_set(imd, read_ahead_info->path); | |
138 } | |
139 | |
140 } | |
141 | |
142 static void view_collection_step_to_end(ViewWindow *vw, gint last) | |
143 { | |
144 ImageWindow *imd = view_window_active_image(vw); | |
145 CollectionData *cd; | |
146 CollectInfo *info; | |
147 CollectInfo *read_ahead_info = NULL; | |
148 | |
149 cd = image_get_collection(imd, &info); | |
150 | |
151 if (!cd || !info) return; | |
152 | |
153 if (last) | |
154 { | |
155 info = collection_get_last(cd); | |
156 if (enable_read_ahead) read_ahead_info = collection_prev_by_info(cd, info); | |
157 } | |
158 else | |
159 { | |
160 info = collection_get_first(cd); | |
161 if (enable_read_ahead) read_ahead_info = collection_next_by_info(cd, info); | |
162 } | |
163 | |
164 if (info) | |
165 { | |
166 image_change_from_collection(imd, cd, info, image_zoom_get_default(imd, zoom_mode)); | |
167 if (read_ahead_info) image_prebuffer_set(imd, read_ahead_info->path); | |
168 } | |
169 } | |
170 | |
171 static void view_list_step(ViewWindow *vw, gint next) | |
172 { | |
173 ImageWindow *imd = view_window_active_image(vw); | |
174 const gchar *path; | |
175 GList *work; | |
176 GList *work_ahead; | |
177 | |
178 if (!vw->list) return; | |
179 | |
180 path = image_get_path(imd); | |
181 if (!path) return; | |
182 | |
183 if (g_list_position(vw->list, vw->list_pointer) >= 0) | |
184 { | |
185 work = vw->list_pointer; | |
186 } | |
187 else | |
188 { | |
189 gint found = FALSE; | |
190 | |
191 work = vw->list; | |
192 while (work && !found) | |
193 { | |
194 gchar *temp; | |
195 | |
196 temp = work->data; | |
197 | |
198 if (strcmp(path, temp) == 0) | |
199 { | |
200 found = TRUE; | |
201 } | |
202 else | |
203 { | |
204 work = work->next; | |
205 } | |
206 } | |
207 } | |
208 if (!work) return; | |
209 | |
210 work_ahead = NULL; | |
211 if (next) | |
212 { | |
213 work = work->next; | |
214 if (work) work_ahead = work->next; | |
215 } | |
216 else | |
217 { | |
218 work = work->prev; | |
219 if (work) work_ahead = work->prev; | |
220 } | |
221 if (!work) return; | |
222 | |
223 vw->list_pointer = work; | |
224 path = work->data; | |
225 image_change_path(imd, path, image_zoom_get_default(imd, zoom_mode)); | |
226 | |
227 if (enable_read_ahead && work_ahead) | |
228 { | |
229 const gchar *next_path = work_ahead->data; | |
230 image_prebuffer_set(imd, next_path); | |
231 } | |
232 } | |
233 | |
234 static void view_list_step_to_end(ViewWindow *vw, gint last) | |
235 { | |
236 ImageWindow *imd = view_window_active_image(vw); | |
237 const gchar *path; | |
238 GList *work; | |
239 GList *work_ahead; | |
240 | |
241 if (!vw->list) return; | |
242 | |
243 if (last) | |
244 { | |
245 work = g_list_last(vw->list); | |
246 work_ahead = work->prev; | |
247 } | |
248 else | |
249 { | |
250 work = vw->list; | |
251 work_ahead = work->next; | |
252 } | |
253 | |
254 vw->list_pointer = work; | |
255 path = work->data; | |
256 image_change_path(imd, path, image_zoom_get_default(imd, zoom_mode)); | |
257 | |
258 if (enable_read_ahead && work_ahead) | |
259 { | |
260 const gchar *next_path = work_ahead->data; | |
261 image_prebuffer_set(imd, next_path); | |
262 } | |
263 } | |
264 | |
265 static void view_step_next(ViewWindow *vw) | |
266 { | |
267 if (vw->ss) | |
268 { | |
269 view_slideshow_next(vw); | |
270 } | |
271 else if (vw->list) | |
272 { | |
273 view_list_step(vw, TRUE); | |
274 } | |
275 else | |
276 { | |
277 view_collection_step(vw, TRUE); | |
278 } | |
279 } | |
280 | |
281 static void view_step_prev(ViewWindow *vw) | |
282 { | |
283 if (vw->ss) | |
284 { | |
285 view_slideshow_prev(vw); | |
286 } | |
287 else if (vw->list) | |
288 { | |
289 view_list_step(vw, FALSE); | |
290 } | |
291 else | |
292 { | |
293 view_collection_step(vw, FALSE); | |
294 } | |
295 } | |
296 | |
297 static void view_step_to_end(ViewWindow *vw, gint last) | |
298 { | |
299 if (vw->list) | |
300 { | |
301 view_list_step_to_end(vw, last); | |
302 } | |
303 else | |
304 { | |
305 view_collection_step_to_end(vw, last); | |
306 } | |
307 } | |
308 | |
1 | 309 /* |
310 *----------------------------------------------------------------------------- | |
311 * view window keyboard | |
312 *----------------------------------------------------------------------------- | |
313 */ | |
314 | |
9 | 315 static void view_window_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) |
316 { | |
317 ViewWindow *vw = data; | |
318 ImageWindow *imd; | |
319 | |
320 imd = view_window_active_image(vw); | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
321 gdk_window_get_origin(imd->pr->window, x, y); |
9 | 322 popup_menu_position_clamp(menu, x, y, 0); |
323 } | |
324 | |
1 | 325 static gint view_window_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) |
326 { | |
9 | 327 ViewWindow *vw = data; |
328 ImageWindow *imd; | |
1 | 329 gint stop_signal = FALSE; |
9 | 330 GtkWidget *menu; |
1 | 331 gint x = 0; |
332 gint y = 0; | |
333 | |
9 | 334 imd = view_window_active_image(vw); |
335 | |
1 | 336 switch (event->keyval) |
337 { | |
9 | 338 case GDK_Left: case GDK_KP_Left: |
1 | 339 x -= 1; |
340 stop_signal = TRUE; | |
341 break; | |
9 | 342 case GDK_Right: case GDK_KP_Right: |
1 | 343 x += 1; |
344 stop_signal = TRUE; | |
345 break; | |
9 | 346 case GDK_Up: case GDK_KP_Up: |
1 | 347 y -= 1; |
348 stop_signal = TRUE; | |
349 break; | |
9 | 350 case GDK_Down: case GDK_KP_Down: |
1 | 351 y += 1; |
352 stop_signal = TRUE; | |
353 break; | |
9 | 354 } |
355 | |
356 if ( !(event->state & GDK_CONTROL_MASK) ) | |
357 switch (event->keyval) | |
358 { | |
359 case GDK_Page_Up: case GDK_KP_Page_Up: | |
360 case GDK_BackSpace: | |
361 case 'B': case 'b': | |
362 view_step_prev(vw); | |
363 stop_signal = TRUE; | |
1 | 364 break; |
9 | 365 case GDK_Page_Down: case GDK_KP_Page_Down: |
366 case GDK_space: | |
367 case 'N': case 'n': | |
368 view_step_next(vw); | |
369 stop_signal = TRUE; | |
1 | 370 break; |
9 | 371 case GDK_Home: case GDK_KP_Home: |
372 view_step_to_end(vw, FALSE); | |
373 stop_signal = TRUE; | |
1 | 374 break; |
9 | 375 case GDK_End: case GDK_KP_End: |
376 view_step_to_end(vw, TRUE); | |
1 | 377 stop_signal = TRUE; |
378 break; | |
9 | 379 case '+': case '=': case GDK_KP_Add: |
380 image_zoom_adjust(imd, get_zoom_increment()); | |
381 break; | |
382 case '-': case GDK_KP_Subtract: | |
383 image_zoom_adjust(imd, -get_zoom_increment()); | |
384 break; | |
385 case 'X': case 'x': case GDK_KP_Multiply: | |
386 image_zoom_set(imd, 0.0); | |
387 break; | |
388 case 'Z': case 'z': case GDK_KP_Divide: case '1': | |
389 image_zoom_set(imd, 1.0); | |
390 break; | |
391 case '2': | |
392 image_zoom_set(imd, 2.0); | |
393 break; | |
394 case '3': | |
395 image_zoom_set(imd, 3.0); | |
396 break; | |
397 case '4': | |
398 image_zoom_set(imd, 4.0); | |
399 break; | |
400 case '7': | |
401 image_zoom_set(imd, -4.0); | |
402 break; | |
403 case '8': | |
404 image_zoom_set(imd, -3.0); | |
405 break; | |
406 case '9': | |
407 image_zoom_set(imd, -2.0); | |
408 break; | |
409 case 'W': case 'w': | |
410 image_zoom_set_fill_geometry(imd, FALSE); | |
411 break; | |
412 case 'H': case 'h': | |
413 image_zoom_set_fill_geometry(imd, TRUE); | |
414 break; | |
415 case 'R': case 'r': | |
416 image_reload(imd); | |
417 break; | |
418 case 'S': case 's': | |
419 if (vw->ss) | |
420 view_slideshow_stop(vw); | |
421 else | |
422 view_slideshow_start(vw); | |
423 stop_signal = TRUE; | |
424 break; | |
425 case 'P': case 'p': | |
426 slideshow_pause_toggle(vw->ss); | |
427 break; | |
428 case 'F': case 'f': | |
429 case 'V': case 'v': | |
430 view_fullscreen_toggle(vw, FALSE); | |
431 stop_signal = TRUE; | |
432 break; | |
433 case 'I': case 'i': | |
434 view_overlay_toggle(vw); | |
435 break; | |
436 case ']': | |
437 image_alter(imd, ALTER_ROTATE_90); | |
438 stop_signal = TRUE; | |
439 break; | |
440 case '[': | |
441 image_alter(imd, ALTER_ROTATE_90_CC); | |
442 stop_signal = TRUE; | |
443 break; | |
444 case GDK_Delete: case GDK_KP_Delete: | |
445 if (enable_delete_key) | |
446 { | |
447 file_util_delete(image_get_path(imd), NULL, imd->widget); | |
448 stop_signal = TRUE; | |
449 } | |
450 break; | |
1 | 451 case GDK_Escape: |
9 | 452 if (vw->fs) |
453 { | |
454 view_fullscreen_toggle(vw, TRUE); | |
455 } | |
456 else | |
457 { | |
458 gtk_widget_destroy(vw->window); | |
459 } | |
460 stop_signal = TRUE; | |
461 break; | |
462 case GDK_Menu: | |
463 case GDK_F10: | |
464 menu = view_popup_menu(vw); | |
465 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, view_window_menu_pos_cb, vw, 0, GDK_CURRENT_TIME); | |
1 | 466 stop_signal = TRUE; |
467 break; | |
468 } | |
469 | |
470 if (event->state & GDK_CONTROL_MASK) | |
471 { | |
472 gint n = -1; | |
473 switch (event->keyval) | |
474 { | |
475 case '1': | |
476 n = 0; | |
477 break; | |
478 case '2': | |
479 n = 1; | |
480 break; | |
481 case '3': | |
482 n = 2; | |
483 break; | |
484 case '4': | |
485 n = 3; | |
486 break; | |
487 case '5': | |
488 n = 4; | |
489 break; | |
490 case '6': | |
491 n = 5; | |
492 break; | |
493 case '7': | |
494 n = 6; | |
495 break; | |
496 case '8': | |
497 n = 7; | |
498 break; | |
9 | 499 case '9': |
500 n = 8; | |
501 break; | |
502 case '0': | |
503 n = 9; | |
504 break; | |
505 case 'C': case 'c': | |
506 file_util_copy(image_get_path(imd), NULL, NULL, imd->widget); | |
507 stop_signal = TRUE; | |
508 break; | |
509 case 'M': case 'm': | |
510 file_util_move(image_get_path(imd), NULL, NULL, imd->widget); | |
511 stop_signal = TRUE; | |
512 break; | |
513 case 'R': case 'r': | |
514 file_util_rename(image_get_path(imd), NULL, imd->widget); | |
515 stop_signal = TRUE; | |
516 break; | |
517 case 'D': case 'd': | |
518 file_util_delete(image_get_path(imd), NULL, imd->widget); | |
519 stop_signal = TRUE; | |
520 break; | |
521 case 'P': case 'p': | |
522 info_window_new(image_get_path(imd), NULL); | |
523 stop_signal = TRUE; | |
524 break; | |
525 case 'W': case 'w': | |
526 view_window_close(vw); | |
527 break; | |
1 | 528 } |
529 if (n != -1) | |
530 { | |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
531 if (!editor_window_flag_set(n)) |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
532 { |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
533 view_fullscreen_toggle(vw, TRUE); |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
534 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
535 imd = view_window_active_image(vw); |
9 | 536 start_editor_from_file(n, image_get_path(imd)); |
1 | 537 } |
538 } | |
9 | 539 else if (event->state & GDK_SHIFT_MASK) |
1 | 540 { |
9 | 541 switch (event->keyval) |
542 { | |
543 case 'R': case 'r': | |
544 image_alter(imd, ALTER_ROTATE_180); | |
545 stop_signal = TRUE; | |
546 break; | |
547 case 'M': case 'm': | |
548 image_alter(imd, ALTER_MIRROR); | |
549 stop_signal = TRUE; | |
550 break; | |
551 case 'F': case 'f': | |
552 image_alter(imd, ALTER_FLIP); | |
553 stop_signal = TRUE; | |
554 break; | |
555 default: | |
556 break; | |
557 } | |
1 | 558 x *= 3; |
559 y *= 3; | |
560 } | |
561 | |
562 if (x != 0 || y!= 0) | |
563 { | |
564 keyboard_scroll_calc(&x, &y, event); | |
9 | 565 image_scroll(imd, x, y); |
1 | 566 } |
567 | |
568 return stop_signal; | |
569 } | |
570 | |
571 /* | |
572 *----------------------------------------------------------------------------- | |
573 * view window main routines | |
574 *----------------------------------------------------------------------------- | |
575 */ | |
576 | |
9 | 577 static void button_cb(ImageWindow *imd, gint button, guint32 time, |
578 gdouble x, gdouble y, guint state, gpointer data) | |
579 { | |
580 ViewWindow *vw = data; | |
581 GtkWidget *menu; | |
582 | |
583 switch (button) | |
584 { | |
585 case 1: | |
586 view_step_next(vw); | |
587 break; | |
588 case 2: | |
589 view_step_prev(vw); | |
590 break; | |
591 case 3: | |
592 menu = view_popup_menu(vw); | |
593 gtk_menu_popup (GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, time); | |
594 break; | |
595 default: | |
596 break; | |
597 } | |
598 } | |
599 | |
600 static void scroll_cb(ImageWindow *imd, GdkScrollDirection direction, guint32 time, | |
601 gdouble x, gdouble y, guint state, gpointer data) | |
1 | 602 { |
9 | 603 ViewWindow *vw = data; |
604 | |
605 if (state & GDK_CONTROL_MASK) | |
606 { | |
607 switch (direction) | |
608 { | |
609 case GDK_SCROLL_UP: | |
610 image_zoom_adjust_at_point(imd, get_zoom_increment(), x, y); | |
611 break; | |
612 case GDK_SCROLL_DOWN: | |
613 image_zoom_adjust_at_point(imd, -get_zoom_increment(), x, y); | |
614 break; | |
615 default: | |
616 break; | |
617 } | |
618 } | |
619 else if ( (state & GDK_SHIFT_MASK) != (mousewheel_scrolls)) | |
620 { | |
621 switch (direction) | |
622 { | |
623 case GDK_SCROLL_UP: | |
624 image_scroll(imd, 0, -MOUSEWHEEL_SCROLL_SIZE); | |
625 break; | |
626 case GDK_SCROLL_DOWN: | |
627 image_scroll(imd, 0, MOUSEWHEEL_SCROLL_SIZE); | |
628 break; | |
629 case GDK_SCROLL_LEFT: | |
630 image_scroll(imd, -MOUSEWHEEL_SCROLL_SIZE, 0); | |
631 break; | |
632 case GDK_SCROLL_RIGHT: | |
633 image_scroll(imd, MOUSEWHEEL_SCROLL_SIZE, 0); | |
634 break; | |
635 default: | |
636 break; | |
637 } | |
638 } | |
639 else | |
640 { | |
641 switch (direction) | |
642 { | |
643 case GDK_SCROLL_UP: | |
644 view_step_prev(vw); | |
645 break; | |
646 case GDK_SCROLL_DOWN: | |
647 view_step_next(vw); | |
648 break; | |
649 default: | |
650 break; | |
651 } | |
652 } | |
653 } | |
654 | |
655 static void view_image_set_buttons(ViewWindow *vw, ImageWindow *imd) | |
656 { | |
657 image_set_button_func(imd, button_cb, vw); | |
658 image_set_scroll_func(imd, scroll_cb, vw); | |
659 } | |
660 | |
661 static void view_fullscreen_stop_func(FullScreenData *fs, gpointer data) | |
662 { | |
663 ViewWindow *vw = data; | |
664 | |
665 vw->fs = NULL; | |
666 | |
667 if (vw->ss) vw->ss->imd = vw->imd; | |
1 | 668 } |
669 | |
9 | 670 static void view_fullscreen_toggle(ViewWindow *vw, gint force_off) |
4 | 671 { |
9 | 672 if (force_off && !vw->fs) return; |
673 | |
674 if (vw->fs) | |
675 { | |
676 fullscreen_stop(vw->fs); | |
677 | |
678 if (vw->overlay_id != -1) vw->overlay_id = image_overlay_info_enable(vw->imd); | |
679 } | |
680 else | |
681 { | |
682 vw->fs = fullscreen_start(vw->window, vw->imd, view_fullscreen_stop_func, vw); | |
683 | |
684 view_image_set_buttons(vw, vw->fs->imd); | |
685 g_signal_connect(G_OBJECT(vw->fs->window), "key_press_event", | |
686 G_CALLBACK(view_window_key_press_cb), vw); | |
687 | |
688 if (vw->ss) vw->ss->imd = vw->fs->imd; | |
689 | |
690 if (vw->overlay_id != -1) | |
691 { | |
692 image_overlay_info_disable(vw->imd, vw->overlay_id); | |
693 vw->overlay_id = image_overlay_info_enable(vw->fs->imd); | |
694 } | |
695 } | |
696 } | |
697 | |
698 static void view_overlay_toggle(ViewWindow *vw) | |
699 { | |
700 ImageWindow *imd; | |
701 | |
702 imd = view_window_active_image(vw); | |
703 | |
704 if (vw->overlay_id == -1) | |
705 { | |
706 vw->overlay_id = image_overlay_info_enable(imd); | |
707 } | |
708 else | |
709 { | |
710 image_overlay_info_disable(imd, vw->overlay_id); | |
711 vw->overlay_id = -1; | |
712 } | |
713 } | |
714 | |
715 static void view_slideshow_next(ViewWindow *vw) | |
716 { | |
717 if (vw->ss) slideshow_next(vw->ss); | |
4 | 718 } |
719 | |
9 | 720 static void view_slideshow_prev(ViewWindow *vw) |
721 { | |
722 if (vw->ss) slideshow_prev(vw->ss); | |
723 } | |
724 | |
725 static void view_slideshow_stop_func(SlideShowData *fs, gpointer data) | |
726 { | |
727 ViewWindow *vw = data; | |
728 | |
729 vw->ss = NULL; | |
730 } | |
731 | |
732 static void view_slideshow_start(ViewWindow *vw) | |
4 | 733 { |
9 | 734 if (!vw->ss) |
735 { | |
736 CollectionData *cd; | |
737 CollectInfo *info; | |
738 | |
739 if (vw->list) | |
740 { | |
741 vw->ss = slideshow_start_from_path_list(view_window_active_image(vw), | |
742 path_list_copy(vw->list), | |
743 view_slideshow_stop_func, vw); | |
744 vw->list_pointer = NULL; | |
745 return; | |
746 } | |
747 | |
748 cd = image_get_collection(view_window_active_image(vw), &info); | |
749 if (cd && info) | |
750 { | |
751 vw->ss = slideshow_start_from_collection(view_window_active_image(vw), cd, | |
752 view_slideshow_stop_func, vw, info); | |
753 } | |
754 } | |
755 } | |
756 | |
757 static void view_slideshow_stop(ViewWindow *vw) | |
758 { | |
759 if (vw->ss) slideshow_free(vw->ss); | |
760 } | |
761 | |
762 static void view_window_close(ViewWindow *vw) | |
763 { | |
764 view_window_list = g_list_remove(view_window_list, vw); | |
765 | |
766 view_slideshow_stop(vw); | |
767 view_fullscreen_toggle(vw, TRUE); | |
768 gtk_widget_destroy(vw->window); | |
769 path_list_free(vw->list); | |
770 g_free(vw); | |
4 | 771 } |
772 | |
1 | 773 static gint view_window_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data) |
774 { | |
9 | 775 ViewWindow *vw = data; |
776 | |
777 view_window_close(vw); | |
1 | 778 return TRUE; |
779 } | |
780 | |
9 | 781 static ViewWindow *real_view_window_new(const gchar *path, GList *list, CollectionData *cd, CollectInfo *info) |
1 | 782 { |
9 | 783 ViewWindow *vw; |
1 | 784 GtkAllocation req_size; |
9 | 785 GdkGeometry geometry; |
1 | 786 gint w, h; |
9 | 787 |
788 if (!path && !list && (!cd || !info)) return NULL; | |
789 | |
790 vw = g_new0(ViewWindow, 1); | |
791 vw->fs = NULL; | |
792 vw->ss = NULL; | |
793 vw->list = NULL; | |
794 vw->list_pointer = NULL; | |
795 | |
796 vw->overlay_id = -1; | |
797 | |
798 vw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
799 | |
800 geometry.min_width = 8; | |
801 geometry.min_height = 8; | |
802 gtk_window_set_geometry_hints(GTK_WINDOW(vw->window), NULL, &geometry, GDK_HINT_MIN_SIZE); | |
1 | 803 |
9 | 804 gtk_window_set_resizable(GTK_WINDOW(vw->window), TRUE); |
805 gtk_window_set_title (GTK_WINDOW(vw->window), "GQview"); | |
806 gtk_window_set_wmclass(GTK_WINDOW(vw->window), "view", "GQview"); | |
807 gtk_container_set_border_width(GTK_CONTAINER(vw->window), 0); | |
808 | |
809 window_set_icon(vw->window, (const gchar **)view_xpm, NULL); | |
810 | |
811 vw->imd = image_new(FALSE); | |
812 | |
813 if (black_window_background) image_background_set_black(vw->imd, TRUE); | |
814 | |
815 image_attach_window(vw->imd, vw->window, NULL, "GQview", TRUE); | |
816 | |
817 image_auto_refresh(vw->imd, 0); | |
818 image_top_window_set_sync(vw->imd, TRUE); | |
819 | |
820 gtk_container_add(GTK_CONTAINER(vw->window), vw->imd->widget); | |
821 gtk_widget_show(vw->imd->widget); | |
822 | |
823 view_window_dnd_init(vw); | |
1 | 824 |
9 | 825 view_image_set_buttons(vw, vw->imd); |
1 | 826 |
9 | 827 g_signal_connect(G_OBJECT(vw->window), "delete_event", |
828 G_CALLBACK(view_window_delete_cb), vw); | |
829 g_signal_connect(G_OBJECT(vw->window), "key_press_event", | |
830 G_CALLBACK(view_window_key_press_cb), vw); | |
831 if (cd && info) | |
832 { | |
833 image_change_from_collection(vw->imd, cd, info, image_zoom_get_default(NULL, zoom_mode)); | |
834 if (enable_read_ahead) | |
835 { | |
836 CollectInfo * r_info = collection_next_by_info(cd, info); | |
837 if (!r_info) r_info = collection_prev_by_info(cd, info); | |
838 if (r_info) image_prebuffer_set(vw->imd, r_info->path); | |
839 } | |
840 } | |
841 else if (list) | |
842 { | |
843 view_window_set_list(vw, list); | |
844 vw->list_pointer = vw->list; | |
845 image_change_path(vw->imd, (gchar *)vw->list->data, image_zoom_get_default(NULL, zoom_mode)); | |
1 | 846 |
9 | 847 if (enable_read_ahead) |
848 { | |
849 GList *work = vw->list->next; | |
850 if (work) image_prebuffer_set(vw->imd, (gchar *)work->data); | |
851 } | |
852 } | |
853 else | |
854 { | |
855 image_change_path(vw->imd, path, image_zoom_get_default(NULL, zoom_mode)); | |
856 } | |
1 | 857 |
9 | 858 if (image_zoom_get(vw->imd) == 0.0) |
859 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
860 pixbuf_renderer_get_image_size(PIXBUF_RENDERER(vw->imd->pr), &w, &h); |
9 | 861 } |
862 else | |
863 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
864 pixbuf_renderer_get_scaled_size(PIXBUF_RENDERER(vw->imd->pr), &w, &h); |
9 | 865 } |
1 | 866 if (limit_window_size) |
867 { | |
868 gint mw = gdk_screen_width() * max_window_size / 100; | |
869 gint mh = gdk_screen_height() * max_window_size / 100; | |
870 | |
871 if (w > mw) w = mw; | |
872 if (h > mh) h = mh; | |
873 } | |
874 | |
9 | 875 gtk_window_set_default_size(GTK_WINDOW(vw->window), w, h); |
1 | 876 req_size.x = req_size.y = 0; |
877 req_size.width = w; | |
878 req_size.height = h; | |
9 | 879 gtk_widget_size_allocate(GTK_WIDGET(vw->window), &req_size); |
880 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
881 gtk_widget_set_size_request(vw->imd->pr, w, h); |
9 | 882 |
883 gtk_widget_show(vw->window); | |
884 | |
885 view_window_list = g_list_append(view_window_list, vw); | |
886 | |
887 return vw; | |
888 } | |
889 | |
890 static void view_window_collection_unref_cb(GtkWidget *widget, gpointer data) | |
891 { | |
892 CollectionData *cd = data; | |
893 | |
894 collection_unref(cd); | |
895 } | |
896 | |
897 void view_window_new(const gchar *path) | |
898 { | |
899 if (file_extension_match(path, ".gqv")) | |
900 { | |
901 ViewWindow *vw; | |
902 CollectionData *cd; | |
903 CollectInfo *info; | |
904 | |
905 cd = collection_new(path); | |
906 if (collection_load(cd, path, FALSE)) | |
907 { | |
908 info = collection_get_first(cd); | |
909 } | |
910 else | |
911 { | |
912 collection_unref(cd); | |
913 cd = NULL; | |
914 info = NULL; | |
915 } | |
916 vw = real_view_window_new(NULL, NULL, cd, info); | |
917 if (vw && cd) | |
918 { | |
919 g_signal_connect(G_OBJECT(vw->window), "destroy", | |
920 G_CALLBACK(view_window_collection_unref_cb), cd); | |
921 } | |
922 } | |
923 else if (isdir(path)) | |
924 { | |
925 GList *list = NULL; | |
1 | 926 |
9 | 927 if (path_list(path, &list, NULL)) |
928 { | |
929 list = path_list_sort(list); | |
930 list = path_list_filter(list, FALSE); | |
931 } | |
932 real_view_window_new(NULL, list, NULL, NULL); | |
933 path_list_free(list); | |
934 } | |
935 else | |
936 { | |
937 real_view_window_new(path, NULL, NULL, NULL); | |
938 } | |
939 } | |
940 | |
941 void view_window_new_from_list(GList *list) | |
942 { | |
943 real_view_window_new(NULL, list, NULL, NULL); | |
944 } | |
945 | |
946 void view_window_new_from_collection(CollectionData *cd, CollectInfo *info) | |
947 { | |
948 real_view_window_new(NULL, NULL, cd, info); | |
949 } | |
950 | |
951 /* | |
952 *----------------------------------------------------------------------------- | |
953 * public | |
954 *----------------------------------------------------------------------------- | |
955 */ | |
956 | |
957 void view_window_colors_update(void) | |
958 { | |
959 GList *work; | |
1 | 960 |
9 | 961 work = view_window_list; |
962 while (work) | |
963 { | |
964 ViewWindow *vw = work->data; | |
965 work = work->next; | |
966 | |
967 image_background_set_black(vw->imd, black_window_background); | |
968 } | |
969 } | |
970 | |
971 gint view_window_find_image(ImageWindow *imd, gint *index, gint *total) | |
972 { | |
973 GList *work; | |
974 | |
975 work = view_window_list; | |
976 while (work) | |
977 { | |
978 ViewWindow *vw = work->data; | |
979 work = work->next; | |
980 | |
981 if (vw->imd == imd || | |
982 (vw->fs && vw->fs->imd == imd)) | |
983 { | |
984 if (vw->ss) | |
985 { | |
986 gint n; | |
987 n = g_list_length(vw->ss->list_done); | |
988 if (index) *index = n - 1; | |
989 if (total) *total = n + g_list_length(vw->ss->list); | |
990 } | |
991 else | |
992 { | |
993 if (index) *index = g_list_position(vw->list, vw->list_pointer); | |
994 if (total) *total = g_list_length(vw->list); | |
995 } | |
996 return TRUE; | |
997 } | |
998 } | |
999 | |
1000 return FALSE; | |
1 | 1001 } |
1002 | |
1003 /* | |
1004 *----------------------------------------------------------------------------- | |
1005 * view window menu routines and callbacks | |
1006 *----------------------------------------------------------------------------- | |
1007 */ | |
1008 | |
9 | 1009 static void view_new_window_cb(GtkWidget *widget, gpointer data) |
1 | 1010 { |
9 | 1011 ViewWindow *vw = data; |
1012 CollectionData *cd; | |
1013 CollectInfo *info; | |
1014 | |
1015 cd = image_get_collection(vw->imd, &info); | |
1016 | |
1017 if (cd && info) | |
1018 { | |
1019 view_window_new_from_collection(cd, info); | |
1020 } | |
1021 else | |
1022 { | |
1023 view_window_new(image_get_path(vw->imd)); | |
1024 } | |
1 | 1025 } |
1026 | |
9 | 1027 static void view_edit_cb(GtkWidget *widget, gpointer data) |
1 | 1028 { |
9 | 1029 ViewWindow *vw; |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
1030 ImageWindow *imd; |
9 | 1031 gint n; |
1032 | |
1033 vw = submenu_item_get_data(widget); | |
1034 n = GPOINTER_TO_INT(data); | |
1035 if (!vw) return; | |
1036 | |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
1037 if (!editor_window_flag_set(n)) |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
1038 { |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
1039 view_fullscreen_toggle(vw, TRUE); |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
1040 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
1041 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
1042 imd = view_window_active_image(vw); |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
1043 start_editor_from_file(n, image_get_path(imd)); |
1 | 1044 } |
1045 | |
9 | 1046 static void view_alter_cb(GtkWidget *widget, gpointer data) |
1047 { | |
1048 ViewWindow *vw; | |
1049 AlterType type; | |
1050 | |
1051 vw = submenu_item_get_data(widget); | |
1052 type = GPOINTER_TO_INT(data); | |
1053 | |
1054 if (!vw) return; | |
1055 image_alter(vw->imd, type); | |
1056 } | |
1057 | |
1058 static void view_info_cb(GtkWidget *widget, gpointer data) | |
3 | 1059 { |
9 | 1060 ViewWindow *vw = data; |
1061 ImageWindow *imd; | |
1062 | |
1063 imd = view_window_active_image(vw); | |
1064 info_window_new(image_get_path(imd), NULL); | |
1065 } | |
1066 | |
1067 static void view_wallpaper_cb(GtkWidget *widget, gpointer data) | |
1068 { | |
1069 ViewWindow *vw = data; | |
1070 ImageWindow *imd; | |
1071 | |
1072 imd = view_window_active_image(vw); | |
1073 image_to_root_window(imd, (image_zoom_get(imd) == 0.0)); | |
3 | 1074 } |
1075 | |
1 | 1076 static void view_zoom_in_cb(GtkWidget *widget, gpointer data) |
1077 { | |
9 | 1078 ViewWindow *vw = data; |
1079 | |
1080 image_zoom_adjust(view_window_active_image(vw), get_zoom_increment()); | |
1 | 1081 } |
1082 | |
1083 static void view_zoom_out_cb(GtkWidget *widget, gpointer data) | |
1084 { | |
9 | 1085 ViewWindow *vw = data; |
1086 | |
1087 image_zoom_adjust(view_window_active_image(vw), -get_zoom_increment()); | |
1 | 1088 } |
1089 | |
1090 static void view_zoom_1_1_cb(GtkWidget *widget, gpointer data) | |
1091 { | |
9 | 1092 ViewWindow *vw = data; |
1093 | |
1094 image_zoom_set(view_window_active_image(vw), 1.0); | |
1 | 1095 } |
1096 | |
1097 static void view_zoom_fit_cb(GtkWidget *widget, gpointer data) | |
1098 { | |
9 | 1099 ViewWindow *vw = data; |
1100 | |
1101 image_zoom_set(view_window_active_image(vw), 0.0); | |
1 | 1102 } |
1103 | |
1104 static void view_copy_cb(GtkWidget *widget, gpointer data) | |
1105 { | |
9 | 1106 ViewWindow *vw = data; |
1107 ImageWindow *imd; | |
1108 | |
1109 imd = view_window_active_image(vw); | |
1110 file_util_copy(image_get_path(imd), NULL, NULL, imd->widget); | |
1 | 1111 } |
1112 | |
1113 static void view_move_cb(GtkWidget *widget, gpointer data) | |
1114 { | |
9 | 1115 ViewWindow *vw = data; |
1116 ImageWindow *imd; | |
1117 | |
1118 imd = view_window_active_image(vw); | |
1119 file_util_move(image_get_path(imd), NULL, NULL, imd->widget); | |
1 | 1120 } |
1121 | |
1122 static void view_rename_cb(GtkWidget *widget, gpointer data) | |
1123 { | |
9 | 1124 ViewWindow *vw = data; |
1125 ImageWindow *imd; | |
1126 | |
1127 imd = view_window_active_image(vw); | |
1128 file_util_rename(image_get_path(imd), NULL, imd->widget); | |
1 | 1129 } |
1130 | |
1131 static void view_delete_cb(GtkWidget *widget, gpointer data) | |
1132 { | |
9 | 1133 ViewWindow *vw = data; |
1134 ImageWindow *imd; | |
1135 | |
1136 imd = view_window_active_image(vw); | |
1137 file_util_delete(image_get_path(imd), NULL, imd->widget); | |
1138 } | |
1139 | |
1140 static void view_fullscreen_cb(GtkWidget *widget, gpointer data) | |
1141 { | |
1142 ViewWindow *vw = data; | |
1143 | |
1144 view_fullscreen_toggle(vw, FALSE); | |
1145 } | |
1146 | |
1147 static void view_slideshow_start_cb(GtkWidget *widget, gpointer data) | |
1148 { | |
1149 ViewWindow *vw = data; | |
1150 | |
1151 view_slideshow_start(vw); | |
1152 } | |
1153 | |
1154 static void view_slideshow_stop_cb(GtkWidget *widget, gpointer data) | |
1155 { | |
1156 ViewWindow *vw = data; | |
1157 | |
1158 view_slideshow_stop(vw); | |
1159 } | |
1160 | |
1161 static void view_slideshow_pause_cb(GtkWidget *widget, gpointer data) | |
1162 { | |
1163 ViewWindow *vw = data; | |
1164 | |
1165 slideshow_pause_toggle(vw->ss); | |
1 | 1166 } |
1167 | |
1168 static void view_close_cb(GtkWidget *widget, gpointer data) | |
1169 { | |
9 | 1170 ViewWindow *vw = data; |
1171 | |
1172 view_window_close(vw); | |
1173 } | |
1174 | |
1175 static GtkWidget *view_popup_menu(ViewWindow *vw) | |
1176 { | |
1177 GtkWidget *menu; | |
1178 GtkWidget *item; | |
1179 | |
1180 menu = popup_menu_short_lived(); | |
1181 | |
1182 menu_item_add_stock(menu, _("Zoom _in"), GTK_STOCK_ZOOM_IN, G_CALLBACK(view_zoom_in_cb), vw); | |
1183 menu_item_add_stock(menu, _("Zoom _out"), GTK_STOCK_ZOOM_OUT, G_CALLBACK(view_zoom_out_cb), vw); | |
1184 menu_item_add_stock(menu, _("Zoom _1:1"), GTK_STOCK_ZOOM_100, G_CALLBACK(view_zoom_1_1_cb), vw); | |
1185 menu_item_add_stock(menu, _("Fit image to _window"), GTK_STOCK_ZOOM_FIT, G_CALLBACK(view_zoom_fit_cb), vw); | |
1186 menu_item_add_divider(menu); | |
1187 | |
1188 item = submenu_add_edit(menu, NULL, G_CALLBACK(view_edit_cb), vw); | |
1189 menu_item_add_divider(item); | |
1190 menu_item_add(item, _("Set as _wallpaper"), G_CALLBACK(view_wallpaper_cb), vw); | |
1191 | |
1192 submenu_add_alter(menu, G_CALLBACK(view_alter_cb), vw); | |
1193 | |
1194 menu_item_add_stock(menu, _("_Properties"), GTK_STOCK_PROPERTIES, G_CALLBACK(view_info_cb), vw); | |
1195 | |
1196 menu_item_add_stock(menu, _("View in _new window"), GTK_STOCK_NEW, G_CALLBACK(view_new_window_cb), vw); | |
1197 | |
1198 menu_item_add_divider(menu); | |
1199 menu_item_add_stock(menu, _("_Copy..."), GTK_STOCK_COPY, G_CALLBACK(view_copy_cb), vw); | |
1200 menu_item_add(menu, _("_Move..."), G_CALLBACK(view_move_cb), vw); | |
1201 menu_item_add(menu, _("_Rename..."), G_CALLBACK(view_rename_cb), vw); | |
1202 menu_item_add_stock(menu, _("_Delete..."), GTK_STOCK_DELETE, G_CALLBACK(view_delete_cb), vw); | |
1203 | |
1204 menu_item_add_divider(menu); | |
1205 | |
1206 if (vw->ss) | |
1207 { | |
1208 menu_item_add(menu, _("_Stop slideshow"), G_CALLBACK(view_slideshow_stop_cb), vw); | |
1209 if (slideshow_paused(vw->ss)) | |
1210 { | |
1211 item = menu_item_add(menu, _("Continue slides_how"), | |
1212 G_CALLBACK(view_slideshow_pause_cb), vw); | |
1213 } | |
1214 else | |
1215 { | |
1216 item = menu_item_add(menu, _("Pause slides_how"), | |
1217 G_CALLBACK(view_slideshow_pause_cb), vw); | |
1218 } | |
1219 } | |
1220 else | |
1221 { | |
1222 item = menu_item_add(menu, _("_Start slideshow"), G_CALLBACK(view_slideshow_start_cb), vw); | |
1223 gtk_widget_set_sensitive(item, (vw->list != NULL) || view_window_contains_collection(vw)); | |
1224 item = menu_item_add(menu, _("Pause slides_how"), G_CALLBACK(view_slideshow_pause_cb), vw); | |
1225 gtk_widget_set_sensitive(item, FALSE); | |
1226 } | |
1227 | |
1228 if (vw->fs) | |
1229 { | |
1230 menu_item_add(menu, _("Exit _full screen"), G_CALLBACK(view_fullscreen_cb), vw); | |
1231 } | |
1232 else | |
1233 { | |
1234 menu_item_add(menu, _("_Full screen"), G_CALLBACK(view_fullscreen_cb), vw); | |
1235 } | |
1236 | |
1237 menu_item_add_divider(menu); | |
1238 menu_item_add_stock(menu, _("C_lose window"), GTK_STOCK_CLOSE, G_CALLBACK(view_close_cb), vw); | |
1239 | |
1240 return menu; | |
1241 } | |
1242 | |
1243 /* | |
1244 *------------------------------------------------------------------- | |
1245 * dnd confirm dir | |
1246 *------------------------------------------------------------------- | |
1247 */ | |
1248 | |
1249 typedef struct { | |
1250 ViewWindow *vw; | |
1251 GList *list; | |
1252 } CViewConfirmD; | |
1253 | |
1254 static void view_dir_list_cancel(GtkWidget *widget, gpointer data) | |
1255 { | |
1256 /* do nothing */ | |
1257 } | |
1258 | |
1259 static void view_dir_list_do(ViewWindow *vw, GList *list, gint skip, gint recurse) | |
1260 { | |
1261 GList *work; | |
1262 | |
1263 view_window_set_list(vw, NULL); | |
1264 | |
1265 work = list; | |
1266 while (work) | |
1267 { | |
1268 gchar *path = work->data; | |
1269 work = work->next; | |
1270 | |
1271 if (isdir(path)) | |
1272 { | |
1273 if (!skip) | |
1274 { | |
1275 GList *list = NULL; | |
1276 | |
1277 if (recurse) | |
1278 { | |
1279 list = path_list_recursive(path); | |
1280 } | |
1281 else | |
1282 { | |
1283 path_list(path, &list, NULL); | |
1284 list = path_list_sort(list); | |
1285 list = path_list_filter(list, FALSE); | |
1286 } | |
1287 if (list) vw->list = g_list_concat(vw->list, list); | |
1288 } | |
1289 } | |
1290 else | |
1291 { | |
1292 /* FIXME: no filtering here */ | |
1293 vw->list = g_list_append(vw->list, g_strdup(path)); | |
1294 } | |
1295 } | |
1296 | |
1297 if (vw->list) | |
1298 { | |
1299 gchar *path; | |
1300 | |
1301 vw->list_pointer = vw->list; | |
1302 path = vw->list->data; | |
1303 image_change_path(vw->imd, path, image_zoom_get_default(vw->imd, zoom_mode)); | |
1304 | |
1305 work = vw->list->next; | |
1306 if (enable_read_ahead && work) | |
1307 { | |
1308 path = work->data; | |
1309 image_prebuffer_set(vw->imd, path); | |
1310 } | |
1311 } | |
1312 else | |
1313 { | |
1314 image_change_path(vw->imd, NULL, image_zoom_get_default(vw->imd, zoom_mode)); | |
1315 } | |
1316 } | |
1317 | |
1318 static void view_dir_list_add(GtkWidget *widget, gpointer data) | |
1319 { | |
1320 CViewConfirmD *d = data; | |
1321 view_dir_list_do(d->vw, d->list, FALSE, FALSE); | |
1322 } | |
1323 | |
1324 static void view_dir_list_recurse(GtkWidget *widget, gpointer data) | |
1325 { | |
1326 CViewConfirmD *d = data; | |
1327 view_dir_list_do(d->vw, d->list, FALSE, TRUE); | |
1328 } | |
1329 | |
1330 static void view_dir_list_skip(GtkWidget *widget, gpointer data) | |
1331 { | |
1332 CViewConfirmD *d = data; | |
1333 view_dir_list_do(d->vw, d->list, TRUE, FALSE); | |
1334 } | |
1335 | |
1336 static void view_dir_list_destroy(GtkWidget *widget, gpointer data) | |
1337 { | |
1338 CViewConfirmD *d = data; | |
1339 path_list_free(d->list); | |
1340 g_free(d); | |
1341 } | |
1342 | |
1343 static GtkWidget *view_confirm_dir_list(ViewWindow *vw, GList *list) | |
1344 { | |
1345 GtkWidget *menu; | |
1346 CViewConfirmD *d; | |
1347 | |
1348 d = g_new(CViewConfirmD, 1); | |
1349 d->vw = vw; | |
1350 d->list = list; | |
1351 | |
1352 menu = popup_menu_short_lived(); | |
1353 g_signal_connect(G_OBJECT(menu), "destroy", | |
1354 G_CALLBACK(view_dir_list_destroy), d); | |
1355 | |
1356 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL); | |
1357 menu_item_add_divider(menu); | |
1358 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK, G_CALLBACK(view_dir_list_add), d); | |
1359 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD, G_CALLBACK(view_dir_list_recurse), d); | |
1360 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE, G_CALLBACK(view_dir_list_skip), d); | |
1361 menu_item_add_divider(menu); | |
1362 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, G_CALLBACK(view_dir_list_cancel), d); | |
1363 | |
1364 return menu; | |
1 | 1365 } |
1366 | |
9 | 1367 /* |
1368 *----------------------------------------------------------------------------- | |
1369 * image drag and drop routines | |
1370 *----------------------------------------------------------------------------- | |
1371 */ | |
1372 | |
1373 static void view_window_get_dnd_data(GtkWidget *widget, GdkDragContext *context, | |
1374 gint x, gint y, | |
1375 GtkSelectionData *selection_data, guint info, | |
1376 guint time, gpointer data) | |
1 | 1377 { |
9 | 1378 ViewWindow *vw = data; |
1379 ImageWindow *imd; | |
1380 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1381 if (gtk_drag_get_source_widget(context) == vw->imd->pr) return; |
9 | 1382 |
1383 imd = vw->imd; | |
1384 | |
1385 if (info == TARGET_URI_LIST || info == TARGET_APP_COLLECTION_MEMBER) | |
1386 { | |
1387 CollectionData *source; | |
1388 GList *list; | |
1389 GList *info_list; | |
1390 | |
1391 if (info == TARGET_URI_LIST) | |
1392 { | |
1393 GList *work; | |
1394 | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
1395 list = uri_list_from_text((gchar *)selection_data->data, TRUE); |
9 | 1396 |
1397 work = list; | |
1398 while (work) | |
1399 { | |
1400 if (isdir((gchar *)work->data)) | |
1401 { | |
1402 GtkWidget *menu; | |
1403 menu = view_confirm_dir_list(vw, list); | |
1404 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time); | |
1405 return; | |
1406 } | |
1407 work = work->next; | |
1408 } | |
1409 | |
1410 list = path_list_filter(list, FALSE); | |
1411 | |
1412 source = NULL; | |
1413 info_list = NULL; | |
1414 } | |
1415 else | |
1416 { | |
1417 source = collection_from_dnd_data((gchar *)selection_data->data, &list, &info_list); | |
1418 } | |
1419 | |
1420 if (list) | |
1421 { | |
1422 gchar *path; | |
1423 | |
1424 path = list->data; | |
1425 if (isfile(path)) | |
1426 { | |
1427 view_slideshow_stop(vw); | |
1428 view_window_set_list(vw, NULL); | |
1 | 1429 |
9 | 1430 if (source && info_list) |
1431 { | |
1432 image_change_from_collection(imd, source, info_list->data, image_zoom_get_default(imd, zoom_mode)); | |
1433 } | |
1434 else | |
1435 { | |
1436 if (list->next) | |
1437 { | |
1438 vw->list = list; | |
1439 list = NULL; | |
1440 | |
1441 vw->list_pointer = vw->list; | |
1442 } | |
1443 image_change_path(imd, path, image_zoom_get_default(imd, zoom_mode)); | |
1444 } | |
1445 } | |
1446 } | |
1447 path_list_free(list); | |
1448 g_list_free(info_list); | |
1449 } | |
1450 } | |
1451 | |
1452 static void view_window_set_dnd_data(GtkWidget *widget, GdkDragContext *context, | |
1453 GtkSelectionData *selection_data, guint info, | |
1454 guint time, gpointer data) | |
1455 { | |
1456 ViewWindow *vw = data; | |
1457 const gchar *path; | |
1458 | |
1459 path = image_get_path(vw->imd); | |
1 | 1460 |
9 | 1461 if (path) |
1462 { | |
1463 gchar *text = NULL; | |
1464 gint len; | |
1465 gint plain_text; | |
1466 GList *list; | |
1 | 1467 |
9 | 1468 switch (info) |
1469 { | |
1470 case TARGET_URI_LIST: | |
1471 plain_text = FALSE; | |
1472 break; | |
1473 case TARGET_TEXT_PLAIN: | |
1474 default: | |
1475 plain_text = TRUE; | |
1476 break; | |
1477 } | |
1478 list = g_list_append(NULL, (gchar *)path); | |
1479 text = uri_text_from_list(list, &len, plain_text); | |
1480 g_list_free(list); | |
1481 if (text) | |
1482 { | |
1483 gtk_selection_data_set (selection_data, selection_data->target, | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
60
diff
changeset
|
1484 8, (guchar *)text, len); |
9 | 1485 g_free(text); |
1486 } | |
1487 } | |
1488 else | |
1489 { | |
1490 gtk_selection_data_set (selection_data, selection_data->target, | |
1491 8, NULL, 0); | |
1492 } | |
1 | 1493 } |
1494 | |
9 | 1495 static void view_window_dnd_init(ViewWindow *vw) |
1496 { | |
1497 ImageWindow *imd; | |
1 | 1498 |
9 | 1499 imd = vw->imd; |
1500 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1501 gtk_drag_source_set(imd->pr, GDK_BUTTON2_MASK, |
9 | 1502 dnd_file_drag_types, dnd_file_drag_types_count, |
1503 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1504 g_signal_connect(G_OBJECT(imd->pr), "drag_data_get", |
9 | 1505 G_CALLBACK(view_window_set_dnd_data), vw); |
1506 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1507 gtk_drag_dest_set(imd->pr, |
9 | 1508 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, |
1509 dnd_file_drop_types, dnd_file_drop_types_count, | |
1510 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1511 g_signal_connect(G_OBJECT(imd->pr), "drag_data_received", |
9 | 1512 G_CALLBACK(view_window_get_dnd_data), vw); |
1513 } | |
1514 | |
1515 /* | |
1516 *----------------------------------------------------------------------------- | |
1517 * maintenance (for rename, move, remove) | |
1518 *----------------------------------------------------------------------------- | |
1519 */ | |
1520 | |
1521 static void view_real_removed(ViewWindow *vw, const gchar *path, GList *ignore_list) | |
1522 { | |
1523 ImageWindow *imd; | |
1524 const gchar *image_path; | |
1525 | |
1526 imd = view_window_active_image(vw); | |
1527 image_path = image_get_path(imd); | |
1528 | |
1529 if (image_path && strcmp(image_path, path) == 0) | |
1530 { | |
1531 if (vw->list) | |
1532 { | |
1533 view_list_step(vw, TRUE); | |
1534 if (image_get_path(imd) == image_path) | |
1535 { | |
1536 view_list_step(vw, FALSE); | |
1537 } | |
1538 } | |
1539 else if (view_window_contains_collection(vw)) | |
1540 { | |
1541 view_collection_step(vw, TRUE); | |
1542 if (image_get_path(imd) == image_path) | |
1543 { | |
1544 view_collection_step(vw, FALSE); | |
1545 } | |
1546 } | |
1547 if (image_get_path(imd) == image_path) | |
1548 { | |
1549 image_change_path(imd, NULL, image_zoom_get_default(imd, zoom_mode)); | |
1550 } | |
1551 } | |
1552 | |
1553 if (vw->list) | |
1554 { | |
1555 GList *work; | |
1556 GList *old; | |
1557 | |
1558 old = vw->list_pointer; | |
1559 | |
1560 work = vw->list; | |
1561 while (work) | |
1562 { | |
1563 gchar *chk_path; | |
1564 GList *chk_link; | |
1565 | |
1566 chk_path = work->data; | |
1567 chk_link = work; | |
1568 work = work->next; | |
1569 | |
1570 if (strcmp(chk_path, path) == 0) | |
1571 { | |
1572 if (vw->list_pointer == chk_link) | |
1573 { | |
1574 vw->list_pointer = (chk_link->next) ? chk_link->next : chk_link->prev; | |
1575 } | |
1576 vw->list = g_list_remove(vw->list, chk_path); | |
1577 g_free(chk_path); | |
1578 } | |
1579 } | |
1580 | |
1581 /* handles stepping correctly when same image is in the list more than once */ | |
1582 if (old && old != vw->list_pointer) | |
1583 { | |
1584 gchar *path; | |
1585 | |
1586 if (vw->list_pointer) | |
1587 { | |
1588 path = vw->list_pointer->data; | |
1589 } | |
1590 else | |
1591 { | |
1592 path = NULL; | |
1593 } | |
1594 | |
1595 image_change_path(imd, path, image_zoom_get_default(imd, zoom_mode)); | |
1596 } | |
1597 } | |
1598 | |
1599 if (vw->overlay_id != -1) image_overlay_update(imd, vw->overlay_id); | |
1600 } | |
1601 | |
1602 static void view_real_moved(ViewWindow *vw, const gchar *source, const gchar *dest) | |
1603 { | |
1604 ImageWindow *imd; | |
1605 const gchar *image_path; | |
1606 | |
1607 imd = view_window_active_image(vw); | |
1608 image_path = image_get_path(imd); | |
1609 | |
1610 if (image_path && strcmp(image_path, source) == 0) | |
1611 { | |
1612 image_set_path(imd, dest); | |
1613 } | |
1614 | |
1615 if (vw->list) | |
1616 { | |
1617 GList *work; | |
1618 work = vw->list; | |
1619 while (work) | |
1620 { | |
1621 gchar *chk_path; | |
1622 | |
1623 chk_path = work->data; | |
1624 | |
1625 if (strcmp(chk_path, source) == 0) | |
1626 { | |
1627 work->data = g_strdup(dest); | |
1628 g_free(chk_path); | |
1629 } | |
1630 | |
1631 work = work->next; | |
1632 } | |
1633 } | |
1634 } | |
1635 | |
1636 void view_window_maint_removed(const gchar *path, GList *ignore_list) | |
1637 { | |
1638 GList *work = view_window_list; | |
1639 while (work) | |
1640 { | |
1641 ViewWindow *vw = work->data; | |
1642 work = work->next; | |
1643 | |
1644 view_real_removed(vw, path, ignore_list); | |
1645 } | |
1646 } | |
1647 | |
1648 void view_window_maint_moved(const gchar *source, const gchar *dest) | |
1649 { | |
1650 GList *work = view_window_list; | |
1651 while (work) | |
1652 { | |
1653 ViewWindow *vw = work->data; | |
1654 work = work->next; | |
1655 | |
1656 view_real_moved(vw, source, dest); | |
1657 } | |
1658 } | |
1659 |