Exemplo n.º 1
0
        LayoutFarm.HtmlBoxes.CssBox CreateInputBox(DomElement domE,
                                                   LayoutFarm.HtmlBoxes.CssBox parentBox,
                                                   BoxSpec spec,
                                                   LayoutFarm.RootGraphic rootgfx, HtmlHost host)
        {
            var typeAttr = domE.FindAttribute("type");

            if (typeAttr != null)
            {
                switch (typeAttr.Value)
                {
                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);
                    var wrapperBox = CreateWrapper(
                        textbox,
                        textbox.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    //place holder support
                    var 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 = "";
                    }
                    button.Text = "testButton";
                    DomElement buttonDom    = button.GetPresentationDomNode((HtmlDocument)domE.OwnerDocument);
                    CssBox     buttonCssBox = host.CreateBox2(parentBox, (WebDom.Impl.HtmlElement)buttonDom, true);     // CreateCssBox(buttonDom, parentBox, spec, host);
                    //var ui = button.GetPrimaryUIElement(this.myHost);

                    //var wrapperBox = CreateWrapper(
                    //    button,
                    //    ui.GetPrimaryRenderElement(rootgfx),
                    //    spec, true);
                    //parentBox.AppendChild(wrapperBox);
                    //return wrapperBox;

                    parentBox.AppendChild(buttonCssBox);
                    return(buttonCssBox);
                }

                case "textbox":
                {
                    var    textbox    = new LayoutFarm.CustomWidgets.TextBox(100, 17, false);
                    CssBox wrapperBox = CreateWrapper(
                        textbox,
                        textbox.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }

                case "radio":
                {
                    //tempfix -> just copy the Button code,
                    //TODO: review here, use proper radio button
                    var    box        = new LayoutFarm.CustomWidgets.Box(20, 20);
                    CssBox wrapperBox = CreateWrapper(
                        box,
                        box.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        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);
        }