]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/gdk-pixbuf-animation.c
Include "config.h" instead of <config.h> Command used: find -name
[~andy/gtk] / gdk-pixbuf / gdk-pixbuf-animation.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2 /* GdkPixbuf library - Simple animation support
3  *
4  * Copyright (C) 1999 The Free Software Foundation
5  *
6  * Authors: Jonathan Blandford <jrb@redhat.com>
7  *          Havoc Pennington <hp@redhat.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #include "config.h"
26 #include <errno.h>
27 #include "gdk-pixbuf-private.h"
28 #include "gdk-pixbuf-io.h"
29 #include "gdk-pixbuf-i18n.h"
30 #include "gdk-pixbuf-animation.h"
31 #include "gdk-pixbuf-alias.h"
32
33 #include <glib/gstdio.h>
34
35 typedef struct _GdkPixbufNonAnim GdkPixbufNonAnim;
36 typedef struct _GdkPixbufNonAnimClass GdkPixbufNonAnimClass;
37
38 #define GDK_TYPE_PIXBUF_NON_ANIM              (gdk_pixbuf_non_anim_get_type ())
39 #define GDK_PIXBUF_NON_ANIM(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_NON_ANIM, GdkPixbufNonAnim))
40 #define GDK_IS_PIXBUF_NON_ANIM(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_NON_ANIM))
41
42 #define GDK_PIXBUF_NON_ANIM_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_NON_ANIM, GdkPixbufNonAnimClass))
43 #define GDK_IS_PIXBUF_NON_ANIM_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_NON_ANIM))
44 #define GDK_PIXBUF_NON_ANIM_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_NON_ANIM, GdkPixbufNonAnimClass))
45
46 /* Private part of the GdkPixbufNonAnim structure */
47 struct _GdkPixbufNonAnim {
48         GdkPixbufAnimation parent_instance;
49
50         GdkPixbuf *pixbuf;
51 };
52
53 struct _GdkPixbufNonAnimClass {
54         GdkPixbufAnimationClass parent_class;
55         
56 };
57
58
59 typedef struct _GdkPixbufNonAnimIter GdkPixbufNonAnimIter;
60 typedef struct _GdkPixbufNonAnimIterClass GdkPixbufNonAnimIterClass;
61
62
63 #define GDK_TYPE_PIXBUF_NON_ANIM_ITER              (gdk_pixbuf_non_anim_iter_get_type ())
64 #define GDK_PIXBUF_NON_ANIM_ITER(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_NON_ANIM_ITER, GdkPixbufNonAnimIter))
65 #define GDK_IS_PIXBUF_NON_ANIM_ITER(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_NON_ANIM_ITER))
66
67 #define GDK_PIXBUF_NON_ANIM_ITER_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_NON_ANIM_ITER, GdkPixbufNonAnimIterClass))
68 #define GDK_IS_PIXBUF_NON_ANIM_ITER_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_NON_ANIM_ITER))
69 #define GDK_PIXBUF_NON_ANIM_ITER_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_NON_ANIM_ITER, GdkPixbufNonAnimIterClass))
70
71 struct _GdkPixbufNonAnimIter {
72         GdkPixbufAnimationIter parent_instance;
73
74         GdkPixbufNonAnim   *non_anim;
75 };
76
77 struct _GdkPixbufNonAnimIterClass {
78         GdkPixbufAnimationIterClass parent_class;
79
80 };
81
82 static GType gdk_pixbuf_non_anim_iter_get_type (void) G_GNUC_CONST;
83
84 G_DEFINE_TYPE (GdkPixbufAnimation, gdk_pixbuf_animation, G_TYPE_OBJECT);
85
86 static void
87 gdk_pixbuf_animation_class_init (GdkPixbufAnimationClass *klass)
88 {
89 }
90
91 static void
92 gdk_pixbuf_animation_init (GdkPixbufAnimation *animation)
93 {
94 }
95
96 /**
97  * gdk_pixbuf_animation_new_from_file:
98  * @filename: Name of file to load, in the GLib file name encoding
99  * @error: return location for error
100  *
101  * Creates a new animation by loading it from a file.  The file format is
102  * detected automatically.  If the file's format does not support multi-frame
103  * images, then an animation with a single frame will be created. Possible errors
104  * are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
105  *
106  * Return value: A newly-created animation with a reference count of 1, or %NULL
107  * if any of several error conditions ocurred:  the file could not be opened,
108  * there was no loader for the file's format, there was not enough memory to
109  * allocate the image buffer, or the image file contained invalid data.
110  **/
111 GdkPixbufAnimation *
112 gdk_pixbuf_animation_new_from_file (const char *filename,
113                                     GError    **error)
114 {
115         GdkPixbufAnimation *animation;
116         int size;
117         FILE *f;
118         guchar buffer [1024];
119         GdkPixbufModule *image_module;
120         gchar *display_name;
121         gboolean locked = FALSE;
122
123         g_return_val_if_fail (filename != NULL, NULL);
124         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
125
126         display_name = g_filename_display_name (filename);
127         f = g_fopen (filename, "rb");
128         if (!f) {
129                 gint save_errno = errno;
130                 g_set_error (error,
131                              G_FILE_ERROR,
132                              g_file_error_from_errno (save_errno),
133                              _("Failed to open file '%s': %s"),
134                              display_name,
135                              g_strerror (save_errno));
136                 g_free (display_name);
137                 return NULL;
138         }
139
140         size = fread (&buffer, 1, sizeof (buffer), f);
141
142         if (size == 0) {
143                 g_set_error (error,
144                              GDK_PIXBUF_ERROR,
145                              GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
146                              _("Image file '%s' contains no data"),
147                              display_name);
148                 g_free (display_name);
149                 fclose (f);
150                 return NULL;
151         }
152
153         image_module = _gdk_pixbuf_get_module (buffer, size, filename, error);
154         if (!image_module) {
155                 g_free (display_name);
156                 fclose (f);
157                 return NULL;
158         }
159
160         if (image_module->module == NULL)
161                 if (!_gdk_pixbuf_load_module (image_module, error)) {
162                         g_free (display_name);
163                         fclose (f);
164                         return NULL;
165                 }
166
167         if (image_module->load_animation == NULL) {
168                 GdkPixbuf *pixbuf;
169
170                 /* Keep this logic in sync with gdk_pixbuf_new_from_file() */
171
172                 fseek (f, 0, SEEK_SET);
173                 pixbuf = _gdk_pixbuf_generic_image_load (image_module, f, error);
174                 fclose (f);
175
176                 if (pixbuf == NULL && error != NULL && *error == NULL) {
177                         /* I don't trust these crufty longjmp()'ing image libs
178                          * to maintain proper error invariants, and I don't
179                          * want user code to segfault as a result. We need to maintain
180                          * the invariant that error gets set if NULL is returned.
181                          */
182                         
183                         g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.",
184                                    image_module->module_name);
185                         g_set_error (error,
186                                      GDK_PIXBUF_ERROR,
187                                      GDK_PIXBUF_ERROR_FAILED,
188                                      _("Failed to load image '%s': reason not known, probably a corrupt image file"),
189                                      display_name);
190                 }
191                 
192                 if (pixbuf == NULL) {
193                         g_free (display_name);
194                         animation = NULL;
195                         goto out_unlock;
196                 }
197
198                 animation = gdk_pixbuf_non_anim_new (pixbuf);
199
200                 g_object_unref (pixbuf);
201         } else {
202                 locked = _gdk_pixbuf_lock (image_module);
203
204                 fseek (f, 0, SEEK_SET);
205                 animation = (* image_module->load_animation) (f, error);
206
207                 if (animation == NULL && error != NULL && *error == NULL) {
208                         /* I don't trust these crufty longjmp()'ing
209                          * image libs to maintain proper error
210                          * invariants, and I don't want user code to
211                          * segfault as a result. We need to maintain
212                          * the invariant that error gets set if NULL
213                          * is returned.
214                          */
215                         
216                         g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.",
217                                    image_module->module_name);
218                         g_set_error (error,
219                                      GDK_PIXBUF_ERROR,
220                                      GDK_PIXBUF_ERROR_FAILED,
221                                      _("Failed to load animation '%s': reason not known, probably a corrupt animation file"),
222                                      display_name);
223                 }
224                 
225                 fclose (f);
226         }
227
228         g_free (display_name);
229
230  out_unlock:
231         if (locked)
232                 _gdk_pixbuf_unlock (image_module);
233         return animation;
234 }
235
236 #ifdef G_OS_WIN32
237
238 #undef gdk_pixbuf_animation_new_from_file
239
240 GdkPixbufAnimation *
241 gdk_pixbuf_animation_new_from_file (const char *filename,
242                                     GError    **error)
243 {
244         gchar *utf8_filename =
245                 g_locale_to_utf8 (filename, -1, NULL, NULL, error);
246         GdkPixbufAnimation *retval;
247
248         if (utf8_filename == NULL)
249                 return NULL;
250
251         retval = gdk_pixbuf_animation_new_from_file_utf8 (utf8_filename, error);
252
253         g_free (utf8_filename);
254
255         return retval;
256 }
257
258 #endif
259
260 /**
261  * gdk_pixbuf_animation_ref:
262  * @animation: An animation.
263  *
264  * Adds a reference to an animation. 
265  *
266  * Return value: The same as the @animation argument.
267  *
268  * Deprecated: Use g_object_ref(). 
269  **/
270 GdkPixbufAnimation *
271 gdk_pixbuf_animation_ref (GdkPixbufAnimation *animation)
272 {
273         return (GdkPixbufAnimation*) g_object_ref (animation);
274 }
275
276 /**
277  * gdk_pixbuf_animation_unref:
278  * @animation: An animation.
279  * 
280  * Removes a reference from an animation. 
281  *
282  * Deprecated: Use g_object_unref().
283  **/
284 void
285 gdk_pixbuf_animation_unref (GdkPixbufAnimation *animation)
286 {
287         g_object_unref (animation);
288 }
289
290 /**
291  * gdk_pixbuf_animation_is_static_image:
292  * @animation: a #GdkPixbufAnimation
293  * 
294  * If you load a file with gdk_pixbuf_animation_new_from_file() and it turns
295  * out to be a plain, unanimated image, then this function will return
296  * %TRUE. Use gdk_pixbuf_animation_get_static_image() to retrieve
297  * the image.
298  * 
299  * Return value: %TRUE if the "animation" was really just an image
300  **/
301 gboolean
302 gdk_pixbuf_animation_is_static_image (GdkPixbufAnimation *animation)
303 {
304         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), FALSE);
305
306         return GDK_PIXBUF_ANIMATION_GET_CLASS (animation)->is_static_image (animation);
307 }
308
309 /**
310  * gdk_pixbuf_animation_get_static_image:
311  * @animation: a #GdkPixbufAnimation
312  * 
313  * If an animation is really just a plain image (has only one frame),
314  * this function returns that image. If the animation is an animation,
315  * this function returns a reasonable thing to display as a static
316  * unanimated image, which might be the first frame, or something more
317  * sophisticated. If an animation hasn't loaded any frames yet, this
318  * function will return %NULL.
319  * 
320  * Return value: unanimated image representing the animation
321  **/
322 GdkPixbuf*
323 gdk_pixbuf_animation_get_static_image (GdkPixbufAnimation *animation)
324 {
325         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), NULL);
326         
327         return GDK_PIXBUF_ANIMATION_GET_CLASS (animation)->get_static_image (animation);
328 }
329
330 /**
331  * gdk_pixbuf_animation_get_width:
332  * @animation: An animation.
333  *
334  * Queries the width of the bounding box of a pixbuf animation.
335  * 
336  * Return value: Width of the bounding box of the animation.
337  **/
338 int
339 gdk_pixbuf_animation_get_width (GdkPixbufAnimation *animation)
340 {
341         int width;
342         
343         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), 0);
344
345         width = 0;
346         GDK_PIXBUF_ANIMATION_GET_CLASS (animation)->get_size (animation,
347                                                               &width, NULL);
348         
349
350         return width;
351 }
352
353 /**
354  * gdk_pixbuf_animation_get_height:
355  * @animation: An animation.
356  *
357  * Queries the height of the bounding box of a pixbuf animation.
358  * 
359  * Return value: Height of the bounding box of the animation.
360  **/
361 int
362 gdk_pixbuf_animation_get_height (GdkPixbufAnimation *animation)
363 {
364         int height;
365         
366         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), 0);
367
368         height = 0;
369         GDK_PIXBUF_ANIMATION_GET_CLASS (animation)->get_size (animation,
370                                                               NULL, &height);
371         
372
373         return height;
374 }
375
376
377 /**
378  * gdk_pixbuf_animation_get_iter:
379  * @animation: a #GdkPixbufAnimation
380  * @start_time: time when the animation starts playing
381  * 
382  * Get an iterator for displaying an animation. The iterator provides
383  * the frames that should be displayed at a given time.
384  * It should be freed after use with g_object_unref().
385  * 
386  * @start_time would normally come from g_get_current_time(), and
387  * marks the beginning of animation playback. After creating an
388  * iterator, you should immediately display the pixbuf returned by
389  * gdk_pixbuf_animation_iter_get_pixbuf(). Then, you should install a
390  * timeout (with g_timeout_add()) or by some other mechanism ensure
391  * that you'll update the image after
392  * gdk_pixbuf_animation_iter_get_delay_time() milliseconds. Each time
393  * the image is updated, you should reinstall the timeout with the new,
394  * possibly-changed delay time.
395  *
396  * As a shortcut, if @start_time is %NULL, the result of
397  * g_get_current_time() will be used automatically.
398  *
399  * To update the image (i.e. possibly change the result of
400  * gdk_pixbuf_animation_iter_get_pixbuf() to a new frame of the animation),
401  * call gdk_pixbuf_animation_iter_advance().
402  *
403  * If you're using #GdkPixbufLoader, in addition to updating the image
404  * after the delay time, you should also update it whenever you
405  * receive the area_updated signal and
406  * gdk_pixbuf_animation_iter_on_currently_loading_frame() returns
407  * %TRUE. In this case, the frame currently being fed into the loader
408  * has received new data, so needs to be refreshed. The delay time for
409  * a frame may also be modified after an area_updated signal, for
410  * example if the delay time for a frame is encoded in the data after
411  * the frame itself. So your timeout should be reinstalled after any
412  * area_updated signal.
413  *
414  * A delay time of -1 is possible, indicating "infinite."
415  * 
416  * Return value: an iterator to move over the animation
417  **/
418 GdkPixbufAnimationIter*
419 gdk_pixbuf_animation_get_iter (GdkPixbufAnimation *animation,
420                                const GTimeVal     *start_time)
421 {
422         GTimeVal val;
423         
424         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION (animation), NULL);
425
426
427         if (start_time)
428                 val = *start_time;
429         else
430                 g_get_current_time (&val);
431         
432         return GDK_PIXBUF_ANIMATION_GET_CLASS (animation)->get_iter (animation, &val);
433 }
434
435 G_DEFINE_TYPE (GdkPixbufAnimationIter, gdk_pixbuf_animation_iter, G_TYPE_OBJECT);
436
437 static void
438 gdk_pixbuf_animation_iter_class_init (GdkPixbufAnimationIterClass *klass)
439 {
440 }
441
442 static void
443 gdk_pixbuf_animation_iter_init (GdkPixbufAnimationIter *iter)
444 {
445 }
446
447 /**
448  * gdk_pixbuf_animation_iter_get_delay_time:
449  * @iter: an animation iterator
450  * 
451  * Gets the number of milliseconds the current pixbuf should be displayed,
452  * or -1 if the current pixbuf should be displayed forever. g_timeout_add()
453  * conveniently takes a timeout in milliseconds, so you can use a timeout
454  * to schedule the next update.
455  *
456  * Return value: delay time in milliseconds (thousandths of a second)
457  **/
458 int
459 gdk_pixbuf_animation_iter_get_delay_time (GdkPixbufAnimationIter *iter)
460 {
461         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), -1);
462   
463         return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_delay_time (iter);
464 }
465
466 /**
467  * gdk_pixbuf_animation_iter_get_pixbuf:
468  * @iter: an animation iterator
469  * 
470  * Gets the current pixbuf which should be displayed; the pixbuf will
471  * be the same size as the animation itself
472  * (gdk_pixbuf_animation_get_width(), gdk_pixbuf_animation_get_height()). 
473  * This pixbuf should be displayed for 
474  * gdk_pixbuf_animation_iter_get_delay_time() milliseconds.  The caller
475  * of this function does not own a reference to the returned pixbuf;
476  * the returned pixbuf will become invalid when the iterator advances
477  * to the next frame, which may happen anytime you call
478  * gdk_pixbuf_animation_iter_advance(). Copy the pixbuf to keep it
479  * (don't just add a reference), as it may get recycled as you advance
480  * the iterator.
481  *
482  * Return value: the pixbuf to be displayed
483  **/
484 GdkPixbuf*
485 gdk_pixbuf_animation_iter_get_pixbuf (GdkPixbufAnimationIter *iter)
486 {
487         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), NULL);
488   
489         return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_pixbuf (iter);
490 }
491
492 /**
493  * gdk_pixbuf_animation_iter_on_currently_loading_frame:
494  * @iter: a #GdkPixbufAnimationIter
495  *
496  * Used to determine how to respond to the area_updated signal on
497  * #GdkPixbufLoader when loading an animation. area_updated is emitted
498  * for an area of the frame currently streaming in to the loader. So if
499  * you're on the currently loading frame, you need to redraw the screen for
500  * the updated area.
501  * 
502  * Return value: %TRUE if the frame we're on is partially loaded, or the last frame
503  **/
504 gboolean
505 gdk_pixbuf_animation_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter)
506 {
507         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), FALSE);
508         
509         return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->on_currently_loading_frame (iter);
510 }
511
512 /**
513  * gdk_pixbuf_animation_iter_advance:
514  * @iter: a #GdkPixbufAnimationIter
515  * @current_time: current time
516  *
517  * Possibly advances an animation to a new frame. Chooses the frame based
518  * on the start time passed to gdk_pixbuf_animation_get_iter().
519  * 
520  * @current_time would normally come from g_get_current_time(), and
521  * must be greater than or equal to the time passed to
522  * gdk_pixbuf_animation_get_iter(), and must increase or remain
523  * unchanged each time gdk_pixbuf_animation_iter_get_pixbuf() is
524  * called. That is, you can't go backward in time; animations only
525  * play forward.
526  *
527  * As a shortcut, pass %NULL for the current time and g_get_current_time()
528  * will be invoked on your behalf. So you only need to explicitly pass
529  * @current_time if you're doing something odd like playing the animation
530  * at double speed.
531  *
532  * If this function returns %FALSE, there's no need to update the animation
533  * display, assuming the display had been rendered prior to advancing;
534  * if %TRUE, you need to call gdk_animation_iter_get_pixbuf() and update the
535  * display with the new pixbuf.
536  *
537  * Returns: %TRUE if the image may need updating
538  * 
539  **/
540 gboolean
541 gdk_pixbuf_animation_iter_advance (GdkPixbufAnimationIter *iter,
542                                    const GTimeVal         *current_time)
543 {
544         GTimeVal val;
545         
546         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), FALSE);
547
548         if (current_time)
549                 val = *current_time;
550         else
551                 g_get_current_time (&val);
552         
553         return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->advance (iter, &val);
554 }
555
556 static void                    gdk_pixbuf_non_anim_finalize         (GObject            *object);
557 static gboolean                gdk_pixbuf_non_anim_is_static_image  (GdkPixbufAnimation *animation);
558 static GdkPixbuf*              gdk_pixbuf_non_anim_get_static_image (GdkPixbufAnimation *animation);
559 static void                    gdk_pixbuf_non_anim_get_size         (GdkPixbufAnimation *anim,
560                                                                      int                *width,
561                                                                      int                *height);
562 static GdkPixbufAnimationIter* gdk_pixbuf_non_anim_get_iter         (GdkPixbufAnimation *anim,
563                                                                      const GTimeVal     *start_time);
564
565 G_DEFINE_TYPE (GdkPixbufNonAnim, gdk_pixbuf_non_anim, GDK_TYPE_PIXBUF_ANIMATION);
566
567 static void
568 gdk_pixbuf_non_anim_class_init (GdkPixbufNonAnimClass *klass)
569 {
570         GObjectClass *object_class = G_OBJECT_CLASS (klass);
571         GdkPixbufAnimationClass *anim_class = GDK_PIXBUF_ANIMATION_CLASS (klass);
572         
573         object_class->finalize = gdk_pixbuf_non_anim_finalize;
574
575         anim_class->is_static_image = gdk_pixbuf_non_anim_is_static_image;
576         anim_class->get_static_image = gdk_pixbuf_non_anim_get_static_image;
577         anim_class->get_size = gdk_pixbuf_non_anim_get_size;
578         anim_class->get_iter = gdk_pixbuf_non_anim_get_iter;
579 }
580
581 static void
582 gdk_pixbuf_non_anim_init (GdkPixbufNonAnim *non_anim)
583 {
584 }
585
586 static void
587 gdk_pixbuf_non_anim_finalize (GObject *object)
588 {
589         GdkPixbufNonAnim *non_anim = GDK_PIXBUF_NON_ANIM (object);
590
591         if (non_anim->pixbuf)
592                 g_object_unref (non_anim->pixbuf);
593         
594         G_OBJECT_CLASS (gdk_pixbuf_non_anim_parent_class)->finalize (object);
595 }
596
597 GdkPixbufAnimation*
598 gdk_pixbuf_non_anim_new (GdkPixbuf *pixbuf)
599 {
600         GdkPixbufNonAnim *non_anim;
601
602         non_anim = g_object_new (GDK_TYPE_PIXBUF_NON_ANIM, NULL);
603
604         non_anim->pixbuf = pixbuf;
605
606         if (pixbuf)
607                 g_object_ref (pixbuf);
608
609         return GDK_PIXBUF_ANIMATION (non_anim);
610 }
611
612 static gboolean
613 gdk_pixbuf_non_anim_is_static_image  (GdkPixbufAnimation *animation)
614 {
615
616         return TRUE;
617 }
618
619 static GdkPixbuf*
620 gdk_pixbuf_non_anim_get_static_image (GdkPixbufAnimation *animation)
621 {
622         GdkPixbufNonAnim *non_anim;
623
624         non_anim = GDK_PIXBUF_NON_ANIM (animation);
625
626         return non_anim->pixbuf;
627 }
628
629 static void
630 gdk_pixbuf_non_anim_get_size (GdkPixbufAnimation *anim,
631                               int                *width,
632                               int                *height)
633 {
634         GdkPixbufNonAnim *non_anim;
635
636         non_anim = GDK_PIXBUF_NON_ANIM (anim);
637
638         if (width)
639                 *width = gdk_pixbuf_get_width (non_anim->pixbuf);
640
641         if (height)
642                 *height = gdk_pixbuf_get_height (non_anim->pixbuf);
643 }
644
645 static GdkPixbufAnimationIter*
646 gdk_pixbuf_non_anim_get_iter (GdkPixbufAnimation *anim,
647                               const GTimeVal     *start_time)
648 {
649         GdkPixbufNonAnimIter *iter;
650
651         iter = g_object_new (GDK_TYPE_PIXBUF_NON_ANIM_ITER, NULL);
652
653         iter->non_anim = GDK_PIXBUF_NON_ANIM (anim);
654
655         g_object_ref (iter->non_anim);
656         
657         return GDK_PIXBUF_ANIMATION_ITER (iter);
658 }
659
660 static void       gdk_pixbuf_non_anim_iter_finalize                   (GObject                *object);
661 static int        gdk_pixbuf_non_anim_iter_get_delay_time             (GdkPixbufAnimationIter *iter);
662 static GdkPixbuf* gdk_pixbuf_non_anim_iter_get_pixbuf                 (GdkPixbufAnimationIter *iter);
663 static gboolean   gdk_pixbuf_non_anim_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter);
664 static gboolean   gdk_pixbuf_non_anim_iter_advance                    (GdkPixbufAnimationIter *iter,
665                                                                        const GTimeVal         *current_time);
666
667 G_DEFINE_TYPE (GdkPixbufNonAnimIter,
668                gdk_pixbuf_non_anim_iter,
669                GDK_TYPE_PIXBUF_ANIMATION_ITER);
670
671 static void
672 gdk_pixbuf_non_anim_iter_class_init (GdkPixbufNonAnimIterClass *klass)
673 {
674         GObjectClass *object_class = G_OBJECT_CLASS (klass);
675         GdkPixbufAnimationIterClass *anim_iter_class =
676                 GDK_PIXBUF_ANIMATION_ITER_CLASS (klass);
677         
678         object_class->finalize = gdk_pixbuf_non_anim_iter_finalize;
679
680         anim_iter_class->get_delay_time = gdk_pixbuf_non_anim_iter_get_delay_time;
681         anim_iter_class->get_pixbuf = gdk_pixbuf_non_anim_iter_get_pixbuf;
682         anim_iter_class->on_currently_loading_frame = gdk_pixbuf_non_anim_iter_on_currently_loading_frame;
683         anim_iter_class->advance = gdk_pixbuf_non_anim_iter_advance;
684 }
685
686 static void
687 gdk_pixbuf_non_anim_iter_init (GdkPixbufNonAnimIter *non_iter)
688 {
689 }
690
691 static void
692 gdk_pixbuf_non_anim_iter_finalize (GObject *object)
693 {
694         GdkPixbufNonAnimIter *iter = GDK_PIXBUF_NON_ANIM_ITER (object);
695
696         g_object_unref (iter->non_anim);
697         
698         G_OBJECT_CLASS (gdk_pixbuf_non_anim_iter_parent_class)->finalize (object);
699 }
700
701 static int
702 gdk_pixbuf_non_anim_iter_get_delay_time (GdkPixbufAnimationIter *iter)
703 {
704         return -1; /* show only frame forever */
705 }
706
707 static GdkPixbuf*
708 gdk_pixbuf_non_anim_iter_get_pixbuf (GdkPixbufAnimationIter *iter)
709 {
710         return GDK_PIXBUF_NON_ANIM_ITER (iter)->non_anim->pixbuf;
711 }
712
713
714 static gboolean
715 gdk_pixbuf_non_anim_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter)
716 {
717         return TRUE;
718 }
719         
720 static gboolean
721 gdk_pixbuf_non_anim_iter_advance (GdkPixbufAnimationIter *iter,
722                                   const GTimeVal         *current_time)
723 {
724
725         /* Advancing never requires a refresh */
726         return FALSE;
727 }
728
729 #define __GDK_PIXBUF_ANIMATION_C__
730 #include "gdk-pixbuf-aliasdef.c"