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