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