2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Web.Mobile / System.Web.UI.MobileControls.Adapters / HtmlMobileTextWriter.cs
1
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
10 // 
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 // 
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 /**
23  * Project   : Mono
24  * Namespace : System.Web.UI.MobileControls.Adapters
25  * Class     : HtmlMobileTextWriter
26  * Author    : Gaurav Vaish
27  *
28  * Copyright : 2003 with Gaurav Vaish, and with
29  *             Ximian Inc
30  */
31
32 using System;
33 using System.IO;
34 using System.Web.Mobile;
35
36 namespace System.Web.UI.MobileControls.Adapters
37 {
38         public class HtmlMobileTextWriter : MobileTextWriter
39         {
40                 private bool beforeFirstControlWritten = true;
41                 private bool maintainState = true;
42                 private bool renderBodyColor = true;
43                 private bool renderBold = true;
44                 private bool renderDivAlign = true;
45                 private bool renderDivNoWrap = false;
46                 private bool renderFontColor = true;
47                 private bool renderFontName = true;
48                 private bool renderFontSize = true;
49                 private bool renderItalic = true;
50                 private bool requiresNoBreak = false;
51                 private bool shouldEnsureStyle = true;
52
53                 private WriterState currentState;
54
55                 [MonoTODO]
56                 public HtmlMobileTextWriter(TextWriter writer,
57                                  MobileCapabilities capabilities)
58                                  : base(writer, capabilities)
59                 {
60                         RenderBold = capabilities.SupportsBold;
61                         RenderItalic = capabilities.SupportsItalic;
62                         RenderFontSize = capabilities.SupportsFontSize;
63                         RenderFontName = capabilities.SupportsFontName;
64                         RenderFontColor = capabilities.SupportsFontColor;
65                         RenderBodyColor = capabilities.SupportsBodyColor;
66                         RenderDivAlign = capabilities.SupportsDivAlign;
67                         RenderDivNoWrap = capabilities.SupportsDivNoWrap;
68                         RequiresNoBreakInFormatting = capabilities.RequiresNoBreakInFormatting;
69
70                         currentState = new WriterState(this);
71                 }
72
73                 public bool BeforeFirstControlWritten
74                 {
75                         get
76                         {
77                                 return beforeFirstControlWritten;
78                         }
79                         set
80                         {
81                                 beforeFirstControlWritten = value;
82                         }
83                 }
84
85                 public bool MaintainState
86                 {
87                         get
88                         {
89                                 return maintainState;
90                         }
91                         set
92                         {
93                                 maintainState = value;
94                         }
95                 }
96
97                 public bool RenderBodyColor
98                 {
99                         get
100                         {
101                                 return renderBodyColor;
102                         }
103                         set
104                         {
105                                 renderBodyColor = value;
106                         }
107                 }
108
109                 public bool RenderBold
110                 {
111                         get
112                         {
113                                 return renderBold;
114                         }
115                         set
116                         {
117                                 renderBold = value;
118                         }
119                 }
120
121                 public bool RenderDivAlign
122                 {
123                         get
124                         {
125                                 return renderDivAlign;
126                         }
127                         set
128                         {
129                                 renderDivAlign = value;
130                         }
131                 }
132
133                 public bool RenderDivNoWrap
134                 {
135                         get
136                         {
137                                 return renderDivNoWrap;
138                         }
139                         set
140                         {
141                                 renderDivNoWrap = value;
142                         }
143                 }
144
145                 public bool RenderFontColor
146                 {
147                         get
148                         {
149                                 return renderFontColor;
150                         }
151                         set
152                         {
153                                 renderFontColor = value;
154                         }
155                 }
156
157                 public bool RenderFontName
158                 {
159                         get
160                         {
161                                 return renderFontName;
162                         }
163                         set
164                         {
165                                 renderFontName = value;
166                         }
167                 }
168
169                 public bool RenderFontSize
170                 {
171                         get
172                         {
173                                 return renderFontSize;
174                         }
175                         set
176                         {
177                                 renderFontSize = value;
178                         }
179                 }
180
181                 public bool RenderItalic
182                 {
183                         get
184                         {
185                                 return renderItalic;
186                         }
187                         set
188                         {
189                                 renderItalic = value;
190                         }
191                 }
192
193                 public bool RequiresNoBreakInFormatting
194                 {
195                         get
196                         {
197                                 return requiresNoBreak;
198                         }
199                         set
200                         {
201                                 requiresNoBreak = value;
202                         }
203                 }
204
205                 public bool ShouldEnsureStyle
206                 {
207                         get
208                         {
209                                 return shouldEnsureStyle;
210                         }
211                         set
212                         {
213                                 shouldEnsureStyle = value;
214                         }
215                 }
216
217                 [MonoTODO]
218                 public void EnterLayout(Style style)
219                 {
220                         throw new NotImplementedException();
221                 }
222
223                 [MonoTODO]
224                 public void ExitLayout(Style style, bool breakAfter)
225                 {
226                         throw new NotImplementedException();
227                 }
228
229                 [MonoTODO]
230                 public void EnterStyle(System.Web.UI.MobileControls.Style style)
231                 {
232                         throw new NotImplementedException();
233                 }
234
235                 private void EnterStyle(WriterStyle style)
236                 {
237                         currentState.Push(style);
238                 }
239
240                 public void ExitStyle(Style style)
241                 {
242                         ExitStyle(style, false);
243                 }
244
245                 [MonoTODO]
246                 public void ExitStyle(Style style, bool breakAfter)
247                 {
248                         throw new NotImplementedException();
249                 }
250
251                 [MonoTODO]
252                 public void WriteText(string text, bool encode)
253                 {
254                         throw new NotImplementedException();
255                 }
256
257                 [MonoTODO]
258                 public override void Write(char c)
259                 {
260                         throw new NotImplementedException();
261                 }
262
263                 [MonoTODO]
264                 public override void Write(string text)
265                 {
266                         throw new NotImplementedException();
267                 }
268
269                 public void BeginStyleContext()
270                 {
271                         if(currentState.IsBreakPending)
272                         {
273                                 WriteBreak();
274                                 currentState.IsBreakPending = false;
275                         }
276                         currentState.PushState();
277                         EnterStyle(new WriterStyle());
278                 }
279                 
280                 public void EndStyleContext()
281                 {
282                         if(currentState.IsBreakPending)
283                         {
284                                 WriteBreak();
285                                 currentState.IsBreakPending = false;
286                         }
287                         currentState.PopState();
288                         currentState.Pop();
289                         currentState.Transition(new WriterStyle());
290                 }
291                 
292                 public void EnterFormat(Style style)
293                 {
294                         WriterStyle wstyle = new WriterStyle(style);
295                         wstyle.Layout = false;
296                         EnterStyle(wstyle);
297                 }
298                 
299                 public virtual void ExitFormat(Style style)
300                 {
301                         ExitStyle(style);
302                 }
303                 
304                 public void WriteBreak()
305                 {
306                         WriteLine("<br>");
307                 }
308                 
309                 public override void WriteLine(string text)
310                 {
311                         EnsureStyle();
312                         base.WriteLine(text);
313                 }
314                 
315                 internal void EnsureStyle()
316                 {
317                         if(shouldEnsureStyle)
318                         {
319                                 if(currentState.Count > 0)
320                                 {
321                                         currentState.Transition(currentState.Peek());
322                                 }
323                                 shouldEnsureStyle = false;
324                         }
325                         if(BeforeFirstControlWritten)
326                         {
327                                 BeforeFirstControlWritten = false;
328                         }
329                 }
330         }
331 }