/// <summary>
        /// get the controls that belong to the toolstrip
        /// </summary>
        public override void ProcessChildren(TFormWriter writer, TControlDef container)
        {
            // add all the children

            // TODO add Container elements in statusbar
            if (container.controlName.StartsWith("stb"))
            {
                return;
            }

            List <XmlNode> childrenlist;

            if (TYml2Xml.GetChild(container.xmlNode, "Controls") != null)
            {
                // this is for generated toolbar, eg. for the PrintPreviewControl
                StringCollection childrenNames = TYml2Xml.GetElements(container.xmlNode, "Controls");
                childrenlist = new List <XmlNode>();

                foreach (string name in childrenNames)
                {
                    childrenlist.Add(container.xmlNode.OwnerDocument.CreateElement(name));
                }
            }
            else
            {
                // usually, the toolbar buttons are direct children of the toolbar control
                childrenlist = TYml2Xml.GetChildren(container.xmlNode, true);
            }

            //Console.WriteLine("Container: " + container.controlName);
            foreach (XmlNode child in childrenlist)
            {
                // Console.WriteLine("Child: " + child.Name);

                /* Get unique name if we need it
                 * at the moment we need it only for menu separators
                 */
                String      UniqueChildName = child.Name;
                TControlDef ControlDefChild = container.FCodeStorage.GetControl(child.Name);

                if (ControlDefChild == null)
                {
                    UniqueChildName = TYml2Xml.GetAttribute(child, "UniqueName");
                    ControlDefChild = container.FCodeStorage.GetControl(UniqueChildName);
                }

                container.Children.Add(ControlDefChild);

                if (ControlDefChild != null)
                {
                    IControlGenerator ctrlGenerator = writer.FindControlGenerator(ControlDefChild);

                    // add control itself
                    if (ctrlGenerator != null)
                    {
                        ctrlGenerator.GenerateControl(writer, ControlDefChild);
                    }
                }
            }
        }
        /// <summary>
        /// process the children
        /// </summary>
        public override void ProcessChildren(TFormWriter writer, TControlDef container)
        {
            // usually, the toolbar buttons are direct children of the toolbar control
            List <XmlNode> childrenlist = TYml2Xml.GetChildren(container.xmlNode, true);

            foreach (XmlNode childNode in childrenlist)
            {
                /* Get unique name if we need it
                 * at the moment we need it only for menu separators
                 */
                String      UniqueChildName = childNode.Name;
                TControlDef childCtrl       = container.FCodeStorage.GetControl(childNode.Name);

                if (childCtrl == null)
                {
                    UniqueChildName = TYml2Xml.GetAttribute(childNode, "UniqueName");
                    childCtrl       = container.FCodeStorage.GetControl(UniqueChildName);
                }

                container.Children.Add(childCtrl);
                IControlGenerator ctrlGenerator = writer.FindControlGenerator(childCtrl);
                ctrlGenerator.GenerateControl(writer, childCtrl);
            }
        }
Exemple #3
0
        /// <summary>
        /// create the code
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="ctrl"></param>
        public void InsertControl(TFormWriter writer, TControlDef ctrl)
        {
            IControlGenerator ctrlGenerator = writer.FindControlGenerator(ctrl);

            string controlName = ctrl.controlName;

            if (FOrientation == eOrientation.TableLayout)
            {
                if (FCurrentRow != ctrl.rowNumber)
                {
                    FCurrentColumn = 0;
                    FCurrentRow    = ctrl.rowNumber;
                }
            }

/* this does not work yet; creates endless loop/recursion
 *          if (ctrl.HasAttribute("LabelUnit"))
 *          {
 *              // we need another label after the control
 *              LabelGenerator lblGenerator = new LabelGenerator();
 *              string lblName = lblGenerator.CalculateName(controlName) + "Unit";
 *              TControlDef unitLabel = writer.CodeStorage.FindOrCreateControl(lblName, controlName);
 *              unitLabel.Label = ctrl.GetAttribute("LabelUnit");
 *
 *              TableLayoutPanelGenerator TlpGenerator = new TableLayoutPanelGenerator();
 *              ctrl.SetAttribute("ControlsOrientation", "horizontal");
 *              TlpGenerator.SetOrientation(ctrl);
 *              StringCollection childControls = new StringCollection();
 *              childControls.Add(controlName);
 *              childControls.Add(lblName);
 *              string subTlpControlName = TlpGenerator.CreateLayout(writer, FTlpName, childControls);
 *
 *              TlpGenerator.CreateCode(writer, ctrl);
 *              TlpGenerator.CreateCode(writer, unitLabel);
 *
 *              if (FOrientation == eOrientation.Vertical)
 *              {
 *                  AddControl(writer, FTlpName, subTlpControlName, 1, FCurrentRow);
 *              }
 *              else
 *              {
 *                  AddControl(writer, FTlpName, subTlpControlName, FCurrentColumn * 2 + 1, 0);
 *              }
 *          }
 *          else
 */
            if (ctrl.HasAttribute("GenerateWithOtherControls"))
            {
                // add the checkbox/radiobutton first
                if (FOrientation == eOrientation.Vertical)
                {
                    AddControl(ctrl, 0, FCurrentRow);
                }
                else if (FOrientation == eOrientation.Horizontal)
                {
                    AddControl(ctrl, FCurrentColumn * 2, 0);
                }
                else if (FOrientation == eOrientation.TableLayout)
                {
                    AddControl(ctrl, FCurrentColumn, FCurrentRow);
                }

                StringCollection childControls = TYml2Xml.GetElements(TXMLParser.GetChild(ctrl.xmlNode, "Controls"));

                if (childControls.Count > 1)
                {
                    // we need another tablelayout to arrange all the controls
                    PanelLayoutGenerator TlpGenerator = new PanelLayoutGenerator();
                    TlpGenerator.SetOrientation(ctrl);

                    Int32 NewHeight = -1;
                    Int32 NewWidth  = -1;

                    if (ctrl.HasAttribute("Height"))
                    {
                        NewHeight = Convert.ToInt32(ctrl.GetAttribute("Height"));
                        ctrl.ClearAttribute("Height");
                    }

                    if (ctrl.HasAttribute("Width"))
                    {
                        NewWidth = Convert.ToInt32(ctrl.GetAttribute("Width"));
                        ctrl.ClearAttribute("Width");
                    }

                    TControlDef subTlpControl = TlpGenerator.CreateNewPanel(writer, ctrl);
                    TlpGenerator.CreateLayout(writer, ctrl, subTlpControl, NewWidth, NewHeight);

                    foreach (string ChildControlName in childControls)
                    {
                        TControlDef ChildControl = ctrl.FCodeStorage.GetControl(ChildControlName);
                        TlpGenerator.InsertControl(writer, ChildControl);
                    }

                    TlpGenerator.WriteTableLayout(writer, subTlpControl);

                    if (FOrientation == eOrientation.Vertical)
                    {
                        AddControl(subTlpControl, 1, FCurrentRow);
                    }
                    else if (FOrientation == eOrientation.Horizontal)
                    {
                        AddControl(subTlpControl, FCurrentColumn * 2 + 1, 0);
                    }
                    else if (FOrientation == eOrientation.TableLayout)
                    {
                        AddControl(subTlpControl, FCurrentColumn + 1, FCurrentRow);
                    }
                }
                else if (childControls.Count == 1)
                {
                    // we don't need to add another table layout for just one other control
                    TControlDef       ChildCtrl      = ctrl.FCodeStorage.GetControl(childControls[0]);
                    IControlGenerator ChildGenerator = writer.FindControlGenerator(ChildCtrl);
                    ChildGenerator.GenerateControl(writer, ChildCtrl);

                    if (FOrientation == eOrientation.Vertical)
                    {
                        AddControl(ChildCtrl, 1, FCurrentRow);
                    }
                    else if (FOrientation == eOrientation.Horizontal)
                    {
                        AddControl(ChildCtrl, FCurrentColumn * 2 + 1, 0);
                    }
                    else if (FOrientation == eOrientation.TableLayout)
                    {
                        AddControl(ChildCtrl, FCurrentColumn + 1, FCurrentRow);
                    }
                }
            }
            else if (ctrl.controlName.StartsWith("pnlEmpty"))
            {
                // don't do anything here!
            }
            else if (ctrlGenerator.GenerateLabel(ctrl))
            {
                // add label
                LabelGenerator lblGenerator = new LabelGenerator();
                string         lblName      = lblGenerator.CalculateName(controlName);
                TControlDef    newLabel     = writer.CodeStorage.FindOrCreateControl(lblName, ctrl.controlName);
                newLabel.Label = ctrl.Label;

                if (ctrl.HasAttribute("LabelWidth"))
                {
                    newLabel.SetAttribute("Width", ctrl.GetAttribute("LabelWidth"));
                }

                if (ctrl.HasAttribute("LabelUnit"))
                {
                    // alternative implementation above does not work: add another label control after the input control
                    newLabel.Label = newLabel.Label + " (in " + ctrl.GetAttribute("LabelUnit") + ")";
                }

                lblGenerator.GenerateDeclaration(writer, newLabel);
                lblGenerator.RightAlign = true;
                lblGenerator.SetControlProperties(writer, newLabel);

                AddControl(newLabel,
                           FCurrentColumn * 2,
                           FCurrentRow);
                AddControl(ctrl,
                           FCurrentColumn * 2 + 1,
                           FCurrentRow);
            }
            else
            {
                AddControl(ctrl,
                           FCurrentColumn * 2,
                           FCurrentRow);
            }

            if (FOrientation == eOrientation.Vertical)
            {
                FCurrentRow++;
                FCurrentColumn = 0;
            }
            else if (FOrientation == eOrientation.Horizontal)
            {
                FCurrentColumn++;
            }
            else if (FOrientation == eOrientation.TableLayout)
            {
                FCurrentColumn += ctrl.colSpan;
            }
        }