support mobile and force re-create of child controls (hack?)

This commit is contained in:
Michael Becker 2024-08-04 14:26:48 -04:00
parent 21fa2c5af0
commit 0750456c5f
4 changed files with 127 additions and 3 deletions

View File

@ -0,0 +1,62 @@
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
//
// 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 <https://www.gnu.org/licenses/>.
using System.Xml;
namespace MBS.Web;
public class Literal : Control
{
/// <summary>
/// When true, outputs <see cref="Content" /> as raw text, including any entity references
/// and HTML tags. When false, properly escapes all such occurrences.
/// </summary> <summary>
///
/// </summary>
/// <value></value>
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
}
}

View File

@ -0,0 +1,47 @@
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
//
// 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 <https://www.gnu.org/licenses/>.
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);
}
}
}

View File

@ -5,6 +5,8 @@ namespace MBS.Web.UI;
public class WebPage : Control
{
public bool MobileFriendly { get; set; } = true;
public WebPage(Dictionary<string, string>? 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<Control> ctls = new List<Control>();
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);
}

View File

@ -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();