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