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 	/**
220 	 * Increments the reference count on @icon_set.
221 	 *
222 	 * Deprecated: Use #GtkIconTheme instead.
223 	 *
224 	 * Returns: @icon_set.
225 	 */
226 	public IconSet doref()
227 	{
228 		auto p = gtk_icon_set_ref(gtkIconSet);
229 
230 		if(p is null)
231 		{
232 			return null;
233 		}
234 
235 		return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p, true);
236 	}
237 
238 	/**
239 	 * Renders an icon using gtk_style_render_icon(). In most cases,
240 	 * gtk_widget_render_icon() is better, since it automatically provides
241 	 * most of the arguments from the current widget settings.  This
242 	 * function never returns %NULL; if the icon can’t be rendered
243 	 * (perhaps because an image file fails to load), a default "missing
244 	 * image" icon will be returned instead.
245 	 *
246 	 * Deprecated: Use gtk_icon_set_render_icon_pixbuf() instead
247 	 *
248 	 * Params:
249 	 *     style = a #GtkStyle associated with @widget, or %NULL
250 	 *     direction = text direction
251 	 *     state = widget state
252 	 *     size = icon size (#GtkIconSize). A size of `(GtkIconSize)-1`
253 	 *         means render at the size of the source and don’t scale.
254 	 *     widget = widget that will display the icon, or %NULL.
255 	 *         The only use that is typically made of this
256 	 *         is to determine the appropriate #GdkScreen.
257 	 *     detail = detail to pass to the theme engine, or %NULL.
258 	 *         Note that passing a detail of anything but %NULL
259 	 *         will disable caching.
260 	 *
261 	 * Returns: a #GdkPixbuf to be displayed
262 	 */
263 	public Pixbuf renderIcon(Style style, GtkTextDirection direction, GtkStateType state, GtkIconSize size, Widget widget, string detail)
264 	{
265 		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));
266 
267 		if(p is null)
268 		{
269 			return null;
270 		}
271 
272 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p, true);
273 	}
274 
275 	/**
276 	 * Renders an icon using gtk_render_icon_pixbuf(). In most cases,
277 	 * gtk_widget_render_icon_pixbuf() is better, since it automatically provides
278 	 * most of the arguments from the current widget settings.  This
279 	 * function never returns %NULL; if the icon can’t be rendered
280 	 * (perhaps because an image file fails to load), a default "missing
281 	 * image" icon will be returned instead.
282 	 *
283 	 * Deprecated: Use #GtkIconTheme instead.
284 	 *
285 	 * Params:
286 	 *     context = a #GtkStyleContext
287 	 *     size = icon size (#GtkIconSize). A size of `(GtkIconSize)-1`
288 	 *         means render at the size of the source and don’t scale.
289 	 *
290 	 * Returns: a #GdkPixbuf to be displayed
291 	 *
292 	 * Since: 3.0
293 	 */
294 	public Pixbuf renderIconPixbuf(StyleContext context, GtkIconSize size)
295 	{
296 		auto p = gtk_icon_set_render_icon_pixbuf(gtkIconSet, (context is null) ? null : context.getStyleContextStruct(), size);
297 
298 		if(p is null)
299 		{
300 			return null;
301 		}
302 
303 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p, true);
304 	}
305 
306 	/**
307 	 * Renders an icon using gtk_render_icon_pixbuf() and converts it to a
308 	 * cairo surface.
309 	 *
310 	 * This function never returns %NULL; if the icon can’t be rendered
311 	 * (perhaps because an image file fails to load), a default "missing
312 	 * image" icon will be returned instead.
313 	 *
314 	 * Deprecated: Use #GtkIconTheme instead.
315 	 *
316 	 * Params:
317 	 *     context = a #GtkStyleContext
318 	 *     size = icon size (#GtkIconSize). A size of `(GtkIconSize)-1`
319 	 *         means render at the size of the source and don’t scale.
320 	 *     scale = the window scale to render for
321 	 *     forWindow = #GdkWindow to optimize drawing for, or %NULL
322 	 *
323 	 * Returns: a #cairo_surface_t to be displayed
324 	 *
325 	 * Since: 3.10
326 	 */
327 	public Surface renderIconSurface(StyleContext context, GtkIconSize size, int scale, Window forWindow)
328 	{
329 		auto p = gtk_icon_set_render_icon_surface(gtkIconSet, (context is null) ? null : context.getStyleContextStruct(), size, scale, (forWindow is null) ? null : forWindow.getWindowStruct());
330 
331 		if(p is null)
332 		{
333 			return null;
334 		}
335 
336 		return new Surface(cast(cairo_surface_t*) p);
337 	}
338 
339 	/**
340 	 * Decrements the reference count on @icon_set, and frees memory
341 	 * if the reference count reaches 0.
342 	 *
343 	 * Deprecated: Use #GtkIconTheme instead.
344 	 */
345 	public void unref()
346 	{
347 		gtk_icon_set_unref(gtkIconSet);
348 	}
349 }