~ubuntu-branches/ubuntu/karmic/moon/karmic

« back to all changes in this revision

Viewing changes to src/text.h

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-14 12:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20090214120108-06539vb25vhbd8bn
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*
 
3
 * text.h: 
 
4
 *
 
5
 * Contact:
 
6
 *   Moonlight List (moonlight-list@lists.ximian.com)
 
7
 *
 
8
 * Copyright 2007 Novell, Inc. (http://www.novell.com)
 
9
 *
 
10
 * See the LICENSE file included with the distribution for details.
 
11
 */
 
12
 
 
13
#ifndef __TEXT_H__
 
14
#define __TEXT_H__
 
15
 
 
16
#include <glib.h>
 
17
#include <cairo.h>
 
18
 
 
19
#include <frameworkelement.h>
 
20
#include <downloader.h>
 
21
#include <moon-path.h>
 
22
#if SL_2_0
 
23
#include <thickness.h>
 
24
#endif
 
25
#include <layout.h>
 
26
#include <brush.h>
 
27
#include <font.h>
 
28
 
 
29
#define TEXTBLOCK_FONT_FAMILY  "Portable User Interface"
 
30
#define TEXTBLOCK_FONT_STRETCH FontStretchesNormal
 
31
#define TEXTBLOCK_FONT_WEIGHT  FontWeightsNormal
 
32
#define TEXTBLOCK_FONT_STYLE   FontStylesNormal
 
33
#define TEXTBLOCK_FONT_SIZE    14.666666984558105
 
34
 
 
35
G_BEGIN_DECLS
 
36
 
 
37
void text_shutdown (void);
 
38
 
 
39
G_END_DECLS
 
40
 
 
41
 
 
42
/* @Namespace=System.Windows.Documents */
 
43
class Inline : public DependencyObject {
 
44
 protected:
 
45
        virtual ~Inline ();
 
46
        
 
47
 public:
 
48
        /* @PropertyType=string,DefaultValue=TEXTBLOCK_FONT_FAMILY,ManagedPropertyType=FontFamily */
 
49
        static DependencyProperty *FontFamilyProperty;
 
50
        /* @PropertyType=double,DefaultValue=TEXTBLOCK_FONT_SIZE,GenerateAccessors */
 
51
        static DependencyProperty *FontSizeProperty;
 
52
        /* @PropertyType=FontStretch,DefaultValue=TEXTBLOCK_FONT_STRETCH,GenerateAccessors */
 
53
        static DependencyProperty *FontStretchProperty;
 
54
        /* @PropertyType=FontStyle,DefaultValue=TEXTBLOCK_FONT_STYLE,GenerateAccessors */
 
55
        static DependencyProperty *FontStyleProperty;
 
56
        /* @PropertyType=FontWeight,DefaultValue=TEXTBLOCK_FONT_WEIGHT,GenerateAccessors */
 
57
        static DependencyProperty *FontWeightProperty;
 
58
        /* @PropertyType=Brush,GenerateAccessors */
 
59
        static DependencyProperty *ForegroundProperty;
 
60
        /* @PropertyType=TextDecorations,DefaultValue=TextDecorationsNone,ManagedPropertyType=TextDecorationCollection */
 
61
        static DependencyProperty *TextDecorationsProperty;
 
62
        /* @PropertyType=string,DefaultValue=\"en-US\",Version=2.0,ManagedPropertyType=XmlLanguage */
 
63
        static DependencyProperty *LanguageProperty;
 
64
        
 
65
        /* Member variables should be considered private, for use only with the parent TextBlock */
 
66
        TextFontDescription *font;
 
67
        Brush *foreground;
 
68
        bool autogen;
 
69
        
 
70
        /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Protected */
 
71
        Inline ();
 
72
        
 
73
        virtual Type::Kind GetObjectType () { return Type::INLINE; }
 
74
        
 
75
        virtual Value *GetDefaultValue (DependencyProperty *prop);
 
76
        virtual void OnPropertyChanged (PropertyChangedEventArgs *args);
 
77
        virtual void OnSubPropertyChanged (DependencyProperty *prop, DependencyObject *obj, PropertyChangedEventArgs *subobj_args);
 
78
 
 
79
        // property accessors
 
80
        double GetFontSize ();
 
81
        void SetFontSize (double value);
 
82
 
 
83
        FontStretches GetFontStretch ();
 
84
        void SetFontStretch (FontStretches value);
 
85
 
 
86
        FontStyles GetFontStyle ();
 
87
        void SetFontStyle (FontStyles value);
 
88
 
 
89
        FontWeights GetFontWeight ();
 
90
        void SetFontWeight (FontWeights value);
 
91
 
 
92
        Brush* GetForeground ();
 
93
        void SetForeground (Brush* value);
 
94
};
 
95
 
 
96
 
 
97
/* @Namespace=System.Windows.Documents */
 
98
class LineBreak : public Inline {
 
99
 protected:
 
100
        virtual ~LineBreak () {}
 
101
        
 
102
 public:
 
103
        /* @GenerateCBinding,GeneratePInvoke */
 
104
        LineBreak () { }
 
105
        
 
106
        virtual Type::Kind GetObjectType () { return Type::LINEBREAK; }
 
107
};
 
108
 
 
109
 
 
110
/* @ContentProperty="Text" */
 
111
/* @Namespace=System.Windows.Documents */
 
112
class Run : public Inline {
 
113
 protected:
 
114
        virtual ~Run () {}
 
115
        
 
116
 public:
 
117
        /* @PropertyType=string,ManagedFieldAccess=Internal,GenerateAccessors */
 
118
        static DependencyProperty *TextProperty;
 
119
        
 
120
        /* @GenerateCBinding,GeneratePInvoke */
 
121
        Run () { }
 
122
        
 
123
        virtual Type::Kind GetObjectType () { return Type::RUN; }
 
124
        
 
125
        //
 
126
        // Property Accessors
 
127
        //
 
128
        void SetText (const char *text);
 
129
        const char *GetText ();
 
130
};
 
131
 
 
132
 
 
133
/* @ContentProperty="Inlines" */
 
134
/* @Namespace=System.Windows.Controls */
 
135
class TextBlock : public FrameworkElement {
 
136
        TextFontDescription *font;
 
137
        TextLayoutHints *hints;
 
138
        TextLayout *layout;
 
139
        Downloader *downloader;
 
140
        
 
141
        double actual_height;
 
142
        double actual_width;
 
143
        bool setvalue;
 
144
        bool dirty;
 
145
        
 
146
        void SetActualHeight (double height);
 
147
        void SetActualWidth (double width);
 
148
        
 
149
        void CalcActualWidthHeight (cairo_t *cr);
 
150
        void Layout (cairo_t *cr);
 
151
        void Paint (cairo_t *cr);
 
152
        
 
153
        char *GetTextInternal ();
 
154
        bool SetTextInternal (const char *text);
 
155
        
 
156
        double GetBoundingWidth ()
 
157
        {
 
158
                double actual = GetActualWidth ();
 
159
                Value *value;
 
160
                
 
161
                if (!(value = GetValueNoDefault (FrameworkElement::WidthProperty)))
 
162
                        return actual;
 
163
                
 
164
                if (value->AsDouble () > actual)
 
165
                        return value->AsDouble ();
 
166
                
 
167
                return actual;
 
168
        }
 
169
        
 
170
        double GetBoundingHeight ()
 
171
        {
 
172
                double actual = GetActualHeight ();
 
173
                Value *value;
 
174
                
 
175
                if (!(value = GetValueNoDefault (FrameworkElement::HeightProperty)))
 
176
                        return actual;
 
177
                
 
178
                if (value->AsDouble () > actual)
 
179
                        return value->AsDouble ();
 
180
                
 
181
                return actual;
 
182
        }
 
183
        
 
184
        void DownloaderComplete ();
 
185
        
 
186
        static void data_write (void *data, gint32 offset, gint32 n, void *closure);
 
187
        static void downloader_complete (EventObject *sender, EventArgs *calldata, gpointer closure);
 
188
        static void size_notify (gint64 size, gpointer data);
 
189
        
 
190
 protected:
 
191
        virtual ~TextBlock ();
 
192
 
 
193
 public:
 
194
        /* @PropertyType=double,ReadOnly */
 
195
        static DependencyProperty *ActualHeightProperty;
 
196
        /* @PropertyType=double,ReadOnly */
 
197
        static DependencyProperty *ActualWidthProperty;
 
198
        /* @PropertyType=string,DefaultValue=TEXTBLOCK_FONT_FAMILY,ManagedPropertyType=FontFamily,GenerateAccessors */
 
199
        static DependencyProperty *FontFamilyProperty;
 
200
        /* @PropertyType=double,DefaultValue=TEXTBLOCK_FONT_SIZE,GenerateAccessors */
 
201
        static DependencyProperty *FontSizeProperty;
 
202
        /* @PropertyType=FontStretch,DefaultValue=TEXTBLOCK_FONT_STRETCH,GenerateAccessors */
 
203
        static DependencyProperty *FontStretchProperty;
 
204
        /* @PropertyType=FontStyle,DefaultValue=TEXTBLOCK_FONT_STYLE,GenerateAccessors */
 
205
        static DependencyProperty *FontStyleProperty;
 
206
        /* @PropertyType=FontWeight,DefaultValue=TEXTBLOCK_FONT_WEIGHT,GenerateAccessors */
 
207
        static DependencyProperty *FontWeightProperty;
 
208
        /* @PropertyType=Brush,GenerateAccessors */
 
209
        static DependencyProperty *ForegroundProperty;
 
210
        /* @PropertyType=InlineCollection,ManagedFieldAccess=Internal,ManagedSetterAccess=Internal,GenerateAccessors */
 
211
        static DependencyProperty *InlinesProperty;
 
212
        /* @PropertyType=string,GenerateAccessors */
 
213
        static DependencyProperty *TextProperty;
 
214
        /* @PropertyType=double,DefaultValue=NAN,Version=2.0,GenerateAccessors */
 
215
        static DependencyProperty *LineHeightProperty;
 
216
        /* @PropertyType=LineStackingStrategy,DefaultValue=LineStackingStrategyMaxHeight,Version=2.0,GenerateAccessors */
 
217
        static DependencyProperty *LineStackingStrategyProperty;
 
218
        /* @PropertyType=Thickness,DefaultValue=Thickness (0),Version=2.0,GenerateAccessors */
 
219
        static DependencyProperty *PaddingProperty;
 
220
        /* @PropertyType=TextAlignment,DefaultValue=TextAlignmentLeft,Version=2.0,GenerateAccessors */
 
221
        static DependencyProperty *TextAlignmentProperty;
 
222
        /* @PropertyType=TextDecorations,DefaultValue=TextDecorationsNone,ManagedPropertyType=TextDecorationCollection,GenerateAccessors */
 
223
        static DependencyProperty *TextDecorationsProperty;
 
224
        /* @PropertyType=TextWrapping,DefaultValue=TextWrappingNoWrap,GenerateAccessors */
 
225
        static DependencyProperty *TextWrappingProperty;
 
226
        
 
227
        /* @GenerateCBinding,GeneratePInvoke */
 
228
        TextBlock ();
 
229
        
 
230
        virtual Type::Kind GetObjectType () { return Type::TEXTBLOCK; }
 
231
        
 
232
        void SetFontSource (Downloader *downloader);
 
233
        
 
234
        //
 
235
        // Overrides
 
236
        //
 
237
        virtual void Render (cairo_t *cr, int x, int y, int width, int height);
 
238
        virtual void GetSizeForBrush (cairo_t *cr, double *width, double *height);
 
239
        virtual void ComputeBounds ();
 
240
        virtual bool InsideObject (cairo_t *cr, double x, double y);
 
241
        virtual Point GetTransformOrigin ();
 
242
        virtual void OnPropertyChanged (PropertyChangedEventArgs *args);
 
243
        virtual void OnSubPropertyChanged (DependencyProperty *prop, DependencyObject *obj, PropertyChangedEventArgs *subobj_args);
 
244
        virtual void OnCollectionItemChanged (Collection *col, DependencyObject *obj, PropertyChangedEventArgs *args);
 
245
        virtual void OnCollectionChanged (Collection *col, CollectionChangedEventArgs *args);
 
246
        
 
247
        virtual Value *GetValue (DependencyProperty *property);
 
248
        
 
249
        //
 
250
        // Property Accessors
 
251
        //
 
252
        double GetActualWidth ()
 
253
        {
 
254
                if (dirty)
 
255
                        CalcActualWidthHeight (NULL);
 
256
                return actual_width;
 
257
        }
 
258
        
 
259
        double GetActualHeight ()
 
260
        {
 
261
                if (dirty)
 
262
                        CalcActualWidthHeight (NULL);
 
263
                return actual_height;
 
264
        }
 
265
        
 
266
        void SetFontFamily (const char *family);
 
267
        const char *GetFontFamily ();
 
268
        
 
269
        void SetFontSize (double size);
 
270
        double GetFontSize ();
 
271
        
 
272
        void SetFontStretch (FontStretches stretch);
 
273
        FontStretches GetFontStretch ();
 
274
        
 
275
        void SetFontStyle (FontStyles style);
 
276
        FontStyles GetFontStyle ();
 
277
        
 
278
        void SetFontWeight (FontWeights weight);
 
279
        FontWeights GetFontWeight ();
 
280
        
 
281
        void SetForeground (Brush *fg);
 
282
        Brush *GetForeground ();
 
283
        
 
284
        void SetInlines (InlineCollection *inlines);
 
285
        InlineCollection *GetInlines ();
 
286
        
 
287
        void SetLineHeight (double height);
 
288
        double GetLineHeight ();
 
289
        
 
290
        void SetLineStackingStrategy (LineStackingStrategy strategy);
 
291
        LineStackingStrategy GetLineStackingStrategy ();
 
292
        
 
293
        void SetPadding (Thickness *padding);
 
294
        Thickness *GetPadding ();
 
295
        
 
296
        void SetText (const char *text);
 
297
        const char *GetText ();
 
298
        
 
299
        void SetTextAlignment (TextAlignment alignment);
 
300
        TextAlignment GetTextAlignment ();
 
301
        
 
302
        void SetTextDecorations (TextDecorations decorations);
 
303
        TextDecorations GetTextDecorations ();
 
304
        
 
305
        void SetTextWrapping (TextWrapping wrapping);
 
306
        TextWrapping GetTextWrapping ();
 
307
};
 
308
 
 
309
 
 
310
/* @Namespace=System.Windows.Documents */
 
311
class Glyphs : public FrameworkElement {
 
312
        TextFontDescription *desc;
 
313
        Downloader *downloader;
 
314
        
 
315
        moon_path *path;
 
316
        gunichar *text;
 
317
        List *attrs;
 
318
        Brush *fill;
 
319
        int index;
 
320
        
 
321
        double origin_x;
 
322
        double origin_y;
 
323
        double height;
 
324
        double width;
 
325
        double left;
 
326
        double top;
 
327
        
 
328
        int origin_y_specified:1;
 
329
        int simulation_none:1;
 
330
        int uri_changed:1;
 
331
        int invalid:1;
 
332
        int dirty:1;
 
333
        
 
334
        void Layout ();
 
335
        void SetIndicesInternal (const char *in);
 
336
        
 
337
        void DownloaderComplete ();
 
338
        
 
339
        static void data_write (void *data, gint32 offset, gint32 n, void *closure);
 
340
        static void downloader_complete (EventObject *sender, EventArgs *calldata, gpointer closure);
 
341
        static void size_notify (gint64 size, gpointer data);
 
342
        
 
343
        void DownloadFont (Surface *surface, const char *url);
 
344
        
 
345
 protected:
 
346
        virtual ~Glyphs ();
 
347
        
 
348
 public:
 
349
        /* @PropertyType=Brush */
 
350
        static DependencyProperty *FillProperty;
 
351
        /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
 
352
        static DependencyProperty *FontRenderingEmSizeProperty;
 
353
        /* @PropertyType=string,ManagedPropertyType=Uri,GenerateAccessors */
 
354
        static DependencyProperty *FontUriProperty;
 
355
        /* @PropertyType=string,GenerateAccessors */
 
356
        static DependencyProperty *IndicesProperty;
 
357
        /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
 
358
        static DependencyProperty *OriginXProperty;
 
359
        /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
 
360
        static DependencyProperty *OriginYProperty;
 
361
        /* @PropertyType=StyleSimulations,DefaultValue=StyleSimulationsNone,GenerateAccessors */
 
362
        static DependencyProperty *StyleSimulationsProperty;
 
363
        /* @PropertyType=string,GenerateAccessors */
 
364
        static DependencyProperty *UnicodeStringProperty;
 
365
        
 
366
        /* @GenerateCBinding,GeneratePInvoke */
 
367
        Glyphs ();
 
368
        
 
369
        virtual Type::Kind GetObjectType () { return Type::GLYPHS; };
 
370
        
 
371
        virtual void GetSizeForBrush (cairo_t *cr, double *width, double *height);
 
372
        virtual void Render (cairo_t *cr, int x, int y, int width, int height);
 
373
        virtual void ComputeBounds ();
 
374
        virtual bool InsideObject (cairo_t *cr, double x, double y);
 
375
        virtual Point GetTransformOrigin ();
 
376
        virtual Point GetOriginPoint ();
 
377
        virtual void SetSurface (Surface *surface);
 
378
        virtual void OnPropertyChanged (PropertyChangedEventArgs *args);
 
379
        virtual void OnSubPropertyChanged (DependencyProperty *prop, DependencyObject *obj, PropertyChangedEventArgs *subobj_args);
 
380
        
 
381
        //
 
382
        // Property Accessors
 
383
        //
 
384
        void SetFill (Brush *fill);
 
385
        Brush *GetFill ();
 
386
        
 
387
        void SetFontRenderingEmSize (double size);
 
388
        double GetFontRenderingEmSize ();
 
389
        
 
390
        void SetFontUri (const char *uri);
 
391
        const char *GetFontUri ();
 
392
        
 
393
        void SetIndices (const char *indices);
 
394
        const char *GetIndices ();
 
395
        
 
396
        void SetOriginX (double origin);
 
397
        double GetOriginX ();
 
398
        
 
399
        void SetOriginY (double origin);
 
400
        double GetOriginY ();
 
401
        
 
402
        void SetStyleSimulations (StyleSimulations style);
 
403
        StyleSimulations GetStyleSimulations ();
 
404
        
 
405
        void SetUnicodeString (const char *unicode);
 
406
        const char *GetUnicodeString ();
 
407
};
 
408
 
 
409
#endif /* __TEXT_H__ */