1 /* GTK - The GIMP Toolkit
2 * gtktextbuffer.h Copyright (C) 2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
25 #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
26 #error "Only <gtk/gtk.h> can be included directly."
29 #ifndef __GTK_TEXT_BUFFER_H__
30 #define __GTK_TEXT_BUFFER_H__
32 #include <gtk/gtkwidget.h>
33 #include <gtk/gtkclipboard.h>
34 #include <gtk/gtktexttagtable.h>
35 #include <gtk/gtktextiter.h>
36 #include <gtk/gtktextmark.h>
37 #include <gtk/gtktextchild.h>
42 * This is the PUBLIC representation of a text buffer.
43 * GtkTextBTree is the PRIVATE internal representation of it.
46 /* these values are used as "info" for the targets contained in the
47 * lists returned by gtk_text_buffer_get_copy,paste_target_list()
49 * the enum counts down from G_MAXUINT to avoid clashes with application
50 * added drag destinations which usually start at 0.
54 GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS = - 1,
55 GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT = - 2,
56 GTK_TEXT_BUFFER_TARGET_INFO_TEXT = - 3
57 } GtkTextBufferTargetInfo;
59 typedef struct _GtkTextBTree GtkTextBTree;
61 #define GTK_TYPE_TEXT_BUFFER (gtk_text_buffer_get_type ())
62 #define GTK_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBuffer))
63 #define GTK_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
64 #define GTK_IS_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_BUFFER))
65 #define GTK_IS_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_BUFFER))
66 #define GTK_TEXT_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
68 typedef struct _GtkTextBufferPrivate GtkTextBufferPrivate;
69 typedef struct _GtkTextBufferClass GtkTextBufferClass;
73 GObject parent_instance;
75 GtkTextBufferPrivate *priv;
78 struct _GtkTextBufferClass
80 GObjectClass parent_class;
82 void (* insert_text) (GtkTextBuffer *buffer,
84 const gchar *new_text,
85 gint new_text_length);
87 void (* insert_pixbuf) (GtkTextBuffer *buffer,
91 void (* insert_child_anchor) (GtkTextBuffer *buffer,
93 GtkTextChildAnchor *anchor);
95 void (* delete_range) (GtkTextBuffer *buffer,
99 /* Only for text/widgets/pixbuf changed, marks/tags don't cause this
102 void (* changed) (GtkTextBuffer *buffer);
105 /* New value for the modified flag */
106 void (* modified_changed) (GtkTextBuffer *buffer);
108 /* Mark moved or created */
109 void (* mark_set) (GtkTextBuffer *buffer,
110 const GtkTextIter *location,
113 void (* mark_deleted) (GtkTextBuffer *buffer,
116 void (* apply_tag) (GtkTextBuffer *buffer,
118 const GtkTextIter *start,
119 const GtkTextIter *end);
121 void (* remove_tag) (GtkTextBuffer *buffer,
123 const GtkTextIter *start,
124 const GtkTextIter *end);
126 /* Called at the start and end of an atomic user action */
127 void (* begin_user_action) (GtkTextBuffer *buffer);
128 void (* end_user_action) (GtkTextBuffer *buffer);
130 void (* paste_done) (GtkTextBuffer *buffer,
131 GtkClipboard *clipboard);
133 /* Padding for future expansion */
134 void (*_gtk_reserved1) (void);
135 void (*_gtk_reserved2) (void);
136 void (*_gtk_reserved3) (void);
137 void (*_gtk_reserved4) (void);
140 GType gtk_text_buffer_get_type (void) G_GNUC_CONST;
144 /* table is NULL to create a new one */
145 GtkTextBuffer *gtk_text_buffer_new (GtkTextTagTable *table);
146 gint gtk_text_buffer_get_line_count (GtkTextBuffer *buffer);
147 gint gtk_text_buffer_get_char_count (GtkTextBuffer *buffer);
150 GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer);
152 /* Delete whole buffer, then insert */
153 void gtk_text_buffer_set_text (GtkTextBuffer *buffer,
157 /* Insert into the buffer */
158 void gtk_text_buffer_insert (GtkTextBuffer *buffer,
162 void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer,
166 gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer,
170 gboolean default_editable);
171 gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
174 gboolean default_editable);
176 void gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
178 const GtkTextIter *start,
179 const GtkTextIter *end);
180 gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
182 const GtkTextIter *start,
183 const GtkTextIter *end,
184 gboolean default_editable);
186 void gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer,
190 GtkTextTag *first_tag,
191 ...) G_GNUC_NULL_TERMINATED;
193 void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
197 const gchar *first_tag_name,
198 ...) G_GNUC_NULL_TERMINATED;
200 /* Delete from the buffer */
201 void gtk_text_buffer_delete (GtkTextBuffer *buffer,
204 gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
205 GtkTextIter *start_iter,
206 GtkTextIter *end_iter,
207 gboolean default_editable);
208 gboolean gtk_text_buffer_backspace (GtkTextBuffer *buffer,
210 gboolean interactive,
211 gboolean default_editable);
213 /* Obtain strings from the buffer */
214 gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer,
215 const GtkTextIter *start,
216 const GtkTextIter *end,
217 gboolean include_hidden_chars);
219 gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
220 const GtkTextIter *start,
221 const GtkTextIter *end,
222 gboolean include_hidden_chars);
224 /* Insert a pixbuf */
225 void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
229 /* Insert a child anchor */
230 void gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer,
232 GtkTextChildAnchor *anchor);
234 /* Convenience, create and insert a child anchor */
235 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
238 /* Mark manipulation */
239 void gtk_text_buffer_add_mark (GtkTextBuffer *buffer,
241 const GtkTextIter *where);
242 GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
243 const gchar *mark_name,
244 const GtkTextIter *where,
245 gboolean left_gravity);
246 void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
248 const GtkTextIter *where);
249 void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
251 GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
254 void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
256 const GtkTextIter *where);
257 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
260 GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
261 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
263 /* efficiently move insert and selection_bound at the same time */
264 void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
265 const GtkTextIter *where);
266 void gtk_text_buffer_select_range (GtkTextBuffer *buffer,
267 const GtkTextIter *ins,
268 const GtkTextIter *bound);
272 /* Tag manipulation */
273 void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
275 const GtkTextIter *start,
276 const GtkTextIter *end);
277 void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
279 const GtkTextIter *start,
280 const GtkTextIter *end);
281 void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
283 const GtkTextIter *start,
284 const GtkTextIter *end);
285 void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
287 const GtkTextIter *start,
288 const GtkTextIter *end);
289 void gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
290 const GtkTextIter *start,
291 const GtkTextIter *end);
294 /* You can either ignore the return value, or use it to
295 * set the attributes of the tag. tag_name can be NULL
297 GtkTextTag *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
298 const gchar *tag_name,
299 const gchar *first_property_name,
302 /* Obtain iterators pointed at various places, then you can move the
303 * iterator around using the GtkTextIter operators
305 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
309 void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
313 void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
316 void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
319 void gtk_text_buffer_get_start_iter (GtkTextBuffer *buffer,
321 void gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer,
323 void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
326 void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
330 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
332 GtkTextChildAnchor *anchor);
334 /* There's no get_first_iter because you just get the iter for
337 /* Used to keep track of whether the buffer needs saving; anytime the
338 buffer contents change, the modified flag is turned on. Whenever
339 you save, turn it off. Tags and marks do not affect the modified
340 flag, but if you would like them to you can connect a handler to
341 the tag/mark signals and call set_modified in your handler */
343 gboolean gtk_text_buffer_get_modified (GtkTextBuffer *buffer);
344 void gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
347 gboolean gtk_text_buffer_get_has_selection (GtkTextBuffer *buffer);
349 void gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer,
350 GtkClipboard *clipboard);
351 void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer,
352 GtkClipboard *clipboard);
354 void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
355 GtkClipboard *clipboard,
356 gboolean default_editable);
357 void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer,
358 GtkClipboard *clipboard);
359 void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
360 GtkClipboard *clipboard,
361 GtkTextIter *override_location,
362 gboolean default_editable);
364 gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
367 gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
368 gboolean interactive,
369 gboolean default_editable);
371 /* Called to specify atomic user actions, used to implement undo */
372 void gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer);
373 void gtk_text_buffer_end_user_action (GtkTextBuffer *buffer);
375 GtkTargetList * gtk_text_buffer_get_copy_target_list (GtkTextBuffer *buffer);
376 GtkTargetList * gtk_text_buffer_get_paste_target_list (GtkTextBuffer *buffer);
378 /* INTERNAL private stuff */
379 void _gtk_text_buffer_spew (GtkTextBuffer *buffer);
381 GtkTextBTree* _gtk_text_buffer_get_btree (GtkTextBuffer *buffer);
383 const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
384 const GtkTextIter *anywhere_in_line,
387 void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,
390 void _gtk_text_buffer_get_text_before (GtkTextBuffer *buffer,
391 AtkTextBoundary boundary_type,
392 GtkTextIter *position,
395 void _gtk_text_buffer_get_text_at (GtkTextBuffer *buffer,
396 AtkTextBoundary boundary_type,
397 GtkTextIter *position,
400 void _gtk_text_buffer_get_text_after (GtkTextBuffer *buffer,
401 AtkTextBoundary boundary_type,
402 GtkTextIter *position,