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