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/gtktexttagtable.h>
32 #include <gtk/gtktextiter.h>
33 #include <gtk/gtktextmark.h>
34 #include <gtk/gtktextchild.h>
38 #endif /* __cplusplus */
41 * This is the PUBLIC representation of a text buffer.
42 * GtkTextBTree is the PRIVATE internal representation of it.
45 typedef struct _GtkTextBTree GtkTextBTree;
47 #define GTK_TYPE_TEXT_BUFFER (gtk_text_buffer_get_type ())
48 #define GTK_TEXT_BUFFER(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBuffer))
49 #define GTK_TEXT_BUFFER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
50 #define GTK_IS_TEXT_BUFFER(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_TEXT_BUFFER))
51 #define GTK_IS_TEXT_BUFFER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_BUFFER))
52 #define GTK_TEXT_BUFFER_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
54 typedef struct _GtkTextBufferClass GtkTextBufferClass;
58 GtkObject parent_instance;
60 GtkTextTagTable *tag_table;
63 GtkTextBuffer *clipboard_contents;
65 /* Whether the buffer has been modified since last save */
69 struct _GtkTextBufferClass
71 GtkObjectClass parent_class;
73 void (* insert_text) (GtkTextBuffer *buffer,
77 gboolean interactive);
80 void (* delete_text) (GtkTextBuffer *buffer,
83 gboolean interactive);
85 /* Only for text/widgets/pixbuf changed, marks/tags don't cause this
88 void (* changed) (GtkTextBuffer *buffer);
91 /* New value for the modified flag */
92 void (* modified_changed) (GtkTextBuffer *buffer);
94 /* Mark moved or created */
95 void (* mark_set) (GtkTextBuffer *buffer,
96 const GtkTextIter *location,
99 void (* mark_deleted) (GtkTextBuffer *buffer,
102 void (* apply_tag) (GtkTextBuffer *buffer,
104 const GtkTextIter *start_char,
105 const GtkTextIter *end_char);
107 void (* remove_tag) (GtkTextBuffer *buffer,
109 const GtkTextIter *start_char,
110 const GtkTextIter *end_char);
114 GtkType gtk_text_buffer_get_type (void) G_GNUC_CONST;
118 /* table is NULL to create a new one */
119 GtkTextBuffer *gtk_text_buffer_new (GtkTextTagTable *table);
120 gint gtk_text_buffer_get_line_count (GtkTextBuffer *buffer);
121 gint gtk_text_buffer_get_char_count (GtkTextBuffer *buffer);
124 GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer);
126 /* Delete whole buffer, then insert */
127 void gtk_text_buffer_set_text (GtkTextBuffer *buffer,
131 /* Insert into the buffer */
132 void gtk_text_buffer_insert (GtkTextBuffer *buffer,
136 void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer,
140 gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer,
144 gboolean default_editable);
145 gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
148 gboolean default_editable);
150 void gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
152 const GtkTextIter *start,
153 const GtkTextIter *end);
154 gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
156 const GtkTextIter *start,
157 const GtkTextIter *end,
158 gboolean default_editable);
160 void gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer,
164 GtkTextTag *first_tag,
167 void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
171 const gchar *first_tag_name,
174 /* Delete from the buffer */
175 void gtk_text_buffer_delete (GtkTextBuffer *buffer,
178 gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
179 GtkTextIter *start_iter,
180 GtkTextIter *end_iter,
181 gboolean default_editable);
185 /* Obtain strings from the buffer */
186 gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer,
187 const GtkTextIter *start,
188 const GtkTextIter *end,
189 gboolean include_hidden_chars);
191 gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
192 const GtkTextIter *start,
193 const GtkTextIter *end,
194 gboolean include_hidden_chars);
196 /* Insert a pixbuf */
197 void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
201 /* Create a child anchor */
202 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
205 /* Mark manipulation */
206 GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
207 const gchar *mark_name,
208 const GtkTextIter *where,
209 gboolean left_gravity);
210 void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
212 const GtkTextIter *where);
213 void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
215 GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
218 void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
220 const GtkTextIter *where);
221 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
224 GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
225 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
227 /* efficiently move insert and selection_bound to same location */
228 void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
229 const GtkTextIter *where);
233 /* Tag manipulation */
234 void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
236 const GtkTextIter *start_index,
237 const GtkTextIter *end_index);
238 void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
240 const GtkTextIter *start_index,
241 const GtkTextIter *end_index);
242 void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
244 const GtkTextIter *start_index,
245 const GtkTextIter *end_index);
246 void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
248 const GtkTextIter *start_index,
249 const GtkTextIter *end_index);
252 /* You can either ignore the return value, or use it to
253 * set the attributes of the tag. tag_name can be NULL
255 GtkTextTag *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
256 const gchar *tag_name);
258 /* Obtain iterators pointed at various places, then you can move the
259 iterator around using the GtkTextIter operators */
260 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
264 void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
268 void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
271 void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
274 void gtk_text_buffer_get_last_iter (GtkTextBuffer *buffer,
276 void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
279 void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
283 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
285 GtkTextChildAnchor *anchor);
287 /* There's no get_first_iter because you just get the iter for
290 /* Used to keep track of whether the buffer needs saving; anytime the
291 buffer contents change, the modified flag is turned on. Whenever
292 you save, turn it off. Tags and marks do not affect the modified
293 flag, but if you would like them to you can connect a handler to
294 the tag/mark signals and call set_modified in your handler */
296 gboolean gtk_text_buffer_modified (GtkTextBuffer *buffer);
297 void gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
300 void gtk_text_buffer_paste_primary (GtkTextBuffer *buffer,
301 const GtkTextIter *override_location,
302 gboolean default_editable);
303 void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
304 gboolean default_editable);
305 void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer);
306 void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
307 gboolean default_editable);
309 gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
312 gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
313 gboolean interactive,
314 gboolean default_editable);
316 /* INTERNAL private stuff */
317 void _gtk_text_buffer_spew (GtkTextBuffer *buffer);
319 GtkTextBTree* _gtk_text_buffer_get_btree (GtkTextBuffer *buffer);
323 #endif /* __cplusplus */