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