1 /*
2 * Copyright (C) 2005 Sasha Vasko <sasha at aftercode.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 */
19
20 #define LOCAL_DEBUG
21 #include "../configure.h"
22
23 #include "../libAfterStep/asapp.h"
24 #include "../libAfterStep/screen.h"
25 #include "../libAfterImage/afterimage.h"
26
27
28 #include "asgtk.h"
29 #include "asgtkai.h"
30 #include "asgtkimageview.h"
31
32 #define NO_IMAGE_TEXT "No image to display"
33
34
35 /* local function prototypes */
36 static void asgtk_image_view_class_init (ASGtkImageViewClass * klass);
37 static void asgtk_image_view_init (ASGtkImageView * iv);
38 static void asgtk_image_view_dispose (GObject * object);
39 static void asgtk_image_view_finalize (GObject * object);
40 static void asgtk_image_view_style_set (GtkWidget * widget,
41 GtkStyle * prev_style);
42
43 /* private variables */
44 static GtkFrameClass *parent_class = NULL;
45
asgtk_image_view_get_type(void)46 GType asgtk_image_view_get_type (void)
47 {
48 static GType iv_type = 0;
49
50 if (!iv_type) {
51 static const GTypeInfo iv_info = {
52 sizeof (ASGtkImageViewClass),
53 (GBaseInitFunc) NULL,
54 (GBaseFinalizeFunc) NULL,
55 (GClassInitFunc) asgtk_image_view_class_init,
56 NULL, /* class_finalize */
57 NULL, /* class_data */
58 sizeof (ASGtkImageView),
59 0, /* n_preallocs */
60 (GInstanceInitFunc) asgtk_image_view_init,
61 };
62
63 iv_type =
64 g_type_register_static (GTK_TYPE_FRAME, "ASGtkImageView", &iv_info,
65 0);
66 }
67
68 return iv_type;
69 }
70
asgtk_image_view_class_init(ASGtkImageViewClass * klass)71 static void asgtk_image_view_class_init (ASGtkImageViewClass * klass)
72 {
73 GObjectClass *object_class = G_OBJECT_CLASS (klass);
74 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
75
76 parent_class = g_type_class_peek_parent (klass);
77
78 object_class->dispose = asgtk_image_view_dispose;
79 object_class->finalize = asgtk_image_view_finalize;
80
81 widget_class->style_set = asgtk_image_view_style_set;
82 }
83
asgtk_image_view_init(ASGtkImageView * iv)84 static void asgtk_image_view_init (ASGtkImageView * iv)
85 {
86 iv->image_entry = NULL;
87 iv->aspect_x = -1;
88 iv->aspect_y = -1;
89 iv->view_width = -1;
90 iv->view_height = -1;
91 gtk_frame_set_shadow_type (GTK_FRAME (iv), GTK_SHADOW_NONE);
92 }
93
asgtk_image_view_dispose(GObject * object)94 static void asgtk_image_view_dispose (GObject * object)
95 {
96 ASGtkImageView *iv = ASGTK_IMAGE_VIEW (object);
97
98 unref_asimage_list_entry (iv->image_entry);
99 iv->image_entry = NULL;
100 G_OBJECT_CLASS (parent_class)->dispose (object);
101 }
102
asgtk_image_view_finalize(GObject * object)103 static void asgtk_image_view_finalize (GObject * object)
104 {
105 G_OBJECT_CLASS (parent_class)->finalize (object);
106 }
107
108 static void
asgtk_image_view_style_set(GtkWidget * widget,GtkStyle * prev_style)109 asgtk_image_view_style_set (GtkWidget * widget, GtkStyle * prev_style)
110 {
111 ASGtkImageView *iv = ASGTK_IMAGE_VIEW (widget);
112
113 GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
114
115 gtk_widget_modify_bg (iv->view, GTK_STATE_NORMAL,
116 &widget->style->base[GTK_STATE_NORMAL]);
117 gtk_widget_modify_bg (iv->view, GTK_STATE_INSENSITIVE,
118 &widget->style->base[GTK_STATE_NORMAL]);
119 }
120
display_image_view(ASGtkImageView * iv)121 static void display_image_view (ASGtkImageView * iv)
122 {
123 ASImage *im = iv->image_entry ? iv->image_entry->preview : NULL;
124 GdkPixbuf *pb = NULL;
125 ASImage *scaled = NULL, *tiled = NULL;
126 int scaled_w, scaled_h;
127 int tiled_h, tiled_w;
128 ASVisual *asv = get_screen_visual (NULL);
129 int view_w, view_h;
130
131 if (im == NULL) {
132 gtk_image_set_from_stock (GTK_IMAGE (iv->view),
133 GTK_STOCK_MISSING_IMAGE,
134 GTK_ICON_SIZE_BUTTON);
135 return;
136 }
137 #if 1
138 view_w = iv->view_width;
139 view_h = iv->view_height;
140 if (view_w <= 0 || view_h <= 0)
141 return;
142
143 scaled_w = im->width;
144 scaled_h = im->height;
145
146 if (get_flags (iv->flags, ASGTK_IMAGE_VIEW_SCALE_TO_VIEW)) {
147 if (get_flags (iv->flags, ASGTK_IMAGE_VIEW_TILE_TO_ASPECT)
148 && iv->aspect_x > 0 && iv->aspect_y > 0) {
149 scaled_w = (im->width * view_w) / iv->aspect_x;
150 scaled_h = (im->height * view_h) / iv->aspect_y;
151 } else {
152 scaled_w = view_w;
153 scaled_h = view_h;
154 }
155 } else if (get_flags (iv->flags, ASGTK_IMAGE_VIEW_SCALE_TO_ASPECT)
156 && iv->aspect_x > 0 && iv->aspect_y > 0) {
157 scaled_w = iv->aspect_x;
158 scaled_h = iv->aspect_y;
159 }
160
161 tiled_w = scaled_w;
162 tiled_h = scaled_h;
163
164 if (get_flags (iv->flags, ASGTK_IMAGE_VIEW_TILE_TO_ASPECT)
165 && iv->aspect_x > 0 && iv->aspect_y > 0) {
166 if (get_flags (iv->flags, ASGTK_IMAGE_VIEW_SCALE_TO_VIEW)) {
167 if (tiled_w < view_w)
168 tiled_w = view_w;
169 if (tiled_h < view_h)
170 tiled_h = view_h;
171 } else {
172 if (tiled_w < iv->aspect_x)
173 tiled_w = iv->aspect_x;
174 if (tiled_h < iv->aspect_y)
175 tiled_h = iv->aspect_y;
176 }
177 }
178 if (get_flags (iv->flags, ASGTK_IMAGE_VIEW_TILE_TO_VIEW)) {
179 if (tiled_w < view_w)
180 tiled_w = view_w;
181 if (tiled_h < view_h)
182 tiled_h = view_h;
183 }
184
185
186 LOCAL_DEBUG_OUT ("scaled size is %dx%d, tiled size %dx%d", scaled_w,
187 scaled_h, tiled_w, tiled_h);
188 if (scaled_w != im->width || scaled_h != im->height) {
189 scaled =
190 scale_asimage (asv, im, scaled_w, scaled_h, ASA_ASImage, 0,
191 ASIMAGE_QUALITY_DEFAULT);
192 if (scaled)
193 im = scaled;
194 }
195
196 if (tiled_w != im->width || tiled_h != im->height) {
197 tiled = tile_asimage (asv, im, 0, 0, tiled_w, tiled_h,
198 TINT_LEAVE_SAME, ASA_ASImage, 0,
199 ASIMAGE_QUALITY_DEFAULT);
200 if (tiled)
201 im = tiled;
202 }
203
204 pb = ASImage2GdkPixbuf (im);
205 if (tiled)
206 destroy_asimage (&tiled);
207 if (scaled)
208 destroy_asimage (&scaled);
209 if (pb) {
210 gtk_image_set_from_pixbuf (GTK_IMAGE (iv->view), pb);
211 g_object_unref (pb);
212 }
213 LOCAL_DEBUG_OUT ("####!!! recquisition is %dx%d",
214 GTK_WIDGET (iv->view)->requisition.width,
215 GTK_WIDGET (iv->view)->requisition.height);
216 #endif
217 }
218
219
220
221 static void
asgtk_imview_view_size_alloc(GtkWidget * widget,GtkAllocation * allocation,gpointer user_data)222 asgtk_imview_view_size_alloc (GtkWidget * widget,
223 GtkAllocation * allocation,
224 gpointer user_data)
225 {
226 ASGtkImageView *iv = ASGTK_IMAGE_VIEW (user_data);
227 int view_w, view_h;
228 int w = allocation->width - 4;
229 int h = allocation->height - 4;
230
231 view_w = GTK_WIDGET (iv->view)->requisition.width;
232 view_h = GTK_WIDGET (iv->view)->requisition.height;
233
234 LOCAL_DEBUG_OUT ("####!!! SizeAlloc for %p is %dx%d%+d%+d", widget,
235 allocation->width, allocation->height, allocation->x,
236 allocation->y);
237 LOCAL_DEBUG_OUT ("####!!! recquisition was %dx%d",
238 widget->requisition.width, widget->requisition.height);
239 LOCAL_DEBUG_OUT ("####!!! view size is %dx%d", iv->view_width,
240 iv->view_height);
241
242 #if 1 /* if size changed - refresh */
243 if (iv->view_width != w || iv->view_height != h) {
244 iv->view_width = w;
245 iv->view_height = h;
246 display_image_view (iv);
247 }
248 #endif
249 }
250
get_old_ratio(ASGtkImageView * iv)251 static gfloat get_old_ratio (ASGtkImageView * iv)
252 {
253 gfloat old_ratio;
254
255 g_object_get (G_OBJECT (iv->frame), "ratio", &old_ratio, NULL);
256 return old_ratio;
257 }
258
259
set_aspect_ratio_from_image(ASGtkImageView * iv)260 static Bool set_aspect_ratio_from_image (ASGtkImageView * iv)
261 {
262 gfloat old_ratio, new_ratio;
263
264 if (iv->image_entry && iv->image_entry->preview)
265 new_ratio =
266 (gfloat) iv->image_entry->preview->width /
267 (gfloat) iv->image_entry->preview->height;
268 else
269 new_ratio = 1.0;
270 old_ratio = get_old_ratio (iv);
271 if (old_ratio == new_ratio)
272 return False;
273
274 gtk_aspect_frame_set (GTK_ASPECT_FRAME (iv->frame), 0.5, 0.5, new_ratio,
275 FALSE);
276 return True;
277 }
278
setup_asgtk_image_view_layout_vert(ASGtkImageView * iv)279 static void setup_asgtk_image_view_layout_vert (ASGtkImageView * iv)
280 {
281 GtkWidget *main_vbox;
282
283 /***************************************/
284 /* Layout code : */
285 main_vbox = gtk_vbox_new (FALSE, 0);
286 gtk_widget_show (main_vbox);
287 gtk_container_add (GTK_CONTAINER (iv), main_vbox);
288
289 gtk_box_pack_start (GTK_BOX (main_vbox), iv->frame, TRUE, TRUE, 0);
290
291 gtk_box_pack_end (GTK_BOX (main_vbox), iv->tools_hbox, FALSE, FALSE, 0);
292 gtk_box_pack_end (GTK_BOX (main_vbox), iv->details_frame, FALSE, FALSE,
293 5);
294
295 }
296
setup_asgtk_image_view_layout_hor(ASGtkImageView * iv)297 static void setup_asgtk_image_view_layout_hor (ASGtkImageView * iv)
298 {
299 GtkWidget *main_hbox, *buttons_vbox, *buttons_frame;
300
301 /***************************************/
302 /* Layout code : */
303 main_hbox = gtk_hbox_new (FALSE, 0);
304 gtk_widget_show (main_hbox);
305 gtk_container_add (GTK_CONTAINER (iv), main_hbox);
306
307 gtk_box_pack_start (GTK_BOX (main_hbox), iv->frame, TRUE, TRUE, 0);
308
309 buttons_vbox = gtk_vbox_new (FALSE, 0);
310 gtk_widget_show (buttons_vbox);
311 gtk_box_pack_end (GTK_BOX (main_hbox), buttons_vbox, FALSE, FALSE, 0);
312
313 buttons_frame = gtk_frame_new (NULL);
314 gtk_widget_show (buttons_frame);
315 gtk_container_set_border_width (GTK_CONTAINER (buttons_frame), 0);
316 gtk_frame_set_shadow_type (GTK_FRAME (buttons_frame), GTK_SHADOW_NONE);
317 colorize_gtk_widget (buttons_frame, get_colorschemed_style_normal ());
318 gtk_container_add (GTK_CONTAINER (buttons_frame), iv->tools_hbox);
319
320 gtk_box_pack_start (GTK_BOX (buttons_vbox), iv->details_frame, FALSE,
321 FALSE, 5);
322 gtk_box_pack_end (GTK_BOX (buttons_vbox), buttons_frame, TRUE, TRUE, 0);
323 }
324
325 static void
asgtk_image_view_make_parts(ASGtkImageView * iv,Bool horizontal)326 asgtk_image_view_make_parts (ASGtkImageView * iv, Bool horizontal)
327 {
328 iv->frame = gtk_aspect_frame_new (NULL, 0.5, 0.5, 1.0, TRUE);
329 gtk_frame_set_shadow_type (GTK_FRAME (iv->frame), GTK_SHADOW_NONE);
330 gtk_widget_show (iv->frame);
331 colorize_gtk_widget (iv->frame, get_colorschemed_style_normal ());
332
333 iv->scrolled_window =
334 ASGTK_SCROLLED_WINDOW (GTK_POLICY_NEVER, GTK_POLICY_NEVER,
335 GTK_SHADOW_NONE);
336 ASGTK_CONTAINER_ADD (iv->frame, iv->scrolled_window);
337
338 if (!get_flags
339 (iv->flags,
340 ASGTK_IMAGE_VIEW_SCALE_TO_VIEW | ASGTK_IMAGE_VIEW_TILE_TO_VIEW)) {
341 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW
342 (iv->scrolled_window),
343 GTK_POLICY_AUTOMATIC,
344 GTK_POLICY_AUTOMATIC);
345 }
346 colorize_gtk_widget (GTK_WIDGET (iv->scrolled_window),
347 get_colorschemed_style_normal ());
348
349 iv->view = gtk_image_new_from_pixbuf (NULL);
350 gtk_widget_show (GTK_WIDGET (iv->view));
351 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW
352 (iv->scrolled_window),
353 GTK_WIDGET (iv->view));
354 colorize_gtk_widget (GTK_WIDGET (iv->view),
355 get_colorschemed_style_normal ());
356
357 g_signal_connect ((gpointer) iv->scrolled_window, "size-allocate",
358 G_CALLBACK (asgtk_imview_view_size_alloc), iv);
359 iv->details_label = gtk_label_new (NO_IMAGE_TEXT);
360 gtk_widget_show (iv->details_label);
361
362 iv->details_frame = gtk_frame_new (NULL);
363 gtk_widget_show (iv->details_frame);
364 gtk_container_set_border_width (GTK_CONTAINER (iv->details_frame), 1);
365 gtk_frame_set_shadow_type (GTK_FRAME (iv->details_frame), GTK_SHADOW_IN);
366 colorize_gtk_widget (iv->details_frame,
367 get_colorschemed_style_normal ());
368
369 iv->tools_hbox =
370 horizontal ? gtk_vbox_new (FALSE, 0) : gtk_hbutton_box_new ();
371 gtk_container_set_border_width (GTK_CONTAINER (iv->tools_hbox), 0);
372 if (GTK_IS_BUTTON_BOX (iv->tools_hbox))
373 gtk_button_box_set_layout (GTK_BUTTON_BOX (iv->tools_hbox),
374 GTK_BUTTONBOX_END /*SPREAD*/);
375 gtk_widget_show (iv->tools_hbox);
376
377 iv->details_hbox =
378 horizontal ? gtk_vbutton_box_new () : gtk_hbutton_box_new ();
379 gtk_container_set_border_width (GTK_CONTAINER (iv->details_hbox), 0);
380 gtk_button_box_set_layout (GTK_BUTTON_BOX (iv->details_hbox),
381 GTK_BUTTONBOX_EDGE);
382 gtk_widget_show (iv->details_hbox);
383
384 gtk_container_add (GTK_CONTAINER (iv->details_frame), iv->details_hbox);
385 gtk_box_pack_end (GTK_BOX (iv->details_hbox), iv->details_label, TRUE,
386 TRUE, 0);
387
388 }
389
390 /* public functions */
391
asgtk_image_view_new()392 GtkWidget *asgtk_image_view_new ()
393 {
394 ASGtkImageView *iv;
395
396 iv = g_object_new (ASGTK_TYPE_IMAGE_VIEW, NULL);
397
398 asgtk_image_view_make_parts (iv, False);
399 setup_asgtk_image_view_layout_vert (iv);
400
401 LOCAL_DEBUG_OUT ("created image ASGtk view object %p", iv);
402 return GTK_WIDGET (iv);
403 }
404
asgtk_image_view_new_horizontal()405 GtkWidget *asgtk_image_view_new_horizontal ()
406 {
407 ASGtkImageView *iv;
408
409 iv = g_object_new (ASGTK_TYPE_IMAGE_VIEW, NULL);
410
411 asgtk_image_view_make_parts (iv, True);
412 setup_asgtk_image_view_layout_hor (iv);
413
414 LOCAL_DEBUG_OUT ("created image ASGtk view object %p", iv);
415 return GTK_WIDGET (iv);
416 }
417
418 void
asgtk_image_view_set_entry(ASGtkImageView * iv,ASImageListEntry * image_entry)419 asgtk_image_view_set_entry (ASGtkImageView * iv,
420 ASImageListEntry * image_entry)
421 {
422 g_return_if_fail (ASGTK_IS_IMAGE_VIEW (iv));
423
424 LOCAL_DEBUG_OUT (" ASGtk image view object's %p entry to %p", iv,
425 image_entry);
426 unref_asimage_list_entry (iv->image_entry);
427 iv->image_entry = ref_asimage_list_entry (image_entry);
428
429 if (iv->image_entry) {
430 #if 1
431 asgtk_image_view_refresh (iv, (iv->image_entry->preview == NULL));
432
433 #endif
434 } else {
435 gtk_label_set_text (GTK_LABEL (iv->details_label), NO_IMAGE_TEXT);
436 gtk_image_set_from_stock (GTK_IMAGE (iv->view),
437 GTK_STOCK_MISSING_IMAGE,
438 GTK_ICON_SIZE_BUTTON);
439 }
440
441 }
442
asgtk_image_view_get_entry(ASGtkImageView * iv)443 ASImageListEntry *asgtk_image_view_get_entry (ASGtkImageView * iv)
444 {
445 if (ASGTK_IS_IMAGE_VIEW (iv))
446 return ref_asimage_list_entry (iv->image_entry);
447 return NULL;
448 }
449
450 void
asgtk_image_view_set_aspect(ASGtkImageView * iv,int aspect_x,int aspect_y)451 asgtk_image_view_set_aspect (ASGtkImageView * iv, int aspect_x,
452 int aspect_y)
453 {
454 Bool changed = False;
455
456 g_return_if_fail (ASGTK_IS_IMAGE_VIEW (iv));
457
458 if (aspect_x <= 0 || aspect_y <= 0) {
459 iv->aspect_x = iv->aspect_y = -1;
460 changed = set_aspect_ratio_from_image (iv);
461 } else {
462 gfloat old_ratio, new_ratio;
463
464 iv->aspect_x = aspect_x;
465 iv->aspect_y = aspect_y;
466 new_ratio = (gfloat) aspect_x / (gfloat) aspect_y;
467 old_ratio = get_old_ratio (iv);
468 if (old_ratio != new_ratio) {
469 changed = True;
470 gtk_aspect_frame_set (GTK_ASPECT_FRAME (iv->frame), 0.5, 0.5,
471 new_ratio, FALSE);
472 }
473 }
474 if (!changed)
475 display_image_view (iv);
476 else
477 gtk_image_set_from_pixbuf (GTK_IMAGE (iv->view), NULL);
478 }
479
480 void
asgtk_image_view_set_resize(ASGtkImageView * iv,unsigned long resize_flags,unsigned long set_mask)481 asgtk_image_view_set_resize (ASGtkImageView * iv,
482 unsigned long resize_flags,
483 unsigned long set_mask)
484 {
485 unsigned long new_flags;
486
487 g_return_if_fail (ASGTK_IS_IMAGE_VIEW (iv));
488
489 new_flags = (iv->flags & (~set_mask)) | (resize_flags & set_mask);
490 if (new_flags == iv->flags)
491 return;
492
493 iv->flags = new_flags;
494 if (get_flags
495 (new_flags,
496 ASGTK_IMAGE_VIEW_SCALE_TO_VIEW | ASGTK_IMAGE_VIEW_TILE_TO_VIEW)) {
497 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW
498 (iv->scrolled_window),
499 GTK_POLICY_NEVER, GTK_POLICY_NEVER);
500 } else {
501 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW
502 (iv->scrolled_window),
503 GTK_POLICY_AUTOMATIC,
504 GTK_POLICY_AUTOMATIC);
505 }
506 if (iv->image_entry) {
507 display_image_view (iv);
508 }
509 }
510
511 void
asgtk_image_view_add_detail(ASGtkImageView * iv,GtkWidget * detail,int spacing)512 asgtk_image_view_add_detail (ASGtkImageView * iv, GtkWidget * detail,
513 int spacing)
514 {
515 g_return_if_fail (ASGTK_IS_IMAGE_VIEW (iv));
516 if (detail) {
517 gtk_box_pack_start (GTK_BOX (iv->details_hbox), detail, FALSE, FALSE,
518 spacing);
519 gtk_box_reorder_child (GTK_BOX (iv->details_hbox), iv->details_label,
520 -1);
521 }
522
523 }
524
525 void
asgtk_image_view_add_tool(ASGtkImageView * iv,GtkWidget * tool,int spacing)526 asgtk_image_view_add_tool (ASGtkImageView * iv, GtkWidget * tool,
527 int spacing)
528 {
529 g_return_if_fail (ASGTK_IS_IMAGE_VIEW (iv));
530 if (tool) {
531 if (GTK_IS_VBOX (iv->tools_hbox)) {
532 //gtk_widget_set_size_request( tool, iv->details_label->requisition.width, -1 );
533 gtk_box_pack_end (GTK_BOX (iv->tools_hbox), tool, FALSE, FALSE,
534 spacing);
535 } else
536 gtk_box_pack_start (GTK_BOX (iv->tools_hbox), tool, TRUE, TRUE,
537 spacing);
538 gtk_container_set_border_width (GTK_CONTAINER (iv->tools_hbox), 1);
539 }
540 }
541
asgtk_image_view_refresh(ASGtkImageView * iv,Bool reload_file)542 void asgtk_image_view_refresh (ASGtkImageView * iv, Bool reload_file)
543 {
544 g_return_if_fail (ASGTK_IS_IMAGE_VIEW (iv));
545 if (iv->image_entry) {
546
547 if (reload_file && iv->image_entry->type <= ASIT_Supported) {
548 if (iv->image_entry->preview) {
549 safe_asimage_destroy (iv->image_entry->preview);
550 iv->image_entry->preview = NULL;
551 }
552 /* show empty screen while loading background for now : */
553 display_image_view (iv);
554
555 LOCAL_DEBUG_OUT ("imman = %p, fullname = \"%s\"",
556 get_screen_image_manager (NULL),
557 iv->image_entry->fullfilename);
558 iv->image_entry->preview =
559 get_asimage (get_screen_image_manager (NULL),
560 iv->image_entry->fullfilename, 0xffffffff, 100);
561 LOCAL_DEBUG_OUT (" ASGtk image view loaded image %p",
562 iv->image_entry->preview);
563
564 }
565
566
567 if (iv->image_entry->preview) {
568 Bool ratio_changed = False;
569 char *details_text;
570
571 details_text =
572 format_asimage_list_entry_details (iv->image_entry,
573 GTK_IS_VBUTTON_BOX (iv->
574 details_hbox));
575 gtk_label_set_text (GTK_LABEL (iv->details_label), details_text);
576 free (details_text);
577
578 if (iv->aspect_x <= 0 || iv->aspect_y <= 0)
579 ratio_changed = set_aspect_ratio_from_image (iv);
580 LOCAL_DEBUG_OUT (" ASGtk image view refreshing image %p",
581 iv->image_entry->preview);
582 /* redisplay */
583 if (!ratio_changed)
584 display_image_view (iv);
585 else
586 gtk_image_set_from_stock (GTK_IMAGE (iv->view),
587 GTK_STOCK_MISSING_IMAGE,
588 GTK_ICON_SIZE_BUTTON);
589 }
590 }
591 }
592
593
594 void
asgtk_image_view_screen_aspect_toggle(GtkWidget * checkbutton,gpointer data)595 asgtk_image_view_screen_aspect_toggle (GtkWidget * checkbutton,
596 gpointer data)
597 {
598 ASGtkImageView *iv = ASGTK_IMAGE_VIEW (data);
599
600 if (GTK_TOGGLE_BUTTON (checkbutton)->active) {
601 asgtk_image_view_set_aspect (iv, get_screen_width (NULL),
602 get_screen_height (NULL));
603 asgtk_image_view_set_resize (iv, ASGTK_IMAGE_VIEW_TILE_TO_ASPECT,
604 ASGTK_IMAGE_VIEW_TILE_TO_ASPECT);
605 } else {
606 asgtk_image_view_set_aspect (iv, -1, -1);
607 asgtk_image_view_set_resize (iv, 0, ASGTK_IMAGE_VIEW_TILE_TO_ASPECT);
608 }
609 }
610
611 void
asgtk_image_view_scale_to_view_toggle(GtkWidget * checkbutton,gpointer data)612 asgtk_image_view_scale_to_view_toggle (GtkWidget * checkbutton,
613 gpointer data)
614 {
615 ASGtkImageView *iv = ASGTK_IMAGE_VIEW (data);
616
617 if (GTK_TOGGLE_BUTTON (checkbutton)->active)
618 asgtk_image_view_set_resize (iv, ASGTK_IMAGE_VIEW_SCALE_TO_VIEW,
619 ASGTK_IMAGE_VIEW_SCALE_TO_VIEW);
620 else
621 asgtk_image_view_set_resize (iv, 0, ASGTK_IMAGE_VIEW_SCALE_TO_VIEW);
622 }
623