Main Page
Widgets
Namespaces
Book
Gtk::TextBuffer Class Reference
[TextView Classes ]
Multi-line text that can be displayed by one or more Gtk::TextView widgets.
More...
Inheritance diagram for Gtk::TextBuffer:
[legend ] List of all members.
Public Types
typedef TextIter iterator
typedef TextTag Tag
typedef TextTagTable TagTable
typedef TextMark Mark
Public Methods
virtual ~TextBuffer ()
GtkTextBuffer* gobj ()
const GtkTextBuffer* gobj () const
GtkTextBuffer* gobj_copy ()
int get_line_count () const
Obtains the number of lines in the buffer.
int get_char_count () const
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.
int size () const
Glib::RefPtr <TextBuffer::TagTable > get_tag_table ()
Get the Gtk::TextTagTable associated with this buffer.
Glib::RefPtr <const TextBuffer::TagTable > get_tag_table () const
Get the Gtk::TextTagTable associated with this buffer.
void set_text (const Glib::ustring & text)
void set_text (const char* text_begin, const char* text_end)
void assign (const Glib::ustring & text)
Alias for set_text() .
void assign (const char* text_begin, const char* text_end)
Alias for set_text() .
iterator insert (const iterator & pos, const Glib::ustring & text)
iterator insert (const iterator & pos, const char* text_begin, const char* text_end)
void insert_at_cursor (const Glib::ustring & text)
void insert_at_cursor (const char* text_begin, const char* text_end)
std::pair<iterator , bool> insert_interactive (const iterator & pos, const Glib::ustring & text, bool default_editable=true)
std::pair<iterator , bool> insert_interactive (const iterator & pos, const char* text_begin, const char* text_end, bool default_editable=true)
bool insert_interactive_at_cursor (const Glib::ustring & text, bool default_editable=true)
bool insert_interactive_at_cursor (const char* text_begin, const char* text_end, bool default_editable=true)
iterator insert (const iterator & pos, const iterator & range_begin, const iterator & range_end)
std::pair<iterator , bool> insert_interactive (const iterator & pos, const iterator & range_begin, const iterator & range_end, bool default_editable=true)
iterator insert_with_tag (const iterator & pos, const Glib::ustring & text, const Glib::RefPtr <Tag >& tag)
iterator insert_with_tag (const iterator & pos, const char* text_begin, const char* text_end, const Glib::RefPtr <Tag >& tag)
iterator insert_with_tag (const iterator & pos, const Glib::ustring & text, const Glib::ustring & tag_name)
iterator insert_with_tag (const iterator & pos, const char* text_begin, const char* text_end, const Glib::ustring & tag_name)
iterator insert_with_tags (const iterator & pos, const Glib::ustring & text, const Glib::ArrayHandle <Glib::RefPtr <Tag >>& tags)
iterator insert_with_tags (const iterator & pos, const char* text_begin, const char* text_end, const Glib::ArrayHandle <Glib::RefPtr <Tag >>& tags)
iterator insert_with_tags_by_name (const iterator & pos, const Glib::ustring & text, const Glib::StringArrayHandle & tag_names)
iterator insert_with_tags_by_name (const iterator & pos, const char* text_begin, const char* text_end, const Glib::StringArrayHandle & tag_names)
iterator erase (const iterator & range_begin, const iterator & range_end)
Returns the iterator where the deletion occured.
std::pair<iterator , bool> erase_interactive (const iterator & range_begin, const iterator & range_end, bool default_editable=true)
Returns the iterator where the deletion occured or end() if no text was deleted.
Glib::ustring get_text (const iterator & range_begin, const iterator & range_end, bool include_hidden_chars=true)
Returns the text in the range [ start , end ).
Glib::ustring get_text (bool include_hidden_chars=true)
Glib::ustring get_slice (const iterator & range_begin, const iterator & range_end, bool include_hidden_chars=true)
Returns the text in the range [ start , end ).
iterator insert_pixbuf (const iterator & pos, const Glib::RefPtr <Gdk::Pixbuf >& pixbuf)
iterator insert_child_anchor (const iterator & pos, const Glib::RefPtr <TextChildAnchor >& anchor)
Glib::RefPtr <TextChildAnchor > create_child_anchor (const iterator & pos)
Glib::RefPtr <TextBuffer::Mark > create_mark (const Glib::ustring & mark_name, const iterator & where, bool left_gravity=true)
Creates a mark at position where .
Glib::RefPtr <Mark > create_mark (const iterator & where, bool left_gravity=true)
Create an anonymous mark.
void move_mark (const Glib::RefPtr <Mark >& mark, const iterator & where)
Moves mark to the new location where .
void delete_mark (const Glib::RefPtr <Mark >& mark)
Deletes mark , so that it's no longer located anywhere in the buffer.
Glib::RefPtr <TextBuffer::Mark > get_mark (const Glib::ustring & name)
Returns the mark named name in buffer buffer , or 0
if no such mark exists in the buffer.
Glib::RefPtr <const TextBuffer::Mark > get_mark (const Glib::ustring & name) const
Returns the mark named name in buffer buffer , or 0
if no such mark exists in the buffer.
void move_mark_by_name (const Glib::ustring & name, const iterator & where)
Moves the mark named name (which must exist) to location where .
void delete_mark_by_name (const Glib::ustring & name)
Deletes the mark named name ; the mark must exist.
Glib::RefPtr <TextBuffer::Mark > get_insert ()
Returns the mark that represents the cursor (insertion point).
Glib::RefPtr <TextBuffer::Mark > get_selection_bound ()
Returns the mark that represents the selection bound.
void place_cursor (const iterator & where)
This function moves the "insert" and "selection_bound" marks simultaneously.
void apply_tag (const Glib::RefPtr <Tag >& tag, const iterator & range_begin, const iterator & range_end)
Emits the "apply_tag" signal on buffer .
void remove_tag (const Glib::RefPtr <Tag >& tag, const iterator & range_begin, const iterator & range_end)
Emits the "remove_tag" signal.
void apply_tag_by_name (const Glib::ustring & name, const iterator & range_begin, const iterator & range_end)
Calls Gtk::TextTagTable::lookup() on the buffer's tag table to get a Gtk::TextTag , then calls apply_tag() .
void remove_tag_by_name (const Glib::ustring & name, const iterator & range_begin, const iterator & range_end)
Calls Gtk::TextTagTable::lookup() on the buffer's tag table to get a Gtk::TextTag , then calls remove_tag() .
void remove_all_tags (const iterator & range_begin, const iterator & range_end)
Removes all tags in the range between start and end .
Glib::RefPtr <Tag > create_tag (const Glib::ustring & tag_name)
iterator get_iter_at_line_offset (int line_number, int char_offset)
iterator get_iter_at_line_index (int line_number, int byte_index)
iterator get_iter_at_offset (int char_offset)
iterator get_iter_at_line (int line_number)
iterator begin ()
iterator end ()
void get_bounds (iterator & range_begin, iterator & range_end)
iterator get_iter_at_mark (const Glib::RefPtr <Mark >& mark)
iterator get_iter_at_child_anchor (const Glib::RefPtr <TextChildAnchor >& anchor)
bool get_modified () const
Indicates whether the buffer has been modified since the last call to set_modified() set the modification flag to false
.
void set_modified (bool setting=true)
Used to keep track of whether the buffer has been modified since the last time it was saved.
void add_selection_clipboard (const Glib::RefPtr <Clipboard >& clipboard)
Adds clipboard to the list of clipboards in which the selection contents of buffer are available.
void remove_selection_clipboard (const Glib::RefPtr <Clipboard >& clipboard)
Removes a Gtk::Clipboard added with add_selection_clipboard() .
void cut_clipboard (const Glib::RefPtr <Clipboard >& clipboard, bool default_editable=true)
Copies the currently-selected text to a clipboard, then deletes said text if it's editable.
void copy_clipboard (const Glib::RefPtr <Clipboard >& clipboard)
Copies the currently-selected text to a clipboard.
void paste_clipboard (const Glib::RefPtr <Clipboard >& clipboard, const iterator & override_location, bool default_editable=true)
void paste_clipboard (const Glib::RefPtr <Clipboard >& clipboard, bool default_editable=true)
void get_selection_bounds (iterator & range_begin, iterator & range_end)
bool erase_selection (bool interactive=true, bool default_editable=true)
Deletes the range between the "insert" and "selection_bound" marks, that is, the currently-selected text.
void begin_user_action ()
Called to indicate that the buffer operations between here and a call to end_user_action() are part of a single user-visible operation.
void end_user_action ()
Should be paired with a call to begin_user_action() .
Glib::SignalProxy3 < void,
const TextBuffer::iterator &,
const Glib::ustring &, int > signal_insert ()
Glib::SignalProxy2 < void,
const TextBuffer::iterator &,
const Glib::RefPtr <Gdk::Pixbuf >&> signal_insert_pixbuf ()
Glib::SignalProxy2 < void,
const TextBuffer::iterator &,
const Glib::RefPtr <TextChildAnchor >&> signal_insert_child_anchor ()
Glib::SignalProxy2 < void,
const TextBuffer::iterator &,
const TextBuffer::iterator & > signal_erase ()
Glib::SignalProxy0 <void> signal_changed ()
Glib::SignalProxy0 <void> signal_modified_changed ()
Glib::SignalProxy2 < void,
const TextBuffer::iterator &,
const Glib::RefPtr <TextBuffer::Mark >&> signal_mark_set ()
Glib::SignalProxy1 < void,
const Glib::RefPtr <TextBuffer::Mark >&> signal_mark_deleted ()
Glib::SignalProxy3 < void,
const Glib::RefPtr <TextBuffer::Tag >&,
const TextBuffer::iterator &,
const TextBuffer::iterator & > signal_apply_tag ()
Glib::SignalProxy3 < void,
const Glib::RefPtr <TextBuffer::Tag >&,
const TextBuffer::iterator &,
const TextBuffer::iterator & > signal_remove_tag ()
Glib::SignalProxy0 <void> signal_begin_user_action ()
Glib::SignalProxy0 <void> signal_end_user_action ()
Static Public Methods
Glib::RefPtr <TextBuffer> create ()
Glib::RefPtr <TextBuffer> create (const Glib::RefPtr <TagTable >& tag_table)
Protected Methods
TextBuffer ()
TextBuffer (const Glib::RefPtr <TagTable >& tag_table)
virtual void on_insert (const TextBuffer::iterator & pos, const Glib::ustring & text, int bytes)
virtual void on_insert_pixbuf (const TextBuffer::iterator & pos, const Glib::RefPtr <Gdk::Pixbuf >& pixbuf)
virtual void on_insert_child_anchor (const TextBuffer::iterator & pos, const Glib::RefPtr <TextChildAnchor >& anchor)
virtual void on_erase (const TextBuffer::iterator & range_begin, const TextBuffer::iterator & range_end)
virtual void on_changed ()
virtual void on_modified_changed ()
virtual void on_mark_set (const TextBuffer::iterator & location, const Glib::RefPtr <TextBuffer::Mark >& mark)
virtual void on_mark_deleted (const Glib::RefPtr <TextBuffer::Mark >& mark)
virtual void on_apply_tag (const Glib::RefPtr <TextBuffer::Tag >& tag, const TextBuffer::iterator & range_begin, const TextBuffer::iterator & range_end)
virtual void on_remove_tag (const Glib::RefPtr <TextBuffer::Tag >& tag, const TextBuffer::iterator & range_begin, const TextBuffer::iterator & range_end)
virtual void on_begin_user_action ()
virtual void on_end_user_action ()
Related Functions
(Note that these are not member functions.)
Glib::RefPtr <Gtk::TextBuffer> wrap (GtkTextBuffer* object, bool take_copy=false)
Detailed Description
Multi-line text that can be displayed by one or more Gtk::TextView widgets.
Member Typedef Documentation
typedef TextIter Gtk::TextBuffer::iterator
typedef TextTag Gtk::TextBuffer::Tag
Constructor & Destructor Documentation
virtual Gtk::TextBuffer::~TextBuffer
(
)
[virtual]
Gtk::TextBuffer::TextBuffer
(
)
[protected]
Member Function Documentation
Adds clipboard to the list of clipboards in which the selection contents of buffer are available.
In most cases, clipboard will be the Gtk::Clipboard of type Gdk::SELECTION_PRIMARY for a view of buffer .
Parameters:
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.
Parameters:
tag A Gtk::TextTag .
start One bound of range to be tagged.
end Other bound of range to be tagged.
void Gtk::TextBuffer::assign
(
const char*
text_begin ,
const char*
text_end
)
void Gtk::TextBuffer::begin_user_action
(
)
Called to indicate that the buffer operations between here and a call to end_user_action() are part of a single user-visible operation.
The operations between begin_user_action() and end_user_action() can then be grouped when creating an undo stack. Gtk::TextBuffer maintains a count of calls to begin_user_action() that have not been closed with a call to 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 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.
Copies the currently-selected text to a clipboard.
Parameters:
Glib::RefPtr <TextBuffer> Gtk::TextBuffer::create
(
)
[static]
Create an anonymous mark.
Creates a mark at position where .
If mark_name is 0
, the mark is anonymous; otherwise, the mark can be retrieved by name using 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 Gtk::TextMark , 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.
Parameters:
mark_name Name for mark, or 0
.
where Location to place mark.
left_gravity Whether the mark has left gravity.
Returns: The new Gtk::TextMark object.
void Gtk::TextBuffer::cut_clipboard
(
const Glib::RefPtr <Clipboard >&
clipboard ,
bool
default_editable = true
)
Copies the currently-selected text to a clipboard, then deletes said text if it's editable.
Parameters:
clipboard The Gtk::Clipboard object to cut to.
default_editable Default editability of the buffer.
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 don't keep a Glib::RefPtr to the mark, it will be freed. Even if the mark isn't freed, most operations on mark become invalid. There is no way to undelete a mark. Gtk::TextMark::get_deleted() will return true
after this function has been called on a mark; Gtk::TextMark::get_deleted() indicates that a mark no longer belongs to a buffer. The "mark_deleted" signal will be emitted as notification after the mark is deleted.
Parameters:
void Gtk::TextBuffer::delete_mark_by_name
(
const Glib::ustring &
name
)
Deletes the mark named name ; the mark must exist.
See delete_mark() for details.
Parameters:
name Name of a mark in buffer .
void Gtk::TextBuffer::end_user_action
(
)
Returns the iterator where the deletion occured.
std::pair<iterator ,bool> Gtk::TextBuffer::erase_interactive
(
const iterator &
range_begin ,
const iterator &
range_end ,
bool
default_editable = true
)
Returns the iterator where the deletion occured or end() if no text was deleted.
bool Gtk::TextBuffer::erase_selection
(
bool
interactive = true,
bool
default_editable = true
)
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).
Parameters:
interactive Whether the deletion is caused by user interaction.
default_editable Whether the buffer is editable by default.
Returns: Whether there was a non-empty selection to delete.
int Gtk::TextBuffer::get_char_count
(
)
const
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.
Returns: Number of characters in the buffer.
Returns the mark that represents the cursor (insertion point).
Equivalent to calling get_mark() to get the mark named "insert", but very slightly more efficient, and involves less typing.
Returns: Insertion point mark.
iterator Gtk::TextBuffer::get_iter_at_line
(
int
line_number
)
iterator Gtk::TextBuffer::get_iter_at_line_index
(
int
line_number ,
int
byte_index
)
iterator Gtk::TextBuffer::get_iter_at_line_offset
(
int
line_number ,
int
char_offset
)
iterator Gtk::TextBuffer::get_iter_at_offset
(
int
char_offset
)
int Gtk::TextBuffer::get_line_count
(
)
const
Obtains the number of lines in the buffer.
This value is cached, so the function is very fast.
Returns: Number of lines in the buffer.
Returns the mark named name in buffer buffer , or 0
if no such mark exists in the buffer.
Parameters:
Returns: A Gtk::TextMark , or 0
.
Returns the mark named name in buffer buffer , or 0
if no such mark exists in the buffer.
Parameters:
Returns: A Gtk::TextMark , or 0
.
bool Gtk::TextBuffer::get_modified
(
)
const
Indicates whether the buffer has been modified since the last call to set_modified() set the modification flag to false
.
Used for example to enable a "save" function in a text editor.
Returns: true
if the buffer has been modified.
Returns the mark that represents the selection bound.
Equivalent to calling 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. 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.
Returns: Selection bound mark.
void Gtk::TextBuffer::get_selection_bounds
(
iterator &
range_begin ,
iterator &
range_end
)
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 get_text() . Note that 0xFFFC can occur in normal text as well, so it is not a reliable indicator that a pixbuf or widget is in the buffer.
Parameters:
start Start of a range.
end End of a range.
include_hidden_chars Whether to include invisible text.
Returns: An allocated UTF-8 string.
Get the Gtk::TextTagTable associated with this buffer.
Returns: The buffer's tag table.
Get the Gtk::TextTagTable associated with this buffer.
Returns: The buffer's tag table.
Glib::ustring Gtk::TextBuffer::get_text
(
bool
include_hidden_chars = true
)
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 get_slice() .
Parameters:
start Start of a range.
end End of a range.
include_hidden_chars Whether to include invisible text.
Returns: An allocated UTF-8 string.
const GtkTextBuffer* Gtk::TextBuffer::gobj
(
)
const [inline]
GtkTextBuffer* Gtk::TextBuffer::gobj
(
)
[inline]
GtkTextBuffer* Gtk::TextBuffer::gobj_copy
(
)
iterator Gtk::TextBuffer::insert
(
const iterator &
pos ,
const char*
text_begin ,
const char*
text_end
)
void Gtk::TextBuffer::insert_at_cursor
(
const char*
text_begin ,
const char*
text_end
)
void Gtk::TextBuffer::insert_at_cursor
(
const Glib::ustring &
text
)
std::pair<iterator ,bool> Gtk::TextBuffer::insert_interactive
(
const iterator &
pos ,
const iterator &
range_begin ,
const iterator &
range_end ,
bool
default_editable = true
)
std::pair<iterator ,bool> Gtk::TextBuffer::insert_interactive
(
const iterator &
pos ,
const char*
text_begin ,
const char*
text_end ,
bool
default_editable = true
)
bool Gtk::TextBuffer::insert_interactive_at_cursor
(
const char*
text_begin ,
const char*
text_end ,
bool
default_editable = true
)
bool Gtk::TextBuffer::insert_interactive_at_cursor
(
const Glib::ustring &
text ,
bool
default_editable = true
)
Moves mark to the new location where .
Emits the "mark_set" signal as notification of the move.
Parameters:
Moves the mark named name (which must exist) to location where .
See move_mark() for details.
Parameters:
name Name of a mark.
where New location for mark.
virtual void Gtk::TextBuffer::on_begin_user_action
(
)
[protected, virtual]
virtual void Gtk::TextBuffer::on_changed
(
)
[protected, virtual]
virtual void Gtk::TextBuffer::on_end_user_action
(
)
[protected, virtual]
virtual void Gtk::TextBuffer::on_modified_changed
(
)
[protected, virtual]
void Gtk::TextBuffer::paste_clipboard
(
const Glib::RefPtr <Clipboard >&
clipboard ,
bool
default_editable = true
)
void Gtk::TextBuffer::paste_clipboard
(
const Glib::RefPtr <Clipboard >&
clipboard ,
const iterator &
override_location ,
bool
default_editable = true
)
void Gtk::TextBuffer::place_cursor
(
const iterator &
where
)
This function moves the "insert" and "selection_bound" marks simultaneously.
If you move them to the same place in two steps with 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.
Parameters:
where Where to put the cursor.
void Gtk::TextBuffer::remove_all_tags
(
const iterator &
range_begin ,
const iterator &
range_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.
Parameters:
start One bound of range to be untagged.
end Other bound of range to be untagged.
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.
Parameters:
tag A Gtk::TextTag .
start One bound of range to be untagged.
end Other bound of range to be untagged.
void Gtk::TextBuffer::set_modified
(
bool
setting = true
)
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 a "modified_changed" signal.
Parameters:
setting Modification flag setting.
void Gtk::TextBuffer::set_text
(
const char*
text_begin ,
const char*
text_end
)
Prototype: void begin_user_action()
Prototype: void end_user_action()
Prototype: void insert_child_anchor(const TextBuffer::iterator & pos, const Glib::RefPtr<TextChildAnchor>& anchor)
Prototype: void insert_pixbuf(const TextBuffer::iterator & pos, const Glib::RefPtr<Gdk::Pixbuf>& pixbuf)
Prototype: void mark_deleted(const Glib::RefPtr<TextBuffer::Mark>& mark)
Prototype: void mark_set(const TextBuffer::iterator & location, const Glib::RefPtr<TextBuffer::Mark>& mark)
Prototype: void modified_changed()
int Gtk::TextBuffer::size
(
)
const
Friends And Related Function Documentation
Glib::RefPtr <Gtk::TextBuffer> wrap
(
GtkTextBuffer*
object ,
bool
take_copy = false
)
[related]
The documentation for this class was generated from the following file:
Generated for gtkmm by
Doxygen 1.3-rc1 © 1997-2001