/// <summary>write the code for the designer file where the properties of the control are written</summary> public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl) { ProcessTemplate ctrlSnippet = base.SetControlProperties(writer, ctrl); string valuesArray = "["; List <XmlNode> optionalValues = TYml2Xml.GetChildren(TXMLParser.GetChild(ctrl.xmlNode, "OptionalValues"), true); // DefaultValue with = sign before control name for (int counter = 0; counter < optionalValues.Count; counter++) { string loopValue = TYml2Xml.GetElementName(optionalValues[counter]); if (loopValue.StartsWith("=")) { loopValue = loopValue.Substring(1).Trim(); ctrlSnippet.SetCodelet("VALUE", loopValue); } if (counter > 0) { valuesArray += ", "; } ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "OPTION" + counter.ToString(), ctrl, loopValue); string strName = "this." + ctrl.controlName + "OPTION" + counter.ToString(); valuesArray += "['" + loopValue + "', " + strName + "]"; } valuesArray += "]"; ctrlSnippet.SetCodelet("OPTIONALVALUESARRAY", valuesArray); if (ctrl.HasAttribute("width")) { ctrlSnippet.SetCodelet("WIDTH", ctrl.GetAttribute("width")); } return(ctrlSnippet); }
/// <summary> /// main function for creating a control /// </summary> /// <param name="ACtrl"></param> /// <param name="ATemplate"></param> /// <param name="AItemsPlaceholder"></param> /// <param name="ANodeName"></param> /// <param name="AWriter"></param> public static void InsertControl(TControlDef ACtrl, ProcessTemplate ATemplate, string AItemsPlaceholder, string ANodeName, TFormWriter AWriter) { XmlNode controlsNode = TXMLParser.GetChild(ACtrl.xmlNode, ANodeName); List <XmlNode> childNodes = TYml2Xml.GetChildren(controlsNode, true); if ((childNodes.Count > 0) && childNodes[0].Name.StartsWith("Row")) { foreach (XmlNode row in TYml2Xml.GetChildren(controlsNode, true)) { ProcessTemplate snippetRowDefinition = AWriter.FTemplate.GetSnippet("ROWDEFINITION"); StringCollection children = TYml2Xml.GetElements(controlsNode, row.Name); foreach (string child in children) { TControlDef childCtrl = AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName); IControlGenerator ctrlGen = AWriter.FindControlGenerator(childCtrl); ProcessTemplate ctrlSnippet = ctrlGen.SetControlProperties(AWriter, childCtrl); ProcessTemplate snippetCellDefinition = AWriter.FTemplate.GetSnippet("CELLDEFINITION"); LayoutCellInForm(childCtrl, children.Count, ctrlSnippet, snippetCellDefinition); if ((children.Count == 1) && ctrlGen is RadioGroupSimpleGenerator) { // do not use the ROWDEFINITION, but insert control directly // this helps with aligning the label for the group radio buttons snippetRowDefinition.InsertSnippet("ITEMS", ctrlSnippet, ","); } else { snippetCellDefinition.InsertSnippet("ITEM", ctrlSnippet); snippetRowDefinition.InsertSnippet("ITEMS", snippetCellDefinition, ","); } } ATemplate.InsertSnippet(AItemsPlaceholder, snippetRowDefinition, ","); } } else { foreach (XmlNode childNode in childNodes) { string child = TYml2Xml.GetElementName(childNode); TControlDef childCtrl = AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName); if ((ANodeName != "HiddenValues") && (childCtrl.controlTypePrefix == "hid")) { // somehow, hidden values get into the controls list as well. we don't want them there continue; } IControlGenerator ctrlGen = AWriter.FindControlGenerator(childCtrl); if (ctrlGen is FieldSetGenerator) { InsertControl(AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName), ATemplate, AItemsPlaceholder, ANodeName, AWriter); } else { ProcessTemplate ctrlSnippet = ctrlGen.SetControlProperties(AWriter, childCtrl); ProcessTemplate snippetCellDefinition = AWriter.FTemplate.GetSnippet("CELLDEFINITION"); LayoutCellInForm(childCtrl, -1, ctrlSnippet, snippetCellDefinition); ATemplate.InsertSnippet(AItemsPlaceholder, ctrlSnippet, ","); } } } }
/// <summary> /// this function should be used for any collection of controls: on a TabPage, in a table, in a groupbox, radio button list etc. /// </summary> /// <returns>the layout control that still needs to be added to the parent</returns> public void CreateLayout(TFormWriter writer, TControlDef parentContainer, TControlDef layoutPanel, Int32 ANewWidth, Int32 ANewHeight) { if (layoutPanel == null) { layoutPanel = parentContainer; } // first check if the table layout has already been defined in the container with sets of rows? XmlNode containerNode = parentContainer.xmlNode; XmlNode controlsNode = TXMLParser.GetChild(containerNode, "Controls"); if (controlsNode != null) { FTabOrder = TYml2Xml.GetAttribute(controlsNode, "TabOrder"); } List <XmlNode> childNodes = TYml2Xml.GetChildren(controlsNode, true); if ((childNodes.Count > 0) && TYml2Xml.GetElementName(childNodes[0]).StartsWith("Row")) { // create a layout using the defined rows in Controls // create TableLayoutPanel that has as many columns (including the labels) and rows as needed FOrientation = eOrientation.TableLayout; FCurrentRow = 0; FCurrentColumn = 0; FColumnCount = 2; // determine maximum number of columns foreach (XmlNode row in TYml2Xml.GetChildren(controlsNode, true)) { // one other column for the label; will be cleaned up in WriteTableLayout int columnCount = 2 * TYml2Xml.GetElements(row).Count; if (columnCount > FColumnCount) { FColumnCount = columnCount; } } FRowCount = TYml2Xml.GetChildren(controlsNode, true).Count; InitTableLayoutGrid(); foreach (TControlDef childctrl in parentContainer.Children) { childctrl.parentName = layoutPanel.controlName; } } else { // create TableLayoutPanel that has a column for the labels and as many rows as needed FCurrentRow = 0; FCurrentColumn = 0; if (FOrientation == eOrientation.Vertical) { FColumnCount = 2; FRowCount = parentContainer.Children.Count; } else if (FOrientation == eOrientation.Horizontal) { // horizontal: label and control, all controls in one row FColumnCount = parentContainer.Children.Count * 2; FRowCount = 1; } InitTableLayoutGrid(); foreach (TControlDef childControl in parentContainer.Children) { childControl.parentName = layoutPanel.controlName; } } #region Custom Column Widths and custom Row Heights /* * Record custom Column Widths, if specified. */ XmlNode colWidthsNode = TXMLParser.GetChild(containerNode, "ColWidths"); StringCollection ColWidths = TYml2Xml.GetElements(colWidthsNode); if (ColWidths.Count > 0) { FColWidths = new Dictionary <int, string>(); foreach (string colWidth in ColWidths) { // Console.WriteLine(containerNode.Name + ".colWidth: " + colWidth + " " + String.Format("FColWidths: {0} / {1})", // colWidth.Substring(0, colWidth.IndexOf('=')), // colWidth.Substring(colWidth.IndexOf('=') + 1))); FColWidths.Add(Convert.ToInt32(colWidth.Substring(0, colWidth.IndexOf('='))), colWidth.Substring(colWidth.IndexOf('=') + 1)); } } /* * Record custom Row Heights, if specified. */ XmlNode colHeightsNode = TXMLParser.GetChild(containerNode, "RowHeights"); StringCollection RowHeights = TYml2Xml.GetElements(colHeightsNode); if (RowHeights.Count > 0) { FRowHeights = new Dictionary <int, string>(); foreach (string rowHeight in RowHeights) { // Console.WriteLine(containerNode.Name + ".rowHeight: " + rowHeight + " " + String.Format("FRowHeights: {0} / {1})", // rowHeight.Substring(0, rowHeight.IndexOf('=')), // rowHeight.Substring(rowHeight.IndexOf('=') + 1))); FRowHeights.Add(Convert.ToInt32(rowHeight.Substring(0, rowHeight.IndexOf('='))), rowHeight.Substring(rowHeight.IndexOf('=') + 1)); } } #endregion }