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.RGBA;
28 private import glib.ConstructionException;
29 private import glib.Str;
30 private import glib.c.functions;
31 private import gobject.ObjectG;
32 private import gobject.Signals;
33 private import gtk.ColorChooserIF;
34 private import gtk.ColorChooserT;
35 private import gtk.Widget;
36 private import gtk.c.functions;
37 public  import gtk.c.types;
38 private import std.algorithm;
39 
40 
41 /**
42  * The `GtkColorButton` allows to open a color chooser dialog to change
43  * the color.
44  * 
45  * ![An example GtkColorButton](color-button.png)
46  * 
47  * It is suitable widget for selecting a color in a preference dialog.
48  * 
49  * # CSS nodes
50  * 
51  * ```
52  * colorbutton
53  * ╰── button.color
54  * ╰── [content]
55  * ```
56  * 
57  * `GtkColorButton` has a single CSS node with name colorbutton which
58  * contains a button node. To differentiate it from a plain `GtkButton`,
59  * it gets the .color style class.
60  */
61 public class ColorButton : Widget, ColorChooserIF
62 {
63 	/** the main Gtk struct */
64 	protected GtkColorButton* gtkColorButton;
65 
66 	/** Get the main Gtk struct */
67 	public GtkColorButton* getColorButtonStruct(bool transferOwnership = false)
68 	{
69 		if (transferOwnership)
70 			ownedRef = false;
71 		return gtkColorButton;
72 	}
73 
74 	/** the main Gtk struct as a void* */
75 	protected override void* getStruct()
76 	{
77 		return cast(void*)gtkColorButton;
78 	}
79 
80 	/**
81 	 * Sets our main struct and passes it to the parent class.
82 	 */
83 	public this (GtkColorButton* gtkColorButton, bool ownedRef = false)
84 	{
85 		this.gtkColorButton = gtkColorButton;
86 		super(cast(GtkWidget*)gtkColorButton, ownedRef);
87 	}
88 
89 	// add the ColorChooser capabilities
90 	mixin ColorChooserT!(GtkColorButton);
91 
92 
93 	/** */
94 	public static GType getType()
95 	{
96 		return gtk_color_button_get_type();
97 	}
98 
99 	/**
100 	 * Creates a new color button.
101 	 *
102 	 * This returns a widget in the form of a small button containing
103 	 * a swatch representing the current selected color. When the button
104 	 * is clicked, a color chooser dialog will open, allowing the user
105 	 * to select a color. The swatch will be updated to reflect the new
106 	 * color when the user finishes.
107 	 *
108 	 * Returns: a new color button
109 	 *
110 	 * Throws: ConstructionException GTK+ fails to create the object.
111 	 */
112 	public this()
113 	{
114 		auto __p = gtk_color_button_new();
115 
116 		if(__p is null)
117 		{
118 			throw new ConstructionException("null returned by new");
119 		}
120 
121 		this(cast(GtkColorButton*) __p);
122 	}
123 
124 	/**
125 	 * Creates a new color button showing the given color.
126 	 *
127 	 * Params:
128 	 *     rgba = A `GdkRGBA` to set the current color with
129 	 *
130 	 * Returns: a new color button
131 	 *
132 	 * Throws: ConstructionException GTK+ fails to create the object.
133 	 */
134 	public this(RGBA rgba)
135 	{
136 		auto __p = gtk_color_button_new_with_rgba((rgba is null) ? null : rgba.getRGBAStruct());
137 
138 		if(__p is null)
139 		{
140 			throw new ConstructionException("null returned by new_with_rgba");
141 		}
142 
143 		this(cast(GtkColorButton*) __p);
144 	}
145 
146 	/**
147 	 * Gets whether the dialog is modal.
148 	 *
149 	 * Returns: %TRUE if the dialog is modal
150 	 */
151 	public bool getModal()
152 	{
153 		return gtk_color_button_get_modal(gtkColorButton) != 0;
154 	}
155 
156 	/**
157 	 * Gets the title of the color chooser dialog.
158 	 *
159 	 * Returns: An internal string, do not free the return value
160 	 */
161 	public string getTitle()
162 	{
163 		return Str.toString(gtk_color_button_get_title(gtkColorButton));
164 	}
165 
166 	/**
167 	 * Sets whether the dialog should be modal.
168 	 *
169 	 * Params:
170 	 *     modal = %TRUE to make the dialog modal
171 	 */
172 	public void setModal(bool modal)
173 	{
174 		gtk_color_button_set_modal(gtkColorButton, modal);
175 	}
176 
177 	/**
178 	 * Sets the title for the color chooser dialog.
179 	 *
180 	 * Params:
181 	 *     title = String containing new window title
182 	 */
183 	public void setTitle(string title)
184 	{
185 		gtk_color_button_set_title(gtkColorButton, Str.toStringz(title));
186 	}
187 
188 	/**
189 	 * Emitted when the user selects a color.
190 	 *
191 	 * When handling this signal, use [method@Gtk.ColorChooser.get_rgba]
192 	 * to find out which color was just selected.
193 	 *
194 	 * Note that this signal is only emitted when the user changes the color.
195 	 * If you need to react to programmatic color changes as well, use
196 	 * the notify::color signal.
197 	 */
198 	gulong addOnColorSet(void delegate(ColorButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
199 	{
200 		return Signals.connect(this, "color-set", dlg, connectFlags ^ ConnectFlags.SWAPPED);
201 	}
202 }