]> Pileus Git - ~andy/gtk/blob - gtk/gtktextlayout.h
Remove g_convert (moved to glib) and now useless utf_to_latin1()
[~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   /* Whether to show the insertion cursor */
72   guint cursor_visible : 1;
73 };
74
75 struct _GtkTextLayoutClass
76 {
77   GtkObjectClass parent_class;
78
79   /* Some portion of the layout was invalidated
80    */
81   void (* invalidated) (GtkTextLayout *layout);
82
83   /* A range of the layout changed appearance and possibly height
84    */
85   void (* changed)  (GtkTextLayout *layout,
86                      gint           y,
87                      gint           old_height,
88                      gint           new_height);
89
90   
91   GtkTextLineData *(* wrap) (GtkTextLayout *layout,
92                              GtkTextLine *line,
93                              /* may be NULL */
94                              GtkTextLineData *line_data);
95   
96   void (* get_log_attrs) (GtkTextLayout  *layout,
97                           GtkTextLine    *line,
98                           PangoLogAttr  **attrs,
99                           gint           *n_attrs);
100   void  (* invalidate)      (GtkTextLayout *layout,
101                              const GtkTextIter *start,
102                              const GtkTextIter *end);
103   void  (* free_line_data) (GtkTextLayout   *layout,
104                             GtkTextLine     *line,
105                             GtkTextLineData *line_data);
106 };
107
108 struct _GtkTextAttrAppearance
109 {
110   PangoAttribute attr;
111   GtkTextAppearance appearance;
112 };
113
114 struct _GtkTextCursorDisplay
115 {
116   gint x;
117   gint y;
118   gint height;
119   guint is_strong : 1;
120   guint is_weak : 1;
121 };
122
123 struct _GtkTextLineDisplay
124 {
125   PangoLayout *layout;
126   GSList *cursors;
127   GSList *pixmaps;
128
129   GtkTextDirection direction;
130
131   gint width;                   /* Width of layout */
132   gint total_width;             /* width - margins, if no width set on layout, if width set on layout, -1 */
133   gint height;
134   gint x_offset;                /* Amount layout is shifted from left edge */
135   gint left_margin;
136   gint right_margin;
137   gint top_margin;
138   gint bottom_margin;
139
140   gboolean size_only;
141   GtkTextLine *line;
142 };
143
144 extern PangoAttrType gtk_text_attr_appearance_type;
145
146 GtkType        gtk_text_layout_get_type (void) G_GNUC_CONST;
147 GtkTextLayout *gtk_text_layout_new      (void);
148
149 void gtk_text_layout_set_buffer             (GtkTextLayout     *layout,
150                                              GtkTextBuffer     *buffer);
151 void gtk_text_layout_set_default_style      (GtkTextLayout     *layout,
152                                              GtkTextAttributes *values);
153 void gtk_text_layout_set_contexts           (GtkTextLayout     *layout,
154                                              PangoContext      *ltr_context,
155                                              PangoContext      *rtl_context);
156 void gtk_text_layout_default_style_changed  (GtkTextLayout     *layout);
157 void gtk_text_layout_set_screen_width       (GtkTextLayout     *layout,
158                                              gint               width);
159
160 void     gtk_text_layout_set_cursor_visible (GtkTextLayout *layout,
161                                              gboolean       cursor_visible);
162 gboolean gtk_text_layout_get_cursor_visible (GtkTextLayout *layout);
163
164 /* Getting the size or the lines potentially results in a call to
165  * recompute, which is pretty massively expensive. Thus it should
166  * basically only be done in an idle handler.
167  * 
168  * Long-term, we would really like to be able to do these without
169  * a full recompute so they may get cheaper over time.
170  */
171 void    gtk_text_layout_get_size (GtkTextLayout  *layout,
172                                   gint           *width,
173                                   gint           *height);
174
175
176 GSList *gtk_text_layout_get_lines (GtkTextLayout *layout,
177                                    /* [top_y, bottom_y) */
178                                    gint           top_y, 
179                                    gint           bottom_y,
180                                    gint          *first_line_y);
181
182 void gtk_text_layout_wrap_loop_start (GtkTextLayout  *layout);
183 void gtk_text_layout_wrap_loop_end   (GtkTextLayout  *layout);
184
185 GtkTextLineDisplay *gtk_text_layout_get_line_display  (GtkTextLayout      *layout,
186                                                        GtkTextLine        *line,
187                                                        gboolean            size_only);
188 void                gtk_text_layout_free_line_display (GtkTextLayout      *layout,
189                                                        GtkTextLineDisplay *display);
190
191 void gtk_text_layout_get_line_at_y     (GtkTextLayout     *layout,
192                                         GtkTextIter       *target_iter,
193                                         gint               y,
194                                         gint              *line_top);
195 void gtk_text_layout_get_iter_at_pixel (GtkTextLayout     *layout,
196                                         GtkTextIter       *iter,
197                                         gint               x,
198                                         gint               y);
199 void gtk_text_layout_invalidate        (GtkTextLayout     *layout,
200                                         const GtkTextIter *start,
201                                         const GtkTextIter *end);
202 void gtk_text_layout_free_line_data    (GtkTextLayout     *layout,
203                                         GtkTextLine       *line,
204                                         GtkTextLineData   *line_data);
205
206 gboolean gtk_text_layout_is_valid        (GtkTextLayout *layout);
207 void     gtk_text_layout_validate_yrange (GtkTextLayout *layout,
208                                           GtkTextIter   *anchor_line,
209                                           gint           y0,
210                                           gint           y1);
211 void     gtk_text_layout_validate        (GtkTextLayout *layout,
212                                           gint           max_pixels);
213
214       /* This function should return the passed-in line data,
215          OR remove the existing line data from the line, and
216          return a NEW line data after adding it to the line.
217          That is, invariant after calling the callback is that
218          there should be exactly one line data for this view
219          stored on the btree line. */
220 GtkTextLineData *gtk_text_layout_wrap (GtkTextLayout   *layout,
221                                        GtkTextLine     *line,
222                                          /* may be NULL */
223                                        GtkTextLineData *line_data);
224 void     gtk_text_layout_get_log_attrs (GtkTextLayout  *layout,
225                                         GtkTextLine    *line,
226                                         PangoLogAttr  **attrs,
227                                         gint           *n_attrs);
228 void     gtk_text_layout_changed              (GtkTextLayout     *layout,
229                                                gint               y,
230                                                gint               old_height,
231                                                gint               new_height);
232 void     gtk_text_layout_get_iter_location    (GtkTextLayout     *layout,
233                                                const GtkTextIter *iter,
234                                                GdkRectangle      *rect);
235 void     gtk_text_layout_get_line_yrange      (GtkTextLayout     *layout,
236                                                const GtkTextIter *iter,
237                                                gint              *y,
238                                                gint              *height);
239 void     gtk_text_layout_get_cursor_locations (GtkTextLayout     *layout,
240                                                GtkTextIter       *iter,
241                                                GdkRectangle      *strong_pos,
242                                                GdkRectangle      *weak_pos);
243 gboolean gtk_text_layout_clamp_iter_to_vrange (GtkTextLayout     *layout,
244                                                GtkTextIter       *iter,
245                                                gint               top,
246                                                gint               bottom);
247
248 void gtk_text_layout_move_iter_to_line_end      (GtkTextLayout *layout,
249                                                  GtkTextIter   *iter,
250                                                  gint           direction);
251 void gtk_text_layout_move_iter_to_previous_line (GtkTextLayout *layout,
252                                                  GtkTextIter   *iter);
253 void gtk_text_layout_move_iter_to_next_line     (GtkTextLayout *layout,
254                                                  GtkTextIter   *iter);
255 void gtk_text_layout_move_iter_to_x             (GtkTextLayout *layout,
256                                                  GtkTextIter   *iter,
257                                                  gint           x);
258 void gtk_text_layout_move_iter_visually         (GtkTextLayout *layout,
259                                                  GtkTextIter   *iter,
260                                                  gint           count);
261
262 void gtk_text_layout_spew (GtkTextLayout *layout);
263
264 #ifdef __cplusplus
265 }
266 #endif /* __cplusplus */
267
268 #endif