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.ColorButton; 26 27 private import gdk.Color; 28 private import gdk.RGBA; 29 private import glib.ConstructionException; 30 private import glib.MemorySlice; 31 private import glib.Str; 32 private import gobject.ObjectG; 33 private import gobject.Signals; 34 private import gtk.Button; 35 private import gtk.ColorChooserIF; 36 private import gtk.ColorChooserT; 37 private import gtk.Widget; 38 private import gtk.c.functions; 39 public import gtk.c.types; 40 public import gtkc.gtktypes; 41 private import std.algorithm; 42 43 44 /** 45 * The #GtkColorButton is a button which displays the currently selected 46 * color and allows to open a color selection dialog to change the color. 47 * It is suitable widget for selecting a color in a preference dialog. 48 * 49 * # CSS nodes 50 * 51 * GtkColorButton has a single CSS node with name button. To differentiate 52 * it from a plain #GtkButton, it gets the .color style class. 53 */ 54 public class ColorButton : Button, ColorChooserIF 55 { 56 /** the main Gtk struct */ 57 protected GtkColorButton* gtkColorButton; 58 59 /** Get the main Gtk struct */ 60 public GtkColorButton* getColorButtonStruct(bool transferOwnership = false) 61 { 62 if (transferOwnership) 63 ownedRef = false; 64 return gtkColorButton; 65 } 66 67 /** the main Gtk struct as a void* */ 68 protected override void* getStruct() 69 { 70 return cast(void*)gtkColorButton; 71 } 72 73 /** 74 * Sets our main struct and passes it to the parent class. 75 */ 76 public this (GtkColorButton* gtkColorButton, bool ownedRef = false) 77 { 78 this.gtkColorButton = gtkColorButton; 79 super(cast(GtkButton*)gtkColorButton, ownedRef); 80 } 81 82 // add the ColorChooser capabilities 83 mixin ColorChooserT!(GtkColorButton); 84 85 86 /** */ 87 public static GType getType() 88 { 89 return gtk_color_button_get_type(); 90 } 91 92 /** 93 * Creates a new color button. 94 * 95 * This returns a widget in the form of a small button containing 96 * a swatch representing the current selected color. When the button 97 * is clicked, a color-selection dialog will open, allowing the user 98 * to select a color. The swatch will be updated to reflect the new 99 * color when the user finishes. 100 * 101 * Returns: a new color button 102 * 103 * Since: 2.4 104 * 105 * Throws: ConstructionException GTK+ fails to create the object. 106 */ 107 public this() 108 { 109 auto p = gtk_color_button_new(); 110 111 if(p is null) 112 { 113 throw new ConstructionException("null returned by new"); 114 } 115 116 this(cast(GtkColorButton*) p); 117 } 118 119 /** 120 * Creates a new color button. 121 * 122 * Deprecated: Use gtk_color_button_new_with_rgba() instead. 123 * 124 * Params: 125 * color = A #GdkColor to set the current color with 126 * 127 * Returns: a new color button 128 * 129 * Since: 2.4 130 * 131 * Throws: ConstructionException GTK+ fails to create the object. 132 */ 133 public this(Color color) 134 { 135 auto p = gtk_color_button_new_with_color((color is null) ? null : color.getColorStruct()); 136 137 if(p is null) 138 { 139 throw new ConstructionException("null returned by new_with_color"); 140 } 141 142 this(cast(GtkColorButton*) p); 143 } 144 145 /** 146 * Creates a new color button. 147 * 148 * Params: 149 * rgba = A #GdkRGBA to set the current color with 150 * 151 * Returns: a new color button 152 * 153 * Since: 3.0 154 * 155 * Throws: ConstructionException GTK+ fails to create the object. 156 */ 157 public this(RGBA rgba) 158 { 159 auto p = gtk_color_button_new_with_rgba((rgba is null) ? null : rgba.getRGBAStruct()); 160 161 if(p is null) 162 { 163 throw new ConstructionException("null returned by new_with_rgba"); 164 } 165 166 this(cast(GtkColorButton*) p); 167 } 168 169 /** 170 * Returns the current alpha value. 171 * 172 * Deprecated: Use gtk_color_chooser_get_rgba() instead. 173 * 174 * Returns: an integer between 0 and 65535 175 * 176 * Since: 2.4 177 */ 178 public ushort getAlpha() 179 { 180 return gtk_color_button_get_alpha(gtkColorButton); 181 } 182 183 /** 184 * Sets @color to be the current color in the #GtkColorButton widget. 185 * 186 * Deprecated: Use gtk_color_chooser_get_rgba() instead. 187 * 188 * Params: 189 * color = a #GdkColor to fill in with the current color 190 * 191 * Since: 2.4 192 */ 193 public void getColor(out Color color) 194 { 195 GdkColor* outcolor = sliceNew!GdkColor(); 196 197 gtk_color_button_get_color(gtkColorButton, outcolor); 198 199 color = ObjectG.getDObject!(Color)(outcolor, true); 200 } 201 202 /** 203 * Gets the title of the color selection dialog. 204 * 205 * Returns: An internal string, do not free the return value 206 * 207 * Since: 2.4 208 */ 209 public string getTitle() 210 { 211 return Str.toString(gtk_color_button_get_title(gtkColorButton)); 212 } 213 214 /** 215 * Sets the current opacity to be @alpha. 216 * 217 * Deprecated: Use gtk_color_chooser_set_rgba() instead. 218 * 219 * Params: 220 * alpha = an integer between 0 and 65535 221 * 222 * Since: 2.4 223 */ 224 public void setAlpha(ushort alpha) 225 { 226 gtk_color_button_set_alpha(gtkColorButton, alpha); 227 } 228 229 /** 230 * Sets the current color to be @color. 231 * 232 * Deprecated: Use gtk_color_chooser_set_rgba() instead. 233 * 234 * Params: 235 * color = A #GdkColor to set the current color with 236 * 237 * Since: 2.4 238 */ 239 public void setColor(Color color) 240 { 241 gtk_color_button_set_color(gtkColorButton, (color is null) ? null : color.getColorStruct()); 242 } 243 244 /** 245 * Sets the title for the color selection dialog. 246 * 247 * Params: 248 * title = String containing new window title 249 * 250 * Since: 2.4 251 */ 252 public void setTitle(string title) 253 { 254 gtk_color_button_set_title(gtkColorButton, Str.toStringz(title)); 255 } 256 257 /** 258 * The ::color-set signal is emitted when the user selects a color. 259 * When handling this signal, use gtk_color_button_get_rgba() to 260 * find out which color was just selected. 261 * 262 * Note that this signal is only emitted when the user 263 * changes the color. If you need to react to programmatic color changes 264 * as well, use the notify::color signal. 265 * 266 * Since: 2.4 267 */ 268 gulong addOnColorSet(void delegate(ColorButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 269 { 270 return Signals.connect(this, "color-set", dlg, connectFlags ^ ConnectFlags.SWAPPED); 271 } 272 }