Bufferten
Gtk::TextBuffer is a model containing the data for the Gtk::TextView, like the Gtk::TreeModel used by Gtk::TreeView. This allows two or more Gtk::TextViews to share the same TextBuffer, and allows those TextBuffers to be displayed slightly differently. Or you could maintain several Gtk::TextBuffers and choose to display each one at different times in the same Gtk::TextView widget.
The TextView creates its own default TextBuffer, which you can access via the get_buffer() method.
Iteratorer
A Gtk::TextBuffer::iterator and a Gtk::TextBuffer::const_iterator represent a position between two characters in the text buffer. Whenever the buffer is modified in a way that affects the number of characters in the buffer, all outstanding iterators become invalid. Because of this, iterators can't be used to preserve positions across buffer modifications. To preserve a position, use Gtk::TextBuffer::Mark.
Taggar och formatering
TagTable
Each Gtk::TextBuffer uses a Gtk::TextBuffer::TagTable, which contains the Tags for that buffer. 2 or more TextBuffers may share the same TagTable. When you create Tags you should add them to the TagTable. For instance:
auto refTagTable = Gtk::TextBuffer::TagTable::create();
refTagTable->add(refTagMatch);
//Hopefully a future version of gtkmm will have a set_tag_table() method,
//for use after creation of the buffer.
auto refBuffer = Gtk::TextBuffer::create(refTagTable);
You can also use get_tag_table() to get, and maybe modify, the TextBuffer's default TagTable instead of creating one explicitly.
Marks
TextBuffer-iteratorer görs vanligen ogiltiga när texten ändras, men du kan använda ett Gtk::TextBuffer::Mark för att komma ihåg en position i dessa fall. Till exempel,
auto refMark = refBuffer->create_mark(iter);
You can then use the get_iter() method later to create an iterator for the Mark's new position.
There are two built-in Marks - insert and selection_bound, which you can access with TextBuffer's get_insert() and get_selection_bound() methods.
The View
Som nämns ovan har varje TextView en TextBuffer, och en eller flera TextView kan dela på samma TextBuffer.
Like the TreeView, you should probably put your TextView inside a ScrolledWindow to allow the user to see and move around the whole text area with scrollbars.
Standardformatering
TextView has various methods which allow you to change the presentation of the buffer for this particular view. Some of these may be overridden by the Gtk::TextTags in the buffer, if they specify the same things. For instance, set_left_margin(), set_right_margin(), set_indent(), etc.
Rullning
Gtk::TextView har olika scroll_to()-metoder. Dessa låter dig säkerställa att en viss del av textbufferten är synlig. Exempelvis använder ditt programs sökfunktion kanske Gtk::TextView::scroll_to() för att visa den hittade texten.