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:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
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.
24 * Namespace : System.Web.UI.MobileControls.Adapters
26 * Author : Gaurav Vaish
28 * Copyright : 2003 with Gaurav Vaish, and with
34 using System
.Collections
;
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;
54 public WriterState(HtmlMobileTextWriter writer
) : base(writer
)
59 public bool IsBreakPending
63 return this.isBreakPending
;
67 this.isBreakPending
= value;
75 return this.fontLevel
;
79 this.fontLevel
= value;
91 this.divLevel
= value;
95 public WriterStyle Current
103 // The tags that have been written.
104 public Stack TagsWritten
108 return this.tagsWritten
;
112 public HtmlTextWriter Writer
120 public void MarkStyleContext()
122 this.mark
= this.tagsWritten
.Count
;
125 public void UnmarkStyleContext()
127 while(tagsWritten
.Count
> mark
)
131 public WriterStyle
PopState()
133 writer
.ShouldEnsureStyle
= true;
134 IsBreakPending
= (bool) stack
.Pop();
136 while(tagsWritten
.Count
> 0)
139 tagsWritten
= (Stack
)stack
.Pop();
140 current
= (WriterStyle
)stack
.Pop();
144 public void PushState()
146 writer
.ShouldEnsureStyle
= true;
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
;
162 public void Transition(WriterStyle style
)
164 Transition(style
, true);
168 public void Transition(WriterStyle style
, bool captureOutput
)
170 HtmlMobileTextWriter tempWriter
= this.writer
;
173 if(!captureOutput
&& !isInTransition
)
175 this.writer
= new HtmlMobileTextWriter(
179 isInTransition
= true;
186 isInTransition
= false;
189 if(current
.Italic
&& writer
.RenderItalic
)
191 while(current
.Italic
)
196 if(current
.Bold
&& writer
.RenderBold
)
203 if(current
.FontColor
!= Color
.Empty
&& writer
.RenderFontColor
)
205 while(current
.FontColor
!= Color
.Empty
)
210 if(current
.FontName
!= String
.Empty
&& writer
.RenderFontName
)
212 while(current
.FontName
!= String
.Empty
)
217 if(FontChange(style
))
219 while(FontLevel
> Count
)
224 if(current
.Wrapping
== Wrapping
.NoWrap
&& writer
.RenderDivNoWrap
)
226 while(current
.Wrapping
== Wrapping
.NoWrap
)
231 if(current
.Alignment
!= Alignment
.NotSet
&& writer
.RenderDivAlign
)
233 while(DivLevel
> Count
)
238 bool dc
= DivChange(style
);
239 if(IsBreakPending
&& !dc
)
242 IsBreakPending
= false;
246 while(FontLevel
> Count
)
248 if(current
.Bold
|| current
.Italic
)
252 bool fc
= FontChange(style
);
253 dc
= DivChange(style
);
256 throw new NotImplementedException();
262 throw new NotImplementedException();
265 // Push Bold, Italic etc in current Stack
266 isInTransition
= false;
267 throw new NotImplementedException();
272 this.writer
= tempWriter
;
276 private bool DivChange(WriterStyle newStyle
)
281 if((current
.Wrapping
!= newStyle
.Wrapping
282 && writer
.RenderDivNoWrap
) ||
283 (current
.Alignment
!= newStyle
.Alignment
284 && writer
.RenderDivAlign
))
290 private bool FontChange(WriterStyle newStyle
)
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
))