gtktextiter.h 15.8 KB
Newer Older
Cody Russell's avatar
Cody Russell committed
1
/* GTK - The GIMP Toolkit
2 3 4 5 6 7 8 9 10
 * gtktextiter.h Copyright (C) 2000 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 13 14
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21
 */

/*
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
22
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
23 24
 */

25 26 27
#ifndef __GTK_TEXT_ITER_H__
#define __GTK_TEXT_ITER_H__

28
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
29 30 31
#error "Only <gtk/gtk.h> can be included directly."
#endif

32
#include <gtk/gtktextattributes.h>
33
#include <gtk/gtktextchild.h>
34
#include <gtk/gtktexttag.h>
35

36
G_BEGIN_DECLS
37

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
/**
 * GtkTextSearchFlags:
 * @GTK_TEXT_SEARCH_VISIBLE_ONLY: Search only visible data. A search match may
 * have invisible text interspersed.
 * @GTK_TEXT_SEARCH_TEXT_ONLY: Search only text. A match may have pixbufs or
 * child widgets mixed inside the matched range.
 * @GTK_TEXT_SEARCH_CASE_INSENSITIVE: The text will be matched regardless of
 * what case it is in.
 *
 * Flags affecting how a search is done.
 *
 * If neither #GTK_TEXT_SEARCH_VISIBLE_ONLY nor #GTK_TEXT_SEARCH_TEXT_ONLY are
 * enabled, the match must be exact; the special 0xFFFC character will match
 * embedded pixbufs or child widgets.
 */
53
typedef enum {
54 55
  GTK_TEXT_SEARCH_VISIBLE_ONLY     = 1 << 0,
  GTK_TEXT_SEARCH_TEXT_ONLY        = 1 << 1,
56
  GTK_TEXT_SEARCH_CASE_INSENSITIVE = 1 << 2
57
  /* Possible future plans: SEARCH_REGEXP */
58 59
} GtkTextSearchFlags;

60 61 62 63 64 65 66 67
/*
 * Iter: represents a location in the text. Becomes invalid if the
 * characters/pixmaps/widgets (indexable objects) in the text buffer
 * are changed.
 */

typedef struct _GtkTextBuffer GtkTextBuffer;

68 69
#define GTK_TYPE_TEXT_ITER     (gtk_text_iter_get_type ())

70
struct _GtkTextIter {
71 72 73 74 75
  /* GtkTextIter is an opaque datatype; ignore all these fields.
   * Initialize the iter with gtk_text_buffer_get_iter_*
   * functions
   */
  /*< private >*/
76 77 78 79 80 81
  gpointer dummy1;
  gpointer dummy2;
  gint dummy3;
  gint dummy4;
  gint dummy5;
  gint dummy6;
Havoc Pennington's avatar
Havoc Pennington committed
82 83 84 85 86 87
  gint dummy7;
  gint dummy8;
  gpointer dummy9;
  gpointer dummy10;
  gint dummy11;
  gint dummy12;
88 89 90
  /* padding */
  gint dummy13;
  gpointer dummy14;
91 92 93 94 95
};


/* This is primarily intended for language bindings that want to avoid
   a "buffer" argument to text insertions, deletions, etc. */
96
GDK_AVAILABLE_IN_ALL
97
GtkTextBuffer *gtk_text_iter_get_buffer (const GtkTextIter *iter);
98 99 100 101 102

/*
 * Life cycle
 */

103
GDK_AVAILABLE_IN_ALL
104
GtkTextIter *gtk_text_iter_copy     (const GtkTextIter *iter);
105
GDK_AVAILABLE_IN_ALL
106
void         gtk_text_iter_free     (GtkTextIter       *iter);
107
GDK_AVAILABLE_IN_3_2
108 109
void         gtk_text_iter_assign   (GtkTextIter       *iter,
                                     const GtkTextIter *other);
110

111
GDK_AVAILABLE_IN_ALL
Matthias Clasen's avatar
Matthias Clasen committed
112
GType        gtk_text_iter_get_type (void) G_GNUC_CONST;
113

114 115 116
/*
 * Convert to different kinds of index
 */
117

118
GDK_AVAILABLE_IN_ALL
119
gint gtk_text_iter_get_offset      (const GtkTextIter *iter);
120
GDK_AVAILABLE_IN_ALL
121
gint gtk_text_iter_get_line        (const GtkTextIter *iter);
122
GDK_AVAILABLE_IN_ALL
123
gint gtk_text_iter_get_line_offset (const GtkTextIter *iter);
124
GDK_AVAILABLE_IN_ALL
125 126
gint gtk_text_iter_get_line_index  (const GtkTextIter *iter);

127
GDK_AVAILABLE_IN_ALL
128
gint gtk_text_iter_get_visible_line_offset (const GtkTextIter *iter);
129
GDK_AVAILABLE_IN_ALL
130 131
gint gtk_text_iter_get_visible_line_index (const GtkTextIter *iter);

132 133

/*
134
 * “Dereference” operators
135
 */
136
GDK_AVAILABLE_IN_ALL
137
gunichar gtk_text_iter_get_char          (const GtkTextIter  *iter);
138

Havoc Pennington's avatar
Havoc Pennington committed
139 140 141
/* includes the 0xFFFC char for pixmaps/widgets, so char offsets
 * into the returned string map properly into buffer char offsets
 */
142
GDK_AVAILABLE_IN_ALL
143
gchar   *gtk_text_iter_get_slice         (const GtkTextIter  *start,
144
                                          const GtkTextIter  *end);
145

Havoc Pennington's avatar
Havoc Pennington committed
146
/* includes only text, no 0xFFFC */
147
GDK_AVAILABLE_IN_ALL
148
gchar   *gtk_text_iter_get_text          (const GtkTextIter  *start,
149
                                          const GtkTextIter  *end);
150
/* exclude invisible chars */
151
GDK_AVAILABLE_IN_ALL
152
gchar   *gtk_text_iter_get_visible_slice (const GtkTextIter  *start,
153
                                          const GtkTextIter  *end);
154
GDK_AVAILABLE_IN_ALL
155
gchar   *gtk_text_iter_get_visible_text  (const GtkTextIter  *start,
156
                                          const GtkTextIter  *end);
157

158
GDK_AVAILABLE_IN_ALL
Havoc Pennington's avatar
Havoc Pennington committed
159
GdkPixbuf* gtk_text_iter_get_pixbuf (const GtkTextIter *iter);
160
GDK_AVAILABLE_IN_ALL
Havoc Pennington's avatar
Havoc Pennington committed
161
GSList  *  gtk_text_iter_get_marks  (const GtkTextIter *iter);
162

163
GDK_AVAILABLE_IN_ALL
164 165
GtkTextChildAnchor* gtk_text_iter_get_child_anchor (const GtkTextIter *iter);

166
/* Return list of tags toggled at this point (toggled_on determines
Havoc Pennington's avatar
Havoc Pennington committed
167 168
 * whether the list is of on-toggles or off-toggles)
 */
169
GDK_AVAILABLE_IN_ALL
170
GSList  *gtk_text_iter_get_toggled_tags  (const GtkTextIter  *iter,
Havoc Pennington's avatar
Havoc Pennington committed
171
                                          gboolean            toggled_on);
172

173
GDK_AVAILABLE_IN_ALL
174
gboolean gtk_text_iter_begins_tag        (const GtkTextIter  *iter,
175
                                          GtkTextTag         *tag);
176

177
GDK_AVAILABLE_IN_ALL
178
gboolean gtk_text_iter_ends_tag          (const GtkTextIter  *iter,
179
                                          GtkTextTag         *tag);
180

181
GDK_AVAILABLE_IN_ALL
182
gboolean gtk_text_iter_toggles_tag       (const GtkTextIter  *iter,
183
                                          GtkTextTag         *tag);
184

185
GDK_AVAILABLE_IN_ALL
186
gboolean gtk_text_iter_has_tag           (const GtkTextIter   *iter,
187
                                          GtkTextTag          *tag);
188
GDK_AVAILABLE_IN_ALL
189
GSList  *gtk_text_iter_get_tags          (const GtkTextIter   *iter);
190

191
GDK_AVAILABLE_IN_ALL
192 193
gboolean gtk_text_iter_editable          (const GtkTextIter   *iter,
                                          gboolean             default_setting);
194
GDK_AVAILABLE_IN_ALL
195 196
gboolean gtk_text_iter_can_insert        (const GtkTextIter   *iter,
                                          gboolean             default_editability);
197

198
GDK_AVAILABLE_IN_ALL
199
gboolean gtk_text_iter_starts_word        (const GtkTextIter   *iter);
200
GDK_AVAILABLE_IN_ALL
201
gboolean gtk_text_iter_ends_word          (const GtkTextIter   *iter);
202
GDK_AVAILABLE_IN_ALL
203
gboolean gtk_text_iter_inside_word        (const GtkTextIter   *iter);
204
GDK_AVAILABLE_IN_ALL
205
gboolean gtk_text_iter_starts_sentence    (const GtkTextIter   *iter);
206
GDK_AVAILABLE_IN_ALL
207
gboolean gtk_text_iter_ends_sentence      (const GtkTextIter   *iter);
208
GDK_AVAILABLE_IN_ALL
209
gboolean gtk_text_iter_inside_sentence    (const GtkTextIter   *iter);
210
GDK_AVAILABLE_IN_ALL
211
gboolean gtk_text_iter_starts_line        (const GtkTextIter   *iter);
212
GDK_AVAILABLE_IN_ALL
213
gboolean gtk_text_iter_ends_line          (const GtkTextIter   *iter);
214
GDK_AVAILABLE_IN_ALL
215
gboolean gtk_text_iter_is_cursor_position (const GtkTextIter   *iter);
216

217
GDK_AVAILABLE_IN_ALL
218
gint     gtk_text_iter_get_chars_in_line (const GtkTextIter   *iter);
219
GDK_AVAILABLE_IN_ALL
220
gint     gtk_text_iter_get_bytes_in_line (const GtkTextIter   *iter);
221

222
GDK_AVAILABLE_IN_ALL
223 224
gboolean       gtk_text_iter_get_attributes (const GtkTextIter *iter,
					     GtkTextAttributes *values);
225
GDK_AVAILABLE_IN_ALL
226
PangoLanguage* gtk_text_iter_get_language   (const GtkTextIter *iter);
227
GDK_AVAILABLE_IN_ALL
228
gboolean       gtk_text_iter_is_end         (const GtkTextIter *iter);
229
GDK_AVAILABLE_IN_ALL
230
gboolean       gtk_text_iter_is_start       (const GtkTextIter *iter);
231

232 233 234
/*
 * Moving around the buffer
 */
235

236
GDK_AVAILABLE_IN_ALL
237
gboolean gtk_text_iter_forward_char         (GtkTextIter *iter);
238
GDK_AVAILABLE_IN_ALL
239
gboolean gtk_text_iter_backward_char        (GtkTextIter *iter);
240
GDK_AVAILABLE_IN_ALL
241 242
gboolean gtk_text_iter_forward_chars        (GtkTextIter *iter,
                                             gint         count);
243
GDK_AVAILABLE_IN_ALL
244 245
gboolean gtk_text_iter_backward_chars       (GtkTextIter *iter,
                                             gint         count);
246
GDK_AVAILABLE_IN_ALL
247
gboolean gtk_text_iter_forward_line         (GtkTextIter *iter);
248
GDK_AVAILABLE_IN_ALL
249
gboolean gtk_text_iter_backward_line        (GtkTextIter *iter);
250
GDK_AVAILABLE_IN_ALL
251 252
gboolean gtk_text_iter_forward_lines        (GtkTextIter *iter,
                                             gint         count);
253
GDK_AVAILABLE_IN_ALL
254 255
gboolean gtk_text_iter_backward_lines       (GtkTextIter *iter,
                                             gint         count);
256
GDK_AVAILABLE_IN_ALL
257
gboolean gtk_text_iter_forward_word_end     (GtkTextIter *iter);
258
GDK_AVAILABLE_IN_ALL
259
gboolean gtk_text_iter_backward_word_start  (GtkTextIter *iter);
260
GDK_AVAILABLE_IN_ALL
261 262
gboolean gtk_text_iter_forward_word_ends    (GtkTextIter *iter,
                                             gint         count);
263
GDK_AVAILABLE_IN_ALL
264 265
gboolean gtk_text_iter_backward_word_starts (GtkTextIter *iter,
                                             gint         count);
266
                                             
267
GDK_AVAILABLE_IN_ALL
268
gboolean gtk_text_iter_forward_visible_line   (GtkTextIter *iter);
269
GDK_AVAILABLE_IN_ALL
270
gboolean gtk_text_iter_backward_visible_line  (GtkTextIter *iter);
271
GDK_AVAILABLE_IN_ALL
272 273
gboolean gtk_text_iter_forward_visible_lines  (GtkTextIter *iter,
                                               gint         count);
274
GDK_AVAILABLE_IN_ALL
275 276
gboolean gtk_text_iter_backward_visible_lines (GtkTextIter *iter,
                                               gint         count);
277

278
GDK_AVAILABLE_IN_ALL
279
gboolean gtk_text_iter_forward_visible_word_end     (GtkTextIter *iter);
280
GDK_AVAILABLE_IN_ALL
281
gboolean gtk_text_iter_backward_visible_word_start  (GtkTextIter *iter);
282
GDK_AVAILABLE_IN_ALL
283 284
gboolean gtk_text_iter_forward_visible_word_ends    (GtkTextIter *iter,
                                             gint         count);
285
GDK_AVAILABLE_IN_ALL
286 287 288
gboolean gtk_text_iter_backward_visible_word_starts (GtkTextIter *iter,
                                             gint         count);

289
GDK_AVAILABLE_IN_ALL
290
gboolean gtk_text_iter_forward_sentence_end     (GtkTextIter *iter);
291
GDK_AVAILABLE_IN_ALL
292
gboolean gtk_text_iter_backward_sentence_start  (GtkTextIter *iter);
293
GDK_AVAILABLE_IN_ALL
294 295
gboolean gtk_text_iter_forward_sentence_ends    (GtkTextIter *iter,
                                                 gint         count);
296
GDK_AVAILABLE_IN_ALL
297 298
gboolean gtk_text_iter_backward_sentence_starts (GtkTextIter *iter,
                                                 gint         count);
299
/* cursor positions are almost equivalent to chars, but not quite;
300 301
 * in some languages, you can’t put the cursor between certain
 * chars. Also, you can’t put the cursor between \r\n at the end
302 303
 * of a line.
 */
304
GDK_AVAILABLE_IN_ALL
305
gboolean gtk_text_iter_forward_cursor_position   (GtkTextIter *iter);
306
GDK_AVAILABLE_IN_ALL
307
gboolean gtk_text_iter_backward_cursor_position  (GtkTextIter *iter);
308
GDK_AVAILABLE_IN_ALL
309 310
gboolean gtk_text_iter_forward_cursor_positions  (GtkTextIter *iter,
                                                  gint         count);
311
GDK_AVAILABLE_IN_ALL
312 313 314
gboolean gtk_text_iter_backward_cursor_positions (GtkTextIter *iter,
                                                  gint         count);

315
GDK_AVAILABLE_IN_ALL
316
gboolean gtk_text_iter_forward_visible_cursor_position   (GtkTextIter *iter);
317
GDK_AVAILABLE_IN_ALL
318
gboolean gtk_text_iter_backward_visible_cursor_position  (GtkTextIter *iter);
319
GDK_AVAILABLE_IN_ALL
320 321
gboolean gtk_text_iter_forward_visible_cursor_positions  (GtkTextIter *iter,
                                                          gint         count);
322
GDK_AVAILABLE_IN_ALL
323 324 325
gboolean gtk_text_iter_backward_visible_cursor_positions (GtkTextIter *iter,
                                                          gint         count);

326
GDK_AVAILABLE_IN_ALL
327 328
void     gtk_text_iter_set_offset         (GtkTextIter *iter,
                                           gint         char_offset);
329
GDK_AVAILABLE_IN_ALL
330 331
void     gtk_text_iter_set_line           (GtkTextIter *iter,
                                           gint         line_number);
332
GDK_AVAILABLE_IN_ALL
333 334
void     gtk_text_iter_set_line_offset    (GtkTextIter *iter,
                                           gint         char_on_line);
335
GDK_AVAILABLE_IN_ALL
336 337
void     gtk_text_iter_set_line_index     (GtkTextIter *iter,
                                           gint         byte_on_line);
338
GDK_AVAILABLE_IN_ALL
339
void     gtk_text_iter_forward_to_end     (GtkTextIter *iter);
340
GDK_AVAILABLE_IN_ALL
Havoc Pennington's avatar
Havoc Pennington committed
341
gboolean gtk_text_iter_forward_to_line_end (GtkTextIter *iter);
342

343
GDK_AVAILABLE_IN_ALL
344 345
void     gtk_text_iter_set_visible_line_offset (GtkTextIter *iter,
                                                gint         char_on_line);
346
GDK_AVAILABLE_IN_ALL
347 348
void     gtk_text_iter_set_visible_line_index  (GtkTextIter *iter,
                                                gint         byte_on_line);
Havoc Pennington's avatar
Havoc Pennington committed
349

350
/* returns TRUE if a toggle was found; NULL for the tag pointer
351
 * means “any tag toggle”, otherwise the next toggle of the
352 353
 * specified tag is located.
 */
354
GDK_AVAILABLE_IN_ALL
355 356
gboolean gtk_text_iter_forward_to_tag_toggle (GtkTextIter *iter,
                                              GtkTextTag  *tag);
357

358
GDK_AVAILABLE_IN_ALL
359 360
gboolean gtk_text_iter_backward_to_tag_toggle (GtkTextIter *iter,
                                               GtkTextTag  *tag);
361

362
typedef gboolean (* GtkTextCharPredicate) (gunichar ch, gpointer user_data);
363

364
GDK_AVAILABLE_IN_ALL
365 366 367 368
gboolean gtk_text_iter_forward_find_char  (GtkTextIter          *iter,
                                           GtkTextCharPredicate  pred,
                                           gpointer              user_data,
                                           const GtkTextIter    *limit);
369
GDK_AVAILABLE_IN_ALL
370 371 372 373
gboolean gtk_text_iter_backward_find_char (GtkTextIter          *iter,
                                           GtkTextCharPredicate  pred,
                                           gpointer              user_data,
                                           const GtkTextIter    *limit);
374

375
GDK_AVAILABLE_IN_ALL
376 377
gboolean gtk_text_iter_forward_search  (const GtkTextIter *iter,
                                        const gchar       *str,
378
                                        GtkTextSearchFlags flags,
379
                                        GtkTextIter       *match_start,
380 381 382
                                        GtkTextIter       *match_end,
                                        const GtkTextIter *limit);

383
GDK_AVAILABLE_IN_ALL
384 385
gboolean gtk_text_iter_backward_search (const GtkTextIter *iter,
                                        const gchar       *str,
386
                                        GtkTextSearchFlags flags,
387
                                        GtkTextIter       *match_start,
388 389
                                        GtkTextIter       *match_end,
                                        const GtkTextIter *limit);
390

391 392 393
/*
 * Comparisons
 */
394
GDK_AVAILABLE_IN_ALL
395
gboolean gtk_text_iter_equal           (const GtkTextIter *lhs,
396
                                        const GtkTextIter *rhs);
397
GDK_AVAILABLE_IN_ALL
398
gint     gtk_text_iter_compare         (const GtkTextIter *lhs,
399
                                        const GtkTextIter *rhs);
400
GDK_AVAILABLE_IN_ALL
Havoc Pennington's avatar
Havoc Pennington committed
401
gboolean gtk_text_iter_in_range        (const GtkTextIter *iter,
402 403
                                        const GtkTextIter *start,
                                        const GtkTextIter *end);
404 405

/* Put these two in ascending order */
406
GDK_AVAILABLE_IN_ALL
407
void     gtk_text_iter_order           (GtkTextIter *first,
408
                                        GtkTextIter *second);
409

410
G_END_DECLS
411 412

#endif