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