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 glib.c.functions;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 private import gtk.c.functions;
33 public  import gtk.c.types;
34 private import std.algorithm;
35 
36 
37 /**
38  * A `GtkEntryBuffer` hold the text displayed in a `GtkText` widget.
39  * 
40  * A single `GtkEntryBuffer` object can be shared by multiple widgets
41  * 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(bool transferOwnership = false)
56 	{
57 		if (transferOwnership)
58 			ownedRef = false;
59 		return gtkEntryBuffer;
60 	}
61 
62 	/** the main Gtk struct as a void* */
63 	protected override void* getStruct()
64 	{
65 		return cast(void*)gtkEntryBuffer;
66 	}
67 
68 	/**
69 	 * Sets our main struct and passes it to the parent class.
70 	 */
71 	public this (GtkEntryBuffer* gtkEntryBuffer, bool ownedRef = false)
72 	{
73 		this.gtkEntryBuffer = gtkEntryBuffer;
74 		super(cast(GObject*)gtkEntryBuffer, ownedRef);
75 	}
76 
77 
78 	/** */
79 	public static GType getType()
80 	{
81 		return gtk_entry_buffer_get_type();
82 	}
83 
84 	/**
85 	 * Create a new `GtkEntryBuffer` object.
86 	 *
87 	 * Optionally, specify initial text to set in the buffer.
88 	 *
89 	 * Params:
90 	 *     initialChars = initial buffer text, or %NULL
91 	 *     nInitialChars = number of characters in @initial_chars, or -1
92 	 *
93 	 * Returns: A new `GtkEntryBuffer` object.
94 	 *
95 	 * Throws: ConstructionException GTK+ fails to create the object.
96 	 */
97 	public this(string initialChars, int nInitialChars)
98 	{
99 		auto __p = gtk_entry_buffer_new(Str.toStringz(initialChars), nInitialChars);
100 
101 		if(__p is null)
102 		{
103 			throw new ConstructionException("null returned by new");
104 		}
105 
106 		this(cast(GtkEntryBuffer*) __p, true);
107 	}
108 
109 	/**
110 	 * Deletes a sequence of characters from the buffer.
111 	 *
112 	 * @n_chars characters are deleted starting at @position.
113 	 * If @n_chars is negative, then all characters until the
114 	 * end of the text are deleted.
115 	 *
116 	 * If @position or @n_chars are out of bounds, then they
117 	 * are coerced to sane values.
118 	 *
119 	 * Note that the positions are specified in characters,
120 	 * not bytes.
121 	 *
122 	 * Params:
123 	 *     position = position at which to delete text
124 	 *     nChars = number of characters to delete
125 	 *
126 	 * Returns: The number of characters deleted.
127 	 */
128 	public uint deleteText(uint position, int nChars)
129 	{
130 		return gtk_entry_buffer_delete_text(gtkEntryBuffer, position, nChars);
131 	}
132 
133 	/**
134 	 * Used when subclassing `GtkEntryBuffer`.
135 	 *
136 	 * Params:
137 	 *     position = position at which text was deleted
138 	 *     nChars = number of characters deleted
139 	 */
140 	public void emitDeletedText(uint position, uint nChars)
141 	{
142 		gtk_entry_buffer_emit_deleted_text(gtkEntryBuffer, position, nChars);
143 	}
144 
145 	/**
146 	 * Used when subclassing `GtkEntryBuffer`.
147 	 *
148 	 * Params:
149 	 *     position = position at which text was inserted
150 	 *     chars = text that was inserted
151 	 *     nChars = number of characters inserted
152 	 */
153 	public void emitInsertedText(uint position, string chars, uint nChars)
154 	{
155 		gtk_entry_buffer_emit_inserted_text(gtkEntryBuffer, position, Str.toStringz(chars), nChars);
156 	}
157 
158 	/**
159 	 * Retrieves the length in bytes of the buffer.
160 	 *
161 	 * See [method@Gtk.EntryBuffer.get_length].
162 	 *
163 	 * Returns: The byte length of the buffer.
164 	 */
165 	public size_t getBytes()
166 	{
167 		return gtk_entry_buffer_get_bytes(gtkEntryBuffer);
168 	}
169 
170 	/**
171 	 * Retrieves the length in characters of the buffer.
172 	 *
173 	 * Returns: The number of characters in the buffer.
174 	 */
175 	public uint getLength()
176 	{
177 		return gtk_entry_buffer_get_length(gtkEntryBuffer);
178 	}
179 
180 	/**
181 	 * Retrieves the maximum allowed length of the text in @buffer.
182 	 *
183 	 * Returns: the maximum allowed number of characters
184 	 *     in #GtkEntryBuffer, or 0 if there is no maximum.
185 	 */
186 	public int getMaxLength()
187 	{
188 		return gtk_entry_buffer_get_max_length(gtkEntryBuffer);
189 	}
190 
191 	/**
192 	 * Retrieves the contents of the buffer.
193 	 *
194 	 * The memory pointer returned by this call will not change
195 	 * unless this object emits a signal, or is finalized.
196 	 *
197 	 * Returns: a pointer to the contents of the widget as a
198 	 *     string. This string points to internally allocated storage
199 	 *     in the buffer and must not be freed, modified or stored.
200 	 */
201 	public string getText()
202 	{
203 		return Str.toString(gtk_entry_buffer_get_text(gtkEntryBuffer));
204 	}
205 
206 	/**
207 	 * Inserts @n_chars characters of @chars into the contents of the
208 	 * buffer, at position @position.
209 	 *
210 	 * If @n_chars is negative, then characters from chars will be inserted
211 	 * until a null-terminator is found. If @position or @n_chars are out of
212 	 * bounds, or the maximum buffer text length is exceeded, then they are
213 	 * coerced to sane values.
214 	 *
215 	 * Note that the position and length are in characters, not in bytes.
216 	 *
217 	 * Params:
218 	 *     position = the position at which to insert text.
219 	 *     chars = the text to insert into the buffer.
220 	 *     nChars = the length of the text in characters, or -1
221 	 *
222 	 * Returns: The number of characters actually inserted.
223 	 */
224 	public uint insertText(uint position, string chars, int nChars)
225 	{
226 		return gtk_entry_buffer_insert_text(gtkEntryBuffer, position, Str.toStringz(chars), nChars);
227 	}
228 
229 	/**
230 	 * Sets the maximum allowed length of the contents of the buffer.
231 	 *
232 	 * If the current contents are longer than the given length, then
233 	 * they will be truncated to fit.
234 	 *
235 	 * Params:
236 	 *     maxLength = the maximum length of the entry buffer, or 0 for no maximum.
237 	 *         (other than the maximum length of entries.) The value passed in will
238 	 *         be clamped to the range 0-65536.
239 	 */
240 	public void setMaxLength(int maxLength)
241 	{
242 		gtk_entry_buffer_set_max_length(gtkEntryBuffer, maxLength);
243 	}
244 
245 	/**
246 	 * Sets the text in the buffer.
247 	 *
248 	 * This is roughly equivalent to calling
249 	 * [method@Gtk.EntryBuffer.delete_text] and
250 	 * [method@Gtk.EntryBuffer.insert_text].
251 	 *
252 	 * Note that @n_chars is in characters, not in bytes.
253 	 *
254 	 * Params:
255 	 *     chars = the new text
256 	 *     nChars = the number of characters in @text, or -1
257 	 */
258 	public void setText(string chars, int nChars)
259 	{
260 		gtk_entry_buffer_set_text(gtkEntryBuffer, Str.toStringz(chars), nChars);
261 	}
262 
263 	/**
264 	 * The text is altered in the default handler for this signal.
265 	 *
266 	 * If you want access to the text after the text has been modified,
267 	 * use %G_CONNECT_AFTER.
268 	 *
269 	 * Params:
270 	 *     position = the position the text was deleted at.
271 	 *     nChars = The number of characters that were deleted.
272 	 */
273 	gulong addOnDeletedText(void delegate(uint, uint, EntryBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
274 	{
275 		return Signals.connect(this, "deleted-text", dlg, connectFlags ^ ConnectFlags.SWAPPED);
276 	}
277 
278 	/**
279 	 * This signal is emitted after text is inserted into the buffer.
280 	 *
281 	 * Params:
282 	 *     position = the position the text was inserted at.
283 	 *     chars = The text that was inserted.
284 	 *     nChars = The number of characters that were inserted.
285 	 */
286 	gulong addOnInsertedText(void delegate(uint, string, uint, EntryBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
287 	{
288 		return Signals.connect(this, "inserted-text", dlg, connectFlags ^ ConnectFlags.SWAPPED);
289 	}
290 }