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.ColorChooserT; 26 27 public import gdk.RGBA; 28 public import gobject.ObjectG; 29 public import gobject.Signals; 30 public import gtkc.gdktypes; 31 public import gtkc.gtk; 32 public import gtkc.gtktypes; 33 34 35 /** 36 * #GtkColorChooser is an interface that is implemented by widgets 37 * for choosing colors. Depending on the situation, colors may be 38 * allowed to have alpha (translucency). 39 * 40 * In GTK+, the main widgets that implement this interface are 41 * #GtkColorChooserWidget, #GtkColorChooserDialog and #GtkColorButton. 42 */ 43 public template ColorChooserT(TStruct) 44 { 45 /** Get the main Gtk struct */ 46 public GtkColorChooser* getColorChooserStruct() 47 { 48 return cast(GtkColorChooser*)getStruct(); 49 } 50 51 52 /** 53 * Adds a palette to the color chooser. If @orientation is horizontal, 54 * the colors are grouped in rows, with @colors_per_line colors 55 * in each row. If @horizontal is %FALSE, the colors are grouped 56 * in columns instead. 57 * 58 * The default color palette of #GtkColorChooserWidget has 59 * 27 colors, organized in columns of 3 colors. The default gray 60 * palette has 9 grays in a single row. 61 * 62 * The layout of the color chooser widget works best when the 63 * palettes have 9-10 columns. 64 * 65 * Calling this function for the first time has the 66 * side effect of removing the default color and gray palettes 67 * from the color chooser. 68 * 69 * If @colors is %NULL, removes all previously added palettes. 70 * 71 * Params: 72 * orientation = %GTK_ORIENTATION_HORIZONTAL if the palette should 73 * be displayed in rows, %GTK_ORIENTATION_VERTICAL for columns 74 * colorsPerLine = the number of colors to show in each row/column 75 * nColors = the total number of elements in @colors 76 * colors = the colors of the palette, or %NULL 77 * 78 * Since: 3.4 79 */ 80 public void addPalette(GtkOrientation orientation, int colorsPerLine, RGBA[] colors) 81 { 82 GdkRGBA[] colorsArray = new GdkRGBA[colors.length]; 83 for ( int i = 0; i < colors.length; i++ ) 84 { 85 colorsArray[i] = *(colors[i].getRGBAStruct()); 86 } 87 88 gtk_color_chooser_add_palette(getColorChooserStruct(), orientation, colorsPerLine, cast(int)colors.length, colorsArray.ptr); 89 } 90 91 /** 92 * Gets the currently-selected color. 93 * 94 * Params: 95 * color = a #GdkRGBA to fill in with the current color 96 * 97 * Since: 3.4 98 */ 99 public void getRgba(out RGBA color) 100 { 101 GdkRGBA* outcolor = gMalloc!GdkRGBA(); 102 103 gtk_color_chooser_get_rgba(getColorChooserStruct(), outcolor); 104 105 color = ObjectG.getDObject!(RGBA)(outcolor, true); 106 } 107 108 /** 109 * Returns whether the color chooser shows the alpha channel. 110 * 111 * Return: %TRUE if the color chooser uses the alpha channel, 112 * %FALSE if not 113 * 114 * Since: 3.4 115 */ 116 public bool getUseAlpha() 117 { 118 return gtk_color_chooser_get_use_alpha(getColorChooserStruct()) != 0; 119 } 120 121 /** 122 * Sets the color. 123 * 124 * Params: 125 * color = the new color 126 * 127 * Since: 3.4 128 */ 129 public void setRgba(RGBA color) 130 { 131 gtk_color_chooser_set_rgba(getColorChooserStruct(), (color is null) ? null : color.getRGBAStruct()); 132 } 133 134 /** 135 * Sets whether or not the color chooser should use the alpha channel. 136 * 137 * Params: 138 * useAlpha = %TRUE if color chooser should use alpha channel, %FALSE if not 139 * 140 * Since: 3.4 141 */ 142 public void setUseAlpha(bool useAlpha) 143 { 144 gtk_color_chooser_set_use_alpha(getColorChooserStruct(), useAlpha); 145 } 146 147 int[string] connectedSignals; 148 149 void delegate(RGBA, ColorChooserIF)[] _onColorActivatedListeners; 150 @property void delegate(RGBA, ColorChooserIF)[] onColorActivatedListeners() 151 { 152 return _onColorActivatedListeners; 153 } 154 /** 155 * Emitted when a color is activated from the color chooser. 156 * This usually happens when the user clicks a color swatch, 157 * or a color is selected and the user presses one of the keys 158 * Space, Shift+Space, Return or Enter. 159 * 160 * Params: 161 * color = the color 162 * 163 * Since: 3.4 164 */ 165 void addOnColorActivated(void delegate(RGBA, ColorChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 166 { 167 if ( "color-activated" !in connectedSignals ) 168 { 169 Signals.connectData( 170 this, 171 "color-activated", 172 cast(GCallback)&callBackColorActivated, 173 cast(void*)cast(ColorChooserIF)this, 174 null, 175 connectFlags); 176 connectedSignals["color-activated"] = 1; 177 } 178 _onColorActivatedListeners ~= dlg; 179 } 180 extern(C) static void callBackColorActivated(GtkColorChooser* colorchooserStruct, GdkRGBA* color, ColorChooserIF _colorchooser) 181 { 182 foreach ( void delegate(RGBA, ColorChooserIF) dlg; _colorchooser.onColorActivatedListeners ) 183 { 184 dlg(ObjectG.getDObject!(RGBA)(color), _colorchooser); 185 } 186 } 187 }