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