Exemple #1
0
        /// <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)
        {
            base.SetControlProperties(writer, ctrl);

            if (TYml2Xml.HasAttribute(ctrl.xmlNode, "DefaultValue"))
            {
                writer.SetControlProperty(ctrl,
                                          "Text",
                                          "\"" + TYml2Xml.GetAttribute(ctrl.xmlNode, "DefaultValue") + "\"");
            }

            if ((TYml2Xml.HasAttribute(ctrl.xmlNode, "Multiline")) && (TYml2Xml.GetAttribute(ctrl.xmlNode, "Multiline") == "true"))
            {
                writer.SetControlProperty(ctrl, "Multiline", "true");

                if ((TYml2Xml.HasAttribute(ctrl.xmlNode, "WordWrap")) && (TYml2Xml.GetAttribute(ctrl.xmlNode, "WordWrap") == "false"))
                {
                    writer.SetControlProperty(ctrl, "WordWrap", "false");
                }

                if (TYml2Xml.HasAttribute(ctrl.xmlNode, "ScrollBars"))
                {
                    writer.SetControlProperty(ctrl, "ScrollBars", "ScrollBars." + TYml2Xml.GetAttribute(ctrl.xmlNode, "ScrollBars"));
                }
            }

            writer.Template.AddToCodelet("ASSIGNFONTATTRIBUTES",
                                         "this." + ctrl.controlName + ".Font = TAppSettingsManager.GetDefaultBoldFont();" + Environment.NewLine);

            return(writer.FTemplate);
        }
Exemple #2
0
        /// <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 (IsMniFilterFindClickAndIgnore(writer, ctrl, false))
            {
                return(writer.FTemplate);
            }

            base.SetControlProperties(writer, ctrl);

            // deactivate menu items that have no action assigned yet.
            if ((ctrl.GetAction() == null) && !ctrl.HasAttribute("ActionClick") && !ctrl.HasAttribute("ActionOpenScreen") &&
                (ctrl.NumberChildren == 0) && !(this is MenuItemSeparatorGenerator))
            {
                string ActionEnabling = ctrl.controlName + ".Enabled = false;" + Environment.NewLine;
                writer.Template.AddToCodelet("ACTIONENABLINGDISABLEMISSINGFUNCS", ActionEnabling);
            }

            writer.SetControlProperty(ctrl, "Text", "\"" + ctrl.Label + "\"");

            if (ctrl.HasAttribute("ShortcutKeys"))
            {
                writer.SetControlProperty(ctrl, "ShortcutKeys", ctrl.GetAttribute("ShortcutKeys"));
            }

            // todo: this.toolStripMenuItem1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;

            return(writer.FTemplate);
        }
Exemple #3
0
        /// <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)
        {
            base.SetControlProperties(writer, ctrl);
            writer.SetControlProperty(ctrl, "ListTable", "TCmbAutoPopulated.TListTableEnum." + ctrl.GetAttribute("List"));

            if (ctrl.GetAttribute("List") != "UserDefinedList")
            {
                writer.Template.AddToCodelet("INITUSERCONTROLS", ctrl.controlName + ".InitialiseUserControl();" + Environment.NewLine);

                if (ctrl.HasAttribute("AllowDbNull"))
                {
                    writer.SetControlProperty(ctrl, "AllowDbNull", ctrl.GetAttribute("AllowDbNull"));
                }

                if (ctrl.HasAttribute("NullValueDesciption"))
                {
                    writer.SetControlProperty(ctrl, "NullValueDesciption", "\"" + ctrl.GetAttribute("NullValueDesciption") + "\"");
                }
            }
            else
            {
                // user defined lists have to be either filled in manual code
                // eg UC_GLJournals.ManualCode.cs, BeforeShowDetailsManual
                // or UC_GLTransactions.ManualCode.cs, LoadTransactions
            }

            if (ctrl.HasAttribute("ComboBoxWidth"))
            {
                writer.SetControlProperty(ctrl, "ComboBoxWidth", ctrl.GetAttribute("ComboBoxWidth"));
            }

            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);
        }
Exemple #5
0
        /// <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)
        {
            string NumberFormat = String.Empty;

            base.SetControlProperties(writer, ctrl);

            if ((ctrl.HasAttribute("ShowLabel") && (ctrl.GetAttribute("ShowLabel").ToLower() == "false")))
            {
                writer.SetControlProperty(ctrl, "ShowLabel", "false");
            }

            // Note: the control defaults to 'ShowLabel' true, so this doesn't need to be set to 'true' in code.

            writer.SetControlProperty(ctrl, "ControlMode", "TTxtNumericTextBox.TNumericTextBoxMode." + FControlMode);
            writer.SetControlProperty(ctrl, "DecimalPlaces", FDecimalPrecision.ToString());
            writer.SetControlProperty(ctrl, "NullValueAllowed", FNullValueAllowed.ToString().ToLower());

            if (ctrl.HasAttribute("Format"))
            {
                NumberFormat = ctrl.GetAttribute("Format");
            }

            if ((NumberFormat.StartsWith("PercentInteger")) ||
                (NumberFormat.StartsWith("PercentDecimal")))
            {
                writer.SetControlProperty(ctrl, "ShowPercentSign", "true");
            }

            return(writer.FTemplate);
        }
Exemple #6
0
        /// <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)
        {
            base.SetControlProperties(writer, ctrl);

            writer.SetControlProperty(ctrl, "Text", "\"" + ctrl.Label + "\"");
            writer.SetControlProperty(ctrl, "Margin", "new System.Windows.Forms.Padding(3, 7, 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)
        {
            base.SetControlProperties(writer, ctrl);

            writer.SetControlProperty(ctrl, "Renderer", "new ToolStripProfessionalRenderer(new TOpenPetraMenuColours())");
            writer.SetControlProperty(ctrl, "GripStyle", "ToolStripGripStyle.Visible");
            writer.SetControlProperty(ctrl, "GripMargin", "new System.Windows.Forms.Padding(3)");

            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);
        }
Exemple #10
0
        /// <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)
        {
            base.SetControlProperties(writer, ctrl);

            if ((ctrl.HasAttribute("ShowLabel") && (ctrl.GetAttribute("ShowLabel").ToLower() == "false")))
            {
                writer.SetControlProperty(ctrl, "ShowLabel", "false");
            }

            writer.SetControlProperty(ctrl, "DecimalPlaces", FDecimalPrecision.ToString());
            writer.SetControlProperty(ctrl, "NullValueAllowed", FNullValueAllowed.ToString().ToLower());
            writer.SetControlProperty(ctrl, "CurrencyCode", "\"###\"");

            return(writer.FTemplate);
        }
Exemple #11
0
 /// <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)
 {
     base.SetControlProperties(writer, ctrl);
     writer.SetControlProperty(ctrl, "FixedRows", "1");
     writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".CancelEditingWithEscapeKey = false;" + 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)
        {
            base.SetControlProperties(writer, ctrl);
            writer.SetControlProperty(ctrl, "FixedRows", "1");
            writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".CancelEditingWithEscapeKey = false;" + Environment.NewLine);

            // Grid AutoFind definition.  Unlike normal grids this applies whether columns and sorting are defined or not.
            // Checked list boxes enable first character auto find by default using column 1/
            // If you want something different it must be specified in YAML
            string autoFindStr = ctrl.controlName + ".AutoFindMode = TAutoFindModeEnum.";

            if (ctrl.HasAttribute("AutoFindMode"))
            {
                autoFindStr += ctrl.GetAttribute("AutoFindMode");
                TLogging.Log("Info: AutoFindMode for checked list box was set from explicit YAML attribute: " + ctrl.controlName);
            }
            else
            {
                autoFindStr += "FirstCharacter";
                TLogging.Log("Info: AutoFindMode for checked list box was set implicitly for: " + ctrl.controlName);
            }

            writer.Template.AddToCodelet("INITMANUALCODE", autoFindStr + ";" + Environment.NewLine);

            if (ctrl.HasAttribute("AutoFindColumn"))
            {
                writer.Template.AddToCodelet("INITMANUALCODE",
                                             ctrl.controlName + ".AutoFindColumn = " + ctrl.GetAttribute("AutoFindColumn") + ";" + Environment.NewLine);
            }

            return(writer.FTemplate);
        }
Exemple #13
0
        /// <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)
        {
            base.SetControlProperties(writer, ctrl);

            writer.SetControlProperty(ctrl, "Description", "\"" + ctrl.Label + "\"");

            return(writer.FTemplate);
        }
Exemple #14
0
        /// <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)
        {
            base.SetControlProperties(writer, ctrl);

            writer.SetControlProperty(ctrl, "LinkType", "TLinkTypes." + FLinkType);

            return(writer.FTemplate);
        }
Exemple #15
0
        /// <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)
        {
            base.SetControlProperties(writer, ctrl);

            if (TYml2Xml.HasAttribute(ctrl.xmlNode, "DefaultValue"))
            {
                writer.SetControlProperty(ctrl,
                                          "Text",
                                          "\"" + TYml2Xml.GetAttribute(ctrl.xmlNode, "DefaultValue") + "\"");
            }

            if ((TYml2Xml.HasAttribute(ctrl.xmlNode, "Multiline")) && (TYml2Xml.GetAttribute(ctrl.xmlNode, "Multiline") == "true"))
            {
                writer.SetControlProperty(ctrl, "Multiline", "true");

                if ((TYml2Xml.HasAttribute(ctrl.xmlNode, "WordWrap")) && (TYml2Xml.GetAttribute(ctrl.xmlNode, "WordWrap") == "false"))
                {
                    writer.SetControlProperty(ctrl, "WordWrap", "false");
                }

                if (TYml2Xml.HasAttribute(ctrl.xmlNode, "ScrollBars"))
                {
                    writer.SetControlProperty(ctrl, "ScrollBars", "ScrollBars." + TYml2Xml.GetAttribute(ctrl.xmlNode, "ScrollBars"));
                }

                if (TYml2Xml.HasAttribute(ctrl.xmlNode, "MinimumSize"))
                {
                    writer.SetControlProperty(ctrl, "MinimumSize", "new System.Drawing.Size(" + TYml2Xml.GetAttribute(ctrl.xmlNode,
                                                                                                                      "MinimumSize") + ")");
                }
            }

            if (TYml2Xml.HasAttribute(ctrl.xmlNode, "TextAlign"))
            {
                writer.SetControlProperty(ctrl, "TextAlign", "HorizontalAlignment." + TYml2Xml.GetAttribute(ctrl.xmlNode, "TextAlign"));
            }

            if (TYml2Xml.HasAttribute(ctrl.xmlNode, "CharacterCasing"))
            {
                writer.SetControlProperty(ctrl, "CharacterCasing", "CharacterCasing." +
                                          TYml2Xml.GetAttribute(ctrl.xmlNode, "CharacterCasing"));
            }

            if ((TYml2Xml.HasAttribute(ctrl.xmlNode, "PasswordEntry")) && (TYml2Xml.GetAttribute(ctrl.xmlNode, "PasswordEntry") == "true"))
            {
                writer.SetControlProperty(ctrl, "UseSystemPasswordChar", "true");
            }

            writer.Template.AddToCodelet("ASSIGNFONTATTRIBUTES",
                                         "this." + ctrl.controlName + ".Font = TAppSettingsManager.GetDefaultBoldFont();" + Environment.NewLine);

            return(writer.FTemplate);
        }
Exemple #16
0
        /// <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)
        {
            base.SetControlProperties(writer, ctrl);

            if (ctrl.GetAttribute("AutoComplete").EndsWith("History"))
            {
                writer.SetControlProperty(ctrl, "AcceptNewValues", "true");
                writer.SetEventHandlerToControl(ctrl.controlName,
                                                "AcceptNewEntries",
                                                "TAcceptNewEntryEventHandler",
                                                "FPetraUtilsObject.AddComboBoxHistory");
                writer.CallControlFunction(ctrl.controlName, "SetDataSourceStringList(\"\")");
                writer.Template.AddToCodelet("INITUSERCONTROLS",
                                             "FPetraUtilsObject.LoadComboBoxHistory(" + ctrl.controlName + ");" + 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("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);
        }
Exemple #18
0
        /// <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)
        {
            base.SetControlProperties(writer, ctrl);

            StringCollection OptionalValues = TYml2Xml.GetElements(ctrl.xmlNode, "OptionalValues");

            if (OptionalValues.Count > 0)
            {
                string formattedValues = "";
                string defaultValue    = "";

                foreach (string value in OptionalValues)
                {
                    if (formattedValues.Length > 0)
                    {
                        formattedValues += ",";
                    }

                    if (value.StartsWith("="))
                    {
                        formattedValues += "\"" + value.Substring(1).Trim() + "\"";
                        defaultValue     = value.Substring(1).Trim();
                    }
                    else
                    {
                        formattedValues += "\"" + value + "\"";
                    }
                }

                writer.CallControlFunction(ctrl.controlName, "Items.AddRange(new object[] {" + formattedValues + "})");

                if (defaultValue.Length > 0)
                {
                    writer.SetControlProperty(ctrl, "Text", "\"" + defaultValue + "\"");
                }
            }

            return(writer.FTemplate);
        }
Exemple #19
0
        /// <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)
        {
            base.SetControlProperties(writer, ctrl);

            if ((ctrl.HasAttribute("AlwaysHideLabel") && (ctrl.GetAttribute("AlwaysHideLabel").ToLower() == "true")))
            {
                writer.SetControlProperty(ctrl, "AlwaysHideLabel", "true");
            }
            else if ((ctrl.HasAttribute("ShowLabel") && (ctrl.GetAttribute("ShowLabel").ToLower() == "false")))
            {
                writer.SetControlProperty(ctrl, "ShowLabel", "false");
            }

            // Order is important: set Context before ControlMode and before CurrencyCode
            writer.SetControlProperty(ctrl, "Context", "this");
            writer.SetControlProperty(ctrl, "ControlMode", "TTxtNumericTextBox.TNumericTextBoxMode.Currency");
            writer.SetControlProperty(ctrl, "NullValueAllowed", FNullValueAllowed.ToString().ToLower());
            writer.SetControlProperty(ctrl, "CurrencyCode", "\"###\"");

            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);
        }
Exemple #21
0
        /// <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;
                        }
                    }
                }
            }
        }
Exemple #22
0
        /// <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);
        }