added MouseWheel event support for Silverlight 3.0
[moon.git] / src / textblock.h
blob85c07045bcc4594878757d1af18eb376bcec838a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * textblock.h:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
13 #ifndef __TEXTBLOCK_H__
14 #define __TEXTBLOCK_H__
16 #include <glib.h>
17 #include <cairo.h>
19 #include "frameworkelement.h"
20 #include "downloader.h"
21 #include "moon-path.h"
22 #include "thickness.h"
23 #include "fontfamily.h"
24 #include "fontstretch.h"
25 #include "fontstyle.h"
26 #include "fontweight.h"
27 #include "fontsource.h"
28 #include "layout.h"
29 #include "brush.h"
30 #include "fonts.h"
32 #define TEXTBLOCK_FONT_FAMILY "Portable User Interface"
33 #define TEXTBLOCK_FONT_STRETCH FontStretchesNormal
34 #define TEXTBLOCK_FONT_WEIGHT FontWeightsNormal
35 #define TEXTBLOCK_FONT_STYLE FontStylesNormal
37 /* @Namespace=System.Windows.Documents */
38 class Inline : public DependencyObject, public ITextAttributes {
39 TextFontDescription *font;
40 GPtrArray *downloaders;
41 bool autogen;
43 void AddFontResource (const char *resource);
44 void AddFontSource (Downloader *downloader);
46 void CleanupDownloaders ();
48 void DownloaderComplete (Downloader *downloader);
50 static void downloader_complete (EventObject *sender, EventArgs *calldata, gpointer closure);
52 protected:
53 virtual ~Inline ();
55 public:
56 /* @PropertyType=FontFamily,DefaultValue=FontFamily(TEXTBLOCK_FONT_FAMILY),GenerateAccessors */
57 const static int FontFamilyProperty;
58 /* @PropertyType=double,AutoCreator=CreateDefaultFontSize,GenerateAccessors */
59 const static int FontSizeProperty;
60 /* @PropertyType=FontStretch,DefaultValue=FontStretch(TEXTBLOCK_FONT_STRETCH),GenerateAccessors */
61 const static int FontStretchProperty;
62 /* @PropertyType=FontStyle,DefaultValue=FontStyle(TEXTBLOCK_FONT_STYLE),GenerateAccessors */
63 const static int FontStyleProperty;
64 /* @PropertyType=FontWeight,DefaultValue=FontWeight(TEXTBLOCK_FONT_WEIGHT),GenerateAccessors */
65 const static int FontWeightProperty;
66 /* @PropertyType=Brush,DefaultValue=new SolidColorBrush("black"),GenerateAccessors */
67 const static int ForegroundProperty;
68 /* @PropertyType=TextDecorations,DefaultValue=TextDecorationsNone,ManagedPropertyType=TextDecorationCollection,GenerateAccessors */
69 const static int TextDecorationsProperty;
70 /* @PropertyType=string,DefaultValue=\"en-US\",Version=2.0,ManagedPropertyType=XmlLanguage,Validator=NonNullValidator,GenerateAccessors */
71 const static int LanguageProperty;
73 // internal properties to inherit the FontSource between inlines and textblocks
74 /* @PropertyType=FontSource,GenerateManagedDP=false,GenerateAccessors */
75 const static int FontSourceProperty;
77 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Protected */
78 Inline ();
80 virtual void OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error);
81 virtual void OnSubPropertyChanged (DependencyProperty *prop, DependencyObject *obj, PropertyChangedEventArgs *subobj_args);
83 virtual bool PermitsMultipleParents () { return false; }
86 // Property Accessors
88 void SetFontFamily (FontFamily *value);
89 FontFamily *GetFontFamily ();
91 void SetLanguage (const char *lang);
92 const char *GetLanguage ();
94 void SetFontSize (double value);
95 double GetFontSize ();
97 void SetFontStretch (FontStretch *value);
98 FontStretch *GetFontStretch ();
100 void SetFontStyle (FontStyle *value);
101 FontStyle *GetFontStyle ();
103 void SetFontWeight (FontWeight *value);
104 FontWeight *GetFontWeight ();
106 void SetFontSource (FontSource *source);
107 FontSource *GetFontSource ();
109 void SetForeground (Brush *value);
110 Brush *GetForeground ();
112 void SetTextDecorations (TextDecorations decorations);
113 TextDecorations GetTextDecorations ();
116 // Non-DependencyProperty Accessors
118 void SetAutogenerated (bool autogen) { this->autogen = autogen; }
119 bool GetAutogenerated () { return autogen; }
122 // ITextAttributes Interface Methods
124 virtual TextDecorations Decorations () { return GetTextDecorations (); }
125 virtual TextFontDescription *FontDescription () { return font; }
126 virtual Brush *Foreground (bool selected) { return GetForeground (); }
127 virtual Brush *Background (bool selected) { return NULL; }
130 // Convenience Methods
132 bool UpdateFontDescription (const char *source, bool force);
134 virtual bool Equals (Inline *item);
138 /* @Namespace=System.Windows.Documents */
139 class LineBreak : public Inline {
140 protected:
141 virtual ~LineBreak () {}
143 public:
144 /* @GenerateCBinding,GeneratePInvoke */
145 LineBreak () { SetObjectType (Type::LINEBREAK); }
149 /* @ContentProperty="Text" */
150 /* @Namespace=System.Windows.Documents */
151 class Run : public Inline {
152 protected:
153 virtual ~Run () {}
155 public:
156 /* @PropertyType=string,ManagedFieldAccess=Internal,GenerateAccessors */
157 const static int TextProperty;
159 /* @GenerateCBinding,GeneratePInvoke */
160 Run () { SetObjectType (Type::RUN); }
162 virtual bool Equals (Inline *item);
165 // Property Accessors
167 void SetText (const char *text);
168 const char *GetText ();
172 class TextBlockDynamicPropertyValueProvider;
174 /* @ContentProperty="Inlines" */
175 /* @Namespace=System.Windows.Controls */
176 class TextBlock : public FrameworkElement {
177 friend class TextBlockDynamicPropertyValueProvider;
179 TextFontDescription *font;
180 GPtrArray *downloaders;
181 Downloader *source;
182 TextLayout *layout;
183 char *font_source;
185 double actual_height;
186 double actual_width;
188 int setvalue:1;
189 int was_set:1;
190 int dirty:1;
192 void Layout (Size constraint);
193 void Paint (cairo_t *cr);
195 char *GetTextInternal (InlineCollection *inlines);
196 void SetTextInternal (const char *text);
198 void AddFontResource (const char *resource);
199 void AddFontSource (Downloader *downloader);
201 void UpdateLayoutAttributes ();
202 bool UpdateFontDescription (bool force);
203 bool UpdateFontDescriptions (bool force);
205 void CleanupDownloaders (bool all);
207 void DownloaderComplete (Downloader *downloader);
209 static void downloader_complete (EventObject *sender, EventArgs *calldata, gpointer closure);
211 protected:
212 virtual ~TextBlock ();
214 public:
215 /* @PropertyType=FontFamily,DefaultValue=FontFamily(TEXTBLOCK_FONT_FAMILY),GenerateAccessors */
216 const static int FontFamilyProperty;
217 /* @PropertyType=double,AutoCreator=CreateDefaultFontSize,GenerateAccessors */
218 const static int FontSizeProperty;
219 /* @PropertyType=FontStretch,DefaultValue=FontStretch(TEXTBLOCK_FONT_STRETCH),GenerateAccessors */
220 const static int FontStretchProperty;
221 /* @PropertyType=FontStyle,DefaultValue=FontStyle(TEXTBLOCK_FONT_STYLE),GenerateAccessors */
222 const static int FontStyleProperty;
223 /* @PropertyType=FontWeight,DefaultValue=FontWeight(TEXTBLOCK_FONT_WEIGHT),GenerateAccessors */
224 const static int FontWeightProperty;
225 /* @PropertyType=FontSource,ManagedFieldAccess=Internal,Version=2.0,GenerateAccessors */
226 const static int FontSourceProperty;
227 /* @PropertyType=Brush,DefaultValue=new SolidColorBrush("black"),GenerateAccessors */
228 const static int ForegroundProperty;
229 /* @PropertyType=InlineCollection,AutoCreateValue,ManagedFieldAccess=Internal,ManagedSetterAccess=Internal,GenerateAccessors */
230 const static int InlinesProperty;
231 /* @PropertyType=string,DefaultValue=\"\",GenerateAccessors */
232 const static int TextProperty;
233 /* @PropertyType=double,DefaultValue=0.0,Version=2.0,GenerateAccessors */
234 const static int LineHeightProperty;
235 /* @PropertyType=LineStackingStrategy,DefaultValue=LineStackingStrategyMaxHeight,Version=2.0,GenerateAccessors */
236 const static int LineStackingStrategyProperty;
237 /* @PropertyType=Thickness,DefaultValue=Thickness (0),Version=2.0,GenerateAccessors */
238 const static int PaddingProperty;
239 /* @PropertyType=TextAlignment,DefaultValue=TextAlignmentLeft,Version=2.0,GenerateAccessors */
240 const static int TextAlignmentProperty;
241 /* @PropertyType=TextDecorations,DefaultValue=TextDecorationsNone,ManagedPropertyType=TextDecorationCollection,GenerateAccessors */
242 const static int TextDecorationsProperty;
243 /* @PropertyType=TextWrapping,DefaultValue=TextWrappingNoWrap,GenerateAccessors */
244 const static int TextWrappingProperty;
246 /* @GenerateCBinding,GeneratePInvoke */
247 TextBlock ();
249 void SetFontSource (Downloader *downloader);
252 // Overrides
254 virtual void Render (cairo_t *cr, Region *region, bool path_only = false);
255 virtual Size MeasureOverride (Size availableSize);
256 virtual Size ArrangeOverride (Size finalSize);
257 virtual Size ComputeActualSize ();
258 virtual void ComputeBounds ();
259 virtual Point GetTransformOrigin ();
260 virtual void GetSizeForBrush (cairo_t *cr, double *width, double *height);
261 virtual void OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error);
262 virtual void OnSubPropertyChanged (DependencyProperty *prop, DependencyObject *obj, PropertyChangedEventArgs *subobj_args);
263 virtual void OnCollectionItemChanged (Collection *col, DependencyObject *obj, PropertyChangedEventArgs *args);
264 virtual void OnCollectionChanged (Collection *col, CollectionChangedEventArgs *args);
266 void SetFontFamily (FontFamily *family);
267 FontFamily *GetFontFamily ();
269 void SetFontSize (double size);
270 double GetFontSize ();
272 void SetFontStretch (FontStretch *stretch);
273 FontStretch *GetFontStretch ();
275 void SetFontStyle (FontStyle *style);
276 FontStyle *GetFontStyle ();
278 void SetFontWeight (FontWeight *weight);
279 FontWeight *GetFontWeight ();
281 void SetFontSource (FontSource *source);
282 FontSource *GetFontSource ();
284 void SetForeground (Brush *fg);
285 Brush *GetForeground ();
287 void SetInlines (InlineCollection *inlines);
288 InlineCollection *GetInlines ();
290 void SetLineHeight (double height);
291 double GetLineHeight ();
293 void SetLineStackingStrategy (LineStackingStrategy strategy);
294 LineStackingStrategy GetLineStackingStrategy ();
296 void SetPadding (Thickness *padding);
297 Thickness *GetPadding ();
299 void SetText (const char *text);
300 const char *GetText ();
302 void SetTextAlignment (TextAlignment alignment);
303 TextAlignment GetTextAlignment ();
305 void SetTextDecorations (TextDecorations decorations);
306 TextDecorations GetTextDecorations ();
308 void SetTextWrapping (TextWrapping wrapping);
309 TextWrapping GetTextWrapping ();
312 #endif /* __TEXTBLOCK_H__ */