]> Pileus Git - ~andy/gtk/blob - gtk/gtktextbuffer.h
e9b6e9716c8ffd7072c25daedd54ef5895ccfec3
[~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 *text,
87                             gint length);
88
89   void (* insert_pixbuf)   (GtkTextBuffer *buffer,
90                             GtkTextIter   *pos,
91                             GdkPixbuf     *pixbuf);
92
93   void (* insert_child_anchor)   (GtkTextBuffer      *buffer,
94                                   GtkTextIter        *pos,
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_char,
121                                const GtkTextIter *end_char);
122
123   void (* remove_tag)         (GtkTextBuffer *buffer,
124                                GtkTextTag *tag,
125                                const GtkTextIter *start_char,
126                                const GtkTextIter *end_char);
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   void (*_gtk_reserved5) (void);
141 };
142
143 GType        gtk_text_buffer_get_type       (void) G_GNUC_CONST;
144
145
146
147 /* table is NULL to create a new one */
148 GtkTextBuffer *gtk_text_buffer_new            (GtkTextTagTable *table);
149 gint           gtk_text_buffer_get_line_count (GtkTextBuffer   *buffer);
150 gint           gtk_text_buffer_get_char_count (GtkTextBuffer   *buffer);
151
152
153 GtkTextTagTable* gtk_text_buffer_get_tag_table (GtkTextBuffer  *buffer);
154
155 /* Delete whole buffer, then insert */
156 void gtk_text_buffer_set_text          (GtkTextBuffer *buffer,
157                                         const gchar   *text,
158                                         gint           len);
159
160 /* Insert into the buffer */
161 void gtk_text_buffer_insert            (GtkTextBuffer *buffer,
162                                         GtkTextIter   *iter,
163                                         const gchar   *text,
164                                         gint           len);
165 void gtk_text_buffer_insert_at_cursor  (GtkTextBuffer *buffer,
166                                         const gchar   *text,
167                                         gint           len);
168
169 gboolean gtk_text_buffer_insert_interactive           (GtkTextBuffer *buffer,
170                                                        GtkTextIter   *iter,
171                                                        const gchar   *text,
172                                                        gint           len,
173                                                        gboolean       default_editable);
174 gboolean gtk_text_buffer_insert_interactive_at_cursor (GtkTextBuffer *buffer,
175                                                        const gchar   *text,
176                                                        gint           len,
177                                                        gboolean       default_editable);
178
179 void     gtk_text_buffer_insert_range             (GtkTextBuffer     *buffer,
180                                                    GtkTextIter       *iter,
181                                                    const GtkTextIter *start,
182                                                    const GtkTextIter *end);
183 gboolean gtk_text_buffer_insert_range_interactive (GtkTextBuffer     *buffer,
184                                                    GtkTextIter       *iter,
185                                                    const GtkTextIter *start,
186                                                    const GtkTextIter *end,
187                                                    gboolean           default_editable);
188
189 void    gtk_text_buffer_insert_with_tags          (GtkTextBuffer     *buffer,
190                                                    GtkTextIter       *iter,
191                                                    const gchar       *text,
192                                                    gint               len,
193                                                    GtkTextTag        *first_tag,
194                                                    ...) G_GNUC_NULL_TERMINATED;
195
196 void    gtk_text_buffer_insert_with_tags_by_name  (GtkTextBuffer     *buffer,
197                                                    GtkTextIter       *iter,
198                                                    const gchar       *text,
199                                                    gint               len,
200                                                    const gchar       *first_tag_name,
201                                                    ...) G_GNUC_NULL_TERMINATED;
202
203 /* Delete from the buffer */
204 void     gtk_text_buffer_delete             (GtkTextBuffer *buffer,
205                                              GtkTextIter   *start,
206                                              GtkTextIter   *end);
207 gboolean gtk_text_buffer_delete_interactive (GtkTextBuffer *buffer,
208                                              GtkTextIter   *start_iter,
209                                              GtkTextIter   *end_iter,
210                                              gboolean       default_editable);
211 gboolean gtk_text_buffer_backspace          (GtkTextBuffer *buffer,
212                                              GtkTextIter   *iter,
213                                              gboolean       interactive,
214                                              gboolean       default_editable);
215
216 /* Obtain strings from the buffer */
217 gchar          *gtk_text_buffer_get_text            (GtkTextBuffer     *buffer,
218                                                      const GtkTextIter *start,
219                                                      const GtkTextIter *end,
220                                                      gboolean           include_hidden_chars);
221
222 gchar          *gtk_text_buffer_get_slice           (GtkTextBuffer     *buffer,
223                                                      const GtkTextIter *start,
224                                                      const GtkTextIter *end,
225                                                      gboolean           include_hidden_chars);
226
227 /* Insert a pixbuf */
228 void gtk_text_buffer_insert_pixbuf         (GtkTextBuffer *buffer,
229                                             GtkTextIter   *iter,
230                                             GdkPixbuf     *pixbuf);
231
232 /* Insert a child anchor */
233 void               gtk_text_buffer_insert_child_anchor (GtkTextBuffer      *buffer,
234                                                         GtkTextIter        *iter,
235                                                         GtkTextChildAnchor *anchor);
236
237 /* Convenience, create and insert a child anchor */
238 GtkTextChildAnchor *gtk_text_buffer_create_child_anchor (GtkTextBuffer *buffer,
239                                                          GtkTextIter   *iter);
240
241 /* Mark manipulation */
242 void           gtk_text_buffer_add_mark    (GtkTextBuffer     *buffer,
243                                             GtkTextMark       *mark,
244                                             const GtkTextIter *where);
245 GtkTextMark   *gtk_text_buffer_create_mark (GtkTextBuffer     *buffer,
246                                             const gchar       *mark_name,
247                                             const GtkTextIter *where,
248                                             gboolean           left_gravity);
249 void           gtk_text_buffer_move_mark   (GtkTextBuffer     *buffer,
250                                             GtkTextMark       *mark,
251                                             const GtkTextIter *where);
252 void           gtk_text_buffer_delete_mark (GtkTextBuffer     *buffer,
253                                             GtkTextMark       *mark);
254 GtkTextMark*   gtk_text_buffer_get_mark    (GtkTextBuffer     *buffer,
255                                             const gchar       *name);
256
257 void gtk_text_buffer_move_mark_by_name   (GtkTextBuffer     *buffer,
258                                           const gchar       *name,
259                                           const GtkTextIter *where);
260 void gtk_text_buffer_delete_mark_by_name (GtkTextBuffer     *buffer,
261                                           const gchar       *name);
262
263 GtkTextMark* gtk_text_buffer_get_insert          (GtkTextBuffer *buffer);
264 GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
265
266 /* efficiently move insert and selection_bound at the same time */
267 void gtk_text_buffer_place_cursor (GtkTextBuffer     *buffer,
268                                    const GtkTextIter *where);
269 void gtk_text_buffer_select_range (GtkTextBuffer     *buffer,
270                                    const GtkTextIter *ins,
271                                    const GtkTextIter *bound);
272
273
274
275 /* Tag manipulation */
276 void gtk_text_buffer_apply_tag             (GtkTextBuffer     *buffer,
277                                             GtkTextTag        *tag,
278                                             const GtkTextIter *start,
279                                             const GtkTextIter *end);
280 void gtk_text_buffer_remove_tag            (GtkTextBuffer     *buffer,
281                                             GtkTextTag        *tag,
282                                             const GtkTextIter *start,
283                                             const GtkTextIter *end);
284 void gtk_text_buffer_apply_tag_by_name     (GtkTextBuffer     *buffer,
285                                             const gchar       *name,
286                                             const GtkTextIter *start,
287                                             const GtkTextIter *end);
288 void gtk_text_buffer_remove_tag_by_name    (GtkTextBuffer     *buffer,
289                                             const gchar       *name,
290                                             const GtkTextIter *start,
291                                             const GtkTextIter *end);
292 void gtk_text_buffer_remove_all_tags       (GtkTextBuffer     *buffer,
293                                             const GtkTextIter *start,
294                                             const GtkTextIter *end);
295
296
297 /* You can either ignore the return value, or use it to
298  * set the attributes of the tag. tag_name can be NULL
299  */
300 GtkTextTag    *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
301                                            const gchar   *tag_name,
302                                            const gchar   *first_property_name,
303                                            ...);
304
305 /* Obtain iterators pointed at various places, then you can move the
306  * iterator around using the GtkTextIter operators
307  */
308 void gtk_text_buffer_get_iter_at_line_offset (GtkTextBuffer *buffer,
309                                               GtkTextIter   *iter,
310                                               gint           line_number,
311                                               gint           char_offset);
312 void gtk_text_buffer_get_iter_at_line_index  (GtkTextBuffer *buffer,
313                                               GtkTextIter   *iter,
314                                               gint           line_number,
315                                               gint           byte_index);
316 void gtk_text_buffer_get_iter_at_offset      (GtkTextBuffer *buffer,
317                                               GtkTextIter   *iter,
318                                               gint           char_offset);
319 void gtk_text_buffer_get_iter_at_line        (GtkTextBuffer *buffer,
320                                               GtkTextIter   *iter,
321                                               gint           line_number);
322 void gtk_text_buffer_get_start_iter          (GtkTextBuffer *buffer,
323                                               GtkTextIter   *iter);
324 void gtk_text_buffer_get_end_iter            (GtkTextBuffer *buffer,
325                                               GtkTextIter   *iter);
326 void gtk_text_buffer_get_bounds              (GtkTextBuffer *buffer,
327                                               GtkTextIter   *start,
328                                               GtkTextIter   *end);
329 void gtk_text_buffer_get_iter_at_mark        (GtkTextBuffer *buffer,
330                                               GtkTextIter   *iter,
331                                               GtkTextMark   *mark);
332
333 void gtk_text_buffer_get_iter_at_child_anchor (GtkTextBuffer      *buffer,
334                                                GtkTextIter        *iter,
335                                                GtkTextChildAnchor *anchor);
336
337 /* There's no get_first_iter because you just get the iter for
338    line or char 0 */
339
340 /* Used to keep track of whether the buffer needs saving; anytime the
341    buffer contents change, the modified flag is turned on. Whenever
342    you save, turn it off. Tags and marks do not affect the modified
343    flag, but if you would like them to you can connect a handler to
344    the tag/mark signals and call set_modified in your handler */
345
346 gboolean        gtk_text_buffer_get_modified            (GtkTextBuffer *buffer);
347 void            gtk_text_buffer_set_modified            (GtkTextBuffer *buffer,
348                                                          gboolean       setting);
349
350 gboolean        gtk_text_buffer_get_has_selection       (GtkTextBuffer *buffer);
351
352 void gtk_text_buffer_add_selection_clipboard    (GtkTextBuffer     *buffer,
353                                                  GtkClipboard      *clipboard);
354 void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer     *buffer,
355                                                  GtkClipboard      *clipboard);
356
357 void            gtk_text_buffer_cut_clipboard           (GtkTextBuffer *buffer,
358                                                          GtkClipboard  *clipboard,
359                                                          gboolean       default_editable);
360 void            gtk_text_buffer_copy_clipboard          (GtkTextBuffer *buffer,
361                                                          GtkClipboard  *clipboard);
362 void            gtk_text_buffer_paste_clipboard         (GtkTextBuffer *buffer,
363                                                          GtkClipboard  *clipboard,
364                                                          GtkTextIter   *override_location,
365                                                          gboolean       default_editable);
366
367 gboolean        gtk_text_buffer_get_selection_bounds    (GtkTextBuffer *buffer,
368                                                          GtkTextIter   *start,
369                                                          GtkTextIter   *end);
370 gboolean        gtk_text_buffer_delete_selection        (GtkTextBuffer *buffer,
371                                                          gboolean       interactive,
372                                                          gboolean       default_editable);
373
374 /* Called to specify atomic user actions, used to implement undo */
375 void            gtk_text_buffer_begin_user_action       (GtkTextBuffer *buffer);
376 void            gtk_text_buffer_end_user_action         (GtkTextBuffer *buffer);
377
378 GtkTargetList * gtk_text_buffer_get_copy_target_list    (GtkTextBuffer *buffer);
379 GtkTargetList * gtk_text_buffer_get_paste_target_list   (GtkTextBuffer *buffer);
380
381 /* INTERNAL private stuff */
382 void            _gtk_text_buffer_spew                  (GtkTextBuffer      *buffer);
383
384 GtkTextBTree*   _gtk_text_buffer_get_btree             (GtkTextBuffer      *buffer);
385
386 const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer     *buffer,
387                                                          const GtkTextIter *anywhere_in_line,
388                                                          gint              *char_len);
389
390 void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,
391                                               GtkTextTag    *tag);
392
393 G_END_DECLS
394
395 #endif