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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #ifndef GTK_TEXT_BUFFER_H
28 #define GTK_TEXT_BUFFER_H
30 #include <gtk/gtkwidget.h>
31 #include <gtk/gtkclipboard.h>
32 #include <gtk/gtktexttagtable.h>
33 #include <gtk/gtktextiter.h>
34 #include <gtk/gtktextmark.h>
35 #include <gtk/gtktextchild.h>
39 #endif /* __cplusplus */
42 * This is the PUBLIC representation of a text buffer.
43 * GtkTextBTree is the PRIVATE internal representation of it.
46 typedef struct _GtkTextBTree GtkTextBTree;
48 typedef struct _GtkTextLogAttrCache GtkTextLogAttrCache;
50 #define GTK_TYPE_TEXT_BUFFER (gtk_text_buffer_get_type ())
51 #define GTK_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBuffer))
52 #define GTK_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
53 #define GTK_IS_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_BUFFER))
54 #define GTK_IS_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_BUFFER))
55 #define GTK_TEXT_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
57 typedef struct _GtkTextBufferClass GtkTextBufferClass;
61 GObject parent_instance;
63 GtkTextTagTable *tag_table;
66 GSList *clipboard_contents_buffers;
67 GSList *selection_clipboards;
69 GtkTextLogAttrCache *log_attr_cache;
71 guint user_action_count;
73 /* Whether the buffer has been modified since last save */
77 struct _GtkTextBufferClass
79 GObjectClass parent_class;
81 void (* insert_text) (GtkTextBuffer *buffer,
86 void (* insert_pixbuf) (GtkTextBuffer *buffer,
90 void (* insert_child_anchor) (GtkTextBuffer *buffer,
92 GtkTextChildAnchor *anchor);
94 void (* delete_range) (GtkTextBuffer *buffer,
98 /* Only for text/widgets/pixbuf changed, marks/tags don't cause this
101 void (* changed) (GtkTextBuffer *buffer);
104 /* New value for the modified flag */
105 void (* modified_changed) (GtkTextBuffer *buffer);
107 /* Mark moved or created */
108 void (* mark_set) (GtkTextBuffer *buffer,
109 const GtkTextIter *location,
112 void (* mark_deleted) (GtkTextBuffer *buffer,
115 void (* apply_tag) (GtkTextBuffer *buffer,
117 const GtkTextIter *start_char,
118 const GtkTextIter *end_char);
120 void (* remove_tag) (GtkTextBuffer *buffer,
122 const GtkTextIter *start_char,
123 const GtkTextIter *end_char);
125 /* Called at the start and end of an atomic user action */
126 void (* begin_user_action) (GtkTextBuffer *buffer);
127 void (* end_user_action) (GtkTextBuffer *buffer);
129 /* Padding for future expansion */
130 void (*_gtk_reserved1) (void);
131 void (*_gtk_reserved2) (void);
132 void (*_gtk_reserved3) (void);
133 void (*_gtk_reserved4) (void);
134 void (*_gtk_reserved5) (void);
135 void (*_gtk_reserved6) (void);
138 GType gtk_text_buffer_get_type (void) G_GNUC_CONST;
142 /* table is NULL to create a new one */
143 GtkTextBuffer *gtk_text_buffer_new (GtkTextTagTable *table);
144 gint gtk_text_buffer_get_line_count (GtkTextBuffer *buffer);
145 gint gtk_text_buffer_get_char_count (GtkTextBuffer *buffer);
148 GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer);
150 /* Delete whole buffer, then insert */
151 void gtk_text_buffer_set_text (GtkTextBuffer *buffer,
155 /* Insert into the buffer */
156 void gtk_text_buffer_insert (GtkTextBuffer *buffer,
160 void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer,
164 gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer,
168 gboolean default_editable);
169 gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
172 gboolean default_editable);
174 void gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
176 const GtkTextIter *start,
177 const GtkTextIter *end);
178 gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
180 const GtkTextIter *start,
181 const GtkTextIter *end,
182 gboolean default_editable);
184 void gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer,
188 GtkTextTag *first_tag,
191 void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
195 const gchar *first_tag_name,
198 /* Delete from the buffer */
199 void gtk_text_buffer_delete (GtkTextBuffer *buffer,
202 gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
203 GtkTextIter *start_iter,
204 GtkTextIter *end_iter,
205 gboolean default_editable);
209 /* Obtain strings from the buffer */
210 gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer,
211 const GtkTextIter *start,
212 const GtkTextIter *end,
213 gboolean include_hidden_chars);
215 gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
216 const GtkTextIter *start,
217 const GtkTextIter *end,
218 gboolean include_hidden_chars);
220 /* Insert a pixbuf */
221 void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
225 /* Insert a child anchor */
226 void gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer,
228 GtkTextChildAnchor *anchor);
230 /* Convenience, create and insert a child anchor */
231 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
234 /* Mark manipulation */
235 GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
236 const gchar *mark_name,
237 const GtkTextIter *where,
238 gboolean left_gravity);
239 void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
241 const GtkTextIter *where);
242 void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
244 GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
247 void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
249 const GtkTextIter *where);
250 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
253 GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
254 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
256 /* efficiently move insert and selection_bound at the same time */
257 void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
258 const GtkTextIter *where);
259 void gtk_text_buffer_select_range (GtkTextBuffer *buffer,
260 const GtkTextIter *ins,
261 const GtkTextIter *bound);
265 /* Tag manipulation */
266 void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
268 const GtkTextIter *start,
269 const GtkTextIter *end);
270 void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
272 const GtkTextIter *start,
273 const GtkTextIter *end);
274 void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
276 const GtkTextIter *start,
277 const GtkTextIter *end);
278 void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
280 const GtkTextIter *start,
281 const GtkTextIter *end);
282 void gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
283 const GtkTextIter *start,
284 const GtkTextIter *end);
287 /* You can either ignore the return value, or use it to
288 * set the attributes of the tag. tag_name can be NULL
290 GtkTextTag *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
291 const gchar *tag_name,
292 const gchar *first_property_name,
295 /* Obtain iterators pointed at various places, then you can move the
296 * iterator around using the GtkTextIter operators
298 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
302 void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
306 void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
309 void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
312 void gtk_text_buffer_get_start_iter (GtkTextBuffer *buffer,
314 void gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer,
316 void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
319 void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
323 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
325 GtkTextChildAnchor *anchor);
327 /* There's no get_first_iter because you just get the iter for
330 /* Used to keep track of whether the buffer needs saving; anytime the
331 buffer contents change, the modified flag is turned on. Whenever
332 you save, turn it off. Tags and marks do not affect the modified
333 flag, but if you would like them to you can connect a handler to
334 the tag/mark signals and call set_modified in your handler */
336 gboolean gtk_text_buffer_get_modified (GtkTextBuffer *buffer);
337 void gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
340 void gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer,
341 GtkClipboard *clipboard);
342 void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer,
343 GtkClipboard *clipboard);
345 void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
346 GtkClipboard *clipboard,
347 gboolean default_editable);
348 void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer,
349 GtkClipboard *clipboard);
350 void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
351 GtkClipboard *clipboard,
352 GtkTextIter *override_location,
353 gboolean default_editable);
355 gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
358 gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
359 gboolean interactive,
360 gboolean default_editable);
362 /* Called to specify atomic user actions, used to implement undo */
363 void gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer);
364 void gtk_text_buffer_end_user_action (GtkTextBuffer *buffer);
366 /* INTERNAL private stuff */
367 void _gtk_text_buffer_spew (GtkTextBuffer *buffer);
369 GtkTextBTree* _gtk_text_buffer_get_btree (GtkTextBuffer *buffer);
371 const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
372 const GtkTextIter *anywhere_in_line,
375 void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,
380 #endif /* __cplusplus */