**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Web.Mobile / System.Web.UI.MobileControls.Adapters / WriterState.cs
blob0c91ab7a9e1129570bc4b606ce3368100a687d11
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.
22 /**
23 * Project : Mono
24 * Namespace : System.Web.UI.MobileControls.Adapters
25 * Class : WriterState
26 * Author : Gaurav Vaish
28 * Copyright : 2003 with Gaurav Vaish, and with
29 * Ximian Inc
32 using System;
33 using System.IO;
34 using System.Collections;
35 using System.Drawing;
36 using System.Web.Mobile;
38 namespace System.Web.UI.MobileControls.Adapters
40 class WriterState : StyleStack
42 // stack of tagswritten and writerstyles
43 private Stack stack = new Stack();
44 private Stack tagsWritten = new Stack();
45 private WriterStyle current = new WriterStyle();
46 private HtmlMobileTextWriter writer;
48 private bool isInTransition = false;
49 private bool isBreakPending = false;
50 private int fontLevel = -1;
51 private int divLevel = -1;
52 private int mark = 0;
54 public WriterState(HtmlMobileTextWriter writer) : base(writer)
56 this.writer = writer;
59 public bool IsBreakPending
61 get
63 return this.isBreakPending;
65 set
67 this.isBreakPending = value;
71 public int FontLevel
73 get
75 return this.fontLevel;
77 set
79 this.fontLevel = value;
83 public int DivLevel
85 get
87 return this.divLevel;
89 set
91 this.divLevel = value;
95 public WriterStyle Current
97 get
99 return this.current;
103 // The tags that have been written.
104 public Stack TagsWritten
108 return this.tagsWritten;
112 public HtmlTextWriter Writer
116 return this.writer;
120 public void MarkStyleContext()
122 this.mark = this.tagsWritten.Count;
125 public void UnmarkStyleContext()
127 while(tagsWritten.Count > mark)
128 CloseTag();
131 public WriterStyle PopState()
133 writer.ShouldEnsureStyle = true;
134 IsBreakPending = (bool) stack.Pop();
136 while(tagsWritten.Count > 0)
137 CloseTag();
139 tagsWritten = (Stack)stack.Pop();
140 current = (WriterStyle)stack.Pop();
141 return current;
144 public void PushState()
146 writer.ShouldEnsureStyle = true;
147 stack.Push(current);
148 stack.Push(tagsWritten);
149 stack.Push(IsBreakPending);
150 current = new WriterStyle();
151 tagsWritten = new Stack();
152 IsBreakPending = false;
155 public void CloseTag()
157 StyleTag tag = tagsWritten.Pop() as StyleTag;
158 if(tag != null)
159 tag.CloseTag(this);
162 public void Transition(WriterStyle style)
164 Transition(style, true);
167 [MonoTODO]
168 public void Transition(WriterStyle style, bool captureOutput)
170 HtmlMobileTextWriter tempWriter = this.writer;
173 if(!captureOutput && !isInTransition)
175 this.writer = new HtmlMobileTextWriter(
176 new HtmlTextWriter(
177 new StringWriter()),
178 tempWriter.Device);
179 isInTransition = true;
180 if(Count > 0)
182 while(Count > 0)
184 CloseTag();
186 isInTransition = false;
187 } else
189 if(current.Italic && writer.RenderItalic)
191 while(current.Italic)
193 CloseTag();
196 if(current.Bold && writer.RenderBold)
198 while(current.Bold)
200 CloseTag();
203 if(current.FontColor != Color.Empty && writer.RenderFontColor)
205 while(current.FontColor != Color.Empty)
207 CloseTag();
210 if(current.FontName != String.Empty && writer.RenderFontName)
212 while(current.FontName != String.Empty)
214 CloseTag();
217 if(FontChange(style))
219 while(FontLevel > Count)
221 CloseTag();
224 if(current.Wrapping == Wrapping.NoWrap && writer.RenderDivNoWrap)
226 while(current.Wrapping == Wrapping.NoWrap)
228 CloseTag();
231 if(current.Alignment != Alignment.NotSet && writer.RenderDivAlign)
233 while(DivLevel > Count)
235 CloseTag();
238 bool dc = DivChange(style);
239 if(IsBreakPending && !dc)
241 writer.WriteBreak();
242 IsBreakPending = false;
244 if(dc)
246 while(FontLevel > Count)
248 if(current.Bold || current.Italic)
249 CloseTag();
252 bool fc = FontChange(style);
253 dc = DivChange(style);
254 if(dc)
256 throw new NotImplementedException();
257 //DivStyleTag
258 // Actually Render
260 if(fc)
262 throw new NotImplementedException();
263 // Actually Render
265 // Push Bold, Italic etc in current Stack
266 isInTransition = false;
267 throw new NotImplementedException();
270 } finally
272 this.writer = tempWriter;
276 private bool DivChange(WriterStyle newStyle)
278 bool retVal = false;
279 if(newStyle.Layout)
281 if((current.Wrapping != newStyle.Wrapping
282 && writer.RenderDivNoWrap) ||
283 (current.Alignment != newStyle.Alignment
284 && writer.RenderDivAlign))
285 retVal = true;
287 return retVal;
290 private bool FontChange(WriterStyle newStyle)
292 bool retVal = false;
293 if( (current.FontColor != newStyle.FontColor
294 && writer.RenderFontColor) ||
295 (current.FontSize != newStyle.FontSize
296 && writer.RenderFontSize) ||
297 (current.FontName != newStyle.FontName
298 && writer.RenderFontName))
299 retVal = true;
300 return retVal;