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.SymbolicColor;
26 
27 private import gdk.RGBA;
28 private import glib.ConstructionException;
29 private import glib.MemorySlice;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gtk.StyleProperties;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 public  import gtkc.gtktypes;
36 private import gtkd.Loader;
37 
38 
39 /**
40  * GtkSymbolicColor is a boxed type that represents a symbolic color.
41  * It is the result of parsing a
42  * [color expression][gtkcssprovider-symbolic-colors].
43  * To obtain the color represented by a GtkSymbolicColor, it has to
44  * be resolved with gtk_symbolic_color_resolve(), which replaces all
45  * symbolic color references by the colors they refer to (in a given
46  * context) and evaluates mix, shade and other expressions, resulting
47  * in a #GdkRGBA value.
48  * 
49  * It is not normally necessary to deal directly with #GtkSymbolicColors,
50  * since they are mostly used behind the scenes by #GtkStyleContext and
51  * #GtkCssProvider.
52  * 
53  * #GtkSymbolicColor is deprecated. Symbolic colors are considered an
54  * implementation detail of GTK+.
55  */
56 public class SymbolicColor
57 {
58 	/** the main Gtk struct */
59 	protected GtkSymbolicColor* gtkSymbolicColor;
60 	protected bool ownedRef;
61 
62 	/** Get the main Gtk struct */
63 	public GtkSymbolicColor* getSymbolicColorStruct(bool transferOwnership = false)
64 	{
65 		if (transferOwnership)
66 			ownedRef = false;
67 		return gtkSymbolicColor;
68 	}
69 
70 	/** the main Gtk struct as a void* */
71 	protected void* getStruct()
72 	{
73 		return cast(void*)gtkSymbolicColor;
74 	}
75 
76 	/**
77 	 * Sets our main struct and passes it to the parent class.
78 	 */
79 	public this (GtkSymbolicColor* gtkSymbolicColor, bool ownedRef = false)
80 	{
81 		this.gtkSymbolicColor = gtkSymbolicColor;
82 		this.ownedRef = ownedRef;
83 	}
84 
85 	~this ()
86 	{
87 		if ( Linker.isLoaded(LIBRARY_GTK) && ownedRef )
88 			gtk_symbolic_color_unref(gtkSymbolicColor);
89 	}
90 
91 	/**
92 	 * Creates a symbolic color defined as a shade of another color.
93 	 * A factor > 1.0 would resolve to a brighter or more transparent color,
94 	 * while < 1.0 would resolve to a darker or more opaque color.
95 	 *
96 	 * Params:
97 	 *     color    = another GtkSymbolicColor.
98 	 *     factor   = shading factor to apply to color.
99 	 *     useAlpha = if true change the relative alpha value of the color,
100 	 *                otherwise change the shade.
101 	 *
102 	 * Throws: ConstructionException GTK+ fails to create the object.
103 	 */
104 	public this (SymbolicColor color, double factor, bool useAlpha = true)
105 	{
106 		GtkSymbolicColor* p;
107 
108 		if ( useAlpha )
109 		{
110 			p = gtk_symbolic_color_new_alpha((color is null) ? null : color.getSymbolicColorStruct(), factor);
111 		}
112 		else
113 		{
114 			p = gtk_symbolic_color_new_shade((color is null) ? null : color.getSymbolicColorStruct(), factor);
115 		}
116 
117 		if(p is null)
118 		{
119 			throw new ConstructionException("null returned by gtk_symbolic_color_new_shade((color is null) ? null : color.getSymbolicColorStruct(), factor)");
120 		}
121 
122 		this(cast(GtkSymbolicColor*) p);
123 	}
124 
125 	/**
126 	 */
127 
128 	/** */
129 	public static GType getType()
130 	{
131 		return gtk_symbolic_color_get_type();
132 	}
133 
134 	/**
135 	 * Creates a symbolic color pointing to a literal color.
136 	 *
137 	 * Deprecated: #GtkSymbolicColor is deprecated.
138 	 *
139 	 * Params:
140 	 *     color = a #GdkRGBA
141 	 *
142 	 * Returns: a newly created #GtkSymbolicColor
143 	 *
144 	 * Since: 3.0
145 	 *
146 	 * Throws: ConstructionException GTK+ fails to create the object.
147 	 */
148 	public this(RGBA color)
149 	{
150 		auto p = gtk_symbolic_color_new_literal((color is null) ? null : color.getRGBAStruct());
151 
152 		if(p is null)
153 		{
154 			throw new ConstructionException("null returned by new_literal");
155 		}
156 
157 		this(cast(GtkSymbolicColor*) p);
158 	}
159 
160 	/**
161 	 * Creates a symbolic color defined as a mix of another
162 	 * two colors. a mix factor of 0 would resolve to @color1,
163 	 * while a factor of 1 would resolve to @color2.
164 	 *
165 	 * Deprecated: #GtkSymbolicColor is deprecated.
166 	 *
167 	 * Params:
168 	 *     color1 = color to mix
169 	 *     color2 = another color to mix
170 	 *     factor = mix factor
171 	 *
172 	 * Returns: A newly created #GtkSymbolicColor
173 	 *
174 	 * Since: 3.0
175 	 *
176 	 * Throws: ConstructionException GTK+ fails to create the object.
177 	 */
178 	public this(SymbolicColor color1, SymbolicColor color2, double factor)
179 	{
180 		auto p = gtk_symbolic_color_new_mix((color1 is null) ? null : color1.getSymbolicColorStruct(), (color2 is null) ? null : color2.getSymbolicColorStruct(), factor);
181 
182 		if(p is null)
183 		{
184 			throw new ConstructionException("null returned by new_mix");
185 		}
186 
187 		this(cast(GtkSymbolicColor*) p);
188 	}
189 
190 	/**
191 	 * Creates a symbolic color pointing to an unresolved named
192 	 * color. See gtk_style_context_lookup_color() and
193 	 * gtk_style_properties_lookup_color().
194 	 *
195 	 * Deprecated: #GtkSymbolicColor is deprecated.
196 	 *
197 	 * Params:
198 	 *     name = color name
199 	 *
200 	 * Returns: a newly created #GtkSymbolicColor
201 	 *
202 	 * Since: 3.0
203 	 *
204 	 * Throws: ConstructionException GTK+ fails to create the object.
205 	 */
206 	public this(string name)
207 	{
208 		auto p = gtk_symbolic_color_new_name(Str.toStringz(name));
209 
210 		if(p is null)
211 		{
212 			throw new ConstructionException("null returned by new_name");
213 		}
214 
215 		this(cast(GtkSymbolicColor*) p);
216 	}
217 
218 	/**
219 	 * Creates a symbolic color based on the current win32
220 	 * theme.
221 	 *
222 	 * Note that while this call is available on all platforms
223 	 * the actual value returned is not reliable on non-win32
224 	 * platforms.
225 	 *
226 	 * Deprecated: #GtkSymbolicColor is deprecated.
227 	 *
228 	 * Params:
229 	 *     themeClass = The theme class to pull color from
230 	 *     id = The color id
231 	 *
232 	 * Returns: A newly created #GtkSymbolicColor
233 	 *
234 	 * Since: 3.4
235 	 *
236 	 * Throws: ConstructionException GTK+ fails to create the object.
237 	 */
238 	public this(string themeClass, int id)
239 	{
240 		auto p = gtk_symbolic_color_new_win32(Str.toStringz(themeClass), id);
241 
242 		if(p is null)
243 		{
244 			throw new ConstructionException("null returned by new_win32");
245 		}
246 
247 		this(cast(GtkSymbolicColor*) p);
248 	}
249 
250 	/**
251 	 * Increases the reference count of @color
252 	 *
253 	 * Deprecated: #GtkSymbolicColor is deprecated.
254 	 *
255 	 * Returns: the same @color
256 	 *
257 	 * Since: 3.0
258 	 */
259 	public SymbolicColor doref()
260 	{
261 		auto p = gtk_symbolic_color_ref(gtkSymbolicColor);
262 
263 		if(p is null)
264 		{
265 			return null;
266 		}
267 
268 		return ObjectG.getDObject!(SymbolicColor)(cast(GtkSymbolicColor*) p, true);
269 	}
270 
271 	/**
272 	 * If @color is resolvable, @resolved_color will be filled in
273 	 * with the resolved color, and %TRUE will be returned. Generally,
274 	 * if @color can’t be resolved, it is due to it being defined on
275 	 * top of a named color that doesn’t exist in @props.
276 	 *
277 	 * When @props is %NULL, resolving of named colors will fail, so if
278 	 * your @color is or references such a color, this function will
279 	 * return %FALSE.
280 	 *
281 	 * Deprecated: #GtkSymbolicColor is deprecated.
282 	 *
283 	 * Params:
284 	 *     props = #GtkStyleProperties to use when resolving
285 	 *         named colors, or %NULL
286 	 *     resolvedColor = return location for the resolved color
287 	 *
288 	 * Returns: %TRUE if the color has been resolved
289 	 *
290 	 * Since: 3.0
291 	 */
292 	public bool resolve(StyleProperties props, out RGBA resolvedColor)
293 	{
294 		GdkRGBA* outresolvedColor = sliceNew!GdkRGBA();
295 
296 		auto p = gtk_symbolic_color_resolve(gtkSymbolicColor, (props is null) ? null : props.getStylePropertiesStruct(), outresolvedColor) != 0;
297 
298 		resolvedColor = ObjectG.getDObject!(RGBA)(outresolvedColor, true);
299 
300 		return p;
301 	}
302 
303 	/**
304 	 * Converts the given @color to a string representation. This is useful
305 	 * both for debugging and for serialization of strings. The format of
306 	 * the string may change between different versions of GTK, but it is
307 	 * guaranteed that the GTK css parser is able to read the string and
308 	 * create the same symbolic color from it.
309 	 *
310 	 * Deprecated: #GtkSymbolicColor is deprecated.
311 	 *
312 	 * Returns: a new string representing @color
313 	 */
314 	public override string toString()
315 	{
316 		auto retStr = gtk_symbolic_color_to_string(gtkSymbolicColor);
317 
318 		scope(exit) Str.freeString(retStr);
319 		return Str.toString(retStr);
320 	}
321 
322 	/**
323 	 * Decreases the reference count of @color, freeing its memory if the
324 	 * reference count reaches 0.
325 	 *
326 	 * Deprecated: #GtkSymbolicColor is deprecated.
327 	 *
328 	 * Since: 3.0
329 	 */
330 	public void unref()
331 	{
332 		gtk_symbolic_color_unref(gtkSymbolicColor);
333 	}
334 }