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