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  = 
27  * outPack = gtk
28  * outFile = IconInfo
29  * strct   = GtkIconInfo
30  * realStrct=
31  * ctorStrct=
32  * clss    = IconInfo
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_icon_info_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ErrorG
48  * 	- glib.GException
49  * 	- gtk.IconInfo
50  * 	- gtk.IconTheme
51  * 	- gdk.Pixbuf
52  * structWrap:
53  * 	- GdkPixbuf* -> Pixbuf
54  * 	- GtkIconInfo* -> IconInfo
55  * 	- GtkIconTheme* -> IconTheme
56  * module aliases:
57  * local aliases:
58  * overrides:
59  */
60 
61 module gtk.IconInfo;
62 
63 public  import gtkc.gtktypes;
64 
65 private import gtkc.gtk;
66 private import glib.ConstructionException;
67 private import gobject.ObjectG;
68 
69 private import gobject.Signals;
70 public  import gtkc.gdktypes;
71 
72 private import glib.Str;
73 private import glib.ErrorG;
74 private import glib.GException;
75 private import gtk.IconInfo;
76 private import gtk.IconTheme;
77 private import gdk.Pixbuf;
78 
79 
80 
81 
82 /**
83  * Description
84  * GtkIconTheme provides a facility for looking up icons by name
85  * and size. The main reason for using a name rather than simply
86  * providing a filename is to allow different icons to be used
87  * depending on what icon theme is selected
88  * by the user. The operation of icon themes on Linux and Unix
89  * follows the Icon
90  * Theme Specification. There is a default icon theme,
91  * named hicolor where applications should install
92  * their icons, but more additional application themes can be
93  * installed as operating system vendors and users choose.
94  * Named icons are similar to the Themeable Stock Images(3)
95  * facility, and the distinction between the two may be a bit confusing.
96  * A few things to keep in mind:
97  * Stock images usually are used in conjunction with
98  * Stock Items(3)., such as GTK_STOCK_OK or
99  * GTK_STOCK_OPEN. Named icons are easier to set up and therefore
100  * are more useful for new icons that an application wants to
101  * add, such as application icons or window icons.
102  * Stock images can only be loaded at the symbolic sizes defined
103  * by the GtkIconSize enumeration, or by custom sizes defined
104  * by gtk_icon_size_register(), while named icons are more flexible
105  * and any pixel size can be specified.
106  * Because stock images are closely tied to stock items, and thus
107  * to actions in the user interface, stock images may come in
108  * multiple variants for different widget states or writing
109  * directions.
110  * A good rule of thumb is that if there is a stock image for what
111  * you want to use, use it, otherwise use a named icon. It turns
112  * out that internally stock images are generally defined in
113  * terms of one or more named icons. (An example of the
114  * more than one case is icons that depend on writing direction;
115  * GTK_STOCK_GO_FORWARD uses the two themed icons
116  * "gtk-stock-go-forward-ltr" and "gtk-stock-go-forward-rtl".)
117  * In many cases, named themes are used indirectly, via GtkImage
118  * or stock items, rather than directly, but looking up icons
119  * directly is also simple. The GtkIconTheme object acts
120  * as a database of all the icons in the current theme. You
121  * can create new GtkIconTheme objects, but its much more
122  * efficient to use the standard icon theme for the GdkScreen
123  * so that the icon information is shared with other people
124  * looking up icons. In the case where the default screen is
125  * being used, looking up an icon can be as simple as:
126  * $(DDOC_COMMENT example)
127  */
128 public class IconInfo
129 {
130 	
131 	/** the main Gtk struct */
132 	protected GtkIconInfo* gtkIconInfo;
133 	
134 	
135 	public GtkIconInfo* getIconInfoStruct()
136 	{
137 		return gtkIconInfo;
138 	}
139 	
140 	
141 	/** the main Gtk struct as a void* */
142 	protected void* getStruct()
143 	{
144 		return cast(void*)gtkIconInfo;
145 	}
146 	
147 	/**
148 	 * Sets our main struct and passes it to the parent class
149 	 */
150 	public this (GtkIconInfo* gtkIconInfo)
151 	{
152 		this.gtkIconInfo = gtkIconInfo;
153 	}
154 	
155 	/**
156 	 */
157 	int[string] connectedSignals;
158 	
159 	void delegate(IconInfo)[] onChangedListeners;
160 	/**
161 	 * Emitted when the current icon theme is switched or GTK+ detects
162 	 * that a change has occurred in the contents of the current
163 	 * icon theme.
164 	 */
165 	void addOnChanged(void delegate(IconInfo) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
166 	{
167 		if ( !("changed" in connectedSignals) )
168 		{
169 			Signals.connectData(
170 			getStruct(),
171 			"changed",
172 			cast(GCallback)&callBackChanged,
173 			cast(void*)this,
174 			null,
175 			connectFlags);
176 			connectedSignals["changed"] = 1;
177 		}
178 		onChangedListeners ~= dlg;
179 	}
180 	extern(C) static void callBackChanged(GtkIconTheme* iconThemeStruct, IconInfo _iconInfo)
181 	{
182 		foreach ( void delegate(IconInfo) dlg ; _iconInfo.onChangedListeners )
183 		{
184 			dlg(_iconInfo);
185 		}
186 	}
187 	
188 	
189 	/**
190 	 * Make a copy of a GtkIconInfo.
191 	 * Since 2.4
192 	 * Returns: the new GtkIconInfo
193 	 */
194 	public IconInfo copy()
195 	{
196 		// GtkIconInfo * gtk_icon_info_copy (GtkIconInfo *icon_info);
197 		auto p = gtk_icon_info_copy(gtkIconInfo);
198 		
199 		if(p is null)
200 		{
201 			return null;
202 		}
203 		
204 		return ObjectG.getDObject!(IconInfo)(cast(GtkIconInfo*) p);
205 	}
206 	
207 	/**
208 	 * Free a GtkIconInfo and associated information
209 	 * Since 2.4
210 	 */
211 	public void free()
212 	{
213 		// void gtk_icon_info_free (GtkIconInfo *icon_info);
214 		gtk_icon_info_free(gtkIconInfo);
215 	}
216 	
217 	/**
218 	 * Creates a GtkIconInfo for a GdkPixbuf.
219 	 * Since 2.14
220 	 * Params:
221 	 * iconTheme = a GtkIconTheme
222 	 * pixbuf = the pixbuf to wrap in a GtkIconInfo
223 	 * Throws: ConstructionException GTK+ fails to create the object.
224 	 */
225 	public this (IconTheme iconTheme, Pixbuf pixbuf)
226 	{
227 		// GtkIconInfo * gtk_icon_info_new_for_pixbuf (GtkIconTheme *icon_theme,  GdkPixbuf *pixbuf);
228 		auto p = gtk_icon_info_new_for_pixbuf((iconTheme is null) ? null : iconTheme.getIconThemeStruct(), (pixbuf is null) ? null : pixbuf.getPixbufStruct());
229 		if(p is null)
230 		{
231 			throw new ConstructionException("null returned by gtk_icon_info_new_for_pixbuf((iconTheme is null) ? null : iconTheme.getIconThemeStruct(), (pixbuf is null) ? null : pixbuf.getPixbufStruct())");
232 		}
233 		this(cast(GtkIconInfo*) p);
234 	}
235 	
236 	/**
237 	 * Gets the base size for the icon. The base size
238 	 * is a size for the icon that was specified by
239 	 * the icon theme creator. This may be different
240 	 * than the actual size of image; an example of
241 	 * this is small emblem icons that can be attached
242 	 * to a larger icon. These icons will be given
243 	 * the same base size as the larger icons to which
244 	 * they are attached.
245 	 * Since 2.4
246 	 * Returns: the base size, or 0, if no base size is known for the icon.
247 	 */
248 	public int getBaseSize()
249 	{
250 		// gint gtk_icon_info_get_base_size (GtkIconInfo *icon_info);
251 		return gtk_icon_info_get_base_size(gtkIconInfo);
252 	}
253 	
254 	/**
255 	 * Gets the filename for the icon. If the
256 	 * GTK_ICON_LOOKUP_USE_BUILTIN flag was passed
257 	 * to gtk_icon_theme_lookup_icon(), there may be
258 	 * no filename if a builtin icon is returned; in this
259 	 * case, you should use gtk_icon_info_get_builtin_pixbuf().
260 	 * Since 2.4
261 	 * Returns: the filename for the icon, or NULL if gtk_icon_info_get_builtin_pixbuf() should be used instead. The return value is owned by GTK+ and should not be modified or freed.
262 	 */
263 	public string getFilename()
264 	{
265 		// const gchar * gtk_icon_info_get_filename (GtkIconInfo *icon_info);
266 		return Str.toString(gtk_icon_info_get_filename(gtkIconInfo));
267 	}
268 	
269 	/**
270 	 * Gets the built-in image for this icon, if any. To allow
271 	 * GTK+ to use built in icon images, you must pass the
272 	 * GTK_ICON_LOOKUP_USE_BUILTIN to
273 	 * gtk_icon_theme_lookup_icon().
274 	 * Since 2.4
275 	 * Returns: the built-in image pixbuf, or NULL. No extra reference is added to the returned pixbuf, so if you want to keep it around, you must use g_object_ref(). The returned image must not be modified. [transfer none]
276 	 */
277 	public Pixbuf getBuiltinPixbuf()
278 	{
279 		// GdkPixbuf * gtk_icon_info_get_builtin_pixbuf (GtkIconInfo *icon_info);
280 		auto p = gtk_icon_info_get_builtin_pixbuf(gtkIconInfo);
281 		
282 		if(p is null)
283 		{
284 			return null;
285 		}
286 		
287 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
288 	}
289 	
290 	/**
291 	 * Renders an icon previously looked up in an icon theme using
292 	 * gtk_icon_theme_lookup_icon(); the size will be based on the size
293 	 * passed to gtk_icon_theme_lookup_icon(). Note that the resulting
294 	 * pixbuf may not be exactly this size; an icon theme may have icons
295 	 * that differ slightly from their nominal sizes, and in addition GTK+
296 	 * will avoid scaling icons that it considers sufficiently close to the
297 	 * requested size or for which the source image would have to be scaled
298 	 * up too far. (This maintains sharpness.). This behaviour can be changed
299 	 * by passing the GTK_ICON_LOOKUP_FORCE_SIZE flag when obtaining
300 	 * the GtkIconInfo. If this flag has been specified, the pixbuf
301 	 * returned by this function will be scaled to the exact size.
302 	 * Since 2.4
303 	 * Returns: the rendered icon; this may be a newly created icon or a new reference to an internal icon, so you must not modify the icon. Use g_object_unref() to release your reference to the icon.
304 	 * Throws: GException on failure.
305 	 */
306 	public Pixbuf loadIcon()
307 	{
308 		// GdkPixbuf * gtk_icon_info_load_icon (GtkIconInfo *icon_info,  GError **error);
309 		GError* err = null;
310 		
311 		auto p = gtk_icon_info_load_icon(gtkIconInfo, &err);
312 		
313 		if (err !is null)
314 		{
315 			throw new GException( new ErrorG(err) );
316 		}
317 		
318 		
319 		if(p is null)
320 		{
321 			return null;
322 		}
323 		
324 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
325 	}
326 	
327 	/**
328 	 * Sets whether the coordinates returned by gtk_icon_info_get_embedded_rect()
329 	 * and gtk_icon_info_get_attach_points() should be returned in their
330 	 * original form as specified in the icon theme, instead of scaled
331 	 * appropriately for the pixbuf returned by gtk_icon_info_load_icon().
332 	 * Raw coordinates are somewhat strange; they are specified to be with
333 	 * respect to the unscaled pixmap for PNG and XPM icons, but for SVG
334 	 * icons, they are in a 1000x1000 coordinate space that is scaled
335 	 * to the final size of the icon. You can determine if the icon is an SVG
336 	 * icon by using gtk_icon_info_get_filename(), and seeing if it is non-NULL
337 	 * and ends in '.svg'.
338 	 * This function is provided primarily to allow compatibility wrappers
339 	 * for older API's, and is not expected to be useful for applications.
340 	 * Since 2.4
341 	 * Params:
342 	 * rawCoordinates = whether the coordinates of embedded rectangles
343 	 *  and attached points should be returned in their original
344 	 *  (unscaled) form.
345 	 */
346 	public void setRawCoordinates(int rawCoordinates)
347 	{
348 		// void gtk_icon_info_set_raw_coordinates (GtkIconInfo *icon_info,  gboolean raw_coordinates);
349 		gtk_icon_info_set_raw_coordinates(gtkIconInfo, rawCoordinates);
350 	}
351 	
352 	/**
353 	 * Gets the coordinates of a rectangle within the icon
354 	 * that can be used for display of information such
355 	 * as a preview of the contents of a text file.
356 	 * See gtk_icon_info_set_raw_coordinates() for further
357 	 * information about the coordinate system.
358 	 * Since 2.4
359 	 * Params:
360 	 * rectangle = GdkRectangle in which to store embedded
361 	 *  rectangle coordinates; coordinates are only stored
362 	 *  when this function returns TRUE.
363 	 * Returns: TRUE if the icon has an embedded rectangle
364 	 */
365 	public int getEmbeddedRect(out GdkRectangle rectangle)
366 	{
367 		// gboolean gtk_icon_info_get_embedded_rect (GtkIconInfo *icon_info,  GdkRectangle *rectangle);
368 		return gtk_icon_info_get_embedded_rect(gtkIconInfo, &rectangle);
369 	}
370 	
371 	/**
372 	 * Fetches the set of attach points for an icon. An attach point
373 	 * is a location in the icon that can be used as anchor points for attaching
374 	 * emblems or overlays to the icon.
375 	 * Since 2.4
376 	 * Params:
377 	 * points = location to store pointer to an array of points, or NULL
378 	 *  free the array of points with g_free(). [allow-none][out]
379 	 * Returns: TRUE if there are any attach points for the icon.
380 	 */
381 	public int getAttachPoints(out GdkPoint[] points)
382 	{
383 		// gboolean gtk_icon_info_get_attach_points (GtkIconInfo *icon_info,  GdkPoint **points,  gint *n_points);
384 		GdkPoint* outpoints = null;
385 		int nPoints;
386 		
387 		auto p = gtk_icon_info_get_attach_points(gtkIconInfo, &outpoints, &nPoints);
388 		
389 		points = outpoints[0 .. nPoints];
390 		return p;
391 	}
392 	
393 	/**
394 	 * Gets the display name for an icon. A display name is a
395 	 * string to be used in place of the icon name in a user
396 	 * visible context like a list of icons.
397 	 * Since 2.4
398 	 * Signal Details
399 	 * The "changed" signal
400 	 * void user_function (GtkIconTheme *icon_theme,
401 	 *  gpointer user_data) : Run Last
402 	 * Emitted when the current icon theme is switched or GTK+ detects
403 	 * that a change has occurred in the contents of the current
404 	 * icon theme.
405 	 * Returns: the display name for the icon or NULL, if the icon doesn't have a specified display name. This value is owned icon_info and must not be modified or free.
406 	 */
407 	public string getDisplayName()
408 	{
409 		// const gchar * gtk_icon_info_get_display_name (GtkIconInfo *icon_info);
410 		return Str.toString(gtk_icon_info_get_display_name(gtkIconInfo));
411 	}
412 }