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