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 	/**
66 	 * Sets our main struct and passes it to the parent class.
67 	 */
68 	public this (GtkCellRendererAccel* gtkCellRendererAccel, bool ownedRef = false)
69 	{
70 		this.gtkCellRendererAccel = gtkCellRendererAccel;
71 		super(cast(GtkCellRendererText*)gtkCellRendererAccel, ownedRef);
72 	}
73 
74 
75 	/** */
76 	public static GType getType()
77 	{
78 		return gtk_cell_renderer_accel_get_type();
79 	}
80 
81 	/**
82 	 * Creates a new #GtkCellRendererAccel.
83 	 *
84 	 * Returns: the new cell renderer
85 	 *
86 	 * Since: 2.10
87 	 *
88 	 * Throws: ConstructionException GTK+ fails to create the object.
89 	 */
90 	public this()
91 	{
92 		auto p = gtk_cell_renderer_accel_new();
93 
94 		if(p is null)
95 		{
96 			throw new ConstructionException("null returned by new");
97 		}
98 
99 		this(cast(GtkCellRendererAccel*) p);
100 	}
101 
102 	protected class OnAccelClearedDelegateWrapper
103 	{
104 		void delegate(string, CellRendererAccel) dlg;
105 		gulong handlerId;
106 
107 		this(void delegate(string, CellRendererAccel) dlg)
108 		{
109 			this.dlg = dlg;
110 			onAccelClearedListeners ~= this;
111 		}
112 
113 		void remove(OnAccelClearedDelegateWrapper source)
114 		{
115 			foreach(index, wrapper; onAccelClearedListeners)
116 			{
117 				if (wrapper.handlerId == source.handlerId)
118 				{
119 					onAccelClearedListeners[index] = null;
120 					onAccelClearedListeners = std.algorithm.remove(onAccelClearedListeners, index);
121 					break;
122 				}
123 			}
124 		}
125 	}
126 	OnAccelClearedDelegateWrapper[] onAccelClearedListeners;
127 
128 	/**
129 	 * Gets emitted when the user has removed the accelerator.
130 	 *
131 	 * Params:
132 	 *     pathString = the path identifying the row of the edited cell
133 	 *
134 	 * Since: 2.10
135 	 */
136 	gulong addOnAccelCleared(void delegate(string, CellRendererAccel) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
137 	{
138 		auto wrapper = new OnAccelClearedDelegateWrapper(dlg);
139 		wrapper.handlerId = Signals.connectData(
140 			this,
141 			"accel-cleared",
142 			cast(GCallback)&callBackAccelCleared,
143 			cast(void*)wrapper,
144 			cast(GClosureNotify)&callBackAccelClearedDestroy,
145 			connectFlags);
146 		return wrapper.handlerId;
147 	}
148 
149 	extern(C) static void callBackAccelCleared(GtkCellRendererAccel* cellrendereraccelStruct, char* pathString, OnAccelClearedDelegateWrapper wrapper)
150 	{
151 		wrapper.dlg(Str.toString(pathString), wrapper.outer);
152 	}
153 
154 	extern(C) static void callBackAccelClearedDestroy(OnAccelClearedDelegateWrapper wrapper, GClosure* closure)
155 	{
156 		wrapper.remove(wrapper);
157 	}
158 
159 	protected class OnAccelEditedDelegateWrapper
160 	{
161 		void delegate(string, uint, GdkModifierType, uint, CellRendererAccel) dlg;
162 		gulong handlerId;
163 
164 		this(void delegate(string, uint, GdkModifierType, uint, CellRendererAccel) dlg)
165 		{
166 			this.dlg = dlg;
167 			onAccelEditedListeners ~= this;
168 		}
169 
170 		void remove(OnAccelEditedDelegateWrapper source)
171 		{
172 			foreach(index, wrapper; onAccelEditedListeners)
173 			{
174 				if (wrapper.handlerId == source.handlerId)
175 				{
176 					onAccelEditedListeners[index] = null;
177 					onAccelEditedListeners = std.algorithm.remove(onAccelEditedListeners, index);
178 					break;
179 				}
180 			}
181 		}
182 	}
183 	OnAccelEditedDelegateWrapper[] onAccelEditedListeners;
184 
185 	/**
186 	 * Gets emitted when the user has selected a new accelerator.
187 	 *
188 	 * Params:
189 	 *     pathString = the path identifying the row of the edited cell
190 	 *     accelKey = the new accelerator keyval
191 	 *     accelMods = the new acclerator modifier mask
192 	 *     hardwareKeycode = the keycode of the new accelerator
193 	 *
194 	 * Since: 2.10
195 	 */
196 	gulong addOnAccelEdited(void delegate(string, uint, GdkModifierType, uint, CellRendererAccel) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
197 	{
198 		auto wrapper = new OnAccelEditedDelegateWrapper(dlg);
199 		wrapper.handlerId = Signals.connectData(
200 			this,
201 			"accel-edited",
202 			cast(GCallback)&callBackAccelEdited,
203 			cast(void*)wrapper,
204 			cast(GClosureNotify)&callBackAccelEditedDestroy,
205 			connectFlags);
206 		return wrapper.handlerId;
207 	}
208 
209 	extern(C) static void callBackAccelEdited(GtkCellRendererAccel* cellrendereraccelStruct, char* pathString, uint accelKey, GdkModifierType accelMods, uint hardwareKeycode, OnAccelEditedDelegateWrapper wrapper)
210 	{
211 		wrapper.dlg(Str.toString(pathString), accelKey, accelMods, hardwareKeycode, wrapper.outer);
212 	}
213 
214 	extern(C) static void callBackAccelEditedDestroy(OnAccelEditedDelegateWrapper wrapper, GClosure* closure)
215 	{
216 		wrapper.remove(wrapper);
217 	}
218 }