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