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