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