2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD 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 Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GdkPixbufLoader.html
27 * outFile = PixbufLoader
28 * strct = GdkPixbufLoader
39 * - gdk_pixbuf_loader_
43 * - gdk_pixbuf_loader_new_with_type
44 * - gdk_pixbuf_loader_new_with_mime_type
46 * - gdkpixbuf.PixbufFormat
48 * - gdkpixbuf.PixbufAnimation
51 * - GdkPixbuf* -> Pixbuf
52 * - GdkPixbufAnimation* -> PixbufAnimation
53 * - GdkPixbufFormat* -> PixbufFormat
58 module gdkpixbuf
.PixbufLoader
;
64 import tango
.io
.Stdout
; // use the tango loging?
68 private import gtkc
.gdkpixbuftypes
;
70 private import gtkc
.gdkpixbuf
;
73 private import gdkpixbuf
.PixbufFormat
;
74 private import gdk
.Pixbuf
;
75 private import gdkpixbuf
.PixbufAnimation
;
76 private import glib
.Str
;
83 * GdkPixbufLoader provides a way for applications to drive the
84 * process of loading an image, by letting them send the image data
85 * directly to the loader instead of having the loader read the data
86 * from a file. Applications can use this functionality instead of
87 * gdk_pixbuf_new_from_file() or gdk_pixbuf_animation_new_from_file()
88 * when they need to parse image data in
89 * small chunks. For example, it should be used when reading an
90 * image from a (potentially) slow network connection, or when
91 * loading an extremely large file.
92 * To use GdkPixbufLoader to load an image, just create a new one,
93 * and call gdk_pixbuf_loader_write() to send the data to it. When
94 * done, gdk_pixbuf_loader_close() should be called to end the stream
95 * and finalize everything. The loader will emit three important
96 * signals throughout the process. The first, "size_prepared",
97 * will be called as soon as the image has enough information to
98 * determine the size of the image to be used. If you want to scale
99 * the image while loading it, you can call gdk_pixbuf_loader_set_size()
100 * in response to this signal.
101 * The second signal, "area_prepared",
102 * will be called as soon as the pixbuf of the desired has been
103 * allocated. You can obtain it by calling gdk_pixbuf_loader_get_pixbuf().
104 * If you want to use it, simply ref it.
105 * In addition, no actual information will be passed in yet, so the
106 * pixbuf can be safely filled with any temporary graphics (or an
107 * initial color) as needed. You can also call
108 * gdk_pixbuf_loader_get_pixbuf() later and get the same pixbuf.
109 * The last signal, "area_updated" gets
110 * called every time a region is updated. This way you can update a
111 * partially completed image. Note that you do not know anything
112 * about the completeness of an image from the area updated. For
113 * example, in an interlaced image, you need to make several passes
114 * before the image is done loading.
115 * Loading an animation
116 * Loading an animation is almost as easy as loading an
117 * image. Once the first "area_prepared" signal
118 * has been emitted, you can call gdk_pixbuf_loader_get_animation()
119 * to get the GdkPixbufAnimation struct and gdk_pixbuf_animation_get_iter()
120 * to get an GdkPixbufAnimationIter for displaying it.
122 private import gobject
.ObjectG
;
123 public class PixbufLoader
: ObjectG
126 /** the main Gtk struct */
127 protected GdkPixbufLoader
* gdkPixbufLoader
;
130 public GdkPixbufLoader
* getPixbufLoaderStruct()
132 return gdkPixbufLoader
;
136 /** the main Gtk struct as a void* */
137 protected void* getStruct()
139 return cast(void*)gdkPixbufLoader
;
143 * Sets our main struct and passes it to the parent class
145 public this (GdkPixbufLoader
* gdkPixbufLoader
)
149 if ( gdkPixbufLoader
is null )
154 Stdout("struct gdkPixbufLoader is null on constructor").newline
;
158 printf("struct gdkPixbufLoader is null on constructor");
165 assert(gdkPixbufLoader
!is null, "struct gdkPixbufLoader is null on constructor");
167 super(cast(GObject
*)gdkPixbufLoader
);
168 this.gdkPixbufLoader
= gdkPixbufLoader
;
172 * Creates a new pixbuf loader object that always attempts to parse
173 * image data as if it were an image of type image_type or mime_type, instead of
174 * identifying the type automatically. Useful if you want an error if
175 * the image isn't the expected type, for loading image formats
176 * that can't be reliably identified by looking at the data, or if
177 * the user manually forces a specific type.
179 * name of the image format or mime to be loaded with the image
181 * return location for an allocated GError, or NULL to ignore errors
183 * A newly-created pixbuf loader.
185 public this (char[] type
, GError
** error
, bool isMimeType
=false)
189 // GdkPixbufLoader* gdk_pixbuf_loader_new_with_mime_type (const char *mime_type, GError **error);
190 this(cast(GdkPixbufLoader
*)gdk_pixbuf_loader_new_with_mime_type(Str
.toStringz(type
), error
) );
194 // GdkPixbufLoader* gdk_pixbuf_loader_new_with_type (const char *image_type, GError **error);
195 this(cast(GdkPixbufLoader
*)gdk_pixbuf_loader_new_with_type(Str
.toStringz(type
), error
) );
202 // imports for the signal processing
203 private import gobject
.Signals
;
204 private import gtkc
.gdktypes
;
205 int[char[]] connectedSignals
;
207 void delegate(PixbufLoader
)[] onAreaPreparedListeners
;
208 void addOnAreaPrepared(void delegate(PixbufLoader
) dlg
, ConnectFlags connectFlags
=cast(ConnectFlags
)0)
210 if ( !("area-prepared" in connectedSignals
) )
215 cast(GCallback
)&callBackAreaPrepared
,
219 connectedSignals
["area-prepared"] = 1;
221 onAreaPreparedListeners
~= dlg
;
223 extern(C
) static void callBackAreaPrepared(GdkPixbufLoader
* loaderStruct
, PixbufLoader pixbufLoader
)
225 bool consumed
= false;
227 foreach ( void delegate(PixbufLoader
) dlg
; pixbufLoader
.onAreaPreparedListeners
)
235 void delegate(gint
, gint
, gint
, gint
, PixbufLoader
)[] onAreaUpdatedListeners
;
236 void addOnAreaUpdated(void delegate(gint
, gint
, gint
, gint
, PixbufLoader
) dlg
, ConnectFlags connectFlags
=cast(ConnectFlags
)0)
238 if ( !("area-updated" in connectedSignals
) )
243 cast(GCallback
)&callBackAreaUpdated
,
247 connectedSignals
["area-updated"] = 1;
249 onAreaUpdatedListeners
~= dlg
;
251 extern(C
) static void callBackAreaUpdated(GdkPixbufLoader
* loaderStruct
, gint x
, gint y
, gint width
, gint height
, PixbufLoader pixbufLoader
)
253 bool consumed
= false;
255 foreach ( void delegate(gint
, gint
, gint
, gint
, PixbufLoader
) dlg
; pixbufLoader
.onAreaUpdatedListeners
)
257 dlg(x
, y
, width
, height
, pixbufLoader
);
263 void delegate(PixbufLoader
)[] onClosedListeners
;
264 void addOnClosed(void delegate(PixbufLoader
) dlg
, ConnectFlags connectFlags
=cast(ConnectFlags
)0)
266 if ( !("closed" in connectedSignals
) )
271 cast(GCallback
)&callBackClosed
,
275 connectedSignals
["closed"] = 1;
277 onClosedListeners
~= dlg
;
279 extern(C
) static void callBackClosed(GdkPixbufLoader
* loaderStruct
, PixbufLoader pixbufLoader
)
281 bool consumed
= false;
283 foreach ( void delegate(PixbufLoader
) dlg
; pixbufLoader
.onClosedListeners
)
291 void delegate(gint
, gint
, PixbufLoader
)[] onSizePreparedListeners
;
292 void addOnSizePrepared(void delegate(gint
, gint
, PixbufLoader
) dlg
, ConnectFlags connectFlags
=cast(ConnectFlags
)0)
294 if ( !("size-prepared" in connectedSignals
) )
299 cast(GCallback
)&callBackSizePrepared
,
303 connectedSignals
["size-prepared"] = 1;
305 onSizePreparedListeners
~= dlg
;
307 extern(C
) static void callBackSizePrepared(GdkPixbufLoader
* loaderStruct
, gint width
, gint height
, PixbufLoader pixbufLoader
)
309 bool consumed
= false;
311 foreach ( void delegate(gint
, gint
, PixbufLoader
) dlg
; pixbufLoader
.onSizePreparedListeners
)
313 dlg(width
, height
, pixbufLoader
);
322 * Creates a new pixbuf loader object.
324 * A newly-created pixbuf loader.
328 // GdkPixbufLoader* gdk_pixbuf_loader_new (void);
329 this(cast(GdkPixbufLoader
*)gdk_pixbuf_loader_new() );
335 * Obtains the available information about the format of the
336 * currently loading image file.
340 * A GdkPixbufFormat or NULL. The return value is owned
341 * by GdkPixbuf and should not be freed.
344 public PixbufFormat
getFormat()
346 // GdkPixbufFormat* gdk_pixbuf_loader_get_format (GdkPixbufLoader *loader);
347 return new PixbufFormat( gdk_pixbuf_loader_get_format(gdkPixbufLoader
) );
351 * This will cause a pixbuf loader to parse the next count bytes of
352 * an image. It will return TRUE if the data was loaded successfully,
353 * and FALSE if an error occurred. In the latter case, the loader
354 * will be closed, and will not accept further writes. If FALSE is
355 * returned, error will be set to an error from the GDK_PIXBUF_ERROR
356 * or G_FILE_ERROR domains.
360 * Pointer to image data.
362 * Length of the buf buffer in bytes.
364 * return location for errors
366 * TRUE if the write was successful, or FALSE if the loader
367 * cannot parse the buffer.
369 public int write(char* buf
, uint count
, GError
** error
)
371 // gboolean gdk_pixbuf_loader_write (GdkPixbufLoader *loader, const guchar *buf, gsize count, GError **error);
372 return gdk_pixbuf_loader_write(gdkPixbufLoader
, buf
, count
, error
);
376 * Causes the image to be scaled while it is loaded. The desired
377 * image size can be determined relative to the original size of
378 * the image by calling gdk_pixbuf_loader_set_size() from a
379 * signal handler for the ::size_prepared signal.
380 * Attempts to set the desired image size are ignored after the
381 * emission of the ::size_prepared signal.
385 * The desired width of the image being loaded.
387 * The desired height of the image being loaded.
390 public void setSize(int width
, int height
)
392 // void gdk_pixbuf_loader_set_size (GdkPixbufLoader *loader, int width, int height);
393 gdk_pixbuf_loader_set_size(gdkPixbufLoader
, width
, height
);
397 * Queries the GdkPixbuf that a pixbuf loader is currently creating.
398 * In general it only makes sense to call this function after the
399 * "area_prepared" signal has been emitted by the loader; this means
400 * that enough data has been read to know the size of the image that
401 * will be allocated. If the loader has not received enough data via
402 * gdk_pixbuf_loader_write(), then this function returns NULL. The
403 * returned pixbuf will be the same in all future calls to the loader,
404 * so simply calling g_object_ref() should be sufficient to continue
405 * using it. Additionally, if the loader is an animation, it will
406 * return the "static image" of the animation
407 * (see gdk_pixbuf_animation_get_static_image()).
411 * The GdkPixbuf that the loader is creating, or NULL if not
412 * enough data has been read to determine how to create the image buffer.
414 public Pixbuf
getPixbuf()
416 // GdkPixbuf* gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader);
417 return new Pixbuf( gdk_pixbuf_loader_get_pixbuf(gdkPixbufLoader
) );
421 * Queries the GdkPixbufAnimation that a pixbuf loader is currently creating.
422 * In general it only makes sense to call this function after the "area_prepared"
423 * signal has been emitted by the loader. If the loader doesn't have enough
424 * bytes yet (hasn't emitted the "area_prepared" signal) this function will
429 * The GdkPixbufAnimation that the loader is loading, or NULL if
430 * not enough data has been read to determine the information.
432 public PixbufAnimation
getAnimation()
434 // GdkPixbufAnimation* gdk_pixbuf_loader_get_animation (GdkPixbufLoader *loader);
435 return new PixbufAnimation( gdk_pixbuf_loader_get_animation(gdkPixbufLoader
) );
439 * Informs a pixbuf loader that no further writes with
440 * gdk_pixbuf_loader_write() will occur, so that it can free its
441 * internal loading structures. Also, tries to parse any data that
442 * hasn't yet been parsed; if the remaining data is partial or
443 * corrupt, an error will be returned. If FALSE is returned, error
444 * will be set to an error from the GDK_PIXBUF_ERROR or G_FILE_ERROR
445 * domains. If you're just cancelling a load rather than expecting it
446 * to be finished, passing NULL for error to ignore it is
451 * return location for a GError, or NULL to ignore errors
453 * TRUE if all image data written so far was successfully
454 * passed out via the update_area signal
456 * The "area-prepared" signal
457 * void user_function (GdkPixbufLoader *loader,
458 * gpointer user_data) : Run Last
459 * This signal is emitted when the pixbuf loader has allocated the
460 * pixbuf in the desired size. After this signal is emitted,
461 * applications can call gdk_pixbuf_loader_get_pixbuf() to fetch
462 * the partially-loaded pixbuf.
464 * the object which received the signal.
466 * user data set when the signal handler was connected.
468 public int close(GError
** error
)
470 // gboolean gdk_pixbuf_loader_close (GdkPixbufLoader *loader, GError **error);
471 return gdk_pixbuf_loader_close(gdkPixbufLoader
, error
);