File: | ctk/ctktextlayout.c |
Warning: | line 2523, column 13 Access to field 'next' results in a dereference of a null pointer (loaded from variable 'seg') |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* CTK - The GIMP Toolkit | |||
2 | * ctktextlayout.c - calculate the layout of the text | |||
3 | * | |||
4 | * Copyright (c) 1992-1994 The Regents of the University of California. | |||
5 | * Copyright (c) 1994-1997 Sun Microsystems, Inc. | |||
6 | * Copyright (c) 2000 Red Hat, Inc. | |||
7 | * Tk->Ctk port by Havoc Pennington | |||
8 | * Pango support by Owen Taylor | |||
9 | * | |||
10 | * This file can be used under your choice of two licenses, the LGPL | |||
11 | * and the original Tk license. | |||
12 | * | |||
13 | * LGPL: | |||
14 | * | |||
15 | * This library is free software; you can redistribute it and/or | |||
16 | * modify it under the terms of the GNU Lesser General Public | |||
17 | * License as published by the Free Software Foundation; either | |||
18 | * version 2 of the License, or (at your option) any later version. | |||
19 | * | |||
20 | * This library is distributed in the hope that it will be useful, | |||
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
23 | * Lesser General Public License for more details. | |||
24 | * | |||
25 | * You should have received a copy of the GNU Lesser General Public | |||
26 | * License along with this library. If not, see <http://www.gnu.org/licenses/>.Free | |||
27 | * | |||
28 | * Original Tk license: | |||
29 | * | |||
30 | * This software is copyrighted by the Regents of the University of | |||
31 | * California, Sun Microsystems, Inc., and other parties. The | |||
32 | * following terms apply to all files associated with the software | |||
33 | * unless explicitly disclaimed in individual files. | |||
34 | * | |||
35 | * The authors hereby grant permission to use, copy, modify, | |||
36 | * distribute, and license this software and its documentation for any | |||
37 | * purpose, provided that existing copyright notices are retained in | |||
38 | * all copies and that this notice is included verbatim in any | |||
39 | * distributions. No written agreement, license, or royalty fee is | |||
40 | * required for any of the authorized uses. Modifications to this | |||
41 | * software may be copyrighted by their authors and need not follow | |||
42 | * the licensing terms described here, provided that the new terms are | |||
43 | * clearly indicated on the first page of each file where they apply. | |||
44 | * | |||
45 | * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY | |||
46 | * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL | |||
47 | * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, | |||
48 | * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED | |||
49 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |||
50 | * | |||
51 | * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, | |||
52 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |||
53 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND | |||
54 | * NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, | |||
55 | * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE | |||
56 | * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |||
57 | * | |||
58 | * GOVERNMENT USE: If you are acquiring this software on behalf of the | |||
59 | * U.S. government, the Government shall have only "Restricted Rights" | |||
60 | * in the software and related documentation as defined in the Federal | |||
61 | * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you | |||
62 | * are acquiring the software on behalf of the Department of Defense, | |||
63 | * the software shall be classified as "Commercial Computer Software" | |||
64 | * and the Government shall have only "Restricted Rights" as defined | |||
65 | * in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the | |||
66 | * foregoing, the authors grant the U.S. Government and others acting | |||
67 | * in its behalf permission to use and distribute the software in | |||
68 | * accordance with the terms specified in this license. | |||
69 | * | |||
70 | */ | |||
71 | /* | |||
72 | * Modified by the CTK+ Team and others 1997-2000. See the AUTHORS | |||
73 | * file for a list of people on the CTK+ Team. See the ChangeLog | |||
74 | * files for a list of changes. These files are distributed with | |||
75 | * CTK+ at ftp://ftp.ctk.org/pub/ctk/. | |||
76 | */ | |||
77 | ||||
78 | #define CTK_TEXT_USE_INTERNAL_UNSUPPORTED_API | |||
79 | #include "config.h" | |||
80 | #include "ctkmarshalers.h" | |||
81 | #include "ctktextlayout.h" | |||
82 | #include "ctktextbtree.h" | |||
83 | #include "ctktextbufferprivate.h" | |||
84 | #include "ctktextiterprivate.h" | |||
85 | #include "ctktextattributesprivate.h" | |||
86 | #include "ctktextutil.h" | |||
87 | #include "ctkintl.h" | |||
88 | ||||
89 | #include <stdlib.h> | |||
90 | #include <string.h> | |||
91 | ||||
92 | #define CTK_TEXT_LAYOUT_GET_PRIVATE(o)((CtkTextLayoutPrivate *) ctk_text_layout_get_instance_private ((o))) ((CtkTextLayoutPrivate *) ctk_text_layout_get_instance_private ((o))) | |||
93 | ||||
94 | typedef struct _CtkTextLayoutPrivate CtkTextLayoutPrivate; | |||
95 | ||||
96 | struct _CtkTextLayoutPrivate | |||
97 | { | |||
98 | /* Cache the line that the cursor is positioned on, as the keyboard | |||
99 | direction only influences the direction of the cursor line. | |||
100 | */ | |||
101 | CtkTextLine *cursor_line; | |||
102 | }; | |||
103 | ||||
104 | static CtkTextLineData *ctk_text_layout_real_wrap (CtkTextLayout *layout, | |||
105 | CtkTextLine *line, | |||
106 | /* may be NULL */ | |||
107 | CtkTextLineData *line_data); | |||
108 | ||||
109 | static void ctk_text_layout_invalidated (CtkTextLayout *layout); | |||
110 | ||||
111 | static void ctk_text_layout_real_invalidate (CtkTextLayout *layout, | |||
112 | const CtkTextIter *start, | |||
113 | const CtkTextIter *end); | |||
114 | static void ctk_text_layout_real_invalidate_cursors(CtkTextLayout *layout, | |||
115 | const CtkTextIter *start, | |||
116 | const CtkTextIter *end); | |||
117 | static void ctk_text_layout_invalidate_cache (CtkTextLayout *layout, | |||
118 | CtkTextLine *line, | |||
119 | gboolean cursors_only); | |||
120 | static void ctk_text_layout_invalidate_cursor_line (CtkTextLayout *layout, | |||
121 | gboolean cursors_only); | |||
122 | static void ctk_text_layout_real_free_line_data (CtkTextLayout *layout, | |||
123 | CtkTextLine *line, | |||
124 | CtkTextLineData *line_data); | |||
125 | static void ctk_text_layout_emit_changed (CtkTextLayout *layout, | |||
126 | gint y, | |||
127 | gint old_height, | |||
128 | gint new_height); | |||
129 | ||||
130 | static void ctk_text_layout_invalidate_all (CtkTextLayout *layout); | |||
131 | ||||
132 | static PangoAttribute *ctk_text_attr_appearance_new (const CtkTextAppearance *appearance); | |||
133 | ||||
134 | static void ctk_text_layout_mark_set_handler (CtkTextBuffer *buffer, | |||
135 | const CtkTextIter *location, | |||
136 | CtkTextMark *mark, | |||
137 | gpointer data); | |||
138 | static void ctk_text_layout_buffer_insert_text (CtkTextBuffer *textbuffer, | |||
139 | CtkTextIter *iter, | |||
140 | gchar *str, | |||
141 | gint len, | |||
142 | gpointer data); | |||
143 | static void ctk_text_layout_buffer_delete_range (CtkTextBuffer *textbuffer, | |||
144 | CtkTextIter *start, | |||
145 | CtkTextIter *end, | |||
146 | gpointer data); | |||
147 | ||||
148 | static void ctk_text_layout_update_cursor_line (CtkTextLayout *layout); | |||
149 | ||||
150 | static void line_display_index_to_iter (CtkTextLayout *layout, | |||
151 | CtkTextLineDisplay *display, | |||
152 | CtkTextIter *iter, | |||
153 | gint index, | |||
154 | gint trailing); | |||
155 | ||||
156 | static gint line_display_iter_to_index (CtkTextLayout *layout, | |||
157 | CtkTextLineDisplay *display, | |||
158 | const CtkTextIter *iter); | |||
159 | ||||
160 | enum { | |||
161 | INVALIDATED, | |||
162 | CHANGED, | |||
163 | ALLOCATE_CHILD, | |||
164 | LAST_SIGNAL | |||
165 | }; | |||
166 | ||||
167 | enum { | |||
168 | ARG_0, | |||
169 | LAST_ARG | |||
170 | }; | |||
171 | ||||
172 | #define PIXEL_BOUND(d)(((d) + 1024 - 1) / 1024) (((d) + PANGO_SCALE1024 - 1) / PANGO_SCALE1024) | |||
173 | ||||
174 | static guint signals[LAST_SIGNAL] = { 0 }; | |||
175 | ||||
176 | PangoAttrType ctk_text_attr_appearance_type = 0; | |||
177 | ||||
178 | G_DEFINE_TYPE_WITH_PRIVATE (CtkTextLayout, ctk_text_layout, G_TYPE_OBJECT)static void ctk_text_layout_init (CtkTextLayout *self); static void ctk_text_layout_class_init (CtkTextLayoutClass *klass); static GType ctk_text_layout_get_type_once (void); static gpointer ctk_text_layout_parent_class = ((void*)0); static gint CtkTextLayout_private_offset ; static void ctk_text_layout_class_intern_init (gpointer klass ) { ctk_text_layout_parent_class = g_type_class_peek_parent ( klass); if (CtkTextLayout_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkTextLayout_private_offset); ctk_text_layout_class_init ((CtkTextLayoutClass*) klass); } __attribute__ ((__unused__) ) static inline gpointer ctk_text_layout_get_instance_private (CtkTextLayout *self) { return (((gpointer) ((guint8*) (self ) + (glong) (CtkTextLayout_private_offset)))); } GType ctk_text_layout_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); (void) ( 0 ? (gpointer) * (&static_g_define_type_id) : ((void*)0)) ; (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = ctk_text_layout_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType ctk_text_layout_get_type_once (void ) { GType g_define_type_id = g_type_register_static_simple (( (GType) ((20) << (2))), g_intern_static_string ("CtkTextLayout" ), sizeof (CtkTextLayoutClass), (GClassInitFunc)(void (*)(void )) ctk_text_layout_class_intern_init, sizeof (CtkTextLayout), (GInstanceInitFunc)(void (*)(void)) ctk_text_layout_init, (GTypeFlags ) 0); { {{ CtkTextLayout_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (CtkTextLayoutPrivate)); };} } return g_define_type_id; } | |||
179 | ||||
180 | static void | |||
181 | ctk_text_layout_dispose (GObject *object) | |||
182 | { | |||
183 | CtkTextLayout *layout; | |||
184 | ||||
185 | layout = CTK_TEXT_LAYOUT (object)((((CtkTextLayout*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_text_layout_get_type ())))))); | |||
186 | ||||
187 | ctk_text_layout_set_buffer (layout, NULL((void*)0)); | |||
188 | ||||
189 | if (layout->default_style != NULL((void*)0)) | |||
190 | { | |||
191 | ctk_text_attributes_unref (layout->default_style); | |||
192 | layout->default_style = NULL((void*)0); | |||
193 | } | |||
194 | ||||
195 | g_clear_object (&layout->ltr_context)do { _Static_assert (sizeof *((&layout->ltr_context)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&layout->ltr_context))) _pp = ((&layout->ltr_context )); __typeof__ (*((&layout->ltr_context))) _ptr = *_pp ; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
196 | g_clear_object (&layout->rtl_context)do { _Static_assert (sizeof *((&layout->rtl_context)) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (((&layout->rtl_context))) _pp = ((&layout->rtl_context )); __typeof__ (*((&layout->rtl_context))) _ptr = *_pp ; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); | |||
197 | ||||
198 | if (layout->one_display_cache) | |||
199 | { | |||
200 | CtkTextLineDisplay *tmp_display = layout->one_display_cache; | |||
201 | layout->one_display_cache = NULL((void*)0); | |||
202 | ctk_text_layout_free_line_display (layout, tmp_display); | |||
203 | } | |||
204 | ||||
205 | if (layout->preedit_attrs != NULL((void*)0)) | |||
206 | { | |||
207 | pango_attr_list_unref (layout->preedit_attrs); | |||
208 | layout->preedit_attrs = NULL((void*)0); | |||
209 | } | |||
210 | ||||
211 | G_OBJECT_CLASS (ctk_text_layout_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_text_layout_parent_class)), (((GType) ((20) << (2))))))))->dispose (object); | |||
212 | } | |||
213 | ||||
214 | static void | |||
215 | ctk_text_layout_finalize (GObject *object) | |||
216 | { | |||
217 | CtkTextLayout *layout; | |||
218 | ||||
219 | layout = CTK_TEXT_LAYOUT (object)((((CtkTextLayout*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_text_layout_get_type ())))))); | |||
220 | ||||
221 | g_free (layout->preedit_string); | |||
222 | ||||
223 | G_OBJECT_CLASS (ctk_text_layout_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_text_layout_parent_class)), (((GType) ((20) << (2))))))))->finalize (object); | |||
224 | } | |||
225 | ||||
226 | static void | |||
227 | ctk_text_layout_class_init (CtkTextLayoutClass *klass) | |||
228 | { | |||
229 | GObjectClass *object_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), (((GType) ((20) << (2)))))))); | |||
230 | ||||
231 | object_class->dispose = ctk_text_layout_dispose; | |||
232 | object_class->finalize = ctk_text_layout_finalize; | |||
233 | ||||
234 | klass->wrap = ctk_text_layout_real_wrap; | |||
235 | klass->invalidate = ctk_text_layout_real_invalidate; | |||
236 | klass->invalidate_cursors = ctk_text_layout_real_invalidate_cursors; | |||
237 | klass->free_line_data = ctk_text_layout_real_free_line_data; | |||
238 | ||||
239 | signals[INVALIDATED] = | |||
240 | g_signal_new (I_("invalidated")g_intern_static_string ("invalidated"), | |||
241 | G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)), | |||
242 | G_SIGNAL_RUN_LAST, | |||
243 | G_STRUCT_OFFSET (CtkTextLayoutClass, invalidated)((glong) __builtin_offsetof(CtkTextLayoutClass, invalidated)), | |||
244 | NULL((void*)0), NULL((void*)0), | |||
245 | NULL((void*)0), | |||
246 | G_TYPE_NONE((GType) ((1) << (2))), | |||
247 | 0); | |||
248 | ||||
249 | signals[CHANGED] = | |||
250 | g_signal_new (I_("changed")g_intern_static_string ("changed"), | |||
251 | G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)), | |||
252 | G_SIGNAL_RUN_LAST, | |||
253 | G_STRUCT_OFFSET (CtkTextLayoutClass, changed)((glong) __builtin_offsetof(CtkTextLayoutClass, changed)), | |||
254 | NULL((void*)0), NULL((void*)0), | |||
255 | _ctk_marshal_VOID__INT_INT_INT, | |||
256 | G_TYPE_NONE((GType) ((1) << (2))), | |||
257 | 3, | |||
258 | G_TYPE_INT((GType) ((6) << (2))), | |||
259 | G_TYPE_INT((GType) ((6) << (2))), | |||
260 | G_TYPE_INT((GType) ((6) << (2)))); | |||
261 | g_signal_set_va_marshaller (signals[CHANGED], G_TYPE_FROM_CLASS (klass)(((GTypeClass*) (klass))->g_type), | |||
262 | _ctk_marshal_VOID__INT_INT_INTv); | |||
263 | ||||
264 | signals[ALLOCATE_CHILD] = | |||
265 | g_signal_new (I_("allocate-child")g_intern_static_string ("allocate-child"), | |||
266 | G_OBJECT_CLASS_TYPE (object_class)((((GTypeClass*) (object_class))->g_type)), | |||
267 | G_SIGNAL_RUN_LAST, | |||
268 | G_STRUCT_OFFSET (CtkTextLayoutClass, allocate_child)((glong) __builtin_offsetof(CtkTextLayoutClass, allocate_child )), | |||
269 | NULL((void*)0), NULL((void*)0), | |||
270 | _ctk_marshal_VOID__OBJECT_INT_INT, | |||
271 | G_TYPE_NONE((GType) ((1) << (2))), | |||
272 | 3, | |||
273 | G_TYPE_OBJECT((GType) ((20) << (2))), | |||
274 | G_TYPE_INT((GType) ((6) << (2))), | |||
275 | G_TYPE_INT((GType) ((6) << (2)))); | |||
276 | } | |||
277 | ||||
278 | static void | |||
279 | ctk_text_layout_init (CtkTextLayout *text_layout) | |||
280 | { | |||
281 | text_layout->cursor_visible = TRUE(!(0)); | |||
282 | } | |||
283 | ||||
284 | CtkTextLayout* | |||
285 | ctk_text_layout_new (void) | |||
286 | { | |||
287 | return g_object_new (CTK_TYPE_TEXT_LAYOUT(ctk_text_layout_get_type ()), NULL((void*)0)); | |||
288 | } | |||
289 | ||||
290 | static void | |||
291 | free_style_cache (CtkTextLayout *text_layout) | |||
292 | { | |||
293 | if (text_layout->one_style_cache) | |||
294 | { | |||
295 | ctk_text_attributes_unref (text_layout->one_style_cache); | |||
296 | text_layout->one_style_cache = NULL((void*)0); | |||
297 | } | |||
298 | } | |||
299 | ||||
300 | /** | |||
301 | * ctk_text_layout_set_buffer: | |||
302 | * @buffer: (allow-none): | |||
303 | */ | |||
304 | void | |||
305 | ctk_text_layout_set_buffer (CtkTextLayout *layout, | |||
306 | CtkTextBuffer *buffer) | |||
307 | { | |||
308 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
309 | g_return_if_fail (buffer == NULL || CTK_IS_TEXT_BUFFER (buffer))do { if ((buffer == ((void*)0) || (((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ((buffer)); GType __t = ((ctk_text_buffer_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "buffer == NULL || CTK_IS_TEXT_BUFFER (buffer)" ); return; } } while (0); | |||
310 | ||||
311 | if (layout->buffer == buffer) | |||
312 | return; | |||
313 | ||||
314 | free_style_cache (layout); | |||
315 | ||||
316 | if (layout->buffer) | |||
317 | { | |||
318 | _ctk_text_btree_remove_view (_ctk_text_buffer_get_btree (layout->buffer), | |||
319 | layout); | |||
320 | ||||
321 | g_signal_handlers_disconnect_by_func (layout->buffer,g_signal_handlers_disconnect_matched ((layout->buffer), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (((GCallback) (ctk_text_layout_mark_set_handler))), (layout )) | |||
322 | G_CALLBACK (ctk_text_layout_mark_set_handler),g_signal_handlers_disconnect_matched ((layout->buffer), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (((GCallback) (ctk_text_layout_mark_set_handler))), (layout )) | |||
323 | layout)g_signal_handlers_disconnect_matched ((layout->buffer), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (((GCallback) (ctk_text_layout_mark_set_handler))), (layout )); | |||
324 | g_signal_handlers_disconnect_by_func (layout->buffer,g_signal_handlers_disconnect_matched ((layout->buffer), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (((GCallback) (ctk_text_layout_buffer_insert_text))), (layout )) | |||
325 | G_CALLBACK (ctk_text_layout_buffer_insert_text),g_signal_handlers_disconnect_matched ((layout->buffer), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (((GCallback) (ctk_text_layout_buffer_insert_text))), (layout )) | |||
326 | layout)g_signal_handlers_disconnect_matched ((layout->buffer), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (((GCallback) (ctk_text_layout_buffer_insert_text))), (layout )); | |||
327 | g_signal_handlers_disconnect_by_func (layout->buffer,g_signal_handlers_disconnect_matched ((layout->buffer), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (((GCallback) (ctk_text_layout_buffer_delete_range))), (layout )) | |||
328 | G_CALLBACK (ctk_text_layout_buffer_delete_range),g_signal_handlers_disconnect_matched ((layout->buffer), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (((GCallback) (ctk_text_layout_buffer_delete_range))), (layout )) | |||
329 | layout)g_signal_handlers_disconnect_matched ((layout->buffer), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (((GCallback) (ctk_text_layout_buffer_delete_range))), (layout )); | |||
330 | ||||
331 | g_object_unref (layout->buffer); | |||
332 | layout->buffer = NULL((void*)0); | |||
333 | } | |||
334 | ||||
335 | if (buffer) | |||
336 | { | |||
337 | layout->buffer = buffer; | |||
338 | ||||
339 | g_object_ref (buffer)((__typeof__ (buffer)) (g_object_ref) (buffer)); | |||
340 | ||||
341 | _ctk_text_btree_add_view (_ctk_text_buffer_get_btree (buffer), layout); | |||
342 | ||||
343 | /* Bind to all signals that move the insert mark. */ | |||
344 | g_signal_connect_after (layout->buffer, "mark-set",g_signal_connect_data ((layout->buffer), ("mark-set"), ((( GCallback) (ctk_text_layout_mark_set_handler))), (layout), (( void*)0), G_CONNECT_AFTER) | |||
345 | G_CALLBACK (ctk_text_layout_mark_set_handler), layout)g_signal_connect_data ((layout->buffer), ("mark-set"), ((( GCallback) (ctk_text_layout_mark_set_handler))), (layout), (( void*)0), G_CONNECT_AFTER); | |||
346 | g_signal_connect_after (layout->buffer, "insert-text",g_signal_connect_data ((layout->buffer), ("insert-text"), ( ((GCallback) (ctk_text_layout_buffer_insert_text))), (layout) , ((void*)0), G_CONNECT_AFTER) | |||
347 | G_CALLBACK (ctk_text_layout_buffer_insert_text), layout)g_signal_connect_data ((layout->buffer), ("insert-text"), ( ((GCallback) (ctk_text_layout_buffer_insert_text))), (layout) , ((void*)0), G_CONNECT_AFTER); | |||
348 | g_signal_connect_after (layout->buffer, "delete-range",g_signal_connect_data ((layout->buffer), ("delete-range"), (((GCallback) (ctk_text_layout_buffer_delete_range))), (layout ), ((void*)0), G_CONNECT_AFTER) | |||
349 | G_CALLBACK (ctk_text_layout_buffer_delete_range), layout)g_signal_connect_data ((layout->buffer), ("delete-range"), (((GCallback) (ctk_text_layout_buffer_delete_range))), (layout ), ((void*)0), G_CONNECT_AFTER); | |||
350 | ||||
351 | ctk_text_layout_update_cursor_line (layout); | |||
352 | } | |||
353 | } | |||
354 | ||||
355 | void | |||
356 | ctk_text_layout_default_style_changed (CtkTextLayout *layout) | |||
357 | { | |||
358 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
359 | ||||
360 | DV (g_print ("invalidating all due to default style change (%s)\n", G_STRLOC)); | |||
361 | ctk_text_layout_invalidate_all (layout); | |||
362 | } | |||
363 | ||||
364 | void | |||
365 | ctk_text_layout_set_default_style (CtkTextLayout *layout, | |||
366 | CtkTextAttributes *values) | |||
367 | { | |||
368 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
369 | g_return_if_fail (values != NULL)do { if ((values != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "values != NULL"); return ; } } while (0); | |||
370 | ||||
371 | if (values == layout->default_style) | |||
372 | return; | |||
373 | ||||
374 | ctk_text_attributes_ref (values); | |||
375 | ||||
376 | if (layout->default_style) | |||
377 | ctk_text_attributes_unref (layout->default_style); | |||
378 | ||||
379 | layout->default_style = values; | |||
380 | ||||
381 | ctk_text_layout_default_style_changed (layout); | |||
382 | } | |||
383 | ||||
384 | void | |||
385 | ctk_text_layout_set_contexts (CtkTextLayout *layout, | |||
386 | PangoContext *ltr_context, | |||
387 | PangoContext *rtl_context) | |||
388 | { | |||
389 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
390 | ||||
391 | if (layout->ltr_context != ltr_context) | |||
392 | { | |||
393 | if (layout->ltr_context) | |||
394 | g_object_unref (layout->ltr_context); | |||
395 | ||||
396 | layout->ltr_context = ltr_context; | |||
397 | g_object_ref (layout->ltr_context)((__typeof__ (layout->ltr_context)) (g_object_ref) (layout ->ltr_context)); | |||
398 | } | |||
399 | ||||
400 | if (layout->rtl_context != rtl_context) | |||
401 | { | |||
402 | if (layout->rtl_context) | |||
403 | g_object_unref (layout->rtl_context); | |||
404 | ||||
405 | layout->rtl_context = rtl_context; | |||
406 | g_object_ref (layout->rtl_context)((__typeof__ (layout->rtl_context)) (g_object_ref) (layout ->rtl_context)); | |||
407 | } | |||
408 | ||||
409 | DV (g_print ("invalidating all due to new pango contexts (%s)\n", G_STRLOC)); | |||
410 | ctk_text_layout_invalidate_all (layout); | |||
411 | } | |||
412 | ||||
413 | /** | |||
414 | * ctk_text_layout_set_overwrite_mode: | |||
415 | * @layout: a #CtkTextLayout | |||
416 | * @overwrite: overwrite mode | |||
417 | * | |||
418 | * Sets overwrite mode | |||
419 | */ | |||
420 | void | |||
421 | ctk_text_layout_set_overwrite_mode (CtkTextLayout *layout, | |||
422 | gboolean overwrite) | |||
423 | { | |||
424 | overwrite = overwrite != 0; | |||
425 | if (overwrite != layout->overwrite_mode) | |||
426 | { | |||
427 | layout->overwrite_mode = overwrite; | |||
428 | ctk_text_layout_invalidate_cursor_line (layout, TRUE(!(0))); | |||
429 | } | |||
430 | } | |||
431 | ||||
432 | /** | |||
433 | * ctk_text_layout_set_cursor_direction: | |||
434 | * @direction: the new direction(s) for which to draw cursors. | |||
435 | * %CTK_TEXT_DIR_NONE means draw cursors for both | |||
436 | * left-to-right insertion and right-to-left insertion. | |||
437 | * (The two cursors will be visually distinguished.) | |||
438 | * | |||
439 | * Sets which text directions (left-to-right and/or right-to-left) for | |||
440 | * which cursors will be drawn for the insertion point. The visual | |||
441 | * point at which new text is inserted depends on whether the new | |||
442 | * text is right-to-left or left-to-right, so it may be desired to | |||
443 | * make the drawn position of the cursor depend on the keyboard state. | |||
444 | */ | |||
445 | void | |||
446 | ctk_text_layout_set_cursor_direction (CtkTextLayout *layout, | |||
447 | CtkTextDirection direction) | |||
448 | { | |||
449 | if (direction != layout->cursor_direction) | |||
450 | { | |||
451 | layout->cursor_direction = direction; | |||
452 | ctk_text_layout_invalidate_cursor_line (layout, TRUE(!(0))); | |||
453 | } | |||
454 | } | |||
455 | ||||
456 | /** | |||
457 | * ctk_text_layout_set_keyboard_direction: | |||
458 | * @keyboard_dir: the current direction of the keyboard. | |||
459 | * | |||
460 | * Sets the keyboard direction; this is used as for the bidirectional | |||
461 | * base direction for the line with the cursor if the line contains | |||
462 | * only neutral characters. | |||
463 | */ | |||
464 | void | |||
465 | ctk_text_layout_set_keyboard_direction (CtkTextLayout *layout, | |||
466 | CtkTextDirection keyboard_dir) | |||
467 | { | |||
468 | if (keyboard_dir != layout->keyboard_direction) | |||
469 | { | |||
470 | layout->keyboard_direction = keyboard_dir; | |||
471 | ctk_text_layout_invalidate_cursor_line (layout, TRUE(!(0))); | |||
472 | } | |||
473 | } | |||
474 | ||||
475 | /** | |||
476 | * ctk_text_layout_get_buffer: | |||
477 | * @layout: a #CtkTextLayout | |||
478 | * | |||
479 | * Gets the text buffer used by the layout. See | |||
480 | * ctk_text_layout_set_buffer(). | |||
481 | * | |||
482 | * Returns: the text buffer used by the layout. | |||
483 | */ | |||
484 | CtkTextBuffer * | |||
485 | ctk_text_layout_get_buffer (CtkTextLayout *layout) | |||
486 | { | |||
487 | g_return_val_if_fail (CTK_IS_TEXT_LAYOUT (layout), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return (((void*)0)); } } while (0); | |||
488 | ||||
489 | return layout->buffer; | |||
490 | } | |||
491 | ||||
492 | void | |||
493 | ctk_text_layout_set_screen_width (CtkTextLayout *layout, gint width) | |||
494 | { | |||
495 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
496 | g_return_if_fail (width >= 0)do { if ((width >= 0)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "width >= 0"); return ; } } while (0); | |||
497 | g_return_if_fail (layout->wrap_loop_count == 0)do { if ((layout->wrap_loop_count == 0)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "layout->wrap_loop_count == 0" ); return; } } while (0); | |||
498 | ||||
499 | if (layout->screen_width == width) | |||
500 | return; | |||
501 | ||||
502 | layout->screen_width = width; | |||
503 | ||||
504 | DV (g_print ("invalidating all due to new screen width (%s)\n", G_STRLOC)); | |||
505 | ctk_text_layout_invalidate_all (layout); | |||
506 | } | |||
507 | ||||
508 | /** | |||
509 | * ctk_text_layout_set_cursor_visible: | |||
510 | * @layout: a #CtkTextLayout | |||
511 | * @cursor_visible: If %FALSE, then the insertion cursor will not | |||
512 | * be shown, even if the text is editable. | |||
513 | * | |||
514 | * Sets whether the insertion cursor should be shown. Generally, | |||
515 | * widgets using #CtkTextLayout will hide the cursor when the | |||
516 | * widget does not have the input focus. | |||
517 | */ | |||
518 | void | |||
519 | ctk_text_layout_set_cursor_visible (CtkTextLayout *layout, | |||
520 | gboolean cursor_visible) | |||
521 | { | |||
522 | cursor_visible = (cursor_visible != FALSE(0)); | |||
523 | ||||
524 | if (layout->cursor_visible != cursor_visible) | |||
525 | { | |||
526 | CtkTextIter iter; | |||
527 | gint y, height; | |||
528 | ||||
529 | layout->cursor_visible = cursor_visible; | |||
530 | ||||
531 | /* Now queue a redraw on the paragraph containing the cursor | |||
532 | */ | |||
533 | ctk_text_buffer_get_iter_at_mark (layout->buffer, &iter, | |||
534 | ctk_text_buffer_get_insert (layout->buffer)); | |||
535 | ||||
536 | ctk_text_layout_get_line_yrange (layout, &iter, &y, &height); | |||
537 | ctk_text_layout_emit_changed (layout, y, height, height); | |||
538 | ||||
539 | ctk_text_layout_invalidate_cache (layout, _ctk_text_iter_get_text_line (&iter), TRUE(!(0))); | |||
540 | } | |||
541 | } | |||
542 | ||||
543 | /** | |||
544 | * ctk_text_layout_get_cursor_visible: | |||
545 | * @layout: a #CtkTextLayout | |||
546 | * | |||
547 | * Returns whether the insertion cursor will be shown. | |||
548 | * | |||
549 | * Returns: if %FALSE, the insertion cursor will not be | |||
550 | * shown, even if the text is editable. | |||
551 | */ | |||
552 | gboolean | |||
553 | ctk_text_layout_get_cursor_visible (CtkTextLayout *layout) | |||
554 | { | |||
555 | return layout->cursor_visible; | |||
556 | } | |||
557 | ||||
558 | /** | |||
559 | * ctk_text_layout_set_preedit_string: | |||
560 | * @layout: a #PangoLayout | |||
561 | * @preedit_string: a string to display at the insertion point | |||
562 | * @preedit_attrs: a #PangoAttrList of attributes that apply to @preedit_string | |||
563 | * @cursor_pos: position of cursor within preedit string in chars | |||
564 | * | |||
565 | * Set the preedit string and attributes. The preedit string is a | |||
566 | * string showing text that is currently being edited and not | |||
567 | * yet committed into the buffer. | |||
568 | */ | |||
569 | void | |||
570 | ctk_text_layout_set_preedit_string (CtkTextLayout *layout, | |||
571 | const gchar *preedit_string, | |||
572 | PangoAttrList *preedit_attrs, | |||
573 | gint cursor_pos) | |||
574 | { | |||
575 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
576 | g_return_if_fail (preedit_attrs != NULL || preedit_string == NULL)do { if ((preedit_attrs != ((void*)0) || preedit_string == (( void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "preedit_attrs != NULL || preedit_string == NULL" ); return; } } while (0); | |||
577 | ||||
578 | g_free (layout->preedit_string); | |||
579 | ||||
580 | if (layout->preedit_attrs) | |||
581 | pango_attr_list_unref (layout->preedit_attrs); | |||
582 | ||||
583 | if (preedit_string) | |||
584 | { | |||
585 | layout->preedit_string = g_strdup (preedit_string)g_strdup_inline (preedit_string); | |||
586 | layout->preedit_len = strlen (layout->preedit_string); | |||
587 | pango_attr_list_ref (preedit_attrs); | |||
588 | layout->preedit_attrs = preedit_attrs; | |||
589 | ||||
590 | cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (layout->preedit_string, -1))(((cursor_pos) > (g_utf8_strlen (layout->preedit_string , -1))) ? (g_utf8_strlen (layout->preedit_string, -1)) : ( ((cursor_pos) < (0)) ? (0) : (cursor_pos))); | |||
591 | layout->preedit_cursor = g_utf8_offset_to_pointer (layout->preedit_string, cursor_pos) - layout->preedit_string; | |||
592 | } | |||
593 | else | |||
594 | { | |||
595 | layout->preedit_string = NULL((void*)0); | |||
596 | layout->preedit_len = 0; | |||
597 | layout->preedit_attrs = NULL((void*)0); | |||
598 | layout->preedit_cursor = 0; | |||
599 | } | |||
600 | ||||
601 | ctk_text_layout_invalidate_cursor_line (layout, FALSE(0)); | |||
602 | } | |||
603 | ||||
604 | void | |||
605 | ctk_text_layout_get_size (CtkTextLayout *layout, | |||
606 | gint *width, | |||
607 | gint *height) | |||
608 | { | |||
609 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
610 | ||||
611 | if (width) | |||
612 | *width = layout->width; | |||
613 | ||||
614 | if (height) | |||
615 | *height = layout->height; | |||
616 | } | |||
617 | ||||
618 | static void | |||
619 | ctk_text_layout_invalidated (CtkTextLayout *layout) | |||
620 | { | |||
621 | g_signal_emit (layout, signals[INVALIDATED], 0); | |||
622 | } | |||
623 | ||||
624 | static void | |||
625 | ctk_text_layout_emit_changed (CtkTextLayout *layout, | |||
626 | gint y, | |||
627 | gint old_height, | |||
628 | gint new_height) | |||
629 | { | |||
630 | g_signal_emit (layout, signals[CHANGED], 0, y, old_height, new_height); | |||
631 | } | |||
632 | ||||
633 | static void | |||
634 | text_layout_changed (CtkTextLayout *layout, | |||
635 | gint y, | |||
636 | gint old_height, | |||
637 | gint new_height, | |||
638 | gboolean cursors_only) | |||
639 | { | |||
640 | /* Check if the range intersects our cached line display, | |||
641 | * and invalidate the cached line if so. | |||
642 | */ | |||
643 | if (layout->one_display_cache) | |||
644 | { | |||
645 | CtkTextLine *line = layout->one_display_cache->line; | |||
646 | gint cache_y = _ctk_text_btree_find_line_top (_ctk_text_buffer_get_btree (layout->buffer), | |||
647 | line, layout); | |||
648 | gint cache_height = layout->one_display_cache->height; | |||
649 | ||||
650 | if (cache_y + cache_height > y && cache_y < y + old_height) | |||
651 | ctk_text_layout_invalidate_cache (layout, line, cursors_only); | |||
652 | } | |||
653 | ||||
654 | ctk_text_layout_emit_changed (layout, y, old_height, new_height); | |||
655 | } | |||
656 | ||||
657 | void | |||
658 | ctk_text_layout_changed (CtkTextLayout *layout, | |||
659 | gint y, | |||
660 | gint old_height, | |||
661 | gint new_height) | |||
662 | { | |||
663 | text_layout_changed (layout, y, old_height, new_height, FALSE(0)); | |||
664 | } | |||
665 | ||||
666 | void | |||
667 | ctk_text_layout_cursors_changed (CtkTextLayout *layout, | |||
668 | gint y, | |||
669 | gint old_height, | |||
670 | gint new_height) | |||
671 | { | |||
672 | text_layout_changed (layout, y, old_height, new_height, TRUE(!(0))); | |||
673 | } | |||
674 | ||||
675 | void | |||
676 | ctk_text_layout_free_line_data (CtkTextLayout *layout, | |||
677 | CtkTextLine *line, | |||
678 | CtkTextLineData *line_data) | |||
679 | { | |||
680 | CTK_TEXT_LAYOUT_GET_CLASS (layout)((((CtkTextLayoutClass*) (((GTypeInstance*) ((layout)))->g_class ))))->free_line_data (layout, line, line_data); | |||
681 | } | |||
682 | ||||
683 | void | |||
684 | ctk_text_layout_invalidate (CtkTextLayout *layout, | |||
685 | const CtkTextIter *start_index, | |||
686 | const CtkTextIter *end_index) | |||
687 | { | |||
688 | CTK_TEXT_LAYOUT_GET_CLASS (layout)((((CtkTextLayoutClass*) (((GTypeInstance*) ((layout)))->g_class ))))->invalidate (layout, start_index, end_index); | |||
689 | } | |||
690 | ||||
691 | void | |||
692 | ctk_text_layout_invalidate_cursors (CtkTextLayout *layout, | |||
693 | const CtkTextIter *start_index, | |||
694 | const CtkTextIter *end_index) | |||
695 | { | |||
696 | CTK_TEXT_LAYOUT_GET_CLASS (layout)((((CtkTextLayoutClass*) (((GTypeInstance*) ((layout)))->g_class ))))->invalidate_cursors (layout, start_index, end_index); | |||
697 | } | |||
698 | ||||
699 | CtkTextLineData* | |||
700 | ctk_text_layout_wrap (CtkTextLayout *layout, | |||
701 | CtkTextLine *line, | |||
702 | /* may be NULL */ | |||
703 | CtkTextLineData *line_data) | |||
704 | { | |||
705 | return CTK_TEXT_LAYOUT_GET_CLASS (layout)((((CtkTextLayoutClass*) (((GTypeInstance*) ((layout)))->g_class ))))->wrap (layout, line, line_data); | |||
706 | } | |||
707 | ||||
708 | ||||
709 | /** | |||
710 | * ctk_text_layout_get_lines: | |||
711 | * | |||
712 | * Returns: (element-type CtkTextLine) (transfer container): | |||
713 | */ | |||
714 | GSList* | |||
715 | ctk_text_layout_get_lines (CtkTextLayout *layout, | |||
716 | /* [top_y, bottom_y) */ | |||
717 | gint top_y, | |||
718 | gint bottom_y, | |||
719 | gint *first_line_y) | |||
720 | { | |||
721 | CtkTextLine *first_btree_line; | |||
722 | CtkTextLine *last_btree_line; | |||
723 | CtkTextLine *line; | |||
724 | GSList *retval; | |||
725 | ||||
726 | g_return_val_if_fail (CTK_IS_TEXT_LAYOUT (layout), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return (((void*)0)); } } while (0); | |||
727 | g_return_val_if_fail (bottom_y > top_y, NULL)do { if ((bottom_y > top_y)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "bottom_y > top_y"); return (((void*)0)); } } while (0); | |||
728 | ||||
729 | retval = NULL((void*)0); | |||
730 | ||||
731 | first_btree_line = | |||
732 | _ctk_text_btree_find_line_by_y (_ctk_text_buffer_get_btree (layout->buffer), | |||
733 | layout, top_y, first_line_y); | |||
734 | if (first_btree_line == NULL((void*)0)) | |||
735 | { | |||
736 | /* off the bottom */ | |||
737 | return NULL((void*)0); | |||
738 | } | |||
739 | ||||
740 | /* -1 since bottom_y is one past */ | |||
741 | last_btree_line = | |||
742 | _ctk_text_btree_find_line_by_y (_ctk_text_buffer_get_btree (layout->buffer), | |||
743 | layout, bottom_y - 1, NULL((void*)0)); | |||
744 | ||||
745 | if (!last_btree_line) | |||
746 | last_btree_line = | |||
747 | _ctk_text_btree_get_end_iter_line (_ctk_text_buffer_get_btree (layout->buffer)); | |||
748 | ||||
749 | g_assert (last_btree_line != NULL)do { if (last_btree_line != ((void*)0)) ; else g_assertion_message_expr ("Ctk", "ctktextlayout.c", 749, ((const char*) (__func__)), "last_btree_line != NULL" ); } while (0); | |||
750 | ||||
751 | line = first_btree_line; | |||
752 | while (TRUE(!(0))) | |||
753 | { | |||
754 | retval = g_slist_prepend (retval, line); | |||
755 | ||||
756 | if (line == last_btree_line) | |||
757 | break; | |||
758 | ||||
759 | line = _ctk_text_line_next_excluding_last (line); | |||
760 | } | |||
761 | ||||
762 | retval = g_slist_reverse (retval); | |||
763 | ||||
764 | return retval; | |||
765 | } | |||
766 | ||||
767 | static void | |||
768 | invalidate_cached_style (CtkTextLayout *layout) | |||
769 | { | |||
770 | free_style_cache (layout); | |||
771 | } | |||
772 | ||||
773 | /* These should be called around a loop which wraps a CONTIGUOUS bunch | |||
774 | * of display lines. If the lines aren’t contiguous you can’t call | |||
775 | * these. | |||
776 | */ | |||
777 | void | |||
778 | ctk_text_layout_wrap_loop_start (CtkTextLayout *layout) | |||
779 | { | |||
780 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
781 | g_return_if_fail (layout->one_style_cache == NULL)do { if ((layout->one_style_cache == ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__) ), "layout->one_style_cache == NULL"); return; } } while ( 0); | |||
782 | ||||
783 | layout->wrap_loop_count += 1; | |||
784 | } | |||
785 | ||||
786 | void | |||
787 | ctk_text_layout_wrap_loop_end (CtkTextLayout *layout) | |||
788 | { | |||
789 | g_return_if_fail (layout->wrap_loop_count > 0)do { if ((layout->wrap_loop_count > 0)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "layout->wrap_loop_count > 0" ); return; } } while (0); | |||
790 | ||||
791 | layout->wrap_loop_count -= 1; | |||
792 | ||||
793 | if (layout->wrap_loop_count == 0) | |||
794 | { | |||
795 | /* We cache a some stuff if we're iterating over some lines wrapping | |||
796 | * them. This cleans it up. | |||
797 | */ | |||
798 | /* Nuke our cached style */ | |||
799 | invalidate_cached_style (layout); | |||
800 | g_assert (layout->one_style_cache == NULL)do { if (layout->one_style_cache == ((void*)0)) ; else g_assertion_message_expr ("Ctk", "ctktextlayout.c", 800, ((const char*) (__func__)), "layout->one_style_cache == NULL" ); } while (0); | |||
801 | } | |||
802 | } | |||
803 | ||||
804 | static void | |||
805 | ctk_text_layout_invalidate_all (CtkTextLayout *layout) | |||
806 | { | |||
807 | CtkTextIter start; | |||
808 | CtkTextIter end; | |||
809 | ||||
810 | if (layout->buffer == NULL((void*)0)) | |||
811 | return; | |||
812 | ||||
813 | ctk_text_buffer_get_bounds (layout->buffer, &start, &end); | |||
814 | ||||
815 | ctk_text_layout_invalidate (layout, &start, &end); | |||
816 | } | |||
817 | ||||
818 | static void | |||
819 | ctk_text_layout_invalidate_cache (CtkTextLayout *layout, | |||
820 | CtkTextLine *line, | |||
821 | gboolean cursors_only) | |||
822 | { | |||
823 | if (layout->one_display_cache && line == layout->one_display_cache->line) | |||
824 | { | |||
825 | CtkTextLineDisplay *display = layout->one_display_cache; | |||
826 | ||||
827 | if (cursors_only) | |||
828 | { | |||
829 | if (display->cursors) | |||
830 | g_array_free (display->cursors, TRUE(!(0))); | |||
831 | display->cursors = NULL((void*)0); | |||
832 | display->cursors_invalid = TRUE(!(0)); | |||
833 | display->has_block_cursor = FALSE(0); | |||
834 | } | |||
835 | else | |||
836 | { | |||
837 | layout->one_display_cache = NULL((void*)0); | |||
838 | ctk_text_layout_free_line_display (layout, display); | |||
839 | } | |||
840 | } | |||
841 | } | |||
842 | ||||
843 | /* Now invalidate the paragraph containing the cursor | |||
844 | */ | |||
845 | static void | |||
846 | ctk_text_layout_invalidate_cursor_line (CtkTextLayout *layout, | |||
847 | gboolean cursors_only) | |||
848 | { | |||
849 | CtkTextLayoutPrivate *priv = CTK_TEXT_LAYOUT_GET_PRIVATE (layout)((CtkTextLayoutPrivate *) ctk_text_layout_get_instance_private ((layout))); | |||
850 | CtkTextLineData *line_data; | |||
851 | ||||
852 | if (priv->cursor_line == NULL((void*)0)) | |||
853 | return; | |||
854 | ||||
855 | line_data = _ctk_text_line_get_data (priv->cursor_line, layout); | |||
856 | if (line_data) | |||
857 | { | |||
858 | if (cursors_only) | |||
859 | ctk_text_layout_invalidate_cache (layout, priv->cursor_line, TRUE(!(0))); | |||
860 | else | |||
861 | { | |||
862 | ctk_text_layout_invalidate_cache (layout, priv->cursor_line, FALSE(0)); | |||
863 | _ctk_text_line_invalidate_wrap (priv->cursor_line, line_data); | |||
864 | } | |||
865 | ||||
866 | ctk_text_layout_invalidated (layout); | |||
867 | } | |||
868 | } | |||
869 | ||||
870 | static void | |||
871 | ctk_text_layout_update_cursor_line(CtkTextLayout *layout) | |||
872 | { | |||
873 | CtkTextLayoutPrivate *priv = CTK_TEXT_LAYOUT_GET_PRIVATE (layout)((CtkTextLayoutPrivate *) ctk_text_layout_get_instance_private ((layout))); | |||
874 | CtkTextIter iter; | |||
875 | ||||
876 | ctk_text_buffer_get_iter_at_mark (layout->buffer, &iter, | |||
877 | ctk_text_buffer_get_insert (layout->buffer)); | |||
878 | ||||
879 | priv->cursor_line = _ctk_text_iter_get_text_line (&iter); | |||
880 | } | |||
881 | ||||
882 | static void | |||
883 | ctk_text_layout_real_invalidate (CtkTextLayout *layout, | |||
884 | const CtkTextIter *start, | |||
885 | const CtkTextIter *end) | |||
886 | { | |||
887 | CtkTextLine *line; | |||
888 | CtkTextLine *last_line; | |||
889 | ||||
890 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
891 | g_return_if_fail (layout->wrap_loop_count == 0)do { if ((layout->wrap_loop_count == 0)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "layout->wrap_loop_count == 0" ); return; } } while (0); | |||
892 | ||||
893 | /* Because we may be invalidating a mark, it's entirely possible | |||
894 | * that ctk_text_iter_equal (start, end) in which case we | |||
895 | * should still invalidate the line they are both on. i.e. | |||
896 | * we always invalidate the line with "start" even | |||
897 | * if there's an empty range. | |||
898 | */ | |||
899 | ||||
900 | #if 0 | |||
901 | ctk_text_view_index_spew (start_index, "invalidate start"); | |||
902 | ctk_text_view_index_spew (end_index, "invalidate end"); | |||
903 | #endif | |||
904 | ||||
905 | last_line = _ctk_text_iter_get_text_line (end); | |||
906 | line = _ctk_text_iter_get_text_line (start); | |||
907 | ||||
908 | while (TRUE(!(0))) | |||
909 | { | |||
910 | CtkTextLineData *line_data = _ctk_text_line_get_data (line, layout); | |||
911 | ||||
912 | ctk_text_layout_invalidate_cache (layout, line, FALSE(0)); | |||
913 | ||||
914 | if (line_data) | |||
915 | _ctk_text_line_invalidate_wrap (line, line_data); | |||
916 | ||||
917 | if (line == last_line) | |||
918 | break; | |||
919 | ||||
920 | line = _ctk_text_line_next_excluding_last (line); | |||
921 | } | |||
922 | ||||
923 | ctk_text_layout_invalidated (layout); | |||
924 | } | |||
925 | ||||
926 | static void | |||
927 | ctk_text_layout_real_invalidate_cursors (CtkTextLayout *layout, | |||
928 | const CtkTextIter *start, | |||
929 | const CtkTextIter *end) | |||
930 | { | |||
931 | /* Check if the range intersects our cached line display, | |||
932 | * and invalidate the cached line if so. | |||
933 | */ | |||
934 | if (layout->one_display_cache) | |||
935 | { | |||
936 | CtkTextIter line_start, line_end; | |||
937 | CtkTextLine *line = layout->one_display_cache->line; | |||
938 | ||||
939 | ctk_text_layout_get_iter_at_line (layout, &line_start, line, 0); | |||
940 | ||||
941 | line_end = line_start; | |||
942 | if (!ctk_text_iter_ends_line (&line_end)) | |||
943 | ctk_text_iter_forward_to_line_end (&line_end); | |||
944 | ||||
945 | if (ctk_text_iter_compare (start, end) > 0) | |||
946 | { | |||
947 | const CtkTextIter *tmp = start; | |||
948 | start = end; | |||
949 | end = tmp; | |||
950 | } | |||
951 | ||||
952 | if (ctk_text_iter_compare (&line_start, end) <= 0 && | |||
953 | ctk_text_iter_compare (start, &line_end) <= 0) | |||
954 | { | |||
955 | ctk_text_layout_invalidate_cache (layout, line, TRUE(!(0))); | |||
956 | } | |||
957 | } | |||
958 | ||||
959 | ctk_text_layout_invalidated (layout); | |||
960 | } | |||
961 | ||||
962 | static void | |||
963 | ctk_text_layout_real_free_line_data (CtkTextLayout *layout, | |||
964 | CtkTextLine *line, | |||
965 | CtkTextLineData *line_data) | |||
966 | { | |||
967 | ctk_text_layout_invalidate_cache (layout, line, FALSE(0)); | |||
968 | ||||
969 | g_slice_free (CtkTextLineData, line_data)do { if (1) g_slice_free1 (sizeof (CtkTextLineData), (line_data )); else (void) ((CtkTextLineData*) 0 == (line_data)); } while (0); | |||
970 | } | |||
971 | ||||
972 | /** | |||
973 | * ctk_text_layout_is_valid: | |||
974 | * @layout: a #CtkTextLayout | |||
975 | * | |||
976 | * Check if there are any invalid regions in a #CtkTextLayout’s buffer | |||
977 | * | |||
978 | * Returns: %TRUE if any invalid regions were found | |||
979 | */ | |||
980 | gboolean | |||
981 | ctk_text_layout_is_valid (CtkTextLayout *layout) | |||
982 | { | |||
983 | g_return_val_if_fail (CTK_IS_TEXT_LAYOUT (layout), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return ((0)); } } while ( 0); | |||
984 | ||||
985 | return _ctk_text_btree_is_valid (_ctk_text_buffer_get_btree (layout->buffer), | |||
986 | layout); | |||
987 | } | |||
988 | ||||
989 | static void | |||
990 | update_layout_size (CtkTextLayout *layout) | |||
991 | { | |||
992 | _ctk_text_btree_get_view_size (_ctk_text_buffer_get_btree (layout->buffer), | |||
993 | layout, | |||
994 | &layout->width, &layout->height); | |||
995 | } | |||
996 | ||||
997 | /** | |||
998 | * ctk_text_layout_validate_yrange: | |||
999 | * @layout: a #CtkTextLayout | |||
1000 | * @anchor: iter pointing into a line that will be used as the | |||
1001 | * coordinate origin | |||
1002 | * @y0_: offset from the top of the line pointed to by @anchor at | |||
1003 | * which to begin validation. (The offset here is in pixels | |||
1004 | * after validation.) | |||
1005 | * @y1_: offset from the top of the line pointed to by @anchor at | |||
1006 | * which to end validation. (The offset here is in pixels | |||
1007 | * after validation.) | |||
1008 | * | |||
1009 | * Ensure that a region of a #CtkTextLayout is valid. The ::changed | |||
1010 | * signal will be emitted if any lines are validated. | |||
1011 | */ | |||
1012 | void | |||
1013 | ctk_text_layout_validate_yrange (CtkTextLayout *layout, | |||
1014 | CtkTextIter *anchor, | |||
1015 | gint y0, | |||
1016 | gint y1) | |||
1017 | { | |||
1018 | CtkTextLine *line; | |||
1019 | CtkTextLine *first_line = NULL((void*)0); | |||
1020 | CtkTextLine *last_line = NULL((void*)0); | |||
1021 | gint seen; | |||
1022 | gint delta_height = 0; | |||
1023 | gint first_line_y = 0; /* Quiet GCC */ | |||
1024 | gint last_line_y = 0; /* Quiet GCC */ | |||
1025 | ||||
1026 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
1027 | ||||
1028 | if (y0 > 0) | |||
1029 | y0 = 0; | |||
1030 | if (y1 < 0) | |||
1031 | y1 = 0; | |||
1032 | ||||
1033 | /* Validate backwards from the anchor line to y0 | |||
1034 | */ | |||
1035 | line = _ctk_text_iter_get_text_line (anchor); | |||
1036 | line = _ctk_text_line_previous (line); | |||
1037 | seen = 0; | |||
1038 | while (line && seen < -y0) | |||
1039 | { | |||
1040 | CtkTextLineData *line_data = _ctk_text_line_get_data (line, layout); | |||
1041 | if (!line_data || !line_data->valid) | |||
1042 | { | |||
1043 | gint old_height, new_height; | |||
1044 | gint top_ink, bottom_ink; | |||
1045 | ||||
1046 | old_height = line_data ? line_data->height : 0; | |||
1047 | top_ink = line_data ? line_data->top_ink : 0; | |||
1048 | bottom_ink = line_data ? line_data->bottom_ink : 0; | |||
1049 | ||||
1050 | _ctk_text_btree_validate_line (_ctk_text_buffer_get_btree (layout->buffer), | |||
1051 | line, layout); | |||
1052 | line_data = _ctk_text_line_get_data (line, layout); | |||
1053 | ||||
1054 | new_height = line_data ? line_data->height : 0; | |||
1055 | if (line_data) | |||
1056 | { | |||
1057 | top_ink = MAX (top_ink, line_data->top_ink)(((top_ink) > (line_data->top_ink)) ? (top_ink) : (line_data ->top_ink)); | |||
1058 | bottom_ink = MAX (bottom_ink, line_data->bottom_ink)(((bottom_ink) > (line_data->bottom_ink)) ? (bottom_ink ) : (line_data->bottom_ink)); | |||
1059 | } | |||
1060 | ||||
1061 | delta_height += new_height - old_height; | |||
1062 | ||||
1063 | first_line = line; | |||
1064 | first_line_y = -seen - new_height - top_ink; | |||
1065 | if (!last_line) | |||
1066 | { | |||
1067 | last_line = line; | |||
1068 | last_line_y = -seen + bottom_ink; | |||
1069 | } | |||
1070 | } | |||
1071 | ||||
1072 | seen += line_data ? line_data->height : 0; | |||
1073 | line = _ctk_text_line_previous (line); | |||
1074 | } | |||
1075 | ||||
1076 | /* Validate forwards to y1 */ | |||
1077 | line = _ctk_text_iter_get_text_line (anchor); | |||
1078 | seen = 0; | |||
1079 | while (line && seen < y1) | |||
1080 | { | |||
1081 | CtkTextLineData *line_data = _ctk_text_line_get_data (line, layout); | |||
1082 | if (!line_data || !line_data->valid) | |||
1083 | { | |||
1084 | gint old_height, new_height; | |||
1085 | gint top_ink, bottom_ink; | |||
1086 | ||||
1087 | old_height = line_data ? line_data->height : 0; | |||
1088 | top_ink = line_data ? line_data->top_ink : 0; | |||
1089 | bottom_ink = line_data ? line_data->bottom_ink : 0; | |||
1090 | ||||
1091 | _ctk_text_btree_validate_line (_ctk_text_buffer_get_btree (layout->buffer), | |||
1092 | line, layout); | |||
1093 | line_data = _ctk_text_line_get_data (line, layout); | |||
1094 | new_height = line_data ? line_data->height : 0; | |||
1095 | if (line_data) | |||
1096 | { | |||
1097 | top_ink = MAX (top_ink, line_data->top_ink)(((top_ink) > (line_data->top_ink)) ? (top_ink) : (line_data ->top_ink)); | |||
1098 | bottom_ink = MAX (bottom_ink, line_data->bottom_ink)(((bottom_ink) > (line_data->bottom_ink)) ? (bottom_ink ) : (line_data->bottom_ink)); | |||
1099 | } | |||
1100 | ||||
1101 | delta_height += new_height - old_height; | |||
1102 | ||||
1103 | if (!first_line) | |||
1104 | { | |||
1105 | first_line = line; | |||
1106 | first_line_y = seen - top_ink; | |||
1107 | } | |||
1108 | last_line = line; | |||
1109 | last_line_y = seen + new_height + bottom_ink; | |||
1110 | } | |||
1111 | ||||
1112 | seen += line_data ? line_data->height : 0; | |||
1113 | line = _ctk_text_line_next_excluding_last (line); | |||
1114 | } | |||
1115 | ||||
1116 | /* If we found and validated any invalid lines, update size and | |||
1117 | * emit the changed signal | |||
1118 | */ | |||
1119 | if (first_line) | |||
1120 | { | |||
1121 | gint line_top; | |||
1122 | ||||
1123 | update_layout_size (layout); | |||
1124 | ||||
1125 | line_top = _ctk_text_btree_find_line_top (_ctk_text_buffer_get_btree (layout->buffer), | |||
1126 | first_line, layout); | |||
1127 | ||||
1128 | ctk_text_layout_emit_changed (layout, | |||
1129 | line_top, | |||
1130 | last_line_y - first_line_y - delta_height, | |||
1131 | last_line_y - first_line_y); | |||
1132 | } | |||
1133 | } | |||
1134 | ||||
1135 | /** | |||
1136 | * ctk_text_layout_validate: | |||
1137 | * @tree: a #CtkTextLayout | |||
1138 | * @max_pixels: the maximum number of pixels to validate. (No more | |||
1139 | * than one paragraph beyond this limit will be validated) | |||
1140 | * | |||
1141 | * Validate regions of a #CtkTextLayout. The ::changed signal will | |||
1142 | * be emitted for each region validated. | |||
1143 | **/ | |||
1144 | void | |||
1145 | ctk_text_layout_validate (CtkTextLayout *layout, | |||
1146 | gint max_pixels) | |||
1147 | { | |||
1148 | gint y, old_height, new_height; | |||
1149 | ||||
1150 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
1151 | ||||
1152 | while (max_pixels > 0 && | |||
1153 | _ctk_text_btree_validate (_ctk_text_buffer_get_btree (layout->buffer), | |||
1154 | layout, max_pixels, | |||
1155 | &y, &old_height, &new_height)) | |||
1156 | { | |||
1157 | max_pixels -= new_height; | |||
1158 | ||||
1159 | update_layout_size (layout); | |||
1160 | ctk_text_layout_emit_changed (layout, y, old_height, new_height); | |||
1161 | } | |||
1162 | } | |||
1163 | ||||
1164 | static CtkTextLineData* | |||
1165 | ctk_text_layout_real_wrap (CtkTextLayout *layout, | |||
1166 | CtkTextLine *line, | |||
1167 | /* may be NULL */ | |||
1168 | CtkTextLineData *line_data) | |||
1169 | { | |||
1170 | CtkTextLineDisplay *display; | |||
1171 | PangoRectangle ink_rect, logical_rect; | |||
1172 | ||||
1173 | g_return_val_if_fail (CTK_IS_TEXT_LAYOUT (layout), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return (((void*)0)); } } while (0); | |||
1174 | g_return_val_if_fail (line != NULL, NULL)do { if ((line != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "line != NULL"); return ( ((void*)0)); } } while (0); | |||
1175 | ||||
1176 | if (line_data == NULL((void*)0)) | |||
1177 | { | |||
1178 | line_data = _ctk_text_line_data_new (layout, line); | |||
1179 | _ctk_text_line_add_data (line, line_data); | |||
1180 | } | |||
1181 | ||||
1182 | display = ctk_text_layout_get_line_display (layout, line, TRUE(!(0))); | |||
1183 | line_data->width = display->width; | |||
1184 | line_data->height = display->height; | |||
1185 | line_data->valid = TRUE(!(0)); | |||
1186 | pango_layout_get_pixel_extents (display->layout, &ink_rect, &logical_rect); | |||
1187 | line_data->top_ink = MAX (0, logical_rect.x - ink_rect.x)(((0) > (logical_rect.x - ink_rect.x)) ? (0) : (logical_rect .x - ink_rect.x)); | |||
1188 | line_data->bottom_ink = MAX (0, logical_rect.x + logical_rect.width - ink_rect.x - ink_rect.width)(((0) > (logical_rect.x + logical_rect.width - ink_rect.x - ink_rect.width)) ? (0) : (logical_rect.x + logical_rect.width - ink_rect.x - ink_rect.width)); | |||
1189 | ctk_text_layout_free_line_display (layout, display); | |||
1190 | ||||
1191 | return line_data; | |||
1192 | } | |||
1193 | ||||
1194 | /* | |||
1195 | * Layout utility functions | |||
1196 | */ | |||
1197 | ||||
1198 | /* If you get the style with get_style () you need to call | |||
1199 | release_style () to free it. */ | |||
1200 | static CtkTextAttributes* | |||
1201 | get_style (CtkTextLayout *layout, | |||
1202 | GPtrArray *tags) | |||
1203 | { | |||
1204 | CtkTextAttributes *style; | |||
1205 | ||||
1206 | /* If we have the one-style cache, then it means | |||
1207 | that we haven't seen a toggle since we filled in the | |||
1208 | one-style cache. | |||
1209 | */ | |||
1210 | if (layout->one_style_cache != NULL((void*)0)) | |||
1211 | { | |||
1212 | ctk_text_attributes_ref (layout->one_style_cache); | |||
1213 | return layout->one_style_cache; | |||
1214 | } | |||
1215 | ||||
1216 | g_assert (layout->one_style_cache == NULL)do { if (layout->one_style_cache == ((void*)0)) ; else g_assertion_message_expr ("Ctk", "ctktextlayout.c", 1216, ((const char*) (__func__)), "layout->one_style_cache == NULL"); } while (0); | |||
1217 | ||||
1218 | /* No tags, use default style */ | |||
1219 | if (tags
| |||
1220 | { | |||
1221 | /* One ref for the return value, one ref for the | |||
1222 | layout->one_style_cache reference */ | |||
1223 | ctk_text_attributes_ref (layout->default_style); | |||
1224 | ctk_text_attributes_ref (layout->default_style); | |||
1225 | layout->one_style_cache = layout->default_style; | |||
1226 | ||||
1227 | return layout->default_style; | |||
1228 | } | |||
1229 | ||||
1230 | style = ctk_text_attributes_new (); | |||
1231 | ||||
1232 | ctk_text_attributes_copy_values (layout->default_style, | |||
1233 | style); | |||
1234 | ||||
1235 | _ctk_text_attributes_fill_from_tags (style, | |||
1236 | (CtkTextTag**) tags->pdata, | |||
1237 | tags->len); | |||
1238 | ||||
1239 | g_assert (style->refcount == 1)do { if (style->refcount == 1) ; else g_assertion_message_expr ("Ctk", "ctktextlayout.c", 1239, ((const char*) (__func__)), "style->refcount == 1"); } while (0); | |||
1240 | ||||
1241 | /* Leave this style as the last one seen */ | |||
1242 | g_assert (layout->one_style_cache == NULL)do { if (layout->one_style_cache == ((void*)0)) ; else g_assertion_message_expr ("Ctk", "ctktextlayout.c", 1242, ((const char*) (__func__)), "layout->one_style_cache == NULL"); } while (0); | |||
1243 | ctk_text_attributes_ref (style); /* ref held by layout->one_style_cache */ | |||
1244 | layout->one_style_cache = style; | |||
1245 | ||||
1246 | /* Returning yet another refcount */ | |||
1247 | return style; | |||
1248 | } | |||
1249 | ||||
1250 | static void | |||
1251 | release_style (CtkTextLayout *layout G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1252 | CtkTextAttributes *style) | |||
1253 | { | |||
1254 | g_return_if_fail (style != NULL)do { if ((style != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "style != NULL"); return ; } } while (0); | |||
1255 | g_return_if_fail (style->refcount > 0)do { if ((style->refcount > 0)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "style->refcount > 0" ); return; } } while (0); | |||
1256 | ||||
1257 | ctk_text_attributes_unref (style); | |||
1258 | } | |||
1259 | ||||
1260 | /* | |||
1261 | * Lines | |||
1262 | */ | |||
1263 | ||||
1264 | /* This function tries to optimize the case where a line | |||
1265 | is completely invisible */ | |||
1266 | static gboolean | |||
1267 | totally_invisible_line (CtkTextLayout *layout, | |||
1268 | CtkTextLine *line, | |||
1269 | CtkTextIter *iter) | |||
1270 | { | |||
1271 | CtkTextLineSegment *seg; | |||
1272 | int bytes = 0; | |||
1273 | ||||
1274 | /* Check if the first char is visible, if so we are partially visible. | |||
1275 | * Note that we have to check this since we don't know the current | |||
1276 | * invisible/noninvisible toggle state; this function can use the whole btree | |||
1277 | * to get it right. | |||
1278 | */ | |||
1279 | ctk_text_layout_get_iter_at_line (layout, iter, line, 0); | |||
1280 | if (!_ctk_text_btree_char_is_invisible (iter)) | |||
1281 | return FALSE(0); | |||
1282 | ||||
1283 | bytes = 0; | |||
1284 | seg = line->segments; | |||
1285 | ||||
1286 | while (seg != NULL((void*)0)) | |||
1287 | { | |||
1288 | if (seg->byte_count > 0) | |||
1289 | bytes += seg->byte_count; | |||
1290 | ||||
1291 | /* Note that these two tests can cause us to bail out | |||
1292 | * when we shouldn't, because a higher-priority tag | |||
1293 | * may override these settings. However the important | |||
1294 | * thing is to only invisible really-invisible lines, rather | |||
1295 | * than to invisible all really-invisible lines. | |||
1296 | */ | |||
1297 | ||||
1298 | else if (seg->type == &ctk_text_toggle_on_type) | |||
1299 | { | |||
1300 | invalidate_cached_style (layout); | |||
1301 | ||||
1302 | /* Bail out if an elision-unsetting tag begins */ | |||
1303 | if (seg->body.toggle.info->tag->priv->invisible_set && | |||
1304 | !seg->body.toggle.info->tag->priv->values->invisible) | |||
1305 | break; | |||
1306 | } | |||
1307 | else if (seg->type == &ctk_text_toggle_off_type) | |||
1308 | { | |||
1309 | invalidate_cached_style (layout); | |||
1310 | ||||
1311 | /* Bail out if an elision-setting tag ends */ | |||
1312 | if (seg->body.toggle.info->tag->priv->invisible_set && | |||
1313 | seg->body.toggle.info->tag->priv->values->invisible) | |||
1314 | break; | |||
1315 | } | |||
1316 | ||||
1317 | seg = seg->next; | |||
1318 | } | |||
1319 | ||||
1320 | if (seg != NULL((void*)0)) /* didn't reach line end */ | |||
1321 | return FALSE(0); | |||
1322 | ||||
1323 | return TRUE(!(0)); | |||
1324 | } | |||
1325 | ||||
1326 | static void | |||
1327 | set_para_values (CtkTextLayout *layout, | |||
1328 | PangoDirection base_dir, | |||
1329 | CtkTextAttributes *style, | |||
1330 | CtkTextLineDisplay *display) | |||
1331 | { | |||
1332 | PangoAlignment pango_align = PANGO_ALIGN_LEFT; | |||
1333 | PangoWrapMode pango_wrap = PANGO_WRAP_WORD; | |||
1334 | gint h_margin; | |||
1335 | gint h_padding; | |||
1336 | ||||
1337 | switch (base_dir) | |||
1338 | { | |||
1339 | /* If no base direction was found, then use the style direction */ | |||
1340 | case PANGO_DIRECTION_NEUTRAL : | |||
1341 | display->direction = style->direction; | |||
1342 | ||||
1343 | /* Override the base direction */ | |||
1344 | if (display->direction == CTK_TEXT_DIR_RTL) | |||
1345 | base_dir = PANGO_DIRECTION_RTL; | |||
1346 | else | |||
1347 | base_dir = PANGO_DIRECTION_LTR; | |||
1348 | ||||
1349 | break; | |||
1350 | case PANGO_DIRECTION_RTL : | |||
1351 | display->direction = CTK_TEXT_DIR_RTL; | |||
1352 | break; | |||
1353 | default: | |||
1354 | display->direction = CTK_TEXT_DIR_LTR; | |||
1355 | break; | |||
1356 | } | |||
1357 | ||||
1358 | if (display->direction == CTK_TEXT_DIR_RTL) | |||
1359 | display->layout = pango_layout_new (layout->rtl_context); | |||
1360 | else | |||
1361 | display->layout = pango_layout_new (layout->ltr_context); | |||
1362 | ||||
1363 | switch (style->justification) | |||
1364 | { | |||
1365 | case CTK_JUSTIFY_LEFT: | |||
1366 | pango_align = (base_dir == PANGO_DIRECTION_LTR) ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT; | |||
1367 | break; | |||
1368 | case CTK_JUSTIFY_RIGHT: | |||
1369 | pango_align = (base_dir == PANGO_DIRECTION_LTR) ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT; | |||
1370 | break; | |||
1371 | case CTK_JUSTIFY_CENTER: | |||
1372 | pango_align = PANGO_ALIGN_CENTER; | |||
1373 | break; | |||
1374 | case CTK_JUSTIFY_FILL: | |||
1375 | pango_align = (base_dir == PANGO_DIRECTION_LTR) ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT; | |||
1376 | pango_layout_set_justify (display->layout, TRUE(!(0))); | |||
1377 | break; | |||
1378 | default: | |||
1379 | g_assert_not_reached ()do { g_assertion_message_expr ("Ctk", "ctktextlayout.c", 1379 , ((const char*) (__func__)), ((void*)0)); } while (0); | |||
1380 | break; | |||
1381 | } | |||
1382 | ||||
1383 | pango_layout_set_alignment (display->layout, pango_align); | |||
1384 | pango_layout_set_spacing (display->layout, | |||
1385 | style->pixels_inside_wrap * PANGO_SCALE1024); | |||
1386 | ||||
1387 | if (style->tabs) | |||
1388 | pango_layout_set_tabs (display->layout, style->tabs); | |||
1389 | ||||
1390 | display->top_margin = style->pixels_above_lines; | |||
1391 | display->height = style->pixels_above_lines + style->pixels_below_lines; | |||
1392 | display->bottom_margin = style->pixels_below_lines; | |||
1393 | display->left_margin = style->left_margin; | |||
1394 | display->right_margin = style->right_margin; | |||
1395 | ||||
1396 | display->x_offset = display->left_margin; | |||
1397 | ||||
1398 | pango_layout_set_indent (display->layout, | |||
1399 | style->indent * PANGO_SCALE1024); | |||
1400 | ||||
1401 | switch (style->wrap_mode) | |||
1402 | { | |||
1403 | case CTK_WRAP_CHAR: | |||
1404 | pango_wrap = PANGO_WRAP_CHAR; | |||
1405 | break; | |||
1406 | case CTK_WRAP_WORD: | |||
1407 | pango_wrap = PANGO_WRAP_WORD; | |||
1408 | break; | |||
1409 | ||||
1410 | case CTK_WRAP_WORD_CHAR: | |||
1411 | pango_wrap = PANGO_WRAP_WORD_CHAR; | |||
1412 | break; | |||
1413 | ||||
1414 | case CTK_WRAP_NONE: | |||
1415 | break; | |||
1416 | } | |||
1417 | ||||
1418 | h_margin = display->left_margin + display->right_margin; | |||
1419 | h_padding = layout->left_padding + layout->right_padding; | |||
1420 | ||||
1421 | if (style->wrap_mode != CTK_WRAP_NONE) | |||
1422 | { | |||
1423 | int layout_width = (layout->screen_width - h_margin - h_padding); | |||
1424 | pango_layout_set_width (display->layout, layout_width * PANGO_SCALE1024); | |||
1425 | pango_layout_set_wrap (display->layout, pango_wrap); | |||
1426 | } | |||
1427 | display->total_width = MAX (layout->screen_width, layout->width)(((layout->screen_width) > (layout->width)) ? (layout ->screen_width) : (layout->width)) - h_margin - h_padding; | |||
1428 | ||||
1429 | if (style->pg_bg_color) | |||
1430 | display->pg_bg_color = cdk_color_copy (style->pg_bg_color); | |||
1431 | else | |||
1432 | display->pg_bg_color = NULL((void*)0); | |||
1433 | ||||
1434 | if (style->pg_bg_rgba) | |||
1435 | display->pg_bg_rgba = cdk_rgba_copy (style->pg_bg_rgba); | |||
1436 | else | |||
1437 | display->pg_bg_rgba = NULL((void*)0); | |||
1438 | } | |||
1439 | ||||
1440 | static PangoAttribute * | |||
1441 | ctk_text_attr_appearance_copy (const PangoAttribute *attr) | |||
1442 | { | |||
1443 | const CtkTextAttrAppearance *appearance_attr = (const CtkTextAttrAppearance *)attr; | |||
1444 | ||||
1445 | return ctk_text_attr_appearance_new (&appearance_attr->appearance); | |||
1446 | } | |||
1447 | ||||
1448 | static void | |||
1449 | ctk_text_attr_appearance_destroy (PangoAttribute *attr) | |||
1450 | { | |||
1451 | CtkTextAttrAppearance *appearance_attr = (CtkTextAttrAppearance *)attr; | |||
1452 | ||||
1453 | if (appearance_attr->appearance.rgba[0]) | |||
1454 | cdk_rgba_free (appearance_attr->appearance.rgba[0]); | |||
1455 | ||||
1456 | if (appearance_attr->appearance.rgba[1]) | |||
1457 | cdk_rgba_free (appearance_attr->appearance.rgba[1]); | |||
1458 | ||||
1459 | g_slice_free (CtkTextAttrAppearance, appearance_attr)do { if (1) g_slice_free1 (sizeof (CtkTextAttrAppearance), (appearance_attr )); else (void) ((CtkTextAttrAppearance*) 0 == (appearance_attr )); } while (0); | |||
1460 | } | |||
1461 | ||||
1462 | static gboolean | |||
1463 | rgba_equal (const CdkRGBA *rgba1, const CdkRGBA *rgba2) | |||
1464 | { | |||
1465 | if (rgba1 && rgba2) | |||
1466 | return cdk_rgba_equal (rgba1, rgba2); | |||
1467 | ||||
1468 | if (rgba1 || rgba2) | |||
1469 | return FALSE(0); | |||
1470 | ||||
1471 | return TRUE(!(0)); | |||
1472 | } | |||
1473 | ||||
1474 | static gboolean | |||
1475 | underline_equal (const CtkTextAppearance *appearance1, | |||
1476 | const CtkTextAppearance *appearance2) | |||
1477 | { | |||
1478 | CdkRGBA c1; | |||
1479 | CdkRGBA c2; | |||
1480 | ||||
1481 | CTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA (appearance1, &c1)do { (&c1)->red = ((guint8*)&(appearance1)->bg_color )[0] / 255.; (&c1)->green = ((guint8*)&(appearance1 )->bg_color)[1] / 255.; (&c1)->blue = ((guint8*)& (appearance1)->bg_color)[2] / 255.; (&c1)->alpha = 1.0 ; } while (0); | |||
1482 | CTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA (appearance2, &c2)do { (&c2)->red = ((guint8*)&(appearance2)->bg_color )[0] / 255.; (&c2)->green = ((guint8*)&(appearance2 )->bg_color)[1] / 255.; (&c2)->blue = ((guint8*)& (appearance2)->bg_color)[2] / 255.; (&c2)->alpha = 1.0 ; } while (0); | |||
1483 | ||||
1484 | return ((appearance1->underline == appearance2->underline) && | |||
1485 | (CTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA_SET (appearance1)(((guint8*)&(appearance1)->bg_color)[3] != 0) == | |||
1486 | CTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA_SET (appearance2)(((guint8*)&(appearance2)->bg_color)[3] != 0)) && | |||
1487 | cdk_rgba_equal (&c1, &c2)); | |||
1488 | } | |||
1489 | ||||
1490 | static gboolean | |||
1491 | strikethrough_equal (const CtkTextAppearance *appearance1, | |||
1492 | const CtkTextAppearance *appearance2) | |||
1493 | { | |||
1494 | CdkRGBA c1; | |||
1495 | CdkRGBA c2; | |||
1496 | ||||
1497 | CTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA (appearance1, &c1)do { (&c1)->red = ((guint8*)&(appearance1)->fg_color )[0] / 255.; (&c1)->green = ((guint8*)&(appearance1 )->fg_color)[1] / 255.; (&c1)->blue = ((guint8*)& (appearance1)->fg_color)[2] / 255.; (&c1)->alpha = 1.0 ; } while (0); | |||
1498 | CTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA (appearance2, &c2)do { (&c2)->red = ((guint8*)&(appearance2)->fg_color )[0] / 255.; (&c2)->green = ((guint8*)&(appearance2 )->fg_color)[1] / 255.; (&c2)->blue = ((guint8*)& (appearance2)->fg_color)[2] / 255.; (&c2)->alpha = 1.0 ; } while (0); | |||
1499 | ||||
1500 | return ((appearance1->strikethrough == appearance2->strikethrough) && | |||
1501 | (CTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA_SET (appearance1)(((guint8*)&(appearance1)->fg_color)[3] != 0) == | |||
1502 | CTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA_SET (appearance2)(((guint8*)&(appearance2)->fg_color)[3] != 0)) && | |||
1503 | cdk_rgba_equal (&c1, &c2)); | |||
1504 | } | |||
1505 | ||||
1506 | static gboolean | |||
1507 | ctk_text_attr_appearance_compare (const PangoAttribute *attr1, | |||
1508 | const PangoAttribute *attr2) | |||
1509 | { | |||
1510 | const CtkTextAppearance *appearance1 = &((const CtkTextAttrAppearance *)attr1)->appearance; | |||
1511 | const CtkTextAppearance *appearance2 = &((const CtkTextAttrAppearance *)attr2)->appearance; | |||
1512 | ||||
1513 | return (rgba_equal (appearance1->rgba[0], appearance2->rgba[0]) && | |||
1514 | rgba_equal (appearance1->rgba[1], appearance2->rgba[1]) && | |||
1515 | appearance1->draw_bg == appearance2->draw_bg && | |||
1516 | strikethrough_equal (appearance1, appearance2) && | |||
1517 | underline_equal (appearance1, appearance2)); | |||
1518 | } | |||
1519 | ||||
1520 | /* | |||
1521 | * ctk_text_attr_appearance_new: | |||
1522 | * @desc: | |||
1523 | * | |||
1524 | * Create a new font description attribute. (This attribute | |||
1525 | * allows setting family, style, weight, variant, stretch, | |||
1526 | * and size simultaneously.) | |||
1527 | * | |||
1528 | * Returns: | |||
1529 | */ | |||
1530 | static PangoAttribute * | |||
1531 | ctk_text_attr_appearance_new (const CtkTextAppearance *appearance) | |||
1532 | { | |||
1533 | static PangoAttrClass klass = { | |||
1534 | 0, | |||
1535 | ctk_text_attr_appearance_copy, | |||
1536 | ctk_text_attr_appearance_destroy, | |||
1537 | ctk_text_attr_appearance_compare | |||
1538 | }; | |||
1539 | ||||
1540 | CtkTextAttrAppearance *result; | |||
1541 | ||||
1542 | if (!klass.type) | |||
1543 | klass.type = ctk_text_attr_appearance_type = | |||
1544 | pango_attr_type_register ("CtkTextAttrAppearance"); | |||
1545 | ||||
1546 | result = g_slice_new (CtkTextAttrAppearance)((CtkTextAttrAppearance*) g_slice_alloc (sizeof (CtkTextAttrAppearance ))); | |||
1547 | result->attr.klass = &klass; | |||
1548 | ||||
1549 | result->appearance = *appearance; | |||
1550 | ||||
1551 | if (appearance->rgba[0]) | |||
1552 | result->appearance.rgba[0] = cdk_rgba_copy (appearance->rgba[0]); | |||
1553 | ||||
1554 | if (appearance->rgba[1]) | |||
1555 | result->appearance.rgba[1] = cdk_rgba_copy (appearance->rgba[1]); | |||
1556 | ||||
1557 | return (PangoAttribute *)result; | |||
1558 | } | |||
1559 | ||||
1560 | static void | |||
1561 | add_generic_attrs (CtkTextLayout *layout G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1562 | CtkTextAppearance *appearance, | |||
1563 | gint byte_count, | |||
1564 | PangoAttrList *attrs, | |||
1565 | gint start, | |||
1566 | gboolean size_only, | |||
1567 | gboolean is_text) | |||
1568 | { | |||
1569 | PangoAttribute *attr; | |||
1570 | ||||
1571 | if (appearance->underline != PANGO_UNDERLINE_NONE) | |||
1572 | { | |||
1573 | attr = pango_attr_underline_new (appearance->underline); | |||
1574 | ||||
1575 | attr->start_index = start; | |||
1576 | attr->end_index = start + byte_count; | |||
1577 | ||||
1578 | pango_attr_list_insert (attrs, attr); | |||
1579 | } | |||
1580 | ||||
1581 | if (CTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA_SET (appearance)(((guint8*)&(appearance)->bg_color)[3] != 0)) | |||
1582 | { | |||
1583 | CdkRGBA rgba; | |||
1584 | ||||
1585 | CTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA (appearance, &rgba)do { (&rgba)->red = ((guint8*)&(appearance)->bg_color )[0] / 255.; (&rgba)->green = ((guint8*)&(appearance )->bg_color)[1] / 255.; (&rgba)->blue = ((guint8*)& (appearance)->bg_color)[2] / 255.; (&rgba)->alpha = 1.0; } while (0); | |||
1586 | ||||
1587 | attr = pango_attr_underline_color_new (rgba.red * 65535, | |||
1588 | rgba.green * 65535, | |||
1589 | rgba.blue * 65535); | |||
1590 | ||||
1591 | attr->start_index = start; | |||
1592 | attr->end_index = start + byte_count; | |||
1593 | ||||
1594 | pango_attr_list_insert (attrs, attr); | |||
1595 | } | |||
1596 | ||||
1597 | if (appearance->strikethrough) | |||
1598 | { | |||
1599 | attr = pango_attr_strikethrough_new (appearance->strikethrough); | |||
1600 | ||||
1601 | attr->start_index = start; | |||
1602 | attr->end_index = start + byte_count; | |||
1603 | ||||
1604 | pango_attr_list_insert (attrs, attr); | |||
1605 | } | |||
1606 | ||||
1607 | if (CTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA_SET (appearance)(((guint8*)&(appearance)->fg_color)[3] != 0)) | |||
1608 | { | |||
1609 | CdkRGBA rgba; | |||
1610 | ||||
1611 | CTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA (appearance, &rgba)do { (&rgba)->red = ((guint8*)&(appearance)->fg_color )[0] / 255.; (&rgba)->green = ((guint8*)&(appearance )->fg_color)[1] / 255.; (&rgba)->blue = ((guint8*)& (appearance)->fg_color)[2] / 255.; (&rgba)->alpha = 1.0; } while (0); | |||
1612 | ||||
1613 | attr = pango_attr_strikethrough_color_new (rgba.red * 65535, | |||
1614 | rgba.green * 65535, | |||
1615 | rgba.blue * 65535); | |||
1616 | ||||
1617 | attr->start_index = start; | |||
1618 | attr->end_index = start + byte_count; | |||
1619 | ||||
1620 | pango_attr_list_insert (attrs, attr); | |||
1621 | } | |||
1622 | ||||
1623 | if (appearance->rise != 0) | |||
1624 | { | |||
1625 | attr = pango_attr_rise_new (appearance->rise); | |||
1626 | ||||
1627 | attr->start_index = start; | |||
1628 | attr->end_index = start + byte_count; | |||
1629 | ||||
1630 | pango_attr_list_insert (attrs, attr); | |||
1631 | } | |||
1632 | ||||
1633 | if (!size_only) | |||
1634 | { | |||
1635 | attr = ctk_text_attr_appearance_new (appearance); | |||
1636 | ||||
1637 | attr->start_index = start; | |||
1638 | attr->end_index = start + byte_count; | |||
1639 | ||||
1640 | ((CtkTextAttrAppearance *)attr)->appearance.is_text = is_text; | |||
1641 | ||||
1642 | pango_attr_list_insert (attrs, attr); | |||
1643 | } | |||
1644 | } | |||
1645 | ||||
1646 | static void | |||
1647 | add_text_attrs (CtkTextLayout *layout G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1648 | CtkTextAttributes *style, | |||
1649 | gint byte_count, | |||
1650 | PangoAttrList *attrs, | |||
1651 | gint start, | |||
1652 | gboolean size_only G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
1653 | { | |||
1654 | PangoAttribute *attr; | |||
1655 | ||||
1656 | attr = pango_attr_font_desc_new (style->font); | |||
1657 | attr->start_index = start; | |||
1658 | attr->end_index = start + byte_count; | |||
1659 | ||||
1660 | pango_attr_list_insert (attrs, attr); | |||
1661 | ||||
1662 | if (style->font_scale != 1.0) | |||
1663 | { | |||
1664 | attr = pango_attr_scale_new (style->font_scale); | |||
1665 | attr->start_index = start; | |||
1666 | attr->end_index = start + byte_count; | |||
1667 | ||||
1668 | pango_attr_list_insert (attrs, attr); | |||
1669 | } | |||
1670 | ||||
1671 | if (style->no_fallback) | |||
1672 | { | |||
1673 | attr = pango_attr_fallback_new (!style->no_fallback); | |||
1674 | attr->start_index = start; | |||
1675 | attr->end_index = start + byte_count; | |||
1676 | ||||
1677 | pango_attr_list_insert (attrs, attr); | |||
1678 | } | |||
1679 | ||||
1680 | if (style->letter_spacing != 0) | |||
1681 | { | |||
1682 | attr = pango_attr_letter_spacing_new (style->letter_spacing); | |||
1683 | attr->start_index = start; | |||
1684 | attr->end_index = start + byte_count; | |||
1685 | ||||
1686 | pango_attr_list_insert (attrs, attr); | |||
1687 | } | |||
1688 | ||||
1689 | if (style->font_features) | |||
1690 | { | |||
1691 | attr = pango_attr_font_features_new (style->font_features); | |||
1692 | attr->start_index = start; | |||
1693 | attr->end_index = start + byte_count; | |||
1694 | ||||
1695 | pango_attr_list_insert (attrs, attr); | |||
1696 | } | |||
1697 | } | |||
1698 | ||||
1699 | static void | |||
1700 | add_pixbuf_attrs (CtkTextLayout *layout G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1701 | CtkTextLineDisplay *display G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1702 | CtkTextAttributes *style G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1703 | CtkTextLineSegment *seg, | |||
1704 | PangoAttrList *attrs, | |||
1705 | gint start) | |||
1706 | { | |||
1707 | PangoAttribute *attr; | |||
1708 | PangoRectangle logical_rect; | |||
1709 | CtkTextPixbuf *pixbuf = &seg->body.pixbuf; | |||
1710 | gint width, height; | |||
1711 | ||||
1712 | width = gdk_pixbuf_get_width (pixbuf->pixbuf); | |||
1713 | height = gdk_pixbuf_get_height (pixbuf->pixbuf); | |||
1714 | ||||
1715 | logical_rect.x = 0; | |||
1716 | logical_rect.y = -height * PANGO_SCALE1024; | |||
1717 | logical_rect.width = width * PANGO_SCALE1024; | |||
1718 | logical_rect.height = height * PANGO_SCALE1024; | |||
1719 | ||||
1720 | attr = pango_attr_shape_new_with_data (&logical_rect, &logical_rect, | |||
1721 | pixbuf->pixbuf, NULL((void*)0), NULL((void*)0)); | |||
1722 | attr->start_index = start; | |||
1723 | attr->end_index = start + seg->byte_count; | |||
1724 | pango_attr_list_insert (attrs, attr); | |||
1725 | } | |||
1726 | ||||
1727 | static void | |||
1728 | add_child_attrs (CtkTextLayout *layout, | |||
1729 | CtkTextLineDisplay *display G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1730 | CtkTextAttributes *style G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
1731 | CtkTextLineSegment *seg, | |||
1732 | PangoAttrList *attrs, | |||
1733 | gint start) | |||
1734 | { | |||
1735 | PangoAttribute *attr; | |||
1736 | PangoRectangle logical_rect; | |||
1737 | gint width, height; | |||
1738 | GSList *tmp_list; | |||
1739 | CtkWidget *widget = NULL((void*)0); | |||
1740 | ||||
1741 | width = 1; | |||
1742 | height = 1; | |||
1743 | ||||
1744 | tmp_list = seg->body.child.widgets; | |||
1745 | while (tmp_list != NULL((void*)0)) | |||
1746 | { | |||
1747 | CtkWidget *child = tmp_list->data; | |||
1748 | ||||
1749 | if (_ctk_anchored_child_get_layout (child) == layout) | |||
1750 | { | |||
1751 | /* Found it */ | |||
1752 | CtkRequisition req; | |||
1753 | ||||
1754 | ctk_widget_get_preferred_size (child, &req, NULL((void*)0)); | |||
1755 | ||||
1756 | width = req.width; | |||
1757 | height = req.height; | |||
1758 | ||||
1759 | widget = child; | |||
1760 | ||||
1761 | break; | |||
1762 | } | |||
1763 | ||||
1764 | tmp_list = tmp_list->next; | |||
1765 | } | |||
1766 | ||||
1767 | if (tmp_list == NULL((void*)0)) | |||
1768 | { | |||
1769 | /* If tmp_list == NULL then there is no widget at this anchor in | |||
1770 | * this display; not an error. We make up an arbitrary size | |||
1771 | * to use, just so the programmer can see the blank spot. | |||
1772 | * We also put a NULL in the shaped objects list, to keep | |||
1773 | * the correspondence between the list and the shaped chars in | |||
1774 | * the layout. A bad hack, yes. | |||
1775 | */ | |||
1776 | ||||
1777 | width = 30; | |||
1778 | height = 20; | |||
1779 | ||||
1780 | widget = NULL((void*)0); | |||
1781 | } | |||
1782 | ||||
1783 | logical_rect.x = 0; | |||
1784 | logical_rect.y = -height * PANGO_SCALE1024; | |||
1785 | logical_rect.width = width * PANGO_SCALE1024; | |||
1786 | logical_rect.height = height * PANGO_SCALE1024; | |||
1787 | ||||
1788 | attr = pango_attr_shape_new_with_data (&logical_rect, &logical_rect, | |||
1789 | widget, NULL((void*)0), NULL((void*)0)); | |||
1790 | attr->start_index = start; | |||
1791 | attr->end_index = start + seg->byte_count; | |||
1792 | pango_attr_list_insert (attrs, attr); | |||
1793 | } | |||
1794 | ||||
1795 | /* | |||
1796 | * get_block_cursor: | |||
1797 | * @layout: a #CtkTextLayout | |||
1798 | * @display: a #CtkTextLineDisplay | |||
1799 | * @insert_iter: iter pointing to the cursor location | |||
1800 | * @insert_index: cursor offset in the @display’s layout, it may | |||
1801 | * be different from @insert_iter’s offset in case when preedit | |||
1802 | * string is present. | |||
1803 | * @pos: location to store cursor position | |||
1804 | * @cursor_at_line_end: whether cursor is at the end of line | |||
1805 | * | |||
1806 | * Checks whether layout should display block cursor at given position. | |||
1807 | * For this layout must be in overwrite mode and text at @insert_iter | |||
1808 | * must be editable. | |||
1809 | */ | |||
1810 | static gboolean | |||
1811 | get_block_cursor (CtkTextLayout *layout, | |||
1812 | CtkTextLineDisplay *display, | |||
1813 | const CtkTextIter *insert_iter, | |||
1814 | gint insert_index, | |||
1815 | CdkRectangle *pos, | |||
1816 | gboolean *cursor_at_line_end) | |||
1817 | { | |||
1818 | PangoRectangle pango_pos; | |||
1819 | ||||
1820 | if (layout->overwrite_mode && | |||
1821 | ctk_text_iter_editable (insert_iter, TRUE(!(0))) && | |||
1822 | _ctk_text_util_get_block_cursor_location (display->layout, | |||
1823 | insert_index, | |||
1824 | &pango_pos, | |||
1825 | cursor_at_line_end)) | |||
1826 | { | |||
1827 | if (pos) | |||
1828 | { | |||
1829 | pos->x = PANGO_PIXELS (pango_pos.x)(((int)(pango_pos.x) + 512) >> 10); | |||
1830 | pos->y = PANGO_PIXELS (pango_pos.y)(((int)(pango_pos.y) + 512) >> 10); | |||
1831 | pos->width = PANGO_PIXELS (pango_pos.width)(((int)(pango_pos.width) + 512) >> 10); | |||
1832 | pos->height = PANGO_PIXELS (pango_pos.height)(((int)(pango_pos.height) + 512) >> 10); | |||
1833 | } | |||
1834 | ||||
1835 | return TRUE(!(0)); | |||
1836 | } | |||
1837 | else | |||
1838 | return FALSE(0); | |||
1839 | } | |||
1840 | ||||
1841 | static void | |||
1842 | add_cursor (CtkTextLayout *layout, | |||
1843 | CtkTextLineDisplay *display, | |||
1844 | CtkTextLineSegment *seg, | |||
1845 | gint start) | |||
1846 | { | |||
1847 | /* Hide insertion cursor when we have a selection or the layout | |||
1848 | * user has hidden the cursor. | |||
1849 | */ | |||
1850 | if (_ctk_text_btree_mark_is_insert (_ctk_text_buffer_get_btree (layout->buffer), | |||
1851 | seg->body.mark.obj) && | |||
1852 | (!layout->cursor_visible || | |||
1853 | ctk_text_buffer_get_selection_bounds (layout->buffer, NULL((void*)0), NULL((void*)0)))) | |||
1854 | return; | |||
1855 | ||||
1856 | if (layout->overwrite_mode && | |||
1857 | _ctk_text_btree_mark_is_insert (_ctk_text_buffer_get_btree (layout->buffer), | |||
1858 | seg->body.mark.obj)) | |||
1859 | { | |||
1860 | CtkTextIter iter; | |||
1861 | gboolean cursor_at_line_end; | |||
1862 | ||||
1863 | _ctk_text_btree_get_iter_at_mark (_ctk_text_buffer_get_btree (layout->buffer), | |||
1864 | &iter, seg->body.mark.obj); | |||
1865 | ||||
1866 | if (get_block_cursor (layout, display, &iter, start, | |||
1867 | &display->block_cursor, | |||
1868 | &cursor_at_line_end)) | |||
1869 | { | |||
1870 | display->has_block_cursor = TRUE(!(0)); | |||
1871 | display->cursor_at_line_end = cursor_at_line_end; | |||
1872 | return; | |||
1873 | } | |||
1874 | } | |||
1875 | ||||
1876 | if (!display->cursors) | |||
1877 | display->cursors = g_array_new (FALSE(0), FALSE(0), sizeof(int)); | |||
1878 | ||||
1879 | display->cursors = g_array_append_val (display->cursors, start)g_array_append_vals (display->cursors, &(start), 1); | |||
1880 | } | |||
1881 | ||||
1882 | static gboolean | |||
1883 | is_shape (PangoLayoutRun *run) | |||
1884 | { | |||
1885 | GSList *tmp_list = run->item->analysis.extra_attrs; | |||
1886 | ||||
1887 | while (tmp_list) | |||
1888 | { | |||
1889 | PangoAttribute *attr = tmp_list->data; | |||
1890 | ||||
1891 | if (attr->klass->type == PANGO_ATTR_SHAPE) | |||
1892 | return TRUE(!(0)); | |||
1893 | ||||
1894 | tmp_list = tmp_list->next; | |||
1895 | } | |||
1896 | ||||
1897 | return FALSE(0); | |||
1898 | } | |||
1899 | ||||
1900 | static void | |||
1901 | allocate_child_widgets (CtkTextLayout *text_layout, | |||
1902 | CtkTextLineDisplay *display) | |||
1903 | { | |||
1904 | PangoLayout *layout = display->layout; | |||
1905 | PangoLayoutIter *run_iter; | |||
1906 | ||||
1907 | run_iter = pango_layout_get_iter (layout); | |||
1908 | do | |||
1909 | { | |||
1910 | PangoLayoutRun *run = pango_layout_iter_get_run_readonly (run_iter); | |||
1911 | ||||
1912 | if (run && is_shape (run)) | |||
1913 | { | |||
1914 | gint byte_index; | |||
1915 | CtkTextIter text_iter; | |||
1916 | CtkTextChildAnchor *anchor = NULL((void*)0); | |||
1917 | GList *widgets = NULL((void*)0); | |||
1918 | GList *l; | |||
1919 | ||||
1920 | /* The pango iterator iterates in visual order. | |||
1921 | * We use the byte index to find the child widget. | |||
1922 | */ | |||
1923 | byte_index = pango_layout_iter_get_index (run_iter); | |||
1924 | line_display_index_to_iter (text_layout, display, &text_iter, byte_index, 0); | |||
1925 | anchor = ctk_text_iter_get_child_anchor (&text_iter); | |||
1926 | if (anchor) | |||
1927 | widgets = ctk_text_child_anchor_get_widgets (anchor); | |||
1928 | ||||
1929 | for (l = widgets; l; l = l->next) | |||
1930 | { | |||
1931 | PangoRectangle extents; | |||
1932 | CtkWidget *child = l->data; | |||
1933 | ||||
1934 | if (_ctk_anchored_child_get_layout (child) == text_layout) | |||
1935 | { | |||
1936 | ||||
1937 | /* We emit "allocate_child" with the x,y of | |||
1938 | * the widget with respect to the top of the line | |||
1939 | * and the left side of the buffer | |||
1940 | */ | |||
1941 | pango_layout_iter_get_run_extents (run_iter, | |||
1942 | NULL((void*)0), | |||
1943 | &extents); | |||
1944 | ||||
1945 | g_signal_emit (text_layout, | |||
1946 | signals[ALLOCATE_CHILD], | |||
1947 | 0, | |||
1948 | child, | |||
1949 | PANGO_PIXELS (extents.x)(((int)(extents.x) + 512) >> 10) + display->x_offset, | |||
1950 | PANGO_PIXELS (extents.y)(((int)(extents.y) + 512) >> 10) + display->top_margin); | |||
1951 | } | |||
1952 | } | |||
1953 | ||||
1954 | g_list_free (widgets); | |||
1955 | } | |||
1956 | } | |||
1957 | while (pango_layout_iter_next_run (run_iter)); | |||
1958 | ||||
1959 | pango_layout_iter_free (run_iter); | |||
1960 | } | |||
1961 | ||||
1962 | static void | |||
1963 | convert_color (CdkRGBA *result, | |||
1964 | PangoAttrColor *attr) | |||
1965 | { | |||
1966 | result->red = attr->color.red / 65535.; | |||
1967 | result->blue = attr->color.blue / 65535.; | |||
1968 | result->green = attr->color.green / 65535.; | |||
1969 | result->alpha = 1; | |||
1970 | } | |||
1971 | ||||
1972 | /* This function is used to convert the preedit string attributes, which are | |||
1973 | * standard PangoAttributes, into the custom attributes used by the text | |||
1974 | * widget and insert them into a attr list with a given offset. | |||
1975 | */ | |||
1976 | static void | |||
1977 | add_preedit_attrs (CtkTextLayout *layout, | |||
1978 | CtkTextAttributes *style, | |||
1979 | PangoAttrList *attrs, | |||
1980 | gint offset, | |||
1981 | gboolean size_only) | |||
1982 | { | |||
1983 | PangoAttrIterator *iter = pango_attr_list_get_iterator (layout->preedit_attrs); | |||
1984 | ||||
1985 | do | |||
1986 | { | |||
1987 | CtkTextAppearance appearance = style->appearance; | |||
1988 | PangoFontDescription *font_desc = pango_font_description_copy_static (style->font); | |||
1989 | PangoAttribute *insert_attr; | |||
1990 | GSList *extra_attrs = NULL((void*)0); | |||
1991 | GSList *tmp_list; | |||
1992 | PangoLanguage *language; | |||
1993 | gint start, end; | |||
1994 | ||||
1995 | pango_attr_iterator_range (iter, &start, &end); | |||
1996 | ||||
1997 | if (end == G_MAXINT2147483647) | |||
1998 | end = layout->preedit_len; | |||
1999 | ||||
2000 | if (end == start) | |||
2001 | continue; | |||
2002 | ||||
2003 | pango_attr_iterator_get_font (iter, font_desc, &language, &extra_attrs); | |||
2004 | ||||
2005 | if (appearance.rgba[0]) | |||
2006 | appearance.rgba[0] = cdk_rgba_copy (appearance.rgba[0]); | |||
2007 | if (appearance.rgba[1]) | |||
2008 | appearance.rgba[1] = cdk_rgba_copy (appearance.rgba[1]); | |||
2009 | ||||
2010 | tmp_list = extra_attrs; | |||
2011 | while (tmp_list) | |||
2012 | { | |||
2013 | PangoAttribute *attr = tmp_list->data; | |||
2014 | CdkRGBA rgba; | |||
2015 | ||||
2016 | switch (attr->klass->type) | |||
2017 | { | |||
2018 | case PANGO_ATTR_FOREGROUND: | |||
2019 | convert_color (&rgba, (PangoAttrColor *)attr); | |||
2020 | if (appearance.rgba[1]) | |||
2021 | cdk_rgba_free (appearance.rgba[1]); | |||
2022 | appearance.rgba[1] = cdk_rgba_copy (&rgba); | |||
2023 | break; | |||
2024 | case PANGO_ATTR_BACKGROUND: | |||
2025 | convert_color (&rgba, (PangoAttrColor *)attr); | |||
2026 | if (appearance.rgba[0]) | |||
2027 | cdk_rgba_free (appearance.rgba[0]); | |||
2028 | appearance.rgba[0] = cdk_rgba_copy (&rgba); | |||
2029 | appearance.draw_bg = TRUE(!(0)); | |||
2030 | break; | |||
2031 | case PANGO_ATTR_UNDERLINE: | |||
2032 | appearance.underline = ((PangoAttrInt *)attr)->value; | |||
2033 | break; | |||
2034 | case PANGO_ATTR_UNDERLINE_COLOR: | |||
2035 | convert_color (&rgba, (PangoAttrColor*)attr); | |||
2036 | CTK_TEXT_APPEARANCE_SET_UNDERLINE_RGBA_SET (&appearance, TRUE)do { ((guint8*)&(&appearance)->bg_color)[3] = !!(! (0)); } while (0); | |||
2037 | CTK_TEXT_APPEARANCE_SET_UNDERLINE_RGBA (&appearance, &rgba)do { ((guint8*)&(&appearance)->bg_color)[0] = (& rgba)->red * 255; ((guint8*)&(&appearance)->bg_color )[1] = (&rgba)->green * 255; ((guint8*)&(&appearance )->bg_color)[2] = (&rgba)->blue * 255; } while (0); | |||
2038 | break; | |||
2039 | case PANGO_ATTR_STRIKETHROUGH: | |||
2040 | appearance.strikethrough = ((PangoAttrInt *)attr)->value; | |||
2041 | break; | |||
2042 | case PANGO_ATTR_STRIKETHROUGH_COLOR: | |||
2043 | convert_color (&rgba, (PangoAttrColor*)attr); | |||
2044 | CTK_TEXT_APPEARANCE_SET_STRIKETHROUGH_RGBA_SET (&appearance, TRUE)do { ((guint8*)&(&appearance)->fg_color)[3] = !!(! (0)); } while (0); | |||
2045 | CTK_TEXT_APPEARANCE_SET_STRIKETHROUGH_RGBA (&appearance, &rgba)do { ((guint8*)&(&appearance)->fg_color)[0] = (& rgba)->red * 255; ((guint8*)&(&appearance)->fg_color )[1] = (&rgba)->green * 255; ((guint8*)&(&appearance )->fg_color)[2] = (&rgba)->blue * 255; } while (0); | |||
2046 | case PANGO_ATTR_RISE: | |||
2047 | appearance.rise = ((PangoAttrInt *)attr)->value; | |||
2048 | break; | |||
2049 | default: | |||
2050 | break; | |||
2051 | } | |||
2052 | ||||
2053 | pango_attribute_destroy (attr); | |||
2054 | tmp_list = tmp_list->next; | |||
2055 | } | |||
2056 | ||||
2057 | g_slist_free (extra_attrs); | |||
2058 | ||||
2059 | insert_attr = pango_attr_font_desc_new (font_desc); | |||
2060 | insert_attr->start_index = start + offset; | |||
2061 | insert_attr->end_index = end + offset; | |||
2062 | ||||
2063 | pango_attr_list_insert (attrs, insert_attr); | |||
2064 | ||||
2065 | if (language) | |||
2066 | { | |||
2067 | insert_attr = pango_attr_language_new (language); | |||
2068 | insert_attr->start_index = start + offset; | |||
2069 | insert_attr->end_index = end + offset; | |||
2070 | ||||
2071 | pango_attr_list_insert (attrs, insert_attr); | |||
2072 | } | |||
2073 | ||||
2074 | add_generic_attrs (layout, &appearance, end - start, | |||
2075 | attrs, start + offset, | |||
2076 | size_only, TRUE(!(0))); | |||
2077 | ||||
2078 | if (appearance.rgba[0]) | |||
2079 | cdk_rgba_free (appearance.rgba[0]); | |||
2080 | if (appearance.rgba[1]) | |||
2081 | cdk_rgba_free (appearance.rgba[1]); | |||
2082 | ||||
2083 | pango_font_description_free (font_desc); | |||
2084 | } | |||
2085 | while (pango_attr_iterator_next (iter)); | |||
2086 | ||||
2087 | pango_attr_iterator_destroy (iter); | |||
2088 | } | |||
2089 | ||||
2090 | /* Iterate over the line and fill in display->cursors. | |||
2091 | * It’s a stripped copy of ctk_text_layout_get_line_display() */ | |||
2092 | static void | |||
2093 | update_text_display_cursors (CtkTextLayout *layout, | |||
2094 | CtkTextLine *line, | |||
2095 | CtkTextLineDisplay *display) | |||
2096 | { | |||
2097 | CtkTextLineSegment *seg; | |||
2098 | CtkTextIter iter; | |||
2099 | gint layout_byte_offset, buffer_byte_offset; | |||
2100 | GSList *cursor_byte_offsets = NULL((void*)0); | |||
2101 | GSList *cursor_segs = NULL((void*)0); | |||
2102 | GSList *tmp_list1, *tmp_list2; | |||
2103 | ||||
2104 | if (!display->cursors_invalid) | |||
2105 | return; | |||
2106 | ||||
2107 | display->cursors_invalid = FALSE(0); | |||
2108 | ||||
2109 | /* Special-case optimization for completely | |||
2110 | * invisible lines; makes it faster to deal | |||
2111 | * with sequences of invisible lines. | |||
2112 | */ | |||
2113 | if (totally_invisible_line (layout, line, &iter)) | |||
2114 | return; | |||
2115 | ||||
2116 | /* Iterate over segments */ | |||
2117 | layout_byte_offset = 0; /* position in the layout text (includes preedit, does not include invisible text) */ | |||
2118 | buffer_byte_offset = 0; /* position in the buffer line */ | |||
2119 | seg = _ctk_text_iter_get_any_segment (&iter); | |||
2120 | while (seg != NULL((void*)0)) | |||
2121 | { | |||
2122 | /* Displayable segments */ | |||
2123 | if (seg->type == &ctk_text_char_type || | |||
2124 | seg->type == &ctk_text_pixbuf_type || | |||
2125 | seg->type == &ctk_text_child_type) | |||
2126 | { | |||
2127 | ctk_text_layout_get_iter_at_line (layout, &iter, line, | |||
2128 | buffer_byte_offset); | |||
2129 | ||||
2130 | if (!_ctk_text_btree_char_is_invisible (&iter)) | |||
2131 | layout_byte_offset += seg->byte_count; | |||
2132 | ||||
2133 | buffer_byte_offset += seg->byte_count; | |||
2134 | } | |||
2135 | ||||
2136 | /* Marks */ | |||
2137 | else if (seg->type == &ctk_text_right_mark_type || | |||
2138 | seg->type == &ctk_text_left_mark_type) | |||
2139 | { | |||
2140 | gint cursor_offset = 0; | |||
2141 | ||||
2142 | /* At the insertion point, add the preedit string, if any */ | |||
2143 | ||||
2144 | if (_ctk_text_btree_mark_is_insert (_ctk_text_buffer_get_btree (layout->buffer), | |||
2145 | seg->body.mark.obj)) | |||
2146 | { | |||
2147 | display->insert_index = layout_byte_offset; | |||
2148 | ||||
2149 | if (layout->preedit_len > 0) | |||
2150 | { | |||
2151 | layout_byte_offset += layout->preedit_len; | |||
2152 | /* DO NOT increment the buffer byte offset for preedit */ | |||
2153 | cursor_offset = layout->preedit_cursor - layout->preedit_len; | |||
2154 | } | |||
2155 | } | |||
2156 | ||||
2157 | /* Display visible marks */ | |||
2158 | ||||
2159 | if (seg->body.mark.visible) | |||
2160 | { | |||
2161 | cursor_byte_offsets = g_slist_prepend (cursor_byte_offsets, | |||
2162 | GINT_TO_POINTER (layout_byte_offset + cursor_offset)((gpointer) (glong) (layout_byte_offset + cursor_offset))); | |||
2163 | cursor_segs = g_slist_prepend (cursor_segs, seg); | |||
2164 | } | |||
2165 | } | |||
2166 | ||||
2167 | /* Toggles */ | |||
2168 | else if (seg->type == &ctk_text_toggle_on_type || | |||
2169 | seg->type == &ctk_text_toggle_off_type) | |||
2170 | { | |||
2171 | } | |||
2172 | ||||
2173 | else | |||
2174 | g_error ("Unknown segment type: %s", seg->type->name); | |||
2175 | ||||
2176 | seg = seg->next; | |||
2177 | } | |||
2178 | ||||
2179 | tmp_list1 = cursor_byte_offsets; | |||
2180 | tmp_list2 = cursor_segs; | |||
2181 | while (tmp_list1) | |||
2182 | { | |||
2183 | add_cursor (layout, display, tmp_list2->data, | |||
2184 | GPOINTER_TO_INT (tmp_list1->data)((gint) (glong) (tmp_list1->data))); | |||
2185 | tmp_list1 = tmp_list1->next; | |||
2186 | tmp_list2 = tmp_list2->next; | |||
2187 | } | |||
2188 | g_slist_free (cursor_byte_offsets); | |||
2189 | g_slist_free (cursor_segs); | |||
2190 | } | |||
2191 | ||||
2192 | /* Same as _ctk_text_btree_get_tags(), except it returns GPtrArray, | |||
2193 | * to be used in ctk_text_layout_get_line_display(). */ | |||
2194 | static GPtrArray * | |||
2195 | get_tags_array_at_iter (CtkTextIter *iter) | |||
2196 | { | |||
2197 | CtkTextTag **tags; | |||
2198 | GPtrArray *array = NULL((void*)0); | |||
2199 | gint n_tags; | |||
2200 | ||||
2201 | tags = _ctk_text_btree_get_tags (iter, &n_tags); | |||
2202 | ||||
2203 | if (n_tags > 0) | |||
2204 | { | |||
2205 | array = g_ptr_array_sized_new (n_tags); | |||
2206 | g_ptr_array_set_size (array, n_tags); | |||
2207 | memcpy (array->pdata, tags, n_tags * sizeof (CtkTextTag*)); | |||
2208 | } | |||
2209 | ||||
2210 | g_free (tags); | |||
2211 | return array; | |||
2212 | } | |||
2213 | ||||
2214 | /* Add the tag to the array if it's not there already, and remove | |||
2215 | * it otherwise. It keeps the array sorted by tags priority. */ | |||
2216 | static GPtrArray * | |||
2217 | tags_array_toggle_tag (GPtrArray *array, | |||
2218 | CtkTextTag *tag) | |||
2219 | { | |||
2220 | gint pos; | |||
2221 | CtkTextTag **tags; | |||
2222 | ||||
2223 | if (array == NULL((void*)0)) | |||
2224 | array = g_ptr_array_new (); | |||
2225 | ||||
2226 | tags = (CtkTextTag**) array->pdata; | |||
2227 | ||||
2228 | for (pos = 0; pos < array->len && tags[pos]->priv->priority < tag->priv->priority; pos++) ; | |||
2229 | ||||
2230 | if (pos < array->len && tags[pos] == tag) | |||
2231 | g_ptr_array_remove_index (array, pos); | |||
2232 | else | |||
2233 | { | |||
2234 | g_ptr_array_set_size (array, array->len + 1); | |||
2235 | if (pos < array->len - 1) | |||
2236 | memmove (array->pdata + pos + 1, array->pdata + pos, | |||
2237 | (array->len - pos - 1) * sizeof (CtkTextTag*)); | |||
2238 | array->pdata[pos] = tag; | |||
2239 | } | |||
2240 | ||||
2241 | return array; | |||
2242 | } | |||
2243 | ||||
2244 | CtkTextLineDisplay * | |||
2245 | ctk_text_layout_get_line_display (CtkTextLayout *layout, | |||
2246 | CtkTextLine *line, | |||
2247 | gboolean size_only) | |||
2248 | { | |||
2249 | CtkTextLayoutPrivate *priv = CTK_TEXT_LAYOUT_GET_PRIVATE (layout)((CtkTextLayoutPrivate *) ctk_text_layout_get_instance_private ((layout))); | |||
2250 | CtkTextLineDisplay *display; | |||
2251 | CtkTextLineSegment *seg; | |||
2252 | CtkTextIter iter; | |||
2253 | CtkTextAttributes *style; | |||
2254 | gchar *text; | |||
2255 | gint text_pixel_width; | |||
2256 | PangoAttrList *attrs; | |||
2257 | gint text_allocated, layout_byte_offset, buffer_byte_offset; | |||
2258 | PangoRectangle extents; | |||
2259 | gboolean para_values_set = FALSE(0); | |||
2260 | GSList *cursor_byte_offsets = NULL((void*)0); | |||
2261 | GSList *cursor_segs = NULL((void*)0); | |||
2262 | GSList *tmp_list1, *tmp_list2; | |||
2263 | gboolean saw_widget = FALSE(0); | |||
2264 | PangoDirection base_dir; | |||
2265 | GPtrArray *tags; | |||
2266 | gboolean initial_toggle_segments; | |||
2267 | gint h_margin; | |||
2268 | gint h_padding; | |||
2269 | ||||
2270 | g_return_val_if_fail (line != NULL, NULL)do { if ((line != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "line != NULL"); return ( ((void*)0)); } } while (0); | |||
| ||||
2271 | ||||
2272 | if (layout->one_display_cache) | |||
2273 | { | |||
2274 | if (line == layout->one_display_cache->line && | |||
2275 | (size_only || !layout->one_display_cache->size_only)) | |||
2276 | { | |||
2277 | if (!size_only) | |||
2278 | update_text_display_cursors (layout, line, layout->one_display_cache); | |||
2279 | return layout->one_display_cache; | |||
2280 | } | |||
2281 | else | |||
2282 | { | |||
2283 | CtkTextLineDisplay *tmp_display = layout->one_display_cache; | |||
2284 | layout->one_display_cache = NULL((void*)0); | |||
2285 | ctk_text_layout_free_line_display (layout, tmp_display); | |||
2286 | } | |||
2287 | } | |||
2288 | ||||
2289 | DV (g_print ("creating one line display cache (%s)\n", G_STRLOC)); | |||
2290 | ||||
2291 | display = g_slice_new0 (CtkTextLineDisplay)((CtkTextLineDisplay*) g_slice_alloc0 (sizeof (CtkTextLineDisplay ))); | |||
2292 | ||||
2293 | display->size_only = size_only; | |||
2294 | display->line = line; | |||
2295 | display->insert_index = -1; | |||
2296 | ||||
2297 | /* Special-case optimization for completely | |||
2298 | * invisible lines; makes it faster to deal | |||
2299 | * with sequences of invisible lines. | |||
2300 | */ | |||
2301 | if (totally_invisible_line (layout, line, &iter)) | |||
2302 | { | |||
2303 | if (display->direction == CTK_TEXT_DIR_RTL) | |||
2304 | display->layout = pango_layout_new (layout->rtl_context); | |||
2305 | else | |||
2306 | display->layout = pango_layout_new (layout->ltr_context); | |||
2307 | ||||
2308 | return display; | |||
2309 | } | |||
2310 | ||||
2311 | /* Find the bidi base direction */ | |||
2312 | base_dir = line->dir_propagated_forward; | |||
2313 | if (base_dir == PANGO_DIRECTION_NEUTRAL) | |||
2314 | base_dir = line->dir_propagated_back; | |||
2315 | ||||
2316 | if (line == priv->cursor_line && | |||
2317 | line->dir_strong == PANGO_DIRECTION_NEUTRAL) | |||
2318 | { | |||
2319 | base_dir = (layout->keyboard_direction == CTK_TEXT_DIR_LTR) ? | |||
2320 | PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL; | |||
2321 | } | |||
2322 | ||||
2323 | /* Allocate space for flat text for buffer | |||
2324 | */ | |||
2325 | text_allocated = _ctk_text_line_byte_count (line); | |||
2326 | text = g_malloc (text_allocated); | |||
2327 | ||||
2328 | attrs = pango_attr_list_new (); | |||
2329 | ||||
2330 | /* Iterate over segments, creating display chunks for them, and updating the tags array. */ | |||
2331 | layout_byte_offset = 0; /* current length of layout text (includes preedit, does not include invisible text) */ | |||
2332 | buffer_byte_offset = 0; /* position in the buffer line */ | |||
2333 | seg = _ctk_text_iter_get_any_segment (&iter); | |||
2334 | tags = get_tags_array_at_iter (&iter); | |||
2335 | initial_toggle_segments = TRUE(!(0)); | |||
2336 | while (seg != NULL((void*)0)) | |||
2337 | { | |||
2338 | /* Displayable segments */ | |||
2339 | if (seg->type == &ctk_text_char_type || | |||
2340 | seg->type == &ctk_text_pixbuf_type || | |||
2341 | seg->type == &ctk_text_child_type) | |||
2342 | { | |||
2343 | style = get_style (layout, tags); | |||
2344 | initial_toggle_segments = FALSE(0); | |||
2345 | ||||
2346 | /* We have to delay setting the paragraph values until we | |||
2347 | * hit the first pixbuf or text segment because toggles at | |||
2348 | * the beginning of the paragraph should affect the | |||
2349 | * paragraph-global values | |||
2350 | */ | |||
2351 | if (!para_values_set
| |||
2352 | { | |||
2353 | set_para_values (layout, base_dir, style, display); | |||
2354 | para_values_set = TRUE(!(0)); | |||
2355 | } | |||
2356 | ||||
2357 | /* First see if the chunk is invisible, and ignore it if so. Tk | |||
2358 | * looked at tabs, wrap mode, etc. before doing this, but | |||
2359 | * that made no sense to me, so I am just skipping the | |||
2360 | * invisible chunks | |||
2361 | */ | |||
2362 | if (!style->invisible) | |||
2363 | { | |||
2364 | if (seg->type == &ctk_text_char_type) | |||
2365 | { | |||
2366 | /* We don't want to split segments because of marks, | |||
2367 | * so we scan forward for more segments only | |||
2368 | * separated from us by marks. In theory, we should | |||
2369 | * also merge segments with identical styles, even | |||
2370 | * if there are toggles in-between | |||
2371 | */ | |||
2372 | ||||
2373 | gint bytes = 0; | |||
2374 | CtkTextLineSegment *prev_seg = NULL((void*)0); | |||
2375 | ||||
2376 | while (seg) | |||
2377 | { | |||
2378 | if (seg->type == &ctk_text_char_type) | |||
2379 | { | |||
2380 | memcpy (text + layout_byte_offset, seg->body.chars, seg->byte_count); | |||
2381 | layout_byte_offset += seg->byte_count; | |||
2382 | buffer_byte_offset += seg->byte_count; | |||
2383 | bytes += seg->byte_count; | |||
2384 | } | |||
2385 | else if (seg->type == &ctk_text_right_mark_type || | |||
2386 | seg->type == &ctk_text_left_mark_type) | |||
2387 | { | |||
2388 | /* If we have preedit string, break out of this loop - we'll almost | |||
2389 | * certainly have different attributes on the preedit string | |||
2390 | */ | |||
2391 | ||||
2392 | if (layout->preedit_len > 0 && | |||
2393 | _ctk_text_btree_mark_is_insert (_ctk_text_buffer_get_btree (layout->buffer), | |||
2394 | seg->body.mark.obj)) | |||
2395 | break; | |||
2396 | ||||
2397 | if (seg->body.mark.visible) | |||
2398 | { | |||
2399 | cursor_byte_offsets = g_slist_prepend (cursor_byte_offsets, GINT_TO_POINTER (layout_byte_offset)((gpointer) (glong) (layout_byte_offset))); | |||
2400 | cursor_segs = g_slist_prepend (cursor_segs, seg); | |||
2401 | if (_ctk_text_btree_mark_is_insert (_ctk_text_buffer_get_btree (layout->buffer), | |||
2402 | seg->body.mark.obj)) | |||
2403 | display->insert_index = layout_byte_offset; | |||
2404 | } | |||
2405 | } | |||
2406 | else | |||
2407 | break; | |||
2408 | ||||
2409 | prev_seg = seg; | |||
2410 | seg = seg->next; | |||
2411 | } | |||
2412 | ||||
2413 | seg = prev_seg; /* Back up one */ | |||
2414 | add_generic_attrs (layout, &style->appearance, | |||
2415 | bytes, | |||
2416 | attrs, layout_byte_offset - bytes, | |||
2417 | size_only, TRUE(!(0))); | |||
2418 | add_text_attrs (layout, style, bytes, attrs, | |||
2419 | layout_byte_offset - bytes, size_only); | |||
2420 | } | |||
2421 | else if (seg->type == &ctk_text_pixbuf_type) | |||
2422 | { | |||
2423 | add_generic_attrs (layout, | |||
2424 | &style->appearance, | |||
2425 | seg->byte_count, | |||
2426 | attrs, layout_byte_offset, | |||
2427 | size_only, FALSE(0)); | |||
2428 | add_pixbuf_attrs (layout, display, style, | |||
2429 | seg, attrs, layout_byte_offset); | |||
2430 | memcpy (text + layout_byte_offset, _ctk_text_unknown_char_utf8, | |||
2431 | seg->byte_count); | |||
2432 | layout_byte_offset += seg->byte_count; | |||
2433 | buffer_byte_offset += seg->byte_count; | |||
2434 | } | |||
2435 | else if (seg->type == &ctk_text_child_type) | |||
2436 | { | |||
2437 | saw_widget = TRUE(!(0)); | |||
2438 | ||||
2439 | add_generic_attrs (layout, &style->appearance, | |||
2440 | seg->byte_count, | |||
2441 | attrs, layout_byte_offset, | |||
2442 | size_only, FALSE(0)); | |||
2443 | add_child_attrs (layout, display, style, | |||
2444 | seg, attrs, layout_byte_offset); | |||
2445 | memcpy (text + layout_byte_offset, _ctk_text_unknown_char_utf8, | |||
2446 | seg->byte_count); | |||
2447 | layout_byte_offset += seg->byte_count; | |||
2448 | buffer_byte_offset += seg->byte_count; | |||
2449 | } | |||
2450 | else | |||
2451 | { | |||
2452 | /* We don't know this segment type */ | |||
2453 | g_assert_not_reached ()do { g_assertion_message_expr ("Ctk", "ctktextlayout.c", 2453 , ((const char*) (__func__)), ((void*)0)); } while (0); | |||
2454 | } | |||
2455 | ||||
2456 | } /* if (segment was visible) */ | |||
2457 | else | |||
2458 | { | |||
2459 | /* Invisible segment */ | |||
2460 | buffer_byte_offset += seg->byte_count; | |||
2461 | } | |||
2462 | ||||
2463 | release_style (layout, style); | |||
2464 | } | |||
2465 | ||||
2466 | /* Toggles */ | |||
2467 | else if (seg->type == &ctk_text_toggle_on_type || | |||
2468 | seg->type == &ctk_text_toggle_off_type) | |||
2469 | { | |||
2470 | /* Style may have changed, drop our | |||
2471 | current cached style */ | |||
2472 | invalidate_cached_style (layout); | |||
2473 | /* Add the tag only after we have seen some non-toggle non-mark segment, | |||
2474 | * otherwise the tag is already accounted for by _ctk_text_btree_get_tags(). */ | |||
2475 | if (!initial_toggle_segments) | |||
2476 | tags = tags_array_toggle_tag (tags, seg->body.toggle.info->tag); | |||
2477 | } | |||
2478 | ||||
2479 | /* Marks */ | |||
2480 | else if (seg->type == &ctk_text_right_mark_type || | |||
2481 | seg->type == &ctk_text_left_mark_type) | |||
2482 | { | |||
2483 | gint cursor_offset = 0; | |||
2484 | ||||
2485 | /* At the insertion point, add the preedit string, if any */ | |||
2486 | ||||
2487 | if (_ctk_text_btree_mark_is_insert (_ctk_text_buffer_get_btree (layout->buffer), | |||
2488 | seg->body.mark.obj)) | |||
2489 | { | |||
2490 | display->insert_index = layout_byte_offset; | |||
2491 | ||||
2492 | if (layout->preedit_len > 0) | |||
2493 | { | |||
2494 | text_allocated += layout->preedit_len; | |||
2495 | text = g_realloc (text, text_allocated); | |||
2496 | ||||
2497 | style = get_style (layout, tags); | |||
2498 | add_preedit_attrs (layout, style, attrs, layout_byte_offset, size_only); | |||
2499 | release_style (layout, style); | |||
2500 | ||||
2501 | memcpy (text + layout_byte_offset, layout->preedit_string, layout->preedit_len); | |||
2502 | layout_byte_offset += layout->preedit_len; | |||
2503 | /* DO NOT increment the buffer byte offset for preedit */ | |||
2504 | ||||
2505 | cursor_offset = layout->preedit_cursor - layout->preedit_len; | |||
2506 | } | |||
2507 | } | |||
2508 | ||||
2509 | ||||
2510 | /* Display visible marks */ | |||
2511 | ||||
2512 | if (seg->body.mark.visible) | |||
2513 | { | |||
2514 | cursor_byte_offsets = g_slist_prepend (cursor_byte_offsets, | |||
2515 | GINT_TO_POINTER (layout_byte_offset + cursor_offset)((gpointer) (glong) (layout_byte_offset + cursor_offset))); | |||
2516 | cursor_segs = g_slist_prepend (cursor_segs, seg); | |||
2517 | } | |||
2518 | } | |||
2519 | ||||
2520 | else | |||
2521 | g_error ("Unknown segment type: %s", seg->type->name); | |||
2522 | ||||
2523 | seg = seg->next; | |||
| ||||
2524 | } | |||
2525 | ||||
2526 | if (!para_values_set) | |||
2527 | { | |||
2528 | style = get_style (layout, tags); | |||
2529 | set_para_values (layout, base_dir, style, display); | |||
2530 | release_style (layout, style); | |||
2531 | } | |||
2532 | ||||
2533 | /* Pango doesn't want the trailing paragraph delimiters */ | |||
2534 | ||||
2535 | { | |||
2536 | /* Only one character has type G_UNICODE_PARAGRAPH_SEPARATOR in | |||
2537 | * Unicode 3.0; update this if that changes. | |||
2538 | */ | |||
2539 | #define PARAGRAPH_SEPARATOR0x2029 0x2029 | |||
2540 | gunichar ch = 0; | |||
2541 | ||||
2542 | if (layout_byte_offset > 0) | |||
2543 | { | |||
2544 | const char *prev = g_utf8_prev_char (text + layout_byte_offset); | |||
2545 | ch = g_utf8_get_char (prev); | |||
2546 | if (ch == PARAGRAPH_SEPARATOR0x2029 || ch == '\r' || ch == '\n') | |||
2547 | layout_byte_offset = prev - text; /* chop off */ | |||
2548 | ||||
2549 | if (ch == '\n' && layout_byte_offset > 0) | |||
2550 | { | |||
2551 | /* Possibly chop a CR as well */ | |||
2552 | prev = g_utf8_prev_char (text + layout_byte_offset); | |||
2553 | if (*prev == '\r') | |||
2554 | --layout_byte_offset; | |||
2555 | } | |||
2556 | } | |||
2557 | } | |||
2558 | ||||
2559 | pango_layout_set_text (display->layout, text, layout_byte_offset); | |||
2560 | pango_layout_set_attributes (display->layout, attrs); | |||
2561 | ||||
2562 | tmp_list1 = cursor_byte_offsets; | |||
2563 | tmp_list2 = cursor_segs; | |||
2564 | while (tmp_list1) | |||
2565 | { | |||
2566 | add_cursor (layout, display, tmp_list2->data, | |||
2567 | GPOINTER_TO_INT (tmp_list1->data)((gint) (glong) (tmp_list1->data))); | |||
2568 | tmp_list1 = tmp_list1->next; | |||
2569 | tmp_list2 = tmp_list2->next; | |||
2570 | } | |||
2571 | g_slist_free (cursor_byte_offsets); | |||
2572 | g_slist_free (cursor_segs); | |||
2573 | ||||
2574 | pango_layout_get_extents (display->layout, NULL((void*)0), &extents); | |||
2575 | ||||
2576 | text_pixel_width = PIXEL_BOUND (extents.width)(((extents.width) + 1024 - 1) / 1024); | |||
2577 | display->width = text_pixel_width + display->left_margin + display->right_margin; | |||
2578 | ||||
2579 | h_margin = display->left_margin + display->right_margin; | |||
2580 | h_padding = layout->left_padding + layout->right_padding; | |||
2581 | ||||
2582 | display->width = text_pixel_width + h_margin + h_padding; | |||
2583 | display->height += PANGO_PIXELS (extents.height)(((int)(extents.height) + 512) >> 10); | |||
2584 | ||||
2585 | /* If we aren't wrapping, we need to do the alignment of each | |||
2586 | * paragraph ourselves. | |||
2587 | */ | |||
2588 | if (pango_layout_get_width (display->layout) < 0) | |||
2589 | { | |||
2590 | gint excess = display->total_width - text_pixel_width; | |||
2591 | ||||
2592 | switch (pango_layout_get_alignment (display->layout)) | |||
2593 | { | |||
2594 | case PANGO_ALIGN_LEFT: | |||
2595 | break; | |||
2596 | case PANGO_ALIGN_CENTER: | |||
2597 | display->x_offset += excess / 2; | |||
2598 | break; | |||
2599 | case PANGO_ALIGN_RIGHT: | |||
2600 | display->x_offset += excess; | |||
2601 | break; | |||
2602 | } | |||
2603 | } | |||
2604 | ||||
2605 | /* Free this if we aren't in a loop */ | |||
2606 | if (layout->wrap_loop_count == 0) | |||
2607 | invalidate_cached_style (layout); | |||
2608 | ||||
2609 | g_free (text); | |||
2610 | pango_attr_list_unref (attrs); | |||
2611 | if (tags != NULL((void*)0)) | |||
2612 | g_ptr_array_free (tags, TRUE(!(0))); | |||
2613 | ||||
2614 | layout->one_display_cache = display; | |||
2615 | ||||
2616 | if (saw_widget) | |||
2617 | allocate_child_widgets (layout, display); | |||
2618 | ||||
2619 | return display; | |||
2620 | } | |||
2621 | ||||
2622 | void | |||
2623 | ctk_text_layout_free_line_display (CtkTextLayout *layout, | |||
2624 | CtkTextLineDisplay *display) | |||
2625 | { | |||
2626 | if (display != layout->one_display_cache) | |||
2627 | { | |||
2628 | if (display->layout) | |||
2629 | g_object_unref (display->layout); | |||
2630 | ||||
2631 | if (display->cursors) | |||
2632 | g_array_free (display->cursors, TRUE(!(0))); | |||
2633 | ||||
2634 | if (display->pg_bg_color) | |||
2635 | cdk_color_free (display->pg_bg_color); | |||
2636 | ||||
2637 | if (display->pg_bg_rgba) | |||
2638 | cdk_rgba_free (display->pg_bg_rgba); | |||
2639 | ||||
2640 | g_slice_free (CtkTextLineDisplay, display)do { if (1) g_slice_free1 (sizeof (CtkTextLineDisplay), (display )); else (void) ((CtkTextLineDisplay*) 0 == (display)); } while (0); | |||
2641 | } | |||
2642 | } | |||
2643 | ||||
2644 | /* Functions to convert iter <=> index for the line of a CtkTextLineDisplay | |||
2645 | * taking into account the preedit string and invisible text if necessary. | |||
2646 | */ | |||
2647 | static gint | |||
2648 | line_display_iter_to_index (CtkTextLayout *layout, | |||
2649 | CtkTextLineDisplay *display, | |||
2650 | const CtkTextIter *iter) | |||
2651 | { | |||
2652 | gint index; | |||
2653 | ||||
2654 | g_return_val_if_fail (_ctk_text_iter_get_text_line (iter) == display->line, 0)do { if ((_ctk_text_iter_get_text_line (iter) == display-> line)) { } else { g_return_if_fail_warning ("Ctk", ((const char *) (__func__)), "_ctk_text_iter_get_text_line (iter) == display->line" ); return (0); } } while (0); | |||
2655 | ||||
2656 | index = ctk_text_iter_get_visible_line_index (iter); | |||
2657 | ||||
2658 | if (layout->preedit_len > 0 && display->insert_index >= 0) | |||
2659 | { | |||
2660 | if (index >= display->insert_index) | |||
2661 | index += layout->preedit_len; | |||
2662 | } | |||
2663 | ||||
2664 | return index; | |||
2665 | } | |||
2666 | ||||
2667 | static void | |||
2668 | line_display_index_to_iter (CtkTextLayout *layout, | |||
2669 | CtkTextLineDisplay *display, | |||
2670 | CtkTextIter *iter, | |||
2671 | gint index, | |||
2672 | gint trailing) | |||
2673 | { | |||
2674 | g_return_if_fail (!_ctk_text_line_is_last (display->line,do { if ((!_ctk_text_line_is_last (display->line, _ctk_text_buffer_get_btree (layout->buffer)))) { } else { g_return_if_fail_warning ( "Ctk", ((const char*) (__func__)), "!_ctk_text_line_is_last (display->line, _ctk_text_buffer_get_btree (layout->buffer))" ); return; } } while (0) | |||
2675 | _ctk_text_buffer_get_btree (layout->buffer)))do { if ((!_ctk_text_line_is_last (display->line, _ctk_text_buffer_get_btree (layout->buffer)))) { } else { g_return_if_fail_warning ( "Ctk", ((const char*) (__func__)), "!_ctk_text_line_is_last (display->line, _ctk_text_buffer_get_btree (layout->buffer))" ); return; } } while (0); | |||
2676 | ||||
2677 | if (layout->preedit_len > 0 && display->insert_index >= 0) | |||
2678 | { | |||
2679 | if (index >= display->insert_index + layout->preedit_len) | |||
2680 | index -= layout->preedit_len; | |||
2681 | else if (index > display->insert_index) | |||
2682 | { | |||
2683 | index = display->insert_index; | |||
2684 | trailing = 0; | |||
2685 | } | |||
2686 | } | |||
2687 | ||||
2688 | ctk_text_layout_get_iter_at_line (layout, iter, display->line, 0); | |||
2689 | ||||
2690 | ctk_text_iter_set_visible_line_index (iter, index); | |||
2691 | ||||
2692 | if (_ctk_text_iter_get_text_line (iter) != display->line) | |||
2693 | { | |||
2694 | /* Clamp to end of line - really this clamping should have been done | |||
2695 | * before here, maybe in Pango, this is a broken band-aid I think | |||
2696 | */ | |||
2697 | ctk_text_layout_get_iter_at_line (layout, iter, display->line, 0); | |||
2698 | if (!ctk_text_iter_ends_line (iter)) | |||
2699 | ctk_text_iter_forward_to_line_end (iter); | |||
2700 | } | |||
2701 | ||||
2702 | ctk_text_iter_forward_chars (iter, trailing); | |||
2703 | } | |||
2704 | ||||
2705 | static void | |||
2706 | get_line_at_y (CtkTextLayout *layout, | |||
2707 | gint y, | |||
2708 | CtkTextLine **line, | |||
2709 | gint *line_top) | |||
2710 | { | |||
2711 | if (y < 0) | |||
2712 | y = 0; | |||
2713 | if (y > layout->height) | |||
2714 | y = layout->height; | |||
2715 | ||||
2716 | *line = _ctk_text_btree_find_line_by_y (_ctk_text_buffer_get_btree (layout->buffer), | |||
2717 | layout, y, line_top); | |||
2718 | if (*line == NULL((void*)0)) | |||
2719 | { | |||
2720 | *line = _ctk_text_btree_get_end_iter_line (_ctk_text_buffer_get_btree (layout->buffer)); | |||
2721 | ||||
2722 | if (line_top) | |||
2723 | *line_top = | |||
2724 | _ctk_text_btree_find_line_top (_ctk_text_buffer_get_btree (layout->buffer), | |||
2725 | *line, layout); | |||
2726 | } | |||
2727 | } | |||
2728 | ||||
2729 | /** | |||
2730 | * ctk_text_layout_get_line_at_y: | |||
2731 | * @layout: a #CtkLayout | |||
2732 | * @target_iter: the iterator in which the result is stored | |||
2733 | * @y: the y positition | |||
2734 | * @line_top: location to store the y coordinate of the | |||
2735 | * top of the line. (Can by %NULL) | |||
2736 | * | |||
2737 | * Get the iter at the beginning of the line which is displayed | |||
2738 | * at the given y. | |||
2739 | */ | |||
2740 | void | |||
2741 | ctk_text_layout_get_line_at_y (CtkTextLayout *layout, | |||
2742 | CtkTextIter *target_iter, | |||
2743 | gint y, | |||
2744 | gint *line_top) | |||
2745 | { | |||
2746 | CtkTextLine *line; | |||
2747 | ||||
2748 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
2749 | g_return_if_fail (target_iter != NULL)do { if ((target_iter != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "target_iter != NULL"); return ; } } while (0); | |||
2750 | ||||
2751 | get_line_at_y (layout, y, &line, line_top); | |||
2752 | ctk_text_layout_get_iter_at_line (layout, target_iter, line, 0); | |||
2753 | } | |||
2754 | ||||
2755 | gboolean | |||
2756 | ctk_text_layout_get_iter_at_pixel (CtkTextLayout *layout, | |||
2757 | CtkTextIter *target_iter, | |||
2758 | gint x, | |||
2759 | gint y) | |||
2760 | { | |||
2761 | gint trailing; | |||
2762 | gboolean inside; | |||
2763 | ||||
2764 | inside = ctk_text_layout_get_iter_at_position (layout, target_iter, &trailing, x, y); | |||
2765 | ||||
2766 | ctk_text_iter_forward_chars (target_iter, trailing); | |||
2767 | ||||
2768 | return inside; | |||
2769 | } | |||
2770 | ||||
2771 | gboolean | |||
2772 | ctk_text_layout_get_iter_at_position (CtkTextLayout *layout, | |||
2773 | CtkTextIter *target_iter, | |||
2774 | gint *trailing, | |||
2775 | gint x, | |||
2776 | gint y) | |||
2777 | { | |||
2778 | CtkTextLine *line; | |||
2779 | gint byte_index; | |||
2780 | gint line_top; | |||
2781 | CtkTextLineDisplay *display; | |||
2782 | gboolean inside; | |||
2783 | ||||
2784 | g_return_val_if_fail (CTK_IS_TEXT_LAYOUT (layout), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return ((0)); } } while ( 0); | |||
2785 | g_return_val_if_fail (target_iter != NULL, FALSE)do { if ((target_iter != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "target_iter != NULL"); return ((0)); } } while (0); | |||
2786 | ||||
2787 | get_line_at_y (layout, y, &line, &line_top); | |||
2788 | ||||
2789 | display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
2790 | ||||
2791 | x -= display->x_offset; | |||
2792 | y -= line_top + display->top_margin; | |||
2793 | ||||
2794 | /* If we are below the layout, position the cursor at the last character | |||
2795 | * of the line. | |||
2796 | */ | |||
2797 | if (y > display->height - display->top_margin - display->bottom_margin) | |||
2798 | { | |||
2799 | byte_index = _ctk_text_line_byte_count (line); | |||
2800 | if (trailing) | |||
2801 | *trailing = 0; | |||
2802 | ||||
2803 | inside = FALSE(0); | |||
2804 | } | |||
2805 | else | |||
2806 | { | |||
2807 | /* Ignore the "outside" return value from pango. Pango is doing | |||
2808 | * the right thing even if we are outside the layout in the | |||
2809 | * x-direction. | |||
2810 | */ | |||
2811 | inside = pango_layout_xy_to_index (display->layout, x * PANGO_SCALE1024, y * PANGO_SCALE1024, | |||
2812 | &byte_index, trailing); | |||
2813 | } | |||
2814 | ||||
2815 | line_display_index_to_iter (layout, display, target_iter, byte_index, 0); | |||
2816 | ||||
2817 | ctk_text_layout_free_line_display (layout, display); | |||
2818 | ||||
2819 | return inside; | |||
2820 | } | |||
2821 | ||||
2822 | ||||
2823 | /** | |||
2824 | * ctk_text_layout_get_cursor_locations: | |||
2825 | * @layout: a #CtkTextLayout | |||
2826 | * @iter: a #CtkTextIter | |||
2827 | * @strong_pos: (out) (optional): location to store the strong cursor position, or %NULL | |||
2828 | * @weak_pos: (out) (optional): location to store the weak cursor position, or %NULL | |||
2829 | * | |||
2830 | * Given an iterator within a text layout, determine the positions of the | |||
2831 | * strong and weak cursors if the insertion point is at that | |||
2832 | * iterator. The position of each cursor is stored as a zero-width | |||
2833 | * rectangle. The strong cursor location is the location where | |||
2834 | * characters of the directionality equal to the base direction of the | |||
2835 | * paragraph are inserted. The weak cursor location is the location | |||
2836 | * where characters of the directionality opposite to the base | |||
2837 | * direction of the paragraph are inserted. | |||
2838 | **/ | |||
2839 | void | |||
2840 | ctk_text_layout_get_cursor_locations (CtkTextLayout *layout, | |||
2841 | CtkTextIter *iter, | |||
2842 | CdkRectangle *strong_pos, | |||
2843 | CdkRectangle *weak_pos) | |||
2844 | { | |||
2845 | CtkTextLine *line; | |||
2846 | CtkTextLineDisplay *display; | |||
2847 | gint line_top; | |||
2848 | gint index; | |||
2849 | CtkTextIter insert_iter; | |||
2850 | ||||
2851 | PangoRectangle pango_strong_pos; | |||
2852 | PangoRectangle pango_weak_pos; | |||
2853 | ||||
2854 | g_return_if_fail (layout != NULL)do { if ((layout != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "layout != NULL"); return ; } } while (0); | |||
2855 | g_return_if_fail (iter != NULL)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "iter != NULL"); return; } } while (0); | |||
2856 | ||||
2857 | line = _ctk_text_iter_get_text_line (iter); | |||
2858 | display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
2859 | index = line_display_iter_to_index (layout, display, iter); | |||
2860 | ||||
2861 | line_top = _ctk_text_btree_find_line_top (_ctk_text_buffer_get_btree (layout->buffer), | |||
2862 | line, layout); | |||
2863 | ||||
2864 | ctk_text_buffer_get_iter_at_mark (layout->buffer, &insert_iter, | |||
2865 | ctk_text_buffer_get_insert (layout->buffer)); | |||
2866 | ||||
2867 | if (ctk_text_iter_equal (iter, &insert_iter)) | |||
2868 | index += layout->preedit_cursor - layout->preedit_len; | |||
2869 | ||||
2870 | pango_layout_get_cursor_pos (display->layout, index, | |||
2871 | strong_pos ? &pango_strong_pos : NULL((void*)0), | |||
2872 | weak_pos ? &pango_weak_pos : NULL((void*)0)); | |||
2873 | ||||
2874 | if (strong_pos) | |||
2875 | { | |||
2876 | strong_pos->x = display->x_offset + pango_strong_pos.x / PANGO_SCALE1024; | |||
2877 | strong_pos->y = line_top + display->top_margin + pango_strong_pos.y / PANGO_SCALE1024; | |||
2878 | strong_pos->width = 0; | |||
2879 | strong_pos->height = pango_strong_pos.height / PANGO_SCALE1024; | |||
2880 | } | |||
2881 | ||||
2882 | if (weak_pos) | |||
2883 | { | |||
2884 | weak_pos->x = display->x_offset + pango_weak_pos.x / PANGO_SCALE1024; | |||
2885 | weak_pos->y = line_top + display->top_margin + pango_weak_pos.y / PANGO_SCALE1024; | |||
2886 | weak_pos->width = 0; | |||
2887 | weak_pos->height = pango_weak_pos.height / PANGO_SCALE1024; | |||
2888 | } | |||
2889 | ||||
2890 | ctk_text_layout_free_line_display (layout, display); | |||
2891 | } | |||
2892 | ||||
2893 | /** | |||
2894 | * _ctk_text_layout_get_block_cursor: | |||
2895 | * @layout: a #CtkTextLayout | |||
2896 | * @pos: a #CdkRectangle to store block cursor position | |||
2897 | * | |||
2898 | * If layout is to display a block cursor, calculates its position | |||
2899 | * and returns %TRUE. Otherwise it returns %FALSE. In case when | |||
2900 | * cursor is visible, it simply returns the position stored in | |||
2901 | * the line display, otherwise it has to compute the position | |||
2902 | * (see get_block_cursor()). | |||
2903 | **/ | |||
2904 | gboolean | |||
2905 | _ctk_text_layout_get_block_cursor (CtkTextLayout *layout, | |||
2906 | CdkRectangle *pos) | |||
2907 | { | |||
2908 | CtkTextLine *line; | |||
2909 | CtkTextLineDisplay *display; | |||
2910 | CtkTextIter iter; | |||
2911 | CdkRectangle rect; | |||
2912 | gboolean block = FALSE(0); | |||
2913 | ||||
2914 | g_return_val_if_fail (layout != NULL, FALSE)do { if ((layout != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "layout != NULL"); return ((0)); } } while (0); | |||
2915 | ||||
2916 | ctk_text_buffer_get_iter_at_mark (layout->buffer, &iter, | |||
2917 | ctk_text_buffer_get_insert (layout->buffer)); | |||
2918 | line = _ctk_text_iter_get_text_line (&iter); | |||
2919 | display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
2920 | ||||
2921 | if (display->has_block_cursor) | |||
2922 | { | |||
2923 | block = TRUE(!(0)); | |||
2924 | rect = display->block_cursor; | |||
2925 | } | |||
2926 | else | |||
2927 | { | |||
2928 | gint index = display->insert_index; | |||
2929 | ||||
2930 | if (index < 0) | |||
2931 | index = ctk_text_iter_get_line_index (&iter); | |||
2932 | ||||
2933 | if (get_block_cursor (layout, display, &iter, index, &rect, NULL((void*)0))) | |||
2934 | block = TRUE(!(0)); | |||
2935 | } | |||
2936 | ||||
2937 | if (block && pos) | |||
2938 | { | |||
2939 | gint line_top; | |||
2940 | ||||
2941 | line_top = _ctk_text_btree_find_line_top (_ctk_text_buffer_get_btree (layout->buffer), | |||
2942 | line, layout); | |||
2943 | ||||
2944 | *pos = rect; | |||
2945 | pos->x += display->x_offset; | |||
2946 | pos->y += line_top + display->top_margin; | |||
2947 | } | |||
2948 | ||||
2949 | ctk_text_layout_free_line_display (layout, display); | |||
2950 | return block; | |||
2951 | } | |||
2952 | ||||
2953 | /** | |||
2954 | * ctk_text_layout_get_line_yrange: | |||
2955 | * @layout: a #CtkTextLayout | |||
2956 | * @iter: a #CtkTextIter | |||
2957 | * @y: location to store the top of the paragraph in pixels, | |||
2958 | * or %NULL. | |||
2959 | * @height location to store the height of the paragraph in pixels, | |||
2960 | * or %NULL. | |||
2961 | * | |||
2962 | * Find the range of y coordinates for the paragraph containing | |||
2963 | * the given iter. | |||
2964 | **/ | |||
2965 | void | |||
2966 | ctk_text_layout_get_line_yrange (CtkTextLayout *layout, | |||
2967 | const CtkTextIter *iter, | |||
2968 | gint *y, | |||
2969 | gint *height) | |||
2970 | { | |||
2971 | CtkTextLine *line; | |||
2972 | ||||
2973 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
2974 | g_return_if_fail (_ctk_text_iter_get_btree (iter) == _ctk_text_buffer_get_btree (layout->buffer))do { if ((_ctk_text_iter_get_btree (iter) == _ctk_text_buffer_get_btree (layout->buffer))) { } else { g_return_if_fail_warning ("Ctk" , ((const char*) (__func__)), "_ctk_text_iter_get_btree (iter) == _ctk_text_buffer_get_btree (layout->buffer)" ); return; } } while (0); | |||
2975 | ||||
2976 | line = _ctk_text_iter_get_text_line (iter); | |||
2977 | ||||
2978 | if (y) | |||
2979 | *y = _ctk_text_btree_find_line_top (_ctk_text_buffer_get_btree (layout->buffer), | |||
2980 | line, layout); | |||
2981 | if (height) | |||
2982 | { | |||
2983 | CtkTextLineData *line_data = _ctk_text_line_get_data (line, layout); | |||
2984 | if (line_data) | |||
2985 | *height = line_data->height; | |||
2986 | else | |||
2987 | *height = 0; | |||
2988 | } | |||
2989 | } | |||
2990 | ||||
2991 | void | |||
2992 | ctk_text_layout_get_iter_location (CtkTextLayout *layout, | |||
2993 | const CtkTextIter *iter, | |||
2994 | CdkRectangle *rect) | |||
2995 | { | |||
2996 | PangoRectangle pango_rect; | |||
2997 | CtkTextLine *line; | |||
2998 | CtkTextBTree *tree; | |||
2999 | CtkTextLineDisplay *display; | |||
3000 | gint byte_index; | |||
3001 | gint x_offset; | |||
3002 | ||||
3003 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
3004 | g_return_if_fail (_ctk_text_iter_get_btree (iter) == _ctk_text_buffer_get_btree (layout->buffer))do { if ((_ctk_text_iter_get_btree (iter) == _ctk_text_buffer_get_btree (layout->buffer))) { } else { g_return_if_fail_warning ("Ctk" , ((const char*) (__func__)), "_ctk_text_iter_get_btree (iter) == _ctk_text_buffer_get_btree (layout->buffer)" ); return; } } while (0); | |||
3005 | g_return_if_fail (rect != NULL)do { if ((rect != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "rect != NULL"); return; } } while (0); | |||
3006 | ||||
3007 | tree = _ctk_text_iter_get_btree (iter); | |||
3008 | line = _ctk_text_iter_get_text_line (iter); | |||
3009 | ||||
3010 | display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
3011 | ||||
3012 | rect->y = _ctk_text_btree_find_line_top (tree, line, layout); | |||
3013 | ||||
3014 | x_offset = display->x_offset * PANGO_SCALE1024; | |||
3015 | ||||
3016 | byte_index = ctk_text_iter_get_line_index (iter); | |||
3017 | ||||
3018 | pango_layout_index_to_pos (display->layout, byte_index, &pango_rect); | |||
3019 | ||||
3020 | rect->x = PANGO_PIXELS (x_offset + pango_rect.x)(((int)(x_offset + pango_rect.x) + 512) >> 10); | |||
3021 | rect->y += PANGO_PIXELS (pango_rect.y)(((int)(pango_rect.y) + 512) >> 10) + display->top_margin; | |||
3022 | rect->width = PANGO_PIXELS (pango_rect.width)(((int)(pango_rect.width) + 512) >> 10); | |||
3023 | rect->height = PANGO_PIXELS (pango_rect.height)(((int)(pango_rect.height) + 512) >> 10); | |||
3024 | ||||
3025 | ctk_text_layout_free_line_display (layout, display); | |||
3026 | } | |||
3027 | ||||
3028 | /* FFIXX */ | |||
3029 | ||||
3030 | /* Find the iter for the logical beginning of the first display line whose | |||
3031 | * top y is >= y. If none exists, move the iter to the logical beginning | |||
3032 | * of the last line in the buffer. | |||
3033 | */ | |||
3034 | static void | |||
3035 | find_display_line_below (CtkTextLayout *layout, | |||
3036 | CtkTextIter *iter, | |||
3037 | gint y) | |||
3038 | { | |||
3039 | CtkTextLine *line, *next; | |||
3040 | CtkTextLine *found_line = NULL((void*)0); | |||
3041 | gint line_top; | |||
3042 | gint found_byte = 0; | |||
3043 | ||||
3044 | line = _ctk_text_btree_find_line_by_y (_ctk_text_buffer_get_btree (layout->buffer), | |||
3045 | layout, y, &line_top); | |||
3046 | if (!line) | |||
3047 | { | |||
3048 | line = | |||
3049 | _ctk_text_btree_get_end_iter_line (_ctk_text_buffer_get_btree (layout->buffer)); | |||
3050 | ||||
3051 | line_top = | |||
3052 | _ctk_text_btree_find_line_top (_ctk_text_buffer_get_btree (layout->buffer), | |||
3053 | line, layout); | |||
3054 | } | |||
3055 | ||||
3056 | while (line && !found_line) | |||
3057 | { | |||
3058 | CtkTextLineDisplay *display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
3059 | PangoLayoutIter *layout_iter; | |||
3060 | ||||
3061 | layout_iter = pango_layout_get_iter (display->layout); | |||
3062 | ||||
3063 | line_top += display->top_margin; | |||
3064 | ||||
3065 | do | |||
3066 | { | |||
3067 | gint first_y, last_y; | |||
3068 | PangoLayoutLine *layout_line = pango_layout_iter_get_line_readonly (layout_iter); | |||
3069 | ||||
3070 | found_byte = layout_line->start_index; | |||
3071 | ||||
3072 | if (line_top >= y) | |||
3073 | { | |||
3074 | found_line = line; | |||
3075 | break; | |||
3076 | } | |||
3077 | ||||
3078 | pango_layout_iter_get_line_yrange (layout_iter, &first_y, &last_y); | |||
3079 | line_top += (last_y - first_y) / PANGO_SCALE1024; | |||
3080 | } | |||
3081 | while (pango_layout_iter_next_line (layout_iter)); | |||
3082 | ||||
3083 | pango_layout_iter_free (layout_iter); | |||
3084 | ||||
3085 | line_top += display->bottom_margin; | |||
3086 | ctk_text_layout_free_line_display (layout, display); | |||
3087 | ||||
3088 | next = _ctk_text_line_next_excluding_last (line); | |||
3089 | if (!next) | |||
3090 | found_line = line; | |||
3091 | ||||
3092 | line = next; | |||
3093 | } | |||
3094 | ||||
3095 | ctk_text_layout_get_iter_at_line (layout, iter, found_line, found_byte); | |||
3096 | } | |||
3097 | ||||
3098 | /* Find the iter for the logical beginning of the last display line whose | |||
3099 | * top y is >= y. If none exists, move the iter to the logical beginning | |||
3100 | * of the first line in the buffer. | |||
3101 | */ | |||
3102 | static void | |||
3103 | find_display_line_above (CtkTextLayout *layout, | |||
3104 | CtkTextIter *iter, | |||
3105 | gint y) | |||
3106 | { | |||
3107 | CtkTextLine *line; | |||
3108 | CtkTextLine *found_line = NULL((void*)0); | |||
3109 | gint line_top; | |||
3110 | gint found_byte = 0; | |||
3111 | ||||
3112 | line = _ctk_text_btree_find_line_by_y (_ctk_text_buffer_get_btree (layout->buffer), layout, y, &line_top); | |||
3113 | if (!line) | |||
3114 | { | |||
3115 | line = _ctk_text_btree_get_end_iter_line (_ctk_text_buffer_get_btree (layout->buffer)); | |||
3116 | ||||
3117 | line_top = _ctk_text_btree_find_line_top (_ctk_text_buffer_get_btree (layout->buffer), line, layout); | |||
3118 | } | |||
3119 | ||||
3120 | while (line && !found_line) | |||
3121 | { | |||
3122 | CtkTextLineDisplay *display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
3123 | PangoRectangle logical_rect; | |||
3124 | PangoLayoutIter *layout_iter; | |||
3125 | gint tmp_top; | |||
3126 | ||||
3127 | layout_iter = pango_layout_get_iter (display->layout); | |||
3128 | ||||
3129 | line_top -= display->top_margin + display->bottom_margin; | |||
3130 | pango_layout_iter_get_layout_extents (layout_iter, NULL((void*)0), &logical_rect); | |||
3131 | line_top -= logical_rect.height / PANGO_SCALE1024; | |||
3132 | ||||
3133 | tmp_top = line_top + display->top_margin; | |||
3134 | ||||
3135 | do | |||
3136 | { | |||
3137 | gint first_y, last_y; | |||
3138 | PangoLayoutLine *layout_line = pango_layout_iter_get_line_readonly (layout_iter); | |||
3139 | ||||
3140 | found_byte = layout_line->start_index; | |||
3141 | ||||
3142 | pango_layout_iter_get_line_yrange (layout_iter, &first_y, &last_y); | |||
3143 | ||||
3144 | tmp_top -= (last_y - first_y) / PANGO_SCALE1024; | |||
3145 | ||||
3146 | if (tmp_top < y) | |||
3147 | { | |||
3148 | found_line = line; | |||
3149 | pango_layout_iter_free (layout_iter); | |||
3150 | goto done; | |||
3151 | } | |||
3152 | } | |||
3153 | while (pango_layout_iter_next_line (layout_iter)); | |||
3154 | ||||
3155 | pango_layout_iter_free (layout_iter); | |||
3156 | ||||
3157 | ctk_text_layout_free_line_display (layout, display); | |||
3158 | ||||
3159 | line = _ctk_text_line_previous (line); | |||
3160 | } | |||
3161 | ||||
3162 | done: | |||
3163 | ||||
3164 | if (found_line) | |||
3165 | ctk_text_layout_get_iter_at_line (layout, iter, found_line, found_byte); | |||
3166 | else | |||
3167 | ctk_text_buffer_get_iter_at_offset (layout->buffer, iter, 0); | |||
3168 | } | |||
3169 | ||||
3170 | /** | |||
3171 | * ctk_text_layout_clamp_iter_to_vrange: | |||
3172 | * @layout: a #CtkTextLayout | |||
3173 | * @iter: a #CtkTextIter | |||
3174 | * @top: the top of the range | |||
3175 | * @bottom: the bottom the range | |||
3176 | * | |||
3177 | * If the iterator is not fully in the range @top <= y < @bottom, | |||
3178 | * then, if possible, move it the minimum distance so that the | |||
3179 | * iterator in this range. | |||
3180 | * | |||
3181 | * Returns: %TRUE if the iterator was moved, otherwise %FALSE. | |||
3182 | **/ | |||
3183 | gboolean | |||
3184 | ctk_text_layout_clamp_iter_to_vrange (CtkTextLayout *layout, | |||
3185 | CtkTextIter *iter, | |||
3186 | gint top, | |||
3187 | gint bottom) | |||
3188 | { | |||
3189 | CdkRectangle iter_rect; | |||
3190 | ||||
3191 | ctk_text_layout_get_iter_location (layout, iter, &iter_rect); | |||
3192 | ||||
3193 | /* If the iter is at least partially above the range, put the iter | |||
3194 | * at the first fully visible line after the range. | |||
3195 | */ | |||
3196 | if (iter_rect.y < top) | |||
3197 | { | |||
3198 | find_display_line_below (layout, iter, top); | |||
3199 | ||||
3200 | return TRUE(!(0)); | |||
3201 | } | |||
3202 | /* Otherwise, if the iter is at least partially below the screen, put the | |||
3203 | * iter on the last logical position of the last completely visible | |||
3204 | * line on screen | |||
3205 | */ | |||
3206 | else if (iter_rect.y + iter_rect.height > bottom) | |||
3207 | { | |||
3208 | find_display_line_above (layout, iter, bottom); | |||
3209 | ||||
3210 | return TRUE(!(0)); | |||
3211 | } | |||
3212 | else | |||
3213 | return FALSE(0); | |||
3214 | } | |||
3215 | ||||
3216 | /** | |||
3217 | * ctk_text_layout_move_iter_to_previous_line: | |||
3218 | * @layout: a #CtkLayout | |||
3219 | * @iter: a #CtkTextIter | |||
3220 | * | |||
3221 | * Move the iterator to the beginning of the previous line. The lines | |||
3222 | * of a wrapped paragraph are treated as distinct for this operation. | |||
3223 | **/ | |||
3224 | gboolean | |||
3225 | ctk_text_layout_move_iter_to_previous_line (CtkTextLayout *layout, | |||
3226 | CtkTextIter *iter) | |||
3227 | { | |||
3228 | CtkTextLine *line; | |||
3229 | CtkTextLineDisplay *display; | |||
3230 | gint line_byte; | |||
3231 | GSList *tmp_list; | |||
3232 | PangoLayoutLine *layout_line; | |||
3233 | CtkTextIter orig; | |||
3234 | gboolean update_byte = FALSE(0); | |||
3235 | ||||
3236 | g_return_val_if_fail (CTK_IS_TEXT_LAYOUT (layout), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return ((0)); } } while ( 0); | |||
3237 | g_return_val_if_fail (iter != NULL, FALSE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "iter != NULL"); return ( (0)); } } while (0); | |||
3238 | ||||
3239 | orig = *iter; | |||
3240 | ||||
3241 | ||||
3242 | line = _ctk_text_iter_get_text_line (iter); | |||
3243 | display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
3244 | line_byte = line_display_iter_to_index (layout, display, iter); | |||
3245 | ||||
3246 | /* If display->height == 0 then the line is invisible, so don't | |||
3247 | * move onto it. | |||
3248 | */ | |||
3249 | while (display->height == 0) | |||
3250 | { | |||
3251 | CtkTextLine *prev_line; | |||
3252 | ||||
3253 | prev_line = _ctk_text_line_previous (line); | |||
3254 | ||||
3255 | if (prev_line == NULL((void*)0)) | |||
3256 | { | |||
3257 | line_display_index_to_iter (layout, display, iter, 0, 0); | |||
3258 | goto out; | |||
3259 | } | |||
3260 | ||||
3261 | ctk_text_layout_free_line_display (layout, display); | |||
3262 | ||||
3263 | line = prev_line; | |||
3264 | display = ctk_text_layout_get_line_display (layout, prev_line, FALSE(0)); | |||
3265 | update_byte = TRUE(!(0)); | |||
3266 | } | |||
3267 | ||||
3268 | tmp_list = pango_layout_get_lines_readonly (display->layout); | |||
3269 | layout_line = tmp_list->data; | |||
3270 | ||||
3271 | if (update_byte) | |||
3272 | { | |||
3273 | line_byte = layout_line->start_index + layout_line->length; | |||
3274 | } | |||
3275 | ||||
3276 | if (line_byte < layout_line->length || !tmp_list->next) /* first line of paragraph */ | |||
3277 | { | |||
3278 | CtkTextLine *prev_line; | |||
3279 | ||||
3280 | prev_line = _ctk_text_line_previous (line); | |||
3281 | ||||
3282 | /* first line of the whole buffer, do not move the iter and return FALSE */ | |||
3283 | if (prev_line == NULL((void*)0)) | |||
3284 | goto out; | |||
3285 | ||||
3286 | while (prev_line) | |||
3287 | { | |||
3288 | ctk_text_layout_free_line_display (layout, display); | |||
3289 | ||||
3290 | display = ctk_text_layout_get_line_display (layout, prev_line, FALSE(0)); | |||
3291 | ||||
3292 | if (display->height > 0) | |||
3293 | { | |||
3294 | tmp_list = g_slist_last (pango_layout_get_lines_readonly (display->layout)); | |||
3295 | layout_line = tmp_list->data; | |||
3296 | ||||
3297 | line_display_index_to_iter (layout, display, iter, | |||
3298 | layout_line->start_index + layout_line->length, 0); | |||
3299 | break; | |||
3300 | } | |||
3301 | ||||
3302 | prev_line = _ctk_text_line_previous (prev_line); | |||
3303 | } | |||
3304 | } | |||
3305 | else | |||
3306 | { | |||
3307 | gint prev_offset = layout_line->start_index; | |||
3308 | ||||
3309 | tmp_list = tmp_list->next; | |||
3310 | while (tmp_list) | |||
3311 | { | |||
3312 | layout_line = tmp_list->data; | |||
3313 | ||||
3314 | if (line_byte < layout_line->start_index + layout_line->length || | |||
3315 | !tmp_list->next) | |||
3316 | { | |||
3317 | line_display_index_to_iter (layout, display, iter, prev_offset, 0); | |||
3318 | break; | |||
3319 | } | |||
3320 | ||||
3321 | prev_offset = layout_line->start_index; | |||
3322 | tmp_list = tmp_list->next; | |||
3323 | } | |||
3324 | } | |||
3325 | ||||
3326 | out: | |||
3327 | ||||
3328 | ctk_text_layout_free_line_display (layout, display); | |||
3329 | ||||
3330 | return | |||
3331 | !ctk_text_iter_equal (iter, &orig) && | |||
3332 | !ctk_text_iter_is_end (iter); | |||
3333 | } | |||
3334 | ||||
3335 | /** | |||
3336 | * ctk_text_layout_move_iter_to_next_line: | |||
3337 | * @layout: a #CtkLayout | |||
3338 | * @iter: a #CtkTextIter | |||
3339 | * | |||
3340 | * Move the iterator to the beginning of the next line. The | |||
3341 | * lines of a wrapped paragraph are treated as distinct for | |||
3342 | * this operation. | |||
3343 | **/ | |||
3344 | gboolean | |||
3345 | ctk_text_layout_move_iter_to_next_line (CtkTextLayout *layout, | |||
3346 | CtkTextIter *iter) | |||
3347 | { | |||
3348 | CtkTextLine *line; | |||
3349 | CtkTextLineDisplay *display; | |||
3350 | gint line_byte; | |||
3351 | CtkTextIter orig; | |||
3352 | gboolean found = FALSE(0); | |||
3353 | gboolean found_after = FALSE(0); | |||
3354 | gboolean first = TRUE(!(0)); | |||
3355 | ||||
3356 | g_return_val_if_fail (CTK_IS_TEXT_LAYOUT (layout), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return ((0)); } } while ( 0); | |||
3357 | g_return_val_if_fail (iter != NULL, FALSE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "iter != NULL"); return ( (0)); } } while (0); | |||
3358 | ||||
3359 | orig = *iter; | |||
3360 | ||||
3361 | line = _ctk_text_iter_get_text_line (iter); | |||
3362 | ||||
3363 | while (line && !found_after) | |||
3364 | { | |||
3365 | GSList *tmp_list; | |||
3366 | ||||
3367 | display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
3368 | ||||
3369 | if (display->height == 0) | |||
3370 | goto next; | |||
3371 | ||||
3372 | if (first) | |||
3373 | { | |||
3374 | line_byte = line_display_iter_to_index (layout, display, iter); | |||
3375 | first = FALSE(0); | |||
3376 | } | |||
3377 | else | |||
3378 | line_byte = 0; | |||
3379 | ||||
3380 | tmp_list = pango_layout_get_lines_readonly (display->layout); | |||
3381 | while (tmp_list && !found_after) | |||
3382 | { | |||
3383 | PangoLayoutLine *layout_line = tmp_list->data; | |||
3384 | ||||
3385 | if (found) | |||
3386 | { | |||
3387 | line_display_index_to_iter (layout, display, iter, | |||
3388 | layout_line->start_index, 0); | |||
3389 | found_after = TRUE(!(0)); | |||
3390 | } | |||
3391 | else if (line_byte < layout_line->start_index + layout_line->length || !tmp_list->next) | |||
3392 | found = TRUE(!(0)); | |||
3393 | ||||
3394 | tmp_list = tmp_list->next; | |||
3395 | } | |||
3396 | ||||
3397 | next: | |||
3398 | ||||
3399 | ctk_text_layout_free_line_display (layout, display); | |||
3400 | ||||
3401 | line = _ctk_text_line_next_excluding_last (line); | |||
3402 | } | |||
3403 | ||||
3404 | if (!found_after) | |||
3405 | ctk_text_buffer_get_end_iter (layout->buffer, iter); | |||
3406 | ||||
3407 | return | |||
3408 | !ctk_text_iter_equal (iter, &orig) && | |||
3409 | !ctk_text_iter_is_end (iter); | |||
3410 | } | |||
3411 | ||||
3412 | /** | |||
3413 | * ctk_text_layout_move_iter_to_line_end: | |||
3414 | * @layout: a #CtkTextLayout | |||
3415 | * @direction: if negative, move to beginning of line, otherwise | |||
3416 | move to end of line. | |||
3417 | * | |||
3418 | * Move to the beginning or end of a display line. | |||
3419 | **/ | |||
3420 | gboolean | |||
3421 | ctk_text_layout_move_iter_to_line_end (CtkTextLayout *layout, | |||
3422 | CtkTextIter *iter, | |||
3423 | gint direction) | |||
3424 | { | |||
3425 | CtkTextLine *line; | |||
3426 | CtkTextLineDisplay *display; | |||
3427 | gint line_byte; | |||
3428 | GSList *tmp_list; | |||
3429 | CtkTextIter orig; | |||
3430 | ||||
3431 | g_return_val_if_fail (CTK_IS_TEXT_LAYOUT (layout), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return ((0)); } } while ( 0); | |||
3432 | g_return_val_if_fail (iter != NULL, FALSE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "iter != NULL"); return ( (0)); } } while (0); | |||
3433 | ||||
3434 | orig = *iter; | |||
3435 | ||||
3436 | line = _ctk_text_iter_get_text_line (iter); | |||
3437 | display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
3438 | line_byte = line_display_iter_to_index (layout, display, iter); | |||
3439 | ||||
3440 | tmp_list = pango_layout_get_lines_readonly (display->layout); | |||
3441 | while (tmp_list) | |||
3442 | { | |||
3443 | PangoLayoutLine *layout_line = tmp_list->data; | |||
3444 | ||||
3445 | if (line_byte < layout_line->start_index + layout_line->length || !tmp_list->next) | |||
3446 | { | |||
3447 | line_display_index_to_iter (layout, display, iter, | |||
3448 | direction < 0 ? layout_line->start_index : layout_line->start_index + layout_line->length, | |||
3449 | 0); | |||
3450 | ||||
3451 | /* FIXME: As a bad hack, we move back one position when we | |||
3452 | * are inside a paragraph to avoid going to next line on a | |||
3453 | * forced break not at whitespace. Real fix is to keep track | |||
3454 | * of whether marks are at leading or trailing edge? */ | |||
3455 | if (direction > 0 && layout_line->length > 0 && | |||
3456 | !ctk_text_iter_ends_line (iter) && | |||
3457 | !_ctk_text_btree_char_is_invisible (iter)) | |||
3458 | ctk_text_iter_backward_char (iter); | |||
3459 | break; | |||
3460 | } | |||
3461 | ||||
3462 | tmp_list = tmp_list->next; | |||
3463 | } | |||
3464 | ||||
3465 | ctk_text_layout_free_line_display (layout, display); | |||
3466 | ||||
3467 | return | |||
3468 | !ctk_text_iter_equal (iter, &orig) && | |||
3469 | !ctk_text_iter_is_end (iter); | |||
3470 | } | |||
3471 | ||||
3472 | ||||
3473 | /** | |||
3474 | * ctk_text_layout_iter_starts_line: | |||
3475 | * @layout: a #CtkTextLayout | |||
3476 | * @iter: iterator to test | |||
3477 | * | |||
3478 | * Tests whether an iterator is at the start of a display line. | |||
3479 | **/ | |||
3480 | gboolean | |||
3481 | ctk_text_layout_iter_starts_line (CtkTextLayout *layout, | |||
3482 | const CtkTextIter *iter) | |||
3483 | { | |||
3484 | CtkTextLine *line; | |||
3485 | CtkTextLineDisplay *display; | |||
3486 | gint line_byte; | |||
3487 | GSList *tmp_list; | |||
3488 | ||||
3489 | g_return_val_if_fail (CTK_IS_TEXT_LAYOUT (layout), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return ((0)); } } while ( 0); | |||
3490 | g_return_val_if_fail (iter != NULL, FALSE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "iter != NULL"); return ( (0)); } } while (0); | |||
3491 | ||||
3492 | line = _ctk_text_iter_get_text_line (iter); | |||
3493 | display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
3494 | line_byte = line_display_iter_to_index (layout, display, iter); | |||
3495 | ||||
3496 | tmp_list = pango_layout_get_lines_readonly (display->layout); | |||
3497 | while (tmp_list) | |||
3498 | { | |||
3499 | PangoLayoutLine *layout_line = tmp_list->data; | |||
3500 | ||||
3501 | if (line_byte < layout_line->start_index + layout_line->length || | |||
3502 | !tmp_list->next) | |||
3503 | { | |||
3504 | /* We're located on this line or the para delimiters before | |||
3505 | * it | |||
3506 | */ | |||
3507 | ctk_text_layout_free_line_display (layout, display); | |||
3508 | ||||
3509 | if (line_byte == layout_line->start_index) | |||
3510 | return TRUE(!(0)); | |||
3511 | else | |||
3512 | return FALSE(0); | |||
3513 | } | |||
3514 | ||||
3515 | tmp_list = tmp_list->next; | |||
3516 | } | |||
3517 | ||||
3518 | g_assert_not_reached ()do { g_assertion_message_expr ("Ctk", "ctktextlayout.c", 3518 , ((const char*) (__func__)), ((void*)0)); } while (0); | |||
3519 | return FALSE(0); | |||
3520 | } | |||
3521 | ||||
3522 | void | |||
3523 | ctk_text_layout_get_iter_at_line (CtkTextLayout *layout, | |||
3524 | CtkTextIter *iter, | |||
3525 | CtkTextLine *line, | |||
3526 | gint byte_offset) | |||
3527 | { | |||
3528 | _ctk_text_btree_get_iter_at_line (_ctk_text_buffer_get_btree (layout->buffer), | |||
3529 | iter, line, byte_offset); | |||
3530 | } | |||
3531 | ||||
3532 | /** | |||
3533 | * ctk_text_layout_move_iter_to_x: | |||
3534 | * @layout: a #CtkTextLayout | |||
3535 | * @iter: a #CtkTextIter | |||
3536 | * @x: X coordinate | |||
3537 | * | |||
3538 | * Keeping the iterator on the same line of the layout, move it to the | |||
3539 | * specified X coordinate. The lines of a wrapped paragraph are | |||
3540 | * treated as distinct for this operation. | |||
3541 | **/ | |||
3542 | void | |||
3543 | ctk_text_layout_move_iter_to_x (CtkTextLayout *layout, | |||
3544 | CtkTextIter *iter, | |||
3545 | gint x) | |||
3546 | { | |||
3547 | CtkTextLine *line; | |||
3548 | CtkTextLineDisplay *display; | |||
3549 | gint line_byte; | |||
3550 | PangoLayoutIter *layout_iter; | |||
3551 | ||||
3552 | g_return_if_fail (CTK_IS_TEXT_LAYOUT (layout))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((layout)); GType __t = ((ctk_text_layout_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_TEXT_LAYOUT (layout)"); return; } } while (0); | |||
3553 | g_return_if_fail (iter != NULL)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "iter != NULL"); return; } } while (0); | |||
3554 | ||||
3555 | line = _ctk_text_iter_get_text_line (iter); | |||
3556 | ||||
3557 | display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
3558 | line_byte = line_display_iter_to_index (layout, display, iter); | |||
3559 | ||||
3560 | layout_iter = pango_layout_get_iter (display->layout); | |||
3561 | ||||
3562 | do | |||
3563 | { | |||
3564 | PangoLayoutLine *layout_line = pango_layout_iter_get_line_readonly (layout_iter); | |||
3565 | ||||
3566 | if (line_byte < layout_line->start_index + layout_line->length || | |||
3567 | pango_layout_iter_at_last_line (layout_iter)) | |||
3568 | { | |||
3569 | PangoRectangle logical_rect; | |||
3570 | gint byte_index, trailing; | |||
3571 | gint x_offset = display->x_offset * PANGO_SCALE1024; | |||
3572 | ||||
3573 | pango_layout_iter_get_line_extents (layout_iter, NULL((void*)0), &logical_rect); | |||
3574 | ||||
3575 | pango_layout_line_x_to_index (layout_line, | |||
3576 | x * PANGO_SCALE1024 - x_offset - logical_rect.x, | |||
3577 | &byte_index, &trailing); | |||
3578 | ||||
3579 | line_display_index_to_iter (layout, display, iter, byte_index, trailing); | |||
3580 | ||||
3581 | break; | |||
3582 | } | |||
3583 | } | |||
3584 | while (pango_layout_iter_next_line (layout_iter)); | |||
3585 | ||||
3586 | pango_layout_iter_free (layout_iter); | |||
3587 | ||||
3588 | ctk_text_layout_free_line_display (layout, display); | |||
3589 | } | |||
3590 | ||||
3591 | /** | |||
3592 | * ctk_text_layout_move_iter_visually: | |||
3593 | * @layout: a #CtkTextLayout | |||
3594 | * @iter: a #CtkTextIter | |||
3595 | * @count: number of characters to move (negative moves left, positive moves right) | |||
3596 | * | |||
3597 | * Move the iterator a given number of characters visually, treating | |||
3598 | * it as the strong cursor position. If @count is positive, then the | |||
3599 | * new strong cursor position will be @count positions to the right of | |||
3600 | * the old cursor position. If @count is negative then the new strong | |||
3601 | * cursor position will be @count positions to the left of the old | |||
3602 | * cursor position. | |||
3603 | * | |||
3604 | * In the presence of bidirection text, the correspondence | |||
3605 | * between logical and visual order will depend on the direction | |||
3606 | * of the current run, and there may be jumps when the cursor | |||
3607 | * is moved off of the end of a run. | |||
3608 | **/ | |||
3609 | ||||
3610 | gboolean | |||
3611 | ctk_text_layout_move_iter_visually (CtkTextLayout *layout, | |||
3612 | CtkTextIter *iter, | |||
3613 | gint count) | |||
3614 | { | |||
3615 | CtkTextLineDisplay *display = NULL((void*)0); | |||
3616 | CtkTextIter orig; | |||
3617 | CtkTextIter lineiter; | |||
3618 | ||||
3619 | g_return_val_if_fail (layout != NULL, FALSE)do { if ((layout != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "layout != NULL"); return ((0)); } } while (0); | |||
3620 | g_return_val_if_fail (iter != NULL, FALSE)do { if ((iter != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "iter != NULL"); return ( (0)); } } while (0); | |||
3621 | ||||
3622 | orig = *iter; | |||
3623 | ||||
3624 | while (count != 0) | |||
3625 | { | |||
3626 | CtkTextLine *line = _ctk_text_iter_get_text_line (iter); | |||
3627 | gint line_byte; | |||
3628 | gint extra_back = 0; | |||
3629 | gboolean strong; | |||
3630 | ||||
3631 | int byte_count = _ctk_text_line_byte_count (line); | |||
3632 | ||||
3633 | int new_index; | |||
3634 | int new_trailing; | |||
3635 | ||||
3636 | if (!display) | |||
3637 | display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
3638 | ||||
3639 | if (layout->cursor_direction == CTK_TEXT_DIR_NONE) | |||
3640 | strong = TRUE(!(0)); | |||
3641 | else | |||
3642 | strong = display->direction == layout->cursor_direction; | |||
3643 | ||||
3644 | line_byte = line_display_iter_to_index (layout, display, iter); | |||
3645 | ||||
3646 | if (count > 0) | |||
3647 | { | |||
3648 | pango_layout_move_cursor_visually (display->layout, strong, line_byte, 0, 1, &new_index, &new_trailing); | |||
3649 | count--; | |||
3650 | } | |||
3651 | else | |||
3652 | { | |||
3653 | pango_layout_move_cursor_visually (display->layout, strong, line_byte, 0, -1, &new_index, &new_trailing); | |||
3654 | count++; | |||
3655 | } | |||
3656 | ||||
3657 | /* We need to handle the preedit string specially. Well, we don't really need to | |||
3658 | * handle it specially, since hopefully calling ctk_im_context_reset() will | |||
3659 | * remove the preedit string; but if we start off in front of the preedit | |||
3660 | * string (logically) and end up in or on the back edge of the preedit string, | |||
3661 | * we should move the iter one place farther. | |||
3662 | */ | |||
3663 | if (layout->preedit_len > 0 && display->insert_index >= 0) | |||
3664 | { | |||
3665 | if (line_byte == display->insert_index + layout->preedit_len && | |||
3666 | new_index < display->insert_index + layout->preedit_len) | |||
3667 | { | |||
3668 | line_byte = display->insert_index; | |||
3669 | extra_back = 1; | |||
3670 | } | |||
3671 | } | |||
3672 | ||||
3673 | if (new_index < 0 || (new_index == 0 && extra_back)) | |||
3674 | { | |||
3675 | do | |||
3676 | { | |||
3677 | line = _ctk_text_line_previous (line); | |||
3678 | if (!line) | |||
3679 | goto done; | |||
3680 | } | |||
3681 | while (totally_invisible_line (layout, line, &lineiter)); | |||
3682 | ||||
3683 | ctk_text_layout_free_line_display (layout, display); | |||
3684 | display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
3685 | ctk_text_iter_forward_to_line_end (&lineiter); | |||
3686 | new_index = ctk_text_iter_get_visible_line_index (&lineiter); | |||
3687 | } | |||
3688 | else if (new_index > byte_count) | |||
3689 | { | |||
3690 | do | |||
3691 | { | |||
3692 | line = _ctk_text_line_next_excluding_last (line); | |||
3693 | if (!line) | |||
3694 | goto done; | |||
3695 | } | |||
3696 | while (totally_invisible_line (layout, line, &lineiter)); | |||
3697 | ||||
3698 | ctk_text_layout_free_line_display (layout, display); | |||
3699 | display = ctk_text_layout_get_line_display (layout, line, FALSE(0)); | |||
3700 | new_index = 0; | |||
3701 | } | |||
3702 | ||||
3703 | line_display_index_to_iter (layout, display, iter, new_index, new_trailing); | |||
3704 | if (extra_back) | |||
3705 | ctk_text_iter_backward_char (iter); | |||
3706 | } | |||
3707 | ||||
3708 | if (display) | |||
3709 | ctk_text_layout_free_line_display (layout, display); | |||
3710 | ||||
3711 | done: | |||
3712 | ||||
3713 | return | |||
3714 | !ctk_text_iter_equal (iter, &orig) && | |||
3715 | !ctk_text_iter_is_end (iter); | |||
3716 | } | |||
3717 | ||||
3718 | void | |||
3719 | ctk_text_layout_spew (CtkTextLayout *layout G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
3720 | { | |||
3721 | #if 0 | |||
3722 | CtkTextDisplayLine *iter; | |||
3723 | guint wrapped = 0; | |||
3724 | guint paragraphs = 0; | |||
3725 | CtkTextLine *last_line = NULL((void*)0); | |||
3726 | ||||
3727 | iter = layout->line_list; | |||
3728 | while (iter != NULL((void*)0)) | |||
3729 | { | |||
3730 | if (iter->line != last_line) | |||
3731 | { | |||
3732 | printf ("%5u paragraph (%p)\n", paragraphs, iter->line); | |||
3733 | ++paragraphs; | |||
3734 | last_line = iter->line; | |||
3735 | } | |||
3736 | ||||
3737 | printf (" %5u y: %d len: %d start: %d bytes: %d\n", | |||
3738 | wrapped, iter->y, iter->length, iter->byte_offset, | |||
3739 | iter->byte_count); | |||
3740 | ||||
3741 | ++wrapped; | |||
3742 | iter = iter->next; | |||
3743 | } | |||
3744 | ||||
3745 | printf ("Layout %s recompute\n", | |||
3746 | layout->need_recompute ? "needs" : "doesn't need"); | |||
3747 | ||||
3748 | printf ("Layout pars: %u lines: %u size: %d x %d Screen width: %d\n", | |||
3749 | paragraphs, wrapped, layout->width, | |||
3750 | layout->height, layout->screen_width); | |||
3751 | #endif | |||
3752 | } | |||
3753 | ||||
3754 | /* Catch all situations that move the insertion point. | |||
3755 | */ | |||
3756 | static void | |||
3757 | ctk_text_layout_mark_set_handler (CtkTextBuffer *buffer, | |||
3758 | const CtkTextIter *location G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3759 | CtkTextMark *mark, | |||
3760 | gpointer data) | |||
3761 | { | |||
3762 | CtkTextLayout *layout = CTK_TEXT_LAYOUT (data)((((CtkTextLayout*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data)), ((ctk_text_layout_get_type ())))))); | |||
3763 | ||||
3764 | if (mark == ctk_text_buffer_get_insert (buffer)) | |||
3765 | ctk_text_layout_update_cursor_line (layout); | |||
3766 | } | |||
3767 | ||||
3768 | static void | |||
3769 | ctk_text_layout_buffer_insert_text (CtkTextBuffer *textbuffer G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3770 | CtkTextIter *iter G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3771 | gchar *str G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3772 | gint len G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3773 | gpointer data) | |||
3774 | { | |||
3775 | CtkTextLayout *layout = CTK_TEXT_LAYOUT (data)((((CtkTextLayout*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data)), ((ctk_text_layout_get_type ())))))); | |||
3776 | ||||
3777 | ctk_text_layout_update_cursor_line (layout); | |||
3778 | } | |||
3779 | ||||
3780 | static void | |||
3781 | ctk_text_layout_buffer_delete_range (CtkTextBuffer *textbuffer G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3782 | CtkTextIter *start G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3783 | CtkTextIter *end G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
3784 | gpointer data) | |||
3785 | { | |||
3786 | CtkTextLayout *layout = CTK_TEXT_LAYOUT (data)((((CtkTextLayout*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((data)), ((ctk_text_layout_get_type ())))))); | |||
3787 | ||||
3788 | ctk_text_layout_update_cursor_line (layout); | |||
3789 | } |