**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Web.Mobile / System.Web.UI.MobileControls.Adapters / ControlAdapter.cs
blob4210fa9869f58345836aaf92074a75a83dd5379f
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.Adapters
25 * Class : ControlAdapter
26 * Author : Gaurav Vaish
28 * Copyright : 2003 with Gaurav Vaish, and with
29 * Ximian Inc
32 using System;
33 using System.Collections.Specialized;
34 using System.Web.Mobile;
35 using System.Web.UI;
36 using System.Web.UI.MobileControls;
38 namespace System.Web.UI.MobileControls.Adapters
40 public abstract class ControlAdapter : IControlAdapter
42 private MobileControl control = null;
44 protected static readonly int BackLabel = 0x00;
45 protected static readonly int GoLabel = 0x01;
46 protected static readonly int OKLabel = 0x02;
47 protected static readonly int MoreLabel = 0x03;
48 protected static readonly int OptionsLabel = 0x04;
49 protected static readonly int NextLabel = 0x05;
50 protected static readonly int PreviousLabel = 0x06;
51 protected static readonly int LinkLabel = 0x07;
52 protected static readonly int CallLabel = 0x08;
54 private static string[] labelIDs = {
55 "ControlAdapter_Back",
56 "ControlAdapter_Go",
57 "ControlAdapter_OK",
58 "ControlAdapter_More",
59 "ControlAdapter_Options",
60 "ControlAdapter_Next",
61 "ControlAdapter_Previous",
62 "ControlAdapter_Link",
63 "ControlAdapter_Call"
66 private string[] defaultLabels = null;
68 public ControlAdapter()
72 public MobileCapabilities Device
74 get
76 if(Page != null)
78 return (MobileCapabilities) Page.Request.Browser;
80 return null;
84 public System.Web.UI.MobileControls.Style Style
86 get
88 return Control.Style;
92 public virtual MobileControl Control
94 get
96 return this.control;
98 set
100 this.control = value;
104 public int ItemWeight
108 return ControlPager.UseDefaultWeight;
112 public MobilePage Page
116 if(Control != null)
117 return Control.MobilePage;
118 return null;
122 public int VisibleWeight
126 return ControlPager.UseDefaultWeight;
130 public void CreateTemplatedUI(bool doDataBind)
132 Control.CreateDefaultTemplatedUI(doDataBind);
135 public virtual bool HandlePostBackEvent(string eventArguments)
137 return false;
140 public virtual void LoadAdapterState(object state)
144 public virtual bool LoadPostData(string postKey,
145 NameValueCollection postCollection,
146 object privateControlData, out bool dataChanged)
148 dataChanged = false;
149 return false;
152 public virtual void OnInit(EventArgs e)
154 return;
157 public virtual void OnLoad(EventArgs e)
159 return;
162 public virtual void OnPreRender(EventArgs e)
164 return;
167 public virtual void OnUnload(EventArgs e)
169 return;
172 public virtual void Render(HtmlTextWriter writer)
174 RenderChildren(writer);
177 public virtual object SaveAdapterState()
179 return null;
182 protected void RenderChildren(HtmlTextWriter writer)
184 if(Control != null && Control.HasControls())
186 foreach(Control cCtrl in Control.Controls)
188 cCtrl.RenderControl(writer);
190 if(Control.Controls.GetEnumerator() is IDisposable)
192 ((IDisposable)Control.Controls.GetEnumerator()).Dispose();
197 protected int CalculateOptimumPageWeight(int defaultPageWeight)
199 int defWt = defaultPageWeight;
200 if(Device != null)
202 string httpDefWt = Device[Constants.OptimumPageWeightParameter];
203 if(httpDefWt != null)
207 defWt = Convert.ToInt32(httpDefWt);
208 } catch { }
211 return -1;
214 protected string GetDefaultLabel(int labelID)
216 if(labelID < 0 || labelID >= labelIDs.Length)
218 // FIXME
219 throw new ArgumentException("ControlAdapter" +
220 "_InvalidDefaultLabel");
222 string retVal = null;
223 if(Page != null)
225 ControlAdapter ca = (ControlAdapter)Page.Adapter;
226 if(defaultLabels == null)
228 defaultLabels = new string[labelIDs.Length];
229 Array.Copy(labelIDs, defaultLabels, labelIDs.Length);
231 retVal = defaultLabels[labelID];
233 if(retVal == null)
235 retVal = labelIDs[labelID];
237 return retVal;