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