public override CssBox CreateCssBox( DomElement domE, CssBox parentBox, BoxSpec spec, HtmlHost host) { switch (domE.Name) { case "select": { CssBox selectedBox = CreateSelectBox(domE, parentBox, spec, myHost.RootGfx, host); if (selectedBox != null) { return(selectedBox); } } break; case "input": { CssBox inputBox = CreateInputBox(domE, parentBox, spec, myHost.RootGfx, host); if (inputBox != null) { return(inputBox); } } break; case "canvas": { //test only //TODO: review here var canvas = new LayoutFarm.CustomWidgets.MiniAggCanvasBox(400, 400); var wrapperBox = CreateWrapper( host, canvas, canvas.GetPrimaryRenderElement(myHost.RootGfx), spec, true); parentBox.AppendChild(wrapperBox); return(wrapperBox); } } //default unknown var simpleBox = new LayoutFarm.CustomWidgets.Box(100, 20); simpleBox.BackColor = PixelFarm.Drawing.Color.LightGray; var wrapperBox2 = CreateWrapper( host, simpleBox, simpleBox.GetPrimaryRenderElement(myHost.RootGfx), spec, false); parentBox.AppendChild(wrapperBox2); return(wrapperBox2); }
public CssBoxSvgRoot CreateSvgBox(CssBox parentBox, HtmlElement elementNode, LayoutFarm.Css.BoxSpec spec) { //TODO: review here // //create blank svg document VgDocument svgdoc = new VgDocument(); svgdoc.CssActiveSheet = new LayoutFarm.WebDom.CssActiveSheet(); _currentDoc = svgdoc; _svgDocBuilder.ResultDocument = svgdoc; // _svgDocBuilder.OnBegin(); CreateBoxContent(elementNode); _svgDocBuilder.OnEnd(); //----------------------------------------- SvgRootEventPortal svgRootController = new SvgRootEventPortal(elementNode); CssBoxSvgRoot svgRoot = new CssBoxSvgRoot( elementNode.Spec, svgdoc); svgRoot.SetController(svgRootController); svgRootController.SvgRoot = svgRoot; parentBox.AppendChild(svgRoot); return(svgRoot); }
public CssBoxMathMLRoot CreateMathMLBox(CssBox parentBox, HtmlElement elementNode, LayoutFarm.Css.BoxSpec spec) { CssBoxMathMLRoot mathMLRoot = new CssBoxMathMLRoot(elementNode.Spec); MathMLDocument doc = new MathMLDocument(); doc.CssActiveSheet = new CssActiveSheet(); _currentDoc = doc; _docBuilder.ResultDoc = doc; _docBuilder.OnBegin(); math mathNode = new math(); _docBuilder.CurrentMathNode = mathNode; CreateBoxContent(elementNode); _docBuilder.OnEnd(); MathMLRootEventPortal mathMLController = new MathMLRootEventPortal(elementNode); mathMLRoot.SetController(mathMLController); parentBox.AppendChild(mathMLRoot); return(mathMLRoot); ////TODO: review here //// ////create blank svg document //VgDocument svgdoc = new VgDocument(); //svgdoc.CssActiveSheet = new LayoutFarm.WebDom.CssActiveSheet(); //_currentDoc = svgdoc; //_svgDocBuilder.ResultDocument = svgdoc; //// //_svgDocBuilder.OnBegin(); //CreateBoxContent(elementNode); //_svgDocBuilder.OnEnd(); ////----------------------------------------- //SvgRootEventPortal svgRootController = new SvgRootEventPortal(elementNode); //CssBoxSvgRoot svgRoot = new CssBoxSvgRoot( // elementNode.Spec, // svgdoc); //svgRoot.SetController(svgRootController); //svgRootController.SvgRoot = svgRoot; //parentBox.AppendChild(svgRoot); //return svgRoot; }
public static CssBoxSvgRoot CreateSvgBox(CssBox parentBox, HtmlElement elementNode, Css.BoxSpec spec) { SvgFragment fragment = new SvgFragment(); SvgRootEventPortal svgRootController = new SvgRootEventPortal(elementNode); CssBoxSvgRoot svgRoot = new CssBoxSvgRoot( elementNode.Spec, parentBox.RootGfx, fragment); svgRoot.SetController(svgRootController); svgRootController.SvgRoot = svgRoot; parentBox.AppendChild(svgRoot); CreateSvgBoxContent(fragment, elementNode); return(svgRoot); }
CssBox CreateInputBox(HtmlElement domE, CssBox parentBox, BoxSpec spec, HtmlHost host) { //https://www.w3schools.com/tags/tag_input.asp //button //checkbox //color //date //datetime - local //email //file //hidden //image //month //number //password //radio //range //reset //search //submit //tel //text //time //url //week HtmlInputElement htmlInputElem = (HtmlInputElement)domE; var typeAttr = domE.FindAttribute("type"); if (typeAttr != null) { switch (typeAttr.Value) { case "password": { var textbox = new LayoutFarm.CustomWidgets.TextBoxContainer(100, 20, false, true); textbox.TextBoxSwitcher = _textboxSwitcher; var subdomExtender = new TextBoxInputSubDomExtender(textbox); CssBox wrapperBox = CreateCssWrapper( host, textbox, textbox.GetPrimaryRenderElement(), spec, subdomExtender, true); textbox.KeyDown += (s, e) => { ((LayoutFarm.UI.IUIEventListener)htmlInputElem).ListenKeyDown(e); }; htmlInputElem.SubDomExtender = subdomExtender; //connect //place holder support DomAttribute placeHolderAttr = domE.FindAttribute("placeholder"); if (placeHolderAttr != null) { textbox.PlaceHolderText = placeHolderAttr.Value; } parentBox.AppendChild(wrapperBox); return(wrapperBox); } case "text": { //TODO: user can specific width of textbox var textbox = new LayoutFarm.CustomWidgets.TextBoxContainer(100, 20, false); textbox.TextBoxSwitcher = _textboxSwitcher; var subdomExtender = new TextBoxInputSubDomExtender(textbox); CssBox wrapperBox = CreateCssWrapper( host, textbox, textbox.GetPrimaryRenderElement(), spec, subdomExtender, true); textbox.KeyDown += (s, e) => { ((LayoutFarm.UI.IUIEventListener)htmlInputElem).ListenKeyDown(e); }; htmlInputElem.SubDomExtender = subdomExtender; //connect //place holder support DomAttribute placeHolderAttr = domE.FindAttribute("placeholder"); if (placeHolderAttr != null) { textbox.PlaceHolderText = placeHolderAttr.Value; } parentBox.AppendChild(wrapperBox); return(wrapperBox); } case "button": { //use subdom technique *** //todo: review the technique here var button = new HtmlWidgets.Button(60, 30); var ihtmlElement = domE as LayoutFarm.WebDom.IHtmlElement; if (ihtmlElement != null) { button.Text = ihtmlElement.innerHTML; } else { button.Text = "testButton"; } HtmlElement buttonDom = button.GetPresentationDomNode(domE); buttonDom.SetAttribute("style", "width:20px;height:20px;background-color:white;cursor:pointer"); CssBox buttonCssBox = host.CreateCssBox(parentBox, buttonDom, true); parentBox.AppendChild(buttonCssBox); return(buttonCssBox); } case "checkbox": { //implement with choice box + multiple value var chkbox = new HtmlWidgets.ChoiceBox(18, 10); chkbox.SetHtmlInputBox(htmlInputElem); chkbox.OnlyOne = false; //*** show as checked box HtmlElement chkBoxElem = chkbox.GetPresentationDomNode(domE); //buttonDom.SetAttribute("style", "width:20px;height:20px;background-color:red;cursor:pointer"); CssBox chkCssBox = host.CreateCssBox(parentBox, chkBoxElem, true); //create and append to the parentBox htmlInputElem.SubDomExtender = chkbox; //connect #if DEBUG chkCssBox.dbugMark1 = 1; #endif return(chkCssBox); } case "radio": { var radio = new HtmlWidgets.ChoiceBox(10, 10); radio.OnlyOne = true; // show as option box HtmlElement radioElem = radio.GetPresentationDomNode(domE); //buttonDom.SetAttribute("style", "width:20px;height:20px;background-color:red;cursor:pointer"); CssBox buttonCssBox = host.CreateCssBox(parentBox, radioElem, true); //create and append to the parentBox htmlInputElem.SubDomExtender = radio; //connect #if DEBUG buttonCssBox.dbugMark1 = 1; #endif return(buttonCssBox); } case "your_box": { //tempfix -> just copy the Button code, //TODO: review here, use proper radio button var box = new LayoutFarm.CustomWidgets.Box(20, 20); CssBox wrapperBox = CreateCssWrapper( host, box, box.GetPrimaryRenderElement(), spec, null, true); parentBox.AppendChild(wrapperBox); return(wrapperBox); } } } return(null); }
public override CssBox CreateCssBox( HtmlElement domE, CssBox parentBox, BoxSpec spec, HtmlHost host) { switch (domE.Name) { case "select": { CssBox selectedBox = CreateSelectBox(domE, parentBox, spec, host); if (selectedBox != null) { return(selectedBox); } } break; case "input": { CssBox inputBox = CreateInputBox(domE, parentBox, spec, host); if (inputBox != null) { return(inputBox); } } break; case "canvas": { //test only //TODO: review here //software canvas ? var canvas = new LayoutFarm.CustomWidgets.MiniAggCanvasBox(400, 400); CssBox wrapperBox = CreateCssWrapper( host, canvas, canvas.GetPrimaryRenderElement(), spec, null, true); parentBox.AppendChild(wrapperBox); return(wrapperBox); } case "textarea": { CssBox textAreaCssBox = CreateTextAreaElement(domE, parentBox, spec, host); if (textAreaCssBox != null) { return(textAreaCssBox); } } break; } //default unknown var simpleBox = new LayoutFarm.CustomWidgets.Box(100, 20); simpleBox.BackColor = PixelFarm.Drawing.KnownColors.LightGray; CssBox wrapperBox2 = CreateCssWrapper( host, simpleBox, simpleBox.GetPrimaryRenderElement(), spec, null, false); parentBox.AppendChild(wrapperBox2); return(wrapperBox2); }
CssBox CreateTextAreaElement(HtmlElement domE, CssBox parentBox, BoxSpec spec, HtmlHost host) { //mulitline //TODO: review default size of a textarea... HtmlTextAreaElement htmlTextAreaElem = (HtmlTextAreaElement)domE; var textbox = new LayoutFarm.CustomWidgets.TextBoxContainer(100, 60, true); var subdomExtender = new TextAreaInputSubDomExtender(textbox); CssBox wrapperBox = CreateCssWrapper( host, textbox, textbox.GetPrimaryRenderElement(), spec, subdomExtender, true); textbox.KeyDown += (s, e) => { ((LayoutFarm.UI.IUIEventListener)domE).ListenKeyDown(e); }; htmlTextAreaElem.SubDomExtender = subdomExtender;//connect //place holder support DomAttribute placeHolderAttr = domE.FindAttribute("placeholder"); if (placeHolderAttr != null) { textbox.PlaceHolderText = placeHolderAttr.Value; } parentBox.AppendChild(wrapperBox); //content of text area HtmlTextNode textNode = null; foreach (DomNode child in domE.GetChildNodeIterForward()) { switch (child.NodeKind) { case HtmlNodeKind.TextNode: { textNode = (HtmlTextNode)child; } break; } if (textNode != null) { break; } } if (textNode != null) { //if first line is blank line we skip //TODO: review here System.Collections.Generic.List <string> strList = new System.Collections.Generic.List <string>(); int lineCount = 0; using (System.IO.StringReader strReader = new System.IO.StringReader(new string(textNode.GetOriginalBuffer()))) { string line = strReader.ReadLine(); while (line != null) { if (lineCount == 0) { if (line.Trim() != string.Empty) { strList.Add(line); } } else { strList.Add(line); } lineCount++; line = strReader.ReadLine(); } if (strList.Count > 0) { //check last line line = strList[strList.Count - 1]; if (line.Trim() == string.Empty) { strList.RemoveAt(strList.Count - 1); } } } // if (strList.Count > 0) { textbox.SetText(strList); } } return(wrapperBox); }
CssBox CreateInputBox(DomElement domE, CssBox parentBox, BoxSpec spec, LayoutFarm.RootGraphic rootgfx, HtmlHost host) { //https://www.w3schools.com/tags/tag_input.asp //button //checkbox //color //date //datetime - local //email //file //hidden //image //month //number //password //radio //range //reset //search //submit //tel //text //time //url //week var typeAttr = domE.FindAttribute("type"); if (typeAttr != null) { switch (typeAttr.Value) { case "password": { var textbox = new LayoutFarm.CustomWidgets.TextBoxContainer(100, 20, false, true); CssBox wrapperBox = CreateWrapper( host, textbox, textbox.GetPrimaryRenderElement(rootgfx), spec, true); //place holder support DomAttribute placeHolderAttr = domE.FindAttribute("placeholder"); if (placeHolderAttr != null) { textbox.PlaceHolderText = placeHolderAttr.Value; } parentBox.AppendChild(wrapperBox); return(wrapperBox); } case "text": { // user can specific width of textbox //var textbox = new LayoutFarm.CustomWidgets.TextBox(100, 17, false); var textbox = new LayoutFarm.CustomWidgets.TextBoxContainer(100, 20, false); CssBox wrapperBox = CreateWrapper( host, textbox, textbox.GetPrimaryRenderElement(rootgfx), spec, true); //place holder support DomAttribute placeHolderAttr = domE.FindAttribute("placeholder"); if (placeHolderAttr != null) { textbox.PlaceHolderText = placeHolderAttr.Value; } parentBox.AppendChild(wrapperBox); return(wrapperBox); } case "button": { //use subdom technique *** //todo: review the technique here var button = new HtmlWidgets.Button(60, 30); var ihtmlElement = domE as LayoutFarm.WebDom.IHtmlElement; if (ihtmlElement != null) { button.Text = ihtmlElement.innerHTML; } else { button.Text = "testButton"; } WebDom.Impl.HtmlElement buttonDom = (WebDom.Impl.HtmlElement)button.GetPresentationDomNode((HtmlDocument)domE.OwnerDocument); buttonDom.SetAttribute("style", "width:20px;height:20px;background-color:white;cursor:pointer"); CssBox buttonCssBox = host.CreateBox(parentBox, buttonDom, true); parentBox.AppendChild(buttonCssBox); return(buttonCssBox); } case "checkbox": { //implement with choice box + multiple value var button = new HtmlWidgets.ChoiceBox(10, 10); button.OnlyOne = false; //*** show as checked box var ihtmlElement = domE as LayoutFarm.WebDom.IHtmlElement; WebDom.Impl.HtmlElement buttonDom = (WebDom.Impl.HtmlElement)button.GetPresentationDomNode((HtmlDocument)domE.OwnerDocument); //buttonDom.SetAttribute("style", "width:20px;height:20px;background-color:red;cursor:pointer"); CssBox buttonCssBox = host.CreateBox(parentBox, buttonDom, true); //create and append to the parentBox #if DEBUG buttonCssBox.dbugMark1 = 1; #endif return(buttonCssBox); } case "radio": { var button = new HtmlWidgets.ChoiceBox(10, 10); button.OnlyOne = true; // show as option box var ihtmlElement = domE as LayoutFarm.WebDom.IHtmlElement; //if (ihtmlElement != null) //{ // button.Text = ihtmlElement.innerHTML; //} //else //{ // button.Text = "testButton"; //} //button.Text = "C"; WebDom.Impl.HtmlElement buttonDom = (WebDom.Impl.HtmlElement)button.GetPresentationDomNode((HtmlDocument)domE.OwnerDocument); //buttonDom.SetAttribute("style", "width:20px;height:20px;background-color:red;cursor:pointer"); CssBox buttonCssBox = host.CreateBox(parentBox, buttonDom, true); //create and append to the parentBox #if DEBUG buttonCssBox.dbugMark1 = 1; #endif return(buttonCssBox); } case "your_box": { //tempfix -> just copy the Button code, //TODO: review here, use proper radio button var box = new LayoutFarm.CustomWidgets.Box(20, 20); CssBox wrapperBox = CreateWrapper( host, box, box.GetPrimaryRenderElement(rootgfx), spec, true); parentBox.AppendChild(wrapperBox); return(wrapperBox); } } } return(null); }