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 = IconSet
29  * strct   = GtkIconSet
30  * realStrct=
31  * ctorStrct=
32  * clss    = IconSet
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = GBoxed
38  * implements:
39  * prefixes:
40  * 	- gtk_icon_set_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- cairo.Surface
48  * 	- gdk.Pixbuf
49  * 	- gtk.IconSource
50  * 	- gtk.Style
51  * 	- gtk.StyleContext
52  * 	- gtk.Widget
53  * 	- gdk.Window
54  * 	- gtkc.paths
55  * 	- gtkc.Loader
56  * structWrap:
57  * 	- GdkPixbuf* -> Pixbuf
58  * 	- GdkWindow* -> Window
59  * 	- GtkIconSet* -> IconSet
60  * 	- GtkIconSource* -> IconSource
61  * 	- GtkStyle* -> Style
62  * 	- GtkStyleContext* -> StyleContext
63  * 	- GtkWidget* -> Widget
64  * 	- cairo_surface_t* -> Surface
65  * module aliases:
66  * local aliases:
67  * overrides:
68  */
69 
70 module gtk.IconSet;
71 
72 public  import gtkc.gtktypes;
73 
74 private import gtkc.gtk;
75 private import glib.ConstructionException;
76 private import gobject.ObjectG;
77 
78 
79 private import glib.Str;
80 private import cairo.Surface;
81 private import gdk.Pixbuf;
82 private import gtk.IconSource;
83 private import gtk.Style;
84 private import gtk.StyleContext;
85 private import gtk.Widget;
86 private import gdk.Window;
87 private import gtkc.paths;
88 private import gtkc.Loader;
89 
90 
91 
92 private import gobject.Boxed;
93 
94 /**
95  * Browse the available stock icons in the list of stock IDs found here. You can also use
96  * the gtk-demo application for this purpose.
97  *
98  * An icon factory manages a collection of GtkIconSet; a GtkIconSet manages a
99  * set of variants of a particular icon (i.e. a GtkIconSet contains variants for
100  * different sizes and widget states). Icons in an icon factory are named by a
101  * stock ID, which is a simple string identifying the icon. Each GtkStyle has a
102  * list of GtkIconFactory derived from the current theme; those icon factories
103  * are consulted first when searching for an icon. If the theme doesn't set a
104  * particular icon, GTK+ looks for the icon in a list of default icon factories,
105  * maintained by gtk_icon_factory_add_default() and
106  * gtk_icon_factory_remove_default(). Applications with icons should add a default
107  * icon factory with their icons, which will allow themes to override the icons
108  * for the application.
109  *
110  * To display an icon, always use gtk_style_lookup_icon_set() on the widget that
111  * will display the icon, or the convenience function
112  * gtk_widget_render_icon(). These functions take the theme into account when
113  * looking up the icon to use for a given stock ID.
114  *
115  * GtkIconFactory as GtkBuildable
116  *
117  * GtkIconFactory supports a custom <sources> element, which can contain
118  * multiple <source> elements.
119  * The following attributes are allowed:
120  *
121  * stock-id
122  *
123  * The stock id of the source, a string.
124  * This attribute is mandatory
125  *
126  * filename
127  *
128  * The filename of the source, a string.
129  * This attribute is optional
130  *
131  * icon-name
132  *
133  * The icon name for the source, a string.
134  * This attribute is optional.
135  *
136  * size
137  *
138  * Size of the icon, a GtkIconSize enum value.
139  * This attribute is optional.
140  *
141  * direction
142  *
143  * Direction of the source, a GtkTextDirection enum value.
144  * This attribute is optional.
145  *
146  * state
147  *
148  * State of the source, a GtkStateType enum value.
149  * This attribute is optional.
150  *
151  * $(DDOC_COMMENT example)
152  */
153 public class IconSet : Boxed
154 {
155 	
156 	/** the main Gtk struct */
157 	protected GtkIconSet* gtkIconSet;
158 	
159 	
160 	public GtkIconSet* getIconSetStruct()
161 	{
162 		return gtkIconSet;
163 	}
164 	
165 	
166 	/** the main Gtk struct as a void* */
167 	protected void* getStruct()
168 	{
169 		return cast(void*)gtkIconSet;
170 	}
171 	
172 	/**
173 	 * Sets our main struct and passes it to the parent class
174 	 */
175 	public this (GtkIconSet* gtkIconSet)
176 	{
177 		this.gtkIconSet = gtkIconSet;
178 	}
179 	
180 	~this ()
181 	{
182 		if (  Linker.isLoaded(LIBRARY.GTK) && gtkIconSet !is null )
183 		{
184 			gtk_icon_set_unref(gtkIconSet);
185 		}
186 	}
187 	
188 	/**
189 	 */
190 	
191 	/**
192 	 * Warning
193 	 * gtk_icon_set_add_source has been deprecated since version 3.10 and should not be used in newly-written code. Use GtkIconTheme instead.
194 	 * Icon sets have a list of GtkIconSource, which they use as base
195 	 * icons for rendering icons in different states and sizes. Icons are
196 	 * scaled, made to look insensitive, etc. in
197 	 * gtk_icon_set_render_icon(), but GtkIconSet needs base images to
198 	 * work with. The base images and when to use them are described by
199 	 * a GtkIconSource.
200 	 * This function copies source, so you can reuse the same source immediately
201 	 * without affecting the icon set.
202 	 * An example of when you'd use this function: a web browser's "Back
203 	 * to Previous Page" icon might point in a different direction in
204 	 * Hebrew and in English; it might look different when insensitive;
205 	 * and it might change size depending on toolbar mode (small/large
206 	 * icons). So a single icon set would contain all those variants of
207 	 * the icon, and you might add a separate source for each one.
208 	 * You should nearly always add a "default" icon source with all
209 	 * fields wildcarded, which will be used as a fallback if no more
210 	 * specific source matches. GtkIconSet always prefers more specific
211 	 * icon sources to more generic icon sources. The order in which you
212 	 * add the sources to the icon set does not matter.
213 	 * gtk_icon_set_new_from_pixbuf() creates a new icon set with a
214 	 * default icon source based on the given pixbuf.
215 	 * Params:
216 	 * source = a GtkIconSource
217 	 */
218 	public void addSource(IconSource source)
219 	{
220 		// void gtk_icon_set_add_source (GtkIconSet *icon_set,  const GtkIconSource *source);
221 		gtk_icon_set_add_source(gtkIconSet, (source is null) ? null : source.getIconSourceStruct());
222 	}
223 	
224 	/**
225 	 * Warning
226 	 * gtk_icon_set_copy has been deprecated since version 3.10 and should not be used in newly-written code. Use GtkIconTheme instead.
227 	 * Copies icon_set by value.
228 	 * Returns: a new GtkIconSet identical to the first.
229 	 */
230 	public IconSet copy()
231 	{
232 		// GtkIconSet * gtk_icon_set_copy (GtkIconSet *icon_set);
233 		auto p = gtk_icon_set_copy(gtkIconSet);
234 		
235 		if(p is null)
236 		{
237 			return null;
238 		}
239 		
240 		return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p);
241 	}
242 	
243 	/**
244 	 * Warning
245 	 * gtk_icon_set_new has been deprecated since version 3.10 and should not be used in newly-written code. Use GtkIconTheme instead.
246 	 * Creates a new GtkIconSet. A GtkIconSet represents a single icon
247 	 * in various sizes and widget states. It can provide a GdkPixbuf
248 	 * for a given size and state on request, and automatically caches
249 	 * some of the rendered GdkPixbuf objects.
250 	 * Normally you would use gtk_widget_render_icon_pixbuf() instead of
251 	 * using GtkIconSet directly. The one case where you'd use
252 	 * GtkIconSet is to create application-specific icon sets to place in
253 	 * a GtkIconFactory.
254 	 * Throws: ConstructionException GTK+ fails to create the object.
255 	 */
256 	public this ()
257 	{
258 		// GtkIconSet * gtk_icon_set_new (void);
259 		auto p = gtk_icon_set_new();
260 		if(p is null)
261 		{
262 			throw new ConstructionException("null returned by gtk_icon_set_new()");
263 		}
264 		this(cast(GtkIconSet*) p);
265 	}
266 	
267 	/**
268 	 * Warning
269 	 * gtk_icon_set_new_from_pixbuf has been deprecated since version 3.10 and should not be used in newly-written code. Use GtkIconTheme instead.
270 	 * Creates a new GtkIconSet with pixbuf as the default/fallback
271 	 * source image. If you don't add any additional GtkIconSource to the
272 	 * icon set, all variants of the icon will be created from pixbuf,
273 	 * using scaling, pixelation, etc. as required to adjust the icon size
274 	 * or make the icon look insensitive/prelighted.
275 	 * Params:
276 	 * pixbuf = a GdkPixbuf
277 	 * Throws: ConstructionException GTK+ fails to create the object.
278 	 */
279 	public this (Pixbuf pixbuf)
280 	{
281 		// GtkIconSet * gtk_icon_set_new_from_pixbuf (GdkPixbuf *pixbuf);
282 		auto p = gtk_icon_set_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct());
283 		if(p is null)
284 		{
285 			throw new ConstructionException("null returned by gtk_icon_set_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct())");
286 		}
287 		this(cast(GtkIconSet*) p);
288 	}
289 	
290 	/**
291 	 * Warning
292 	 * gtk_icon_set_ref has been deprecated since version 3.10 and should not be used in newly-written code. Use GtkIconTheme instead.
293 	 * Increments the reference count on icon_set.
294 	 * Returns: icon_set.
295 	 */
296 	public IconSet doref()
297 	{
298 		// GtkIconSet * gtk_icon_set_ref (GtkIconSet *icon_set);
299 		auto p = gtk_icon_set_ref(gtkIconSet);
300 		
301 		if(p is null)
302 		{
303 			return null;
304 		}
305 		
306 		return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p);
307 	}
308 	
309 	/**
310 	 * Warning
311 	 * gtk_icon_set_render_icon has been deprecated since version 3.0 and should not be used in newly-written code. Use gtk_icon_set_render_icon_pixbuf() instead
312 	 * Renders an icon using gtk_style_render_icon(). In most cases,
313 	 * gtk_widget_render_icon() is better, since it automatically provides
314 	 * most of the arguments from the current widget settings. This
315 	 * function never returns NULL; if the icon can't be rendered
316 	 * (perhaps because an image file fails to load), a default "missing
317 	 * image" icon will be returned instead.
318 	 * Params:
319 	 * style = a GtkStyle associated with widget, or NULL. [allow-none]
320 	 * direction = text direction
321 	 * state = widget state
322 	 * size = icon size. A size of (GtkIconSize)-1
323 	 * means render at the size of the source and don't scale. [type int]
324 	 * widget = widget that will display the icon, or NULL.
325 	 * The only use that is typically made of this
326 	 * is to determine the appropriate GdkScreen. [allow-none]
327 	 * detail = detail to pass to the theme engine, or NULL.
328 	 * Note that passing a detail of anything but NULL
329 	 * will disable caching. [allow-none]
330 	 * Returns: a GdkPixbuf to be displayed. [transfer full]
331 	 */
332 	public Pixbuf renderIcon(Style style, GtkTextDirection direction, GtkStateType state, GtkIconSize size, Widget widget, string detail)
333 	{
334 		// GdkPixbuf * gtk_icon_set_render_icon (GtkIconSet *icon_set,  GtkStyle *style,  GtkTextDirection direction,  GtkStateType state,  GtkIconSize size,  GtkWidget *widget,  const gchar *detail);
335 		auto p = gtk_icon_set_render_icon(gtkIconSet, (style is null) ? null : style.getStyleStruct(), direction, state, size, (widget is null) ? null : widget.getWidgetStruct(), Str.toStringz(detail));
336 		
337 		if(p is null)
338 		{
339 			return null;
340 		}
341 		
342 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
343 	}
344 	
345 	/**
346 	 * Warning
347 	 * gtk_icon_set_render_icon_pixbuf has been deprecated since version 3.10 and should not be used in newly-written code. Use GtkIconTheme instead.
348 	 * Renders an icon using gtk_render_icon_pixbuf(). In most cases,
349 	 * gtk_widget_render_icon_pixbuf() is better, since it automatically provides
350 	 * most of the arguments from the current widget settings. This
351 	 * function never returns NULL; if the icon can't be rendered
352 	 * (perhaps because an image file fails to load), a default "missing
353 	 * image" icon will be returned instead.
354 	 * Params:
355 	 * context = a GtkStyleContext
356 	 * size = icon size. A size of (GtkIconSize)-1
357 	 * means render at the size of the source and don't scale. [type int]
358 	 * Returns: a GdkPixbuf to be displayed. [transfer full] Since 3.0
359 	 */
360 	public Pixbuf renderIconPixbuf(StyleContext context, GtkIconSize size)
361 	{
362 		// GdkPixbuf * gtk_icon_set_render_icon_pixbuf (GtkIconSet *icon_set,  GtkStyleContext *context,  GtkIconSize size);
363 		auto p = gtk_icon_set_render_icon_pixbuf(gtkIconSet, (context is null) ? null : context.getStyleContextStruct(), size);
364 		
365 		if(p is null)
366 		{
367 			return null;
368 		}
369 		
370 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
371 	}
372 	
373 	/**
374 	 * Warning
375 	 * gtk_icon_set_render_icon_surface has been deprecated since version 3.10 and should not be used in newly-written code. Use GtkIconTheme instead.
376 	 * Renders an icon using gtk_render_icon_pixbuf() and converts it to a
377 	 * cairo surface.
378 	 * This function never returns NULL; if the icon can't be rendered
379 	 * (perhaps because an image file fails to load), a default "missing
380 	 * image" icon will be returned instead.
381 	 * Params:
382 	 * context = a GtkStyleContext
383 	 * size = icon size. A size of (GtkIconSize)-1
384 	 * means render at the size of the source and don't scale. [type int]
385 	 * scale = the window scale to render for
386 	 * forWindow = GdkWindow to optimize drawing for, or NULL. [allow-none]
387 	 * Returns: a cairo_surface_t to be displayed. [transfer full] Since 3.10
388 	 */
389 	public Surface renderIconSurface(StyleContext context, GtkIconSize size, int scale, Window forWindow)
390 	{
391 		// cairo_surface_t * gtk_icon_set_render_icon_surface (GtkIconSet *icon_set,  GtkStyleContext *context,  GtkIconSize size,  int scale,  GdkWindow *for_window);
392 		auto p = gtk_icon_set_render_icon_surface(gtkIconSet, (context is null) ? null : context.getStyleContextStruct(), size, scale, (forWindow is null) ? null : forWindow.getWindowStruct());
393 		
394 		if(p is null)
395 		{
396 			return null;
397 		}
398 		
399 		return ObjectG.getDObject!(Surface)(cast(cairo_surface_t*) p);
400 	}
401 	
402 	/**
403 	 * Warning
404 	 * gtk_icon_set_unref has been deprecated since version 3.10 and should not be used in newly-written code. Use GtkIconTheme instead.
405 	 * Decrements the reference count on icon_set, and frees memory
406 	 * if the reference count reaches 0.
407 	 */
408 	public void unref()
409 	{
410 		// void gtk_icon_set_unref (GtkIconSet *icon_set);
411 		gtk_icon_set_unref(gtkIconSet);
412 	}
413 	
414 	/**
415 	 * Warning
416 	 * gtk_icon_set_get_sizes has been deprecated since version 3.10 and should not be used in newly-written code. Use GtkIconTheme instead.
417 	 * Obtains a list of icon sizes this icon set can render. The returned
418 	 * array must be freed with g_free().
419 	 * Params:
420 	 * sizes = return location
421 	 * for array of sizes. [array length=n_sizes][out][type int]
422 	 */
423 	public void getSizes(out GtkIconSize[] sizes)
424 	{
425 		// void gtk_icon_set_get_sizes (GtkIconSet *icon_set,  GtkIconSize **sizes,  gint *n_sizes);
426 		GtkIconSize* outsizes = null;
427 		int nSizes;
428 		
429 		gtk_icon_set_get_sizes(gtkIconSet, &outsizes, &nSizes);
430 		
431 		sizes = outsizes[0 .. nSizes];
432 	}
433 }