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.ColorSelection; 26 27 private import gdk.Color; 28 private import gdk.RGBA; 29 private import glib.ConstructionException; 30 private import glib.Str; 31 private import gobject.ObjectG; 32 private import gobject.Signals; 33 private import gtk.Box; 34 private import gtk.Widget; 35 private import gtkc.gtk; 36 public import gtkc.gtktypes; 37 private import std.algorithm; 38 39 40 /** */ 41 public class ColorSelection : Box 42 { 43 /** the main Gtk struct */ 44 protected GtkColorSelection* gtkColorSelection; 45 46 /** Get the main Gtk struct */ 47 public GtkColorSelection* getColorSelectionStruct(bool transferOwnership = false) 48 { 49 if (transferOwnership) 50 ownedRef = false; 51 return gtkColorSelection; 52 } 53 54 /** the main Gtk struct as a void* */ 55 protected override void* getStruct() 56 { 57 return cast(void*)gtkColorSelection; 58 } 59 60 protected override void setStruct(GObject* obj) 61 { 62 gtkColorSelection = cast(GtkColorSelection*)obj; 63 super.setStruct(obj); 64 } 65 66 /** 67 * Sets our main struct and passes it to the parent class. 68 */ 69 public this (GtkColorSelection* gtkColorSelection, bool ownedRef = false) 70 { 71 this.gtkColorSelection = gtkColorSelection; 72 super(cast(GtkBox*)gtkColorSelection, ownedRef); 73 } 74 75 76 /** */ 77 public static GType getType() 78 { 79 return gtk_color_selection_get_type(); 80 } 81 82 /** 83 * Creates a new GtkColorSelection. 84 * 85 * Returns: a new #GtkColorSelection 86 * 87 * Throws: ConstructionException GTK+ fails to create the object. 88 */ 89 public this() 90 { 91 auto p = gtk_color_selection_new(); 92 93 if(p is null) 94 { 95 throw new ConstructionException("null returned by new"); 96 } 97 98 this(cast(GtkColorSelection*) p); 99 } 100 101 /** 102 * Parses a color palette string; the string is a colon-separated 103 * list of color names readable by gdk_color_parse(). 104 * 105 * Params: 106 * str = a string encoding a color palette 107 * colors = return location for 108 * allocated array of #GdkColor 109 * nColors = return location for length of array 110 * 111 * Returns: %TRUE if a palette was successfully parsed 112 */ 113 public static bool paletteFromString(string str, out Color[] colors) 114 { 115 GdkColor* outcolors = null; 116 int nColors; 117 118 auto p = gtk_color_selection_palette_from_string(Str.toStringz(str), &outcolors, &nColors) != 0; 119 120 colors = new Color[nColors]; 121 for(size_t i = 0; i < nColors; i++) 122 { 123 colors[i] = ObjectG.getDObject!(Color)(cast(GdkColor*) &outcolors[i]); 124 } 125 126 return p; 127 } 128 129 /** 130 * Encodes a palette as a string, useful for persistent storage. 131 * 132 * Params: 133 * colors = an array of colors 134 * nColors = length of the array 135 * 136 * Returns: allocated string encoding the palette 137 */ 138 public static string paletteToString(Color[] colors) 139 { 140 GdkColor[] colorsArray = new GdkColor[colors.length]; 141 for ( int i = 0; i < colors.length; i++ ) 142 { 143 colorsArray[i] = *(colors[i].getColorStruct()); 144 } 145 146 auto retStr = gtk_color_selection_palette_to_string(colorsArray.ptr, cast(int)colors.length); 147 148 scope(exit) Str.freeString(retStr); 149 return Str.toString(retStr); 150 } 151 152 /** 153 * Installs a global function to be called whenever the user 154 * tries to modify the palette in a color selection. 155 * 156 * This function should save the new palette contents, and update 157 * the #GtkSettings:gtk-color-palette GtkSettings property so all 158 * GtkColorSelection widgets will be modified. 159 * 160 * Params: 161 * func = a function to call when the custom palette needs saving 162 * 163 * Returns: the previous change palette hook (that was replaced) 164 * 165 * Since: 2.2 166 */ 167 public static GtkColorSelectionChangePaletteWithScreenFunc setChangePaletteWithScreenHook(GtkColorSelectionChangePaletteWithScreenFunc func) 168 { 169 return gtk_color_selection_set_change_palette_with_screen_hook(func); 170 } 171 172 /** 173 * Returns the current alpha value. 174 * 175 * Returns: an integer between 0 and 65535 176 */ 177 public ushort getCurrentAlpha() 178 { 179 return gtk_color_selection_get_current_alpha(gtkColorSelection); 180 } 181 182 /** 183 * Sets @color to be the current color in the GtkColorSelection widget. 184 * 185 * Deprecated: Use gtk_color_selection_get_current_rgba() instead. 186 * 187 * Params: 188 * color = a #GdkColor to fill in with the current color 189 */ 190 public void getCurrentColor(out Color color) 191 { 192 GdkColor* outcolor = gMalloc!GdkColor(); 193 194 gtk_color_selection_get_current_color(gtkColorSelection, outcolor); 195 196 color = ObjectG.getDObject!(Color)(outcolor, true); 197 } 198 199 /** 200 * Sets @rgba to be the current color in the GtkColorSelection widget. 201 * 202 * Params: 203 * rgba = a #GdkRGBA to fill in with the current color 204 * 205 * Since: 3.0 206 */ 207 public void getCurrentRgba(out RGBA rgba) 208 { 209 GdkRGBA* outrgba = gMalloc!GdkRGBA(); 210 211 gtk_color_selection_get_current_rgba(gtkColorSelection, outrgba); 212 213 rgba = ObjectG.getDObject!(RGBA)(outrgba, true); 214 } 215 216 /** 217 * Determines whether the colorsel has an opacity control. 218 * 219 * Returns: %TRUE if the @colorsel has an opacity control, 220 * %FALSE if it does't 221 */ 222 public bool getHasOpacityControl() 223 { 224 return gtk_color_selection_get_has_opacity_control(gtkColorSelection) != 0; 225 } 226 227 /** 228 * Determines whether the color selector has a color palette. 229 * 230 * Returns: %TRUE if the selector has a palette, %FALSE if it hasn't 231 */ 232 public bool getHasPalette() 233 { 234 return gtk_color_selection_get_has_palette(gtkColorSelection) != 0; 235 } 236 237 /** 238 * Returns the previous alpha value. 239 * 240 * Returns: an integer between 0 and 65535 241 */ 242 public ushort getPreviousAlpha() 243 { 244 return gtk_color_selection_get_previous_alpha(gtkColorSelection); 245 } 246 247 /** 248 * Fills @color in with the original color value. 249 * 250 * Deprecated: Use gtk_color_selection_get_previous_rgba() instead. 251 * 252 * Params: 253 * color = a #GdkColor to fill in with the original color value 254 */ 255 public void getPreviousColor(out Color color) 256 { 257 GdkColor* outcolor = gMalloc!GdkColor(); 258 259 gtk_color_selection_get_previous_color(gtkColorSelection, outcolor); 260 261 color = ObjectG.getDObject!(Color)(outcolor, true); 262 } 263 264 /** 265 * Fills @rgba in with the original color value. 266 * 267 * Params: 268 * rgba = a #GdkRGBA to fill in with the original color value 269 * 270 * Since: 3.0 271 */ 272 public void getPreviousRgba(out RGBA rgba) 273 { 274 GdkRGBA* outrgba = gMalloc!GdkRGBA(); 275 276 gtk_color_selection_get_previous_rgba(gtkColorSelection, outrgba); 277 278 rgba = ObjectG.getDObject!(RGBA)(outrgba, true); 279 } 280 281 /** 282 * Gets the current state of the @colorsel. 283 * 284 * Returns: %TRUE if the user is currently dragging 285 * a color around, and %FALSE if the selection has stopped 286 */ 287 public bool isAdjusting() 288 { 289 return gtk_color_selection_is_adjusting(gtkColorSelection) != 0; 290 } 291 292 /** 293 * Sets the current opacity to be @alpha. 294 * 295 * The first time this is called, it will also set 296 * the original opacity to be @alpha too. 297 * 298 * Params: 299 * alpha = an integer between 0 and 65535 300 */ 301 public void setCurrentAlpha(ushort alpha) 302 { 303 gtk_color_selection_set_current_alpha(gtkColorSelection, alpha); 304 } 305 306 /** 307 * Sets the current color to be @color. 308 * 309 * The first time this is called, it will also set 310 * the original color to be @color too. 311 * 312 * Deprecated: Use gtk_color_selection_set_current_rgba() instead. 313 * 314 * Params: 315 * color = a #GdkColor to set the current color with 316 */ 317 public void setCurrentColor(Color color) 318 { 319 gtk_color_selection_set_current_color(gtkColorSelection, (color is null) ? null : color.getColorStruct()); 320 } 321 322 /** 323 * Sets the current color to be @rgba. 324 * 325 * The first time this is called, it will also set 326 * the original color to be @rgba too. 327 * 328 * Params: 329 * rgba = A #GdkRGBA to set the current color with 330 * 331 * Since: 3.0 332 */ 333 public void setCurrentRgba(RGBA rgba) 334 { 335 gtk_color_selection_set_current_rgba(gtkColorSelection, (rgba is null) ? null : rgba.getRGBAStruct()); 336 } 337 338 /** 339 * Sets the @colorsel to use or not use opacity. 340 * 341 * Params: 342 * hasOpacity = %TRUE if @colorsel can set the opacity, %FALSE otherwise 343 */ 344 public void setHasOpacityControl(bool hasOpacity) 345 { 346 gtk_color_selection_set_has_opacity_control(gtkColorSelection, hasOpacity); 347 } 348 349 /** 350 * Shows and hides the palette based upon the value of @has_palette. 351 * 352 * Params: 353 * hasPalette = %TRUE if palette is to be visible, %FALSE otherwise 354 */ 355 public void setHasPalette(bool hasPalette) 356 { 357 gtk_color_selection_set_has_palette(gtkColorSelection, hasPalette); 358 } 359 360 /** 361 * Sets the “previous” alpha to be @alpha. 362 * 363 * This function should be called with some hesitations, 364 * as it might seem confusing to have that alpha change. 365 * 366 * Params: 367 * alpha = an integer between 0 and 65535 368 */ 369 public void setPreviousAlpha(ushort alpha) 370 { 371 gtk_color_selection_set_previous_alpha(gtkColorSelection, alpha); 372 } 373 374 /** 375 * Sets the “previous” color to be @color. 376 * 377 * This function should be called with some hesitations, 378 * as it might seem confusing to have that color change. 379 * Calling gtk_color_selection_set_current_color() will also 380 * set this color the first time it is called. 381 * 382 * Deprecated: Use gtk_color_selection_set_previous_rgba() instead. 383 * 384 * Params: 385 * color = a #GdkColor to set the previous color with 386 */ 387 public void setPreviousColor(Color color) 388 { 389 gtk_color_selection_set_previous_color(gtkColorSelection, (color is null) ? null : color.getColorStruct()); 390 } 391 392 /** 393 * Sets the “previous” color to be @rgba. 394 * 395 * This function should be called with some hesitations, 396 * as it might seem confusing to have that color change. 397 * Calling gtk_color_selection_set_current_rgba() will also 398 * set this color the first time it is called. 399 * 400 * Params: 401 * rgba = a #GdkRGBA to set the previous color with 402 * 403 * Since: 3.0 404 */ 405 public void setPreviousRgba(RGBA rgba) 406 { 407 gtk_color_selection_set_previous_rgba(gtkColorSelection, (rgba is null) ? null : rgba.getRGBAStruct()); 408 } 409 410 protected class OnColorChangedDelegateWrapper 411 { 412 static OnColorChangedDelegateWrapper[] listeners; 413 void delegate(ColorSelection) dlg; 414 gulong handlerId; 415 416 this(void delegate(ColorSelection) dlg) 417 { 418 this.dlg = dlg; 419 this.listeners ~= this; 420 } 421 422 void remove(OnColorChangedDelegateWrapper source) 423 { 424 foreach(index, wrapper; listeners) 425 { 426 if (wrapper.handlerId == source.handlerId) 427 { 428 listeners[index] = null; 429 listeners = std.algorithm.remove(listeners, index); 430 break; 431 } 432 } 433 } 434 } 435 436 /** 437 * This signal is emitted when the color changes in the #GtkColorSelection 438 * according to its update policy. 439 */ 440 gulong addOnColorChanged(void delegate(ColorSelection) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 441 { 442 auto wrapper = new OnColorChangedDelegateWrapper(dlg); 443 wrapper.handlerId = Signals.connectData( 444 this, 445 "color-changed", 446 cast(GCallback)&callBackColorChanged, 447 cast(void*)wrapper, 448 cast(GClosureNotify)&callBackColorChangedDestroy, 449 connectFlags); 450 return wrapper.handlerId; 451 } 452 453 extern(C) static void callBackColorChanged(GtkColorSelection* colorselectionStruct, OnColorChangedDelegateWrapper wrapper) 454 { 455 wrapper.dlg(wrapper.outer); 456 } 457 458 extern(C) static void callBackColorChangedDestroy(OnColorChangedDelegateWrapper wrapper, GClosure* closure) 459 { 460 wrapper.remove(wrapper); 461 } 462 }