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.Adapters
25 * Class : ControlAdapter
26 * Author : Gaurav Vaish
28 * Copyright : 2003 with Gaurav Vaish, and with
33 using System
.Collections
.Specialized
;
34 using System
.Web
.Mobile
;
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",
58 "ControlAdapter_More",
59 "ControlAdapter_Options",
60 "ControlAdapter_Next",
61 "ControlAdapter_Previous",
62 "ControlAdapter_Link",
66 private string[] defaultLabels
= null;
68 public ControlAdapter()
72 public MobileCapabilities Device
78 return (MobileCapabilities
) Page
.Request
.Browser
;
84 public System
.Web
.UI
.MobileControls
.Style Style
92 public virtual MobileControl Control
100 this.control
= value;
104 public int ItemWeight
108 return ControlPager
.UseDefaultWeight
;
112 public MobilePage Page
117 return Control
.MobilePage
;
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
)
140 public virtual void LoadAdapterState(object state
)
144 public virtual bool LoadPostData(string postKey
,
145 NameValueCollection postCollection
,
146 object privateControlData
, out bool dataChanged
)
152 public virtual void OnInit(EventArgs e
)
157 public virtual void OnLoad(EventArgs e
)
162 public virtual void OnPreRender(EventArgs e
)
167 public virtual void OnUnload(EventArgs e
)
172 public virtual void Render(HtmlTextWriter writer
)
174 RenderChildren(writer
);
177 public virtual object SaveAdapterState()
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
;
202 string httpDefWt
= Device
[Constants
.OptimumPageWeightParameter
];
203 if(httpDefWt
!= null)
207 defWt
= Convert
.ToInt32(httpDefWt
);
214 protected string GetDefaultLabel(int labelID
)
216 if(labelID
< 0 || labelID
>= labelIDs
.Length
)
219 throw new ArgumentException("ControlAdapter" +
220 "_InvalidDefaultLabel");
222 string retVal
= 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
];
235 retVal
= labelIDs
[labelID
];