]> Pileus Git - ~andy/gtk/blob - gtk/gtktextlayout.h
Get widgets working on the btree/buffer side. Display of them still
[~andy/gtk] / gtk / gtktextlayout.h
1 /* GTK - The GIMP Toolkit
2  * gtktextlayout.h
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->Gtk 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, write to the Free
27  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28  *
29  * Original Tk license:
30  *
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.
35  *
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.
45  *
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.
51  *
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.
58  *
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.
70  *
71  */
72 /*
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/.
77  */
78
79 #ifndef GTK_TEXT_LAYOUT_H
80 #define GTK_TEXT_LAYOUT_H
81
82 #ifdef __cplusplus
83 extern "C" {
84 #endif /* __cplusplus */
85
86 /* This is a "semi-private" header; it is intended for
87  * use by the text widget, and the text canvas item,
88  * but that's all. We may have to install it so the
89  * canvas item can use it, but users are not supposed
90  * to use it.
91  */
92
93 #include <gtk/gtktextbuffer.h>
94 #include <gtk/gtktextiter.h>
95
96 /* forward declarations that have to be here to avoid including
97  * gtktextbtree.h
98  */
99 typedef struct _GtkTextLine     GtkTextLine;
100 typedef struct _GtkTextLineData GtkTextLineData;
101
102 #define GTK_TYPE_TEXT_LAYOUT             (gtk_text_layout_get_type ())
103 #define GTK_TEXT_LAYOUT(obj)             (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT_LAYOUT, GtkTextLayout))
104 #define GTK_TEXT_LAYOUT_CLASS(klass)     (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutClass))
105 #define GTK_IS_TEXT_LAYOUT(obj)          (GTK_CHECK_TYPE ((obj), GTK_TYPE_TEXT_LAYOUT))
106 #define GTK_IS_TEXT_LAYOUT_CLASS(klass)  (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_LAYOUT))
107 #define GTK_TEXT_LAYOUT_GET_CLASS(obj)   (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutClass))
108
109 typedef struct _GtkTextLayout         GtkTextLayout;
110 typedef struct _GtkTextLayoutClass    GtkTextLayoutClass;
111 typedef struct _GtkTextLineDisplay    GtkTextLineDisplay;
112 typedef struct _GtkTextCursorDisplay  GtkTextCursorDisplay;
113 typedef struct _GtkTextAttrAppearance GtkTextAttrAppearance;
114
115 struct _GtkTextLayout
116 {
117   GtkObject parent_instance;
118
119   /* width of the display area on-screen,
120    * i.e. pixels we should wrap to fit inside. */
121   gint screen_width;
122
123   /* width/height of the total logical area being layed out */
124   gint width;
125   gint height;
126
127   /* Pixel offsets from the left and from the top to be used when we
128    * draw; these allow us to create left/top margins. We don't need
129    * anything special for bottom/right margins, because those don't
130    * affect drawing.
131    */
132   /* gint left_edge; */
133   /* gint top_edge; */
134
135   GtkTextBuffer *buffer;
136
137   /* Default style used if no tags override it */
138   GtkTextAttributes *default_style;
139
140   /* Pango contexts used for creating layouts */
141   PangoContext *ltr_context;
142   PangoContext *rtl_context;
143
144   /* A cache of one style; this is used to ensure
145    * we don't constantly regenerate the style
146    * over long runs with the same style. */
147   GtkTextAttributes *one_style_cache;
148
149   /* A cache of one line display. Getting the same line
150    * many times in a row is the most common case.
151    */
152   GtkTextLineDisplay *one_display_cache;
153
154   /* Whether we are allowed to wrap right now */
155   gint wrap_loop_count;
156   
157   /* Whether to show the insertion cursor */
158   guint cursor_visible : 1;
159 };
160
161 struct _GtkTextLayoutClass
162 {
163   GtkObjectClass parent_class;
164
165   /* Some portion of the layout was invalidated
166    */
167   void  (*invalidated)  (GtkTextLayout *layout);
168
169   /* A range of the layout changed appearance and possibly height
170    */
171   void  (*changed)              (GtkTextLayout     *layout,
172                                  gint               y,
173                                  gint               old_height,
174                                  gint               new_height);
175   GtkTextLineData* (*wrap)      (GtkTextLayout     *layout,
176                                  GtkTextLine       *line,
177                                  GtkTextLineData   *line_data); /* may be NULL */
178   void  (*get_log_attrs)        (GtkTextLayout     *layout,
179                                  GtkTextLine       *line,
180                                  PangoLogAttr     **attrs,
181                                  gint              *n_attrs);
182   void  (*invalidate)           (GtkTextLayout     *layout,
183                                  const GtkTextIter *start,
184                                  const GtkTextIter *end);
185   void  (*free_line_data)       (GtkTextLayout     *layout,
186                                  GtkTextLine       *line,
187                                  GtkTextLineData   *line_data);
188
189   void (*allocate_child)        (GtkTextLayout     *layout,
190                                  GtkWidget         *child,
191                                  gint               x,
192                                  gint               y);
193 };
194
195 struct _GtkTextAttrAppearance
196 {
197   PangoAttribute attr;
198   GtkTextAppearance appearance;
199 };
200 struct _GtkTextCursorDisplay
201 {
202   gint x;
203   gint y;
204   gint height;
205   guint is_strong : 1;
206   guint is_weak : 1;
207 };
208 struct _GtkTextLineDisplay
209 {
210   PangoLayout *layout;
211   GSList *cursors;
212   GSList *shaped_objects;
213   
214   GtkTextDirection direction;
215
216   gint width;                   /* Width of layout */
217   gint total_width;             /* width - margins, if no width set on layout, if width set on layout, -1 */
218   gint height;
219   gint x_offset;                /* Amount layout is shifted from left edge */
220   gint left_margin;
221   gint right_margin;
222   gint top_margin;
223   gint bottom_margin;
224
225   gboolean size_only;
226   GtkTextLine *line;
227 };
228
229 extern PangoAttrType gtk_text_attr_appearance_type;
230
231 GtkType         gtk_text_layout_get_type    (void) G_GNUC_CONST;
232 GtkTextLayout*  gtk_text_layout_new         (void);
233 void gtk_text_layout_set_buffer             (GtkTextLayout     *layout,
234                                              GtkTextBuffer     *buffer);
235 void gtk_text_layout_set_default_style      (GtkTextLayout     *layout,
236                                              GtkTextAttributes *values);
237 void gtk_text_layout_set_contexts           (GtkTextLayout     *layout,
238                                              PangoContext      *ltr_context,
239                                              PangoContext      *rtl_context);
240 void gtk_text_layout_default_style_changed  (GtkTextLayout     *layout);
241 void gtk_text_layout_set_screen_width       (GtkTextLayout     *layout,
242                                              gint               width);
243 void     gtk_text_layout_set_cursor_visible (GtkTextLayout     *layout,
244                                              gboolean           cursor_visible);
245 gboolean gtk_text_layout_get_cursor_visible (GtkTextLayout     *layout);
246
247 /* Getting the size or the lines potentially results in a call to
248  * recompute, which is pretty massively expensive. Thus it should
249  * basically only be done in an idle handler.
250  *
251  * Long-term, we would really like to be able to do these without
252  * a full recompute so they may get cheaper over time.
253  */
254 void    gtk_text_layout_get_size  (GtkTextLayout  *layout,
255                                    gint           *width,
256                                    gint           *height);
257 GSList* gtk_text_layout_get_lines (GtkTextLayout  *layout,
258                                    /* [top_y, bottom_y) */
259                                    gint            top_y,
260                                    gint            bottom_y,
261                                    gint           *first_line_y);
262
263 void gtk_text_layout_wrap_loop_start (GtkTextLayout *layout);
264 void gtk_text_layout_wrap_loop_end   (GtkTextLayout *layout);
265
266 GtkTextLineDisplay* gtk_text_layout_get_line_display  (GtkTextLayout      *layout,
267                                                        GtkTextLine        *line,
268                                                        gboolean            size_only);
269 void                gtk_text_layout_free_line_display (GtkTextLayout      *layout,
270                                                        GtkTextLineDisplay *display);
271
272 void gtk_text_layout_get_line_at_y     (GtkTextLayout     *layout,
273                                         GtkTextIter       *target_iter,
274                                         gint               y,
275                                         gint              *line_top);
276 void gtk_text_layout_get_iter_at_pixel (GtkTextLayout     *layout,
277                                         GtkTextIter       *iter,
278                                         gint               x,
279                                         gint               y);
280 void gtk_text_layout_invalidate        (GtkTextLayout     *layout,
281                                         const GtkTextIter *start,
282                                         const GtkTextIter *end);
283 void gtk_text_layout_free_line_data    (GtkTextLayout     *layout,
284                                         GtkTextLine       *line,
285                                         GtkTextLineData   *line_data);
286
287 gboolean gtk_text_layout_is_valid        (GtkTextLayout *layout);
288 void     gtk_text_layout_validate_yrange (GtkTextLayout *layout,
289                                           GtkTextIter   *anchor_line,
290                                           gint           y0,
291                                           gint           y1);
292 void     gtk_text_layout_validate        (GtkTextLayout *layout,
293                                           gint           max_pixels);
294
295 /* This function should return the passed-in line data,
296  * OR remove the existing line data from the line, and
297  * return a NEW line data after adding it to the line.
298  * That is, invariant after calling the callback is that
299  * there should be exactly one line data for this view
300  * stored on the btree line.
301  */
302 GtkTextLineData* gtk_text_layout_wrap  (GtkTextLayout   *layout,
303                                         GtkTextLine     *line,
304                                         GtkTextLineData *line_data); /* may be NULL */
305 void     gtk_text_layout_get_log_attrs (GtkTextLayout  *layout,
306                                         GtkTextLine    *line,
307                                         PangoLogAttr  **attrs,
308                                         gint           *n_attrs);
309 void     gtk_text_layout_changed              (GtkTextLayout     *layout,
310                                                gint               y,
311                                                gint               old_height,
312                                                gint               new_height);
313 void     gtk_text_layout_get_iter_location    (GtkTextLayout     *layout,
314                                                const GtkTextIter *iter,
315                                                GdkRectangle      *rect);
316 void     gtk_text_layout_get_line_yrange      (GtkTextLayout     *layout,
317                                                const GtkTextIter *iter,
318                                                gint              *y,
319                                                gint              *height);
320 void     gtk_text_layout_get_cursor_locations (GtkTextLayout     *layout,
321                                                GtkTextIter       *iter,
322                                                GdkRectangle      *strong_pos,
323                                                GdkRectangle      *weak_pos);
324 gboolean gtk_text_layout_clamp_iter_to_vrange (GtkTextLayout     *layout,
325                                                GtkTextIter       *iter,
326                                                gint               top,
327                                                gint               bottom);
328
329 void gtk_text_layout_move_iter_to_line_end      (GtkTextLayout *layout,
330                                                  GtkTextIter   *iter,
331                                                  gint           direction);
332 void gtk_text_layout_move_iter_to_previous_line (GtkTextLayout *layout,
333                                                  GtkTextIter   *iter);
334 void gtk_text_layout_move_iter_to_next_line     (GtkTextLayout *layout,
335                                                  GtkTextIter   *iter);
336 void gtk_text_layout_move_iter_to_x             (GtkTextLayout *layout,
337                                                  GtkTextIter   *iter,
338                                                  gint           x);
339 void gtk_text_layout_move_iter_visually         (GtkTextLayout *layout,
340                                                  GtkTextIter   *iter,
341                                                  gint           count);
342
343
344 /* Don't use these. Use gtk_text_view_add_child_at_anchor().
345  * These functions are defined in gtktextchild.c, but here
346  * since they are semi-public and require GtkTextLayout to
347  * be declared.
348  */
349 void gtk_text_child_anchor_register_child   (GtkTextChildAnchor *anchor,
350                                              GtkWidget          *child,
351                                              GtkTextLayout      *layout);
352 void gtk_text_child_anchor_unregister_child (GtkTextChildAnchor *anchor,
353                                              GtkWidget          *child);
354
355 void gtk_text_child_anchor_queue_resize     (GtkTextChildAnchor *anchor,
356                                              GtkTextLayout      *layout);
357
358 void gtk_text_layout_spew (GtkTextLayout *layout);
359
360 #ifdef __cplusplus
361 }
362 #endif /* __cplusplus */
363
364 #endif  /* GTK_TEXT_LAYOUT_H */