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 typedef struct _GtkTextLogAttrCache GtkTextLogAttrCache;
49 #define GTK_TYPE_TEXT_BUFFER (gtk_text_buffer_get_type ())
50 #define GTK_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBuffer))
51 #define GTK_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
52 #define GTK_IS_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_BUFFER))
53 #define GTK_IS_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_BUFFER))
54 #define GTK_TEXT_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
56 typedef struct _GtkTextBufferClass GtkTextBufferClass;
60 GObject parent_instance;
62 GtkTextTagTable *tag_table;
65 GtkTextBuffer *clipboard_contents;
67 GtkTextLogAttrCache *log_attr_cache;
69 guint user_action_count;
71 /* Whether the buffer has been modified since last save */
75 struct _GtkTextBufferClass
77 GObjectClass parent_class;
79 void (* insert_text) (GtkTextBuffer *buffer,
84 void (* insert_pixbuf) (GtkTextBuffer *buffer,
88 void (* insert_child_anchor) (GtkTextBuffer *buffer,
90 GtkTextChildAnchor *anchor);
92 void (* delete_range) (GtkTextBuffer *buffer,
96 /* Only for text/widgets/pixbuf changed, marks/tags don't cause this
99 void (* changed) (GtkTextBuffer *buffer);
102 /* New value for the modified flag */
103 void (* modified_changed) (GtkTextBuffer *buffer);
105 /* Mark moved or created */
106 void (* mark_set) (GtkTextBuffer *buffer,
107 const GtkTextIter *location,
110 void (* mark_deleted) (GtkTextBuffer *buffer,
113 void (* apply_tag) (GtkTextBuffer *buffer,
115 const GtkTextIter *start_char,
116 const GtkTextIter *end_char);
118 void (* remove_tag) (GtkTextBuffer *buffer,
120 const GtkTextIter *start_char,
121 const GtkTextIter *end_char);
123 /* Called at the start and end of an atomic user action */
124 void (* begin_user_action) (GtkTextBuffer *buffer);
125 void (* end_user_action) (GtkTextBuffer *buffer);
128 GType gtk_text_buffer_get_type (void) G_GNUC_CONST;
132 /* table is NULL to create a new one */
133 GtkTextBuffer *gtk_text_buffer_new (GtkTextTagTable *table);
134 gint gtk_text_buffer_get_line_count (GtkTextBuffer *buffer);
135 gint gtk_text_buffer_get_char_count (GtkTextBuffer *buffer);
138 GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer);
140 /* Delete whole buffer, then insert */
141 void gtk_text_buffer_set_text (GtkTextBuffer *buffer,
145 /* Insert into the buffer */
146 void gtk_text_buffer_insert (GtkTextBuffer *buffer,
150 void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer,
154 gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer,
158 gboolean default_editable);
159 gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
162 gboolean default_editable);
164 void gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
166 const GtkTextIter *start,
167 const GtkTextIter *end);
168 gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
170 const GtkTextIter *start,
171 const GtkTextIter *end,
172 gboolean default_editable);
174 void gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer,
178 GtkTextTag *first_tag,
181 void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
185 const gchar *first_tag_name,
188 /* Delete from the buffer */
189 void gtk_text_buffer_delete (GtkTextBuffer *buffer,
192 gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
193 GtkTextIter *start_iter,
194 GtkTextIter *end_iter,
195 gboolean default_editable);
199 /* Obtain strings from the buffer */
200 gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer,
201 const GtkTextIter *start,
202 const GtkTextIter *end,
203 gboolean include_hidden_chars);
205 gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
206 const GtkTextIter *start,
207 const GtkTextIter *end,
208 gboolean include_hidden_chars);
210 /* Insert a pixbuf */
211 void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
215 /* Insert a child anchor */
216 void gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer,
218 GtkTextChildAnchor *anchor);
220 /* Convenience, create and insert a child anchor */
221 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
224 /* Mark manipulation */
225 GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
226 const gchar *mark_name,
227 const GtkTextIter *where,
228 gboolean left_gravity);
229 void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
231 const GtkTextIter *where);
232 void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
234 GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
237 void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
239 const GtkTextIter *where);
240 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
243 GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
244 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
246 /* efficiently move insert and selection_bound to same location */
247 void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
248 const GtkTextIter *where);
252 /* Tag manipulation */
253 void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
255 const GtkTextIter *start,
256 const GtkTextIter *end);
257 void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
259 const GtkTextIter *start,
260 const GtkTextIter *end);
261 void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
263 const GtkTextIter *start,
264 const GtkTextIter *end);
265 void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
267 const GtkTextIter *start,
268 const GtkTextIter *end);
269 void gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
270 const GtkTextIter *start,
271 const GtkTextIter *end);
274 /* You can either ignore the return value, or use it to
275 * set the attributes of the tag. tag_name can be NULL
277 GtkTextTag *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
278 const gchar *tag_name,
279 const gchar *first_property_name,
282 /* Obtain iterators pointed at various places, then you can move the
283 * iterator around using the GtkTextIter operators
285 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
289 void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
293 void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
296 void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
299 void gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer,
301 void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
304 void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
308 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
310 GtkTextChildAnchor *anchor);
312 /* There's no get_first_iter because you just get the iter for
315 /* Used to keep track of whether the buffer needs saving; anytime the
316 buffer contents change, the modified flag is turned on. Whenever
317 you save, turn it off. Tags and marks do not affect the modified
318 flag, but if you would like them to you can connect a handler to
319 the tag/mark signals and call set_modified in your handler */
321 gboolean gtk_text_buffer_get_modified (GtkTextBuffer *buffer);
322 void gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
325 void gtk_text_buffer_paste_primary (GtkTextBuffer *buffer,
326 const GtkTextIter *override_location,
327 gboolean default_editable);
328 void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
329 gboolean default_editable);
330 void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer);
331 void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
332 gboolean default_editable);
334 gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
337 gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
338 gboolean interactive,
339 gboolean default_editable);
341 /* Called to specify atomic user actions, used to implement undo */
342 void gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer);
343 void gtk_text_buffer_end_user_action (GtkTextBuffer *buffer);
345 /* INTERNAL private stuff */
346 void _gtk_text_buffer_spew (GtkTextBuffer *buffer);
348 GtkTextBTree* _gtk_text_buffer_get_btree (GtkTextBuffer *buffer);
350 const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
351 const GtkTextIter *anywhere_in_line,
356 #endif /* __cplusplus */