]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/gdk-pixbuf-animation.c
Updated Arabic translation
[~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: 2.0: 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: 2.0: 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         g_return_val_if_fail (GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_delay_time, -1);
463
464         return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_delay_time (iter);
465 }
466
467 /**
468  * gdk_pixbuf_animation_iter_get_pixbuf:
469  * @iter: an animation iterator
470  * 
471  * Gets the current pixbuf which should be displayed; the pixbuf will
472  * be the same size as the animation itself
473  * (gdk_pixbuf_animation_get_width(), gdk_pixbuf_animation_get_height()). 
474  * This pixbuf should be displayed for 
475  * gdk_pixbuf_animation_iter_get_delay_time() milliseconds.  The caller
476  * of this function does not own a reference to the returned pixbuf;
477  * the returned pixbuf will become invalid when the iterator advances
478  * to the next frame, which may happen anytime you call
479  * gdk_pixbuf_animation_iter_advance(). Copy the pixbuf to keep it
480  * (don't just add a reference), as it may get recycled as you advance
481  * the iterator.
482  *
483  * Return value: the pixbuf to be displayed
484  **/
485 GdkPixbuf*
486 gdk_pixbuf_animation_iter_get_pixbuf (GdkPixbufAnimationIter *iter)
487 {
488         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), NULL);
489         g_return_val_if_fail (GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_pixbuf, NULL);
490
491         return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->get_pixbuf (iter);
492 }
493
494 /**
495  * gdk_pixbuf_animation_iter_on_currently_loading_frame:
496  * @iter: a #GdkPixbufAnimationIter
497  *
498  * Used to determine how to respond to the area_updated signal on
499  * #GdkPixbufLoader when loading an animation. area_updated is emitted
500  * for an area of the frame currently streaming in to the loader. So if
501  * you're on the currently loading frame, you need to redraw the screen for
502  * the updated area.
503  *
504  * Return value: %TRUE if the frame we're on is partially loaded, or the last frame
505  **/
506 gboolean
507 gdk_pixbuf_animation_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter)
508 {
509         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), FALSE);
510         g_return_val_if_fail (GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->on_currently_loading_frame, FALSE);
511
512         return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->on_currently_loading_frame (iter);
513 }
514
515 /**
516  * gdk_pixbuf_animation_iter_advance:
517  * @iter: a #GdkPixbufAnimationIter
518  * @current_time: current time
519  *
520  * Possibly advances an animation to a new frame. Chooses the frame based
521  * on the start time passed to gdk_pixbuf_animation_get_iter().
522  *
523  * @current_time would normally come from g_get_current_time(), and
524  * must be greater than or equal to the time passed to
525  * gdk_pixbuf_animation_get_iter(), and must increase or remain
526  * unchanged each time gdk_pixbuf_animation_iter_get_pixbuf() is
527  * called. That is, you can't go backward in time; animations only
528  * play forward.
529  *
530  * As a shortcut, pass %NULL for the current time and g_get_current_time()
531  * will be invoked on your behalf. So you only need to explicitly pass
532  * @current_time if you're doing something odd like playing the animation
533  * at double speed.
534  *
535  * If this function returns %FALSE, there's no need to update the animation
536  * display, assuming the display had been rendered prior to advancing;
537  * if %TRUE, you need to call gdk_animation_iter_get_pixbuf() and update the
538  * display with the new pixbuf.
539  *
540  * Returns: %TRUE if the image may need updating
541  * 
542  **/
543 gboolean
544 gdk_pixbuf_animation_iter_advance (GdkPixbufAnimationIter *iter,
545                                    const GTimeVal         *current_time)
546 {
547         GTimeVal val;
548
549         g_return_val_if_fail (GDK_IS_PIXBUF_ANIMATION_ITER (iter), FALSE);
550         g_return_val_if_fail (GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->advance, FALSE);
551
552         if (current_time)
553                 val = *current_time;
554         else
555                 g_get_current_time (&val);
556
557         return GDK_PIXBUF_ANIMATION_ITER_GET_CLASS (iter)->advance (iter, &val);
558 }
559
560 static void                    gdk_pixbuf_non_anim_finalize         (GObject            *object);
561 static gboolean                gdk_pixbuf_non_anim_is_static_image  (GdkPixbufAnimation *animation);
562 static GdkPixbuf*              gdk_pixbuf_non_anim_get_static_image (GdkPixbufAnimation *animation);
563 static void                    gdk_pixbuf_non_anim_get_size         (GdkPixbufAnimation *anim,
564                                                                      int                *width,
565                                                                      int                *height);
566 static GdkPixbufAnimationIter* gdk_pixbuf_non_anim_get_iter         (GdkPixbufAnimation *anim,
567                                                                      const GTimeVal     *start_time);
568
569 G_DEFINE_TYPE (GdkPixbufNonAnim, gdk_pixbuf_non_anim, GDK_TYPE_PIXBUF_ANIMATION);
570
571 static void
572 gdk_pixbuf_non_anim_class_init (GdkPixbufNonAnimClass *klass)
573 {
574         GObjectClass *object_class = G_OBJECT_CLASS (klass);
575         GdkPixbufAnimationClass *anim_class = GDK_PIXBUF_ANIMATION_CLASS (klass);
576         
577         object_class->finalize = gdk_pixbuf_non_anim_finalize;
578
579         anim_class->is_static_image = gdk_pixbuf_non_anim_is_static_image;
580         anim_class->get_static_image = gdk_pixbuf_non_anim_get_static_image;
581         anim_class->get_size = gdk_pixbuf_non_anim_get_size;
582         anim_class->get_iter = gdk_pixbuf_non_anim_get_iter;
583 }
584
585 static void
586 gdk_pixbuf_non_anim_init (GdkPixbufNonAnim *non_anim)
587 {
588 }
589
590 static void
591 gdk_pixbuf_non_anim_finalize (GObject *object)
592 {
593         GdkPixbufNonAnim *non_anim = GDK_PIXBUF_NON_ANIM (object);
594
595         if (non_anim->pixbuf)
596                 g_object_unref (non_anim->pixbuf);
597         
598         G_OBJECT_CLASS (gdk_pixbuf_non_anim_parent_class)->finalize (object);
599 }
600
601 GdkPixbufAnimation*
602 gdk_pixbuf_non_anim_new (GdkPixbuf *pixbuf)
603 {
604         GdkPixbufNonAnim *non_anim;
605
606         non_anim = g_object_new (GDK_TYPE_PIXBUF_NON_ANIM, NULL);
607
608         non_anim->pixbuf = pixbuf;
609
610         if (pixbuf)
611                 g_object_ref (pixbuf);
612
613         return GDK_PIXBUF_ANIMATION (non_anim);
614 }
615
616 static gboolean
617 gdk_pixbuf_non_anim_is_static_image  (GdkPixbufAnimation *animation)
618 {
619
620         return TRUE;
621 }
622
623 static GdkPixbuf*
624 gdk_pixbuf_non_anim_get_static_image (GdkPixbufAnimation *animation)
625 {
626         GdkPixbufNonAnim *non_anim;
627
628         non_anim = GDK_PIXBUF_NON_ANIM (animation);
629
630         return non_anim->pixbuf;
631 }
632
633 static void
634 gdk_pixbuf_non_anim_get_size (GdkPixbufAnimation *anim,
635                               int                *width,
636                               int                *height)
637 {
638         GdkPixbufNonAnim *non_anim;
639
640         non_anim = GDK_PIXBUF_NON_ANIM (anim);
641
642         if (width)
643                 *width = gdk_pixbuf_get_width (non_anim->pixbuf);
644
645         if (height)
646                 *height = gdk_pixbuf_get_height (non_anim->pixbuf);
647 }
648
649 static GdkPixbufAnimationIter*
650 gdk_pixbuf_non_anim_get_iter (GdkPixbufAnimation *anim,
651                               const GTimeVal     *start_time)
652 {
653         GdkPixbufNonAnimIter *iter;
654
655         iter = g_object_new (GDK_TYPE_PIXBUF_NON_ANIM_ITER, NULL);
656
657         iter->non_anim = GDK_PIXBUF_NON_ANIM (anim);
658
659         g_object_ref (iter->non_anim);
660         
661         return GDK_PIXBUF_ANIMATION_ITER (iter);
662 }
663
664 static void       gdk_pixbuf_non_anim_iter_finalize                   (GObject                *object);
665 static int        gdk_pixbuf_non_anim_iter_get_delay_time             (GdkPixbufAnimationIter *iter);
666 static GdkPixbuf* gdk_pixbuf_non_anim_iter_get_pixbuf                 (GdkPixbufAnimationIter *iter);
667 static gboolean   gdk_pixbuf_non_anim_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter);
668 static gboolean   gdk_pixbuf_non_anim_iter_advance                    (GdkPixbufAnimationIter *iter,
669                                                                        const GTimeVal         *current_time);
670
671 G_DEFINE_TYPE (GdkPixbufNonAnimIter,
672                gdk_pixbuf_non_anim_iter,
673                GDK_TYPE_PIXBUF_ANIMATION_ITER);
674
675 static void
676 gdk_pixbuf_non_anim_iter_class_init (GdkPixbufNonAnimIterClass *klass)
677 {
678         GObjectClass *object_class = G_OBJECT_CLASS (klass);
679         GdkPixbufAnimationIterClass *anim_iter_class =
680                 GDK_PIXBUF_ANIMATION_ITER_CLASS (klass);
681         
682         object_class->finalize = gdk_pixbuf_non_anim_iter_finalize;
683
684         anim_iter_class->get_delay_time = gdk_pixbuf_non_anim_iter_get_delay_time;
685         anim_iter_class->get_pixbuf = gdk_pixbuf_non_anim_iter_get_pixbuf;
686         anim_iter_class->on_currently_loading_frame = gdk_pixbuf_non_anim_iter_on_currently_loading_frame;
687         anim_iter_class->advance = gdk_pixbuf_non_anim_iter_advance;
688 }
689
690 static void
691 gdk_pixbuf_non_anim_iter_init (GdkPixbufNonAnimIter *non_iter)
692 {
693 }
694
695 static void
696 gdk_pixbuf_non_anim_iter_finalize (GObject *object)
697 {
698         GdkPixbufNonAnimIter *iter = GDK_PIXBUF_NON_ANIM_ITER (object);
699
700         g_object_unref (iter->non_anim);
701         
702         G_OBJECT_CLASS (gdk_pixbuf_non_anim_iter_parent_class)->finalize (object);
703 }
704
705 static int
706 gdk_pixbuf_non_anim_iter_get_delay_time (GdkPixbufAnimationIter *iter)
707 {
708         return -1; /* show only frame forever */
709 }
710
711 static GdkPixbuf*
712 gdk_pixbuf_non_anim_iter_get_pixbuf (GdkPixbufAnimationIter *iter)
713 {
714         return GDK_PIXBUF_NON_ANIM_ITER (iter)->non_anim->pixbuf;
715 }
716
717
718 static gboolean
719 gdk_pixbuf_non_anim_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter)
720 {
721         return TRUE;
722 }
723         
724 static gboolean
725 gdk_pixbuf_non_anim_iter_advance (GdkPixbufAnimationIter *iter,
726                                   const GTimeVal         *current_time)
727 {
728
729         /* Advancing never requires a refresh */
730         return FALSE;
731 }
732
733 #define __GDK_PIXBUF_ANIMATION_C__
734 #include "gdk-pixbuf-aliasdef.c"