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_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 #define GTK_TYPE_TEXT_BUFFER (gtk_text_buffer_get_type ())
64 #define GTK_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBuffer))
65 #define GTK_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
66 #define GTK_IS_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_BUFFER))
67 #define GTK_IS_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_BUFFER))
68 #define GTK_TEXT_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
70 typedef struct _GtkTextBufferPrivate GtkTextBufferPrivate;
71 typedef struct _GtkTextBufferClass GtkTextBufferClass;
75 GObject parent_instance;
77 GtkTextBufferPrivate *priv;
80 struct _GtkTextBufferClass
82 GObjectClass parent_class;
84 void (* insert_text) (GtkTextBuffer *buffer,
89 void (* insert_pixbuf) (GtkTextBuffer *buffer,
93 void (* insert_child_anchor) (GtkTextBuffer *buffer,
95 GtkTextChildAnchor *anchor);
97 void (* delete_range) (GtkTextBuffer *buffer,
101 /* Only for text/widgets/pixbuf changed, marks/tags don't cause this
104 void (* changed) (GtkTextBuffer *buffer);
107 /* New value for the modified flag */
108 void (* modified_changed) (GtkTextBuffer *buffer);
110 /* Mark moved or created */
111 void (* mark_set) (GtkTextBuffer *buffer,
112 const GtkTextIter *location,
115 void (* mark_deleted) (GtkTextBuffer *buffer,
118 void (* apply_tag) (GtkTextBuffer *buffer,
120 const GtkTextIter *start_char,
121 const GtkTextIter *end_char);
123 void (* remove_tag) (GtkTextBuffer *buffer,
125 const GtkTextIter *start_char,
126 const GtkTextIter *end_char);
128 /* Called at the start and end of an atomic user action */
129 void (* begin_user_action) (GtkTextBuffer *buffer);
130 void (* end_user_action) (GtkTextBuffer *buffer);
132 void (* paste_done) (GtkTextBuffer *buffer,
133 GtkClipboard *clipboard);
135 /* Padding for future expansion */
136 void (*_gtk_reserved1) (void);
137 void (*_gtk_reserved2) (void);
138 void (*_gtk_reserved3) (void);
139 void (*_gtk_reserved4) (void);
140 void (*_gtk_reserved5) (void);
143 GType gtk_text_buffer_get_type (void) G_GNUC_CONST;
147 /* table is NULL to create a new one */
148 GtkTextBuffer *gtk_text_buffer_new (GtkTextTagTable *table);
149 gint gtk_text_buffer_get_line_count (GtkTextBuffer *buffer);
150 gint gtk_text_buffer_get_char_count (GtkTextBuffer *buffer);
153 GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer);
155 /* Delete whole buffer, then insert */
156 void gtk_text_buffer_set_text (GtkTextBuffer *buffer,
160 /* Insert into the buffer */
161 void gtk_text_buffer_insert (GtkTextBuffer *buffer,
165 void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer,
169 gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer,
173 gboolean default_editable);
174 gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
177 gboolean default_editable);
179 void gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
181 const GtkTextIter *start,
182 const GtkTextIter *end);
183 gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
185 const GtkTextIter *start,
186 const GtkTextIter *end,
187 gboolean default_editable);
189 void gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer,
193 GtkTextTag *first_tag,
194 ...) G_GNUC_NULL_TERMINATED;
196 void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
200 const gchar *first_tag_name,
201 ...) G_GNUC_NULL_TERMINATED;
203 /* Delete from the buffer */
204 void gtk_text_buffer_delete (GtkTextBuffer *buffer,
207 gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
208 GtkTextIter *start_iter,
209 GtkTextIter *end_iter,
210 gboolean default_editable);
211 gboolean gtk_text_buffer_backspace (GtkTextBuffer *buffer,
213 gboolean interactive,
214 gboolean default_editable);
216 /* Obtain strings from the buffer */
217 gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer,
218 const GtkTextIter *start,
219 const GtkTextIter *end,
220 gboolean include_hidden_chars);
222 gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
223 const GtkTextIter *start,
224 const GtkTextIter *end,
225 gboolean include_hidden_chars);
227 /* Insert a pixbuf */
228 void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
232 /* Insert a child anchor */
233 void gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer,
235 GtkTextChildAnchor *anchor);
237 /* Convenience, create and insert a child anchor */
238 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
241 /* Mark manipulation */
242 void gtk_text_buffer_add_mark (GtkTextBuffer *buffer,
244 const GtkTextIter *where);
245 GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
246 const gchar *mark_name,
247 const GtkTextIter *where,
248 gboolean left_gravity);
249 void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
251 const GtkTextIter *where);
252 void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
254 GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
257 void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
259 const GtkTextIter *where);
260 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
263 GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
264 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
266 /* efficiently move insert and selection_bound at the same time */
267 void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
268 const GtkTextIter *where);
269 void gtk_text_buffer_select_range (GtkTextBuffer *buffer,
270 const GtkTextIter *ins,
271 const GtkTextIter *bound);
275 /* Tag manipulation */
276 void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
278 const GtkTextIter *start,
279 const GtkTextIter *end);
280 void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
282 const GtkTextIter *start,
283 const GtkTextIter *end);
284 void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
286 const GtkTextIter *start,
287 const GtkTextIter *end);
288 void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
290 const GtkTextIter *start,
291 const GtkTextIter *end);
292 void gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
293 const GtkTextIter *start,
294 const GtkTextIter *end);
297 /* You can either ignore the return value, or use it to
298 * set the attributes of the tag. tag_name can be NULL
300 GtkTextTag *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
301 const gchar *tag_name,
302 const gchar *first_property_name,
305 /* Obtain iterators pointed at various places, then you can move the
306 * iterator around using the GtkTextIter operators
308 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
312 void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
316 void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
319 void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
322 void gtk_text_buffer_get_start_iter (GtkTextBuffer *buffer,
324 void gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer,
326 void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
329 void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
333 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
335 GtkTextChildAnchor *anchor);
337 /* There's no get_first_iter because you just get the iter for
340 /* Used to keep track of whether the buffer needs saving; anytime the
341 buffer contents change, the modified flag is turned on. Whenever
342 you save, turn it off. Tags and marks do not affect the modified
343 flag, but if you would like them to you can connect a handler to
344 the tag/mark signals and call set_modified in your handler */
346 gboolean gtk_text_buffer_get_modified (GtkTextBuffer *buffer);
347 void gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
350 gboolean gtk_text_buffer_get_has_selection (GtkTextBuffer *buffer);
352 void gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer,
353 GtkClipboard *clipboard);
354 void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer,
355 GtkClipboard *clipboard);
357 void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
358 GtkClipboard *clipboard,
359 gboolean default_editable);
360 void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer,
361 GtkClipboard *clipboard);
362 void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
363 GtkClipboard *clipboard,
364 GtkTextIter *override_location,
365 gboolean default_editable);
367 gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
370 gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
371 gboolean interactive,
372 gboolean default_editable);
374 /* Called to specify atomic user actions, used to implement undo */
375 void gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer);
376 void gtk_text_buffer_end_user_action (GtkTextBuffer *buffer);
378 GtkTargetList * gtk_text_buffer_get_copy_target_list (GtkTextBuffer *buffer);
379 GtkTargetList * gtk_text_buffer_get_paste_target_list (GtkTextBuffer *buffer);
381 /* INTERNAL private stuff */
382 void _gtk_text_buffer_spew (GtkTextBuffer *buffer);
384 GtkTextBTree* _gtk_text_buffer_get_btree (GtkTextBuffer *buffer);
386 const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
387 const GtkTextIter *anywhere_in_line,
390 void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,