support mobile and force re-create of child controls (hack?)
This commit is contained in:
parent
21fa2c5af0
commit
0750456c5f
62
src/lib/MBS.Web/UI/Literal.cs
Normal file
62
src/lib/MBS.Web/UI/Literal.cs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/lib/MBS.Web/UI/WebControls/Heading.cs
Normal file
47
src/lib/MBS.Web/UI/WebControls/Heading.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,6 +5,8 @@ namespace MBS.Web.UI;
|
|||||||
|
|
||||||
public class WebPage : Control
|
public class WebPage : Control
|
||||||
{
|
{
|
||||||
|
public bool MobileFriendly { get; set; } = true;
|
||||||
|
|
||||||
public WebPage(Dictionary<string, string>? pathVariables = null) : base(pathVariables) { }
|
public WebPage(Dictionary<string, string>? pathVariables = null) : base(pathVariables) { }
|
||||||
|
|
||||||
public Control.ControlCollection HeaderControls { get; } = new Control.ControlCollection();
|
public Control.ControlCollection HeaderControls { get; } = new Control.ControlCollection();
|
||||||
@ -26,15 +28,28 @@ public class WebPage : Control
|
|||||||
|
|
||||||
protected override void RenderContents(XmlWriter writer)
|
protected override void RenderContents(XmlWriter writer)
|
||||||
{
|
{
|
||||||
|
Controls.Clear();
|
||||||
|
CreateChildControls();
|
||||||
|
|
||||||
|
/*
|
||||||
if (!ChildControlsCreated)
|
if (!ChildControlsCreated)
|
||||||
{
|
{
|
||||||
CreateChildControls();
|
CreateChildControls();
|
||||||
ChildControlsCreated = true;
|
ChildControlsCreated = true;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
writer.WriteStartElement("head");
|
writer.WriteStartElement("head");
|
||||||
writer.WriteElementString("title", "Mocha Application");
|
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>();
|
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"));
|
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.WriteStartElement("form");
|
||||||
writer.WriteAttributeString("method", "POST");
|
writer.WriteAttributeString("method", "POST");
|
||||||
foreach (WebControl control in Controls)
|
foreach (Control control in Controls)
|
||||||
{
|
{
|
||||||
control.Render(writer);
|
control.Render(writer);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,9 +39,9 @@ public abstract class WebApplication : Application
|
|||||||
{
|
{
|
||||||
base.OnStartup(e);
|
base.OnStartup(e);
|
||||||
|
|
||||||
Console.WriteLine("starting server...");
|
|
||||||
|
|
||||||
WebServer server = new WebServer(new IPEndPoint(IPAddress.Any, DefaultPort));
|
WebServer server = new WebServer(new IPEndPoint(IPAddress.Any, DefaultPort));
|
||||||
|
Console.WriteLine("server listening on port {0}", DefaultPort);
|
||||||
|
|
||||||
OnServerCreated(new WebServerCreatedEventArgs(server));
|
OnServerCreated(new WebServerCreatedEventArgs(server));
|
||||||
server.ProcessRequest += server_OnProcessRequest;
|
server.ProcessRequest += server_OnProcessRequest;
|
||||||
server.Start();
|
server.Start();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user