/// <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;
        }
示例#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)
        {
            // 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>
        /// Sets the properties of a control which are defined under "Actions:" in the .yaml file
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="ctrl"></param>
        /// <param name="AActionHandler"></param>
        public virtual void SetControlActionProperties(TFormWriter writer, TControlDef ctrl, TActionHandler AActionHandler)
        {
            if (AActionHandler.actionImage.Length > 0)
            {
                /* Get the name of the image for the toolbar button
                 * and put it into the resources.
                 * The images must be in the directory specified by the ResourceDir command line parameter
                 */
                writer.SetControlProperty(ctrl, "Image",
                    "((System.Drawing.Bitmap)resources" + ctrl.controlType + ".GetObject(\"" + ctrl.controlName + ".Glyph\"))");
                writer.AddImageToResource(ctrl.controlName, AActionHandler.actionImage, "Bitmap");
            }

            if ((AActionHandler.actionTooltip.Length > 0) && (ctrl.controlTypePrefix != "btn"))
            {
                writer.SetControlProperty(ctrl, "ToolTipText", "\"" + AActionHandler.actionTooltip + "\"");
            }
        }
        /// <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 + "\"");

            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 (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;
        }
        /// <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;
        }
        /// <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;
        }
        /// <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;
        }
        /// <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)
        {
            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)
        {
            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;
        }
示例#12
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);

            // 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;
        }
示例#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, "FixedRows", "1");
     writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".CancelEditingWithEscapeKey = false;" + Environment.NewLine);
     return writer.FTemplate;
 }
示例#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)
        {
            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)
        {
            string Width;

            base.SetControlProperties(writer, ctrl);

            if (ctrl.GetAttribute("Height").ToString() == "36")  // 36 is the Height of pnlButtons/pnlDetailButtons Panels that have ControlsOrientation=horizontal and whose Buttons have been shrinked in size to 23 Pixels by the ButtonGenerator - and
            {                                                    // whose 'Height' Element hasn't been set in the YAML file...
                if (ctrl.IsGridButtonPanel)
                {
                    Width = ctrl.GetAttribute("Width").ToString();

                    // Somehow we can run into a situation where Width isn't specified. This would lead to writing out an
                    // invalid Size Property. To prevent that we set it to some value which we can find easily in files and
                    // which will be ignored anyway at runtime as the Panel will be Docked with 'DockStyle.Bottom'!
                    if (Width.Length == 0)
                    {
                        Width = "1111";
                    }

                    FDefaultHeight = 28;

                    TLogging.LogAtLevel(1, "Adjusted Height of Panel '" + ctrl.controlName + "' as it is a horizontal Grid Button Panel");
                    writer.SetControlProperty(ctrl, "Size", "new System.Drawing.Size(" +
                        Width + ", " + FDefaultHeight.ToString() + ")");

                    writer.SetControlProperty(ctrl, "BackColor", "System.Drawing.Color.Green");
                }
            }

            return writer.FTemplate;
        }
        private void ProcessButtonsForMaxWidthSizing(TFormWriter writer, TControlDef ctrl, SortedSet <int>ButtonWidths,
            SortedSet <int>ButtonTops, List <TControlDef>Buttons, out int NewButtonWidthForAll)
        {
            const int MIN_BUTTON_WIDTH = 76; // 76 seems to be pretty much a standard width (on the Windows OS)
            int LeftPos = PanelLayoutGenerator.MARGIN_LEFT;
            int ButtonCounter = 0;
            bool EnforceMinimumWidth = false;
            bool RepositionButtonsHorizontally = ButtonTops.Max == ButtonTops.Min;

            NewButtonWidthForAll = MIN_BUTTON_WIDTH;

            TLogging.LogAtLevel(1, "Max. Button Width: " + ButtonWidths.Max.ToString() + ", Number of Buttons: " + Buttons.Count.ToString());

            if ((!ctrl.HasAttribute("AutoButtonMaxWidthsEnforceMinimumWidth")
                 || (ctrl.GetAttribute("AutoButtonMaxWidthsEnforceMinimumWidth").ToLower() == "true")))
            {
                EnforceMinimumWidth = true;
            }

            if ((EnforceMinimumWidth)
                && (ButtonWidths.Max < MIN_BUTTON_WIDTH))
            {
                if (Buttons.Count > 0)
                {
                    NewButtonWidthForAll = MIN_BUTTON_WIDTH;
                    TLogging.LogAtLevel(1,
                        "Max. Button width (" + ButtonWidths.Max.ToString() + ") was smaller than MIN_BUTTON_WIDTH, adjusting to the latter!");
                }
            }
            else
            {
                NewButtonWidthForAll = ButtonWidths.Max;
            }

            foreach (var Button in Buttons)
            {
// TLogging.LogAtLevel(1, "Button ' " + Button.controlName + "': Width = " + Button.GetAttribute("Width"));

                if ((!Button.HasAttribute("NoLabel")
                     || (Button.GetAttribute("NoLabel").ToLower() == "false")))
                {
                    TLogging.LogAtLevel(1, "Applying Width to Button '" + Button.controlName + "'");
                    writer.SetControlProperty(Button, "Size", "new System.Drawing.Size(" +
                        NewButtonWidthForAll.ToString() + ", " + Button.GetAttribute("Height").ToString() + ")");

                    if (ButtonCounter != 0)
                    {
                        LeftPos += NewButtonWidthForAll + PanelLayoutGenerator.HORIZONTAL_SPACE;
                    }
                }
                else
                {
                    TLogging.LogAtLevel(
                        1,
                        "Not applying Width to Button '" + Button.controlName + "' as its 'NoLabel' Element is set to 'true'! (Current Width: " +
                        Button.Width.ToString() + ")");

                    if (ButtonCounter != 0)
                    {
                        LeftPos += Button.Width + PanelLayoutGenerator.HORIZONTAL_SPACE;
                    }
                }

                if (RepositionButtonsHorizontally)
                {
                    writer.SetControlProperty(Button, "Location", String.Format("new System.Drawing.Point({0}, {1})", LeftPos, ButtonTops.Max));
                    TLogging.LogAtLevel(1,
                        "Repositioned Button '" + Button.controlName + "' horizontally. New Location: " + LeftPos.ToString() + "," +
                        ButtonTops.Max.ToString());
                }

                //               TLogging.LogAtLevel(1, "Button '" + Button.controlName + "' Width: " + Button.Width.ToString());

                ButtonCounter++;
            }
        }
        /// <summary>
        /// Handle 'special' Panels
        /// </summary>
        public override void ProcessChildren(TFormWriter writer, TControlDef ctrl)
        {
            SortedSet <int>ButtonWidths = new SortedSet <int>();
            SortedSet <int>ButtonTops = new SortedSet <int>();
            List <TControlDef>Buttons = new List <TControlDef>();

            int NewButtonWidthForAll = -1;

            if (ctrl.controlName == PNL_FILTER_AND_FIND)
            {
                listNumericColumns.Clear();

                writer.Template.SetCodelet("FILTERANDFIND", "true");

                writer.SetControlProperty(ctrl, "Dock", "Left");
                writer.SetControlProperty(ctrl, "BackColor", "System.Drawing.Color.LightSteelBlue");
                writer.SetControlProperty(ctrl, "Width", "0");

                if (!ctrl.HasAttribute("ExpandedWidth"))
                {
                    writer.Template.SetCodelet("FINDANDFILTERINITIALWIDTH", "150");
                }
                else
                {
                    writer.Template.SetCodelet("FINDANDFILTERINITIALWIDTH", ctrl.GetAttribute("ExpandedWidth"));
                }

                if ((ctrl.HasAttribute("InitiallyExpanded"))
                    && (ctrl.GetAttribute("InitiallyExpanded").ToLower() != "false"))
                {
                    writer.Template.SetCodelet("FINDANDFILTERINITIALLYEXPANDED", "true");
                }
                else
                {
                    writer.Template.SetCodelet("FINDANDFILTERINITIALLYEXPANDED", "false");
                }

                if (!ctrl.HasAttribute("ShowApplyFilterButton"))
                {
                    writer.Template.SetCodelet("FINDANDFILTERAPPLYFILTERBUTTONCONTEXT", "TUcoFilterAndFind.FilterContext.None");
                }
                else
                {
                    writer.Template.SetCodelet("FINDANDFILTERAPPLYFILTERBUTTONCONTEXT", "TUcoFilterAndFind." +
                        ctrl.GetAttribute("ShowApplyFilterButton"));
                }

                if (!ctrl.HasAttribute("ShowKeepFilterTurnedOnButton"))
                {
                    writer.Template.SetCodelet("FINDANDFILTERSHOWKEEPFILTERTURNEDONBUTTONCONTEXT", "TUcoFilterAndFind.FilterContext.None");
                }
                else
                {
                    writer.Template.SetCodelet("FINDANDFILTERSHOWKEEPFILTERTURNEDONBUTTONCONTEXT", "TUcoFilterAndFind." +
                        ctrl.GetAttribute("ShowKeepFilterTurnedOnButton"));
                }

                if (!ctrl.HasAttribute("ShowFilterIsAlwaysOnLabel"))
                {
                    writer.Template.SetCodelet("FINDANDFILTERSHOWFILTERISALWAYSONLABELCONTEXT", "TUcoFilterAndFind.FilterContext.None");
                }
                else
                {
                    writer.Template.SetCodelet("FINDANDFILTERSHOWFILTERISALWAYSONLABELCONTEXT", "TUcoFilterAndFind." +
                        ctrl.GetAttribute("ShowFilterIsAlwaysOnLabel"));
                }

                writer.Template.SetCodelet("CUSTOMDISPOSING",
                    "if (FFilterAndFindObject != null && FFilterAndFindObject.FilterFindPanel != null)" + Environment.NewLine +
                    "{" + Environment.NewLine +
                    "    FFilterAndFindObject.FilterFindPanel.Dispose();" + Environment.NewLine +
                    "}");

                XmlNodeList controlAttributesList = null;
                XmlNode ctrlNode = ctrl.xmlNode;

                foreach (XmlNode child in ctrlNode.ChildNodes)
                {
                    if (child.Name == "ControlAttributes")
                    {
                        controlAttributesList = child.ChildNodes;
                    }
                }

                ProcessTemplate snippetFilterAndFindDeclarations = writer.Template.GetSnippet("FILTERANDFINDDECLARATIONS");
                writer.Template.InsertSnippet("FILTERANDFINDDECLARATIONS", snippetFilterAndFindDeclarations);

                ProcessTemplate snippetFilterAndFindMethods = writer.Template.GetSnippet("FILTERANDFINDMETHODS");

                writer.Template.SetCodelet("INDIVIDUALFILTERPANELS", "");
                writer.Template.SetCodelet("INDIVIDUALEXTRAFILTERPANELS", "");
                writer.Template.SetCodelet("INDIVIDUALFINDPANELS", "");
                writer.Template.SetCodelet("INDIVIDUALFILTERFINDPANELEVENTS", "");
                writer.Template.SetCodelet("INDIVIDUALFILTERFINDPANELPROPERTIES", "");
                writer.Template.SetCodelet("NUMERICFILTERFINDCOLUMNS", "");
                writer.Template.SetCodelet("FILTERBUTTON", "");

                if (ctrl.HasAttribute("FilterButton"))
                {
                    // This specifies the button text (optional) and status bar text separated by semi-colon
                    // eg FilterButton=F&ilter;Click to Toggle the Analysis Values filter on and off
                    string attVal = ctrl.GetAttribute("FilterButton");
                    int pos = attVal.IndexOf(';');

                    if ((pos >= 0) && (pos < attVal.Length - 1))
                    {
                        string codelet = String.Empty;

                        if (pos > 0)
                        {
                            codelet = String.Format("chkToggleFilter.Text = \"{0}\";{1}", attVal.Substring(0, pos), Environment.NewLine);
                        }

                        codelet += String.Format("FPetraUtilsObject.SetStatusBarText(chkToggleFilter, \"{0}\");", attVal.Substring(pos + 1));
                        writer.Template.SetCodelet("FILTERBUTTON", codelet);
                    }
                }

                // Process each of the three Filter/Find definitions
                int TotalPanels = ProcessIndividualFilterFindPanel(writer,
                    "FilterControls",
                    "Filter",
                    "StandardFilter",
                    controlAttributesList,
                    "INDIVIDUALFILTERPANELS");
                TotalPanels += ProcessIndividualFilterFindPanel(writer,
                    "ExtraFilterControls",
                    "Filter",
                    "ExtraFilter",
                    controlAttributesList,
                    "INDIVIDUALEXTRAFILTERPANELS");
                TotalPanels += ProcessIndividualFilterFindPanel(writer, "FindControls", "Find", "Find", controlAttributesList, "INDIVIDUALFINDPANELS");

                if (TotalPanels == 0)
                {
                    throw new Exception("Found no controls for the Filter/Find panel");
                }

                // Manual code methods
                if (FCodeStorage.ManualFileExistsAndContains("void CreateFilterFindPanelsManual()"))
                {
                    writer.Template.SetCodelet("CREATEFILTERFINDPANELSMANUAL", "CreateFilterFindPanelsManual();" + Environment.NewLine);
                }
                else
                {
                    writer.Template.SetCodelet("CREATEFILTERFINDPANELSMANUAL", "");
                }

                if (FCodeStorage.ManualFileExistsAndContains("void FilterToggledManual(bool"))
                {
                    writer.Template.SetCodelet("FILTERTOGGLEDMANUAL", "FilterToggledManual(pnlFilterAndFind.Width == 0);" + Environment.NewLine);
                }
                else
                {
                    writer.Template.SetCodelet("FILTERTOGGLEDMANUAL", "");
                }

                if (FCodeStorage.ManualFileExistsAndContains("void ApplyFilterManual(ref"))
                {
                    writer.Template.SetCodelet("APPLYFILTERMANUAL", "ApplyFilterManual(ref AFilterString);" + Environment.NewLine);
                }
                else
                {
                    writer.Template.SetCodelet("APPLYFILTERMANUAL", "");
                }

                if (FCodeStorage.ManualFileExistsAndContains("bool IsMatchingRowManual("))
                {
                    writer.Template.SetCodelet("ISMATCHINGROW", "IsMatchingRowManual");
                }
                else
                {
                    writer.Template.SetCodelet("ISMATCHINGROW", "FFilterAndFindObject.FindPanelControls.IsMatchingRow");
                }

                // Write the whole thing out
                writer.Template.InsertSnippet("FILTERANDFINDMETHODS", snippetFilterAndFindMethods);
            }
            else
            {
                TControlDef subChildCtrl;

                TLogging.LogAtLevel(1, "PanelGenerator:Processing Children '" + ctrl.controlName + "' (about to call base method)");

                base.ProcessChildren(writer, ctrl);

                foreach (TControlDef childCtrl in ctrl.Children)
                {
                    TLogging.LogAtLevel(1, "Child Name: " + childCtrl.controlName);

                    if ((childCtrl.HasAttribute("AutoButtonMaxWidths"))
                        || (childCtrl.GetAttribute("AutoButtonMaxWidths") == "true"))
                    {
                        TLogging.LogAtLevel(1, "Control '" + childCtrl.controlName + "' has AutoButtonMaxWidths = true!");


                        XmlNode controlsNode = TXMLParser.GetChild(childCtrl.xmlNode, "Controls");

                        if ((controlsNode != null) && TYml2Xml.GetChildren(controlsNode, true)[0].Name.StartsWith("Row"))
                        {
                            TLogging.LogAtLevel(1, "Row processing");

                            // this defines the layout with several rows with several controls per row
                            foreach (XmlNode row in TYml2Xml.GetChildren(controlsNode, true))
                            {
                                StringCollection controls = TYml2Xml.GetElements(row);

                                foreach (string ctrlname in controls)
                                {
                                    subChildCtrl = writer.CodeStorage.GetControl(ctrlname);

                                    TLogging.LogAtLevel(1, "Child: '" + subChildCtrl.controlName + "'");

                                    ProcessButtonsForMaxWidthDetermination(writer, subChildCtrl, ButtonWidths, ButtonTops, Buttons);
                                }

                                ProcessButtonsForMaxWidthSizing(writer, childCtrl, ButtonWidths, ButtonTops, Buttons, out NewButtonWidthForAll);
                            }
                        }
                        else
                        {
                            if ((controlsNode != null) && (childCtrl.Children.Count != 0))
                            {
                                TLogging.LogAtLevel(1, "Controls processing");

                                foreach (TControlDef subChildCtrl2 in childCtrl.Children)
                                {
                                    TLogging.LogAtLevel(1, "Child: '" + subChildCtrl2.controlName + "'");

                                    ProcessButtonsForMaxWidthDetermination(writer, subChildCtrl2, ButtonWidths, ButtonTops, Buttons);
                                }

                                ProcessButtonsForMaxWidthSizing(writer, childCtrl, ButtonWidths, ButtonTops, Buttons, out NewButtonWidthForAll);
                            }
                        }

                        if ((Buttons.Count > 0)
                            && ((childCtrl.HasAttribute("AutoButtonMaxWidthsAutoSizesContainerWidth"))
                                && ((childCtrl.GetAttribute("AutoButtonMaxWidthsAutoSizesContainerWidth").ToLower() == "true"))))
                        {
                            int NewContainerWidth = 5 + 7 + (Buttons.Count * NewButtonWidthForAll) + ((Buttons.Count - 1) * 5); // + ((Buttons.Count - 1) * 12) - (Buttons.Count * 2);
                            TLogging.LogAtLevel(1, "NewContainerWidth: " + NewContainerWidth.ToString());
                            writer.SetControlProperty(childCtrl, "Size", "new System.Drawing.Size(" +
                                NewContainerWidth.ToString() + ", " + childCtrl.GetAttribute("Height").ToString() + ")");
                        }

                        Buttons.Clear();
                        ButtonWidths.Clear();
                    }
                }
            }
        }
        /// <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 (!FManualExtendedPanel)
            {
                writer.SetControlProperty(ctrl, "ShadowOffSet", "0");
                writer.SetControlProperty(ctrl, "RoundCornerRadius", "0");
                writer.SetControlProperty(ctrl, "GradientStartColor", "System.Drawing.Color.AntiqueWhite");
                writer.SetControlProperty(ctrl, "GradientEndColor", "System.Drawing.Color.LightGray");
                writer.SetControlProperty(ctrl, "GradientDirection", "System.Drawing.Drawing2D.LinearGradientMode.Vertical");
            }
            else
            {
                if (ctrl.HasAttribute("ShadowOffSet"))
                {
                    writer.SetControlProperty(ctrl, "ShadowOffSet", ctrl.GetAttribute("ShadowOffSet"));
                }
                else
                {
                    writer.SetControlProperty(ctrl, "ShadowOffSet", "0");
                }

                if (ctrl.HasAttribute("RoundCornerRadius"))
                {
                    writer.SetControlProperty(ctrl, "RoundCornerRadius", ctrl.GetAttribute("RoundCornerRadius"));
                }
                else
                {
                    writer.SetControlProperty(ctrl, "RoundCornerRadius", "0");
                }

                if (ctrl.HasAttribute("GradientDirection"))
                {
                    writer.SetControlProperty(ctrl, "GradientDirection", ctrl.GetAttribute("GradientDirection"));
                }
                else
                {
                    writer.SetControlProperty(ctrl, "GradientDirection", "System.Drawing.Drawing2D.LinearGradientMode.Horizontal");
                }

                if (ctrl.HasAttribute("GradientStartColor"))
                {
                    writer.SetControlProperty(ctrl, "GradientStartColor", ctrl.GetAttribute("GradientStartColor"));
                }
                else
                {
                    writer.SetControlProperty(ctrl, "GradientStartColor", "System.Drawing.Color.Yellow");
                }

                if (ctrl.HasAttribute("GradientEndColor"))
                {
                    writer.SetControlProperty(ctrl, "GradientEndColor", ctrl.GetAttribute("GradientEndColor"));
                }
                else
                {
                    writer.SetControlProperty(ctrl, "GradientEndColor", "System.Drawing.Color.Green");
                }

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

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

            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);

            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;
        }
        /// <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)
        {
            writer.AddContainer(ctrl.controlName + ".Panel1");
            writer.AddContainer(ctrl.controlName + ".Panel2");

            base.SetControlProperties(writer, ctrl);

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

            if (ctrl.HasAttribute("SplitterOrientation"))
            {
                writer.SetControlProperty(ctrl, "Orientation", "System.Windows.Forms.Orientation." +
                    StringHelper.UpperCamelCase(ctrl.GetAttribute("SplitterOrientation")));
            }

            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>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            ProcessTemplate snippetDynamicTabPage = null;
            ProcessTemplate snippetTabPageSelectionChanged = null;
            string IgnoreFirstTabSel = String.Empty;

            base.SetControlProperties(writer, ctrl);

            writer.SetControlProperty(ctrl, "DrawMode", "System.Windows.Forms.TabDrawMode.OwnerDrawFixed");

            // by default the tab order cannot be changed
            if (!ctrl.HasAttribute("DragTabPageEnabled") || (ctrl.GetAttribute("DragTabPageEnabled").ToLower() == "false"))
            {
                writer.SetControlProperty(ctrl, "AllowDrop", "false");
            }

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

            writer.Template.SetCodelet("TABPAGECTRL", ctrl.controlName);

            if (ctrl.HasAttribute("IgnoreFirstTabPageSelectionChange")
                && (ctrl.GetAttribute("IgnoreFirstTabPageSelectionChange").ToLower() == "true"))
            {
                IgnoreFirstTabSel += "if (FirstTabPageSelectionChanged)" + Environment.NewLine;
                IgnoreFirstTabSel += "{" + Environment.NewLine;
                IgnoreFirstTabSel += "    // The first time we run this Method we exit straight away!" + Environment.NewLine;
                IgnoreFirstTabSel += "    return;" + Environment.NewLine;
                IgnoreFirstTabSel += "}" + Environment.NewLine + Environment.NewLine + Environment.NewLine;

                writer.Template.AddToCodelet("IGNOREFIRSTTABPAGESELECTIONCHANGEDEVENT", IgnoreFirstTabSel);
            }

            if (IgnoreFirstTabSel != String.Empty)
            {
                writer.Template.SetCodelet("FIRSTTABPAGESELECTIONCHANGEDVAR", "true");
            }

            if (ctrl.HasAttribute("LoadPagesDynamically") && (ctrl.GetAttribute("LoadPagesDynamically").ToLower() == "true"))
            {
                snippetDynamicTabPage = writer.Template.GetSnippet("DYNAMICTABPAGE");

                if (IgnoreFirstTabSel != String.Empty)
                {
                    snippetDynamicTabPage.SetCodelet("FIRSTTABPAGESELECTIONCHANGEDVAR", "true");
                }

                if (writer.IsUserControlTemplate)
                {
                    snippetDynamicTabPage.SetCodelet("ISUSERCONTROL", "true");
                }

                writer.Template.InsertSnippet("DYNAMICTABPAGEBASICS", snippetDynamicTabPage);

                snippetTabPageSelectionChanged = writer.Template.GetSnippet("TABPAGESELECTIONCHANGED");

                if (writer.IsUserControlTemplate)
                {
                    snippetTabPageSelectionChanged.SetCodelet("ISUSERCONTROL", "true");
                }

                writer.Template.InsertSnippet("DYNAMICTABPAGEUSERCONTROLSELECTIONCHANGED", snippetTabPageSelectionChanged);
            }
            else
            {
                writer.Template.AddToCodelet("DYNAMICTABPAGEUSERCONTROLSELECTIONCHANGED", "");
            }

            // writer.Template.FTemplateCode.Contains is not very clean, since it might be in a snippet or in an ifdef that will not be part of the resulting file
            if ((writer.CodeStorage.ManualFileExistsAndContains("void TabSelectionChanged"))
                || (writer.Template.FTemplateCode.Contains("void TabSelectionChanged"))
                || (snippetDynamicTabPage != null))
            {
                AssignEventHandlerToControl(writer, ctrl, "SelectedIndexChanged", "TabSelectionChanged");

                writer.Template.AddToCodelet("INITMANUALCODE", ctrl.controlName + ".SelectedIndex = 0;" + Environment.NewLine);
                writer.Template.AddToCodelet("INITMANUALCODE", "TabSelectionChanged(null, null);" + 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);

            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;
        }
        /// <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;
        }
示例#25
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, "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)
        {
            string CntrlNameWithoutPrefix = ctrl.controlName.Substring(3);
            string CntrlVaribleNameWithoutPrefix;
            StringCollection DynamicControlTypes;

            base.SetControlProperties(writer, ctrl);
            writer.SetControlProperty(ctrl, "Dock", "Fill");

            if (ctrl.HasAttribute("ToolTip"))
            {
                writer.SetControlProperty(ctrl, "ToolTipText", "\"" + ctrl.GetAttribute("ToolTip") + "\"");
            }

            #region Dynamic TabPage UserControl loading ('LoadPageDynamically' attribute and 'DynamicControlTypes' Element)

            if (ctrl.HasAttribute("LoadPageDynamically") && (ctrl.GetAttribute("LoadPageDynamically").ToLower() == "true"))
            {
                if ((!ctrl.HasAttribute("DynamicControlType")
                     && (TYml2Xml.GetElements(ctrl.xmlNode, "DynamicControlTypes").Count == 0)))
                {
                    throw new Exception(
                        "TabPage '" + ctrl.controlName +
                        "': Either the 'DynamicControlType' or the 'DynamicControlTypes' property need to be specified if 'LoadPageDynamically' is specified");
                }
                else if (ctrl.HasAttribute("DynamicControlType"))
                {
                    DynamicControlTypes = new StringCollection();
                    DynamicControlTypes.Add(ctrl.GetAttribute("DynamicControlType"));
                }
                else
                {
                    DynamicControlTypes = TYml2Xml.GetElements(ctrl.xmlNode, "DynamicControlTypes");
                }

                ProcessTemplate snippetUserControlInitialisation = writer.Template.GetSnippet("USERCONTROLINITIALISATION");
                ProcessTemplate snippetUserControlSetupMethod = writer.Template.GetSnippet("DYNAMICTABPAGEUSERCONTROLSETUPMETHOD");

                for (int Counter = 0; Counter < DynamicControlTypes.Count; Counter = Counter + 2)
                {
                    if (DynamicControlTypes.Count == 1)
                    {
                        CntrlVaribleNameWithoutPrefix = CntrlNameWithoutPrefix;
                    }
                    else
                    {
                        CntrlVaribleNameWithoutPrefix = CntrlNameWithoutPrefix + DynamicControlTypes[Counter + 1];
                    }

//Console.WriteLine("CntrlVaribleNameWithoutPrefix: " + CntrlVaribleNameWithoutPrefix + "; Counter: " + Counter.ToString());
                    writer.Template.AddToCodelet("DYNAMICTABPAGEUSERCONTROLDECLARATION",
                        "private " + DynamicControlTypes[Counter] + " FUco" + CntrlVaribleNameWithoutPrefix + ";" + Environment.NewLine);

                    // Declare an Enum for each dynamically loaded TabPage
                    string DynamicTabPageEnums = "";
                    DynamicTabPageEnums += "///<summary>Denotes dynamic loadable UserControl" + " FUco" + CntrlVaribleNameWithoutPrefix +
                                           "</summary>" + Environment.NewLine;
                    DynamicTabPageEnums += "dluc" + CntrlVaribleNameWithoutPrefix + "," + Environment.NewLine;
                    writer.Template.AddToCodelet("DYNAMICTABPAGEUSERCONTROLENUM", DynamicTabPageEnums);

                    // Dispose UserControl for each dynamically loaded TabPage
                    string CustomDisposingOfControl = "";
                    CustomDisposingOfControl += "if (FUco" + CntrlVaribleNameWithoutPrefix + " != null)" + Environment.NewLine;
                    CustomDisposingOfControl += "{" + Environment.NewLine;
                    CustomDisposingOfControl += "    FUco" + CntrlVaribleNameWithoutPrefix + ".Dispose();" + Environment.NewLine;
                    CustomDisposingOfControl += "}" + Environment.NewLine;
                    writer.Template.AddToCodelet("CUSTOMDISPOSING", CustomDisposingOfControl);


                    // Initialise each dynamically loaded TabPage

                    ProcessTemplate snippetUserControlSetup = writer.Template.GetSnippet("DYNAMICTABPAGEUSERCONTROLSETUP");
                    ProcessTemplate snippetTabPageSubseqAct = writer.Template.GetSnippet("DYNAMICTABPAGESUBSEQUENTACTIVATION");

                    if (writer.IsUserControlTemplate)
                    {
                        snippetUserControlSetup.SetCodelet("ISUSERCONTROL", "true");
                    }

                    snippetUserControlInitialisation.SetCodelet("CONTROLNAME", ctrl.controlName);
                    snippetUserControlInitialisation.SetCodelet("CONTROLNAMEWITHOUTPREFIX", CntrlNameWithoutPrefix);

                    snippetUserControlSetup.SetCodelet("CONTROLNAME", ctrl.controlName);

                    snippetUserControlInitialisation.SetCodelet("TABCONTROLNAME", TabControlGenerator.TabControlName);
                    snippetUserControlSetup.SetCodelet("DYNAMICCONTROLTYPE", DynamicControlTypes[Counter]);

                    ProcessTemplate snippetUserControlLoading = writer.Template.GetSnippet("USERCONTROLLOADING");

                    if ((ctrl.HasAttribute("SeparateDynamicControlSetupMethod")
                         && (ctrl.GetAttribute("SeparateDynamicControlSetupMethod").ToLower() == "true"))
                        || (DynamicControlTypes.Count > 1))
                    {
                        if (DynamicControlTypes.Count == 1)
                        {
                            snippetUserControlInitialisation.SetCodelet("TABKEY", "TDynamicLoadableUserControls.dluc" + CntrlNameWithoutPrefix + ")");
                            snippetUserControlSetupMethod = writer.Template.GetSnippet("DYNAMICTABPAGEUSERCONTROLSETUPMETHOD");
                            snippetUserControlSetup.SetCodelet("CONTROLNAMEWITHOUTPREFIX", CntrlNameWithoutPrefix);
                            snippetUserControlSetupMethod.SetCodelet("DYNLOADINFO", "UserControl 'FUco" + CntrlNameWithoutPrefix + "'.");
                            snippetUserControlSetupMethod.SetCodelet("USERORTABCONTROLNAMEWITHOUTPREFIX", "UserControl" + CntrlNameWithoutPrefix);
                            snippetUserControlSetupMethod.InsertSnippet("DYNAMICTABPAGEUSERCONTROLSETUPINLINE2", snippetUserControlSetup);
                            writer.Template.InsertSnippet("DYNAMICTABPAGEUSERCONTROLSETUPMETHODS", snippetUserControlSetupMethod);

                            snippetUserControlInitialisation.AddToCodelet("DYNAMICTABPAGEUSERCONTROLSETUPINLINE1",
                                "SetupUserControl" + CntrlNameWithoutPrefix + "();" + Environment.NewLine);

                            snippetTabPageSubseqAct.SetCodelet("CONTROLNAME", ctrl.controlName);
                            snippetTabPageSubseqAct.SetCodelet("CONTROLNAMEWITHOUTPREFIX", CntrlNameWithoutPrefix);
                            snippetUserControlInitialisation.InsertSnippet("DYNAMICTABPAGESUBSEQUENTACTIVATION", snippetTabPageSubseqAct);

                            writer.Template.InsertSnippet("DYNAMICTABPAGEUSERCONTROLINITIALISATION", snippetUserControlInitialisation);

                            snippetUserControlLoading.SetCodelet("CONTROLNAMEWITHOUTPREFIX", CntrlNameWithoutPrefix);
                        }
                        else
                        {
                            snippetUserControlInitialisation.SetCodelet("TABKEY", "Get" + CntrlNameWithoutPrefix + "VariableUC())");
                            ProcessTemplate snippetUserControlSetupMethodMultiUC = writer.Template.GetSnippet(
                                "DYNAMICTABPAGEUSERCONTROLSETUPMULTIUCPART");
                            ProcessTemplate snippetTabPageSubseqActIfStmt = writer.Template.GetSnippet("DYNAMICTABPAGEUSERCONTROLSETUPMULTIUCPART");

                            snippetUserControlSetup.SetCodelet("CONTROLNAMEWITHOUTPREFIX", CntrlVaribleNameWithoutPrefix);
                            snippetUserControlSetupMethod.SetCodelet("DYNLOADINFO", "TabPage '" + ctrl.controlName + "' with varying UserControls.");
                            snippetUserControlSetupMethod.SetCodelet("USERORTABCONTROLNAMEWITHOUTPREFIX",
                                "VariableUserControlForTabPage" + CntrlNameWithoutPrefix);
                            snippetUserControlSetupMethodMultiUC.SetCodelet("TABCONTROLNAMEWITHOUTPREFIX", CntrlNameWithoutPrefix);
                            snippetUserControlSetupMethodMultiUC.SetCodelet("USERCONTROLNAMEWITHOUTPREFIX", CntrlVaribleNameWithoutPrefix);

                            snippetUserControlSetupMethodMultiUC.InsertSnippet("MULTIUCCODE", snippetUserControlSetup);

                            if (Counter < DynamicControlTypes.Count - 2)
                            {
                                snippetUserControlSetupMethodMultiUC.SetCodelet("ELSESTATEMENT", "else");
                                snippetTabPageSubseqActIfStmt.SetCodelet("ELSESTATEMENT", "else");
                            }

                            snippetUserControlSetupMethod.InsertSnippet("DYNAMICTABPAGEUSERCONTROLSETUPINLINE2", snippetUserControlSetupMethodMultiUC);

                            snippetTabPageSubseqActIfStmt.SetCodelet("TABCONTROLNAMEWITHOUTPREFIX", CntrlNameWithoutPrefix);
                            snippetTabPageSubseqActIfStmt.SetCodelet("USERCONTROLNAMEWITHOUTPREFIX", CntrlVaribleNameWithoutPrefix);

                            snippetTabPageSubseqAct.SetCodelet("CONTROLNAME", ctrl.controlName);
                            snippetTabPageSubseqAct.SetCodelet("CONTROLNAMEWITHOUTPREFIX", CntrlVaribleNameWithoutPrefix);

                            snippetTabPageSubseqActIfStmt.InsertSnippet("MULTIUCCODE", snippetTabPageSubseqAct);
                            snippetUserControlInitialisation.InsertSnippet("DYNAMICTABPAGESUBSEQUENTACTIVATION", snippetTabPageSubseqActIfStmt);

                            if (Counter + 2 == DynamicControlTypes.Count)
                            {
                                writer.Template.InsertSnippet("DYNAMICTABPAGEUSERCONTROLSETUPMETHODS", snippetUserControlSetupMethod);
                                snippetUserControlInitialisation.AddToCodelet("DYNAMICTABPAGEUSERCONTROLSETUPINLINE1",
                                    "SetupVariableUserControlForTabPage" + CntrlNameWithoutPrefix + "();" + Environment.NewLine);
                                writer.Template.InsertSnippet("DYNAMICTABPAGEUSERCONTROLINITIALISATION", snippetUserControlInitialisation);
                            }

                            snippetUserControlLoading.SetCodelet("CONTROLNAMEWITHOUTPREFIX", CntrlVaribleNameWithoutPrefix);
                        }
                    }
                    else
                    {
                        snippetUserControlInitialisation.SetCodelet("TABKEY", "TDynamicLoadableUserControls.dluc" + CntrlNameWithoutPrefix + ")");
                        snippetUserControlSetup.SetCodelet("CONTROLNAMEWITHOUTPREFIX", CntrlNameWithoutPrefix);
                        snippetUserControlInitialisation.InsertSnippet("DYNAMICTABPAGEUSERCONTROLSETUPINLINE1", snippetUserControlSetup);

                        snippetTabPageSubseqAct.SetCodelet("CONTROLNAME", ctrl.controlName);
                        snippetTabPageSubseqAct.SetCodelet("CONTROLNAMEWITHOUTPREFIX", CntrlNameWithoutPrefix);
                        snippetUserControlInitialisation.InsertSnippet("DYNAMICTABPAGESUBSEQUENTACTIVATION", snippetTabPageSubseqAct);

                        writer.Template.InsertSnippet("DYNAMICTABPAGEUSERCONTROLINITIALISATION", snippetUserControlInitialisation);

                        snippetUserControlLoading.SetCodelet("CONTROLNAMEWITHOUTPREFIX", CntrlNameWithoutPrefix);
                    }

                    // Dynamically load each dynamically loaded TabPage
                    snippetUserControlLoading.SetCodelet("CONTROLNAME", ctrl.controlName);
                    snippetUserControlLoading.SetCodelet("DYNAMICCONTROLTYPE", DynamicControlTypes[Counter]);
                    writer.Template.InsertSnippet("DYNAMICTABPAGEUSERCONTROLLOADING", snippetUserControlLoading);
                }
            }

            #endregion

            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>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;
        }
示例#29
0
        /// <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;
        }
示例#30
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)
        {
            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;
        }