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