1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * provider.h: an api for PropertyValue providers (for property inheritance)
5 * Copyright 2007 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
11 #ifndef __MOON_PROVIDER_H__
12 #define __MOON_PROVIDER_H__
18 class DependencyObject
;
19 class DependencyProperty
;
25 enum PropertyPrecedence
{
26 PropertyPrecedence_LocalValue
,
27 PropertyPrecedence_DynamicValue
, // use this level for types that need to compute property values lazily
29 PropertyPrecedence_LocalStyle
,
30 PropertyPrecedence_DefaultStyle
,
32 PropertyPrecedence_Inherited
,
33 PropertyPrecedence_DefaultValue
,
34 PropertyPrecedence_AutoCreate
,
36 PropertyPrecedence_Count
,
38 PropertyPrecedence_Highest
= PropertyPrecedence_LocalValue
,
39 PropertyPrecedence_Lowest
= PropertyPrecedence_AutoCreate
,
42 class PropertyValueProvider
{
44 PropertyValueProvider (DependencyObject
*_obj
, PropertyPrecedence _precedence
) : obj(_obj
), precedence(_precedence
) { }
45 virtual ~PropertyValueProvider () { }
47 virtual Value
*GetPropertyValue (DependencyProperty
*property
) = 0;
49 virtual void RecomputePropertyValue (DependencyProperty
*property
) { }
52 DependencyObject
*obj
;
53 PropertyPrecedence precedence
;
57 class LocalPropertyValueProvider
: public PropertyValueProvider
{
59 LocalPropertyValueProvider (DependencyObject
*obj
, PropertyPrecedence _precedence
);
60 virtual ~LocalPropertyValueProvider ();
62 virtual Value
*GetPropertyValue (DependencyProperty
*property
);
65 class StylePropertyValueProvider
: public PropertyValueProvider
{
67 StylePropertyValueProvider (DependencyObject
*obj
, PropertyPrecedence _precedence
);
68 virtual ~StylePropertyValueProvider ();
70 virtual Value
*GetPropertyValue (DependencyProperty
*property
);
72 virtual void RecomputePropertyValue (DependencyProperty
*property
);
74 void SealStyle (Style
*style
);
77 GHashTable
*style_hash
;
78 static void unlink_converted_value (gpointer key
, gpointer value
, gpointer data
);
81 class InheritedPropertyValueProvider
: public PropertyValueProvider
{
83 InheritedPropertyValueProvider (DependencyObject
*obj
, PropertyPrecedence _precedence
) : PropertyValueProvider (obj
, precedence
) { };
84 virtual ~InheritedPropertyValueProvider () { };
86 virtual Value
*GetPropertyValue (DependencyProperty
*property
);
88 static bool IsPropertyInherited (int propertyId
);
91 // this method is used when a property changes on object @obj,
92 // and that notification needs to propagate down the tree
93 static void PropagateInheritedProperty (DependencyObject
*obj
, DependencyProperty
*property
, Value
*old_value
, Value
*new_value
);
95 // this method is used when you add a subtree into a
96 // pre-existing tree. it propagates all inheritable
97 // properties throughout the tree
98 static void PropagateInheritedPropertiesOnAddingToTree (UIElement
*subtreeRoot
);
101 // given a dependency property and a descendent, this maps the
102 // property to whatever corresponds to that property on the
105 // i.e. Control::ForegroundProperty + Type::TEXTBLOCK = TextBlock::ForegroundProperty
107 static DependencyProperty
* MapPropertyToDescendant (Types
*types
,
108 DependencyProperty
*property
,
109 Type::Kind descendantKind
);
112 class DefaultValuePropertyValueProvider
: public PropertyValueProvider
{
114 DefaultValuePropertyValueProvider (DependencyObject
*obj
, PropertyPrecedence _precedence
) : PropertyValueProvider (obj
, precedence
) { };
115 virtual ~DefaultValuePropertyValueProvider () { };
117 virtual Value
*GetPropertyValue (DependencyProperty
*property
);
120 typedef Value
* AutoCreator (DependencyObject
*instance
, DependencyProperty
*property
);
124 static AutoCreator default_autocreator
;
126 static AutoCreator CreateDefaultFontSize
;
129 class AutoCreatePropertyValueProvider
: public PropertyValueProvider
{
131 GHashTable
*auto_values
;
133 AutoCreatePropertyValueProvider (DependencyObject
*obj
, PropertyPrecedence _precedence
);
134 virtual ~AutoCreatePropertyValueProvider ();
136 virtual Value
*GetPropertyValue (DependencyProperty
*property
);
138 Value
*ReadLocalValue (DependencyProperty
*property
);
139 void ClearValue (DependencyProperty
*property
);
143 #endif /* __MOON_PROVIDER_H__ */