gtktextiter.h 13.2 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 15 16 17 18 19 20 21 22 23
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
 * 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
24
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
25 26
 */

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

31 32
#ifndef __GTK_TEXT_ITER_H__
#define __GTK_TEXT_ITER_H__
33

34
#include <gtk/gtktexttag.h>
35
#include <gtk/gtktextchild.h>
36

37
G_BEGIN_DECLS
38

39
typedef enum {
40 41
  GTK_TEXT_SEARCH_VISIBLE_ONLY = 1 << 0,
  GTK_TEXT_SEARCH_TEXT_ONLY    = 1 << 1
42 43 44
  /* Possible future plans: SEARCH_CASE_INSENSITIVE, SEARCH_REGEXP */
} GtkTextSearchFlags;

45 46 47 48 49 50 51 52
/*
 * 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;

53 54
#define GTK_TYPE_TEXT_ITER     (gtk_text_iter_get_type ())

55
struct _GtkTextIter {
56 57 58 59 60
  /* GtkTextIter is an opaque datatype; ignore all these fields.
   * Initialize the iter with gtk_text_buffer_get_iter_*
   * functions
   */
  /*< private >*/
61 62 63 64 65 66
  gpointer dummy1;
  gpointer dummy2;
  gint dummy3;
  gint dummy4;
  gint dummy5;
  gint dummy6;
Havoc Pennington's avatar
Havoc Pennington committed
67 68 69 70 71 72
  gint dummy7;
  gint dummy8;
  gpointer dummy9;
  gpointer dummy10;
  gint dummy11;
  gint dummy12;
73 74 75
  /* padding */
  gint dummy13;
  gpointer dummy14;
76 77 78 79 80
};


/* This is primarily intended for language bindings that want to avoid
   a "buffer" argument to text insertions, deletions, etc. */
81
GtkTextBuffer *gtk_text_iter_get_buffer (const GtkTextIter *iter);
82 83 84 85 86 87 88 89

/*
 * Life cycle
 */

GtkTextIter *gtk_text_iter_copy     (const GtkTextIter *iter);
void         gtk_text_iter_free     (GtkTextIter       *iter);

Matthias Clasen's avatar
Matthias Clasen committed
90
GType        gtk_text_iter_get_type (void) G_GNUC_CONST;
91

92 93 94
/*
 * Convert to different kinds of index
 */
95 96 97 98 99 100

gint gtk_text_iter_get_offset      (const GtkTextIter *iter);
gint gtk_text_iter_get_line        (const GtkTextIter *iter);
gint gtk_text_iter_get_line_offset (const GtkTextIter *iter);
gint gtk_text_iter_get_line_index  (const GtkTextIter *iter);

101 102 103
gint gtk_text_iter_get_visible_line_offset (const GtkTextIter *iter);
gint gtk_text_iter_get_visible_line_index (const GtkTextIter *iter);

104 105 106 107

/*
 * "Dereference" operators
 */
108
gunichar gtk_text_iter_get_char          (const GtkTextIter  *iter);
109

Havoc Pennington's avatar
Havoc Pennington committed
110 111 112
/* includes the 0xFFFC char for pixmaps/widgets, so char offsets
 * into the returned string map properly into buffer char offsets
 */
113
gchar   *gtk_text_iter_get_slice         (const GtkTextIter  *start,
114
                                          const GtkTextIter  *end);
115

Havoc Pennington's avatar
Havoc Pennington committed
116
/* includes only text, no 0xFFFC */
117
gchar   *gtk_text_iter_get_text          (const GtkTextIter  *start,
118
                                          const GtkTextIter  *end);
119 120
/* exclude invisible chars */
gchar   *gtk_text_iter_get_visible_slice (const GtkTextIter  *start,
121
                                          const GtkTextIter  *end);
122
gchar   *gtk_text_iter_get_visible_text  (const GtkTextIter  *start,
123
                                          const GtkTextIter  *end);
124

Havoc Pennington's avatar
Havoc Pennington committed
125 126
GdkPixbuf* gtk_text_iter_get_pixbuf (const GtkTextIter *iter);
GSList  *  gtk_text_iter_get_marks  (const GtkTextIter *iter);
127

128 129
GtkTextChildAnchor* gtk_text_iter_get_child_anchor (const GtkTextIter *iter);

130
/* Return list of tags toggled at this point (toggled_on determines
Havoc Pennington's avatar
Havoc Pennington committed
131 132
 * whether the list is of on-toggles or off-toggles)
 */
133
GSList  *gtk_text_iter_get_toggled_tags  (const GtkTextIter  *iter,
Havoc Pennington's avatar
Havoc Pennington committed
134
                                          gboolean            toggled_on);
135 136

gboolean gtk_text_iter_begins_tag        (const GtkTextIter  *iter,
137
                                          GtkTextTag         *tag);
138 139

gboolean gtk_text_iter_ends_tag          (const GtkTextIter  *iter,
140
                                          GtkTextTag         *tag);
141 142

gboolean gtk_text_iter_toggles_tag       (const GtkTextIter  *iter,
143
                                          GtkTextTag         *tag);
144 145

gboolean gtk_text_iter_has_tag           (const GtkTextIter   *iter,
146
                                          GtkTextTag          *tag);
147
GSList  *gtk_text_iter_get_tags          (const GtkTextIter   *iter);
148

149 150
gboolean gtk_text_iter_editable          (const GtkTextIter   *iter,
                                          gboolean             default_setting);
151 152
gboolean gtk_text_iter_can_insert        (const GtkTextIter   *iter,
                                          gboolean             default_editability);
153

154 155 156
gboolean gtk_text_iter_starts_word        (const GtkTextIter   *iter);
gboolean gtk_text_iter_ends_word          (const GtkTextIter   *iter);
gboolean gtk_text_iter_inside_word        (const GtkTextIter   *iter);
157 158 159
gboolean gtk_text_iter_starts_sentence    (const GtkTextIter   *iter);
gboolean gtk_text_iter_ends_sentence      (const GtkTextIter   *iter);
gboolean gtk_text_iter_inside_sentence    (const GtkTextIter   *iter);
160 161 162
gboolean gtk_text_iter_starts_line        (const GtkTextIter   *iter);
gboolean gtk_text_iter_ends_line          (const GtkTextIter   *iter);
gboolean gtk_text_iter_is_cursor_position (const GtkTextIter   *iter);
163 164

gint     gtk_text_iter_get_chars_in_line (const GtkTextIter   *iter);
165
gint     gtk_text_iter_get_bytes_in_line (const GtkTextIter   *iter);
166

167 168 169 170 171
gboolean       gtk_text_iter_get_attributes (const GtkTextIter *iter,
					     GtkTextAttributes *values);
PangoLanguage* gtk_text_iter_get_language   (const GtkTextIter *iter);
gboolean       gtk_text_iter_is_end         (const GtkTextIter *iter);
gboolean       gtk_text_iter_is_start       (const GtkTextIter *iter);
172

173 174 175
/*
 * Moving around the buffer
 */
176

177 178
gboolean gtk_text_iter_forward_char         (GtkTextIter *iter);
gboolean gtk_text_iter_backward_char        (GtkTextIter *iter);
179 180 181 182 183 184 185 186 187 188
gboolean gtk_text_iter_forward_chars        (GtkTextIter *iter,
                                             gint         count);
gboolean gtk_text_iter_backward_chars       (GtkTextIter *iter,
                                             gint         count);
gboolean gtk_text_iter_forward_line         (GtkTextIter *iter);
gboolean gtk_text_iter_backward_line        (GtkTextIter *iter);
gboolean gtk_text_iter_forward_lines        (GtkTextIter *iter,
                                             gint         count);
gboolean gtk_text_iter_backward_lines       (GtkTextIter *iter,
                                             gint         count);
189 190
gboolean gtk_text_iter_forward_word_end     (GtkTextIter *iter);
gboolean gtk_text_iter_backward_word_start  (GtkTextIter *iter);
191 192 193 194
gboolean gtk_text_iter_forward_word_ends    (GtkTextIter *iter,
                                             gint         count);
gboolean gtk_text_iter_backward_word_starts (GtkTextIter *iter,
                                             gint         count);
195 196 197 198 199 200 201
                                             
gboolean gtk_text_iter_forward_visible_line   (GtkTextIter *iter);
gboolean gtk_text_iter_backward_visible_line  (GtkTextIter *iter);
gboolean gtk_text_iter_forward_visible_lines  (GtkTextIter *iter,
                                               gint         count);
gboolean gtk_text_iter_backward_visible_lines (GtkTextIter *iter,
                                               gint         count);
202

203 204 205 206 207 208 209
gboolean gtk_text_iter_forward_visible_word_end     (GtkTextIter *iter);
gboolean gtk_text_iter_backward_visible_word_start  (GtkTextIter *iter);
gboolean gtk_text_iter_forward_visible_word_ends    (GtkTextIter *iter,
                                             gint         count);
gboolean gtk_text_iter_backward_visible_word_starts (GtkTextIter *iter,
                                             gint         count);

210 211 212 213 214 215
gboolean gtk_text_iter_forward_sentence_end     (GtkTextIter *iter);
gboolean gtk_text_iter_backward_sentence_start  (GtkTextIter *iter);
gboolean gtk_text_iter_forward_sentence_ends    (GtkTextIter *iter,
                                                 gint         count);
gboolean gtk_text_iter_backward_sentence_starts (GtkTextIter *iter,
                                                 gint         count);
216 217 218 219 220 221 222 223 224 225 226 227
/* cursor positions are almost equivalent to chars, but not quite;
 * 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
 * of a line.
 */
gboolean gtk_text_iter_forward_cursor_position   (GtkTextIter *iter);
gboolean gtk_text_iter_backward_cursor_position  (GtkTextIter *iter);
gboolean gtk_text_iter_forward_cursor_positions  (GtkTextIter *iter,
                                                  gint         count);
gboolean gtk_text_iter_backward_cursor_positions (GtkTextIter *iter,
                                                  gint         count);

228 229 230 231 232 233 234
gboolean gtk_text_iter_forward_visible_cursor_position   (GtkTextIter *iter);
gboolean gtk_text_iter_backward_visible_cursor_position  (GtkTextIter *iter);
gboolean gtk_text_iter_forward_visible_cursor_positions  (GtkTextIter *iter,
                                                          gint         count);
gboolean gtk_text_iter_backward_visible_cursor_positions (GtkTextIter *iter,
                                                          gint         count);

235 236 237 238 239 240 241

void     gtk_text_iter_set_offset         (GtkTextIter *iter,
                                           gint         char_offset);
void     gtk_text_iter_set_line           (GtkTextIter *iter,
                                           gint         line_number);
void     gtk_text_iter_set_line_offset    (GtkTextIter *iter,
                                           gint         char_on_line);
242 243
void     gtk_text_iter_set_line_index     (GtkTextIter *iter,
                                           gint         byte_on_line);
244
void     gtk_text_iter_forward_to_end     (GtkTextIter *iter);
Havoc Pennington's avatar
Havoc Pennington committed
245
gboolean gtk_text_iter_forward_to_line_end (GtkTextIter *iter);
246

247 248 249 250
void     gtk_text_iter_set_visible_line_offset (GtkTextIter *iter,
                                                gint         char_on_line);
void     gtk_text_iter_set_visible_line_index  (GtkTextIter *iter,
                                                gint         byte_on_line);
Havoc Pennington's avatar
Havoc Pennington committed
251

252
/* returns TRUE if a toggle was found; NULL for the tag pointer
253 254 255
 * means "any tag toggle", otherwise the next toggle of the
 * specified tag is located.
 */
256 257
gboolean gtk_text_iter_forward_to_tag_toggle (GtkTextIter *iter,
                                              GtkTextTag  *tag);
258

259 260
gboolean gtk_text_iter_backward_to_tag_toggle (GtkTextIter *iter,
                                               GtkTextTag  *tag);
261

262
typedef gboolean (* GtkTextCharPredicate) (gunichar ch, gpointer user_data);
263

264 265 266 267 268 269 270 271
gboolean gtk_text_iter_forward_find_char  (GtkTextIter          *iter,
                                           GtkTextCharPredicate  pred,
                                           gpointer              user_data,
                                           const GtkTextIter    *limit);
gboolean gtk_text_iter_backward_find_char (GtkTextIter          *iter,
                                           GtkTextCharPredicate  pred,
                                           gpointer              user_data,
                                           const GtkTextIter    *limit);
272

273 274
gboolean gtk_text_iter_forward_search  (const GtkTextIter *iter,
                                        const gchar       *str,
275
                                        GtkTextSearchFlags flags,
276
                                        GtkTextIter       *match_start,
277 278 279
                                        GtkTextIter       *match_end,
                                        const GtkTextIter *limit);

280 281
gboolean gtk_text_iter_backward_search (const GtkTextIter *iter,
                                        const gchar       *str,
282
                                        GtkTextSearchFlags flags,
283
                                        GtkTextIter       *match_start,
284 285
                                        GtkTextIter       *match_end,
                                        const GtkTextIter *limit);
286

287

288 289 290 291
/*
 * Comparisons
 */
gboolean gtk_text_iter_equal           (const GtkTextIter *lhs,
292
                                        const GtkTextIter *rhs);
293
gint     gtk_text_iter_compare         (const GtkTextIter *lhs,
294
                                        const GtkTextIter *rhs);
Havoc Pennington's avatar
Havoc Pennington committed
295
gboolean gtk_text_iter_in_range        (const GtkTextIter *iter,
296 297
                                        const GtkTextIter *start,
                                        const GtkTextIter *end);
298 299

/* Put these two in ascending order */
300
void     gtk_text_iter_order           (GtkTextIter *first,
301
                                        GtkTextIter *second);
302

303
G_END_DECLS
304 305 306 307

#endif