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