ControlAdapter.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /**
  2. * Project : Mono
  3. * Namespace : System.Web.UI.MobileControls.Adapters
  4. * Class : ControlAdapter
  5. * Author : Gaurav Vaish
  6. *
  7. * Copyright : 2003 with Gaurav Vaish, and with
  8. * Ximian Inc
  9. */
  10. using System;
  11. using System.Collections.Specialized;
  12. using System.Web.Mobile;
  13. using System.Web.UI;
  14. using System.Web.UI.MobileControls;
  15. namespace System.Web.UI.MobileControls.Adapters
  16. {
  17. public abstract class ControlAdapter : IControlAdapter
  18. {
  19. private MobileControl control = null;
  20. protected static readonly int BackLabel = 0x00;
  21. protected static readonly int GoLabel = 0x01;
  22. protected static readonly int OKLabel = 0x02;
  23. protected static readonly int MoreLabel = 0x03;
  24. protected static readonly int OptionsLabel = 0x04;
  25. protected static readonly int NextLabel = 0x05;
  26. protected static readonly int PreviousLabel = 0x06;
  27. protected static readonly int LinkLabel = 0x07;
  28. protected static readonly int CallLabel = 0x08;
  29. private static string[] labelIDs = {
  30. "ControlAdapter_Back",
  31. "ControlAdapter_Go",
  32. "ControlAdapter_OK",
  33. "ControlAdapter_More",
  34. "ControlAdapter_Options",
  35. "ControlAdapter_Next",
  36. "ControlAdapter_Previous",
  37. "ControlAdapter_Link",
  38. "ControlAdapter_Call"
  39. };
  40. private string[] defaultLabels = null;
  41. public ControlAdapter()
  42. {
  43. }
  44. public MobileCapabilities Device
  45. {
  46. get
  47. {
  48. if(Page != null)
  49. {
  50. return (MobileCapabilities) Page.Request.Browser;
  51. }
  52. return null;
  53. }
  54. }
  55. public System.Web.UI.MobileControls.Style Style
  56. {
  57. get
  58. {
  59. return Control.Style;
  60. }
  61. }
  62. public virtual MobileControl Control
  63. {
  64. get
  65. {
  66. return this.control;
  67. }
  68. set
  69. {
  70. this.control = value;
  71. }
  72. }
  73. public int ItemWeight
  74. {
  75. get
  76. {
  77. return ControlPager.UseDefaultWeight;
  78. }
  79. }
  80. public MobilePage Page
  81. {
  82. get
  83. {
  84. if(Control != null)
  85. return Control.MobilePage;
  86. return null;
  87. }
  88. }
  89. public int VisibleWeight
  90. {
  91. get
  92. {
  93. return ControlPager.UseDefaultWeight;
  94. }
  95. }
  96. public void CreateTemplatedUI(bool doDataBind)
  97. {
  98. Control.CreateDefaultTemplatedUI(doDataBind);
  99. }
  100. public virtual bool HandlePostBackEvent(string eventArguments)
  101. {
  102. return false;
  103. }
  104. public virtual void LoadAdapterState(object state)
  105. {
  106. }
  107. public virtual bool LoadPostData(string postKey,
  108. NameValueCollection postCollection,
  109. object privateControlData, out bool dataChanged)
  110. {
  111. dataChanged = false;
  112. return false;
  113. }
  114. public virtual void OnInit(EventArgs e)
  115. {
  116. return;
  117. }
  118. public virtual void OnLoad(EventArgs e)
  119. {
  120. return;
  121. }
  122. public virtual void OnPreRender(EventArgs e)
  123. {
  124. return;
  125. }
  126. public virtual void OnUnload(EventArgs e)
  127. {
  128. return;
  129. }
  130. public virtual void Render(HtmlTextWriter writer)
  131. {
  132. RenderChildren(writer);
  133. }
  134. public virtual object SaveAdapterState()
  135. {
  136. return null;
  137. }
  138. protected void RenderChildren(HtmlTextWriter writer)
  139. {
  140. if(Control != null && Control.HasControls())
  141. {
  142. foreach(Control cCtrl in Control.Controls)
  143. {
  144. cCtrl.RenderControl(writer);
  145. }
  146. if(Control.Controls.GetEnumerator() is IDisposable)
  147. {
  148. ((IDisposable)Control.Controls.GetEnumerator()).Dispose();
  149. }
  150. }
  151. }
  152. protected int CalculateOptimumPageWeight(int defaultPageWeight)
  153. {
  154. int defWt = defaultPageWeight;
  155. if(Device != null)
  156. {
  157. string httpDefWt = Device[Constants.OptimumPageWeightParameter];
  158. if(httpDefWt != null)
  159. {
  160. try
  161. {
  162. defWt = Convert.ToInt32(httpDefWt);
  163. } catch { }
  164. }
  165. }
  166. return -1;
  167. }
  168. protected string GetDefaultLabel(int labelID)
  169. {
  170. if(labelID < 0 || labelID >= labelIDs.Length)
  171. {
  172. // FIXME
  173. throw new ArgumentException("ControlAdapter" +
  174. "_InvalidDefaultLabel");
  175. }
  176. string retVal = null;
  177. if(Page != null)
  178. {
  179. ControlAdapter ca = (ControlAdapter)Page.Adapter;
  180. if(defaultLabels == null)
  181. {
  182. defaultLabels = new string[labelIDs.Length];
  183. Array.Copy(labelIDs, defaultLabels, labelIDs.Length);
  184. }
  185. retVal = defaultLabels[labelID];
  186. }
  187. if(retVal == null)
  188. {
  189. retVal = labelIDs[labelID];
  190. }
  191. return retVal;
  192. }
  193. }
  194. }