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.EntryBuffer;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 public  import gtkc.gdktypes;
32 private import gtkc.gtk;
33 public  import gtkc.gtktypes;
34 
35 
36 /**
37  * The #GtkEntryBuffer class contains the actual text displayed in a
38  * #GtkEntry widget.
39  * 
40  * A single #GtkEntryBuffer object can be shared by multiple #GtkEntry
41  * widgets which will then share the same text content, but not the cursor
42  * position, visibility attributes, icon etc.
43  * 
44  * #GtkEntryBuffer may be derived from. Such a derived class might allow
45  * text to be stored in an alternate location, such as non-pageable memory,
46  * useful in the case of important passwords. Or a derived class could
47  * integrate with an application’s concept of undo/redo.
48  */
49 public class EntryBuffer : ObjectG
50 {
51 	/** the main Gtk struct */
52 	protected GtkEntryBuffer* gtkEntryBuffer;
53 
54 	/** Get the main Gtk struct */
55 	public GtkEntryBuffer* getEntryBufferStruct()
56 	{
57 		return gtkEntryBuffer;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)gtkEntryBuffer;
64 	}
65 
66 	protected override void setStruct(GObject* obj)
67 	{
68 		gtkEntryBuffer = cast(GtkEntryBuffer*)obj;
69 		super.setStruct(obj);
70 	}
71 
72 	/**
73 	 * Sets our main struct and passes it to the parent class.
74 	 */
75 	public this (GtkEntryBuffer* gtkEntryBuffer, bool ownedRef = false)
76 	{
77 		this.gtkEntryBuffer = gtkEntryBuffer;
78 		super(cast(GObject*)gtkEntryBuffer, ownedRef);
79 	}
80 
81 
82 	/** */
83 	public static GType getType()
84 	{
85 		return gtk_entry_buffer_get_type();
86 	}
87 
88 	/**
89 	 * Create a new GtkEntryBuffer object.
90 	 *
91 	 * Optionally, specify initial text to set in the buffer.
92 	 *
93 	 * Params:
94 	 *     initialChars = initial buffer text, or %NULL
95 	 *     nInitialChars = number of characters in @initial_chars, or -1
96 	 *
97 	 * Return: A new GtkEntryBuffer object.
98 	 *
99 	 * Since: 2.18
100 	 *
101 	 * Throws: ConstructionException GTK+ fails to create the object.
102 	 */
103 	public this(string initialChars, int nInitialChars)
104 	{
105 		auto p = gtk_entry_buffer_new(Str.toStringz(initialChars), nInitialChars);
106 		
107 		if(p is null)
108 		{
109 			throw new ConstructionException("null returned by new");
110 		}
111 		
112 		this(cast(GtkEntryBuffer*) p, true);
113 	}
114 
115 	/**
116 	 * Deletes a sequence of characters from the buffer. @n_chars characters are
117 	 * deleted starting at @position. If @n_chars is negative, then all characters
118 	 * until the end of the text are deleted.
119 	 *
120 	 * If @position or @n_chars are out of bounds, then they are coerced to sane
121 	 * values.
122 	 *
123 	 * Note that the positions are specified in characters, not bytes.
124 	 *
125 	 * Params:
126 	 *     position = position at which to delete text
127 	 *     nChars = number of characters to delete
128 	 *
129 	 * Return: The number of characters deleted.
130 	 *
131 	 * Since: 2.18
132 	 */
133 	public uint deleteText(uint position, int nChars)
134 	{
135 		return gtk_entry_buffer_delete_text(gtkEntryBuffer, position, nChars);
136 	}
137 
138 	/**
139 	 * Used when subclassing #GtkEntryBuffer
140 	 *
141 	 * Params:
142 	 *     position = position at which text was deleted
143 	 *     nChars = number of characters deleted
144 	 *
145 	 * Since: 2.18
146 	 */
147 	public void emitDeletedText(uint position, uint nChars)
148 	{
149 		gtk_entry_buffer_emit_deleted_text(gtkEntryBuffer, position, nChars);
150 	}
151 
152 	/**
153 	 * Used when subclassing #GtkEntryBuffer
154 	 *
155 	 * Params:
156 	 *     position = position at which text was inserted
157 	 *     chars = text that was inserted
158 	 *     nChars = number of characters inserted
159 	 *
160 	 * Since: 2.18
161 	 */
162 	public void emitInsertedText(uint position, string chars, uint nChars)
163 	{
164 		gtk_entry_buffer_emit_inserted_text(gtkEntryBuffer, position, Str.toStringz(chars), nChars);
165 	}
166 
167 	/**
168 	 * Retrieves the length in bytes of the buffer.
169 	 * See gtk_entry_buffer_get_length().
170 	 *
171 	 * Return: The byte length of the buffer.
172 	 *
173 	 * Since: 2.18
174 	 */
175 	public size_t getBytes()
176 	{
177 		return gtk_entry_buffer_get_bytes(gtkEntryBuffer);
178 	}
179 
180 	/**
181 	 * Retrieves the length in characters of the buffer.
182 	 *
183 	 * Return: The number of characters in the buffer.
184 	 *
185 	 * Since: 2.18
186 	 */
187 	public uint getLength()
188 	{
189 		return gtk_entry_buffer_get_length(gtkEntryBuffer);
190 	}
191 
192 	/**
193 	 * Retrieves the maximum allowed length of the text in
194 	 * @buffer. See gtk_entry_buffer_set_max_length().
195 	 *
196 	 * Return: the maximum allowed number of characters
197 	 *     in #GtkEntryBuffer, or 0 if there is no maximum.
198 	 *
199 	 * Since: 2.18
200 	 */
201 	public int getMaxLength()
202 	{
203 		return gtk_entry_buffer_get_max_length(gtkEntryBuffer);
204 	}
205 
206 	/**
207 	 * Retrieves the contents of the buffer.
208 	 *
209 	 * The memory pointer returned by this call will not change
210 	 * unless this object emits a signal, or is finalized.
211 	 *
212 	 * Return: a pointer to the contents of the widget as a
213 	 *     string. This string points to internally allocated
214 	 *     storage in the buffer and must not be freed, modified or
215 	 *     stored.
216 	 *
217 	 * Since: 2.18
218 	 */
219 	public string getText()
220 	{
221 		return Str.toString(gtk_entry_buffer_get_text(gtkEntryBuffer));
222 	}
223 
224 	/**
225 	 * Inserts @n_chars characters of @chars into the contents of the
226 	 * buffer, at position @position.
227 	 *
228 	 * If @n_chars is negative, then characters from chars will be inserted
229 	 * until a null-terminator is found. If @position or @n_chars are out of
230 	 * bounds, or the maximum buffer text length is exceeded, then they are
231 	 * coerced to sane values.
232 	 *
233 	 * Note that the position and length are in characters, not in bytes.
234 	 *
235 	 * Params:
236 	 *     position = the position at which to insert text.
237 	 *     chars = the text to insert into the buffer.
238 	 *     nChars = the length of the text in characters, or -1
239 	 *
240 	 * Return: The number of characters actually inserted.
241 	 *
242 	 * Since: 2.18
243 	 */
244 	public uint insertText(uint position, string chars, int nChars)
245 	{
246 		return gtk_entry_buffer_insert_text(gtkEntryBuffer, position, Str.toStringz(chars), nChars);
247 	}
248 
249 	/**
250 	 * Sets the maximum allowed length of the contents of the buffer. If
251 	 * the current contents are longer than the given length, then they
252 	 * will be truncated to fit.
253 	 *
254 	 * Params:
255 	 *     maxLength = the maximum length of the entry buffer, or 0 for no maximum.
256 	 *         (other than the maximum length of entries.) The value passed in will
257 	 *         be clamped to the range 0-65536.
258 	 *
259 	 * Since: 2.18
260 	 */
261 	public void setMaxLength(int maxLength)
262 	{
263 		gtk_entry_buffer_set_max_length(gtkEntryBuffer, maxLength);
264 	}
265 
266 	/**
267 	 * Sets the text in the buffer.
268 	 *
269 	 * This is roughly equivalent to calling gtk_entry_buffer_delete_text()
270 	 * and gtk_entry_buffer_insert_text().
271 	 *
272 	 * Note that @n_chars is in characters, not in bytes.
273 	 *
274 	 * Params:
275 	 *     chars = the new text
276 	 *     nChars = the number of characters in @text, or -1
277 	 *
278 	 * Since: 2.18
279 	 */
280 	public void setText(string chars, int nChars)
281 	{
282 		gtk_entry_buffer_set_text(gtkEntryBuffer, Str.toStringz(chars), nChars);
283 	}
284 
285 	int[string] connectedSignals;
286 
287 	void delegate(uint, uint, EntryBuffer)[] onDeletedTextListeners;
288 	/**
289 	 * This signal is emitted after text is deleted from the buffer.
290 	 *
291 	 * Params:
292 	 *     position = the position the text was deleted at.
293 	 *     nChars = The number of characters that were deleted.
294 	 *
295 	 * Since: 2.18
296 	 */
297 	void addOnDeletedText(void delegate(uint, uint, EntryBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
298 	{
299 		if ( "deleted-text" !in connectedSignals )
300 		{
301 			Signals.connectData(
302 				this,
303 				"deleted-text",
304 				cast(GCallback)&callBackDeletedText,
305 				cast(void*)this,
306 				null,
307 				connectFlags);
308 			connectedSignals["deleted-text"] = 1;
309 		}
310 		onDeletedTextListeners ~= dlg;
311 	}
312 	extern(C) static void callBackDeletedText(GtkEntryBuffer* entrybufferStruct, uint position, uint nChars, EntryBuffer _entrybuffer)
313 	{
314 		foreach ( void delegate(uint, uint, EntryBuffer) dlg; _entrybuffer.onDeletedTextListeners )
315 		{
316 			dlg(position, nChars, _entrybuffer);
317 		}
318 	}
319 
320 	void delegate(uint, string, uint, EntryBuffer)[] onInsertedTextListeners;
321 	/**
322 	 * This signal is emitted after text is inserted into the buffer.
323 	 *
324 	 * Params:
325 	 *     position = the position the text was inserted at.
326 	 *     chars = The text that was inserted.
327 	 *     nChars = The number of characters that were inserted.
328 	 *
329 	 * Since: 2.18
330 	 */
331 	void addOnInsertedText(void delegate(uint, string, uint, EntryBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
332 	{
333 		if ( "inserted-text" !in connectedSignals )
334 		{
335 			Signals.connectData(
336 				this,
337 				"inserted-text",
338 				cast(GCallback)&callBackInsertedText,
339 				cast(void*)this,
340 				null,
341 				connectFlags);
342 			connectedSignals["inserted-text"] = 1;
343 		}
344 		onInsertedTextListeners ~= dlg;
345 	}
346 	extern(C) static void callBackInsertedText(GtkEntryBuffer* entrybufferStruct, uint position, char* chars, uint nChars, EntryBuffer _entrybuffer)
347 	{
348 		foreach ( void delegate(uint, string, uint, EntryBuffer) dlg; _entrybuffer.onInsertedTextListeners )
349 		{
350 			dlg(position, Str.toString(chars), nChars, _entrybuffer);
351 		}
352 	}
353 }