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