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;
56 struct _GtkTextBuffer {
57 GtkObject parent_instance;
59 GtkTextTagTable *tag_table;
62 /* Whether the buffer has been modified since last save */
66 struct _GtkTextBufferClass {
67 GtkObjectClass parent_class;
69 void (* insert_text) (GtkTextBuffer *buffer,
73 gboolean interactive);
76 void (* delete_text) (GtkTextBuffer *buffer,
79 gboolean interactive);
81 /* Only for text/widgets/pixbuf changed, marks/tags don't cause this
84 void (* changed) (GtkTextBuffer *buffer);
87 /* New value for the modified flag */
88 void (* modified_changed) (GtkTextBuffer *buffer);
90 /* Mark moved or created */
91 void (* mark_set) (GtkTextBuffer *buffer,
92 const GtkTextIter *location,
95 void (* mark_deleted) (GtkTextBuffer *buffer,
98 void (* apply_tag) (GtkTextBuffer *buffer,
100 const GtkTextIter *start_char,
101 const GtkTextIter *end_char);
103 void (* remove_tag) (GtkTextBuffer *buffer,
105 const GtkTextIter *start_char,
106 const GtkTextIter *end_char);
110 GtkType gtk_text_buffer_get_type (void) G_GNUC_CONST;
114 /* table is NULL to create a new one */
115 GtkTextBuffer *gtk_text_buffer_new (GtkTextTagTable *table);
116 gint gtk_text_buffer_get_line_count (GtkTextBuffer *buffer);
117 gint gtk_text_buffer_get_char_count (GtkTextBuffer *buffer);
120 GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer);
122 /* Delete whole buffer, then insert */
123 void gtk_text_buffer_set_text (GtkTextBuffer *buffer,
127 /* Insert into the buffer */
128 void gtk_text_buffer_insert (GtkTextBuffer *buffer,
132 void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer,
136 gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer,
140 gboolean default_editable);
141 gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
144 gboolean default_editable);
146 void gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
148 const GtkTextIter *start,
149 const GtkTextIter *end);
150 gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
152 const GtkTextIter *start,
153 const GtkTextIter *end,
154 gboolean default_editable);
156 void gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer,
160 GtkTextTag *first_tag,
163 void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
167 const gchar *first_tag_name,
170 /* Delete from the buffer */
171 void gtk_text_buffer_delete (GtkTextBuffer *buffer,
174 gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
175 GtkTextIter *start_iter,
176 GtkTextIter *end_iter,
177 gboolean default_editable);
181 /* Obtain strings from the buffer */
182 gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer,
183 const GtkTextIter *start,
184 const GtkTextIter *end,
185 gboolean include_hidden_chars);
187 gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
188 const GtkTextIter *start,
189 const GtkTextIter *end,
190 gboolean include_hidden_chars);
192 /* Insert a pixbuf */
193 void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
197 /* Create a child anchor */
198 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
201 /* Mark manipulation */
202 GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
203 const gchar *mark_name,
204 const GtkTextIter *where,
205 gboolean left_gravity);
206 void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
208 const GtkTextIter *where);
209 void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
211 GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
214 void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
216 const GtkTextIter *where);
217 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
220 GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
221 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
223 /* efficiently move insert and selection_bound to same location */
224 void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
225 const GtkTextIter *where);
229 /* Tag manipulation */
230 void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
232 const GtkTextIter *start_index,
233 const GtkTextIter *end_index);
234 void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
236 const GtkTextIter *start_index,
237 const GtkTextIter *end_index);
238 void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
240 const GtkTextIter *start_index,
241 const GtkTextIter *end_index);
242 void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
244 const GtkTextIter *start_index,
245 const GtkTextIter *end_index);
248 /* You can either ignore the return value, or use it to
249 * set the attributes of the tag. tag_name can be NULL
251 GtkTextTag *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
252 const gchar *tag_name);
254 /* Obtain iterators pointed at various places, then you can move the
255 iterator around using the GtkTextIter operators */
256 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
260 void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
264 void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
267 void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
270 void gtk_text_buffer_get_last_iter (GtkTextBuffer *buffer,
272 void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
275 void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
279 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
281 GtkTextChildAnchor *anchor);
283 /* There's no get_first_iter because you just get the iter for
286 /* Used to keep track of whether the buffer needs saving; anytime the
287 buffer contents change, the modified flag is turned on. Whenever
288 you save, turn it off. Tags and marks do not affect the modified
289 flag, but if you would like them to you can connect a handler to
290 the tag/mark signals and call set_modified in your handler */
292 gboolean gtk_text_buffer_modified (GtkTextBuffer *buffer);
293 void gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
296 void gtk_text_buffer_paste_primary (GtkTextBuffer *buffer,
297 const GtkTextIter *override_location,
298 gboolean default_editable);
299 void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
300 gboolean default_editable);
301 void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer);
302 void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
303 gboolean default_editable);
305 gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
308 gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
309 gboolean interactive,
310 gboolean default_editable);
312 /* INTERNAL private stuff */
313 void _gtk_text_buffer_spew (GtkTextBuffer *buffer);
315 GtkTextBTree* _gtk_text_buffer_get_btree (GtkTextBuffer *buffer);
319 #endif /* __cplusplus */