]> Pileus Git - ~andy/gtk/blob - gtk/gtktextbtree.h
Avoid recreating pangolayouts in GtkTextView on cursor movement (#435405,
[~andy/gtk] / gtk / gtktextbtree.h
1 /* GTK - The GIMP Toolkit
2  * gtktextbtree.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_BTREE_H__
28 #define __GTK_TEXT_BTREE_H__
29
30 #if 0
31 #define DEBUG_VALIDATION_AND_SCROLLING
32 #endif
33
34 #ifdef DEBUG_VALIDATION_AND_SCROLLING
35 #define DV(x) (x)
36 #else
37 #define DV(x)
38 #endif
39
40 #include <gtk/gtktextbuffer.h>
41 #include <gtk/gtktexttag.h>
42 #include <gtk/gtktextmark.h>
43 #include <gtk/gtktextchild.h>
44 #include <gtk/gtktextsegment.h>
45 #include <gtk/gtktextiter.h>
46
47 G_BEGIN_DECLS
48
49 GtkTextBTree  *_gtk_text_btree_new        (GtkTextTagTable *table,
50                                            GtkTextBuffer   *buffer);
51 void           _gtk_text_btree_ref        (GtkTextBTree    *tree);
52 void           _gtk_text_btree_unref      (GtkTextBTree    *tree);
53 GtkTextBuffer *_gtk_text_btree_get_buffer (GtkTextBTree    *tree);
54
55
56 guint _gtk_text_btree_get_chars_changed_stamp    (GtkTextBTree *tree);
57 guint _gtk_text_btree_get_segments_changed_stamp (GtkTextBTree *tree);
58 void  _gtk_text_btree_segments_changed           (GtkTextBTree *tree);
59
60 gboolean _gtk_text_btree_is_end (GtkTextBTree       *tree,
61                                  GtkTextLine        *line,
62                                  GtkTextLineSegment *seg,
63                                  int                 byte_index,
64                                  int                 char_offset);
65
66 /* Indexable segment mutation */
67
68 void _gtk_text_btree_delete        (GtkTextIter *start,
69                                     GtkTextIter *end);
70 void _gtk_text_btree_insert        (GtkTextIter *iter,
71                                     const gchar *text,
72                                     gint         len);
73 void _gtk_text_btree_insert_pixbuf (GtkTextIter *iter,
74                                     GdkPixbuf   *pixbuf);
75
76 void _gtk_text_btree_insert_child_anchor (GtkTextIter        *iter,
77                                           GtkTextChildAnchor *anchor);
78
79 void _gtk_text_btree_unregister_child_anchor (GtkTextChildAnchor *anchor);
80
81 /* View stuff */
82 GtkTextLine *_gtk_text_btree_find_line_by_y    (GtkTextBTree      *tree,
83                                                 gpointer           view_id,
84                                                 gint               ypixel,
85                                                 gint              *line_top_y);
86 gint         _gtk_text_btree_find_line_top     (GtkTextBTree      *tree,
87                                                 GtkTextLine       *line,
88                                                 gpointer           view_id);
89 void         _gtk_text_btree_add_view          (GtkTextBTree      *tree,
90                                                 GtkTextLayout     *layout);
91 void         _gtk_text_btree_remove_view       (GtkTextBTree      *tree,
92                                                 gpointer           view_id);
93 void         _gtk_text_btree_invalidate_region (GtkTextBTree      *tree,
94                                                 const GtkTextIter *start,
95                                                 const GtkTextIter *end,
96                                                 gboolean           cursors_only);
97 void         _gtk_text_btree_get_view_size     (GtkTextBTree      *tree,
98                                                 gpointer           view_id,
99                                                 gint              *width,
100                                                 gint              *height);
101 gboolean     _gtk_text_btree_is_valid          (GtkTextBTree      *tree,
102                                                 gpointer           view_id);
103 gboolean     _gtk_text_btree_validate          (GtkTextBTree      *tree,
104                                                 gpointer           view_id,
105                                                 gint               max_pixels,
106                                                 gint              *y,
107                                                 gint              *old_height,
108                                                 gint              *new_height);
109 void         _gtk_text_btree_validate_line     (GtkTextBTree      *tree,
110                                                 GtkTextLine       *line,
111                                                 gpointer           view_id);
112
113 /* Tag */
114
115 void _gtk_text_btree_tag (const GtkTextIter *start,
116                           const GtkTextIter *end,
117                           GtkTextTag        *tag,
118                           gboolean           apply);
119
120 /* "Getters" */
121
122 GtkTextLine * _gtk_text_btree_get_line          (GtkTextBTree      *tree,
123                                                  gint               line_number,
124                                                  gint              *real_line_number);
125 GtkTextLine * _gtk_text_btree_get_line_no_last  (GtkTextBTree      *tree,
126                                                  gint               line_number,
127                                                  gint              *real_line_number);
128 GtkTextLine * _gtk_text_btree_get_end_iter_line (GtkTextBTree      *tree);
129 GtkTextLine * _gtk_text_btree_get_line_at_char  (GtkTextBTree      *tree,
130                                                  gint               char_index,
131                                                  gint              *line_start_index,
132                                                  gint              *real_char_index);
133 GtkTextTag**  _gtk_text_btree_get_tags          (const GtkTextIter *iter,
134                                                  gint              *num_tags);
135 gchar        *_gtk_text_btree_get_text          (const GtkTextIter *start,
136                                                  const GtkTextIter *end,
137                                                  gboolean           include_hidden,
138                                                  gboolean           include_nonchars);
139 gint          _gtk_text_btree_line_count        (GtkTextBTree      *tree);
140 gint          _gtk_text_btree_char_count        (GtkTextBTree      *tree);
141 gboolean      _gtk_text_btree_char_is_invisible (const GtkTextIter *iter);
142
143
144
145 /* Get iterators (these are implemented in gtktextiter.c) */
146 void     _gtk_text_btree_get_iter_at_char         (GtkTextBTree       *tree,
147                                                    GtkTextIter        *iter,
148                                                    gint                char_index);
149 void     _gtk_text_btree_get_iter_at_line_char    (GtkTextBTree       *tree,
150                                                    GtkTextIter        *iter,
151                                                    gint                line_number,
152                                                    gint                char_index);
153 void     _gtk_text_btree_get_iter_at_line_byte    (GtkTextBTree       *tree,
154                                                    GtkTextIter        *iter,
155                                                    gint                line_number,
156                                                    gint                byte_index);
157 gboolean _gtk_text_btree_get_iter_from_string     (GtkTextBTree       *tree,
158                                                    GtkTextIter        *iter,
159                                                    const gchar        *string);
160 gboolean _gtk_text_btree_get_iter_at_mark_name    (GtkTextBTree       *tree,
161                                                    GtkTextIter        *iter,
162                                                    const gchar        *mark_name);
163 void     _gtk_text_btree_get_iter_at_mark         (GtkTextBTree       *tree,
164                                                    GtkTextIter        *iter,
165                                                    GtkTextMark        *mark);
166 void     _gtk_text_btree_get_end_iter             (GtkTextBTree       *tree,
167                                                    GtkTextIter        *iter);
168 void     _gtk_text_btree_get_iter_at_line         (GtkTextBTree       *tree,
169                                                    GtkTextIter        *iter,
170                                                    GtkTextLine        *line,
171                                                    gint                byte_offset);
172 gboolean _gtk_text_btree_get_iter_at_first_toggle (GtkTextBTree       *tree,
173                                                    GtkTextIter        *iter,
174                                                    GtkTextTag         *tag);
175 gboolean _gtk_text_btree_get_iter_at_last_toggle  (GtkTextBTree       *tree,
176                                                    GtkTextIter        *iter,
177                                                    GtkTextTag         *tag);
178
179 void     _gtk_text_btree_get_iter_at_child_anchor  (GtkTextBTree       *tree,
180                                                     GtkTextIter        *iter,
181                                                     GtkTextChildAnchor *anchor);
182
183
184
185 /* Manipulate marks */
186 GtkTextMark        *_gtk_text_btree_set_mark                (GtkTextBTree       *tree,
187                                                              GtkTextMark         *existing_mark,
188                                                              const gchar        *name,
189                                                              gboolean            left_gravity,
190                                                              const GtkTextIter  *index,
191                                                              gboolean           should_exist);
192 void                _gtk_text_btree_remove_mark_by_name     (GtkTextBTree       *tree,
193                                                              const gchar        *name);
194 void                _gtk_text_btree_remove_mark             (GtkTextBTree       *tree,
195                                                              GtkTextMark        *segment);
196 gboolean            _gtk_text_btree_get_selection_bounds    (GtkTextBTree       *tree,
197                                                              GtkTextIter        *start,
198                                                              GtkTextIter        *end);
199 void                _gtk_text_btree_place_cursor            (GtkTextBTree       *tree,
200                                                              const GtkTextIter  *where);
201 void                _gtk_text_btree_select_range            (GtkTextBTree       *tree,
202                                                              const GtkTextIter  *ins,
203                                                              const GtkTextIter 
204 *bound);
205 gboolean            _gtk_text_btree_mark_is_insert          (GtkTextBTree       *tree,
206                                                              GtkTextMark        *segment);
207 gboolean            _gtk_text_btree_mark_is_selection_bound (GtkTextBTree       *tree,
208                                                              GtkTextMark        *segment);
209 GtkTextMark        *_gtk_text_btree_get_mark_by_name        (GtkTextBTree       *tree,
210                                                              const gchar        *name);
211 GtkTextLine *       _gtk_text_btree_first_could_contain_tag (GtkTextBTree       *tree,
212                                                              GtkTextTag         *tag);
213 GtkTextLine *       _gtk_text_btree_last_could_contain_tag  (GtkTextBTree       *tree,
214                                                              GtkTextTag         *tag);
215
216 /* Lines */
217
218 /* Chunk of data associated with a line; views can use this to store
219    info at the line. They should "subclass" the header struct here. */
220 struct _GtkTextLineData {
221   gpointer view_id;
222   GtkTextLineData *next;
223   gint height;
224   signed int width : 24;
225   guint valid : 8;              /* Actually a boolean */
226 };
227
228 /*
229  * The data structure below defines a single line of text (from newline
230  * to newline, not necessarily what appears on one line of the screen).
231  *
232  * You can consider this line a "paragraph" also
233  */
234
235 struct _GtkTextLine {
236   GtkTextBTreeNode *parent;             /* Pointer to parent node containing
237                                          * line. */
238   GtkTextLine *next;            /* Next in linked list of lines with
239                                  * same parent node in B-tree.  NULL
240                                  * means end of list. */
241   GtkTextLineSegment *segments; /* First in ordered list of segments
242                                  * that make up the line. */
243   GtkTextLineData *views;      /* data stored here by views */
244   guchar dir_strong;                /* BiDi algo dir of line */
245   guchar dir_propagated_back;       /* BiDi algo dir of next line */
246   guchar dir_propagated_forward;    /* BiDi algo dir of prev line */
247 };
248
249
250 gint                _gtk_text_line_get_number                 (GtkTextLine         *line);
251 gboolean            _gtk_text_line_char_has_tag               (GtkTextLine         *line,
252                                                                GtkTextBTree        *tree,
253                                                                gint                 char_in_line,
254                                                                GtkTextTag          *tag);
255 gboolean            _gtk_text_line_byte_has_tag               (GtkTextLine         *line,
256                                                                GtkTextBTree        *tree,
257                                                                gint                 byte_in_line,
258                                                                GtkTextTag          *tag);
259 gboolean            _gtk_text_line_is_last                    (GtkTextLine         *line,
260                                                                GtkTextBTree        *tree);
261 gboolean            _gtk_text_line_contains_end_iter          (GtkTextLine         *line,
262                                                                GtkTextBTree        *tree);
263 GtkTextLine *       _gtk_text_line_next                       (GtkTextLine         *line);
264 GtkTextLine *       _gtk_text_line_next_excluding_last        (GtkTextLine         *line);
265 GtkTextLine *       _gtk_text_line_previous                   (GtkTextLine         *line);
266 void                _gtk_text_line_add_data                   (GtkTextLine         *line,
267                                                                GtkTextLineData     *data);
268 gpointer            _gtk_text_line_remove_data                (GtkTextLine         *line,
269                                                                gpointer             view_id);
270 gpointer            _gtk_text_line_get_data                   (GtkTextLine         *line,
271                                                                gpointer             view_id);
272 void                _gtk_text_line_invalidate_wrap            (GtkTextLine         *line,
273                                                                GtkTextLineData     *ld);
274 gint                _gtk_text_line_char_count                 (GtkTextLine         *line);
275 gint                _gtk_text_line_byte_count                 (GtkTextLine         *line);
276 gint                _gtk_text_line_char_index                 (GtkTextLine         *line);
277 GtkTextLineSegment *_gtk_text_line_byte_to_segment            (GtkTextLine         *line,
278                                                                gint                 byte_offset,
279                                                                gint                *seg_offset);
280 GtkTextLineSegment *_gtk_text_line_char_to_segment            (GtkTextLine         *line,
281                                                                gint                 char_offset,
282                                                                gint                *seg_offset);
283 gboolean            _gtk_text_line_byte_locate                (GtkTextLine         *line,
284                                                                gint                 byte_offset,
285                                                                GtkTextLineSegment **segment,
286                                                                GtkTextLineSegment **any_segment,
287                                                                gint                *seg_byte_offset,
288                                                                gint                *line_byte_offset);
289 gboolean            _gtk_text_line_char_locate                (GtkTextLine         *line,
290                                                                gint                 char_offset,
291                                                                GtkTextLineSegment **segment,
292                                                                GtkTextLineSegment **any_segment,
293                                                                gint                *seg_char_offset,
294                                                                gint                *line_char_offset);
295 void                _gtk_text_line_byte_to_char_offsets       (GtkTextLine         *line,
296                                                                gint                 byte_offset,
297                                                                gint                *line_char_offset,
298                                                                gint                *seg_char_offset);
299 void                _gtk_text_line_char_to_byte_offsets       (GtkTextLine         *line,
300                                                                gint                 char_offset,
301                                                                gint                *line_byte_offset,
302                                                                gint                *seg_byte_offset);
303 GtkTextLineSegment *_gtk_text_line_byte_to_any_segment        (GtkTextLine         *line,
304                                                                gint                 byte_offset,
305                                                                gint                *seg_offset);
306 GtkTextLineSegment *_gtk_text_line_char_to_any_segment        (GtkTextLine         *line,
307                                                                gint                 char_offset,
308                                                                gint                *seg_offset);
309 gint                _gtk_text_line_byte_to_char               (GtkTextLine         *line,
310                                                                gint                 byte_offset);
311 gint                _gtk_text_line_char_to_byte               (GtkTextLine         *line,
312                                                                gint                 char_offset);
313 GtkTextLine    *    _gtk_text_line_next_could_contain_tag     (GtkTextLine         *line,
314                                                                GtkTextBTree        *tree,
315                                                                GtkTextTag          *tag);
316 GtkTextLine    *    _gtk_text_line_previous_could_contain_tag (GtkTextLine         *line,
317                                                                GtkTextBTree        *tree,
318                                                                GtkTextTag          *tag);
319
320 GtkTextLineData    *_gtk_text_line_data_new                   (GtkTextLayout     *layout,
321                                                                GtkTextLine       *line);
322
323 /* Debug */
324 void _gtk_text_btree_check (GtkTextBTree *tree);
325 void _gtk_text_btree_spew (GtkTextBTree *tree);
326 extern gboolean _gtk_text_view_debug_btree;
327
328 /* ignore, exported only for gtktextsegment.c */
329 void _gtk_toggle_segment_check_func (GtkTextLineSegment *segPtr,
330                                      GtkTextLine        *line);
331 void _gtk_change_node_toggle_count  (GtkTextBTreeNode   *node,
332                                      GtkTextTagInfo     *info,
333                                      gint                delta);
334
335 /* for gtktextmark.c */
336 void _gtk_text_btree_release_mark_segment (GtkTextBTree       *tree,
337                                            GtkTextLineSegment *segment);
338
339 /* for coordination with the tag table */
340 void _gtk_text_btree_notify_will_remove_tag (GtkTextBTree *tree,
341                                              GtkTextTag   *tag);
342
343 G_END_DECLS
344
345 #endif
346
347