Exemple #1
0
        public override void ConnectComponents(IDomain domain, IDynamic currentDynamic, IReadOnlyCollection <IComponent> components)
        {
            base.ConnectComponents(domain, currentDynamic, components);

            if (Items.Count < 1)
            {
                throw new ParsingException(203, Source, $"Panel '{GetType().Name}' has no item.");
            }

            double MaxWidthValue;

            if (MaxWidth != null && !ParserDomain.TryParseDouble(MaxWidth, out MaxWidthValue))
            {
                throw new ParsingException(204, Source, "Invalid max width.");
            }

            double MaxHeightValue;

            if (MaxHeight != null && !ParserDomain.TryParseDouble(MaxHeight, out MaxHeightValue))
            {
                throw new ParsingException(205, Source, "Invalid max height.");
            }

            foreach (ILayoutElement Item in Items)
            {
                Item.ConnectComponents(domain, currentDynamic, components);
            }
        }
Exemple #2
0
        private double[] ParseDoubleList(string stringList, int maxCount, string propertyName)
        {
            if (stringList == null)
            {
                stringList = "";
            }

            string[] Splitted = stringList.Split(',');
            if (Splitted.Length > maxCount)
            {
                throw new ParsingException(169, Source, $"Too many values in '{stringList}', expected at most {maxCount}.");
            }

            double[] Result = new double[maxCount];

            int i;

            for (i = 0; i < Splitted.Length; i++)
            {
                string WidthString = Splitted[i];
                if (WidthString.Length == 0)
                {
                    Result[i] = 0;
                }
                else if (WidthString.ToLower() == "auto")
                {
                    Result[i] = double.NaN;
                }
                else if (!ParserDomain.TryParseDouble(WidthString, out Result[i]))
                {
                    throw new ParsingException(170, Source, $"'{WidthString}' not parsed as a {propertyName}.");
                }
            }
            for (; i < maxCount; i++)
            {
                Result[i] = 0;
            }

            return(Result);
        }
Exemple #3
0
        public virtual void ConnectComponents(IDomain domain, IDynamic currentDynamic, IReadOnlyCollection <IComponent> components)
        {
            double WidthValue;

            if (Width != null && !ParserDomain.TryParseDouble(Width, out WidthValue))
            {
                throw new ParsingException(193, Source, "Invalid width.");
            }

            double HeightValue;

            if (Height != null && !ParserDomain.TryParseDouble(Height, out HeightValue))
            {
                throw new ParsingException(194, Source, "Invalid height.");
            }

            double SingleMargin;

            if (Margin != null && !ParserDomain.TryParseDouble(Margin, out SingleMargin))
            {
                string[] ThicknessMargin = Margin.Split(',');
                int      i;

                for (i = 0; i < 4 && i < ThicknessMargin.Length; i++)
                {
                    if (!ParserDomain.TryParseDouble(ThicknessMargin[i], out SingleMargin))
                    {
                        break;
                    }
                }

                if (i < 4)
                {
                    throw new ParsingException(195, Source, "Invalid margin.");
                }
            }

            if (HorizontalAlignment != null &&
                HorizontalAlignment != Windows.UI.Xaml.HorizontalAlignment.Left.ToString() &&
                HorizontalAlignment != Windows.UI.Xaml.HorizontalAlignment.Center.ToString() &&
                HorizontalAlignment != Windows.UI.Xaml.HorizontalAlignment.Right.ToString() &&
                HorizontalAlignment != Windows.UI.Xaml.HorizontalAlignment.Stretch.ToString())
            {
                throw new ParsingException(196, Source, "Invalid horizontal alignment.");
            }

            if (VerticalAlignment != null &&
                VerticalAlignment != Windows.UI.Xaml.VerticalAlignment.Top.ToString() &&
                VerticalAlignment != Windows.UI.Xaml.VerticalAlignment.Center.ToString() &&
                VerticalAlignment != Windows.UI.Xaml.VerticalAlignment.Bottom.ToString() &&
                VerticalAlignment != Windows.UI.Xaml.VerticalAlignment.Stretch.ToString())
            {
                throw new ParsingException(197, Source, "Invalid vertical alignment.");
            }

            if (DynamicEnable != null && DynamicController == null)
            {
                foreach (IDynamicProperty Item in currentDynamic.Properties)
                {
                    if (DynamicEnable == Item.Source.Name)
                    {
                        DynamicController = Item;
                        break;
                    }
                }

                if (DynamicController == null)
                {
                    throw new ParsingException(198, Source, $"Dynamic property '{DynamicEnable}' not found in '{currentDynamic.Name}'.");
                }
                else if (DynamicController.Result != DynamicOperationResults.Boolean)
                {
                    throw new ParsingException(199, Source, $"Dynamic property '{DynamicEnable}' is not boolean.");
                }

                DynamicController.SetIsUsed();
            }
        }
Exemple #4
0
        private IComponentPopup ParseComponentPopup(IDeclarationSource nameSource, IParsingSourceStream sourceStream, List <ComponentInfo> infoList)
        {
            IComponentProperty SourceProperty        = null;
            IComponentProperty SourcePressedProperty = null;
            IComponentProperty AreaProperty          = null;
            IComponentProperty WidthProperty         = null;
            IComponentProperty HeightProperty        = null;

            foreach (ComponentInfo Info in infoList)
            {
                if (Info.NameSource.Name == "source" && SourceProperty == null)
                {
                    SourceProperty = new ComponentProperty(Info);
                }
                else if (Info.NameSource.Name == "source pressed" && SourcePressedProperty == null)
                {
                    SourcePressedProperty = new ComponentProperty(Info);
                }
                else if (Info.NameSource.Name == "area" && AreaProperty == null)
                {
                    AreaProperty = new ComponentProperty(Info);
                }
                else if (Info.NameSource.Name == "width" && WidthProperty == null)
                {
                    WidthProperty = new ComponentProperty(Info);
                }
                else if (Info.NameSource.Name == "height" && HeightProperty == null)
                {
                    HeightProperty = new ComponentProperty(Info);
                }
                else if (Info.NameSource.Name != "source" && Info.NameSource.Name != "source pressed" && Info.NameSource.Name != "area" && Info.NameSource.Name != "width" && Info.NameSource.Name != "height")
                {
                    throw new ParsingException(27, sourceStream, $"Unknown token '{Info.NameSource.Name}'.");
                }
                else
                {
                    throw new ParsingException(28, sourceStream, $"'{Info.NameSource.Name}' is repeated.");
                }
            }

            if (SourceProperty == null)
            {
                throw new ParsingException(57, sourceStream, "Source not specified.");
            }
            if (SourceProperty.FixedValueSource == null)
            {
                throw new ParsingException(186, sourceStream, "Source can only be a static name.");
            }

            if (SourcePressedProperty != null && SourcePressedProperty.FixedValueSource == null)
            {
                throw new ParsingException(186, sourceStream, "Source pressed can only be a static name.");
            }

            if (AreaProperty == null)
            {
                throw new ParsingException(58, sourceStream, "Area not specified.");
            }
            if (AreaProperty.FixedValueSource == null)
            {
                throw new ParsingException(59, sourceStream, "Area name can only be a static name.");
            }

            double WidthValue;

            if (WidthProperty != null)
            {
                if (WidthProperty.FixedValueSource == null)
                {
                    throw new ParsingException(54, sourceStream, "Width can only be a static value.");
                }

                string ImageWidth = WidthProperty.FixedValueSource.Name;
                if (!ParserDomain.TryParseDouble(ImageWidth, out WidthValue))
                {
                    throw new ParsingException(128, WidthProperty.FixedValueSource.Source, $"'{ImageWidth}' not parsed as a width.");
                }
            }
            else
            {
                WidthValue = double.NaN;
            }

            double HeightValue;

            if (HeightProperty != null)
            {
                if (HeightProperty.FixedValueSource == null)
                {
                    throw new ParsingException(56, sourceStream, "Height can only be a static value.");
                }

                string ImageHeight = HeightProperty.FixedValueSource.Name;
                if (!ParserDomain.TryParseDouble(ImageHeight, out HeightValue))
                {
                    throw new ParsingException(129, HeightProperty.FixedValueSource.Source, $"'{ImageHeight}' not parsed as a height.");
                }
            }
            else
            {
                HeightValue = double.NaN;
            }

            return(new ComponentPopup(nameSource, ParserDomain.ToXamlName(nameSource.Source, nameSource.Name, "Popup"), SourceProperty, SourcePressedProperty, AreaProperty.FixedValueSource, WidthValue, HeightValue));
        }
Exemple #5
0
        private IComponentImage ParseComponentImage(IDeclarationSource nameSource, IParsingSourceStream sourceStream, List <ComponentInfo> infoList)
        {
            IComponentProperty SourceProperty = null;
            IComponentProperty WidthProperty  = null;
            IComponentProperty HeightProperty = null;

            foreach (ComponentInfo Info in infoList)
            {
                if (Info.NameSource.Name == "source" && SourceProperty == null)
                {
                    SourceProperty = new ComponentProperty(Info);
                }
                else if (Info.NameSource.Name == "width" && WidthProperty == null)
                {
                    WidthProperty = new ComponentProperty(Info);
                }
                else if (Info.NameSource.Name == "height" && HeightProperty == null)
                {
                    HeightProperty = new ComponentProperty(Info);
                }
                else if (Info.NameSource.Name != "source" && Info.NameSource.Name != "width" && Info.NameSource.Name != "height")
                {
                    throw new ParsingException(27, sourceStream, $"Unknown token '{Info.NameSource.Name}'.");
                }
                else
                {
                    throw new ParsingException(28, sourceStream, $"'{Info.NameSource.Name}' is repeated.");
                }
            }

            if (SourceProperty == null)
            {
                throw new ParsingException(52, sourceStream, "Source not specified.");
            }
            if (SourceProperty.FixedValueSource == null)
            {
                throw new ParsingException(0, sourceStream, "Source can only be a static resource name.");
            }

            bool   IsResourceWidth;
            double WidthValue;

            if (WidthProperty != null)
            {
                if (WidthProperty.FixedValueSource == null)
                {
                    throw new ParsingException(54, sourceStream, "Width can only be a static value.");
                }

                string ImageWidth = WidthProperty.FixedValueSource.Name;
                if (ImageWidth == "resource")
                {
                    IsResourceWidth = true;
                    WidthValue      = double.NaN;
                }
                else if (ParserDomain.TryParseDouble(ImageWidth, out WidthValue))
                {
                    IsResourceWidth = false;
                }
                else
                {
                    throw new ParsingException(128, WidthProperty.FixedValueSource.Source, $"'{ImageWidth}' not parsed as a width.");
                }
            }
            else
            {
                IsResourceWidth = false;
                WidthValue      = double.NaN;
            }

            bool   IsResourceHeight;
            double HeightValue;

            if (HeightProperty != null)
            {
                if (HeightProperty.FixedValueSource == null)
                {
                    throw new ParsingException(56, sourceStream, "Height can only be a static value.");
                }

                string ImageHeight = HeightProperty.FixedValueSource.Name;
                if (ImageHeight == "resource")
                {
                    IsResourceHeight = true;
                    HeightValue      = double.NaN;
                }
                else if (ParserDomain.TryParseDouble(ImageHeight, out HeightValue))
                {
                    IsResourceHeight = false;
                }
                else
                {
                    throw new ParsingException(129, HeightProperty.FixedValueSource.Source, $"'{ImageHeight}' not parsed as a height.");
                }
            }
            else
            {
                IsResourceHeight = false;
                HeightValue      = double.NaN;
            }

            return(new ComponentImage(nameSource, ParserDomain.ToXamlName(nameSource.Source, nameSource.Name, "Image"), SourceProperty, IsResourceWidth, WidthValue, IsResourceHeight, HeightValue));
        }
Exemple #6
0
        public void ConnectBackground(IDomain domain, ref bool IsConnected)
        {
            if (Background == null && BackgroundSource != null)
            {
                foreach (IBackground Item in domain.Backgrounds)
                {
                    if (Item.Name == BackgroundSource.Name)
                    {
                        Background = Item;
                        break;
                    }
                }

                if (Background == null)
                {
                    throw new ParsingException(122, BackgroundSource.Source, $"Unknown background '{BackgroundSource.Name}'.");
                }

                double WidthValue;
                if (!ParserDomain.TryParseDouble(WidthSource.Name, out WidthValue))
                {
                    throw new ParsingException(123, WidthSource.Source, $"'{WidthSource.Name}' not parsed as a width.");
                }

                Width = WidthValue;

                IsConnected = true;
            }
            else if (Width == 0 && BackgroundSource == null)
            {
                if (WidthSource.Name != "stretch")
                {
                    throw new ParsingException(124, WidthSource.Source, "Only valid width when no background is 'stretch'.");
                }

                Width = double.NaN;

                IsConnected = true;
            }

            if (Height == 0)
            {
                if (HeightSource.Name == "infinite")
                {
                    Height = double.NaN;
                }
                else
                {
                    double HeightValue;
                    if (!ParserDomain.TryParseDouble(HeightSource.Name, out HeightValue))
                    {
                        throw new ParsingException(126, HeightSource.Source, $"'{HeightSource.Name}' not parsed as a height (only valid values are integer constants or 'infinite').");
                    }

                    Height = HeightValue;
                }

                IsConnected = true;
            }

            if (BackgroundColor == null)
            {
                foreach (IColorTheme Item in domain.ColorThemes)
                {
                    foreach (KeyValuePair <IDeclarationSource, string> Entry in Item.Colors)
                    {
                        if (Entry.Key.Name == BackgroundColorSource.Name)
                        {
                            BackgroundColor = BackgroundColorSource.Name;
                            break;
                        }
                    }

                    if (BackgroundColor == null)
                    {
                        throw new ParsingException(127, BackgroundColorSource.Source, $"Background color '{BackgroundColorSource.Name}' not found in color theme '{Item.Name}'.");
                    }
                }

                IsConnected = true;
            }
        }