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 module gtk.Image;
26 
27 private import gdk.PaintableIF;
28 private import gdkpixbuf.Pixbuf;
29 private import gio.IconIF;
30 private import glib.ConstructionException;
31 private import glib.Str;
32 private import glib.c.functions;
33 private import gobject.ObjectG;
34 private import gtk.Widget;
35 private import gtk.c.functions;
36 public  import gtk.c.types;
37 
38 
39 /**
40  * The `GtkImage` widget displays an image.
41  * 
42  * ![An example GtkImage](image.png)
43  * 
44  * Various kinds of object can be displayed as an image; most typically,
45  * you would load a `GdkTexture` from a file, using the convenience function
46  * [ctor@Gtk.Image.new_from_file], for instance:
47  * 
48  * ```c
49  * GtkWidget *image = gtk_image_new_from_file ("myfile.png");
50  * ```
51  * 
52  * If the file isn’t loaded successfully, the image will contain a
53  * “broken image” icon similar to that used in many web browsers.
54  * 
55  * If you want to handle errors in loading the file yourself,
56  * for example by displaying an error message, then load the image with
57  * [ctor@Gdk.Texture.new_from_file], then create the `GtkImage` with
58  * [ctor@Gtk.Image.new_from_paintable].
59  * 
60  * Sometimes an application will want to avoid depending on external data
61  * files, such as image files. See the documentation of `GResource` inside
62  * GIO, for details. In this case, [property@Gtk.Image:resource],
63  * [ctor@Gtk.Image.new_from_resource], and [method@Gtk.Image.set_from_resource]
64  * should be used.
65  * 
66  * `GtkImage` displays its image as an icon, with a size that is determined
67  * by the application. See [class@Gtk.Picture] if you want to show an image
68  * at is actual size.
69  * 
70  * ## CSS nodes
71  * 
72  * `GtkImage` has a single CSS node with the name `image`. The style classes
73  * `.normal-icons` or `.large-icons` may appear, depending on the
74  * [property@Gtk.Image:icon-size] property.
75  * 
76  * ## Accessibility
77  * 
78  * `GtkImage` uses the `GTK_ACCESSIBLE_ROLE_IMG` role.
79  */
80 public class Image : Widget
81 {
82 	/** the main Gtk struct */
83 	protected GtkImage* gtkImage;
84 
85 	/** Get the main Gtk struct */
86 	public GtkImage* getImageStruct(bool transferOwnership = false)
87 	{
88 		if (transferOwnership)
89 			ownedRef = false;
90 		return gtkImage;
91 	}
92 
93 	/** the main Gtk struct as a void* */
94 	protected override void* getStruct()
95 	{
96 		return cast(void*)gtkImage;
97 	}
98 
99 	/**
100 	 * Sets our main struct and passes it to the parent class.
101 	 */
102 	public this (GtkImage* gtkImage, bool ownedRef = false)
103 	{
104 		this.gtkImage = gtkImage;
105 		super(cast(GtkWidget*)gtkImage, ownedRef);
106 	}
107 
108 
109 	/** */
110 	public static GType getType()
111 	{
112 		return gtk_image_get_type();
113 	}
114 
115 	/**
116 	 * Creates a new empty `GtkImage` widget.
117 	 *
118 	 * Returns: a newly created `GtkImage` widget.
119 	 *
120 	 * Throws: ConstructionException GTK+ fails to create the object.
121 	 */
122 	public this()
123 	{
124 		auto __p = gtk_image_new();
125 
126 		if(__p is null)
127 		{
128 			throw new ConstructionException("null returned by new");
129 		}
130 
131 		this(cast(GtkImage*) __p);
132 	}
133 
134 	/**
135 	 * Creates a new `GtkImage` displaying the file @filename.
136 	 *
137 	 * If the file isn’t found or can’t be loaded, the resulting `GtkImage`
138 	 * will display a “broken image” icon. This function never returns %NULL,
139 	 * it always returns a valid `GtkImage` widget.
140 	 *
141 	 * If you need to detect failures to load the file, use
142 	 * [ctor@Gdk.Texture.new_from_file] to load the file yourself,
143 	 * then create the `GtkImage` from the texture.
144 	 *
145 	 * The storage type (see [method@Gtk.Image.get_storage_type])
146 	 * of the returned image is not defined, it will be whatever
147 	 * is appropriate for displaying the file.
148 	 *
149 	 * Params:
150 	 *     filename = a filename
151 	 *
152 	 * Returns: a new `GtkImage`
153 	 *
154 	 * Throws: ConstructionException GTK+ fails to create the object.
155 	 */
156 	public this(string filename)
157 	{
158 		auto __p = gtk_image_new_from_file(Str.toStringz(filename));
159 
160 		if(__p is null)
161 		{
162 			throw new ConstructionException("null returned by new_from_file");
163 		}
164 
165 		this(cast(GtkImage*) __p);
166 	}
167 
168 	/**
169 	 * Creates a `GtkImage` displaying an icon from the current icon theme.
170 	 *
171 	 * If the icon name isn’t known, a “broken image” icon will be
172 	 * displayed instead. If the current icon theme is changed, the icon
173 	 * will be updated appropriately.
174 	 *
175 	 * Params:
176 	 *     icon = an icon
177 	 *
178 	 * Returns: a new `GtkImage` displaying the themed icon
179 	 *
180 	 * Throws: ConstructionException GTK+ fails to create the object.
181 	 */
182 	public this(IconIF icon)
183 	{
184 		auto __p = gtk_image_new_from_gicon((icon is null) ? null : icon.getIconStruct());
185 
186 		if(__p is null)
187 		{
188 			throw new ConstructionException("null returned by new_from_gicon");
189 		}
190 
191 		this(cast(GtkImage*) __p);
192 	}
193 
194 	/**
195 	 * Creates a new `GtkImage` displaying @paintable.
196 	 *
197 	 * The `GtkImage` does not assume a reference to the paintable; you still
198 	 * need to unref it if you own references. `GtkImage` will add its own
199 	 * reference rather than adopting yours.
200 	 *
201 	 * The `GtkImage` will track changes to the @paintable and update
202 	 * its size and contents in response to it.
203 	 *
204 	 * Params:
205 	 *     paintable = a `GdkPaintable`, or %NULL
206 	 *
207 	 * Returns: a new `GtkImage`
208 	 *
209 	 * Throws: ConstructionException GTK+ fails to create the object.
210 	 */
211 	public this(PaintableIF paintable)
212 	{
213 		auto __p = gtk_image_new_from_paintable((paintable is null) ? null : paintable.getPaintableStruct());
214 
215 		if(__p is null)
216 		{
217 			throw new ConstructionException("null returned by new_from_paintable");
218 		}
219 
220 		this(cast(GtkImage*) __p);
221 	}
222 
223 	/**
224 	 * Creates a new `GtkImage` displaying @pixbuf.
225 	 *
226 	 * The `GtkImage` does not assume a reference to the pixbuf; you still
227 	 * need to unref it if you own references. `GtkImage` will add its own
228 	 * reference rather than adopting yours.
229 	 *
230 	 * This is a helper for [ctor@Gtk.Image.new_from_paintable], and you can't
231 	 * get back the exact pixbuf once this is called, only a texture.
232 	 *
233 	 * Note that this function just creates an `GtkImage` from the pixbuf.
234 	 * The `GtkImage` created will not react to state changes. Should you
235 	 * want that, you should use [ctor@Gtk.Image.new_from_icon_name].
236 	 *
237 	 * Params:
238 	 *     pixbuf = a `GdkPixbuf`, or %NULL
239 	 *
240 	 * Returns: a new `GtkImage`
241 	 *
242 	 * Throws: ConstructionException GTK+ fails to create the object.
243 	 */
244 	public this(Pixbuf pixbuf)
245 	{
246 		auto __p = gtk_image_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct());
247 
248 		if(__p is null)
249 		{
250 			throw new ConstructionException("null returned by new_from_pixbuf");
251 		}
252 
253 		this(cast(GtkImage*) __p);
254 	}
255 
256 	/**
257 	 * Resets the image to be empty.
258 	 */
259 	public void clear()
260 	{
261 		gtk_image_clear(gtkImage);
262 	}
263 
264 	/**
265 	 * Gets the `GIcon` being displayed by the `GtkImage`.
266 	 *
267 	 * The storage type of the image must be %GTK_IMAGE_EMPTY or
268 	 * %GTK_IMAGE_GICON (see [method@Gtk.Image.get_storage_type]).
269 	 * The caller of this function does not own a reference to the
270 	 * returned `GIcon`.
271 	 *
272 	 * Returns: a `GIcon`, or %NULL
273 	 */
274 	public IconIF getGicon()
275 	{
276 		auto __p = gtk_image_get_gicon(gtkImage);
277 
278 		if(__p is null)
279 		{
280 			return null;
281 		}
282 
283 		return ObjectG.getDObject!(IconIF)(cast(GIcon*) __p);
284 	}
285 
286 	/**
287 	 * Gets the icon name and size being displayed by the `GtkImage`.
288 	 *
289 	 * The storage type of the image must be %GTK_IMAGE_EMPTY or
290 	 * %GTK_IMAGE_ICON_NAME (see [method@Gtk.Image.get_storage_type]).
291 	 * The returned string is owned by the `GtkImage` and should not
292 	 * be freed.
293 	 *
294 	 * Returns: the icon name, or %NULL
295 	 */
296 	public string getIconName()
297 	{
298 		return Str.toString(gtk_image_get_icon_name(gtkImage));
299 	}
300 
301 	/**
302 	 * Gets the icon size used by the @image when rendering icons.
303 	 *
304 	 * Returns: the image size used by icons
305 	 */
306 	public GtkIconSize getIconSize()
307 	{
308 		return gtk_image_get_icon_size(gtkImage);
309 	}
310 
311 	/**
312 	 * Gets the image `GdkPaintable` being displayed by the `GtkImage`.
313 	 *
314 	 * The storage type of the image must be %GTK_IMAGE_EMPTY or
315 	 * %GTK_IMAGE_PAINTABLE (see [method@Gtk.Image.get_storage_type]).
316 	 * The caller of this function does not own a reference to the
317 	 * returned paintable.
318 	 *
319 	 * Returns: the displayed paintable,
320 	 *     or %NULL if the image is empty
321 	 */
322 	public PaintableIF getPaintable()
323 	{
324 		auto __p = gtk_image_get_paintable(gtkImage);
325 
326 		if(__p is null)
327 		{
328 			return null;
329 		}
330 
331 		return ObjectG.getDObject!(PaintableIF)(cast(GdkPaintable*) __p);
332 	}
333 
334 	/**
335 	 * Gets the pixel size used for named icons.
336 	 *
337 	 * Returns: the pixel size used for named icons.
338 	 */
339 	public int getPixelSize()
340 	{
341 		return gtk_image_get_pixel_size(gtkImage);
342 	}
343 
344 	/**
345 	 * Gets the type of representation being used by the `GtkImage`
346 	 * to store image data.
347 	 *
348 	 * If the `GtkImage` has no image data, the return value will
349 	 * be %GTK_IMAGE_EMPTY.
350 	 *
351 	 * Returns: image representation being used
352 	 */
353 	public GtkImageType getStorageType()
354 	{
355 		return gtk_image_get_storage_type(gtkImage);
356 	}
357 
358 	/**
359 	 * Sets a `GtkImage` to show a file.
360 	 *
361 	 * See [ctor@Gtk.Image.new_from_file] for details.
362 	 *
363 	 * Params:
364 	 *     filename = a filename or %NULL
365 	 */
366 	public void setFromFile(string filename)
367 	{
368 		gtk_image_set_from_file(gtkImage, Str.toStringz(filename));
369 	}
370 
371 	/**
372 	 * Sets a `GtkImage` to show a `GIcon`.
373 	 *
374 	 * See [ctor@Gtk.Image.new_from_gicon] for details.
375 	 *
376 	 * Params:
377 	 *     icon = an icon
378 	 */
379 	public void setFromGicon(IconIF icon)
380 	{
381 		gtk_image_set_from_gicon(gtkImage, (icon is null) ? null : icon.getIconStruct());
382 	}
383 
384 	/**
385 	 * Sets a `GtkImage` to show a named icon.
386 	 *
387 	 * See [ctor@Gtk.Image.new_from_icon_name] for details.
388 	 *
389 	 * Params:
390 	 *     iconName = an icon name or %NULL
391 	 */
392 	public void setFromIconName(string iconName)
393 	{
394 		gtk_image_set_from_icon_name(gtkImage, Str.toStringz(iconName));
395 	}
396 
397 	/**
398 	 * Sets a `GtkImage` to show a `GdkPaintable`.
399 	 *
400 	 * See [ctor@Gtk.Image.new_from_paintable] for details.
401 	 *
402 	 * Params:
403 	 *     paintable = a `GdkPaintable` or %NULL
404 	 */
405 	public void setFromPaintable(PaintableIF paintable)
406 	{
407 		gtk_image_set_from_paintable(gtkImage, (paintable is null) ? null : paintable.getPaintableStruct());
408 	}
409 
410 	/**
411 	 * Sets a `GtkImage` to show a `GdkPixbuf`.
412 	 *
413 	 * See [ctor@Gtk.Image.new_from_pixbuf] for details.
414 	 *
415 	 * Note: This is a helper for [method@Gtk.Image.set_from_paintable],
416 	 * and you can't get back the exact pixbuf once this is called,
417 	 * only a paintable.
418 	 *
419 	 * Params:
420 	 *     pixbuf = a `GdkPixbuf` or `NULL`
421 	 */
422 	public void setFromPixbuf(Pixbuf pixbuf)
423 	{
424 		gtk_image_set_from_pixbuf(gtkImage, (pixbuf is null) ? null : pixbuf.getPixbufStruct());
425 	}
426 
427 	/**
428 	 * Sets a `GtkImage` to show a resource.
429 	 *
430 	 * See [ctor@Gtk.Image.new_from_resource] for details.
431 	 *
432 	 * Params:
433 	 *     resourcePath = a resource path or %NULL
434 	 */
435 	public void setFromResource(string resourcePath)
436 	{
437 		gtk_image_set_from_resource(gtkImage, Str.toStringz(resourcePath));
438 	}
439 
440 	/**
441 	 * Suggests an icon size to the theme for named icons.
442 	 *
443 	 * Params:
444 	 *     iconSize = the new icon size
445 	 */
446 	public void setIconSize(GtkIconSize iconSize)
447 	{
448 		gtk_image_set_icon_size(gtkImage, iconSize);
449 	}
450 
451 	/**
452 	 * Sets the pixel size to use for named icons.
453 	 *
454 	 * If the pixel size is set to a value != -1, it is used instead
455 	 * of the icon size set by [method@Gtk.Image.set_from_icon_name].
456 	 *
457 	 * Params:
458 	 *     pixelSize = the new pixel size
459 	 */
460 	public void setPixelSize(int pixelSize)
461 	{
462 		gtk_image_set_pixel_size(gtkImage, pixelSize);
463 	}
464 }