fixed the build
[moon.git] / src / layout.h
blob803e6615c8bc73706ee50a7f3825993421bb20e6
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * layout.h:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2008 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
13 #ifndef __LAYOUT_H__
14 #define __LAYOUT_H__
16 #include <cairo.h>
17 #include <glib.h>
18 #include <math.h>
20 #include <brush.h>
21 #include <enums.h>
22 #include <fonts.h>
23 #include <list.h>
25 class TextLayout;
27 class ITextAttributes {
28 public:
29 virtual ~ITextAttributes () {};
30 virtual TextFontDescription *FontDescription () = 0;
31 virtual TextDecorations Decorations () = 0;
32 virtual Brush *Background (bool selected) = 0;
33 virtual Brush *Foreground (bool selected) = 0;
36 class TextLayoutAttributes : public List::Node {
37 public:
38 ITextAttributes *source;
39 int start;
41 TextLayoutAttributes (ITextAttributes *source, int start)
43 this->source = source;
44 this->start = start;
47 Brush *Background (bool selected)
49 return source->Background (selected);
52 Brush *Foreground (bool selected)
54 return source->Foreground (selected);
57 TextFont *Font ()
59 return source->FontDescription ()->GetFont ();
62 bool IsUnderlined ()
64 return (source->Decorations () & TextDecorationsUnderline);
68 struct TextLayoutGlyphCluster {
69 int start, length;
70 moon_path *path;
71 double uadvance;
72 double advance;
73 bool selected;
75 TextLayoutGlyphCluster (int start, int length);
76 ~TextLayoutGlyphCluster ();
78 void Render (cairo_t *cr, const Point &origin, TextLayoutAttributes *attrs, const char *text, double x, double y, bool uline_full);
81 struct TextLayoutLine {
82 int start, length, offset, count;
83 TextLayout *layout;
84 GPtrArray *runs;
85 double advance;
86 double descend;
87 double height;
88 double width;
90 TextLayoutLine (TextLayout *layout, int start, int offset);
91 ~TextLayoutLine ();
93 void Render (cairo_t *cr, const Point &origin, double left, double top);
95 int GetCursorFromX (const Point &offset, double x);
98 struct TextLayoutRun {
99 TextLayoutAttributes *attrs;
100 int start, length, count;
101 TextLayoutLine *line;
102 GPtrArray *clusters;
103 double advance;
105 TextLayoutRun (TextLayoutLine *line, TextLayoutAttributes *attrs, int start);
106 ~TextLayoutRun ();
108 void Render (cairo_t *cr, const Point &origin, double x, double y, bool is_last_run);
109 void GenerateCache ();
110 void ClearCache ();
113 class TextLayout {
114 LineStackingStrategy strategy;
115 TextAlignment alignment;
116 TextWrapping wrapping;
117 int selection_length;
118 int selection_start;
119 double base_descent;
120 double base_height;
121 double avail_width;
122 double line_height;
123 double max_height;
124 double max_width;
125 List *attributes;
126 bool is_wrapped;
127 char *text;
128 int length;
129 int count;
131 // cached data
132 double actual_height;
133 double actual_width;
134 GPtrArray *lines;
136 bool OverrideLineHeight () { return (strategy == LineStackingStrategyBlockLineHeight && line_height != 0); }
137 double LineHeightOverride ();
138 double DescendOverride ();
140 void ClearCache ();
141 void ClearLines ();
143 public:
144 TextLayout ();
145 ~TextLayout ();
148 // Property Accessors
150 // Set[Property]() accessors return %true if the extents have
151 // changed or %false otherwise.
154 int GetSelectionLength () { return selection_length; }
155 int GetSelectionStart () { return selection_start; }
157 LineStackingStrategy GetLineStackingStrtegy () { return strategy; }
158 bool SetLineStackingStrategy (LineStackingStrategy mode);
160 List *GetTextAttributes () { return attributes; }
161 bool SetTextAttributes (List *attrs);
163 TextAlignment GetTextAlignment () { return alignment; }
164 bool SetTextAlignment (TextAlignment align);
166 TextWrapping GetTextWrapping () { return wrapping; }
167 bool SetTextWrapping (TextWrapping mode);
169 double GetLineHeight () { return line_height; }
170 bool SetLineHeight (double height);
172 double GetMaxHeight () { return max_height; }
173 bool SetMaxHeight (double height);
175 double GetAvailableWidth () { return avail_width; }
176 bool SetAvailableWidth (double width) { avail_width = width; return false; }
178 double GetMaxWidth () { return max_width; }
179 bool SetMaxWidth (double width);
181 bool SetText (const char *str, int len = -1);
182 const char *GetText () { return text; }
184 void SetBaseFont (const TextFont *font);
187 // Methods
190 void Render (cairo_t *cr, const Point &origin, const Point &offset);
191 void Select (int start, int length, bool byte_offsets = false);
192 void ResetState ();
193 void Layout ();
195 double HorizontalAlignment (double line_width);
197 TextLayoutLine *GetLineFromY (const Point &offset, double y, int *index = NULL);
198 TextLayoutLine *GetLineFromIndex (int index);
199 int GetLineCount () { return lines->len; }
201 int GetCursorFromXY (const Point &offset, double x, double y);
202 Rect GetCursor (const Point &offset, int pos);
204 void GetActualExtents (double *width, double *height);
207 #endif /* __LAYOUT_H__ */