fixed the build
[moon.git] / src / provider.h
blobd0825ce0f7c9cba16b47d42953d7564ff6387489
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
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.
8 *
9 */
11 #ifndef __MOON_PROVIDER_H__
12 #define __MOON_PROVIDER_H__
14 #include <glib.h>
16 #include "type.h"
18 class DependencyObject;
19 class DependencyProperty;
20 class UIElement;
21 class Surface;
22 class Style;
23 struct Value;
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 {
43 public:
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) { }
51 protected:
52 DependencyObject *obj;
53 PropertyPrecedence precedence;
57 class LocalPropertyValueProvider : public PropertyValueProvider {
58 public:
59 LocalPropertyValueProvider (DependencyObject *obj, PropertyPrecedence _precedence);
60 virtual ~LocalPropertyValueProvider ();
62 virtual Value *GetPropertyValue (DependencyProperty *property);
65 class StylePropertyValueProvider : public PropertyValueProvider {
66 public:
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);
76 private:
77 GHashTable *style_hash;
78 static void unlink_converted_value (gpointer key, gpointer value, gpointer data);
81 class InheritedPropertyValueProvider : public PropertyValueProvider {
82 public:
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);
99 private:
101 // given a dependency property and a descendent, this maps the
102 // property to whatever corresponds to that property on the
103 // descendent.
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 {
113 public:
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);
122 class AutoCreators {
123 public:
124 static AutoCreator default_autocreator;
126 static AutoCreator CreateDefaultFontSize;
129 class AutoCreatePropertyValueProvider : public PropertyValueProvider {
130 public:
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__ */