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
void (* paste_done) (GtkTextBuffer *buffer,
147
GtkClipboard *clipboard);
149
/* Padding for future expansion */
150
void (*_gtk_reserved1) (void);
151
void (*_gtk_reserved2) (void);
152
void (*_gtk_reserved3) (void);
153
void (*_gtk_reserved4) (void);
154
void (*_gtk_reserved5) (void);
157
GType gtk_text_buffer_get_type (void) G_GNUC_CONST;
161
/* table is NULL to create a new one */
162
GtkTextBuffer *gtk_text_buffer_new (GtkTextTagTable *table);
163
gint gtk_text_buffer_get_line_count (GtkTextBuffer *buffer);
164
gint gtk_text_buffer_get_char_count (GtkTextBuffer *buffer);
167
GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer);
169
/* Delete whole buffer, then insert */
170
void gtk_text_buffer_set_text (GtkTextBuffer *buffer,
174
/* Insert into the buffer */
175
void gtk_text_buffer_insert (GtkTextBuffer *buffer,
179
void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer,
183
gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer,
187
gboolean default_editable);
188
gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
191
gboolean default_editable);
193
void gtk_text_buffer_insert_range (GtkTextBuffer *buffer,
195
const GtkTextIter *start,
196
const GtkTextIter *end);
197
gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer,
199
const GtkTextIter *start,
200
const GtkTextIter *end,
201
gboolean default_editable);
203
void gtk_text_buffer_insert_with_tags (GtkTextBuffer *buffer,
207
GtkTextTag *first_tag,
208
...) G_GNUC_NULL_TERMINATED;
210
void gtk_text_buffer_insert_with_tags_by_name (GtkTextBuffer *buffer,
214
const gchar *first_tag_name,
215
...) G_GNUC_NULL_TERMINATED;
217
/* Delete from the buffer */
218
void gtk_text_buffer_delete (GtkTextBuffer *buffer,
221
gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
222
GtkTextIter *start_iter,
223
GtkTextIter *end_iter,
224
gboolean default_editable);
225
gboolean gtk_text_buffer_backspace (GtkTextBuffer *buffer,
227
gboolean interactive,
228
gboolean default_editable);
230
/* Obtain strings from the buffer */
231
gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer,
232
const GtkTextIter *start,
233
const GtkTextIter *end,
234
gboolean include_hidden_chars);
236
gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
237
const GtkTextIter *start,
238
const GtkTextIter *end,
239
gboolean include_hidden_chars);
241
/* Insert a pixbuf */
242
void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
246
/* Insert a child anchor */
247
void gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer,
249
GtkTextChildAnchor *anchor);
251
/* Convenience, create and insert a child anchor */
252
GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
255
/* Mark manipulation */
256
void gtk_text_buffer_add_mark (GtkTextBuffer *buffer,
258
const GtkTextIter *where);
259
GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
260
const gchar *mark_name,
261
const GtkTextIter *where,
262
gboolean left_gravity);
263
void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
265
const GtkTextIter *where);
266
void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
268
GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
271
void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer,
273
const GtkTextIter *where);
274
void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer,
277
GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
278
GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
280
/* efficiently move insert and selection_bound at the same time */
281
void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,
282
const GtkTextIter *where);
283
void gtk_text_buffer_select_range (GtkTextBuffer *buffer,
284
const GtkTextIter *ins,
285
const GtkTextIter *bound);
289
/* Tag manipulation */
290
void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer,
292
const GtkTextIter *start,
293
const GtkTextIter *end);
294
void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer,
296
const GtkTextIter *start,
297
const GtkTextIter *end);
298
void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer,
300
const GtkTextIter *start,
301
const GtkTextIter *end);
302
void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer,
304
const GtkTextIter *start,
305
const GtkTextIter *end);
306
void gtk_text_buffer_remove_all_tags (GtkTextBuffer *buffer,
307
const GtkTextIter *start,
308
const GtkTextIter *end);
311
/* You can either ignore the return value, or use it to
312
* set the attributes of the tag. tag_name can be NULL
314
GtkTextTag *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
315
const gchar *tag_name,
316
const gchar *first_property_name,
319
/* Obtain iterators pointed at various places, then you can move the
320
* iterator around using the GtkTextIter operators
322
void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
326
void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer,
330
void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer,
333
void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer,
336
void gtk_text_buffer_get_start_iter (GtkTextBuffer *buffer,
338
void gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer,
340
void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer,
343
void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer,
347
void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer *buffer,
349
GtkTextChildAnchor *anchor);
351
/* There's no get_first_iter because you just get the iter for
354
/* Used to keep track of whether the buffer needs saving; anytime the
355
buffer contents change, the modified flag is turned on. Whenever
356
you save, turn it off. Tags and marks do not affect the modified
357
flag, but if you would like them to you can connect a handler to
358
the tag/mark signals and call set_modified in your handler */
360
gboolean gtk_text_buffer_get_modified (GtkTextBuffer *buffer);
361
void gtk_text_buffer_set_modified (GtkTextBuffer *buffer,
364
gboolean gtk_text_buffer_get_has_selection (GtkTextBuffer *buffer);
366
void gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer,
367
GtkClipboard *clipboard);
368
void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer,
369
GtkClipboard *clipboard);
371
void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer,
372
GtkClipboard *clipboard,
373
gboolean default_editable);
374
void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer,
375
GtkClipboard *clipboard);
376
void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer,
377
GtkClipboard *clipboard,
378
GtkTextIter *override_location,
379
gboolean default_editable);
381
gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer,
384
gboolean gtk_text_buffer_delete_selection (GtkTextBuffer *buffer,
385
gboolean interactive,
386
gboolean default_editable);
388
/* Called to specify atomic user actions, used to implement undo */
389
void gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer);
390
void gtk_text_buffer_end_user_action (GtkTextBuffer *buffer);
392
GtkTargetList * gtk_text_buffer_get_copy_target_list (GtkTextBuffer *buffer);
393
GtkTargetList * gtk_text_buffer_get_paste_target_list (GtkTextBuffer *buffer);
395
/* INTERNAL private stuff */
396
void _gtk_text_buffer_spew (GtkTextBuffer *buffer);
398
GtkTextBTree* _gtk_text_buffer_get_btree (GtkTextBuffer *buffer);
400
const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer *buffer,
401
const GtkTextIter *anywhere_in_line,
404
void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,