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 	/**
130 	 * Sets our main struct and passes it to the parent class.
131 	 */
132 	public this (GtkIconFactory* gtkIconFactory, bool ownedRef = false)
133 	{
134 		this.gtkIconFactory = gtkIconFactory;
135 		super(cast(GObject*)gtkIconFactory, ownedRef);
136 	}
137 
138 	// add the Buildable capabilities
139 	mixin BuildableT!(GtkIconFactory);
140 
141 
142 	/** */
143 	public static GType getType()
144 	{
145 		return gtk_icon_factory_get_type();
146 	}
147 
148 	/**
149 	 * Creates a new #GtkIconFactory. An icon factory manages a collection
150 	 * of #GtkIconSets; a #GtkIconSet manages a set of variants of a
151 	 * particular icon (i.e. a #GtkIconSet contains variants for different
152 	 * sizes and widget states). Icons in an icon factory are named by a
153 	 * stock ID, which is a simple string identifying the icon. Each
154 	 * #GtkStyle has a list of #GtkIconFactorys derived from the current
155 	 * theme; those icon factories are consulted first when searching for
156 	 * an icon. If the theme doesn’t set a particular icon, GTK+ looks for
157 	 * the icon in a list of default icon factories, maintained by
158 	 * gtk_icon_factory_add_default() and
159 	 * gtk_icon_factory_remove_default(). Applications with icons should
160 	 * add a default icon factory with their icons, which will allow
161 	 * themes to override the icons for the application.
162 	 *
163 	 * Deprecated: Use #GtkIconTheme instead.
164 	 *
165 	 * Returns: a new #GtkIconFactory
166 	 *
167 	 * Throws: ConstructionException GTK+ fails to create the object.
168 	 */
169 	public this()
170 	{
171 		auto p = gtk_icon_factory_new();
172 
173 		if(p is null)
174 		{
175 			throw new ConstructionException("null returned by new");
176 		}
177 
178 		this(cast(GtkIconFactory*) p, true);
179 	}
180 
181 	/**
182 	 * Looks for an icon in the list of default icon factories.  For
183 	 * display to the user, you should use gtk_style_lookup_icon_set() on
184 	 * the #GtkStyle for the widget that will display the icon, instead of
185 	 * using this function directly, so that themes are taken into
186 	 * account.
187 	 *
188 	 * Deprecated: Use #GtkIconTheme instead.
189 	 *
190 	 * Params:
191 	 *     stockId = an icon name
192 	 *
193 	 * Returns: a #GtkIconSet, or %NULL
194 	 */
195 	public static IconSet lookupDefault(string stockId)
196 	{
197 		auto p = gtk_icon_factory_lookup_default(Str.toStringz(stockId));
198 
199 		if(p is null)
200 		{
201 			return null;
202 		}
203 
204 		return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p);
205 	}
206 
207 	/**
208 	 * Adds the given @icon_set to the icon factory, under the name
209 	 * @stock_id.  @stock_id should be namespaced for your application,
210 	 * e.g. “myapp-whatever-icon”.  Normally applications create a
211 	 * #GtkIconFactory, then add it to the list of default factories with
212 	 * gtk_icon_factory_add_default(). Then they pass the @stock_id to
213 	 * widgets such as #GtkImage to display the icon. Themes can provide
214 	 * an icon with the same name (such as "myapp-whatever-icon") to
215 	 * override your application’s default icons. If an icon already
216 	 * existed in @factory for @stock_id, it is unreferenced and replaced
217 	 * with the new @icon_set.
218 	 *
219 	 * Deprecated: Use #GtkIconTheme instead.
220 	 *
221 	 * Params:
222 	 *     stockId = icon name
223 	 *     iconSet = icon set
224 	 */
225 	public void add(string stockId, IconSet iconSet)
226 	{
227 		gtk_icon_factory_add(gtkIconFactory, Str.toStringz(stockId), (iconSet is null) ? null : iconSet.getIconSetStruct());
228 	}
229 
230 	/**
231 	 * Adds an icon factory to the list of icon factories searched by
232 	 * gtk_style_lookup_icon_set(). This means that, for example,
233 	 * gtk_image_new_from_stock() will be able to find icons in @factory.
234 	 * There will normally be an icon factory added for each library or
235 	 * application that comes with icons. The default icon factories
236 	 * can be overridden by themes.
237 	 *
238 	 * Deprecated: Use #GtkIconTheme instead.
239 	 */
240 	public void addDefault()
241 	{
242 		gtk_icon_factory_add_default(gtkIconFactory);
243 	}
244 
245 	/**
246 	 * Looks up @stock_id in the icon factory, returning an icon set
247 	 * if found, otherwise %NULL. For display to the user, you should
248 	 * use gtk_style_lookup_icon_set() on the #GtkStyle for the
249 	 * widget that will display the icon, instead of using this
250 	 * function directly, so that themes are taken into account.
251 	 *
252 	 * Deprecated: Use #GtkIconTheme instead.
253 	 *
254 	 * Params:
255 	 *     stockId = an icon name
256 	 *
257 	 * Returns: icon set of @stock_id.
258 	 */
259 	public IconSet lookup(string stockId)
260 	{
261 		auto p = gtk_icon_factory_lookup(gtkIconFactory, Str.toStringz(stockId));
262 
263 		if(p is null)
264 		{
265 			return null;
266 		}
267 
268 		return ObjectG.getDObject!(IconSet)(cast(GtkIconSet*) p);
269 	}
270 
271 	/**
272 	 * Removes an icon factory from the list of default icon
273 	 * factories. Not normally used; you might use it for a library that
274 	 * can be unloaded or shut down.
275 	 *
276 	 * Deprecated: Use #GtkIconTheme instead.
277 	 */
278 	public void removeDefault()
279 	{
280 		gtk_icon_factory_remove_default(gtkIconFactory);
281 	}
282 }