1 /* GTK - The GIMP Toolkit
2 * gtktextbuffer.c Copyright (C) 2000 Red Hat, Inc.
3 * Copyright (C) 2004 Nokia Corporation
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
33 #include "gtkclipboard.h"
35 #include "gtkinvisible.h"
36 #include "gtkmarshalers.h"
37 #include "gtktextbuffer.h"
38 #include "gtktextbufferrichtext.h"
39 #include "gtktextbtree.h"
40 #include "gtktextiterprivate.h"
41 #include "gtkprivate.h"
46 #define GTK_TEXT_BUFFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferPrivate))
48 typedef struct _GtkTextBufferPrivate GtkTextBufferPrivate;
50 struct _GtkTextBufferPrivate
52 GtkTargetList *copy_target_list;
53 GtkTargetEntry *copy_target_entries;
54 gint n_copy_target_entries;
56 GtkTargetList *paste_target_list;
57 GtkTargetEntry *paste_target_entries;
58 gint n_paste_target_entries;
62 typedef struct _ClipboardRequest ClipboardRequest;
64 struct _ClipboardRequest
66 GtkTextBuffer *buffer;
68 gboolean default_editable;
69 gboolean is_clipboard;
70 gboolean replace_selection;
100 PROP_COPY_TARGET_LIST,
101 PROP_PASTE_TARGET_LIST
104 static void gtk_text_buffer_finalize (GObject *object);
106 static void gtk_text_buffer_real_insert_text (GtkTextBuffer *buffer,
110 static void gtk_text_buffer_real_insert_pixbuf (GtkTextBuffer *buffer,
113 static void gtk_text_buffer_real_insert_anchor (GtkTextBuffer *buffer,
115 GtkTextChildAnchor *anchor);
116 static void gtk_text_buffer_real_delete_range (GtkTextBuffer *buffer,
119 static void gtk_text_buffer_real_apply_tag (GtkTextBuffer *buffer,
121 const GtkTextIter *start_char,
122 const GtkTextIter *end_char);
123 static void gtk_text_buffer_real_remove_tag (GtkTextBuffer *buffer,
125 const GtkTextIter *start_char,
126 const GtkTextIter *end_char);
127 static void gtk_text_buffer_real_changed (GtkTextBuffer *buffer);
128 static void gtk_text_buffer_real_mark_set (GtkTextBuffer *buffer,
129 const GtkTextIter *iter,
132 static GtkTextBTree* get_btree (GtkTextBuffer *buffer);
133 static void free_log_attr_cache (GtkTextLogAttrCache *cache);
135 static void remove_all_selection_clipboards (GtkTextBuffer *buffer);
136 static void update_selection_clipboards (GtkTextBuffer *buffer);
138 static GtkTextBuffer *create_clipboard_contents_buffer (GtkTextBuffer *buffer);
140 static void gtk_text_buffer_free_target_lists (GtkTextBuffer *buffer);
142 static guint signals[LAST_SIGNAL] = { 0 };
144 static void gtk_text_buffer_set_property (GObject *object,
148 static void gtk_text_buffer_get_property (GObject *object,
152 static void gtk_text_buffer_notify (GObject *object,
155 G_DEFINE_TYPE (GtkTextBuffer, gtk_text_buffer, G_TYPE_OBJECT)
158 gtk_text_buffer_class_init (GtkTextBufferClass *klass)
160 GObjectClass *object_class = G_OBJECT_CLASS (klass);
162 object_class->finalize = gtk_text_buffer_finalize;
163 object_class->set_property = gtk_text_buffer_set_property;
164 object_class->get_property = gtk_text_buffer_get_property;
165 object_class->notify = gtk_text_buffer_notify;
167 klass->insert_text = gtk_text_buffer_real_insert_text;
168 klass->insert_pixbuf = gtk_text_buffer_real_insert_pixbuf;
169 klass->insert_child_anchor = gtk_text_buffer_real_insert_anchor;
170 klass->delete_range = gtk_text_buffer_real_delete_range;
171 klass->apply_tag = gtk_text_buffer_real_apply_tag;
172 klass->remove_tag = gtk_text_buffer_real_remove_tag;
173 klass->changed = gtk_text_buffer_real_changed;
174 klass->mark_set = gtk_text_buffer_real_mark_set;
177 g_object_class_install_property (object_class,
179 g_param_spec_object ("tag-table",
181 P_("Text Tag Table"),
182 GTK_TYPE_TEXT_TAG_TABLE,
183 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
185 /* Normal properties*/
188 * GtkTextBuffer:text:
190 * The text content of the buffer. Without child widgets and images,
191 * see gtk_text_buffer_get_text() for more information.
195 g_object_class_install_property (object_class,
197 g_param_spec_string ("text",
199 P_("Current text of the buffer"),
201 GTK_PARAM_READWRITE));
204 * GtkTextBuffer:has-selection:
206 * Whether the buffer has some text currently selected.
210 g_object_class_install_property (object_class,
212 g_param_spec_boolean ("has-selection",
214 P_("Whether the buffer has some text currently selected"),
216 GTK_PARAM_READABLE));
219 * GtkTextBuffer:cursor-position:
221 * The position of the insert mark (as offset from the beginning
222 * of the buffer). It is useful for getting notified when the
227 g_object_class_install_property (object_class,
228 PROP_CURSOR_POSITION,
229 g_param_spec_int ("cursor-position",
230 P_("Cursor position"),
231 P_("The position of the insert mark (as offset from the beginning of the buffer)"),
233 GTK_PARAM_READABLE));
236 * GtkTextBuffer:copy-target-list:
238 * The list of targets this buffer supports for clipboard copying
243 g_object_class_install_property (object_class,
244 PROP_COPY_TARGET_LIST,
245 g_param_spec_boxed ("copy-target-list",
246 P_("Copy target list"),
247 P_("The list of targets this buffer supports for clipboard copying and DND source"),
248 GTK_TYPE_TARGET_LIST,
249 GTK_PARAM_READABLE));
252 * GtkTextBuffer:paste-target-list:
254 * The list of targets this buffer supports for clipboard pasting
255 * and as DND destination.
259 g_object_class_install_property (object_class,
260 PROP_PASTE_TARGET_LIST,
261 g_param_spec_boxed ("paste-target-list",
262 P_("Paste target list"),
263 P_("The list of targets this buffer supports for clipboard pasting and DND destination"),
264 GTK_TYPE_TARGET_LIST,
265 GTK_PARAM_READABLE));
268 * GtkTextBuffer::insert-text:
269 * @textbuffer: the object which received the signal
270 * @location: position to insert @text in @textbuffer
271 * @text: the UTF-8 text to be inserted
272 * @len: length of the inserted text in bytes
274 * The ::insert-text signal is emitted to insert text in a #GtkTextBuffer.
275 * Insertion actually occurs in the default handler.
277 * Note that if your handler runs before the default handler it must not
278 * invalidate the @location iter (or has to revalidate it).
279 * The default signal handler revalidates it to point to the end of the
283 * gtk_text_buffer_insert(),
284 * gtk_text_buffer_insert_range().
286 signals[INSERT_TEXT] =
287 g_signal_new (I_("insert-text"),
288 G_OBJECT_CLASS_TYPE (object_class),
290 G_STRUCT_OFFSET (GtkTextBufferClass, insert_text),
292 _gtk_marshal_VOID__BOXED_STRING_INT,
295 GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE,
296 G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
300 * GtkTextBuffer::insert-pixbuf:
301 * @textbuffer: the object which received the signal
302 * @location: position to insert @pixbuf in @textbuffer
303 * @pixbuf: the #GdkPixbuf to be inserted
305 * The ::insert-pixbuf signal is emitted to insert a #GdkPixbuf
306 * in a #GtkTextBuffer. Insertion actually occurs in the default handler.
308 * Note that if your handler runs before the default handler it must not
309 * invalidate the @location iter (or has to revalidate it).
310 * The default signal handler revalidates it to be placed after the
313 * See also: gtk_text_buffer_insert_pixbuf().
315 signals[INSERT_PIXBUF] =
316 g_signal_new (I_("insert-pixbuf"),
317 G_OBJECT_CLASS_TYPE (object_class),
319 G_STRUCT_OFFSET (GtkTextBufferClass, insert_pixbuf),
321 _gtk_marshal_VOID__BOXED_OBJECT,
324 GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE,
329 * GtkTextBuffer::insert-child-anchor:
330 * @textbuffer: the object which received the signal
331 * @location: position to insert @anchor in @textbuffer
332 * @anchor: the #GtkTextChildAnchor to be inserted
334 * The ::insert-child-anchor signal is emitted to insert a
335 * #GtkTextChildAnchor in a #GtkTextBuffer.
336 * Insertion actually occurs in the default handler.
338 * Note that if your handler runs before the default handler it must
339 * not invalidate the @location iter (or has to revalidate it).
340 * The default signal handler revalidates it to be placed after the
343 * See also: gtk_text_buffer_insert_child_anchor().
345 signals[INSERT_CHILD_ANCHOR] =
346 g_signal_new (I_("insert-child-anchor"),
347 G_OBJECT_CLASS_TYPE (object_class),
349 G_STRUCT_OFFSET (GtkTextBufferClass, insert_child_anchor),
351 _gtk_marshal_VOID__BOXED_OBJECT,
354 GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE,
355 GTK_TYPE_TEXT_CHILD_ANCHOR);
358 * GtkTextBuffer::delete-range:
359 * @textbuffer: the object which received the signal
360 * @start: the start of the range to be deleted
361 * @end: the end of the range to be deleted
363 * The ::delete-range signal is emitted to delete a range
364 * from a #GtkTextBuffer.
366 * Note that if your handler runs before the default handler it must not
367 * invalidate the @start and @end iters (or has to revalidate them).
368 * The default signal handler revalidates the @start and @end iters to
369 * both point point to the location where text was deleted. Handlers
370 * which run after the default handler (see g_signal_connect_after())
371 * do not have access to the deleted text.
373 * See also: gtk_text_buffer_delete().
375 signals[DELETE_RANGE] =
376 g_signal_new (I_("delete-range"),
377 G_OBJECT_CLASS_TYPE (object_class),
379 G_STRUCT_OFFSET (GtkTextBufferClass, delete_range),
381 _gtk_marshal_VOID__BOXED_BOXED,
384 GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE,
385 GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE);
388 * GtkTextBuffer::changed:
389 * @textbuffer: the object which received the signal
391 * The ::changed signal is emitted when the content of a #GtkTextBuffer
395 g_signal_new (I_("changed"),
396 G_OBJECT_CLASS_TYPE (object_class),
398 G_STRUCT_OFFSET (GtkTextBufferClass, changed),
400 _gtk_marshal_VOID__VOID,
405 * GtkTextBuffer::modified-changed:
406 * @textbuffer: the object which received the signal
408 * The ::modified-changed signal is emitted when the modified bit of a
409 * #GtkTextBuffer flips.
412 * gtk_text_buffer_set_modified().
414 signals[MODIFIED_CHANGED] =
415 g_signal_new (I_("modified-changed"),
416 G_OBJECT_CLASS_TYPE (object_class),
418 G_STRUCT_OFFSET (GtkTextBufferClass, modified_changed),
420 _gtk_marshal_VOID__VOID,
425 * GtkTextBuffer::mark-set:
426 * @textbuffer: the object which received the signal
427 * @location: The location of @mark in @textbuffer
428 * @mark: The mark that is set
430 * The ::mark-set signal is emitted as notification
431 * after a #GtkTextMark is set.
434 * gtk_text_buffer_create_mark(),
435 * gtk_text_buffer_move_mark().
438 g_signal_new (I_("mark-set"),
439 G_OBJECT_CLASS_TYPE (object_class),
441 G_STRUCT_OFFSET (GtkTextBufferClass, mark_set),
443 _gtk_marshal_VOID__BOXED_OBJECT,
450 * GtkTextBuffer::mark-deleted:
451 * @textbuffer: the object which received the signal
452 * @mark: The mark that was deleted
454 * The ::mark-deleted signal is emitted as notification
455 * after a #GtkTextMark is deleted.
458 * gtk_text_buffer_delete_mark().
460 signals[MARK_DELETED] =
461 g_signal_new (I_("mark-deleted"),
462 G_OBJECT_CLASS_TYPE (object_class),
464 G_STRUCT_OFFSET (GtkTextBufferClass, mark_deleted),
466 _gtk_marshal_VOID__OBJECT,
472 * GtkTextBuffer::apply-tag:
473 * @textbuffer: the object which received the signal
474 * @tag: the applied tag
475 * @start: the start of the range the tag is applied to
476 * @end: the end of the range the tag is applied to
478 * The ::apply-tag signal is emitted to apply a tag to a
479 * range of text in a #GtkTextBuffer.
480 * Applying actually occurs in the default handler.
482 * Note that if your handler runs before the default handler it must not
483 * invalidate the @start and @end iters (or has to revalidate them).
486 * gtk_text_buffer_apply_tag(),
487 * gtk_text_buffer_insert_with_tags(),
488 * gtk_text_buffer_insert_range().
491 g_signal_new (I_("apply-tag"),
492 G_OBJECT_CLASS_TYPE (object_class),
494 G_STRUCT_OFFSET (GtkTextBufferClass, apply_tag),
496 _gtk_marshal_VOID__OBJECT_BOXED_BOXED,
505 * GtkTextBuffer::remove-tag:
506 * @textbuffer: the object which received the signal
507 * @tag: the tag to be removed
508 * @start: the start of the range the tag is removed from
509 * @end: the end of the range the tag is removed from
511 * The ::remove-tag signal is emitted to remove all occurrences of @tag from
512 * a range of text in a #GtkTextBuffer.
513 * Removal actually occurs in the default handler.
515 * Note that if your handler runs before the default handler it must not
516 * invalidate the @start and @end iters (or has to revalidate them).
519 * gtk_text_buffer_remove_tag().
521 signals[REMOVE_TAG] =
522 g_signal_new (I_("remove-tag"),
523 G_OBJECT_CLASS_TYPE (object_class),
525 G_STRUCT_OFFSET (GtkTextBufferClass, remove_tag),
527 _gtk_marshal_VOID__OBJECT_BOXED_BOXED,
535 * GtkTextBuffer::begin-user-action:
536 * @textbuffer: the object which received the signal
538 * The ::begin-user-action signal is emitted at the beginning of a single
539 * user-visible operation on a #GtkTextBuffer.
542 * gtk_text_buffer_begin_user_action(),
543 * gtk_text_buffer_insert_interactive(),
544 * gtk_text_buffer_insert_range_interactive(),
545 * gtk_text_buffer_delete_interactive(),
546 * gtk_text_buffer_backspace(),
547 * gtk_text_buffer_delete_selection().
549 signals[BEGIN_USER_ACTION] =
550 g_signal_new (I_("begin-user-action"),
551 G_OBJECT_CLASS_TYPE (object_class),
553 G_STRUCT_OFFSET (GtkTextBufferClass, begin_user_action),
555 _gtk_marshal_VOID__VOID,
560 * GtkTextBuffer::end-user-action:
561 * @textbuffer: the object which received the signal
563 * The ::end-user-action signal is emitted at the end of a single
564 * user-visible operation on the #GtkTextBuffer.
567 * gtk_text_buffer_end_user_action(),
568 * gtk_text_buffer_insert_interactive(),
569 * gtk_text_buffer_insert_range_interactive(),
570 * gtk_text_buffer_delete_interactive(),
571 * gtk_text_buffer_backspace(),
572 * gtk_text_buffer_delete_selection(),
573 * gtk_text_buffer_backspace().
575 signals[END_USER_ACTION] =
576 g_signal_new (I_("end-user-action"),
577 G_OBJECT_CLASS_TYPE (object_class),
579 G_STRUCT_OFFSET (GtkTextBufferClass, end_user_action),
581 _gtk_marshal_VOID__VOID,
586 * GtkTextBuffer::paste-done:
587 * @textbuffer: the object which received the signal
589 * The paste-done signal is emitted after paste operation has been completed.
590 * This is useful to properly scroll the view to the end of the pasted text.
591 * See gtk_text_buffer_paste_clipboard() for more details.
595 signals[PASTE_DONE] =
596 g_signal_new (I_("paste-done"),
597 G_OBJECT_CLASS_TYPE (object_class),
599 G_STRUCT_OFFSET (GtkTextBufferClass, paste_done),
601 _gtk_marshal_VOID__OBJECT,
606 g_type_class_add_private (object_class, sizeof (GtkTextBufferPrivate));
610 gtk_text_buffer_init (GtkTextBuffer *buffer)
612 buffer->clipboard_contents_buffers = NULL;
613 buffer->tag_table = NULL;
615 /* allow copying of arbiatray stuff in the internal rich text format */
616 gtk_text_buffer_register_serialize_tagset (buffer, NULL);
620 set_table (GtkTextBuffer *buffer, GtkTextTagTable *table)
622 g_return_if_fail (buffer->tag_table == NULL);
626 buffer->tag_table = table;
627 g_object_ref (buffer->tag_table);
628 _gtk_text_tag_table_add_buffer (table, buffer);
632 static GtkTextTagTable*
633 get_table (GtkTextBuffer *buffer)
635 if (buffer->tag_table == NULL)
637 buffer->tag_table = gtk_text_tag_table_new ();
638 _gtk_text_tag_table_add_buffer (buffer->tag_table, buffer);
641 return buffer->tag_table;
645 gtk_text_buffer_set_property (GObject *object,
650 GtkTextBuffer *text_buffer;
652 text_buffer = GTK_TEXT_BUFFER (object);
657 set_table (text_buffer, g_value_get_object (value));
661 gtk_text_buffer_set_text (text_buffer,
662 g_value_get_string (value), -1);
666 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
672 gtk_text_buffer_get_property (GObject *object,
677 GtkTextBuffer *text_buffer;
680 text_buffer = GTK_TEXT_BUFFER (object);
685 g_value_set_object (value, get_table (text_buffer));
690 GtkTextIter start, end;
692 gtk_text_buffer_get_start_iter (text_buffer, &start);
693 gtk_text_buffer_get_end_iter (text_buffer, &end);
695 g_value_take_string (value,
696 gtk_text_buffer_get_text (text_buffer,
697 &start, &end, FALSE));
701 case PROP_HAS_SELECTION:
702 g_value_set_boolean (value, text_buffer->has_selection);
705 case PROP_CURSOR_POSITION:
706 gtk_text_buffer_get_iter_at_mark (text_buffer, &iter,
707 gtk_text_buffer_get_insert (text_buffer));
708 g_value_set_int (value, gtk_text_iter_get_offset (&iter));
711 case PROP_COPY_TARGET_LIST:
712 g_value_set_boxed (value, gtk_text_buffer_get_copy_target_list (text_buffer));
715 case PROP_PASTE_TARGET_LIST:
716 g_value_set_boxed (value, gtk_text_buffer_get_paste_target_list (text_buffer));
720 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
726 gtk_text_buffer_notify (GObject *object,
729 if (!strcmp (pspec->name, "copy-target-list") ||
730 !strcmp (pspec->name, "paste-target-list"))
732 gtk_text_buffer_free_target_lists (GTK_TEXT_BUFFER (object));
737 * gtk_text_buffer_new:
738 * @table: (allow-none): a tag table, or %NULL to create a new one
740 * Creates a new text buffer.
742 * Return value: a new text buffer
745 gtk_text_buffer_new (GtkTextTagTable *table)
747 GtkTextBuffer *text_buffer;
749 text_buffer = g_object_new (GTK_TYPE_TEXT_BUFFER, "tag-table", table, NULL);
755 gtk_text_buffer_finalize (GObject *object)
757 GtkTextBuffer *buffer;
759 buffer = GTK_TEXT_BUFFER (object);
761 remove_all_selection_clipboards (buffer);
763 if (buffer->tag_table)
765 _gtk_text_tag_table_remove_buffer (buffer->tag_table, buffer);
766 g_object_unref (buffer->tag_table);
767 buffer->tag_table = NULL;
772 _gtk_text_btree_unref (buffer->btree);
773 buffer->btree = NULL;
776 if (buffer->log_attr_cache)
777 free_log_attr_cache (buffer->log_attr_cache);
779 buffer->log_attr_cache = NULL;
781 gtk_text_buffer_free_target_lists (buffer);
783 G_OBJECT_CLASS (gtk_text_buffer_parent_class)->finalize (object);
787 get_btree (GtkTextBuffer *buffer)
789 if (buffer->btree == NULL)
790 buffer->btree = _gtk_text_btree_new (gtk_text_buffer_get_tag_table (buffer),
793 return buffer->btree;
797 _gtk_text_buffer_get_btree (GtkTextBuffer *buffer)
799 return get_btree (buffer);
803 * gtk_text_buffer_get_tag_table:
804 * @buffer: a #GtkTextBuffer
806 * Get the #GtkTextTagTable associated with this buffer.
808 * Return value: (transfer none): the buffer's tag table
811 gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer)
813 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
815 return get_table (buffer);
819 * gtk_text_buffer_set_text:
820 * @buffer: a #GtkTextBuffer
821 * @text: UTF-8 text to insert
822 * @len: length of @text in bytes
824 * Deletes current contents of @buffer, and inserts @text instead. If
825 * @len is -1, @text must be nul-terminated. @text must be valid UTF-8.
828 gtk_text_buffer_set_text (GtkTextBuffer *buffer,
832 GtkTextIter start, end;
834 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
835 g_return_if_fail (text != NULL);
840 gtk_text_buffer_get_bounds (buffer, &start, &end);
842 gtk_text_buffer_delete (buffer, &start, &end);
846 gtk_text_buffer_get_iter_at_offset (buffer, &start, 0);
847 gtk_text_buffer_insert (buffer, &start, text, len);
850 g_object_notify (G_OBJECT (buffer), "text");
860 gtk_text_buffer_real_insert_text (GtkTextBuffer *buffer,
865 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
866 g_return_if_fail (iter != NULL);
868 _gtk_text_btree_insert (iter, text, len);
870 g_signal_emit (buffer, signals[CHANGED], 0);
871 g_object_notify (G_OBJECT (buffer), "cursor-position");
875 gtk_text_buffer_emit_insert (GtkTextBuffer *buffer,
880 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
881 g_return_if_fail (iter != NULL);
882 g_return_if_fail (text != NULL);
887 g_return_if_fail (g_utf8_validate (text, len, NULL));
891 g_signal_emit (buffer, signals[INSERT_TEXT], 0,
897 * gtk_text_buffer_insert:
898 * @buffer: a #GtkTextBuffer
899 * @iter: a position in the buffer
900 * @text: UTF-8 format text to insert
901 * @len: length of text in bytes, or -1
903 * Inserts @len bytes of @text at position @iter. If @len is -1,
904 * @text must be nul-terminated and will be inserted in its
905 * entirety. Emits the "insert-text" signal; insertion actually occurs
906 * in the default handler for the signal. @iter is invalidated when
907 * insertion occurs (because the buffer contents change), but the
908 * default signal handler revalidates it to point to the end of the
912 gtk_text_buffer_insert (GtkTextBuffer *buffer,
917 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
918 g_return_if_fail (iter != NULL);
919 g_return_if_fail (text != NULL);
920 g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer);
922 gtk_text_buffer_emit_insert (buffer, iter, text, len);
926 * gtk_text_buffer_insert_at_cursor:
927 * @buffer: a #GtkTextBuffer
928 * @text: some text in UTF-8 format
929 * @len: length of text, in bytes
931 * Simply calls gtk_text_buffer_insert(), using the current
932 * cursor position as the insertion point.
935 gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer,
941 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
942 g_return_if_fail (text != NULL);
944 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
945 gtk_text_buffer_get_insert (buffer));
947 gtk_text_buffer_insert (buffer, &iter, text, len);
951 * gtk_text_buffer_insert_interactive:
952 * @buffer: a #GtkTextBuffer
953 * @iter: a position in @buffer
954 * @text: some UTF-8 text
955 * @len: length of text in bytes, or -1
956 * @default_editable: default editability of buffer
958 * Like gtk_text_buffer_insert(), but the insertion will not occur if
959 * @iter is at a non-editable location in the buffer. Usually you
960 * want to prevent insertions at ineditable locations if the insertion
961 * results from a user action (is interactive).
963 * @default_editable indicates the editability of text that doesn't
964 * have a tag affecting editability applied to it. Typically the
965 * result of gtk_text_view_get_editable() is appropriate here.
967 * Return value: whether text was actually inserted
970 gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer,
974 gboolean default_editable)
976 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
977 g_return_val_if_fail (text != NULL, FALSE);
978 g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == buffer, FALSE);
980 if (gtk_text_iter_can_insert (iter, default_editable))
982 gtk_text_buffer_begin_user_action (buffer);
983 gtk_text_buffer_emit_insert (buffer, iter, text, len);
984 gtk_text_buffer_end_user_action (buffer);
992 * gtk_text_buffer_insert_interactive_at_cursor:
993 * @buffer: a #GtkTextBuffer
994 * @text: text in UTF-8 format
995 * @len: length of text in bytes, or -1
996 * @default_editable: default editability of buffer
998 * Calls gtk_text_buffer_insert_interactive() at the cursor
1001 * @default_editable indicates the editability of text that doesn't
1002 * have a tag affecting editability applied to it. Typically the
1003 * result of gtk_text_view_get_editable() is appropriate here.
1005 * Return value: whether text was actually inserted
1008 gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
1011 gboolean default_editable)
1015 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
1016 g_return_val_if_fail (text != NULL, FALSE);
1018 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
1019 gtk_text_buffer_get_insert (buffer));
1021 return gtk_text_buffer_insert_interactive (buffer, &iter, text, len,
1026 possibly_not_text (gunichar ch,
1029 return ch == GTK_TEXT_UNKNOWN_CHAR;
1033 insert_text_range (GtkTextBuffer *buffer,
1035 const GtkTextIter *orig_start,
1036 const GtkTextIter *orig_end,
1037 gboolean interactive)
1041 text = gtk_text_iter_get_text (orig_start, orig_end);
1043 gtk_text_buffer_emit_insert (buffer, iter, text, -1);
1048 typedef struct _Range Range;
1051 GtkTextBuffer *buffer;
1052 GtkTextMark *start_mark;
1053 GtkTextMark *end_mark;
1054 GtkTextMark *whole_end_mark;
1055 GtkTextIter *range_start;
1056 GtkTextIter *range_end;
1057 GtkTextIter *whole_end;
1061 save_range (GtkTextIter *range_start,
1062 GtkTextIter *range_end,
1063 GtkTextIter *whole_end)
1067 r = g_new (Range, 1);
1069 r->buffer = gtk_text_iter_get_buffer (range_start);
1070 g_object_ref (r->buffer);
1073 gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (range_start),
1078 gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (range_start),
1084 gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (range_start),
1089 r->range_start = range_start;
1090 r->range_end = range_end;
1091 r->whole_end = whole_end;
1097 restore_range (Range *r)
1099 gtk_text_buffer_get_iter_at_mark (r->buffer,
1103 gtk_text_buffer_get_iter_at_mark (r->buffer,
1107 gtk_text_buffer_get_iter_at_mark (r->buffer,
1111 gtk_text_buffer_delete_mark (r->buffer, r->start_mark);
1112 gtk_text_buffer_delete_mark (r->buffer, r->end_mark);
1113 gtk_text_buffer_delete_mark (r->buffer, r->whole_end_mark);
1115 /* Due to the gravities on the marks, the ordering could have
1116 * gotten mangled; we switch to an empty range in that
1120 if (gtk_text_iter_compare (r->range_start, r->range_end) > 0)
1121 *r->range_start = *r->range_end;
1123 if (gtk_text_iter_compare (r->range_end, r->whole_end) > 0)
1124 *r->range_end = *r->whole_end;
1126 g_object_unref (r->buffer);
1131 insert_range_untagged (GtkTextBuffer *buffer,
1133 const GtkTextIter *orig_start,
1134 const GtkTextIter *orig_end,
1135 gboolean interactive)
1137 GtkTextIter range_start;
1138 GtkTextIter range_end;
1139 GtkTextIter start, end;
1142 if (gtk_text_iter_equal (orig_start, orig_end))
1145 start = *orig_start;
1148 range_start = start;
1153 if (gtk_text_iter_equal (&range_start, &range_end))
1155 /* Figure out how to move forward */
1157 g_assert (gtk_text_iter_compare (&range_end, &end) <= 0);
1159 if (gtk_text_iter_equal (&range_end, &end))
1161 /* nothing left to do */
1164 else if (gtk_text_iter_get_char (&range_end) == GTK_TEXT_UNKNOWN_CHAR)
1166 GdkPixbuf *pixbuf = NULL;
1167 GtkTextChildAnchor *anchor = NULL;
1168 pixbuf = gtk_text_iter_get_pixbuf (&range_end);
1169 anchor = gtk_text_iter_get_child_anchor (&range_end);
1173 r = save_range (&range_start,
1177 gtk_text_buffer_insert_pixbuf (buffer,
1184 gtk_text_iter_forward_char (&range_end);
1186 range_start = range_end;
1190 /* Just skip anchors */
1192 gtk_text_iter_forward_char (&range_end);
1193 range_start = range_end;
1197 /* The GTK_TEXT_UNKNOWN_CHAR was in a text segment, so
1200 gtk_text_iter_forward_find_char (&range_end,
1201 possibly_not_text, NULL,
1204 g_assert (gtk_text_iter_compare (&range_end, &end) <= 0);
1209 /* Text segment starts here, so forward search to
1210 * find its possible endpoint
1212 gtk_text_iter_forward_find_char (&range_end,
1213 possibly_not_text, NULL,
1216 g_assert (gtk_text_iter_compare (&range_end, &end) <= 0);
1221 r = save_range (&range_start,
1225 insert_text_range (buffer,
1234 range_start = range_end;
1240 insert_range_not_inside_self (GtkTextBuffer *buffer,
1242 const GtkTextIter *orig_start,
1243 const GtkTextIter *orig_end,
1244 gboolean interactive)
1246 /* Find each range of uniformly-tagged text, insert it,
1247 * then apply the tags.
1249 GtkTextIter start = *orig_start;
1250 GtkTextIter end = *orig_end;
1251 GtkTextIter range_start;
1252 GtkTextIter range_end;
1254 if (gtk_text_iter_equal (orig_start, orig_end))
1257 gtk_text_iter_order (&start, &end);
1259 range_start = start;
1265 GtkTextIter start_iter;
1270 if (gtk_text_iter_equal (&range_start, &end))
1271 break; /* All done */
1273 g_assert (gtk_text_iter_compare (&range_start, &end) < 0);
1275 gtk_text_iter_forward_to_tag_toggle (&range_end, NULL);
1277 g_assert (!gtk_text_iter_equal (&range_start, &range_end));
1279 /* Clamp to the end iterator */
1280 if (gtk_text_iter_compare (&range_end, &end) > 0)
1283 /* We have a range with unique tags; insert it, and
1286 start_offset = gtk_text_iter_get_offset (iter);
1288 r = save_range (&range_start, &range_end, &end);
1290 insert_range_untagged (buffer, iter, &range_start, &range_end, interactive);
1295 gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, start_offset);
1297 tags = gtk_text_iter_get_tags (&range_start);
1299 while (tmp_list != NULL)
1301 gtk_text_buffer_apply_tag (buffer,
1306 tmp_list = g_slist_next (tmp_list);
1308 g_slist_free (tags);
1310 range_start = range_end;
1315 gtk_text_buffer_real_insert_range (GtkTextBuffer *buffer,
1317 const GtkTextIter *orig_start,
1318 const GtkTextIter *orig_end,
1319 gboolean interactive)
1321 GtkTextBuffer *src_buffer;
1323 /* Find each range of uniformly-tagged text, insert it,
1324 * then apply the tags.
1326 if (gtk_text_iter_equal (orig_start, orig_end))
1330 gtk_text_buffer_begin_user_action (buffer);
1332 src_buffer = gtk_text_iter_get_buffer (orig_start);
1334 if (gtk_text_iter_get_buffer (iter) != src_buffer ||
1335 !gtk_text_iter_in_range (iter, orig_start, orig_end))
1337 insert_range_not_inside_self (buffer, iter, orig_start, orig_end, interactive);
1341 /* If you insert a range into itself, it could loop infinitely
1342 * because the region being copied keeps growing as we insert. So
1343 * we have to separately copy the range before and after
1344 * the insertion point.
1346 GtkTextIter start = *orig_start;
1347 GtkTextIter end = *orig_end;
1348 GtkTextIter range_start;
1349 GtkTextIter range_end;
1353 gtk_text_iter_order (&start, &end);
1355 range_start = start;
1357 first_half = save_range (&range_start, &range_end, &end);
1359 range_start = *iter;
1361 second_half = save_range (&range_start, &range_end, &end);
1363 restore_range (first_half);
1364 insert_range_not_inside_self (buffer, iter, &range_start, &range_end, interactive);
1366 restore_range (second_half);
1367 insert_range_not_inside_self (buffer, iter, &range_start, &range_end, interactive);
1371 gtk_text_buffer_end_user_action (buffer);
1375 * gtk_text_buffer_insert_range:
1376 * @buffer: a #GtkTextBuffer
1377 * @iter: a position in @buffer
1378 * @start: a position in a #GtkTextBuffer
1379 * @end: another position in the same buffer as @start
1381 * Copies text, tags, and pixbufs between @start and @end (the order
1382 * of @start and @end doesn't matter) and inserts the copy at @iter.
1383 * Used instead of simply getting/inserting text because it preserves
1384 * images and tags. If @start and @end are in a different buffer from
1385 * @buffer, the two buffers must share the same tag table.
1387 * Implemented via emissions of the insert_text and apply_tag signals,
1391 gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
1393 const GtkTextIter *start,
1394 const GtkTextIter *end)
1396 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
1397 g_return_if_fail (iter != NULL);
1398 g_return_if_fail (start != NULL);
1399 g_return_if_fail (end != NULL);
1400 g_return_if_fail (gtk_text_iter_get_buffer (start) ==
1401 gtk_text_iter_get_buffer (end));
1402 g_return_if_fail (gtk_text_iter_get_buffer (start)->tag_table ==
1404 g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer);
1406 gtk_text_buffer_real_insert_range (buffer, iter, start, end, FALSE);
1410 * gtk_text_buffer_insert_range_interactive:
1411 * @buffer: a #GtkTextBuffer
1412 * @iter: a position in @buffer
1413 * @start: a position in a #GtkTextBuffer
1414 * @end: another position in the same buffer as @start
1415 * @default_editable: default editability of the buffer
1417 * Same as gtk_text_buffer_insert_range(), but does nothing if the
1418 * insertion point isn't editable. The @default_editable parameter
1419 * indicates whether the text is editable at @iter if no tags
1420 * enclosing @iter affect editability. Typically the result of
1421 * gtk_text_view_get_editable() is appropriate here.
1423 * Returns: whether an insertion was possible at @iter
1426 gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
1428 const GtkTextIter *start,
1429 const GtkTextIter *end,
1430 gboolean default_editable)
1432 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
1433 g_return_val_if_fail (iter != NULL, FALSE);
1434 g_return_val_if_fail (start != NULL, FALSE);
1435 g_return_val_if_fail (end != NULL, FALSE);
1436 g_return_val_if_fail (gtk_text_iter_get_buffer (start) ==
1437 gtk_text_iter_get_buffer (end), FALSE);
1438 g_return_val_if_fail (gtk_text_iter_get_buffer (start)->tag_table ==
1439 buffer->tag_table, FALSE);
1441 if (gtk_text_iter_can_insert (iter, default_editable))
1443 gtk_text_buffer_real_insert_range (buffer, iter, start, end, TRUE);
1451 * gtk_text_buffer_insert_with_tags:
1452 * @buffer: a #GtkTextBuffer
1453 * @iter: an iterator in @buffer
1455 * @len: length of @text, or -1
1456 * @first_tag: first tag to apply to @text
1457 * @Varargs: NULL-terminated list of tags to apply
1459 * Inserts @text into @buffer at @iter, applying the list of tags to
1460 * the newly-inserted text. The last tag specified must be NULL to
1461 * terminate the list. Equivalent to calling gtk_text_buffer_insert(),
1462 * then gtk_text_buffer_apply_tag() on the inserted text;
1463 * gtk_text_buffer_insert_with_tags() is just a convenience function.
1466 gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer,
1470 GtkTextTag *first_tag,
1478 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
1479 g_return_if_fail (iter != NULL);
1480 g_return_if_fail (text != NULL);
1481 g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer);
1483 start_offset = gtk_text_iter_get_offset (iter);
1485 gtk_text_buffer_insert (buffer, iter, text, len);
1487 if (first_tag == NULL)
1490 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_offset);
1492 va_start (args, first_tag);
1496 gtk_text_buffer_apply_tag (buffer, tag, &start, iter);
1498 tag = va_arg (args, GtkTextTag*);
1505 * gtk_text_buffer_insert_with_tags_by_name:
1506 * @buffer: a #GtkTextBuffer
1507 * @iter: position in @buffer
1509 * @len: length of @text, or -1
1510 * @first_tag_name: name of a tag to apply to @text
1511 * @Varargs: more tag names
1513 * Same as gtk_text_buffer_insert_with_tags(), but allows you
1514 * to pass in tag names instead of tag objects.
1517 gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
1521 const gchar *first_tag_name,
1527 const gchar *tag_name;
1529 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
1530 g_return_if_fail (iter != NULL);
1531 g_return_if_fail (text != NULL);
1532 g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer);
1534 start_offset = gtk_text_iter_get_offset (iter);
1536 gtk_text_buffer_insert (buffer, iter, text, len);
1538 if (first_tag_name == NULL)
1541 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_offset);
1543 va_start (args, first_tag_name);
1544 tag_name = first_tag_name;
1549 tag = gtk_text_tag_table_lookup (buffer->tag_table,
1554 g_warning ("%s: no tag with name '%s'!", G_STRLOC, tag_name);
1559 gtk_text_buffer_apply_tag (buffer, tag, &start, iter);
1561 tag_name = va_arg (args, const gchar*);
1573 gtk_text_buffer_real_delete_range (GtkTextBuffer *buffer,
1577 gboolean has_selection;
1579 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
1580 g_return_if_fail (start != NULL);
1581 g_return_if_fail (end != NULL);
1583 _gtk_text_btree_delete (start, end);
1585 /* may have deleted the selection... */
1586 update_selection_clipboards (buffer);
1588 has_selection = gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL);
1589 if (has_selection != buffer->has_selection)
1591 buffer->has_selection = has_selection;
1592 g_object_notify (G_OBJECT (buffer), "has-selection");
1595 g_signal_emit (buffer, signals[CHANGED], 0);
1596 g_object_notify (G_OBJECT (buffer), "cursor-position");
1600 gtk_text_buffer_emit_delete (GtkTextBuffer *buffer,
1604 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
1605 g_return_if_fail (start != NULL);
1606 g_return_if_fail (end != NULL);
1608 if (gtk_text_iter_equal (start, end))
1611 gtk_text_iter_order (start, end);
1613 g_signal_emit (buffer,
1614 signals[DELETE_RANGE],
1620 * gtk_text_buffer_delete:
1621 * @buffer: a #GtkTextBuffer
1622 * @start: a position in @buffer
1623 * @end: another position in @buffer
1625 * Deletes text between @start and @end. The order of @start and @end
1626 * is not actually relevant; gtk_text_buffer_delete() will reorder
1627 * them. This function actually emits the "delete-range" signal, and
1628 * the default handler of that signal deletes the text. Because the
1629 * buffer is modified, all outstanding iterators become invalid after
1630 * calling this function; however, the @start and @end will be
1631 * re-initialized to point to the location where text was deleted.
1634 gtk_text_buffer_delete (GtkTextBuffer *buffer,
1638 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
1639 g_return_if_fail (start != NULL);
1640 g_return_if_fail (end != NULL);
1641 g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
1642 g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
1644 gtk_text_buffer_emit_delete (buffer, start, end);
1648 * gtk_text_buffer_delete_interactive:
1649 * @buffer: a #GtkTextBuffer
1650 * @start_iter: start of range to delete
1651 * @end_iter: end of range
1652 * @default_editable: whether the buffer is editable by default
1654 * Deletes all <emphasis>editable</emphasis> text in the given range.
1655 * Calls gtk_text_buffer_delete() for each editable sub-range of
1656 * [@start,@end). @start and @end are revalidated to point to
1657 * the location of the last deleted range, or left untouched if
1658 * no text was deleted.
1660 * Return value: whether some text was actually deleted
1663 gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
1664 GtkTextIter *start_iter,
1665 GtkTextIter *end_iter,
1666 gboolean default_editable)
1668 GtkTextMark *end_mark;
1669 GtkTextMark *start_mark;
1671 gboolean current_state;
1672 gboolean deleted_stuff = FALSE;
1674 /* Delete all editable text in the range start_iter, end_iter */
1676 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
1677 g_return_val_if_fail (start_iter != NULL, FALSE);
1678 g_return_val_if_fail (end_iter != NULL, FALSE);
1679 g_return_val_if_fail (gtk_text_iter_get_buffer (start_iter) == buffer, FALSE);
1680 g_return_val_if_fail (gtk_text_iter_get_buffer (end_iter) == buffer, FALSE);
1683 gtk_text_buffer_begin_user_action (buffer);
1685 gtk_text_iter_order (start_iter, end_iter);
1687 start_mark = gtk_text_buffer_create_mark (buffer, NULL,
1689 end_mark = gtk_text_buffer_create_mark (buffer, NULL,
1692 gtk_text_buffer_get_iter_at_mark (buffer, &iter, start_mark);
1694 current_state = gtk_text_iter_editable (&iter, default_editable);
1699 gboolean done = FALSE;
1702 gtk_text_iter_forward_to_tag_toggle (&iter, NULL);
1704 gtk_text_buffer_get_iter_at_mark (buffer, &end, end_mark);
1706 if (gtk_text_iter_compare (&iter, &end) >= 0)
1709 iter = end; /* clamp to the last boundary */
1712 new_state = gtk_text_iter_editable (&iter, default_editable);
1714 if (current_state == new_state)
1720 /* We're ending an editable region. Delete said region. */
1723 gtk_text_buffer_get_iter_at_mark (buffer, &start, start_mark);
1725 gtk_text_buffer_emit_delete (buffer, &start, &iter);
1727 deleted_stuff = TRUE;
1729 /* revalidate user's iterators. */
1730 *start_iter = start;
1740 if (current_state && !new_state)
1742 /* End of an editable region. Delete it. */
1745 gtk_text_buffer_get_iter_at_mark (buffer, &start, start_mark);
1747 gtk_text_buffer_emit_delete (buffer, &start, &iter);
1749 /* It's more robust to ask for the state again then to assume that
1750 * we're on the next not-editable segment. We don't know what the
1751 * ::delete-range handler did.... maybe it deleted the following
1752 * not-editable segment because it was associated with the editable
1755 current_state = gtk_text_iter_editable (&iter, default_editable);
1756 deleted_stuff = TRUE;
1758 /* revalidate user's iterators. */
1759 *start_iter = start;
1764 /* We are at the start of an editable region. We won't be deleting
1765 * the previous region. Move start mark to start of this region.
1768 g_assert (!current_state && new_state);
1770 gtk_text_buffer_move_mark (buffer, start_mark, &iter);
1772 current_state = TRUE;
1779 gtk_text_buffer_delete_mark (buffer, start_mark);
1780 gtk_text_buffer_delete_mark (buffer, end_mark);
1782 gtk_text_buffer_end_user_action (buffer);
1784 return deleted_stuff;
1788 * Extracting textual buffer contents
1792 * gtk_text_buffer_get_text:
1793 * @buffer: a #GtkTextBuffer
1794 * @start: start of a range
1795 * @end: end of a range
1796 * @include_hidden_chars: whether to include invisible text
1798 * Returns the text in the range [@start,@end). Excludes undisplayed
1799 * text (text marked with tags that set the invisibility attribute) if
1800 * @include_hidden_chars is %FALSE. Does not include characters
1801 * representing embedded images, so byte and character indexes into
1802 * the returned string do <emphasis>not</emphasis> correspond to byte
1803 * and character indexes into the buffer. Contrast with
1804 * gtk_text_buffer_get_slice().
1806 * Return value: an allocated UTF-8 string
1809 gtk_text_buffer_get_text (GtkTextBuffer *buffer,
1810 const GtkTextIter *start,
1811 const GtkTextIter *end,
1812 gboolean include_hidden_chars)
1814 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
1815 g_return_val_if_fail (start != NULL, NULL);
1816 g_return_val_if_fail (end != NULL, NULL);
1817 g_return_val_if_fail (gtk_text_iter_get_buffer (start) == buffer, NULL);
1818 g_return_val_if_fail (gtk_text_iter_get_buffer (end) == buffer, NULL);
1820 if (include_hidden_chars)
1821 return gtk_text_iter_get_text (start, end);
1823 return gtk_text_iter_get_visible_text (start, end);
1827 * gtk_text_buffer_get_slice:
1828 * @buffer: a #GtkTextBuffer
1829 * @start: start of a range
1830 * @end: end of a range
1831 * @include_hidden_chars: whether to include invisible text
1833 * Returns the text in the range [@start,@end). Excludes undisplayed
1834 * text (text marked with tags that set the invisibility attribute) if
1835 * @include_hidden_chars is %FALSE. The returned string includes a
1836 * 0xFFFC character whenever the buffer contains
1837 * embedded images, so byte and character indexes into
1838 * the returned string <emphasis>do</emphasis> correspond to byte
1839 * and character indexes into the buffer. Contrast with
1840 * gtk_text_buffer_get_text(). Note that 0xFFFC can occur in normal
1841 * text as well, so it is not a reliable indicator that a pixbuf or
1842 * widget is in the buffer.
1844 * Return value: an allocated UTF-8 string
1847 gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
1848 const GtkTextIter *start,
1849 const GtkTextIter *end,
1850 gboolean include_hidden_chars)
1852 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
1853 g_return_val_if_fail (start != NULL, NULL);
1854 g_return_val_if_fail (end != NULL, NULL);
1855 g_return_val_if_fail (gtk_text_iter_get_buffer (start) == buffer, NULL);
1856 g_return_val_if_fail (gtk_text_iter_get_buffer (end) == buffer, NULL);
1858 if (include_hidden_chars)
1859 return gtk_text_iter_get_slice (start, end);
1861 return gtk_text_iter_get_visible_slice (start, end);
1869 gtk_text_buffer_real_insert_pixbuf (GtkTextBuffer *buffer,
1873 _gtk_text_btree_insert_pixbuf (iter, pixbuf);
1875 g_signal_emit (buffer, signals[CHANGED], 0);
1879 * gtk_text_buffer_insert_pixbuf:
1880 * @buffer: a #GtkTextBuffer
1881 * @iter: location to insert the pixbuf
1882 * @pixbuf: a #GdkPixbuf
1884 * Inserts an image into the text buffer at @iter. The image will be
1885 * counted as one character in character counts, and when obtaining
1886 * the buffer contents as a string, will be represented by the Unicode
1887 * "object replacement character" 0xFFFC. Note that the "slice"
1888 * variants for obtaining portions of the buffer as a string include
1889 * this character for pixbufs, but the "text" variants do
1890 * not. e.g. see gtk_text_buffer_get_slice() and
1891 * gtk_text_buffer_get_text().
1894 gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
1898 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
1899 g_return_if_fail (iter != NULL);
1900 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
1901 g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer);
1903 g_signal_emit (buffer, signals[INSERT_PIXBUF], 0,
1913 gtk_text_buffer_real_insert_anchor (GtkTextBuffer *buffer,
1915 GtkTextChildAnchor *anchor)
1917 _gtk_text_btree_insert_child_anchor (iter, anchor);
1919 g_signal_emit (buffer, signals[CHANGED], 0);
1923 * gtk_text_buffer_insert_child_anchor:
1924 * @buffer: a #GtkTextBuffer
1925 * @iter: location to insert the anchor
1926 * @anchor: a #GtkTextChildAnchor
1928 * Inserts a child widget anchor into the text buffer at @iter. The
1929 * anchor will be counted as one character in character counts, and
1930 * when obtaining the buffer contents as a string, will be represented
1931 * by the Unicode "object replacement character" 0xFFFC. Note that the
1932 * "slice" variants for obtaining portions of the buffer as a string
1933 * include this character for child anchors, but the "text" variants do
1934 * not. E.g. see gtk_text_buffer_get_slice() and
1935 * gtk_text_buffer_get_text(). Consider
1936 * gtk_text_buffer_create_child_anchor() as a more convenient
1937 * alternative to this function. The buffer will add a reference to
1938 * the anchor, so you can unref it after insertion.
1941 gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer,
1943 GtkTextChildAnchor *anchor)
1945 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
1946 g_return_if_fail (iter != NULL);
1947 g_return_if_fail (GTK_IS_TEXT_CHILD_ANCHOR (anchor));
1948 g_return_if_fail (gtk_text_iter_get_buffer (iter) == buffer);
1950 g_signal_emit (buffer, signals[INSERT_CHILD_ANCHOR], 0,
1955 * gtk_text_buffer_create_child_anchor:
1956 * @buffer: a #GtkTextBuffer
1957 * @iter: location in the buffer
1959 * This is a convenience function which simply creates a child anchor
1960 * with gtk_text_child_anchor_new() and inserts it into the buffer
1961 * with gtk_text_buffer_insert_child_anchor(). The new anchor is
1962 * owned by the buffer; no reference count is returned to
1963 * the caller of gtk_text_buffer_create_child_anchor().
1965 * Return value: the created child anchor
1968 gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
1971 GtkTextChildAnchor *anchor;
1973 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
1974 g_return_val_if_fail (iter != NULL, NULL);
1975 g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == buffer, NULL);
1977 anchor = gtk_text_child_anchor_new ();
1979 gtk_text_buffer_insert_child_anchor (buffer, iter, anchor);
1981 g_object_unref (anchor);
1991 gtk_text_buffer_mark_set (GtkTextBuffer *buffer,
1992 const GtkTextIter *location,
1995 /* IMO this should NOT work like insert_text and delete_range,
1996 * where the real action happens in the default handler.
1998 * The reason is that the default handler would be _required_,
1999 * i.e. the whole widget would start breaking and segfaulting if the
2000 * default handler didn't get run. So you can't really override the
2001 * default handler or stop the emission; that is, this signal is
2002 * purely for notification, and not to allow users to modify the
2006 g_object_ref (mark);
2008 g_signal_emit (buffer,
2014 g_object_unref (mark);
2018 * gtk_text_buffer_set_mark:
2019 * @buffer: a #GtkTextBuffer
2020 * @mark_name: name of the mark
2021 * @iter: location for the mark
2022 * @left_gravity: if the mark is created by this function, gravity for
2024 * @should_exist: if %TRUE, warn if the mark does not exist, and return
2027 * Move the mark to the given position, if not @should_exist,
2030 * Return value: mark
2033 gtk_text_buffer_set_mark (GtkTextBuffer *buffer,
2034 GtkTextMark *existing_mark,
2035 const gchar *mark_name,
2036 const GtkTextIter *iter,
2037 gboolean left_gravity,
2038 gboolean should_exist)
2040 GtkTextIter location;
2043 g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == buffer, NULL);
2045 mark = _gtk_text_btree_set_mark (get_btree (buffer),
2052 _gtk_text_btree_get_iter_at_mark (get_btree (buffer),
2056 gtk_text_buffer_mark_set (buffer, &location, mark);
2062 * gtk_text_buffer_create_mark:
2063 * @buffer: a #GtkTextBuffer
2064 * @mark_name: (allow-none): name for mark, or %NULL
2065 * @where: location to place mark
2066 * @left_gravity: whether the mark has left gravity
2068 * Creates a mark at position @where. If @mark_name is %NULL, the mark
2069 * is anonymous; otherwise, the mark can be retrieved by name using
2070 * gtk_text_buffer_get_mark(). If a mark has left gravity, and text is
2071 * inserted at the mark's current location, the mark will be moved to
2072 * the left of the newly-inserted text. If the mark has right gravity
2073 * (@left_gravity = %FALSE), the mark will end up on the right of
2074 * newly-inserted text. The standard left-to-right cursor is a mark
2075 * with right gravity (when you type, the cursor stays on the right
2076 * side of the text you're typing).
2078 * The caller of this function does <emphasis>not</emphasis> own a
2079 * reference to the returned #GtkTextMark, so you can ignore the
2080 * return value if you like. Marks are owned by the buffer and go
2081 * away when the buffer does.
2083 * Emits the "mark-set" signal as notification of the mark's initial
2086 * Return value: the new #GtkTextMark object
2089 gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
2090 const gchar *mark_name,
2091 const GtkTextIter *where,
2092 gboolean left_gravity)
2094 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
2096 return gtk_text_buffer_set_mark (buffer, NULL, mark_name, where,
2097 left_gravity, FALSE);
2101 * gtk_text_buffer_add_mark:
2102 * @buffer: a #GtkTextBuffer
2103 * @mark: the mark to add
2104 * @where: location to place mark
2106 * Adds the mark at position @where. The mark must not be added to
2107 * another buffer, and if its name is not %NULL then there must not
2108 * be another mark in the buffer with the same name.
2110 * Emits the "mark-set" signal as notification of the mark's initial
2116 gtk_text_buffer_add_mark (GtkTextBuffer *buffer,
2118 const GtkTextIter *where)
2122 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2123 g_return_if_fail (GTK_IS_TEXT_MARK (mark));
2124 g_return_if_fail (where != NULL);
2125 g_return_if_fail (gtk_text_mark_get_buffer (mark) == NULL);
2127 name = gtk_text_mark_get_name (mark);
2129 if (name != NULL && gtk_text_buffer_get_mark (buffer, name) != NULL)
2131 g_critical ("Mark %s already exists in the buffer", name);
2135 gtk_text_buffer_set_mark (buffer, mark, NULL, where, FALSE, FALSE);
2139 * gtk_text_buffer_move_mark:
2140 * @buffer: a #GtkTextBuffer
2141 * @mark: a #GtkTextMark
2142 * @where: new location for @mark in @buffer
2144 * Moves @mark to the new location @where. Emits the "mark-set" signal
2145 * as notification of the move.
2148 gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
2150 const GtkTextIter *where)
2152 g_return_if_fail (GTK_IS_TEXT_MARK (mark));
2153 g_return_if_fail (!gtk_text_mark_get_deleted (mark));
2154 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2156 gtk_text_buffer_set_mark (buffer, mark, NULL, where, FALSE, TRUE);
2160 * gtk_text_buffer_get_iter_at_mark:
2161 * @buffer: a #GtkTextBuffer
2162 * @iter: iterator to initialize
2163 * @mark: a #GtkTextMark in @buffer
2165 * Initializes @iter with the current position of @mark.
2168 gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
2172 g_return_if_fail (GTK_IS_TEXT_MARK (mark));
2173 g_return_if_fail (!gtk_text_mark_get_deleted (mark));
2174 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2176 _gtk_text_btree_get_iter_at_mark (get_btree (buffer),
2182 * gtk_text_buffer_delete_mark:
2183 * @buffer: a #GtkTextBuffer
2184 * @mark: a #GtkTextMark in @buffer
2186 * Deletes @mark, so that it's no longer located anywhere in the
2187 * buffer. Removes the reference the buffer holds to the mark, so if
2188 * you haven't called g_object_ref() on the mark, it will be freed. Even
2189 * if the mark isn't freed, most operations on @mark become
2190 * invalid, until it gets added to a buffer again with
2191 * gtk_text_buffer_add_mark(). Use gtk_text_mark_get_deleted() to
2192 * find out if a mark has been removed from its buffer.
2193 * The "mark-deleted" signal will be emitted as notification after
2194 * the mark is deleted.
2197 gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
2200 g_return_if_fail (GTK_IS_TEXT_MARK (mark));
2201 g_return_if_fail (!gtk_text_mark_get_deleted (mark));
2202 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2204 g_object_ref (mark);
2206 _gtk_text_btree_remove_mark (get_btree (buffer), mark);
2208 /* See rationale above for MARK_SET on why we emit this after
2209 * removing the mark, rather than removing the mark in a default
2212 g_signal_emit (buffer, signals[MARK_DELETED],
2216 g_object_unref (mark);
2220 * gtk_text_buffer_get_mark:
2221 * @buffer: a #GtkTextBuffer
2222 * @name: a mark name
2224 * Returns the mark named @name in buffer @buffer, or %NULL if no such
2225 * mark exists in the buffer.
2227 * Return value: (transfer none): a #GtkTextMark, or %NULL
2230 gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
2235 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
2236 g_return_val_if_fail (name != NULL, NULL);
2238 mark = _gtk_text_btree_get_mark_by_name (get_btree (buffer), name);
2244 * gtk_text_buffer_move_mark_by_name:
2245 * @buffer: a #GtkTextBuffer
2246 * @name: name of a mark
2247 * @where: new location for mark
2249 * Moves the mark named @name (which must exist) to location @where.
2250 * See gtk_text_buffer_move_mark() for details.
2253 gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
2255 const GtkTextIter *where)
2259 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2260 g_return_if_fail (name != NULL);
2262 mark = _gtk_text_btree_get_mark_by_name (get_btree (buffer), name);
2266 g_warning ("%s: no mark named '%s'", G_STRLOC, name);
2270 gtk_text_buffer_move_mark (buffer, mark, where);
2274 * gtk_text_buffer_delete_mark_by_name:
2275 * @buffer: a #GtkTextBuffer
2276 * @name: name of a mark in @buffer
2278 * Deletes the mark named @name; the mark must exist. See
2279 * gtk_text_buffer_delete_mark() for details.
2282 gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
2287 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2288 g_return_if_fail (name != NULL);
2290 mark = _gtk_text_btree_get_mark_by_name (get_btree (buffer), name);
2294 g_warning ("%s: no mark named '%s'", G_STRLOC, name);
2298 gtk_text_buffer_delete_mark (buffer, mark);
2302 * gtk_text_buffer_get_insert:
2303 * @buffer: a #GtkTextBuffer
2305 * Returns the mark that represents the cursor (insertion point).
2306 * Equivalent to calling gtk_text_buffer_get_mark() to get the mark
2307 * named "insert", but very slightly more efficient, and involves less
2310 * Return value: (transfer none): insertion point mark
2313 gtk_text_buffer_get_insert (GtkTextBuffer *buffer)
2315 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
2317 return _gtk_text_btree_get_insert (get_btree (buffer));
2321 * gtk_text_buffer_get_selection_bound:
2322 * @buffer: a #GtkTextBuffer
2324 * Returns the mark that represents the selection bound. Equivalent
2325 * to calling gtk_text_buffer_get_mark() to get the mark named
2326 * "selection_bound", but very slightly more efficient, and involves
2329 * The currently-selected text in @buffer is the region between the
2330 * "selection_bound" and "insert" marks. If "selection_bound" and
2331 * "insert" are in the same place, then there is no current selection.
2332 * gtk_text_buffer_get_selection_bounds() is another convenient function
2333 * for handling the selection, if you just want to know whether there's a
2334 * selection and what its bounds are.
2336 * Return value: (transfer none): selection bound mark
2339 gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer)
2341 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
2343 return _gtk_text_btree_get_selection_bound (get_btree (buffer));
2347 * gtk_text_buffer_get_iter_at_child_anchor:
2348 * @buffer: a #GtkTextBuffer
2349 * @iter: an iterator to be initialized
2350 * @anchor: a child anchor that appears in @buffer
2352 * Obtains the location of @anchor within @buffer.
2355 gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
2357 GtkTextChildAnchor *anchor)
2359 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2360 g_return_if_fail (iter != NULL);
2361 g_return_if_fail (GTK_IS_TEXT_CHILD_ANCHOR (anchor));
2362 g_return_if_fail (!gtk_text_child_anchor_get_deleted (anchor));
2364 _gtk_text_btree_get_iter_at_child_anchor (get_btree (buffer),
2370 * gtk_text_buffer_place_cursor:
2371 * @buffer: a #GtkTextBuffer
2372 * @where: where to put the cursor
2374 * This function moves the "insert" and "selection_bound" marks
2375 * simultaneously. If you move them to the same place in two steps
2376 * with gtk_text_buffer_move_mark(), you will temporarily select a
2377 * region in between their old and new locations, which can be pretty
2378 * inefficient since the temporarily-selected region will force stuff
2379 * to be recalculated. This function moves them as a unit, which can
2383 gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
2384 const GtkTextIter *where)
2386 gtk_text_buffer_select_range (buffer, where, where);
2390 * gtk_text_buffer_select_range:
2391 * @buffer: a #GtkTextBuffer
2392 * @ins: where to put the "insert" mark
2393 * @bound: where to put the "selection_bound" mark
2395 * This function moves the "insert" and "selection_bound" marks
2396 * simultaneously. If you move them in two steps
2397 * with gtk_text_buffer_move_mark(), you will temporarily select a
2398 * region in between their old and new locations, which can be pretty
2399 * inefficient since the temporarily-selected region will force stuff
2400 * to be recalculated. This function moves them as a unit, which can
2406 gtk_text_buffer_select_range (GtkTextBuffer *buffer,
2407 const GtkTextIter *ins,
2408 const GtkTextIter *bound)
2410 GtkTextIter real_ins;
2411 GtkTextIter real_bound;
2413 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2416 real_bound = *bound;
2418 _gtk_text_btree_select_range (get_btree (buffer), &real_ins, &real_bound);
2419 gtk_text_buffer_mark_set (buffer, &real_ins,
2420 gtk_text_buffer_get_insert (buffer));
2421 gtk_text_buffer_mark_set (buffer, &real_bound,
2422 gtk_text_buffer_get_selection_bound (buffer));
2430 * gtk_text_buffer_create_tag:
2431 * @buffer: a #GtkTextBuffer
2432 * @tag_name: (allow-none): name of the new tag, or %NULL
2433 * @first_property_name: (allow-none): name of first property to set, or %NULL
2434 * @Varargs: %NULL-terminated list of property names and values
2437 * Creates a tag and adds it to the tag table for @buffer.
2438 * Equivalent to calling gtk_text_tag_new() and then adding the
2439 * tag to the buffer's tag table. The returned tag is owned by
2440 * the buffer's tag table, so the ref count will be equal to one.
2442 * If @tag_name is %NULL, the tag is anonymous.
2444 * If @tag_name is non-%NULL, a tag called @tag_name must not already
2445 * exist in the tag table for this buffer.
2447 * The @first_property_name argument and subsequent arguments are a list
2448 * of properties to set on the tag, as with g_object_set().
2450 * Return value: a new tag
2453 gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
2454 const gchar *tag_name,
2455 const gchar *first_property_name,
2461 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
2463 tag = gtk_text_tag_new (tag_name);
2465 gtk_text_tag_table_add (get_table (buffer), tag);
2467 if (first_property_name)
2469 va_start (list, first_property_name);
2470 g_object_set_valist (G_OBJECT (tag), first_property_name, list);
2474 g_object_unref (tag);
2480 gtk_text_buffer_real_apply_tag (GtkTextBuffer *buffer,
2482 const GtkTextIter *start,
2483 const GtkTextIter *end)
2485 if (tag->table != buffer->tag_table)
2487 g_warning ("Can only apply tags that are in the tag table for the buffer");
2491 _gtk_text_btree_tag (start, end, tag, TRUE);
2495 gtk_text_buffer_real_remove_tag (GtkTextBuffer *buffer,
2497 const GtkTextIter *start,
2498 const GtkTextIter *end)
2500 if (tag->table != buffer->tag_table)
2502 g_warning ("Can only remove tags that are in the tag table for the buffer");
2506 _gtk_text_btree_tag (start, end, tag, FALSE);
2510 gtk_text_buffer_real_changed (GtkTextBuffer *buffer)
2512 gtk_text_buffer_set_modified (buffer, TRUE);
2516 gtk_text_buffer_real_mark_set (GtkTextBuffer *buffer,
2517 const GtkTextIter *iter,
2520 GtkTextMark *insert;
2522 insert = gtk_text_buffer_get_insert (buffer);
2524 if (mark == insert || mark == gtk_text_buffer_get_selection_bound (buffer))
2526 gboolean has_selection;
2528 update_selection_clipboards (buffer);
2530 has_selection = gtk_text_buffer_get_selection_bounds (buffer,
2534 if (has_selection != buffer->has_selection)
2536 buffer->has_selection = has_selection;
2537 g_object_notify (G_OBJECT (buffer), "has-selection");
2542 g_object_notify (G_OBJECT (buffer), "cursor-position");
2546 gtk_text_buffer_emit_tag (GtkTextBuffer *buffer,
2549 const GtkTextIter *start,
2550 const GtkTextIter *end)
2552 GtkTextIter start_tmp = *start;
2553 GtkTextIter end_tmp = *end;
2555 g_return_if_fail (tag != NULL);
2557 gtk_text_iter_order (&start_tmp, &end_tmp);
2560 g_signal_emit (buffer, signals[APPLY_TAG],
2562 tag, &start_tmp, &end_tmp);
2564 g_signal_emit (buffer, signals[REMOVE_TAG],
2566 tag, &start_tmp, &end_tmp);
2570 * gtk_text_buffer_apply_tag:
2571 * @buffer: a #GtkTextBuffer
2572 * @tag: a #GtkTextTag
2573 * @start: one bound of range to be tagged
2574 * @end: other bound of range to be tagged
2576 * Emits the "apply-tag" signal on @buffer. The default
2577 * handler for the signal applies @tag to the given range.
2578 * @start and @end do not have to be in order.
2581 gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
2583 const GtkTextIter *start,
2584 const GtkTextIter *end)
2586 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2587 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
2588 g_return_if_fail (start != NULL);
2589 g_return_if_fail (end != NULL);
2590 g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
2591 g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
2592 g_return_if_fail (tag->table == buffer->tag_table);
2594 gtk_text_buffer_emit_tag (buffer, tag, TRUE, start, end);
2598 * gtk_text_buffer_remove_tag:
2599 * @buffer: a #GtkTextBuffer
2600 * @tag: a #GtkTextTag
2601 * @start: one bound of range to be untagged
2602 * @end: other bound of range to be untagged
2604 * Emits the "remove-tag" signal. The default handler for the signal
2605 * removes all occurrences of @tag from the given range. @start and
2606 * @end don't have to be in order.
2609 gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
2611 const GtkTextIter *start,
2612 const GtkTextIter *end)
2615 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2616 g_return_if_fail (GTK_IS_TEXT_TAG (tag));
2617 g_return_if_fail (start != NULL);
2618 g_return_if_fail (end != NULL);
2619 g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
2620 g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
2621 g_return_if_fail (tag->table == buffer->tag_table);
2623 gtk_text_buffer_emit_tag (buffer, tag, FALSE, start, end);
2627 * gtk_text_buffer_apply_tag_by_name:
2628 * @buffer: a #GtkTextBuffer
2629 * @name: name of a named #GtkTextTag
2630 * @start: one bound of range to be tagged
2631 * @end: other bound of range to be tagged
2633 * Calls gtk_text_tag_table_lookup() on the buffer's tag table to
2634 * get a #GtkTextTag, then calls gtk_text_buffer_apply_tag().
2637 gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
2639 const GtkTextIter *start,
2640 const GtkTextIter *end)
2644 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2645 g_return_if_fail (name != NULL);
2646 g_return_if_fail (start != NULL);
2647 g_return_if_fail (end != NULL);
2648 g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
2649 g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
2651 tag = gtk_text_tag_table_lookup (get_table (buffer),
2656 g_warning ("Unknown tag `%s'", name);
2660 gtk_text_buffer_emit_tag (buffer, tag, TRUE, start, end);
2664 * gtk_text_buffer_remove_tag_by_name:
2665 * @buffer: a #GtkTextBuffer
2666 * @name: name of a #GtkTextTag
2667 * @start: one bound of range to be untagged
2668 * @end: other bound of range to be untagged
2670 * Calls gtk_text_tag_table_lookup() on the buffer's tag table to
2671 * get a #GtkTextTag, then calls gtk_text_buffer_remove_tag().
2674 gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
2676 const GtkTextIter *start,
2677 const GtkTextIter *end)
2681 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2682 g_return_if_fail (name != NULL);
2683 g_return_if_fail (start != NULL);
2684 g_return_if_fail (end != NULL);
2685 g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
2686 g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
2688 tag = gtk_text_tag_table_lookup (get_table (buffer),
2693 g_warning ("Unknown tag `%s'", name);
2697 gtk_text_buffer_emit_tag (buffer, tag, FALSE, start, end);
2701 pointer_cmp (gconstpointer a,
2713 * gtk_text_buffer_remove_all_tags:
2714 * @buffer: a #GtkTextBuffer
2715 * @start: one bound of range to be untagged
2716 * @end: other bound of range to be untagged
2718 * Removes all tags in the range between @start and @end. Be careful
2719 * with this function; it could remove tags added in code unrelated to
2720 * the code you're currently writing. That is, using this function is
2721 * probably a bad idea if you have two or more unrelated code sections
2725 gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
2726 const GtkTextIter *start,
2727 const GtkTextIter *end)
2729 GtkTextIter first, second, tmp;
2732 GSList *prev, *next;
2735 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2736 g_return_if_fail (start != NULL);
2737 g_return_if_fail (end != NULL);
2738 g_return_if_fail (gtk_text_iter_get_buffer (start) == buffer);
2739 g_return_if_fail (gtk_text_iter_get_buffer (end) == buffer);
2744 gtk_text_iter_order (&first, &second);
2746 /* Get all tags turned on at the start */
2747 tags = gtk_text_iter_get_tags (&first);
2749 /* Find any that are toggled on within the range */
2751 while (gtk_text_iter_forward_to_tag_toggle (&tmp, NULL))
2756 if (gtk_text_iter_compare (&tmp, &second) >= 0)
2757 break; /* past the end of the range */
2759 toggled = gtk_text_iter_get_toggled_tags (&tmp, TRUE);
2761 /* We could end up with a really big-ass list here.
2764 tmp_list2 = toggled;
2765 while (tmp_list2 != NULL)
2767 tags = g_slist_prepend (tags, tmp_list2->data);
2769 tmp_list2 = g_slist_next (tmp_list2);
2772 g_slist_free (toggled);
2776 tags = g_slist_sort (tags, pointer_cmp);
2778 /* Strip duplicates */
2782 while (tmp_list != NULL)
2784 if (tag == tmp_list->data)
2787 next = tmp_list->next;
2791 tmp_list->next = NULL;
2793 g_slist_free (tmp_list);
2796 /* prev is unchanged */
2800 /* not a duplicate */
2801 tag = GTK_TEXT_TAG (tmp_list->data);
2803 tmp_list = tmp_list->next;
2807 g_slist_foreach (tags, (GFunc) g_object_ref, NULL);
2810 while (tmp_list != NULL)
2812 tag = GTK_TEXT_TAG (tmp_list->data);
2814 gtk_text_buffer_remove_tag (buffer, tag, &first, &second);
2816 tmp_list = tmp_list->next;
2819 g_slist_foreach (tags, (GFunc) g_object_unref, NULL);
2821 g_slist_free (tags);
2826 * Obtain various iterators
2830 * gtk_text_buffer_get_iter_at_line_offset:
2831 * @buffer: a #GtkTextBuffer
2832 * @iter: iterator to initialize
2833 * @line_number: line number counting from 0
2834 * @char_offset: char offset from start of line
2836 * Obtains an iterator pointing to @char_offset within the given
2837 * line. The @char_offset must exist, offsets off the end of the line
2838 * are not allowed. Note <emphasis>characters</emphasis>, not bytes;
2839 * UTF-8 may encode one character as multiple bytes.
2842 gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
2847 g_return_if_fail (iter != NULL);
2848 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2850 _gtk_text_btree_get_iter_at_line_char (get_btree (buffer),
2851 iter, line_number, char_offset);
2855 * gtk_text_buffer_get_iter_at_line_index:
2856 * @buffer: a #GtkTextBuffer
2857 * @iter: iterator to initialize
2858 * @line_number: line number counting from 0
2859 * @byte_index: byte index from start of line
2861 * Obtains an iterator pointing to @byte_index within the given line.
2862 * @byte_index must be the start of a UTF-8 character, and must not be
2863 * beyond the end of the line. Note <emphasis>bytes</emphasis>, not
2864 * characters; UTF-8 may encode one character as multiple bytes.
2867 gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
2872 g_return_if_fail (iter != NULL);
2873 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2875 _gtk_text_btree_get_iter_at_line_byte (get_btree (buffer),
2876 iter, line_number, byte_index);
2880 * gtk_text_buffer_get_iter_at_line:
2881 * @buffer: a #GtkTextBuffer
2882 * @iter: iterator to initialize
2883 * @line_number: line number counting from 0
2885 * Initializes @iter to the start of the given line.
2888 gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
2892 g_return_if_fail (iter != NULL);
2893 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2895 gtk_text_buffer_get_iter_at_line_offset (buffer, iter, line_number, 0);
2899 * gtk_text_buffer_get_iter_at_offset:
2900 * @buffer: a #GtkTextBuffer
2901 * @iter: iterator to initialize
2902 * @char_offset: char offset from start of buffer, counting from 0, or -1
2904 * Initializes @iter to a position @char_offset chars from the start
2905 * of the entire buffer. If @char_offset is -1 or greater than the number
2906 * of characters in the buffer, @iter is initialized to the end iterator,
2907 * the iterator one past the last valid character in the buffer.
2910 gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
2914 g_return_if_fail (iter != NULL);
2915 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2917 _gtk_text_btree_get_iter_at_char (get_btree (buffer), iter, char_offset);
2921 * gtk_text_buffer_get_start_iter:
2922 * @buffer: a #GtkTextBuffer
2923 * @iter: iterator to initialize
2925 * Initialized @iter with the first position in the text buffer. This
2926 * is the same as using gtk_text_buffer_get_iter_at_offset() to get
2927 * the iter at character offset 0.
2930 gtk_text_buffer_get_start_iter (GtkTextBuffer *buffer,
2933 g_return_if_fail (iter != NULL);
2934 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2936 _gtk_text_btree_get_iter_at_char (get_btree (buffer), iter, 0);
2940 * gtk_text_buffer_get_end_iter:
2941 * @buffer: a #GtkTextBuffer
2942 * @iter: iterator to initialize
2944 * Initializes @iter with the "end iterator," one past the last valid
2945 * character in the text buffer. If dereferenced with
2946 * gtk_text_iter_get_char(), the end iterator has a character value of
2947 * 0. The entire buffer lies in the range from the first position in
2948 * the buffer (call gtk_text_buffer_get_start_iter() to get
2949 * character position 0) to the end iterator.
2952 gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer,
2955 g_return_if_fail (iter != NULL);
2956 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2958 _gtk_text_btree_get_end_iter (get_btree (buffer), iter);
2962 * gtk_text_buffer_get_bounds:
2963 * @buffer: a #GtkTextBuffer
2964 * @start: iterator to initialize with first position in the buffer
2965 * @end: iterator to initialize with the end iterator
2967 * Retrieves the first and last iterators in the buffer, i.e. the
2968 * entire buffer lies within the range [@start,@end).
2971 gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
2975 g_return_if_fail (start != NULL);
2976 g_return_if_fail (end != NULL);
2977 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
2979 _gtk_text_btree_get_iter_at_char (get_btree (buffer), start, 0);
2980 _gtk_text_btree_get_end_iter (get_btree (buffer), end);
2988 * gtk_text_buffer_get_modified:
2989 * @buffer: a #GtkTextBuffer
2991 * Indicates whether the buffer has been modified since the last call
2992 * to gtk_text_buffer_set_modified() set the modification flag to
2993 * %FALSE. Used for example to enable a "save" function in a text
2996 * Return value: %TRUE if the buffer has been modified
2999 gtk_text_buffer_get_modified (GtkTextBuffer *buffer)
3001 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
3003 return buffer->modified;
3007 * gtk_text_buffer_set_modified:
3008 * @buffer: a #GtkTextBuffer
3009 * @setting: modification flag setting
3011 * Used to keep track of whether the buffer has been modified since the
3012 * last time it was saved. Whenever the buffer is saved to disk, call
3013 * gtk_text_buffer_set_modified (@buffer, FALSE). When the buffer is modified,
3014 * it will automatically toggled on the modified bit again. When the modified
3015 * bit flips, the buffer emits a "modified-changed" signal.
3018 gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
3021 gboolean fixed_setting;
3023 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
3025 fixed_setting = setting != FALSE;
3027 if (buffer->modified == fixed_setting)
3031 buffer->modified = fixed_setting;
3032 g_signal_emit (buffer, signals[MODIFIED_CHANGED], 0);
3037 * gtk_text_buffer_get_has_selection:
3038 * @buffer: a #GtkTextBuffer
3040 * Indicates whether the buffer has some text currently selected.
3042 * Return value: %TRUE if the there is text selected
3047 gtk_text_buffer_get_has_selection (GtkTextBuffer *buffer)
3049 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
3051 return buffer->has_selection;
3056 * Assorted other stuff
3060 * gtk_text_buffer_get_line_count:
3061 * @buffer: a #GtkTextBuffer
3063 * Obtains the number of lines in the buffer. This value is cached, so
3064 * the function is very fast.
3066 * Return value: number of lines in the buffer
3069 gtk_text_buffer_get_line_count (GtkTextBuffer *buffer)
3071 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), 0);
3073 return _gtk_text_btree_line_count (get_btree (buffer));
3077 * gtk_text_buffer_get_char_count:
3078 * @buffer: a #GtkTextBuffer
3080 * Gets the number of characters in the buffer; note that characters
3081 * and bytes are not the same, you can't e.g. expect the contents of
3082 * the buffer in string form to be this many bytes long. The character
3083 * count is cached, so this function is very fast.
3085 * Return value: number of characters in the buffer
3088 gtk_text_buffer_get_char_count (GtkTextBuffer *buffer)
3090 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), 0);
3092 return _gtk_text_btree_char_count (get_btree (buffer));
3095 /* Called when we lose the primary selection.
3098 clipboard_clear_selection_cb (GtkClipboard *clipboard,
3101 /* Move selection_bound to the insertion point */
3103 GtkTextIter selection_bound;
3104 GtkTextBuffer *buffer = GTK_TEXT_BUFFER (data);
3106 gtk_text_buffer_get_iter_at_mark (buffer, &insert,
3107 gtk_text_buffer_get_insert (buffer));
3108 gtk_text_buffer_get_iter_at_mark (buffer, &selection_bound,
3109 gtk_text_buffer_get_selection_bound (buffer));
3111 if (!gtk_text_iter_equal (&insert, &selection_bound))
3112 gtk_text_buffer_move_mark (buffer,
3113 gtk_text_buffer_get_selection_bound (buffer),
3117 /* Called when we have the primary selection and someone else wants our
3118 * data in order to paste it.
3121 clipboard_get_selection_cb (GtkClipboard *clipboard,
3122 GtkSelectionData *selection_data,
3126 GtkTextBuffer *buffer = GTK_TEXT_BUFFER (data);
3127 GtkTextIter start, end;
3129 if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
3131 if (info == GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
3133 /* Provide the address of the buffer; this will only be
3134 * used within-process
3136 gtk_selection_data_set (selection_data,
3137 selection_data->target,
3142 else if (info == GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT)
3147 str = gtk_text_buffer_serialize (buffer, buffer,
3148 selection_data->target,
3149 &start, &end, &len);
3151 gtk_selection_data_set (selection_data,
3152 selection_data->target,
3161 str = gtk_text_iter_get_visible_text (&start, &end);
3162 gtk_selection_data_set_text (selection_data, str, -1);
3168 static GtkTextBuffer *
3169 create_clipboard_contents_buffer (GtkTextBuffer *buffer)
3171 GtkTextBuffer *contents;
3173 contents = gtk_text_buffer_new (gtk_text_buffer_get_tag_table (buffer));
3175 g_object_set_data (G_OBJECT (contents), I_("gtk-text-buffer-clipboard-source"),
3177 g_object_set_data (G_OBJECT (contents), I_("gtk-text-buffer-clipboard"),
3178 GINT_TO_POINTER (1));
3180 /* Ref the source buffer as long as the clipboard contents buffer
3181 * exists, because it's needed for serializing the contents buffer.
3182 * See http://bugzilla.gnome.org/show_bug.cgi?id=339195
3184 g_object_ref (buffer);
3185 g_object_weak_ref (G_OBJECT (contents), (GWeakNotify) g_object_unref, buffer);
3190 /* Provide cut/copied data */
3192 clipboard_get_contents_cb (GtkClipboard *clipboard,
3193 GtkSelectionData *selection_data,
3197 GtkTextBuffer *contents = GTK_TEXT_BUFFER (data);
3199 g_assert (contents); /* This should never be called unless we own the clipboard */
3201 if (info == GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS)
3203 /* Provide the address of the clipboard buffer; this will only
3204 * be used within-process. OK to supply a NULL value for contents.
3206 gtk_selection_data_set (selection_data,
3207 selection_data->target,
3212 else if (info == GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT)
3214 GtkTextBuffer *clipboard_source_buffer;
3215 GtkTextIter start, end;
3219 clipboard_source_buffer = g_object_get_data (G_OBJECT (contents),
3220 "gtk-text-buffer-clipboard-source");
3222 gtk_text_buffer_get_bounds (contents, &start, &end);
3224 str = gtk_text_buffer_serialize (clipboard_source_buffer, contents,
3225 selection_data->target,
3226 &start, &end, &len);
3228 gtk_selection_data_set (selection_data,
3229 selection_data->target,
3237 GtkTextIter start, end;
3239 gtk_text_buffer_get_bounds (contents, &start, &end);
3241 str = gtk_text_iter_get_visible_text (&start, &end);
3242 gtk_selection_data_set_text (selection_data, str, -1);
3248 clipboard_clear_contents_cb (GtkClipboard *clipboard,
3251 GtkTextBuffer *contents = GTK_TEXT_BUFFER (data);
3253 g_object_unref (contents);
3257 get_paste_point (GtkTextBuffer *buffer,
3259 gboolean clear_afterward)
3261 GtkTextIter insert_point;
3262 GtkTextMark *paste_point_override;
3264 paste_point_override = gtk_text_buffer_get_mark (buffer,
3265 "gtk_paste_point_override");
3267 if (paste_point_override != NULL)
3269 gtk_text_buffer_get_iter_at_mark (buffer, &insert_point,
3270 paste_point_override);
3271 if (clear_afterward)
3272 gtk_text_buffer_delete_mark (buffer,
3273 gtk_text_buffer_get_mark (buffer,
3274 "gtk_paste_point_override"));
3278 gtk_text_buffer_get_iter_at_mark (buffer, &insert_point,
3279 gtk_text_buffer_get_insert (buffer));
3282 *iter = insert_point;
3286 pre_paste_prep (ClipboardRequest *request_data,
3287 GtkTextIter *insert_point)
3289 GtkTextBuffer *buffer = request_data->buffer;
3291 get_paste_point (buffer, insert_point, TRUE);
3293 /* If we're going to replace the selection, we insert before it to
3294 * avoid messing it up, then we delete the selection after inserting.
3296 if (request_data->replace_selection)
3298 GtkTextIter start, end;
3300 if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
3301 *insert_point = start;
3306 post_paste_cleanup (ClipboardRequest *request_data)
3308 if (request_data->replace_selection)
3310 GtkTextIter start, end;
3312 if (gtk_text_buffer_get_selection_bounds (request_data->buffer,
3315 if (request_data->interactive)
3316 gtk_text_buffer_delete_interactive (request_data->buffer,
3319 request_data->default_editable);
3321 gtk_text_buffer_delete (request_data->buffer, &start, &end);
3327 emit_paste_done (GtkTextBuffer *buffer,
3328 GtkClipboard *clipboard)
3330 g_signal_emit (buffer, signals[PASTE_DONE], 0, clipboard);
3334 free_clipboard_request (ClipboardRequest *request_data)
3336 g_object_unref (request_data->buffer);
3337 g_free (request_data);
3340 /* Called when we request a paste and receive the text data
3343 clipboard_text_received (GtkClipboard *clipboard,
3347 ClipboardRequest *request_data = data;
3348 GtkTextBuffer *buffer = request_data->buffer;
3352 GtkTextIter insert_point;
3354 if (request_data->interactive)
3355 gtk_text_buffer_begin_user_action (buffer);
3357 pre_paste_prep (request_data, &insert_point);
3359 if (request_data->interactive)
3360 gtk_text_buffer_insert_interactive (buffer, &insert_point,
3361 str, -1, request_data->default_editable);
3363 gtk_text_buffer_insert (buffer, &insert_point,
3366 post_paste_cleanup (request_data);
3368 if (request_data->interactive)
3369 gtk_text_buffer_end_user_action (buffer);
3371 emit_paste_done (buffer, clipboard);
3374 free_clipboard_request (request_data);
3377 static GtkTextBuffer*
3378 selection_data_get_buffer (GtkSelectionData *selection_data,
3379 ClipboardRequest *request_data)
3382 GtkTextBuffer *src_buffer = NULL;
3384 /* If we can get the owner, the selection is in-process */
3385 owner = gdk_selection_owner_get_for_display (selection_data->display,
3386 selection_data->selection);
3391 if (gdk_window_get_window_type (owner) == GDK_WINDOW_FOREIGN)
3394 if (selection_data->type !=
3395 gdk_atom_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS"))
3398 if (selection_data->length != sizeof (src_buffer))
3401 memcpy (&src_buffer, selection_data->data, sizeof (src_buffer));
3403 if (src_buffer == NULL)
3406 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (src_buffer), NULL);
3408 if (gtk_text_buffer_get_tag_table (src_buffer) !=
3409 gtk_text_buffer_get_tag_table (request_data->buffer))
3416 /* These are pretty handy functions; maybe something like them
3417 * should be in the public API. Also, there are other places in this
3418 * file where they could be used.
3421 save_iter (const GtkTextIter *iter,
3422 gboolean left_gravity)
3424 return gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (iter),
3431 restore_iter (const GtkTextIter *iter,
3434 gtk_text_buffer_get_iter_at_mark (gtk_text_mark_get_buffer (save_id),
3435 (GtkTextIter*) iter,
3437 gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (save_id),
3443 clipboard_rich_text_received (GtkClipboard *clipboard,
3449 ClipboardRequest *request_data = data;
3450 GtkTextIter insert_point;
3451 gboolean retval = TRUE;
3452 GError *error = NULL;
3454 if (text != NULL && length > 0)
3456 pre_paste_prep (request_data, &insert_point);
3458 if (request_data->interactive)
3459 gtk_text_buffer_begin_user_action (request_data->buffer);
3461 if (!request_data->interactive ||
3462 gtk_text_iter_can_insert (&insert_point,
3463 request_data->default_editable))
3465 retval = gtk_text_buffer_deserialize (request_data->buffer,
3466 request_data->buffer,
3475 g_warning ("error pasting: %s\n", error->message);
3476 g_clear_error (&error);
3479 if (request_data->interactive)
3480 gtk_text_buffer_end_user_action (request_data->buffer);
3482 emit_paste_done (request_data->buffer, clipboard);
3486 post_paste_cleanup (request_data);
3491 /* Request the text selection instead */
3492 gtk_clipboard_request_text (clipboard,
3493 clipboard_text_received,
3498 paste_from_buffer (GtkClipboard *clipboard,
3499 ClipboardRequest *request_data,
3500 GtkTextBuffer *src_buffer,
3501 const GtkTextIter *start,
3502 const GtkTextIter *end)
3504 GtkTextIter insert_point;
3505 GtkTextBuffer *buffer = request_data->buffer;
3507 /* We're about to emit a bunch of signals, so be safe */
3508 g_object_ref (src_buffer);
3510 pre_paste_prep (request_data, &insert_point);
3512 if (request_data->interactive)
3513 gtk_text_buffer_begin_user_action (buffer);
3515 if (!gtk_text_iter_equal (start, end))
3517 if (!request_data->interactive ||
3518 (gtk_text_iter_can_insert (&insert_point,
3519 request_data->default_editable)))
3520 gtk_text_buffer_real_insert_range (buffer,
3524 request_data->interactive);
3527 post_paste_cleanup (request_data);
3529 if (request_data->interactive)
3530 gtk_text_buffer_end_user_action (buffer);
3532 emit_paste_done (buffer, clipboard);
3534 g_object_unref (src_buffer);
3536 free_clipboard_request (request_data);
3540 clipboard_clipboard_buffer_received (GtkClipboard *clipboard,
3541 GtkSelectionData *selection_data,
3544 ClipboardRequest *request_data = data;
3545 GtkTextBuffer *src_buffer;
3547 src_buffer = selection_data_get_buffer (selection_data, request_data);
3551 GtkTextIter start, end;
3553 if (g_object_get_data (G_OBJECT (src_buffer), "gtk-text-buffer-clipboard"))
3555 gtk_text_buffer_get_bounds (src_buffer, &start, &end);
3557 paste_from_buffer (clipboard, request_data, src_buffer,
3562 if (gtk_text_buffer_get_selection_bounds (src_buffer, &start, &end))
3563 paste_from_buffer (clipboard, request_data, src_buffer,
3569 if (gtk_clipboard_wait_is_rich_text_available (clipboard,
3570 request_data->buffer))
3572 /* Request rich text */
3573 gtk_clipboard_request_rich_text (clipboard,
3574 request_data->buffer,
3575 clipboard_rich_text_received,
3580 /* Request the text selection instead */
3581 gtk_clipboard_request_text (clipboard,
3582 clipboard_text_received,
3590 GtkClipboard *clipboard;
3592 } SelectionClipboard;
3595 update_selection_clipboards (GtkTextBuffer *buffer)
3597 GtkTextBufferPrivate *priv;
3598 GSList *tmp_list = buffer->selection_clipboards;
3600 priv = GTK_TEXT_BUFFER_GET_PRIVATE (buffer);
3602 gtk_text_buffer_get_copy_target_list (buffer);
3609 SelectionClipboard *selection_clipboard = tmp_list->data;
3610 GtkClipboard *clipboard = selection_clipboard->clipboard;
3612 /* Determine whether we have a selection and adjust X selection
3615 if (!gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
3617 if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (buffer))
3618 gtk_clipboard_clear (clipboard);
3622 /* Even if we already have the selection, we need to update our
3625 if (!gtk_clipboard_set_with_owner (clipboard,
3626 priv->copy_target_entries,
3627 priv->n_copy_target_entries,
3628 clipboard_get_selection_cb,
3629 clipboard_clear_selection_cb,
3631 clipboard_clear_selection_cb (clipboard, buffer);
3634 tmp_list = tmp_list->next;
3638 static SelectionClipboard *
3639 find_selection_clipboard (GtkTextBuffer *buffer,
3640 GtkClipboard *clipboard)
3642 GSList *tmp_list = buffer->selection_clipboards;
3645 SelectionClipboard *selection_clipboard = tmp_list->data;
3646 if (selection_clipboard->clipboard == clipboard)
3647 return selection_clipboard;
3649 tmp_list = tmp_list->next;
3656 * gtk_text_buffer_add_selection_clipboard:
3657 * @buffer: a #GtkTextBuffer
3658 * @clipboard: a #GtkClipboard
3660 * Adds @clipboard to the list of clipboards in which the selection
3661 * contents of @buffer are available. In most cases, @clipboard will be
3662 * the #GtkClipboard of type %GDK_SELECTION_PRIMARY for a view of @buffer.
3665 gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer,
3666 GtkClipboard *clipboard)
3668 SelectionClipboard *selection_clipboard;
3670 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
3671 g_return_if_fail (clipboard != NULL);
3673 selection_clipboard = find_selection_clipboard (buffer, clipboard);
3674 if (selection_clipboard)
3676 selection_clipboard->ref_count++;
3680 selection_clipboard = g_new (SelectionClipboard, 1);
3682 selection_clipboard->clipboard = clipboard;
3683 selection_clipboard->ref_count = 1;
3685 buffer->selection_clipboards = g_slist_prepend (buffer->selection_clipboards, selection_clipboard);
3690 * gtk_text_buffer_remove_selection_clipboard:
3691 * @buffer: a #GtkTextBuffer
3692 * @clipboard: a #GtkClipboard added to @buffer by
3693 * gtk_text_buffer_add_selection_clipboard()
3695 * Removes a #GtkClipboard added with
3696 * gtk_text_buffer_add_selection_clipboard().
3699 gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer,
3700 GtkClipboard *clipboard)
3702 SelectionClipboard *selection_clipboard;
3704 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
3705 g_return_if_fail (clipboard != NULL);
3707 selection_clipboard = find_selection_clipboard (buffer, clipboard);
3708 g_return_if_fail (selection_clipboard != NULL);
3710 selection_clipboard->ref_count--;
3711 if (selection_clipboard->ref_count == 0)
3713 if (gtk_clipboard_get_owner (selection_clipboard->clipboard) == G_OBJECT (buffer))
3714 gtk_clipboard_clear (selection_clipboard->clipboard);
3716 buffer->selection_clipboards = g_slist_remove (buffer->selection_clipboards,
3717 selection_clipboard);
3719 g_free (selection_clipboard);
3724 remove_all_selection_clipboards (GtkTextBuffer *buffer)
3726 g_slist_foreach (buffer->selection_clipboards, (GFunc)g_free, NULL);
3727 g_slist_free (buffer->selection_clipboards);
3728 buffer->selection_clipboards = NULL;
3732 * gtk_text_buffer_paste_clipboard:
3733 * @buffer: a #GtkTextBuffer
3734 * @clipboard: the #GtkClipboard to paste from
3735 * @override_location: (allow-none): location to insert pasted text, or %NULL for
3737 * @default_editable: whether the buffer is editable by default
3739 * Pastes the contents of a clipboard at the insertion point, or at
3740 * @override_location. (Note: pasting is asynchronous, that is, we'll
3741 * ask for the paste data and return, and at some point later after
3742 * the main loop runs, the paste data will be inserted.)
3745 gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
3746 GtkClipboard *clipboard,
3747 GtkTextIter *override_location,
3748 gboolean default_editable)
3750 ClipboardRequest *data = g_new (ClipboardRequest, 1);
3751 GtkTextIter paste_point;
3752 GtkTextIter start, end;
3754 if (override_location != NULL)
3755 gtk_text_buffer_create_mark (buffer,
3756 "gtk_paste_point_override",
3757 override_location, FALSE);
3759 data->buffer = g_object_ref (buffer);
3760 data->interactive = TRUE;
3761 data->default_editable = default_editable;
3763 /* When pasting with the cursor inside the selection area, you
3764 * replace the selection with the new text, otherwise, you
3765 * simply insert the new text at the point where the click
3766 * occured, unselecting any selected text. The replace_selection
3767 * flag toggles this behavior.
3769 data->replace_selection = FALSE;
3771 get_paste_point (buffer, &paste_point, FALSE);
3772 if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end) &&
3773 (gtk_text_iter_in_range (&paste_point, &start, &end) ||
3774 gtk_text_iter_equal (&paste_point, &end)))
3775 data->replace_selection = TRUE;
3777 gtk_clipboard_request_contents (clipboard,
3778 gdk_atom_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS"),
3779 clipboard_clipboard_buffer_received, data);
3783 * gtk_text_buffer_delete_selection:
3784 * @buffer: a #GtkTextBuffer
3785 * @interactive: whether the deletion is caused by user interaction
3786 * @default_editable: whether the buffer is editable by default
3788 * Deletes the range between the "insert" and "selection_bound" marks,
3789 * that is, the currently-selected text. If @interactive is %TRUE,
3790 * the editability of the selection will be considered (users can't delete
3793 * Return value: whether there was a non-empty selection to delete
3796 gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
3797 gboolean interactive,
3798 gboolean default_editable)
3803 if (!gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
3805 return FALSE; /* No selection */
3810 gtk_text_buffer_delete_interactive (buffer, &start, &end, default_editable);
3812 gtk_text_buffer_delete (buffer, &start, &end);
3814 return TRUE; /* We deleted stuff */
3819 * gtk_text_buffer_backspace:
3820 * @buffer: a #GtkTextBuffer
3821 * @iter: a position in @buffer
3822 * @interactive: whether the deletion is caused by user interaction
3823 * @default_editable: whether the buffer is editable by default
3825 * Performs the appropriate action as if the user hit the delete
3826 * key with the cursor at the position specified by @iter. In the
3827 * normal case a single character will be deleted, but when
3828 * combining accents are involved, more than one character can
3829 * be deleted, and when precomposed character and accent combinations
3830 * are involved, less than one character will be deleted.
3832 * Because the buffer is modified, all outstanding iterators become
3833 * invalid after calling this function; however, the @iter will be
3834 * re-initialized to point to the location where text was deleted.
3836 * Return value: %TRUE if the buffer was modified
3841 gtk_text_buffer_backspace (GtkTextBuffer *buffer,
3843 gboolean interactive,
3844 gboolean default_editable)
3846 gchar *cluster_text;
3849 gboolean retval = FALSE;
3850 const PangoLogAttr *attrs;
3852 gboolean backspace_deletes_character;
3854 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
3855 g_return_val_if_fail (iter != NULL, FALSE);
3860 attrs = _gtk_text_buffer_get_line_log_attrs (buffer, &start, NULL);
3862 /* For no good reason, attrs is NULL for the empty last line in
3863 * a buffer. Special case that here. (#156164)
3867 offset = gtk_text_iter_get_line_offset (&start);
3868 backspace_deletes_character = attrs[offset].backspace_deletes_character;
3871 backspace_deletes_character = FALSE;
3873 gtk_text_iter_backward_cursor_position (&start);
3875 if (gtk_text_iter_equal (&start, &end))
3878 cluster_text = gtk_text_iter_get_text (&start, &end);
3881 gtk_text_buffer_begin_user_action (buffer);
3883 if (gtk_text_buffer_delete_interactive (buffer, &start, &end,
3886 /* special case \r\n, since we never want to reinsert \r */
3887 if (backspace_deletes_character && strcmp ("\r\n", cluster_text))
3889 gchar *normalized_text = g_utf8_normalize (cluster_text,
3890 strlen (cluster_text),
3892 glong len = g_utf8_strlen (normalized_text, -1);
3895 gtk_text_buffer_insert_interactive (buffer,
3898 g_utf8_offset_to_pointer (normalized_text, len - 1) - normalized_text,
3901 g_free (normalized_text);
3908 gtk_text_buffer_end_user_action (buffer);
3910 g_free (cluster_text);
3912 /* Revalidate the users iter */
3919 cut_or_copy (GtkTextBuffer *buffer,
3920 GtkClipboard *clipboard,
3921 gboolean delete_region_after,
3922 gboolean interactive,
3923 gboolean default_editable)
3925 GtkTextBufferPrivate *priv;
3927 /* We prefer to cut the selected region between selection_bound and
3928 * insertion point. If that region is empty, then we cut the region
3929 * between the "anchor" and the insertion point (this is for
3930 * C-space and M-w and other Emacs-style copy/yank keys). Note that
3931 * insert and selection_bound are guaranteed to exist, but the
3932 * anchor only exists sometimes.
3937 priv = GTK_TEXT_BUFFER_GET_PRIVATE (buffer);
3939 gtk_text_buffer_get_copy_target_list (buffer);
3941 if (!gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
3943 /* Let's try the anchor thing */
3944 GtkTextMark * anchor = gtk_text_buffer_get_mark (buffer, "anchor");
3950 gtk_text_buffer_get_iter_at_mark (buffer, &end, anchor);
3951 gtk_text_iter_order (&start, &end);
3955 if (!gtk_text_iter_equal (&start, &end))
3958 GtkTextBuffer *contents;
3960 contents = create_clipboard_contents_buffer (buffer);
3962 gtk_text_buffer_get_iter_at_offset (contents, &ins, 0);
3964 gtk_text_buffer_insert_range (contents, &ins, &start, &end);
3966 if (!gtk_clipboard_set_with_data (clipboard,
3967 priv->copy_target_entries,
3968 priv->n_copy_target_entries,
3969 clipboard_get_contents_cb,
3970 clipboard_clear_contents_cb,
3972 g_object_unref (contents);
3974 gtk_clipboard_set_can_store (clipboard,
3975 priv->copy_target_entries + 1,
3976 priv->n_copy_target_entries - 1);
3978 if (delete_region_after)
3981 gtk_text_buffer_delete_interactive (buffer, &start, &end,
3984 gtk_text_buffer_delete (buffer, &start, &end);
3990 * gtk_text_buffer_cut_clipboard:
3991 * @buffer: a #GtkTextBuffer
3992 * @clipboard: the #GtkClipboard object to cut to
3993 * @default_editable: default editability of the buffer
3995 * Copies the currently-selected text to a clipboard, then deletes
3996 * said text if it's editable.
3999 gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
4000 GtkClipboard *clipboard,
4001 gboolean default_editable)
4003 gtk_text_buffer_begin_user_action (buffer);
4004 cut_or_copy (buffer, clipboard, TRUE, TRUE, default_editable);
4005 gtk_text_buffer_end_user_action (buffer);
4009 * gtk_text_buffer_copy_clipboard:
4010 * @buffer: a #GtkTextBuffer
4011 * @clipboard: the #GtkClipboard object to copy to
4013 * Copies the currently-selected text to a clipboard.
4016 gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer,
4017 GtkClipboard *clipboard)
4019 cut_or_copy (buffer, clipboard, FALSE, TRUE, TRUE);
4023 * gtk_text_buffer_get_selection_bounds:
4024 * @buffer: a #GtkTextBuffer a #GtkTextBuffer
4025 * @start: iterator to initialize with selection start
4026 * @end: iterator to initialize with selection end
4028 * Returns %TRUE if some text is selected; places the bounds
4029 * of the selection in @start and @end (if the selection has length 0,
4030 * then @start and @end are filled in with the same value).
4031 * @start and @end will be in ascending order. If @start and @end are
4032 * NULL, then they are not filled in, but the return value still indicates
4033 * whether text is selected.
4035 * Return value: whether the selection has nonzero length
4038 gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
4042 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
4044 return _gtk_text_btree_get_selection_bounds (get_btree (buffer), start, end);
4048 * gtk_text_buffer_begin_user_action:
4049 * @buffer: a #GtkTextBuffer
4051 * Called to indicate that the buffer operations between here and a
4052 * call to gtk_text_buffer_end_user_action() are part of a single
4053 * user-visible operation. The operations between
4054 * gtk_text_buffer_begin_user_action() and
4055 * gtk_text_buffer_end_user_action() can then be grouped when creating
4056 * an undo stack. #GtkTextBuffer maintains a count of calls to
4057 * gtk_text_buffer_begin_user_action() that have not been closed with
4058 * a call to gtk_text_buffer_end_user_action(), and emits the
4059 * "begin-user-action" and "end-user-action" signals only for the
4060 * outermost pair of calls. This allows you to build user actions
4061 * from other user actions.
4063 * The "interactive" buffer mutation functions, such as
4064 * gtk_text_buffer_insert_interactive(), automatically call begin/end
4065 * user action around the buffer operations they perform, so there's
4066 * no need to add extra calls if you user action consists solely of a
4067 * single call to one of those functions.
4070 gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer)
4072 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
4074 buffer->user_action_count += 1;
4076 if (buffer->user_action_count == 1)
4078 /* Outermost nested user action begin emits the signal */
4079 g_signal_emit (buffer, signals[BEGIN_USER_ACTION], 0);
4084 * gtk_text_buffer_end_user_action:
4085 * @buffer: a #GtkTextBuffer
4087 * Should be paired with a call to gtk_text_buffer_begin_user_action().
4088 * See that function for a full explanation.
4091 gtk_text_buffer_end_user_action (GtkTextBuffer *buffer)
4093 g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
4094 g_return_if_fail (buffer->user_action_count > 0);
4096 buffer->user_action_count -= 1;
4098 if (buffer->user_action_count == 0)
4100 /* Ended the outermost-nested user action end, so emit the signal */
4101 g_signal_emit (buffer, signals[END_USER_ACTION], 0);
4106 gtk_text_buffer_free_target_lists (GtkTextBuffer *buffer)
4108 GtkTextBufferPrivate *priv = GTK_TEXT_BUFFER_GET_PRIVATE (buffer);
4110 if (priv->copy_target_list)
4112 gtk_target_list_unref (priv->copy_target_list);
4113 priv->copy_target_list = NULL;
4115 gtk_target_table_free (priv->copy_target_entries,
4116 priv->n_copy_target_entries);
4117 priv->copy_target_entries = NULL;
4118 priv->n_copy_target_entries = 0;
4121 if (priv->paste_target_list)
4123 gtk_target_list_unref (priv->paste_target_list);
4124 priv->paste_target_list = NULL;
4126 gtk_target_table_free (priv->paste_target_entries,
4127 priv->n_paste_target_entries);
4128 priv->paste_target_entries = NULL;
4129 priv->n_paste_target_entries = 0;
4133 static GtkTargetList *
4134 gtk_text_buffer_get_target_list (GtkTextBuffer *buffer,
4135 gboolean deserializable,
4136 GtkTargetEntry **entries,
4139 GtkTargetList *target_list;
4141 target_list = gtk_target_list_new (NULL, 0);
4143 gtk_target_list_add (target_list,
4144 gdk_atom_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS"),
4145 GTK_TARGET_SAME_APP,
4146 GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS);
4148 gtk_target_list_add_rich_text_targets (target_list,
4149 GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT,
4153 gtk_target_list_add_text_targets (target_list,
4154 GTK_TEXT_BUFFER_TARGET_INFO_TEXT);
4156 *entries = gtk_target_table_new_from_list (target_list, n_entries);
4162 * gtk_text_buffer_get_copy_target_list:
4163 * @buffer: a #GtkTextBuffer
4165 * This function returns the list of targets this text buffer can
4166 * provide for copying and as DND source. The targets in the list are
4167 * added with %info values from the #GtkTextBufferTargetInfo enum,
4168 * using gtk_target_list_add_rich_text_targets() and
4169 * gtk_target_list_add_text_targets().
4171 * Return value: the #GtkTargetList
4176 gtk_text_buffer_get_copy_target_list (GtkTextBuffer *buffer)
4178 GtkTextBufferPrivate *priv;
4180 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
4182 priv = GTK_TEXT_BUFFER_GET_PRIVATE (buffer);
4184 if (! priv->copy_target_list)
4185 priv->copy_target_list =
4186 gtk_text_buffer_get_target_list (buffer, FALSE,
4187 &priv->copy_target_entries,
4188 &priv->n_copy_target_entries);
4190 return priv->copy_target_list;
4194 * gtk_text_buffer_get_paste_target_list:
4195 * @buffer: a #GtkTextBuffer
4197 * This function returns the list of targets this text buffer supports
4198 * for pasting and as DND destination. The targets in the list are
4199 * added with %info values from the #GtkTextBufferTargetInfo enum,
4200 * using gtk_target_list_add_rich_text_targets() and
4201 * gtk_target_list_add_text_targets().
4203 * Return value: the #GtkTargetList
4208 gtk_text_buffer_get_paste_target_list (GtkTextBuffer *buffer)
4210 GtkTextBufferPrivate *priv;
4212 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
4214 priv = GTK_TEXT_BUFFER_GET_PRIVATE (buffer);
4216 if (! priv->paste_target_list)
4217 priv->paste_target_list =
4218 gtk_text_buffer_get_target_list (buffer, TRUE,
4219 &priv->paste_target_entries,
4220 &priv->n_paste_target_entries);
4222 return priv->paste_target_list;
4226 * Logical attribute cache
4229 #define ATTR_CACHE_SIZE 2
4231 typedef struct _CacheEntry CacheEntry;
4236 PangoLogAttr *attrs;
4239 struct _GtkTextLogAttrCache
4241 gint chars_changed_stamp;
4242 CacheEntry entries[ATTR_CACHE_SIZE];
4246 free_log_attr_cache (GtkTextLogAttrCache *cache)
4249 while (i < ATTR_CACHE_SIZE)
4251 g_free (cache->entries[i].attrs);
4258 clear_log_attr_cache (GtkTextLogAttrCache *cache)
4261 while (i < ATTR_CACHE_SIZE)
4263 g_free (cache->entries[i].attrs);
4264 cache->entries[i].attrs = NULL;
4269 static PangoLogAttr*
4270 compute_log_attrs (const GtkTextIter *iter,
4276 gint char_len, byte_len;
4277 PangoLogAttr *attrs = NULL;
4282 gtk_text_iter_set_line_offset (&start, 0);
4283 gtk_text_iter_forward_line (&end);
4285 paragraph = gtk_text_iter_get_slice (&start, &end);
4286 char_len = g_utf8_strlen (paragraph, -1);
4287 byte_len = strlen (paragraph);
4289 g_assert (char_len > 0);
4292 *char_lenp = char_len;
4294 attrs = g_new (PangoLogAttr, char_len + 1);
4296 /* FIXME we need to follow PangoLayout and allow different language
4297 * tags within the paragraph
4299 pango_get_log_attrs (paragraph, byte_len, -1,
4300 gtk_text_iter_get_language (&start),
4309 /* The return value from this is valid until you call this a second time.
4312 _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
4313 const GtkTextIter *anywhere_in_line,
4317 GtkTextLogAttrCache *cache;
4320 g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
4321 g_return_val_if_fail (anywhere_in_line != NULL, NULL);
4323 /* special-case for empty last line in buffer */
4324 if (gtk_text_iter_is_end (anywhere_in_line) &&
4325 gtk_text_iter_get_line_offset (anywhere_in_line) == 0)
4332 /* FIXME we also need to recompute log attrs if the language tag at
4333 * the start of a paragraph changes
4336 if (buffer->log_attr_cache == NULL)
4338 buffer->log_attr_cache = g_new0 (GtkTextLogAttrCache, 1);
4339 buffer->log_attr_cache->chars_changed_stamp =
4340 _gtk_text_btree_get_chars_changed_stamp (get_btree (buffer));
4342 else if (buffer->log_attr_cache->chars_changed_stamp !=
4343 _gtk_text_btree_get_chars_changed_stamp (get_btree (buffer)))
4345 clear_log_attr_cache (buffer->log_attr_cache);
4348 cache = buffer->log_attr_cache;
4349 line = gtk_text_iter_get_line (anywhere_in_line);
4352 while (i < ATTR_CACHE_SIZE)
4354 if (cache->entries[i].attrs &&
4355 cache->entries[i].line == line)
4358 *char_len = cache->entries[i].char_len;
4359 return cache->entries[i].attrs;
4364 /* Not in cache; open up the first cache entry */
4365 g_free (cache->entries[ATTR_CACHE_SIZE-1].attrs);
4367 g_memmove (cache->entries + 1, cache->entries,
4368 sizeof (CacheEntry) * (ATTR_CACHE_SIZE - 1));
4370 cache->entries[0].line = line;
4371 cache->entries[0].attrs = compute_log_attrs (anywhere_in_line,
4372 &cache->entries[0].char_len);
4375 *char_len = cache->entries[0].char_len;
4377 return cache->entries[0].attrs;
4381 _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,
4384 /* This removes tag from the buffer, but DOESN'T emit the
4385 * remove-tag signal, because we can't afford to have user
4386 * code messing things up at this point; the tag MUST be removed
4390 _gtk_text_btree_notify_will_remove_tag (buffer->btree, tag);
4398 _gtk_text_buffer_spew (GtkTextBuffer *buffer)
4400 _gtk_text_btree_spew (get_btree (buffer));
4403 #define __GTK_TEXT_BUFFER_C__
4404 #include "gtkaliasdef.c"