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