1 /* GTK - The GIMP Toolkit
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->Gtk port by Havoc Pennington
8 * Pango support by Owen Taylor
10 * This file can be used under your choice of two licenses, the LGPL
11 * and the original Tk license.
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.
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.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 * Original Tk license:
31 * This software is copyrighted by the Regents of the University of
32 * California, Sun Microsystems, Inc., and other parties. The
33 * following terms apply to all files associated with the software
34 * unless explicitly disclaimed in individual files.
36 * The authors hereby grant permission to use, copy, modify,
37 * distribute, and license this software and its documentation for any
38 * purpose, provided that existing copyright notices are retained in
39 * all copies and that this notice is included verbatim in any
40 * distributions. No written agreement, license, or royalty fee is
41 * required for any of the authorized uses. Modifications to this
42 * software may be copyrighted by their authors and need not follow
43 * the licensing terms described here, provided that the new terms are
44 * clearly indicated on the first page of each file where they apply.
46 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
47 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
48 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
49 * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
54 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
55 * NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
56 * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
57 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
59 * GOVERNMENT USE: If you are acquiring this software on behalf of the
60 * U.S. government, the Government shall have only "Restricted Rights"
61 * in the software and related documentation as defined in the Federal
62 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
63 * are acquiring the software on behalf of the Department of Defense,
64 * the software shall be classified as "Commercial Computer Software"
65 * and the Government shall have only "Restricted Rights" as defined
66 * in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the
67 * foregoing, the authors grant the U.S. Government and others acting
68 * in its behalf permission to use and distribute the software in
69 * accordance with the terms specified in this license.
73 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
74 * file for a list of people on the GTK+ Team. See the ChangeLog
75 * files for a list of changes. These files are distributed with
76 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
79 #ifndef __GTK_TEXT_LAYOUT_H__
80 #define __GTK_TEXT_LAYOUT_H__
82 /* This is a "semi-private" header; it is intended for
83 * use by the text widget, and the text canvas item,
84 * but that's all. We may have to install it so the
85 * canvas item can use it, but users are not supposed
88 #ifndef GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
89 #error "You are not supposed to be including this file; the equivalent public API is in gtktextview.h"
96 /* forward declarations that have to be here to avoid including
99 typedef struct _GtkTextLine GtkTextLine;
100 typedef struct _GtkTextLineData GtkTextLineData;
102 #define GTK_TYPE_TEXT_LAYOUT (gtk_text_layout_get_type ())
103 #define GTK_TEXT_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_LAYOUT, GtkTextLayout))
104 #define GTK_TEXT_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutClass))
105 #define GTK_IS_TEXT_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_LAYOUT))
106 #define GTK_IS_TEXT_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_LAYOUT))
107 #define GTK_TEXT_LAYOUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutClass))
109 typedef struct _GtkTextLayout GtkTextLayout;
110 typedef struct _GtkTextLayoutClass GtkTextLayoutClass;
111 typedef struct _GtkTextLineDisplay GtkTextLineDisplay;
112 typedef struct _GtkTextAttrAppearance GtkTextAttrAppearance;
114 struct _GtkTextLayout
116 GObject parent_instance;
118 /* width of the display area on-screen,
119 * i.e. pixels we should wrap to fit inside. */
122 /* width/height of the total logical area being layed out */
126 /* Pixel offsets from the left and from the top to be used when we
127 * draw; these allow us to create left/top margins. We don't need
128 * anything special for bottom/right margins, because those don't
131 /* gint left_edge; */
134 GtkTextBuffer *buffer;
136 /* Default style used if no tags override it */
137 GtkTextAttributes *default_style;
139 /* Pango contexts used for creating layouts */
140 PangoContext *ltr_context;
141 PangoContext *rtl_context;
143 /* A cache of one style; this is used to ensure
144 * we don't constantly regenerate the style
145 * over long runs with the same style. */
146 GtkTextAttributes *one_style_cache;
148 /* A cache of one line display. Getting the same line
149 * many times in a row is the most common case.
151 GtkTextLineDisplay *one_display_cache;
153 /* Whether we are allowed to wrap right now */
154 gint wrap_loop_count;
156 /* Whether to show the insertion cursor */
157 guint cursor_visible : 1;
159 /* For what GtkTextDirection to draw cursor GTK_TEXT_DIR_NONE -
160 * means draw both cursors.
162 guint cursor_direction : 2;
164 /* The keyboard direction is used to default the alignment when
165 there are no strong characters.
167 guint keyboard_direction : 2;
169 /* The preedit string and attributes, if any */
171 gchar *preedit_string;
172 PangoAttrList *preedit_attrs;
176 guint overwrite_mode : 1;
179 struct _GtkTextLayoutClass
181 GObjectClass parent_class;
183 /* Some portion of the layout was invalidated
185 void (*invalidated) (GtkTextLayout *layout);
187 /* A range of the layout changed appearance and possibly height
189 void (*changed) (GtkTextLayout *layout,
193 GtkTextLineData* (*wrap) (GtkTextLayout *layout,
195 GtkTextLineData *line_data); /* may be NULL */
196 void (*get_log_attrs) (GtkTextLayout *layout,
198 PangoLogAttr **attrs,
200 void (*invalidate) (GtkTextLayout *layout,
201 const GtkTextIter *start,
202 const GtkTextIter *end);
203 void (*free_line_data) (GtkTextLayout *layout,
205 GtkTextLineData *line_data);
207 void (*allocate_child) (GtkTextLayout *layout,
212 void (*invalidate_cursors) (GtkTextLayout *layout,
213 const GtkTextIter *start,
214 const GtkTextIter *end);
216 /* Padding for future expansion */
217 void (*_gtk_reserved1) (void);
218 void (*_gtk_reserved2) (void);
219 void (*_gtk_reserved3) (void);
222 struct _GtkTextAttrAppearance
225 GtkTextAppearance appearance;
228 struct _GtkTextLineDisplay
231 GArray *cursors; /* indexes of cursors in the PangoLayout */
233 GtkTextDirection direction;
235 gint width; /* Width of layout */
236 gint total_width; /* width - margins, if no width set on layout, if width set on layout, -1 */
238 /* Amount layout is shifted from left edge - this is the left margin
239 * plus any other factors, such as alignment or indentation.
246 gint insert_index; /* Byte index of insert cursor within para or -1 */
250 GdkColor *pg_bg_color;
252 GdkRectangle block_cursor;
253 guint cursors_invalid : 1;
254 guint has_block_cursor : 1;
255 guint cursor_at_line_end : 1;
261 #ifdef GTK_COMPILATION
262 extern G_GNUC_INTERNAL PangoAttrType gtk_text_attr_appearance_type;
265 GType gtk_text_layout_get_type (void) G_GNUC_CONST;
267 GtkTextLayout* gtk_text_layout_new (void);
268 void gtk_text_layout_set_buffer (GtkTextLayout *layout,
269 GtkTextBuffer *buffer);
270 GtkTextBuffer *gtk_text_layout_get_buffer (GtkTextLayout *layout);
271 void gtk_text_layout_set_default_style (GtkTextLayout *layout,
272 GtkTextAttributes *values);
273 void gtk_text_layout_set_contexts (GtkTextLayout *layout,
274 PangoContext *ltr_context,
275 PangoContext *rtl_context);
276 void gtk_text_layout_set_cursor_direction (GtkTextLayout *layout,
277 GtkTextDirection direction);
278 void gtk_text_layout_set_overwrite_mode (GtkTextLayout *layout,
280 void gtk_text_layout_set_keyboard_direction (GtkTextLayout *layout,
281 GtkTextDirection keyboard_dir);
282 void gtk_text_layout_default_style_changed (GtkTextLayout *layout);
284 void gtk_text_layout_set_screen_width (GtkTextLayout *layout,
286 void gtk_text_layout_set_preedit_string (GtkTextLayout *layout,
287 const gchar *preedit_string,
288 PangoAttrList *preedit_attrs,
291 void gtk_text_layout_set_cursor_visible (GtkTextLayout *layout,
292 gboolean cursor_visible);
293 gboolean gtk_text_layout_get_cursor_visible (GtkTextLayout *layout);
295 /* Getting the size or the lines potentially results in a call to
296 * recompute, which is pretty massively expensive. Thus it should
297 * basically only be done in an idle handler.
299 * Long-term, we would really like to be able to do these without
300 * a full recompute so they may get cheaper over time.
302 void gtk_text_layout_get_size (GtkTextLayout *layout,
305 GSList* gtk_text_layout_get_lines (GtkTextLayout *layout,
306 /* [top_y, bottom_y) */
311 void gtk_text_layout_wrap_loop_start (GtkTextLayout *layout);
312 void gtk_text_layout_wrap_loop_end (GtkTextLayout *layout);
314 GtkTextLineDisplay* gtk_text_layout_get_line_display (GtkTextLayout *layout,
317 void gtk_text_layout_free_line_display (GtkTextLayout *layout,
318 GtkTextLineDisplay *display);
320 void gtk_text_layout_get_line_at_y (GtkTextLayout *layout,
321 GtkTextIter *target_iter,
324 void gtk_text_layout_get_iter_at_pixel (GtkTextLayout *layout,
328 void gtk_text_layout_get_iter_at_position (GtkTextLayout *layout,
333 void gtk_text_layout_invalidate (GtkTextLayout *layout,
334 const GtkTextIter *start,
335 const GtkTextIter *end);
336 void gtk_text_layout_invalidate_cursors(GtkTextLayout *layout,
337 const GtkTextIter *start,
338 const GtkTextIter *end);
339 void gtk_text_layout_free_line_data (GtkTextLayout *layout,
341 GtkTextLineData *line_data);
343 gboolean gtk_text_layout_is_valid (GtkTextLayout *layout);
344 void gtk_text_layout_validate_yrange (GtkTextLayout *layout,
345 GtkTextIter *anchor_line,
348 void gtk_text_layout_validate (GtkTextLayout *layout,
351 /* This function should return the passed-in line data,
352 * OR remove the existing line data from the line, and
353 * return a NEW line data after adding it to the line.
354 * That is, invariant after calling the callback is that
355 * there should be exactly one line data for this view
356 * stored on the btree line.
358 GtkTextLineData* gtk_text_layout_wrap (GtkTextLayout *layout,
360 GtkTextLineData *line_data); /* may be NULL */
361 void gtk_text_layout_changed (GtkTextLayout *layout,
365 void gtk_text_layout_cursors_changed (GtkTextLayout *layout,
369 void gtk_text_layout_get_iter_location (GtkTextLayout *layout,
370 const GtkTextIter *iter,
372 void gtk_text_layout_get_line_yrange (GtkTextLayout *layout,
373 const GtkTextIter *iter,
376 void _gtk_text_layout_get_line_xrange (GtkTextLayout *layout,
377 const GtkTextIter *iter,
380 void gtk_text_layout_get_cursor_locations (GtkTextLayout *layout,
382 GdkRectangle *strong_pos,
383 GdkRectangle *weak_pos);
384 gboolean _gtk_text_layout_get_block_cursor (GtkTextLayout *layout,
386 gboolean gtk_text_layout_clamp_iter_to_vrange (GtkTextLayout *layout,
391 gboolean gtk_text_layout_move_iter_to_line_end (GtkTextLayout *layout,
394 gboolean gtk_text_layout_move_iter_to_previous_line (GtkTextLayout *layout,
396 gboolean gtk_text_layout_move_iter_to_next_line (GtkTextLayout *layout,
398 void gtk_text_layout_move_iter_to_x (GtkTextLayout *layout,
401 gboolean gtk_text_layout_move_iter_visually (GtkTextLayout *layout,
405 gboolean gtk_text_layout_iter_starts_line (GtkTextLayout *layout,
406 const GtkTextIter *iter);
408 void gtk_text_layout_get_iter_at_line (GtkTextLayout *layout,
413 /* Don't use these. Use gtk_text_view_add_child_at_anchor().
414 * These functions are defined in gtktextchild.c, but here
415 * since they are semi-public and require GtkTextLayout to
418 void gtk_text_child_anchor_register_child (GtkTextChildAnchor *anchor,
420 GtkTextLayout *layout);
421 void gtk_text_child_anchor_unregister_child (GtkTextChildAnchor *anchor,
424 void gtk_text_child_anchor_queue_resize (GtkTextChildAnchor *anchor,
425 GtkTextLayout *layout);
427 void gtk_text_anchored_child_set_layout (GtkWidget *child,
428 GtkTextLayout *layout);
430 void gtk_text_layout_spew (GtkTextLayout *layout);
434 #endif /* __GTK_TEXT_LAYOUT_H__ */