1 #ifndef GTK_TEXT_LAYOUT_H
2 #define GTK_TEXT_LAYOUT_H
6 #endif /* __cplusplus */
8 /* This is a "semi-private" header; it is intended for
9 * use by the text widget, and the text canvas item,
10 * but that's all. We may have to install it so the
11 * canvas item can use it, but users are not supposed
15 #include <gtk/gtktextbuffer.h>
16 #include <gtk/gtktextiter.h>
17 #include <gtk/gtktextbtree.h>
20 #define GTK_TYPE_TEXT_LAYOUT (gtk_text_layout_get_type())
21 #define GTK_TEXT_LAYOUT(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT_LAYOUT, GtkTextLayout))
22 #define GTK_TEXT_LAYOUT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutClass))
23 #define GTK_IS_TEXT_LAYOUT(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_TEXT_LAYOUT))
24 #define GTK_IS_TEXT_LAYOUT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_LAYOUT))
25 #define GTK_TEXT_LAYOUT_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutClass))
27 typedef struct _GtkTextLayoutClass GtkTextLayoutClass;
28 typedef struct _GtkTextLineDisplay GtkTextLineDisplay;
29 typedef struct _GtkTextCursorDisplay GtkTextCursorDisplay;
30 typedef struct _GtkTextAttrAppearance GtkTextAttrAppearance;
34 GtkObject parent_instance;
36 /* width of the display area on-screen,
37 * i.e. pixels we should wrap to fit inside. */
40 /* width/height of the total logical area being layed out */
44 GtkTextBuffer *buffer;
46 /* Default style used if no tags override it */
47 GtkTextStyleValues *default_style;
49 /* Pango contexts used for creating layouts */
50 PangoContext *ltr_context;
51 PangoContext *rtl_context;
53 /* A cache of one style; this is used to ensure
54 * we don't constantly regenerate the style
55 * over long runs with the same style. */
56 GtkTextStyleValues *one_style_cache;
58 /* A cache of one line display. Getting the same line
59 * many times in a row is the most common case.
61 GtkTextLineDisplay *one_display_cache;
63 /* Whether we are allowed to wrap right now */
67 struct _GtkTextLayoutClass
69 GtkObjectClass parent_class;
71 /* Some portion of the layout was invalidated
73 void (* invalidated) (GtkTextLayout *layout);
75 /* A range of the layout changed appearance and possibly height
77 void (* changed) (GtkTextLayout *layout,
83 GtkTextLineData *(* wrap) (GtkTextLayout *layout,
86 GtkTextLineData *line_data);
88 void (* get_log_attrs) (GtkTextLayout *layout,
92 void (* invalidate) (GtkTextLayout *layout,
93 const GtkTextIter *start,
94 const GtkTextIter *end);
95 void (* free_line_data) (GtkTextLayout *layout,
97 GtkTextLineData *line_data);
100 struct _GtkTextAttrAppearance
103 GtkTextAppearance appearance;
106 struct _GtkTextCursorDisplay
115 struct _GtkTextLineDisplay
120 GtkTextDirection direction;
122 gint width; /* Width of layout */
123 gint total_width; /* width - margins, if no width set on layout, if width set on layout, -1 */
125 gint x_offset; /* Amount layout is shifted from left edge */
135 extern PangoAttrType gtk_text_attr_appearance_type;
137 GtkType gtk_text_layout_get_type (void);
138 GtkTextLayout *gtk_text_layout_new (void);
140 void gtk_text_layout_set_buffer (GtkTextLayout *layout,
141 GtkTextBuffer *buffer);
142 void gtk_text_layout_set_default_style (GtkTextLayout *layout,
143 GtkTextStyleValues *values);
144 void gtk_text_layout_set_contexts (GtkTextLayout *layout,
145 PangoContext *ltr_context,
146 PangoContext *rtl_context);
147 void gtk_text_layout_default_style_changed (GtkTextLayout *layout);
148 void gtk_text_layout_set_screen_width (GtkTextLayout *layout,
151 /* Getting the size or the lines potentially results in a call to
152 * recompute, which is pretty massively expensive. Thus it should
153 * basically only be done in an idle handler.
155 * Long-term, we would really like to be able to do these without
156 * a full recompute so they may get cheaper over time.
158 void gtk_text_layout_get_size (GtkTextLayout *layout,
163 GSList *gtk_text_layout_get_lines (GtkTextLayout *layout,
164 /* [top_y, bottom_y) */
169 void gtk_text_layout_wrap_loop_start (GtkTextLayout *layout);
170 void gtk_text_layout_wrap_loop_end (GtkTextLayout *layout);
172 GtkTextLineDisplay *gtk_text_layout_get_line_display (GtkTextLayout *layout,
175 void gtk_text_layout_free_line_display (GtkTextLayout *layout,
176 GtkTextLineDisplay *display);
178 void gtk_text_layout_get_line_at_y (GtkTextLayout *layout,
179 GtkTextIter *target_iter,
182 void gtk_text_layout_get_iter_at_pixel (GtkTextLayout *layout,
186 void gtk_text_layout_invalidate (GtkTextLayout *layout,
187 const GtkTextIter *start,
188 const GtkTextIter *end);
189 void gtk_text_layout_free_line_data (GtkTextLayout *layout,
191 GtkTextLineData *line_data);
193 gboolean gtk_text_layout_is_valid (GtkTextLayout *layout);
194 void gtk_text_layout_validate_yrange (GtkTextLayout *layout,
195 GtkTextIter *anchor_line,
198 void gtk_text_layout_validate (GtkTextLayout *layout,
201 /* This function should return the passed-in line data,
202 OR remove the existing line data from the line, and
203 return a NEW line data after adding it to the line.
204 That is, invariant after calling the callback is that
205 there should be exactly one line data for this view
206 stored on the btree line. */
207 GtkTextLineData *gtk_text_layout_wrap (GtkTextLayout *layout,
210 GtkTextLineData *line_data);
211 void gtk_text_layout_get_log_attrs (GtkTextLayout *layout,
213 PangoLogAttr **attrs,
215 void gtk_text_layout_changed (GtkTextLayout *layout,
219 void gtk_text_layout_get_iter_location (GtkTextLayout *layout,
220 const GtkTextIter *iter,
222 gint gtk_text_layout_get_line_y (GtkTextLayout *layout,
223 const GtkTextIter *iter);
224 void gtk_text_layout_get_cursor_locations (GtkTextLayout *layout,
226 GdkRectangle *strong_pos,
227 GdkRectangle *weak_pos);
228 gboolean gtk_text_layout_clamp_iter_to_vrange (GtkTextLayout *layout,
233 void gtk_text_layout_move_iter_to_previous_line (GtkTextLayout *layout,
235 void gtk_text_layout_move_iter_to_next_line (GtkTextLayout *layout,
237 void gtk_text_layout_move_iter_to_x (GtkTextLayout *layout,
240 void gtk_text_layout_move_iter_visually (GtkTextLayout *layout,
245 void gtk_text_layout_spew (GtkTextLayout *layout);
249 #endif /* __cplusplus */