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.CellEditableT;
26 
27 public  import gdk.Event;
28 public  import gobject.Signals;
29 public  import gtkc.gdktypes;
30 public  import gtkc.gtk;
31 public  import gtkc.gtktypes;
32 public  import std.algorithm;
33 
34 
35 /**
36  * The #GtkCellEditable interface must be implemented for widgets to be usable
37  * when editing the contents of a #GtkTreeView cell.
38  */
39 public template CellEditableT(TStruct)
40 {
41 	/** Get the main Gtk struct */
42 	public GtkCellEditable* getCellEditableStruct()
43 	{
44 		return cast(GtkCellEditable*)getStruct();
45 	}
46 
47 
48 	/**
49 	 * Emits the #GtkCellEditable::editing-done signal.
50 	 */
51 	public void editingDone()
52 	{
53 		gtk_cell_editable_editing_done(getCellEditableStruct());
54 	}
55 
56 	/**
57 	 * Emits the #GtkCellEditable::remove-widget signal.
58 	 */
59 	public void removeWidget()
60 	{
61 		gtk_cell_editable_remove_widget(getCellEditableStruct());
62 	}
63 
64 	/**
65 	 * Begins editing on a @cell_editable. @event is the #GdkEvent that began
66 	 * the editing process. It may be %NULL, in the instance that editing was
67 	 * initiated through programatic means.
68 	 *
69 	 * Params:
70 	 *     event = A #GdkEvent, or %NULL
71 	 */
72 	public void startEditing(Event event)
73 	{
74 		gtk_cell_editable_start_editing(getCellEditableStruct(), (event is null) ? null : event.getEventStruct());
75 	}
76 
77 	protected class OnEditingDoneDelegateWrapper
78 	{
79 		void delegate(CellEditableIF) dlg;
80 		gulong handlerId;
81 		ConnectFlags flags;
82 		this(void delegate(CellEditableIF) dlg, gulong handlerId, ConnectFlags flags)
83 		{
84 			this.dlg = dlg;
85 			this.handlerId = handlerId;
86 			this.flags = flags;
87 		}
88 	}
89 	protected OnEditingDoneDelegateWrapper[] onEditingDoneListeners;
90 
91 	/**
92 	 * This signal is a sign for the cell renderer to update its
93 	 * value from the @cell_editable.
94 	 *
95 	 * Implementations of #GtkCellEditable are responsible for
96 	 * emitting this signal when they are done editing, e.g.
97 	 * #GtkEntry is emitting it when the user presses Enter.
98 	 *
99 	 * gtk_cell_editable_editing_done() is a convenience method
100 	 * for emitting #GtkCellEditable::editing-done.
101 	 */
102 	gulong addOnEditingDone(void delegate(CellEditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
103 	{
104 		onEditingDoneListeners ~= new OnEditingDoneDelegateWrapper(dlg, 0, connectFlags);
105 		onEditingDoneListeners[onEditingDoneListeners.length - 1].handlerId = Signals.connectData(
106 			this,
107 			"editing-done",
108 			cast(GCallback)&callBackEditingDone,
109 			cast(void*)onEditingDoneListeners[onEditingDoneListeners.length - 1],
110 			cast(GClosureNotify)&callBackEditingDoneDestroy,
111 			connectFlags);
112 		return onEditingDoneListeners[onEditingDoneListeners.length - 1].handlerId;
113 	}
114 	
115 	extern(C) static void callBackEditingDone(GtkCellEditable* celleditableStruct,OnEditingDoneDelegateWrapper wrapper)
116 	{
117 		wrapper.dlg(wrapper.outer);
118 	}
119 	
120 	extern(C) static void callBackEditingDoneDestroy(OnEditingDoneDelegateWrapper wrapper, GClosure* closure)
121 	{
122 		wrapper.outer.internalRemoveOnEditingDone(wrapper);
123 	}
124 
125 	protected void internalRemoveOnEditingDone(OnEditingDoneDelegateWrapper source)
126 	{
127 		foreach(index, wrapper; onEditingDoneListeners)
128 		{
129 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
130 			{
131 				onEditingDoneListeners[index] = null;
132 				onEditingDoneListeners = std.algorithm.remove(onEditingDoneListeners, index);
133 				break;
134 			}
135 		}
136 	}
137 	
138 
139 	protected class OnRemoveWidgetDelegateWrapper
140 	{
141 		void delegate(CellEditableIF) dlg;
142 		gulong handlerId;
143 		ConnectFlags flags;
144 		this(void delegate(CellEditableIF) dlg, gulong handlerId, ConnectFlags flags)
145 		{
146 			this.dlg = dlg;
147 			this.handlerId = handlerId;
148 			this.flags = flags;
149 		}
150 	}
151 	protected OnRemoveWidgetDelegateWrapper[] onRemoveWidgetListeners;
152 
153 	/**
154 	 * This signal is meant to indicate that the cell is finished
155 	 * editing, and the widget may now be destroyed.
156 	 *
157 	 * Implementations of #GtkCellEditable are responsible for
158 	 * emitting this signal when they are done editing. It must
159 	 * be emitted after the #GtkCellEditable::editing-done signal,
160 	 * to give the cell renderer a chance to update the cell's value
161 	 * before the widget is removed.
162 	 *
163 	 * gtk_cell_editable_remove_widget() is a convenience method
164 	 * for emitting #GtkCellEditable::remove-widget.
165 	 */
166 	gulong addOnRemoveWidget(void delegate(CellEditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
167 	{
168 		onRemoveWidgetListeners ~= new OnRemoveWidgetDelegateWrapper(dlg, 0, connectFlags);
169 		onRemoveWidgetListeners[onRemoveWidgetListeners.length - 1].handlerId = Signals.connectData(
170 			this,
171 			"remove-widget",
172 			cast(GCallback)&callBackRemoveWidget,
173 			cast(void*)onRemoveWidgetListeners[onRemoveWidgetListeners.length - 1],
174 			cast(GClosureNotify)&callBackRemoveWidgetDestroy,
175 			connectFlags);
176 		return onRemoveWidgetListeners[onRemoveWidgetListeners.length - 1].handlerId;
177 	}
178 	
179 	extern(C) static void callBackRemoveWidget(GtkCellEditable* celleditableStruct,OnRemoveWidgetDelegateWrapper wrapper)
180 	{
181 		wrapper.dlg(wrapper.outer);
182 	}
183 	
184 	extern(C) static void callBackRemoveWidgetDestroy(OnRemoveWidgetDelegateWrapper wrapper, GClosure* closure)
185 	{
186 		wrapper.outer.internalRemoveOnRemoveWidget(wrapper);
187 	}
188 
189 	protected void internalRemoveOnRemoveWidget(OnRemoveWidgetDelegateWrapper source)
190 	{
191 		foreach(index, wrapper; onRemoveWidgetListeners)
192 		{
193 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
194 			{
195 				onRemoveWidgetListeners[index] = null;
196 				onRemoveWidgetListeners = std.algorithm.remove(onRemoveWidgetListeners, index);
197 				break;
198 			}
199 		}
200 	}
201 	
202 }