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: No
35  * interface Code: No
36  * template for:
37  * extend  = 
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  * 	- gtk.IconSource
48  * 	- gdk.Pixbuf
49  * 	- gtk.Style
50  * 	- gtk.Widget
51  * structWrap:
52  * 	- GdkPixbuf* -> Pixbuf
53  * 	- GtkIconSet* -> IconSet
54  * 	- GtkIconSource* -> IconSource
55  * 	- GtkStyle* -> Style
56  * 	- GtkWidget* -> Widget
57  * module aliases:
58  * local aliases:
59  * overrides:
60  */
61 
62 module gtk.IconSet;
63 
64 public  import gtkc.gtktypes;
65 
66 private import gtkc.gtk;
67 private import glib.ConstructionException;
68 private import gobject.ObjectG;
69 
70 
71 private import glib.Str;
72 private import gtk.IconSource;
73 private import gdk.Pixbuf;
74 private import gtk.Style;
75 private import gtk.Widget;
76 
77 
78 
79 
80 /**
81  * Description
82  * Browse the available stock icons in the list of stock IDs found here. You can also use
83  * the gtk-demo application for this purpose.
84  *  An icon factory manages a collection of GtkIconSet; a GtkIconSet manages a
85  *  set of variants of a particular icon (i.e. a GtkIconSet contains variants for
86  *  different sizes and widget states). Icons in an icon factory are named by a
87  *  stock ID, which is a simple string identifying the icon. Each GtkStyle has a
88  *  list of GtkIconFactory derived from the current theme; those icon factories
89  *  are consulted first when searching for an icon. If the theme doesn't set a
90  *  particular icon, GTK+ looks for the icon in a list of default icon factories,
91  *  maintained by gtk_icon_factory_add_default() and
92  *  gtk_icon_factory_remove_default(). Applications with icons should add a default
93  *  icon factory with their icons, which will allow themes to override the icons
94  *  for the application.
95  * To display an icon, always use gtk_style_lookup_icon_set() on the widget that
96  * will display the icon, or the convenience function
97  * gtk_widget_render_icon(). These functions take the theme into account when
98  * looking up the icon to use for a given stock ID.
99  * GtkIconFactory as GtkBuildable
100  * GtkIconFactory supports a custom <sources> element, which
101  * can contain multiple <source> elements.
102  * The following attributes are allowed:
103  * stock-id
104  * The stock id of the source, a string.
105  * This attribute is mandatory
106  * filename
107  * The filename of the source, a string.
108  * This attribute is optional
109  * icon-name
110  * The icon name for the source, a string.
111  * This attribute is optional.
112  * size
113  * Size of the icon, a GtkIconSize enum value.
114  * This attribute is optional.
115  * direction
116  * Direction of the source, a GtkTextDirection enum value.
117  * This attribute is optional.
118  * state
119  * State of the source, a GtkStateType enum value.
120  * This attribute is optional.
121  * $(DDOC_COMMENT example)
122  */
123 public class IconSet
124 {
125 	
126 	/** the main Gtk struct */
127 	protected GtkIconSet* gtkIconSet;
128 	
129 	
130 	public GtkIconSet* getIconSetStruct()
131 	{
132 		return gtkIconSet;
133 	}
134 	
135 	
136 	/** the main Gtk struct as a void* */
137 	protected void* getStruct()
138 	{
139 		return cast(void*)gtkIconSet;
140 	}
141 	
142 	/**
143 	 * Sets our main struct and passes it to the parent class
144 	 */
145 	public this (GtkIconSet* gtkIconSet)
146 	{
147 		this.gtkIconSet = gtkIconSet;
148 	}
149 	
150 	/**
151 	 */
152 	
153 	/**
154 	 * Icon sets have a list of GtkIconSource, which they use as base
155 	 * icons for rendering icons in different states and sizes. Icons are
156 	 * scaled, made to look insensitive, etc. in
157 	 * gtk_icon_set_render_icon(), but GtkIconSet needs base images to
158 	 * work with. The base images and when to use them are described by
159 	 * a GtkIconSource.
160 	 * This function copies source, so you can reuse the same source immediately
161 	 * without affecting the icon set.
162 	 * An example of when you'd use this function: a web browser's "Back
163 	 * to Previous Page" icon might point in a different direction in
164 	 * Hebrew and in English; it might look different when insensitive;
165 	 * and it might change size depending on toolbar mode (small/large
166 	 * icons). So a single icon set would contain all those variants of
167 	 * the icon, and you might add a separate source for each one.
168 	 * You should nearly always add a "default" icon source with all
169 	 * fields wildcarded, which will be used as a fallback if no more
170 	 * specific source matches. GtkIconSet always prefers more specific
171 	 * icon sources to more generic icon sources. The order in which you
172 	 * add the sources to the icon set does not matter.
173 	 * gtk_icon_set_new_from_pixbuf() creates a new icon set with a
174 	 * default icon source based on the given pixbuf.
175 	 * Params:
176 	 * source = a GtkIconSource
177 	 */
178 	public void addSource(IconSource source)
179 	{
180 		// void gtk_icon_set_add_source (GtkIconSet *icon_set,  const GtkIconSource *source);
181 		gtk_icon_set_add_source(gtkIconSet, (source is null) ? null : source.getIconSourceStruct());
182 	}
183 	
184 	/**
185 	 * Copies icon_set by value.
186 	 * Returns: a new GtkIconSet identical to the first.
187 	 */
188 	public IconSet copy()
189 	{
190 		// GtkIconSet* gtk_icon_set_copy (GtkIconSet *icon_set);
191 		auto p = gtk_icon_set_copy(gtkIconSet);
192 		
193 		if(p is null)
194 		{
195 			return null;
196 		}
197 		
198 		return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p);
199 	}
200 	
201 	/**
202 	 * Creates a new GtkIconSet. A GtkIconSet represents a single icon
203 	 * in various sizes and widget states. It can provide a GdkPixbuf
204 	 * for a given size and state on request, and automatically caches
205 	 * some of the rendered GdkPixbuf objects.
206 	 * Normally you would use gtk_widget_render_icon() instead of
207 	 * using GtkIconSet directly. The one case where you'd use
208 	 * GtkIconSet is to create application-specific icon sets to place in
209 	 * a GtkIconFactory.
210 	 * Throws: ConstructionException GTK+ fails to create the object.
211 	 */
212 	public this ()
213 	{
214 		// GtkIconSet* gtk_icon_set_new (void);
215 		auto p = gtk_icon_set_new();
216 		if(p is null)
217 		{
218 			throw new ConstructionException("null returned by gtk_icon_set_new()");
219 		}
220 		this(cast(GtkIconSet*) p);
221 	}
222 	
223 	/**
224 	 * Creates a new GtkIconSet with pixbuf as the default/fallback
225 	 * source image. If you don't add any additional GtkIconSource to the
226 	 * icon set, all variants of the icon will be created from pixbuf,
227 	 * using scaling, pixelation, etc. as required to adjust the icon size
228 	 * or make the icon look insensitive/prelighted.
229 	 * Params:
230 	 * pixbuf = a GdkPixbuf
231 	 * Throws: ConstructionException GTK+ fails to create the object.
232 	 */
233 	public this (Pixbuf pixbuf)
234 	{
235 		// GtkIconSet* gtk_icon_set_new_from_pixbuf (GdkPixbuf *pixbuf);
236 		auto p = gtk_icon_set_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct());
237 		if(p is null)
238 		{
239 			throw new ConstructionException("null returned by gtk_icon_set_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct())");
240 		}
241 		this(cast(GtkIconSet*) p);
242 	}
243 	
244 	/**
245 	 * Increments the reference count on icon_set.
246 	 * Returns: icon_set.
247 	 */
248 	public IconSet doref()
249 	{
250 		// GtkIconSet* gtk_icon_set_ref (GtkIconSet *icon_set);
251 		auto p = gtk_icon_set_ref(gtkIconSet);
252 		
253 		if(p is null)
254 		{
255 			return null;
256 		}
257 		
258 		return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p);
259 	}
260 	
261 	/**
262 	 * Renders an icon using gtk_style_render_icon(). In most cases,
263 	 * gtk_widget_render_icon() is better, since it automatically provides
264 	 * most of the arguments from the current widget settings. This
265 	 * function never returns NULL; if the icon can't be rendered
266 	 * (perhaps because an image file fails to load), a default "missing
267 	 * image" icon will be returned instead.
268 	 * Params:
269 	 * style = a GtkStyle associated with widget, or NULL. [allow-none]
270 	 * direction = text direction
271 	 * state = widget state
272 	 * size = icon size. A size of (GtkIconSize)-1
273 	 *  means render at the size of the source and don't scale. [type int]
274 	 * widget = widget that will display the icon, or NULL.
275 	 *  The only use that is typically made of this
276 	 *  is to determine the appropriate GdkScreen. [allow-none]
277 	 * detail = detail to pass to the theme engine, or NULL.
278 	 *  Note that passing a detail of anything but NULL
279 	 *  will disable caching. [allow-none]
280 	 * Returns: a GdkPixbuf to be displayed
281 	 */
282 	public Pixbuf renderIcon(Style style, GtkTextDirection direction, GtkStateType state, GtkIconSize size, Widget widget, string detail)
283 	{
284 		// GdkPixbuf* gtk_icon_set_render_icon (GtkIconSet *icon_set,  GtkStyle *style,  GtkTextDirection direction,  GtkStateType state,  GtkIconSize size,  GtkWidget *widget,  const char *detail);
285 		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));
286 		
287 		if(p is null)
288 		{
289 			return null;
290 		}
291 		
292 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
293 	}
294 	
295 	/**
296 	 * Decrements the reference count on icon_set, and frees memory
297 	 * if the reference count reaches 0.
298 	 */
299 	public void unref()
300 	{
301 		// void gtk_icon_set_unref (GtkIconSet *icon_set);
302 		gtk_icon_set_unref(gtkIconSet);
303 	}
304 	
305 	/**
306 	 * Obtains a list of icon sizes this icon set can render. The returned
307 	 * array must be freed with g_free().
308 	 * Params:
309 	 * sizes = return location
310 	 *  for array of sizes. [array length=n_sizes][out length=n_sizes][type int]
311 	 */
312 	public void getSizes(out GtkIconSize[] sizes)
313 	{
314 		// void gtk_icon_set_get_sizes (GtkIconSet *icon_set,  GtkIconSize **sizes,  gint *n_sizes);
315 		GtkIconSize* outsizes = null;
316 		int nSizes;
317 		
318 		gtk_icon_set_get_sizes(gtkIconSet, &outsizes, &nSizes);
319 		
320 		sizes = outsizes[0 .. nSizes];
321 	}
322 }