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