2009-11-12 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / frameworkelement.h
blob9a96a6546cbef2a031bbbaeead8eae02a811df81
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * frameworkelement.h
5 * Copyright 2007 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
8 *
9 */
11 #ifndef __MOON_FRAMEWORKELEMENT_H__
12 #define __MOON_FRAMEWORKELEMENT_H__
14 #include <glib.h>
15 #include <math.h>
17 #include "uielement.h"
19 /* @CBindingRequisite */
20 typedef Size (*MeasureOverrideCallback)(Size availableSize);
21 /* @CBindingRequisite */
22 typedef Size (*ArrangeOverrideCallback)(Size finalSize);
23 /* @CBindingRequisite */
24 typedef UIElement *(*GetDefaultTemplateCallback)(FrameworkElement *element);
25 /* @CBindingRequisite */
26 typedef void (*LoadedCallback)(FrameworkElement *element);
28 /* @Namespace=System.Windows */
29 /* @CallInitialize */
30 class FrameworkElement : public UIElement {
31 public:
32 /* @PropertyType=double,DefaultValue=NAN,GenerateAccessors */
33 const static int HeightProperty;
34 /* @PropertyType=double,DefaultValue=NAN,GenerateAccessors */
35 const static int WidthProperty;
37 /* @PropertyType=double,DefaultValue=0.0,Version=2,ManagedSetterAccess=Internal,GenerateAccessors,ReadOnly */
38 const static int ActualHeightProperty;
39 /* @PropertyType=double,DefaultValue=0.0,Version=2,ManagedSetterAccess=Internal,GenerateAccessors,ReadOnly */
40 const static int ActualWidthProperty;
41 /* @PropertyType=object,Version=2.0 */
42 const static int DataContextProperty;
43 /* @PropertyType=HorizontalAlignment,DefaultValue=HorizontalAlignmentStretch,Version=2.0,GenerateAccessors */
44 const static int HorizontalAlignmentProperty;
45 /* @PropertyType=string,DefaultValue=\"en-US\",Version=2.0,ManagedPropertyType=XmlLanguage,Validator=NonNullValidator,GenerateAccessors */
46 const static int LanguageProperty;
47 /* @PropertyType=Thickness,DefaultValue=Thickness (0),Version=2.0,GenerateAccessors */
48 const static int MarginProperty;
49 /* @PropertyType=double,DefaultValue=INFINITY,Version=2.0,GenerateAccessors */
50 const static int MaxHeightProperty;
51 /* @PropertyType=double,DefaultValue=INFINITY,Version=2.0,GenerateAccessors */
52 const static int MaxWidthProperty;
53 /* @PropertyType=double,DefaultValue=0.0,Version=2.0,GenerateAccessors */
54 const static int MinHeightProperty;
55 /* @PropertyType=double,DefaultValue=0.0,Version=2.0,GenerateAccessors */
56 const static int MinWidthProperty;
57 /* @PropertyType=VerticalAlignment,DefaultValue=VerticalAlignmentStretch,Version=2.0,GenerateAccessors */
58 const static int VerticalAlignmentProperty;
59 /* @PropertyType=Style,Version=2.0,GenerateAccessors,Validator=StyleValidator */
60 const static int StyleProperty;
62 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Protected */
63 FrameworkElement ();
65 /* @GenerateCBinding,GeneratePInvoke */
66 bool ApplyTemplate ();
67 virtual bool DoApplyTemplate ();
68 virtual UIElement * GetDefaultTemplate ();
69 virtual void OnApplyTemplate () { }
71 virtual void ElementRemoved (UIElement *obj);
73 virtual void ComputeBounds ();
74 virtual Rect GetSubtreeBounds ();
76 virtual void HitTest (cairo_t *cr, Point p, List *uielement_list);
77 virtual void FindElementsInHostCoordinates (cairo_t *cr, Point P, List *uielement_list);
78 virtual void FindElementsInHostCoordinates (cairo_t *cr, Rect r, List *uielement_list);
80 //virtual void OnSubPropertyChanged (DependencyProperty *prop, DependencyObject *obj, PropertyChangedEventArgs *subobj_args);
81 virtual void OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error);
83 virtual bool InsideObject (cairo_t *cr, double x, double y);
84 bool InsideLayoutClip (double x, double y);
85 void RenderLayoutClip (cairo_t *cr);
87 virtual void GetSizeForBrush (cairo_t *cr, double *width, double *height);
88 virtual Point GetTransformOrigin ();
90 /* @GenerateCBinding,GeneratePInvoke */
91 void SetLogicalParent (DependencyObject *logical_parent, MoonError *error);
92 /* @GenerateCBinding,GeneratePInvoke */
93 DependencyObject *GetLogicalParent () { return logical_parent; }
96 // Property Accessors
98 void SetHeight (double height);
99 double GetHeight ();
101 void SetWidth (double width);
102 double GetWidth ();
104 void SetLanguage (const char *value);
105 const char *GetLanguage ();
108 // 2.0 methods
110 // Layout
111 virtual void Measure (Size availableSize);
112 virtual void Arrange (Rect finalRect);
114 /* @GeneratePInvoke,GenerateCBinding */
115 void RegisterManagedOverrides (MeasureOverrideCallback measure_cb, ArrangeOverrideCallback arrange_cb,
116 GetDefaultTemplateCallback get_default_template_cb, LoadedCallback loaded_cb);
118 // These two methods call into managed land using the
119 // delegates registered in RegisterManagedOverrides. If
120 // classes want to implement fully unmanaged layout, they
121 // should override these two methods.
123 /* @GenerateCBinding,GeneratePInvoke */
124 virtual Size MeasureOverride (Size availableSize);
125 /* @GenerateCBinding,GeneratePInvoke */
126 virtual Size ArrangeOverride (Size finalSize);
127 virtual Size ComputeActualSize ();
130 // Apply specific constraint values to the given size
131 Size ApplySizeConstraints (const Size &size);
133 virtual void UpdateLayout ();
135 virtual void OnLoaded ();
137 /* @DelegateType=SizeChangedEventHandler */
138 const static int SizeChangedEvent;
139 // XXX 2.0 also has the Loaded event moved here from
140 // UIElement.
143 // Property Accessors (2.0)
146 void SetActualWidth (double width);
147 double GetActualWidth ();
149 void SetActualHeight (double width);
150 double GetActualHeight ();
152 Thickness *GetMargin ();
153 void SetMargin (Thickness *value);
155 double GetMaxHeight ();
156 void SetMaxHeight (double value);
158 double GetMinHeight ();
159 void SetMinHeight (double value);
161 double GetMaxWidth ();
162 void SetMaxWidth (double value);
164 double GetMinWidth ();
165 void SetMinWidth (double value);
167 HorizontalAlignment GetHorizontalAlignment ();
168 void SetHorizontalAlignment (HorizontalAlignment value);
170 Style *GetStyle ();
171 void SetStyle (Style *value);
173 VerticalAlignment GetVerticalAlignment ();
174 void SetVerticalAlignment (VerticalAlignment value);
176 /* @GenerateCBinding,GeneratePInvoke */
177 void SetDefaultStyle (Style *value);
179 bool default_style_applied;
181 protected:
182 GetDefaultTemplateCallback get_default_template_cb;
183 Rect bounds_with_children;
184 GHashTable *styles;
186 virtual void ElementAdded (UIElement *item);
188 virtual ~FrameworkElement ();
190 private:
191 MeasureOverrideCallback measure_cb;
192 ArrangeOverrideCallback arrange_cb;
193 LoadedCallback loaded_cb;
195 DependencyObject *logical_parent;
198 class FrameworkElementProvider : public PropertyValueProvider {
199 Value *actual_height_value;
200 Value *actual_width_value;
201 Size last;
203 public:
204 FrameworkElementProvider (DependencyObject *obj, PropertyPrecedence precedence);
205 virtual ~FrameworkElementProvider ();
206 virtual Value *GetPropertyValue (DependencyProperty *property);
210 #endif /* __FRAMEWORKELEMENT_H__ */