diff --git a/src/lib/MBS.Web/UI/Literal.cs b/src/lib/MBS.Web/UI/Literal.cs new file mode 100644 index 0000000..6def7c0 --- /dev/null +++ b/src/lib/MBS.Web/UI/Literal.cs @@ -0,0 +1,62 @@ +// Copyright (C) 2024 Michael Becker +// +// This file is part of Mocha.NET. +// +// Mocha.NET is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Mocha.NET is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Mocha.NET. If not, see . + +using System.Xml; + +namespace MBS.Web; + +public class Literal : Control +{ + /// + /// When true, outputs as raw text, including any entity references + /// and HTML tags. When false, properly escapes all such occurrences. + /// + /// + /// + /// + public bool UseMarkup { get; set; } = true; + public string Content { get; set; } = String.Empty; + + public Literal() + { + } + public Literal(string content) + { + Content = content; + } + + protected override void RenderBeginTag(XmlWriter writer) + { + // intentionally left blank; this is raw HTML + } + protected override void RenderContents(XmlWriter writer) + { + // intentionally overridden; this is raw HTML + if (UseMarkup) + { + writer.WriteRaw(Content); + } + else + { + writer.WriteString(Content); + } + } + protected override void RenderEndTag(XmlWriter writer) + { + // intentionally left blank; this is raw HTML + } +} \ No newline at end of file diff --git a/src/lib/MBS.Web/UI/WebControls/Heading.cs b/src/lib/MBS.Web/UI/WebControls/Heading.cs new file mode 100644 index 0000000..9656c14 --- /dev/null +++ b/src/lib/MBS.Web/UI/WebControls/Heading.cs @@ -0,0 +1,47 @@ +// Copyright (C) 2024 Michael Becker +// +// This file is part of MBS Web Framework. +// +// MBS Web Framework is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// MBS Web Framework is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with MBS Web Framework. If not, see . + +using System.Xml; + +namespace MBS.Web.UI.WebControls; + +public class Heading : WebControl +{ + public int Level { get; set; } = 1; + public string Text { get; set; } = String.Empty; + public bool UseMarkup { get; set; } = true; + + protected override string TagName => String.Format("h{0}", Level); + + public Heading(int level, string text) + { + Level = level; + Text = text; + } + + protected override void RenderContents(XmlWriter writer) + { + if (UseMarkup) + { + writer.WriteRaw(Text); + } + else + { + writer.WriteString(Text); + } + } +} \ No newline at end of file diff --git a/src/lib/MBS.Web/UI/WebPage.cs b/src/lib/MBS.Web/UI/WebPage.cs index 2c77f4e..6583e25 100644 --- a/src/lib/MBS.Web/UI/WebPage.cs +++ b/src/lib/MBS.Web/UI/WebPage.cs @@ -5,6 +5,8 @@ namespace MBS.Web.UI; public class WebPage : Control { + public bool MobileFriendly { get; set; } = true; + public WebPage(Dictionary? pathVariables = null) : base(pathVariables) { } public Control.ControlCollection HeaderControls { get; } = new Control.ControlCollection(); @@ -26,15 +28,28 @@ public class WebPage : Control protected override void RenderContents(XmlWriter writer) { + Controls.Clear(); + CreateChildControls(); + + /* if (!ChildControlsCreated) { CreateChildControls(); ChildControlsCreated = true; } + */ writer.WriteStartElement("head"); writer.WriteElementString("title", "Mocha Application"); + if (MobileFriendly) + { + writer.WriteStartElement("meta"); + writer.WriteAttributeString("name", "viewport"); + writer.WriteAttributeString("content", "width=device-width, initial-scale=1.0"); + writer.WriteEndElement(); + } + List ctls = new List(); ctls.Add(new HtmlLink("stylesheet", "text/css", "/madi/asset/ui-html/2024.27.5/css/mochaApp.css?plate=BMT216A&sha256-XjJJ2%2BcFxZXtxY579nwOKBNYdP1KUySxNDbxR4QGxvQ%3D")); @@ -61,7 +76,7 @@ public class WebPage : Control writer.WriteStartElement("form"); writer.WriteAttributeString("method", "POST"); - foreach (WebControl control in Controls) + foreach (Control control in Controls) { control.Render(writer); } diff --git a/src/lib/MBS.Web/WebApplication.cs b/src/lib/MBS.Web/WebApplication.cs index 55be34c..01e3030 100644 --- a/src/lib/MBS.Web/WebApplication.cs +++ b/src/lib/MBS.Web/WebApplication.cs @@ -39,9 +39,9 @@ public abstract class WebApplication : Application { base.OnStartup(e); - Console.WriteLine("starting server..."); - WebServer server = new WebServer(new IPEndPoint(IPAddress.Any, DefaultPort)); + Console.WriteLine("server listening on port {0}", DefaultPort); + OnServerCreated(new WebServerCreatedEventArgs(server)); server.ProcessRequest += server_OnProcessRequest; server.Start();