From 157ce6cced7d190f337e488857c6fa479786724d Mon Sep 17 00:00:00 2001 From: Gaurav Vaish Date: Mon, 29 Sep 2003 17:45:34 +0000 Subject: 2003-09-29 Gaurav Vaish * HtmlMobileTextWriter.cs : Added several Style related methods, and also some Write methods. * MobileTextWriter.cs : Device { get; } - Implemented * StyleStack.cs, WriterState.cs, WriterStyle.cs, StyleTag.cs : (Private / Internal) Helper classes. svn path=/trunk/mcs/; revision=18402 --- .../ChangeLog | 9 + .../HtmlMobileTextWriter.cs | 94 ++++++- .../MobileTextWriter.cs | 11 + .../StyleStack.cs | 58 +++++ .../StyleTag.cs | 40 +++ .../WriterState.cs | 282 +++++++++++++++++++++ .../WriterStyle.cs | 149 +++++++++++ 7 files changed, 641 insertions(+), 2 deletions(-) create mode 100644 mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/StyleStack.cs create mode 100644 mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/StyleTag.cs create mode 100644 mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/WriterState.cs create mode 100644 mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/WriterStyle.cs (limited to 'mcs/class/System.Web.Mobile') diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/ChangeLog b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/ChangeLog index 04cdbc0fa97..2184f31bd59 100644 --- a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/ChangeLog +++ b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/ChangeLog @@ -1,4 +1,13 @@ +2003-09-29 Gaurav Vaish + + * HtmlMobileTextWriter.cs + : Added several Style related methods, + and also some Write methods. + * MobileTextWriter.cs : Device { get; } - Implemented + * StyleStack.cs, WriterState.cs, WriterStyle.cs, StyleTag.cs + : (Private / Internal) Helper classes. + 2003-09-04 Gaurav Vaish * ControlAdapter.cs : Control property - Marked virtual diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/HtmlMobileTextWriter.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/HtmlMobileTextWriter.cs index f4017234c25..6c2ca69eb8c 100644 --- a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/HtmlMobileTextWriter.cs +++ b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/HtmlMobileTextWriter.cs @@ -29,12 +29,24 @@ namespace System.Web.UI.MobileControls.Adapters private bool requiresNoBreak = false; private bool shouldEnsureStyle = true; + private WriterState currentState; + [MonoTODO] public HtmlMobileTextWriter(TextWriter writer, MobileCapabilities capabilities) : base(writer, capabilities) { - throw new NotImplementedException(); + RenderBold = capabilities.SupportsBold; + RenderItalic = capabilities.SupportsItalic; + RenderFontSize = capabilities.SupportsFontSize; + RenderFontName = capabilities.SupportsFontName; + RenderFontColor = capabilities.SupportsFontColor; + RenderBodyColor = capabilities.SupportsBodyColor; + RenderDivAlign = capabilities.SupportsDivAlign; + RenderDivNoWrap = capabilities.SupportsDivNoWrap; + RequiresNoBreakInFormatting = capabilities.RequiresNoBreakInFormatting; + + currentState = new WriterState(this); } public bool BeforeFirstControlWritten @@ -186,7 +198,7 @@ namespace System.Web.UI.MobileControls.Adapters { throw new NotImplementedException(); } - + [MonoTODO] public void ExitLayout(Style style, bool breakAfter) { @@ -199,6 +211,16 @@ namespace System.Web.UI.MobileControls.Adapters throw new NotImplementedException(); } + private void EnterStyle(WriterStyle style) + { + currentState.Push(style); + } + + public void ExitStyle(Style style) + { + ExitStyle(style, false); + } + [MonoTODO] public void ExitStyle(Style style, bool breakAfter) { @@ -211,10 +233,78 @@ namespace System.Web.UI.MobileControls.Adapters throw new NotImplementedException(); } + [MonoTODO] + public override void Write(char c) + { + throw new NotImplementedException(); + } + [MonoTODO] public override void Write(string text) { throw new NotImplementedException(); } + + public void BeginStyleContext() + { + if(currentState.IsBreakPending) + { + WriteBreak(); + currentState.IsBreakPending = false; + } + currentState.PushState(); + EnterStyle(new WriterStyle()); + } + + public void EndStyleContext() + { + if(currentState.IsBreakPending) + { + WriteBreak(); + currentState.IsBreakPending = false; + } + currentState.PopState(); + currentState.Pop(); + currentState.Transition(new WriterStyle()); + } + + public void EnterFormat(Style style) + { + WriterStyle wstyle = new WriterStyle(style); + wstyle.Layout = false; + EnterStyle(wstyle); + } + + public virtual void ExitFormat(Style style) + { + ExitStyle(style); + } + + public void WriteBreak() + { + WriteLine("
"); + } + + public override void WriteLine(string text) + { + EnsureStyle(); + base.WriteLine(text); + } + + internal void EnsureStyle() + { + if(shouldEnsureStyle) + { + if(currentState.Count > 0) + { + currentState.Transition(currentState.Peek()); + } + shouldEnsureStyle = false; + } + if(BeforeFirstControlWritten) + { + BeforeFirstControlWritten = false; + } + } } } diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/MobileTextWriter.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/MobileTextWriter.cs index 65b1be1dc55..7cf8ea373ec 100644 --- a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/MobileTextWriter.cs +++ b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/MobileTextWriter.cs @@ -16,10 +16,21 @@ namespace System.Web.UI.MobileControls.Adapters { public class MobileTextWriter : MultiPartWriter { + private MobileCapabilities device; + public MobileTextWriter(TextWriter writer, MobileCapabilities capabilities) : base(writer) { + this.device = capabilities; throw new NotImplementedException(); } + + public MobileCapabilities Device + { + get + { + return device; + } + } } } diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/StyleStack.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/StyleStack.cs new file mode 100644 index 00000000000..27c3888d522 --- /dev/null +++ b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/StyleStack.cs @@ -0,0 +1,58 @@ +/** + * Project : Mono + * Namespace : System.Web.UI.MobileControls.Adapters + * Class : StyleStack + * Author : Gaurav Vaish + * + * Copyright : 2003 with Gaurav Vaish, and with + * Ximian Inc + */ + +using System; +using System.Collections; +using System.Web.Mobile; + +namespace System.Web.UI.MobileControls.Adapters +{ + class StyleStack + { + private HtmlMobileTextWriter writer; + private Stack stack; + + protected StyleStack(HtmlMobileTextWriter writer) + { + this.writer = writer; + stack = new Stack(); + } + + public int Count + { + get + { + return stack.Count; + } + } + + public WriterStyle Peek() + { + WriterStyle retVal = null; + if(stack.Count > 0) + retVal = (WriterStyle)stack.Peek(); + return retVal; + } + + public WriterStyle Pop() + { + WriterStyle retVal = null; + if(stack.Count > 0) + retVal = (WriterStyle)stack.Pop(); + return retVal; + } + + public void Push(WriterStyle style) + { + stack.Push(style); + writer.ShouldEnsureStyle = true; + } + } +} diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/StyleTag.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/StyleTag.cs new file mode 100644 index 00000000000..c416050f0e5 --- /dev/null +++ b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/StyleTag.cs @@ -0,0 +1,40 @@ +/** + * Project : Mono + * Namespace : System.Web.UI.MobileControls.Adapters + * Class : StyleTag + * Author : Gaurav Vaish + * + * Copyright : 2003 with Gaurav Vaish, and with + * Ximian Inc + */ + +using System; +using System.Collections; +using System.Web.Mobile; + +namespace System.Web.UI.MobileControls.Adapters +{ + abstract class StyleTag + { + private int level; + + public StyleTag(int level) + { + this.level = level; + } + + public int Level + { + get + { + return this.level; + } + set + { + this.level = value; + } + } + + public abstract void CloseTag(WriterState state); + } +} diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/WriterState.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/WriterState.cs new file mode 100644 index 00000000000..c60f65cc058 --- /dev/null +++ b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/WriterState.cs @@ -0,0 +1,282 @@ +/** + * Project : Mono + * Namespace : System.Web.UI.MobileControls.Adapters + * Class : WriterState + * Author : Gaurav Vaish + * + * Copyright : 2003 with Gaurav Vaish, and with + * Ximian Inc + */ + +using System; +using System.IO; +using System.Collections; +using System.Drawing; +using System.Web.Mobile; + +namespace System.Web.UI.MobileControls.Adapters +{ + class WriterState : StyleStack + { + // stack of tagswritten and writerstyles + private Stack stack = new Stack(); + private Stack tagsWritten = new Stack(); + private WriterStyle current = new WriterStyle(); + private HtmlMobileTextWriter writer; + + private bool isInTransition = false; + private bool isBreakPending = false; + private int fontLevel = -1; + private int divLevel = -1; + private int mark = 0; + + public WriterState(HtmlMobileTextWriter writer) : base(writer) + { + this.writer = writer; + } + + public bool IsBreakPending + { + get + { + return this.isBreakPending; + } + set + { + this.isBreakPending = value; + } + } + + public int FontLevel + { + get + { + return this.fontLevel; + } + set + { + this.fontLevel = value; + } + } + + public int DivLevel + { + get + { + return this.divLevel; + } + set + { + this.divLevel = value; + } + } + + public WriterStyle Current + { + get + { + return this.current; + } + } + + // The tags that have been written. + public Stack TagsWritten + { + get + { + return this.tagsWritten; + } + } + + public HtmlTextWriter Writer + { + get + { + return this.writer; + } + } + + public void MarkStyleContext() + { + this.mark = this.tagsWritten.Count; + } + + public void UnmarkStyleContext() + { + while(tagsWritten.Count > mark) + CloseTag(); + } + + public WriterStyle PopState() + { + writer.ShouldEnsureStyle = true; + IsBreakPending = (bool) stack.Pop(); + + while(tagsWritten.Count > 0) + CloseTag(); + + tagsWritten = (Stack)stack.Pop(); + current = (WriterStyle)stack.Pop(); + return current; + } + + public void PushState() + { + writer.ShouldEnsureStyle = true; + stack.Push(current); + stack.Push(tagsWritten); + stack.Push(IsBreakPending); + current = new WriterStyle(); + tagsWritten = new Stack(); + IsBreakPending = false; + } + + public void CloseTag() + { + StyleTag tag = tagsWritten.Pop() as StyleTag; + if(tag != null) + tag.CloseTag(this); + } + + public void Transition(WriterStyle style) + { + Transition(style, true); + } + + [MonoTODO] + public void Transition(WriterStyle style, bool captureOutput) + { + HtmlMobileTextWriter tempWriter = this.writer; + try + { + if(!captureOutput && !isInTransition) + { + this.writer = new HtmlMobileTextWriter( + new HtmlTextWriter( + new StringWriter()), + tempWriter.Device); + isInTransition = true; + if(Count > 0) + { + while(Count > 0) + { + CloseTag(); + } + isInTransition = false; + } else + { + if(current.Italic && writer.RenderItalic) + { + while(current.Italic) + { + CloseTag(); + } + } + if(current.Bold && writer.RenderBold) + { + while(current.Bold) + { + CloseTag(); + } + } + if(current.FontColor != Color.Empty && writer.RenderFontColor) + { + while(current.FontColor != Color.Empty) + { + CloseTag(); + } + } + if(current.FontName != String.Empty && writer.RenderFontName) + { + while(current.FontName != String.Empty) + { + CloseTag(); + } + } + if(FontChange(style)) + { + while(FontLevel > Count) + { + CloseTag(); + } + } + if(current.Wrapping == Wrapping.NoWrap && writer.RenderDivNoWrap) + { + while(current.Wrapping == Wrapping.NoWrap) + { + CloseTag(); + } + } + if(current.Alignment != Alignment.NotSet && writer.RenderDivAlign) + { + while(DivLevel > Count) + { + CloseTag(); + } + } + bool dc = DivChange(style); + if(IsBreakPending && !dc) + { + writer.WriteBreak(); + IsBreakPending = false; + } + if(dc) + { + while(FontLevel > Count) + { + if(current.Bold || current.Italic) + CloseTag(); + } + } + bool fc = FontChange(style); + dc = DivChange(style); + if(dc) + { + throw new NotImplementedException(); + //DivStyleTag + // Actually Render + } + if(fc) + { + throw new NotImplementedException(); + // Actually Render + } + // Push Bold, Italic etc in current Stack + isInTransition = false; + throw new NotImplementedException(); + } + } + } finally + { + this.writer = tempWriter; + } + } + + private bool DivChange(WriterStyle newStyle) + { + bool retVal = false; + if(newStyle.Layout) + { + if((current.Wrapping != newStyle.Wrapping + && writer.RenderDivNoWrap) || + (current.Alignment != newStyle.Alignment + && writer.RenderDivAlign)) + retVal = true; + } + return retVal; + } + + private bool FontChange(WriterStyle newStyle) + { + bool retVal = false; + if( (current.FontColor != newStyle.FontColor + && writer.RenderFontColor) || + (current.FontSize != newStyle.FontSize + && writer.RenderFontSize) || + (current.FontName != newStyle.FontName + && writer.RenderFontName)) + retVal = true; + return retVal; + } + } +} diff --git a/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/WriterStyle.cs b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/WriterStyle.cs new file mode 100644 index 00000000000..208437177c4 --- /dev/null +++ b/mcs/class/System.Web.Mobile/System.Web.UI.MobileControls.Adapters/WriterStyle.cs @@ -0,0 +1,149 @@ +/** + * Project : Mono + * Namespace : System.Web.UI.MobileControls.Adapters + * Class : WriterStyle + * Author : Gaurav Vaish + * + * Copyright : 2003 with Gaurav Vaish, and with + * Ximian Inc + */ + +using System; +using System.Collections; +using System.Drawing; +using System.Web.Mobile; +using System.Web.UI.MobileControls; + +namespace System.Web.UI.MobileControls.Adapters +{ + class WriterStyle + { + private bool layout; + private Alignment alignment; + private bool bold; + private Color fontColor; + private string fontName; + private FontSize fontSize; + private bool format; + private bool italic; + private Wrapping wrapping; + + public WriterStyle() + { + throw new NotImplementedException(); + } + + public WriterStyle(Style style) + { + throw new NotImplementedException(); + } + + public bool Layout + { + get + { + return this.layout; + } + set + { + this.layout = value; + } + } + + public Alignment Alignment + { + get + { + return alignment; + } + set + { + alignment = value; + } + } + + public bool Bold + { + get + { + return bold; + } + set + { + bold = value; + } + } + + public Color FontColor + { + get + { + return fontColor; + } + set + { + fontColor = value; + } + } + + public string FontName + { + get + { + return fontName; + } + set + { + fontName = value; + } + } + + public FontSize FontSize + { + get + { + return fontSize; + } + set + { + fontSize = value; + } + } + + public bool Format + { + get + { + return format; + } + set + { + format = value; + } + } + + public bool Italic + { + get + { + return italic; + } + set + { + italic = value; + } + } + + public Wrapping Wrapping + { + get + { + return wrapping; + } + set + { + wrapping = value; + } + } + } +} -- cgit v1.2.3