PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/mcs/class/referencesource/System.Web.Mobile/UI/MobileControls/Adapters/WmlControlAdapter.cs

https://github.com/pruiz/mono
C# | 354 lines | 269 code | 49 blank | 36 comment | 39 complexity | dd385b51758eb1f4c32dc01353e269e3 MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. //------------------------------------------------------------------------------
  2. // <copyright file="WmlControlAdapter.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. //------------------------------------------------------------------------------
  6. using System;
  7. using System.Collections;
  8. using System.Diagnostics;
  9. using System.Web.UI.MobileControls;
  10. using System.Web.UI.MobileControls.Adapters;
  11. using System.Web.Security;
  12. using System.Text;
  13. using System.Security.Permissions;
  14. #if COMPILING_FOR_SHIPPED_SOURCE
  15. namespace System.Web.UI.MobileControls.ShippedAdapterSource
  16. #else
  17. namespace System.Web.UI.MobileControls.Adapters
  18. #endif
  19. {
  20. /*
  21. * WmlControlAdapter base class contains wml specific methods.
  22. *
  23. * Copyright (c) 2000 Microsoft Corporation
  24. */
  25. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter"]/*' />
  26. [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
  27. [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
  28. [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
  29. public class WmlControlAdapter : System.Web.UI.MobileControls.Adapters.ControlAdapter
  30. {
  31. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.PageAdapter"]/*' />
  32. protected WmlPageAdapter PageAdapter
  33. {
  34. get
  35. {
  36. return ((WmlPageAdapter)Page.Adapter);
  37. }
  38. }
  39. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.FormAdapter"]/*' />
  40. protected WmlFormAdapter FormAdapter
  41. {
  42. get
  43. {
  44. return (WmlFormAdapter)Control.Form.Adapter;
  45. }
  46. }
  47. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.Render"]/*' />
  48. public override void Render(HtmlTextWriter writer)
  49. {
  50. Render((WmlMobileTextWriter)writer);
  51. }
  52. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.Render1"]/*' />
  53. public virtual void Render(WmlMobileTextWriter writer)
  54. {
  55. RenderChildren(writer);
  56. }
  57. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.RenderLink"]/*' />
  58. protected void RenderLink(WmlMobileTextWriter writer,
  59. String targetUrl,
  60. String softkeyLabel,
  61. bool implicitSoftkeyLabel,
  62. bool mapToSoftkey,
  63. String text,
  64. bool breakAfter)
  65. {
  66. RenderBeginLink(writer, targetUrl, softkeyLabel, implicitSoftkeyLabel, mapToSoftkey);
  67. writer.RenderText(text);
  68. RenderEndLink(writer, targetUrl, breakAfter);
  69. }
  70. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.RenderBeginLink"]/*' />
  71. protected void RenderBeginLink(WmlMobileTextWriter writer,
  72. String targetUrl,
  73. String softkeyLabel,
  74. bool implicitSoftkeyLabel,
  75. bool mapToSoftkey)
  76. {
  77. if (mapToSoftkey && !writer.IsValidSoftkeyLabel(softkeyLabel))
  78. {
  79. // If softkey label was specified explicitly, then truncate.
  80. if (!implicitSoftkeyLabel && softkeyLabel.Length > 0)
  81. {
  82. softkeyLabel = softkeyLabel.Substring(0, Device.MaximumSoftkeyLabelLength);
  83. }
  84. else
  85. {
  86. softkeyLabel = GetDefaultLabel(LinkLabel);
  87. implicitSoftkeyLabel = true;
  88. }
  89. }
  90. String postback = DeterminePostBack(targetUrl);
  91. if (postback != null)
  92. {
  93. writer.RenderBeginPostBack(softkeyLabel, implicitSoftkeyLabel, mapToSoftkey);
  94. }
  95. else
  96. {
  97. String prefix = Constants.FormIDPrefix;
  98. if (targetUrl.StartsWith(prefix, StringComparison.Ordinal))
  99. {
  100. String formID = targetUrl.Substring(prefix.Length);
  101. Form form = Control.ResolveFormReference(formID);
  102. targetUrl = prefix + form.ClientID;
  103. }
  104. else
  105. {
  106. bool absoluteUrl = ( (targetUrl.StartsWith("http:", StringComparison.Ordinal)) || (targetUrl.StartsWith("https:", StringComparison.Ordinal)) );
  107. // AUI 3652
  108. targetUrl = Control.ResolveUrl(targetUrl);
  109. bool queryStringWritten = targetUrl.IndexOf('?') != -1;
  110. IDictionary dictionary = PageAdapter.CookielessDataDictionary;
  111. String formsAuthCookieName = FormsAuthentication.FormsCookieName;
  112. if((dictionary != null) && (!absoluteUrl) && (Control.MobilePage.Adapter.PersistCookielessData))
  113. {
  114. StringBuilder sb = new StringBuilder(targetUrl);
  115. foreach(String name in dictionary.Keys)
  116. {
  117. if(queryStringWritten)
  118. {
  119. sb.Append("&amp;");
  120. }
  121. else
  122. {
  123. sb.Append("?");
  124. queryStringWritten = true;
  125. }
  126. if(name.Equals(formsAuthCookieName) && Device.CanRenderOneventAndPrevElementsTogether )
  127. {
  128. sb.Append(name);
  129. sb.Append("=$(");
  130. sb.Append(writer.MapClientIDToShortName("__facn",false));
  131. sb.Append(")");
  132. }
  133. else
  134. {
  135. sb.Append(name);
  136. sb.Append("=");
  137. sb.Append(dictionary[name]);
  138. }
  139. }
  140. targetUrl = sb.ToString();
  141. }
  142. }
  143. writer.RenderBeginHyperlink(targetUrl,
  144. false,
  145. softkeyLabel,
  146. implicitSoftkeyLabel,
  147. mapToSoftkey);
  148. }
  149. }
  150. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.RenderEndLink"]/*' />
  151. protected void RenderEndLink(WmlMobileTextWriter writer, String targetUrl, bool breakAfter)
  152. {
  153. String postback = DeterminePostBack(targetUrl);
  154. if (postback != null)
  155. {
  156. writer.RenderEndPostBack(Control.UniqueID, postback, WmlPostFieldType.Normal, false, breakAfter);
  157. }
  158. else
  159. {
  160. writer.RenderEndHyperlink(breakAfter);
  161. }
  162. }
  163. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.DeterminePostBack"]/*' />
  164. protected String DeterminePostBack(String target)
  165. {
  166. String postback = null;
  167. String prefix = Constants.FormIDPrefix;
  168. if (target.StartsWith(prefix, StringComparison.Ordinal)) // link to another form
  169. {
  170. String formID = target.Substring(prefix.Length);
  171. Form form = Control.ResolveFormReference(formID);
  172. Form thisForm = Control.Form;
  173. // must postback to forms not rendered in deck (not visible) or links to same form,
  174. // as long as it's safe to do so.
  175. if (form == thisForm ||
  176. !PageAdapter.IsFormRendered(form) ||
  177. thisForm.HasDeactivateHandler() ||
  178. form.HasActivateHandler())
  179. {
  180. postback = form.UniqueID;
  181. }
  182. }
  183. return postback;
  184. }
  185. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.RenderSubmitEvent"]/*' />
  186. protected void RenderSubmitEvent(
  187. WmlMobileTextWriter writer,
  188. String softkeyLabel,
  189. String text,
  190. bool breakAfter)
  191. {
  192. RenderPostBackEvent(writer, null, softkeyLabel, true,
  193. text, breakAfter, WmlPostFieldType.Submit);
  194. }
  195. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.RenderPostBackEvent"]/*' />
  196. protected void RenderPostBackEvent(
  197. WmlMobileTextWriter writer,
  198. String argument,
  199. String softkeyLabel,
  200. bool mapToSoftkey,
  201. String text,
  202. bool breakAfter)
  203. {
  204. RenderPostBackEvent(writer, argument, softkeyLabel, mapToSoftkey,
  205. text, breakAfter, WmlPostFieldType.Normal);
  206. }
  207. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.RenderPostBackEvent1"]/*' />
  208. protected void RenderPostBackEvent(
  209. WmlMobileTextWriter writer,
  210. String argument,
  211. String softkeyLabel,
  212. bool mapToSoftkey,
  213. String text,
  214. bool breakAfter,
  215. WmlPostFieldType postBackType)
  216. {
  217. bool implicitSoftkeyLabel = false;
  218. if (mapToSoftkey)
  219. {
  220. if (softkeyLabel == null || softkeyLabel.Length == 0)
  221. {
  222. softkeyLabel = text;
  223. implicitSoftkeyLabel = true;
  224. }
  225. if (!writer.IsValidSoftkeyLabel(softkeyLabel))
  226. {
  227. // If softkey label was specified explicitly, then truncate.
  228. if (!implicitSoftkeyLabel && softkeyLabel.Length > 0)
  229. {
  230. softkeyLabel = softkeyLabel.Substring(0, Device.MaximumSoftkeyLabelLength);
  231. }
  232. else
  233. {
  234. softkeyLabel = GetDefaultLabel(GoLabel);
  235. implicitSoftkeyLabel = true;
  236. }
  237. }
  238. }
  239. writer.RenderBeginPostBack(softkeyLabel, implicitSoftkeyLabel, mapToSoftkey);
  240. writer.RenderText(text);
  241. writer.RenderEndPostBack(Control.UniqueID, argument, postBackType, true, breakAfter);
  242. }
  243. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.GetPostBackValue"]/*' />
  244. protected virtual String GetPostBackValue()
  245. {
  246. return null;
  247. }
  248. internal String GetControlPostBackValue(MobileControl ctl)
  249. {
  250. WmlControlAdapter adapter = ctl.Adapter as WmlControlAdapter;
  251. return adapter != null ? adapter.GetPostBackValue() : null;
  252. }
  253. /////////////////////////////////////////////////////////////////////////
  254. // SECONDARY UI SUPPORT
  255. /////////////////////////////////////////////////////////////////////////
  256. internal const int NotSecondaryUIInit = -1; // For initialization of private consts in derived classes.
  257. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.NotSecondaryUI"]/*' />
  258. protected static readonly int NotSecondaryUI = NotSecondaryUIInit;
  259. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.SecondaryUIMode"]/*' />
  260. protected int SecondaryUIMode
  261. {
  262. get
  263. {
  264. if (Control == null || Control.Form == null)
  265. {
  266. return NotSecondaryUI;
  267. }
  268. else
  269. {
  270. return ((WmlFormAdapter)Control.Form.Adapter).GetSecondaryUIMode(Control);
  271. }
  272. }
  273. set
  274. {
  275. ((WmlFormAdapter)Control.Form.Adapter).SetSecondaryUIMode(Control, value);
  276. }
  277. }
  278. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.ExitSecondaryUIMode"]/*' />
  279. protected void ExitSecondaryUIMode()
  280. {
  281. SecondaryUIMode = NotSecondaryUI;
  282. }
  283. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.LoadAdapterState"]/*' />
  284. public override void LoadAdapterState(Object state)
  285. {
  286. if (state != null)
  287. {
  288. SecondaryUIMode = (int)state;
  289. }
  290. }
  291. /// <include file='doc\WmlControlAdapter.uex' path='docs/doc[@for="WmlControlAdapter.SaveAdapterState"]/*' />
  292. public override Object SaveAdapterState()
  293. {
  294. int mode = SecondaryUIMode;
  295. if (mode != NotSecondaryUI)
  296. {
  297. return mode;
  298. }
  299. else
  300. {
  301. return null;
  302. }
  303. }
  304. }
  305. }