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