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