2
0

ControlAdapter.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. //
  2. // Permission is hereby granted, free of charge, to any person obtaining
  3. // a copy of this software and associated documentation files (the
  4. // "Software"), to deal in the Software without restriction, including
  5. // without limitation the rights to use, copy, modify, merge, publish,
  6. // distribute, sublicense, and/or sell copies of the Software, and to
  7. // permit persons to whom the Software is furnished to do so, subject to
  8. // the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be
  11. // included in all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. /**
  22. * Project : Mono
  23. * Namespace : System.Web.UI.MobileControls.Adapters
  24. * Class : ControlAdapter
  25. * Author : Gaurav Vaish
  26. *
  27. * Copyright : 2003 with Gaurav Vaish, and with
  28. * Ximian Inc
  29. */
  30. using System;
  31. using System.Collections.Specialized;
  32. using System.Web.Mobile;
  33. using System.Web.UI;
  34. using System.Web.UI.MobileControls;
  35. namespace System.Web.UI.MobileControls.Adapters
  36. {
  37. public abstract class ControlAdapter : IControlAdapter
  38. {
  39. private MobileControl control = null;
  40. protected static readonly int BackLabel = 0x00;
  41. protected static readonly int GoLabel = 0x01;
  42. protected static readonly int OKLabel = 0x02;
  43. protected static readonly int MoreLabel = 0x03;
  44. protected static readonly int OptionsLabel = 0x04;
  45. protected static readonly int NextLabel = 0x05;
  46. protected static readonly int PreviousLabel = 0x06;
  47. protected static readonly int LinkLabel = 0x07;
  48. protected static readonly int CallLabel = 0x08;
  49. private static string[] labelIDs = {
  50. "ControlAdapter_Back",
  51. "ControlAdapter_Go",
  52. "ControlAdapter_OK",
  53. "ControlAdapter_More",
  54. "ControlAdapter_Options",
  55. "ControlAdapter_Next",
  56. "ControlAdapter_Previous",
  57. "ControlAdapter_Link",
  58. "ControlAdapter_Call"
  59. };
  60. private string[] defaultLabels = null;
  61. public ControlAdapter()
  62. {
  63. }
  64. public MobileCapabilities Device
  65. {
  66. get
  67. {
  68. if(Page != null)
  69. {
  70. return (MobileCapabilities) Page.Request.Browser;
  71. }
  72. return null;
  73. }
  74. }
  75. public System.Web.UI.MobileControls.Style Style
  76. {
  77. get
  78. {
  79. return Control.Style;
  80. }
  81. }
  82. public virtual MobileControl Control
  83. {
  84. get
  85. {
  86. return this.control;
  87. }
  88. set
  89. {
  90. this.control = value;
  91. }
  92. }
  93. public int ItemWeight
  94. {
  95. get
  96. {
  97. return ControlPager.UseDefaultWeight;
  98. }
  99. }
  100. public MobilePage Page
  101. {
  102. get
  103. {
  104. if(Control != null)
  105. return Control.MobilePage;
  106. return null;
  107. }
  108. }
  109. public int VisibleWeight
  110. {
  111. get
  112. {
  113. return ControlPager.UseDefaultWeight;
  114. }
  115. }
  116. public void CreateTemplatedUI(bool doDataBind)
  117. {
  118. Control.CreateDefaultTemplatedUI(doDataBind);
  119. }
  120. public virtual bool HandlePostBackEvent(string eventArguments)
  121. {
  122. return false;
  123. }
  124. public virtual void LoadAdapterState(object state)
  125. {
  126. }
  127. public virtual bool LoadPostData(string postKey,
  128. NameValueCollection postCollection,
  129. object privateControlData, out bool dataChanged)
  130. {
  131. dataChanged = false;
  132. return false;
  133. }
  134. public virtual void OnInit(EventArgs e)
  135. {
  136. return;
  137. }
  138. public virtual void OnLoad(EventArgs e)
  139. {
  140. return;
  141. }
  142. public virtual void OnPreRender(EventArgs e)
  143. {
  144. return;
  145. }
  146. public virtual void OnUnload(EventArgs e)
  147. {
  148. return;
  149. }
  150. public virtual void Render(HtmlTextWriter writer)
  151. {
  152. RenderChildren(writer);
  153. }
  154. public virtual object SaveAdapterState()
  155. {
  156. return null;
  157. }
  158. protected void RenderChildren(HtmlTextWriter writer)
  159. {
  160. if(Control != null && Control.HasControls())
  161. {
  162. foreach(Control cCtrl in Control.Controls)
  163. {
  164. cCtrl.RenderControl(writer);
  165. }
  166. if(Control.Controls.GetEnumerator() is IDisposable)
  167. {
  168. ((IDisposable)Control.Controls.GetEnumerator()).Dispose();
  169. }
  170. }
  171. }
  172. protected int CalculateOptimumPageWeight(int defaultPageWeight)
  173. {
  174. int defWt = defaultPageWeight;
  175. if(Device != null)
  176. {
  177. string httpDefWt = Device[Constants.OptimumPageWeightParameter];
  178. if(httpDefWt != null)
  179. {
  180. try
  181. {
  182. defWt = Convert.ToInt32(httpDefWt);
  183. } catch { }
  184. }
  185. }
  186. return -1;
  187. }
  188. protected string GetDefaultLabel(int labelID)
  189. {
  190. if(labelID < 0 || labelID >= labelIDs.Length)
  191. {
  192. // FIXME
  193. throw new ArgumentException("ControlAdapter" +
  194. "_InvalidDefaultLabel");
  195. }
  196. string retVal = null;
  197. if(Page != null)
  198. {
  199. ControlAdapter ca = (ControlAdapter)Page.Adapter;
  200. if(defaultLabels == null)
  201. {
  202. defaultLabels = new string[labelIDs.Length];
  203. Array.Copy(labelIDs, defaultLabels, labelIDs.Length);
  204. }
  205. retVal = defaultLabels[labelID];
  206. }
  207. if(retVal == null)
  208. {
  209. retVal = labelIDs[labelID];
  210. }
  211. return retVal;
  212. }
  213. }
  214. }