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