1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
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__
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"
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
;
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
);
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 */
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; }
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
{
141 virtual ~LineBreak () {}
144 /* @GenerateCBinding,GeneratePInvoke */
145 LineBreak () { SetObjectType (Type::LINEBREAK
); }
149 /* @ContentProperty="Text" */
150 /* @Namespace=System.Windows.Documents */
151 class Run
: public Inline
{
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
;
185 double actual_height
;
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
);
212 virtual ~TextBlock ();
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 */
249 void SetFontSource (Downloader
*downloader
);
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 OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
261 virtual void OnSubPropertyChanged (DependencyProperty
*prop
, DependencyObject
*obj
, PropertyChangedEventArgs
*subobj_args
);
262 virtual void OnCollectionItemChanged (Collection
*col
, DependencyObject
*obj
, PropertyChangedEventArgs
*args
);
263 virtual void OnCollectionChanged (Collection
*col
, CollectionChangedEventArgs
*args
);
264 virtual bool CanFindElement () { return true; }
265 virtual bool InsideObject (cairo_t
*cr
, double x
, double y
);
267 void SetFontFamily (FontFamily
*family
);
268 FontFamily
*GetFontFamily ();
270 void SetFontSize (double size
);
271 double GetFontSize ();
273 void SetFontStretch (FontStretch
*stretch
);
274 FontStretch
*GetFontStretch ();
276 void SetFontStyle (FontStyle
*style
);
277 FontStyle
*GetFontStyle ();
279 void SetFontWeight (FontWeight
*weight
);
280 FontWeight
*GetFontWeight ();
282 void SetFontSource (FontSource
*source
);
283 FontSource
*GetFontSource ();
285 void SetForeground (Brush
*fg
);
286 Brush
*GetForeground ();
288 void SetInlines (InlineCollection
*inlines
);
289 InlineCollection
*GetInlines ();
291 void SetLineHeight (double height
);
292 double GetLineHeight ();
294 void SetLineStackingStrategy (LineStackingStrategy strategy
);
295 LineStackingStrategy
GetLineStackingStrategy ();
297 void SetPadding (Thickness
*padding
);
298 Thickness
*GetPadding ();
300 void SetText (const char *text
);
301 const char *GetText ();
303 void SetTextAlignment (TextAlignment alignment
);
304 TextAlignment
GetTextAlignment ();
306 void SetTextDecorations (TextDecorations decorations
);
307 TextDecorations
GetTextDecorations ();
309 void SetTextWrapping (TextWrapping wrapping
);
310 TextWrapping
GetTextWrapping ();
313 #endif /* __TEXTBLOCK_H__ */