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 alias delet = delete_; 459 /** 460 * Deletes text between @start and @end. The order of @start and @end 461 * is not actually relevant; gtk_text_buffer_delete() will reorder 462 * them. This function actually emits the “delete-range” signal, and 463 * the default handler of that signal deletes the text. Because the 464 * buffer is modified, all outstanding iterators become invalid after 465 * calling this function; however, the @start and @end will be 466 * re-initialized to point to the location where text was deleted. 467 * 468 * Params: 469 * start = a position in @buffer 470 * end = another position in @buffer 471 */ 472 public void delete_(TextIter start, TextIter end) 473 { 474 gtk_text_buffer_delete(gtkTextBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 475 } 476 477 /** 478 * Deletes all editable text in the given range. 479 * Calls gtk_text_buffer_delete() for each editable sub-range of 480 * [@start,@end). @start and @end are revalidated to point to 481 * the location of the last deleted range, or left untouched if 482 * no text was deleted. 483 * 484 * Params: 485 * startIter = start of range to delete 486 * endIter = end of range 487 * defaultEditable = whether the buffer is editable by default 488 * 489 * Returns: whether some text was actually deleted 490 */ 491 public bool deleteInteractive(TextIter startIter, TextIter endIter, bool defaultEditable) 492 { 493 return gtk_text_buffer_delete_interactive(gtkTextBuffer, (startIter is null) ? null : startIter.getTextIterStruct(), (endIter is null) ? null : endIter.getTextIterStruct(), defaultEditable) != 0; 494 } 495 496 /** 497 * Deletes @mark, so that it’s no longer located anywhere in the 498 * buffer. Removes the reference the buffer holds to the mark, so if 499 * you haven’t called g_object_ref() on the mark, it will be freed. Even 500 * if the mark isn’t freed, most operations on @mark become 501 * invalid, until it gets added to a buffer again with 502 * gtk_text_buffer_add_mark(). Use gtk_text_mark_get_deleted() to 503 * find out if a mark has been removed from its buffer. 504 * The #GtkTextBuffer::mark-deleted signal will be emitted as notification after 505 * the mark is deleted. 506 * 507 * Params: 508 * mark = a #GtkTextMark in @buffer 509 */ 510 public void deleteMark(TextMark mark) 511 { 512 gtk_text_buffer_delete_mark(gtkTextBuffer, (mark is null) ? null : mark.getTextMarkStruct()); 513 } 514 515 /** 516 * Deletes the mark named @name; the mark must exist. See 517 * gtk_text_buffer_delete_mark() for details. 518 * 519 * Params: 520 * name = name of a mark in @buffer 521 */ 522 public void deleteMarkByName(string name) 523 { 524 gtk_text_buffer_delete_mark_by_name(gtkTextBuffer, Str.toStringz(name)); 525 } 526 527 /** 528 * Deletes the range between the “insert” and “selection_bound” marks, 529 * that is, the currently-selected text. If @interactive is %TRUE, 530 * the editability of the selection will be considered (users can’t delete 531 * uneditable text). 532 * 533 * Params: 534 * interactive = whether the deletion is caused by user interaction 535 * defaultEditable = whether the buffer is editable by default 536 * 537 * Returns: whether there was a non-empty selection to delete 538 */ 539 public bool deleteSelection(bool interactive, bool defaultEditable) 540 { 541 return gtk_text_buffer_delete_selection(gtkTextBuffer, interactive, defaultEditable) != 0; 542 } 543 544 /** 545 * This function deserializes rich text in format @format and inserts 546 * it at @iter. 547 * 548 * @formats to be used must be registered using 549 * gtk_text_buffer_register_deserialize_format() or 550 * gtk_text_buffer_register_deserialize_tagset() beforehand. 551 * 552 * Params: 553 * contentBuffer = the #GtkTextBuffer to deserialize into 554 * format = the rich text format to use for deserializing 555 * iter = insertion point for the deserialized text 556 * data = data to deserialize 557 * 558 * Returns: %TRUE on success, %FALSE otherwise. 559 * 560 * Since: 2.10 561 * 562 * Throws: GException on failure. 563 */ 564 public bool deserialize(TextBuffer contentBuffer, GdkAtom format, TextIter iter, ubyte[] data) 565 { 566 GError* err = null; 567 568 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; 569 570 if (err !is null) 571 { 572 throw new GException( new ErrorG(err) ); 573 } 574 575 return p; 576 } 577 578 /** 579 * This functions returns the value set with 580 * gtk_text_buffer_deserialize_set_can_create_tags() 581 * 582 * Params: 583 * format = a #GdkAtom representing a registered rich text format 584 * 585 * Returns: whether deserializing this format may create tags 586 * 587 * Since: 2.10 588 */ 589 public bool deserializeGetCanCreateTags(GdkAtom format) 590 { 591 return gtk_text_buffer_deserialize_get_can_create_tags(gtkTextBuffer, format) != 0; 592 } 593 594 /** 595 * Use this function to allow a rich text deserialization function to 596 * create new tags in the receiving buffer. Note that using this 597 * function is almost always a bad idea, because the rich text 598 * functions you register should know how to map the rich text format 599 * they handler to your text buffers set of tags. 600 * 601 * The ability of creating new (arbitrary!) tags in the receiving buffer 602 * is meant for special rich text formats like the internal one that 603 * is registered using gtk_text_buffer_register_deserialize_tagset(), 604 * because that format is essentially a dump of the internal structure 605 * of the source buffer, including its tag names. 606 * 607 * You should allow creation of tags only if you know what you are 608 * doing, e.g. if you defined a tagset name for your application 609 * suite’s text buffers and you know that it’s fine to receive new 610 * tags from these buffers, because you know that your application can 611 * handle the newly created tags. 612 * 613 * Params: 614 * format = a #GdkAtom representing a registered rich text format 615 * canCreateTags = whether deserializing this format may create tags 616 * 617 * Since: 2.10 618 */ 619 public void deserializeSetCanCreateTags(GdkAtom format, bool canCreateTags) 620 { 621 gtk_text_buffer_deserialize_set_can_create_tags(gtkTextBuffer, format, canCreateTags); 622 } 623 624 /** 625 * Should be paired with a call to gtk_text_buffer_begin_user_action(). 626 * See that function for a full explanation. 627 */ 628 public void endUserAction() 629 { 630 gtk_text_buffer_end_user_action(gtkTextBuffer); 631 } 632 633 /** 634 * Retrieves the first and last iterators in the buffer, i.e. the 635 * entire buffer lies within the range [@start,@end). 636 * 637 * Params: 638 * start = iterator to initialize with first position in the buffer 639 * end = iterator to initialize with the end iterator 640 */ 641 public void getBounds(out TextIter start, out TextIter end) 642 { 643 GtkTextIter* outstart = sliceNew!GtkTextIter(); 644 GtkTextIter* outend = sliceNew!GtkTextIter(); 645 646 gtk_text_buffer_get_bounds(gtkTextBuffer, outstart, outend); 647 648 start = ObjectG.getDObject!(TextIter)(outstart, true); 649 end = ObjectG.getDObject!(TextIter)(outend, true); 650 } 651 652 /** 653 * Gets the number of characters in the buffer; note that characters 654 * and bytes are not the same, you can’t e.g. expect the contents of 655 * the buffer in string form to be this many bytes long. The character 656 * count is cached, so this function is very fast. 657 * 658 * Returns: number of characters in the buffer 659 */ 660 public int getCharCount() 661 { 662 return gtk_text_buffer_get_char_count(gtkTextBuffer); 663 } 664 665 /** 666 * This function returns the list of targets this text buffer can 667 * provide for copying and as DND source. The targets in the list are 668 * added with @info values from the #GtkTextBufferTargetInfo enum, 669 * using gtk_target_list_add_rich_text_targets() and 670 * gtk_target_list_add_text_targets(). 671 * 672 * Returns: the #GtkTargetList 673 * 674 * Since: 2.10 675 */ 676 public TargetList getCopyTargetList() 677 { 678 auto p = gtk_text_buffer_get_copy_target_list(gtkTextBuffer); 679 680 if(p is null) 681 { 682 return null; 683 } 684 685 return ObjectG.getDObject!(TargetList)(cast(GtkTargetList*) p); 686 } 687 688 /** 689 * This function returns the rich text deserialize formats registered 690 * with @buffer using gtk_text_buffer_register_deserialize_format() or 691 * gtk_text_buffer_register_deserialize_tagset() 692 * 693 * Returns: an array of 694 * #GdkAtoms representing the registered formats. 695 * 696 * Since: 2.10 697 */ 698 public GdkAtom[] getDeserializeFormats() 699 { 700 int nFormats; 701 702 auto p = gtk_text_buffer_get_deserialize_formats(gtkTextBuffer, &nFormats); 703 704 return p[0 .. nFormats]; 705 } 706 707 /** 708 * Initializes @iter with the “end iterator,” one past the last valid 709 * character in the text buffer. If dereferenced with 710 * gtk_text_iter_get_char(), the end iterator has a character value of 0. 711 * The entire buffer lies in the range from the first position in 712 * the buffer (call gtk_text_buffer_get_start_iter() to get 713 * character position 0) to the end iterator. 714 * 715 * Params: 716 * iter = iterator to initialize 717 */ 718 public void getEndIter(out TextIter iter) 719 { 720 GtkTextIter* outiter = sliceNew!GtkTextIter(); 721 722 gtk_text_buffer_get_end_iter(gtkTextBuffer, outiter); 723 724 iter = ObjectG.getDObject!(TextIter)(outiter, true); 725 } 726 727 /** 728 * Indicates whether the buffer has some text currently selected. 729 * 730 * Returns: %TRUE if the there is text selected 731 * 732 * Since: 2.10 733 */ 734 public bool getHasSelection() 735 { 736 return gtk_text_buffer_get_has_selection(gtkTextBuffer) != 0; 737 } 738 739 /** 740 * Returns the mark that represents the cursor (insertion point). 741 * Equivalent to calling gtk_text_buffer_get_mark() to get the mark 742 * named “insert”, but very slightly more efficient, and involves less 743 * typing. 744 * 745 * Returns: insertion point mark 746 */ 747 public TextMark getInsert() 748 { 749 auto p = gtk_text_buffer_get_insert(gtkTextBuffer); 750 751 if(p is null) 752 { 753 return null; 754 } 755 756 return ObjectG.getDObject!(TextMark)(cast(GtkTextMark*) p); 757 } 758 759 /** 760 * Obtains the location of @anchor within @buffer. 761 * 762 * Params: 763 * iter = an iterator to be initialized 764 * anchor = a child anchor that appears in @buffer 765 */ 766 public void getIterAtChildAnchor(out TextIter iter, TextChildAnchor anchor) 767 { 768 GtkTextIter* outiter = sliceNew!GtkTextIter(); 769 770 gtk_text_buffer_get_iter_at_child_anchor(gtkTextBuffer, outiter, (anchor is null) ? null : anchor.getTextChildAnchorStruct()); 771 772 iter = ObjectG.getDObject!(TextIter)(outiter, true); 773 } 774 775 /** 776 * Initializes @iter to the start of the given line. If @line_number is greater 777 * than the number of lines in the @buffer, the end iterator is returned. 778 * 779 * Params: 780 * iter = iterator to initialize 781 * lineNumber = line number counting from 0 782 */ 783 public void getIterAtLine(out TextIter iter, int lineNumber) 784 { 785 GtkTextIter* outiter = sliceNew!GtkTextIter(); 786 787 gtk_text_buffer_get_iter_at_line(gtkTextBuffer, outiter, lineNumber); 788 789 iter = ObjectG.getDObject!(TextIter)(outiter, true); 790 } 791 792 /** 793 * Obtains an iterator pointing to @byte_index within the given line. 794 * @byte_index must be the start of a UTF-8 character. Note bytes, not 795 * characters; UTF-8 may encode one character as multiple bytes. 796 * 797 * Before the 3.20 version, it was not allowed to pass an invalid location. 798 * 799 * Since the 3.20 version, if @line_number is greater than the number of lines 800 * in the @buffer, the end iterator is returned. And if @byte_index is off the 801 * end of the line, the iterator at the end of the line is returned. 802 * 803 * Params: 804 * iter = iterator to initialize 805 * lineNumber = line number counting from 0 806 * byteIndex = byte index from start of line 807 */ 808 public void getIterAtLineIndex(out TextIter iter, int lineNumber, int byteIndex) 809 { 810 GtkTextIter* outiter = sliceNew!GtkTextIter(); 811 812 gtk_text_buffer_get_iter_at_line_index(gtkTextBuffer, outiter, lineNumber, byteIndex); 813 814 iter = ObjectG.getDObject!(TextIter)(outiter, true); 815 } 816 817 /** 818 * Obtains an iterator pointing to @char_offset within the given line. Note 819 * characters, not bytes; UTF-8 may encode one character as multiple bytes. 820 * 821 * Before the 3.20 version, it was not allowed to pass an invalid location. 822 * 823 * Since the 3.20 version, if @line_number is greater than the number of lines 824 * in the @buffer, the end iterator is returned. And if @char_offset is off the 825 * end of the line, the iterator at the end of the line is returned. 826 * 827 * Params: 828 * iter = iterator to initialize 829 * lineNumber = line number counting from 0 830 * charOffset = char offset from start of line 831 */ 832 public void getIterAtLineOffset(out TextIter iter, int lineNumber, int charOffset) 833 { 834 GtkTextIter* outiter = sliceNew!GtkTextIter(); 835 836 gtk_text_buffer_get_iter_at_line_offset(gtkTextBuffer, outiter, lineNumber, charOffset); 837 838 iter = ObjectG.getDObject!(TextIter)(outiter, true); 839 } 840 841 /** 842 * Initializes @iter with the current position of @mark. 843 * 844 * Params: 845 * iter = iterator to initialize 846 * mark = a #GtkTextMark in @buffer 847 */ 848 public void getIterAtMark(out TextIter iter, TextMark mark) 849 { 850 GtkTextIter* outiter = sliceNew!GtkTextIter(); 851 852 gtk_text_buffer_get_iter_at_mark(gtkTextBuffer, outiter, (mark is null) ? null : mark.getTextMarkStruct()); 853 854 iter = ObjectG.getDObject!(TextIter)(outiter, true); 855 } 856 857 /** 858 * Initializes @iter to a position @char_offset chars from the start 859 * of the entire buffer. If @char_offset is -1 or greater than the number 860 * of characters in the buffer, @iter is initialized to the end iterator, 861 * the iterator one past the last valid character in the buffer. 862 * 863 * Params: 864 * iter = iterator to initialize 865 * charOffset = char offset from start of buffer, counting from 0, or -1 866 */ 867 public void getIterAtOffset(out TextIter iter, int charOffset) 868 { 869 GtkTextIter* outiter = sliceNew!GtkTextIter(); 870 871 gtk_text_buffer_get_iter_at_offset(gtkTextBuffer, outiter, charOffset); 872 873 iter = ObjectG.getDObject!(TextIter)(outiter, true); 874 } 875 876 /** 877 * Obtains the number of lines in the buffer. This value is cached, so 878 * the function is very fast. 879 * 880 * Returns: number of lines in the buffer 881 */ 882 public int getLineCount() 883 { 884 return gtk_text_buffer_get_line_count(gtkTextBuffer); 885 } 886 887 /** 888 * Returns the mark named @name in buffer @buffer, or %NULL if no such 889 * mark exists in the buffer. 890 * 891 * Params: 892 * name = a mark name 893 * 894 * Returns: a #GtkTextMark, or %NULL 895 */ 896 public TextMark getMark(string name) 897 { 898 auto p = gtk_text_buffer_get_mark(gtkTextBuffer, Str.toStringz(name)); 899 900 if(p is null) 901 { 902 return null; 903 } 904 905 return ObjectG.getDObject!(TextMark)(cast(GtkTextMark*) p); 906 } 907 908 /** 909 * Indicates whether the buffer has been modified since the last call 910 * to gtk_text_buffer_set_modified() set the modification flag to 911 * %FALSE. Used for example to enable a “save” function in a text 912 * editor. 913 * 914 * Returns: %TRUE if the buffer has been modified 915 */ 916 public bool getModified() 917 { 918 return gtk_text_buffer_get_modified(gtkTextBuffer) != 0; 919 } 920 921 /** 922 * This function returns the list of targets this text buffer supports 923 * for pasting and as DND destination. The targets in the list are 924 * added with @info values from the #GtkTextBufferTargetInfo enum, 925 * using gtk_target_list_add_rich_text_targets() and 926 * gtk_target_list_add_text_targets(). 927 * 928 * Returns: the #GtkTargetList 929 * 930 * Since: 2.10 931 */ 932 public TargetList getPasteTargetList() 933 { 934 auto p = gtk_text_buffer_get_paste_target_list(gtkTextBuffer); 935 936 if(p is null) 937 { 938 return null; 939 } 940 941 return ObjectG.getDObject!(TargetList)(cast(GtkTargetList*) p); 942 } 943 944 /** 945 * Returns the mark that represents the selection bound. Equivalent 946 * to calling gtk_text_buffer_get_mark() to get the mark named 947 * “selection_bound”, but very slightly more efficient, and involves 948 * less typing. 949 * 950 * The currently-selected text in @buffer is the region between the 951 * “selection_bound” and “insert” marks. If “selection_bound” and 952 * “insert” are in the same place, then there is no current selection. 953 * gtk_text_buffer_get_selection_bounds() is another convenient function 954 * for handling the selection, if you just want to know whether there’s a 955 * selection and what its bounds are. 956 * 957 * Returns: selection bound mark 958 */ 959 public TextMark getSelectionBound() 960 { 961 auto p = gtk_text_buffer_get_selection_bound(gtkTextBuffer); 962 963 if(p is null) 964 { 965 return null; 966 } 967 968 return ObjectG.getDObject!(TextMark)(cast(GtkTextMark*) p); 969 } 970 971 /** 972 * Returns %TRUE if some text is selected; places the bounds 973 * of the selection in @start and @end (if the selection has length 0, 974 * then @start and @end are filled in with the same value). 975 * @start and @end will be in ascending order. If @start and @end are 976 * NULL, then they are not filled in, but the return value still indicates 977 * whether text is selected. 978 * 979 * Params: 980 * start = iterator to initialize with selection start 981 * end = iterator to initialize with selection end 982 * 983 * Returns: whether the selection has nonzero length 984 */ 985 public bool getSelectionBounds(out TextIter start, out TextIter end) 986 { 987 GtkTextIter* outstart = sliceNew!GtkTextIter(); 988 GtkTextIter* outend = sliceNew!GtkTextIter(); 989 990 auto p = gtk_text_buffer_get_selection_bounds(gtkTextBuffer, outstart, outend) != 0; 991 992 start = ObjectG.getDObject!(TextIter)(outstart, true); 993 end = ObjectG.getDObject!(TextIter)(outend, true); 994 995 return p; 996 } 997 998 /** 999 * This function returns the rich text serialize formats registered 1000 * with @buffer using gtk_text_buffer_register_serialize_format() or 1001 * gtk_text_buffer_register_serialize_tagset() 1002 * 1003 * Returns: an array of 1004 * #GdkAtoms representing the registered formats. 1005 * 1006 * Since: 2.10 1007 */ 1008 public GdkAtom[] getSerializeFormats() 1009 { 1010 int nFormats; 1011 1012 auto p = gtk_text_buffer_get_serialize_formats(gtkTextBuffer, &nFormats); 1013 1014 return p[0 .. nFormats]; 1015 } 1016 1017 /** 1018 * Returns the text in the range [@start,@end). Excludes undisplayed 1019 * text (text marked with tags that set the invisibility attribute) if 1020 * @include_hidden_chars is %FALSE. The returned string includes a 1021 * 0xFFFC character whenever the buffer contains 1022 * embedded images, so byte and character indexes into 1023 * the returned string do correspond to byte 1024 * and character indexes into the buffer. Contrast with 1025 * gtk_text_buffer_get_text(). Note that 0xFFFC can occur in normal 1026 * text as well, so it is not a reliable indicator that a pixbuf or 1027 * widget is in the buffer. 1028 * 1029 * Params: 1030 * start = start of a range 1031 * end = end of a range 1032 * includeHiddenChars = whether to include invisible text 1033 * 1034 * Returns: an allocated UTF-8 string 1035 */ 1036 public string getSlice(TextIter start, TextIter end, bool includeHiddenChars) 1037 { 1038 auto retStr = gtk_text_buffer_get_slice(gtkTextBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct(), includeHiddenChars); 1039 1040 scope(exit) Str.freeString(retStr); 1041 return Str.toString(retStr); 1042 } 1043 1044 /** 1045 * Initialized @iter with the first position in the text buffer. This 1046 * is the same as using gtk_text_buffer_get_iter_at_offset() to get 1047 * the iter at character offset 0. 1048 * 1049 * Params: 1050 * iter = iterator to initialize 1051 */ 1052 public void getStartIter(out TextIter iter) 1053 { 1054 GtkTextIter* outiter = sliceNew!GtkTextIter(); 1055 1056 gtk_text_buffer_get_start_iter(gtkTextBuffer, outiter); 1057 1058 iter = ObjectG.getDObject!(TextIter)(outiter, true); 1059 } 1060 1061 /** 1062 * Get the #GtkTextTagTable associated with this buffer. 1063 * 1064 * Returns: the buffer’s tag table 1065 */ 1066 public TextTagTable getTagTable() 1067 { 1068 auto p = gtk_text_buffer_get_tag_table(gtkTextBuffer); 1069 1070 if(p is null) 1071 { 1072 return null; 1073 } 1074 1075 return ObjectG.getDObject!(TextTagTable)(cast(GtkTextTagTable*) p); 1076 } 1077 1078 /** 1079 * Returns the text in the range [@start,@end). Excludes undisplayed 1080 * text (text marked with tags that set the invisibility attribute) if 1081 * @include_hidden_chars is %FALSE. Does not include characters 1082 * representing embedded images, so byte and character indexes into 1083 * the returned string do not correspond to byte 1084 * and character indexes into the buffer. Contrast with 1085 * gtk_text_buffer_get_slice(). 1086 * 1087 * Params: 1088 * start = start of a range 1089 * end = end of a range 1090 * includeHiddenChars = whether to include invisible text 1091 * 1092 * Returns: an allocated UTF-8 string 1093 */ 1094 public string getText(TextIter start, TextIter end, bool includeHiddenChars) 1095 { 1096 auto retStr = gtk_text_buffer_get_text(gtkTextBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct(), includeHiddenChars); 1097 1098 scope(exit) Str.freeString(retStr); 1099 return Str.toString(retStr); 1100 } 1101 1102 /** 1103 * Inserts @len bytes of @text at position @iter. If @len is -1, 1104 * @text must be nul-terminated and will be inserted in its 1105 * entirety. Emits the “insert-text” signal; insertion actually occurs 1106 * in the default handler for the signal. @iter is invalidated when 1107 * insertion occurs (because the buffer contents change), but the 1108 * default signal handler revalidates it to point to the end of the 1109 * inserted text. 1110 * 1111 * Params: 1112 * iter = a position in the buffer 1113 * text = text in UTF-8 format 1114 */ 1115 public void insert(TextIter iter, string text) 1116 { 1117 gtk_text_buffer_insert(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(text), cast(int)text.length); 1118 } 1119 1120 /** 1121 * Simply calls gtk_text_buffer_insert(), using the current 1122 * cursor position as the insertion point. 1123 * 1124 * Params: 1125 * text = text in UTF-8 format 1126 */ 1127 public void insertAtCursor(string text) 1128 { 1129 gtk_text_buffer_insert_at_cursor(gtkTextBuffer, Str.toStringz(text), cast(int)text.length); 1130 } 1131 1132 /** 1133 * Inserts a child widget anchor into the text buffer at @iter. The 1134 * anchor will be counted as one character in character counts, and 1135 * when obtaining the buffer contents as a string, will be represented 1136 * by the Unicode “object replacement character” 0xFFFC. Note that the 1137 * “slice” variants for obtaining portions of the buffer as a string 1138 * include this character for child anchors, but the “text” variants do 1139 * not. E.g. see gtk_text_buffer_get_slice() and 1140 * gtk_text_buffer_get_text(). Consider 1141 * gtk_text_buffer_create_child_anchor() as a more convenient 1142 * alternative to this function. The buffer will add a reference to 1143 * the anchor, so you can unref it after insertion. 1144 * 1145 * Params: 1146 * iter = location to insert the anchor 1147 * anchor = a #GtkTextChildAnchor 1148 */ 1149 public void insertChildAnchor(TextIter iter, TextChildAnchor anchor) 1150 { 1151 gtk_text_buffer_insert_child_anchor(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), (anchor is null) ? null : anchor.getTextChildAnchorStruct()); 1152 } 1153 1154 /** 1155 * Like gtk_text_buffer_insert(), but the insertion will not occur if 1156 * @iter is at a non-editable location in the buffer. Usually you 1157 * want to prevent insertions at ineditable locations if the insertion 1158 * results from a user action (is interactive). 1159 * 1160 * @default_editable indicates the editability of text that doesn't 1161 * have a tag affecting editability applied to it. Typically the 1162 * result of gtk_text_view_get_editable() is appropriate here. 1163 * 1164 * Params: 1165 * iter = a position in @buffer 1166 * text = some UTF-8 text 1167 * defaultEditable = default editability of buffer 1168 * 1169 * Returns: whether text was actually inserted 1170 */ 1171 public bool insertInteractive(TextIter iter, string text, bool defaultEditable) 1172 { 1173 return gtk_text_buffer_insert_interactive(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(text), cast(int)text.length, defaultEditable) != 0; 1174 } 1175 1176 /** 1177 * Calls gtk_text_buffer_insert_interactive() at the cursor 1178 * position. 1179 * 1180 * @default_editable indicates the editability of text that doesn't 1181 * have a tag affecting editability applied to it. Typically the 1182 * result of gtk_text_view_get_editable() is appropriate here. 1183 * 1184 * Params: 1185 * text = text in UTF-8 format 1186 * defaultEditable = default editability of buffer 1187 * 1188 * Returns: whether text was actually inserted 1189 */ 1190 public bool insertInteractiveAtCursor(string text, bool defaultEditable) 1191 { 1192 return gtk_text_buffer_insert_interactive_at_cursor(gtkTextBuffer, Str.toStringz(text), cast(int)text.length, defaultEditable) != 0; 1193 } 1194 1195 /** 1196 * Inserts the text in @markup at position @iter. @markup will be inserted 1197 * in its entirety and must be nul-terminated and valid UTF-8. Emits the 1198 * #GtkTextBuffer::insert-text signal, possibly multiple times; insertion 1199 * actually occurs in the default handler for the signal. @iter will point 1200 * to the end of the inserted text on return. 1201 * 1202 * Params: 1203 * iter = location to insert the markup 1204 * markup = a nul-terminated UTF-8 string containing [Pango markup][PangoMarkupFormat] 1205 * len = length of @markup in bytes, or -1 1206 * 1207 * Since: 3.16 1208 */ 1209 public void insertMarkup(TextIter iter, string markup, int len) 1210 { 1211 gtk_text_buffer_insert_markup(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), Str.toStringz(markup), len); 1212 } 1213 1214 /** 1215 * Inserts an image into the text buffer at @iter. The image will be 1216 * counted as one character in character counts, and when obtaining 1217 * the buffer contents as a string, will be represented by the Unicode 1218 * “object replacement character” 0xFFFC. Note that the “slice” 1219 * variants for obtaining portions of the buffer as a string include 1220 * this character for pixbufs, but the “text” variants do 1221 * not. e.g. see gtk_text_buffer_get_slice() and 1222 * gtk_text_buffer_get_text(). 1223 * 1224 * Params: 1225 * iter = location to insert the pixbuf 1226 * pixbuf = a #GdkPixbuf 1227 */ 1228 public void insertPixbuf(TextIter iter, Pixbuf pixbuf) 1229 { 1230 gtk_text_buffer_insert_pixbuf(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), (pixbuf is null) ? null : pixbuf.getPixbufStruct()); 1231 } 1232 1233 /** 1234 * Copies text, tags, and pixbufs between @start and @end (the order 1235 * of @start and @end doesn’t matter) and inserts the copy at @iter. 1236 * Used instead of simply getting/inserting text because it preserves 1237 * images and tags. If @start and @end are in a different buffer from 1238 * @buffer, the two buffers must share the same tag table. 1239 * 1240 * Implemented via emissions of the insert_text and apply_tag signals, 1241 * so expect those. 1242 * 1243 * Params: 1244 * iter = a position in @buffer 1245 * start = a position in a #GtkTextBuffer 1246 * end = another position in the same buffer as @start 1247 */ 1248 public void insertRange(TextIter iter, TextIter start, TextIter end) 1249 { 1250 gtk_text_buffer_insert_range(gtkTextBuffer, (iter is null) ? null : iter.getTextIterStruct(), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 1251 } 1252 1253 /** 1254 * Same as gtk_text_buffer_insert_range(), but does nothing if the 1255 * insertion point isn’t editable. The @default_editable parameter 1256 * indicates whether the text is editable at @iter if no tags 1257 * enclosing @iter affect editability. Typically the result of 1258 * gtk_text_view_get_editable() is appropriate here. 1259 * 1260 * Params: 1261 * iter = a position in @buffer 1262 * start = a position in a #GtkTextBuffer 1263 * end = another position in the same buffer as @start 1264 * defaultEditable = default editability of the buffer 1265 * 1266 * Returns: whether an insertion was possible at @iter 1267 */ 1268 public bool insertRangeInteractive(TextIter iter, TextIter start, TextIter end, bool defaultEditable) 1269 { 1270 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; 1271 } 1272 1273 /** 1274 * Moves @mark to the new location @where. Emits the #GtkTextBuffer::mark-set 1275 * signal as notification of the move. 1276 * 1277 * Params: 1278 * mark = a #GtkTextMark 1279 * where = new location for @mark in @buffer 1280 */ 1281 public void moveMark(TextMark mark, TextIter where) 1282 { 1283 gtk_text_buffer_move_mark(gtkTextBuffer, (mark is null) ? null : mark.getTextMarkStruct(), (where is null) ? null : where.getTextIterStruct()); 1284 } 1285 1286 /** 1287 * Moves the mark named @name (which must exist) to location @where. 1288 * See gtk_text_buffer_move_mark() for details. 1289 * 1290 * Params: 1291 * name = name of a mark 1292 * where = new location for mark 1293 */ 1294 public void moveMarkByName(string name, TextIter where) 1295 { 1296 gtk_text_buffer_move_mark_by_name(gtkTextBuffer, Str.toStringz(name), (where is null) ? null : where.getTextIterStruct()); 1297 } 1298 1299 /** 1300 * Pastes the contents of a clipboard. If @override_location is %NULL, the 1301 * pasted text will be inserted at the cursor position, or the buffer selection 1302 * will be replaced if the selection is non-empty. 1303 * 1304 * Note: pasting is asynchronous, that is, we’ll ask for the paste data and 1305 * return, and at some point later after the main loop runs, the paste data will 1306 * be inserted. 1307 * 1308 * Params: 1309 * clipboard = the #GtkClipboard to paste from 1310 * overrideLocation = location to insert pasted text, or %NULL 1311 * defaultEditable = whether the buffer is editable by default 1312 */ 1313 public void pasteClipboard(Clipboard clipboard, TextIter overrideLocation, bool defaultEditable) 1314 { 1315 gtk_text_buffer_paste_clipboard(gtkTextBuffer, (clipboard is null) ? null : clipboard.getClipboardStruct(), (overrideLocation is null) ? null : overrideLocation.getTextIterStruct(), defaultEditable); 1316 } 1317 1318 /** 1319 * This function moves the “insert” and “selection_bound” marks 1320 * simultaneously. If you move them to the same place in two steps 1321 * with gtk_text_buffer_move_mark(), you will temporarily select a 1322 * region in between their old and new locations, which can be pretty 1323 * inefficient since the temporarily-selected region will force stuff 1324 * to be recalculated. This function moves them as a unit, which can 1325 * be optimized. 1326 * 1327 * Params: 1328 * where = where to put the cursor 1329 */ 1330 public void placeCursor(TextIter where) 1331 { 1332 gtk_text_buffer_place_cursor(gtkTextBuffer, (where is null) ? null : where.getTextIterStruct()); 1333 } 1334 1335 /** 1336 * This function registers a rich text deserialization @function along with 1337 * its @mime_type with the passed @buffer. 1338 * 1339 * Params: 1340 * mimeType = the format’s mime-type 1341 * function_ = the deserialize function to register 1342 * userData = @function’s user_data 1343 * userDataDestroy = a function to call when @user_data is no longer needed 1344 * 1345 * Returns: the #GdkAtom that corresponds to the 1346 * newly registered format’s mime-type. 1347 * 1348 * Since: 2.10 1349 */ 1350 public GdkAtom registerDeserializeFormat(string mimeType, GtkTextBufferDeserializeFunc function_, void* userData, GDestroyNotify userDataDestroy) 1351 { 1352 return gtk_text_buffer_register_deserialize_format(gtkTextBuffer, Str.toStringz(mimeType), function_, userData, userDataDestroy); 1353 } 1354 1355 /** 1356 * This function registers GTK+’s internal rich text serialization 1357 * format with the passed @buffer. See 1358 * gtk_text_buffer_register_serialize_tagset() for details. 1359 * 1360 * Params: 1361 * tagsetName = an optional tagset name, on %NULL 1362 * 1363 * Returns: the #GdkAtom that corresponds to the 1364 * newly registered format’s mime-type. 1365 * 1366 * Since: 2.10 1367 */ 1368 public GdkAtom registerDeserializeTagset(string tagsetName) 1369 { 1370 return gtk_text_buffer_register_deserialize_tagset(gtkTextBuffer, Str.toStringz(tagsetName)); 1371 } 1372 1373 /** 1374 * This function registers a rich text serialization @function along with 1375 * its @mime_type with the passed @buffer. 1376 * 1377 * Params: 1378 * mimeType = the format’s mime-type 1379 * function_ = the serialize function to register 1380 * userData = @function’s user_data 1381 * userDataDestroy = a function to call when @user_data is no longer needed 1382 * 1383 * Returns: the #GdkAtom that corresponds to the 1384 * newly registered format’s mime-type. 1385 * 1386 * Since: 2.10 1387 */ 1388 public GdkAtom registerSerializeFormat(string mimeType, GtkTextBufferSerializeFunc function_, void* userData, GDestroyNotify userDataDestroy) 1389 { 1390 return gtk_text_buffer_register_serialize_format(gtkTextBuffer, Str.toStringz(mimeType), function_, userData, userDataDestroy); 1391 } 1392 1393 /** 1394 * This function registers GTK+’s internal rich text serialization 1395 * format with the passed @buffer. The internal format does not comply 1396 * to any standard rich text format and only works between #GtkTextBuffer 1397 * instances. It is capable of serializing all of a text buffer’s tags 1398 * and embedded pixbufs. 1399 * 1400 * This function is just a wrapper around 1401 * gtk_text_buffer_register_serialize_format(). The mime type used 1402 * for registering is “application/x-gtk-text-buffer-rich-text”, or 1403 * “application/x-gtk-text-buffer-rich-text;format=@tagset_name” if a 1404 * @tagset_name was passed. 1405 * 1406 * The @tagset_name can be used to restrict the transfer of rich text 1407 * to buffers with compatible sets of tags, in order to avoid unknown 1408 * tags from being pasted. It is probably the common case to pass an 1409 * identifier != %NULL here, since the %NULL tagset requires the 1410 * receiving buffer to deal with with pasting of arbitrary tags. 1411 * 1412 * Params: 1413 * tagsetName = an optional tagset name, on %NULL 1414 * 1415 * Returns: the #GdkAtom that corresponds to the 1416 * newly registered format’s mime-type. 1417 * 1418 * Since: 2.10 1419 */ 1420 public GdkAtom registerSerializeTagset(string tagsetName) 1421 { 1422 return gtk_text_buffer_register_serialize_tagset(gtkTextBuffer, Str.toStringz(tagsetName)); 1423 } 1424 1425 /** 1426 * Removes all tags in the range between @start and @end. Be careful 1427 * with this function; it could remove tags added in code unrelated to 1428 * the code you’re currently writing. That is, using this function is 1429 * probably a bad idea if you have two or more unrelated code sections 1430 * that add tags. 1431 * 1432 * Params: 1433 * start = one bound of range to be untagged 1434 * end = other bound of range to be untagged 1435 */ 1436 public void removeAllTags(TextIter start, TextIter end) 1437 { 1438 gtk_text_buffer_remove_all_tags(gtkTextBuffer, (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 1439 } 1440 1441 /** 1442 * Removes a #GtkClipboard added with 1443 * gtk_text_buffer_add_selection_clipboard(). 1444 * 1445 * Params: 1446 * clipboard = a #GtkClipboard added to @buffer by 1447 * gtk_text_buffer_add_selection_clipboard() 1448 */ 1449 public void removeSelectionClipboard(Clipboard clipboard) 1450 { 1451 gtk_text_buffer_remove_selection_clipboard(gtkTextBuffer, (clipboard is null) ? null : clipboard.getClipboardStruct()); 1452 } 1453 1454 /** 1455 * Emits the “remove-tag” signal. The default handler for the signal 1456 * removes all occurrences of @tag from the given range. @start and 1457 * @end don’t have to be in order. 1458 * 1459 * Params: 1460 * tag = a #GtkTextTag 1461 * start = one bound of range to be untagged 1462 * end = other bound of range to be untagged 1463 */ 1464 public void removeTag(TextTag tag, TextIter start, TextIter end) 1465 { 1466 gtk_text_buffer_remove_tag(gtkTextBuffer, (tag is null) ? null : tag.getTextTagStruct(), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 1467 } 1468 1469 /** 1470 * Calls gtk_text_tag_table_lookup() on the buffer’s tag table to 1471 * get a #GtkTextTag, then calls gtk_text_buffer_remove_tag(). 1472 * 1473 * Params: 1474 * name = name of a #GtkTextTag 1475 * start = one bound of range to be untagged 1476 * end = other bound of range to be untagged 1477 */ 1478 public void removeTagByName(string name, TextIter start, TextIter end) 1479 { 1480 gtk_text_buffer_remove_tag_by_name(gtkTextBuffer, Str.toStringz(name), (start is null) ? null : start.getTextIterStruct(), (end is null) ? null : end.getTextIterStruct()); 1481 } 1482 1483 /** 1484 * This function moves the “insert” and “selection_bound” marks 1485 * simultaneously. If you move them in two steps 1486 * with gtk_text_buffer_move_mark(), you will temporarily select a 1487 * region in between their old and new locations, which can be pretty 1488 * inefficient since the temporarily-selected region will force stuff 1489 * to be recalculated. This function moves them as a unit, which can 1490 * be optimized. 1491 * 1492 * Params: 1493 * ins = where to put the “insert” mark 1494 * bound = where to put the “selection_bound” mark 1495 * 1496 * Since: 2.4 1497 */ 1498 public void selectRange(TextIter ins, TextIter bound) 1499 { 1500 gtk_text_buffer_select_range(gtkTextBuffer, (ins is null) ? null : ins.getTextIterStruct(), (bound is null) ? null : bound.getTextIterStruct()); 1501 } 1502 1503 /** 1504 * This function serializes the portion of text between @start 1505 * and @end in the rich text format represented by @format. 1506 * 1507 * @formats to be used must be registered using 1508 * gtk_text_buffer_register_serialize_format() or 1509 * gtk_text_buffer_register_serialize_tagset() beforehand. 1510 * 1511 * Params: 1512 * contentBuffer = the #GtkTextBuffer to serialize 1513 * format = the rich text format to use for serializing 1514 * start = start of block of text to serialize 1515 * end = end of block of test to serialize 1516 * 1517 * Returns: the serialized 1518 * data, encoded as @format 1519 * 1520 * Since: 2.10 1521 */ 1522 public ubyte[] serialize(TextBuffer contentBuffer, GdkAtom format, TextIter start, TextIter end) 1523 { 1524 size_t length; 1525 1526 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); 1527 1528 return p[0 .. length]; 1529 } 1530 1531 /** 1532 * Used to keep track of whether the buffer has been modified since the 1533 * last time it was saved. Whenever the buffer is saved to disk, call 1534 * gtk_text_buffer_set_modified (@buffer, FALSE). When the buffer is modified, 1535 * it will automatically toggled on the modified bit again. When the modified 1536 * bit flips, the buffer emits the #GtkTextBuffer::modified-changed signal. 1537 * 1538 * Params: 1539 * setting = modification flag setting 1540 */ 1541 public void setModified(bool setting) 1542 { 1543 gtk_text_buffer_set_modified(gtkTextBuffer, setting); 1544 } 1545 1546 /** 1547 * Deletes current contents of @buffer, and inserts @text instead. If 1548 * @len is -1, @text must be nul-terminated. @text must be valid UTF-8. 1549 * 1550 * Params: 1551 * text = UTF-8 text to insert 1552 */ 1553 public void setText(string text) 1554 { 1555 gtk_text_buffer_set_text(gtkTextBuffer, Str.toStringz(text), cast(int)text.length); 1556 } 1557 1558 /** 1559 * This function unregisters a rich text format that was previously 1560 * registered using gtk_text_buffer_register_deserialize_format() or 1561 * gtk_text_buffer_register_deserialize_tagset(). 1562 * 1563 * Params: 1564 * format = a #GdkAtom representing a registered rich text format. 1565 * 1566 * Since: 2.10 1567 */ 1568 public void unregisterDeserializeFormat(GdkAtom format) 1569 { 1570 gtk_text_buffer_unregister_deserialize_format(gtkTextBuffer, format); 1571 } 1572 1573 /** 1574 * This function unregisters a rich text format that was previously 1575 * registered using gtk_text_buffer_register_serialize_format() or 1576 * gtk_text_buffer_register_serialize_tagset() 1577 * 1578 * Params: 1579 * format = a #GdkAtom representing a registered rich text format. 1580 * 1581 * Since: 2.10 1582 */ 1583 public void unregisterSerializeFormat(GdkAtom format) 1584 { 1585 gtk_text_buffer_unregister_serialize_format(gtkTextBuffer, format); 1586 } 1587 1588 /** 1589 * The ::apply-tag signal is emitted to apply a tag to a 1590 * range of text in a #GtkTextBuffer. 1591 * Applying actually occurs in the default handler. 1592 * 1593 * Note that if your handler runs before the default handler it must not 1594 * invalidate the @start and @end iters (or has to revalidate them). 1595 * 1596 * See also: 1597 * gtk_text_buffer_apply_tag(), 1598 * gtk_text_buffer_insert_with_tags(), 1599 * gtk_text_buffer_insert_range(). 1600 * 1601 * Params: 1602 * tag = the applied tag 1603 * start = the start of the range the tag is applied to 1604 * end = the end of the range the tag is applied to 1605 */ 1606 gulong addOnApplyTag(void delegate(TextTag, TextIter, TextIter, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1607 { 1608 return Signals.connect(this, "apply-tag", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1609 } 1610 1611 /** 1612 * The ::begin-user-action signal is emitted at the beginning of a single 1613 * user-visible operation on a #GtkTextBuffer. 1614 * 1615 * See also: 1616 * gtk_text_buffer_begin_user_action(), 1617 * gtk_text_buffer_insert_interactive(), 1618 * gtk_text_buffer_insert_range_interactive(), 1619 * gtk_text_buffer_delete_interactive(), 1620 * gtk_text_buffer_backspace(), 1621 * gtk_text_buffer_delete_selection(). 1622 */ 1623 gulong addOnBeginUserAction(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1624 { 1625 return Signals.connect(this, "begin-user-action", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1626 } 1627 1628 /** 1629 * The ::changed signal is emitted when the content of a #GtkTextBuffer 1630 * has changed. 1631 */ 1632 gulong addOnChanged(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1633 { 1634 return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1635 } 1636 1637 /** 1638 * The ::delete-range signal is emitted to delete a range 1639 * from a #GtkTextBuffer. 1640 * 1641 * Note that if your handler runs before the default handler it must not 1642 * invalidate the @start and @end iters (or has to revalidate them). 1643 * The default signal handler revalidates the @start and @end iters to 1644 * both point to the location where text was deleted. Handlers 1645 * which run after the default handler (see g_signal_connect_after()) 1646 * do not have access to the deleted text. 1647 * 1648 * See also: gtk_text_buffer_delete(). 1649 * 1650 * Params: 1651 * start = the start of the range to be deleted 1652 * end = the end of the range to be deleted 1653 */ 1654 gulong addOnDeleteRange(void delegate(TextIter, TextIter, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1655 { 1656 return Signals.connect(this, "delete-range", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1657 } 1658 1659 /** 1660 * The ::end-user-action signal is emitted at the end of a single 1661 * user-visible operation on the #GtkTextBuffer. 1662 * 1663 * See also: 1664 * gtk_text_buffer_end_user_action(), 1665 * gtk_text_buffer_insert_interactive(), 1666 * gtk_text_buffer_insert_range_interactive(), 1667 * gtk_text_buffer_delete_interactive(), 1668 * gtk_text_buffer_backspace(), 1669 * gtk_text_buffer_delete_selection(), 1670 * gtk_text_buffer_backspace(). 1671 */ 1672 gulong addOnEndUserAction(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1673 { 1674 return Signals.connect(this, "end-user-action", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1675 } 1676 1677 /** 1678 * The ::insert-child-anchor signal is emitted to insert a 1679 * #GtkTextChildAnchor in a #GtkTextBuffer. 1680 * Insertion actually occurs in the default handler. 1681 * 1682 * Note that if your handler runs before the default handler it must 1683 * not invalidate the @location iter (or has to revalidate it). 1684 * The default signal handler revalidates it to be placed after the 1685 * inserted @anchor. 1686 * 1687 * See also: gtk_text_buffer_insert_child_anchor(). 1688 * 1689 * Params: 1690 * location = position to insert @anchor in @textbuffer 1691 * anchor = the #GtkTextChildAnchor to be inserted 1692 */ 1693 gulong addOnInsertChildAnchor(void delegate(TextIter, TextChildAnchor, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1694 { 1695 return Signals.connect(this, "insert-child-anchor", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1696 } 1697 1698 /** 1699 * The ::insert-pixbuf signal is emitted to insert a #GdkPixbuf 1700 * in a #GtkTextBuffer. Insertion actually occurs in the default handler. 1701 * 1702 * Note that if your handler runs before the default handler it must not 1703 * invalidate the @location iter (or has to revalidate it). 1704 * The default signal handler revalidates it to be placed after the 1705 * inserted @pixbuf. 1706 * 1707 * See also: gtk_text_buffer_insert_pixbuf(). 1708 * 1709 * Params: 1710 * location = position to insert @pixbuf in @textbuffer 1711 * pixbuf = the #GdkPixbuf to be inserted 1712 */ 1713 gulong addOnInsertPixbuf(void delegate(TextIter, Pixbuf, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1714 { 1715 return Signals.connect(this, "insert-pixbuf", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1716 } 1717 1718 /** 1719 * The ::insert-text signal is emitted to insert text in a #GtkTextBuffer. 1720 * Insertion actually occurs in the default handler. 1721 * 1722 * Note that if your handler runs before the default handler it must not 1723 * invalidate the @location iter (or has to revalidate it). 1724 * The default signal handler revalidates it to point to the end of the 1725 * inserted text. 1726 * 1727 * See also: 1728 * gtk_text_buffer_insert(), 1729 * gtk_text_buffer_insert_range(). 1730 * 1731 * Params: 1732 * location = position to insert @text in @textbuffer 1733 * text = the UTF-8 text to be inserted 1734 * len = length of the inserted text in bytes 1735 */ 1736 gulong addOnInsertText(void delegate(TextIter, string, int, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1737 { 1738 return Signals.connect(this, "insert-text", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1739 } 1740 1741 /** 1742 * The ::mark-deleted signal is emitted as notification 1743 * after a #GtkTextMark is deleted. 1744 * 1745 * See also: 1746 * gtk_text_buffer_delete_mark(). 1747 * 1748 * Params: 1749 * mark = The mark that was deleted 1750 */ 1751 gulong addOnMarkDeleted(void delegate(TextMark, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1752 { 1753 return Signals.connect(this, "mark-deleted", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1754 } 1755 1756 /** 1757 * The ::mark-set signal is emitted as notification 1758 * after a #GtkTextMark is set. 1759 * 1760 * See also: 1761 * gtk_text_buffer_create_mark(), 1762 * gtk_text_buffer_move_mark(). 1763 * 1764 * Params: 1765 * location = The location of @mark in @textbuffer 1766 * mark = The mark that is set 1767 */ 1768 gulong addOnMarkSet(void delegate(TextIter, TextMark, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1769 { 1770 return Signals.connect(this, "mark-set", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1771 } 1772 1773 /** 1774 * The ::modified-changed signal is emitted when the modified bit of a 1775 * #GtkTextBuffer flips. 1776 * 1777 * See also: 1778 * gtk_text_buffer_set_modified(). 1779 */ 1780 gulong addOnModifiedChanged(void delegate(TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1781 { 1782 return Signals.connect(this, "modified-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1783 } 1784 1785 /** 1786 * The paste-done signal is emitted after paste operation has been completed. 1787 * This is useful to properly scroll the view to the end of the pasted text. 1788 * See gtk_text_buffer_paste_clipboard() for more details. 1789 * 1790 * Params: 1791 * clipboard = the #GtkClipboard pasted from 1792 * 1793 * Since: 2.16 1794 */ 1795 gulong addOnPasteDone(void delegate(Clipboard, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1796 { 1797 return Signals.connect(this, "paste-done", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1798 } 1799 1800 /** 1801 * The ::remove-tag signal is emitted to remove all occurrences of @tag from 1802 * a range of text in a #GtkTextBuffer. 1803 * Removal actually occurs in the default handler. 1804 * 1805 * Note that if your handler runs before the default handler it must not 1806 * invalidate the @start and @end iters (or has to revalidate them). 1807 * 1808 * See also: 1809 * gtk_text_buffer_remove_tag(). 1810 * 1811 * Params: 1812 * tag = the tag to be removed 1813 * start = the start of the range the tag is removed from 1814 * end = the end of the range the tag is removed from 1815 */ 1816 gulong addOnRemoveTag(void delegate(TextTag, TextIter, TextIter, TextBuffer) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1817 { 1818 return Signals.connect(this, "remove-tag", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1819 } 1820 }