]> Pileus Git - ~andy/gtk/blob - gtk/gtktextbuffer.h
f8c00a6710928d109261379a53ff0491fa6d4355
[~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/gtktexttagtable.h>
32 #include <gtk/gtktextiter.h>
33 #include <gtk/gtktextmark.h>
34 #include <gtk/gtktextchild.h>
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
39
40 /*
41  * This is the PUBLIC representation of a text buffer.
42  * GtkTextBTree is the PRIVATE internal representation of it.
43  */
44
45 typedef struct _GtkTextBTree GtkTextBTree;
46
47 #define GTK_TYPE_TEXT_BUFFER            (gtk_text_buffer_get_type ())
48 #define GTK_TEXT_BUFFER(obj)            (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBuffer))
49 #define GTK_TEXT_BUFFER_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
50 #define GTK_IS_TEXT_BUFFER(obj)         (GTK_CHECK_TYPE ((obj), GTK_TYPE_TEXT_BUFFER))
51 #define GTK_IS_TEXT_BUFFER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_BUFFER))
52 #define GTK_TEXT_BUFFER_GET_CLASS(obj)  (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
53
54 typedef struct _GtkTextBufferClass GtkTextBufferClass;
55
56 struct _GtkTextBuffer
57 {
58   GtkObject parent_instance;
59
60   GtkTextTagTable *tag_table;
61   GtkTextBTree *btree;
62
63   GtkTextBuffer *clipboard_contents;
64   
65   /* Whether the buffer has been modified since last save */
66   guint modified : 1;
67 };
68
69 struct _GtkTextBufferClass
70 {
71   GtkObjectClass parent_class;
72
73   void (* insert_text)     (GtkTextBuffer *buffer,
74                             GtkTextIter *pos,
75                             const gchar *text,
76                             gint length,
77                             gboolean interactive);
78
79
80   void (* delete_text)     (GtkTextBuffer *buffer,
81                             GtkTextIter *start,
82                             GtkTextIter *end,
83                             gboolean interactive);
84
85   /* Only for text/widgets/pixbuf changed, marks/tags don't cause this
86    * to be emitted
87    */
88   void (* changed)         (GtkTextBuffer *buffer);
89
90
91   /* New value for the modified flag */
92   void (* modified_changed)   (GtkTextBuffer *buffer);
93
94   /* Mark moved or created */
95   void (* mark_set)           (GtkTextBuffer *buffer,
96                                const GtkTextIter *location,
97                                GtkTextMark *mark);
98
99   void (* mark_deleted)       (GtkTextBuffer *buffer,
100                                GtkTextMark *mark);
101
102   void (* apply_tag)          (GtkTextBuffer *buffer,
103                                GtkTextTag *tag,
104                                const GtkTextIter *start_char,
105                                const GtkTextIter *end_char);
106
107   void (* remove_tag)         (GtkTextBuffer *buffer,
108                                GtkTextTag *tag,
109                                const GtkTextIter *start_char,
110                                const GtkTextIter *end_char);
111
112 };
113
114 GtkType        gtk_text_buffer_get_type       (void) G_GNUC_CONST;
115
116
117
118 /* table is NULL to create a new one */
119 GtkTextBuffer *gtk_text_buffer_new            (GtkTextTagTable *table);
120 gint           gtk_text_buffer_get_line_count (GtkTextBuffer   *buffer);
121 gint           gtk_text_buffer_get_char_count (GtkTextBuffer   *buffer);
122
123
124 GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer  *buffer);
125
126 /* Delete whole buffer, then insert */
127 void gtk_text_buffer_set_text          (GtkTextBuffer *buffer,
128                                         const gchar   *text,
129                                         gint           len);
130
131 /* Insert into the buffer */
132 void gtk_text_buffer_insert            (GtkTextBuffer *buffer,
133                                         GtkTextIter   *iter,
134                                         const gchar   *text,
135                                         gint           len);
136 void gtk_text_buffer_insert_at_cursor  (GtkTextBuffer *buffer,
137                                         const gchar   *text,
138                                         gint           len);
139
140 gboolean gtk_text_buffer_insert_interactive           (GtkTextBuffer *buffer,
141                                                        GtkTextIter   *iter,
142                                                        const gchar   *text,
143                                                        gint           len,
144                                                        gboolean       default_editable);
145 gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
146                                                        const gchar   *text,
147                                                        gint           len,
148                                                        gboolean       default_editable);
149
150 void     gtk_text_buffer_insert_range             (GtkTextBuffer     *buffer,
151                                                    GtkTextIter       *iter,
152                                                    const GtkTextIter *start,
153                                                    const GtkTextIter *end);
154 gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer     *buffer,
155                                                    GtkTextIter       *iter,
156                                                    const GtkTextIter *start,
157                                                    const GtkTextIter *end,
158                                                    gboolean           default_editable);
159
160 void    gtk_text_buffer_insert_with_tags          (GtkTextBuffer     *buffer,
161                                                    GtkTextIter       *iter,
162                                                    const gchar       *text,
163                                                    gint               len,
164                                                    GtkTextTag        *first_tag,
165                                                    ...);
166
167 void    gtk_text_buffer_insert_with_tags_by_name  (GtkTextBuffer     *buffer,
168                                                    GtkTextIter       *iter,
169                                                    const gchar       *text,
170                                                    gint               len,
171                                                    const gchar       *first_tag_name,
172                                                    ...);
173
174 /* Delete from the buffer */
175 void     gtk_text_buffer_delete             (GtkTextBuffer *buffer,
176                                              GtkTextIter   *start,
177                                              GtkTextIter   *end);
178 gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
179                                              GtkTextIter   *start_iter,
180                                              GtkTextIter   *end_iter,
181                                              gboolean       default_editable);
182
183
184
185 /* Obtain strings from the buffer */
186 gchar          *gtk_text_buffer_get_text            (GtkTextBuffer     *buffer,
187                                                      const GtkTextIter *start,
188                                                      const GtkTextIter *end,
189                                                      gboolean           include_hidden_chars);
190
191 gchar          *gtk_text_buffer_get_slice           (GtkTextBuffer     *buffer,
192                                                      const GtkTextIter *start,
193                                                      const GtkTextIter *end,
194                                                      gboolean           include_hidden_chars);
195
196 /* Insert a pixbuf */
197 void gtk_text_buffer_insert_pixbuf         (GtkTextBuffer *buffer,
198                                             GtkTextIter   *iter,
199                                             GdkPixbuf     *pixbuf);
200
201 /* Create a child anchor */
202 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
203                                                          GtkTextIter   *iter);
204
205 /* Mark manipulation */
206 GtkTextMark   *gtk_text_buffer_create_mark (GtkTextBuffer     *buffer,
207                                             const gchar       *mark_name,
208                                             const GtkTextIter *where,
209                                             gboolean           left_gravity);
210 void           gtk_text_buffer_move_mark   (GtkTextBuffer     *buffer,
211                                             GtkTextMark       *mark,
212                                             const GtkTextIter *where);
213 void           gtk_text_buffer_delete_mark (GtkTextBuffer     *buffer,
214                                             GtkTextMark       *mark);
215 GtkTextMark*   gtk_text_buffer_get_mark    (GtkTextBuffer     *buffer,
216                                             const gchar       *name);
217
218 void gtk_text_buffer_move_mark_by_name   (GtkTextBuffer     *buffer,
219                                           const gchar       *name,
220                                           const GtkTextIter *where);
221 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer     *buffer,
222                                           const gchar       *name);
223
224 GtkTextMark* gtk_text_buffer_get_insert          (GtkTextBuffer *buffer);
225 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
226
227 /* efficiently move insert and selection_bound to same location */
228 void gtk_text_buffer_place_cursor (GtkTextBuffer     *buffer,
229                                    const GtkTextIter *where);
230
231
232
233 /* Tag manipulation */
234 void gtk_text_buffer_apply_tag             (GtkTextBuffer     *buffer,
235                                             GtkTextTag        *tag,
236                                             const GtkTextIter *start_index,
237                                             const GtkTextIter *end_index);
238 void gtk_text_buffer_remove_tag            (GtkTextBuffer     *buffer,
239                                             GtkTextTag        *tag,
240                                             const GtkTextIter *start_index,
241                                             const GtkTextIter *end_index);
242 void gtk_text_buffer_apply_tag_by_name     (GtkTextBuffer     *buffer,
243                                             const gchar       *name,
244                                             const GtkTextIter *start_index,
245                                             const GtkTextIter *end_index);
246 void gtk_text_buffer_remove_tag_by_name    (GtkTextBuffer     *buffer,
247                                             const gchar       *name,
248                                             const GtkTextIter *start_index,
249                                             const GtkTextIter *end_index);
250
251
252 /* You can either ignore the return value, or use it to
253  * set the attributes of the tag. tag_name can be NULL
254  */
255 GtkTextTag    *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
256                                            const gchar   *tag_name);
257
258 /* Obtain iterators pointed at various places, then you can move the
259    iterator around using the GtkTextIter operators */
260 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
261                                               GtkTextIter   *iter,
262                                               gint           line_number,
263                                               gint           char_offset);
264 void gtk_text_buffer_get_iter_at_line_index  (GtkTextBuffer *buffer,
265                                               GtkTextIter   *iter,
266                                               gint           line_number,
267                                               gint           byte_index);
268 void gtk_text_buffer_get_iter_at_offset      (GtkTextBuffer *buffer,
269                                               GtkTextIter   *iter,
270                                               gint           char_offset);
271 void gtk_text_buffer_get_iter_at_line        (GtkTextBuffer *buffer,
272                                               GtkTextIter   *iter,
273                                               gint           line_number);
274 void gtk_text_buffer_get_last_iter           (GtkTextBuffer *buffer,
275                                               GtkTextIter   *iter);
276 void gtk_text_buffer_get_bounds              (GtkTextBuffer *buffer,
277                                               GtkTextIter   *start,
278                                               GtkTextIter   *end);
279 void gtk_text_buffer_get_iter_at_mark        (GtkTextBuffer *buffer,
280                                               GtkTextIter   *iter,
281                                               GtkTextMark   *mark);
282
283 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer      *buffer,
284                                                GtkTextIter        *iter,
285                                                GtkTextChildAnchor *anchor);
286
287 /* There's no get_first_iter because you just get the iter for
288    line or char 0 */
289
290 /* Used to keep track of whether the buffer needs saving; anytime the
291    buffer contents change, the modified flag is turned on. Whenever
292    you save, turn it off. Tags and marks do not affect the modified
293    flag, but if you would like them to you can connect a handler to
294    the tag/mark signals and call set_modified in your handler */
295
296 gboolean        gtk_text_buffer_modified                (GtkTextBuffer *buffer);
297 void            gtk_text_buffer_set_modified            (GtkTextBuffer *buffer,
298                                                          gboolean       setting);
299
300 void            gtk_text_buffer_paste_primary           (GtkTextBuffer       *buffer,
301                                                          const GtkTextIter   *override_location,
302                                                          gboolean             default_editable);
303 void            gtk_text_buffer_cut_clipboard           (GtkTextBuffer *buffer,
304                                                          gboolean       default_editable);
305 void            gtk_text_buffer_copy_clipboard          (GtkTextBuffer *buffer);
306 void            gtk_text_buffer_paste_clipboard         (GtkTextBuffer *buffer,
307                                                          gboolean       default_editable);
308
309 gboolean        gtk_text_buffer_get_selection_bounds    (GtkTextBuffer *buffer,
310                                                          GtkTextIter   *start,
311                                                          GtkTextIter   *end);
312 gboolean        gtk_text_buffer_delete_selection        (GtkTextBuffer *buffer,
313                                                          gboolean       interactive,
314                                                          gboolean       default_editable);
315
316 /* INTERNAL private stuff */
317 void            _gtk_text_buffer_spew                  (GtkTextBuffer      *buffer);
318
319 GtkTextBTree*   _gtk_text_buffer_get_btree             (GtkTextBuffer      *buffer);
320
321 #ifdef __cplusplus
322 }
323 #endif /* __cplusplus */
324
325 #endif