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