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