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.gtk;
38 public  import gtkc.gtktypes;
39 private import gtkd.Loader;
40 
41 
42 /** */
43 public class IconSet
44 {
45 	/** the main Gtk struct */
46 	protected GtkIconSet* gtkIconSet;
47 	protected bool ownedRef;
48 
49 	/** Get the main Gtk struct */
50 	public GtkIconSet* getIconSetStruct(bool transferOwnership = false)
51 	{
52 		if (transferOwnership)
53 			ownedRef = false;
54 		return gtkIconSet;
55 	}
56 
57 	/** the main Gtk struct as a void* */
58 	protected void* getStruct()
59 	{
60 		return cast(void*)gtkIconSet;
61 	}
62 
63 	/**
64 	 * Sets our main struct and passes it to the parent class.
65 	 */
66 	public this (GtkIconSet* gtkIconSet, bool ownedRef = false)
67 	{
68 		this.gtkIconSet = gtkIconSet;
69 		this.ownedRef = ownedRef;
70 	}
71 
72 	~this ()
73 	{
74 		if (  Linker.isLoaded(LIBRARY_GTK) && ownedRef )
75 			gtk_icon_set_unref(gtkIconSet);
76 	}
77 
78 
79 	/** */
80 	public static GType getType()
81 	{
82 		return gtk_icon_set_get_type();
83 	}
84 
85 	/**
86 	 * Creates a new #GtkIconSet. A #GtkIconSet represents a single icon
87 	 * in various sizes and widget states. It can provide a #GdkPixbuf
88 	 * for a given size and state on request, and automatically caches
89 	 * some of the rendered #GdkPixbuf objects.
90 	 *
91 	 * Normally you would use gtk_widget_render_icon_pixbuf() instead of
92 	 * using #GtkIconSet directly. The one case where you’d use
93 	 * #GtkIconSet is to create application-specific icon sets to place in
94 	 * a #GtkIconFactory.
95 	 *
96 	 * Deprecated: Use #GtkIconTheme instead.
97 	 *
98 	 * Returns: a new #GtkIconSet
99 	 *
100 	 * Throws: ConstructionException GTK+ fails to create the object.
101 	 */
102 	public this()
103 	{
104 		auto p = gtk_icon_set_new();
105 		
106 		if(p is null)
107 		{
108 			throw new ConstructionException("null returned by new");
109 		}
110 		
111 		this(cast(GtkIconSet*) p);
112 	}
113 
114 	/**
115 	 * Creates a new #GtkIconSet with @pixbuf as the default/fallback
116 	 * source image. If you don’t add any additional #GtkIconSource to the
117 	 * icon set, all variants of the icon will be created from @pixbuf,
118 	 * using scaling, pixelation, etc. as required to adjust the icon size
119 	 * or make the icon look insensitive/prelighted.
120 	 *
121 	 * Deprecated: Use #GtkIconTheme instead.
122 	 *
123 	 * Params:
124 	 *     pixbuf = a #GdkPixbuf
125 	 *
126 	 * Returns: a new #GtkIconSet
127 	 *
128 	 * Throws: ConstructionException GTK+ fails to create the object.
129 	 */
130 	public this(Pixbuf pixbuf)
131 	{
132 		auto p = gtk_icon_set_new_from_pixbuf((pixbuf is null) ? null : pixbuf.getPixbufStruct());
133 		
134 		if(p is null)
135 		{
136 			throw new ConstructionException("null returned by new_from_pixbuf");
137 		}
138 		
139 		this(cast(GtkIconSet*) p);
140 	}
141 
142 	/**
143 	 * Icon sets have a list of #GtkIconSource, which they use as base
144 	 * icons for rendering icons in different states and sizes. Icons are
145 	 * scaled, made to look insensitive, etc. in
146 	 * gtk_icon_set_render_icon(), but #GtkIconSet needs base images to
147 	 * work with. The base images and when to use them are described by
148 	 * a #GtkIconSource.
149 	 *
150 	 * This function copies @source, so you can reuse the same source immediately
151 	 * without affecting the icon set.
152 	 *
153 	 * An example of when you’d use this function: a web browser’s "Back
154 	 * to Previous Page" icon might point in a different direction in
155 	 * Hebrew and in English; it might look different when insensitive;
156 	 * and it might change size depending on toolbar mode (small/large
157 	 * icons). So a single icon set would contain all those variants of
158 	 * the icon, and you might add a separate source for each one.
159 	 *
160 	 * You should nearly always add a “default” icon source with all
161 	 * fields wildcarded, which will be used as a fallback if no more
162 	 * specific source matches. #GtkIconSet always prefers more specific
163 	 * icon sources to more generic icon sources. The order in which you
164 	 * add the sources to the icon set does not matter.
165 	 *
166 	 * gtk_icon_set_new_from_pixbuf() creates a new icon set with a
167 	 * default icon source based on the given pixbuf.
168 	 *
169 	 * Deprecated: Use #GtkIconTheme instead.
170 	 *
171 	 * Params:
172 	 *     source = a #GtkIconSource
173 	 */
174 	public void addSource(IconSource source)
175 	{
176 		gtk_icon_set_add_source(gtkIconSet, (source is null) ? null : source.getIconSourceStruct());
177 	}
178 
179 	/**
180 	 * Copies @icon_set by value.
181 	 *
182 	 * Deprecated: Use #GtkIconTheme instead.
183 	 *
184 	 * Returns: a new #GtkIconSet identical to the first.
185 	 */
186 	public IconSet copy()
187 	{
188 		auto p = gtk_icon_set_copy(gtkIconSet);
189 		
190 		if(p is null)
191 		{
192 			return null;
193 		}
194 		
195 		return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p, true);
196 	}
197 
198 	/**
199 	 * Obtains a list of icon sizes this icon set can render. The returned
200 	 * array must be freed with g_free().
201 	 *
202 	 * Deprecated: Use #GtkIconTheme instead.
203 	 *
204 	 * Params:
205 	 *     sizes = return location
206 	 *         for array of sizes (#GtkIconSize)
207 	 *     nSizes = location to store number of elements in returned array
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 }