]> Pileus Git - ~andy/gtk/blob - gtk/gtktextlayout.h
Make PLT-reduction work with gcc4, and don't include everything in
[~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 /* 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
86  * to use it.
87  */
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"
90 #endif
91
92 #include <gtk/gtktextbuffer.h>
93 #include <gtk/gtktextiter.h>
94
95 G_BEGIN_DECLS
96
97 /* forward declarations that have to be here to avoid including
98  * gtktextbtree.h
99  */
100 typedef struct _GtkTextLine     GtkTextLine;
101 typedef struct _GtkTextLineData GtkTextLineData;
102
103 #define GTK_TYPE_TEXT_LAYOUT             (gtk_text_layout_get_type ())
104 #define GTK_TEXT_LAYOUT(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_LAYOUT, GtkTextLayout))
105 #define GTK_TEXT_LAYOUT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutClass))
106 #define GTK_IS_TEXT_LAYOUT(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_LAYOUT))
107 #define GTK_IS_TEXT_LAYOUT_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_LAYOUT))
108 #define GTK_TEXT_LAYOUT_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutClass))
109
110 typedef struct _GtkTextLayout         GtkTextLayout;
111 typedef struct _GtkTextLayoutClass    GtkTextLayoutClass;
112 typedef struct _GtkTextLineDisplay    GtkTextLineDisplay;
113 typedef struct _GtkTextCursorDisplay  GtkTextCursorDisplay;
114 typedef struct _GtkTextAttrAppearance GtkTextAttrAppearance;
115
116 struct _GtkTextLayout
117 {
118   GObject parent_instance;
119
120   /* width of the display area on-screen,
121    * i.e. pixels we should wrap to fit inside. */
122   gint screen_width;
123
124   /* width/height of the total logical area being layed out */
125   gint width;
126   gint height;
127
128   /* Pixel offsets from the left and from the top to be used when we
129    * draw; these allow us to create left/top margins. We don't need
130    * anything special for bottom/right margins, because those don't
131    * affect drawing.
132    */
133   /* gint left_edge; */
134   /* gint top_edge; */
135
136   GtkTextBuffer *buffer;
137
138   /* Default style used if no tags override it */
139   GtkTextAttributes *default_style;
140
141   /* Pango contexts used for creating layouts */
142   PangoContext *ltr_context;
143   PangoContext *rtl_context;
144
145   /* A cache of one style; this is used to ensure
146    * we don't constantly regenerate the style
147    * over long runs with the same style. */
148   GtkTextAttributes *one_style_cache;
149
150   /* A cache of one line display. Getting the same line
151    * many times in a row is the most common case.
152    */
153   GtkTextLineDisplay *one_display_cache;
154
155   /* Whether we are allowed to wrap right now */
156   gint wrap_loop_count;
157   
158   /* Whether to show the insertion cursor */
159   guint cursor_visible : 1;
160
161   /* For what GtkTextDirection to draw cursor GTK_TEXT_DIR_NONE -
162    * means draw both cursors.
163    */
164   guint cursor_direction : 2;
165
166   /* The keyboard direction is used to default the alignment when
167      there are no strong characters.
168   */
169   guint keyboard_direction : 2;
170
171   /* The preedit string and attributes, if any */
172
173   gchar *preedit_string;
174   PangoAttrList *preedit_attrs;
175   gint preedit_len;
176   gint preedit_cursor;
177 };
178
179 struct _GtkTextLayoutClass
180 {
181   GObjectClass parent_class;
182
183   /* Some portion of the layout was invalidated
184    */
185   void  (*invalidated)  (GtkTextLayout *layout);
186
187   /* A range of the layout changed appearance and possibly height
188    */
189   void  (*changed)              (GtkTextLayout     *layout,
190                                  gint               y,
191                                  gint               old_height,
192                                  gint               new_height);
193   GtkTextLineData* (*wrap)      (GtkTextLayout     *layout,
194                                  GtkTextLine       *line,
195                                  GtkTextLineData   *line_data); /* may be NULL */
196   void  (*get_log_attrs)        (GtkTextLayout     *layout,
197                                  GtkTextLine       *line,
198                                  PangoLogAttr     **attrs,
199                                  gint              *n_attrs);
200   void  (*invalidate)           (GtkTextLayout     *layout,
201                                  const GtkTextIter *start,
202                                  const GtkTextIter *end);
203   void  (*free_line_data)       (GtkTextLayout     *layout,
204                                  GtkTextLine       *line,
205                                  GtkTextLineData   *line_data);
206
207   void (*allocate_child)        (GtkTextLayout     *layout,
208                                  GtkWidget         *child,
209                                  gint               x,
210                                  gint               y);
211
212   /* Padding for future expansion */
213   void (*_gtk_reserved1) (void);
214   void (*_gtk_reserved2) (void);
215   void (*_gtk_reserved3) (void);
216   void (*_gtk_reserved4) (void);
217 };
218
219 struct _GtkTextAttrAppearance
220 {
221   PangoAttribute attr;
222   GtkTextAppearance appearance;
223 };
224 struct _GtkTextCursorDisplay
225 {
226   gint x;
227   gint y;
228   gint height;
229   guint is_strong : 1;
230   guint is_weak : 1;
231 };
232 struct _GtkTextLineDisplay
233 {
234   PangoLayout *layout;
235   GSList *cursors;
236   GSList *shaped_objects;       /* Only for backwards compatibility */
237   
238   GtkTextDirection direction;
239
240   gint width;                   /* Width of layout */
241   gint total_width;             /* width - margins, if no width set on layout, if width set on layout, -1 */
242   gint height;
243   /* Amount layout is shifted from left edge - this is the left margin
244    * plus any other factors, such as alignment or indentation.
245    */
246   gint x_offset;
247   gint left_margin;
248   gint right_margin;
249   gint top_margin;
250   gint bottom_margin;
251   gint insert_index;            /* Byte index of insert cursor within para or -1 */
252
253   gboolean size_only;
254   GtkTextLine *line;
255 };
256
257 extern PangoAttrType gtk_text_attr_appearance_type;
258
259 GType         gtk_text_layout_get_type    (void) G_GNUC_CONST;
260
261 GtkTextLayout*     gtk_text_layout_new                   (void);
262 void               gtk_text_layout_set_buffer            (GtkTextLayout     *layout,
263                                                           GtkTextBuffer     *buffer);
264 GtkTextBuffer     *gtk_text_layout_get_buffer            (GtkTextLayout     *layout);
265 void               gtk_text_layout_set_default_style     (GtkTextLayout     *layout,
266                                                           GtkTextAttributes *values);
267 void               gtk_text_layout_set_contexts          (GtkTextLayout     *layout,
268                                                           PangoContext      *ltr_context,
269                                                           PangoContext      *rtl_context);
270 void               gtk_text_layout_set_cursor_direction  (GtkTextLayout     *layout,
271                                                           GtkTextDirection   direction);
272 void               gtk_text_layout_set_keyboard_direction (GtkTextLayout     *layout,
273                                                            GtkTextDirection keyboard_dir);
274 void               gtk_text_layout_default_style_changed (GtkTextLayout     *layout);
275
276 void gtk_text_layout_set_screen_width       (GtkTextLayout     *layout,
277                                              gint               width);
278 void gtk_text_layout_set_preedit_string     (GtkTextLayout     *layout,
279                                              const gchar       *preedit_string,
280                                              PangoAttrList     *preedit_attrs,
281                                              gint               cursor_pos);
282
283 void     gtk_text_layout_set_cursor_visible (GtkTextLayout     *layout,
284                                              gboolean           cursor_visible);
285 gboolean gtk_text_layout_get_cursor_visible (GtkTextLayout     *layout);
286
287 /* Getting the size or the lines potentially results in a call to
288  * recompute, which is pretty massively expensive. Thus it should
289  * basically only be done in an idle handler.
290  *
291  * Long-term, we would really like to be able to do these without
292  * a full recompute so they may get cheaper over time.
293  */
294 void    gtk_text_layout_get_size  (GtkTextLayout  *layout,
295                                    gint           *width,
296                                    gint           *height);
297 GSList* gtk_text_layout_get_lines (GtkTextLayout  *layout,
298                                    /* [top_y, bottom_y) */
299                                    gint            top_y,
300                                    gint            bottom_y,
301                                    gint           *first_line_y);
302
303 void gtk_text_layout_wrap_loop_start (GtkTextLayout *layout);
304 void gtk_text_layout_wrap_loop_end   (GtkTextLayout *layout);
305
306 GtkTextLineDisplay* gtk_text_layout_get_line_display  (GtkTextLayout      *layout,
307                                                        GtkTextLine        *line,
308                                                        gboolean            size_only);
309 void                gtk_text_layout_free_line_display (GtkTextLayout      *layout,
310                                                        GtkTextLineDisplay *display);
311
312 void gtk_text_layout_get_line_at_y     (GtkTextLayout     *layout,
313                                         GtkTextIter       *target_iter,
314                                         gint               y,
315                                         gint              *line_top);
316 void gtk_text_layout_get_iter_at_pixel (GtkTextLayout     *layout,
317                                         GtkTextIter       *iter,
318                                         gint               x,
319                                         gint               y);
320 void gtk_text_layout_get_iter_at_position (GtkTextLayout     *layout,
321                                            GtkTextIter       *iter,
322                                            gint              *trailing,
323                                            gint               x,
324                                            gint               y);
325 void gtk_text_layout_invalidate        (GtkTextLayout     *layout,
326                                         const GtkTextIter *start,
327                                         const GtkTextIter *end);
328 void gtk_text_layout_free_line_data    (GtkTextLayout     *layout,
329                                         GtkTextLine       *line,
330                                         GtkTextLineData   *line_data);
331
332 gboolean gtk_text_layout_is_valid        (GtkTextLayout *layout);
333 void     gtk_text_layout_validate_yrange (GtkTextLayout *layout,
334                                           GtkTextIter   *anchor_line,
335                                           gint           y0_,
336                                           gint           y1_);
337 void     gtk_text_layout_validate        (GtkTextLayout *layout,
338                                           gint           max_pixels);
339
340 /* This function should return the passed-in line data,
341  * OR remove the existing line data from the line, and
342  * return a NEW line data after adding it to the line.
343  * That is, invariant after calling the callback is that
344  * there should be exactly one line data for this view
345  * stored on the btree line.
346  */
347 GtkTextLineData* gtk_text_layout_wrap  (GtkTextLayout   *layout,
348                                         GtkTextLine     *line,
349                                         GtkTextLineData *line_data); /* may be NULL */
350 void     gtk_text_layout_changed              (GtkTextLayout     *layout,
351                                                gint               y,
352                                                gint               old_height,
353                                                gint               new_height);
354 void     gtk_text_layout_get_iter_location    (GtkTextLayout     *layout,
355                                                const GtkTextIter *iter,
356                                                GdkRectangle      *rect);
357 void     gtk_text_layout_get_line_yrange      (GtkTextLayout     *layout,
358                                                const GtkTextIter *iter,
359                                                gint              *y,
360                                                gint              *height);
361 void     _gtk_text_layout_get_line_xrange     (GtkTextLayout     *layout,
362                                                const GtkTextIter *iter,
363                                                gint              *x,
364                                                gint              *width);
365 void     gtk_text_layout_get_cursor_locations (GtkTextLayout     *layout,
366                                                GtkTextIter       *iter,
367                                                GdkRectangle      *strong_pos,
368                                                GdkRectangle      *weak_pos);
369 gboolean gtk_text_layout_clamp_iter_to_vrange (GtkTextLayout     *layout,
370                                                GtkTextIter       *iter,
371                                                gint               top,
372                                                gint               bottom);
373
374 gboolean gtk_text_layout_move_iter_to_line_end      (GtkTextLayout *layout,
375                                                      GtkTextIter   *iter,
376                                                      gint           direction);
377 gboolean gtk_text_layout_move_iter_to_previous_line (GtkTextLayout *layout,
378                                                      GtkTextIter   *iter);
379 gboolean gtk_text_layout_move_iter_to_next_line     (GtkTextLayout *layout,
380                                                      GtkTextIter   *iter);
381 void     gtk_text_layout_move_iter_to_x             (GtkTextLayout *layout,
382                                                      GtkTextIter   *iter,
383                                                      gint           x);
384 gboolean gtk_text_layout_move_iter_visually         (GtkTextLayout *layout,
385                                                      GtkTextIter   *iter,
386                                                      gint           count);
387
388 gboolean gtk_text_layout_iter_starts_line           (GtkTextLayout       *layout,
389                                                      const GtkTextIter   *iter);
390
391 void     gtk_text_layout_get_iter_at_line           (GtkTextLayout *layout,
392                                                      GtkTextIter    *iter,
393                                                      GtkTextLine    *line,
394                                                      gint            byte_offset);
395
396 /* Don't use these. Use gtk_text_view_add_child_at_anchor().
397  * These functions are defined in gtktextchild.c, but here
398  * since they are semi-public and require GtkTextLayout to
399  * be declared.
400  */
401 void gtk_text_child_anchor_register_child   (GtkTextChildAnchor *anchor,
402                                              GtkWidget          *child,
403                                              GtkTextLayout      *layout);
404 void gtk_text_child_anchor_unregister_child (GtkTextChildAnchor *anchor,
405                                              GtkWidget          *child);
406
407 void gtk_text_child_anchor_queue_resize     (GtkTextChildAnchor *anchor,
408                                              GtkTextLayout      *layout);
409
410 void gtk_text_anchored_child_set_layout     (GtkWidget          *child,
411                                              GtkTextLayout      *layout);
412
413 void gtk_text_layout_spew (GtkTextLayout *layout);
414
415 G_END_DECLS
416
417 #endif  /* __GTK_TEXT_LAYOUT_H__ */