1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = GdkPixbufLoader.html
27  * outPack = gdkpixbuf
28  * outFile = PixbufLoader
29  * strct   = GdkPixbufLoader
30  * realStrct=
31  * ctorStrct=
32  * clss    = PixbufLoader
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gdk_pixbuf_loader_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * 	- gdk_pixbuf_loader_new_with_type
45  * 	- gdk_pixbuf_loader_new_with_mime_type
46  * omit signals:
47  * imports:
48  * 	- gdkpixbuf.PixbufFormat
49  * 	- glib.ErrorG
50  * 	- glib.GException
51  * 	- glib.Bytes
52  * 	- gdk.Pixbuf
53  * 	- gdkpixbuf.PixbufAnimation
54  * 	- glib.Str
55  * structWrap:
56  * 	- GBytes* -> Bytes
57  * 	- GdkPixbuf* -> Pixbuf
58  * 	- GdkPixbufAnimation* -> PixbufAnimation
59  * 	- GdkPixbufFormat* -> PixbufFormat
60  * module aliases:
61  * local aliases:
62  * overrides:
63  */
64 
65 module gdkpixbuf.PixbufLoader;
66 
67 public  import gtkc.gdkpixbuftypes;
68 
69 private import gtkc.gdkpixbuf;
70 private import glib.ConstructionException;
71 private import gobject.ObjectG;
72 
73 private import gobject.Signals;
74 public  import gtkc.gdktypes;
75 
76 private import gdkpixbuf.PixbufFormat;
77 private import glib.ErrorG;
78 private import glib.GException;
79 private import glib.Bytes;
80 private import gdk.Pixbuf;
81 private import gdkpixbuf.PixbufAnimation;
82 private import glib.Str;
83 
84 
85 
86 private import gobject.ObjectG;
87 
88 /**
89  * GdkPixbufLoader provides a way for applications to drive the
90  * process of loading an image, by letting them send the image data
91  * directly to the loader instead of having the loader read the data
92  * from a file. Applications can use this functionality instead of
93  * gdk_pixbuf_new_from_file() or gdk_pixbuf_animation_new_from_file()
94  * when they need to parse image data in
95  * small chunks. For example, it should be used when reading an
96  * image from a (potentially) slow network connection, or when
97  * loading an extremely large file.
98  *
99  * To use GdkPixbufLoader to load an image, just create a new one,
100  * and call gdk_pixbuf_loader_write() to send the data to it. When
101  * done, gdk_pixbuf_loader_close() should be called to end the stream
102  * and finalize everything. The loader will emit three important
103  * signals throughout the process. The first, "size_prepared",
104  * will be called as soon as the image has enough information to
105  * determine the size of the image to be used. If you want to scale
106  * the image while loading it, you can call gdk_pixbuf_loader_set_size()
107  * in response to this signal.
108  *
109  * The second signal, "area_prepared",
110  * will be called as soon as the pixbuf of the desired has been
111  * allocated. You can obtain it by calling gdk_pixbuf_loader_get_pixbuf().
112  * If you want to use it, simply ref it.
113  * In addition, no actual information will be passed in yet, so the
114  * pixbuf can be safely filled with any temporary graphics (or an
115  * initial color) as needed. You can also call
116  * gdk_pixbuf_loader_get_pixbuf() later and get the same pixbuf.
117  *
118  * The last signal, "area_updated" gets
119  * called every time a region is updated. This way you can update a
120  * partially completed image. Note that you do not know anything
121  * about the completeness of an image from the area updated. For
122  * example, in an interlaced image, you need to make several passes
123  * before the image is done loading.
124  *
125  * Loading an animation
126  *
127  * Loading an animation is almost as easy as loading an
128  * image. Once the first "area_prepared" signal
129  * has been emitted, you can call gdk_pixbuf_loader_get_animation()
130  * to get the GdkPixbufAnimation struct and gdk_pixbuf_animation_get_iter()
131  * to get an GdkPixbufAnimationIter for displaying it.
132  */
133 public class PixbufLoader : ObjectG
134 {
135 	
136 	/** the main Gtk struct */
137 	protected GdkPixbufLoader* gdkPixbufLoader;
138 	
139 	
140 	public GdkPixbufLoader* getPixbufLoaderStruct()
141 	{
142 		return gdkPixbufLoader;
143 	}
144 	
145 	
146 	/** the main Gtk struct as a void* */
147 	protected override void* getStruct()
148 	{
149 		return cast(void*)gdkPixbufLoader;
150 	}
151 	
152 	/**
153 	 * Sets our main struct and passes it to the parent class
154 	 */
155 	public this (GdkPixbufLoader* gdkPixbufLoader)
156 	{
157 		super(cast(GObject*)gdkPixbufLoader);
158 		this.gdkPixbufLoader = gdkPixbufLoader;
159 	}
160 	
161 	protected override void setStruct(GObject* obj)
162 	{
163 		super.setStruct(obj);
164 		gdkPixbufLoader = cast(GdkPixbufLoader*)obj;
165 	}
166 	
167 	/**
168 	 * Creates a new pixbuf loader object that always attempts to parse
169 	 * image data as if it were an image of type image_type or mime_type, instead of
170 	 * identifying the type automatically. Useful if you want an error if
171 	 * the image isn't the expected type, for loading image formats
172 	 * that can't be reliably identified by looking at the data, or if
173 	 * the user manually forces a specific type.
174 	 * Params:
175 	 *  type = name of the image format or mime to be loaded with the image
176 	 */
177 	public this (string type, bool isMimeType=false)
178 	{
179 		GdkPixbufLoader* p;
180 		GError* err = null;
181 		
182 		if ( isMimeType )
183 		{
184 			// GdkPixbufLoader* gdk_pixbuf_loader_new_with_mime_type  (const char *mime_type,  GError **error);
185 			p = cast(GdkPixbufLoader*)gdk_pixbuf_loader_new_with_mime_type(Str.toStringz(type), &err);
186 		}
187 		else
188 		{
189 			// GdkPixbufLoader* gdk_pixbuf_loader_new_with_type  (const char *image_type,  GError **error);
190 			p = cast(GdkPixbufLoader*)gdk_pixbuf_loader_new_with_type(Str.toStringz(type), &err);
191 		}
192 		
193 		if (err !is null)
194 		{
195 			throw new GException( new ErrorG(err) );
196 		}
197 		
198 		if(p is null)
199 		{
200 			throw new ConstructionException("null returned by gtk_button_new()");
201 		}
202 		
203 		this(p);
204 	}
205 	
206 	/**
207 	 */
208 	int[string] connectedSignals;
209 	
210 	void delegate(PixbufLoader)[] onAreaPreparedListeners;
211 	/**
212 	 * This signal is emitted when the pixbuf loader has allocated the
213 	 * pixbuf in the desired size. After this signal is emitted,
214 	 * applications can call gdk_pixbuf_loader_get_pixbuf() to fetch
215 	 * the partially-loaded pixbuf.
216 	 */
217 	void addOnAreaPrepared(void delegate(PixbufLoader) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
218 	{
219 		if ( !("area-prepared" in connectedSignals) )
220 		{
221 			Signals.connectData(
222 			getStruct(),
223 			"area-prepared",
224 			cast(GCallback)&callBackAreaPrepared,
225 			cast(void*)this,
226 			null,
227 			connectFlags);
228 			connectedSignals["area-prepared"] = 1;
229 		}
230 		onAreaPreparedListeners ~= dlg;
231 	}
232 	extern(C) static void callBackAreaPrepared(GdkPixbufLoader* loaderStruct, PixbufLoader _pixbufLoader)
233 	{
234 		foreach ( void delegate(PixbufLoader) dlg ; _pixbufLoader.onAreaPreparedListeners )
235 		{
236 			dlg(_pixbufLoader);
237 		}
238 	}
239 	
240 	void delegate(gint, gint, gint, gint, PixbufLoader)[] onAreaUpdatedListeners;
241 	/**
242 	 * This signal is emitted when a significant area of the image being
243 	 * loaded has been updated. Normally it means that a complete
244 	 * scanline has been read in, but it could be a different area as
245 	 * well. Applications can use this signal to know when to repaint
246 	 * areas of an image that is being loaded.
247 	 */
248 	void addOnAreaUpdated(void delegate(gint, gint, gint, gint, PixbufLoader) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
249 	{
250 		if ( !("area-updated" in connectedSignals) )
251 		{
252 			Signals.connectData(
253 			getStruct(),
254 			"area-updated",
255 			cast(GCallback)&callBackAreaUpdated,
256 			cast(void*)this,
257 			null,
258 			connectFlags);
259 			connectedSignals["area-updated"] = 1;
260 		}
261 		onAreaUpdatedListeners ~= dlg;
262 	}
263 	extern(C) static void callBackAreaUpdated(GdkPixbufLoader* loaderStruct, gint x, gint y, gint width, gint height, PixbufLoader _pixbufLoader)
264 	{
265 		foreach ( void delegate(gint, gint, gint, gint, PixbufLoader) dlg ; _pixbufLoader.onAreaUpdatedListeners )
266 		{
267 			dlg(x, y, width, height, _pixbufLoader);
268 		}
269 	}
270 	
271 	void delegate(PixbufLoader)[] onClosedListeners;
272 	/**
273 	 * This signal is emitted when gdk_pixbuf_loader_close() is called.
274 	 * It can be used by different parts of an application to receive
275 	 * notification when an image loader is closed by the code that
276 	 * drives it.
277 	 */
278 	void addOnClosed(void delegate(PixbufLoader) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
279 	{
280 		if ( !("closed" in connectedSignals) )
281 		{
282 			Signals.connectData(
283 			getStruct(),
284 			"closed",
285 			cast(GCallback)&callBackClosed,
286 			cast(void*)this,
287 			null,
288 			connectFlags);
289 			connectedSignals["closed"] = 1;
290 		}
291 		onClosedListeners ~= dlg;
292 	}
293 	extern(C) static void callBackClosed(GdkPixbufLoader* loaderStruct, PixbufLoader _pixbufLoader)
294 	{
295 		foreach ( void delegate(PixbufLoader) dlg ; _pixbufLoader.onClosedListeners )
296 		{
297 			dlg(_pixbufLoader);
298 		}
299 	}
300 	
301 	void delegate(gint, gint, PixbufLoader)[] onSizePreparedListeners;
302 	/**
303 	 * This signal is emitted when the pixbuf loader has been fed the
304 	 * initial amount of data that is required to figure out the size
305 	 * of the image that it will create. Applications can call
306 	 * gdk_pixbuf_loader_set_size() in response to this signal to set
307 	 * the desired size to which the image should be scaled.
308 	 * See Also
309 	 * gdk_pixbuf_new_from_file(), gdk_pixbuf_animation_new_from_file()
310 	 */
311 	void addOnSizePrepared(void delegate(gint, gint, PixbufLoader) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
312 	{
313 		if ( !("size-prepared" in connectedSignals) )
314 		{
315 			Signals.connectData(
316 			getStruct(),
317 			"size-prepared",
318 			cast(GCallback)&callBackSizePrepared,
319 			cast(void*)this,
320 			null,
321 			connectFlags);
322 			connectedSignals["size-prepared"] = 1;
323 		}
324 		onSizePreparedListeners ~= dlg;
325 	}
326 	extern(C) static void callBackSizePrepared(GdkPixbufLoader* loaderStruct, gint width, gint height, PixbufLoader _pixbufLoader)
327 	{
328 		foreach ( void delegate(gint, gint, PixbufLoader) dlg ; _pixbufLoader.onSizePreparedListeners )
329 		{
330 			dlg(width, height, _pixbufLoader);
331 		}
332 	}
333 	
334 	
335 	/**
336 	 * Creates a new pixbuf loader object.
337 	 * Throws: ConstructionException GTK+ fails to create the object.
338 	 */
339 	public this ()
340 	{
341 		// GdkPixbufLoader * gdk_pixbuf_loader_new (void);
342 		auto p = gdk_pixbuf_loader_new();
343 		if(p is null)
344 		{
345 			throw new ConstructionException("null returned by gdk_pixbuf_loader_new()");
346 		}
347 		this(cast(GdkPixbufLoader*) p);
348 	}
349 	
350 	/**
351 	 * Obtains the available information about the format of the
352 	 * currently loading image file.
353 	 * Since 2.2
354 	 * Returns: A GdkPixbufFormat or NULL. The return value is owned by GdkPixbuf and should not be freed. [transfer none]
355 	 */
356 	public PixbufFormat getFormat()
357 	{
358 		// GdkPixbufFormat * gdk_pixbuf_loader_get_format (GdkPixbufLoader *loader);
359 		auto p = gdk_pixbuf_loader_get_format(gdkPixbufLoader);
360 		
361 		if(p is null)
362 		{
363 			return null;
364 		}
365 		
366 		return ObjectG.getDObject!(PixbufFormat)(cast(GdkPixbufFormat*) p);
367 	}
368 	
369 	/**
370 	 * This will cause a pixbuf loader to parse the next count bytes of
371 	 * an image. It will return TRUE if the data was loaded successfully,
372 	 * and FALSE if an error occurred. In the latter case, the loader
373 	 * will be closed, and will not accept further writes. If FALSE is
374 	 * returned, error will be set to an error from the GDK_PIXBUF_ERROR
375 	 * or G_FILE_ERROR domains.
376 	 * Params:
377 	 * buf = Pointer to image data. [array length=count]
378 	 * Returns: TRUE if the write was successful, or FALSE if the loader cannot parse the buffer.
379 	 * Throws: GException on failure.
380 	 */
381 	public int write(char[] buf)
382 	{
383 		// gboolean gdk_pixbuf_loader_write (GdkPixbufLoader *loader,  const guchar *buf,  gsize count,  GError **error);
384 		GError* err = null;
385 		
386 		auto p = gdk_pixbuf_loader_write(gdkPixbufLoader, buf.ptr, cast(int) buf.length, &err);
387 		
388 		if (err !is null)
389 		{
390 			throw new GException( new ErrorG(err) );
391 		}
392 		
393 		return p;
394 	}
395 	
396 	/**
397 	 * This will cause a pixbuf loader to parse a buffer inside a GBytes
398 	 * for an image. It will return TRUE if the data was loaded successfully,
399 	 * and FALSE if an error occurred. In the latter case, the loader
400 	 * will be closed, and will not accept further writes. If FALSE is
401 	 * returned, error will be set to an error from the GDK_PIXBUF_ERROR
402 	 * or G_FILE_ERROR domains.
403 	 * See also: gdk_pixbuf_loader_write()
404 	 * Since 2.30
405 	 * Params:
406 	 * buffer = The image data as a GBytes
407 	 * Returns: TRUE if the write was successful, or FALSE if the loader cannot parse the buffer.
408 	 * Throws: GException on failure.
409 	 */
410 	public int writeBytes(Bytes buffer)
411 	{
412 		// gboolean gdk_pixbuf_loader_write_bytes (GdkPixbufLoader *loader,  GBytes *buffer,  GError **error);
413 		GError* err = null;
414 		
415 		auto p = gdk_pixbuf_loader_write_bytes(gdkPixbufLoader, (buffer is null) ? null : buffer.getBytesStruct(), &err);
416 		
417 		if (err !is null)
418 		{
419 			throw new GException( new ErrorG(err) );
420 		}
421 		
422 		return p;
423 	}
424 	
425 	/**
426 	 * Causes the image to be scaled while it is loaded. The desired
427 	 * image size can be determined relative to the original size of
428 	 * the image by calling gdk_pixbuf_loader_set_size() from a
429 	 * signal handler for the ::size-prepared signal.
430 	 * Attempts to set the desired image size are ignored after the
431 	 * emission of the ::size-prepared signal.
432 	 * Since 2.2
433 	 * Params:
434 	 * width = The desired width of the image being loaded.
435 	 * height = The desired height of the image being loaded.
436 	 */
437 	public void setSize(int width, int height)
438 	{
439 		// void gdk_pixbuf_loader_set_size (GdkPixbufLoader *loader,  int width,  int height);
440 		gdk_pixbuf_loader_set_size(gdkPixbufLoader, width, height);
441 	}
442 	
443 	/**
444 	 * Queries the GdkPixbuf that a pixbuf loader is currently creating.
445 	 * In general it only makes sense to call this function after the
446 	 * "area-prepared" signal has been emitted by the loader; this means
447 	 * that enough data has been read to know the size of the image that
448 	 * will be allocated. If the loader has not received enough data via
449 	 * gdk_pixbuf_loader_write(), then this function returns NULL. The
450 	 * returned pixbuf will be the same in all future calls to the loader,
451 	 * so simply calling g_object_ref() should be sufficient to continue
452 	 * using it. Additionally, if the loader is an animation, it will
453 	 * return the "static image" of the animation
454 	 * (see gdk_pixbuf_animation_get_static_image()).
455 	 * Returns: The GdkPixbuf that the loader is creating, or NULL if not enough data has been read to determine how to create the image buffer. [transfer none]
456 	 */
457 	public Pixbuf getPixbuf()
458 	{
459 		// GdkPixbuf * gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader);
460 		auto p = gdk_pixbuf_loader_get_pixbuf(gdkPixbufLoader);
461 		
462 		if(p is null)
463 		{
464 			return null;
465 		}
466 		
467 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
468 	}
469 	
470 	/**
471 	 * Queries the GdkPixbufAnimation that a pixbuf loader is currently creating.
472 	 * In general it only makes sense to call this function after the "area-prepared"
473 	 * signal has been emitted by the loader. If the loader doesn't have enough
474 	 * bytes yet (hasn't emitted the "area-prepared" signal) this function will
475 	 * return NULL.
476 	 * Returns: The GdkPixbufAnimation that the loader is loading, or NULL if not enough data has been read to determine the information. [transfer none]
477 	 */
478 	public PixbufAnimation getAnimation()
479 	{
480 		// GdkPixbufAnimation * gdk_pixbuf_loader_get_animation (GdkPixbufLoader *loader);
481 		auto p = gdk_pixbuf_loader_get_animation(gdkPixbufLoader);
482 		
483 		if(p is null)
484 		{
485 			return null;
486 		}
487 		
488 		return ObjectG.getDObject!(PixbufAnimation)(cast(GdkPixbufAnimation*) p);
489 	}
490 	
491 	/**
492 	 * Informs a pixbuf loader that no further writes with
493 	 * gdk_pixbuf_loader_write() will occur, so that it can free its
494 	 * internal loading structures. Also, tries to parse any data that
495 	 * hasn't yet been parsed; if the remaining data is partial or
496 	 * corrupt, an error will be returned. If FALSE is returned, error
497 	 * will be set to an error from the GDK_PIXBUF_ERROR or G_FILE_ERROR
498 	 * domains. If you're just cancelling a load rather than expecting it
499 	 * to be finished, passing NULL for error to ignore it is
500 	 * reasonable.
501 	 * Remember that this does not unref the loader, so if you plan not to
502 	 * use it anymore, please g_object_unref() it.
503 	 * Returns: TRUE if all image data written so far was successfully passed out via the update_area signal Signal Details The "area-prepared" signal void user_function (GdkPixbufLoader *loader, gpointer user_data) : Run Last This signal is emitted when the pixbuf loader has allocated the pixbuf in the desired size. After this signal is emitted, applications can call gdk_pixbuf_loader_get_pixbuf() to fetch the partially-loaded pixbuf.
504 	 * Throws: GException on failure.
505 	 */
506 	public int close()
507 	{
508 		// gboolean gdk_pixbuf_loader_close (GdkPixbufLoader *loader,  GError **error);
509 		GError* err = null;
510 		
511 		auto p = gdk_pixbuf_loader_close(gdkPixbufLoader, &err);
512 		
513 		if (err !is null)
514 		{
515 			throw new GException( new ErrorG(err) );
516 		}
517 		
518 		return p;
519 	}
520 }