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.TextBuffer; 26 27 private import core.vararg; 28 private import gdk.Color; 29 private import gdkpixbuf.Pixbuf; 30 private import glib.ConstructionException; 31 private import glib.ErrorG; 32 private import glib.GException; 33 private import glib.Str; 34 private import gobject.ObjectG; 35 private import gobject.Signals; 36 private import gtk.Clipboard; 37 private import gtk.TargetList; 38 private import gtk.TextChildAnchor; 39 private import gtk.TextIter; 40 private import gtk.TextMark; 41 private import gtk.TextTag; 42 private import gtk.TextTagTable; 43 private import gtkc.gobject; 44 private import gtkc.gtk; 45 public import gtkc.gtktypes; 46 private import pango.PgFontDescription; 47 private import pango.PgTabArray; 48 private import std.algorithm; 49 private import std.stdio; 50 51 52 /** 53 * You may wish to begin by reading the 54 * [text widget conceptual overview][TextWidget] 55 * which gives an overview of all the objects and data 56 * types related to the text widget and how they work together. 57 */ 58 public class TextBuffer : ObjectG 59 { 60 /** the main Gtk struct */ 61 protected GtkTextBuffer* gtkTextBuffer; 62 63 /** Get the main Gtk struct */ 64 public GtkTextBuffer* getTextBufferStruct() 65 { 66 return gtkTextBuffer; 67 } 68 69 /** the main Gtk struct as a void* */ 70 protected override void* getStruct() 71 { 72 return cast(void*)gtkTextBuffer; 73 } 74 75 protected override void setStruct(GObject* obj) 76 { 77 gtkTextBuffer = cast(GtkTextBuffer*)obj; 78 super.setStruct(obj); 79 } 80 81 /** 82 * Sets our main struct and passes it to the parent class. 83 */ 84 public this (GtkTextBuffer* gtkTextBuffer, bool ownedRef = false) 85 { 86 this.gtkTextBuffer = gtkTextBuffer; 87 super(cast(GObject*)gtkTextBuffer, ownedRef); 88 } 89 90 /** 91 * Inserts text into buffer at iter, applying the list of tags to 92 * the newly-inserted text. The last tag specified must be NULL to 93 * terminate the list. Equivalent to calling gtk_text_buffer_insert(), 94 * then gtk_text_buffer_apply_tag() on the inserted text; 95 * gtk_text_buffer_insert_with_tags() is just a convenience function. 96 * Params: 97 * iter = an iterator in buffer 98 * text = UTF-8 text 99 * tags = list of tags to apply 100 */ 101 public void insertWithTags(TextIter iter, string text, TextTag[] tags ... ) 102 { 103 int startOffset = iter.getOffset(); 104 105 insert(iter, text); 106 107 if ( tags.length == 0 ) 108 return; 109 110 TextIter start = new TextIter(); 111 getIterAtOffset(start, startOffset); 112 113 foreach( tag; tags ) 114 { 115 applyTag(tag, start, iter); 116 } 117 } 118 119 /** 120 * Same as gtk_text_buffer_insert_with_tags(), but allows you 121 * to pass in tag names instead of tag objects. 122 * Params: 123 * iter = position in buffer 124 * text = UTF-8 text 125 * tags = tag names 126 */ 127 public void insertWithTagsByName(TextIter iter, string text, string[] tags ... ) 128 { 129 int startOffset = iter.getOffset(); 130 131 insert(iter, text); 132 133 if ( tags.length == 0 ) 134 return; 135 136 TextIter start = new TextIter(); 137 getIterAtOffset(start, startOffset); 138 139 foreach( tag; tags ) 140 { 141 applyTagByName(tag, start, iter); 142 } 143 } 144 145 /** 146 * Creates a tag and adds it to the tag table for buffer. Equivalent to 147 * adding a new tag to the buffer's tag table. 148 * 149 * If tagName is null, the tag is anonymous. 150 * 151 * If tagName is non-NULL, a tag called tagName must not already exist 152 * in the tag table for this buffer. 153 * 154 * Params: 155 * tagName = the name for the new tag. 156 * ... = A list of property names and there values. 157 */ 158 TextTag createTag(string tagName, ...) 159 { 160 TextTag tag = new TextTag(gtk_text_buffer_create_tag(gtkTextBuffer, Str.toStringz(tagName), null, null)); 161 162 for (size_t i = 0; i < _arguments.length; i+=2) 163 { 164 //TODO: Add a proper eception type for this. 165 if ( _arguments[i] != typeid(string) ) 166 throw new Exception("TextBuffer.CreateTag: The property name must be a string."); 167 168 string name = va_arg!(string)(_argptr); 169 170 if ( _arguments[i+1] == typeid(bool) || 171 _arguments[i+1] == typeid(int) || 172 _arguments[i+1] == typeid(GtkJustification) || 173 _arguments[i+1] == typeid(GtkTextDirection) || 174 _arguments[i+1] == typeid(GtkWrapMode) || 175 _arguments[i+1] == typeid(PangoStretch) || 176 _arguments[i+1] == typeid(PangoStyle) || 177 _arguments[i+1] == typeid(PangoUnderline) || 178 _arguments[i+1] == typeid(PangoVariant) || 179 _arguments[i+1] == typeid(PangoWeight) ) 180 { 181 182 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), va_arg!(int)(_argptr), null); 183 } 184 else if ( _arguments[i+1] == typeid(Color) ) 185 { 186 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), va_arg!(Color)(_argptr).getColorStruct(), null); 187 } 188 else if ( _arguments[i+1] == typeid(double) ) 189 { 190 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), va_arg!(double)(_argptr), null); 191 } 192 else if ( _arguments[i+1] == typeid(const(double)) ) 193 { 194 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), va_arg!(double)(_argptr), null); 195 } 196 else if ( _arguments[i+1] == typeid(PgFontDescription) ) 197 { 198 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), va_arg!(PgFontDescription)(_argptr).getPgFontDescriptionStruct(), null); 199 } 200 else if ( _arguments[i+1] == typeid(PgTabArray) ) 201 { 202 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), va_arg!(PgTabArray)(_argptr).getPgTabArrayStruct(), null); 203 } 204 else if ( _arguments[i+1] == typeid(string) ) 205 { 206 g_object_set(tag.getObjectGStruct(), Str.toStringz(name), Str.toStringz(va_arg!(string)(_argptr)), null); 207 } 208 else 209 { 210 stderr.writefln("TextBuffer.CreateTag: Unsupported type: \"%s\" for property: \"%s\"", _arguments[i+1], name); 211 212 //TODO: throw segfaults, druntime bug? 213 throw new Exception("TextBuffer.CreateTag: Unsupported type: \""~_arguments[i+1].toString()~"\" for property: \""~name~"\""); 214 } 215 } 216 217 return tag; 218 } 219 220 /** 221 * Obtain the entire text 222 * Returns: The text string 223 */ 224 string getText() 225 { 226 TextIter start = new TextIter(); 227 TextIter end = new TextIter(); 228 getBounds(start,end); 229 return Str.toString(gtk_text_buffer_get_slice(gtkTextBuffer, start.getTextIterStruct(), end.getTextIterStruct(), true)); 230 } 231 232 /** 233 */ 234 235 /** */ 236 public static GType getType() 237 { 238 return gtk_text_buffer_get_type(); 239 } 240 241 /** 242 * Creates a new text buffer. 243 * 244 * Params: 245 * table = a tag table, or %NULL to create a new one 246 * 247 * Returns: a new text buffer 248 * 249 * Throws: ConstructionException GTK+ fails to create the object. 250 */ 251 public this(TextTagTable table) 252 { 253 auto p = gtk_text_buffer_new((table is null) ? null : table.getTextTagTableStruct()); 254 255 if(p is null) 256 { 257 throw new ConstructionException("null returned by new"); 258 } 259 260 this(cast(GtkTextBuffer*) p, true); 261 } 262 263 /** 264 * Adds the mark at position @where. The mark must not be added to 265 * another buffer, and if its name is not %NULL then there must not 266 * be another mark in the buffer with the same name. 267 * 268 * Emits the #GtkTextBuffer::mark-set signal as notification of the mark's 269 * initial placement. 270 * 271 * Params: 272 * mark = the mark to add 273 * where = location to place mark 274 * 275 * Since: 2.12 276 */ 277 public void addMark(TextMark mark, TextIter where) 278 { 279 gtk_text_buffer_add_mark(gtkTextBuffer, (mark is null) ? null : mark.getTextMarkStruct(), (where is null) ? null : where.getTextIterStruct()); 280 } 281 282 /** 283 * Adds @clipboard to the list of clipboards in which the selection 284 * contents of @buffer are available. In most cases, @clipboard will be 285 * the #GtkClipboard of type %GDK_SELECTION_PRIMARY for a view of @buffer. 286 * 287 * Params: 288 * clipboard = a #GtkClipboard 289 */ 290 public void addSelectionClipboard(Clipboard clipboard) 291 { 292 gtk_text_buffer_add_selection_clipboard(gtkTextBuffer, (clipboard is null) ? null : clipboard.getClipboardStruct()); 293 } 294 295 /** 296 * Emits the “apply-tag” signal on @buffer. The default 297 * handler for the signal applies @tag to the given range. 298 * @start and @end do not have to be in order. 299 * 300 * Params: 301 * tag = a #GtkTextTag 302 * start = one bound of range to be tagged 303 * end = other bound of range to be tagged 304 */ 305 public void applyTag(TextTag tag, TextIter start, TextIter end) 306 { 307 gtk_text_buffer_apply_tag(gtkTextBuffer, (tag is null) ? null : tag.getTextTagStruct(), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 308 } 309 310 /** 311 * Calls gtk_text_tag_table_lookup() on the buffer’s tag table to 312 * get a #GtkTextTag, then calls gtk_text_buffer_apply_tag(). 313 * 314 * Params: 315 * name = name of a named #GtkTextTag 316 * start = one bound of range to be tagged 317 * end = other bound of range to be tagged 318 */ 319 public void applyTagByName(string name, TextIter start, TextIter end) 320 { 321 gtk_text_buffer_apply_tag_by_name(gtkTextBuffer, Str.toStringz(name), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 322 } 323 324 /** 325 * Performs the appropriate action as if the user hit the delete 326 * key with the cursor at the position specified by @iter. In the 327 * normal case a single character will be deleted, but when 328 * combining accents are involved, more than one character can 329 * be deleted, and when precomposed character and accent combinations 330 * are involved, less than one character will be deleted. 331 * 332 * Because the buffer is modified, all outstanding iterators become 333 * invalid after calling this function; however, the @iter will be 334 * re-initialized to point to the location where text was deleted. 335 * 336 * Params: 337 * iter = a position in @buffer 338 * interactive = whether the deletion is caused by user interaction 339 * defaultEditable = whether the buffer is editable by default 340 * 341 * Returns: %TRUE if the buffer was modified 342 * 343 * Since: 2.6 344 */ 345 public bool backspace(TextIter iter, bool interactive, bool defaultEditable) 346 { 347 return gtk_text_buffer_backspace(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), interactive, defaultEditable) != 0; 348 } 349 350 /** 351 * Called to indicate that the buffer operations between here and a 352 * call to gtk_text_buffer_end_user_action() are part of a single 353 * user-visible operation. The operations between 354 * gtk_text_buffer_begin_user_action() and 355 * gtk_text_buffer_end_user_action() can then be grouped when creating 356 * an undo stack. #GtkTextBuffer maintains a count of calls to 357 * gtk_text_buffer_begin_user_action() that have not been closed with 358 * a call to gtk_text_buffer_end_user_action(), and emits the 359 * “begin-user-action” and “end-user-action” signals only for the 360 * outermost pair of calls. This allows you to build user actions 361 * from other user actions. 362 * 363 * The “interactive” buffer mutation functions, such as 364 * gtk_text_buffer_insert_interactive(), automatically call begin/end 365 * user action around the buffer operations they perform, so there's 366 * no need to add extra calls if you user action consists solely of a 367 * single call to one of those functions. 368 */ 369 public void beginUserAction() 370 { 371 gtk_text_buffer_begin_user_action(gtkTextBuffer); 372 } 373 374 /** 375 * Copies the currently-selected text to a clipboard. 376 * 377 * Params: 378 * clipboard = the #GtkClipboard object to copy to 379 */ 380 public void copyClipboard(Clipboard clipboard) 381 { 382 gtk_text_buffer_copy_clipboard(gtkTextBuffer, (clipboard is null) ? null : clipboard.getClipboardStruct()); 383 } 384 385 /** 386 * This is a convenience function which simply creates a child anchor 387 * with gtk_text_child_anchor_new() and inserts it into the buffer 388 * with gtk_text_buffer_insert_child_anchor(). The new anchor is 389 * owned by the buffer; no reference count is returned to 390 * the caller of gtk_text_buffer_create_child_anchor(). 391 * 392 * Params: 393 * iter = location in the buffer 394 * 395 * Returns: the created child anchor 396 */ 397 public TextChildAnchor createChildAnchor(TextIter iter) 398 { 399 auto p = gtk_text_buffer_create_child_anchor(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct()); 400 401 if(p is null) 402 { 403 return null; 404 } 405 406 return ObjectG.getDObject!(TextChildAnchor)(cast(GtkTextChildAnchor*) p); 407 } 408 409 /** 410 * Creates a mark at position @where. If @mark_name is %NULL, the mark 411 * is anonymous; otherwise, the mark can be retrieved by name using 412 * gtk_text_buffer_get_mark(). If a mark has left gravity, and text is 413 * inserted at the mark’s current location, the mark will be moved to 414 * the left of the newly-inserted text. If the mark has right gravity 415 * (@left_gravity = %FALSE), the mark will end up on the right of 416 * newly-inserted text. The standard left-to-right cursor is a mark 417 * with right gravity (when you type, the cursor stays on the right 418 * side of the text you’re typing). 419 * 420 * The caller of this function does not own a 421 * reference to the returned #GtkTextMark, so you can ignore the 422 * return value if you like. Marks are owned by the buffer and go 423 * away when the buffer does. 424 * 425 * Emits the #GtkTextBuffer::mark-set signal as notification of the mark's 426 * initial placement. 427 * 428 * Params: 429 * markName = name for mark, or %NULL 430 * where = location to place mark 431 * leftGravity = whether the mark has left gravity 432 * 433 * Returns: the new #GtkTextMark object 434 */ 435 public TextMark createMark(string markName, TextIter where, bool leftGravity) 436 { 437 auto p = gtk_text_buffer_create_mark(gtkTextBuffer, Str.toStringz(markName), (where is null) ? null : where.getTextIterStruct(), leftGravity); 438 439 if(p is null) 440 { 441 return null; 442 } 443 444 return ObjectG.getDObject!(TextMark)(cast(GtkTextMark*) p); 445 } 446 447 /** 448 * Copies the currently-selected text to a clipboard, then deletes 449 * said text if it’s editable. 450 * 451 * Params: 452 * clipboard = the #GtkClipboard object to cut to 453 * defaultEditable = default editability of the buffer 454 */ 455 public void cutClipboard(Clipboard clipboard, bool defaultEditable) 456 { 457 gtk_text_buffer_cut_clipboard(gtkTextBuffer, (clipboard is null) ? null : clipboard.getClipboardStruct(), defaultEditable); 458 } 459 460 /** 461 * Deletes text between @start and @end. The order of @start and @end 462 * is not actually relevant; gtk_text_buffer_delete() will reorder 463 * them. This function actually emits the “delete-range” signal, and 464 * the default handler of that signal deletes the text. Because the 465 * buffer is modified, all outstanding iterators become invalid after 466 * calling this function; however, the @start and @end will be 467 * re-initialized to point to the location where text was deleted. 468 * 469 * Params: 470 * start = a position in @buffer 471 * end = another position in @buffer 472 */ 473 public void delet(TextIter start, TextIter end) 474 { 475 gtk_text_buffer_delete(gtkTextBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 476 } 477 478 /** 479 * Deletes all editable text in the given range. 480 * Calls gtk_text_buffer_delete() for each editable sub-range of 481 * [@start,@end). @start and @end are revalidated to point to 482 * the location of the last deleted range, or left untouched if 483 * no text was deleted. 484 * 485 * Params: 486 * startIter = start of range to delete 487 * endIter = end of range 488 * defaultEditable = whether the buffer is editable by default 489 * 490 * Returns: whether some text was actually deleted 491 */ 492 public bool deleteInteractive(TextIter startIter, TextIter endIter, bool defaultEditable) 493 { 494 return gtk_text_buffer_delete_interactive(gtkTextBuffer, (startIter is null) ? null : startIter.getTextIterStruct(), (endIter is null) ? null : endIter.getTextIterStruct(), defaultEditable) != 0; 495 } 496 497 /** 498 * Deletes @mark, so that it’s no longer located anywhere in the 499 * buffer. Removes the reference the buffer holds to the mark, so if 500 * you haven’t called g_object_ref() on the mark, it will be freed. Even 501 * if the mark isn’t freed, most operations on @mark become 502 * invalid, until it gets added to a buffer again with 503 * gtk_text_buffer_add_mark(). Use gtk_text_mark_get_deleted() to 504 * find out if a mark has been removed from its buffer. 505 * The #GtkTextBuffer::mark-deleted signal will be emitted as notification after 506 * the mark is deleted. 507 * 508 * Params: 509 * mark = a #GtkTextMark in @buffer 510 */ 511 public void deleteMark(TextMark mark) 512 { 513 gtk_text_buffer_delete_mark(gtkTextBuffer, (mark is null) ? null : mark.getTextMarkStruct()); 514 } 515 516 /** 517 * Deletes the mark named @name; the mark must exist. See 518 * gtk_text_buffer_delete_mark() for details. 519 * 520 * Params: 521 * name = name of a mark in @buffer 522 */ 523 public void deleteMarkByName(string name) 524 { 525 gtk_text_buffer_delete_mark_by_name(gtkTextBuffer, Str.toStringz(name)); 526 } 527 528 /** 529 * Deletes the range between the “insert” and “selection_bound” marks, 530 * that is, the currently-selected text. If @interactive is %TRUE, 531 * the editability of the selection will be considered (users can’t delete 532 * uneditable text). 533 * 534 * Params: 535 * interactive = whether the deletion is caused by user interaction 536 * defaultEditable = whether the buffer is editable by default 537 * 538 * Returns: whether there was a non-empty selection to delete 539 */ 540 public bool deleteSelection(bool interactive, bool defaultEditable) 541 { 542 return gtk_text_buffer_delete_selection(gtkTextBuffer, interactive, defaultEditable) != 0; 543 } 544 545 /** 546 * This function deserializes rich text in format @format and inserts 547 * it at @iter. 548 * 549 * @formats to be used must be registered using 550 * gtk_text_buffer_register_deserialize_format() or 551 * gtk_text_buffer_register_deserialize_tagset() beforehand. 552 * 553 * Params: 554 * contentBuffer = the #GtkTextBuffer to deserialize into 555 * format = the rich text format to use for deserializing 556 * iter = insertion point for the deserialized text 557 * data = data to deserialize 558 * length = length of @data 559 * 560 * Returns: %TRUE on success, %FALSE otherwise. 561 * 562 * Since: 2.10 563 * 564 * Throws: GException on failure. 565 */ 566 public bool deserialize(TextBuffer contentBuffer, GdkAtom format, TextIter iter, ubyte[] data) 567 { 568 GError* err = null; 569 570 auto p = gtk_text_buffer_deserialize(gtkTextBuffer, (contentBuffer is null) ? null : contentBuffer.getTextBufferStruct(), format, (iter is null) ? null : iter.getTextIterStruct(), data.ptr, cast(size_t)data.length, &err) != 0; 571 572 if (err !is null) 573 { 574 throw new GException( new ErrorG(err) ); 575 } 576 577 return p; 578 } 579 580 /** 581 * This functions returns the value set with 582 * gtk_text_buffer_deserialize_set_can_create_tags() 583 * 584 * Params: 585 * format = a #GdkAtom representing a registered rich text format 586 * 587 * Returns: whether deserializing this format may create tags 588 * 589 * Since: 2.10 590 */ 591 public bool deserializeGetCanCreateTags(GdkAtom format) 592 { 593 return gtk_text_buffer_deserialize_get_can_create_tags(gtkTextBuffer, format) != 0; 594 } 595 596 /** 597 * Use this function to allow a rich text deserialization function to 598 * create new tags in the receiving buffer. Note that using this 599 * function is almost always a bad idea, because the rich text 600 * functions you register should know how to map the rich text format 601 * they handler to your text buffers set of tags. 602 * 603 * The ability of creating new (arbitrary!) tags in the receiving buffer 604 * is meant for special rich text formats like the internal one that 605 * is registered using gtk_text_buffer_register_deserialize_tagset(), 606 * because that format is essentially a dump of the internal structure 607 * of the source buffer, including its tag names. 608 * 609 * You should allow creation of tags only if you know what you are 610 * doing, e.g. if you defined a tagset name for your application 611 * suite’s text buffers and you know that it’s fine to receive new 612 * tags from these buffers, because you know that your application can 613 * handle the newly created tags. 614 * 615 * Params: 616 * format = a #GdkAtom representing a registered rich text format 617 * canCreateTags = whether deserializing this format may create tags 618 * 619 * Since: 2.10 620 */ 621 public void deserializeSetCanCreateTags(GdkAtom format, bool canCreateTags) 622 { 623 gtk_text_buffer_deserialize_set_can_create_tags(gtkTextBuffer, format, canCreateTags); 624 } 625 626 /** 627 * Should be paired with a call to gtk_text_buffer_begin_user_action(). 628 * See that function for a full explanation. 629 */ 630 public void endUserAction() 631 { 632 gtk_text_buffer_end_user_action(gtkTextBuffer); 633 } 634 635 /** 636 * Retrieves the first and last iterators in the buffer, i.e. the 637 * entire buffer lies within the range [@start,@end). 638 * 639 * Params: 640 * start = iterator to initialize with first position in the buffer 641 * end = iterator to initialize with the end iterator 642 */ 643 public void getBounds(out TextIter start, out TextIter end) 644 { 645 GtkTextIter* outstart = gMalloc!GtkTextIter(); 646 GtkTextIter* outend = gMalloc!GtkTextIter(); 647 648 gtk_text_buffer_get_bounds(gtkTextBuffer, outstart, outend); 649 650 start = ObjectG.getDObject!(TextIter)(outstart, true); 651 end = ObjectG.getDObject!(TextIter)(outend, true); 652 } 653 654 /** 655 * Gets the number of characters in the buffer; note that characters 656 * and bytes are not the same, you can’t e.g. expect the contents of 657 * the buffer in string form to be this many bytes long. The character 658 * count is cached, so this function is very fast. 659 * 660 * Returns: number of characters in the buffer 661 */ 662 public int getCharCount() 663 { 664 return gtk_text_buffer_get_char_count(gtkTextBuffer); 665 } 666 667 /** 668 * This function returns the list of targets this text buffer can 669 * provide for copying and as DND source. The targets in the list are 670 * added with @info values from the #GtkTextBufferTargetInfo enum, 671 * using gtk_target_list_add_rich_text_targets() and 672 * gtk_target_list_add_text_targets(). 673 * 674 * Returns: the #GtkTargetList 675 * 676 * Since: 2.10 677 */ 678 public TargetList getCopyTargetList() 679 { 680 auto p = gtk_text_buffer_get_copy_target_list(gtkTextBuffer); 681 682 if(p is null) 683 { 684 return null; 685 } 686 687 return ObjectG.getDObject!(TargetList)(cast(GtkTargetList*) p); 688 } 689 690 /** 691 * This function returns the rich text deserialize formats registered 692 * with @buffer using gtk_text_buffer_register_deserialize_format() or 693 * gtk_text_buffer_register_deserialize_tagset() 694 * 695 * Returns: an array of 696 * #GdkAtoms representing the registered formats. 697 * 698 * Since: 2.10 699 */ 700 public GdkAtom[] getDeserializeFormats() 701 { 702 int nFormats; 703 704 auto p = gtk_text_buffer_get_deserialize_formats(gtkTextBuffer, &nFormats); 705 706 return p[0 .. nFormats]; 707 } 708 709 /** 710 * Initializes @iter with the “end iterator,” one past the last valid 711 * character in the text buffer. If dereferenced with 712 * gtk_text_iter_get_char(), the end iterator has a character value of 0. 713 * The entire buffer lies in the range from the first position in 714 * the buffer (call gtk_text_buffer_get_start_iter() to get 715 * character position 0) to the end iterator. 716 * 717 * Params: 718 * iter = iterator to initialize 719 */ 720 public void getEndIter(out TextIter iter) 721 { 722 GtkTextIter* outiter = gMalloc!GtkTextIter(); 723 724 gtk_text_buffer_get_end_iter(gtkTextBuffer, outiter); 725 726 iter = ObjectG.getDObject!(TextIter)(outiter, true); 727 } 728 729 /** 730 * Indicates whether the buffer has some text currently selected. 731 * 732 * Returns: %TRUE if the there is text selected 733 * 734 * Since: 2.10 735 */ 736 public bool getHasSelection() 737 { 738 return gtk_text_buffer_get_has_selection(gtkTextBuffer) != 0; 739 } 740 741 /** 742 * Returns the mark that represents the cursor (insertion point). 743 * Equivalent to calling gtk_text_buffer_get_mark() to get the mark 744 * named “insert”, but very slightly more efficient, and involves less 745 * typing. 746 * 747 * Returns: insertion point mark 748 */ 749 public TextMark getInsert() 750 { 751 auto p = gtk_text_buffer_get_insert(gtkTextBuffer); 752 753 if(p is null) 754 { 755 return null; 756 } 757 758 return ObjectG.getDObject!(TextMark)(cast(GtkTextMark*) p); 759 } 760 761 /** 762 * Obtains the location of @anchor within @buffer. 763 * 764 * Params: 765 * iter = an iterator to be initialized 766 * anchor = a child anchor that appears in @buffer 767 */ 768 public void getIterAtChildAnchor(out TextIter iter, TextChildAnchor anchor) 769 { 770 GtkTextIter* outiter = gMalloc!GtkTextIter(); 771 772 gtk_text_buffer_get_iter_at_child_anchor(gtkTextBuffer, outiter, (anchor is null) ? null : anchor.getTextChildAnchorStruct()); 773 774 iter = ObjectG.getDObject!(TextIter)(outiter, true); 775 } 776 777 /** 778 * Initializes @iter to the start of the given line. If @line_number is greater 779 * than the number of lines in the @buffer, the end iterator is returned. 780 * 781 * Params: 782 * iter = iterator to initialize 783 * lineNumber = line number counting from 0 784 */ 785 public void getIterAtLine(out TextIter iter, int lineNumber) 786 { 787 GtkTextIter* outiter = gMalloc!GtkTextIter(); 788 789 gtk_text_buffer_get_iter_at_line(gtkTextBuffer, outiter, lineNumber); 790 791 iter = ObjectG.getDObject!(TextIter)(outiter, true); 792 } 793 794 /** 795 * Obtains an iterator pointing to @byte_index within the given line. 796 * @byte_index must be the start of a UTF-8 character. Note bytes, not 797 * characters; UTF-8 may encode one character as multiple bytes. 798 * 799 * Before the 3.20 version, it was not allowed to pass an invalid location. 800 * 801 * Since the 3.20 version, if @line_number is greater than the number of lines 802 * in the @buffer, the end iterator is returned. And if @byte_index is off the 803 * end of the line, the iterator at the end of the line is returned. 804 * 805 * Params: 806 * iter = iterator to initialize 807 * lineNumber = line number counting from 0 808 * byteIndex = byte index from start of line 809 */ 810 public void getIterAtLineIndex(out TextIter iter, int lineNumber, int byteIndex) 811 { 812 GtkTextIter* outiter = gMalloc!GtkTextIter(); 813 814 gtk_text_buffer_get_iter_at_line_index(gtkTextBuffer, outiter, lineNumber, byteIndex); 815 816 iter = ObjectG.getDObject!(TextIter)(outiter, true); 817 } 818 819 /** 820 * Obtains an iterator pointing to @char_offset within the given line. Note 821 * characters, not bytes; UTF-8 may encode one character as multiple bytes. 822 * 823 * Before the 3.20 version, it was not allowed to pass an invalid location. 824 * 825 * Since the 3.20 version, if @line_number is greater than the number of lines 826 * in the @buffer, the end iterator is returned. And if @char_offset is off the 827 * end of the line, the iterator at the end of the line is returned. 828 * 829 * Params: 830 * iter = iterator to initialize 831 * lineNumber = line number counting from 0 832 * charOffset = char offset from start of line 833 */ 834 public void getIterAtLineOffset(out TextIter iter, int lineNumber, int charOffset) 835 { 836 GtkTextIter* outiter = gMalloc!GtkTextIter(); 837 838 gtk_text_buffer_get_iter_at_line_offset(gtkTextBuffer, outiter, lineNumber, charOffset); 839 840 iter = ObjectG.getDObject!(TextIter)(outiter, true); 841 } 842 843 /** 844 * Initializes @iter with the current position of @mark. 845 * 846 * Params: 847 * iter = iterator to initialize 848 * mark = a #GtkTextMark in @buffer 849 */ 850 public void getIterAtMark(out TextIter iter, TextMark mark) 851 { 852 GtkTextIter* outiter = gMalloc!GtkTextIter(); 853 854 gtk_text_buffer_get_iter_at_mark(gtkTextBuffer, outiter, (mark is null) ? null : mark.getTextMarkStruct()); 855 856 iter = ObjectG.getDObject!(TextIter)(outiter, true); 857 } 858 859 /** 860 * Initializes @iter to a position @char_offset chars from the start 861 * of the entire buffer. If @char_offset is -1 or greater than the number 862 * of characters in the buffer, @iter is initialized to the end iterator, 863 * the iterator one past the last valid character in the buffer. 864 * 865 * Params: 866 * iter = iterator to initialize 867 * charOffset = char offset from start of buffer, counting from 0, or -1 868 */ 869 public void getIterAtOffset(out TextIter iter, int charOffset) 870 { 871 GtkTextIter* outiter = gMalloc!GtkTextIter(); 872 873 gtk_text_buffer_get_iter_at_offset(gtkTextBuffer, outiter, charOffset); 874 875 iter = ObjectG.getDObject!(TextIter)(outiter, true); 876 } 877 878 /** 879 * Obtains the number of lines in the buffer. This value is cached, so 880 * the function is very fast. 881 * 882 * Returns: number of lines in the buffer 883 */ 884 public int getLineCount() 885 { 886 return gtk_text_buffer_get_line_count(gtkTextBuffer); 887 } 888 889 /** 890 * Returns the mark named @name in buffer @buffer, or %NULL if no such 891 * mark exists in the buffer. 892 * 893 * Params: 894 * name = a mark name 895 * 896 * Returns: a #GtkTextMark, or %NULL 897 */ 898 public TextMark getMark(string name) 899 { 900 auto p = gtk_text_buffer_get_mark(gtkTextBuffer, Str.toStringz(name)); 901 902 if(p is null) 903 { 904 return null; 905 } 906 907 return ObjectG.getDObject!(TextMark)(cast(GtkTextMark*) p); 908 } 909 910 /** 911 * Indicates whether the buffer has been modified since the last call 912 * to gtk_text_buffer_set_modified() set the modification flag to 913 * %FALSE. Used for example to enable a “save” function in a text 914 * editor. 915 * 916 * Returns: %TRUE if the buffer has been modified 917 */ 918 public bool getModified() 919 { 920 return gtk_text_buffer_get_modified(gtkTextBuffer) != 0; 921 } 922 923 /** 924 * This function returns the list of targets this text buffer supports 925 * for pasting and as DND destination. The targets in the list are 926 * added with @info values from the #GtkTextBufferTargetInfo enum, 927 * using gtk_target_list_add_rich_text_targets() and 928 * gtk_target_list_add_text_targets(). 929 * 930 * Returns: the #GtkTargetList 931 * 932 * Since: 2.10 933 */ 934 public TargetList getPasteTargetList() 935 { 936 auto p = gtk_text_buffer_get_paste_target_list(gtkTextBuffer); 937 938 if(p is null) 939 { 940 return null; 941 } 942 943 return ObjectG.getDObject!(TargetList)(cast(GtkTargetList*) p); 944 } 945 946 /** 947 * Returns the mark that represents the selection bound. Equivalent 948 * to calling gtk_text_buffer_get_mark() to get the mark named 949 * “selection_bound”, but very slightly more efficient, and involves 950 * less typing. 951 * 952 * The currently-selected text in @buffer is the region between the 953 * “selection_bound” and “insert” marks. If “selection_bound” and 954 * “insert” are in the same place, then there is no current selection. 955 * gtk_text_buffer_get_selection_bounds() is another convenient function 956 * for handling the selection, if you just want to know whether there’s a 957 * selection and what its bounds are. 958 * 959 * Returns: selection bound mark 960 */ 961 public TextMark getSelectionBound() 962 { 963 auto p = gtk_text_buffer_get_selection_bound(gtkTextBuffer); 964 965 if(p is null) 966 { 967 return null; 968 } 969 970 return ObjectG.getDObject!(TextMark)(cast(GtkTextMark*) p); 971 } 972 973 /** 974 * Returns %TRUE if some text is selected; places the bounds 975 * of the selection in @start and @end (if the selection has length 0, 976 * then @start and @end are filled in with the same value). 977 * @start and @end will be in ascending order. If @start and @end are 978 * NULL, then they are not filled in, but the return value still indicates 979 * whether text is selected. 980 * 981 * Params: 982 * start = iterator to initialize with selection start 983 * end = iterator to initialize with selection end 984 * 985 * Returns: whether the selection has nonzero length 986 */ 987 public bool getSelectionBounds(out TextIter start, out TextIter end) 988 { 989 GtkTextIter* outstart = gMalloc!GtkTextIter(); 990 GtkTextIter* outend = gMalloc!GtkTextIter(); 991 992 auto p = gtk_text_buffer_get_selection_bounds(gtkTextBuffer, outstart, outend) != 0; 993 994 start = ObjectG.getDObject!(TextIter)(outstart, true); 995 end = ObjectG.getDObject!(TextIter)(outend, true); 996 997 return p; 998 } 999 1000 /** 1001 * This function returns the rich text serialize formats registered 1002 * with @buffer using gtk_text_buffer_register_serialize_format() or 1003 * gtk_text_buffer_register_serialize_tagset() 1004 * 1005 * Returns: an array of 1006 * #GdkAtoms representing the registered formats. 1007 * 1008 * Since: 2.10 1009 */ 1010 public GdkAtom[] getSerializeFormats() 1011 { 1012 int nFormats; 1013 1014 auto p = gtk_text_buffer_get_serialize_formats(gtkTextBuffer, &nFormats); 1015 1016 return p[0 .. nFormats]; 1017 } 1018 1019 /** 1020 * Returns the text in the range [@start,@end). Excludes undisplayed 1021 * text (text marked with tags that set the invisibility attribute) if 1022 * @include_hidden_chars is %FALSE. The returned string includes a 1023 * 0xFFFC character whenever the buffer contains 1024 * embedded images, so byte and character indexes into 1025 * the returned string do correspond to byte 1026 * and character indexes into the buffer. Contrast with 1027 * gtk_text_buffer_get_text(). Note that 0xFFFC can occur in normal 1028 * text as well, so it is not a reliable indicator that a pixbuf or 1029 * widget is in the buffer. 1030 * 1031 * Params: 1032 * start = start of a range 1033 * end = end of a range 1034 * includeHiddenChars = whether to include invisible text 1035 * 1036 * Returns: an allocated UTF-8 string 1037 */ 1038 public string getSlice(TextIter start, TextIter end, bool includeHiddenChars) 1039 { 1040 auto retStr = gtk_text_buffer_get_slice(gtkTextBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct(), includeHiddenChars); 1041 1042 scope(exit) Str.freeString(retStr); 1043 return Str.toString(retStr); 1044 } 1045 1046 /** 1047 * Initialized @iter with the first position in the text buffer. This 1048 * is the same as using gtk_text_buffer_get_iter_at_offset() to get 1049 * the iter at character offset 0. 1050 * 1051 * Params: 1052 * iter = iterator to initialize 1053 */ 1054 public void getStartIter(out TextIter iter) 1055 { 1056 GtkTextIter* outiter = gMalloc!GtkTextIter(); 1057 1058 gtk_text_buffer_get_start_iter(gtkTextBuffer, outiter); 1059 1060 iter = ObjectG.getDObject!(TextIter)(outiter, true); 1061 } 1062 1063 /** 1064 * Get the #GtkTextTagTable associated with this buffer. 1065 * 1066 * Returns: the buffer’s tag table 1067 */ 1068 public TextTagTable getTagTable() 1069 { 1070 auto p = gtk_text_buffer_get_tag_table(gtkTextBuffer); 1071 1072 if(p is null) 1073 { 1074 return null; 1075 } 1076 1077 return ObjectG.getDObject!(TextTagTable)(cast(GtkTextTagTable*) p); 1078 } 1079 1080 /** 1081 * Returns the text in the range [@start,@end). Excludes undisplayed 1082 * text (text marked with tags that set the invisibility attribute) if 1083 * @include_hidden_chars is %FALSE. Does not include characters 1084 * representing embedded images, so byte and character indexes into 1085 * the returned string do not correspond to byte 1086 * and character indexes into the buffer. Contrast with 1087 * gtk_text_buffer_get_slice(). 1088 * 1089 * Params: 1090 * start = start of a range 1091 * end = end of a range 1092 * includeHiddenChars = whether to include invisible text 1093 * 1094 * Returns: an allocated UTF-8 string 1095 */ 1096 public string getText(TextIter start, TextIter end, bool includeHiddenChars) 1097 { 1098 auto retStr = gtk_text_buffer_get_text(gtkTextBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct(), includeHiddenChars); 1099 1100 scope(exit) Str.freeString(retStr); 1101 return Str.toString(retStr); 1102 } 1103 1104 /** 1105 * Inserts @len bytes of @text at position @iter. If @len is -1, 1106 * @text must be nul-terminated and will be inserted in its 1107 * entirety. Emits the “insert-text” signal; insertion actually occurs 1108 * in the default handler for the signal. @iter is invalidated when 1109 * insertion occurs (because the buffer contents change), but the 1110 * default signal handler revalidates it to point to the end of the 1111 * inserted text. 1112 * 1113 * Params: 1114 * iter = a position in the buffer 1115 * text = text in UTF-8 format 1116 * len = length of text in bytes, or -1 1117 */ 1118 public void insert(TextIter iter, string text) 1119 { 1120 gtk_text_buffer_insert(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(text), cast(int)text.length); 1121 } 1122 1123 /** 1124 * Simply calls gtk_text_buffer_insert(), using the current 1125 * cursor position as the insertion point. 1126 * 1127 * Params: 1128 * text = text in UTF-8 format 1129 * len = length of text, in bytes 1130 */ 1131 public void insertAtCursor(string text) 1132 { 1133 gtk_text_buffer_insert_at_cursor(gtkTextBuffer, Str.toStringz(text), cast(int)text.length); 1134 } 1135 1136 /** 1137 * Inserts a child widget anchor into the text buffer at @iter. The 1138 * anchor will be counted as one character in character counts, and 1139 * when obtaining the buffer contents as a string, will be represented 1140 * by the Unicode “object replacement character” 0xFFFC. Note that the 1141 * “slice” variants for obtaining portions of the buffer as a string 1142 * include this character for child anchors, but the “text” variants do 1143 * not. E.g. see gtk_text_buffer_get_slice() and 1144 * gtk_text_buffer_get_text(). Consider 1145 * gtk_text_buffer_create_child_anchor() as a more convenient 1146 * alternative to this function. The buffer will add a reference to 1147 * the anchor, so you can unref it after insertion. 1148 * 1149 * Params: 1150 * iter = location to insert the anchor 1151 * anchor = a #GtkTextChildAnchor 1152 */ 1153 public void insertChildAnchor(TextIter iter, TextChildAnchor anchor) 1154 { 1155 gtk_text_buffer_insert_child_anchor(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), (anchor is null) ? null : anchor.getTextChildAnchorStruct()); 1156 } 1157 1158 /** 1159 * Like gtk_text_buffer_insert(), but the insertion will not occur if 1160 * @iter is at a non-editable location in the buffer. Usually you 1161 * want to prevent insertions at ineditable locations if the insertion 1162 * results from a user action (is interactive). 1163 * 1164 * @default_editable indicates the editability of text that doesn't 1165 * have a tag affecting editability applied to it. Typically the 1166 * result of gtk_text_view_get_editable() is appropriate here. 1167 * 1168 * Params: 1169 * iter = a position in @buffer 1170 * text = some UTF-8 text 1171 * len = length of text in bytes, or -1 1172 * defaultEditable = default editability of buffer 1173 * 1174 * Returns: whether text was actually inserted 1175 */ 1176 public bool insertInteractive(TextIter iter, string text, bool defaultEditable) 1177 { 1178 return gtk_text_buffer_insert_interactive(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(text), cast(int)text.length, defaultEditable) != 0; 1179 } 1180 1181 /** 1182 * Calls gtk_text_buffer_insert_interactive() at the cursor 1183 * position. 1184 * 1185 * @default_editable indicates the editability of text that doesn't 1186 * have a tag affecting editability applied to it. Typically the 1187 * result of gtk_text_view_get_editable() is appropriate here. 1188 * 1189 * Params: 1190 * text = text in UTF-8 format 1191 * len = length of text in bytes, or -1 1192 * defaultEditable = default editability of buffer 1193 * 1194 * Returns: whether text was actually inserted 1195 */ 1196 public bool insertInteractiveAtCursor(string text, bool defaultEditable) 1197 { 1198 return gtk_text_buffer_insert_interactive_at_cursor(gtkTextBuffer, Str.toStringz(text), cast(int)text.length, defaultEditable) != 0; 1199 } 1200 1201 /** 1202 * Inserts the text in @markup at position @iter. @markup will be inserted 1203 * in its entirety and must be nul-terminated and valid UTF-8. Emits the 1204 * #GtkTextBuffer::insert-text signal, possibly multiple times; insertion 1205 * actually occurs in the default handler for the signal. @iter will point 1206 * to the end of the inserted text on return. 1207 * 1208 * Params: 1209 * iter = location to insert the markup 1210 * markup = a nul-terminated UTF-8 string containing [Pango markup][PangoMarkupFormat] 1211 * len = length of @markup in bytes, or -1 1212 * 1213 * Since: 3.16 1214 */ 1215 public void insertMarkup(TextIter iter, string markup, int len) 1216 { 1217 gtk_text_buffer_insert_markup(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(markup), len); 1218 } 1219 1220 /** 1221 * Inserts an image into the text buffer at @iter. The image will be 1222 * counted as one character in character counts, and when obtaining 1223 * the buffer contents as a string, will be represented by the Unicode 1224 * “object replacement character” 0xFFFC. Note that the “slice” 1225 * variants for obtaining portions of the buffer as a string include 1226 * this character for pixbufs, but the “text” variants do 1227 * not. e.g. see gtk_text_buffer_get_slice() and 1228 * gtk_text_buffer_get_text(). 1229 * 1230 * Params: 1231 * iter = location to insert the pixbuf 1232 * pixbuf = a #GdkPixbuf 1233 */ 1234 public void insertPixbuf(TextIter iter, Pixbuf pixbuf) 1235 { 1236 gtk_text_buffer_insert_pixbuf(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), (pixbuf is null) ? null : pixbuf.getPixbufStruct()); 1237 } 1238 1239 /** 1240 * Copies text, tags, and pixbufs between @start and @end (the order 1241 * of @start and @end doesn’t matter) and inserts the copy at @iter. 1242 * Used instead of simply getting/inserting text because it preserves 1243 * images and tags. If @start and @end are in a different buffer from 1244 * @buffer, the two buffers must share the same tag table. 1245 * 1246 * Implemented via emissions of the insert_text and apply_tag signals, 1247 * so expect those. 1248 * 1249 * Params: 1250 * iter = a position in @buffer 1251 * start = a position in a #GtkTextBuffer 1252 * end = another position in the same buffer as @start 1253 */ 1254 public void insertRange(TextIter iter, TextIter start, TextIter end) 1255 { 1256 gtk_text_buffer_insert_range(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 1257 } 1258 1259 /** 1260 * Same as gtk_text_buffer_insert_range(), but does nothing if the 1261 * insertion point isn’t editable. The @default_editable parameter 1262 * indicates whether the text is editable at @iter if no tags 1263 * enclosing @iter affect editability. Typically the result of 1264 * gtk_text_view_get_editable() is appropriate here. 1265 * 1266 * Params: 1267 * iter = a position in @buffer 1268 * start = a position in a #GtkTextBuffer 1269 * end = another position in the same buffer as @start 1270 * defaultEditable = default editability of the buffer 1271 * 1272 * Returns: whether an insertion was possible at @iter 1273 */ 1274 public bool insertRangeInteractive(TextIter iter, TextIter start, TextIter end, bool defaultEditable) 1275 { 1276 return gtk_text_buffer_insert_range_interactive(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct(), defaultEditable) != 0; 1277 } 1278 1279 /** 1280 * Moves @mark to the new location @where. Emits the #GtkTextBuffer::mark-set 1281 * signal as notification of the move. 1282 * 1283 * Params: 1284 * mark = a #GtkTextMark 1285 * where = new location for @mark in @buffer 1286 */ 1287 public void moveMark(TextMark mark, TextIter where) 1288 { 1289 gtk_text_buffer_move_mark(gtkTextBuffer, (mark is null) ? null : mark.getTextMarkStruct(), (where is null) ? null : where.getTextIterStruct()); 1290 } 1291 1292 /** 1293 * Moves the mark named @name (which must exist) to location @where. 1294 * See gtk_text_buffer_move_mark() for details. 1295 * 1296 * Params: 1297 * name = name of a mark 1298 * where = new location for mark 1299 */ 1300 public void moveMarkByName(string name, TextIter where) 1301 { 1302 gtk_text_buffer_move_mark_by_name(gtkTextBuffer, Str.toStringz(name), (where is null) ? null : where.getTextIterStruct()); 1303 } 1304 1305 /** 1306 * Pastes the contents of a clipboard. If @override_location is %NULL, the 1307 * pasted text will be inserted at the cursor position, or the buffer selection 1308 * will be replaced if the selection is non-empty. 1309 * 1310 * Note: pasting is asynchronous, that is, we’ll ask for the paste data and 1311 * return, and at some point later after the main loop runs, the paste data will 1312 * be inserted. 1313 * 1314 * Params: 1315 * clipboard = the #GtkClipboard to paste from 1316 * overrideLocation = location to insert pasted text, or %NULL 1317 * defaultEditable = whether the buffer is editable by default 1318 */ 1319 public void pasteClipboard(Clipboard clipboard, TextIter overrideLocation, bool defaultEditable) 1320 { 1321 gtk_text_buffer_paste_clipboard(gtkTextBuffer, (clipboard is null) ? null : clipboard.getClipboardStruct(), (overrideLocation is null) ? null : overrideLocation.getTextIterStruct(), defaultEditable); 1322 } 1323 1324 /** 1325 * This function moves the “insert” and “selection_bound” marks 1326 * simultaneously. If you move them to the same place in two steps 1327 * with gtk_text_buffer_move_mark(), you will temporarily select a 1328 * region in between their old and new locations, which can be pretty 1329 * inefficient since the temporarily-selected region will force stuff 1330 * to be recalculated. This function moves them as a unit, which can 1331 * be optimized. 1332 * 1333 * Params: 1334 * where = where to put the cursor 1335 */ 1336 public void placeCursor(TextIter where) 1337 { 1338 gtk_text_buffer_place_cursor(gtkTextBuffer, (where is null) ? null : where.getTextIterStruct()); 1339 } 1340 1341 /** 1342 * This function registers a rich text deserialization @function along with 1343 * its @mime_type with the passed @buffer. 1344 * 1345 * Params: 1346 * mimeType = the format’s mime-type 1347 * funct = the deserialize function to register 1348 * userData = @function’s user_data 1349 * userDataDestroy = a function to call when @user_data is no longer needed 1350 * 1351 * Returns: the #GdkAtom that corresponds to the 1352 * newly registered format’s mime-type. 1353 * 1354 * Since: 2.10 1355 */ 1356 public GdkAtom registerDeserializeFormat(string mimeType, GtkTextBufferDeserializeFunc funct, void* userData, GDestroyNotify userDataDestroy) 1357 { 1358 return gtk_text_buffer_register_deserialize_format(gtkTextBuffer, Str.toStringz(mimeType), funct, userData, userDataDestroy); 1359 } 1360 1361 /** 1362 * This function registers GTK+’s internal rich text serialization 1363 * format with the passed @buffer. See 1364 * gtk_text_buffer_register_serialize_tagset() for details. 1365 * 1366 * Params: 1367 * tagsetName = an optional tagset name, on %NULL 1368 * 1369 * Returns: the #GdkAtom that corresponds to the 1370 * newly registered format’s mime-type. 1371 * 1372 * Since: 2.10 1373 */ 1374 public GdkAtom registerDeserializeTagset(string tagsetName) 1375 { 1376 return gtk_text_buffer_register_deserialize_tagset(gtkTextBuffer, Str.toStringz(tagsetName)); 1377 } 1378 1379 /** 1380 * This function registers a rich text serialization @function along with 1381 * its @mime_type with the passed @buffer. 1382 * 1383 * Params: 1384 * mimeType = the format’s mime-type 1385 * funct = the serialize function to register 1386 * userData = @function’s user_data 1387 * userDataDestroy = a function to call when @user_data is no longer needed 1388 * 1389 * Returns: the #GdkAtom that corresponds to the 1390 * newly registered format’s mime-type. 1391 * 1392 * Since: 2.10 1393 */ 1394 public GdkAtom registerSerializeFormat(string mimeType, GtkTextBufferSerializeFunc funct, void* userData, GDestroyNotify userDataDestroy) 1395 { 1396 return gtk_text_buffer_register_serialize_format(gtkTextBuffer, Str.toStringz(mimeType), funct, userData, userDataDestroy); 1397 } 1398 1399 /** 1400 * This function registers GTK+’s internal rich text serialization 1401 * format with the passed @buffer. The internal format does not comply 1402 * to any standard rich text format and only works between #GtkTextBuffer 1403 * instances. It is capable of serializing all of a text buffer’s tags 1404 * and embedded pixbufs. 1405 * 1406 * This function is just a wrapper around 1407 * gtk_text_buffer_register_serialize_format(). The mime type used 1408 * for registering is “application/x-gtk-text-buffer-rich-text”, or 1409 * “application/x-gtk-text-buffer-rich-text;format=@tagset_name” if a 1410 * @tagset_name was passed. 1411 * 1412 * The @tagset_name can be used to restrict the transfer of rich text 1413 * to buffers with compatible sets of tags, in order to avoid unknown 1414 * tags from being pasted. It is probably the common case to pass an 1415 * identifier != %NULL here, since the %NULL tagset requires the 1416 * receiving buffer to deal with with pasting of arbitrary tags. 1417 * 1418 * Params: 1419 * tagsetName = an optional tagset name, on %NULL 1420 * 1421 * Returns: the #GdkAtom that corresponds to the 1422 * newly registered format’s mime-type. 1423 * 1424 * Since: 2.10 1425 */ 1426 public GdkAtom registerSerializeTagset(string tagsetName) 1427 { 1428 return gtk_text_buffer_register_serialize_tagset(gtkTextBuffer, Str.toStringz(tagsetName)); 1429 } 1430 1431 /** 1432 * Removes all tags in the range between @start and @end. Be careful 1433 * with this function; it could remove tags added in code unrelated to 1434 * the code you’re currently writing. That is, using this function is 1435 * probably a bad idea if you have two or more unrelated code sections 1436 * that add tags. 1437 * 1438 * Params: 1439 * start = one bound of range to be untagged 1440 * end = other bound of range to be untagged 1441 */ 1442 public void removeAllTags(TextIter start, TextIter end) 1443 { 1444 gtk_text_buffer_remove_all_tags(gtkTextBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 1445 } 1446 1447 /** 1448 * Removes a #GtkClipboard added with 1449 * gtk_text_buffer_add_selection_clipboard(). 1450 * 1451 * Params: 1452 * clipboard = a #GtkClipboard added to @buffer by 1453 * gtk_text_buffer_add_selection_clipboard() 1454 */ 1455 public void removeSelectionClipboard(Clipboard clipboard) 1456 { 1457 gtk_text_buffer_remove_selection_clipboard(gtkTextBuffer, (clipboard is null) ? null : clipboard.getClipboardStruct()); 1458 } 1459 1460 /** 1461 * Emits the “remove-tag” signal. The default handler for the signal 1462 * removes all occurrences of @tag from the given range. @start and 1463 * @end don’t have to be in order. 1464 * 1465 * Params: 1466 * tag = a #GtkTextTag 1467 * start = one bound of range to be untagged 1468 * end = other bound of range to be untagged 1469 */ 1470 public void removeTag(TextTag tag, TextIter start, TextIter end) 1471 { 1472 gtk_text_buffer_remove_tag(gtkTextBuffer, (tag is null) ? null : tag.getTextTagStruct(), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 1473 } 1474 1475 /** 1476 * Calls gtk_text_tag_table_lookup() on the buffer’s tag table to 1477 * get a #GtkTextTag, then calls gtk_text_buffer_remove_tag(). 1478 * 1479 * Params: 1480 * name = name of a #GtkTextTag 1481 * start = one bound of range to be untagged 1482 * end = other bound of range to be untagged 1483 */ 1484 public void removeTagByName(string name, TextIter start, TextIter end) 1485 { 1486 gtk_text_buffer_remove_tag_by_name(gtkTextBuffer, Str.toStringz(name), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 1487 } 1488 1489 /** 1490 * This function moves the “insert” and “selection_bound” marks 1491 * simultaneously. If you move them in two steps 1492 * with gtk_text_buffer_move_mark(), you will temporarily select a 1493 * region in between their old and new locations, which can be pretty 1494 * inefficient since the temporarily-selected region will force stuff 1495 * to be recalculated. This function moves them as a unit, which can 1496 * be optimized. 1497 * 1498 * Params: 1499 * ins = where to put the “insert” mark 1500 * bound = where to put the “selection_bound” mark 1501 * 1502 * Since: 2.4 1503 */ 1504 public void selectRange(TextIter ins, TextIter bound) 1505 { 1506 gtk_text_buffer_select_range(gtkTextBuffer, (ins is null) ? null : ins.getTextIterStruct(), (bound is null) ? null : bound.getTextIterStruct()); 1507 } 1508 1509 /** 1510 * This function serializes the portion of text between @start 1511 * and @end in the rich text format represented by @format. 1512 * 1513 * @formats to be used must be registered using 1514 * gtk_text_buffer_register_serialize_format() or 1515 * gtk_text_buffer_register_serialize_tagset() beforehand. 1516 * 1517 * Params: 1518 * contentBuffer = the #GtkTextBuffer to serialize 1519 * format = the rich text format to use for serializing 1520 * start = start of block of text to serialize 1521 * end = end of block of test to serialize 1522 * 1523 * Returns: the serialized 1524 * data, encoded as @format 1525 * 1526 * Since: 2.10 1527 */ 1528 public ubyte[] serialize(TextBuffer contentBuffer, GdkAtom format, TextIter start, TextIter end) 1529 { 1530 size_t length; 1531 1532 auto p = gtk_text_buffer_serialize(gtkTextBuffer, (contentBuffer is null) ? null : contentBuffer.getTextBufferStruct(), format, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct(), &length); 1533 1534 return p[0 .. length]; 1535 } 1536 1537 /** 1538 * Used to keep track of whether the buffer has been modified since the 1539 * last time it was saved. Whenever the buffer is saved to disk, call 1540 * gtk_text_buffer_set_modified (@buffer, FALSE). When the buffer is modified, 1541 * it will automatically toggled on the modified bit again. When the modified 1542 * bit flips, the buffer emits the #GtkTextBuffer::modified-changed signal. 1543 * 1544 * Params: 1545 * setting = modification flag setting 1546 */ 1547 public void setModified(bool setting) 1548 { 1549 gtk_text_buffer_set_modified(gtkTextBuffer, setting); 1550 } 1551 1552 /** 1553 * Deletes current contents of @buffer, and inserts @text instead. If 1554 * @len is -1, @text must be nul-terminated. @text must be valid UTF-8. 1555 * 1556 * Params: 1557 * text = UTF-8 text to insert 1558 * len = length of @text in bytes 1559 */ 1560 public void setText(string text) 1561 { 1562 gtk_text_buffer_set_text(gtkTextBuffer, Str.toStringz(text), cast(int)text.length); 1563 } 1564 1565 /** 1566 * This function unregisters a rich text format that was previously 1567 * registered using gtk_text_buffer_register_deserialize_format() or 1568 * gtk_text_buffer_register_deserialize_tagset(). 1569 * 1570 * Params: 1571 * format = a #GdkAtom representing a registered rich text format. 1572 * 1573 * Since: 2.10 1574 */ 1575 public void unregisterDeserializeFormat(GdkAtom format) 1576 { 1577 gtk_text_buffer_unregister_deserialize_format(gtkTextBuffer, format); 1578 } 1579 1580 /** 1581 * This function unregisters a rich text format that was previously 1582 * registered using gtk_text_buffer_register_serialize_format() or 1583 * gtk_text_buffer_register_serialize_tagset() 1584 * 1585 * Params: 1586 * format = a #GdkAtom representing a registered rich text format. 1587 * 1588 * Since: 2.10 1589 */ 1590 public void unregisterSerializeFormat(GdkAtom format) 1591 { 1592 gtk_text_buffer_unregister_serialize_format(gtkTextBuffer, format); 1593 } 1594 1595 protected class OnApplyTagDelegateWrapper 1596 { 1597 static OnApplyTagDelegateWrapper[] listeners; 1598 void delegate(TextTag, TextIter, TextIter, TextBuffer) dlg; 1599 gulong handlerId; 1600 1601 this(void delegate(TextTag, TextIter, TextIter, TextBuffer) dlg) 1602 { 1603 this.dlg = dlg; 1604 this.listeners ~= this; 1605 } 1606 1607 void remove(OnApplyTagDelegateWrapper source) 1608 { 1609 foreach(index, wrapper; listeners) 1610 { 1611 if (wrapper.handlerId == source.handlerId) 1612 { 1613 listeners[index] = null; 1614 listeners = std.algorithm.remove(listeners, index); 1615 break; 1616 } 1617 } 1618 } 1619 } 1620 1621 /** 1622 * The ::apply-tag signal is emitted to apply a tag to a 1623 * range of text in a #GtkTextBuffer. 1624 * Applying actually occurs in the default handler. 1625 * 1626 * Note that if your handler runs before the default handler it must not 1627 * invalidate the @start and @end iters (or has to revalidate them). 1628 * 1629 * See also: 1630 * gtk_text_buffer_apply_tag(), 1631 * gtk_text_buffer_insert_with_tags(), 1632 * gtk_text_buffer_insert_range(). 1633 * 1634 * Params: 1635 * tag = the applied tag 1636 * start = the start of the range the tag is applied to 1637 * end = the end of the range the tag is applied to 1638 */ 1639 gulong addOnApplyTag(void delegate(TextTag, TextIter, TextIter, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1640 { 1641 auto wrapper = new OnApplyTagDelegateWrapper(dlg); 1642 wrapper.handlerId = Signals.connectData( 1643 this, 1644 "apply-tag", 1645 cast(GCallback)&callBackApplyTag, 1646 cast(void*)wrapper, 1647 cast(GClosureNotify)&callBackApplyTagDestroy, 1648 connectFlags); 1649 return wrapper.handlerId; 1650 } 1651 1652 extern(C) static void callBackApplyTag(GtkTextBuffer* textbufferStruct, GtkTextTag* tag, GtkTextIter* start, GtkTextIter* end, OnApplyTagDelegateWrapper wrapper) 1653 { 1654 wrapper.dlg(ObjectG.getDObject!(TextTag)(tag), ObjectG.getDObject!(TextIter)(start), ObjectG.getDObject!(TextIter)(end), wrapper.outer); 1655 } 1656 1657 extern(C) static void callBackApplyTagDestroy(OnApplyTagDelegateWrapper wrapper, GClosure* closure) 1658 { 1659 wrapper.remove(wrapper); 1660 } 1661 1662 protected class OnBeginUserActionDelegateWrapper 1663 { 1664 static OnBeginUserActionDelegateWrapper[] listeners; 1665 void delegate(TextBuffer) dlg; 1666 gulong handlerId; 1667 1668 this(void delegate(TextBuffer) dlg) 1669 { 1670 this.dlg = dlg; 1671 this.listeners ~= this; 1672 } 1673 1674 void remove(OnBeginUserActionDelegateWrapper source) 1675 { 1676 foreach(index, wrapper; listeners) 1677 { 1678 if (wrapper.handlerId == source.handlerId) 1679 { 1680 listeners[index] = null; 1681 listeners = std.algorithm.remove(listeners, index); 1682 break; 1683 } 1684 } 1685 } 1686 } 1687 1688 /** 1689 * The ::begin-user-action signal is emitted at the beginning of a single 1690 * user-visible operation on a #GtkTextBuffer. 1691 * 1692 * See also: 1693 * gtk_text_buffer_begin_user_action(), 1694 * gtk_text_buffer_insert_interactive(), 1695 * gtk_text_buffer_insert_range_interactive(), 1696 * gtk_text_buffer_delete_interactive(), 1697 * gtk_text_buffer_backspace(), 1698 * gtk_text_buffer_delete_selection(). 1699 */ 1700 gulong addOnBeginUserAction(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1701 { 1702 auto wrapper = new OnBeginUserActionDelegateWrapper(dlg); 1703 wrapper.handlerId = Signals.connectData( 1704 this, 1705 "begin-user-action", 1706 cast(GCallback)&callBackBeginUserAction, 1707 cast(void*)wrapper, 1708 cast(GClosureNotify)&callBackBeginUserActionDestroy, 1709 connectFlags); 1710 return wrapper.handlerId; 1711 } 1712 1713 extern(C) static void callBackBeginUserAction(GtkTextBuffer* textbufferStruct, OnBeginUserActionDelegateWrapper wrapper) 1714 { 1715 wrapper.dlg(wrapper.outer); 1716 } 1717 1718 extern(C) static void callBackBeginUserActionDestroy(OnBeginUserActionDelegateWrapper wrapper, GClosure* closure) 1719 { 1720 wrapper.remove(wrapper); 1721 } 1722 1723 protected class OnChangedDelegateWrapper 1724 { 1725 static OnChangedDelegateWrapper[] listeners; 1726 void delegate(TextBuffer) dlg; 1727 gulong handlerId; 1728 1729 this(void delegate(TextBuffer) dlg) 1730 { 1731 this.dlg = dlg; 1732 this.listeners ~= this; 1733 } 1734 1735 void remove(OnChangedDelegateWrapper source) 1736 { 1737 foreach(index, wrapper; listeners) 1738 { 1739 if (wrapper.handlerId == source.handlerId) 1740 { 1741 listeners[index] = null; 1742 listeners = std.algorithm.remove(listeners, index); 1743 break; 1744 } 1745 } 1746 } 1747 } 1748 1749 /** 1750 * The ::changed signal is emitted when the content of a #GtkTextBuffer 1751 * has changed. 1752 */ 1753 gulong addOnChanged(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1754 { 1755 auto wrapper = new OnChangedDelegateWrapper(dlg); 1756 wrapper.handlerId = Signals.connectData( 1757 this, 1758 "changed", 1759 cast(GCallback)&callBackChanged, 1760 cast(void*)wrapper, 1761 cast(GClosureNotify)&callBackChangedDestroy, 1762 connectFlags); 1763 return wrapper.handlerId; 1764 } 1765 1766 extern(C) static void callBackChanged(GtkTextBuffer* textbufferStruct, OnChangedDelegateWrapper wrapper) 1767 { 1768 wrapper.dlg(wrapper.outer); 1769 } 1770 1771 extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure) 1772 { 1773 wrapper.remove(wrapper); 1774 } 1775 1776 protected class OnDeleteRangeDelegateWrapper 1777 { 1778 static OnDeleteRangeDelegateWrapper[] listeners; 1779 void delegate(TextIter, TextIter, TextBuffer) dlg; 1780 gulong handlerId; 1781 1782 this(void delegate(TextIter, TextIter, TextBuffer) dlg) 1783 { 1784 this.dlg = dlg; 1785 this.listeners ~= this; 1786 } 1787 1788 void remove(OnDeleteRangeDelegateWrapper source) 1789 { 1790 foreach(index, wrapper; listeners) 1791 { 1792 if (wrapper.handlerId == source.handlerId) 1793 { 1794 listeners[index] = null; 1795 listeners = std.algorithm.remove(listeners, index); 1796 break; 1797 } 1798 } 1799 } 1800 } 1801 1802 /** 1803 * The ::delete-range signal is emitted to delete a range 1804 * from a #GtkTextBuffer. 1805 * 1806 * Note that if your handler runs before the default handler it must not 1807 * invalidate the @start and @end iters (or has to revalidate them). 1808 * The default signal handler revalidates the @start and @end iters to 1809 * both point to the location where text was deleted. Handlers 1810 * which run after the default handler (see g_signal_connect_after()) 1811 * do not have access to the deleted text. 1812 * 1813 * See also: gtk_text_buffer_delete(). 1814 * 1815 * Params: 1816 * start = the start of the range to be deleted 1817 * end = the end of the range to be deleted 1818 */ 1819 gulong addOnDeleteRange(void delegate(TextIter, TextIter, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1820 { 1821 auto wrapper = new OnDeleteRangeDelegateWrapper(dlg); 1822 wrapper.handlerId = Signals.connectData( 1823 this, 1824 "delete-range", 1825 cast(GCallback)&callBackDeleteRange, 1826 cast(void*)wrapper, 1827 cast(GClosureNotify)&callBackDeleteRangeDestroy, 1828 connectFlags); 1829 return wrapper.handlerId; 1830 } 1831 1832 extern(C) static void callBackDeleteRange(GtkTextBuffer* textbufferStruct, GtkTextIter* start, GtkTextIter* end, OnDeleteRangeDelegateWrapper wrapper) 1833 { 1834 wrapper.dlg(ObjectG.getDObject!(TextIter)(start), ObjectG.getDObject!(TextIter)(end), wrapper.outer); 1835 } 1836 1837 extern(C) static void callBackDeleteRangeDestroy(OnDeleteRangeDelegateWrapper wrapper, GClosure* closure) 1838 { 1839 wrapper.remove(wrapper); 1840 } 1841 1842 protected class OnEndUserActionDelegateWrapper 1843 { 1844 static OnEndUserActionDelegateWrapper[] listeners; 1845 void delegate(TextBuffer) dlg; 1846 gulong handlerId; 1847 1848 this(void delegate(TextBuffer) dlg) 1849 { 1850 this.dlg = dlg; 1851 this.listeners ~= this; 1852 } 1853 1854 void remove(OnEndUserActionDelegateWrapper source) 1855 { 1856 foreach(index, wrapper; listeners) 1857 { 1858 if (wrapper.handlerId == source.handlerId) 1859 { 1860 listeners[index] = null; 1861 listeners = std.algorithm.remove(listeners, index); 1862 break; 1863 } 1864 } 1865 } 1866 } 1867 1868 /** 1869 * The ::end-user-action signal is emitted at the end of a single 1870 * user-visible operation on the #GtkTextBuffer. 1871 * 1872 * See also: 1873 * gtk_text_buffer_end_user_action(), 1874 * gtk_text_buffer_insert_interactive(), 1875 * gtk_text_buffer_insert_range_interactive(), 1876 * gtk_text_buffer_delete_interactive(), 1877 * gtk_text_buffer_backspace(), 1878 * gtk_text_buffer_delete_selection(), 1879 * gtk_text_buffer_backspace(). 1880 */ 1881 gulong addOnEndUserAction(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1882 { 1883 auto wrapper = new OnEndUserActionDelegateWrapper(dlg); 1884 wrapper.handlerId = Signals.connectData( 1885 this, 1886 "end-user-action", 1887 cast(GCallback)&callBackEndUserAction, 1888 cast(void*)wrapper, 1889 cast(GClosureNotify)&callBackEndUserActionDestroy, 1890 connectFlags); 1891 return wrapper.handlerId; 1892 } 1893 1894 extern(C) static void callBackEndUserAction(GtkTextBuffer* textbufferStruct, OnEndUserActionDelegateWrapper wrapper) 1895 { 1896 wrapper.dlg(wrapper.outer); 1897 } 1898 1899 extern(C) static void callBackEndUserActionDestroy(OnEndUserActionDelegateWrapper wrapper, GClosure* closure) 1900 { 1901 wrapper.remove(wrapper); 1902 } 1903 1904 protected class OnInsertChildAnchorDelegateWrapper 1905 { 1906 static OnInsertChildAnchorDelegateWrapper[] listeners; 1907 void delegate(TextIter, TextChildAnchor, TextBuffer) dlg; 1908 gulong handlerId; 1909 1910 this(void delegate(TextIter, TextChildAnchor, TextBuffer) dlg) 1911 { 1912 this.dlg = dlg; 1913 this.listeners ~= this; 1914 } 1915 1916 void remove(OnInsertChildAnchorDelegateWrapper source) 1917 { 1918 foreach(index, wrapper; listeners) 1919 { 1920 if (wrapper.handlerId == source.handlerId) 1921 { 1922 listeners[index] = null; 1923 listeners = std.algorithm.remove(listeners, index); 1924 break; 1925 } 1926 } 1927 } 1928 } 1929 1930 /** 1931 * The ::insert-child-anchor signal is emitted to insert a 1932 * #GtkTextChildAnchor in a #GtkTextBuffer. 1933 * Insertion actually occurs in the default handler. 1934 * 1935 * Note that if your handler runs before the default handler it must 1936 * not invalidate the @location iter (or has to revalidate it). 1937 * The default signal handler revalidates it to be placed after the 1938 * inserted @anchor. 1939 * 1940 * See also: gtk_text_buffer_insert_child_anchor(). 1941 * 1942 * Params: 1943 * location = position to insert @anchor in @textbuffer 1944 * anchor = the #GtkTextChildAnchor to be inserted 1945 */ 1946 gulong addOnInsertChildAnchor(void delegate(TextIter, TextChildAnchor, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1947 { 1948 auto wrapper = new OnInsertChildAnchorDelegateWrapper(dlg); 1949 wrapper.handlerId = Signals.connectData( 1950 this, 1951 "insert-child-anchor", 1952 cast(GCallback)&callBackInsertChildAnchor, 1953 cast(void*)wrapper, 1954 cast(GClosureNotify)&callBackInsertChildAnchorDestroy, 1955 connectFlags); 1956 return wrapper.handlerId; 1957 } 1958 1959 extern(C) static void callBackInsertChildAnchor(GtkTextBuffer* textbufferStruct, GtkTextIter* location, GtkTextChildAnchor* anchor, OnInsertChildAnchorDelegateWrapper wrapper) 1960 { 1961 wrapper.dlg(ObjectG.getDObject!(TextIter)(location), ObjectG.getDObject!(TextChildAnchor)(anchor), wrapper.outer); 1962 } 1963 1964 extern(C) static void callBackInsertChildAnchorDestroy(OnInsertChildAnchorDelegateWrapper wrapper, GClosure* closure) 1965 { 1966 wrapper.remove(wrapper); 1967 } 1968 1969 protected class OnInsertPixbufDelegateWrapper 1970 { 1971 static OnInsertPixbufDelegateWrapper[] listeners; 1972 void delegate(TextIter, Pixbuf, TextBuffer) dlg; 1973 gulong handlerId; 1974 1975 this(void delegate(TextIter, Pixbuf, TextBuffer) dlg) 1976 { 1977 this.dlg = dlg; 1978 this.listeners ~= this; 1979 } 1980 1981 void remove(OnInsertPixbufDelegateWrapper source) 1982 { 1983 foreach(index, wrapper; listeners) 1984 { 1985 if (wrapper.handlerId == source.handlerId) 1986 { 1987 listeners[index] = null; 1988 listeners = std.algorithm.remove(listeners, index); 1989 break; 1990 } 1991 } 1992 } 1993 } 1994 1995 /** 1996 * The ::insert-pixbuf signal is emitted to insert a #GdkPixbuf 1997 * in a #GtkTextBuffer. Insertion actually occurs in the default handler. 1998 * 1999 * Note that if your handler runs before the default handler it must not 2000 * invalidate the @location iter (or has to revalidate it). 2001 * The default signal handler revalidates it to be placed after the 2002 * inserted @pixbuf. 2003 * 2004 * See also: gtk_text_buffer_insert_pixbuf(). 2005 * 2006 * Params: 2007 * location = position to insert @pixbuf in @textbuffer 2008 * pixbuf = the #GdkPixbuf to be inserted 2009 */ 2010 gulong addOnInsertPixbuf(void delegate(TextIter, Pixbuf, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 2011 { 2012 auto wrapper = new OnInsertPixbufDelegateWrapper(dlg); 2013 wrapper.handlerId = Signals.connectData( 2014 this, 2015 "insert-pixbuf", 2016 cast(GCallback)&callBackInsertPixbuf, 2017 cast(void*)wrapper, 2018 cast(GClosureNotify)&callBackInsertPixbufDestroy, 2019 connectFlags); 2020 return wrapper.handlerId; 2021 } 2022 2023 extern(C) static void callBackInsertPixbuf(GtkTextBuffer* textbufferStruct, GtkTextIter* location, GdkPixbuf* pixbuf, OnInsertPixbufDelegateWrapper wrapper) 2024 { 2025 wrapper.dlg(ObjectG.getDObject!(TextIter)(location), ObjectG.getDObject!(Pixbuf)(pixbuf), wrapper.outer); 2026 } 2027 2028 extern(C) static void callBackInsertPixbufDestroy(OnInsertPixbufDelegateWrapper wrapper, GClosure* closure) 2029 { 2030 wrapper.remove(wrapper); 2031 } 2032 2033 protected class OnInsertTextDelegateWrapper 2034 { 2035 static OnInsertTextDelegateWrapper[] listeners; 2036 void delegate(TextIter, string, int, TextBuffer) dlg; 2037 gulong handlerId; 2038 2039 this(void delegate(TextIter, string, int, TextBuffer) dlg) 2040 { 2041 this.dlg = dlg; 2042 this.listeners ~= this; 2043 } 2044 2045 void remove(OnInsertTextDelegateWrapper source) 2046 { 2047 foreach(index, wrapper; listeners) 2048 { 2049 if (wrapper.handlerId == source.handlerId) 2050 { 2051 listeners[index] = null; 2052 listeners = std.algorithm.remove(listeners, index); 2053 break; 2054 } 2055 } 2056 } 2057 } 2058 2059 /** 2060 * The ::insert-text signal is emitted to insert text in a #GtkTextBuffer. 2061 * Insertion actually occurs in the default handler. 2062 * 2063 * Note that if your handler runs before the default handler it must not 2064 * invalidate the @location iter (or has to revalidate it). 2065 * The default signal handler revalidates it to point to the end of the 2066 * inserted text. 2067 * 2068 * See also: 2069 * gtk_text_buffer_insert(), 2070 * gtk_text_buffer_insert_range(). 2071 * 2072 * Params: 2073 * location = position to insert @text in @textbuffer 2074 * text = the UTF-8 text to be inserted 2075 * len = length of the inserted text in bytes 2076 */ 2077 gulong addOnInsertText(void delegate(TextIter, string, int, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 2078 { 2079 auto wrapper = new OnInsertTextDelegateWrapper(dlg); 2080 wrapper.handlerId = Signals.connectData( 2081 this, 2082 "insert-text", 2083 cast(GCallback)&callBackInsertText, 2084 cast(void*)wrapper, 2085 cast(GClosureNotify)&callBackInsertTextDestroy, 2086 connectFlags); 2087 return wrapper.handlerId; 2088 } 2089 2090 extern(C) static void callBackInsertText(GtkTextBuffer* textbufferStruct, GtkTextIter* location, char* text, int len, OnInsertTextDelegateWrapper wrapper) 2091 { 2092 wrapper.dlg(ObjectG.getDObject!(TextIter)(location), Str.toString(text), len, wrapper.outer); 2093 } 2094 2095 extern(C) static void callBackInsertTextDestroy(OnInsertTextDelegateWrapper wrapper, GClosure* closure) 2096 { 2097 wrapper.remove(wrapper); 2098 } 2099 2100 protected class OnMarkDeletedDelegateWrapper 2101 { 2102 static OnMarkDeletedDelegateWrapper[] listeners; 2103 void delegate(TextMark, TextBuffer) dlg; 2104 gulong handlerId; 2105 2106 this(void delegate(TextMark, TextBuffer) dlg) 2107 { 2108 this.dlg = dlg; 2109 this.listeners ~= this; 2110 } 2111 2112 void remove(OnMarkDeletedDelegateWrapper source) 2113 { 2114 foreach(index, wrapper; listeners) 2115 { 2116 if (wrapper.handlerId == source.handlerId) 2117 { 2118 listeners[index] = null; 2119 listeners = std.algorithm.remove(listeners, index); 2120 break; 2121 } 2122 } 2123 } 2124 } 2125 2126 /** 2127 * The ::mark-deleted signal is emitted as notification 2128 * after a #GtkTextMark is deleted. 2129 * 2130 * See also: 2131 * gtk_text_buffer_delete_mark(). 2132 * 2133 * Params: 2134 * mark = The mark that was deleted 2135 */ 2136 gulong addOnMarkDeleted(void delegate(TextMark, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 2137 { 2138 auto wrapper = new OnMarkDeletedDelegateWrapper(dlg); 2139 wrapper.handlerId = Signals.connectData( 2140 this, 2141 "mark-deleted", 2142 cast(GCallback)&callBackMarkDeleted, 2143 cast(void*)wrapper, 2144 cast(GClosureNotify)&callBackMarkDeletedDestroy, 2145 connectFlags); 2146 return wrapper.handlerId; 2147 } 2148 2149 extern(C) static void callBackMarkDeleted(GtkTextBuffer* textbufferStruct, GtkTextMark* mark, OnMarkDeletedDelegateWrapper wrapper) 2150 { 2151 wrapper.dlg(ObjectG.getDObject!(TextMark)(mark), wrapper.outer); 2152 } 2153 2154 extern(C) static void callBackMarkDeletedDestroy(OnMarkDeletedDelegateWrapper wrapper, GClosure* closure) 2155 { 2156 wrapper.remove(wrapper); 2157 } 2158 2159 protected class OnMarkSetDelegateWrapper 2160 { 2161 static OnMarkSetDelegateWrapper[] listeners; 2162 void delegate(TextIter, TextMark, TextBuffer) dlg; 2163 gulong handlerId; 2164 2165 this(void delegate(TextIter, TextMark, TextBuffer) dlg) 2166 { 2167 this.dlg = dlg; 2168 this.listeners ~= this; 2169 } 2170 2171 void remove(OnMarkSetDelegateWrapper source) 2172 { 2173 foreach(index, wrapper; listeners) 2174 { 2175 if (wrapper.handlerId == source.handlerId) 2176 { 2177 listeners[index] = null; 2178 listeners = std.algorithm.remove(listeners, index); 2179 break; 2180 } 2181 } 2182 } 2183 } 2184 2185 /** 2186 * The ::mark-set signal is emitted as notification 2187 * after a #GtkTextMark is set. 2188 * 2189 * See also: 2190 * gtk_text_buffer_create_mark(), 2191 * gtk_text_buffer_move_mark(). 2192 * 2193 * Params: 2194 * location = The location of @mark in @textbuffer 2195 * mark = The mark that is set 2196 */ 2197 gulong addOnMarkSet(void delegate(TextIter, TextMark, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 2198 { 2199 auto wrapper = new OnMarkSetDelegateWrapper(dlg); 2200 wrapper.handlerId = Signals.connectData( 2201 this, 2202 "mark-set", 2203 cast(GCallback)&callBackMarkSet, 2204 cast(void*)wrapper, 2205 cast(GClosureNotify)&callBackMarkSetDestroy, 2206 connectFlags); 2207 return wrapper.handlerId; 2208 } 2209 2210 extern(C) static void callBackMarkSet(GtkTextBuffer* textbufferStruct, GtkTextIter* location, GtkTextMark* mark, OnMarkSetDelegateWrapper wrapper) 2211 { 2212 wrapper.dlg(ObjectG.getDObject!(TextIter)(location), ObjectG.getDObject!(TextMark)(mark), wrapper.outer); 2213 } 2214 2215 extern(C) static void callBackMarkSetDestroy(OnMarkSetDelegateWrapper wrapper, GClosure* closure) 2216 { 2217 wrapper.remove(wrapper); 2218 } 2219 2220 protected class OnModifiedChangedDelegateWrapper 2221 { 2222 static OnModifiedChangedDelegateWrapper[] listeners; 2223 void delegate(TextBuffer) dlg; 2224 gulong handlerId; 2225 2226 this(void delegate(TextBuffer) dlg) 2227 { 2228 this.dlg = dlg; 2229 this.listeners ~= this; 2230 } 2231 2232 void remove(OnModifiedChangedDelegateWrapper source) 2233 { 2234 foreach(index, wrapper; listeners) 2235 { 2236 if (wrapper.handlerId == source.handlerId) 2237 { 2238 listeners[index] = null; 2239 listeners = std.algorithm.remove(listeners, index); 2240 break; 2241 } 2242 } 2243 } 2244 } 2245 2246 /** 2247 * The ::modified-changed signal is emitted when the modified bit of a 2248 * #GtkTextBuffer flips. 2249 * 2250 * See also: 2251 * gtk_text_buffer_set_modified(). 2252 */ 2253 gulong addOnModifiedChanged(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 2254 { 2255 auto wrapper = new OnModifiedChangedDelegateWrapper(dlg); 2256 wrapper.handlerId = Signals.connectData( 2257 this, 2258 "modified-changed", 2259 cast(GCallback)&callBackModifiedChanged, 2260 cast(void*)wrapper, 2261 cast(GClosureNotify)&callBackModifiedChangedDestroy, 2262 connectFlags); 2263 return wrapper.handlerId; 2264 } 2265 2266 extern(C) static void callBackModifiedChanged(GtkTextBuffer* textbufferStruct, OnModifiedChangedDelegateWrapper wrapper) 2267 { 2268 wrapper.dlg(wrapper.outer); 2269 } 2270 2271 extern(C) static void callBackModifiedChangedDestroy(OnModifiedChangedDelegateWrapper wrapper, GClosure* closure) 2272 { 2273 wrapper.remove(wrapper); 2274 } 2275 2276 protected class OnPasteDoneDelegateWrapper 2277 { 2278 static OnPasteDoneDelegateWrapper[] listeners; 2279 void delegate(Clipboard, TextBuffer) dlg; 2280 gulong handlerId; 2281 2282 this(void delegate(Clipboard, TextBuffer) dlg) 2283 { 2284 this.dlg = dlg; 2285 this.listeners ~= this; 2286 } 2287 2288 void remove(OnPasteDoneDelegateWrapper source) 2289 { 2290 foreach(index, wrapper; listeners) 2291 { 2292 if (wrapper.handlerId == source.handlerId) 2293 { 2294 listeners[index] = null; 2295 listeners = std.algorithm.remove(listeners, index); 2296 break; 2297 } 2298 } 2299 } 2300 } 2301 2302 /** 2303 * The paste-done signal is emitted after paste operation has been completed. 2304 * This is useful to properly scroll the view to the end of the pasted text. 2305 * See gtk_text_buffer_paste_clipboard() for more details. 2306 * 2307 * Params: 2308 * clipboard = the #GtkClipboard pasted from 2309 * 2310 * Since: 2.16 2311 */ 2312 gulong addOnPasteDone(void delegate(Clipboard, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 2313 { 2314 auto wrapper = new OnPasteDoneDelegateWrapper(dlg); 2315 wrapper.handlerId = Signals.connectData( 2316 this, 2317 "paste-done", 2318 cast(GCallback)&callBackPasteDone, 2319 cast(void*)wrapper, 2320 cast(GClosureNotify)&callBackPasteDoneDestroy, 2321 connectFlags); 2322 return wrapper.handlerId; 2323 } 2324 2325 extern(C) static void callBackPasteDone(GtkTextBuffer* textbufferStruct, GtkClipboard* clipboard, OnPasteDoneDelegateWrapper wrapper) 2326 { 2327 wrapper.dlg(ObjectG.getDObject!(Clipboard)(clipboard), wrapper.outer); 2328 } 2329 2330 extern(C) static void callBackPasteDoneDestroy(OnPasteDoneDelegateWrapper wrapper, GClosure* closure) 2331 { 2332 wrapper.remove(wrapper); 2333 } 2334 2335 protected class OnRemoveTagDelegateWrapper 2336 { 2337 static OnRemoveTagDelegateWrapper[] listeners; 2338 void delegate(TextTag, TextIter, TextIter, TextBuffer) dlg; 2339 gulong handlerId; 2340 2341 this(void delegate(TextTag, TextIter, TextIter, TextBuffer) dlg) 2342 { 2343 this.dlg = dlg; 2344 this.listeners ~= this; 2345 } 2346 2347 void remove(OnRemoveTagDelegateWrapper source) 2348 { 2349 foreach(index, wrapper; listeners) 2350 { 2351 if (wrapper.handlerId == source.handlerId) 2352 { 2353 listeners[index] = null; 2354 listeners = std.algorithm.remove(listeners, index); 2355 break; 2356 } 2357 } 2358 } 2359 } 2360 2361 /** 2362 * The ::remove-tag signal is emitted to remove all occurrences of @tag from 2363 * a range of text in a #GtkTextBuffer. 2364 * Removal actually occurs in the default handler. 2365 * 2366 * Note that if your handler runs before the default handler it must not 2367 * invalidate the @start and @end iters (or has to revalidate them). 2368 * 2369 * See also: 2370 * gtk_text_buffer_remove_tag(). 2371 * 2372 * Params: 2373 * tag = the tag to be removed 2374 * start = the start of the range the tag is removed from 2375 * end = the end of the range the tag is removed from 2376 */ 2377 gulong addOnRemoveTag(void delegate(TextTag, TextIter, TextIter, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 2378 { 2379 auto wrapper = new OnRemoveTagDelegateWrapper(dlg); 2380 wrapper.handlerId = Signals.connectData( 2381 this, 2382 "remove-tag", 2383 cast(GCallback)&callBackRemoveTag, 2384 cast(void*)wrapper, 2385 cast(GClosureNotify)&callBackRemoveTagDestroy, 2386 connectFlags); 2387 return wrapper.handlerId; 2388 } 2389 2390 extern(C) static void callBackRemoveTag(GtkTextBuffer* textbufferStruct, GtkTextTag* tag, GtkTextIter* start, GtkTextIter* end, OnRemoveTagDelegateWrapper wrapper) 2391 { 2392 wrapper.dlg(ObjectG.getDObject!(TextTag)(tag), ObjectG.getDObject!(TextIter)(start), ObjectG.getDObject!(TextIter)(end), wrapper.outer); 2393 } 2394 2395 extern(C) static void callBackRemoveTagDestroy(OnRemoveTagDelegateWrapper wrapper, GClosure* closure) 2396 { 2397 wrapper.remove(wrapper); 2398 } 2399 }