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>
40 * This is the PUBLIC representation of a text buffer.
41 * GtkTextBTree is the PRIVATE internal representation of it.
44 /* these values are used as "info" for the targets contained in the
45 * lists returned by gtk_text_buffer_get_copy,paste_target_list()
47 * the enum counts down from G_MAXUINT to avoid clashes with application
48 * added drag destinations which usually start at 0.
52 GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS = - 1,
53 GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT = - 2,
54 GTK_TEXT_BUFFER_TARGET_INFO_TEXT = - 3
55 } GtkTextBufferTargetInfo;
57 typedef struct _GtkTextBTree GtkTextBTree;
59 typedef struct _GtkTextLogAttrCache GtkTextLogAttrCache;
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 _GtkTextBufferClass GtkTextBufferClass;
72 GObject parent_instance;
74 GtkTextTagTable *tag_table;
77 GSList *clipboard_contents_buffers;
78 GSList *selection_clipboards;
80 GtkTextLogAttrCache *log_attr_cache;
82 guint user_action_count;
84 /* Whether the buffer has been modified since last save */
87 guint has_selection : 1;
90 struct _GtkTextBufferClass
92 GObjectClass parent_class;
94 void (* insert_text) (GtkTextBuffer *buffer,
99 void (* insert_pixbuf) (GtkTextBuffer *buffer,
103 void (* insert_child_anchor) (GtkTextBuffer *buffer,
105 GtkTextChildAnchor *anchor);
107 void (* delete_range) (GtkTextBuffer *buffer,
111 /* Only for text/widgets/pixbuf changed, marks/tags don't cause this
114 void (* changed) (GtkTextBuffer *buffer);
117 /* New value for the modified flag */
118 void (* modified_changed) (GtkTextBuffer *buffer);
120 /* Mark moved or created */
121 void (* mark_set) (GtkTextBuffer *buffer,
122 const GtkTextIter *location,
125 void (* mark_deleted) (GtkTextBuffer *buffer,
128 void (* apply_tag) (GtkTextBuffer *buffer,
130 const GtkTextIter *start_char,
131 const GtkTextIter *end_char);
133 void (* remove_tag) (GtkTextBuffer *buffer,
135 const GtkTextIter *start_char,
136 const GtkTextIter *end_char);
138 /* Called at the start and end of an atomic user action */
139 void (* begin_user_action) (GtkTextBuffer *buffer);
140 void (* end_user_action) (GtkTextBuffer *buffer);
142 /* Padding for future expansion */
143 void (*_gtk_reserved1) (void);
144 void (*_gtk_reserved2) (void);
145 void (*_gtk_reserved3) (void);
146 void (*_gtk_reserved4) (void);
147 void (*_gtk_reserved5) (void);
148 void (*_gtk_reserved6) (void);
151 GType gtk_text_buffer_get_type (void) G_GNUC_CONST;
155 /* table is NULL to create a new one */
156 GtkTextBuffer *gtk_text_buffer_new (GtkTextTagTable *table);
157 gint gtk_text_buffer_get_line_count (GtkTextBuffer *buffer);
158 gint gtk_text_buffer_get_char_count (GtkTextBuffer *buffer);
161 GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer);
163 /* Delete whole buffer, then insert */
164 void gtk_text_buffer_set_text (GtkTextBuffer *buffer,
168 /* Insert into the buffer */
169 void gtk_text_buffer_insert (GtkTextBuffer *buffer,
173 void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer,
177 gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer,
181 gboolean default_editable);
182 gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
185 gboolean default_editable);
187 void gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
189 const GtkTextIter *start,
190 const GtkTextIter *end);
191 gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
193 const GtkTextIter *start,
194 const GtkTextIter *end,
195 gboolean default_editable);
197 void gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer,
201 GtkTextTag *first_tag,
202 ...) G_GNUC_NULL_TERMINATED;
204 void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
208 const gchar *first_tag_name,
209 ...) G_GNUC_NULL_TERMINATED;
211 /* Delete from the buffer */
212 void gtk_text_buffer_delete (GtkTextBuffer *buffer,
215 gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
216 GtkTextIter *start_iter,
217 GtkTextIter *end_iter,
218 gboolean default_editable);
219 gboolean gtk_text_buffer_backspace (GtkTextBuffer *buffer,
221 gboolean interactive,
222 gboolean default_editable);
224 /* Obtain strings from the buffer */
225 gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer,
226 const GtkTextIter *start,
227 const GtkTextIter *end,
228 gboolean include_hidden_chars);
230 gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
231 const GtkTextIter *start,
232 const GtkTextIter *end,
233 gboolean include_hidden_chars);
235 /* Insert a pixbuf */
236 void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
240 /* Insert a child anchor */
241 void gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer,
243 GtkTextChildAnchor *anchor);
245 /* Convenience, create and insert a child anchor */
246 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
249 /* Mark manipulation */
250 void gtk_text_buffer_add_mark (GtkTextBuffer *buffer,
252 const GtkTextIter *where);
253 GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
254 const gchar *mark_name,
255 const GtkTextIter *where,
256 gboolean left_gravity);
257 void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
259 const GtkTextIter *where);
260 void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
262 GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
265 void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
267 const GtkTextIter *where);
268 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
271 GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
272 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
274 /* efficiently move insert and selection_bound at the same time */
275 void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
276 const GtkTextIter *where);
277 void gtk_text_buffer_select_range (GtkTextBuffer *buffer,
278 const GtkTextIter *ins,
279 const GtkTextIter *bound);
283 /* Tag manipulation */
284 void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
286 const GtkTextIter *start,
287 const GtkTextIter *end);
288 void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
290 const GtkTextIter *start,
291 const GtkTextIter *end);
292 void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
294 const GtkTextIter *start,
295 const GtkTextIter *end);
296 void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
298 const GtkTextIter *start,
299 const GtkTextIter *end);
300 void gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
301 const GtkTextIter *start,
302 const GtkTextIter *end);
305 /* You can either ignore the return value, or use it to
306 * set the attributes of the tag. tag_name can be NULL
308 GtkTextTag *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
309 const gchar *tag_name,
310 const gchar *first_property_name,
313 /* Obtain iterators pointed at various places, then you can move the
314 * iterator around using the GtkTextIter operators
316 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
320 void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
324 void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
327 void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
330 void gtk_text_buffer_get_start_iter (GtkTextBuffer *buffer,
332 void gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer,
334 void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
337 void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
341 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
343 GtkTextChildAnchor *anchor);
345 /* There's no get_first_iter because you just get the iter for
348 /* Used to keep track of whether the buffer needs saving; anytime the
349 buffer contents change, the modified flag is turned on. Whenever
350 you save, turn it off. Tags and marks do not affect the modified
351 flag, but if you would like them to you can connect a handler to
352 the tag/mark signals and call set_modified in your handler */
354 gboolean gtk_text_buffer_get_modified (GtkTextBuffer *buffer);
355 void gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
358 gboolean gtk_text_buffer_get_has_selection (GtkTextBuffer *buffer);
360 void gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer,
361 GtkClipboard *clipboard);
362 void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer,
363 GtkClipboard *clipboard);
365 void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
366 GtkClipboard *clipboard,
367 gboolean default_editable);
368 void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer,
369 GtkClipboard *clipboard);
370 void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
371 GtkClipboard *clipboard,
372 GtkTextIter *override_location,
373 gboolean default_editable);
375 gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
378 gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
379 gboolean interactive,
380 gboolean default_editable);
382 /* Called to specify atomic user actions, used to implement undo */
383 void gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer);
384 void gtk_text_buffer_end_user_action (GtkTextBuffer *buffer);
386 GtkTargetList * gtk_text_buffer_get_copy_target_list (GtkTextBuffer *buffer);
387 GtkTargetList * gtk_text_buffer_get_paste_target_list (GtkTextBuffer *buffer);
389 /* INTERNAL private stuff */
390 void _gtk_text_buffer_spew (GtkTextBuffer *buffer);
392 GtkTextBTree* _gtk_text_buffer_get_btree (GtkTextBuffer *buffer);
394 const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
395 const GtkTextIter *anywhere_in_line,
398 void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,