]> Pileus Git - ~andy/gtk/blob - gtk/gtktextbuffer.h
The render vfunc takes a GdkDrawable* instead of a GdkWindow*, because
[~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 at the same time */
257 void gtk_text_buffer_place_cursor (GtkTextBuffer     *buffer,
258                                    const GtkTextIter *where);
259 void gtk_text_buffer_select_range (GtkTextBuffer     *buffer,
260                                    const GtkTextIter *ins,
261                                    const GtkTextIter *bound);
262
263
264
265 /* Tag manipulation */
266 void gtk_text_buffer_apply_tag             (GtkTextBuffer     *buffer,
267                                             GtkTextTag        *tag,
268                                             const GtkTextIter *start,
269                                             const GtkTextIter *end);
270 void gtk_text_buffer_remove_tag            (GtkTextBuffer     *buffer,
271                                             GtkTextTag        *tag,
272                                             const GtkTextIter *start,
273                                             const GtkTextIter *end);
274 void gtk_text_buffer_apply_tag_by_name     (GtkTextBuffer     *buffer,
275                                             const gchar       *name,
276                                             const GtkTextIter *start,
277                                             const GtkTextIter *end);
278 void gtk_text_buffer_remove_tag_by_name    (GtkTextBuffer     *buffer,
279                                             const gchar       *name,
280                                             const GtkTextIter *start,
281                                             const GtkTextIter *end);
282 void gtk_text_buffer_remove_all_tags       (GtkTextBuffer     *buffer,
283                                             const GtkTextIter *start,
284                                             const GtkTextIter *end);
285
286
287 /* You can either ignore the return value, or use it to
288  * set the attributes of the tag. tag_name can be NULL
289  */
290 GtkTextTag    *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
291                                            const gchar   *tag_name,
292                                            const gchar   *first_property_name,
293                                            ...);
294
295 /* Obtain iterators pointed at various places, then you can move the
296  * iterator around using the GtkTextIter operators
297  */
298 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
299                                               GtkTextIter   *iter,
300                                               gint           line_number,
301                                               gint           char_offset);
302 void gtk_text_buffer_get_iter_at_line_index  (GtkTextBuffer *buffer,
303                                               GtkTextIter   *iter,
304                                               gint           line_number,
305                                               gint           byte_index);
306 void gtk_text_buffer_get_iter_at_offset      (GtkTextBuffer *buffer,
307                                               GtkTextIter   *iter,
308                                               gint           char_offset);
309 void gtk_text_buffer_get_iter_at_line        (GtkTextBuffer *buffer,
310                                               GtkTextIter   *iter,
311                                               gint           line_number);
312 void gtk_text_buffer_get_start_iter          (GtkTextBuffer *buffer,
313                                               GtkTextIter   *iter);
314 void gtk_text_buffer_get_end_iter            (GtkTextBuffer *buffer,
315                                               GtkTextIter   *iter);
316 void gtk_text_buffer_get_bounds              (GtkTextBuffer *buffer,
317                                               GtkTextIter   *start,
318                                               GtkTextIter   *end);
319 void gtk_text_buffer_get_iter_at_mark        (GtkTextBuffer *buffer,
320                                               GtkTextIter   *iter,
321                                               GtkTextMark   *mark);
322
323 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer      *buffer,
324                                                GtkTextIter        *iter,
325                                                GtkTextChildAnchor *anchor);
326
327 /* There's no get_first_iter because you just get the iter for
328    line or char 0 */
329
330 /* Used to keep track of whether the buffer needs saving; anytime the
331    buffer contents change, the modified flag is turned on. Whenever
332    you save, turn it off. Tags and marks do not affect the modified
333    flag, but if you would like them to you can connect a handler to
334    the tag/mark signals and call set_modified in your handler */
335
336 gboolean        gtk_text_buffer_get_modified            (GtkTextBuffer *buffer);
337 void            gtk_text_buffer_set_modified            (GtkTextBuffer *buffer,
338                                                          gboolean       setting);
339
340 void gtk_text_buffer_add_selection_clipboard    (GtkTextBuffer     *buffer,
341                                                  GtkClipboard      *clipboard);
342 void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer     *buffer,
343                                                  GtkClipboard      *clipboard);
344
345 void            gtk_text_buffer_cut_clipboard           (GtkTextBuffer *buffer,
346                                                          GtkClipboard  *clipboard,
347                                                          gboolean       default_editable);
348 void            gtk_text_buffer_copy_clipboard          (GtkTextBuffer *buffer,
349                                                          GtkClipboard  *clipboard);
350 void            gtk_text_buffer_paste_clipboard         (GtkTextBuffer *buffer,
351                                                          GtkClipboard  *clipboard,
352                                                          GtkTextIter   *override_location,
353                                                          gboolean       default_editable);
354
355 gboolean        gtk_text_buffer_get_selection_bounds    (GtkTextBuffer *buffer,
356                                                          GtkTextIter   *start,
357                                                          GtkTextIter   *end);
358 gboolean        gtk_text_buffer_delete_selection        (GtkTextBuffer *buffer,
359                                                          gboolean       interactive,
360                                                          gboolean       default_editable);                                                    
361
362 /* Called to specify atomic user actions, used to implement undo */
363 void            gtk_text_buffer_begin_user_action       (GtkTextBuffer *buffer);
364 void            gtk_text_buffer_end_user_action         (GtkTextBuffer *buffer);
365
366 /* INTERNAL private stuff */
367 void            _gtk_text_buffer_spew                  (GtkTextBuffer      *buffer);
368
369 GtkTextBTree*   _gtk_text_buffer_get_btree             (GtkTextBuffer      *buffer);
370
371 const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer     *buffer,
372                                                          const GtkTextIter *anywhere_in_line,
373                                                          gint              *char_len);
374
375 void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,
376                                               GtkTextTag    *tag);
377
378 #ifdef __cplusplus
379 }
380 #endif /* __cplusplus */
381
382 #endif