3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Namespace : System.Web.UI.MobileControls
25 * Class : DeviceSpecificChoice
26 * Author : Gaurav Vaish
28 * Copyright : 2003 with Gaurav Vaish, and with
32 using System
.ComponentModel
;
33 using System
.Collections
;
34 using System
.Collections
.Specialized
;
35 using System
.Reflection
;
37 using System
.Web
.Mobile
;
39 namespace System
.Web
.UI
.MobileControls
41 public class DeviceSpecificChoice
: IParserAccessor
,
44 private string argument
;
45 private IDictionary contents
;
46 private string filter
;
47 private DeviceSpecific owner
;
48 private IDictionary templates
;
51 private static IComparer caseInsensitiveComparer
52 = new CaseInsensitiveComparer();
54 public DeviceSpecificChoice()
58 string IAttributeAccessor
.GetAttribute(string key
)
60 object val
= Contents
[key
];
61 if(val
!= null && val
is string)
64 throw new ArgumentException("DeviceSpecificChoice" +
65 "_PropetyNotAnAttribute");
68 void IAttributeAccessor
.SetAttribute(string key
, string value)
70 Contents
[key
] = value;
73 void IParserAccessor
.AddParsedSubObject(object obj
)
75 if(obj
is DeviceSpecificChoiceTemplateContainer
)
77 DeviceSpecificChoiceTemplateContainer ctr
=
78 (DeviceSpecificChoiceTemplateContainer
)obj
;
79 Templates
[ctr
.Name
] = ctr
.Template
;
83 public string Argument
91 this.argument
= value;
95 public IDictionary Contents
99 if(this.contents
== null)
101 this.contents
= new ListDictionary(caseInsensitiveComparer
);
103 return this.contents
;
119 public DeviceSpecific Owner
131 public IDictionary Templates
135 if(this.templates
== null)
137 this.templates
= new ListDictionary(caseInsensitiveComparer
);
139 return this.templates
;
143 internal void ApplyProperties()
145 IDictionaryEnumerator ide
= Contents
.GetEnumerator();
146 while(ide
.MoveNext())
148 object owner
= Owner
.Owner
;
149 string key
= (string)ide
.Key
;
150 string value = (string)ide
.Value
;
151 if(key
.ToLower() == "id")
154 throw new ArgumentException("DeviceSpecificChoice" +
155 "_InvalidPropertyOverride");
160 while((dash
= key
.IndexOf('-')) != -1)
162 string first
= key
.Substring(0, dash
);
163 PropertyDescriptor pd
=
164 TypeDescriptor
.GetProperties(owner
).Find(key
, true);
168 throw new ArgumentException("DeviceSpecificChoice" +
169 "_OverridingPropertyNotFound");
171 owner
= pd
.GetValue(owner
);
172 key
= key
.Substring(dash
+ 1);
174 if(!FindAndApplyProperty(owner
, key
, value) &&
175 !FindAndApplyEvent(owner
, key
, value))
177 if(owner
is IAttributeAccessor
)
179 ((IAttributeAccessor
)owner
).SetAttribute(key
, value);
183 throw new ArgumentException("DeviceSpecificChoice" +
184 "_OverridingPropertyNotFound");
192 /// Returns false if not found or not applied
194 private bool FindAndApplyProperty(object parentObj
, string key
,
198 PropertyDescriptor pd
=
199 TypeDescriptor
.GetProperties(parentObj
).Find(key
, true);
202 if(pd
.Attributes
.Contains(
203 DesignerSerializationVisibilityAttribute
.Hidden
))
205 throw new ArgumentException("DeviceSpecificChoice" +
206 "_OverridingPropertyNotDeclarable");
208 throw new NotImplementedException();
213 private bool FindAndApplyEvent(object parentObj
, string key
,
219 if(key
.ToLower().StartsWith("on"))
221 string eventName
= key
.Substring(2);
223 TypeDescriptor
.GetEvents(parentObj
).Find(key
, true);
226 ed
.AddEventHandler(parentObj
,
227 Delegate
.CreateDelegate(ed
.EventType
,
228 Owner
.MobilePage
, eventName
));
235 private bool CheckOnPageEvaluator(MobileCapabilities capabilities
,
236 out bool evaluatorResult
)
239 evaluatorResult
= false;
240 TemplateControl tc
= Owner
.ClosestTemplateControl
;
241 // I have to get the method (MethodInfo?) and then invoke
242 // the method and send back the results of the method!
243 throw new NotImplementedException();
246 public bool HasTemplates
250 return (templates
!= null && templates
.Count
> 0);