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