]> Pileus Git - ~andy/gtk/blob - gtk/gtktextbuffer.h
Use G_GNUC_NULL_TERMINATED where appropriate. (#165682, Marc Meissner)
[~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                                                    ...) G_GNUC_NULL_TERMINATED;
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                                                    ...) G_GNUC_NULL_TERMINATED;
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 gboolean gtk_text_buffer_backspace          (GtkTextBuffer *buffer,
207                                              GtkTextIter   *iter,
208                                              gboolean       interactive,
209                                              gboolean       default_editable);
210
211 /* Obtain strings from the buffer */
212 gchar          *gtk_text_buffer_get_text            (GtkTextBuffer     *buffer,
213                                                      const GtkTextIter *start,
214                                                      const GtkTextIter *end,
215                                                      gboolean           include_hidden_chars);
216
217 gchar          *gtk_text_buffer_get_slice           (GtkTextBuffer     *buffer,
218                                                      const GtkTextIter *start,
219                                                      const GtkTextIter *end,
220                                                      gboolean           include_hidden_chars);
221
222 /* Insert a pixbuf */
223 void gtk_text_buffer_insert_pixbuf         (GtkTextBuffer *buffer,
224                                             GtkTextIter   *iter,
225                                             GdkPixbuf     *pixbuf);
226
227 /* Insert a child anchor */
228 void               gtk_text_buffer_insert_child_anchor (GtkTextBuffer      *buffer,
229                                                         GtkTextIter        *iter,
230                                                         GtkTextChildAnchor *anchor);
231
232 /* Convenience, create and insert a child anchor */
233 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
234                                                          GtkTextIter   *iter);
235
236 /* Mark manipulation */
237 GtkTextMark   *gtk_text_buffer_create_mark (GtkTextBuffer     *buffer,
238                                             const gchar       *mark_name,
239                                             const GtkTextIter *where,
240                                             gboolean           left_gravity);
241 void           gtk_text_buffer_move_mark   (GtkTextBuffer     *buffer,
242                                             GtkTextMark       *mark,
243                                             const GtkTextIter *where);
244 void           gtk_text_buffer_delete_mark (GtkTextBuffer     *buffer,
245                                             GtkTextMark       *mark);
246 GtkTextMark*   gtk_text_buffer_get_mark    (GtkTextBuffer     *buffer,
247                                             const gchar       *name);
248
249 void gtk_text_buffer_move_mark_by_name   (GtkTextBuffer     *buffer,
250                                           const gchar       *name,
251                                           const GtkTextIter *where);
252 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer     *buffer,
253                                           const gchar       *name);
254
255 GtkTextMark* gtk_text_buffer_get_insert          (GtkTextBuffer *buffer);
256 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
257
258 /* efficiently move insert and selection_bound at the same time */
259 void gtk_text_buffer_place_cursor (GtkTextBuffer     *buffer,
260                                    const GtkTextIter *where);
261 void gtk_text_buffer_select_range (GtkTextBuffer     *buffer,
262                                    const GtkTextIter *ins,
263                                    const GtkTextIter *bound);
264
265
266
267 /* Tag manipulation */
268 void gtk_text_buffer_apply_tag             (GtkTextBuffer     *buffer,
269                                             GtkTextTag        *tag,
270                                             const GtkTextIter *start,
271                                             const GtkTextIter *end);
272 void gtk_text_buffer_remove_tag            (GtkTextBuffer     *buffer,
273                                             GtkTextTag        *tag,
274                                             const GtkTextIter *start,
275                                             const GtkTextIter *end);
276 void gtk_text_buffer_apply_tag_by_name     (GtkTextBuffer     *buffer,
277                                             const gchar       *name,
278                                             const GtkTextIter *start,
279                                             const GtkTextIter *end);
280 void gtk_text_buffer_remove_tag_by_name    (GtkTextBuffer     *buffer,
281                                             const gchar       *name,
282                                             const GtkTextIter *start,
283                                             const GtkTextIter *end);
284 void gtk_text_buffer_remove_all_tags       (GtkTextBuffer     *buffer,
285                                             const GtkTextIter *start,
286                                             const GtkTextIter *end);
287
288
289 /* You can either ignore the return value, or use it to
290  * set the attributes of the tag. tag_name can be NULL
291  */
292 GtkTextTag    *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
293                                            const gchar   *tag_name,
294                                            const gchar   *first_property_name,
295                                            ...) G_GNUC_NULL_TERMINATED;
296
297 /* Obtain iterators pointed at various places, then you can move the
298  * iterator around using the GtkTextIter operators
299  */
300 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
301                                               GtkTextIter   *iter,
302                                               gint           line_number,
303                                               gint           char_offset);
304 void gtk_text_buffer_get_iter_at_line_index  (GtkTextBuffer *buffer,
305                                               GtkTextIter   *iter,
306                                               gint           line_number,
307                                               gint           byte_index);
308 void gtk_text_buffer_get_iter_at_offset      (GtkTextBuffer *buffer,
309                                               GtkTextIter   *iter,
310                                               gint           char_offset);
311 void gtk_text_buffer_get_iter_at_line        (GtkTextBuffer *buffer,
312                                               GtkTextIter   *iter,
313                                               gint           line_number);
314 void gtk_text_buffer_get_start_iter          (GtkTextBuffer *buffer,
315                                               GtkTextIter   *iter);
316 void gtk_text_buffer_get_end_iter            (GtkTextBuffer *buffer,
317                                               GtkTextIter   *iter);
318 void gtk_text_buffer_get_bounds              (GtkTextBuffer *buffer,
319                                               GtkTextIter   *start,
320                                               GtkTextIter   *end);
321 void gtk_text_buffer_get_iter_at_mark        (GtkTextBuffer *buffer,
322                                               GtkTextIter   *iter,
323                                               GtkTextMark   *mark);
324
325 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer      *buffer,
326                                                GtkTextIter        *iter,
327                                                GtkTextChildAnchor *anchor);
328
329 /* There's no get_first_iter because you just get the iter for
330    line or char 0 */
331
332 /* Used to keep track of whether the buffer needs saving; anytime the
333    buffer contents change, the modified flag is turned on. Whenever
334    you save, turn it off. Tags and marks do not affect the modified
335    flag, but if you would like them to you can connect a handler to
336    the tag/mark signals and call set_modified in your handler */
337
338 gboolean        gtk_text_buffer_get_modified            (GtkTextBuffer *buffer);
339 void            gtk_text_buffer_set_modified            (GtkTextBuffer *buffer,
340                                                          gboolean       setting);
341
342 void gtk_text_buffer_add_selection_clipboard    (GtkTextBuffer     *buffer,
343                                                  GtkClipboard      *clipboard);
344 void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer     *buffer,
345                                                  GtkClipboard      *clipboard);
346
347 void            gtk_text_buffer_cut_clipboard           (GtkTextBuffer *buffer,
348                                                          GtkClipboard  *clipboard,
349                                                          gboolean       default_editable);
350 void            gtk_text_buffer_copy_clipboard          (GtkTextBuffer *buffer,
351                                                          GtkClipboard  *clipboard);
352 void            gtk_text_buffer_paste_clipboard         (GtkTextBuffer *buffer,
353                                                          GtkClipboard  *clipboard,
354                                                          GtkTextIter   *override_location,
355                                                          gboolean       default_editable);
356
357 gboolean        gtk_text_buffer_get_selection_bounds    (GtkTextBuffer *buffer,
358                                                          GtkTextIter   *start,
359                                                          GtkTextIter   *end);
360 gboolean        gtk_text_buffer_delete_selection        (GtkTextBuffer *buffer,
361                                                          gboolean       interactive,
362                                                          gboolean       default_editable);                                                    
363
364 /* Called to specify atomic user actions, used to implement undo */
365 void            gtk_text_buffer_begin_user_action       (GtkTextBuffer *buffer);
366 void            gtk_text_buffer_end_user_action         (GtkTextBuffer *buffer);
367
368 /* INTERNAL private stuff */
369 void            _gtk_text_buffer_spew                  (GtkTextBuffer      *buffer);
370
371 GtkTextBTree*   _gtk_text_buffer_get_btree             (GtkTextBuffer      *buffer);
372
373 const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer     *buffer,
374                                                          const GtkTextIter *anywhere_in_line,
375                                                          gint              *char_len);
376
377 void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,
378                                               GtkTextTag    *tag);
379
380 #ifdef __cplusplus
381 }
382 #endif /* __cplusplus */
383
384 #endif