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