HtmlMobileTextWriter.cs 5.1 KB

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