]> Pileus Git - ~andy/gtk/blob - gtk/gtktextbuffer.h
Include files outside of the extern "C" block. Makes some C++ compiler
[~andy/gtk] / gtk / gtktextbuffer.h
1 #ifndef GTK_TEXT_BUFFER_H
2 #define GTK_TEXT_BUFFER_H
3
4 #include <gtk/gtkwidget.h>
5 #include <gtk/gtktexttagtable.h>
6 #include <gtk/gtktextiter.h>
7 #include <gtk/gtktextmark.h>
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif /* __cplusplus */
12
13 /*
14  * This is the PUBLIC representation of a text buffer.
15  * GtkTextBTree is the PRIVATE internal representation of it.
16  */
17
18 typedef struct _GtkTextBTree GtkTextBTree;
19
20 #define GTK_TYPE_TEXT_BUFFER            (gtk_text_buffer_get_type())
21 #define GTK_TEXT_BUFFER(obj)            (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBuffer))
22 #define GTK_TEXT_BUFFER_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
23 #define GTK_IS_TEXT_BUFFER(obj)         (GTK_CHECK_TYPE ((obj), GTK_TYPE_TEXT_BUFFER))
24 #define GTK_IS_TEXT_BUFFER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_BUFFER))
25 #define GTK_TEXT_BUFFER_GET_CLASS(obj)  (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_TEXT_BUFFER, GtkTextBufferClass))
26
27 typedef struct _GtkTextBufferClass GtkTextBufferClass;
28
29 struct _GtkTextBuffer {
30   GtkObject parent_instance;
31
32   GtkTextTagTable *tag_table;
33   GtkTextBTree *tree;
34
35   /* Text currently pasted to the clipboard */
36   gchar *clipboard_text;
37
38   /* Whether the buffer has been modified since last save */
39   gboolean modified;
40
41   /* We use this for selections */
42   GtkWidget *selection_widget;
43   gboolean have_selection;
44   gboolean selection_handlers_installed;
45 };
46
47 struct _GtkTextBufferClass {
48   GtkObjectClass parent_class;
49
50   void (* insert_text)     (GtkTextBuffer *buffer,
51                             GtkTextIter *pos,
52                             const gchar *text,
53                             gint length);
54
55
56   void (* delete_text)     (GtkTextBuffer *buffer,
57                             GtkTextIter *start,
58                             GtkTextIter *end);
59
60   /* Only for text changed, marks/tags don't cause this
61      to be emitted */
62   void (* changed)         (GtkTextBuffer *buffer);
63
64
65   /* New value for the modified flag */
66   void (* modified_changed)   (GtkTextBuffer *buffer);
67
68   /* Mark moved or created */
69   void (* mark_set)           (GtkTextBuffer *buffer,
70                                const GtkTextIter *location,
71                                GtkTextMark *mark);
72
73   void (* mark_deleted)       (GtkTextBuffer *buffer,
74                                GtkTextMark *mark);
75
76   void (* apply_tag)          (GtkTextBuffer *buffer,
77                                GtkTextTag *tag,
78                                const GtkTextIter *start_char,
79                                const GtkTextIter *end_char);
80
81   void (* remove_tag)         (GtkTextBuffer *buffer,
82                                GtkTextTag *tag,
83                                const GtkTextIter *start_char,
84                                const GtkTextIter *end_char);
85
86 };
87
88 GtkType        gtk_text_buffer_get_type       (void);
89
90
91
92 /* table is NULL to create a new one */
93 GtkTextBuffer *gtk_text_buffer_new            (GtkTextTagTable *table);
94 gint           gtk_text_buffer_get_line_count (GtkTextBuffer   *buffer);
95 gint           gtk_text_buffer_get_char_count (GtkTextBuffer   *buffer);
96
97
98
99 /* Insert into the buffer */
100 void gtk_text_buffer_insert            (GtkTextBuffer *buffer,
101                                         GtkTextIter   *iter,
102                                         const gchar   *text,
103                                         gint           len);
104 void gtk_text_buffer_insert_at_cursor  (GtkTextBuffer *buffer,
105                                         const gchar   *text,
106                                         gint           len);
107 void gtk_text_buffer_insert_at_char    (GtkTextBuffer *buffer,
108                                         gint           char_pos,
109                                         const gchar   *text,
110                                         gint           len);
111 void gtk_text_buffer_insert_after_line (GtkTextBuffer *buffer,
112                                         gint           after_this_line,
113                                         const gchar   *text,
114                                         gint           len);
115
116
117
118 /* Delete from the buffer */
119
120 void gtk_text_buffer_delete           (GtkTextBuffer *buffer,
121                                        GtkTextIter   *start_iter,
122                                        GtkTextIter   *end_iter);
123 void gtk_text_buffer_delete_chars     (GtkTextBuffer *buffer,
124                                        gint           start_char,
125                                        gint           end_char);
126 void gtk_text_buffer_delete_lines     (GtkTextBuffer *buffer,
127                                        gint           start_line,
128                                        gint           end_line);
129 void gtk_text_buffer_delete_from_line (GtkTextBuffer *buffer,
130                                        gint           line,
131                                        gint           start_char,
132                                        gint           end_char);
133 /* Obtain strings from the buffer */
134 gchar          *gtk_text_buffer_get_text            (GtkTextBuffer     *buffer,
135                                                      const GtkTextIter *start_iter,
136                                                      const GtkTextIter *end_iter,
137                                                      gboolean           include_hidden_chars);
138 gchar          *gtk_text_buffer_get_text_chars      (GtkTextBuffer     *buffer,
139                                                      gint               start_char,
140                                                      gint               end_char,
141                                                      gboolean           include_hidden_chars);
142 gchar          *gtk_text_buffer_get_text_from_line  (GtkTextBuffer     *buffer,
143                                                      gint               line,
144                                                      gint               start_char,
145                                                      gint               end_char,
146                                                      gboolean           include_hidden_chars);
147 gchar          *gtk_text_buffer_get_slice           (GtkTextBuffer     *buffer,
148                                                      const GtkTextIter *start_iter,
149                                                      const GtkTextIter *end_iter,
150                                                      gboolean           include_hidden_chars);
151 gchar          *gtk_text_buffer_get_slice_chars     (GtkTextBuffer     *buffer,
152                                                      gint               start_char,
153                                                      gint               end_char,
154                                                      gboolean           include_hidden_chars);
155 gchar          *gtk_text_buffer_get_slice_from_line (GtkTextBuffer     *buffer,
156                                                      gint               line,
157                                                      gint               start_char,
158                                                      gint               end_char,
159                                                      gboolean           include_hidden_chars);
160
161 /* Insert a pixmap */
162 void gtk_text_buffer_insert_pixmap         (GtkTextBuffer *buffer,
163                                             GtkTextIter   *iter,
164                                             GdkPixmap     *pixmap,
165                                             GdkBitmap     *mask);
166 void gtk_text_buffer_insert_pixmap_at_char (GtkTextBuffer *buffer,
167                                             gint           char_index,
168                                             GdkPixmap     *pixmap,
169                                             GdkBitmap     *mask);
170
171
172
173 /* Mark manipulation */
174 GtkTextMark   *gtk_text_buffer_create_mark (GtkTextBuffer     *buffer,
175                                             const gchar       *mark_name,
176                                             const GtkTextIter *where,
177                                             gboolean           left_gravity);
178 void           gtk_text_buffer_move_mark   (GtkTextBuffer     *buffer,
179                                             GtkTextMark       *mark,
180                                             const GtkTextIter *where);
181 void           gtk_text_buffer_delete_mark (GtkTextBuffer     *buffer,
182                                             GtkTextMark       *mark);
183 GtkTextMark   *gtk_text_buffer_get_mark    (GtkTextBuffer     *buffer,
184                                             const gchar       *name);
185
186
187 /* efficiently move insert and selection_bound to same location */
188 void gtk_text_buffer_place_cursor (GtkTextBuffer     *buffer,
189                                    const GtkTextIter *where);
190
191
192
193 /* Tag manipulation */
194 void gtk_text_buffer_apply_tag_to_chars    (GtkTextBuffer     *buffer,
195                                             const gchar       *name,
196                                             gint               start_char,
197                                             gint               end_char);
198 void gtk_text_buffer_remove_tag_from_chars (GtkTextBuffer     *buffer,
199                                             const gchar       *name,
200                                             gint               start_char,
201                                             gint               end_char);
202 void gtk_text_buffer_apply_tag             (GtkTextBuffer     *buffer,
203                                             const gchar       *name,
204                                             const GtkTextIter *start_index,
205                                             const GtkTextIter *end_index);
206 void gtk_text_buffer_remove_tag            (GtkTextBuffer     *buffer,
207                                             const gchar       *name,
208                                             const GtkTextIter *start_index,
209                                             const GtkTextIter *end_index);
210
211
212
213 /* You can either ignore the return value, or use it to
214    set the attributes of the tag */
215 GtkTextTag    *gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
216                                            const gchar   *tag_name);
217
218 /* Obtain iterators pointed at various places, then you can move the
219    iterator around using the GtkTextIter operators */
220
221 void     gtk_text_buffer_get_iter_at_line_char (GtkTextBuffer *buffer,
222                                                 GtkTextIter   *iter,
223                                                 gint           line_number,
224                                                 gint           char_number);
225 void     gtk_text_buffer_get_iter_at_char      (GtkTextBuffer *buffer,
226                                                 GtkTextIter   *iter,
227                                                 gint           char_index);
228 void     gtk_text_buffer_get_iter_at_line      (GtkTextBuffer *buffer,
229                                                 GtkTextIter   *iter,
230                                                 gint           line_number);
231 void     gtk_text_buffer_get_last_iter         (GtkTextBuffer *buffer,
232                                                 GtkTextIter   *iter);
233 void     gtk_text_buffer_get_bounds            (GtkTextBuffer *buffer,
234                                                 GtkTextIter   *start,
235                                                 GtkTextIter   *end);
236 void     gtk_text_buffer_get_iter_at_mark      (GtkTextBuffer *buffer,
237                                                 GtkTextIter   *iter,
238                                                 GtkTextMark   *mark);
239
240
241 /* There's no get_first_iter because you just get the iter for
242    line or char 0 */
243
244 /*
245   Parses a string, read the man page for the Tk text widget; the only
246   variation from that is we don't support getting the index at a
247   certain pixel since the buffer has no pixel knowledge.  This
248   function is mostly useful for language bindings I think.
249 */
250 gboolean gtk_text_buffer_get_iter_from_string (GtkTextBuffer *buffer,
251                                                GtkTextIter   *iter,
252                                                const gchar   *iter_string);
253
254
255
256 GSList         *gtk_text_buffer_get_tags (GtkTextBuffer     *buffer,
257                                           const GtkTextIter *iter);
258
259
260 /* Used to keep track of whether the buffer needs saving; anytime the
261    buffer contents change, the modified flag is turned on. Whenever
262    you save, turn it off. Tags and marks do not affect the modified
263    flag, but if you would like them to you can connect a handler to
264    the tag/mark signals and call set_modified in your handler */
265
266 gboolean        gtk_text_buffer_modified                (GtkTextBuffer *buffer);
267 void            gtk_text_buffer_set_modified            (GtkTextBuffer *buffer,
268                                                          gboolean       setting);
269 void            gtk_text_buffer_set_clipboard_contents  (GtkTextBuffer *buffer,
270                                                          const gchar   *text);
271 const gchar    *gtk_text_buffer_get_clipboard_contents  (GtkTextBuffer *buffer);
272 void            gtk_text_buffer_paste_primary_selection (GtkTextBuffer *buffer,
273                                                          GtkTextIter   *override_location,
274                                                          guint32        time);
275 gboolean        gtk_text_buffer_delete_selection        (GtkTextBuffer *buffer);
276 void            gtk_text_buffer_cut                     (GtkTextBuffer *buffer,
277                                                          guint32        time);
278 void            gtk_text_buffer_copy                    (GtkTextBuffer *buffer,
279                                                          guint32        time);
280 void            gtk_text_buffer_paste_clipboard         (GtkTextBuffer *buffer,
281                                                          guint32        time);
282 gboolean        gtk_text_buffer_get_selection_bounds    (GtkTextBuffer *buffer,
283                                                          GtkTextIter   *start,
284                                                          GtkTextIter   *end);
285
286
287 /* This function is not implemented. */
288 gboolean gtk_text_buffer_find_string(GtkTextBuffer *buffer,
289                                      GtkTextIter *iter,
290                                      const gchar *str,
291                                      const GtkTextIter *start,
292                                      const GtkTextIter *end);
293
294 #if 0
295 /* Waiting on glib 1.4 regexp facility */
296 gboolean gtk_text_buffer_find_regexp(GtkTextBuffer *buffer,
297                                      GRegexp *regexp,
298                                      const GtkTextIter *start,
299                                      const GtkTextIter *end);
300 #endif
301
302 /* INTERNAL private stuff */
303 void            gtk_text_buffer_spew                   (GtkTextBuffer      *buffer);
304
305 #ifdef __cplusplus
306 }
307 #endif /* __cplusplus */
308
309 #endif