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,
86 const gchar *new_text,
87 gint new_text_length);
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,
121 const GtkTextIter *end);
123 void (* remove_tag) (GtkTextBuffer *buffer,
125 const GtkTextIter *start,
126 const GtkTextIter *end);
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);
142 GType gtk_text_buffer_get_type (void) G_GNUC_CONST;
146 /* table is NULL to create a new one */
147 GtkTextBuffer *gtk_text_buffer_new (GtkTextTagTable *table);
148 gint gtk_text_buffer_get_line_count (GtkTextBuffer *buffer);
149 gint gtk_text_buffer_get_char_count (GtkTextBuffer *buffer);
152 GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer);
154 /* Delete whole buffer, then insert */
155 void gtk_text_buffer_set_text (GtkTextBuffer *buffer,
159 /* Insert into the buffer */
160 void gtk_text_buffer_insert (GtkTextBuffer *buffer,
164 void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer,
168 gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer,
172 gboolean default_editable);
173 gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
176 gboolean default_editable);
178 void gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
180 const GtkTextIter *start,
181 const GtkTextIter *end);
182 gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
184 const GtkTextIter *start,
185 const GtkTextIter *end,
186 gboolean default_editable);
188 void gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer,
192 GtkTextTag *first_tag,
193 ...) G_GNUC_NULL_TERMINATED;
195 void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
199 const gchar *first_tag_name,
200 ...) G_GNUC_NULL_TERMINATED;
202 /* Delete from the buffer */
203 void gtk_text_buffer_delete (GtkTextBuffer *buffer,
206 gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
207 GtkTextIter *start_iter,
208 GtkTextIter *end_iter,
209 gboolean default_editable);
210 gboolean gtk_text_buffer_backspace (GtkTextBuffer *buffer,
212 gboolean interactive,
213 gboolean default_editable);
215 /* Obtain strings from the buffer */
216 gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer,
217 const GtkTextIter *start,
218 const GtkTextIter *end,
219 gboolean include_hidden_chars);
221 gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
222 const GtkTextIter *start,
223 const GtkTextIter *end,
224 gboolean include_hidden_chars);
226 /* Insert a pixbuf */
227 void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
231 /* Insert a child anchor */
232 void gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer,
234 GtkTextChildAnchor *anchor);
236 /* Convenience, create and insert a child anchor */
237 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
240 /* Mark manipulation */
241 void gtk_text_buffer_add_mark (GtkTextBuffer *buffer,
243 const GtkTextIter *where);
244 GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
245 const gchar *mark_name,
246 const GtkTextIter *where,
247 gboolean left_gravity);
248 void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
250 const GtkTextIter *where);
251 void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
253 GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
256 void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
258 const GtkTextIter *where);
259 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
262 GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
263 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
265 /* efficiently move insert and selection_bound at the same time */
266 void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
267 const GtkTextIter *where);
268 void gtk_text_buffer_select_range (GtkTextBuffer *buffer,
269 const GtkTextIter *ins,
270 const GtkTextIter *bound);
274 /* Tag manipulation */
275 void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
277 const GtkTextIter *start,
278 const GtkTextIter *end);
279 void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
281 const GtkTextIter *start,
282 const GtkTextIter *end);
283 void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
285 const GtkTextIter *start,
286 const GtkTextIter *end);
287 void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
289 const GtkTextIter *start,
290 const GtkTextIter *end);
291 void gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
292 const GtkTextIter *start,
293 const GtkTextIter *end);
296 /* You can either ignore the return value, or use it to
297 * set the attributes of the tag. tag_name can be NULL
299 GtkTextTag *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
300 const gchar *tag_name,
301 const gchar *first_property_name,
304 /* Obtain iterators pointed at various places, then you can move the
305 * iterator around using the GtkTextIter operators
307 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
311 void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
315 void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
318 void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
321 void gtk_text_buffer_get_start_iter (GtkTextBuffer *buffer,
323 void gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer,
325 void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
328 void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
332 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
334 GtkTextChildAnchor *anchor);
336 /* There's no get_first_iter because you just get the iter for
339 /* Used to keep track of whether the buffer needs saving; anytime the
340 buffer contents change, the modified flag is turned on. Whenever
341 you save, turn it off. Tags and marks do not affect the modified
342 flag, but if you would like them to you can connect a handler to
343 the tag/mark signals and call set_modified in your handler */
345 gboolean gtk_text_buffer_get_modified (GtkTextBuffer *buffer);
346 void gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
349 gboolean gtk_text_buffer_get_has_selection (GtkTextBuffer *buffer);
351 void gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer,
352 GtkClipboard *clipboard);
353 void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer,
354 GtkClipboard *clipboard);
356 void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
357 GtkClipboard *clipboard,
358 gboolean default_editable);
359 void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer,
360 GtkClipboard *clipboard);
361 void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
362 GtkClipboard *clipboard,
363 GtkTextIter *override_location,
364 gboolean default_editable);
366 gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
369 gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
370 gboolean interactive,
371 gboolean default_editable);
373 /* Called to specify atomic user actions, used to implement undo */
374 void gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer);
375 void gtk_text_buffer_end_user_action (GtkTextBuffer *buffer);
377 GtkTargetList * gtk_text_buffer_get_copy_target_list (GtkTextBuffer *buffer);
378 GtkTargetList * gtk_text_buffer_get_paste_target_list (GtkTextBuffer *buffer);
380 /* INTERNAL private stuff */
381 void _gtk_text_buffer_spew (GtkTextBuffer *buffer);
383 GtkTextBTree* _gtk_text_buffer_get_btree (GtkTextBuffer *buffer);
385 const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
386 const GtkTextIter *anywhere_in_line,
389 void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,
392 void _gtk_text_buffer_get_text_before (GtkTextBuffer *buffer,
393 AtkTextBoundary boundary_type,
394 GtkTextIter *position,
397 void _gtk_text_buffer_get_text_at (GtkTextBuffer *buffer,
398 AtkTextBoundary boundary_type,
399 GtkTextIter *position,
402 void _gtk_text_buffer_get_text_after (GtkTextBuffer *buffer,
403 AtkTextBoundary boundary_type,
404 GtkTextIter *position,