Top |
Functions
Properties
gboolean | can-redo | Read |
gboolean | can-undo | Read |
int | cursor-position | Read |
gboolean | enable-undo | Read / Write |
gboolean | has-selection | Read |
GtkTextTagTable * | tag-table | Read / Write / Construct Only |
char * | text | Read / Write |
Signals
void | apply-tag | Run Last |
void | begin-user-action | Run Last |
void | changed | Run Last |
void | delete-range | Run Last |
void | end-user-action | Run Last |
void | insert-child-anchor | Run Last |
void | insert-paintable | Run Last |
void | insert-text | Run Last |
void | mark-deleted | Run Last |
void | mark-set | Run Last |
void | modified-changed | Run Last |
void | paste-done | Run Last |
void | redo | Run Last |
void | remove-tag | Run Last |
void | undo | Run Last |
Description
You may wish to begin by reading the text widget conceptual overview which gives an overview of all the objects and data types related to the text widget and how they work together.
Functions
gtk_text_buffer_new ()
GtkTextBuffer *
gtk_text_buffer_new (GtkTextTagTable *table
);
Creates a new text buffer.
gtk_text_buffer_get_line_count ()
int
gtk_text_buffer_get_line_count (GtkTextBuffer *buffer
);
Obtains the number of lines in the buffer. This value is cached, so the function is very fast.
gtk_text_buffer_get_char_count ()
int
gtk_text_buffer_get_char_count (GtkTextBuffer *buffer
);
Gets the number of characters in the buffer; note that characters and bytes are not the same, you can’t e.g. expect the contents of the buffer in string form to be this many bytes long. The character count is cached, so this function is very fast.
gtk_text_buffer_get_tag_table ()
GtkTextTagTable *
gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer
);
Get the GtkTextTagTable associated with this buffer.
gtk_text_buffer_insert ()
void gtk_text_buffer_insert (GtkTextBuffer *buffer
,GtkTextIter *iter
,const char *text
,int len
);
Inserts len
bytes of text
at position iter
. If len
is -1,
text
must be nul-terminated and will be inserted in its
entirety. Emits the “insert-text” signal; insertion actually occurs
in the default handler for the signal. iter
is invalidated when
insertion occurs (because the buffer contents change), but the
default signal handler revalidates it to point to the end of the
inserted text.
gtk_text_buffer_insert_at_cursor ()
void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer
,const char *text
,int len
);
Simply calls gtk_text_buffer_insert()
, using the current
cursor position as the insertion point.
gtk_text_buffer_insert_interactive ()
gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer
,GtkTextIter *iter
,const char *text
,int len
,gboolean default_editable
);
Like gtk_text_buffer_insert()
, but the insertion will not occur if
iter
is at a non-editable location in the buffer. Usually you
want to prevent insertions at ineditable locations if the insertion
results from a user action (is interactive).
default_editable
indicates the editability of text that doesn't
have a tag affecting editability applied to it. Typically the
result of gtk_text_view_get_editable()
is appropriate here.
gtk_text_buffer_insert_interactive_at_cursor ()
gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer
,const char *text
,int len
,gboolean default_editable
);
Calls gtk_text_buffer_insert_interactive()
at the cursor
position.
default_editable
indicates the editability of text that doesn't
have a tag affecting editability applied to it. Typically the
result of gtk_text_view_get_editable()
is appropriate here.
gtk_text_buffer_insert_range ()
void gtk_text_buffer_insert_range (GtkTextBuffer *buffer
,GtkTextIter *iter
,const GtkTextIter *start
,const GtkTextIter *end
);
Copies text, tags, and paintables between start
and end
(the order
of start
and end
doesn’t matter) and inserts the copy at iter
.
Used instead of simply getting/inserting text because it preserves
images and tags. If start
and end
are in a different buffer from
buffer
, the two buffers must share the same tag table.
Implemented via emissions of the insert_text and apply_tag signals, so expect those.
Parameters
buffer |
||
iter |
a position in |
|
start |
a position in a GtkTextBuffer |
|
end |
another position in the same buffer as |
gtk_text_buffer_insert_range_interactive ()
gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer
,GtkTextIter *iter
,const GtkTextIter *start
,const GtkTextIter *end
,gboolean default_editable
);
Same as gtk_text_buffer_insert_range()
, but does nothing if the
insertion point isn’t editable. The default_editable
parameter
indicates whether the text is editable at iter
if no tags
enclosing iter
affect editability. Typically the result of
gtk_text_view_get_editable()
is appropriate here.
Parameters
buffer |
||
iter |
a position in |
|
start |
a position in a GtkTextBuffer |
|
end |
another position in the same buffer as |
|
default_editable |
default editability of the buffer |
gtk_text_buffer_insert_with_tags ()
void gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer
,GtkTextIter *iter
,const char *text
,int len
,GtkTextTag *first_tag
,...
);
Inserts text
into buffer
at iter
, applying the list of tags to
the newly-inserted text. The last tag specified must be NULL
to
terminate the list. Equivalent to calling gtk_text_buffer_insert()
,
then gtk_text_buffer_apply_tag()
on the inserted text;
gtk_text_buffer_insert_with_tags()
is just a convenience function.
gtk_text_buffer_insert_with_tags_by_name ()
void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer
,GtkTextIter *iter
,const char *text
,int len
,const char *first_tag_name
,...
);
Same as gtk_text_buffer_insert_with_tags()
, but allows you
to pass in tag names instead of tag objects.
gtk_text_buffer_insert_markup ()
void gtk_text_buffer_insert_markup (GtkTextBuffer *buffer
,GtkTextIter *iter
,const char *markup
,int len
);
Inserts the text in markup
at position iter
. markup
will be inserted
in its entirety and must be nul-terminated and valid UTF-8. Emits the
“insert-text” signal, possibly multiple times; insertion
actually occurs in the default handler for the signal. iter
will point
to the end of the inserted text on return.
gtk_text_buffer_insert_paintable ()
void gtk_text_buffer_insert_paintable (GtkTextBuffer *buffer
,GtkTextIter *iter
,GdkPaintable *paintable
);
Inserts an image into the text buffer at iter
. The image will be
counted as one character in character counts, and when obtaining
the buffer contents as a string, will be represented by the Unicode
“object replacement character” 0xFFFC. Note that the “slice”
variants for obtaining portions of the buffer as a string include
this character for paintable, but the “text” variants do
not. e.g. see gtk_text_buffer_get_slice()
and
gtk_text_buffer_get_text()
.
gtk_text_buffer_delete ()
void gtk_text_buffer_delete (GtkTextBuffer *buffer
,GtkTextIter *start
,GtkTextIter *end
);
Deletes text between start
and end
. The order of start
and end
is not actually relevant; gtk_text_buffer_delete()
will reorder
them. This function actually emits the “delete-range” signal, and
the default handler of that signal deletes the text. Because the
buffer is modified, all outstanding iterators become invalid after
calling this function; however, the start
and end
will be
re-initialized to point to the location where text was deleted.
gtk_text_buffer_delete_interactive ()
gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer
,GtkTextIter *start_iter
,GtkTextIter *end_iter
,gboolean default_editable
);
Deletes all editable text in the given range.
Calls gtk_text_buffer_delete()
for each editable sub-range of
[start
,end
). start
and end
are revalidated to point to
the location of the last deleted range, or left untouched if
no text was deleted.
gtk_text_buffer_backspace ()
gboolean gtk_text_buffer_backspace (GtkTextBuffer *buffer
,GtkTextIter *iter
,gboolean interactive
,gboolean default_editable
);
Performs the appropriate action as if the user hit the delete
key with the cursor at the position specified by iter
. In the
normal case a single character will be deleted, but when
combining accents are involved, more than one character can
be deleted, and when precomposed character and accent combinations
are involved, less than one character will be deleted.
Because the buffer is modified, all outstanding iterators become
invalid after calling this function; however, the iter
will be
re-initialized to point to the location where text was deleted.
gtk_text_buffer_set_text ()
void gtk_text_buffer_set_text (GtkTextBuffer *buffer
,const char *text
,int len
);
Deletes current contents of buffer
, and inserts text
instead. If
len
is -1, text
must be nul-terminated. text
must be valid UTF-8.
gtk_text_buffer_get_text ()
char * gtk_text_buffer_get_text (GtkTextBuffer *buffer
,const GtkTextIter *start
,const GtkTextIter *end
,gboolean include_hidden_chars
);
Returns the text in the range [start
,end
). Excludes undisplayed
text (text marked with tags that set the invisibility attribute) if
include_hidden_chars
is FALSE
. Does not include characters
representing embedded images, so byte and character indexes into
the returned string do not correspond to byte
and character indexes into the buffer. Contrast with
gtk_text_buffer_get_slice()
.
gtk_text_buffer_get_slice ()
char * gtk_text_buffer_get_slice (GtkTextBuffer *buffer
,const GtkTextIter *start
,const GtkTextIter *end
,gboolean include_hidden_chars
);
Returns the text in the range [start
,end
). Excludes undisplayed
text (text marked with tags that set the invisibility attribute) if
include_hidden_chars
is FALSE
. The returned string includes a
0xFFFC character whenever the buffer contains
embedded images, so byte and character indexes into
the returned string do correspond to byte
and character indexes into the buffer. Contrast with
gtk_text_buffer_get_text()
. Note that 0xFFFC can occur in normal
text as well, so it is not a reliable indicator that a paintable or
widget is in the buffer.
gtk_text_buffer_insert_child_anchor ()
void gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer
,GtkTextIter *iter
,GtkTextChildAnchor *anchor
);
Inserts a child widget anchor into the text buffer at iter
. The
anchor will be counted as one character in character counts, and
when obtaining the buffer contents as a string, will be represented
by the Unicode “object replacement character” 0xFFFC. Note that the
“slice” variants for obtaining portions of the buffer as a string
include this character for child anchors, but the “text” variants do
not. E.g. see gtk_text_buffer_get_slice()
and
gtk_text_buffer_get_text()
. Consider
gtk_text_buffer_create_child_anchor()
as a more convenient
alternative to this function. The buffer will add a reference to
the anchor, so you can unref it after insertion.
gtk_text_buffer_create_child_anchor ()
GtkTextChildAnchor * gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer
,GtkTextIter *iter
);
This is a convenience function which simply creates a child anchor
with gtk_text_child_anchor_new()
and inserts it into the buffer
with gtk_text_buffer_insert_child_anchor()
. The new anchor is
owned by the buffer; no reference count is returned to
the caller of gtk_text_buffer_create_child_anchor()
.
gtk_text_buffer_create_mark ()
GtkTextMark * gtk_text_buffer_create_mark (GtkTextBuffer *buffer
,const char *mark_name
,const GtkTextIter *where
,gboolean left_gravity
);
Creates a mark at position where
. If mark_name
is NULL
, the mark
is anonymous; otherwise, the mark can be retrieved by name using
gtk_text_buffer_get_mark()
. If a mark has left gravity, and text is
inserted at the mark’s current location, the mark will be moved to
the left of the newly-inserted text. If the mark has right gravity
(left_gravity
= FALSE
), the mark will end up on the right of
newly-inserted text. The standard left-to-right cursor is a mark
with right gravity (when you type, the cursor stays on the right
side of the text you’re typing).
The caller of this function does not own a reference to the returned GtkTextMark, so you can ignore the return value if you like. Marks are owned by the buffer and go away when the buffer does.
Emits the “mark-set” signal as notification of the mark's initial placement.
gtk_text_buffer_move_mark ()
void gtk_text_buffer_move_mark (GtkTextBuffer *buffer
,GtkTextMark *mark
,const GtkTextIter *where
);
Moves mark
to the new location where
. Emits the “mark-set”
signal as notification of the move.
gtk_text_buffer_move_mark_by_name ()
void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer
,const char *name
,const GtkTextIter *where
);
Moves the mark named name
(which must exist) to location where
.
See gtk_text_buffer_move_mark()
for details.
gtk_text_buffer_add_mark ()
void gtk_text_buffer_add_mark (GtkTextBuffer *buffer
,GtkTextMark *mark
,const GtkTextIter *where
);
Adds the mark at position where
. The mark must not be added to
another buffer, and if its name is not NULL
then there must not
be another mark in the buffer with the same name.
Emits the “mark-set” signal as notification of the mark's initial placement.
gtk_text_buffer_delete_mark ()
void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer
,GtkTextMark *mark
);
Deletes mark
, so that it’s no longer located anywhere in the
buffer. Removes the reference the buffer holds to the mark, so if
you haven’t called g_object_ref()
on the mark, it will be freed. Even
if the mark isn’t freed, most operations on mark
become
invalid, until it gets added to a buffer again with
gtk_text_buffer_add_mark()
. Use gtk_text_mark_get_deleted()
to
find out if a mark has been removed from its buffer.
The “mark-deleted” signal will be emitted as notification after
the mark is deleted.
gtk_text_buffer_delete_mark_by_name ()
void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer
,const char *name
);
Deletes the mark named name
; the mark must exist. See
gtk_text_buffer_delete_mark()
for details.
gtk_text_buffer_get_mark ()
GtkTextMark * gtk_text_buffer_get_mark (GtkTextBuffer *buffer
,const char *name
);
Returns the mark named name
in buffer buffer
, or NULL
if no such
mark exists in the buffer.
gtk_text_buffer_get_insert ()
GtkTextMark *
gtk_text_buffer_get_insert (GtkTextBuffer *buffer
);
Returns the mark that represents the cursor (insertion point).
Equivalent to calling gtk_text_buffer_get_mark()
to get the mark
named “insert”, but very slightly more efficient, and involves less
typing.
gtk_text_buffer_get_selection_bound ()
GtkTextMark *
gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer
);
Returns the mark that represents the selection bound. Equivalent
to calling gtk_text_buffer_get_mark()
to get the mark named
“selection_bound”, but very slightly more efficient, and involves
less typing.
The currently-selected text in buffer
is the region between the
“selection_bound” and “insert” marks. If “selection_bound” and
“insert” are in the same place, then there is no current selection.
gtk_text_buffer_get_selection_bounds()
is another convenient function
for handling the selection, if you just want to know whether there’s a
selection and what its bounds are.
gtk_text_buffer_get_has_selection ()
gboolean
gtk_text_buffer_get_has_selection (GtkTextBuffer *buffer
);
Indicates whether the buffer has some text currently selected.
gtk_text_buffer_place_cursor ()
void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer
,const GtkTextIter *where
);
This function moves the “insert” and “selection_bound” marks
simultaneously. If you move them to the same place in two steps
with gtk_text_buffer_move_mark()
, you will temporarily select a
region in between their old and new locations, which can be pretty
inefficient since the temporarily-selected region will force stuff
to be recalculated. This function moves them as a unit, which can
be optimized.
gtk_text_buffer_select_range ()
void gtk_text_buffer_select_range (GtkTextBuffer *buffer
,const GtkTextIter *ins
,const GtkTextIter *bound
);
This function moves the “insert” and “selection_bound” marks
simultaneously. If you move them in two steps
with gtk_text_buffer_move_mark()
, you will temporarily select a
region in between their old and new locations, which can be pretty
inefficient since the temporarily-selected region will force stuff
to be recalculated. This function moves them as a unit, which can
be optimized.
gtk_text_buffer_apply_tag ()
void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer
,GtkTextTag *tag
,const GtkTextIter *start
,const GtkTextIter *end
);
Emits the “apply-tag” signal on buffer
. The default
handler for the signal applies tag
to the given range.
start
and end
do not have to be in order.
gtk_text_buffer_remove_tag ()
void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer
,GtkTextTag *tag
,const GtkTextIter *start
,const GtkTextIter *end
);
Emits the “remove-tag” signal. The default handler for the signal
removes all occurrences of tag
from the given range. start
and
end
don’t have to be in order.
gtk_text_buffer_apply_tag_by_name ()
void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer
,const char *name
,const GtkTextIter *start
,const GtkTextIter *end
);
Calls gtk_text_tag_table_lookup()
on the buffer’s tag table to
get a GtkTextTag, then calls gtk_text_buffer_apply_tag()
.
Parameters
buffer |
||
name |
name of a named GtkTextTag |
|
start |
one bound of range to be tagged |
|
end |
other bound of range to be tagged |
gtk_text_buffer_remove_tag_by_name ()
void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer
,const char *name
,const GtkTextIter *start
,const GtkTextIter *end
);
Calls gtk_text_tag_table_lookup()
on the buffer’s tag table to
get a GtkTextTag, then calls gtk_text_buffer_remove_tag()
.
Parameters
buffer |
||
name |
name of a GtkTextTag |
|
start |
one bound of range to be untagged |
|
end |
other bound of range to be untagged |
gtk_text_buffer_remove_all_tags ()
void gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer
,const GtkTextIter *start
,const GtkTextIter *end
);
Removes all tags in the range between start
and end
. Be careful
with this function; it could remove tags added in code unrelated to
the code you’re currently writing. That is, using this function is
probably a bad idea if you have two or more unrelated code sections
that add tags.
gtk_text_buffer_create_tag ()
GtkTextTag * gtk_text_buffer_create_tag (GtkTextBuffer *buffer
,const char *tag_name
,const char *first_property_name
,...
);
Creates a tag and adds it to the tag table for buffer
.
Equivalent to calling gtk_text_tag_new()
and then adding the
tag to the buffer’s tag table. The returned tag is owned by
the buffer’s tag table, so the ref count will be equal to one.
If tag_name
is NULL
, the tag is anonymous.
If tag_name
is non-NULL
, a tag called tag_name
must not already
exist in the tag table for this buffer.
The first_property_name
argument and subsequent arguments are a list
of properties to set on the tag, as with g_object_set()
.
gtk_text_buffer_get_iter_at_line_offset ()
gboolean gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer
,GtkTextIter *iter
,int line_number
,int char_offset
);
Obtains an iterator pointing to char_offset
within the given line. Note
characters, not bytes; UTF-8 may encode one character as multiple bytes.
Before the 3.20 version, it was not allowed to pass an invalid location.
If line_number
is greater than the number of lines
in the buffer
, the end iterator is returned. And if char_offset
is off the
end of the line, the iterator at the end of the line is returned.
gtk_text_buffer_get_iter_at_offset ()
void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer
,GtkTextIter *iter
,int char_offset
);
Initializes iter
to a position char_offset
chars from the start
of the entire buffer. If char_offset
is -1 or greater than the number
of characters in the buffer, iter
is initialized to the end iterator,
the iterator one past the last valid character in the buffer.
gtk_text_buffer_get_iter_at_line ()
gboolean gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer
,GtkTextIter *iter
,int line_number
);
Initializes iter
to the start of the given line. If line_number
is greater
than the number of lines in the buffer
, the end iterator is returned.
gtk_text_buffer_get_iter_at_line_index ()
gboolean gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer
,GtkTextIter *iter
,int line_number
,int byte_index
);
Obtains an iterator pointing to byte_index
within the given line.
byte_index
must be the start of a UTF-8 character. Note bytes, not
characters; UTF-8 may encode one character as multiple bytes.
If line_number
is greater than the number of lines
in the buffer
, the end iterator is returned. And if byte_index
is off the
end of the line, the iterator at the end of the line is returned.
gtk_text_buffer_get_iter_at_mark ()
void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer
,GtkTextIter *iter
,GtkTextMark *mark
);
Initializes iter
with the current position of mark
.
gtk_text_buffer_get_iter_at_child_anchor ()
void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer
,GtkTextIter *iter
,GtkTextChildAnchor *anchor
);
Obtains the location of anchor
within buffer
.
gtk_text_buffer_get_start_iter ()
void gtk_text_buffer_get_start_iter (GtkTextBuffer *buffer
,GtkTextIter *iter
);
Initialized iter
with the first position in the text buffer. This
is the same as using gtk_text_buffer_get_iter_at_offset()
to get
the iter at character offset 0.
gtk_text_buffer_get_end_iter ()
void gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer
,GtkTextIter *iter
);
Initializes iter
with the “end iterator,” one past the last valid
character in the text buffer. If dereferenced with
gtk_text_iter_get_char()
, the end iterator has a character value of 0.
The entire buffer lies in the range from the first position in
the buffer (call gtk_text_buffer_get_start_iter()
to get
character position 0) to the end iterator.
gtk_text_buffer_get_bounds ()
void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer
,GtkTextIter *start
,GtkTextIter *end
);
Retrieves the first and last iterators in the buffer, i.e. the
entire buffer lies within the range [start
,end
).
gtk_text_buffer_get_modified ()
gboolean
gtk_text_buffer_get_modified (GtkTextBuffer *buffer
);
Indicates whether the buffer has been modified since the last call
to gtk_text_buffer_set_modified()
set the modification flag to
FALSE
. Used for example to enable a “save” function in a text
editor.
gtk_text_buffer_set_modified ()
void gtk_text_buffer_set_modified (GtkTextBuffer *buffer
,gboolean setting
);
Used to keep track of whether the buffer has been modified since the
last time it was saved. Whenever the buffer is saved to disk, call
gtk_text_buffer_set_modified (buffer
, FALSE). When the buffer is modified,
it will automatically toggled on the modified bit again. When the modified
bit flips, the buffer emits the “modified-changed” signal.
gtk_text_buffer_delete_selection ()
gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer
,gboolean interactive
,gboolean default_editable
);
Deletes the range between the “insert” and “selection_bound” marks,
that is, the currently-selected text. If interactive
is TRUE
,
the editability of the selection will be considered (users can’t delete
uneditable text).
gtk_text_buffer_paste_clipboard ()
void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer
,GdkClipboard *clipboard
,GtkTextIter *override_location
,gboolean default_editable
);
Pastes the contents of a clipboard. If override_location
is NULL
, the
pasted text will be inserted at the cursor position, or the buffer selection
will be replaced if the selection is non-empty.
Note: pasting is asynchronous, that is, we’ll ask for the paste data and return, and at some point later after the main loop runs, the paste data will be inserted.
Parameters
buffer |
||
clipboard |
the GdkClipboard to paste from |
|
override_location |
location to insert pasted text, or |
[allow-none] |
default_editable |
whether the buffer is editable by default |
gtk_text_buffer_copy_clipboard ()
void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer
,GdkClipboard *clipboard
);
Copies the currently-selected text to a clipboard.
gtk_text_buffer_cut_clipboard ()
void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer
,GdkClipboard *clipboard
,gboolean default_editable
);
Copies the currently-selected text to a clipboard, then deletes said text if it’s editable.
Parameters
buffer |
||
clipboard |
the GdkClipboard object to cut to |
|
default_editable |
default editability of the buffer |
gtk_text_buffer_get_selection_bounds ()
gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer
,GtkTextIter *start
,GtkTextIter *end
);
Returns TRUE
if some text is selected; places the bounds
of the selection in start
and end
(if the selection has length 0,
then start
and end
are filled in with the same value).
start
and end
will be in ascending order. If start
and end
are
NULL, then they are not filled in, but the return value still indicates
whether text is selected.
gtk_text_buffer_get_selection_content ()
GdkContentProvider *
gtk_text_buffer_get_selection_content (GtkTextBuffer *buffer
);
Get a content provider for this buffer. It can be
used to make the content of buffer
available in a
GdkClipboard, see gdk_clipboard_set_content()
.
gtk_text_buffer_begin_user_action ()
void
gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer
);
Called to indicate that the buffer operations between here and a
call to gtk_text_buffer_end_user_action()
are part of a single
user-visible operation. The operations between
gtk_text_buffer_begin_user_action()
and
gtk_text_buffer_end_user_action()
can then be grouped when creating
an undo stack. GtkTextBuffer maintains a count of calls to
gtk_text_buffer_begin_user_action()
that have not been closed with
a call to gtk_text_buffer_end_user_action()
, and emits the
“begin-user-action” and “end-user-action” signals only for the
outermost pair of calls. This allows you to build user actions
from other user actions.
The “interactive” buffer mutation functions, such as
gtk_text_buffer_insert_interactive()
, automatically call begin/end
user action around the buffer operations they perform, so there's
no need to add extra calls if you user action consists solely of a
single call to one of those functions.
gtk_text_buffer_end_user_action ()
void
gtk_text_buffer_end_user_action (GtkTextBuffer *buffer
);
Should be paired with a call to gtk_text_buffer_begin_user_action()
.
See that function for a full explanation.
gtk_text_buffer_add_selection_clipboard ()
void gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer
,GdkClipboard *clipboard
);
Adds clipboard
to the list of clipboards in which the selection
contents of buffer
are available. In most cases, clipboard
will be
the GdkClipboard returned by gtk_widget_get_primary_clipboard()
for a view of buffer
.
gtk_text_buffer_remove_selection_clipboard ()
void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer
,GdkClipboard *clipboard
);
Removes a GdkClipboard added with
gtk_text_buffer_add_selection_clipboard()
.
Parameters
buffer |
||
clipboard |
a GdkClipboard added to |
gtk_text_buffer_get_can_undo ()
gboolean
gtk_text_buffer_get_can_undo (GtkTextBuffer *buffer
);
Gets whether there is an undoable action in the history.
gtk_text_buffer_get_can_redo ()
gboolean
gtk_text_buffer_get_can_redo (GtkTextBuffer *buffer
);
Gets whether there is a redoable action in the history.
gtk_text_buffer_get_enable_undo ()
gboolean
gtk_text_buffer_get_enable_undo (GtkTextBuffer *buffer
);
Gets whether the buffer is saving modifications to the buffer to allow for undo and redo actions.
See gtk_text_buffer_begin_irreversible_action()
and
gtk_text_buffer_end_irreversible_action()
to create changes to the buffer
that cannot be undone.
gtk_text_buffer_set_enable_undo ()
void gtk_text_buffer_set_enable_undo (GtkTextBuffer *buffer
,gboolean enable_undo
);
Sets whether or not to enable undoable actions in the text buffer. If
enabled, the user will be able to undo the last number of actions up to
gtk_text_buffer_get_max_undo_levels()
.
See gtk_text_buffer_begin_irreversible_action()
and
gtk_text_buffer_end_irreversible_action()
to create changes to the buffer
that cannot be undone.
gtk_text_buffer_get_max_undo_levels ()
guint
gtk_text_buffer_get_max_undo_levels (GtkTextBuffer *buffer
);
Gets the maximum number of undo levels to perform. If 0, unlimited undo actions may be performed. Note that this may have a memory usage impact as it requires storing an additional copy of the inserted or removed text within the text buffer.
gtk_text_buffer_set_max_undo_levels ()
void gtk_text_buffer_set_max_undo_levels (GtkTextBuffer *buffer
,guint max_undo_levels
);
Sets the maximum number of undo levels to perform. If 0, unlimited undo actions may be performed. Note that this may have a memory usage impact as it requires storing an additional copy of the inserted or removed text within the text buffer.
gtk_text_buffer_undo ()
void
gtk_text_buffer_undo (GtkTextBuffer *buffer
);
Undoes the last undoable action on the buffer, if there is one.
gtk_text_buffer_redo ()
void
gtk_text_buffer_redo (GtkTextBuffer *buffer
);
Redoes the next redoable action on the buffer, if there is one.
gtk_text_buffer_begin_irreversible_action ()
void
gtk_text_buffer_begin_irreversible_action
(GtkTextBuffer *buffer
);
Denotes the beginning of an action that may not be undone. This will cause any previous operations in the undo/redo queue to be cleared.
This should be paired with a call to
gtk_text_buffer_end_irreversible_action()
after the irreversible action
has completed.
You may nest calls to gtk_text_buffer_begin_irreversible_action()
and
gtk_text_buffer_end_irreversible_action()
pairs.
gtk_text_buffer_end_irreversible_action ()
void
gtk_text_buffer_end_irreversible_action
(GtkTextBuffer *buffer
);
Denotes the end of an action that may not be undone. This will cause any previous operations in the undo/redo queue to be cleared.
This should be called after completing modifications to the text buffer
after gtk_text_buffer_begin_irreversible_action()
was called.
You may nest calls to gtk_text_buffer_begin_irreversible_action()
and
gtk_text_buffer_end_irreversible_action()
pairs.
Types and Values
struct GtkTextBufferClass
struct GtkTextBufferClass { GObjectClass parent_class; void (* insert_text) (GtkTextBuffer *buffer, GtkTextIter *pos, const char *new_text, int new_text_length); void (* insert_paintable) (GtkTextBuffer *buffer, GtkTextIter *iter, GdkPaintable *paintable); void (* insert_child_anchor) (GtkTextBuffer *buffer, GtkTextIter *iter, GtkTextChildAnchor *anchor); void (* delete_range) (GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end); void (* changed) (GtkTextBuffer *buffer); void (* modified_changed) (GtkTextBuffer *buffer); void (* mark_set) (GtkTextBuffer *buffer, const GtkTextIter *location, GtkTextMark *mark); void (* mark_deleted) (GtkTextBuffer *buffer, GtkTextMark *mark); void (* apply_tag) (GtkTextBuffer *buffer, GtkTextTag *tag, const GtkTextIter *start, const GtkTextIter *end); void (* remove_tag) (GtkTextBuffer *buffer, GtkTextTag *tag, const GtkTextIter *start, const GtkTextIter *end); void (* begin_user_action) (GtkTextBuffer *buffer); void (* end_user_action) (GtkTextBuffer *buffer); void (* paste_done) (GtkTextBuffer *buffer, GdkClipboard *clipboard); void (* undo) (GtkTextBuffer *buffer); void (* redo) (GtkTextBuffer *buffer); };
The class structure for GtkTextBuffer.
Members
The class handler for the “insert-text” signal. |
||
The class handler for the “insert-paintable” signal. |
||
The class handler for the “insert-child-anchor” signal. |
||
The class handler for the “delete-range” signal. |
||
The class handler for the “changed” signal. |
||
The class handler for the “modified-changed” signal. |
||
The class handler for the “mark-set” signal. |
||
The class handler for the “mark-deleted” signal. |
||
The class handler for the “apply-tag” signal. |
||
The class handler for the “remove-tag” signal. |
||
The class handler for the “begin-user-action” signal. |
||
The class handler for the “end-user-action” signal. |
||
The class handler for the “paste-done” signal. |
||
The class handler for the “undo” signal |
||
The class handler for the “redo” signal |
Property Details
The “can-redo”
property
“can-redo” gboolean
The “can-redo” property denotes that the buffer can reapply the last undone action.
Owner: GtkTextBuffer
Flags: Read
Default value: FALSE
The “can-undo”
property
“can-undo” gboolean
The “can-undo” property denotes that the buffer can undo the last applied action.
Owner: GtkTextBuffer
Flags: Read
Default value: FALSE
The “cursor-position”
property
“cursor-position” int
The position of the insert mark (as offset from the beginning of the buffer). It is useful for getting notified when the cursor moves.
Owner: GtkTextBuffer
Flags: Read
Allowed values: >= 0
Default value: 0
The “enable-undo”
property
“enable-undo” gboolean
The “enable-undo” property denotes if support for undoing and redoing changes to the buffer is allowed.
Owner: GtkTextBuffer
Flags: Read / Write
Default value: TRUE
The “has-selection”
property
“has-selection” gboolean
Whether the buffer has some text currently selected.
Owner: GtkTextBuffer
Flags: Read
Default value: FALSE
The “tag-table”
property
“tag-table” GtkTextTagTable *
Text Tag Table.
Owner: GtkTextBuffer
Flags: Read / Write / Construct Only
The “text”
property
“text” char *
The text content of the buffer. Without child widgets and images,
see gtk_text_buffer_get_text()
for more information.
Owner: GtkTextBuffer
Flags: Read / Write
Default value: ""
Signal Details
The “apply-tag”
signal
void user_function (GtkTextBuffer *textbuffer, GtkTextTag *tag, GtkTextIter *start, GtkTextIter *end, gpointer user_data)
The “apply-tag” signal is emitted to apply a tag to a range of text in a GtkTextBuffer. Applying actually occurs in the default handler.
Note that if your handler runs before the default handler it must not
invalidate the start
and end
iters (or has to revalidate them).
See also:
gtk_text_buffer_apply_tag()
,
gtk_text_buffer_insert_with_tags()
,
gtk_text_buffer_insert_range()
.
Parameters
textbuffer |
the object which received the signal |
|
tag |
the applied tag |
|
start |
the start of the range the tag is applied to |
|
end |
the end of the range the tag is applied to |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “begin-user-action”
signal
void user_function (GtkTextBuffer *textbuffer, gpointer user_data)
The “begin-user-action” signal is emitted at the beginning of a single user-visible operation on a GtkTextBuffer.
See also:
gtk_text_buffer_begin_user_action()
,
gtk_text_buffer_insert_interactive()
,
gtk_text_buffer_insert_range_interactive()
,
gtk_text_buffer_delete_interactive()
,
gtk_text_buffer_backspace()
,
gtk_text_buffer_delete_selection()
.
Parameters
textbuffer |
the object which received the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “changed”
signal
void user_function (GtkTextBuffer *textbuffer, gpointer user_data)
The “changed” signal is emitted when the content of a GtkTextBuffer has changed.
Parameters
textbuffer |
the object which received the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “delete-range”
signal
void user_function (GtkTextBuffer *textbuffer, GtkTextIter *start, GtkTextIter *end, gpointer user_data)
The “delete-range” signal is emitted to delete a range from a GtkTextBuffer.
Note that if your handler runs before the default handler it must not
invalidate the start
and end
iters (or has to revalidate them).
The default signal handler revalidates the start
and end
iters to
both point to the location where text was deleted. Handlers
which run after the default handler (see g_signal_connect_after()
)
do not have access to the deleted text.
See also: gtk_text_buffer_delete()
.
Parameters
textbuffer |
the object which received the signal |
|
start |
the start of the range to be deleted |
|
end |
the end of the range to be deleted |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “end-user-action”
signal
void user_function (GtkTextBuffer *textbuffer, gpointer user_data)
The “end-user-action” signal is emitted at the end of a single user-visible operation on the GtkTextBuffer.
See also:
gtk_text_buffer_end_user_action()
,
gtk_text_buffer_insert_interactive()
,
gtk_text_buffer_insert_range_interactive()
,
gtk_text_buffer_delete_interactive()
,
gtk_text_buffer_backspace()
,
gtk_text_buffer_delete_selection()
,
gtk_text_buffer_backspace()
.
Parameters
textbuffer |
the object which received the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “insert-child-anchor”
signal
void user_function (GtkTextBuffer *textbuffer, GtkTextIter *location, GtkTextChildAnchor *anchor, gpointer user_data)
The “insert-child-anchor” signal is emitted to insert a GtkTextChildAnchor in a GtkTextBuffer. Insertion actually occurs in the default handler.
Note that if your handler runs before the default handler it must
not invalidate the location
iter (or has to revalidate it).
The default signal handler revalidates it to be placed after the
inserted anchor
.
See also: gtk_text_buffer_insert_child_anchor()
.
Parameters
textbuffer |
the object which received the signal |
|
location |
position to insert |
|
anchor |
the GtkTextChildAnchor to be inserted |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “insert-paintable”
signal
void user_function (GtkTextBuffer *textbuffer, GtkTextIter *location, GdkPaintable *paintable, gpointer user_data)
The “insert-paintable” signal is emitted to insert a GdkPaintable in a GtkTextBuffer. Insertion actually occurs in the default handler.
Note that if your handler runs before the default handler it must not
invalidate the location
iter (or has to revalidate it).
The default signal handler revalidates it to be placed after the
inserted paintable
.
See also: gtk_text_buffer_insert_paintable()
.
Parameters
textbuffer |
the object which received the signal |
|
location |
position to insert |
|
paintable |
the GdkPaintable to be inserted |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “insert-text”
signal
void user_function (GtkTextBuffer *textbuffer, GtkTextIter *location, char *text, int len, gpointer user_data)
The ::insert-text signal is emitted to insert text in a GtkTextBuffer. Insertion actually occurs in the default handler.
Note that if your handler runs before the default handler it must not
invalidate the location
iter (or has to revalidate it).
The default signal handler revalidates it to point to the end of the
inserted text.
See also:
gtk_text_buffer_insert()
,
gtk_text_buffer_insert_range()
.
Parameters
textbuffer |
the object which received the signal |
|
location |
position to insert |
|
text |
the UTF-8 text to be inserted |
|
len |
length of the inserted text in bytes |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “mark-deleted”
signal
void user_function (GtkTextBuffer *textbuffer, GtkTextMark *mark, gpointer user_data)
The “mark-deleted” signal is emitted as notification after a GtkTextMark is deleted.
See also:
gtk_text_buffer_delete_mark()
.
Parameters
textbuffer |
the object which received the signal |
|
mark |
The mark that was deleted |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “mark-set”
signal
void user_function (GtkTextBuffer *textbuffer, GtkTextIter *location, GtkTextMark *mark, gpointer user_data)
The “mark-set” signal is emitted as notification after a GtkTextMark is set.
See also:
gtk_text_buffer_create_mark()
,
gtk_text_buffer_move_mark()
.
Parameters
textbuffer |
the object which received the signal |
|
location |
The location of |
|
mark |
The mark that is set |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “modified-changed”
signal
void user_function (GtkTextBuffer *textbuffer, gpointer user_data)
The “modified-changed” signal is emitted when the modified bit of a GtkTextBuffer flips.
See also:
gtk_text_buffer_set_modified()
.
Parameters
textbuffer |
the object which received the signal |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “paste-done”
signal
void user_function (GtkTextBuffer *textbuffer, GdkClipboard *clipboard, gpointer user_data)
The paste-done signal is emitted after paste operation has been completed.
This is useful to properly scroll the view to the end of the pasted text.
See gtk_text_buffer_paste_clipboard()
for more details.
Parameters
textbuffer |
the object which received the signal |
|
clipboard |
the GdkClipboard pasted from |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “redo”
signal
void user_function (GtkTextBuffer *buffer, gpointer user_data)
The "redo" signal is emitted when a request has been made to redo the previously undone operation.
Flags: Run Last
The “remove-tag”
signal
void user_function (GtkTextBuffer *textbuffer, GtkTextTag *tag, GtkTextIter *start, GtkTextIter *end, gpointer user_data)
The “remove-tag” signal is emitted to remove all occurrences
of tag
from a range of text in a GtkTextBuffer.
Removal actually occurs in the default handler.
Note that if your handler runs before the default handler it must not
invalidate the start
and end
iters (or has to revalidate them).
See also:
gtk_text_buffer_remove_tag()
.
Parameters
textbuffer |
the object which received the signal |
|
tag |
the tag to be removed |
|
start |
the start of the range the tag is removed from |
|
end |
the end of the range the tag is removed from |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
The “undo”
signal
void user_function (GtkTextBuffer *buffer, gpointer user_data)
The "undo" signal is emitted when a request has been made to undo the previous operation or set of operations that have been grouped together.
Flags: Run Last