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 public class EntryBuffer : ObjectG 51 { 52 /** the main Gtk struct */ 53 protected GtkEntryBuffer* gtkEntryBuffer; 54 55 /** Get the main Gtk struct */ 56 public GtkEntryBuffer* getEntryBufferStruct(bool transferOwnership = false) 57 { 58 if (transferOwnership) 59 ownedRef = false; 60 return gtkEntryBuffer; 61 } 62 63 /** the main Gtk struct as a void* */ 64 protected override void* getStruct() 65 { 66 return cast(void*)gtkEntryBuffer; 67 } 68 69 /** 70 * Sets our main struct and passes it to the parent class. 71 */ 72 public this (GtkEntryBuffer* gtkEntryBuffer, bool ownedRef = false) 73 { 74 this.gtkEntryBuffer = gtkEntryBuffer; 75 super(cast(GObject*)gtkEntryBuffer, ownedRef); 76 } 77 78 79 /** */ 80 public static GType getType() 81 { 82 return gtk_entry_buffer_get_type(); 83 } 84 85 /** 86 * Create a new GtkEntryBuffer object. 87 * 88 * Optionally, specify initial text to set in the buffer. 89 * 90 * Params: 91 * initialChars = initial buffer text, or %NULL 92 * nInitialChars = number of characters in @initial_chars, or -1 93 * 94 * Returns: A new GtkEntryBuffer object. 95 * 96 * Since: 2.18 97 * 98 * Throws: ConstructionException GTK+ fails to create the object. 99 */ 100 public this(string initialChars, int nInitialChars) 101 { 102 auto p = gtk_entry_buffer_new(Str.toStringz(initialChars), nInitialChars); 103 104 if(p is null) 105 { 106 throw new ConstructionException("null returned by new"); 107 } 108 109 this(cast(GtkEntryBuffer*) p, true); 110 } 111 112 /** 113 * Deletes a sequence of characters from the buffer. @n_chars characters are 114 * deleted starting at @position. If @n_chars is negative, then all characters 115 * until the end of the text are deleted. 116 * 117 * If @position or @n_chars are out of bounds, then they are coerced to sane 118 * values. 119 * 120 * Note that the positions are specified in characters, 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 * Since: 2.18 129 */ 130 public uint deleteText(uint position, int nChars) 131 { 132 return gtk_entry_buffer_delete_text(gtkEntryBuffer, position, nChars); 133 } 134 135 /** 136 * Used when subclassing #GtkEntryBuffer 137 * 138 * Params: 139 * position = position at which text was deleted 140 * nChars = number of characters deleted 141 * 142 * Since: 2.18 143 */ 144 public void emitDeletedText(uint position, uint nChars) 145 { 146 gtk_entry_buffer_emit_deleted_text(gtkEntryBuffer, position, nChars); 147 } 148 149 /** 150 * Used when subclassing #GtkEntryBuffer 151 * 152 * Params: 153 * position = position at which text was inserted 154 * chars = text that was inserted 155 * nChars = number of characters inserted 156 * 157 * Since: 2.18 158 */ 159 public void emitInsertedText(uint position, string chars, uint nChars) 160 { 161 gtk_entry_buffer_emit_inserted_text(gtkEntryBuffer, position, Str.toStringz(chars), nChars); 162 } 163 164 /** 165 * Retrieves the length in bytes of the buffer. 166 * See gtk_entry_buffer_get_length(). 167 * 168 * Returns: The byte length of the buffer. 169 * 170 * Since: 2.18 171 */ 172 public size_t getBytes() 173 { 174 return gtk_entry_buffer_get_bytes(gtkEntryBuffer); 175 } 176 177 /** 178 * Retrieves the length in characters of the buffer. 179 * 180 * Returns: The number of characters in the buffer. 181 * 182 * Since: 2.18 183 */ 184 public uint getLength() 185 { 186 return gtk_entry_buffer_get_length(gtkEntryBuffer); 187 } 188 189 /** 190 * Retrieves the maximum allowed length of the text in 191 * @buffer. See gtk_entry_buffer_set_max_length(). 192 * 193 * Returns: the maximum allowed number of characters 194 * in #GtkEntryBuffer, or 0 if there is no maximum. 195 * 196 * Since: 2.18 197 */ 198 public int getMaxLength() 199 { 200 return gtk_entry_buffer_get_max_length(gtkEntryBuffer); 201 } 202 203 /** 204 * Retrieves the contents of the buffer. 205 * 206 * The memory pointer returned by this call will not change 207 * unless this object emits a signal, or is finalized. 208 * 209 * Returns: a pointer to the contents of the widget as a 210 * string. This string points to internally allocated 211 * storage in the buffer and must not be freed, modified or 212 * stored. 213 * 214 * Since: 2.18 215 */ 216 public string getText() 217 { 218 return Str.toString(gtk_entry_buffer_get_text(gtkEntryBuffer)); 219 } 220 221 /** 222 * Inserts @n_chars characters of @chars into the contents of the 223 * buffer, at position @position. 224 * 225 * If @n_chars is negative, then characters from chars will be inserted 226 * until a null-terminator is found. If @position or @n_chars are out of 227 * bounds, or the maximum buffer text length is exceeded, then they are 228 * coerced to sane values. 229 * 230 * Note that the position and length are in characters, not in bytes. 231 * 232 * Params: 233 * position = the position at which to insert text. 234 * chars = the text to insert into the buffer. 235 * nChars = the length of the text in characters, or -1 236 * 237 * Returns: The number of characters actually inserted. 238 * 239 * Since: 2.18 240 */ 241 public uint insertText(uint position, string chars, int nChars) 242 { 243 return gtk_entry_buffer_insert_text(gtkEntryBuffer, position, Str.toStringz(chars), nChars); 244 } 245 246 /** 247 * Sets the maximum allowed length of the contents of the buffer. If 248 * the current contents are longer than the given length, then they 249 * will be truncated to fit. 250 * 251 * Params: 252 * maxLength = the maximum length of the entry buffer, or 0 for no maximum. 253 * (other than the maximum length of entries.) The value passed in will 254 * be clamped to the range 0-65536. 255 * 256 * Since: 2.18 257 */ 258 public void setMaxLength(int maxLength) 259 { 260 gtk_entry_buffer_set_max_length(gtkEntryBuffer, maxLength); 261 } 262 263 /** 264 * Sets the text in the buffer. 265 * 266 * This is roughly equivalent to calling gtk_entry_buffer_delete_text() 267 * and gtk_entry_buffer_insert_text(). 268 * 269 * Note that @n_chars is in characters, not in bytes. 270 * 271 * Params: 272 * chars = the new text 273 * nChars = the number of characters in @text, or -1 274 * 275 * Since: 2.18 276 */ 277 public void setText(string chars, int nChars) 278 { 279 gtk_entry_buffer_set_text(gtkEntryBuffer, Str.toStringz(chars), nChars); 280 } 281 282 protected class OnDeletedTextDelegateWrapper 283 { 284 void delegate(uint, uint, EntryBuffer) dlg; 285 gulong handlerId; 286 287 this(void delegate(uint, uint, EntryBuffer) dlg) 288 { 289 this.dlg = dlg; 290 onDeletedTextListeners ~= this; 291 } 292 293 void remove(OnDeletedTextDelegateWrapper source) 294 { 295 foreach(index, wrapper; onDeletedTextListeners) 296 { 297 if (wrapper.handlerId == source.handlerId) 298 { 299 onDeletedTextListeners[index] = null; 300 onDeletedTextListeners = std.algorithm.remove(onDeletedTextListeners, index); 301 break; 302 } 303 } 304 } 305 } 306 OnDeletedTextDelegateWrapper[] onDeletedTextListeners; 307 308 /** 309 * This signal is emitted after text is deleted from the buffer. 310 * 311 * Params: 312 * position = the position the text was deleted at. 313 * nChars = The number of characters that were deleted. 314 * 315 * Since: 2.18 316 */ 317 gulong addOnDeletedText(void delegate(uint, uint, EntryBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 318 { 319 auto wrapper = new OnDeletedTextDelegateWrapper(dlg); 320 wrapper.handlerId = Signals.connectData( 321 this, 322 "deleted-text", 323 cast(GCallback)&callBackDeletedText, 324 cast(void*)wrapper, 325 cast(GClosureNotify)&callBackDeletedTextDestroy, 326 connectFlags); 327 return wrapper.handlerId; 328 } 329 330 extern(C) static void callBackDeletedText(GtkEntryBuffer* entrybufferStruct, uint position, uint nChars, OnDeletedTextDelegateWrapper wrapper) 331 { 332 wrapper.dlg(position, nChars, wrapper.outer); 333 } 334 335 extern(C) static void callBackDeletedTextDestroy(OnDeletedTextDelegateWrapper wrapper, GClosure* closure) 336 { 337 wrapper.remove(wrapper); 338 } 339 340 protected class OnInsertedTextDelegateWrapper 341 { 342 void delegate(uint, string, uint, EntryBuffer) dlg; 343 gulong handlerId; 344 345 this(void delegate(uint, string, uint, EntryBuffer) dlg) 346 { 347 this.dlg = dlg; 348 onInsertedTextListeners ~= this; 349 } 350 351 void remove(OnInsertedTextDelegateWrapper source) 352 { 353 foreach(index, wrapper; onInsertedTextListeners) 354 { 355 if (wrapper.handlerId == source.handlerId) 356 { 357 onInsertedTextListeners[index] = null; 358 onInsertedTextListeners = std.algorithm.remove(onInsertedTextListeners, index); 359 break; 360 } 361 } 362 } 363 } 364 OnInsertedTextDelegateWrapper[] onInsertedTextListeners; 365 366 /** 367 * This signal is emitted after text is inserted into the buffer. 368 * 369 * Params: 370 * position = the position the text was inserted at. 371 * chars = The text that was inserted. 372 * nChars = The number of characters that were inserted. 373 * 374 * Since: 2.18 375 */ 376 gulong addOnInsertedText(void delegate(uint, string, uint, EntryBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 377 { 378 auto wrapper = new OnInsertedTextDelegateWrapper(dlg); 379 wrapper.handlerId = Signals.connectData( 380 this, 381 "inserted-text", 382 cast(GCallback)&callBackInsertedText, 383 cast(void*)wrapper, 384 cast(GClosureNotify)&callBackInsertedTextDestroy, 385 connectFlags); 386 return wrapper.handlerId; 387 } 388 389 extern(C) static void callBackInsertedText(GtkEntryBuffer* entrybufferStruct, uint position, char* chars, uint nChars, OnInsertedTextDelegateWrapper wrapper) 390 { 391 wrapper.dlg(position, Str.toString(chars), nChars, wrapper.outer); 392 } 393 394 extern(C) static void callBackInsertedTextDestroy(OnInsertedTextDelegateWrapper wrapper, GClosure* closure) 395 { 396 wrapper.remove(wrapper); 397 } 398 }