2005-07-18 Iain McCoy <iain@mccoy.id.au>
[mono.git] / mcs / class / WindowsBase / System.Windows / DependencyObject.cs
1 //
2 // DependencyObject.cs
3 //
4 // Author:
5 //   Iain McCoy (iain@mccoy.id.au)
6 //
7 // (C) 2005 Iain McCoy
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System.Collections;
30
31 namespace System.Windows {
32         public class DependencyObject {
33                 private static Hashtable propertyDeclarations = new Hashtable();
34                 private Hashtable properties = new Hashtable();
35                 
36                 private DependencyObjectType dependencyObjectType;
37                 public DependencyObjectType DependencyObjectType { 
38                         get { return dependencyObjectType; }
39                 }
40
41                 [MonoTODO()]            
42                 public void ClearValue(DependencyProperty dp)
43                 {
44                         throw new NotImplementedException("ClearValue(DependencyProperty dp)");
45                 }
46                 
47                 [MonoTODO()]            
48                 public void ClearValue(DependencyPropertyKey key)
49                 {
50                         throw new NotImplementedException("ClearValue(DependencyPropertyKey key)");
51                 }
52                 
53                 [MonoTODO()]            
54                 public LocalValueEnumerator GetLocalValueEnumerator()
55                 {
56                         return new LocalValueEnumerator(properties);
57                 }
58                 
59                 public object GetValue(DependencyProperty dp)
60                 {
61                         object val = properties[dp];
62                         if (val == null)
63                                 val = dp.DefaultMetadata.DefaultValue;
64                         return val;
65                 }
66                 
67                 [MonoTODO()]            
68                 public object GetValueBase(DependencyProperty dp)
69                 {
70                         throw new NotImplementedException("GetValueBase(DependencyProperty dp)");
71                 }
72                 
73                 [MonoTODO()]            
74                 protected virtual object GetValueCore(DependencyProperty dp, object baseValue, PropertyMetadata metadata)
75                 {
76                         throw new NotImplementedException("GetValueCore(DependencyProperty dp, object baseValue, PropertyMetadata metadata)");
77                 }
78                 
79                 [MonoTODO()]            
80                 public void InvalidateProperty(DependencyProperty dp)
81                 {
82                         throw new NotImplementedException("InvalidateProperty(DependencyProperty dp)");
83                 }
84                 
85                 [MonoTODO()]            
86                 protected virtual void OnPropertyInvalidated(DependencyProperty dp, PropertyMetadata metadata)
87                 {
88                         throw new NotImplementedException("OnPropertyInvalidated(DependencyProperty dp, PropertyMetadata metadata)");
89                 }
90                 
91                 [MonoTODO()]            
92                 public object ReadLocalValue(DependencyProperty dp)
93                 {
94                         throw new NotImplementedException("ReadLocalValue(DependencyProperty dp)");
95                 }
96                 
97                 public void SetValue(DependencyProperty dp, object value)
98                 {
99
100                         ValidateValueCallback validate = dp.ValidateValueCallback;
101                         if (validate != null && !validate(value))
102                                 throw new Exception("Value does not validate");
103                         else
104                                 properties[dp] = value;
105                 }
106                 
107                 [MonoTODO()]            
108                 public void SetValue(DependencyPropertyKey key, object value)
109                 {
110                         throw new NotImplementedException("SetValue(DependencyPropertyKey key, object value)");
111                 }
112                 
113                 [MonoTODO()]            
114                 public void SetValueBase(DependencyProperty dp, object value)
115                 {
116                         throw new NotImplementedException("SetValueBase(DependencyProperty dp, object value)");
117                 }
118                 
119                 [MonoTODO()]            
120                 public void SetValueBase(DependencyPropertyKey key, object value)
121                 {
122                         throw new NotImplementedException("SetValueBase(DependencyPropertyKey key, object value)");
123                 }
124
125                 internal static DependencyProperty lookup(Type t, string name)
126                 {
127                         return (DependencyProperty)((Hashtable)propertyDeclarations[t])[name];
128                 }
129
130                 internal static void register(Type t, DependencyProperty dp)
131                 {
132                         if (propertyDeclarations[t] == null)
133                                 propertyDeclarations[t] = new Hashtable();
134                         Hashtable typeDeclarations = (Hashtable)propertyDeclarations[t];
135                         if (!typeDeclarations.ContainsKey(dp.Name))
136                                 typeDeclarations[dp.Name] = dp;
137                         else
138                                 throw new Exception("A property named " + dp.Name + " already exists on " + t.Name);
139                 }
140         }
141 }