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.StyleProperties;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.ParamSpec;
31 private import gobject.Value;
32 private import gtk.StyleProviderIF;
33 private import gtk.StyleProviderT;
34 private import gtk.SymbolicColor;
35 private import gtkc.gtk;
36 public  import gtkc.gtktypes;
37 
38 
39 /**
40  * GtkStyleProperties provides the storage for style information
41  * that is used by #GtkStyleContext and other #GtkStyleProvider
42  * implementations.
43  * 
44  * Before style properties can be stored in GtkStyleProperties, they
45  * must be registered with gtk_style_properties_register_property().
46  * 
47  * Unless you are writing a #GtkStyleProvider implementation, you
48  * are unlikely to use this API directly, as gtk_style_context_get()
49  * and its variants are the preferred way to access styling information
50  * from widget implementations and theming engine implementations
51  * should use the APIs provided by #GtkThemingEngine instead.
52  */
53 public class StyleProperties : ObjectG, StyleProviderIF
54 {
55 	/** the main Gtk struct */
56 	protected GtkStyleProperties* gtkStyleProperties;
57 
58 	/** Get the main Gtk struct */
59 	public GtkStyleProperties* getStylePropertiesStruct()
60 	{
61 		return gtkStyleProperties;
62 	}
63 
64 	/** the main Gtk struct as a void* */
65 	protected override void* getStruct()
66 	{
67 		return cast(void*)gtkStyleProperties;
68 	}
69 
70 	protected override void setStruct(GObject* obj)
71 	{
72 		gtkStyleProperties = cast(GtkStyleProperties*)obj;
73 		super.setStruct(obj);
74 	}
75 
76 	/**
77 	 * Sets our main struct and passes it to the parent class.
78 	 */
79 	public this (GtkStyleProperties* gtkStyleProperties, bool ownedRef = false)
80 	{
81 		this.gtkStyleProperties = gtkStyleProperties;
82 		super(cast(GObject*)gtkStyleProperties, ownedRef);
83 	}
84 
85 	// add the StyleProvider capabilities
86 	mixin StyleProviderT!(GtkStyleProperties);
87 
88 	/**
89 	 */
90 
91 	public static GType getType()
92 	{
93 		return gtk_style_properties_get_type();
94 	}
95 
96 	/**
97 	 * Returns a newly created #GtkStyleProperties
98 	 *
99 	 * Return: a new #GtkStyleProperties
100 	 *
101 	 * Throws: ConstructionException GTK+ fails to create the object.
102 	 */
103 	public this()
104 	{
105 		auto p = gtk_style_properties_new();
106 		
107 		if(p is null)
108 		{
109 			throw new ConstructionException("null returned by new");
110 		}
111 		
112 		this(cast(GtkStyleProperties*) p, true);
113 	}
114 
115 	/**
116 	 * Returns %TRUE if a property has been registered, if @pspec or
117 	 * @parse_func are not %NULL, the #GParamSpec and parsing function
118 	 * will be respectively returned.
119 	 *
120 	 * Deprecated: This code could only look up custom properties and
121 	 * those are deprecated.
122 	 *
123 	 * Params:
124 	 *     propertyName = property name to look up
125 	 *     parseFunc = return location for the parse function
126 	 *     pspec = return location for the #GParamSpec
127 	 *
128 	 * Return: %TRUE if the property is registered, %FALSE otherwise
129 	 *
130 	 * Since: 3.0
131 	 */
132 	public static bool lookupProperty(string propertyName, out GtkStylePropertyParser parseFunc, out ParamSpec pspec)
133 	{
134 		GParamSpec* outpspec = null;
135 		
136 		auto p = gtk_style_properties_lookup_property(Str.toStringz(propertyName), &parseFunc, &outpspec) != 0;
137 		
138 		pspec = ObjectG.getDObject!(ParamSpec)(outpspec);
139 		
140 		return p;
141 	}
142 
143 	/**
144 	 * Registers a property so it can be used in the CSS file format.
145 	 * This function is the low-level equivalent of
146 	 * gtk_theming_engine_register_property(), if you are implementing
147 	 * a theming engine, you want to use that function instead.
148 	 *
149 	 * Deprecated: Code should use the default properties provided by CSS.
150 	 *
151 	 * Params:
152 	 *     parseFunc = parsing function to use, or %NULL
153 	 *     pspec = the #GParamSpec for the new property
154 	 *
155 	 * Since: 3.0
156 	 */
157 	public static void registerProperty(GtkStylePropertyParser parseFunc, ParamSpec pspec)
158 	{
159 		gtk_style_properties_register_property(parseFunc, (pspec is null) ? null : pspec.getParamSpecStruct());
160 	}
161 
162 	/**
163 	 * Clears all style information from @props.
164 	 */
165 	public void clear()
166 	{
167 		gtk_style_properties_clear(gtkStyleProperties);
168 	}
169 
170 	/**
171 	 * Gets a style property from @props for the given state. When done with @value,
172 	 * g_value_unset() needs to be called to free any allocated memory.
173 	 *
174 	 * Params:
175 	 *     property = style property name
176 	 *     state = state to retrieve the property value for
177 	 *     value = return location for the style property value.
178 	 *
179 	 * Return: %TRUE if the property exists in @props, %FALSE otherwise
180 	 *
181 	 * Since: 3.0
182 	 */
183 	public bool getStyleProperty(string property, GtkStateFlags state, out Value value)
184 	{
185 		GValue* outvalue = new GValue;
186 		
187 		auto p = gtk_style_properties_get_property(gtkStyleProperties, Str.toStringz(property), state, outvalue) != 0;
188 		
189 		value = ObjectG.getDObject!(Value)(outvalue);
190 		
191 		return p;
192 	}
193 
194 	/**
195 	 * Retrieves several style property values from @props for a given state.
196 	 *
197 	 * Params:
198 	 *     state = state to retrieve the property values for
199 	 *     args = va_list of property name/return location pairs, followed by %NULL
200 	 *
201 	 * Since: 3.0
202 	 */
203 	public void getStyleValist(GtkStateFlags state, void* args)
204 	{
205 		gtk_style_properties_get_valist(gtkStyleProperties, state, args);
206 	}
207 
208 	/**
209 	 * Returns the symbolic color that is mapped
210 	 * to @name.
211 	 *
212 	 * Deprecated: #GtkSymbolicColor is deprecated.
213 	 *
214 	 * Params:
215 	 *     name = color name to lookup
216 	 *
217 	 * Return: The mapped color
218 	 *
219 	 * Since: 3.0
220 	 */
221 	public SymbolicColor lookupColor(string name)
222 	{
223 		auto p = gtk_style_properties_lookup_color(gtkStyleProperties, Str.toStringz(name));
224 		
225 		if(p is null)
226 		{
227 			return null;
228 		}
229 		
230 		return ObjectG.getDObject!(SymbolicColor)(cast(GtkSymbolicColor*) p);
231 	}
232 
233 	/**
234 	 * Maps @color so it can be referenced by @name. See
235 	 * gtk_style_properties_lookup_color()
236 	 *
237 	 * Deprecated: #GtkSymbolicColor is deprecated.
238 	 *
239 	 * Params:
240 	 *     name = color name
241 	 *     color = #GtkSymbolicColor to map @name to
242 	 *
243 	 * Since: 3.0
244 	 */
245 	public void mapColor(string name, SymbolicColor color)
246 	{
247 		gtk_style_properties_map_color(gtkStyleProperties, Str.toStringz(name), (color is null) ? null : color.getSymbolicColorStruct());
248 	}
249 
250 	/**
251 	 * Merges into @props all the style information contained
252 	 * in @props_to_merge. If @replace is %TRUE, the values
253 	 * will be overwritten, if it is %FALSE, the older values
254 	 * will prevail.
255 	 *
256 	 * Params:
257 	 *     propsToMerge = a second #GtkStyleProperties
258 	 *     replace = whether to replace values or not
259 	 *
260 	 * Since: 3.0
261 	 */
262 	public void merge(StyleProperties propsToMerge, bool replace)
263 	{
264 		gtk_style_properties_merge(gtkStyleProperties, (propsToMerge is null) ? null : propsToMerge.getStylePropertiesStruct(), replace);
265 	}
266 
267 	/**
268 	 * Sets a styling property in @props.
269 	 *
270 	 * Params:
271 	 *     property = styling property to set
272 	 *     state = state to set the value for
273 	 *     value = new value for the property
274 	 *
275 	 * Since: 3.0
276 	 */
277 	public void setStyleProperty(string property, GtkStateFlags state, Value value)
278 	{
279 		gtk_style_properties_set_property(gtkStyleProperties, Str.toStringz(property), state, (value is null) ? null : value.getValueStruct());
280 	}
281 
282 	/**
283 	 * Sets several style properties on @props.
284 	 *
285 	 * Params:
286 	 *     state = state to set the values for
287 	 *     args = va_list of property name/value pairs, followed by %NULL
288 	 *
289 	 * Since: 3.0
290 	 */
291 	public void setStyleValist(GtkStateFlags state, void* args)
292 	{
293 		gtk_style_properties_set_valist(gtkStyleProperties, state, args);
294 	}
295 
296 	/**
297 	 * Unsets a style property in @props.
298 	 *
299 	 * Params:
300 	 *     property = property to unset
301 	 *     state = state to unset
302 	 *
303 	 * Since: 3.0
304 	 */
305 	public void unsetProperty(string property, GtkStateFlags state)
306 	{
307 		gtk_style_properties_unset_property(gtkStyleProperties, Str.toStringz(property), state);
308 	}
309 }