]> Pileus Git - ~andy/gtk/blob - gtk/gtktextbuffer.h
Fixes for #78258
[~andy/gtk] / gtk / gtktextbuffer.h
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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
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/.
25  */
26
27 #ifndef GTK_TEXT_BUFFER_H
28 #define GTK_TEXT_BUFFER_H
29
30 #include <gtk/gtkwidget.h>
31 #include <gtk/gtkclipboard.h>
32 #include <gtk/gtktexttagtable.h>
33 #include <gtk/gtktextiter.h>
34 #include <gtk/gtktextmark.h>
35 #include <gtk/gtktextchild.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif /* __cplusplus */
40
41 /*
42  * This is the PUBLIC representation of a text buffer.
43  * GtkTextBTree is the PRIVATE internal representation of it.
44  */
45
46 typedef struct _GtkTextBTree GtkTextBTree;
47
48 typedef struct _GtkTextLogAttrCache GtkTextLogAttrCache;
49
50 #define GTK_TYPE_TEXT_BUFFER            (gtk_text_buffer_get_type ())
51 #define GTK_TEXT_BUFFER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBuffer))
52 #define GTK_TEXT_BUFFER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
53 #define GTK_IS_TEXT_BUFFER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_BUFFER))
54 #define GTK_IS_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_BUFFER))
55 #define GTK_TEXT_BUFFER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
56
57 typedef struct _GtkTextBufferClass GtkTextBufferClass;
58
59 struct _GtkTextBuffer
60 {
61   GObject parent_instance;
62
63   GtkTextTagTable *tag_table;
64   GtkTextBTree *btree;
65
66   GSList *clipboard_contents_buffers;
67   GSList *selection_clipboards;
68
69   GtkTextLogAttrCache *log_attr_cache;
70
71   guint user_action_count;
72   
73   /* Whether the buffer has been modified since last save */
74   guint modified : 1;
75 };
76
77 struct _GtkTextBufferClass
78 {
79   GObjectClass parent_class;
80
81   void (* insert_text)     (GtkTextBuffer *buffer,
82                             GtkTextIter *pos,
83                             const gchar *text,
84                             gint length);
85
86   void (* insert_pixbuf)   (GtkTextBuffer *buffer,
87                             GtkTextIter   *pos,
88                             GdkPixbuf     *pixbuf);
89
90   void (* insert_child_anchor)   (GtkTextBuffer      *buffer,
91                                   GtkTextIter        *pos,
92                                   GtkTextChildAnchor *anchor);
93   
94   void (* delete_range)     (GtkTextBuffer *buffer,
95                              GtkTextIter   *start,
96                              GtkTextIter   *end);
97
98   /* Only for text/widgets/pixbuf changed, marks/tags don't cause this
99    * to be emitted
100    */
101   void (* changed)         (GtkTextBuffer *buffer);
102
103
104   /* New value for the modified flag */
105   void (* modified_changed)   (GtkTextBuffer *buffer);
106
107   /* Mark moved or created */
108   void (* mark_set)           (GtkTextBuffer *buffer,
109                                const GtkTextIter *location,
110                                GtkTextMark *mark);
111
112   void (* mark_deleted)       (GtkTextBuffer *buffer,
113                                GtkTextMark *mark);
114
115   void (* apply_tag)          (GtkTextBuffer *buffer,
116                                GtkTextTag *tag,
117                                const GtkTextIter *start_char,
118                                const GtkTextIter *end_char);
119
120   void (* remove_tag)         (GtkTextBuffer *buffer,
121                                GtkTextTag *tag,
122                                const GtkTextIter *start_char,
123                                const GtkTextIter *end_char);
124
125   /* Called at the start and end of an atomic user action */
126   void (* begin_user_action)  (GtkTextBuffer *buffer);
127   void (* end_user_action)    (GtkTextBuffer *buffer);
128
129   /* Padding for future expansion */
130   void (*_gtk_reserved1) (void);
131   void (*_gtk_reserved2) (void);
132   void (*_gtk_reserved3) (void);
133   void (*_gtk_reserved4) (void);
134   void (*_gtk_reserved5) (void);
135   void (*_gtk_reserved6) (void);
136 };
137
138 GType        gtk_text_buffer_get_type       (void) G_GNUC_CONST;
139
140
141
142 /* table is NULL to create a new one */
143 GtkTextBuffer *gtk_text_buffer_new            (GtkTextTagTable *table);
144 gint           gtk_text_buffer_get_line_count (GtkTextBuffer   *buffer);
145 gint           gtk_text_buffer_get_char_count (GtkTextBuffer   *buffer);
146
147
148 GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer  *buffer);
149
150 /* Delete whole buffer, then insert */
151 void gtk_text_buffer_set_text          (GtkTextBuffer *buffer,
152                                         const gchar   *text,
153                                         gint           len);
154
155 /* Insert into the buffer */
156 void gtk_text_buffer_insert            (GtkTextBuffer *buffer,
157                                         GtkTextIter   *iter,
158                                         const gchar   *text,
159                                         gint           len);
160 void gtk_text_buffer_insert_at_cursor  (GtkTextBuffer *buffer,
161                                         const gchar   *text,
162                                         gint           len);
163
164 gboolean gtk_text_buffer_insert_interactive           (GtkTextBuffer *buffer,
165                                                        GtkTextIter   *iter,
166                                                        const gchar   *text,
167                                                        gint           len,
168                                                        gboolean       default_editable);
169 gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
170                                                        const gchar   *text,
171                                                        gint           len,
172                                                        gboolean       default_editable);
173
174 void     gtk_text_buffer_insert_range             (GtkTextBuffer     *buffer,
175                                                    GtkTextIter       *iter,
176                                                    const GtkTextIter *start,
177                                                    const GtkTextIter *end);
178 gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer     *buffer,
179                                                    GtkTextIter       *iter,
180                                                    const GtkTextIter *start,
181                                                    const GtkTextIter *end,
182                                                    gboolean           default_editable);
183
184 void    gtk_text_buffer_insert_with_tags          (GtkTextBuffer     *buffer,
185                                                    GtkTextIter       *iter,
186                                                    const gchar       *text,
187                                                    gint               len,
188                                                    GtkTextTag        *first_tag,
189                                                    ...);
190
191 void    gtk_text_buffer_insert_with_tags_by_name  (GtkTextBuffer     *buffer,
192                                                    GtkTextIter       *iter,
193                                                    const gchar       *text,
194                                                    gint               len,
195                                                    const gchar       *first_tag_name,
196                                                    ...);
197
198 /* Delete from the buffer */
199 void     gtk_text_buffer_delete             (GtkTextBuffer *buffer,
200                                              GtkTextIter   *start,
201                                              GtkTextIter   *end);
202 gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
203                                              GtkTextIter   *start_iter,
204                                              GtkTextIter   *end_iter,
205                                              gboolean       default_editable);
206
207
208
209 /* Obtain strings from the buffer */
210 gchar          *gtk_text_buffer_get_text            (GtkTextBuffer     *buffer,
211                                                      const GtkTextIter *start,
212                                                      const GtkTextIter *end,
213                                                      gboolean           include_hidden_chars);
214
215 gchar          *gtk_text_buffer_get_slice           (GtkTextBuffer     *buffer,
216                                                      const GtkTextIter *start,
217                                                      const GtkTextIter *end,
218                                                      gboolean           include_hidden_chars);
219
220 /* Insert a pixbuf */
221 void gtk_text_buffer_insert_pixbuf         (GtkTextBuffer *buffer,
222                                             GtkTextIter   *iter,
223                                             GdkPixbuf     *pixbuf);
224
225 /* Insert a child anchor */
226 void               gtk_text_buffer_insert_child_anchor (GtkTextBuffer      *buffer,
227                                                         GtkTextIter        *iter,
228                                                         GtkTextChildAnchor *anchor);
229
230 /* Convenience, create and insert a child anchor */
231 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
232                                                          GtkTextIter   *iter);
233
234 /* Mark manipulation */
235 GtkTextMark   *gtk_text_buffer_create_mark (GtkTextBuffer     *buffer,
236                                             const gchar       *mark_name,
237                                             const GtkTextIter *where,
238                                             gboolean           left_gravity);
239 void           gtk_text_buffer_move_mark   (GtkTextBuffer     *buffer,
240                                             GtkTextMark       *mark,
241                                             const GtkTextIter *where);
242 void           gtk_text_buffer_delete_mark (GtkTextBuffer     *buffer,
243                                             GtkTextMark       *mark);
244 GtkTextMark*   gtk_text_buffer_get_mark    (GtkTextBuffer     *buffer,
245                                             const gchar       *name);
246
247 void gtk_text_buffer_move_mark_by_name   (GtkTextBuffer     *buffer,
248                                           const gchar       *name,
249                                           const GtkTextIter *where);
250 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer     *buffer,
251                                           const gchar       *name);
252
253 GtkTextMark* gtk_text_buffer_get_insert          (GtkTextBuffer *buffer);
254 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
255
256 /* efficiently move insert and selection_bound to same location */
257 void gtk_text_buffer_place_cursor (GtkTextBuffer     *buffer,
258                                    const GtkTextIter *where);
259
260
261
262 /* Tag manipulation */
263 void gtk_text_buffer_apply_tag             (GtkTextBuffer     *buffer,
264                                             GtkTextTag        *tag,
265                                             const GtkTextIter *start,
266                                             const GtkTextIter *end);
267 void gtk_text_buffer_remove_tag            (GtkTextBuffer     *buffer,
268                                             GtkTextTag        *tag,
269                                             const GtkTextIter *start,
270                                             const GtkTextIter *end);
271 void gtk_text_buffer_apply_tag_by_name     (GtkTextBuffer     *buffer,
272                                             const gchar       *name,
273                                             const GtkTextIter *start,
274                                             const GtkTextIter *end);
275 void gtk_text_buffer_remove_tag_by_name    (GtkTextBuffer     *buffer,
276                                             const gchar       *name,
277                                             const GtkTextIter *start,
278                                             const GtkTextIter *end);
279 void gtk_text_buffer_remove_all_tags       (GtkTextBuffer     *buffer,
280                                             const GtkTextIter *start,
281                                             const GtkTextIter *end);
282
283
284 /* You can either ignore the return value, or use it to
285  * set the attributes of the tag. tag_name can be NULL
286  */
287 GtkTextTag    *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
288                                            const gchar   *tag_name,
289                                            const gchar   *first_property_name,
290                                            ...);
291
292 /* Obtain iterators pointed at various places, then you can move the
293  * iterator around using the GtkTextIter operators
294  */
295 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
296                                               GtkTextIter   *iter,
297                                               gint           line_number,
298                                               gint           char_offset);
299 void gtk_text_buffer_get_iter_at_line_index  (GtkTextBuffer *buffer,
300                                               GtkTextIter   *iter,
301                                               gint           line_number,
302                                               gint           byte_index);
303 void gtk_text_buffer_get_iter_at_offset      (GtkTextBuffer *buffer,
304                                               GtkTextIter   *iter,
305                                               gint           char_offset);
306 void gtk_text_buffer_get_iter_at_line        (GtkTextBuffer *buffer,
307                                               GtkTextIter   *iter,
308                                               gint           line_number);
309 void gtk_text_buffer_get_start_iter          (GtkTextBuffer *buffer,
310                                               GtkTextIter   *iter);
311 void gtk_text_buffer_get_end_iter            (GtkTextBuffer *buffer,
312                                               GtkTextIter   *iter);
313 void gtk_text_buffer_get_bounds              (GtkTextBuffer *buffer,
314                                               GtkTextIter   *start,
315                                               GtkTextIter   *end);
316 void gtk_text_buffer_get_iter_at_mark        (GtkTextBuffer *buffer,
317                                               GtkTextIter   *iter,
318                                               GtkTextMark   *mark);
319
320 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer      *buffer,
321                                                GtkTextIter        *iter,
322                                                GtkTextChildAnchor *anchor);
323
324 /* There's no get_first_iter because you just get the iter for
325    line or char 0 */
326
327 /* Used to keep track of whether the buffer needs saving; anytime the
328    buffer contents change, the modified flag is turned on. Whenever
329    you save, turn it off. Tags and marks do not affect the modified
330    flag, but if you would like them to you can connect a handler to
331    the tag/mark signals and call set_modified in your handler */
332
333 gboolean        gtk_text_buffer_get_modified            (GtkTextBuffer *buffer);
334 void            gtk_text_buffer_set_modified            (GtkTextBuffer *buffer,
335                                                          gboolean       setting);
336
337 void gtk_text_buffer_add_selection_clipboard    (GtkTextBuffer     *buffer,
338                                                  GtkClipboard      *clipboard);
339 void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer     *buffer,
340                                                  GtkClipboard      *clipboard);
341
342 void            gtk_text_buffer_cut_clipboard           (GtkTextBuffer *buffer,
343                                                          GtkClipboard  *clipboard,
344                                                          gboolean       default_editable);
345 void            gtk_text_buffer_copy_clipboard          (GtkTextBuffer *buffer,
346                                                          GtkClipboard  *clipboard);
347 void            gtk_text_buffer_paste_clipboard         (GtkTextBuffer *buffer,
348                                                          GtkClipboard  *clipboard,
349                                                          GtkTextIter   *override_location,
350                                                          gboolean       default_editable);
351
352 gboolean        gtk_text_buffer_get_selection_bounds    (GtkTextBuffer *buffer,
353                                                          GtkTextIter   *start,
354                                                          GtkTextIter   *end);
355 gboolean        gtk_text_buffer_delete_selection        (GtkTextBuffer *buffer,
356                                                          gboolean       interactive,
357                                                          gboolean       default_editable);                                                    
358
359 /* Called to specify atomic user actions, used to implement undo */
360 void            gtk_text_buffer_begin_user_action       (GtkTextBuffer *buffer);
361 void            gtk_text_buffer_end_user_action         (GtkTextBuffer *buffer);
362
363 /* INTERNAL private stuff */
364 void            _gtk_text_buffer_spew                  (GtkTextBuffer      *buffer);
365
366 GtkTextBTree*   _gtk_text_buffer_get_btree             (GtkTextBuffer      *buffer);
367
368 const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer     *buffer,
369                                                          const GtkTextIter *anywhere_in_line,
370                                                          gint              *char_len);
371
372 void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,
373                                               GtkTextTag    *tag);
374
375 #ifdef __cplusplus
376 }
377 #endif /* __cplusplus */
378
379 #endif