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