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.IconSet;
26 
27 private import cairo.Surface;
28 private import gdk.Window;
29 private import gdkpixbuf.Pixbuf;
30 private import glib.ConstructionException;
31 private import glib.Str;
32 private import gobject.ObjectG;
33 private import gtk.IconSource;
34 private import gtk.Style;
35 private import gtk.StyleContext;
36 private import gtk.Widget;
37 private import gtkc.Loader;
38 private import gtkc.gtk;
39 public  import gtkc.gtktypes;
40 private import gtkc.paths;
41 
42 
43 /** */
44 public class IconSet
45 {
46 	/** the main Gtk struct */
47 	protected GtkIconSet* gtkIconSet;
48 	protected bool ownedRef;
49 
50 	/** Get the main Gtk struct */
51 	public GtkIconSet* getIconSetStruct()
52 	{
53 		return gtkIconSet;
54 	}
55 
56 	/** the main Gtk struct as a void* */
57 	protected void* getStruct()
58 	{
59 		return cast(void*)gtkIconSet;
60 	}
61 
62 	/**
63 	 * Sets our main struct and passes it to the parent class.
64 	 */
65 	public this (GtkIconSet* gtkIconSet, bool ownedRef = false)
66 	{
67 		this.gtkIconSet = gtkIconSet;
68 		this.ownedRef = ownedRef;
69 	}
70 
71 	~this ()
72 	{
73 		if (  Linker.isLoaded(LIBRARY.GTK) && ownedRef )
74 		{
75 			gtk_icon_set_unref(gtkIconSet);
76 		}
77 	}
78 
79 	/**
80 	 */
81 
82 	/** */
83 	public static GType getType()
84 	{
85 		return gtk_icon_set_get_type();
86 	}
87 
88 	/**
89 	 * Creates a new #GtkIconSet. A #GtkIconSet represents a single icon
90 	 * in various sizes and widget states. It can provide a #GdkPixbuf
91 	 * for a given size and state on request, and automatically caches
92 	 * some of the rendered #GdkPixbuf objects.
93 	 *
94 	 * Normally you would use gtk_widget_render_icon_pixbuf() instead of
95 	 * using #GtkIconSet directly. The one case where you’d use
96 	 * #GtkIconSet is to create application-specific icon sets to place in
97 	 * a #GtkIconFactory.
98 	 *
99 	 * Deprecated: Use #GtkIconTheme instead.
100 	 *
101 	 * Return: a new #GtkIconSet
102 	 *
103 	 * Throws: ConstructionException GTK+ fails to create the object.
104 	 */
105 	public this()
106 	{
107 		auto p = gtk_icon_set_new();
108 		
109 		if(p is null)
110 		{
111 			throw new ConstructionException("null returned by new");
112 		}
113 		
114 		this(cast(GtkIconSet*) p);
115 	}
116 
117 	/**
118 	 * Creates a new #GtkIconSet with @pixbuf as the default/fallback
119 	 * source image. If you don’t add any additional #GtkIconSource to the
120 	 * icon set, all variants of the icon will be created from @pixbuf,
121 	 * using scaling, pixelation, etc. as required to adjust the icon size
122 	 * or make the icon look insensitive/prelighted.
123 	 *
124 	 * Deprecated: Use #GtkIconTheme instead.
125 	 *
126 	 * Params:
127 	 *     pixbuf = a #GdkPixbuf
128 	 *
129 	 * Return: a new #GtkIconSet
130 	 *
131 	 * Throws: ConstructionException GTK+ fails to create the object.
132 	 */
133 	public this(Pixbuf pixbuf)
134 	{
135 		auto p = gtk_icon_set_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct());
136 		
137 		if(p is null)
138 		{
139 			throw new ConstructionException("null returned by new_from_pixbuf");
140 		}
141 		
142 		this(cast(GtkIconSet*) p);
143 	}
144 
145 	/**
146 	 * Icon sets have a list of #GtkIconSource, which they use as base
147 	 * icons for rendering icons in different states and sizes. Icons are
148 	 * scaled, made to look insensitive, etc. in
149 	 * gtk_icon_set_render_icon(), but #GtkIconSet needs base images to
150 	 * work with. The base images and when to use them are described by
151 	 * a #GtkIconSource.
152 	 *
153 	 * This function copies @source, so you can reuse the same source immediately
154 	 * without affecting the icon set.
155 	 *
156 	 * An example of when you’d use this function: a web browser’s "Back
157 	 * to Previous Page" icon might point in a different direction in
158 	 * Hebrew and in English; it might look different when insensitive;
159 	 * and it might change size depending on toolbar mode (small/large
160 	 * icons). So a single icon set would contain all those variants of
161 	 * the icon, and you might add a separate source for each one.
162 	 *
163 	 * You should nearly always add a “default” icon source with all
164 	 * fields wildcarded, which will be used as a fallback if no more
165 	 * specific source matches. #GtkIconSet always prefers more specific
166 	 * icon sources to more generic icon sources. The order in which you
167 	 * add the sources to the icon set does not matter.
168 	 *
169 	 * gtk_icon_set_new_from_pixbuf() creates a new icon set with a
170 	 * default icon source based on the given pixbuf.
171 	 *
172 	 * Deprecated: Use #GtkIconTheme instead.
173 	 *
174 	 * Params:
175 	 *     source = a #GtkIconSource
176 	 */
177 	public void addSource(IconSource source)
178 	{
179 		gtk_icon_set_add_source(gtkIconSet, (source is null) ? null : source.getIconSourceStruct());
180 	}
181 
182 	/**
183 	 * Copies @icon_set by value.
184 	 *
185 	 * Deprecated: Use #GtkIconTheme instead.
186 	 *
187 	 * Return: a new #GtkIconSet identical to the first.
188 	 */
189 	public IconSet copy()
190 	{
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, true);
199 	}
200 
201 	/**
202 	 * Obtains a list of icon sizes this icon set can render. The returned
203 	 * array must be freed with g_free().
204 	 *
205 	 * Deprecated: Use #GtkIconTheme instead.
206 	 *
207 	 * Params:
208 	 *     sizes = return location
209 	 *         for array of sizes (#GtkIconSize)
210 	 *     nSizes = location to store number of elements in returned array
211 	 */
212 	public void getSizes(out GtkIconSize[] sizes)
213 	{
214 		GtkIconSize* outsizes = null;
215 		int nSizes;
216 		
217 		gtk_icon_set_get_sizes(gtkIconSet, &outsizes, &nSizes);
218 		
219 		sizes = outsizes[0 .. nSizes];
220 	}
221 
222 	/**
223 	 * Increments the reference count on @icon_set.
224 	 *
225 	 * Deprecated: Use #GtkIconTheme instead.
226 	 *
227 	 * Return: @icon_set.
228 	 */
229 	public IconSet doref()
230 	{
231 		auto p = gtk_icon_set_ref(gtkIconSet);
232 		
233 		if(p is null)
234 		{
235 			return null;
236 		}
237 		
238 		return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p, true);
239 	}
240 
241 	/**
242 	 * Renders an icon using gtk_style_render_icon(). In most cases,
243 	 * gtk_widget_render_icon() is better, since it automatically provides
244 	 * most of the arguments from the current widget settings.  This
245 	 * function never returns %NULL; if the icon can’t be rendered
246 	 * (perhaps because an image file fails to load), a default "missing
247 	 * image" icon will be returned instead.
248 	 *
249 	 * Deprecated: Use gtk_icon_set_render_icon_pixbuf() instead
250 	 *
251 	 * Params:
252 	 *     style = a #GtkStyle associated with @widget, or %NULL
253 	 *     direction = text direction
254 	 *     state = widget state
255 	 *     size = icon size (#GtkIconSize). A size of `(GtkIconSize)-1`
256 	 *         means render at the size of the source and don’t scale.
257 	 *     widget = widget that will display the icon, or %NULL.
258 	 *         The only use that is typically made of this
259 	 *         is to determine the appropriate #GdkScreen.
260 	 *     detail = detail to pass to the theme engine, or %NULL.
261 	 *         Note that passing a detail of anything but %NULL
262 	 *         will disable caching.
263 	 *
264 	 * Return: a #GdkPixbuf to be displayed
265 	 */
266 	public Pixbuf renderIcon(Style style, GtkTextDirection direction, GtkStateType state, GtkIconSize size, Widget widget, string detail)
267 	{
268 		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));
269 		
270 		if(p is null)
271 		{
272 			return null;
273 		}
274 		
275 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p, true);
276 	}
277 
278 	/**
279 	 * Renders an icon using gtk_render_icon_pixbuf(). In most cases,
280 	 * gtk_widget_render_icon_pixbuf() is better, since it automatically provides
281 	 * most of the arguments from the current widget settings.  This
282 	 * function never returns %NULL; if the icon can’t be rendered
283 	 * (perhaps because an image file fails to load), a default "missing
284 	 * image" icon will be returned instead.
285 	 *
286 	 * Deprecated: Use #GtkIconTheme instead.
287 	 *
288 	 * Params:
289 	 *     context = a #GtkStyleContext
290 	 *     size = icon size (#GtkIconSize). A size of `(GtkIconSize)-1`
291 	 *         means render at the size of the source and don’t scale.
292 	 *
293 	 * Return: a #GdkPixbuf to be displayed
294 	 *
295 	 * Since: 3.0
296 	 */
297 	public Pixbuf renderIconPixbuf(StyleContext context, GtkIconSize size)
298 	{
299 		auto p = gtk_icon_set_render_icon_pixbuf(gtkIconSet, (context is null) ? null : context.getStyleContextStruct(), size);
300 		
301 		if(p is null)
302 		{
303 			return null;
304 		}
305 		
306 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p, true);
307 	}
308 
309 	/**
310 	 * Renders an icon using gtk_render_icon_pixbuf() and converts it to a
311 	 * cairo surface.
312 	 *
313 	 * This function never returns %NULL; if the icon can’t be rendered
314 	 * (perhaps because an image file fails to load), a default "missing
315 	 * image" icon will be returned instead.
316 	 *
317 	 * Deprecated: Use #GtkIconTheme instead.
318 	 *
319 	 * Params:
320 	 *     context = a #GtkStyleContext
321 	 *     size = icon size (#GtkIconSize). A size of `(GtkIconSize)-1`
322 	 *         means render at the size of the source and don’t scale.
323 	 *     scale = the window scale to render for
324 	 *     forWindow = #GdkWindow to optimize drawing for, or %NULL
325 	 *
326 	 * Return: a #cairo_surface_t to be displayed
327 	 *
328 	 * Since: 3.10
329 	 */
330 	public Surface renderIconSurface(StyleContext context, GtkIconSize size, int scale, Window forWindow)
331 	{
332 		auto p = gtk_icon_set_render_icon_surface(gtkIconSet, (context is null) ? null : context.getStyleContextStruct(), size, scale, (forWindow is null) ? null : forWindow.getWindowStruct());
333 		
334 		if(p is null)
335 		{
336 			return null;
337 		}
338 		
339 		return new Surface(cast(cairo_surface_t*) p);
340 	}
341 
342 	/**
343 	 * Decrements the reference count on @icon_set, and frees memory
344 	 * if the reference count reaches 0.
345 	 *
346 	 * Deprecated: Use #GtkIconTheme instead.
347 	 */
348 	public void unref()
349 	{
350 		gtk_icon_set_unref(gtkIconSet);
351 	}
352 }