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 #if defined(GTK_DISABLE_SINGLE_INCLUDES) && !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
28 #error "Only <gtk/gtk.h> can be included directly."
31 #ifndef __GTK_TEXT_BUFFER_H__
32 #define __GTK_TEXT_BUFFER_H__
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclipboard.h>
36 #include <gtk/gtktexttagtable.h>
37 #include <gtk/gtktextiter.h>
38 #include <gtk/gtktextmark.h>
39 #include <gtk/gtktextchild.h>
44 * This is the PUBLIC representation of a text buffer.
45 * GtkTextBTree is the PRIVATE internal representation of it.
48 /* these values are used as "info" for the targets contained in the
49 * lists returned by gtk_text_buffer_get_copy,paste_target_list()
51 * the enum counts down from G_MAXUINT to avoid clashes with application
52 * added drag destinations which usually start at 0.
56 GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS = - 1,
57 GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT = - 2,
58 GTK_TEXT_BUFFER_TARGET_INFO_TEXT = - 3
59 } GtkTextBufferTargetInfo;
61 typedef struct _GtkTextBTree GtkTextBTree;
63 typedef struct _GtkTextLogAttrCache GtkTextLogAttrCache;
65 #define GTK_TYPE_TEXT_BUFFER (gtk_text_buffer_get_type ())
66 #define GTK_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBuffer))
67 #define GTK_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
68 #define GTK_IS_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_BUFFER))
69 #define GTK_IS_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_BUFFER))
70 #define GTK_TEXT_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
72 typedef struct _GtkTextBufferClass GtkTextBufferClass;
76 GObject parent_instance;
78 GtkTextTagTable *GSEAL (tag_table);
79 GtkTextBTree *GSEAL (btree);
81 GSList *GSEAL (clipboard_contents_buffers);
82 GSList *GSEAL (selection_clipboards);
84 GtkTextLogAttrCache *GSEAL (log_attr_cache);
86 guint GSEAL (user_action_count);
88 /* Whether the buffer has been modified since last save */
89 guint GSEAL (modified) : 1;
91 guint GSEAL (has_selection) : 1;
94 struct _GtkTextBufferClass
96 GObjectClass parent_class;
98 void (* insert_text) (GtkTextBuffer *buffer,
103 void (* insert_pixbuf) (GtkTextBuffer *buffer,
107 void (* insert_child_anchor) (GtkTextBuffer *buffer,
109 GtkTextChildAnchor *anchor);
111 void (* delete_range) (GtkTextBuffer *buffer,
115 /* Only for text/widgets/pixbuf changed, marks/tags don't cause this
118 void (* changed) (GtkTextBuffer *buffer);
121 /* New value for the modified flag */
122 void (* modified_changed) (GtkTextBuffer *buffer);
124 /* Mark moved or created */
125 void (* mark_set) (GtkTextBuffer *buffer,
126 const GtkTextIter *location,
129 void (* mark_deleted) (GtkTextBuffer *buffer,
132 void (* apply_tag) (GtkTextBuffer *buffer,
134 const GtkTextIter *start_char,
135 const GtkTextIter *end_char);
137 void (* remove_tag) (GtkTextBuffer *buffer,
139 const GtkTextIter *start_char,
140 const GtkTextIter *end_char);
142 /* Called at the start and end of an atomic user action */
143 void (* begin_user_action) (GtkTextBuffer *buffer);
144 void (* end_user_action) (GtkTextBuffer *buffer);
146 /* Padding for future expansion */
147 void (*_gtk_reserved1) (void);
148 void (*_gtk_reserved2) (void);
149 void (*_gtk_reserved3) (void);
150 void (*_gtk_reserved4) (void);
151 void (*_gtk_reserved5) (void);
152 void (*_gtk_reserved6) (void);
155 GType gtk_text_buffer_get_type (void) G_GNUC_CONST;
159 /* table is NULL to create a new one */
160 GtkTextBuffer *gtk_text_buffer_new (GtkTextTagTable *table);
161 gint gtk_text_buffer_get_line_count (GtkTextBuffer *buffer);
162 gint gtk_text_buffer_get_char_count (GtkTextBuffer *buffer);
165 GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer);
167 /* Delete whole buffer, then insert */
168 void gtk_text_buffer_set_text (GtkTextBuffer *buffer,
172 /* Insert into the buffer */
173 void gtk_text_buffer_insert (GtkTextBuffer *buffer,
177 void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer,
181 gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer,
185 gboolean default_editable);
186 gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
189 gboolean default_editable);
191 void gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
193 const GtkTextIter *start,
194 const GtkTextIter *end);
195 gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
197 const GtkTextIter *start,
198 const GtkTextIter *end,
199 gboolean default_editable);
201 void gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer,
205 GtkTextTag *first_tag,
206 ...) G_GNUC_NULL_TERMINATED;
208 void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
212 const gchar *first_tag_name,
213 ...) G_GNUC_NULL_TERMINATED;
215 /* Delete from the buffer */
216 void gtk_text_buffer_delete (GtkTextBuffer *buffer,
219 gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
220 GtkTextIter *start_iter,
221 GtkTextIter *end_iter,
222 gboolean default_editable);
223 gboolean gtk_text_buffer_backspace (GtkTextBuffer *buffer,
225 gboolean interactive,
226 gboolean default_editable);
228 /* Obtain strings from the buffer */
229 gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer,
230 const GtkTextIter *start,
231 const GtkTextIter *end,
232 gboolean include_hidden_chars);
234 gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
235 const GtkTextIter *start,
236 const GtkTextIter *end,
237 gboolean include_hidden_chars);
239 /* Insert a pixbuf */
240 void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
244 /* Insert a child anchor */
245 void gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer,
247 GtkTextChildAnchor *anchor);
249 /* Convenience, create and insert a child anchor */
250 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
253 /* Mark manipulation */
254 void gtk_text_buffer_add_mark (GtkTextBuffer *buffer,
256 const GtkTextIter *where);
257 GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
258 const gchar *mark_name,
259 const GtkTextIter *where,
260 gboolean left_gravity);
261 void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
263 const GtkTextIter *where);
264 void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
266 GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
269 void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
271 const GtkTextIter *where);
272 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
275 GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
276 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
278 /* efficiently move insert and selection_bound at the same time */
279 void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
280 const GtkTextIter *where);
281 void gtk_text_buffer_select_range (GtkTextBuffer *buffer,
282 const GtkTextIter *ins,
283 const GtkTextIter *bound);
287 /* Tag manipulation */
288 void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
290 const GtkTextIter *start,
291 const GtkTextIter *end);
292 void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
294 const GtkTextIter *start,
295 const GtkTextIter *end);
296 void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
298 const GtkTextIter *start,
299 const GtkTextIter *end);
300 void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
302 const GtkTextIter *start,
303 const GtkTextIter *end);
304 void gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
305 const GtkTextIter *start,
306 const GtkTextIter *end);
309 /* You can either ignore the return value, or use it to
310 * set the attributes of the tag. tag_name can be NULL
312 GtkTextTag *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
313 const gchar *tag_name,
314 const gchar *first_property_name,
317 /* Obtain iterators pointed at various places, then you can move the
318 * iterator around using the GtkTextIter operators
320 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
324 void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
328 void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
331 void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
334 void gtk_text_buffer_get_start_iter (GtkTextBuffer *buffer,
336 void gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer,
338 void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
341 void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
345 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
347 GtkTextChildAnchor *anchor);
349 /* There's no get_first_iter because you just get the iter for
352 /* Used to keep track of whether the buffer needs saving; anytime the
353 buffer contents change, the modified flag is turned on. Whenever
354 you save, turn it off. Tags and marks do not affect the modified
355 flag, but if you would like them to you can connect a handler to
356 the tag/mark signals and call set_modified in your handler */
358 gboolean gtk_text_buffer_get_modified (GtkTextBuffer *buffer);
359 void gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
362 gboolean gtk_text_buffer_get_has_selection (GtkTextBuffer *buffer);
364 void gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer,
365 GtkClipboard *clipboard);
366 void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer,
367 GtkClipboard *clipboard);
369 void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
370 GtkClipboard *clipboard,
371 gboolean default_editable);
372 void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer,
373 GtkClipboard *clipboard);
374 void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
375 GtkClipboard *clipboard,
376 GtkTextIter *override_location,
377 gboolean default_editable);
379 gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
382 gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
383 gboolean interactive,
384 gboolean default_editable);
386 /* Called to specify atomic user actions, used to implement undo */
387 void gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer);
388 void gtk_text_buffer_end_user_action (GtkTextBuffer *buffer);
390 GtkTargetList * gtk_text_buffer_get_copy_target_list (GtkTextBuffer *buffer);
391 GtkTargetList * gtk_text_buffer_get_paste_target_list (GtkTextBuffer *buffer);
393 /* INTERNAL private stuff */
394 void _gtk_text_buffer_spew (GtkTextBuffer *buffer);
396 GtkTextBTree* _gtk_text_buffer_get_btree (GtkTextBuffer *buffer);
398 const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
399 const GtkTextIter *anywhere_in_line,
402 void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,