HtmlMobileTextWriter.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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 : HtmlMobileTextWriter
  25. * Author : Gaurav Vaish
  26. *
  27. * Copyright : 2003 with Gaurav Vaish, and with
  28. * Ximian Inc
  29. */
  30. using System;
  31. using System.IO;
  32. using System.Web.Mobile;
  33. namespace System.Web.UI.MobileControls.Adapters
  34. {
  35. public class HtmlMobileTextWriter : MobileTextWriter
  36. {
  37. private bool beforeFirstControlWritten = true;
  38. private bool maintainState = true;
  39. private bool renderBodyColor = true;
  40. private bool renderBold = true;
  41. private bool renderDivAlign = true;
  42. private bool renderDivNoWrap = false;
  43. private bool renderFontColor = true;
  44. private bool renderFontName = true;
  45. private bool renderFontSize = true;
  46. private bool renderItalic = true;
  47. private bool requiresNoBreak = false;
  48. private bool shouldEnsureStyle = true;
  49. private WriterState currentState;
  50. [MonoTODO]
  51. public HtmlMobileTextWriter(TextWriter writer,
  52. MobileCapabilities capabilities)
  53. : base(writer, capabilities)
  54. {
  55. RenderBold = capabilities.SupportsBold;
  56. RenderItalic = capabilities.SupportsItalic;
  57. RenderFontSize = capabilities.SupportsFontSize;
  58. RenderFontName = capabilities.SupportsFontName;
  59. RenderFontColor = capabilities.SupportsFontColor;
  60. RenderBodyColor = capabilities.SupportsBodyColor;
  61. RenderDivAlign = capabilities.SupportsDivAlign;
  62. RenderDivNoWrap = capabilities.SupportsDivNoWrap;
  63. RequiresNoBreakInFormatting = capabilities.RequiresNoBreakInFormatting;
  64. currentState = new WriterState(this);
  65. }
  66. public bool BeforeFirstControlWritten
  67. {
  68. get
  69. {
  70. return beforeFirstControlWritten;
  71. }
  72. set
  73. {
  74. beforeFirstControlWritten = value;
  75. }
  76. }
  77. public bool MaintainState
  78. {
  79. get
  80. {
  81. return maintainState;
  82. }
  83. set
  84. {
  85. maintainState = value;
  86. }
  87. }
  88. public bool RenderBodyColor
  89. {
  90. get
  91. {
  92. return renderBodyColor;
  93. }
  94. set
  95. {
  96. renderBodyColor = value;
  97. }
  98. }
  99. public bool RenderBold
  100. {
  101. get
  102. {
  103. return renderBold;
  104. }
  105. set
  106. {
  107. renderBold = value;
  108. }
  109. }
  110. public bool RenderDivAlign
  111. {
  112. get
  113. {
  114. return renderDivAlign;
  115. }
  116. set
  117. {
  118. renderDivAlign = value;
  119. }
  120. }
  121. public bool RenderDivNoWrap
  122. {
  123. get
  124. {
  125. return renderDivNoWrap;
  126. }
  127. set
  128. {
  129. renderDivNoWrap = value;
  130. }
  131. }
  132. public bool RenderFontColor
  133. {
  134. get
  135. {
  136. return renderFontColor;
  137. }
  138. set
  139. {
  140. renderFontColor = value;
  141. }
  142. }
  143. public bool RenderFontName
  144. {
  145. get
  146. {
  147. return renderFontName;
  148. }
  149. set
  150. {
  151. renderFontName = value;
  152. }
  153. }
  154. public bool RenderFontSize
  155. {
  156. get
  157. {
  158. return renderFontSize;
  159. }
  160. set
  161. {
  162. renderFontSize = value;
  163. }
  164. }
  165. public bool RenderItalic
  166. {
  167. get
  168. {
  169. return renderItalic;
  170. }
  171. set
  172. {
  173. renderItalic = value;
  174. }
  175. }
  176. public bool RequiresNoBreakInFormatting
  177. {
  178. get
  179. {
  180. return requiresNoBreak;
  181. }
  182. set
  183. {
  184. requiresNoBreak = value;
  185. }
  186. }
  187. public bool ShouldEnsureStyle
  188. {
  189. get
  190. {
  191. return shouldEnsureStyle;
  192. }
  193. set
  194. {
  195. shouldEnsureStyle = value;
  196. }
  197. }
  198. [MonoTODO]
  199. public void EnterLayout(Style style)
  200. {
  201. throw new NotImplementedException();
  202. }
  203. [MonoTODO]
  204. public void ExitLayout(Style style, bool breakAfter)
  205. {
  206. throw new NotImplementedException();
  207. }
  208. [MonoTODO]
  209. public void EnterStyle(System.Web.UI.MobileControls.Style style)
  210. {
  211. throw new NotImplementedException();
  212. }
  213. private void EnterStyle(WriterStyle style)
  214. {
  215. currentState.Push(style);
  216. }
  217. public void ExitStyle(Style style)
  218. {
  219. ExitStyle(style, false);
  220. }
  221. [MonoTODO]
  222. public void ExitStyle(Style style, bool breakAfter)
  223. {
  224. throw new NotImplementedException();
  225. }
  226. [MonoTODO]
  227. public void WriteText(string text, bool encode)
  228. {
  229. throw new NotImplementedException();
  230. }
  231. [MonoTODO]
  232. public override void Write(char c)
  233. {
  234. throw new NotImplementedException();
  235. }
  236. [MonoTODO]
  237. public override void Write(string text)
  238. {
  239. throw new NotImplementedException();
  240. }
  241. public void BeginStyleContext()
  242. {
  243. if(currentState.IsBreakPending)
  244. {
  245. WriteBreak();
  246. currentState.IsBreakPending = false;
  247. }
  248. currentState.PushState();
  249. EnterStyle(new WriterStyle());
  250. }
  251. public void EndStyleContext()
  252. {
  253. if(currentState.IsBreakPending)
  254. {
  255. WriteBreak();
  256. currentState.IsBreakPending = false;
  257. }
  258. currentState.PopState();
  259. currentState.Pop();
  260. currentState.Transition(new WriterStyle());
  261. }
  262. public void EnterFormat(Style style)
  263. {
  264. WriterStyle wstyle = new WriterStyle(style);
  265. wstyle.Layout = false;
  266. EnterStyle(wstyle);
  267. }
  268. public virtual void ExitFormat(Style style)
  269. {
  270. ExitStyle(style);
  271. }
  272. public void WriteBreak()
  273. {
  274. WriteLine("<br>");
  275. }
  276. public override void WriteLine(string text)
  277. {
  278. EnsureStyle();
  279. base.WriteLine(text);
  280. }
  281. internal void EnsureStyle()
  282. {
  283. if(shouldEnsureStyle)
  284. {
  285. if(currentState.Count > 0)
  286. {
  287. currentState.Transition(currentState.Peek());
  288. }
  289. shouldEnsureStyle = false;
  290. }
  291. if(BeforeFirstControlWritten)
  292. {
  293. BeforeFirstControlWritten = false;
  294. }
  295. }
  296. }
  297. }