HtmlCommandAdapter.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 : HtmlCommandAdapter
  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.MobileControls;
  34. namespace System.Web.UI.MobileControls.Adapters
  35. {
  36. public class HtmlCommandAdapter : HtmlControlAdapter
  37. {
  38. public HtmlCommandAdapter() : base()
  39. {
  40. }
  41. protected new Command Control
  42. {
  43. get
  44. {
  45. return base.Control as Command;
  46. }
  47. }
  48. public override bool LoadPostData(string postKey,
  49. NameValueCollection data,
  50. object privateControlData, out bool dataChanged)
  51. {
  52. dataChanged = false;
  53. bool retVal = false;
  54. if(Control != null)
  55. {
  56. string id = Control.UniqueID;
  57. string ctrl = data[id + ".x"];
  58. string evnt = data[id + ".y"];
  59. if(ctrl != null && evnt != null && ctrl.Length > 0 && evnt.Length > 0)
  60. {
  61. dataChanged = true;
  62. retVal = true;
  63. }
  64. }
  65. return retVal;
  66. }
  67. public override void Render(HtmlMobileTextWriter writer)
  68. {
  69. bool supportsImgSbt = false;
  70. bool supportsJavascript = false;
  71. Form mobileForm = null;
  72. if(Control != null)
  73. {
  74. if(Control.ImageUrl != String.Empty && Device.SupportsImageSubmit)
  75. {
  76. supportsImgSbt = true;
  77. if(Control.Format == CommandFormat.Link)
  78. {
  79. if(Device.JavaScript)
  80. {
  81. supportsJavascript = true;
  82. }
  83. }
  84. }
  85. }
  86. if(supportsJavascript)
  87. {
  88. writer.EnterStyle(Style);
  89. mobileForm = Control.Form;
  90. if(mobileForm.Action.Length > 0)
  91. {
  92. writer.Write("<a href=\"javascript:document.");
  93. writer.Write(mobileForm.ClientID);
  94. writer.Write(".submit()\"");
  95. base.AddAttributes(writer);
  96. writer.Write(">");
  97. writer.WriteText(Control.Text, false);
  98. writer.WriteEndTag("a");
  99. } else
  100. {
  101. base.RenderBeginLink(writer, Constants.FormIDPrefix + mobileForm.UniqueID);
  102. writer.WriteText(Control.Text, true);
  103. base.RenderEndLink(writer);
  104. }
  105. writer.ExitStyle(Style, Control.BreakAfter);
  106. } else
  107. {
  108. writer.EnterLayout(Style);
  109. writer.WriteBeginTag("input");
  110. writer.WriteAttribute("name", Control.UniqueID);
  111. if(supportsImgSbt)
  112. {
  113. writer.WriteAttribute("type", "image");
  114. writer.WriteAttribute("src", Control.ResolveUrl(Control.ImageUrl));
  115. writer.WriteAttribute("alt", Control.Text);
  116. } else
  117. {
  118. writer.WriteAttribute("type", "submit");
  119. writer.Write("value=\"");
  120. writer.WriteText(Control.Text, true);
  121. }
  122. writer.Write("\"");
  123. base.AddAttributes(writer);
  124. writer.Write("/>");
  125. writer.ExitLayout(Style, Control.BreakAfter);
  126. }
  127. }
  128. }
  129. }