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.IconFactory;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gtk.BuildableIF;
31 private import gtk.BuildableT;
32 private import gtk.IconSet;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * An icon factory manages a collection of #GtkIconSet; a #GtkIconSet manages a
40  * set of variants of a particular icon (i.e. a #GtkIconSet contains variants for
41  * different sizes and widget states). Icons in an icon factory are named by a
42  * stock ID, which is a simple string identifying the icon. Each #GtkStyle has a
43  * list of #GtkIconFactory derived from the current theme; those icon factories
44  * are consulted first when searching for an icon. If the theme doesn’t set a
45  * particular icon, GTK+ looks for the icon in a list of default icon factories,
46  * maintained by gtk_icon_factory_add_default() and
47  * gtk_icon_factory_remove_default(). Applications with icons should add a default
48  * icon factory with their icons, which will allow themes to override the icons
49  * for the application.
50  * 
51  * To display an icon, always use gtk_style_lookup_icon_set() on the widget that
52  * will display the icon, or the convenience function
53  * gtk_widget_render_icon(). These functions take the theme into account when
54  * looking up the icon to use for a given stock ID.
55  * 
56  * # GtkIconFactory as GtkBuildable # {#GtkIconFactory-BUILDER-UI}
57  * 
58  * GtkIconFactory supports a custom <sources> element, which can contain
59  * multiple <source> elements. The following attributes are allowed:
60  * 
61  * - stock-id
62  * 
63  * The stock id of the source, a string. This attribute is
64  * mandatory
65  * 
66  * - filename
67  * 
68  * The filename of the source, a string.  This attribute is
69  * optional
70  * 
71  * - icon-name
72  * 
73  * The icon name for the source, a string.  This attribute is
74  * optional.
75  * 
76  * - size
77  * 
78  * Size of the icon, a #GtkIconSize enum value.  This attribute is
79  * optional.
80  * 
81  * - direction
82  * 
83  * Direction of the source, a #GtkTextDirection enum value.  This
84  * attribute is optional.
85  * 
86  * - state
87  * 
88  * State of the source, a #GtkStateType enum value.  This
89  * attribute is optional.
90  * 
91  * 
92  * ## A #GtkIconFactory UI definition fragment. ##
93  * 
94  * |[
95  * <object class="GtkIconFactory" id="iconfactory1">
96  * <sources>
97  * <source stock-id="apple-red" filename="apple-red.png"/>
98  * </sources>
99  * </object>
100  * <object class="GtkWindow" id="window1">
101  * <child>
102  * <object class="GtkButton" id="apple_button">
103  * <property name="label">apple-red</property>
104  * <property name="use-stock">True</property>
105  * </object>
106  * </child>
107  * </object>
108  * ]|
109  */
110 public class IconFactory : ObjectG, BuildableIF
111 {
112 	/** the main Gtk struct */
113 	protected GtkIconFactory* gtkIconFactory;
114 
115 	/** Get the main Gtk struct */
116 	public GtkIconFactory* getIconFactoryStruct(bool transferOwnership = false)
117 	{
118 		if (transferOwnership)
119 			ownedRef = false;
120 		return gtkIconFactory;
121 	}
122 
123 	/** the main Gtk struct as a void* */
124 	protected override void* getStruct()
125 	{
126 		return cast(void*)gtkIconFactory;
127 	}
128 
129 	protected override void setStruct(GObject* obj)
130 	{
131 		gtkIconFactory = cast(GtkIconFactory*)obj;
132 		super.setStruct(obj);
133 	}
134 
135 	/**
136 	 * Sets our main struct and passes it to the parent class.
137 	 */
138 	public this (GtkIconFactory* gtkIconFactory, bool ownedRef = false)
139 	{
140 		this.gtkIconFactory = gtkIconFactory;
141 		super(cast(GObject*)gtkIconFactory, ownedRef);
142 	}
143 
144 	// add the Buildable capabilities
145 	mixin BuildableT!(GtkIconFactory);
146 
147 
148 	/** */
149 	public static GType getType()
150 	{
151 		return gtk_icon_factory_get_type();
152 	}
153 
154 	/**
155 	 * Creates a new #GtkIconFactory. An icon factory manages a collection
156 	 * of #GtkIconSets; a #GtkIconSet manages a set of variants of a
157 	 * particular icon (i.e. a #GtkIconSet contains variants for different
158 	 * sizes and widget states). Icons in an icon factory are named by a
159 	 * stock ID, which is a simple string identifying the icon. Each
160 	 * #GtkStyle has a list of #GtkIconFactorys derived from the current
161 	 * theme; those icon factories are consulted first when searching for
162 	 * an icon. If the theme doesn’t set a particular icon, GTK+ looks for
163 	 * the icon in a list of default icon factories, maintained by
164 	 * gtk_icon_factory_add_default() and
165 	 * gtk_icon_factory_remove_default(). Applications with icons should
166 	 * add a default icon factory with their icons, which will allow
167 	 * themes to override the icons for the application.
168 	 *
169 	 * Deprecated: Use #GtkIconTheme instead.
170 	 *
171 	 * Returns: a new #GtkIconFactory
172 	 *
173 	 * Throws: ConstructionException GTK+ fails to create the object.
174 	 */
175 	public this()
176 	{
177 		auto p = gtk_icon_factory_new();
178 
179 		if(p is null)
180 		{
181 			throw new ConstructionException("null returned by new");
182 		}
183 
184 		this(cast(GtkIconFactory*) p, true);
185 	}
186 
187 	/**
188 	 * Looks for an icon in the list of default icon factories.  For
189 	 * display to the user, you should use gtk_style_lookup_icon_set() on
190 	 * the #GtkStyle for the widget that will display the icon, instead of
191 	 * using this function directly, so that themes are taken into
192 	 * account.
193 	 *
194 	 * Deprecated: Use #GtkIconTheme instead.
195 	 *
196 	 * Params:
197 	 *     stockId = an icon name
198 	 *
199 	 * Returns: a #GtkIconSet, or %NULL
200 	 */
201 	public static IconSet lookupDefault(string stockId)
202 	{
203 		auto p = gtk_icon_factory_lookup_default(Str.toStringz(stockId));
204 
205 		if(p is null)
206 		{
207 			return null;
208 		}
209 
210 		return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p);
211 	}
212 
213 	/**
214 	 * Adds the given @icon_set to the icon factory, under the name
215 	 * @stock_id.  @stock_id should be namespaced for your application,
216 	 * e.g. “myapp-whatever-icon”.  Normally applications create a
217 	 * #GtkIconFactory, then add it to the list of default factories with
218 	 * gtk_icon_factory_add_default(). Then they pass the @stock_id to
219 	 * widgets such as #GtkImage to display the icon. Themes can provide
220 	 * an icon with the same name (such as "myapp-whatever-icon") to
221 	 * override your application’s default icons. If an icon already
222 	 * existed in @factory for @stock_id, it is unreferenced and replaced
223 	 * with the new @icon_set.
224 	 *
225 	 * Deprecated: Use #GtkIconTheme instead.
226 	 *
227 	 * Params:
228 	 *     stockId = icon name
229 	 *     iconSet = icon set
230 	 */
231 	public void add(string stockId, IconSet iconSet)
232 	{
233 		gtk_icon_factory_add(gtkIconFactory, Str.toStringz(stockId), (iconSet is null) ? null : iconSet.getIconSetStruct());
234 	}
235 
236 	/**
237 	 * Adds an icon factory to the list of icon factories searched by
238 	 * gtk_style_lookup_icon_set(). This means that, for example,
239 	 * gtk_image_new_from_stock() will be able to find icons in @factory.
240 	 * There will normally be an icon factory added for each library or
241 	 * application that comes with icons. The default icon factories
242 	 * can be overridden by themes.
243 	 *
244 	 * Deprecated: Use #GtkIconTheme instead.
245 	 */
246 	public void addDefault()
247 	{
248 		gtk_icon_factory_add_default(gtkIconFactory);
249 	}
250 
251 	/**
252 	 * Looks up @stock_id in the icon factory, returning an icon set
253 	 * if found, otherwise %NULL. For display to the user, you should
254 	 * use gtk_style_lookup_icon_set() on the #GtkStyle for the
255 	 * widget that will display the icon, instead of using this
256 	 * function directly, so that themes are taken into account.
257 	 *
258 	 * Deprecated: Use #GtkIconTheme instead.
259 	 *
260 	 * Params:
261 	 *     stockId = an icon name
262 	 *
263 	 * Returns: icon set of @stock_id.
264 	 */
265 	public IconSet lookup(string stockId)
266 	{
267 		auto p = gtk_icon_factory_lookup(gtkIconFactory, Str.toStringz(stockId));
268 
269 		if(p is null)
270 		{
271 			return null;
272 		}
273 
274 		return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p);
275 	}
276 
277 	/**
278 	 * Removes an icon factory from the list of default icon
279 	 * factories. Not normally used; you might use it for a library that
280 	 * can be unloaded or shut down.
281 	 *
282 	 * Deprecated: Use #GtkIconTheme instead.
283 	 */
284 	public void removeDefault()
285 	{
286 		gtk_icon_factory_remove_default(gtkIconFactory);
287 	}
288 }