(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web.Mobile / System.Web.UI.MobileControls / DeviceSpecificChoice.cs
blob76741e9ed35eb504b6d17933f92292a36f8dcbaa
2 //
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:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
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.
22 /**
23 * Project : Mono
24 * Namespace : System.Web.UI.MobileControls
25 * Class : DeviceSpecificChoice
26 * Author : Gaurav Vaish
28 * Copyright : 2003 with Gaurav Vaish, and with
29 * Ximian Inc
32 using System.ComponentModel;
33 using System.Collections;
34 using System.Collections.Specialized;
35 using System.Reflection;
36 using System.Web.UI;
37 using System.Web.Mobile;
39 namespace System.Web.UI.MobileControls
41 public class DeviceSpecificChoice : IParserAccessor,
42 IAttributeAccessor
44 private string argument;
45 private IDictionary contents;
46 private string filter;
47 private DeviceSpecific owner;
48 private IDictionary templates;
49 private string xmlns;
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)
62 return (string)val;
63 //FIXME
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
85 get
87 return this.argument;
89 set
91 this.argument = value;
95 public IDictionary Contents
97 get
99 if(this.contents == null)
101 this.contents = new ListDictionary(caseInsensitiveComparer);
103 return this.contents;
107 public string Filter
111 return this.filter;
115 this.filter = value;
119 public DeviceSpecific Owner
123 return this.owner;
127 this.owner = value;
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")
153 //FIXME
154 throw new ArgumentException("DeviceSpecificChoice" +
155 "_InvalidPropertyOverride");
157 if(value != null)
159 int dash = 0;
160 while((dash = key.IndexOf('-')) != -1)
162 string first = key.Substring(0, dash);
163 PropertyDescriptor pd =
164 TypeDescriptor.GetProperties(owner).Find(key, true);
165 if(pd == null)
167 //FIXME
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);
180 } else
182 //FIXME
183 throw new ArgumentException("DeviceSpecificChoice" +
184 "_OverridingPropertyNotFound");
191 /// <summary>
192 /// Returns false if not found or not applied
193 /// </summary>
194 private bool FindAndApplyProperty(object parentObj, string key,
195 string value)
197 bool retVal = false;
198 PropertyDescriptor pd =
199 TypeDescriptor.GetProperties(parentObj).Find(key, true);
200 if(pd != null)
202 if(pd.Attributes.Contains(
203 DesignerSerializationVisibilityAttribute.Hidden))
205 throw new ArgumentException("DeviceSpecificChoice" +
206 "_OverridingPropertyNotDeclarable");
208 throw new NotImplementedException();
210 return retVal;
213 private bool FindAndApplyEvent(object parentObj, string key,
214 string value)
216 bool retVal = false;
217 if(key.Length > 0)
219 if(key.ToLower().StartsWith("on"))
221 string eventName = key.Substring(2);
222 EventDescriptor ed =
223 TypeDescriptor.GetEvents(parentObj).Find(key, true);
224 if(ed != null)
226 ed.AddEventHandler(parentObj,
227 Delegate.CreateDelegate(ed.EventType,
228 Owner.MobilePage, eventName));
232 return retVal;
235 private bool CheckOnPageEvaluator(MobileCapabilities capabilities,
236 out bool evaluatorResult)
238 bool retVal = false;
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);