Debian Codegraph @

gtk/src/textbuffer.hg

raw
1 /* Copyright (C) 1998-2002 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or(at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
15 */
16
17 // This is for including the config header before any code (such as
18 // the #ifndef GTKMM_DISABLE_DEPRECATED in deprecated classes) is generated:
19 _CONFIGINCLUDE(gtkmmconfig.h)
20
21 #include <vector>
22
23 #include <gtkmm/texttagtable.h>
24 #include <gtkmm/textchildanchor.h>
25 #include <gtkmm/textmark.h>
26 #include <gtkmm/textiter.h>
27 #include <gtkmm/clipboard.h>
28 #include <gdkmm/pixbuf.h>
29 #include <gtkmmconfig.h>
30 #include <utility>
31
32 _DEFS(gtkmm,gtk)
33 _PINCLUDE(glibmm/private/object_p.h)
34
35 namespace Gtk
36 {
37
38 class GTKMM_API TextMark;
39 class GTKMM_API TextIter;
40
41 /** Multi-line attributed text that can be displayed by one or more Gtk::TextView widgets.
42 *
43 * 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
44 * might be called "bold" and make the text inside the tag bold. However, the tag concept is more general than that; tags don't
45 * have to affect appearance. They can instead affect the behavior of mouse and key presses, "lock" a range of text so the user
46 * can't edit it, or countless other things. A tag is represented by a @link Gtk::TextTag Gtk::TextBuffer::Tag@endlink object.
47 * 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.
48 *
49 * 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
50 * table associated with it; only tags from that tag table can be used with the buffer. A single tag table can be shared between
51 * multiple buffers, however.
52 *
53 * Most text manipulation is accomplished with iterators, represented by an @link Gtk::TextIter iterator@endlink. The iterator can
54 * be used to navigate over characters, words, lines, and sentences.
55 *
56 * But iterators can't be used to preserve positions across buffer modifications. To preserve a position, the
57 * @link Gtk::TextMark Gtk::TextBuffer::Mark@endlink object is ideal. There are two marks built-in to GtkTextBuffer; these are
58 * named "insert" and "selection_bound" and refer to the insertion point and the boundary of the selection which is not the
59 * insertion point. If no text is selected, these two marks will be in the same position. You can manipulate what is selected and
60 * where the cursor appears by moving these marks around.
61 *
62 * Text buffers always contain at least one line, but may be empty (that is, buffers can contain zero characters). The last line
63 * in the text buffer never ends in a line separator (such as newline); the other lines in the buffer always end in a line
64 * separator. Line separators count as characters when computing character counts and character offsets. Note that some Unicode
65 * line separators are represented with multiple bytes in UTF-8, and the two-character sequence "\r\n" is also considered a line
66 * separator.
67 *
68 * @ingroup TextView
69 */
70 class GTKMM_API TextBuffer : public Glib::Object
71 {
72 _CLASS_GOBJECT(TextBuffer, GtkTextBuffer, GTK_TEXT_BUFFER, Glib::Object, GObject, , , GTKMM_API)
73 _IGNORE(gtk_text_buffer_get_iter_at_line_offset, gtk_text_buffer_get_iter_at_line_index,
74 gtk_text_buffer_get_iter_at_offset, gtk_text_buffer_get_iter_at_line, gtk_text_buffer_get_start_iter,
75 gtk_text_buffer_get_end_iter, gtk_text_buffer_get_bounds, gtk_text_buffer_get_iter_at_mark,
76 gtk_text_buffer_get_selection_bounds, gtk_text_buffer_insert_interactive,
77 gtk_text_buffer_insert, gtk_text_buffer_insert_at_cursor, gtk_text_buffer_insert_interactive_at_cursor,
78 gtk_text_buffer_insert_with_tags, gtk_text_buffer_insert_with_tags_by_name,
79 gtk_text_buffer_get_iter_at_child_anchor, gtk_text_buffer_insert_markup)
80 public:
81 typedef TextIter iterator;
82 typedef TextTag Tag;
83 typedef TextTagTable TagTable;
84 typedef TextMark Mark;
85 typedef TextChildAnchor ChildAnchor;
86
87 protected:
88 _CTOR_DEFAULT()
89 explicit TextBuffer(const Glib::RefPtr<TagTable>& tag_table);
90
91 public:
92 _WRAP_CREATE()
93 _WRAP_CREATE(const Glib::RefPtr<TagTable>& tag_table)
94
95 _WRAP_METHOD(int get_line_count() const, gtk_text_buffer_get_line_count)
96 _WRAP_METHOD(int get_char_count() const, gtk_text_buffer_get_char_count)
97
98 /// See get_char_count().
99 int size() const;
100
101 _WRAP_METHOD(Glib::RefPtr<TextBuffer::TagTable> get_tag_table(), gtk_text_buffer_get_tag_table, refreturn)
102 _WRAP_METHOD(Glib::RefPtr<const TextBuffer::TagTable> get_tag_table() const, gtk_text_buffer_get_tag_table, refreturn, constversion)
103
104 /** Removes the current contents of the buffer, and inserts @a text instead.
105 * @param text The text to put in the buffer.
106 */
107 void set_text(const Glib::ustring& text);
108
109 /** Removes the current contents of the buffer, and inserts @a text instead.
110 * @param text_begin The start of a UTF8 character array.
111 * @param text_end The end of the UTF8 character array.
112 */
113 void set_text(const char* text_begin, const char* text_end);
114 _IGNORE(gtk_text_buffer_set_text)
115
116 //TODO: Make all insert() methods have the same return type:
117
118 /** Inserts @a text at position @a pos.
119 * Emits the "insert_text" signal; insertion actually occurs in the default handler for the signal.
120 * The @a pos iterator is invalidated when insertion occurs (because the buffer contents change).
121 *
122 * @param pos An iterator pointing to the position at which the text should be inserted.
123 * @param text The text to be inserted in the buffer.
124 * @result An iterator that points to the end of the inserted text.
125 */
126 iterator insert(const iterator& pos, const Glib::ustring& text);
127
128 /** Inserts text at position @a pos.
129 * Emits the "insert_text" signal; insertion actually occurs in the default handler for the signal.
130 * The @a pos iterator is invalidated when insertion occurs (because the buffer contents change).
131 *
132 * @param pos An iterator pointing to the position at which the text should be inserted.
133 * @param text_begin The start of a UTF8 character array.
134 * @param text_end The end of the UTF8 character array.
135 * @result An iterator that points to the end of the inserted text.
136 */
137 iterator insert(const iterator& pos, const char* text_begin, const char* text_end);
138
139 /** Inserts @a text, using the current cursor position as the insertion point.
140 * Emits the "insert_text" signal; insertion actually occurs in the default handler for the signal.
141 *
142 * @param text The text to be inserted in the buffer.
143 * @result An iterator that points to the end of the inserted text.
144 */
145 void insert_at_cursor(const Glib::ustring& text);
146
147 /** Inserts text, using the current cursor position as the insertion point.
148 * Emits the "insert_text" signal; insertion actually occurs in the default handler for the signal.
149 *
150 * @param text_begin The start of a UTF8 character array.
151 * @param text_end The end of the UTF8 character array.
152 * @result An iterator that points to the end of the inserted text.
153 */
154 void insert_at_cursor(const char* text_begin, const char* text_end);
155
156 /** Like insert(), but the insertion will not occur if @a iter is at a non-editable location in the buffer.
157 * Usually you want to prevent insertions at ineditable locations if the insertion results from a user action (is interactive).
158 *
159 * @a default_editable indicates the editability of text that doesn't have a tag affecting editability applied to it.
160 * Typically the result of Gtk::TextView::get_editable() is appropriate here.
161 *
162 * @param pos An iterator pointing to the position at which the text should be inserted.
163 * @param text The text to be inserted in the buffer.
164 * @param default_editable Default editability of buffer
165 * @result Whether text was actually inserted
166 */
167 std::pair<iterator,bool> insert_interactive(
168 const iterator& pos, const Glib::ustring& text, bool default_editable = true);
169
170 /** Like insert(), but the insertion will not occur if @a pos is at a non-editable location in the buffer.
171 * Usually you want to prevent insertions at ineditable locations if the insertion results from a user action (is interactive).
172 *
173 * @a default_editable indicates the editability of text that doesn't have a tag affecting editability applied to it.
174 * Typically the result of Gtk::TextView::get_editable() is appropriate here.
175 *
176 * @param pos An iterator pointing to the position at which the text should be inserted.
177 * @param text_begin The start of a UTF8 character array.
178 * @param text_end The end of the UTF8 character array.
179 * @param default_editable Default editability of buffer.
180 * @result Whether text was actually inserted
181 */
182 std::pair<iterator,bool> insert_interactive(
183 const iterator& pos, const char* text_begin, const char* text_end, bool default_editable = true);
184
185 /** Calls insert_interactive() at the cursor position.
186 *
187 * @a default_editable indicates the editability of text that doesn't have a tag affecting editability applied to it.
188 * Typically the result of Gtk::TextView::get_editable() is appropriate here.
189 *
190 * @param text The text to be inserted in the buffer.
191 * @param default_editable Default editability of buffer
192 * @result Whether text was actually inserted
193 */
194 bool insert_interactive_at_cursor(const Glib::ustring& text, bool default_editable = true);
195
196 /** Calls insert_interactive() at the cursor position.
197 *
198 * @a default_editable indicates the editability of text that doesn't have a tag affecting editability applied to it.
199 * Typically the result of Gtk::TextView::get_editable() is appropriate here.
200 *
201 * @param text_begin The start of a UTF8 character array.
202 * @param text_end The end of the UTF8 character array.
203 * @param default_editable Default editability of buffer
204 * @result Whether text was actually inserted
205 */
206 bool insert_interactive_at_cursor(const char* text_begin, const char* text_end,
207 bool default_editable = true);
208
209 /** Copies text, tags, and pixbufs between @a range_begin and @a range_end (the order of range_begin and range_begin doesn't
210 * matter) and inserts the copy at @a pos. Used instead of simply getting/inserting text because it preserves images and tags.
211 * If range_begin and range_end are in a different buffer, the two buffers must share the same tag table.
212 *
213 * Implemented via emissions of the insert_text and apply_tag signals, so expect those.
214 *
215 * @param pos An iterator pointing to the position at which the text should be inserted.
216 * @param range_begin A position in a buffer.
217 * @param range_end Another position in the same buffer as @a range_begin.
218 * @result Whether text was actually inserted
219 */
220 iterator insert(const iterator& pos, const iterator& range_begin, const iterator& range_end);
221 _IGNORE(gtk_text_buffer_insert_range)
222
223 /** Same as insert_range(), but does nothing if the insertion point isn't editable.
224 *
225 * The @a default_editable parameter indicates whether the text is editable at @a pos if no tags enclosing @a pos affect editability.
226 * Typically the result of Gtk::TextView::get_editable() is appropriate here.
227 *
228 * @param pos An iterator pointing to the position at which the text should be inserted.
229 * @param range_begin A position in a buffer.
230 * @param range_end Another position in the same buffer as @a range_begin.
231 * @param default_editable Default editability of buffer.
232 * @result Whether text was actually inserted
233 */
234 std::pair<iterator,bool> insert_interactive(const iterator& pos, const iterator& range_begin, const iterator& range_end, bool default_editable = true);
235 _IGNORE(gtk_text_buffer_insert_range_interactive)
236
237 iterator insert_with_tag(const iterator& pos, const Glib::ustring& text, const Glib::RefPtr<Tag>& tag);
238 iterator insert_with_tag(const iterator& pos, const char* text_begin, const char* text_end, const Glib::RefPtr<Tag>& tag);
239
240 iterator insert_with_tag(const iterator& pos, const Glib::ustring& text, const Glib::ustring& tag_name);
241 iterator insert_with_tag(const iterator& pos, const char* text_begin, const char* text_end, const Glib::ustring& tag_name);
242
243 /** Inserts text into buffer at @a pos, applying the list of tags to the newly-inserted text.
244 * Equivalent to calling insert(), then apply_tag() on the inserted text; This is just a convenience function.
245 *
246 * @param pos An iterator pointing to the position at which the text should be inserted.
247 * @param text The text to be inserted in the buffer.
248 * @param tags A standard C++ container of @link Gtk::TextTag Gtk::TextBuffer::Tags@endlink.
249 * @result Whether text was actually inserted
250 */
251 iterator insert_with_tags(const iterator& pos, const Glib::ustring& text,
252 const std::vector< Glib::RefPtr<Tag> >& tags);
253
254 /** Inserts text into buffer at @a pos, applying the list of tags to the newly-inserted text.
255 * Equivalent to calling insert(), then apply_tag() on the inserted text; This is just a convenience function.
256 *
257 * @param pos An iterator pointing to the position at which the text should be inserted.
258 * @param text_begin The start of a UTF8 character array.
259 * @param text_end The end of the UTF8 character array.
260 * @param tags A standard C++ container of @link Gtk::TextTag Gtk::TextBuffer::Tags@endlink.
261 * @result Whether text was actually inserted
262 */
263 iterator insert_with_tags(const iterator& pos, const char* text_begin, const char* text_end,
264 const std::vector< Glib::RefPtr<Tag> >& tags);
265
266 /** Inserts text into buffer at @a pos, applying the list of tags to the newly-inserted text.
267 * Equivalent to calling insert(), then apply_tag() on the inserted text; This is just a convenience function.
268 *
269 * @param pos An iterator pointing to the position at which the text should be inserted.
270 * @param text The text to be inserted in the buffer.
271 * @param tag_names A standard C++ container of tag names.
272 * @result Whether text was actually inserted
273 */
274 iterator insert_with_tags_by_name(const iterator& pos, const Glib::ustring& text,
275 const std::vector<Glib::ustring>& tag_names);
276
277
278 /** Equivalent to calling insert(), then apply_tag() on the inserted text; This is just a convenience function.
279 *
280 * @param pos An iterator pointing to the position at which the text should be inserted.
281 * @param text_begin The start of a UTF8 character array.
282 * @param text_end The end of the UTF8 character array.
283 * @param tag_names A standard C++ container of tag names.
284 * @result Whether text was actually inserted
285 */
286 iterator insert_with_tags_by_name(const iterator& pos, const char* text_begin, const char* text_end,
287 const std::vector<Glib::ustring>& tag_names);
288
289 /** Inserts text in @a markup at position @a pos.
290 * Emits the "insert_text" signal, possibly multiple times; insertion actually occurs in the
291 * default handler for the signal. The @a pos iterator will point to the end of the
292 * inserted text on return.
293 *
294 * @param pos Location to insert the markup.
295 * @param markup The text containing pango markup to be inserted in the buffer.
296 * @result An iterator that points to the end of the inserted markup text.
297 */
298 iterator insert_markup(const iterator& pos, const Glib::ustring& markup);
299
300 /** Inserts markup text at position @a pos.
301 * Emits the "insert_text" signal; insertion actually occurs in the default handler for the signal.
302 * The @a pos iterator will point to the end of the inserted text on return.
303 *
304 * @param pos Location to insert the markup.
305 * @param markup_begin The start of a UTF8 character array containing pango markup.
306 * @param markup_end The end of the UTF8 character array containing pango markup.
307 * @result An iterator that points to the end of the inserted markup text.
308 */
309 iterator insert_markup(const iterator& pos, const char* markup_begin, const char* markup_end);
310
311 /* Deletes all text between @a range_begin and @a range_end. The order of range_begin and range_end is not actually relevant.
312 * This function actually emits the "delete_range" signal, and the default handler of that signal deletes the text.
313 * Because the buffer is modified, all outstanding iterators become invalid after calling this function.
314 * @param range_begin
315 * @param range_end
316 * @result An iterator that points to the location where text was deleted.
317 */
318 iterator erase(const iterator& range_begin, const iterator& range_end);
319 _IGNORE(gtk_text_buffer_delete)
320
321 /* Deletes all editable text between @a range_begin and @a range_end. The order of range_begin and range_end is not actually relevant.
322 * This function actually emits the "delete_range" signal, and the default handler of that signal deletes the text.
323 * Because the buffer is modified, all outstanding iterators become invalid after calling this function.
324 *
325 * @a default_editable indicates the editability of text that doesn't have a tag affecting editability applied to it.
326 * Typically the result of Gtk::TextView::get_editable() is appropriate here.
327 *
328 * @param range_begin
329 * @param range_end
330 * @param default_editable Default editability of buffer
331 * @result An iterator that points to the location where text was deleted, or end() is no text was deleted.
332 */
333 std::pair<iterator,bool> erase_interactive(const iterator& range_begin, const iterator& range_end, bool default_editable = true);
334 _IGNORE(gtk_text_buffer_delete_interactive)
335
336 /** Performs the appropriate action as if the user hit the delete
337 * key with the cursor at the position specified by @a iter. In the
338 * normal case a single character will be deleted, but when
339 * combining accents are involved, more than one character can
340 * be deleted, and when precomposed character and accent combinations
341 * are involved, less than one character will be deleted.
342 *
343 * Because the buffer is modified, all outstanding iterators become
344 * invalid after calling this method; however, this method returns
345 * a valid iterator that points to the location where text was deleted.
346 *
347 * @param iter A position in the buffer.
348 * @param interactive Whether the deletion is caused by user interaction.
349 * @param default_editable Whether the buffer is editable by default.
350 * @result An iterator to the location where text was deleted, if the buffer was modified.
351 *
352 * @newin{2,6}
353 */
354 iterator backspace(const iterator& iter, bool interactive = true, bool default_editable = true);
355 _IGNORE(gtk_text_buffer_backspace)
356
357 _WRAP_METHOD(Glib::ustring get_text(const iterator& range_start, const iterator& range_end, bool include_hidden_chars = true) const, gtk_text_buffer_get_text)
358
359 /** Returns all the text in the buffer. Excludes undisplayed
360 * text (text marked with tags that set the invisibility attribute) if
361 * @a include_hidden_chars is <tt>false</tt>. Does not include characters
362 * representing embedded images, so byte and character indexes into
363 * the returned string do <em>not</em> correspond to byte
364 * and character indexes into the buffer. Contrast with
365 * get_slice().
366 *
367 * @param include_hidden_chars Whether to include invisible text.
368 * @return An allocated UTF-8 string.
369 */
370 Glib::ustring get_text(bool include_hidden_chars = true) const;
371
372 _WRAP_METHOD(Glib::ustring get_slice(const iterator& range_start, const iterator& range_end, bool include_hidden_chars = true) const, gtk_text_buffer_get_slice)
373
374 iterator insert_pixbuf(const iterator& pos, const Glib::RefPtr<Gdk::Pixbuf>& pixbuf);
375 _IGNORE(gtk_text_buffer_insert_pixbuf)
376
377 iterator insert_child_anchor(const iterator& pos, const Glib::RefPtr<ChildAnchor>& anchor);
378 _IGNORE(gtk_text_buffer_insert_child_anchor)
379
380 Glib::RefPtr<ChildAnchor> create_child_anchor(const iterator& pos);
381 _IGNORE(gtk_text_buffer_create_child_anchor)
382
383 _WRAP_METHOD(void add_mark(const Glib::RefPtr<TextBuffer::Mark>& mark, const iterator& where), gtk_text_buffer_add_mark)
384
385 _WRAP_METHOD(Glib::RefPtr<TextBuffer::Mark> create_mark(const Glib::ustring& mark_name, const iterator& where, bool left_gravity = true), gtk_text_buffer_create_mark, refreturn)
386
387 /** Create an anonymous mark. */
388 /** Creates an anonymous mark at position @a where.
389 *
390 * If a mark has left gravity, and text is
391 * inserted at the mark's current location, the mark will be moved to
392 * the left of the newly-inserted text. If the mark has right gravity
393 * ( @a left_gravity = <tt>false</tt>), the mark will end up on the right of
394 * newly-inserted text. The standard left-to-right cursor is a mark
395 * with right gravity (when you type, the cursor stays on the right
396 * side of the text you're typing).
397 *
398 * Emits the "mark_set" signal as notification of the mark's initial
399 * placement.
400 * @param where Location to place mark.
401 * @param left_gravity Whether the mark has left gravity.
402 * @return The new Gtk::TextMark object.
403 */
404 Glib::RefPtr<Mark> create_mark(const iterator& where, bool left_gravity = true);
405
406 _WRAP_METHOD(void move_mark(const Glib::RefPtr<Mark>& mark, const iterator& where), gtk_text_buffer_move_mark)
407 _WRAP_METHOD(void delete_mark(const Glib::RefPtr<Mark>& mark), gtk_text_buffer_delete_mark)
408
409 _WRAP_METHOD(Glib::RefPtr<TextBuffer::Mark> get_mark(const Glib::ustring& name), gtk_text_buffer_get_mark, refreturn)
410 _WRAP_METHOD(Glib::RefPtr<const TextBuffer::Mark> get_mark(const Glib::ustring& name) const, gtk_text_buffer_get_mark, refreturn, constversion)
411
412 _WRAP_METHOD(void move_mark_by_name(const Glib::ustring& name, const iterator& where), gtk_text_buffer_move_mark_by_name)
413 _WRAP_METHOD(void delete_mark_by_name(const Glib::ustring& name), gtk_text_buffer_delete_mark_by_name)
414
415 _WRAP_METHOD(Glib::RefPtr<TextBuffer::Mark> get_insert(), gtk_text_buffer_get_insert, refreturn)
416 _WRAP_METHOD(Glib::RefPtr<TextBuffer::Mark> get_selection_bound(), gtk_text_buffer_get_selection_bound, refreturn)
417
418 _WRAP_METHOD(void place_cursor(const iterator& where), gtk_text_buffer_place_cursor)
419 _WRAP_METHOD(void apply_tag(const Glib::RefPtr<Tag>& tag, const iterator& range_start, const iterator& range_end), gtk_text_buffer_apply_tag)
420 _WRAP_METHOD(void remove_tag(const Glib::RefPtr<Tag>& tag, const iterator& range_start, const iterator& range_end), gtk_text_buffer_remove_tag)
421 _WRAP_METHOD(void apply_tag_by_name(const Glib::ustring& name, const iterator& range_start, const iterator& range_end), gtk_text_buffer_apply_tag_by_name)
422 _WRAP_METHOD(void remove_tag_by_name(const Glib::ustring& name, const iterator& range_start, const iterator& range_end), gtk_text_buffer_remove_tag_by_name)
423 _WRAP_METHOD(void remove_all_tags(const iterator& range_start, const iterator& range_end), gtk_text_buffer_remove_all_tags)
424
425 /** Creates a tag and adds it to the tag table for buffer. Equivalent to calling Gtk::TextBuffer::Tag::create() and then adding
426 * the tag to the buffer's tag table.
427 * A tag called @a tag_name must not already exist in the tag table for this buffer.
428 *
429 * @param tag_name The name for the new tag.
430 * @result The new tag.
431 */
432 Glib::RefPtr<Tag> create_tag(const Glib::ustring& tag_name);
433 _IGNORE(gtk_text_buffer_create_tag)
434
435 /** Creates an anoymous tag and adds it to the tag table for buffer. Equivalent to calling Gtk::TextBuffer::Tag::create() and then adding
436 * the tag to the buffer's tag table.
437 *
438 * @result The new tag.
439 */
440 Glib::RefPtr<Tag> create_tag();
441
442 iterator get_iter_at_line_offset(int line_number, int char_offset);
443 iterator get_iter_at_line_index(int line_number, int byte_index);
444 iterator get_iter_at_offset(int char_offset);
445 iterator get_iter_at_line(int line_number);
446 iterator begin();
447 iterator end();
448 void get_bounds(iterator& range_begin, iterator& range_end);
449
450 /** Get the current position of a mark.
451 * @param mark The @link Gtk::TextMark Gtk::TextBuffer::Mark@endlink
452 * @result An iterator that points to the position of the @a mark.
453 */
454 iterator get_iter_at_mark(const Glib::RefPtr<Mark>& mark);
455
456 /** Get the current position of an anchor.
457 * @param anchor A @link Gtk::TextChildAnchor Gtk::TextBuffer::Anchor@endlink that appears in the buffer.
458 * @result An iterator that points to the position of the @a anchor.
459 */
460 iterator get_iter_at_child_anchor(const Glib::RefPtr<ChildAnchor>& anchor);
461
462 _WRAP_METHOD(bool get_modified() const, gtk_text_buffer_get_modified)
463 _WRAP_METHOD(void set_modified(bool setting = true), gtk_text_buffer_set_modified)
464
465 _WRAP_METHOD(bool get_has_selection() const, gtk_text_buffer_get_has_selection)
466
467 _WRAP_METHOD(void add_selection_clipboard(const Glib::RefPtr<Clipboard>& clipboard), gtk_text_buffer_add_selection_clipboard)
468 _WRAP_METHOD(void remove_selection_clipboard(const Glib::RefPtr<Clipboard>& clipboard), gtk_text_buffer_remove_selection_clipboard)
469 _WRAP_METHOD(void cut_clipboard(const Glib::RefPtr<Clipboard>& clipboard, bool default_editable = true), gtk_text_buffer_cut_clipboard)
470 _WRAP_METHOD(void copy_clipboard(const Glib::RefPtr<Clipboard>& clipboard), gtk_text_buffer_copy_clipboard)
471 void paste_clipboard(const Glib::RefPtr<Clipboard>& clipboard, const iterator& override_location, bool default_editable = true);
472 void paste_clipboard(const Glib::RefPtr<Clipboard>& clipboard, bool default_editable = true);
473 _IGNORE(gtk_text_buffer_paste_clipboard)
474
475 _WRAP_METHOD(bool get_selection_bounds(iterator& range_start, iterator& range_end) const, gtk_text_buffer_get_selection_bounds)
476 _WRAP_METHOD(bool erase_selection(bool interactive = true, bool default_editable = true), gtk_text_buffer_delete_selection)
477
478 _WRAP_METHOD(void select_range(const iterator& ins, const iterator& bound), gtk_text_buffer_select_range)
479
480 /* Called to specify atomic user actions, used to implement undo */
481 _WRAP_METHOD(void begin_user_action(), gtk_text_buffer_begin_user_action)
482 _WRAP_METHOD(void end_user_action(), gtk_text_buffer_end_user_action)
483
484 _WRAP_METHOD(Glib::RefPtr<TargetList> get_copy_target_list() const, gtk_text_buffer_get_copy_target_list, refreturn)
485 _WRAP_METHOD(Glib::RefPtr<TargetList> get_paste_target_list() const, gtk_text_buffer_get_paste_target_list, refreturn)
486
487 /** For instance,<br>
488 * guint8* on_serialize(const Glib::RefPtr<TextBuffer>& content_buffer, const iterator& start, const iterator& end, gsize& length);
489 *
490 * @param content_buffer The TextBuffer to serialize. It may be different from
491 * the TextBuffer where the serialize format is registered.
492 * @param start Start of the block of text to serialize.
493 * @param end End of the block of text to serialize.
494 * @param[out] length The length of the serialized data.
495 * @return A newly-allocated array of guint8 which contains the serialized data, or <tt>0</tt> if an error occurred.
496 */
497 typedef sigc::slot<guint8*, const Glib::RefPtr<TextBuffer>&, const iterator&, const iterator&, gsize&> SlotSerialize;
498
499 /** For instance,<br>
500 * bool on_deserialize(const Glib::RefPtr<TextBuffer>& content_buffer, iterator& iter, const guint8* data, gsize length, bool create_tags);
501 *
502 * @param content_buffer The TextBuffer to deserialize into. It may be different
503 * from the TextBuffer where the deserialize format is registered.
504 * @param iter Insertion point for the deserialized text.
505 * @param data Data to deserialize.
506 * @param length Length of data.
507 * @param create_tags <tt>true</tt> if deserializing may create tags.
508 * @return <tt>true</tt> on success, <tt>false</tt> otherwise.
509 * @throw Glib::Error If the deserialize slot throws a Glib::Error or an object
510 * derived from Glib::Error, the exception will be propagated out from
511 * the calling deserialize() method.
512 */
513 typedef sigc::slot<bool, const Glib::RefPtr<TextBuffer>&, iterator&, const guint8*, gsize, bool> SlotDeserialize;
514
515 /** This function registers a rich text serialization @a slot along with
516 * its @a mime_type with this TextBuffer.
517 *
518 * @newin{3,16}
519 *
520 * @param mime_type The format’s mime-type.
521 * @param slot The serialize slot to register.
522 * @return The newly registered format’s mime-type.
523 */
524 Glib::ustring register_serialize_format(const Glib::ustring& mime_type, const SlotSerialize& slot);
525 _IGNORE(gtk_text_buffer_register_serialize_format)
526
527 _WRAP_METHOD(Glib::ustring register_serialize_tagset(const Glib::ustring& tagset_name), gtk_text_buffer_register_serialize_tagset)
528
529 /** This function registers a rich text deserialization @a slot along with
530 * its @a mime_type with this TextBuffer.
531 *
532 * @newin{3,16}
533 *
534 * @param mime_type The format’s mime-type.
535 * @param slot The deserialize slot to register.
536 * @return The newly registered format’s mime-type.
537 */
538 Glib::ustring register_deserialize_format(const Glib::ustring& mime_type, const SlotDeserialize& slot);
539 _IGNORE(gtk_text_buffer_register_deserialize_format)
540
541 _WRAP_METHOD(Glib::ustring register_deserialize_tagset(const Glib::ustring& tagset_name), gtk_text_buffer_register_deserialize_tagset)
542
543 _WRAP_METHOD(void unregister_serialize_format(const Glib::ustring& format), gtk_text_buffer_unregister_serialize_format)
544 _WRAP_METHOD(void unregister_deserialize_format(const Glib::ustring& format), gtk_text_buffer_unregister_deserialize_format)
545
546 _WRAP_METHOD(void set_can_create_tags(const Glib::ustring& format, bool can_create_tags = true), gtk_text_buffer_deserialize_set_can_create_tags)
547 _WRAP_METHOD(bool get_can_create_tags(const Glib::ustring& format) const, gtk_text_buffer_deserialize_get_can_create_tags)
548
549
550 std::vector<Glib::ustring> get_serialize_formats() const;
551 _IGNORE(gtk_text_buffer_get_serialize_formats)
552 std::vector<Glib::ustring> get_deserialize_formats() const;
553 _IGNORE(gtk_text_buffer_get_deserialize_formats)
554
555 _WRAP_METHOD(guint8* serialize(const Glib::RefPtr<TextBuffer>& content_buffer,
556 const Glib::ustring& format,
557 const iterator& range_start,
558 const iterator& range_end,
559 gsize& length), gtk_text_buffer_serialize)
560
561 _WRAP_METHOD(bool deserialize(const Glib::RefPtr<TextBuffer>& content_buffer,
562 const Glib::ustring& format,
563 iterator& iter, const guint8* data,
564 gsize length), gtk_text_buffer_deserialize, errthrow)
565
566 #m4begin
567 dnl // HACK: Override the default conversion to deal correctly
568 dnl // with non-0-terminated strings in insert_text_callback().
569 _CONVERSION(`const char*',`const Glib::ustring&',`Glib::ustring(p1, p1 + p2)')
570 #m4end
571 _WRAP_SIGNAL(void insert(const TextBuffer::iterator& pos, const Glib::ustring& text, int bytes), "insert_text")
572
573 #m4 _CONVERSION(`GdkPixbuf*',`const Glib::RefPtr<Gdk::Pixbuf>&', Glib::wrap($3, true))
574 _WRAP_SIGNAL(void insert_pixbuf(const TextBuffer::iterator& pos, const Glib::RefPtr<Gdk::Pixbuf>& pixbuf), "insert_pixbuf")
575
576 #m4 _CONVERSION(`GtkTextChildAnchor*',`const Glib::RefPtr<ChildAnchor>&',`Glib::wrap($3, true)')
577 _WRAP_SIGNAL(void insert_child_anchor(const TextBuffer::iterator& pos, const Glib::RefPtr<ChildAnchor>& anchor), "insert_child_anchor")
578
579 _WRAP_SIGNAL(void erase(const TextBuffer::iterator& range_start, const TextBuffer::iterator& range_end), "delete_range")
580 _WRAP_SIGNAL(void changed(), "changed")
581 _WRAP_SIGNAL(void modified_changed(), "modified_changed")
582
583 #m4 _CONVERSION(`GtkTextMark*',`const Glib::RefPtr<TextBuffer::Mark>&',`Glib::wrap($3, true)')
584 _WRAP_SIGNAL(void mark_set(const TextBuffer::iterator& location, const Glib::RefPtr<TextBuffer::Mark>& mark), "mark_set")
585
586 #m4 _CONVERSION(`GtkTextTag*',`const Glib::RefPtr<TextBuffer::Tag>&',`Glib::wrap($3, true)')
587 _WRAP_SIGNAL(void mark_deleted(const Glib::RefPtr<TextBuffer::Mark>& mark), "mark_deleted")
588 _WRAP_SIGNAL(void apply_tag(const Glib::RefPtr<TextBuffer::Tag>& tag, const TextBuffer::iterator& range_begin, const TextBuffer::iterator& range_end), "apply_tag")
589 _WRAP_SIGNAL(void remove_tag(const Glib::RefPtr<TextBuffer::Tag>& tag, const TextBuffer::iterator& range_begin, const TextBuffer::iterator& range_end), "remove_tag")
590 _WRAP_SIGNAL(void begin_user_action(), "begin_user_action")
591 _WRAP_SIGNAL(void end_user_action(), "end_user_action")
592
593 #m4 _CONVERSION(`GtkClipboard*',`const Glib::RefPtr<Gtk::Clipboard>&', Glib::wrap($3, true))
594 #m4 _CONVERSION(`const Glib::RefPtr<Gtk::Clipboard>&', `GtkClipboard*', Glib::unwrap($3))
595 _WRAP_SIGNAL(void paste_done(const Glib::RefPtr<Gtk::Clipboard>& clipboard), "paste_done")
596
597 _WRAP_PROPERTY("tag-table", Glib::RefPtr<TextBuffer::TagTable>)
598 _WRAP_PROPERTY("text", Glib::ustring)
599 _WRAP_PROPERTY("has-selection", bool)
600 _WRAP_PROPERTY("cursor-position", int)
601 _WRAP_PROPERTY("copy-target-list", Glib::RefPtr<TargetList>)
602 _WRAP_PROPERTY("paste-target-list", Glib::RefPtr<TargetList>)
603 };
604
605 } // namespace Gtk