1/* GTK - The GIMP Toolkit
2 * gtktextbuffer.h Copyright (C) 2000 Red Hat, Inc.
3 *
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.
8 *
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.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/*
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
23 */
24
25#ifndef __GTK_TEXT_BUFFER_H__
26#define __GTK_TEXT_BUFFER_H__
27
28#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
29#error "Only <gtk/gtk.h> can be included directly."
30#endif
31
32#include <gtk/gtkwidget.h>
33#include <gtk/gtkclipboard.h>
34#include <gtk/gtktexttagtable.h>
35#include <gtk/gtktextiter.h>
36#include <gtk/gtktextmark.h>
37#include <gtk/gtktextchild.h>
38
39G_BEGIN_DECLS
40
41/*
42 * This is the PUBLIC representation of a text buffer.
43 * GtkTextBTree is the PRIVATE internal representation of it.
44 */
45
46/**
47 * GtkTextBufferTargetInfo:
48 * @GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS: Buffer contents
49 * @GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT: Rich text
50 * @GTK_TEXT_BUFFER_TARGET_INFO_TEXT: Text
51 *
52 * These values are used as “info” for the targets contained in the
53 * lists returned by gtk_text_buffer_get_copy_target_list() and
54 * gtk_text_buffer_get_paste_target_list().
55 *
56 * The values counts down from `-1` to avoid clashes
57 * with application added drag destinations which usually start at 0.
58 */
59typedef enum
60{
61 GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS = - 1,
62 GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT = - 2,
63 GTK_TEXT_BUFFER_TARGET_INFO_TEXT = - 3
64} GtkTextBufferTargetInfo;
65
66typedef struct _GtkTextBTree GtkTextBTree;
67
68#define GTK_TYPE_TEXT_BUFFER (gtk_text_buffer_get_type ())
69#define GTK_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBuffer))
70#define GTK_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
71#define GTK_IS_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_BUFFER))
72#define GTK_IS_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_BUFFER))
73#define GTK_TEXT_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
74
75typedef struct _GtkTextBufferPrivate GtkTextBufferPrivate;
76typedef struct _GtkTextBufferClass GtkTextBufferClass;
77
78struct _GtkTextBuffer
79{
80 GObject parent_instance;
81
82 GtkTextBufferPrivate *priv;
83};
84
85/**
86 * GtkTextBufferClass:
87 * @parent_class: The object class structure needs to be the first.
88 * @insert_text: The class handler for the #GtkTextBuffer::insert-text signal.
89 * @insert_pixbuf: The class handler for the #GtkTextBuffer::insert-pixbuf
90 * signal.
91 * @insert_child_anchor: The class handler for the
92 * #GtkTextBuffer::insert-child-anchor signal.
93 * @delete_range: The class handler for the #GtkTextBuffer::delete-range signal.
94 * @changed: The class handler for the #GtkTextBuffer::changed signal.
95 * @modified_changed: The class handler for the #GtkTextBuffer::modified-changed
96 * signal.
97 * @mark_set: The class handler for the #GtkTextBuffer::mark-set signal.
98 * @mark_deleted: The class handler for the #GtkTextBuffer::mark-deleted signal.
99 * @apply_tag: The class handler for the #GtkTextBuffer::apply-tag signal.
100 * @remove_tag: The class handler for the #GtkTextBuffer::remove-tag signal.
101 * @begin_user_action: The class handler for the
102 * #GtkTextBuffer::begin-user-action signal.
103 * @end_user_action: The class handler for the #GtkTextBuffer::end-user-action
104 * signal.
105 * @paste_done: The class handler for the #GtkTextBuffer::paste-done signal.
106 */
107struct _GtkTextBufferClass
108{
109 GObjectClass parent_class;
110
111 void (* insert_text) (GtkTextBuffer *buffer,
112 GtkTextIter *pos,
113 const gchar *new_text,
114 gint new_text_length);
115
116 void (* insert_pixbuf) (GtkTextBuffer *buffer,
117 GtkTextIter *iter,
118 GdkPixbuf *pixbuf);
119
120 void (* insert_child_anchor) (GtkTextBuffer *buffer,
121 GtkTextIter *iter,
122 GtkTextChildAnchor *anchor);
123
124 void (* delete_range) (GtkTextBuffer *buffer,
125 GtkTextIter *start,
126 GtkTextIter *end);
127
128 void (* changed) (GtkTextBuffer *buffer);
129
130 void (* modified_changed) (GtkTextBuffer *buffer);
131
132 void (* mark_set) (GtkTextBuffer *buffer,
133 const GtkTextIter *location,
134 GtkTextMark *mark);
135
136 void (* mark_deleted) (GtkTextBuffer *buffer,
137 GtkTextMark *mark);
138
139 void (* apply_tag) (GtkTextBuffer *buffer,
140 GtkTextTag *tag,
141 const GtkTextIter *start,
142 const GtkTextIter *end);
143
144 void (* remove_tag) (GtkTextBuffer *buffer,
145 GtkTextTag *tag,
146 const GtkTextIter *start,
147 const GtkTextIter *end);
148
149 void (* begin_user_action) (GtkTextBuffer *buffer);
150
151 void (* end_user_action) (GtkTextBuffer *buffer);
152
153 void (* paste_done) (GtkTextBuffer *buffer,
154 GtkClipboard *clipboard);
155
156 /*< private >*/
157
158 /* Padding for future expansion */
159 void (*_gtk_reserved1) (void);
160 void (*_gtk_reserved2) (void);
161 void (*_gtk_reserved3) (void);
162 void (*_gtk_reserved4) (void);
163};
164
165GDK_AVAILABLE_IN_ALL
166GType gtk_text_buffer_get_type (void) G_GNUC_CONST;
167
168
169
170/* table is NULL to create a new one */
171GDK_AVAILABLE_IN_ALL
172GtkTextBuffer *gtk_text_buffer_new (GtkTextTagTable *table);
173GDK_AVAILABLE_IN_ALL
174gint gtk_text_buffer_get_line_count (GtkTextBuffer *buffer);
175GDK_AVAILABLE_IN_ALL
176gint gtk_text_buffer_get_char_count (GtkTextBuffer *buffer);
177
178
179GDK_AVAILABLE_IN_ALL
180GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer);
181
182/* Delete whole buffer, then insert */
183GDK_AVAILABLE_IN_ALL
184void gtk_text_buffer_set_text (GtkTextBuffer *buffer,
185 const gchar *text,
186 gint len);
187
188/* Insert into the buffer */
189GDK_AVAILABLE_IN_ALL
190void gtk_text_buffer_insert (GtkTextBuffer *buffer,
191 GtkTextIter *iter,
192 const gchar *text,
193 gint len);
194GDK_AVAILABLE_IN_ALL
195void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer,
196 const gchar *text,
197 gint len);
198
199GDK_AVAILABLE_IN_ALL
200gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer,
201 GtkTextIter *iter,
202 const gchar *text,
203 gint len,
204 gboolean default_editable);
205GDK_AVAILABLE_IN_ALL
206gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
207 const gchar *text,
208 gint len,
209 gboolean default_editable);
210
211GDK_AVAILABLE_IN_ALL
212void gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
213 GtkTextIter *iter,
214 const GtkTextIter *start,
215 const GtkTextIter *end);
216GDK_AVAILABLE_IN_ALL
217gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
218 GtkTextIter *iter,
219 const GtkTextIter *start,
220 const GtkTextIter *end,
221 gboolean default_editable);
222
223GDK_AVAILABLE_IN_ALL
224void gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer,
225 GtkTextIter *iter,
226 const gchar *text,
227 gint len,
228 GtkTextTag *first_tag,
229 ...) G_GNUC_NULL_TERMINATED;
230
231GDK_AVAILABLE_IN_ALL
232void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
233 GtkTextIter *iter,
234 const gchar *text,
235 gint len,
236 const gchar *first_tag_name,
237 ...) G_GNUC_NULL_TERMINATED;
238
239GDK_AVAILABLE_IN_3_16
240void gtk_text_buffer_insert_markup (GtkTextBuffer *buffer,
241 GtkTextIter *iter,
242 const gchar *markup,
243 gint len);
244
245/* Delete from the buffer */
246GDK_AVAILABLE_IN_ALL
247void gtk_text_buffer_delete (GtkTextBuffer *buffer,
248 GtkTextIter *start,
249 GtkTextIter *end);
250GDK_AVAILABLE_IN_ALL
251gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
252 GtkTextIter *start_iter,
253 GtkTextIter *end_iter,
254 gboolean default_editable);
255GDK_AVAILABLE_IN_ALL
256gboolean gtk_text_buffer_backspace (GtkTextBuffer *buffer,
257 GtkTextIter *iter,
258 gboolean interactive,
259 gboolean default_editable);
260
261/* Obtain strings from the buffer */
262GDK_AVAILABLE_IN_ALL
263gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer,
264 const GtkTextIter *start,
265 const GtkTextIter *end,
266 gboolean include_hidden_chars);
267
268GDK_AVAILABLE_IN_ALL
269gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
270 const GtkTextIter *start,
271 const GtkTextIter *end,
272 gboolean include_hidden_chars);
273
274/* Insert a pixbuf */
275GDK_AVAILABLE_IN_ALL
276void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
277 GtkTextIter *iter,
278 GdkPixbuf *pixbuf);
279
280/* Insert a child anchor */
281GDK_AVAILABLE_IN_ALL
282void gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer,
283 GtkTextIter *iter,
284 GtkTextChildAnchor *anchor);
285
286/* Convenience, create and insert a child anchor */
287GDK_AVAILABLE_IN_ALL
288GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
289 GtkTextIter *iter);
290
291/* Mark manipulation */
292GDK_AVAILABLE_IN_ALL
293void gtk_text_buffer_add_mark (GtkTextBuffer *buffer,
294 GtkTextMark *mark,
295 const GtkTextIter *where);
296GDK_AVAILABLE_IN_ALL
297GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
298 const gchar *mark_name,
299 const GtkTextIter *where,
300 gboolean left_gravity);
301GDK_AVAILABLE_IN_ALL
302void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
303 GtkTextMark *mark,
304 const GtkTextIter *where);
305GDK_AVAILABLE_IN_ALL
306void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
307 GtkTextMark *mark);
308GDK_AVAILABLE_IN_ALL
309GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
310 const gchar *name);
311
312GDK_AVAILABLE_IN_ALL
313void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
314 const gchar *name,
315 const GtkTextIter *where);
316GDK_AVAILABLE_IN_ALL
317void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
318 const gchar *name);
319
320GDK_AVAILABLE_IN_ALL
321GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
322GDK_AVAILABLE_IN_ALL
323GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
324
325/* efficiently move insert and selection_bound at the same time */
326GDK_AVAILABLE_IN_ALL
327void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
328 const GtkTextIter *where);
329GDK_AVAILABLE_IN_ALL
330void gtk_text_buffer_select_range (GtkTextBuffer *buffer,
331 const GtkTextIter *ins,
332 const GtkTextIter *bound);
333
334
335
336/* Tag manipulation */
337GDK_AVAILABLE_IN_ALL
338void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
339 GtkTextTag *tag,
340 const GtkTextIter *start,
341 const GtkTextIter *end);
342GDK_AVAILABLE_IN_ALL
343void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
344 GtkTextTag *tag,
345 const GtkTextIter *start,
346 const GtkTextIter *end);
347GDK_AVAILABLE_IN_ALL
348void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
349 const gchar *name,
350 const GtkTextIter *start,
351 const GtkTextIter *end);
352GDK_AVAILABLE_IN_ALL
353void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
354 const gchar *name,
355 const GtkTextIter *start,
356 const GtkTextIter *end);
357GDK_AVAILABLE_IN_ALL
358void gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
359 const GtkTextIter *start,
360 const GtkTextIter *end);
361
362
363/* You can either ignore the return value, or use it to
364 * set the attributes of the tag. tag_name can be NULL
365 */
366GDK_AVAILABLE_IN_ALL
367GtkTextTag *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
368 const gchar *tag_name,
369 const gchar *first_property_name,
370 ...);
371
372/* Obtain iterators pointed at various places, then you can move the
373 * iterator around using the GtkTextIter operators
374 */
375GDK_AVAILABLE_IN_ALL
376void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
377 GtkTextIter *iter,
378 gint line_number,
379 gint char_offset);
380GDK_AVAILABLE_IN_ALL
381void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
382 GtkTextIter *iter,
383 gint line_number,
384 gint byte_index);
385GDK_AVAILABLE_IN_ALL
386void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
387 GtkTextIter *iter,
388 gint char_offset);
389GDK_AVAILABLE_IN_ALL
390void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
391 GtkTextIter *iter,
392 gint line_number);
393GDK_AVAILABLE_IN_ALL
394void gtk_text_buffer_get_start_iter (GtkTextBuffer *buffer,
395 GtkTextIter *iter);
396GDK_AVAILABLE_IN_ALL
397void gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer,
398 GtkTextIter *iter);
399GDK_AVAILABLE_IN_ALL
400void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
401 GtkTextIter *start,
402 GtkTextIter *end);
403GDK_AVAILABLE_IN_ALL
404void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
405 GtkTextIter *iter,
406 GtkTextMark *mark);
407
408GDK_AVAILABLE_IN_ALL
409void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
410 GtkTextIter *iter,
411 GtkTextChildAnchor *anchor);
412
413/* There's no get_first_iter because you just get the iter for
414 line or char 0 */
415
416/* Used to keep track of whether the buffer needs saving; anytime the
417 buffer contents change, the modified flag is turned on. Whenever
418 you save, turn it off. Tags and marks do not affect the modified
419 flag, but if you would like them to you can connect a handler to
420 the tag/mark signals and call set_modified in your handler */
421
422GDK_AVAILABLE_IN_ALL
423gboolean gtk_text_buffer_get_modified (GtkTextBuffer *buffer);
424GDK_AVAILABLE_IN_ALL
425void gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
426 gboolean setting);
427
428GDK_AVAILABLE_IN_ALL
429gboolean gtk_text_buffer_get_has_selection (GtkTextBuffer *buffer);
430
431GDK_AVAILABLE_IN_ALL
432void gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer,
433 GtkClipboard *clipboard);
434GDK_AVAILABLE_IN_ALL
435void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer,
436 GtkClipboard *clipboard);
437
438GDK_AVAILABLE_IN_ALL
439void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
440 GtkClipboard *clipboard,
441 gboolean default_editable);
442GDK_AVAILABLE_IN_ALL
443void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer,
444 GtkClipboard *clipboard);
445GDK_AVAILABLE_IN_ALL
446void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
447 GtkClipboard *clipboard,
448 GtkTextIter *override_location,
449 gboolean default_editable);
450
451GDK_AVAILABLE_IN_ALL
452gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
453 GtkTextIter *start,
454 GtkTextIter *end);
455GDK_AVAILABLE_IN_ALL
456gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
457 gboolean interactive,
458 gboolean default_editable);
459
460/* Called to specify atomic user actions, used to implement undo */
461GDK_AVAILABLE_IN_ALL
462void gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer);
463GDK_AVAILABLE_IN_ALL
464void gtk_text_buffer_end_user_action (GtkTextBuffer *buffer);
465
466GDK_AVAILABLE_IN_ALL
467GtkTargetList * gtk_text_buffer_get_copy_target_list (GtkTextBuffer *buffer);
468GDK_AVAILABLE_IN_ALL
469GtkTargetList * gtk_text_buffer_get_paste_target_list (GtkTextBuffer *buffer);
470
471
472G_END_DECLS
473
474#endif
475