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