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