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