/// <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> /// load the parameters of a report /// </summary> /// <param name="curNode"></param> protected void LoadReportParameters(XmlNode curNode) { if (curNode != null) { List <XmlNode> children = TYml2Xml.GetChildren(curNode, true); foreach (XmlNode childNode in children) { FCodeStorage.AddReportParameter(childNode, curNode.Attributes["ColumnFunction"].Value); } } }
/// <summary> /// load the events /// </summary> /// <param name="curNode"></param> protected void LoadEvents(XmlNode curNode) { if (curNode != null) { List <XmlNode> children = TYml2Xml.GetChildren(curNode, true); foreach (XmlNode childNode in children) { FCodeStorage.AddEvent(childNode); } } }
/// <summary> /// load the toolbar /// </summary> /// <param name="parentName"></param> /// <param name="curNode"></param> /// <returns></returns> public Boolean LoadToolbar(string parentName, XmlNode curNode) { List <XmlNode> children = TYml2Xml.GetChildren(curNode, true); XmlNode rootBarNode = FCodeStorage.GetRootControl("tbr").xmlNode; foreach (XmlNode childNode in children) { // the check for tbb works around problems with elements list, shortcutkeys if (childNode.Name.StartsWith("tbb") || childNode.Name.StartsWith("tbc")) { string tbbName = childNode.Name; if (tbbName == "tbbSeparator") { // UniqueName is not stored to yml again; just used temporary TYml2Xml.SetAttribute(childNode, "UniqueName", tbbName + FToolbarSeparatorCount.ToString()); FToolbarSeparatorCount++; } TControlDef tbbItem = FCodeStorage.AddControl(childNode); tbbItem.parentName = parentName; rootBarNode.AppendChild(childNode); } else { // use ToolStripControlHost to host any control TControlDef tbbItem = FCodeStorage.AddControl(childNode); string prefix = TControlDef.GetLowerCasePrefix(childNode.Name); tbbItem.parentName = "tch" + childNode.Name.Substring(prefix.Length); XmlNode controlHostNode = rootBarNode.OwnerDocument.CreateElement(tbbItem.parentName); TYml2Xml.SetAttribute(controlHostNode, "depth", TYml2Xml.GetAttribute(childNode, "depth")); TYml2Xml.SetAttribute(controlHostNode, "HostedControl", childNode.Name); rootBarNode.AppendChild(controlHostNode); XmlNode controlsNode = rootBarNode.OwnerDocument.CreateElement("Controls"); controlHostNode.AppendChild(controlsNode); XmlNode elementNode = rootBarNode.OwnerDocument.CreateElement("Element"); controlsNode.AppendChild(elementNode); TYml2Xml.SetAttribute(elementNode, "name", childNode.Name); TControlDef hostItem = FCodeStorage.AddControl(controlHostNode); hostItem.parentName = parentName; } } return(true); }
/// <summary> /// load the layout /// </summary> /// <param name="ALayoutNode"></param> public void LoadLayout(XmlNode ALayoutNode) { if (ALayoutNode != null) { List <XmlNode> children = TYml2Xml.GetChildren(ALayoutNode, true); if ((children.Count > 0) && (children[0].Name == "Tabs")) { foreach (XmlNode curNode in children) { AddTabPage(curNode); } } } }
/// <summary> /// load the menu /// </summary> /// <param name="parentName"></param> /// <param name="curNode"></param> /// <returns></returns> public Boolean LoadMenu(string parentName, XmlNode curNode) { string menuName = curNode.Name; if (menuName == "mniSeparator") { // UniqueName is not stored to yml again; just used temporary TYml2Xml.SetAttribute(curNode, "UniqueName", menuName + FMenuSeparatorCount.ToString()); FMenuSeparatorCount++; } if (curNode.ParentNode.Name == TParseYAMLFormsDefinition.ROOTNODEYML) { // add each menu, but obviously not the "Menu" tag XmlNode menuNode = curNode; List <XmlNode> children = TYml2Xml.GetChildren(menuNode, true); foreach (XmlNode childNode in children) { LoadMenu(parentName, childNode); // attach the menu to the appropriate root control XmlNode rootMenu = FCodeStorage.GetRootControl("mnu").xmlNode; rootMenu.AppendChild(childNode); } return(true); } TControlDef menuItem = FCodeStorage.AddControl(curNode); menuItem.parentName = parentName; List <XmlNode> children2 = TYml2Xml.GetChildren(curNode, true); foreach (XmlNode childNode in children2) { // the check for mni works around problems with elements list, shortcutkeys if (childNode.Name.StartsWith("mni")) { LoadMenu(menuName, childNode); } } return(true); }
/// <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> /// 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); } }
/// <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 }