just kick off another build
[moon.git] / src / layout.h
blobce7450e04304c96833a5e3c54cf5085a4230902f
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 avail_width;
120 double line_height;
121 double max_height;
122 double max_width;
123 List *attributes;
124 bool is_wrapped;
125 char *text;
126 int length;
127 int count;
129 // cached data
130 double actual_height;
131 double actual_width;
132 GPtrArray *lines;
134 bool OverrideLineHeight () { return (strategy == LineStackingStrategyBlockLineHeight && !isnan (line_height)); }
136 void ClearCache ();
137 void ClearLines ();
139 public:
140 TextLayout ();
141 ~TextLayout ();
144 // Property Accessors
146 // Set[Property]() accessors return %true if the extents have
147 // changed or %false otherwise.
150 int GetSelectionLength () { return selection_length; }
151 int GetSelectionStart () { return selection_start; }
153 LineStackingStrategy GetLineStackingStrtegy () { return strategy; }
154 bool SetLineStackingStrategy (LineStackingStrategy mode);
156 List *GetTextAttributes () { return attributes; }
157 bool SetTextAttributes (List *attrs);
159 TextAlignment GetTextAlignment () { return alignment; }
160 bool SetTextAlignment (TextAlignment align);
162 TextWrapping GetTextWrapping () { return wrapping; }
163 bool SetTextWrapping (TextWrapping mode);
165 double GetLineHeight () { return line_height; }
166 bool SetLineHeight (double height);
168 double GetMaxHeight () { return max_height; }
169 bool SetMaxHeight (double height);
171 double GetAvailableWidth () { return avail_width; }
172 bool SetAvailableWidth (double width) { avail_width = width; return false; }
174 double GetMaxWidth () { return max_width; }
175 bool SetMaxWidth (double width);
177 bool SetText (const char *str, int len = -1);
178 const char *GetText () { return text; }
181 // Methods
184 void Render (cairo_t *cr, const Point &origin, const Point &offset);
185 void Select (int start, int length, bool byte_offsets = false);
186 void ResetState ();
187 void Layout ();
189 double HorizontalAlignment (double line_width);
191 TextLayoutLine *GetLineFromY (const Point &offset, double y, int *index = NULL);
192 TextLayoutLine *GetLineFromIndex (int index);
193 int GetLineCount () { return lines->len; }
195 int GetCursorFromXY (const Point &offset, double x, double y);
196 Rect GetCursor (const Point &offset, int pos);
198 void GetActualExtents (double *width, double *height);
201 #endif /* __LAYOUT_H__ */