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.CellRendererAccel;
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.CellRendererText;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 public  import gtkc.gtktypes;
36 private import std.algorithm;
37 
38 
39 /**
40  * #GtkCellRendererAccel displays a keyboard accelerator (i.e. a key
41  * combination like `Control + a`). If the cell renderer is editable,
42  * the accelerator can be changed by simply typing the new combination.
43  * 
44  * The #GtkCellRendererAccel cell renderer was added in GTK+ 2.10.
45  */
46 public class CellRendererAccel : CellRendererText
47 {
48 	/** the main Gtk struct */
49 	protected GtkCellRendererAccel* gtkCellRendererAccel;
50 
51 	/** Get the main Gtk struct */
52 	public GtkCellRendererAccel* getCellRendererAccelStruct(bool transferOwnership = false)
53 	{
54 		if (transferOwnership)
55 			ownedRef = false;
56 		return gtkCellRendererAccel;
57 	}
58 
59 	/** the main Gtk struct as a void* */
60 	protected override void* getStruct()
61 	{
62 		return cast(void*)gtkCellRendererAccel;
63 	}
64 
65 	protected override void setStruct(GObject* obj)
66 	{
67 		gtkCellRendererAccel = cast(GtkCellRendererAccel*)obj;
68 		super.setStruct(obj);
69 	}
70 
71 	/**
72 	 * Sets our main struct and passes it to the parent class.
73 	 */
74 	public this (GtkCellRendererAccel* gtkCellRendererAccel, bool ownedRef = false)
75 	{
76 		this.gtkCellRendererAccel = gtkCellRendererAccel;
77 		super(cast(GtkCellRendererText*)gtkCellRendererAccel, ownedRef);
78 	}
79 
80 
81 	/** */
82 	public static GType getType()
83 	{
84 		return gtk_cell_renderer_accel_get_type();
85 	}
86 
87 	/**
88 	 * Creates a new #GtkCellRendererAccel.
89 	 *
90 	 * Returns: the new cell renderer
91 	 *
92 	 * Since: 2.10
93 	 *
94 	 * Throws: ConstructionException GTK+ fails to create the object.
95 	 */
96 	public this()
97 	{
98 		auto p = gtk_cell_renderer_accel_new();
99 
100 		if(p is null)
101 		{
102 			throw new ConstructionException("null returned by new");
103 		}
104 
105 		this(cast(GtkCellRendererAccel*) p);
106 	}
107 
108 	protected class OnAccelClearedDelegateWrapper
109 	{
110 		void delegate(string, CellRendererAccel) dlg;
111 		gulong handlerId;
112 
113 		this(void delegate(string, CellRendererAccel) dlg)
114 		{
115 			this.dlg = dlg;
116 			onAccelClearedListeners ~= this;
117 		}
118 
119 		void remove(OnAccelClearedDelegateWrapper source)
120 		{
121 			foreach(index, wrapper; onAccelClearedListeners)
122 			{
123 				if (wrapper.handlerId == source.handlerId)
124 				{
125 					onAccelClearedListeners[index] = null;
126 					onAccelClearedListeners = std.algorithm.remove(onAccelClearedListeners, index);
127 					break;
128 				}
129 			}
130 		}
131 	}
132 	OnAccelClearedDelegateWrapper[] onAccelClearedListeners;
133 
134 	/**
135 	 * Gets emitted when the user has removed the accelerator.
136 	 *
137 	 * Params:
138 	 *     pathString = the path identifying the row of the edited cell
139 	 *
140 	 * Since: 2.10
141 	 */
142 	gulong addOnAccelCleared(void delegate(string, CellRendererAccel) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
143 	{
144 		auto wrapper = new OnAccelClearedDelegateWrapper(dlg);
145 		wrapper.handlerId = Signals.connectData(
146 			this,
147 			"accel-cleared",
148 			cast(GCallback)&callBackAccelCleared,
149 			cast(void*)wrapper,
150 			cast(GClosureNotify)&callBackAccelClearedDestroy,
151 			connectFlags);
152 		return wrapper.handlerId;
153 	}
154 
155 	extern(C) static void callBackAccelCleared(GtkCellRendererAccel* cellrendereraccelStruct, char* pathString, OnAccelClearedDelegateWrapper wrapper)
156 	{
157 		wrapper.dlg(Str.toString(pathString), wrapper.outer);
158 	}
159 
160 	extern(C) static void callBackAccelClearedDestroy(OnAccelClearedDelegateWrapper wrapper, GClosure* closure)
161 	{
162 		wrapper.remove(wrapper);
163 	}
164 
165 	protected class OnAccelEditedDelegateWrapper
166 	{
167 		void delegate(string, uint, GdkModifierType, uint, CellRendererAccel) dlg;
168 		gulong handlerId;
169 
170 		this(void delegate(string, uint, GdkModifierType, uint, CellRendererAccel) dlg)
171 		{
172 			this.dlg = dlg;
173 			onAccelEditedListeners ~= this;
174 		}
175 
176 		void remove(OnAccelEditedDelegateWrapper source)
177 		{
178 			foreach(index, wrapper; onAccelEditedListeners)
179 			{
180 				if (wrapper.handlerId == source.handlerId)
181 				{
182 					onAccelEditedListeners[index] = null;
183 					onAccelEditedListeners = std.algorithm.remove(onAccelEditedListeners, index);
184 					break;
185 				}
186 			}
187 		}
188 	}
189 	OnAccelEditedDelegateWrapper[] onAccelEditedListeners;
190 
191 	/**
192 	 * Gets emitted when the user has selected a new accelerator.
193 	 *
194 	 * Params:
195 	 *     pathString = the path identifying the row of the edited cell
196 	 *     accelKey = the new accelerator keyval
197 	 *     accelMods = the new acclerator modifier mask
198 	 *     hardwareKeycode = the keycode of the new accelerator
199 	 *
200 	 * Since: 2.10
201 	 */
202 	gulong addOnAccelEdited(void delegate(string, uint, GdkModifierType, uint, CellRendererAccel) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
203 	{
204 		auto wrapper = new OnAccelEditedDelegateWrapper(dlg);
205 		wrapper.handlerId = Signals.connectData(
206 			this,
207 			"accel-edited",
208 			cast(GCallback)&callBackAccelEdited,
209 			cast(void*)wrapper,
210 			cast(GClosureNotify)&callBackAccelEditedDestroy,
211 			connectFlags);
212 		return wrapper.handlerId;
213 	}
214 
215 	extern(C) static void callBackAccelEdited(GtkCellRendererAccel* cellrendereraccelStruct, char* pathString, uint accelKey, GdkModifierType accelMods, uint hardwareKeycode, OnAccelEditedDelegateWrapper wrapper)
216 	{
217 		wrapper.dlg(Str.toString(pathString), accelKey, accelMods, hardwareKeycode, wrapper.outer);
218 	}
219 
220 	extern(C) static void callBackAccelEditedDestroy(OnAccelEditedDelegateWrapper wrapper, GClosure* closure)
221 	{
222 		wrapper.remove(wrapper);
223 	}
224 }