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.ThemingEngine;
26 
27 private import gdk.RGBA;
28 private import gdk.Screen;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gobject.ParamSpec;
32 private import gobject.Value;
33 private import gtk.Border;
34 private import gtk.WidgetPath;
35 private import gtkc.gtk;
36 public  import gtkc.gtktypes;
37 private import pango.PgFontDescription;
38 
39 
40 /**
41  * #GtkThemingEngine was the object used for rendering themed content
42  * in GTK+ widgets. It used to allow overriding GTK+'s default
43  * implementation of rendering functions by allowing engines to be
44  * loaded as modules.
45  * 
46  * #GtkThemingEngine has been deprecated in GTK+ 3.14 and will be
47  * ignored for rendering. The advancements in CSS theming are good
48  * enough to allow themers to achieve their goals without the need
49  * to modify source code.
50  */
51 public class ThemingEngine : ObjectG
52 {
53 	/** the main Gtk struct */
54 	protected GtkThemingEngine* gtkThemingEngine;
55 
56 	/** Get the main Gtk struct */
57 	public GtkThemingEngine* getThemingEngineStruct()
58 	{
59 		return gtkThemingEngine;
60 	}
61 
62 	/** the main Gtk struct as a void* */
63 	protected override void* getStruct()
64 	{
65 		return cast(void*)gtkThemingEngine;
66 	}
67 
68 	protected override void setStruct(GObject* obj)
69 	{
70 		gtkThemingEngine = cast(GtkThemingEngine*)obj;
71 		super.setStruct(obj);
72 	}
73 
74 	/**
75 	 * Sets our main struct and passes it to the parent class.
76 	 */
77 	public this (GtkThemingEngine* gtkThemingEngine, bool ownedRef = false)
78 	{
79 		this.gtkThemingEngine = gtkThemingEngine;
80 		super(cast(GObject*)gtkThemingEngine, ownedRef);
81 	}
82 
83 	/**
84 	 */
85 
86 	public static GType getType()
87 	{
88 		return gtk_theming_engine_get_type();
89 	}
90 
91 	/**
92 	 * Loads and initializes a theming engine module from the
93 	 * standard directories.
94 	 *
95 	 * Params:
96 	 *     name = Theme engine name to load
97 	 *
98 	 * Return: A theming engine, or %NULL if
99 	 *     the engine @name doesn’t exist.
100 	 */
101 	public static ThemingEngine load(string name)
102 	{
103 		auto p = gtk_theming_engine_load(Str.toStringz(name));
104 		
105 		if(p is null)
106 		{
107 			return null;
108 		}
109 		
110 		return ObjectG.getDObject!(ThemingEngine)(cast(GtkThemingEngine*) p);
111 	}
112 
113 	/**
114 	 * Registers a property so it can be used in the CSS file format,
115 	 * on the CSS file the property will look like
116 	 * "-${@name_space}-${property_name}". being
117 	 * ${property_name} the given to @pspec. @name_space will usually
118 	 * be the theme engine name.
119 	 *
120 	 * For any type a @parse_func may be provided, being this function
121 	 * used for turning any property value (between “:” and “;”) in
122 	 * CSS to the #GValue needed. For basic types there is already
123 	 * builtin parsing support, so %NULL may be provided for these
124 	 * cases.
125 	 *
126 	 * Engines must ensure property registration happens exactly once,
127 	 * usually GTK+ deals with theming engines as singletons, so this
128 	 * should be guaranteed to happen once, but bear this in mind
129 	 * when creating #GtkThemeEngines yourself.
130 	 *
131 	 * In order to make use of the custom registered properties in
132 	 * the CSS file, make sure the engine is loaded first by specifying
133 	 * the engine property, either in a previous rule or within the same
134 	 * one.
135 	 * |[
136 	 * * {
137 	 * engine: someengine;
138 	 * -SomeEngine-custom-property: 2;
139 	 * }
140 	 * ]|
141 	 *
142 	 * Deprecated: Code should use the default properties provided by CSS.
143 	 *
144 	 * Params:
145 	 *     nameSpace = namespace for the property name
146 	 *     parseFunc = parsing function to use, or %NULL
147 	 *     pspec = the #GParamSpec for the new property
148 	 *
149 	 * Since: 3.0
150 	 */
151 	public static void registerProperty(string nameSpace, GtkStylePropertyParser parseFunc, ParamSpec pspec)
152 	{
153 		gtk_theming_engine_register_property(Str.toStringz(nameSpace), parseFunc, (pspec is null) ? null : pspec.getParamSpecStruct());
154 	}
155 
156 	/**
157 	 * Gets the background color for a given state.
158 	 *
159 	 * Params:
160 	 *     state = state to retrieve the color for
161 	 *     color = return value for the background color
162 	 *
163 	 * Since: 3.0
164 	 */
165 	public void getBackgroundColor(GtkStateFlags state, out RGBA color)
166 	{
167 		GdkRGBA* outcolor = new GdkRGBA;
168 		
169 		gtk_theming_engine_get_background_color(gtkThemingEngine, state, outcolor);
170 		
171 		color = ObjectG.getDObject!(RGBA)(outcolor);
172 	}
173 
174 	/**
175 	 * Gets the border for a given state as a #GtkBorder.
176 	 *
177 	 * Params:
178 	 *     state = state to retrieve the border for
179 	 *     border = return value for the border settings
180 	 *
181 	 * Since: 3.0
182 	 */
183 	public void getBorder(GtkStateFlags state, out Border border)
184 	{
185 		GtkBorder* outborder = new GtkBorder;
186 		
187 		gtk_theming_engine_get_border(gtkThemingEngine, state, outborder);
188 		
189 		border = ObjectG.getDObject!(Border)(outborder);
190 	}
191 
192 	/**
193 	 * Gets the border color for a given state.
194 	 *
195 	 * Params:
196 	 *     state = state to retrieve the color for
197 	 *     color = return value for the border color
198 	 *
199 	 * Since: 3.0
200 	 */
201 	public void getBorderColor(GtkStateFlags state, out RGBA color)
202 	{
203 		GdkRGBA* outcolor = new GdkRGBA;
204 		
205 		gtk_theming_engine_get_border_color(gtkThemingEngine, state, outcolor);
206 		
207 		color = ObjectG.getDObject!(RGBA)(outcolor);
208 	}
209 
210 	/**
211 	 * Gets the foreground color for a given state.
212 	 *
213 	 * Params:
214 	 *     state = state to retrieve the color for
215 	 *     color = return value for the foreground color
216 	 *
217 	 * Since: 3.0
218 	 */
219 	public void getColor(GtkStateFlags state, out RGBA color)
220 	{
221 		GdkRGBA* outcolor = new GdkRGBA;
222 		
223 		gtk_theming_engine_get_color(gtkThemingEngine, state, outcolor);
224 		
225 		color = ObjectG.getDObject!(RGBA)(outcolor);
226 	}
227 
228 	/**
229 	 * Returns the widget direction used for rendering.
230 	 *
231 	 * Deprecated: Use gtk_theming_engine_get_state() and
232 	 * check for #GTK_STATE_FLAG_DIR_LTR and
233 	 * #GTK_STATE_FLAG_DIR_RTL instead.
234 	 *
235 	 * Return: the widget direction
236 	 *
237 	 * Since: 3.0
238 	 */
239 	public GtkTextDirection getDirection()
240 	{
241 		return gtk_theming_engine_get_direction(gtkThemingEngine);
242 	}
243 
244 	/**
245 	 * Returns the font description for a given state.
246 	 *
247 	 * Deprecated: Use gtk_theming_engine_get()
248 	 *
249 	 * Params:
250 	 *     state = state to retrieve the font for
251 	 *
252 	 * Return: the #PangoFontDescription for the given
253 	 *     state. This object is owned by GTK+ and should not be
254 	 *     freed.
255 	 *
256 	 * Since: 3.0
257 	 */
258 	public PgFontDescription getFont(GtkStateFlags state)
259 	{
260 		auto p = gtk_theming_engine_get_font(gtkThemingEngine, state);
261 		
262 		if(p is null)
263 		{
264 			return null;
265 		}
266 		
267 		return ObjectG.getDObject!(PgFontDescription)(cast(PangoFontDescription*) p);
268 	}
269 
270 	/**
271 	 * Returns the widget direction used for rendering.
272 	 *
273 	 * Return: the widget direction
274 	 *
275 	 * Since: 3.0
276 	 */
277 	public GtkJunctionSides getJunctionSides()
278 	{
279 		return gtk_theming_engine_get_junction_sides(gtkThemingEngine);
280 	}
281 
282 	/**
283 	 * Gets the margin for a given state as a #GtkBorder.
284 	 *
285 	 * Params:
286 	 *     state = state to retrieve the border for
287 	 *     margin = return value for the margin settings
288 	 *
289 	 * Since: 3.0
290 	 */
291 	public void getMargin(GtkStateFlags state, out Border margin)
292 	{
293 		GtkBorder* outmargin = new GtkBorder;
294 		
295 		gtk_theming_engine_get_margin(gtkThemingEngine, state, outmargin);
296 		
297 		margin = ObjectG.getDObject!(Border)(outmargin);
298 	}
299 
300 	/**
301 	 * Gets the padding for a given state as a #GtkBorder.
302 	 *
303 	 * Params:
304 	 *     state = state to retrieve the padding for
305 	 *     padding = return value for the padding settings
306 	 *
307 	 * Since: 3.0
308 	 */
309 	public void getPadding(GtkStateFlags state, out Border padding)
310 	{
311 		GtkBorder* outpadding = new GtkBorder;
312 		
313 		gtk_theming_engine_get_padding(gtkThemingEngine, state, outpadding);
314 		
315 		padding = ObjectG.getDObject!(Border)(outpadding);
316 	}
317 
318 	/**
319 	 * Returns the widget path used for style matching.
320 	 *
321 	 * Return: A #GtkWidgetPath
322 	 *
323 	 * Since: 3.0
324 	 */
325 	public WidgetPath getPath()
326 	{
327 		auto p = gtk_theming_engine_get_path(gtkThemingEngine);
328 		
329 		if(p is null)
330 		{
331 			return null;
332 		}
333 		
334 		return ObjectG.getDObject!(WidgetPath)(cast(GtkWidgetPath*) p);
335 	}
336 
337 	/**
338 	 * Gets a property value as retrieved from the style settings that apply
339 	 * to the currently rendered element.
340 	 *
341 	 * Params:
342 	 *     property = the property name
343 	 *     state = state to retrieve the value for
344 	 *     value = return location for the property value,
345 	 *         you must free this memory using g_value_unset() once you are
346 	 *         done with it.
347 	 *
348 	 * Since: 3.0
349 	 */
350 	public void getProperty(string property, GtkStateFlags state, out Value value)
351 	{
352 		GValue* outvalue = new GValue;
353 		
354 		gtk_theming_engine_get_property(gtkThemingEngine, Str.toStringz(property), state, outvalue);
355 		
356 		value = ObjectG.getDObject!(Value)(outvalue);
357 	}
358 
359 	/**
360 	 * Returns the #GdkScreen to which @engine currently rendering to.
361 	 *
362 	 * Return: a #GdkScreen, or %NULL.
363 	 */
364 	public Screen getScreen()
365 	{
366 		auto p = gtk_theming_engine_get_screen(gtkThemingEngine);
367 		
368 		if(p is null)
369 		{
370 			return null;
371 		}
372 		
373 		return ObjectG.getDObject!(Screen)(cast(GdkScreen*) p);
374 	}
375 
376 	/**
377 	 * returns the state used when rendering.
378 	 *
379 	 * Return: the state flags
380 	 *
381 	 * Since: 3.0
382 	 */
383 	public GtkStateFlags getState()
384 	{
385 		return gtk_theming_engine_get_state(gtkThemingEngine);
386 	}
387 
388 	/**
389 	 * Gets the value for a widget style property.
390 	 *
391 	 * Params:
392 	 *     propertyName = the name of the widget style property
393 	 *     value = Return location for the property value, free with
394 	 *         g_value_unset() after use.
395 	 *
396 	 * Since: 3.0
397 	 */
398 	public void getStyleProperty(string propertyName, out Value value)
399 	{
400 		GValue* outvalue = new GValue;
401 		
402 		gtk_theming_engine_get_style_property(gtkThemingEngine, Str.toStringz(propertyName), outvalue);
403 		
404 		value = ObjectG.getDObject!(Value)(outvalue);
405 	}
406 
407 	/**
408 	 * Retrieves several widget style properties from @engine according to the
409 	 * currently rendered content’s style.
410 	 *
411 	 * Params:
412 	 *     args = va_list of property name/return location pairs, followed by %NULL
413 	 *
414 	 * Since: 3.0
415 	 */
416 	public void getStyleValist(void* args)
417 	{
418 		gtk_theming_engine_get_style_valist(gtkThemingEngine, args);
419 	}
420 
421 	/**
422 	 * Retrieves several style property values that apply to the currently
423 	 * rendered element.
424 	 *
425 	 * Params:
426 	 *     state = state to retrieve values for
427 	 *     args = va_list of property name/return location pairs, followed by %NULL
428 	 *
429 	 * Since: 3.0
430 	 */
431 	public void getValist(GtkStateFlags state, void* args)
432 	{
433 		gtk_theming_engine_get_valist(gtkThemingEngine, state, args);
434 	}
435 
436 	/**
437 	 * Returns %TRUE if the currently rendered contents have
438 	 * defined the given class name.
439 	 *
440 	 * Params:
441 	 *     styleClass = class name to look up
442 	 *
443 	 * Return: %TRUE if @engine has @class_name defined
444 	 *
445 	 * Since: 3.0
446 	 */
447 	public bool hasClass(string styleClass)
448 	{
449 		return gtk_theming_engine_has_class(gtkThemingEngine, Str.toStringz(styleClass)) != 0;
450 	}
451 
452 	/**
453 	 * Returns %TRUE if the currently rendered contents have the
454 	 * region defined. If @flags_return is not %NULL, it is set
455 	 * to the flags affecting the region.
456 	 *
457 	 * Params:
458 	 *     styleRegion = a region name
459 	 *     flags = return location for region flags
460 	 *
461 	 * Return: %TRUE if region is defined
462 	 *
463 	 * Since: 3.0
464 	 */
465 	public bool hasRegion(string styleRegion, out GtkRegionFlags flags)
466 	{
467 		return gtk_theming_engine_has_region(gtkThemingEngine, Str.toStringz(styleRegion), &flags) != 0;
468 	}
469 
470 	/**
471 	 * Looks up and resolves a color name in the current style’s color map.
472 	 *
473 	 * Params:
474 	 *     colorName = color name to lookup
475 	 *     color = Return location for the looked up color
476 	 *
477 	 * Return: %TRUE if @color_name was found and resolved, %FALSE otherwise
478 	 *
479 	 * Since: 3.0
480 	 */
481 	public bool lookupColor(string colorName, out RGBA color)
482 	{
483 		GdkRGBA* outcolor = new GdkRGBA;
484 		
485 		auto p = gtk_theming_engine_lookup_color(gtkThemingEngine, Str.toStringz(colorName), outcolor) != 0;
486 		
487 		color = ObjectG.getDObject!(RGBA)(outcolor);
488 		
489 		return p;
490 	}
491 
492 	/**
493 	 * Returns %TRUE if there is a transition animation running for the
494 	 * current region (see gtk_style_context_push_animatable_region()).
495 	 *
496 	 * If @progress is not %NULL, the animation progress will be returned
497 	 * there, 0.0 means the state is closest to being %FALSE, while 1.0 means
498 	 * it’s closest to being %TRUE. This means transition animations will
499 	 * run from 0 to 1 when @state is being set to %TRUE and from 1 to 0 when
500 	 * it’s being set to %FALSE.
501 	 *
502 	 * Deprecated: Always returns %FALSE
503 	 *
504 	 * Params:
505 	 *     state = a widget state
506 	 *     progress = return location for the transition progress
507 	 *
508 	 * Return: %TRUE if there is a running transition animation for @state.
509 	 *
510 	 * Since: 3.0
511 	 */
512 	public bool stateIsRunning(GtkStateType state, out double progress)
513 	{
514 		return gtk_theming_engine_state_is_running(gtkThemingEngine, state, &progress) != 0;
515 	}
516 }