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 84 public static GType getType() 85 { 86 return gtk_entry_buffer_get_type(); 87 } 88 89 /** 90 * Create a new GtkEntryBuffer object. 91 * 92 * Optionally, specify initial text to set in the buffer. 93 * 94 * Params: 95 * initialChars = initial buffer text, or %NULL 96 * nInitialChars = number of characters in @initial_chars, or -1 97 * 98 * Return: A new GtkEntryBuffer object. 99 * 100 * Since: 2.18 101 * 102 * Throws: ConstructionException GTK+ fails to create the object. 103 */ 104 public this(string initialChars, int nInitialChars) 105 { 106 auto p = gtk_entry_buffer_new(Str.toStringz(initialChars), nInitialChars); 107 108 if(p is null) 109 { 110 throw new ConstructionException("null returned by new"); 111 } 112 113 this(cast(GtkEntryBuffer*) p, true); 114 } 115 116 /** 117 * Deletes a sequence of characters from the buffer. @n_chars characters are 118 * deleted starting at @position. If @n_chars is negative, then all characters 119 * until the end of the text are deleted. 120 * 121 * If @position or @n_chars are out of bounds, then they are coerced to sane 122 * values. 123 * 124 * Note that the positions are specified in characters, not bytes. 125 * 126 * Params: 127 * position = position at which to delete text 128 * nChars = number of characters to delete 129 * 130 * Return: The number of characters deleted. 131 * 132 * Since: 2.18 133 */ 134 public uint deleteText(uint position, int nChars) 135 { 136 return gtk_entry_buffer_delete_text(gtkEntryBuffer, position, nChars); 137 } 138 139 /** 140 * Used when subclassing #GtkEntryBuffer 141 * 142 * Params: 143 * position = position at which text was deleted 144 * nChars = number of characters deleted 145 * 146 * Since: 2.18 147 */ 148 public void emitDeletedText(uint position, uint nChars) 149 { 150 gtk_entry_buffer_emit_deleted_text(gtkEntryBuffer, position, nChars); 151 } 152 153 /** 154 * Used when subclassing #GtkEntryBuffer 155 * 156 * Params: 157 * position = position at which text was inserted 158 * chars = text that was inserted 159 * nChars = number of characters inserted 160 * 161 * Since: 2.18 162 */ 163 public void emitInsertedText(uint position, string chars, uint nChars) 164 { 165 gtk_entry_buffer_emit_inserted_text(gtkEntryBuffer, position, Str.toStringz(chars), nChars); 166 } 167 168 /** 169 * Retrieves the length in bytes of the buffer. 170 * See gtk_entry_buffer_get_length(). 171 * 172 * Return: The byte length of the buffer. 173 * 174 * Since: 2.18 175 */ 176 public size_t getBytes() 177 { 178 return gtk_entry_buffer_get_bytes(gtkEntryBuffer); 179 } 180 181 /** 182 * Retrieves the length in characters of the buffer. 183 * 184 * Return: The number of characters in the buffer. 185 * 186 * Since: 2.18 187 */ 188 public uint getLength() 189 { 190 return gtk_entry_buffer_get_length(gtkEntryBuffer); 191 } 192 193 /** 194 * Retrieves the maximum allowed length of the text in 195 * @buffer. See gtk_entry_buffer_set_max_length(). 196 * 197 * Return: the maximum allowed number of characters 198 * in #GtkEntryBuffer, or 0 if there is no maximum. 199 * 200 * Since: 2.18 201 */ 202 public int getMaxLength() 203 { 204 return gtk_entry_buffer_get_max_length(gtkEntryBuffer); 205 } 206 207 /** 208 * Retrieves the contents of the buffer. 209 * 210 * The memory pointer returned by this call will not change 211 * unless this object emits a signal, or is finalized. 212 * 213 * Return: a pointer to the contents of the widget as a 214 * string. This string points to internally allocated 215 * storage in the buffer and must not be freed, modified or 216 * stored. 217 * 218 * Since: 2.18 219 */ 220 public string getText() 221 { 222 return Str.toString(gtk_entry_buffer_get_text(gtkEntryBuffer)); 223 } 224 225 /** 226 * Inserts @n_chars characters of @chars into the contents of the 227 * buffer, at position @position. 228 * 229 * If @n_chars is negative, then characters from chars will be inserted 230 * until a null-terminator is found. If @position or @n_chars are out of 231 * bounds, or the maximum buffer text length is exceeded, then they are 232 * coerced to sane values. 233 * 234 * Note that the position and length are in characters, not in bytes. 235 * 236 * Params: 237 * position = the position at which to insert text. 238 * chars = the text to insert into the buffer. 239 * nChars = the length of the text in characters, or -1 240 * 241 * Return: The number of characters actually inserted. 242 * 243 * Since: 2.18 244 */ 245 public uint insertText(uint position, string chars, int nChars) 246 { 247 return gtk_entry_buffer_insert_text(gtkEntryBuffer, position, Str.toStringz(chars), nChars); 248 } 249 250 /** 251 * Sets the maximum allowed length of the contents of the buffer. If 252 * the current contents are longer than the given length, then they 253 * will be truncated to fit. 254 * 255 * Params: 256 * maxLength = the maximum length of the entry buffer, or 0 for no maximum. 257 * (other than the maximum length of entries.) The value passed in will 258 * be clamped to the range 0-65536. 259 * 260 * Since: 2.18 261 */ 262 public void setMaxLength(int maxLength) 263 { 264 gtk_entry_buffer_set_max_length(gtkEntryBuffer, maxLength); 265 } 266 267 /** 268 * Sets the text in the buffer. 269 * 270 * This is roughly equivalent to calling gtk_entry_buffer_delete_text() 271 * and gtk_entry_buffer_insert_text(). 272 * 273 * Note that @n_chars is in characters, not in bytes. 274 * 275 * Params: 276 * chars = the new text 277 * nChars = the number of characters in @text, or -1 278 * 279 * Since: 2.18 280 */ 281 public void setText(string chars, int nChars) 282 { 283 gtk_entry_buffer_set_text(gtkEntryBuffer, Str.toStringz(chars), nChars); 284 } 285 286 int[string] connectedSignals; 287 288 void delegate(uint, uint, EntryBuffer)[] onDeletedTextListeners; 289 /** 290 * This signal is emitted after text is deleted from the buffer. 291 * 292 * Params: 293 * position = the position the text was deleted at. 294 * nChars = The number of characters that were deleted. 295 * 296 * Since: 2.18 297 */ 298 void addOnDeletedText(void delegate(uint, uint, EntryBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 299 { 300 if ( "deleted-text" !in connectedSignals ) 301 { 302 Signals.connectData( 303 this, 304 "deleted-text", 305 cast(GCallback)&callBackDeletedText, 306 cast(void*)this, 307 null, 308 connectFlags); 309 connectedSignals["deleted-text"] = 1; 310 } 311 onDeletedTextListeners ~= dlg; 312 } 313 extern(C) static void callBackDeletedText(GtkEntryBuffer* entrybufferStruct, uint position, uint nChars, EntryBuffer _entrybuffer) 314 { 315 foreach ( void delegate(uint, uint, EntryBuffer) dlg; _entrybuffer.onDeletedTextListeners ) 316 { 317 dlg(position, nChars, _entrybuffer); 318 } 319 } 320 321 void delegate(uint, string, uint, EntryBuffer)[] onInsertedTextListeners; 322 /** 323 * This signal is emitted after text is inserted into the buffer. 324 * 325 * Params: 326 * position = the position the text was inserted at. 327 * chars = The text that was inserted. 328 * nChars = The number of characters that were inserted. 329 * 330 * Since: 2.18 331 */ 332 void addOnInsertedText(void delegate(uint, string, uint, EntryBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 333 { 334 if ( "inserted-text" !in connectedSignals ) 335 { 336 Signals.connectData( 337 this, 338 "inserted-text", 339 cast(GCallback)&callBackInsertedText, 340 cast(void*)this, 341 null, 342 connectFlags); 343 connectedSignals["inserted-text"] = 1; 344 } 345 onInsertedTextListeners ~= dlg; 346 } 347 extern(C) static void callBackInsertedText(GtkEntryBuffer* entrybufferStruct, uint position, char* chars, uint nChars, EntryBuffer _entrybuffer) 348 { 349 foreach ( void delegate(uint, string, uint, EntryBuffer) dlg; _entrybuffer.onInsertedTextListeners ) 350 { 351 dlg(position, Str.toString(chars), nChars, _entrybuffer); 352 } 353 } 354 }