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