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,
189 ...) G_GNUC_NULL_TERMINATED;
191 void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
195 const gchar *first_tag_name,
196 ...) G_GNUC_NULL_TERMINATED;
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);
206 gboolean gtk_text_buffer_backspace (GtkTextBuffer *buffer,
208 gboolean interactive,
209 gboolean default_editable);
211 /* Obtain strings from the buffer */
212 gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer,
213 const GtkTextIter *start,
214 const GtkTextIter *end,
215 gboolean include_hidden_chars);
217 gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
218 const GtkTextIter *start,
219 const GtkTextIter *end,
220 gboolean include_hidden_chars);
222 /* Insert a pixbuf */
223 void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
227 /* Insert a child anchor */
228 void gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer,
230 GtkTextChildAnchor *anchor);
232 /* Convenience, create and insert a child anchor */
233 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
236 /* Mark manipulation */
237 GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
238 const gchar *mark_name,
239 const GtkTextIter *where,
240 gboolean left_gravity);
241 void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
243 const GtkTextIter *where);
244 void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
246 GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
249 void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
251 const GtkTextIter *where);
252 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
255 GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
256 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
258 /* efficiently move insert and selection_bound at the same time */
259 void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
260 const GtkTextIter *where);
261 void gtk_text_buffer_select_range (GtkTextBuffer *buffer,
262 const GtkTextIter *ins,
263 const GtkTextIter *bound);
267 /* Tag manipulation */
268 void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
270 const GtkTextIter *start,
271 const GtkTextIter *end);
272 void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
274 const GtkTextIter *start,
275 const GtkTextIter *end);
276 void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
278 const GtkTextIter *start,
279 const GtkTextIter *end);
280 void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
282 const GtkTextIter *start,
283 const GtkTextIter *end);
284 void gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
285 const GtkTextIter *start,
286 const GtkTextIter *end);
289 /* You can either ignore the return value, or use it to
290 * set the attributes of the tag. tag_name can be NULL
292 GtkTextTag *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
293 const gchar *tag_name,
294 const gchar *first_property_name,
295 ...) G_GNUC_NULL_TERMINATED;
297 /* Obtain iterators pointed at various places, then you can move the
298 * iterator around using the GtkTextIter operators
300 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
304 void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
308 void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
311 void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
314 void gtk_text_buffer_get_start_iter (GtkTextBuffer *buffer,
316 void gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer,
318 void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
321 void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
325 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
327 GtkTextChildAnchor *anchor);
329 /* There's no get_first_iter because you just get the iter for
332 /* Used to keep track of whether the buffer needs saving; anytime the
333 buffer contents change, the modified flag is turned on. Whenever
334 you save, turn it off. Tags and marks do not affect the modified
335 flag, but if you would like them to you can connect a handler to
336 the tag/mark signals and call set_modified in your handler */
338 gboolean gtk_text_buffer_get_modified (GtkTextBuffer *buffer);
339 void gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
342 void gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer,
343 GtkClipboard *clipboard);
344 void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer,
345 GtkClipboard *clipboard);
347 void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
348 GtkClipboard *clipboard,
349 gboolean default_editable);
350 void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer,
351 GtkClipboard *clipboard);
352 void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
353 GtkClipboard *clipboard,
354 GtkTextIter *override_location,
355 gboolean default_editable);
357 gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
360 gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
361 gboolean interactive,
362 gboolean default_editable);
364 /* Called to specify atomic user actions, used to implement undo */
365 void gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer);
366 void gtk_text_buffer_end_user_action (GtkTextBuffer *buffer);
368 /* INTERNAL private stuff */
369 void _gtk_text_buffer_spew (GtkTextBuffer *buffer);
371 GtkTextBTree* _gtk_text_buffer_get_btree (GtkTextBuffer *buffer);
373 const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
374 const GtkTextIter *anywhere_in_line,
377 void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,
382 #endif /* __cplusplus */