private void AddContent(HtmlParser htmlParser, string htmlContent) { ElementState elementState = htmlParser.CurrentElementState; string decodedHtml = HtmlParser.UrlDecode(htmlContent); switch (elementState.TypeName) { case "p": { elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "p"; elementsUnderConstruction.Peek().HAnchor = HAnchor.ParentLeftRight; if (decodedHtml != null && decodedHtml != "") { WrappingTextWidget content = new WrappingTextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); //content.VAnchor = VAnchor.ParentTop; elementsUnderConstruction.Peek().AddChild(content); } } break; case "div": { elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "div"; if (decodedHtml != null && decodedHtml != "") { TextWidget content = new TextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); elementsUnderConstruction.Peek().AddChild(content); } } break; case "!DOCTYPE": break; case "body": break; case "img": { ImageBuffer image = new ImageBuffer(elementState.SizeFixed.x, elementState.SizeFixed.y, 32, new BlenderBGRA()); ImageWidget_AsyncLoadOnDraw imageWidget = new ImageWidget_AsyncLoadOnDraw(image, elementState.src); // put the image into the widget when it is done downloading. if (elementsUnderConstruction.Peek().Name == "a") { Button linkButton = new Button(0, 0, imageWidget); linkButton.Cursor = Cursors.Hand; linkButton.Click += (sender, mouseEvent) => { MatterControlApplication.Instance.LaunchBrowser(elementState.Href); }; elementsUnderConstruction.Peek().AddChild(linkButton); } else { elementsUnderConstruction.Peek().AddChild(imageWidget); } } break; case "a": { elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "a"; if (decodedHtml != null && decodedHtml != "") { Button linkButton = linkButtonFactory.Generate(decodedHtml); StyledTypeFace styled = new StyledTypeFace(LiberationSansFont.Instance, elementState.PointSize); double descentInPixels = styled.DescentInPixels; linkButton.OriginRelativeParent = new VectorMath.Vector2(linkButton.OriginRelativeParent.x, linkButton.OriginRelativeParent.y + descentInPixels); linkButton.Click += (sender, mouseEvent) => { MatterControlApplication.Instance.LaunchBrowser(elementState.Href); }; elementsUnderConstruction.Peek().AddChild(linkButton); } } break; case "table": break; case "td": case "span": GuiWidget widgetToAdd; if (elementState.Classes.Contains("translate")) { decodedHtml = decodedHtml.Localize(); } if (elementState.Classes.Contains("toUpper")) { decodedHtml = decodedHtml.ToUpper(); } if (elementState.Classes.Contains("versionNumber")) { decodedHtml = VersionInfo.Instance.ReleaseVersion; } if (elementState.Classes.Contains("buildNumber")) { decodedHtml = VersionInfo.Instance.BuildVersion; } Button createdButton = null; if (elementState.Classes.Contains("centeredButton")) { createdButton = textImageButtonFactory.Generate(decodedHtml); widgetToAdd = createdButton; } else if (elementState.Classes.Contains("linkButton")) { double oldFontSize = linkButtonFactory.fontSize; linkButtonFactory.fontSize = elementState.PointSize; createdButton = linkButtonFactory.Generate(decodedHtml); StyledTypeFace styled = new StyledTypeFace(LiberationSansFont.Instance, elementState.PointSize); double descentInPixels = styled.DescentInPixels; createdButton.OriginRelativeParent = new VectorMath.Vector2(createdButton.OriginRelativeParent.x, createdButton.OriginRelativeParent.y + descentInPixels); widgetToAdd = createdButton; linkButtonFactory.fontSize = oldFontSize; } else { TextWidget content = new TextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); widgetToAdd = content; } if (createdButton != null) { if (elementState.Id == "sendFeedback") { createdButton.Click += (sender, mouseEvent) => { ContactFormWindow.Open(); }; } else if (elementState.Id == "clearCache") { createdButton.Click += (sender, mouseEvent) => { AboutWidget.DeleteCacheData(); }; } } if (elementState.VerticalAlignment == ElementState.VerticalAlignType.top) { widgetToAdd.VAnchor = VAnchor.ParentTop; } elementsUnderConstruction.Peek().AddChild(widgetToAdd); break; case "tr": elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "tr"; if (elementState.SizePercent.y == 100) { elementsUnderConstruction.Peek().VAnchor = VAnchor.ParentBottomTop; } if (elementState.Alignment == ElementState.AlignType.center) { elementsUnderConstruction.Peek().HAnchor |= HAnchor.ParentCenter; } break; default: throw new NotImplementedException("Don't know what to do with '{0}'".FormatWith(elementState.TypeName)); } }
private void AddContent(HtmlParser htmlParser, string htmlContent) { ElementState elementState = htmlParser.CurrentElementState; string decodedHtml = HtmlParser.UrlDecode(htmlContent); switch (elementState.TypeName) { case "p": { elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "p"; elementsUnderConstruction.Peek().HAnchor = HAnchor.ParentLeftRight; if (decodedHtml != null && decodedHtml != "") { WrappingTextWidget content = new WrappingTextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); //content.VAnchor = VAnchor.ParentTop; elementsUnderConstruction.Peek().AddChild(content); } } break; case "div": { elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "div"; if (decodedHtml != null && decodedHtml != "") { TextWidget content = new TextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); elementsUnderConstruction.Peek().AddChild(content); } } break; case "!DOCTYPE": break; case "body": break; case "img": { ImageBuffer image = new ImageBuffer(elementState.SizeFixed.x, elementState.SizeFixed.y, 32, new BlenderBGRA()); ImageWidget_AsyncLoadOnDraw imageWidget = new ImageWidget_AsyncLoadOnDraw(image, elementState.src); // put the image into the widget when it is done downloading. if (elementsUnderConstruction.Peek().Name == "a") { Button linkButton = new Button(0, 0, imageWidget); linkButton.Cursor = Cursors.Hand; linkButton.Click += (sender, mouseEvent) => { MatterControlApplication.Instance.LaunchBrowser(elementState.Href); }; elementsUnderConstruction.Peek().AddChild(linkButton); } else { elementsUnderConstruction.Peek().AddChild(imageWidget); } } break; case "a": { elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "a"; if (decodedHtml != null && decodedHtml != "") { Button linkButton = linkButtonFactory.Generate(decodedHtml); StyledTypeFace styled = new StyledTypeFace(LiberationSansFont.Instance, elementState.PointSize); double descentInPixels = styled.DescentInPixels; linkButton.OriginRelativeParent = new VectorMath.Vector2(linkButton.OriginRelativeParent.x, linkButton.OriginRelativeParent.y + descentInPixels); linkButton.Click += (sender, mouseEvent) => { MatterControlApplication.Instance.LaunchBrowser(elementState.Href); }; elementsUnderConstruction.Peek().AddChild(linkButton); } } break; case "table": break; case "td": case "span": GuiWidget widgetToAdd; if (elementState.Classes.Contains("translate")) { decodedHtml = decodedHtml.Localize(); } if (elementState.Classes.Contains("toUpper")) { decodedHtml = decodedHtml.ToUpper(); } if (elementState.Classes.Contains("versionNumber")) { decodedHtml = VersionInfo.Instance.ReleaseVersion; } if (elementState.Classes.Contains("buildNumber")) { decodedHtml = VersionInfo.Instance.BuildVersion; } Button createdButton = null; if (elementState.Classes.Contains("centeredButton")) { createdButton = textImageButtonFactory.Generate(decodedHtml); widgetToAdd = createdButton; } else if (elementState.Classes.Contains("linkButton")) { double oldFontSize = linkButtonFactory.fontSize; linkButtonFactory.fontSize = elementState.PointSize; createdButton = linkButtonFactory.Generate(decodedHtml); StyledTypeFace styled = new StyledTypeFace(LiberationSansFont.Instance, elementState.PointSize); double descentInPixels = styled.DescentInPixels; createdButton.OriginRelativeParent = new VectorMath.Vector2(createdButton.OriginRelativeParent.x, createdButton.OriginRelativeParent.y + descentInPixels); widgetToAdd = createdButton; linkButtonFactory.fontSize = oldFontSize; } else { TextWidget content = new TextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); widgetToAdd = content; } if (createdButton != null) { if (elementState.Id == "sendFeedback") { createdButton.Click += (sender, mouseEvent) => { ContactFormWindow.Open(); }; } else if (elementState.Id == "clearCache") { createdButton.Click += (sender, mouseEvent) => { AboutWidget.DeleteCacheData(); }; } } if (elementState.VerticalAlignment == ElementState.VerticalAlignType.top) { widgetToAdd.VAnchor = VAnchor.ParentTop; } elementsUnderConstruction.Peek().AddChild(widgetToAdd); break; case "tr": elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "tr"; if (elementState.SizePercent.y == 100) { elementsUnderConstruction.Peek().VAnchor = VAnchor.ParentBottomTop; } if (elementState.Alignment == ElementState.AlignType.center) { elementsUnderConstruction.Peek().HAnchor |= HAnchor.ParentCenter; } break; default: throw new NotImplementedException("Don't know what to do with {0}".FormatWith(elementState.TypeName)); } }