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