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 | |
39 | G_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 | */ |
59 | typedef 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 | |
66 | typedef 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 | |
75 | typedef struct _GtkTextBufferPrivate GtkTextBufferPrivate; |
76 | typedef struct _GtkTextBufferClass GtkTextBufferClass; |
77 | |
78 | struct _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 | */ |
107 | struct _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 | |
165 | GDK_AVAILABLE_IN_ALL |
166 | GType gtk_text_buffer_get_type (void) G_GNUC_CONST; |
167 | |
168 | |
169 | |
170 | /* table is NULL to create a new one */ |
171 | GDK_AVAILABLE_IN_ALL |
172 | GtkTextBuffer *gtk_text_buffer_new (GtkTextTagTable *table); |
173 | GDK_AVAILABLE_IN_ALL |
174 | gint gtk_text_buffer_get_line_count (GtkTextBuffer *buffer); |
175 | GDK_AVAILABLE_IN_ALL |
176 | gint gtk_text_buffer_get_char_count (GtkTextBuffer *buffer); |
177 | |
178 | |
179 | GDK_AVAILABLE_IN_ALL |
180 | GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer *buffer); |
181 | |
182 | /* Delete whole buffer, then insert */ |
183 | GDK_AVAILABLE_IN_ALL |
184 | void gtk_text_buffer_set_text (GtkTextBuffer *buffer, |
185 | const gchar *text, |
186 | gint len); |
187 | |
188 | /* Insert into the buffer */ |
189 | GDK_AVAILABLE_IN_ALL |
190 | void gtk_text_buffer_insert (GtkTextBuffer *buffer, |
191 | GtkTextIter *iter, |
192 | const gchar *text, |
193 | gint len); |
194 | GDK_AVAILABLE_IN_ALL |
195 | void gtk_text_buffer_insert_at_cursor (GtkTextBuffer *buffer, |
196 | const gchar *text, |
197 | gint len); |
198 | |
199 | GDK_AVAILABLE_IN_ALL |
200 | gboolean gtk_text_buffer_insert_interactive (GtkTextBuffer *buffer, |
201 | GtkTextIter *iter, |
202 | const gchar *text, |
203 | gint len, |
204 | gboolean default_editable); |
205 | GDK_AVAILABLE_IN_ALL |
206 | gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer, |
207 | const gchar *text, |
208 | gint len, |
209 | gboolean default_editable); |
210 | |
211 | GDK_AVAILABLE_IN_ALL |
212 | void gtk_text_buffer_insert_range (GtkTextBuffer *buffer, |
213 | GtkTextIter *iter, |
214 | const GtkTextIter *start, |
215 | const GtkTextIter *end); |
216 | GDK_AVAILABLE_IN_ALL |
217 | gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer *buffer, |
218 | GtkTextIter *iter, |
219 | const GtkTextIter *start, |
220 | const GtkTextIter *end, |
221 | gboolean default_editable); |
222 | |
223 | GDK_AVAILABLE_IN_ALL |
224 | void 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 | |
231 | GDK_AVAILABLE_IN_ALL |
232 | void 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 | |
239 | GDK_AVAILABLE_IN_3_16 |
240 | void gtk_text_buffer_insert_markup (GtkTextBuffer *buffer, |
241 | GtkTextIter *iter, |
242 | const gchar *markup, |
243 | gint len); |
244 | |
245 | /* Delete from the buffer */ |
246 | GDK_AVAILABLE_IN_ALL |
247 | void gtk_text_buffer_delete (GtkTextBuffer *buffer, |
248 | GtkTextIter *start, |
249 | GtkTextIter *end); |
250 | GDK_AVAILABLE_IN_ALL |
251 | gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer, |
252 | GtkTextIter *start_iter, |
253 | GtkTextIter *end_iter, |
254 | gboolean default_editable); |
255 | GDK_AVAILABLE_IN_ALL |
256 | gboolean gtk_text_buffer_backspace (GtkTextBuffer *buffer, |
257 | GtkTextIter *iter, |
258 | gboolean interactive, |
259 | gboolean default_editable); |
260 | |
261 | /* Obtain strings from the buffer */ |
262 | GDK_AVAILABLE_IN_ALL |
263 | gchar *gtk_text_buffer_get_text (GtkTextBuffer *buffer, |
264 | const GtkTextIter *start, |
265 | const GtkTextIter *end, |
266 | gboolean include_hidden_chars); |
267 | |
268 | GDK_AVAILABLE_IN_ALL |
269 | gchar *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 */ |
275 | GDK_AVAILABLE_IN_ALL |
276 | void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer, |
277 | GtkTextIter *iter, |
278 | GdkPixbuf *pixbuf); |
279 | |
280 | /* Insert a child anchor */ |
281 | GDK_AVAILABLE_IN_ALL |
282 | void gtk_text_buffer_insert_child_anchor (GtkTextBuffer *buffer, |
283 | GtkTextIter *iter, |
284 | GtkTextChildAnchor *anchor); |
285 | |
286 | /* Convenience, create and insert a child anchor */ |
287 | GDK_AVAILABLE_IN_ALL |
288 | GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer, |
289 | GtkTextIter *iter); |
290 | |
291 | /* Mark manipulation */ |
292 | GDK_AVAILABLE_IN_ALL |
293 | void gtk_text_buffer_add_mark (GtkTextBuffer *buffer, |
294 | GtkTextMark *mark, |
295 | const GtkTextIter *where); |
296 | GDK_AVAILABLE_IN_ALL |
297 | GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer, |
298 | const gchar *mark_name, |
299 | const GtkTextIter *where, |
300 | gboolean left_gravity); |
301 | GDK_AVAILABLE_IN_ALL |
302 | void gtk_text_buffer_move_mark (GtkTextBuffer *buffer, |
303 | GtkTextMark *mark, |
304 | const GtkTextIter *where); |
305 | GDK_AVAILABLE_IN_ALL |
306 | void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer, |
307 | GtkTextMark *mark); |
308 | GDK_AVAILABLE_IN_ALL |
309 | GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer, |
310 | const gchar *name); |
311 | |
312 | GDK_AVAILABLE_IN_ALL |
313 | void gtk_text_buffer_move_mark_by_name (GtkTextBuffer *buffer, |
314 | const gchar *name, |
315 | const GtkTextIter *where); |
316 | GDK_AVAILABLE_IN_ALL |
317 | void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer *buffer, |
318 | const gchar *name); |
319 | |
320 | GDK_AVAILABLE_IN_ALL |
321 | GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer); |
322 | GDK_AVAILABLE_IN_ALL |
323 | GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer); |
324 | |
325 | /* efficiently move insert and selection_bound at the same time */ |
326 | GDK_AVAILABLE_IN_ALL |
327 | void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer, |
328 | const GtkTextIter *where); |
329 | GDK_AVAILABLE_IN_ALL |
330 | void gtk_text_buffer_select_range (GtkTextBuffer *buffer, |
331 | const GtkTextIter *ins, |
332 | const GtkTextIter *bound); |
333 | |
334 | |
335 | |
336 | /* Tag manipulation */ |
337 | GDK_AVAILABLE_IN_ALL |
338 | void gtk_text_buffer_apply_tag (GtkTextBuffer *buffer, |
339 | GtkTextTag *tag, |
340 | const GtkTextIter *start, |
341 | const GtkTextIter *end); |
342 | GDK_AVAILABLE_IN_ALL |
343 | void gtk_text_buffer_remove_tag (GtkTextBuffer *buffer, |
344 | GtkTextTag *tag, |
345 | const GtkTextIter *start, |
346 | const GtkTextIter *end); |
347 | GDK_AVAILABLE_IN_ALL |
348 | void gtk_text_buffer_apply_tag_by_name (GtkTextBuffer *buffer, |
349 | const gchar *name, |
350 | const GtkTextIter *start, |
351 | const GtkTextIter *end); |
352 | GDK_AVAILABLE_IN_ALL |
353 | void gtk_text_buffer_remove_tag_by_name (GtkTextBuffer *buffer, |
354 | const gchar *name, |
355 | const GtkTextIter *start, |
356 | const GtkTextIter *end); |
357 | GDK_AVAILABLE_IN_ALL |
358 | void 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 | */ |
366 | GDK_AVAILABLE_IN_ALL |
367 | GtkTextTag *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 | */ |
375 | GDK_AVAILABLE_IN_ALL |
376 | void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer, |
377 | GtkTextIter *iter, |
378 | gint line_number, |
379 | gint char_offset); |
380 | GDK_AVAILABLE_IN_ALL |
381 | void gtk_text_buffer_get_iter_at_line_index (GtkTextBuffer *buffer, |
382 | GtkTextIter *iter, |
383 | gint line_number, |
384 | gint byte_index); |
385 | GDK_AVAILABLE_IN_ALL |
386 | void gtk_text_buffer_get_iter_at_offset (GtkTextBuffer *buffer, |
387 | GtkTextIter *iter, |
388 | gint char_offset); |
389 | GDK_AVAILABLE_IN_ALL |
390 | void gtk_text_buffer_get_iter_at_line (GtkTextBuffer *buffer, |
391 | GtkTextIter *iter, |
392 | gint line_number); |
393 | GDK_AVAILABLE_IN_ALL |
394 | void gtk_text_buffer_get_start_iter (GtkTextBuffer *buffer, |
395 | GtkTextIter *iter); |
396 | GDK_AVAILABLE_IN_ALL |
397 | void gtk_text_buffer_get_end_iter (GtkTextBuffer *buffer, |
398 | GtkTextIter *iter); |
399 | GDK_AVAILABLE_IN_ALL |
400 | void gtk_text_buffer_get_bounds (GtkTextBuffer *buffer, |
401 | GtkTextIter *start, |
402 | GtkTextIter *end); |
403 | GDK_AVAILABLE_IN_ALL |
404 | void gtk_text_buffer_get_iter_at_mark (GtkTextBuffer *buffer, |
405 | GtkTextIter *iter, |
406 | GtkTextMark *mark); |
407 | |
408 | GDK_AVAILABLE_IN_ALL |
409 | void 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 | |
422 | GDK_AVAILABLE_IN_ALL |
423 | gboolean gtk_text_buffer_get_modified (GtkTextBuffer *buffer); |
424 | GDK_AVAILABLE_IN_ALL |
425 | void gtk_text_buffer_set_modified (GtkTextBuffer *buffer, |
426 | gboolean setting); |
427 | |
428 | GDK_AVAILABLE_IN_ALL |
429 | gboolean gtk_text_buffer_get_has_selection (GtkTextBuffer *buffer); |
430 | |
431 | GDK_AVAILABLE_IN_ALL |
432 | void gtk_text_buffer_add_selection_clipboard (GtkTextBuffer *buffer, |
433 | GtkClipboard *clipboard); |
434 | GDK_AVAILABLE_IN_ALL |
435 | void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer *buffer, |
436 | GtkClipboard *clipboard); |
437 | |
438 | GDK_AVAILABLE_IN_ALL |
439 | void gtk_text_buffer_cut_clipboard (GtkTextBuffer *buffer, |
440 | GtkClipboard *clipboard, |
441 | gboolean default_editable); |
442 | GDK_AVAILABLE_IN_ALL |
443 | void gtk_text_buffer_copy_clipboard (GtkTextBuffer *buffer, |
444 | GtkClipboard *clipboard); |
445 | GDK_AVAILABLE_IN_ALL |
446 | void gtk_text_buffer_paste_clipboard (GtkTextBuffer *buffer, |
447 | GtkClipboard *clipboard, |
448 | GtkTextIter *override_location, |
449 | gboolean default_editable); |
450 | |
451 | GDK_AVAILABLE_IN_ALL |
452 | gboolean gtk_text_buffer_get_selection_bounds (GtkTextBuffer *buffer, |
453 | GtkTextIter *start, |
454 | GtkTextIter *end); |
455 | GDK_AVAILABLE_IN_ALL |
456 | gboolean 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 */ |
461 | GDK_AVAILABLE_IN_ALL |
462 | void gtk_text_buffer_begin_user_action (GtkTextBuffer *buffer); |
463 | GDK_AVAILABLE_IN_ALL |
464 | void gtk_text_buffer_end_user_action (GtkTextBuffer *buffer); |
465 | |
466 | GDK_AVAILABLE_IN_ALL |
467 | GtkTargetList * gtk_text_buffer_get_copy_target_list (GtkTextBuffer *buffer); |
468 | GDK_AVAILABLE_IN_ALL |
469 | GtkTargetList * gtk_text_buffer_get_paste_target_list (GtkTextBuffer *buffer); |
470 | |
471 | |
472 | G_END_DECLS |
473 | |
474 | #endif |
475 | |