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.CellRendererToggle;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.CellRenderer;
32 public  import gtkc.gdktypes;
33 private import gtkc.gtk;
34 public  import gtkc.gtktypes;
35 private import std.algorithm;
36 
37 
38 /**
39  * #GtkCellRendererToggle renders a toggle button in a cell. The
40  * button is drawn as a radio or a checkbutton, depending on the
41  * #GtkCellRendererToggle:radio property.
42  * When activated, it emits the #GtkCellRendererToggle::toggled signal.
43  */
44 public class CellRendererToggle : CellRenderer
45 {
46 	/** the main Gtk struct */
47 	protected GtkCellRendererToggle* gtkCellRendererToggle;
48 
49 	/** Get the main Gtk struct */
50 	public GtkCellRendererToggle* getCellRendererToggleStruct()
51 	{
52 		return gtkCellRendererToggle;
53 	}
54 
55 	/** the main Gtk struct as a void* */
56 	protected override void* getStruct()
57 	{
58 		return cast(void*)gtkCellRendererToggle;
59 	}
60 
61 	protected override void setStruct(GObject* obj)
62 	{
63 		gtkCellRendererToggle = cast(GtkCellRendererToggle*)obj;
64 		super.setStruct(obj);
65 	}
66 
67 	/**
68 	 * Sets our main struct and passes it to the parent class.
69 	 */
70 	public this (GtkCellRendererToggle* gtkCellRendererToggle, bool ownedRef = false)
71 	{
72 		this.gtkCellRendererToggle = gtkCellRendererToggle;
73 		super(cast(GtkCellRenderer*)gtkCellRendererToggle, ownedRef);
74 	}
75 
76 
77 	/** */
78 	public static GType getType()
79 	{
80 		return gtk_cell_renderer_toggle_get_type();
81 	}
82 
83 	/**
84 	 * Creates a new #GtkCellRendererToggle. Adjust rendering
85 	 * parameters using object properties. Object properties can be set
86 	 * globally (with g_object_set()). Also, with #GtkTreeViewColumn, you
87 	 * can bind a property to a value in a #GtkTreeModel. For example, you
88 	 * can bind the “active” property on the cell renderer to a boolean value
89 	 * in the model, thus causing the check button to reflect the state of
90 	 * the model.
91 	 *
92 	 * Return: the new cell renderer
93 	 *
94 	 * Throws: ConstructionException GTK+ fails to create the object.
95 	 */
96 	public this()
97 	{
98 		auto p = gtk_cell_renderer_toggle_new();
99 		
100 		if(p is null)
101 		{
102 			throw new ConstructionException("null returned by new");
103 		}
104 		
105 		this(cast(GtkCellRendererToggle*) p);
106 	}
107 
108 	/**
109 	 * Returns whether the cell renderer is activatable. See
110 	 * gtk_cell_renderer_toggle_set_activatable().
111 	 *
112 	 * Return: %TRUE if the cell renderer is activatable.
113 	 *
114 	 * Since: 2.18
115 	 */
116 	public bool getActivatable()
117 	{
118 		return gtk_cell_renderer_toggle_get_activatable(gtkCellRendererToggle) != 0;
119 	}
120 
121 	/**
122 	 * Returns whether the cell renderer is active. See
123 	 * gtk_cell_renderer_toggle_set_active().
124 	 *
125 	 * Return: %TRUE if the cell renderer is active.
126 	 */
127 	public bool getActive()
128 	{
129 		return gtk_cell_renderer_toggle_get_active(gtkCellRendererToggle) != 0;
130 	}
131 
132 	/**
133 	 * Returns whether we’re rendering radio toggles rather than checkboxes.
134 	 *
135 	 * Return: %TRUE if we’re rendering radio toggles rather than checkboxes
136 	 */
137 	public bool getRadio()
138 	{
139 		return gtk_cell_renderer_toggle_get_radio(gtkCellRendererToggle) != 0;
140 	}
141 
142 	/**
143 	 * Makes the cell renderer activatable.
144 	 *
145 	 * Params:
146 	 *     setting = the value to set.
147 	 *
148 	 * Since: 2.18
149 	 */
150 	public void setActivatable(bool setting)
151 	{
152 		gtk_cell_renderer_toggle_set_activatable(gtkCellRendererToggle, setting);
153 	}
154 
155 	/**
156 	 * Activates or deactivates a cell renderer.
157 	 *
158 	 * Params:
159 	 *     setting = the value to set.
160 	 */
161 	public void setActive(bool setting)
162 	{
163 		gtk_cell_renderer_toggle_set_active(gtkCellRendererToggle, setting);
164 	}
165 
166 	/**
167 	 * If @radio is %TRUE, the cell renderer renders a radio toggle
168 	 * (i.e. a toggle in a group of mutually-exclusive toggles).
169 	 * If %FALSE, it renders a check toggle (a standalone boolean option).
170 	 * This can be set globally for the cell renderer, or changed just
171 	 * before rendering each cell in the model (for #GtkTreeView, you set
172 	 * up a per-row setting using #GtkTreeViewColumn to associate model
173 	 * columns with cell renderer properties).
174 	 *
175 	 * Params:
176 	 *     radio = %TRUE to make the toggle look like a radio button
177 	 */
178 	public void setRadio(bool radio)
179 	{
180 		gtk_cell_renderer_toggle_set_radio(gtkCellRendererToggle, radio);
181 	}
182 
183 	protected class OnToggledDelegateWrapper
184 	{
185 		void delegate(string, CellRendererToggle) dlg;
186 		gulong handlerId;
187 		ConnectFlags flags;
188 		this(void delegate(string, CellRendererToggle) dlg, gulong handlerId, ConnectFlags flags)
189 		{
190 			this.dlg = dlg;
191 			this.handlerId = handlerId;
192 			this.flags = flags;
193 		}
194 	}
195 	protected OnToggledDelegateWrapper[] onToggledListeners;
196 
197 	/**
198 	 * The ::toggled signal is emitted when the cell is toggled.
199 	 *
200 	 * It is the responsibility of the application to update the model
201 	 * with the correct value to store at @path.  Often this is simply the
202 	 * opposite of the value currently stored at @path.
203 	 *
204 	 * Params:
205 	 *     path = string representation of #GtkTreePath describing the
206 	 *         event location
207 	 */
208 	gulong addOnToggled(void delegate(string, CellRendererToggle) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
209 	{
210 		onToggledListeners ~= new OnToggledDelegateWrapper(dlg, 0, connectFlags);
211 		onToggledListeners[onToggledListeners.length - 1].handlerId = Signals.connectData(
212 			this,
213 			"toggled",
214 			cast(GCallback)&callBackToggled,
215 			cast(void*)onToggledListeners[onToggledListeners.length - 1],
216 			cast(GClosureNotify)&callBackToggledDestroy,
217 			connectFlags);
218 		return onToggledListeners[onToggledListeners.length - 1].handlerId;
219 	}
220 	
221 	extern(C) static void callBackToggled(GtkCellRendererToggle* cellrenderertoggleStruct, char* path,OnToggledDelegateWrapper wrapper)
222 	{
223 		wrapper.dlg(Str.toString(path), wrapper.outer);
224 	}
225 	
226 	extern(C) static void callBackToggledDestroy(OnToggledDelegateWrapper wrapper, GClosure* closure)
227 	{
228 		wrapper.outer.internalRemoveOnToggled(wrapper);
229 	}
230 
231 	protected void internalRemoveOnToggled(OnToggledDelegateWrapper source)
232 	{
233 		foreach(index, wrapper; onToggledListeners)
234 		{
235 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
236 			{
237 				onToggledListeners[index] = null;
238 				onToggledListeners = std.algorithm.remove(onToggledListeners, index);
239 				break;
240 			}
241 		}
242 	}
243 	
244 }