2 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #ifndef _GTKMM_TEXTBUFFER_H
4 #define _GTKMM_TEXTBUFFER_H
11 /* Copyright(C) 1998-2002 The gtkmm Development Team
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Library General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or(at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Library General Public License for more details.
23 * You should have received a copy of the GNU Library General Public
24 * License along with this library; if not, write to the Free
25 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <gtkmm/object.h>
30 #include <gtkmm/texttagtable.h>
31 #include <gtkmm/textchildanchor.h>
32 #include <gtkmm/textmark.h>
33 #include <gtkmm/textiter.h>
34 #include <gtkmm/clipboard.h>
35 #include <gdkmm/pixbuf.h>
36 #include <gtkmmconfig.h>
39 GLIBMM_USING_STD(pair)
42 #ifndef DOXYGEN_SHOULD_SKIP_THIS
43 typedef struct _GtkTextBuffer GtkTextBuffer;
44 typedef struct _GtkTextBufferClass GtkTextBufferClass;
45 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
49 { class TextBuffer_Class; } // namespace Gtk
56 /** Multi-line attributed text that can be displayed by one or more Gtk::TextView widgets.
58 * Text in a buffer can be marked with tags. A @link Gtk::TextTag Gtk::TextBuffer::Tag@endlink is an attribute that can be applied to some range of text. For example, a tag
59 * might be called "bold" and make the text inside the tag bold. However, the tag concept is more general than that; tags don't
60 * have to affect appearance. They can instead affect the behavior of mouse and key presses, "lock" a range of text so the user
61 * can't edit it, or countless other things. A tag is represented by a @link Gtk::TextTag Gtk::TextBuffer::Tag@endlink object.
62 * One @link Gtk::TextTag Gtk::TextBuffer::Tag@endlink can be applied to any number of text ranges in any number of @link Gtk::TextBuffer Gtk::TextBuffers@endlink.
64 * Each tag is stored in a @link Gtk::TextTagTable Gtk::TextBuffer::TagTable@endlink. A tag table defines a set of tags that can be used together. Each buffer has one tag
65 * table associated with it; only tags from that tag table can be used with the buffer. A single tag table can be shared between
66 * multiple buffers, however.
68 * Most text manipulation is accomplished with iterators, represented by an @link Gtk::TextIter iterator@endlink. The iterator can
69 * be used to navigate over characters, words, lines, and sentences.
71 * But iterators can't be used to preserve positions across buffer modifications. To preserve a position, the
72 * @link Gtk::TextMark Gtk::TextBuffer::Mark@endlink object is ideal. There are two marks built-in to GtkTextBuffer; these are
73 * named "insert" and "selection_bound" and refer to the insertion point and the boundary of the selection which is not the
74 * insertion point. If no text is selected, these two marks will be in the same position. You can manipulate what is selected and
75 * where the cursor appears by moving these marks around.
77 * Text buffers always contain at least one line, but may be empty (that is, buffers can contain zero characters). The last line
78 * in the text buffer never ends in a line separator (such as newline); the other lines in the buffer always end in a line
79 * separator. Line separators count as characters when computing character counts and character offsets. Note that some Unicode
80 * line separators are represented with multiple bytes in UTF-8, and the two-character sequence "\r\n" is also considered a line
86 class TextBuffer : public Glib::Object
89 #ifndef DOXYGEN_SHOULD_SKIP_THIS
92 typedef TextBuffer CppObjectType;
93 typedef TextBuffer_Class CppClassType;
94 typedef GtkTextBuffer BaseObjectType;
95 typedef GtkTextBufferClass BaseClassType;
97 private: friend class TextBuffer_Class;
98 static CppClassType textbuffer_class_;
102 TextBuffer(const TextBuffer&);
103 TextBuffer& operator=(const TextBuffer&);
106 explicit TextBuffer(const Glib::ConstructParams& construct_params);
107 explicit TextBuffer(GtkTextBuffer* castitem);
109 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
112 virtual ~TextBuffer();
114 #ifndef DOXYGEN_SHOULD_SKIP_THIS
115 static GType get_type() G_GNUC_CONST;
116 static GType get_base_type() G_GNUC_CONST;
119 ///Provides access to the underlying C GObject.
120 GtkTextBuffer* gobj() { return reinterpret_cast<GtkTextBuffer*>(gobject_); }
122 ///Provides access to the underlying C GObject.
123 const GtkTextBuffer* gobj() const { return reinterpret_cast<GtkTextBuffer*>(gobject_); }
125 ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
126 GtkTextBuffer* gobj_copy();
132 typedef TextIter iterator;
134 typedef TextTagTable TagTable;
135 typedef TextMark Mark;
136 typedef TextChildAnchor ChildAnchor;
140 explicit TextBuffer(const Glib::RefPtr<TagTable>& tag_table);
144 static Glib::RefPtr<TextBuffer> create();
147 static Glib::RefPtr<TextBuffer> create(const Glib::RefPtr<TagTable>& tag_table);
150 /** Obtains the number of lines in the buffer. This value is cached, so
151 * the function is very fast.
152 * @return Number of lines in the buffer.
154 int get_line_count() const;
156 /** Gets the number of characters in the buffer; note that characters
157 * and bytes are not the same, you can't e.g.\ expect the contents of
158 * the buffer in string form to be this many bytes long. The character
159 * count is cached, so this function is very fast.
160 * @return Number of characters in the buffer.
162 int get_char_count() const;
164 /// See get_char_count().
168 /** Get the Gtk::TextTagTable associated with this buffer.
169 * @return The buffer's tag table.
171 Glib::RefPtr<TextBuffer::TagTable> get_tag_table();
173 /** Get the Gtk::TextTagTable associated with this buffer.
174 * @return The buffer's tag table.
176 Glib::RefPtr<const TextBuffer::TagTable> get_tag_table() const;
178 /** Removes the current contents of the buffer, and inserts @a text instead.
179 * @param text The text to put in the buffer.
181 void set_text(const Glib::ustring& text);
183 /** Removes the current contents of the buffer, and inserts @a text instead.
184 * @param text_begin The start of a UTF8 character array.
185 * @param text_end The end of the UTF8 character array.
187 void set_text(const char* text_begin, const char* text_end);
190 #ifndef GTKMM_DISABLE_DEPRECATED
192 /** @deprecated Use set_text()
194 void assign(const Glib::ustring& text);
196 /** @deprecated Use set_text()
198 void assign(const char* text_begin, const char* text_end);
199 #endif // GTKMM_DISABLE_DEPRECATED
202 //TODO: Make all insert() methods have the same return type:
204 /** Inserts @a text at position @a pos.
205 * Emits the "insert_text" signal; insertion actually occurs in the default handler for the signal.
206 * The @a pos iterator is invalidated when insertion occurs (because the buffer contents change).
208 * @param pos An iterator pointing to the position at which the text should be inserted.
209 * @param text The text to be inserted in the buffer.
210 * @result An iterator that points to the end of the inserted text.
212 iterator insert(const iterator& pos, const Glib::ustring& text);
214 /** Inserts text at position @a pos.
215 * Emits the "insert_text" signal; insertion actually occurs in the default handler for the signal.
216 * The @a pos iterator is invalidated when insertion occurs (because the buffer contents change).
218 * @param pos An iterator pointing to the position at which the text should be inserted.
219 * @param text_begin The start of a UTF8 character array.
220 * @param text_end The end of the UTF8 character array.
221 * @result An iterator that points to the end of the inserted text.
223 iterator insert(const iterator& pos, const char* text_begin, const char* text_end);
225 /** Inserts @a text, using the current cursor position as the insertion point.
226 * Emits the "insert_text" signal; insertion actually occurs in the default handler for the signal.
228 * @param text The text to be inserted in the buffer.
229 * @result An iterator that points to the end of the inserted text.
231 void insert_at_cursor(const Glib::ustring& text);
233 /** Inserts text, using the current cursor position as the insertion point.
234 * Emits the "insert_text" signal; insertion actually occurs in the default handler for the signal.
236 * @param text_begin The start of a UTF8 character array.
237 * @param text_end The end of the UTF8 character array.
238 * @result An iterator that points to the end of the inserted text.
240 void insert_at_cursor(const char* text_begin, const char* text_end);
242 /** Like insert(), but the insertion will not occur if @a iter is at a non-editable location in the buffer.
243 * Usually you want to prevent insertions at ineditable locations if the insertion results from a user action (is interactive).
245 * @a default_editable indicates the editability of text that doesn't have a tag affecting editability applied to it.
246 * Typically the result of Gtk::TextView::get_editable() is appropriate here.
248 * @param pos An iterator pointing to the position at which the text should be inserted.
249 * @param text The text to be inserted in the buffer.
250 * @param default_editable Default editability of buffer
251 * @result Whether text was actually inserted
253 std::pair<iterator,bool> insert_interactive(
254 const iterator& pos, const Glib::ustring& text, bool default_editable = true);
256 /** Like insert(), but the insertion will not occur if @a pos is at a non-editable location in the buffer.
257 * Usually you want to prevent insertions at ineditable locations if the insertion results from a user action (is interactive).
259 * @a default_editable indicates the editability of text that doesn't have a tag affecting editability applied to it.
260 * Typically the result of Gtk::TextView::get_editable() is appropriate here.
262 * @param pos An iterator pointing to the position at which the text should be inserted.
263 * @param text_begin The start of a UTF8 character array.
264 * @param text_end The end of the UTF8 character array.
265 * @param default_editable Default editability of buffer.
266 * @result Whether text was actually inserted
268 std::pair<iterator,bool> insert_interactive(
269 const iterator& pos, const char* text_begin, const char* text_end, bool default_editable = true);
271 /** Calls insert_interactive() at the cursor position.
273 * @a default_editable indicates the editability of text that doesn't have a tag affecting editability applied to it.
274 * Typically the result of Gtk::TextView::get_editable() is appropriate here.
276 * @param text The text to be inserted in the buffer.
277 * @param default_editable Default editability of buffer
278 * @result Whether text was actually inserted
280 bool insert_interactive_at_cursor(const Glib::ustring& text, bool default_editable = true);
282 /** Calls insert_interactive() at the cursor position.
284 * @a default_editable indicates the editability of text that doesn't have a tag affecting editability applied to it.
285 * Typically the result of Gtk::TextView::get_editable() is appropriate here.
287 * @param text_begin The start of a UTF8 character array.
288 * @param text_end The end of the UTF8 character array.
289 * @param default_editable Default editability of buffer
290 * @result Whether text was actually inserted
292 bool insert_interactive_at_cursor(const char* text_begin, const char* text_end,
293 bool default_editable = true);
295 /** Copies text, tags, and pixbufs between @a range_begin and @a range_end (the order of range_begin and range_begin doesn't
296 * matter) and inserts the copy at @a pos. Used instead of simply getting/inserting text because it preserves images and tags.
297 * If range_begin and range_end are in a different buffer, the two buffers must share the same tag table.
299 * Implemented via emissions of the insert_text and apply_tag signals, so expect those.
301 * @param pos An iterator pointing to the position at which the text should be inserted.
302 * @param range_begin A position in a buffer.
303 * @param range_end Another position in the same buffer as @a range_begin.
304 * @result Whether text was actually inserted
306 iterator insert(const iterator& pos, const iterator& range_begin, const iterator& range_end);
309 /** Same as insert_range(), but does nothing if the insertion point isn't editable.
311 * The @a default_editable parameter indicates whether the text is editable at @a pos if no tags enclosing @a pos affect editability.
312 * Typically the result of Gtk::TextView::get_editable() is appropriate here.
314 * @param pos An iterator pointing to the position at which the text should be inserted.
315 * @param range_begin A position in a buffer.
316 * @param range_end Another position in the same buffer as @a range_begin.
317 * @param default_editable Default editability of buffer.
318 * @result Whether text was actually inserted
320 std::pair<iterator,bool> insert_interactive(const iterator& pos, const iterator& range_begin, const iterator& range_end, bool default_editable = true);
323 iterator insert_with_tag(const iterator& pos, const Glib::ustring& text, const Glib::RefPtr<Tag>& tag);
324 iterator insert_with_tag(const iterator& pos, const char* text_begin, const char* text_end, const Glib::RefPtr<Tag>& tag);
326 iterator insert_with_tag(const iterator& pos, const Glib::ustring& text, const Glib::ustring& tag_name);
327 iterator insert_with_tag(const iterator& pos, const char* text_begin, const char* text_end, const Glib::ustring& tag_name);
329 /** Inserts text into buffer at @a pos, applying the list of tags to the newly-inserted text.
330 * Equivalent to calling insert(), then apply_tag() on the inserted text; This is just a convenience function.
332 * @param pos An iterator pointing to the position at which the text should be inserted.
333 * @param text The text to be inserted in the buffer.
334 * @param tags A standard C++ container of @link Gtk::TextTag Gtk::TextBuffer::Tags@endlink.
335 * @result Whether text was actually inserted
337 iterator insert_with_tags(const iterator& pos, const Glib::ustring& text,
338 const Glib::ArrayHandle< Glib::RefPtr<Tag> >& tags);
340 /** Inserts text into buffer at @a pos, applying the list of tags to the newly-inserted text.
341 * Equivalent to calling insert(), then apply_tag() on the inserted text; This is just a convenience function.
343 * @param pos An iterator pointing to the position at which the text should be inserted.
344 * @param text_begin The start of a UTF8 character array.
345 * @param text_end The end of the UTF8 character array.
346 * @param tags A standard C++ container of @link Gtk::TextTag Gtk::TextBuffer::Tags@endlink.
347 * @result Whether text was actually inserted
349 iterator insert_with_tags(const iterator& pos, const char* text_begin, const char* text_end,
350 const Glib::ArrayHandle< Glib::RefPtr<Tag> >& tags);
352 /** Inserts text into buffer at @a pos, applying the list of tags to the newly-inserted text.
353 * Equivalent to calling insert(), then apply_tag() on the inserted text; This is just a convenience function.
355 * @param pos An iterator pointing to the position at which the text should be inserted.
356 * @param text The text to be inserted in the buffer.
357 * @param tag_names A standard C++ container of tag names.
358 * @result Whether text was actually inserted
360 iterator insert_with_tags_by_name(const iterator& pos, const Glib::ustring& text,
361 const Glib::StringArrayHandle& tag_names);
364 /** Equivalent to calling insert(), then apply_tag() on the inserted text; This is just a convenience function.
366 * @param pos An iterator pointing to the position at which the text should be inserted.
367 * @param text_begin The start of a UTF8 character array.
368 * @param text_end The end of the UTF8 character array.
369 * @param tag_names A standard C++ container of tag names.
370 * @result Whether text was actually inserted
372 iterator insert_with_tags_by_name(const iterator& pos, const char* text_begin, const char* text_end,
373 const Glib::StringArrayHandle& tag_names);
375 /* Deletes all text between @a range_begin and @a range_end. The order of range_begin and range_end is not actually relevant.
376 * This function actually emits the "delete_range" signal, and the default handler of that signal deletes the text.
377 * Because the buffer is modified, all outstanding iterators become invalid after calling this function.
380 * @result An iterator that points to the location where text was deleted.
382 iterator erase(const iterator& range_begin, const iterator& range_end);
385 /* Deletes all editable text between @a range_begin and @a range_end. The order of range_begin and range_end is not actually relevant.
386 * This function actually emits the "delete_range" signal, and the default handler of that signal deletes the text.
387 * Because the buffer is modified, all outstanding iterators become invalid after calling this function.
389 * @a default_editable indicates the editability of text that doesn't have a tag affecting editability applied to it.
390 * Typically the result of Gtk::TextView::get_editable() is appropriate here.
394 * @param default_editable Default editability of buffer
395 * @result An iterator that points to the location where text was deleted, or end() is no text was deleted.
397 std::pair<iterator,bool> erase_interactive(const iterator& range_begin, const iterator& range_end, bool default_editable = true);
400 /** Performs the appropriate action as if the user hit the delete
401 * key with the cursor at the position specified by @a iter. In the
402 * normal case a single character will be deleted, but when
403 * combining accents are involved, more than one character can
404 * be deleted, and when precomposed character and accent combinations
405 * are involved, less than one character will be deleted.
407 * Because the buffer is modified, all outstanding iterators become
408 * invalid after calling this method; however, this method returns
409 * a valid iterator that points to the location where text was deleted.
411 * @param iter A position in the buffer.
412 * @param interactive Whether the deletion is caused by user interaction.
413 * @param default_editable Whether the buffer is editable by default.
414 * @result An iterator to the location where text was deleted, if the buffer was modified.
418 iterator backspace(const iterator& iter, bool interactive = true, bool default_editable = true);
421 /** @deprecated Use get_text(const iterator& start, const iterator& end, bool include_hidden_chars) const
424 /** Returns the text in the range [ @a start , @a end ). Excludes undisplayed
425 * text (text marked with tags that set the invisibility attribute) if
426 * @a include_hidden_chars is <tt>false</tt>. Does not include characters
427 * representing embedded images, so byte and character indexes into
428 * the returned string do <em>not</em> correspond to byte
429 * and character indexes into the buffer. Contrast with
431 * @param start Start of a range.
432 * @param end End of a range.
433 * @param include_hidden_chars Whether to include invisible text.
434 * @return An allocated UTF-8 string.
436 Glib::ustring get_text(const iterator& start, const iterator& end, bool include_hidden_chars = true);
439 /** Returns the text in the range [ @a start , @a end ). Excludes undisplayed
440 * text (text marked with tags that set the invisibility attribute) if
441 * @a include_hidden_chars is <tt>false</tt>. Does not include characters
442 * representing embedded images, so byte and character indexes into
443 * the returned string do <em>not</em> correspond to byte
444 * and character indexes into the buffer. Contrast with
446 * @param start Start of a range.
447 * @param end End of a range.
448 * @param include_hidden_chars Whether to include invisible text.
449 * @return An allocated UTF-8 string.
451 Glib::ustring get_text(const iterator& start, const iterator& end, bool include_hidden_chars = true) const;
453 /** @deprecated Use get_text(bool include_hidden_chars) const.
455 Glib::ustring get_text(bool include_hidden_chars = true);
457 /** Returns all the text in the buffer. Excludes undisplayed
458 * text (text marked with tags that set the invisibility attribute) if
459 * @a include_hidden_chars is <tt>false</tt>. Does not include characters
460 * representing embedded images, so byte and character indexes into
461 * the returned string do <em>not</em> correspond to byte
462 * and character indexes into the buffer. Contrast with
465 * @param include_hidden_chars Whether to include invisible text.
466 * @return An allocated UTF-8 string.
468 Glib::ustring get_text(bool include_hidden_chars = true) const;
470 /** @deprecated Use get_slice(const iterator& start, const iterator& end, bool include_hidden_chars) const.
473 /** Returns the text in the range [ @a start , @a end ). Excludes undisplayed
474 * text (text marked with tags that set the invisibility attribute) if
475 * @a include_hidden_chars is <tt>false</tt>. The returned string includes a
476 * 0xFFFC character whenever the buffer contains
477 * embedded images, so byte and character indexes into
478 * the returned string <em>do</em> correspond to byte
479 * and character indexes into the buffer. Contrast with
480 * get_text(). Note that 0xFFFC can occur in normal
481 * text as well, so it is not a reliable indicator that a pixbuf or
482 * widget is in the buffer.
483 * @param start Start of a range.
484 * @param end End of a range.
485 * @param include_hidden_chars Whether to include invisible text.
486 * @return An allocated UTF-8 string.
488 Glib::ustring get_slice(const iterator& start, const iterator& end, bool include_hidden_chars = true);
491 /** Returns the text in the range [ @a start , @a end ). Excludes undisplayed
492 * text (text marked with tags that set the invisibility attribute) if
493 * @a include_hidden_chars is <tt>false</tt>. The returned string includes a
494 * 0xFFFC character whenever the buffer contains
495 * embedded images, so byte and character indexes into
496 * the returned string <em>do</em> correspond to byte
497 * and character indexes into the buffer. Contrast with
498 * get_text(). Note that 0xFFFC can occur in normal
499 * text as well, so it is not a reliable indicator that a pixbuf or
500 * widget is in the buffer.
501 * @param start Start of a range.
502 * @param end End of a range.
503 * @param include_hidden_chars Whether to include invisible text.
504 * @return An allocated UTF-8 string.
506 Glib::ustring get_slice(const iterator& start, const iterator& end, bool include_hidden_chars = true) const;
508 iterator insert_pixbuf(const iterator& pos, const Glib::RefPtr<Gdk::Pixbuf>& pixbuf);
511 iterator insert_child_anchor(const iterator& pos, const Glib::RefPtr<ChildAnchor>& anchor);
514 Glib::RefPtr<ChildAnchor> create_child_anchor(const iterator& pos);
517 /** Creates a mark at position @a where . The mark can be retrieved by name using
518 * get_mark(). If a mark has left gravity, and text is
519 * inserted at the mark's current location, the mark will be moved to
520 * the left of the newly-inserted text. If the mark has right gravity
521 * ( @a left_gravity = <tt>false</tt>), the mark will end up on the right of
522 * newly-inserted text. The standard left-to-right cursor is a mark
523 * with right gravity (when you type, the cursor stays on the right
524 * side of the text you're typing).
526 * Emits the "mark_set" signal as notification of the mark's initial
528 * @param mark_name Name for mark, or <tt>0</tt>.
529 * @param where Location to place mark.
530 * @param left_gravity Whether the mark has left gravity.
531 * @return The new Gtk::TextMark object.
533 Glib::RefPtr<TextBuffer::Mark> create_mark(const Glib::ustring& mark_name, const iterator& where, bool left_gravity = true);
535 /** Create an anonymous mark. */
536 /** Creates an anonymous mark at position @a where.
538 * If a mark has left gravity, and text is
539 * inserted at the mark's current location, the mark will be moved to
540 * the left of the newly-inserted text. If the mark has right gravity
541 * ( @a left_gravity = <tt>false</tt>), the mark will end up on the right of
542 * newly-inserted text. The standard left-to-right cursor is a mark
543 * with right gravity (when you type, the cursor stays on the right
544 * side of the text you're typing).
546 * Emits the "mark_set" signal as notification of the mark's initial
548 * @param where Location to place mark.
549 * @param left_gravity Whether the mark has left gravity.
550 * @return The new Gtk::TextMark object.
552 Glib::RefPtr<Mark> create_mark(const iterator& where, bool left_gravity = true);
555 /** Moves @a mark to the new location @a where . Emits the "mark_set" signal
556 * as notification of the move.
557 * @param mark A Gtk::TextMark.
558 * @param where New location for @a mark in @a buffer .
560 void move_mark(const Glib::RefPtr<Mark>& mark, const iterator& where);
562 /** Deletes @a mark , so that it's no longer located anywhere in the
563 * buffer. Removes the reference the buffer holds to the mark, so if
564 * you don't keep a Glib::RefPtr to the mark, it will be freed. Even
565 * if the mark isn't freed, most operations on @a mark become
566 * invalid. There is no way to undelete a
567 * mark. Gtk::TextMark::get_deleted() will return <tt>true</tt> after this
568 * function has been called on a mark; Gtk::TextMark::get_deleted()
569 * indicates that a mark no longer belongs to a buffer. The "mark_deleted"
570 * signal will be emitted as notification after the mark is deleted.
571 * @param mark A Gtk::TextMark in @a buffer .
573 void delete_mark(const Glib::RefPtr<Mark>& mark);
576 /** Returns the mark named @a name in buffer @a buffer , or <tt>0</tt> if no such
577 * mark exists in the buffer.
578 * @param name A mark name.
579 * @return A Gtk::TextMark, or <tt>0</tt>.
581 Glib::RefPtr<TextBuffer::Mark> get_mark(const Glib::ustring& name);
583 /** Returns the mark named @a name in buffer @a buffer , or <tt>0</tt> if no such
584 * mark exists in the buffer.
585 * @param name A mark name.
586 * @return A Gtk::TextMark, or <tt>0</tt>.
588 Glib::RefPtr<const TextBuffer::Mark> get_mark(const Glib::ustring& name) const;
591 /** Moves the mark named @a name (which must exist) to location @a where .
592 * See move_mark() for details.
593 * @param name Name of a mark.
594 * @param where New location for mark.
596 void move_mark_by_name(const Glib::ustring& name, const iterator& where);
598 /** Deletes the mark named @a name ; the mark must exist. See
599 * delete_mark() for details.
600 * @param name Name of a mark in @a buffer .
602 void delete_mark_by_name(const Glib::ustring& name);
605 /** Returns the mark that represents the cursor (insertion point).
606 * Equivalent to calling get_mark() to get the mark
607 * named "insert", but very slightly more efficient, and involves less
609 * @return Insertion point mark.
611 Glib::RefPtr<TextBuffer::Mark> get_insert();
613 /** Returns the mark that represents the selection bound. Equivalent
614 * to calling get_mark() to get the mark named
615 * "selection_bound", but very slightly more efficient, and involves
618 * The currently-selected text in @a buffer is the region between the
619 * "selection_bound" and "insert" marks. If "selection_bound" and
620 * "insert" are in the same place, then there is no current selection.
621 * get_selection_bounds() is another convenient function
622 * for handling the selection, if you just want to know whether there's a
623 * selection and what its bounds are.
624 * @return Selection bound mark.
626 Glib::RefPtr<TextBuffer::Mark> get_selection_bound();
629 /** This function moves the "insert" and "selection_bound" marks
630 * simultaneously. If you move them to the same place in two steps
631 * with move_mark(), you will temporarily select a
632 * region in between their old and new locations, which can be pretty
633 * inefficient since the temporarily-selected region will force stuff
634 * to be recalculated. This function moves them as a unit, which can
636 * @param where Where to put the cursor.
638 void place_cursor(const iterator& where);
640 /** Emits the "apply_tag" signal on @a buffer . The default
641 * handler for the signal applies @a tag to the given range.
642 * @a start and @a end do not have to be in order.
643 * @param tag A Gtk::TextTag.
644 * @param start One bound of range to be tagged.
645 * @param end Other bound of range to be tagged.
647 void apply_tag(const Glib::RefPtr<Tag>& tag, const iterator& start, const iterator& end);
649 /** Emits the "remove_tag" signal. The default handler for the signal
650 * removes all occurrences of @a tag from the given range. @a start and
651 * @a end don't have to be in order.
652 * @param tag A Gtk::TextTag.
653 * @param start One bound of range to be untagged.
654 * @param end Other bound of range to be untagged.
656 void remove_tag(const Glib::RefPtr<Tag>& tag, const iterator& start, const iterator& end);
658 /** Calls Gtk::TextTagTable::lookup() on the buffer's tag table to
659 * get a Gtk::TextTag, then calls apply_tag().
660 * @param name Name of a named Gtk::TextTag.
661 * @param start One bound of range to be tagged.
662 * @param end Other bound of range to be tagged.
664 void apply_tag_by_name(const Glib::ustring& name, const iterator& start, const iterator& end);
666 /** Calls Gtk::TextTagTable::lookup() on the buffer's tag table to
667 * get a Gtk::TextTag, then calls remove_tag().
668 * @param name Name of a Gtk::TextTag.
669 * @param start One bound of range to be untagged.
670 * @param end Other bound of range to be untagged.
672 void remove_tag_by_name(const Glib::ustring& name, const iterator& start, const iterator& end);
674 /** Removes all tags in the range between @a start and @a end . Be careful
675 * with this function; it could remove tags added in code unrelated to
676 * the code you're currently writing. That is, using this function is
677 * probably a bad idea if you have two or more unrelated code sections
679 * @param start One bound of range to be untagged.
680 * @param end Other bound of range to be untagged.
682 void remove_all_tags(const iterator& start, const iterator& end);
684 /** Creates a tag and adds it to the tag table for buffer. Equivalent to calling Gtk::TextBuffer::Tag::create() and then adding
685 * the tag to the buffer's tag table.
686 * A tag called @a tag_name must not already exist in the tag table for this buffer.
688 * @param tag_name The name for the new tag.
689 * @result The new tag.
691 Glib::RefPtr<Tag> create_tag(const Glib::ustring& tag_name);
694 /** Creates an anoymous tag and adds it to the tag table for buffer. Equivalent to calling Gtk::TextBuffer::Tag::create() and then adding
695 * the tag to the buffer's tag table.
697 * @result The new tag.
699 Glib::RefPtr<Tag> create_tag();
701 iterator get_iter_at_line_offset(int line_number, int char_offset);
702 iterator get_iter_at_line_index(int line_number, int byte_index);
703 iterator get_iter_at_offset(int char_offset);
704 iterator get_iter_at_line(int line_number);
707 void get_bounds(iterator& range_begin, iterator& range_end);
709 /** Get the current position of a mark.
710 * @param mark The @link Gtk::TextMark Gtk::TextBuffer::Mark@endlink
711 * @result An iterator that points to the position of the @a mark.
713 iterator get_iter_at_mark(const Glib::RefPtr<Mark>& mark);
715 /** Get the current position of an anchor.
716 * @param anchor A @link Gtk::TextChildAnchor Gtk::TextBuffer::Anchor@endlink that appears in the buffer.
717 * @result An iterator that points to the position of the @a anchor.
719 iterator get_iter_at_child_anchor(const Glib::RefPtr<ChildAnchor>& anchor);
722 /** Indicates whether the buffer has been modified since the last call
723 * to set_modified() set the modification flag to
724 * <tt>false</tt>. Used for example to enable a "save" function in a text
726 * @return <tt>true</tt> if the buffer has been modified.
728 bool get_modified() const;
730 /** Used to keep track of whether the buffer has been modified since the
731 * last time it was saved. Whenever the buffer is saved to disk, call
732 * gtk_text_buffer_set_modified ( @a buffer , <tt>false</tt>). When the buffer is modified,
733 * it will automatically toggled on the modified bit again. When the modified
734 * bit flips, the buffer emits a "modified_changed" signal.
735 * @param setting Modification flag setting.
737 void set_modified(bool setting = true);
740 bool get_has_selection() const;
743 /** Adds @a clipboard to the list of clipboards in which the selection contents
744 * of @a buffer are available. In most cases, @a clipboard will be the Gtk::Clipboard
745 * of type Gdk::SELECTION_PRIMARY for a view of @a buffer .
746 * @param clipboard A Gtk::Clipboard.
748 void add_selection_clipboard(const Glib::RefPtr<Clipboard>& clipboard);
750 /** Removes a Gtk::Clipboard added with add_selection_clipboard()
751 * @param clipboard A Gtk::Clipboard added to @a buffer by add_selection_clipboard().
753 void remove_selection_clipboard(const Glib::RefPtr<Clipboard>& clipboard);
755 /** Copies the currently-selected text to a clipboard, then deletes
756 * said text if it's editable.
757 * @param clipboard The Gtk::Clipboard object to cut to.
758 * @param default_editable Default editability of the buffer.
760 void cut_clipboard(const Glib::RefPtr<Clipboard>& clipboard, bool default_editable = true);
762 /** Copies the currently-selected text to a clipboard.
763 * @param clipboard The Gtk::Clipboard object to copy to.
765 void copy_clipboard(const Glib::RefPtr<Clipboard>& clipboard);
766 void paste_clipboard(const Glib::RefPtr<Clipboard>& clipboard, const iterator& override_location, bool default_editable = true);
767 void paste_clipboard(const Glib::RefPtr<Clipboard>& clipboard, bool default_editable = true);
770 /** Returns <tt>true</tt> if some text is selected; places the bounds
771 * of the selection in @a start and @a end (if the selection has length 0,
772 * then @a start and @a end are filled in with the same value).
773 * @a start and @a end will be in ascending order. If @a start and @a end are
774 * <tt>0</tt>, then they are not filled in, but the return value still indicates
775 * whether text is selected.
776 * @param start Iterator to initialize with selection start.
777 * @param end Iterator to initialize with selection end.
778 * @return Whether the selection has nonzero length.
780 bool get_selection_bounds(iterator& start, iterator& end) const;
782 /** Deletes the range between the "insert" and "selection_bound" marks,
783 * that is, the currently-selected text. If @a interactive is <tt>true</tt>,
784 * the editability of the selection will be considered (users can't delete
786 * @param interactive Whether the deletion is caused by user interaction.
787 * @param default_editable Whether the buffer is editable by default.
788 * @return Whether there was a non-empty selection to delete.
790 bool erase_selection(bool interactive = true, bool default_editable = true);
793 /** This function moves the "insert" and "selection_bound" marks
794 * simultaneously. If you move them in two steps
795 * with move_mark(), you will temporarily select a
796 * region in between their old and new locations, which can be pretty
797 * inefficient since the temporarily-selected region will force stuff
798 * to be recalculated. This function moves them as a unit, which can
802 * @param ins Where to put the "insert" mark.
803 * @param bound Where to put the "selection_bound" mark.
805 void select_range(const iterator& ins, const iterator& bound);
807 /* Called to specify atomic user actions, used to implement undo */
809 /** Called to indicate that the buffer operations between here and a
810 * call to end_user_action() are part of a single
811 * user-visible operation. The operations between
812 * begin_user_action() and
813 * end_user_action() can then be grouped when creating
814 * an undo stack. Gtk::TextBuffer maintains a count of calls to
815 * begin_user_action() that have not been closed with
816 * a call to end_user_action(), and emits the "begin_user_action"
817 * and "end_user_action" signals only for the outermost pair of calls.
818 * This allows you to build user actions from other user actions.
820 * The "interactive" buffer mutation functions, such as
821 * insert_interactive(), automatically call begin/end
822 * user action around the buffer operations they perform, so there's
823 * no need to add extra calls if you user action consists solely of a
824 * single call to one of those functions.
826 void begin_user_action();
828 /** Should be paired with a call to begin_user_action().
829 * See that function for a full explanation.
831 void end_user_action();
834 //These are only available on the Maemo platform (patched Gtk+):
837 /** Sets whether rich text can be pasted and dropped to the text buffer.
840 * @param can_paste_rich_text Whether rich text pasting and dropping is enabled.
843 #ifdef GTKMM_MAEMO_EXTENSIONS_ENABLED
844 void set_can_paste_rich_text(bool can_paste_rich_text);
845 #endif // GTKMM_MAEMO_EXTENSIONS_ENABLED
849 * @return Whether rich text pasting and dropping is enabled
854 #ifdef GTKMM_MAEMO_EXTENSIONS_ENABLED
855 bool get_can_paste_rich_text() const;
856 #endif // GTKMM_MAEMO_EXTENSIONS_ENABLED
859 /** Sets a new rich text format for the widget.
862 * @param format Name of a collection of tags that the text view supports.
865 #ifdef GTKMM_MAEMO_EXTENSIONS_ENABLED
866 void set_rich_text_format(const Glib::ustring& format);
867 #endif // GTKMM_MAEMO_EXTENSIONS_ENABLED
870 #ifdef GTKMM_MAEMO_EXTENSIONS_ENABLED
871 /** Accept all formats from clipboard
874 void set_rich_text_format_all();
875 #endif //GTKMM_MAEMO_EXTENSIONS_ENABLED
879 * @return The widget's current rich text format.
884 #ifdef GTKMM_MAEMO_EXTENSIONS_ENABLED
885 Glib::ustring get_rich_text_format() const;
886 #endif // GTKMM_MAEMO_EXTENSIONS_ENABLED
889 //TODO: I have commented these out for now because I don't understand what the register_buffer and content_buffer are. murrayc.
890 //TODO: Documentation.
891 // typedef sigc::slot<guint8*, const Glib::RefPtr<TextBuffer>& /* content_buffer */, const iterator& /* start */, const iterator& /* end */, gsize& /* length */> SlotSerialize;
894 //TODO: Use ArrayHandle, or just use guint8* to be more efficient?
895 // typedef sigc::slot<bool, const Glib::RefPtr<TextBuffer>& /* content_buffer */, iterator& /* iter */, const guint8* /* data */, gsize /* length */, bool /* create_tags */> SlotDeserialize;
898 Glib::ustring register_serialize_format(const Glib::ustring& mime_type, const SlotSerialize& slot);
899 _IGNORE(gtk_text_buffer_register_serialize_format)
903 Glib::ustring register_serialize_tagset(const Glib::ustring& tagset_name);
906 Glib::ustring register_deserialize_format(const Glib::ustring& mime_type, const SlotDeserialize& slot);
907 _IGNORE(gtk_text_buffer_register_deserialize_format)
910 Glib::ustring register_deserialize_tagset(const Glib::ustring& tagset_name);
913 void unregister_serialize_format(const Glib::ustring& format);
915 void unregister_deserialize_format(const Glib::ustring& format);
917 //TODO: Wrap property too, if there is one.
919 void set_can_create_tags(const Glib::ustring& format, bool can_create_tags = true);
921 bool get_can_create_tags(const Glib::ustring& format) const;
924 Glib::StringArrayHandle get_serialize_formats() const;
926 Glib::StringArrayHandle get_deserialize_formats() const;
930 //TODO: I have commented these out for now because I don't understand what the register_buffer and content_buffer are. murrayc.
932 //TODO: Use something other than gsize?
933 #m4 _CONVERSION(`const iterator&', `GtkTextIter*',`($3).gobj()')
934 _WRAP_METHOD(guint8* serialize(const Glib::RefPtr<TextBuffer>& content_buffer,
935 const Glib::ustring& format,
936 const iterator& iterstart,
937 const iterator& iterend,
938 gsize& length), gtk_text_buffer_serialize)
940 //TODO: Is the bool superfluous?
941 //TODO: Use an ArrayHandle?
942 _WRAP_METHOD(bool deserialize(const Glib::RefPtr<TextBuffer>& content_buffer,
943 const Glib::ustring& format,
944 const iterator& iter, const guint8* data,
945 gsize length), gtk_text_buffer_deserialize, errthrow)
951 * <tt>void %insert(const TextBuffer::iterator& pos, const Glib::ustring& text, int bytes)</tt>
954 Glib::SignalProxy3< void,const TextBuffer::iterator&,const Glib::ustring&,int > signal_insert();
959 * <tt>void %insert_pixbuf(const TextBuffer::iterator& pos, const Glib::RefPtr<Gdk::Pixbuf>& pixbuf)</tt>
962 Glib::SignalProxy2< void,const TextBuffer::iterator&,const Glib::RefPtr<Gdk::Pixbuf>& > signal_insert_pixbuf();
967 * <tt>void %insert_child_anchor(const TextBuffer::iterator& pos, const Glib::RefPtr<ChildAnchor>& anchor)</tt>
970 Glib::SignalProxy2< void,const TextBuffer::iterator&,const Glib::RefPtr<ChildAnchor>& > signal_insert_child_anchor();
973 /** The delete_range signal is emitted to delete a range from
974 * a TextBuffer. Note that your handler must not invalidate the
975 * @a start and @a end iters (or has to revalidate them), if it runs before the
976 * default handler. There is no need to keep the iters valid in handlers
977 * which run after the default handler but
978 * those don't have access to the deleted text.
980 * @param start the start of the range to be deleted.
981 * @param end the end of the range to be deleted.
986 * <tt>void %erase(const TextBuffer::iterator& start, const TextBuffer::iterator& end)</tt>
989 Glib::SignalProxy2< void,const TextBuffer::iterator&,const TextBuffer::iterator& > signal_erase();
994 * <tt>void %changed()</tt>
997 Glib::SignalProxy0< void > signal_changed();
1002 * <tt>void %modified_changed()</tt>
1005 Glib::SignalProxy0< void > signal_modified_changed();
1010 * <tt>void %mark_set(const TextBuffer::iterator& location, const Glib::RefPtr<TextBuffer::Mark>& mark)</tt>
1013 Glib::SignalProxy2< void,const TextBuffer::iterator&,const Glib::RefPtr<TextBuffer::Mark>& > signal_mark_set();
1018 * <tt>void %mark_deleted(const Glib::RefPtr<TextBuffer::Mark>& mark)</tt>
1021 Glib::SignalProxy1< void,const Glib::RefPtr<TextBuffer::Mark>& > signal_mark_deleted();
1026 * <tt>void %apply_tag(const Glib::RefPtr<TextBuffer::Tag>& tag, const TextBuffer::iterator& range_begin, const TextBuffer::iterator& range_end)</tt>
1029 Glib::SignalProxy3< void,const Glib::RefPtr<TextBuffer::Tag>&,const TextBuffer::iterator&,const TextBuffer::iterator& > signal_apply_tag();
1034 * <tt>void %remove_tag(const Glib::RefPtr<TextBuffer::Tag>& tag, const TextBuffer::iterator& range_begin, const TextBuffer::iterator& range_end)</tt>
1037 Glib::SignalProxy3< void,const Glib::RefPtr<TextBuffer::Tag>&,const TextBuffer::iterator&,const TextBuffer::iterator& > signal_remove_tag();
1042 * <tt>void %begin_user_action()</tt>
1045 Glib::SignalProxy0< void > signal_begin_user_action();
1050 * <tt>void %end_user_action()</tt>
1053 Glib::SignalProxy0< void > signal_end_user_action();
1056 #ifdef GLIBMM_PROPERTIES_ENABLED
1057 /** Current text of the buffer.
1059 * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
1060 * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
1061 * the value of the property changes.
1063 Glib::PropertyProxy<Glib::ustring> property_text() ;
1064 #endif //#GLIBMM_PROPERTIES_ENABLED
1066 #ifdef GLIBMM_PROPERTIES_ENABLED
1067 /** Current text of the buffer.
1069 * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
1070 * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
1071 * the value of the property changes.
1073 Glib::PropertyProxy_ReadOnly<Glib::ustring> property_text() const;
1074 #endif //#GLIBMM_PROPERTIES_ENABLED
1076 #ifdef GLIBMM_PROPERTIES_ENABLED
1077 /** Whether the buffer has some text currently selected.
1079 * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
1080 * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
1081 * the value of the property changes.
1083 Glib::PropertyProxy_ReadOnly<bool> property_has_selection() const;
1084 #endif //#GLIBMM_PROPERTIES_ENABLED
1090 //C++ methods used to invoke GTK+ virtual functions:
1091 #ifdef GLIBMM_VFUNCS_ENABLED
1092 #endif //GLIBMM_VFUNCS_ENABLED
1095 //GTK+ Virtual Functions (override these to change behaviour):
1096 #ifdef GLIBMM_VFUNCS_ENABLED
1097 #endif //GLIBMM_VFUNCS_ENABLED
1099 //Default Signal Handlers::
1100 #ifdef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
1101 virtual void on_insert(const TextBuffer::iterator& pos, const Glib::ustring& text, int bytes);
1102 virtual void on_insert_pixbuf(const TextBuffer::iterator& pos, const Glib::RefPtr<Gdk::Pixbuf>& pixbuf);
1103 virtual void on_insert_child_anchor(const TextBuffer::iterator& pos, const Glib::RefPtr<ChildAnchor>& anchor);
1104 virtual void on_erase(const TextBuffer::iterator& start, const TextBuffer::iterator& end);
1105 virtual void on_changed();
1106 virtual void on_modified_changed();
1107 virtual void on_mark_set(const TextBuffer::iterator& location, const Glib::RefPtr<TextBuffer::Mark>& mark);
1108 virtual void on_mark_deleted(const Glib::RefPtr<TextBuffer::Mark>& mark);
1109 virtual void on_apply_tag(const Glib::RefPtr<TextBuffer::Tag>& tag, const TextBuffer::iterator& range_begin, const TextBuffer::iterator& range_end);
1110 virtual void on_remove_tag(const Glib::RefPtr<TextBuffer::Tag>& tag, const TextBuffer::iterator& range_begin, const TextBuffer::iterator& range_end);
1111 virtual void on_begin_user_action();
1112 virtual void on_end_user_action();
1113 #endif //GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
1123 /** @relates Gtk::TextBuffer
1124 * @param object The C instance
1125 * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
1126 * @result A C++ instance that wraps this C instance.
1128 Glib::RefPtr<Gtk::TextBuffer> wrap(GtkTextBuffer* object, bool take_copy = false);
1132 #endif /* _GTKMM_TEXTBUFFER_H */