]> Pileus Git - ~andy/gtk/blob - gtk/gtktextlayout.h
Rename GtkTextStyleValues to GtkTextAttributes
[~andy/gtk] / gtk / gtktextlayout.h
1 #ifndef GTK_TEXT_LAYOUT_H
2 #define GTK_TEXT_LAYOUT_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif /* __cplusplus */
7
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
12  * to use it. 
13  */
14
15 #include <gtk/gtktextbuffer.h>
16 #include <gtk/gtktextiter.h>
17
18 /* forward declarations that have to be here to avoid including
19  * gtktextbtree.h
20  */
21 typedef struct _GtkTextLine     GtkTextLine;
22 typedef struct _GtkTextLineData GtkTextLineData;
23
24 #define GTK_TYPE_TEXT_LAYOUT             (gtk_text_layout_get_type())
25 #define GTK_TEXT_LAYOUT(obj)             (GTK_CHECK_CAST ((obj), GTK_TYPE_TEXT_LAYOUT, GtkTextLayout))
26 #define GTK_TEXT_LAYOUT_CLASS(klass)     (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutClass))
27 #define GTK_IS_TEXT_LAYOUT(obj)          (GTK_CHECK_TYPE ((obj), GTK_TYPE_TEXT_LAYOUT))
28 #define GTK_IS_TEXT_LAYOUT_CLASS(klass)  (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_LAYOUT))
29 #define GTK_TEXT_LAYOUT_GET_CLASS(obj)   (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_TEXT_LAYOUT, GtkTextLayoutClass))
30
31 typedef struct _GtkTextLayout      GtkTextLayout;
32 typedef struct _GtkTextLayoutClass GtkTextLayoutClass;
33 typedef struct _GtkTextLineDisplay GtkTextLineDisplay;
34 typedef struct _GtkTextCursorDisplay GtkTextCursorDisplay;
35 typedef struct _GtkTextAttrAppearance GtkTextAttrAppearance;
36
37 struct _GtkTextLayout
38 {
39   GtkObject parent_instance;
40
41   /* width of the display area on-screen,
42    * i.e. pixels we should wrap to fit inside. */
43   gint screen_width;
44
45   /* width/height of the total logical area being layed out */
46   gint width;
47   gint height;
48
49   GtkTextBuffer *buffer;
50
51   /* Default style used if no tags override it */
52   GtkTextAttributes *default_style;
53
54   /* Pango contexts used for creating layouts */
55   PangoContext *ltr_context;
56   PangoContext *rtl_context;
57
58   /* A cache of one style; this is used to ensure
59    * we don't constantly regenerate the style
60    * over long runs with the same style. */
61   GtkTextAttributes *one_style_cache;
62
63   /* A cache of one line display. Getting the same line
64    * many times in a row is the most common case.
65    */
66   GtkTextLineDisplay *one_display_cache;
67   
68   /* Whether we are allowed to wrap right now */
69   gint wrap_loop_count;
70 };
71
72 struct _GtkTextLayoutClass
73 {
74   GtkObjectClass parent_class;
75
76   /* Some portion of the layout was invalidated
77    */
78   void (* invalidated) (GtkTextLayout *layout);
79
80   /* A range of the layout changed appearance and possibly height
81    */
82   void (* changed)  (GtkTextLayout *layout,
83                      gint           y,
84                      gint           old_height,
85                      gint           new_height);
86
87   
88   GtkTextLineData *(* wrap) (GtkTextLayout *layout,
89                              GtkTextLine *line,
90                              /* may be NULL */
91                              GtkTextLineData *line_data);
92   
93   void (* get_log_attrs) (GtkTextLayout  *layout,
94                           GtkTextLine    *line,
95                           PangoLogAttr  **attrs,
96                           gint           *n_attrs);
97   void  (* invalidate)      (GtkTextLayout *layout,
98                              const GtkTextIter *start,
99                              const GtkTextIter *end);
100   void  (* free_line_data) (GtkTextLayout   *layout,
101                             GtkTextLine     *line,
102                             GtkTextLineData *line_data);
103 };
104
105 struct _GtkTextAttrAppearance
106 {
107   PangoAttribute attr;
108   GtkTextAppearance appearance;
109 };
110
111 struct _GtkTextCursorDisplay
112 {
113   gint x;
114   gint y;
115   gint height;
116   guint is_strong : 1;
117   guint is_weak : 1;
118 };
119
120 struct _GtkTextLineDisplay
121 {
122   PangoLayout *layout;
123   GSList *cursors;
124   GSList *pixmaps;
125
126   GtkTextDirection direction;
127
128   gint width;                   /* Width of layout */
129   gint total_width;             /* width - margins, if no width set on layout, if width set on layout, -1 */
130   gint height;
131   gint x_offset;                /* Amount layout is shifted from left edge */
132   gint left_margin;
133   gint right_margin;
134   gint top_margin;
135   gint bottom_margin;
136
137   gboolean size_only;
138   GtkTextLine *line;
139 };
140
141 extern PangoAttrType gtk_text_attr_appearance_type;
142
143 GtkType        gtk_text_layout_get_type (void) G_GNUC_CONST;
144 GtkTextLayout *gtk_text_layout_new      (void);
145
146 void gtk_text_layout_set_buffer            (GtkTextLayout      *layout,
147                                             GtkTextBuffer      *buffer);
148 void gtk_text_layout_set_default_style     (GtkTextLayout      *layout,
149                                             GtkTextAttributes  *values);
150 void gtk_text_layout_set_contexts          (GtkTextLayout      *layout,
151                                             PangoContext       *ltr_context,
152                                             PangoContext       *rtl_context);
153 void gtk_text_layout_default_style_changed (GtkTextLayout      *layout);
154 void gtk_text_layout_set_screen_width      (GtkTextLayout      *layout,
155                                             gint                width);
156
157 /* Getting the size or the lines potentially results in a call to
158  * recompute, which is pretty massively expensive. Thus it should
159  * basically only be done in an idle handler.
160  * 
161  * Long-term, we would really like to be able to do these without
162  * a full recompute so they may get cheaper over time.
163  */
164 void    gtk_text_layout_get_size (GtkTextLayout  *layout,
165                                   gint           *width,
166                                   gint           *height);
167
168
169 GSList *gtk_text_layout_get_lines (GtkTextLayout *layout,
170                                    /* [top_y, bottom_y) */
171                                    gint           top_y, 
172                                    gint           bottom_y,
173                                    gint          *first_line_y);
174
175 void gtk_text_layout_wrap_loop_start (GtkTextLayout  *layout);
176 void gtk_text_layout_wrap_loop_end   (GtkTextLayout  *layout);
177
178 GtkTextLineDisplay *gtk_text_layout_get_line_display  (GtkTextLayout      *layout,
179                                                        GtkTextLine        *line,
180                                                        gboolean            size_only);
181 void                gtk_text_layout_free_line_display (GtkTextLayout      *layout,
182                                                        GtkTextLineDisplay *display);
183
184 void gtk_text_layout_get_line_at_y     (GtkTextLayout     *layout,
185                                         GtkTextIter       *target_iter,
186                                         gint               y,
187                                         gint              *line_top);
188 void gtk_text_layout_get_iter_at_pixel (GtkTextLayout     *layout,
189                                         GtkTextIter       *iter,
190                                         gint               x,
191                                         gint               y);
192 void gtk_text_layout_invalidate        (GtkTextLayout     *layout,
193                                         const GtkTextIter *start,
194                                         const GtkTextIter *end);
195 void gtk_text_layout_free_line_data    (GtkTextLayout     *layout,
196                                         GtkTextLine       *line,
197                                         GtkTextLineData   *line_data);
198
199 gboolean gtk_text_layout_is_valid        (GtkTextLayout *layout);
200 void     gtk_text_layout_validate_yrange (GtkTextLayout *layout,
201                                           GtkTextIter   *anchor_line,
202                                           gint           y0,
203                                           gint           y1);
204 void     gtk_text_layout_validate        (GtkTextLayout *layout,
205                                           gint           max_pixels);
206
207       /* This function should return the passed-in line data,
208          OR remove the existing line data from the line, and
209          return a NEW line data after adding it to the line.
210          That is, invariant after calling the callback is that
211          there should be exactly one line data for this view
212          stored on the btree line. */
213 GtkTextLineData *gtk_text_layout_wrap (GtkTextLayout   *layout,
214                                        GtkTextLine     *line,
215                                          /* may be NULL */
216                                        GtkTextLineData *line_data);
217 void     gtk_text_layout_get_log_attrs (GtkTextLayout  *layout,
218                                         GtkTextLine    *line,
219                                         PangoLogAttr  **attrs,
220                                         gint           *n_attrs);
221 void     gtk_text_layout_changed              (GtkTextLayout     *layout,
222                                                gint               y,
223                                                gint               old_height,
224                                                gint               new_height);
225 void     gtk_text_layout_get_iter_location    (GtkTextLayout     *layout,
226                                                const GtkTextIter *iter,
227                                                GdkRectangle      *rect);
228 gint     gtk_text_layout_get_line_y           (GtkTextLayout     *layout,
229                                                const GtkTextIter *iter);
230 void     gtk_text_layout_get_cursor_locations (GtkTextLayout     *layout,
231                                                GtkTextIter       *iter,
232                                                GdkRectangle      *strong_pos,
233                                                GdkRectangle      *weak_pos);
234 gboolean gtk_text_layout_clamp_iter_to_vrange (GtkTextLayout     *layout,
235                                                GtkTextIter       *iter,
236                                                gint               top,
237                                                gint               bottom);
238
239 void gtk_text_layout_move_iter_to_previous_line (GtkTextLayout *layout,
240                                                  GtkTextIter   *iter);
241 void gtk_text_layout_move_iter_to_next_line     (GtkTextLayout *layout,
242                                                  GtkTextIter   *iter);
243 void gtk_text_layout_move_iter_to_x             (GtkTextLayout *layout,
244                                                  GtkTextIter   *iter,
245                                                  gint           x);
246 void gtk_text_layout_move_iter_visually         (GtkTextLayout *layout,
247                                                  GtkTextIter   *iter,
248                                                  gint           count);
249
250
251 void gtk_text_layout_spew (GtkTextLayout *layout);
252
253 #ifdef __cplusplus
254 }
255 #endif /* __cplusplus */
256
257 #endif