Beispiel #1
0
        private static void AddImplicitProperties(IVB6FormObject formObject)
        {
            formObject.Properties.Add(new VB6FormControlProperty()
            {
                Name = "Name", Value = $"\"{formObject.Name}\""
            });

            foreach (var child in formObject.Children)
            {
                AddImplicitProperties(child);
            }
        }
Beispiel #2
0
        private static void RewriteIndexedControls(IVB6FormObject formObject)
        {
            for (int i = 0; i < formObject.Children.Count; i++)
            {
                var child = formObject.Children[i];
                int?index = child.Properties.Where(property => property.Name == "Index").Select(property => Convert.ToInt32(property.Value)).Cast <int?>().FirstOrDefault();
                if (index.HasValue)
                {
                    child.Name = $"{child.Name}_{index.Value}";
                }

                RewriteIndexedControls(child);
            }
        }
Beispiel #3
0
        public PropertyMapping GetMapping(IVB6FormObject formObject, string property)
        {
            if (specificMappings.TryGetValue(formObject.Type, out var specificMapping))
            {
                if (specificMapping.TryGetValue(property, out var mapping))
                {
                    return(mapping);
                }
            }

            if (generalMappings.TryGetValue(property, out var generalMapping))
            {
                return(generalMapping);
            }

            return(null);
        }
Beispiel #4
0
        private static void ReadProperties(StreamReader streamReader, IVB6FormObject parentObject, List <VB6FormControlProperty> properties)
        {
            while (true)
            {
                var line = streamReader.ReadLine().Trim();

                if (line.StartsWith("BeginProperty "))
                {
                    var args = line.Split(' ');

                    var property = new VB6FormControlProperty();
                    property.Name = args[1];

                    ReadProperties(streamReader, parentObject, property.ChildProperties);

                    properties.Add(property);
                }
                else if (line.StartsWith("Begin "))
                {
                    var args = line.Split(' ');

                    var childObject = GenerateFormObject(args);
                    parentObject.Children.Add(childObject);

                    ReadProperties(streamReader, childObject, childObject.Properties);
                }
                else if (line == "EndProperty")
                {
                    return;
                }
                else if (line == "End")
                {
                    return;
                }
                else
                {
                    // Regular property, add it
                    var args = line.Split('=');

                    properties.Add(new VB6FormControlProperty()
                    {
                        Name = args[0].Trim(), Value = args[1].Trim()
                    });
                }
            }
        }
Beispiel #5
0
        private IList <SyntaxNode> GenerateControlProperties(IVB6FormObject control)
        {
            var propertyNodes = new List <SyntaxNode>();

            int?height = null;
            int?width  = null;
            int?top    = null;
            int?left   = null;

            int?clientHeight = null;
            int?clientWidth  = null;
            int?clientLeft   = null;
            int?clientTop    = null;

            foreach (var property in control.Properties)
            {
                if (property.Name == "Height")
                {
                    height = Convert.ToInt32(property.Value);
                }
                else if (property.Name == "Width")
                {
                    width = Convert.ToInt32(property.Value);
                }
                else if (property.Name == "Top")
                {
                    top = Convert.ToInt32(property.Value);
                }
                else if (property.Name == "Left")
                {
                    left = Convert.ToInt32(property.Value);
                }
                else if (property.Name == "ClientHeight")
                {
                    clientHeight = Convert.ToInt32(property.Value);
                }
                else if (property.Name == "ClientWidth")
                {
                    clientWidth = Convert.ToInt32(property.Value);
                }
                else if (property.Name == "ClientTop")
                {
                    clientTop = Convert.ToInt32(property.Value);
                }
                else if (property.Name == "ClientLeft")
                {
                    clientLeft = Convert.ToInt32(property.Value);
                }
                else
                {
                    var mapping = mappings.GetMapping(control, property.Name);
                    if (mapping != null)
                    {
                        foreach (var mappingResult in mapping.Mapping(property.Value))
                        {
                            if (mappingResult.Value != null)
                            {
                                if (control.Type == "Form")
                                {
                                    propertyNodes.Add(compilationUnit.Generator.AssignmentStatement(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.ThisExpression(), mappingResult.Property), mappingResult.Value));
                                }
                                else
                                {
                                    propertyNodes.Add(compilationUnit.Generator.AssignmentStatement(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.ThisExpression(), control.Name), mappingResult.Property), mappingResult.Value));
                                }
                            }
                        }
                    }
                }
            }

            // Size
            if (height.HasValue && width.HasValue)
            {
                width  = UnitConverter.ConvertTwipsToXPixels(width.Value);
                height = UnitConverter.ConvertTwipsToYPixels(height.Value);

                var result = compilationUnit.Generator.ObjectCreationExpression(compilationUnit.Generator.IdentifierName("System.Drawing.Size"), compilationUnit.Generator.LiteralExpression(width.Value), compilationUnit.Generator.LiteralExpression(height.Value));

                propertyNodes.Add(compilationUnit.Generator.AssignmentStatement(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.ThisExpression(), control.Name), "Size"), result));
            }

            // Location
            if (top.HasValue && left.HasValue)
            {
                left = UnitConverter.ConvertTwipsToXPixels(left.Value);
                top  = UnitConverter.ConvertTwipsToYPixels(top.Value);

                var result = compilationUnit.Generator.ObjectCreationExpression(compilationUnit.Generator.IdentifierName("System.Drawing.Point"), compilationUnit.Generator.LiteralExpression(left.Value), compilationUnit.Generator.LiteralExpression(top.Value));

                propertyNodes.Add(compilationUnit.Generator.AssignmentStatement(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.ThisExpression(), control.Name), "Location"), result));
            }

            // Client size
            if (clientHeight.HasValue && clientWidth.HasValue && clientLeft.HasValue && clientTop.HasValue)
            {
                clientWidth  = UnitConverter.ConvertTwipsToXPixels(clientWidth.Value) + UnitConverter.ConvertTwipsToXPixels(clientLeft.Value);
                clientHeight = UnitConverter.ConvertTwipsToYPixels(clientHeight.Value) + UnitConverter.ConvertTwipsToYPixels(clientTop.Value);

                var result = compilationUnit.Generator.ObjectCreationExpression(compilationUnit.Generator.IdentifierName("System.Drawing.Size"), compilationUnit.Generator.LiteralExpression(clientWidth.Value), compilationUnit.Generator.LiteralExpression(clientHeight.Value));

                propertyNodes.Add(compilationUnit.Generator.AssignmentStatement(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.ThisExpression(), "Size"), result));
            }

            // Add children
            foreach (var childControl in control.Children)
            {
                if (control.Type == "Form")
                {
                    propertyNodes.Add(compilationUnit.Generator.InvocationExpression(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.ThisExpression(), "Controls"), "Add"), compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.ThisExpression(), childControl.Name)));
                }
                else
                {
                    propertyNodes.Add(compilationUnit.Generator.InvocationExpression(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.ThisExpression(), control.Name), "Controls"), "Add"), compilationUnit.Generator.MemberAccessExpression(compilationUnit.Generator.ThisExpression(), childControl.Name)));
                }
            }

            foreach (var childControl in control.Children)
            {
                propertyNodes.AddRange(GenerateControlProperties(childControl));
            }

            return(propertyNodes);
        }