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 * Conversion parameters: 26 * inFile = GtkColorButton.html 27 * outPack = gtk 28 * outFile = ColorButton 29 * strct = GtkColorButton 30 * realStrct= 31 * ctorStrct= 32 * clss = ColorButton 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * - ColorChooserIF 40 * prefixes: 41 * - gtk_color_button_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * - gtk_color_button_set_rgba 46 * - gtk_color_button_get_rgba 47 * - gtk_color_button_set_use_alpha 48 * - gtk_color_button_get_use_alpha 49 * omit signals: 50 * imports: 51 * - glib.Str 52 * - gdk.Color 53 * - gdk.RGBA 54 * - gtk.ColorChooserIF 55 * - gtk.ColorChooserT 56 * structWrap: 57 * - GdkColor* -> Color 58 * - GdkRGBA* -> RGBA 59 * module aliases: 60 * local aliases: 61 * overrides: 62 */ 63 64 module gtk.ColorButton; 65 66 public import gtkc.gtktypes; 67 68 private import gtkc.gtk; 69 private import glib.ConstructionException; 70 private import gobject.ObjectG; 71 72 private import gobject.Signals; 73 public import gtkc.gdktypes; 74 private import glib.Str; 75 private import gdk.Color; 76 private import gdk.RGBA; 77 private import gtk.ColorChooserIF; 78 private import gtk.ColorChooserT; 79 80 81 private import gtk.Button; 82 83 /** 84 * The GtkColorButton is a button which displays the currently selected 85 * color an allows to open a color selection dialog to change the color. 86 * It is suitable widget for selecting a color in a preference dialog. 87 */ 88 public class ColorButton : Button, ColorChooserIF 89 { 90 91 /** the main Gtk struct */ 92 protected GtkColorButton* gtkColorButton; 93 94 95 /** Get the main Gtk struct */ 96 public GtkColorButton* getColorButtonStruct() 97 { 98 return gtkColorButton; 99 } 100 101 102 /** the main Gtk struct as a void* */ 103 protected override void* getStruct() 104 { 105 return cast(void*)gtkColorButton; 106 } 107 108 /** 109 * Sets our main struct and passes it to the parent class 110 */ 111 public this (GtkColorButton* gtkColorButton) 112 { 113 super(cast(GtkButton*)gtkColorButton); 114 this.gtkColorButton = gtkColorButton; 115 } 116 117 protected override void setStruct(GObject* obj) 118 { 119 super.setStruct(obj); 120 gtkColorButton = cast(GtkColorButton*)obj; 121 } 122 123 // add the ColorChooser capabilities 124 mixin ColorChooserT!(GtkColorButton); 125 126 /** 127 */ 128 int[string] connectedSignals; 129 130 void delegate(ColorButton)[] onColorSetListeners; 131 /** 132 * The ::color-set signal is emitted when the user selects a color. 133 * When handling this signal, use gtk_color_button_get_rgba() to 134 * find out which color was just selected. 135 * Note that this signal is only emitted when the user 136 * changes the color. If you need to react to programmatic color changes 137 * as well, use the notify::color signal. 138 * Since 2.4 139 * See Also 140 * GtkColorSelectionDialog, GtkFontButton 141 */ 142 void addOnColorSet(void delegate(ColorButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 143 { 144 if ( !("color-set" in connectedSignals) ) 145 { 146 Signals.connectData( 147 getStruct(), 148 "color-set", 149 cast(GCallback)&callBackColorSet, 150 cast(void*)this, 151 null, 152 connectFlags); 153 connectedSignals["color-set"] = 1; 154 } 155 onColorSetListeners ~= dlg; 156 } 157 extern(C) static void callBackColorSet(GtkColorButton* widgetStruct, ColorButton _colorButton) 158 { 159 foreach ( void delegate(ColorButton) dlg ; _colorButton.onColorSetListeners ) 160 { 161 dlg(_colorButton); 162 } 163 } 164 165 166 /** 167 * Creates a new color button. 168 * This returns a widget in the form of a small button containing 169 * a swatch representing the current selected color. When the button 170 * is clicked, a color-selection dialog will open, allowing the user 171 * to select a color. The swatch will be updated to reflect the new 172 * color when the user finishes. 173 * Since 2.4 174 * Throws: ConstructionException GTK+ fails to create the object. 175 */ 176 public this () 177 { 178 // GtkWidget * gtk_color_button_new (void); 179 auto p = gtk_color_button_new(); 180 if(p is null) 181 { 182 throw new ConstructionException("null returned by gtk_color_button_new()"); 183 } 184 this(cast(GtkColorButton*) p); 185 } 186 187 /** 188 * Warning 189 * gtk_color_button_new_with_color has been deprecated since version 3.4 and should not be used in newly-written code. Use gtk_color_button_new_with_rgba() instead. 190 * Creates a new color button. 191 * Since 2.4 192 * Params: 193 * color = A GdkColor to set the current color with 194 * Throws: ConstructionException GTK+ fails to create the object. 195 */ 196 public this (Color color) 197 { 198 // GtkWidget * gtk_color_button_new_with_color (const GdkColor *color); 199 auto p = gtk_color_button_new_with_color((color is null) ? null : color.getColorStruct()); 200 if(p is null) 201 { 202 throw new ConstructionException("null returned by gtk_color_button_new_with_color((color is null) ? null : color.getColorStruct())"); 203 } 204 this(cast(GtkColorButton*) p); 205 } 206 207 /** 208 * Creates a new color button. 209 * Params: 210 * rgba = A GdkRGBA to set the current color with 211 * Throws: ConstructionException GTK+ fails to create the object. 212 */ 213 public this (RGBA rgba) 214 { 215 // GtkWidget * gtk_color_button_new_with_rgba (const GdkRGBA *rgba); 216 auto p = gtk_color_button_new_with_rgba((rgba is null) ? null : rgba.getRGBAStruct()); 217 if(p is null) 218 { 219 throw new ConstructionException("null returned by gtk_color_button_new_with_rgba((rgba is null) ? null : rgba.getRGBAStruct())"); 220 } 221 this(cast(GtkColorButton*) p); 222 } 223 224 /** 225 * Warning 226 * gtk_color_button_set_color is deprecated and should not be used in newly-written code. Use gtk_color_chooser_set_rgba() instead. 227 * Sets the current color to be color. 228 * Since 2.4 229 * Params: 230 * color = A GdkColor to set the current color with 231 */ 232 public void setColor(Color color) 233 { 234 // void gtk_color_button_set_color (GtkColorButton *button, const GdkColor *color); 235 gtk_color_button_set_color(gtkColorButton, (color is null) ? null : color.getColorStruct()); 236 } 237 238 /** 239 * Warning 240 * gtk_color_button_get_color has been deprecated since version 3.4 and should not be used in newly-written code. Use gtk_color_chooser_get_rgba() instead. 241 * Sets color to be the current color in the GtkColorButton widget. 242 * Since 2.4 243 * Params: 244 * color = a GdkColor to fill in with the current color. [out] 245 */ 246 public void getColor(Color color) 247 { 248 // void gtk_color_button_get_color (GtkColorButton *button, GdkColor *color); 249 gtk_color_button_get_color(gtkColorButton, (color is null) ? null : color.getColorStruct()); 250 } 251 252 /** 253 * Warning 254 * gtk_color_button_set_alpha has been deprecated since version 3.4 and should not be used in newly-written code. Use gtk_color_chooser_set_rgba() instead. 255 * Sets the current opacity to be alpha. 256 * Since 2.4 257 * Params: 258 * alpha = an integer between 0 and 65535 259 */ 260 public void setAlpha(ushort alpha) 261 { 262 // void gtk_color_button_set_alpha (GtkColorButton *button, guint16 alpha); 263 gtk_color_button_set_alpha(gtkColorButton, alpha); 264 } 265 266 /** 267 * Warning 268 * gtk_color_button_get_alpha has been deprecated since version 3.4 and should not be used in newly-written code. Use gtk_color_chooser_get_rgba() instead. 269 * Returns the current alpha value. 270 * Since 2.4 271 * Returns: an integer between 0 and 65535 272 */ 273 public ushort getAlpha() 274 { 275 // guint16 gtk_color_button_get_alpha (GtkColorButton *button); 276 return gtk_color_button_get_alpha(gtkColorButton); 277 } 278 279 /** 280 * Sets the title for the color selection dialog. 281 * Since 2.4 282 * Params: 283 * title = String containing new window title 284 */ 285 public void setTitle(string title) 286 { 287 // void gtk_color_button_set_title (GtkColorButton *button, const gchar *title); 288 gtk_color_button_set_title(gtkColorButton, Str.toStringz(title)); 289 } 290 291 /** 292 * Gets the title of the color selection dialog. 293 * Since 2.4 294 * Returns: An internal string, do not free the return value 295 */ 296 public string getTitle() 297 { 298 // const gchar * gtk_color_button_get_title (GtkColorButton *button); 299 return Str.toString(gtk_color_button_get_title(gtkColorButton)); 300 } 301 }