ControlAdapter.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 MobileControl Control
  56. {
  57. get
  58. {
  59. return this.control;
  60. }
  61. set
  62. {
  63. this.control = value;
  64. }
  65. }
  66. public int ItemWeight
  67. {
  68. get
  69. {
  70. return ControlPager.UseDefaultWeight;
  71. }
  72. }
  73. public MobilePage Page
  74. {
  75. get
  76. {
  77. if(Control != null)
  78. return Control.MobilePage;
  79. return null;
  80. }
  81. }
  82. public int VisibleWeight
  83. {
  84. get
  85. {
  86. return ControlPager.UseDefaultWeight;
  87. }
  88. }
  89. public void CreateTemplatedUI(bool doDataBind)
  90. {
  91. Control.CreateDefaultTemplatedUI(doDataBind);
  92. }
  93. public bool HandlePostBackEvent(string eventArguments)
  94. {
  95. return false;
  96. }
  97. public void LoadAdapterState(object state)
  98. {
  99. return;
  100. }
  101. public bool LoadPostData(string postKey,
  102. NameValueCollection postCollection,
  103. object privateControlData, out bool dataChanged)
  104. {
  105. dataChanged = false;
  106. return false;
  107. }
  108. public void OnInit(EventArgs e)
  109. {
  110. return;
  111. }
  112. public void OnLoad(EventArgs e)
  113. {
  114. return;
  115. }
  116. public void OnPreRender(EventArgs e)
  117. {
  118. return;
  119. }
  120. public void OnUnload(EventArgs e)
  121. {
  122. return;
  123. }
  124. public void Render(HtmlTextWriter writer)
  125. {
  126. RenderChildren(writer);
  127. }
  128. public object SaveAdapterState()
  129. {
  130. return null;
  131. }
  132. protected void RenderChildren(HtmlTextWriter writer)
  133. {
  134. if(Control != null && Control.HasControls())
  135. {
  136. foreach(Control cCtrl in Control.Controls)
  137. {
  138. cCtrl.RenderControl(writer);
  139. }
  140. if(Control.Controls.GetEnumerator() is IDisposable)
  141. {
  142. ((IDisposable)Control.Controls.GetEnumerator()).Dispose();
  143. }
  144. }
  145. }
  146. protected int CalculateOptimumPageWeight(int defaultPageWeight)
  147. {
  148. int defWt = defaultPageWeight;
  149. if(Device != null)
  150. {
  151. string httpDefWt = Device[Constants.OptimumPageWeightParameter];
  152. if(httpDefWt != null)
  153. {
  154. try
  155. {
  156. defWt = Convert.ToInt32(httpDefWt);
  157. } catch { }
  158. }
  159. }
  160. return -1;
  161. }
  162. }
  163. }