/// <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) { // Support NoLabel=true FGenerateLabel = true; if (GenerateLabel(ctrl)) { writer.SetControlProperty(ctrl, "Text", "\"" + ctrl.Label + "\""); ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(ctrl.Label) + 30).ToString()); } else { ctrl.SetAttribute("Width", "15"); } base.SetControlProperties(writer, ctrl); FGenerateLabel = false; if (TYml2Xml.HasAttribute(ctrl.xmlNode, "RadioChecked")) { writer.SetControlProperty(ctrl, "Checked", TYml2Xml.GetAttribute(ctrl.xmlNode, "RadioChecked")); } return(writer.FTemplate); }
/// <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) { // TODO this does not work yet. see EventRole Maintain screen if ((!ctrl.HasAttribute("Align")) && (!ctrl.HasAttribute("Width"))) { ctrl.SetAttribute("Stretch", "horizontally"); } base.SetControlProperties(writer, ctrl); TControlDef parentCtrl = writer.FCodeStorage.GetControl(ctrl.parentName); // We need to over-ride any Anchor requests in the YAML to anchor an attached label to anything other than top-left // But pure label controls can be anchored to, say, left-top-right if ((ctrl.controlName.Substring(ctrl.controlTypePrefix.Length) == parentCtrl.controlName.Substring(parentCtrl.controlTypePrefix.Length)) || ((ctrl.HasAttribute("Dock") == false) && (ctrl.HasAttribute("Align") == false))) { // stretch at design time, but do not align to the right writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)))"); } string labelText = ""; if (TYml2Xml.HasAttribute(ctrl.xmlNode, "Text")) { labelText = TYml2Xml.GetAttribute(ctrl.xmlNode, "Text"); } else { labelText = ctrl.Label + ":"; } if (ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", ctrl.GetAttribute("Width")); } else { ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(labelText) + 5).ToString()); } if (ctrl.HasAttribute("Height")) { ctrl.SetAttribute("Height", ctrl.GetAttribute("Height")); } writer.SetControlProperty(ctrl, "Text", "\"" + labelText + "\""); writer.SetControlProperty(ctrl, "Padding", "new System.Windows.Forms.Padding(0, 5, 0, 0)"); if (FRightAlign) { writer.SetControlProperty(ctrl, "TextAlign", "System.Drawing.ContentAlignment.TopRight"); } return(writer.FTemplate); }
/// <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) { // TODO this does not work yet. see EventRole Maintain screen if ((!ctrl.HasAttribute("Align")) && (!ctrl.HasAttribute("Width"))) { ctrl.SetAttribute("Stretch", "horizontally"); } base.SetControlProperties(writer, ctrl); // stretch at design time, but do not align to the right writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)))"); string labelText = ""; if (TYml2Xml.HasAttribute(ctrl.xmlNode, "Text")) { labelText = TYml2Xml.GetAttribute(ctrl.xmlNode, "Text"); } else { labelText = ctrl.Label + ":"; } if (ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", ctrl.GetAttribute("Width")); } else { ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(labelText) + 5).ToString()); } if (ctrl.HasAttribute("Height")) { ctrl.SetAttribute("Height", ctrl.GetAttribute("Height")); } writer.SetControlProperty(ctrl, "Text", "\"" + labelText + "\""); writer.SetControlProperty(ctrl, "Padding", "new System.Windows.Forms.Padding(0, 5, 0, 0)"); if (FRightAlign) { writer.SetControlProperty(ctrl, "TextAlign", "System.Drawing.ContentAlignment.TopRight"); } return(writer.FTemplate); }
/// <summary> /// create the radio buttons and the controls that depend on them /// </summary> /// <param name="writer"></param> /// <param name="curNode"></param> /// <returns></returns> public override StringCollection FindContainedControls(TFormWriter writer, XmlNode curNode) { StringCollection Controls = TYml2Xml.GetElements(TXMLParser.GetChild(curNode, "Controls")); string DefaultValue = Controls[0]; if (TXMLParser.HasAttribute(curNode, "DefaultValue")) { DefaultValue = TXMLParser.GetAttribute(curNode, "DefaultValue"); } foreach (string controlName in Controls) { TControlDef radioButton = writer.CodeStorage.GetControl(controlName); if (radioButton == null) { throw new Exception("cannot find control " + controlName + " used in RadioGroup " + curNode.Name); } if (StringHelper.IsSame(DefaultValue, controlName)) { radioButton.SetAttribute("RadioChecked", "true"); } } return(Controls); }
/// <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) { if ((ctrl.HasAttribute("CheckBoxAttachedLabel")) && ((ctrl.GetAttribute("CheckBoxAttachedLabel").ToLower() == "left") || (ctrl.GetAttribute("CheckBoxAttachedLabel").ToLower() == "right"))) { base.FAutoSize = true; if (ctrl.HasAttribute("NoLabel") && (ctrl.GetAttribute("NoLabel").ToLower() == "true")) { writer.SetControlProperty(ctrl, "Text", "\"\""); } else { writer.SetControlProperty(ctrl, "Text", "\"" + ctrl.Label + "\""); if (ctrl.GetAttribute("CheckBoxAttachedLabel").ToLower() == "left") { writer.SetControlProperty(ctrl, "CheckAlign", "System.Drawing.ContentAlignment.MiddleRight"); } else { writer.SetControlProperty(ctrl, "CheckAlign", "System.Drawing.ContentAlignment.MiddleLeft"); } writer.SetControlProperty(ctrl, "Margin", "new System.Windows.Forms.Padding(3, 4, 3, 0)"); ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(ctrl.Label) + 30).ToString()); ctrl.SetAttribute("Height", "17"); } base.SetControlProperties(writer, ctrl); } else { base.FAutoSize = false; ctrl.SetAttribute("Width", 30.ToString ()); base.SetControlProperties(writer, ctrl); writer.SetControlProperty(ctrl, "Text", "\"\""); writer.SetControlProperty(ctrl, "Margin", "new System.Windows.Forms.Padding(3, 0, 3, 0)"); } return(writer.FTemplate); }
/// <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) { Int32 buttonWidth = 40; Int32 textBoxWidth = 80; // seems to be hardcoded in csharp\ICT\Petra\Client\CommonControls\Gui\txtAutoPopulatedButtonLabel.Designer.cs Int32 controlWidth = 390; base.SetControlProperties(writer, ctrl); if ((ctrl.HasAttribute("ShowLabel") && (ctrl.GetAttribute("ShowLabel").ToLower() == "false"))) { writer.SetControlProperty(ctrl, "ShowLabel", "false"); controlWidth = 120; } // Note: the control defaults to 'ShowLabel' true, so this doesn't need to be set to 'true' in code. writer.SetControlProperty(ctrl, "ASpecialSetting", "true"); writer.SetControlProperty(ctrl, "ButtonTextAlign", "System.Drawing.ContentAlignment.MiddleCenter"); writer.SetControlProperty(ctrl, "ListTable", "TtxtAutoPopulatedButtonLabel.TListTableEnum." + FButtonLabelType); writer.SetControlProperty(ctrl, "PartnerClass", "\"" + ctrl.GetAttribute("PartnerClass") + "\""); writer.SetControlProperty(ctrl, "MaxLength", "32767"); writer.SetControlProperty(ctrl, "Tag", "\"CustomDisableAlthoughInvisible\""); writer.SetControlProperty(ctrl, "TextBoxWidth", textBoxWidth.ToString()); if (!(ctrl.HasAttribute("ReadOnly") && (ctrl.GetAttribute("ReadOnly").ToLower() == "true"))) { writer.SetControlProperty(ctrl, "ButtonWidth", buttonWidth.ToString()); writer.SetControlProperty(ctrl, "ReadOnly", "false"); writer.SetControlProperty(ctrl, "Font", "new System.Drawing.Font(\"Verdana\", 8.25f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (byte)0)"); writer.SetControlProperty(ctrl, "ButtonText", "\"Find\""); } else { writer.SetControlProperty(ctrl, "ButtonWidth", "0"); writer.SetControlProperty(ctrl, "BorderStyle", "System.Windows.Forms.BorderStyle.None"); writer.SetControlProperty(ctrl, "Padding", "new System.Windows.Forms.Padding(0, 4, 0, 0)"); } if (!ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", controlWidth.ToString()); } if (TYml2Xml.HasAttribute(ctrl.xmlNode, "DefaultValue")) { writer.SetControlProperty(ctrl, "Text", "\"" + TYml2Xml.GetAttribute(ctrl.xmlNode, "DefaultValue") + "\""); } return(writer.FTemplate); }
/// <summary> /// create the radio buttons /// </summary> /// <param name="writer"></param> /// <param name="curNode"></param> /// <returns></returns> public override StringCollection FindContainedControls(TFormWriter writer, XmlNode curNode) { StringCollection optionalValues = TYml2Xml.GetElements(TXMLParser.GetChild(curNode, "OptionalValues")); string DefaultValue = optionalValues[0]; if (TXMLParser.HasAttribute(curNode, "DefaultValue")) { DefaultValue = TXMLParser.GetAttribute(curNode, "DefaultValue"); } else { // DefaultValue with = sign before control name for (int counter = 0; counter < optionalValues.Count; counter++) { if (optionalValues[counter].StartsWith("=")) { optionalValues[counter] = optionalValues[counter].Substring(1).Trim(); DefaultValue = optionalValues[counter]; } } } // add the radiobuttons on the fly StringCollection Controls = new StringCollection(); foreach (string optionalValue in optionalValues) { string radioButtonName = "rbt" + StringHelper.UpperCamelCase(optionalValue.Replace("'", "").Replace(" ", "_").Replace("&", ""), false, false); TControlDef newCtrl = writer.CodeStorage.FindOrCreateControl(radioButtonName, curNode.Name); newCtrl.Label = optionalValue; if (StringHelper.IsSame(DefaultValue, optionalValue)) { newCtrl.SetAttribute("RadioChecked", "true"); } Controls.Add(radioButtonName); } return(Controls); }
/// <summary>write the code for the designer file where the properties of the control are written</summary> public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef container) { container.SetAttribute("Dock", FDocking); base.SetControlProperties(writer, container); // todo: location? // todo: event handler /* * this.menuStrip1.Dock = System.Windows.Forms.DockStyle.None; * this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { * this.toolStripMenuItem1}); * this.menuStrip1.Location = new System.Drawing.Point(0, 0); * this.menuStrip1.Name = "menuStrip1"; * this.menuStrip1.Size = new System.Drawing.Size(138, 24); * this.menuStrip1.TabIndex = 1; * this.menuStrip1.Text = "menuStrip1"; * this.menuStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.MenuStrip1ItemClicked); */ return(writer.FTemplate); }
/// <summary> /// get the radio buttons /// </summary> public override void ProcessChildren(TFormWriter writer, TControlDef ctrl) { StringCollection Controls = TYml2Xml.GetElements(TXMLParser.GetChild(ctrl.xmlNode, "Controls")); string DefaultValue = Controls[0]; if (TYml2Xml.HasAttribute(ctrl.xmlNode, "DefaultValue")) { DefaultValue = TYml2Xml.GetAttribute(ctrl.xmlNode, "DefaultValue"); } foreach (string controlName in Controls) { TControlDef radioButton = writer.CodeStorage.GetControl(controlName); if (StringHelper.IsSame(DefaultValue, controlName)) { radioButton.SetAttribute("RadioChecked", "true"); } } base.ProcessChildren(writer, ctrl); }
/// <summary> /// optimise the table layout, and write it; /// </summary> public void WriteTableLayout(TFormWriter writer, TControlDef LayoutCtrl) { // calculate the width and height for the columns and rows int[] ColumnWidth = new int[FColumnCount]; int[] RowHeight = new int[FRowCount]; // first go: ignore cells spanning rows and columns; second go: check that spanning cells fit as well for (int spanRunCounter = 0; spanRunCounter < 2; spanRunCounter++) { for (int columnCounter = 0; columnCounter < FColumnCount; columnCounter++) { // initialise the summary values if (spanRunCounter == 0) { ColumnWidth[columnCounter] = 0; if (columnCounter == 0) { for (int rowCounter = 0; rowCounter < FRowCount; rowCounter++) { RowHeight[rowCounter] = 0; } } } for (int rowCounter = 0; rowCounter < FRowCount; rowCounter++) { if ((FGrid[columnCounter, rowCounter] != null)) { TControlDef ctrl = FGrid[columnCounter, rowCounter]; int CellWidth = ctrl.Width; TLogging.LogAtLevel(1, "Control '" + ctrl.controlName + "' Width in WriteTableLayout: " + CellWidth.ToString()); if ((spanRunCounter == 0) && (ctrl.colSpanWithLabel == 1)) { if (CellWidth > ColumnWidth[columnCounter]) { ColumnWidth[columnCounter] = CellWidth; } } else { int CurrentSpanWidth = 0; if (columnCounter + ctrl.colSpanWithLabel > FColumnCount) { // TODO: make an exception again? TLogging.Log("Warning: invalid colspan " + ctrl.colSpan.ToString() + " in control " + ctrl.controlName + ". There are only " + (FColumnCount / 2).ToString() + " columns overall"); ctrl.colSpanWithLabel = ctrl.colSpan; } for (int columnCounter2 = columnCounter; columnCounter2 < columnCounter + ctrl.colSpanWithLabel; columnCounter2++) { CurrentSpanWidth += ColumnWidth[columnCounter2]; } if (CurrentSpanWidth < CellWidth) { ColumnWidth[columnCounter + ctrl.colSpanWithLabel - 1] += CellWidth - CurrentSpanWidth; } } int CellHeight = ctrl.Height; if (CellHeight == 17) { // for labels, we should consider the margin top as well. CellHeight = 22; } if ((spanRunCounter == 0) && (ctrl.colSpanWithLabel == 1)) { if (CellHeight > RowHeight[rowCounter]) { RowHeight[rowCounter] = CellHeight; } } else { int CurrentSpanHeight = 0; for (int rowCounter2 = rowCounter; rowCounter2 < rowCounter + ctrl.rowSpan; rowCounter2++) { CurrentSpanHeight += RowHeight[rowCounter2]; } if (CurrentSpanHeight < CellHeight) { RowHeight[rowCounter + ctrl.rowSpan - 1] += CellHeight - CurrentSpanHeight; } } } } } } // now apply settings about the column width and row height if (FColWidths != null) { bool simpleColumnWidth = false; // for the simple column width specification, you need to provide a width for each column, without the label columns if (FColWidths.Count * 2 == FColumnCount) { simpleColumnWidth = true; for (int columnCounter = 0; columnCounter < FColWidths.Count; columnCounter++) { if (!FColWidths.ContainsKey(columnCounter)) { simpleColumnWidth = false; } } } for (int columnCounter = 0; columnCounter < FColumnCount; columnCounter++) { if (simpleColumnWidth) { // the specified width includes the label column if (FColWidths.ContainsKey(columnCounter / 2)) { string[] ColWidthSpec = FColWidths[columnCounter / 2].Split(':'); if (ColWidthSpec[0].ToLower() == "fixed") { ColumnWidth[columnCounter] = Convert.ToInt32(ColWidthSpec[1]) / 2; } else if (ColWidthSpec[0].ToLower() == "percent") { // TODO } } } else { if (FColWidths.ContainsKey(columnCounter)) { string[] ColWidthSpec = FColWidths[columnCounter].Split(':'); if (ColWidthSpec[0].ToLower() == "fixed") { ColumnWidth[columnCounter] = Convert.ToInt32(ColWidthSpec[1]); } else if (ColWidthSpec[0].ToLower() == "percent") { // TODO TLogging.Log("Warning: we currently don't support colwidth in percentage, control " + LayoutCtrl.controlName); } } } } } if (FRowHeights != null) { for (int rowCounter = 0; rowCounter < FRowCount; rowCounter++) { if (FRowHeights.ContainsKey(rowCounter)) { string[] RowHeightSpec = FRowHeights[rowCounter].Split(':'); if (RowHeightSpec[0].ToLower() == "fixed") { RowHeight[rowCounter] = Convert.ToInt32(RowHeightSpec[1]); } else if (RowHeightSpec[0].ToLower() == "percent") { // TODO TLogging.Log("Warning: we currently don't support rowheight in percentage, control " + LayoutCtrl.controlName); } } } } if (TLogging.DebugLevel >= 4) { StringCollection widthStringCollection = new StringCollection(); for (int columnCounter = 0; columnCounter < FColumnCount; columnCounter++) { widthStringCollection.Add(ColumnWidth[columnCounter].ToString()); } TLogging.Log("column width for " + LayoutCtrl.controlName + ": " + StringHelper.StrMerge(widthStringCollection, ',')); for (int rowCounter = 0; rowCounter < FRowCount; rowCounter++) { string rowText = string.Empty; for (int columnCounter = 0; columnCounter < FColumnCount; columnCounter++) { if (FGrid[columnCounter, rowCounter] != null) { TControlDef childctrl = FGrid[columnCounter, rowCounter]; for (int countspan = 0; countspan < childctrl.colSpanWithLabel; countspan++) { rowText += string.Format("{0}:{1} ", columnCounter + countspan, childctrl.controlName); } } } TLogging.Log(String.Format(" Row{0}: {1}", rowCounter, rowText)); } } int Width = 0; int Height = 0; int CurrentLeftPosition = Convert.ToInt32(LayoutCtrl.GetAttribute("MarginLeft", MARGIN_LEFT.ToString())); for (int columnCounter = 0; columnCounter < FColumnCount; columnCounter++) { int CurrentTopPosition; if (LayoutCtrl.IsHorizontalGridButtonPanel) { TLogging.LogAtLevel(1, "Setting CurrentTopPosition to 3 for all Controls on Control '" + LayoutCtrl.controlName + "' as it is a horizontal Grid Button Panel (used for Buttons)."); CurrentTopPosition = 3; } else { CurrentTopPosition = Convert.ToInt32(LayoutCtrl.GetAttribute("MarginTop", MARGIN_TOP.ToString())); } // only twice the margin for groupboxes if ((LayoutCtrl.controlTypePrefix == "grp") || (LayoutCtrl.controlTypePrefix == "rgr")) { CurrentTopPosition += MARGIN_TOP; } for (int rowCounter = 0; rowCounter < FRowCount; rowCounter++) { if (FGrid[columnCounter, rowCounter] != null) { TControlDef childctrl = FGrid[columnCounter, rowCounter]; if (childctrl.GetAttribute("Stretch") == "horizontally") { // use the full column width // add up spanning columns int concatenatedColumnWidth = ColumnWidth[columnCounter]; for (int colSpanCounter = 1; colSpanCounter < childctrl.colSpanWithLabel; colSpanCounter++) { concatenatedColumnWidth += ColumnWidth[columnCounter + colSpanCounter]; } if (concatenatedColumnWidth > 0) { TControlDef ParentControl = childctrl.FCodeStorage.GetControl(childctrl.parentName); System.Windows.Forms.Padding? ParentPad = null; if (ParentControl.HasAttribute("Padding")) { string ParentPadding = ParentControl.GetAttribute("Padding"); TLogging.LogAtLevel(1, "ParentControl '" + ParentControl.controlName + "' Padding: " + ParentPadding); if (ParentPadding.IndexOf(',') == -1) { ParentPad = new Padding(Convert.ToInt32(ParentPadding)); } else { string[] Paddings = ParentPadding.Split(','); ParentPad = new Padding(Convert.ToInt32(Paddings[0]), Convert.ToInt32(Paddings[1]), Convert.ToInt32(Paddings[2]), Convert.ToInt32(Paddings[3])); } TLogging.LogAtLevel(1, "ParentControl Padding (parsed): " + ParentPad.ToString()); } writer.SetControlProperty(childctrl, "Size", String.Format("new System.Drawing.Size({0}, {1})", concatenatedColumnWidth - (ParentPad.HasValue ? ParentPad.Value.Right : 0), childctrl.Height)); } } int ControlTopPosition = CurrentTopPosition; int ControlLeftPosition = CurrentLeftPosition; TLogging.LogAtLevel(1, "WriteTableLayout for Control '" + childctrl.controlName + "'"); // add margin or padding string padding = writer.GetControlProperty(childctrl.controlName, "Padding"); if (padding.Length > 0) { string[] values = padding.Substring(padding.IndexOf("(") + 1).Replace(")", "").Split(new char[] { ',' }); ControlLeftPosition += Convert.ToInt32(values[0]); ControlTopPosition += Convert.ToInt32(values[1]); TLogging.LogAtLevel(1, "Removing Padding Property from Control '" + childctrl.controlName + "'!"); writer.ClearControlProperty(childctrl.controlName, "Padding"); } string margin = writer.GetControlProperty(childctrl.controlName, "Margin"); if (margin.Length > 0) { string[] values = margin.Substring(margin.IndexOf("(") + 1).Replace(")", "").Split(new char[] { ',' }); ControlLeftPosition += Convert.ToInt32(values[0]); ControlTopPosition += Convert.ToInt32(values[1]); writer.ClearControlProperty(childctrl.controlName, "Margin"); } if ((childctrl.IsOnHorizontalGridButtonPanel) && (columnCounter != 0) && !((childctrl.HasAttribute("StartNewButtonGroup")) && (childctrl.GetAttribute("StartNewButtonGroup").ToLower() == "true"))) { TLogging.LogAtLevel(1, "Adjusted ControlLeftPosition for Control '" + childctrl.controlName + "' as it is on a horizontal Grid Button Panel."); ControlLeftPosition -= 8; } writer.SetControlProperty(childctrl.controlName, "Location", String.Format("new System.Drawing.Point({0},{1})", ControlLeftPosition.ToString(), ControlTopPosition.ToString()), false); writer.CallControlFunction(LayoutCtrl.controlName, "Controls.Add(this." + childctrl.controlName + ")"); if (FTabOrder == "Horizontal") { writer.SetControlProperty(childctrl.controlName, "TabIndex", FCurrentTabIndex.ToString(), false); FCurrentTabIndex += 10; } } CurrentTopPosition += RowHeight[rowCounter]; CurrentTopPosition += Convert.ToInt32(LayoutCtrl.GetAttribute("VerticalSpace", VERTICAL_SPACE.ToString())); if (CurrentTopPosition > Height) { Height = CurrentTopPosition; } } CurrentLeftPosition += ColumnWidth[columnCounter]; CurrentLeftPosition += Convert.ToInt32(LayoutCtrl.GetAttribute("HorizontalSpace", HORIZONTAL_SPACE.ToString())); if (CurrentLeftPosition > Width) { Width = CurrentLeftPosition; } } Height += Convert.ToInt32(LayoutCtrl.GetAttribute("MarginBottom", MARGIN_BOTTOM.ToString())) - Convert.ToInt32(LayoutCtrl.GetAttribute("VerticalSpace", VERTICAL_SPACE.ToString())); if (!LayoutCtrl.HasAttribute("Width")) { LayoutCtrl.SetAttribute("Width", Width.ToString()); } else { Width = Convert.ToInt32(LayoutCtrl.GetAttribute("Width")); } if (!LayoutCtrl.HasAttribute("Height")) { LayoutCtrl.SetAttribute("Height", Height.ToString()); } else { Height = Convert.ToInt32(LayoutCtrl.GetAttribute("Height")); } writer.SetControlProperty(LayoutCtrl, "Location", String.Format("new System.Drawing.Point({0}, {1})", MARGIN_LEFT, MARGIN_TOP)); writer.SetControlProperty(LayoutCtrl, "Size", String.Format("new System.Drawing.Size({0}, {1})", Width, Height)); // by default, the TabOrder is by column, Vertical if (FTabOrder != "Horizontal") { for (int rowCounter = 0; rowCounter < FRowCount; rowCounter++) { for (int columnCounter = 0; columnCounter < FColumnCount; columnCounter++) { if (FGrid[columnCounter, rowCounter] != null) { TControlDef childctrl = FGrid[columnCounter, rowCounter]; writer.SetControlProperty(childctrl.controlName, "TabIndex", FCurrentTabIndex.ToString(), false); FCurrentTabIndex += 10; } } } } }
/// <summary>write the code for the designer file where the properties of the control are written</summary> public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef container) { container.SetAttribute("Dock", FDocking); base.SetControlProperties(writer, container); // todo: location? // todo: event handler /* * this.menuStrip1.Dock = System.Windows.Forms.DockStyle.None; * this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { * this.toolStripMenuItem1}); * this.menuStrip1.Location = new System.Drawing.Point(0, 0); * this.menuStrip1.Name = "menuStrip1"; * this.menuStrip1.Size = new System.Drawing.Size(138, 24); * this.menuStrip1.TabIndex = 1; * this.menuStrip1.Text = "menuStrip1"; * this.menuStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.MenuStrip1ItemClicked); */ return writer.FTemplate; }
/// <summary>add GeneratedReadSetControls, and all dependent controls</summary> public override void ApplyDerivedFunctionality(TFormWriter writer, TControlDef control) { string paramName = ReportControls.GetParameterName(control.xmlNode); if (paramName == null) { return; } StringCollection Controls = TYml2Xml.GetElements(TXMLParser.GetChild(control.xmlNode, "Controls")); foreach (string controlName in Controls) { TControlDef rbtCtrl = writer.CodeStorage.GetControl(controlName); string rbtValue = rbtCtrl.Label; rbtValue = StringHelper.UpperCamelCase(rbtValue.Replace("'", "").Replace(" ", "_"), false, false); if (rbtCtrl.HasAttribute("ParameterValue")) { rbtValue = rbtCtrl.GetAttribute("ParameterValue"); } string rbtName = "rbt" + controlName.Substring(3); if (controlName.StartsWith("layoutPanel")) { // the table layouts of sub controls for each radio button need to be skipped continue; } ProcessTemplate RadioButtonReadControlsSnippet = writer.Template.GetSnippet("RADIOBUTTONREADCONTROLS"); RadioButtonReadControlsSnippet.SetCodelet("RBTNAME", rbtName); RadioButtonReadControlsSnippet.SetCodelet("PARAMNAME", paramName); RadioButtonReadControlsSnippet.SetCodelet("RBTVALUE", rbtValue); RadioButtonReadControlsSnippet.SetCodelet("READCONTROLS", ""); XmlNode childControls = TXMLParser.GetChild(rbtCtrl.xmlNode, "Controls"); // only assign variables that make sense if (childControls != null) { StringCollection childControlNames = TYml2Xml.GetElements(childControls); foreach (string childName in childControlNames) { if (childName.StartsWith("layoutPanel")) { continue; } TControlDef childCtrl = writer.CodeStorage.GetControl(childName); IControlGenerator generator = writer.FindControlGenerator(childCtrl); // make sure we ignore Button etc if (generator.GetType().ToString().EndsWith("ReportGenerator")) { childCtrl.SetAttribute("DependsOnRadioButton", ""); ReportControls.GenerateReadSetControls(writer, childCtrl.xmlNode, RadioButtonReadControlsSnippet, generator.TemplateSnippetName); childCtrl.SetAttribute("DependsOnRadioButton", "true"); } } } writer.Template.InsertSnippet("READCONTROLS", RadioButtonReadControlsSnippet); ProcessTemplate RadioButtonSetControlsSnippet = writer.Template.GetSnippet("RADIOBUTTONSETCONTROLS"); RadioButtonSetControlsSnippet.SetCodelet("RBTNAME", rbtName); RadioButtonSetControlsSnippet.SetCodelet("PARAMNAME", paramName); RadioButtonSetControlsSnippet.SetCodelet("RBTVALUE", rbtValue); // only assign variables that make sense if (childControls != null) { StringCollection childControlNames = TYml2Xml.GetElements(childControls); foreach (string childName in childControlNames) { if (childName.StartsWith("layoutPanel")) { continue; } TControlDef childCtrl = writer.CodeStorage.GetControl(childName); IControlGenerator generator = writer.FindControlGenerator(childCtrl); // make sure we ignore Button etc if (generator.GetType().ToString().EndsWith("ReportGenerator")) { childCtrl.SetAttribute("DependsOnRadioButton", ""); ReportControls.GenerateReadSetControls(writer, childCtrl.xmlNode, RadioButtonSetControlsSnippet, generator.TemplateSnippetName); childCtrl.SetAttribute("DependsOnRadioButton", "true"); } } } writer.Template.InsertSnippet("SETCONTROLS", RadioButtonSetControlsSnippet); } }
/// <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) { Int32 buttonWidth = 40; Int32 textBoxWidth = 80; // seems to be hardcoded in csharp\ICT\Petra\Client\CommonControls\Gui\txtAutoPopulatedButtonLabel.Designer.cs Int32 controlWidth = 390; base.SetControlProperties(writer, ctrl); if ((ctrl.HasAttribute("ShowLabel") && (ctrl.GetAttribute("ShowLabel").ToLower() == "false"))) { writer.SetControlProperty(ctrl, "ShowLabel", "false"); controlWidth = 120; } // Note: the control defaults to 'ShowLabel' true, so this doesn't need to be set to 'true' in code. writer.SetControlProperty(ctrl, "ASpecialSetting", "true"); writer.SetControlProperty(ctrl, "ButtonTextAlign", "System.Drawing.ContentAlignment.MiddleCenter"); writer.SetControlProperty(ctrl, "ListTable", "TtxtAutoPopulatedButtonLabel.TListTableEnum." + FButtonLabelType); writer.SetControlProperty(ctrl, "PartnerClass", "\"" + ctrl.GetAttribute("PartnerClass") + "\""); writer.SetControlProperty(ctrl, "MaxLength", "32767"); writer.SetControlProperty(ctrl, "Tag", "\"CustomDisableAlthoughInvisible\""); writer.SetControlProperty(ctrl, "TextBoxWidth", textBoxWidth.ToString()); if (!(ctrl.HasAttribute("ReadOnly") && (ctrl.GetAttribute("ReadOnly").ToLower() == "true"))) { writer.SetControlProperty(ctrl, "ButtonWidth", buttonWidth.ToString()); writer.SetControlProperty(ctrl, "ReadOnly", "false"); writer.SetControlProperty(ctrl, "Font", "new System.Drawing.Font(\"Verdana\", 8.25f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (byte)0)"); writer.SetControlProperty(ctrl, "ButtonText", "\"Find\""); } else { writer.SetControlProperty(ctrl, "ButtonWidth", "0"); writer.SetControlProperty(ctrl, "BorderStyle", "System.Windows.Forms.BorderStyle.None"); writer.SetControlProperty(ctrl, "Padding", "new System.Windows.Forms.Padding(0, 4, 0, 0)"); } if (!ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", controlWidth.ToString()); } if (TYml2Xml.HasAttribute(ctrl.xmlNode, "DefaultValue")) { writer.SetControlProperty(ctrl, "Text", "\"" + TYml2Xml.GetAttribute(ctrl.xmlNode, "DefaultValue") + "\""); } return writer.FTemplate; }
/// <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) { if (ctrl.HasAttribute("Width") && ctrl.HasAttribute("Height")) { FAutoSize = false; } else if (ctrl.HasAttribute("Height")) { // assume width of parent control ctrl.SetAttribute("Width", (FCodeStorage.FWidth - 10).ToString()); FAutoSize = false; } else if (ctrl.HasAttribute("Width") && (ctrl.GetAttribute("Dock") != "Left") && (ctrl.GetAttribute("Dock") != "Right")) { throw new Exception( "Control " + ctrl.controlName + " must have both Width and Height attributes, or just Height, but not Width alone"); } base.CreateControlsAddStatements = false; base.SetControlProperties(writer, ctrl); if ((base.FPrefix == "grp") || (base.FPrefix == "rgr") || (base.FPrefix == "tpg")) { FGenerateLabel = true; if (GenerateLabel(ctrl)) { writer.SetControlProperty(ctrl, "Text", "\"" + ctrl.Label + "\""); } FGenerateLabel = false; } return writer.FTemplate; }
/// <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) { // Support NoLabel=true FGenerateLabel = true; if (GenerateLabel(ctrl)) { writer.SetControlProperty(ctrl, "Text", "\"" + ctrl.Label + "\""); ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(ctrl.Label) + 30).ToString()); } else { ctrl.SetAttribute("Width", "15"); } base.SetControlProperties(writer, ctrl); FGenerateLabel = false; if (TYml2Xml.HasAttribute(ctrl.xmlNode, "RadioChecked")) { writer.SetControlProperty(ctrl, "Checked", TYml2Xml.GetAttribute(ctrl.xmlNode, "RadioChecked")); } return writer.FTemplate; }
/// <summary>write the code for the designer file where the properties of the control are written</summary> public virtual ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl) { bool AutomDataValidation; string ReasonForAutomValidation; bool IsDetailNotMaster; writer.SetControlProperty(ctrl, "Name", "\"" + ctrl.controlName + "\""); if (FLocation && !ctrl.HasAttribute("Dock")) { writer.SetControlProperty(ctrl, "Location", "new System.Drawing.Point(2,2)"); } #region Aligning and stretching if (ctrl.HasAttribute("Align") && !(ctrl.HasAttribute("Stretch"))) { if ((ctrl.GetAttribute("Align").ToLower() == "right") || (ctrl.GetAttribute("Align").ToLower() == "top-right")) { writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)))"); } else if (ctrl.GetAttribute("Align").ToLower() == "middle-right") { writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Right))"); } else if (ctrl.GetAttribute("Align").ToLower() == "bottom-right") { writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)))"); } else if ((ctrl.GetAttribute("Align").ToLower() == "center") || (ctrl.GetAttribute("Align").ToLower() == "top-center")) { writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top))"); } else if (ctrl.GetAttribute("Align").ToLower() == "middle-center") { writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.None))"); } else if (ctrl.GetAttribute("Align").ToLower() == "bottom-center") { writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom))"); } else if ((ctrl.GetAttribute("Align").ToLower() == "bottom") || (ctrl.GetAttribute("Align").ToLower() == "bottom-left")) { writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Bottom)))"); } else if ((ctrl.GetAttribute("Align").ToLower() == "middle") || (ctrl.GetAttribute("Align").ToLower() == "middle-left")) { writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Left))"); } else if ((ctrl.GetAttribute("Align").ToLower() == "left") || (ctrl.GetAttribute("Align").ToLower() == "top") || (ctrl.GetAttribute("Align").ToLower() == "top-left")) { // do nothing (here just to avoid throwing the following Exception) Console.WriteLine( "HINT: Attribute 'Align' with value 'left', 'top' or 'top-left' does not affect the layout since these create the default alignment. Control: '" + ctrl.controlName + "'."); } else { throw new Exception("Invalid value for Attribute 'Align' of Control '" + ctrl.controlName + "': '" + ctrl.GetAttribute( "Align") + "'. Supported values are: Simple: left, right, center; top, middle, bottom; Combined: top-left, middle-left, bottom-left, top-center, middle-center, bottom-center, top-right, middle-right, bottom-right."); } } if (ctrl.HasAttribute("Stretch")) { if (ctrl.GetAttribute("Stretch").ToLower() == "horizontally") { if ((!ctrl.HasAttribute("Align")) || (ctrl.HasAttribute("Align") && (ctrl.GetAttribute("Align").ToLower() == "top"))) { // Horizontally stretched, top aligned (=default) writer.SetControlProperty( ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)))"); } else { if (ctrl.GetAttribute("Align").ToLower() == "bottom") { // Horizontally stretched, bottom aligned writer.SetControlProperty( ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)))"); } else if (ctrl.GetAttribute("Align").ToLower() == "middle") { // Horizontally stretched, vertically centered writer.SetControlProperty( ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)))"); } else { throw new Exception("Invalid value '" + ctrl.GetAttribute( "Align") + "' for Attribute 'Align' of Control '" + ctrl.controlName + "' whose Attribute 'Stretch' is set to '" + ctrl.GetAttribute("Stretch") + "'. Supported values are: top, middle, bottom."); } } } else if (ctrl.GetAttribute("Stretch").ToLower() == "vertically") { if ((!ctrl.HasAttribute("Align")) || (ctrl.HasAttribute("Align") && (ctrl.GetAttribute("Align").ToLower() == "left"))) { // Vertically stretched, left aligned (=default) writer.SetControlProperty( ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Bottom)))"); } else { if (ctrl.GetAttribute("Align").ToLower() == "right") { // Vertically stretched, right aligned writer.SetControlProperty( ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right) | System.Windows.Forms.AnchorStyles.Bottom)))"); } else if (ctrl.GetAttribute("Align").ToLower() == "center") { // Vertically stretched, horizontally centered writer.SetControlProperty( ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)))"); } else { throw new Exception("Invalid value '" + ctrl.GetAttribute( "Align") + "' for Attribute 'Align' of Control '" + ctrl.controlName + "' whose Attribute 'Stretch' is set to '" + ctrl.GetAttribute("Stretch") + "'. Supported values are: left, center, right."); } } } else if (ctrl.GetAttribute("Stretch").ToLower() == "fully") { // Fully stretched writer.SetControlProperty( ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)(((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right) | System.Windows.Forms.AnchorStyles.Bottom))))"); if (ctrl.HasAttribute("Align")) { Console.WriteLine( "WARNING for Control '" + ctrl.controlName + "': Attribute 'Align' gets ignored when Attribute 'Stretch' with value 'fully' is used."); } } else if (ctrl.GetAttribute("Stretch").ToLower() == "none") { // do nothing (here just to avoid throwing the following Exception) Console.WriteLine( "HINT: Attribute 'Stretch' with value 'none' does not affect the layout since this is the default. Control: '" + ctrl.controlName + "'."); } else { throw new Exception("Invalid value for Attribute 'Stretch' of Control '" + ctrl.controlName + "': '" + ctrl.GetAttribute("Stretch") + "'. Supported values are: horizontally, vertically, fully, none."); } } #endregion if (ctrl.HasAttribute("Dock")) { writer.SetControlProperty(ctrl, "Dock"); } if (ctrl.HasAttribute("Visible") && (ctrl.GetAttribute("Visible").ToLower() == "false")) { writer.SetControlProperty(ctrl, "Visible", "false"); } if (ctrl.HasAttribute("Enabled") && (ctrl.GetAttribute("Enabled").ToLower() == "false")) { writer.SetControlProperty(ctrl, "Enabled", "false"); } else if ((ctrl.GetAction() != null) && (TYml2Xml.GetAttribute(ctrl.GetAction().actionNode, "InitiallyEnabled").ToLower() == "false")) { string ActionEnabling = ctrl.controlName + ".Enabled = false;" + Environment.NewLine; writer.Template.AddToCodelet("INITACTIONSTATE", ActionEnabling); } if (ctrl.HasAttribute("TabStop") && (ctrl.GetAttribute("TabStop").ToLower() == "false")) { writer.SetControlProperty(ctrl, "TabStop", "false"); } if (ctrl.HasAttribute("TabIndex")) { writer.SetControlProperty(ctrl, "TabIndex", ctrl.GetAttribute("TabIndex")); } if (ctrl.HasAttribute("BorderStyle")) { writer.SetControlProperty(ctrl, "BorderStyle", "System.Windows.Forms.BorderStyle." + ctrl.GetAttribute("BorderStyle")); if (ctrl.GetAttribute("BorderStyle").ToLower() == "none") { writer.SetControlProperty(ctrl, "Margin", "new System.Windows.Forms.Padding(0, 5, 0, 0)"); } } if (ctrl.HasAttribute("Padding")) { writer.SetControlProperty(ctrl, "Padding", "new System.Windows.Forms.Padding(" + ctrl.GetAttribute("Padding") + ")"); } if (ctrl.HasAttribute("Margin")) { string margin = ctrl.GetAttribute("Margin"); if (margin != "0") { writer.SetControlProperty(ctrl, "Margin", "new System.Windows.Forms.Padding(" + margin + ")"); } } if (ctrl.HasAttribute("BackColor")) { writer.SetControlProperty(ctrl, "BackColor", ctrl.GetAttribute("BackColor")); } if (ctrl.HasAttribute("AutoScroll")) { writer.SetControlProperty(ctrl, "AutoScroll", ctrl.GetAttribute("AutoScroll")); } // needed so that ctrl.Height and ctrl.Width return correct values ctrl.SetAttribute("DefaultWidth", FDefaultWidth.ToString()); ctrl.SetAttribute("DefaultHeight", FDefaultHeight.ToString()); if (ctrl.HasAttribute("Width") || ctrl.HasAttribute("Height")) { if (!ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", FDefaultWidth.ToString()); } if (!ctrl.HasAttribute("Height")) { ctrl.SetAttribute("Height", FDefaultHeight.ToString()); } if (ctrl.HasAttribute("Width") && ctrl.HasAttribute("Height")) { writer.SetControlProperty(ctrl, "Size", "new System.Drawing.Size(" + ctrl.GetAttribute("Width").ToString() + ", " + ctrl.GetAttribute("Height").ToString() + ")"); } } else if (ctrl.GetAttribute("Dock").ToLower() == "fill") { // no size information for Dock Fill } else { writer.SetControlProperty(ctrl, "Size", "new System.Drawing.Size(" + FDefaultWidth.ToString() + ", " + FDefaultHeight.ToString() + ")"); } if (ctrl.HasAttribute("SuppressChangeDetection") && (ctrl.GetAttribute("SuppressChangeDetection").ToLower() == "true")) { writer.SetControlProperty(ctrl, "Tag", "\"SuppressChangeDetection\""); } if (ctrl.GetAction() != null) { string ActionToPerform = ctrl.GetAction().actionName; // deal with enabling and disabling of action, affecting the menu item if (!writer.Template.FCodelets.Keys.Contains("ENABLEDEPENDINGACTIONS_" + ActionToPerform)) { string ActionEnabling = ""; ActionEnabling += "if (e.ActionName == \"" + ActionToPerform + "\")" + Environment.NewLine; ActionEnabling += "{" + Environment.NewLine; ActionEnabling += " {#ENABLEDEPENDINGACTIONS_" + ActionToPerform + "}" + Environment.NewLine; ActionEnabling += "}" + Environment.NewLine; writer.Template.AddToCodelet("ACTIONENABLING", ActionEnabling); } AddToActionEnabledEvent(writer, ActionToPerform, ctrl.controlName); // deal with action handler if (((ActionToPerform == "actEditFilter") || (ActionToPerform == "actEditFindNext") || (ActionToPerform == "actEditFindPrevious") || (ActionToPerform == "actEditFind")) && !writer.FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind")) { // Do nothing unless there is a manual code handler (on screens with user controls) if (writer.FCodeStorage.ManualFileExistsAndContains("void MniFilterFind_Click(")) { AssignEventHandlerToControl(writer, ctrl, "Click", "MniFilterFind_Click"); } else if (ActionToPerform == "actEditFind") { TLogging.Log("No implementation of actEditFind on this screen"); } } else { AssignEventHandlerToControl(writer, ctrl, "Click", ActionToPerform); } TActionHandler ActionHandler = writer.CodeStorage.FActionList[ActionToPerform]; SetControlActionProperties(writer, ctrl, ActionHandler); string strMniFilterFindClick = "void MniFilterFind_Click("; if ((ActionToPerform == "actEditFind") && (ctrl.controlName == "mniEditFind") && (writer.FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind") || writer.FCodeStorage.ManualFileExistsAndContains(strMniFilterFindClick))) { writer.SetControlProperty("mniEditFind", "ShortcutKeys", "Keys.F | Keys.Control", false); } if ((ActionToPerform == "actEditFindNext") && (ctrl.controlName == "mniEditFindNext") && (writer.FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind") || writer.FCodeStorage.ManualFileExistsAndContains(strMniFilterFindClick))) { writer.SetControlProperty("mniEditFindNext", "ShortcutKeys", "Keys.F3", false); } if ((ActionToPerform == "actEditFindPrevious") && (ctrl.controlName == "mniEditFindPrevious") && (writer.FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind") || writer.FCodeStorage.ManualFileExistsAndContains(strMniFilterFindClick))) { writer.SetControlProperty("mniEditFindPrevious", "ShortcutKeys", "Keys.F3 | Keys.Shift", false); } if ((ActionToPerform == "actEditTop") && (ctrl.controlName == "mniEditTop")) { writer.SetControlProperty("mniEditTop", "ShortcutKeys", "Keys.Home | Keys.Control", false); } if ((ActionToPerform == "actEditPrevious") && (ctrl.controlName == "mniEditPrevious")) { writer.SetControlProperty("mniEditPrevious", "ShortcutKeys", "Keys.Up | Keys.Control", false); } if ((ActionToPerform == "actEditNext") && (ctrl.controlName == "mniEditNext")) { writer.SetControlProperty("mniEditNext", "ShortcutKeys", "Keys.Down | Keys.Control", false); } if ((ActionToPerform == "actEditBottom") && (ctrl.controlName == "mniEditBottom")) { writer.SetControlProperty("mniEditBottom", "ShortcutKeys", "Keys.End | Keys.Control", false); } if ((ActionToPerform == "actEditFocusGrid") && (ctrl.controlName == "mniEditFocusGrid")) { writer.SetControlProperty("mniEditFocusGrid", "ShortcutKeys", "Keys.G | Keys.Control", false); } if ((ActionToPerform == "actEditFilter") && (ctrl.controlName == "mniEditFilter") && (writer.FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind") || writer.FCodeStorage.ManualFileExistsAndContains(strMniFilterFindClick))) { writer.SetControlProperty("mniEditFilter", "ShortcutKeys", "Keys.R | Keys.Control", false); } if ((ActionToPerform == "actSave") && (ctrl.controlName == "mniFileSave")) { ProcessTemplate snipCtrlS = writer.FTemplate.GetSnippet("PROCESSCMDKEYCTRLS"); writer.FTemplate.InsertSnippet("PROCESSCMDKEY", snipCtrlS); writer.SetControlProperty("mniFileSave", "ShortcutKeys", "Keys.S | Keys.Control", false); } if ((ActionToPerform == "actPrint") && (ctrl.controlName == "mniFilePrint")) { writer.SetControlProperty("mniFilePrint", "ShortcutKeys", "Keys.P | Keys.Control", false); } if (FCodeStorage.ManualFileExistsAndContains(" " + ActionHandler.actionName.Substring(3) + "(Form AParentForm)")) { writer.SetEventHandlerFunction(ActionHandler.actionName.Substring(3), "", ActionHandler.actionName.Substring( 3) + "(this);"); } } else if (ctrl.HasAttribute("ActionClick")) { if (ctrl.GetAttribute("ActionClick").EndsWith("FilterFind_Click")) { // MniFilterFind_Click is part of the base template for many forms. // We only create an action handler if the screen has a pnlFilterAndFind if (writer.FCodeStorage.FControlList.ContainsKey("pnlFilterAndFind")) { AssignEventHandlerToControl(writer, ctrl, "Click", ctrl.GetAttribute("ActionClick")); } } else { // The control is not mniEditFilter or mniEditFind, so just write the resource file item // The manual code file will have the event handler itself AssignEventHandlerToControl(writer, ctrl, "Click", ctrl.GetAttribute("ActionClick")); } } else if (ctrl.HasAttribute("ActionDoubleClick")) { AssignEventHandlerToControl(writer, ctrl, "DoubleClick", ctrl.GetAttribute("ActionDoubleClick")); } else if (ctrl.HasAttribute("ActionOpenScreen")) { AssignEventHandlerToControl(writer, ctrl, "Click", "OpenScreen" + ctrl.controlName.Substring(ctrl.controlTypePrefix.Length)); string ActionHandler = "/// auto generated" + Environment.NewLine + "protected void OpenScreen" + ctrl.controlName.Substring(ctrl.controlTypePrefix.Length) + "(object sender, EventArgs e)" + Environment.NewLine + "{" + Environment.NewLine; string ActionOpenScreen = ctrl.GetAttribute("ActionOpenScreen"); ActionHandler += " " + ActionOpenScreen + " frm = new " + ActionOpenScreen + "(this);" + Environment.NewLine; if (ActionOpenScreen.Contains(".")) { string namespaceOfScreen = ActionOpenScreen.Substring(0, ActionOpenScreen.LastIndexOf(".")); writer.Template.AddToCodelet("USINGNAMESPACES", "using " + namespaceOfScreen + ";" + Environment.NewLine, false); } // Does PropertyForSubScreens fit a property in the new screen? eg LedgerNumber if (FCodeStorage.HasAttribute("PropertyForSubScreens")) { string propertyName = FCodeStorage.GetAttribute("PropertyForSubScreens"); if (FCodeStorage.ImplementationContains(ctrl.GetAttribute("ActionOpenScreen"), " " + propertyName + Environment.NewLine)) { ActionHandler += " frm." + propertyName + " = F" + propertyName + ";" + Environment.NewLine; } } /* for (string propertyName in FCodeStorage.GetFittingProperties(ctrl.GetAttribute("ActionOpenScreen"))) * { * ActionHandler += " frm." + propertyName + " = F" + propertyName + ";" + Environment.NewLine; * } */ ActionHandler += " frm.Show();" + Environment.NewLine; ActionHandler += "}" + Environment.NewLine + Environment.NewLine; FCodeStorage.FActionHandlers += ActionHandler; } if (ctrl.HasAttribute("Enabled")) { AddToActionEnabledEvent(writer, ctrl.GetAttribute("Enabled"), ctrl.controlName); } if (ctrl.HasAttribute("OnChange")) { AssignEventHandlerToControl(writer, ctrl, GetEventNameForChangeEvent(), GetEventHandlerTypeForChangeEvent(), ctrl.GetAttribute("OnChange")); } if (ctrl.HasAttribute("OnEnter")) { AssignEventHandlerToControl(writer, ctrl, "Enter", "System.EventHandler", ctrl.GetAttribute("OnEnter")); } if (ctrl.HasAttribute("OnLeave")) { AssignEventHandlerToControl(writer, ctrl, "Leave", "System.EventHandler", ctrl.GetAttribute("OnLeave")); } if (ctrl.HasAttribute("Tooltip")) { writer.Template.AddToCodelet("INITUSERCONTROLS", "FPetraUtilsObject.SetStatusBarText(" + ctrl.controlName + ", Catalog.GetString(\"" + ctrl.GetAttribute("Tooltip") + "\"));" + Environment.NewLine); } else if (ctrl.controlName == "grdDetails") { writer.Template.AddToCodelet("INITUSERCONTROLS", "FPetraUtilsObject.SetStatusBarText(" + ctrl.controlName + ", Catalog.GetString(\"Use the mouse or navigation keys to select a data row to view or edit\"));" + Environment.NewLine); } else if (ctrl.controlName == "btnNew") { writer.Template.AddToCodelet("INITUSERCONTROLS", "FPetraUtilsObject.SetStatusBarText(" + ctrl.controlName + ", Catalog.GetString(\"Click to create a new record\"));" + Environment.NewLine); } else if (ctrl.controlName == "btnDelete") { writer.Template.AddToCodelet("INITUSERCONTROLS", "FPetraUtilsObject.SetStatusBarText(" + ctrl.controlName + ", Catalog.GetString(\"Click to delete the highlighted record(s)\"));" + Environment.NewLine); } else if (ctrl.controlName.StartsWith("spt")) { writer.Template.AddToCodelet( "INITUSERCONTROLS", "FPetraUtilsObject.SetStatusBarText(" + ctrl.controlName + ", Catalog.GetString(\"Use the arrow keys to change the Splitter position and change the relative proportions of the panels\"));" + Environment.NewLine); } //TODO: CT // if (ctrl.HasAttribute("DefaultValue")) // { // writer.Template.AddToCodelet("DEFAULTOVERRIDE", UndoValue(ctrl, ; // } //Console.WriteLine("ctrl.controlTypePrefix: " + ctrl.controlName + ": " + ctrl.controlTypePrefix); if (ctrl.HasAttribute("PartnerShortNameLookup")) { LinkControlPartnerShortNameLookup(writer, ctrl); } else if (ctrl.HasAttribute("DataField")) { string dataField = ctrl.GetAttribute("DataField"); TTableField field = TDataBinding.GetTableField(ctrl, dataField, out IsDetailNotMaster, true); LinkControlDataField(writer, ctrl, field, IsDetailNotMaster); DataFieldUndoCapability(writer, ctrl, field, IsDetailNotMaster); } else if (writer.CodeStorage.HasAttribute("MasterTable") || writer.CodeStorage.HasAttribute("DetailTable")) { //if (ctrl.controlTypePrefix != "lbl" && ctrl.controlTypePrefix != "pnl" && ctrl.controlTypePrefix != "grp" && if (!((this is LabelGenerator) || (this is LinkLabelGenerator))) { TTableField field = TDataBinding.GetTableField(ctrl, ctrl.controlName.Substring( ctrl.controlTypePrefix.Length), out IsDetailNotMaster, false); if (field != null) { LinkControlDataField(writer, ctrl, field, IsDetailNotMaster); DataFieldUndoCapability(writer, ctrl, field, IsDetailNotMaster); } } } else if (ctrl.controlTypePrefix == "uco") { AddChildUserControlExtraCalls(writer, ctrl); } else if (ctrl.HasAttribute("DynamicControlType")) { writer.Template.AddToCodelet("SAVEDATA", "if(FUco" + ctrl.controlName.Substring( 3) + " != null)" + Environment.NewLine + "{" + Environment.NewLine + " FUco" + ctrl.controlName.Substring(3) + ".GetDataFromControls();" + Environment.NewLine + "}" + Environment.NewLine); writer.Template.AddToCodelet("PRIMARYKEYCONTROLSREADONLY", "if(FUco" + ctrl.controlName.Substring( 3) + " != null)" + Environment.NewLine + "{" + Environment.NewLine + " FUco" + ctrl.controlName.Substring( 3) + ".SetPrimaryKeyReadOnly(AReadOnly);" + Environment.NewLine + "}" + Environment.NewLine); } // Allow for adding of child-usercontrol extra calls *even* if the Template has got 'MasterTable' or 'DetailTable' attribute(s) [see above for those checks] if ((ctrl.controlTypePrefix == "uco") && (writer.CodeStorage.GetAttribute("DependentChildUserControl") == "true")) { AddChildUserControlExtraCalls(writer, ctrl); } // the readonly property eg of Textbox still allows tooltips and copy to clipboard, which enable=false would not allow if (TYml2Xml.HasAttribute(ctrl.xmlNode, "ReadOnly") && (TYml2Xml.GetAttribute(ctrl.xmlNode, "ReadOnly").ToLower() == "true")) { if (FHasReadOnlyProperty) { writer.SetControlProperty(ctrl, "ReadOnly", "true"); writer.SetControlProperty(ctrl, "TabStop", "false"); } else { writer.SetControlProperty(ctrl, "Enabled", "false"); } } if (GenerateDataValidationCode(writer, ctrl, out AutomDataValidation, out ReasonForAutomValidation)) { AssignEventHandlerToControl(writer, ctrl, "Validated", "ControlValidatedHandler"); } else { bool AssignControlUpdateDataHandler = false; if (ctrl.HasAttribute("DataField")) { TDataBinding.GetTableField(ctrl, ctrl.GetAttribute("DataField"), out IsDetailNotMaster, true); if (IsDetailNotMaster) { AssignControlUpdateDataHandler = true; } } else { if (writer.CodeStorage.HasAttribute("DetailTable")) { if (!((this is LabelGenerator) || (this is LinkLabelGenerator))) { if (TDataBinding.GetTableField(ctrl, ctrl.controlName.Substring( ctrl.controlTypePrefix.Length), out IsDetailNotMaster, false) != null) { if (IsDetailNotMaster) { AssignControlUpdateDataHandler = true; } } } } } if (AssignControlUpdateDataHandler) { if ((!ctrl.controlTypePrefix.StartsWith("mn")) && (!ctrl.controlTypePrefix.StartsWith("tb")) && (ctrl.controlTypePrefix != "pnl") && (ctrl.controlTypePrefix != "grp") && (ctrl.controlTypePrefix != "grd") && (ctrl.controlTypePrefix != "btn") && (ctrl.controlTypePrefix != "stb") && (ctrl.controlTypePrefix != "lbl")) { AssignEventHandlerToControl(writer, ctrl, "Validated", "ControlUpdateDataHandler"); writer.Template.SetCodelet("GENERATECONTROLUPDATEDATAHANDLER", "true"); } } } return writer.Template; }
/// <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) { if ((ctrl.HasAttribute("CheckBoxAttachedLabel")) && ((ctrl.GetAttribute("CheckBoxAttachedLabel").ToLower() == "left") || (ctrl.GetAttribute("CheckBoxAttachedLabel").ToLower() == "right"))) { base.FAutoSize = true; if (ctrl.HasAttribute("NoLabel") && (ctrl.GetAttribute("NoLabel").ToLower() == "true")) { writer.SetControlProperty(ctrl, "Text", "\"\""); } else { writer.SetControlProperty(ctrl, "Text", "\"" + ctrl.Label + "\""); if (ctrl.GetAttribute("CheckBoxAttachedLabel").ToLower() == "left") { writer.SetControlProperty(ctrl, "CheckAlign", "System.Drawing.ContentAlignment.MiddleRight"); } else { writer.SetControlProperty(ctrl, "CheckAlign", "System.Drawing.ContentAlignment.MiddleLeft"); } writer.SetControlProperty(ctrl, "Margin", "new System.Windows.Forms.Padding(3, 4, 3, 0)"); ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(ctrl.Label) + 30).ToString()); ctrl.SetAttribute("Height", "17"); } base.SetControlProperties(writer, ctrl); } else { base.FAutoSize = false; ctrl.SetAttribute("Width", 30.ToString ()); base.SetControlProperties(writer, ctrl); writer.SetControlProperty(ctrl, "Text", "\"\""); writer.SetControlProperty(ctrl, "Margin", "new System.Windows.Forms.Padding(3, 0, 3, 0)"); } return writer.FTemplate; }
/// <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) { bool OverrideImageAlign = false; bool OverrideTextAlign = false; bool NoLabel = false; TLogging.LogAtLevel(1, "ButtonGenerator.SetControlProperties for Control " + ctrl.controlName); if (!ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(ctrl.Label) + 15).ToString()); } if (ctrl.HasAttribute("NoLabel") && (ctrl.GetAttribute("NoLabel").ToLower() == "true")) { writer.SetControlProperty(ctrl, "Text", "\"\""); NoLabel = true; } else { writer.SetControlProperty(ctrl, "Size", "new System.Drawing.Size(" + ctrl.GetAttribute("Width").ToString() + ", " + ctrl.GetAttribute("Height").ToString() + ")"); writer.SetControlProperty(ctrl, "Text", "\"" + ctrl.Label + "\""); } if (ctrl.IsOnHorizontalGridButtonPanel) { TLogging.LogAtLevel(1, "Setting Height for Control '" + ctrl.controlName + "' to 23 as it is on a horizontal Grid Button Panel"); FDefaultHeight = 23; if (!ctrl.HasAttribute("ImageAlign")) { if (NoLabel) { //TLogging.LogAtLevel(1, "Setting ImageAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.BottomCenter as it is on a horizontal Grid Button Panel (no Text)"); writer.SetControlProperty(ctrl, "ImageAlign", "System.Drawing.ContentAlignment.BottomCenter"); } else { //TLogging.LogAtLevel(1, "Setting ImageAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.BottomLeft as it is on a horizontal Grid Button Panel"); writer.SetControlProperty(ctrl, "ImageAlign", "System.Drawing.ContentAlignment.BottomLeft"); // Note: In this case want the text centered on the Button, which the TextAlign Property will achieve. // However, its default value is System.Drawing.ContentAlignment.MiddleCenter which means we don't need to explicitly write this out into the Designer file... //TLogging.LogAtLevel(1, "Setting TextAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.MiddleCenter as it is on a horizontal Grid Button Panel"); // writer.SetControlProperty(ctrl, "TextAlign", "System.Drawing.ContentAlignment.MiddleCenter"); } OverrideImageAlign = true; OverrideTextAlign = true; } } else { if (!ctrl.HasAttribute("Height")) { ctrl.SetAttribute("Height", FDefaultHeight.ToString()); } } base.SetControlProperties(writer, ctrl); if (ctrl.GetAttribute("AcceptButton").ToLower() == "true") { writer.Template.AddToCodelet("INITUSERCONTROLS", "this.AcceptButton = " + ctrl.controlName + ";" + Environment.NewLine); } if (ctrl.GetAction() != null) { string img = ctrl.GetAction().actionImage; if (img.Length > 0) { ctrl.SetAttribute("Width", (Convert.ToInt32(ctrl.GetAttribute("Width")) + Convert.ToInt32(ctrl.GetAttribute("IconWidth", "15"))).ToString()); writer.SetControlProperty(ctrl, "Size", "new System.Drawing.Size(" + ctrl.GetAttribute("Width").ToString() + ", " + ctrl.GetAttribute("Height").ToString() + ")"); if (writer.GetControlProperty(ctrl.controlName, "Text") == "\"\"") { if ((!ctrl.HasAttribute("ImageAlign")) && !OverrideImageAlign) { // Note: In this case we want the Image centered on the Button, which the ImageAlign Property will achieve. // However, its default value is System.Drawing.ContentAlignment.MiddleCenter which means we don't need to explicitly write this out into the Designer file... //Console.WriteLine("Setting ImageAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.MiddleCenter as it is NOT on a horizontal Grid Button Panel (no Text)"); // writer.SetControlProperty(ctrl, "ImageAlign", "System.Drawing.ContentAlignment.MiddleCenter"); } } else { if ((!ctrl.HasAttribute("ImageAlign")) && !OverrideImageAlign) { //Console.WriteLine("Setting ImageAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.MiddleLeft as it is NOT on a horizontal Grid Button Panel"); writer.SetControlProperty(ctrl, "ImageAlign", "System.Drawing.ContentAlignment.MiddleLeft"); } } if (!OverrideTextAlign) { //Console.WriteLine("Setting TextAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.MiddleRight as it is NOT on a horizontal Grid Button Panel"); writer.SetControlProperty(ctrl, "TextAlign", "System.Drawing.ContentAlignment.MiddleRight"); } } } return(writer.FTemplate); }
/// <summary> /// get the radio buttons /// </summary> public override void ProcessChildren(TFormWriter writer, TControlDef ctrl) { StringCollection optionalValues = TYml2Xml.GetElements(TXMLParser.GetChild(ctrl.xmlNode, "OptionalValues")); string DefaultValue; if ((TYml2Xml.HasAttribute(ctrl.xmlNode, "NoDefaultValue") && ((TYml2Xml.GetAttribute(ctrl.xmlNode, "NoDefaultValue")) == "true"))) { DefaultValue = String.Empty; FNoDefaultValue = true; } else { DefaultValue = optionalValues[0]; } if (TYml2Xml.HasAttribute(ctrl.xmlNode, "DefaultValue")) { DefaultValue = TYml2Xml.GetAttribute(ctrl.xmlNode, "DefaultValue"); } else { // DefaultValue with = sign before control name for (int counter = 0; counter < optionalValues.Count; counter++) { if (optionalValues[counter].StartsWith("=")) { optionalValues[counter] = optionalValues[counter].Substring(1).Trim(); DefaultValue = optionalValues[counter]; } } } StringCollection optionalValuesLabels = TYml2Xml.GetElements(TYml2Xml.GetChild(ctrl.xmlNode, "LabelsForOptionalValues")); StringCollection optionalValuesConstants = TYml2Xml.GetElements(TYml2Xml.GetChild(ctrl.xmlNode, "OptionalValuesConstants")); // add the radiobuttons on the fly int count = 0; foreach (string optionalValue in optionalValues) { string radioButtonName = "rbt" + StringHelper.UpperCamelCase(optionalValue.Replace("'", "").Replace(" ", "_").Replace("&", ""), false, false); TControlDef newCtrl = writer.CodeStorage.FindOrCreateControl(radioButtonName, ctrl.controlName); newCtrl.Label = optionalValuesLabels.Count > 0 ? optionalValuesLabels[count] : optionalValue; if (StringHelper.IsSame(DefaultValue, optionalValue)) { newCtrl.SetAttribute("RadioChecked", "true"); FDefaultValueRadioButton = radioButtonName; } if (TYml2Xml.HasAttribute(ctrl.xmlNode, "SuppressChangeDetection")) { newCtrl.SetAttribute("SuppressChangeDetection", TYml2Xml.GetAttribute(ctrl.xmlNode, "SuppressChangeDetection")); } if (TYml2Xml.HasAttribute(ctrl.xmlNode, "OnChange")) { newCtrl.SetAttribute("OnChange", TYml2Xml.GetAttribute(ctrl.xmlNode, "OnChange")); } if (optionalValuesConstants.Count > count) { newCtrl.SetAttribute("ConstantValue", optionalValuesConstants[count]); } ctrl.Children.Add(newCtrl); count++; } base.ProcessChildren(writer, ctrl); }
/// <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) { if (!ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", FDefaultWidth.ToString()); } base.SetControlProperties(writer, ctrl); writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".CancelEditingWithEscapeKey = false;" + Environment.NewLine); if (TYml2Xml.HasAttribute(ctrl.xmlNode, "SelectedRowActivates")) { // TODO: this function needs to be called by the manual code at the moment when eg a search finishes // TODO: call "Activate" + TYml2Xml.GetAttribute(ctrl.xmlNode, "SelectedRowActivates") } StringCollection Columns = TYml2Xml.GetElements(ctrl.xmlNode, "Columns"); if (Columns.Count > 0) { writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".Columns.Clear();" + Environment.NewLine); //This needs to come immediately after the Columns.Clear() and before the creation of the columns if (ctrl.HasAttribute("SortableHeaders")) { string trueOrFalse = ctrl.GetAttribute("SortableHeaders"); writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".SortableHeaders = " + trueOrFalse + ";" + Environment.NewLine); } foreach (string ColumnFieldName in Columns) { bool IsDetailNotMaster; TTableField field = null; string TableFieldTable; string ColumnFieldNameResolved; // customfield, eg. UC_GLTransactions, ATransaction.DateEntered and ATransaction.AnalysisAttributes // there needs to be a list of CustomColumns XmlNode CustomColumnsNode = TYml2Xml.GetChild(ctrl.xmlNode, "CustomColumns"); XmlNode CustomColumnNode = null; if (CustomColumnsNode != null) { CustomColumnNode = TYml2Xml.GetChild(CustomColumnsNode, ColumnFieldName); } if ((ctrl.controlName == "grdDetails") && FCodeStorage.HasAttribute("DetailTable")) { TableFieldTable = FCodeStorage.GetAttribute("DetailTable"); if (ColumnFieldName.StartsWith("Detail") && !IsLegitimateDetailFieldName(TableFieldTable, ColumnFieldName)) { ColumnFieldNameResolved = ColumnFieldName.Substring(6); // Drop 'Details' out of 'Details...' } else { ColumnFieldNameResolved = ColumnFieldName; } } else { TableFieldTable = ctrl.GetAttribute("TableName"); ColumnFieldNameResolved = ColumnFieldName; } if (CustomColumnNode != null) { // if grd has no TableName property if ((TableFieldTable == "") && ColumnFieldNameResolved.Contains(".")) { int Period = ColumnFieldNameResolved.IndexOf("."); string TableName = ColumnFieldNameResolved.Remove(Period); string ColumnName = ColumnFieldNameResolved.Remove(0, TableName.Length + 1); AddColumnToGrid(writer, ctrl.controlName, TYml2Xml.GetAttribute(CustomColumnNode, "Type"), TYml2Xml.GetAttribute(CustomColumnNode, "Label"), TYml2Xml.GetAttribute(CustomColumnNode, "Tooltip"), TableName, ColumnName); } else { AddColumnToGrid(writer, ctrl.controlName, TYml2Xml.GetAttribute(CustomColumnNode, "Type"), TYml2Xml.GetAttribute(CustomColumnNode, "Label"), TYml2Xml.GetAttribute(CustomColumnNode, "Tooltip"), TableFieldTable, ColumnFieldNameResolved); } } else if (ctrl.HasAttribute("TableName")) { field = TDataBinding.GetTableField(null, ctrl.GetAttribute("TableName") + "." + ColumnFieldName, out IsDetailNotMaster, true); } else { field = TDataBinding.GetTableField(null, ColumnFieldName, out IsDetailNotMaster, true); } if (field != null) { AddColumnToGrid(writer, ctrl.controlName, field.iDecimals == 10 && field.iLength == 24 ? "Decimal" : field.GetDotNetType(), field.strLabel.Length > 0 ? field.strLabel : field.strName, String.Empty, TTable.NiceTableName(field.strTableName), TTable.NiceFieldName(field.strName)); } } } else { //If no columns, but the user is able to add columns dynamically during the running of the form, then need this here. if (ctrl.HasAttribute("SortableHeaders")) { string trueOrFalse = ctrl.GetAttribute("SortableHeaders"); writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".SortableHeaders = " + trueOrFalse + ";" + Environment.NewLine); } } if (ctrl.controlName != "grdDetails") { if (ctrl.HasAttribute("ActionLeavingRow")) { AssignEventHandlerToControl(writer, ctrl, "Selection.FocusRowLeaving", "SourceGrid.RowCancelEventHandler", ctrl.GetAttribute("ActionLeavingRow")); } if (ctrl.HasAttribute("ActionFocusRow")) { AssignEventHandlerToControl(writer, ctrl, "Selection.FocusRowEntered", "SourceGrid.RowEventHandler", ctrl.GetAttribute("ActionFocusRow")); } } if (ctrl.HasAttribute("ActionEnterKeyPressed")) { AssignEventHandlerToControl(writer, ctrl, "EnterKeyPressed", "TKeyPressedEventHandler", ctrl.GetAttribute("ActionEnterKeyPressed")); } if ((ctrl.controlName == "grdDetails") && FCodeStorage.HasAttribute("DetailTable")) { writer.Template.AddToCodelet("SHOWDATA", ""); if (ctrl.HasAttribute("SortOrder")) { // SortOrder is comma separated and has DESC or ASC after the column name string SortOrder = ctrl.GetAttribute("SortOrder"); foreach (string SortOrderPart in SortOrder.Split(',')) { bool temp; TTableField field = null; if ((SortOrderPart.Split(' ')[0].IndexOf(".") == -1) && ctrl.HasAttribute("TableName")) { field = TDataBinding.GetTableField(null, ctrl.GetAttribute("TableName") + "." + SortOrderPart.Split( ' ')[0], out temp, true); } else { field = TDataBinding.GetTableField( null, SortOrderPart.Split(' ')[0], out temp, true); } if (field != null) { SortOrder = SortOrder.Replace(SortOrderPart.Split(' ')[0], field.strName); } } writer.Template.AddToCodelet("GRIDSORT", SortOrder); } if (ctrl.HasAttribute("RowFilter")) { // this references a field in the table, and assumes there exists a local variable with the same name // eg. FBatchNumber in GL Journals string RowFilter = ctrl.GetAttribute("RowFilter"); String FilterString = "\""; foreach (string RowFilterPart in RowFilter.Split(',')) { bool temp; string columnName = TDataBinding.GetTableField( null, RowFilterPart, out temp, true).strName; if (FilterString.Length > 1) { FilterString += " + \" and "; } FilterString += columnName + " = \" + F" + TTable.NiceFieldName(columnName) + ".ToString()"; } writer.Template.AddToCodelet("GRIDFILTER", FilterString); } } if (ctrl.controlName == "grdDetails") { if (ctrl.HasAttribute("EnableMultiSelection")) { writer.Template.SetCodelet("GRIDMULTISELECTION", String.Format("grdDetails.Selection.EnableMultiSelection = {0};{1}", ctrl.GetAttribute("EnableMultiSelection"), Environment.NewLine)); } else if (FCodeStorage.FControlList.ContainsKey("btnDelete")) { writer.Template.SetCodelet("GRIDMULTISELECTION", "grdDetails.Selection.EnableMultiSelection = true;" + Environment.NewLine); } } return(writer.FTemplate); }
/// <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) { if (!ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", FDefaultWidth.ToString()); } base.SetControlProperties(writer, ctrl); writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".CancelEditingWithEscapeKey = false;" + Environment.NewLine); if (TYml2Xml.HasAttribute(ctrl.xmlNode, "SelectedRowActivates")) { // TODO: this function needs to be called by the manual code at the moment when eg a search finishes // TODO: call "Activate" + TYml2Xml.GetAttribute(ctrl.xmlNode, "SelectedRowActivates") } StringCollection Columns = TYml2Xml.GetElements(ctrl.xmlNode, "Columns"); if (Columns.Count > 0) { writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".Columns.Clear();" + Environment.NewLine); //This needs to come immediately after the Columns.Clear() and before the creation of the columns if (ctrl.HasAttribute("SortableHeaders")) { string trueOrFalse = ctrl.GetAttribute("SortableHeaders"); writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".SortableHeaders = " + trueOrFalse + ";" + Environment.NewLine); } foreach (string ColumnFieldName in Columns) { bool IsDetailNotMaster; TTableField field = null; string TableFieldTable; string ColumnFieldNameResolved; // customfield, eg. UC_GLTransactions, ATransaction.DateEntered and ATransaction.AnalysisAttributes // there needs to be a list of CustomColumns XmlNode CustomColumnsNode = TYml2Xml.GetChild(ctrl.xmlNode, "CustomColumns"); XmlNode CustomColumnNode = null; if (CustomColumnsNode != null) { CustomColumnNode = TYml2Xml.GetChild(CustomColumnsNode, ColumnFieldName); } if ((ctrl.controlName == "grdDetails") && FCodeStorage.HasAttribute("DetailTable")) { TableFieldTable = FCodeStorage.GetAttribute("DetailTable"); if (ColumnFieldName.StartsWith("Detail") && !IsLegitimateDetailFieldName(TableFieldTable, ColumnFieldName)) { ColumnFieldNameResolved = ColumnFieldName.Substring(6); // Drop 'Details' out of 'Details...' } else { ColumnFieldNameResolved = ColumnFieldName; } } else { TableFieldTable = ctrl.GetAttribute("TableName"); ColumnFieldNameResolved = ColumnFieldName; } if (CustomColumnNode != null) { // if grd has no TableName property if ((TableFieldTable == "") && ColumnFieldNameResolved.Contains(".")) { int Period = ColumnFieldNameResolved.IndexOf("."); string TableName = ColumnFieldNameResolved.Remove(Period); string ColumnName = ColumnFieldNameResolved.Remove(0, TableName.Length + 1); AddColumnToGrid(writer, ctrl.controlName, TYml2Xml.GetAttribute(CustomColumnNode, "Type"), TYml2Xml.GetAttribute(CustomColumnNode, "Label"), TYml2Xml.GetAttribute(CustomColumnNode, "Tooltip"), TableName, ColumnName); } else { AddColumnToGrid(writer, ctrl.controlName, TYml2Xml.GetAttribute(CustomColumnNode, "Type"), TYml2Xml.GetAttribute(CustomColumnNode, "Label"), TYml2Xml.GetAttribute(CustomColumnNode, "Tooltip"), TableFieldTable, ColumnFieldNameResolved); } } else if (ctrl.HasAttribute("TableName")) { field = TDataBinding.GetTableField(null, ctrl.GetAttribute("TableName") + "." + ColumnFieldName, out IsDetailNotMaster, true); } else { field = TDataBinding.GetTableField(null, ColumnFieldName, out IsDetailNotMaster, true); } if (field != null) { AddColumnToGrid(writer, ctrl.controlName, field.iDecimals == 10 && field.iLength == 24 ? "Currency" : field.GetDotNetType(), field.strLabel.Length > 0 ? field.strLabel : field.strName, String.Empty, TTable.NiceTableName(field.strTableName), TTable.NiceFieldName(field.strName)); } } } else { //If no columns, but the user is able to add columns dynamically during the running of the form, then need this here. if (ctrl.HasAttribute("SortableHeaders")) { string trueOrFalse = ctrl.GetAttribute("SortableHeaders"); writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".SortableHeaders = " + trueOrFalse + ";" + Environment.NewLine); } } if (ctrl.controlName != "grdDetails") { if (ctrl.HasAttribute("ActionLeavingRow")) { AssignEventHandlerToControl(writer, ctrl, "Selection.FocusRowLeaving", "SourceGrid.RowCancelEventHandler", ctrl.GetAttribute("ActionLeavingRow")); } if (ctrl.HasAttribute("ActionFocusRow")) { AssignEventHandlerToControl(writer, ctrl, "Selection.FocusRowEntered", "SourceGrid.RowEventHandler", ctrl.GetAttribute("ActionFocusRow")); } } if (ctrl.HasAttribute("ActionEnterKeyPressed")) { AssignEventHandlerToControl(writer, ctrl, "EnterKeyPressed", "TKeyPressedEventHandler", ctrl.GetAttribute("ActionEnterKeyPressed")); } if ((ctrl.controlName == "grdDetails") && FCodeStorage.HasAttribute("DetailTable")) { writer.Template.AddToCodelet("SHOWDATA", ""); if (ctrl.HasAttribute("SortOrder")) { // SortOrder is comma separated and has DESC or ASC after the column name string SortOrder = ctrl.GetAttribute("SortOrder"); foreach (string SortOrderPart in SortOrder.Split(',')) { bool temp; TTableField field = null; if ((SortOrderPart.Split(' ')[0].IndexOf(".") == -1) && ctrl.HasAttribute("TableName")) { field = TDataBinding.GetTableField(null, ctrl.GetAttribute("TableName") + "." + SortOrderPart.Split( ' ')[0], out temp, true); } else { field = TDataBinding.GetTableField( null, SortOrderPart.Split(' ')[0], out temp, true); } if (field != null) { SortOrder = SortOrder.Replace(SortOrderPart.Split(' ')[0], field.strName); } } writer.Template.AddToCodelet("GRIDSORT", SortOrder); } if (ctrl.HasAttribute("RowFilter")) { // this references a field in the table, and assumes there exists a local variable with the same name // eg. FBatchNumber in GL Journals string RowFilter = ctrl.GetAttribute("RowFilter"); String FilterString = "\""; foreach (string RowFilterPart in RowFilter.Split(',')) { bool temp; string columnName = TDataBinding.GetTableField( null, RowFilterPart, out temp, true).strName; if (FilterString.Length > 1) { FilterString += " + \" and "; } FilterString += columnName + " = \" + F" + TTable.NiceFieldName(columnName) + ".ToString()"; } writer.Template.AddToCodelet("GRIDFILTER", FilterString); } } if (ctrl.controlName == "grdDetails") { if (ctrl.HasAttribute("EnableMultiSelection")) { writer.Template.SetCodelet("GRIDMULTISELECTION", String.Format("grdDetails.Selection.EnableMultiSelection = {0};{1}", ctrl.GetAttribute("EnableMultiSelection"), Environment.NewLine)); } else if (FCodeStorage.FControlList.ContainsKey("btnDelete")) { writer.Template.SetCodelet("GRIDMULTISELECTION", "grdDetails.Selection.EnableMultiSelection = true;" + Environment.NewLine); } } return writer.FTemplate; }
/// <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) { // TODO this does not work yet. see EventRole Maintain screen if ((!ctrl.HasAttribute("Align")) && (!ctrl.HasAttribute("Width"))) { ctrl.SetAttribute("Stretch", "horizontally"); } base.SetControlProperties(writer, ctrl); // stretch at design time, but do not align to the right writer.SetControlProperty(ctrl, "Anchor", "((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)))"); string labelText = ""; if (TYml2Xml.HasAttribute(ctrl.xmlNode, "Text")) { labelText = TYml2Xml.GetAttribute(ctrl.xmlNode, "Text"); } else { labelText = ctrl.Label + ":"; } if (ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", ctrl.GetAttribute("Width")); } else { ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(labelText) + 5).ToString()); } if (ctrl.HasAttribute("Height")) { ctrl.SetAttribute("Height", ctrl.GetAttribute("Height")); } writer.SetControlProperty(ctrl, "Text", "\"" + labelText + "\""); writer.SetControlProperty(ctrl, "Padding", "new System.Windows.Forms.Padding(0, 5, 0, 0)"); if (FRightAlign) { writer.SetControlProperty(ctrl, "TextAlign", "System.Drawing.ContentAlignment.TopRight"); } return writer.FTemplate; }
/// <summary> /// optimise the table layout, and write it; /// </summary> public void WriteTableLayout(TFormWriter writer, TControlDef LayoutCtrl) { // calculate the width and height for the columns and rows int[] ColumnWidth = new int[FColumnCount]; int[] RowHeight = new int[FRowCount]; // first go: ignore cells spanning rows and columns; second go: check that spanning cells fit as well for (int spanRunCounter = 0; spanRunCounter < 2; spanRunCounter++) { for (int columnCounter = 0; columnCounter < FColumnCount; columnCounter++) { // initialise the summary values if (spanRunCounter == 0) { ColumnWidth[columnCounter] = 0; if (columnCounter == 0) { for (int rowCounter = 0; rowCounter < FRowCount; rowCounter++) { RowHeight[rowCounter] = 0; } } } for (int rowCounter = 0; rowCounter < FRowCount; rowCounter++) { if ((FGrid[columnCounter, rowCounter] != null)) { TControlDef ctrl = FGrid[columnCounter, rowCounter]; int CellWidth = ctrl.Width; TLogging.LogAtLevel(1, "Control '" + ctrl.controlName + "' Width in WriteTableLayout: " + CellWidth.ToString()); if ((spanRunCounter == 0) && (ctrl.colSpanWithLabel == 1)) { if (CellWidth > ColumnWidth[columnCounter]) { ColumnWidth[columnCounter] = CellWidth; } } else { int CurrentSpanWidth = 0; if (columnCounter + ctrl.colSpanWithLabel > FColumnCount) { // TODO: make an exception again? TLogging.Log("Warning: invalid colspan " + ctrl.colSpan.ToString() + " in control " + ctrl.controlName + ". There are only " + (FColumnCount / 2).ToString() + " columns overall"); ctrl.colSpanWithLabel = ctrl.colSpan; } for (int columnCounter2 = columnCounter; columnCounter2 < columnCounter + ctrl.colSpanWithLabel; columnCounter2++) { CurrentSpanWidth += ColumnWidth[columnCounter2]; } if (CurrentSpanWidth < CellWidth) { ColumnWidth[columnCounter + ctrl.colSpanWithLabel - 1] += CellWidth - CurrentSpanWidth; } } int CellHeight = ctrl.Height; if (CellHeight == 17) { // for labels, we should consider the margin top as well. CellHeight = 22; } if ((spanRunCounter == 0) && (ctrl.colSpanWithLabel == 1)) { if (CellHeight > RowHeight[rowCounter]) { RowHeight[rowCounter] = CellHeight; } } else { int CurrentSpanHeight = 0; for (int rowCounter2 = rowCounter; rowCounter2 < rowCounter + ctrl.rowSpan; rowCounter2++) { CurrentSpanHeight += RowHeight[rowCounter2]; } if (CurrentSpanHeight < CellHeight) { RowHeight[rowCounter + ctrl.rowSpan - 1] += CellHeight - CurrentSpanHeight; } } } } } } // now apply settings about the column width and row height if (FColWidths != null) { bool simpleColumnWidth = false; // for the simple column width specification, you need to provide a width for each column, without the label columns if (FColWidths.Count * 2 == FColumnCount) { simpleColumnWidth = true; for (int columnCounter = 0; columnCounter < FColWidths.Count; columnCounter++) { if (!FColWidths.ContainsKey(columnCounter)) { simpleColumnWidth = false; } } } for (int columnCounter = 0; columnCounter < FColumnCount; columnCounter++) { if (simpleColumnWidth) { // the specified width includes the label column if (FColWidths.ContainsKey(columnCounter / 2)) { string[] ColWidthSpec = FColWidths[columnCounter / 2].Split(':'); if (ColWidthSpec[0].ToLower() == "fixed") { ColumnWidth[columnCounter] = Convert.ToInt32(ColWidthSpec[1]) / 2; } else if (ColWidthSpec[0].ToLower() == "percent") { // TODO } } } else { if (FColWidths.ContainsKey(columnCounter)) { string[] ColWidthSpec = FColWidths[columnCounter].Split(':'); if (ColWidthSpec[0].ToLower() == "fixed") { ColumnWidth[columnCounter] = Convert.ToInt32(ColWidthSpec[1]); } else if (ColWidthSpec[0].ToLower() == "percent") { // TODO TLogging.Log("Warning: we currently don't support colwidth in percentage, control " + LayoutCtrl.controlName); } } } } } if (FRowHeights != null) { for (int rowCounter = 0; rowCounter < FRowCount; rowCounter++) { if (FRowHeights.ContainsKey(rowCounter)) { string[] RowHeightSpec = FRowHeights[rowCounter].Split(':'); if (RowHeightSpec[0].ToLower() == "fixed") { RowHeight[rowCounter] = Convert.ToInt32(RowHeightSpec[1]); } else if (RowHeightSpec[0].ToLower() == "percent") { // TODO TLogging.Log("Warning: we currently don't support rowheight in percentage, control " + LayoutCtrl.controlName); } } } } if (TLogging.DebugLevel >= 4) { StringCollection widthStringCollection = new StringCollection(); for (int columnCounter = 0; columnCounter < FColumnCount; columnCounter++) { widthStringCollection.Add(ColumnWidth[columnCounter].ToString()); } TLogging.Log("column width for " + LayoutCtrl.controlName + ": " + StringHelper.StrMerge(widthStringCollection, ',')); for (int rowCounter = 0; rowCounter < FRowCount; rowCounter++) { string rowText = string.Empty; for (int columnCounter = 0; columnCounter < FColumnCount; columnCounter++) { if (FGrid[columnCounter, rowCounter] != null) { TControlDef childctrl = FGrid[columnCounter, rowCounter]; for (int countspan = 0; countspan < childctrl.colSpanWithLabel; countspan++) { rowText += string.Format("{0}:{1} ", columnCounter + countspan, childctrl.controlName); } } } TLogging.Log(String.Format(" Row{0}: {1}", rowCounter, rowText)); } } int Width = 0; int Height = 0; int CurrentLeftPosition = Convert.ToInt32(LayoutCtrl.GetAttribute("MarginLeft", MARGIN_LEFT.ToString())); for (int columnCounter = 0; columnCounter < FColumnCount; columnCounter++) { int CurrentTopPosition; if (LayoutCtrl.IsHorizontalGridButtonPanel) { TLogging.LogAtLevel(1, "Setting CurrentTopPosition to 3 for all Controls on Control '" + LayoutCtrl.controlName + "' as it is a horizontal Grid Button Panel (used for Buttons)."); CurrentTopPosition = 3; } else { CurrentTopPosition = Convert.ToInt32(LayoutCtrl.GetAttribute("MarginTop", MARGIN_TOP.ToString())); } // only twice the margin for groupboxes if ((LayoutCtrl.controlTypePrefix == "grp") || (LayoutCtrl.controlTypePrefix == "rgr")) { CurrentTopPosition += MARGIN_TOP; } for (int rowCounter = 0; rowCounter < FRowCount; rowCounter++) { if (FGrid[columnCounter, rowCounter] != null) { TControlDef childctrl = FGrid[columnCounter, rowCounter]; if (childctrl.GetAttribute("Stretch") == "horizontally") { // use the full column width // add up spanning columns int concatenatedColumnWidth = ColumnWidth[columnCounter]; for (int colSpanCounter = 1; colSpanCounter < childctrl.colSpanWithLabel; colSpanCounter++) { concatenatedColumnWidth += ColumnWidth[columnCounter + colSpanCounter]; } if (concatenatedColumnWidth > 0) { TControlDef ParentControl = childctrl.FCodeStorage.GetControl(childctrl.parentName); System.Windows.Forms.Padding?ParentPad = null; if (ParentControl.HasAttribute("Padding")) { string ParentPadding = ParentControl.GetAttribute("Padding"); TLogging.LogAtLevel(1, "ParentControl '" + ParentControl.controlName + "' Padding: " + ParentPadding); if (ParentPadding.IndexOf(',') == -1) { ParentPad = new Padding(Convert.ToInt32(ParentPadding)); } else { string[] Paddings = ParentPadding.Split(','); ParentPad = new Padding(Convert.ToInt32(Paddings[0]), Convert.ToInt32(Paddings[1]), Convert.ToInt32(Paddings[2]), Convert.ToInt32(Paddings[3])); } TLogging.LogAtLevel(1, "ParentControl Padding (parsed): " + ParentPad.ToString()); } writer.SetControlProperty(childctrl, "Size", String.Format("new System.Drawing.Size({0}, {1})", concatenatedColumnWidth - (ParentPad.HasValue ? ParentPad.Value.Right : 0), childctrl.Height)); } } int ControlTopPosition = CurrentTopPosition; int ControlLeftPosition = CurrentLeftPosition; TLogging.LogAtLevel(1, "WriteTableLayout for Control '" + childctrl.controlName + "'"); // add margin or padding string padding = writer.GetControlProperty(childctrl.controlName, "Padding"); if (padding.Length > 0) { string[] values = padding.Substring(padding.IndexOf("(") + 1).Replace(")", "").Split(new char[] { ',' }); ControlLeftPosition += Convert.ToInt32(values[0]); ControlTopPosition += Convert.ToInt32(values[1]); TLogging.LogAtLevel(1, "Removing Padding Property from Control '" + childctrl.controlName + "'!"); writer.ClearControlProperty(childctrl.controlName, "Padding"); } string margin = writer.GetControlProperty(childctrl.controlName, "Margin"); if (margin.Length > 0) { string[] values = margin.Substring(margin.IndexOf("(") + 1).Replace(")", "").Split(new char[] { ',' }); ControlLeftPosition += Convert.ToInt32(values[0]); ControlTopPosition += Convert.ToInt32(values[1]); writer.ClearControlProperty(childctrl.controlName, "Margin"); } if ((childctrl.IsOnHorizontalGridButtonPanel) && (columnCounter != 0) && !((childctrl.HasAttribute("StartNewButtonGroup")) && (childctrl.GetAttribute("StartNewButtonGroup").ToLower() == "true"))) { TLogging.LogAtLevel(1, "Adjusted ControlLeftPosition for Control '" + childctrl.controlName + "' as it is on a horizontal Grid Button Panel."); ControlLeftPosition -= 8; } writer.SetControlProperty(childctrl.controlName, "Location", String.Format("new System.Drawing.Point({0},{1})", ControlLeftPosition.ToString(), ControlTopPosition.ToString()), false); writer.CallControlFunction(LayoutCtrl.controlName, "Controls.Add(this." + childctrl.controlName + ")"); if (FTabOrder == "Horizontal") { writer.SetControlProperty(childctrl.controlName, "TabIndex", FCurrentTabIndex.ToString(), false); FCurrentTabIndex += 10; } } CurrentTopPosition += RowHeight[rowCounter]; CurrentTopPosition += Convert.ToInt32(LayoutCtrl.GetAttribute("VerticalSpace", VERTICAL_SPACE.ToString())); if (CurrentTopPosition > Height) { Height = CurrentTopPosition; } } CurrentLeftPosition += ColumnWidth[columnCounter]; CurrentLeftPosition += Convert.ToInt32(LayoutCtrl.GetAttribute("HorizontalSpace", HORIZONTAL_SPACE.ToString())); if (CurrentLeftPosition > Width) { Width = CurrentLeftPosition; } } Height += Convert.ToInt32(LayoutCtrl.GetAttribute("MarginBottom", MARGIN_BOTTOM.ToString())) - Convert.ToInt32(LayoutCtrl.GetAttribute("VerticalSpace", VERTICAL_SPACE.ToString())); if (!LayoutCtrl.HasAttribute("Width")) { LayoutCtrl.SetAttribute("Width", Width.ToString()); } else { Width = Convert.ToInt32(LayoutCtrl.GetAttribute("Width")); } if (!LayoutCtrl.HasAttribute("Height")) { LayoutCtrl.SetAttribute("Height", Height.ToString()); } else { Height = Convert.ToInt32(LayoutCtrl.GetAttribute("Height")); } writer.SetControlProperty(LayoutCtrl, "Location", String.Format("new System.Drawing.Point({0}, {1})", MARGIN_LEFT, MARGIN_TOP)); writer.SetControlProperty(LayoutCtrl, "Size", String.Format("new System.Drawing.Size({0}, {1})", Width, Height)); // by default, the TabOrder is by column, Vertical if (FTabOrder != "Horizontal") { for (int rowCounter = 0; rowCounter < FRowCount; rowCounter++) { for (int columnCounter = 0; columnCounter < FColumnCount; columnCounter++) { if (FGrid[columnCounter, rowCounter] != null) { TControlDef childctrl = FGrid[columnCounter, rowCounter]; writer.SetControlProperty(childctrl.controlName, "TabIndex", FCurrentTabIndex.ToString(), false); FCurrentTabIndex += 10; } } } } }
/// <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; } }
/// <summary> /// generate the children, and write the size of this control /// </summary> public override void ProcessChildren(TFormWriter writer, TControlDef ctrl) { XmlNode Controls = TXMLParser.GetChild(ctrl.xmlNode, "Controls"); if (Controls != null) { StringCollection childControls = TYml2Xml.GetElements(Controls); // this is a checkbox that enables another control or a group of controls ctrl.SetAttribute("GenerateWithOtherControls", "yes"); if (childControls.Count == 1) { TControlDef ChildCtrl = ctrl.FCodeStorage.GetControl(childControls[0]); ChildCtrl.parentName = ctrl.controlName; ctrl.Children.Add(ChildCtrl); ChildCtrl.SetAttribute("DependsOnRadioButton", "true"); // use the label of the child control if (ChildCtrl.HasAttribute("Label")) { ctrl.Label = ChildCtrl.Label; } } else { foreach (string child in childControls) { TControlDef ChildCtrl = ctrl.FCodeStorage.GetControl(child); if (ChildCtrl == null) { throw new Exception("cannot find control " + child + " which should belong to " + ctrl.controlName); } ChildCtrl.parentName = ctrl.controlName; ctrl.Children.Add(ChildCtrl); ChildCtrl.SetAttribute("DependsOnRadioButton", "true"); IControlGenerator ctrlGenerator = writer.FindControlGenerator(ChildCtrl); ctrlGenerator.GenerateControl(writer, ChildCtrl); } } } }
/// <summary> /// generate the children /// </summary> public override void ProcessChildren(TFormWriter writer, TControlDef ctrl) { base.ProcessChildren(writer, ctrl); XmlNode controlsNode = TXMLParser.GetChild(ctrl.xmlNode, "Controls"); if ((controlsNode != null) && TYml2Xml.GetChildren(controlsNode, true)[0].Name.StartsWith("Row")) { // this defines the layout with several rows with several controls per row Int32 countRow = 0; foreach (XmlNode row in TYml2Xml.GetChildren(controlsNode, true)) { StringCollection controls = TYml2Xml.GetElements(row); foreach (string ctrlname in controls) { TControlDef childCtrl = writer.CodeStorage.GetControl(ctrlname); if (ctrlname.StartsWith("Empty")) { childCtrl = writer.CodeStorage.FindOrCreateControl("pnlEmpty", ctrl.controlName); } if (childCtrl == null) { throw new Exception("cannot find control with name " + ctrlname + "; it belongs to " + ctrl.controlName); } // add control itself ctrl.Children.Add(childCtrl); childCtrl.parentName = ctrl.controlName; IControlGenerator ctrlGenerator = writer.FindControlGenerator(childCtrl); ctrlGenerator.GenerateControl(writer, childCtrl); childCtrl.rowNumber = countRow; } countRow++; } } else { if ((controlsNode != null) && (ctrl.Children.Count == 0)) { StringCollection controlNamesCollection = TYml2Xml.GetElements(TXMLParser.GetChild(ctrl.xmlNode, "Controls")); foreach (string childCtrlName in controlNamesCollection) { TControlDef childCtrl = writer.CodeStorage.GetControl(childCtrlName); if (childCtrlName.StartsWith("Empty")) { childCtrl = writer.CodeStorage.FindOrCreateControl("pnlEmpty", ctrl.controlName); } if (childCtrl == null) { throw new Exception("cannot find control with name " + childCtrlName + "; it belongs to " + ctrl.controlName); } childCtrl.parentName = ctrl.controlName; ctrl.Children.Add(childCtrl); } } foreach (TControlDef childCtrl in ctrl.Children) { TLogging.LogAtLevel(1, "foreach (TControlDef childCtrl in ctrl.Children) -- Control: " + childCtrl.controlName); if (!childCtrl.controlName.StartsWith("pnlEmpty")) { // process the control itself IControlGenerator ctrlGenerator = writer.FindControlGenerator(childCtrl); ctrlGenerator.GenerateControl(writer, childCtrl); } } } bool hasDockingChildren = false; // don't use a tablelayout for controls where all children have the Dock property set foreach (TControlDef ChildControl in ctrl.Children) { if (!ChildControl.HasAttribute("Dock")) { ctrl.SetAttribute("UseTableLayout", "true"); } else { hasDockingChildren = true; } } if (ctrl.GetAttribute("UseTableLayout") == "true") { // show a warning if there are some controls with Docking, and some without if (hasDockingChildren) { StringCollection clearDockAttributeChildren = new StringCollection(); foreach (TControlDef ChildControl in ctrl.Children) { if ((ChildControl.HasAttribute("Dock")) && ((!ChildControl.IsHorizontalGridButtonPanelStrict) && (ChildControl.controlName != TControlDef.STR_GRID_DETAILS_NAME))) { ChildControl.ClearAttribute("Dock"); clearDockAttributeChildren.Add(ChildControl.controlName); } } if (clearDockAttributeChildren.Count > 0) { TLogging.Log("Warning: please remove the Dock attribute from control(s) " + StringHelper.StrMerge(clearDockAttributeChildren, ',')); } } if (ctrl.GetAttribute("Margin") == "0") { if (!ctrl.HasAttribute("MarginTop")) { ctrl.SetAttribute("MarginTop", "0"); ctrl.SetAttribute("MarginBottom", "0"); ctrl.SetAttribute("MarginLeft", "0"); } } PanelLayoutGenerator TlpGenerator = new PanelLayoutGenerator(); TlpGenerator.SetOrientation(ctrl); TlpGenerator.CreateLayout(writer, ctrl, null, -1, -1); foreach (TControlDef ChildControl in ctrl.Children) { TlpGenerator.InsertControl(writer, ChildControl); } TlpGenerator.WriteTableLayout(writer, ctrl); if (ctrl.GetAttribute("Dock", "None") != "None") { writer.SetControlProperty(ctrl.controlName, "Dock", ctrl.GetAttribute("Dock"), false); // groupboxes do not have AutoScroll property (grp, rgr) if ((this.FPrefix == "pnl") || (this.FPrefix == "tab") || (this.FPrefix == "rng")) { writer.SetControlProperty(ctrl.controlName, "AutoScroll", "true", false); } } } return; }
/// <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) { if (!ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", FDefaultWidth.ToString()); } base.SetControlProperties(writer, ctrl); writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".CancelEditingWithEscapeKey = false;" + Environment.NewLine); if (TYml2Xml.HasAttribute(ctrl.xmlNode, "SelectedRowActivates")) { // TODO: this function needs to be called by the manual code at the moment when eg a search finishes // TODO: call "Activate" + TYml2Xml.GetAttribute(ctrl.xmlNode, "SelectedRowActivates") } StringCollection Columns = TYml2Xml.GetElements(ctrl.xmlNode, "Columns"); if (Columns.Count > 0) { writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".Columns.Clear();" + Environment.NewLine); //This needs to come immediately after the Columns.Clear() and before the creation of the columns if (ctrl.HasAttribute("SortableHeaders")) { string trueOrFalse = ctrl.GetAttribute("SortableHeaders"); writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".SortableHeaders = " + trueOrFalse + ";" + Environment.NewLine); } bool isFirstColumnVarchar = false; bool doneFirstColumn = false; foreach (string ColumnFieldName in Columns) { bool IsDetailNotMaster; TTableField field = null; string TableFieldTable; string ColumnFieldNameResolved; // customfield, eg. UC_GLTransactions, ATransaction.DateEntered and ATransaction.AnalysisAttributes // there needs to be a list of CustomColumns XmlNode CustomColumnsNode = TYml2Xml.GetChild(ctrl.xmlNode, "CustomColumns"); XmlNode CustomColumnNode = null; if (CustomColumnsNode != null) { CustomColumnNode = TYml2Xml.GetChild(CustomColumnsNode, ColumnFieldName); } if ((ctrl.controlName == "grdDetails") && FCodeStorage.HasAttribute("DetailTable")) { TableFieldTable = FCodeStorage.GetAttribute("DetailTable"); if (ColumnFieldName.StartsWith("Detail") && !IsLegitimateDetailFieldName(TableFieldTable, ColumnFieldName)) { ColumnFieldNameResolved = ColumnFieldName.Substring(6); // Drop 'Details' out of 'Details...' } else { ColumnFieldNameResolved = ColumnFieldName; } } else { TableFieldTable = ctrl.GetAttribute("TableName"); ColumnFieldNameResolved = ColumnFieldName; } if (CustomColumnNode != null) { TTableField tf = null; // if grd has no TableName property if ((TableFieldTable == "") && ColumnFieldNameResolved.Contains(".")) { int Period = ColumnFieldNameResolved.IndexOf("."); string TableName = ColumnFieldNameResolved.Remove(Period); string ColumnName = ColumnFieldNameResolved.Remove(0, TableName.Length + 1); AddColumnToGrid(writer, ctrl.controlName, TYml2Xml.GetAttribute(CustomColumnNode, "Type"), TYml2Xml.GetAttribute(CustomColumnNode, "Label"), TYml2Xml.GetAttribute(CustomColumnNode, "Tooltip"), TableName, ColumnName); tf = TDataBinding.GetTableField(null, TableName + "." + ColumnName, out IsDetailNotMaster, true); } else { AddColumnToGrid(writer, ctrl.controlName, TYml2Xml.GetAttribute(CustomColumnNode, "Type"), TYml2Xml.GetAttribute(CustomColumnNode, "Label"), TYml2Xml.GetAttribute(CustomColumnNode, "Tooltip"), TableFieldTable, ColumnFieldNameResolved); tf = TDataBinding.GetTableField(null, TableFieldTable + "." + ColumnFieldNameResolved, out IsDetailNotMaster, true); } if (!doneFirstColumn) { isFirstColumnVarchar = tf.strName.EndsWith("_c"); doneFirstColumn = true; } } else if (ctrl.HasAttribute("TableName")) { field = TDataBinding.GetTableField(null, ctrl.GetAttribute("TableName") + "." + ColumnFieldName, out IsDetailNotMaster, true); } else { field = TDataBinding.GetTableField(null, ColumnFieldName, out IsDetailNotMaster, true); } if (field != null) { AddColumnToGrid(writer, ctrl.controlName, field.iDecimals == 10 && field.iLength == 24 ? "Decimal" : field.GetDotNetType(), field.strLabel.Length > 0 ? field.strLabel : field.strName, String.Empty, TTable.NiceTableName(field.strTableName), TTable.NiceFieldName(field.strName)); if (!doneFirstColumn) { isFirstColumnVarchar = field.strName.EndsWith("_c"); doneFirstColumn = true; } } } if (FControlType == TYPE_DATA_GRID_NON_PAGED) { // Grid AutoFind definition (not allowed in paged grids) string autoFindStr = ctrl.controlName + ".AutoFindMode = TAutoFindModeEnum."; string mode = "NoAutoFind"; if (ctrl.HasAttribute("AutoFindMode")) { // Use the specified value in YAML mode = ctrl.GetAttribute("AutoFindMode"); TLogging.Log("Info: AutoFindMode (with columns) was set to " + mode + " from explicit YAML attribute: " + ctrl.controlName); } else if (isFirstColumnVarchar) { // We can use auto-find because we have a first column based on a varchar mode = "FirstCharacter"; TLogging.Log("Info: AutoFindMode (with columns) was set implicitly for: " + ctrl.controlName); } else { TLogging.Log("Info: AutoFindMode (with columns) was set to NoAutoFind for: " + ctrl.controlName); } writer.Template.AddToCodelet("INITMANUALCODE", autoFindStr + mode + ";" + Environment.NewLine); if (ctrl.HasAttribute("AutoFindColumn")) { string colNum = ctrl.GetAttribute("AutoFindColumn"); writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".AutoFindColumn = " + colNum + ";" + Environment.NewLine); TLogging.Log("Info: AutoFindColumn was set to " + colNum + " for: " + ctrl.controlName); } if ((mode == "FirstCharacter") && !ctrl.HasAttribute("SortOrder")) { TLogging.Log("Info: AutoFind has been turned on for a grid with no YAML-defined sort order: (" + ctrl.controlName + "). You can remove this message by explicitly setting a SortOrder in the YAML file."); } } } else { //If no columns, but the user is able to add columns dynamically during the running of the form, then need this here. if (ctrl.HasAttribute("SortableHeaders")) { string trueOrFalse = ctrl.GetAttribute("SortableHeaders"); writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".SortableHeaders = " + trueOrFalse + ";" + Environment.NewLine); } if (FControlType == TYPE_DATA_GRID_NON_PAGED) { // Grid AutoFind definition (not allowed in paged grids) string autoFindStr = ctrl.controlName + ".AutoFindMode = TAutoFindModeEnum."; string mode = "FirstCharacter"; if (ctrl.HasAttribute("AutoFindMode")) { // Use the specified value in YAML mode = ctrl.GetAttribute("AutoFindMode"); TLogging.Log("Info: AutoFindMode (without columns) was set to " + mode + " from explicit YAML attribute: " + ctrl.controlName); } else if (writer.FCodeStorage.ManualFileExistsAndContains(ctrl.controlName + ".AddTextColumn(")) { // We presume can use auto-find because we have a column (maybe the first) based on a varchar TLogging.Log("Info: AutoFindMode (without columns) was set implicitly for: " + ctrl.controlName); } else { mode = "NoAutoFind"; TLogging.Log("Info: AutoFindMode (without columns) was set to NoAutoFind for: " + ctrl.controlName); } writer.Template.AddToCodelet("INITMANUALCODE", autoFindStr + mode + ";" + Environment.NewLine); if (ctrl.HasAttribute("AutoFindColumn")) { string colNum = ctrl.GetAttribute("AutoFindColumn"); writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".AutoFindColumn = " + colNum + ";" + Environment.NewLine); TLogging.Log("Info: AutoFindColumn was set to " + colNum + " for: " + ctrl.controlName); } } } if (ctrl.controlName != "grdDetails") { if (ctrl.HasAttribute("ActionLeavingRow")) { AssignEventHandlerToControl(writer, ctrl, "Selection.FocusRowLeaving", "SourceGrid.RowCancelEventHandler", ctrl.GetAttribute("ActionLeavingRow")); } if (ctrl.HasAttribute("ActionFocusRow")) { AssignEventHandlerToControl(writer, ctrl, "Selection.FocusRowEntered", "SourceGrid.RowEventHandler", ctrl.GetAttribute("ActionFocusRow")); } } if (ctrl.HasAttribute("ActionEnterKeyPressed")) { AssignEventHandlerToControl(writer, ctrl, "EnterKeyPressed", "TKeyPressedEventHandler", ctrl.GetAttribute("ActionEnterKeyPressed")); } if ((ctrl.controlName == "grdDetails") && FCodeStorage.HasAttribute("DetailTable")) { writer.Template.AddToCodelet("SHOWDATA", ""); if (ctrl.HasAttribute("SortOrder")) { // SortOrder is comma separated and has DESC or ASC after the column name string SortOrder = ctrl.GetAttribute("SortOrder"); foreach (string SortOrderPart in SortOrder.Split(',')) { bool temp; TTableField field = null; string columnNamePart = SortOrderPart.Split(' ')[0]; if ((columnNamePart.IndexOf(".") == -1) && ctrl.HasAttribute("TableName")) { field = TDataBinding.GetTableField(null, ctrl.GetAttribute("TableName") + "." + columnNamePart, out temp, true); } else { field = TDataBinding.GetTableField(null, columnNamePart, out temp, true); } if (field != null) { SortOrder = SortOrder.Replace(columnNamePart, field.strName); } } writer.Template.AddToCodelet("GRIDSORT", SortOrder); } if (ctrl.HasAttribute("RowFilter")) { // this references a field in the table, and assumes there exists a local variable with the same name // eg. FBatchNumber in GL Journals string RowFilter = ctrl.GetAttribute("RowFilter"); String FilterString = "\""; foreach (string RowFilterPart in RowFilter.Split(',')) { bool temp; string columnName = TDataBinding.GetTableField( null, RowFilterPart, out temp, true).strName; if (FilterString.Length > 1) { FilterString += " + \" and "; } FilterString += columnName + " = \" + F" + TTable.NiceFieldName(columnName) + ".ToString()"; } writer.Template.AddToCodelet("GRIDFILTER", FilterString); } } if (ctrl.controlName == "grdDetails") { if (ctrl.HasAttribute("EnableMultiSelection")) { writer.Template.SetCodelet("GRIDMULTISELECTION", String.Format("grdDetails.Selection.EnableMultiSelection = {0};{1}", ctrl.GetAttribute("EnableMultiSelection"), Environment.NewLine)); } else if (FCodeStorage.FControlList.ContainsKey("btnDelete")) { writer.Template.SetCodelet("GRIDMULTISELECTION", "grdDetails.Selection.EnableMultiSelection = true;" + Environment.NewLine); } } return(writer.FTemplate); }
/// <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) { bool OverrideImageAlign = false; bool OverrideTextAlign = false; bool NoLabel = false; TLogging.LogAtLevel(1, "ButtonGenerator.SetControlProperties for Control " + ctrl.controlName); if (!ctrl.HasAttribute("Width")) { ctrl.SetAttribute("Width", (PanelLayoutGenerator.MeasureTextWidth(ctrl.Label) + 15).ToString()); } if (ctrl.HasAttribute("NoLabel") && (ctrl.GetAttribute("NoLabel").ToLower() == "true")) { writer.SetControlProperty(ctrl, "Text", "\"\""); NoLabel = true; } else { writer.SetControlProperty(ctrl, "Size", "new System.Drawing.Size(" + ctrl.GetAttribute("Width").ToString() + ", " + ctrl.GetAttribute("Height").ToString() + ")"); writer.SetControlProperty(ctrl, "Text", "\"" + ctrl.Label + "\""); } if (ctrl.IsOnHorizontalGridButtonPanel) { TLogging.LogAtLevel(1, "Setting Height for Control '" + ctrl.controlName + "' to 23 as it is on a horizontal Grid Button Panel"); FDefaultHeight = 23; if (!ctrl.HasAttribute("ImageAlign")) { if (NoLabel) { //TLogging.LogAtLevel(1, "Setting ImageAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.BottomCenter as it is on a horizontal Grid Button Panel (no Text)"); writer.SetControlProperty(ctrl, "ImageAlign", "System.Drawing.ContentAlignment.BottomCenter"); } else { //TLogging.LogAtLevel(1, "Setting ImageAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.BottomLeft as it is on a horizontal Grid Button Panel"); writer.SetControlProperty(ctrl, "ImageAlign", "System.Drawing.ContentAlignment.BottomLeft"); // Note: In this case want the text centered on the Button, which the TextAlign Property will achieve. // However, its default value is System.Drawing.ContentAlignment.MiddleCenter which means we don't need to explicitly write this out into the Designer file... //TLogging.LogAtLevel(1, "Setting TextAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.MiddleCenter as it is on a horizontal Grid Button Panel"); // writer.SetControlProperty(ctrl, "TextAlign", "System.Drawing.ContentAlignment.MiddleCenter"); } OverrideImageAlign = true; OverrideTextAlign = true; } } else { if (!ctrl.HasAttribute("Height")) { ctrl.SetAttribute("Height", FDefaultHeight.ToString()); } } base.SetControlProperties(writer, ctrl); if (ctrl.GetAttribute("AcceptButton").ToLower() == "true") { writer.Template.AddToCodelet("INITUSERCONTROLS", "this.AcceptButton = " + ctrl.controlName + ";" + Environment.NewLine); } if (ctrl.GetAction() != null) { string img = ctrl.GetAction().actionImage; if (img.Length > 0) { ctrl.SetAttribute("Width", (Convert.ToInt32(ctrl.GetAttribute("Width")) + Convert.ToInt32(ctrl.GetAttribute("IconWidth", "15"))).ToString()); writer.SetControlProperty(ctrl, "Size", "new System.Drawing.Size(" + ctrl.GetAttribute("Width").ToString() + ", " + ctrl.GetAttribute("Height").ToString() + ")"); if (writer.GetControlProperty(ctrl.controlName, "Text") == "\"\"") { if ((!ctrl.HasAttribute("ImageAlign")) && !OverrideImageAlign) { // Note: In this case we want the Image centered on the Button, which the ImageAlign Property will achieve. // However, its default value is System.Drawing.ContentAlignment.MiddleCenter which means we don't need to explicitly write this out into the Designer file... //Console.WriteLine("Setting ImageAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.MiddleCenter as it is NOT on a horizontal Grid Button Panel (no Text)"); // writer.SetControlProperty(ctrl, "ImageAlign", "System.Drawing.ContentAlignment.MiddleCenter"); } } else { if ((!ctrl.HasAttribute("ImageAlign")) && !OverrideImageAlign) { //Console.WriteLine("Setting ImageAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.MiddleLeft as it is NOT on a horizontal Grid Button Panel"); writer.SetControlProperty(ctrl, "ImageAlign", "System.Drawing.ContentAlignment.MiddleLeft"); } } if (!OverrideTextAlign) { //Console.WriteLine("Setting TextAlign Attribute of Control '" + ctrl.controlName + "' to System.Drawing.ContentAlignment.MiddleRight as it is NOT on a horizontal Grid Button Panel"); writer.SetControlProperty(ctrl, "TextAlign", "System.Drawing.ContentAlignment.MiddleRight"); } } } return writer.FTemplate; }