Beispiel #1
0
        internal static new void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            // TODO: Hardcoded to wrap - should align with lineBreakMode
            domObject.SetMemberValue(domObject.Type.GetMember("TextWrapping"), "Wrap");

            var textColor = GetElementWithMatchingAttribute(tag, "key", "textColor");
            if (textColor != null)
            {
                SetColor(domObject, textColor, domObject.Type.GetMember("Foreground"));
            }

            var isEnabled = GetElementWithMatchingAttribute(tag, "key", "enabled");
            if (isEnabled != null)
            {
                if (isEnabled.Value.Equals("no", StringComparison.InvariantCultureIgnoreCase))
                {
                    domObject.SetMemberValue(domObject.Type.GetMember("IsEnabled"), "false");
                }
            }

            // TextBlock doesn't like inlines as content in attribute form
            GetAndSetValue(tag, domObject, "text", domObject.Type.GetMember("Text"));
        }
        internal new static void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            // TODO: Hardcoded to wrap - should align with lineBreakMode
            domObject.SetMemberValue(domObject.Type.GetMember("TextWrapping"), "Wrap");

            var textColor = GetElementWithMatchingAttribute(tag, "key", "textColor");

            if (textColor != null)
            {
                SetColor(domObject, textColor, domObject.Type.GetMember("Foreground"));
            }

            var isEnabled = GetElementWithMatchingAttribute(tag, "key", "enabled");

            if (isEnabled != null)
            {
                if (isEnabled.Value.Equals("no", StringComparison.InvariantCultureIgnoreCase))
                {
                    domObject.SetMemberValue(domObject.Type.GetMember("IsEnabled"), "false");
                }
            }

            // TextBlock doesn't like inlines as content in attribute form
            GetAndSetValue(tag, domObject, "text", domObject.Type.GetMember("Text"));
        }
Beispiel #3
0
        internal new static void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            var value    = float.Parse(GetElementWithMatchingAttribute(tag, "key", "IBUIValue").Value);
            var maxValue = float.Parse(GetElementWithMatchingAttribute(tag, "key", "IBUIMaxValue").Value);

            domObject.SetMemberValue("Value", value.ToString());
            domObject.SetMemberValue("Maximum", maxValue.ToString());
        }
Beispiel #4
0
        internal static new void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            var value = float.Parse(GetElementWithMatchingAttribute(tag, "key", "IBUIValue").Value);
            var maxValue = float.Parse(GetElementWithMatchingAttribute(tag, "key", "IBUIMaxValue").Value);

            domObject.SetMemberValue("Value", value.ToString());
            domObject.SetMemberValue("Maximum", maxValue.ToString());
        }
Beispiel #5
0
        internal static new void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            var value = float.Parse(tag.Attribute(XName.Get("value")).Value);
            var minValue = float.Parse(tag.Attribute(XName.Get("minValue")).Value);
            var maxValue = float.Parse(tag.Attribute(XName.Get("maxValue")).Value);

            domObject.SetMemberValue("Value", value.ToString());
            domObject.SetMemberValue("Minimum", minValue.ToString());
            domObject.SetMemberValue("Maximum", maxValue.ToString());
        }
        internal new static void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            var value    = float.Parse(tag.Attribute(XName.Get("value")).Value);
            var minValue = float.Parse(tag.Attribute(XName.Get("minValue")).Value);
            var maxValue = float.Parse(tag.Attribute(XName.Get("maxValue")).Value);

            domObject.SetMemberValue("Value", value.ToString());
            domObject.SetMemberValue("Minimum", minValue.ToString());
            domObject.SetMemberValue("Maximum", maxValue.ToString());
        }
Beispiel #7
0
        protected static void SetFrameSize(XElement windowTag, XamlDomObject rootWindowNode)
        {
            // Set the window's height and width
            var frameSizeElement = GetElementWithMatchingAttribute(windowTag, "key", "NSFrameSize");

            if (frameSizeElement != null)
            {
                var frameSize = frameSizeElement.Value;
                var matches   = Regex.Matches(frameSize, @"\d+");
                Debug.Assert(matches.Count == 2);
                rootWindowNode.SetMemberValue("Width", matches[0].Value);
                rootWindowNode.SetMemberValue("Height", matches[1].Value);
            }
        }
Beispiel #8
0
        protected static void SetOpacity(XElement element, XamlDomObject domObject)
        {
            var opacityAttr = element.Attribute(XName.Get("opaque"));

            if (opacityAttr != null && opacityAttr.Value.Equals("yes", StringComparison.InvariantCultureIgnoreCase))
            {
                // TODO: Investigate why the legacy handler set the opacity to 0.7 vs 1.0
                domObject.SetMemberValue(domObject.Type.GetMember("Opacity"), "0.7");
            }
        }
Beispiel #9
0
        protected static void GetAndSetValue(XElement element, XamlDomObject domObject, string key, XamlMember member)
        {
            var valueElement = element.Attribute(XName.Get(key));

            if (valueElement != null)
            {
                var textValue = valueElement.Value;
                domObject.SetMemberValue(member, textValue);
            }
        }
Beispiel #10
0
        protected static void SetFrameSize(XElement windowTag, XamlDomObject rootWindowNode)
        {
            // Set the window's height and width
            var frameSizeElement = GetElementWithMatchingAttribute(windowTag, "key", "frame");

            if (frameSizeElement != null)
            {
                var widthAttr = frameSizeElement.Attribute(XName.Get("width"));
                if (widthAttr != null)
                {
                    rootWindowNode.SetMemberValue("Width", widthAttr.Value);
                }

                var heightAttr = frameSizeElement.Attribute(XName.Get("height"));
                if (heightAttr != null)
                {
                    rootWindowNode.SetMemberValue("Height", heightAttr.Value);
                }
            }
        }
Beispiel #11
0
 private static void SetImage(XElement element, XamlDomObject domObject)
 {
     var imageElement = GetElementWithMatchingAttribute(element, "key", "image");
     if (imageElement != null)
     {
         var imageFile = GetElementWithMatchingAttribute(imageElement, "key", "NSResourceName");
         if (imageFile != null)
         {
             domObject.SetMemberValue(domObject.Type.GetMember("Source"), imageFile.Value);
         }
     }
 }
Beispiel #12
0
        internal static new void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);
            domObject.SetMemberValue("TextWrapping", "Wrap");

            var backgroundColor = GetElementWithMatchingAttribute(tag, "key", "IBUITextColor");
            if (backgroundColor != null)
            {
                SetColor(domObject, backgroundColor, domObject.Type.GetMember("Foreground"));
            }

            var isEnabled = GetElementWithMatchingAttribute(tag, "key", "IBUIEnabled");
            if (isEnabled != null)
            {
                if (isEnabled.Value.Equals("no", StringComparison.InvariantCultureIgnoreCase))
                {
                    domObject.SetMemberValue(domObject.Type.GetMember("IsEnabled"), "false");
                }
            }

            GetAndSetValue(tag, domObject, "IBUIText", domObject.Type.ContentProperty);
        }
Beispiel #13
0
        protected static void GetDimensions(XElement element, XamlDomObject domObject)
        {
            // Look for dimensions and location
            var frame = GetElementWithMatchingAttribute(element, "key", "frame");

            if (frame != null)
            {
                var xAttr      = frame.Attribute(XName.Get("x"));
                var yAttr      = frame.Attribute(XName.Get("y"));
                var widthAttr  = frame.Attribute(XName.Get("width"));
                var heightAttr = frame.Attribute(XName.Get("height"));

                domObject.SetAttachableMemberValue(typeof(Canvas), "Left", xAttr.Value);
                domObject.SetAttachableMemberValue(typeof(Canvas), "Top", yAttr.Value);
                domObject.SetMemberValue("Width", widthAttr.Value);
                domObject.SetMemberValue("Height", heightAttr.Value);
            }
            else
            {
                SetFrameSize(element, domObject);
            }
        }
Beispiel #14
0
        private static void SetImage(XElement element, XamlDomObject domObject)
        {
            var imageElement = GetElementWithMatchingAttribute(element, "key", "IBUIImage");

            if (imageElement != null)
            {
                var imageFile = GetElementWithMatchingAttribute(imageElement, "key", "NSResourceName");
                if (imageFile != null)
                {
                    domObject.SetMemberValue(domObject.Type.GetMember("Source"), imageFile.Value);
                }
            }
        }
Beispiel #15
0
        protected static void SetOpacity(XElement element, XamlDomObject domObject)
        {
            var opacity = GetElementWithMatchingAttribute(element, "key", "IBUIOpaque");

            if (opacity != null)
            {
                var opacityValue = opacity.Value;
                Debug.Assert(opacityValue != null);
                if (opacityValue.Equals("yes", StringComparison.InvariantCultureIgnoreCase))
                {
                    domObject.SetMemberValue(domObject.Type.GetMember("Opacity"), "0.7");
                }
            }
        }
Beispiel #16
0
        internal new static void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);
            domObject.SetMemberValue("TextWrapping", "Wrap");

            var backgroundColor = GetElementWithMatchingAttribute(tag, "key", "IBUITextColor");

            if (backgroundColor != null)
            {
                SetColor(domObject, backgroundColor, domObject.Type.GetMember("Foreground"));
            }

            var isEnabled = GetElementWithMatchingAttribute(tag, "key", "IBUIEnabled");

            if (isEnabled != null)
            {
                if (isEnabled.Value.Equals("no", StringComparison.InvariantCultureIgnoreCase))
                {
                    domObject.SetMemberValue(domObject.Type.GetMember("IsEnabled"), "false");
                }
            }

            GetAndSetValue(tag, domObject, "IBUIText", domObject.Type.ContentProperty);
        }
Beispiel #17
0
        internal static new void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            var backgroundColor = GetElementWithMatchingAttribute(tag, "key", "IBUITextColor");
            if (backgroundColor != null)
            {
                SetColor(domObject, backgroundColor, domObject.Type.GetMember("Foreground"));
            }

            domObject.SetMemberValue(domObject.Type.GetMember("TextWrapping"), "Wrap");

            // TextBlock doesn't like Inlines as content in attribute form...
            GetAndSetValue(tag, domObject, "IBUIText", domObject.Type.GetMember("Text"));
        }
        internal new static void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            var backgroundColor = GetElementWithMatchingAttribute(tag, "key", "IBUITextColor");

            if (backgroundColor != null)
            {
                SetColor(domObject, backgroundColor, domObject.Type.GetMember("Foreground"));
            }

            domObject.SetMemberValue(domObject.Type.GetMember("TextWrapping"), "Wrap");

            // TextBlock doesn't like Inlines as content in attribute form...
            GetAndSetValue(tag, domObject, "IBUIText", domObject.Type.GetMember("Text"));
        }
Beispiel #19
0
        protected static void SetColor(XamlDomObject domObject, XElement color, XamlMember colorMember)
        {
            string value = null;

            // Image doesn't have a background but the XIB file allows setting it
            if (colorMember == null && domObject.Type.UnderlyingType == typeof(Image))
            {
                return;
            }

            // ColorSpace could be set to custom, calibratedWhite, calibratedRGB
            var colorSpace = color.Attribute(XName.Get("colorSpace"));

            if (colorSpace != null)
            {
                var colorValue = colorSpace.Value;
                if (colorValue.Contains("RGB"))
                {
                    var redValue   = color.Attribute(XName.Get("red")).Value;
                    var greenValue = color.Attribute(XName.Get("green")).Value;
                    var blueValue  = color.Attribute(XName.Get("blue")).Value;
                    var alphaValue = color.Attribute(XName.Get("alpha")).Value;

                    var red   = (byte)(double.Parse(redValue) * 255);
                    var green = (byte)(double.Parse(greenValue) * 255);
                    var blue  = (byte)(double.Parse(blueValue) * 255);
                    var alpha = (byte)(double.Parse(alphaValue) * 255);

                    var colorARGB = Color.FromArgb(alpha, red, green, blue);
                    value = colorARGB.ToString();
                }
            }
            else
            {
                throw new NotImplementedException("Doesn't support colorspace");
            }

            Debug.Assert(value != null);
            domObject.SetMemberValue(colorMember, value);
        }
Beispiel #20
0
        protected static void GetDimensions(XElement element, XamlDomObject domObject)
        {
            // Look for dimensions and location
            var frame = GetElementWithMatchingAttribute(element, "key", "frame");

            if (frame != null)
            {
                var xAttr      = frame.Attribute(XName.Get("x"));
                var yAttr      = frame.Attribute(XName.Get("y"));
                var widthAttr  = frame.Attribute(XName.Get("width"));
                var heightAttr = frame.Attribute(XName.Get("height"));

                // Certain controls have a 12 pixel border around them.  Make them look normal
                if (domObject.Type.CanAssignTo(domObject.SchemaContext.GetXamlType(typeof(TextBox))) ||
                    domObject.Type.CanAssignTo(domObject.SchemaContext.GetXamlType(typeof(Button)))
                    )
                {
                    var left   = int.Parse(xAttr.Value) - 12;      // XamlXibReader.WIDTHMULTIPLIER);
                    var top    = int.Parse(yAttr.Value) - 12;      // * XamlXibReader.HEIGHTMULTIPLIER);
                    var width  = int.Parse(widthAttr.Value) + 24;  // * XamlXibReader.WIDTHMULTIPLIER);
                    var height = int.Parse(heightAttr.Value) + 24; // * XamlXibReader.HEIGHTMULTIPLIER);

                    domObject.SetAttachableMemberValue(typeof(Canvas), "Left", left.ToString());
                    domObject.SetAttachableMemberValue(typeof(Canvas), "Top", top.ToString());

                    domObject.SetMemberValue("Width", width.ToString());
                    domObject.SetMemberValue("Height", height.ToString());

                    domObject.SetMemberValue("MinWidth", "0");
                    domObject.SetMemberValue("MinHeight", "0");
                }
                else
                {
                    domObject.SetAttachableMemberValue(typeof(Canvas), "Left", xAttr.Value);
                    domObject.SetAttachableMemberValue(typeof(Canvas), "Top", yAttr.Value);
                    domObject.SetMemberValue("Width", widthAttr.Value);
                    domObject.SetMemberValue("Height", heightAttr.Value);
                }
            }
            else
            {
                SetFrameSize(element, domObject);
            }
        }
Beispiel #21
0
        //static protected void GetNormalTitle(XElement element, XamlDomObject domObject)
        //{
        //    GetAndSetValue(element, domObject, "IBUINormalTitle", domObject.Type.ContentProperty);
        ////}

        //private void GetText(XElement element, XamlDomObject domObject)
        //{
        //    GetAndSetValue(element, domObject, "IBUIText", domObject.Type.ContentProperty);
        //}

        protected static void GetAndSetValue(XElement element, XamlDomObject domObject, string key, XamlMember member)
        {
            var valueElement = GetElementWithMatchingAttribute(element, "key", key);

            if (valueElement != null && !string.IsNullOrEmpty(valueElement.Value))
            {
                var attr      = valueElement.Attribute(XName.Get("type"));
                var textValue = valueElement.Value;
                if (attr != null)
                {
                    if (attr.Value.Equals("base64-UTF8", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var sb       = new StringBuilder();
                        var newlines = textValue.Split('\n');
                        foreach (var line in newlines)
                        {
                            sb.Append(XamlLegacyXibReader.DecodeFromBase64(line));
                        }
                        textValue = sb.ToString();
                    }
                }
                domObject.SetMemberValue(member, textValue);
            }
        }
Beispiel #22
0
        protected static void GetDimensions(XElement element, XamlDomObject domObject)
        {
            var frame = GetElementWithMatchingAttribute(element, "key", "NSFrame");

            // Look for dimensions and location
            if (frame != null)
            {
                var dimensions = frame.Value;
                var matches    = Regex.Matches(dimensions, @"\d+");
                // Certain controls have a 12 pixel border around them.  Make them look normal
                if (domObject.Type.CanAssignTo(domObject.SchemaContext.GetXamlType(typeof(TextBox))) ||
                    domObject.Type.CanAssignTo(domObject.SchemaContext.GetXamlType(typeof(Button)))
                    )
                {
                    var left   = int.Parse(matches[0].Value) - 12; // XamlLegacyXibReader.WIDTHMULTIPLIER);
                    var top    = int.Parse(matches[1].Value) - 12; // * XamlLegacyXibReader.HEIGHTMULTIPLIER);
                    var width  = int.Parse(matches[2].Value) + 24; // * XamlLegacyXibReader.WIDTHMULTIPLIER);
                    var height = int.Parse(matches[3].Value) + 24; // * XamlLegacyXibReader.HEIGHTMULTIPLIER);

                    domObject.SetAttachableMemberValue(typeof(Canvas), "Left", left.ToString());
                    domObject.SetAttachableMemberValue(typeof(Canvas), "Top", top.ToString());
                    domObject.SetMemberValue("Width", width.ToString());
                    domObject.SetMemberValue("Height", height.ToString());

                    domObject.SetMemberValue("MinWidth", "0");
                    domObject.SetMemberValue("MinHeight", "0");
                }
                else
                {
                    domObject.SetAttachableMemberValue(typeof(Canvas), "Left", matches[0].Value);
                    domObject.SetAttachableMemberValue(typeof(Canvas), "Top", matches[1].Value);
                    domObject.SetMemberValue("Width", matches[2].Value);
                    domObject.SetMemberValue("Height", matches[3].Value);
                }
            }
            else
            {
                SetFrameSize(element, domObject);
            }
        }
Beispiel #23
0
        protected static void GetDimensions(XElement element, XamlDomObject domObject)
        {
            var frame = GetElementWithMatchingAttribute(element, "key", "NSFrame");

            // Look for dimensions and location
            if (frame != null)
            {
                var dimensions = frame.Value;
                var matches = Regex.Matches(dimensions, @"\d+");
                // Certain controls have a 12 pixel border around them.  Make them look normal
                if (domObject.Type.CanAssignTo(domObject.SchemaContext.GetXamlType(typeof(TextBox))) ||
                    domObject.Type.CanAssignTo(domObject.SchemaContext.GetXamlType(typeof(Button)))
                    )
                {
                    var left = int.Parse(matches[0].Value) - 12; // XamlLegacyXibReader.WIDTHMULTIPLIER);
                    var top = int.Parse(matches[1].Value) - 12; // * XamlLegacyXibReader.HEIGHTMULTIPLIER);
                    var width = int.Parse(matches[2].Value) + 24; // * XamlLegacyXibReader.WIDTHMULTIPLIER);
                    var height = int.Parse(matches[3].Value) + 24; // * XamlLegacyXibReader.HEIGHTMULTIPLIER);

                    domObject.SetAttachableMemberValue(typeof(Canvas), "Left", left.ToString());
                    domObject.SetAttachableMemberValue(typeof(Canvas), "Top", top.ToString());
                    domObject.SetMemberValue("Width", width.ToString());
                    domObject.SetMemberValue("Height", height.ToString());

                    domObject.SetMemberValue("MinWidth", "0");
                    domObject.SetMemberValue("MinHeight", "0");
                }
                else
                {
                    domObject.SetAttachableMemberValue(typeof(Canvas), "Left", matches[0].Value);
                    domObject.SetAttachableMemberValue(typeof(Canvas), "Top", matches[1].Value);
                    domObject.SetMemberValue("Width", matches[2].Value);
                    domObject.SetMemberValue("Height", matches[3].Value);
                }
            }
            else
            {
                SetFrameSize(element, domObject);
            }
        }
Beispiel #24
0
 protected static void GetAndSetValue(XElement element, XamlDomObject domObject, string key, XamlMember member)
 {
     var valueElement = element.Attribute(XName.Get(key));
     if (valueElement != null)
     {
         var textValue = valueElement.Value;
         domObject.SetMemberValue(member, textValue);
     }
 }
Beispiel #25
0
        protected static void GetDimensions(XElement element, XamlDomObject domObject)
        {
            // Look for dimensions and location
            var frame = GetElementWithMatchingAttribute(element, "key", "frame");
            if (frame != null)
            {
                var xAttr = frame.Attribute(XName.Get("x"));
                var yAttr = frame.Attribute(XName.Get("y"));
                var widthAttr = frame.Attribute(XName.Get("width"));
                var heightAttr = frame.Attribute(XName.Get("height"));

                domObject.SetAttachableMemberValue(typeof(Canvas), "Left", xAttr.Value);
                domObject.SetAttachableMemberValue(typeof(Canvas), "Top", yAttr.Value);
                domObject.SetMemberValue("Width", widthAttr.Value);
                domObject.SetMemberValue("Height", heightAttr.Value);
            }
            else
            {
                SetFrameSize(element, domObject);
            }
        }
Beispiel #26
0
        protected static void SetColor(XamlDomObject domObject, XElement color, XamlMember colorMember)
        {
            string value = null;

            // Image doesn't have a background but the XIB file allows setting it
            if (colorMember == null && domObject.Type.UnderlyingType == typeof(Image))
            {
                return;
            }

            // ColorSpace could be set to custom, calibratedWhite, calibratedRGB
            var colorSpace = color.Attribute(XName.Get("colorSpace"));
            if (colorSpace != null)
            {
                var colorValue = colorSpace.Value;
                if (colorValue.Contains("RGB"))
                {
                    var redValue = color.Attribute(XName.Get("red")).Value;
                    var greenValue = color.Attribute(XName.Get("green")).Value;
                    var blueValue = color.Attribute(XName.Get("blue")).Value;
                    var alphaValue = color.Attribute(XName.Get("alpha")).Value;

                    var red = (byte) (double.Parse(redValue)*255);
                    var green = (byte) (double.Parse(greenValue)*255);
                    var blue = (byte) (double.Parse(blueValue)*255);
                    var alpha = (byte) (double.Parse(alphaValue)*255);

                    var colorARGB = Color.FromArgb(alpha, red, green, blue);
                    value = colorARGB.ToString();
                }
            }
            else
            {
                throw new NotImplementedException("Doesn't support colorspace");
            }

            Debug.Assert(value != null);
            domObject.SetMemberValue(colorMember, value);
        }
Beispiel #27
0
        protected static void SetFrameSize(XElement windowTag, XamlDomObject rootWindowNode)
        {
            // Set the window's height and width
            var frameSizeElement = GetElementWithMatchingAttribute(windowTag, "key", "frame");
            if (frameSizeElement != null)
            {
                var widthAttr = frameSizeElement.Attribute(XName.Get("width"));
                if (widthAttr != null)
                {
                    rootWindowNode.SetMemberValue("Width", widthAttr.Value);
                }

                var heightAttr = frameSizeElement.Attribute(XName.Get("height"));
                if (heightAttr != null)
                {
                    rootWindowNode.SetMemberValue("Height", heightAttr.Value);
                }
            }
        }
Beispiel #28
0
 protected static void SetOpacity(XElement element, XamlDomObject domObject)
 {
     var opacityAttr = element.Attribute(XName.Get("opaque"));
     if (opacityAttr != null && opacityAttr.Value.Equals("yes", StringComparison.InvariantCultureIgnoreCase))
     {
         // TODO: Investigate why the legacy handler set the opacity to 0.7 vs 1.0
         domObject.SetMemberValue(domObject.Type.GetMember("Opacity"), "0.7");
     }
 }
Beispiel #29
0
 protected static void SetOpacity(XElement element, XamlDomObject domObject)
 {
     var opacity = GetElementWithMatchingAttribute(element, "key", "IBUIOpaque");
     if (opacity != null)
     {
         var opacityValue = opacity.Value;
         Debug.Assert(opacityValue != null);
         if (opacityValue.Equals("yes", StringComparison.InvariantCultureIgnoreCase))
         {
             domObject.SetMemberValue(domObject.Type.GetMember("Opacity"), "0.7");
         }
     }
 }
Beispiel #30
0
 protected static void SetFrameSize(XElement windowTag, XamlDomObject rootWindowNode)
 {
     // Set the window's height and width
     var frameSizeElement = GetElementWithMatchingAttribute(windowTag, "key", "NSFrameSize");
     if (frameSizeElement != null)
     {
         var frameSize = frameSizeElement.Value;
         var matches = Regex.Matches(frameSize, @"\d+");
         Debug.Assert(matches.Count == 2);
         rootWindowNode.SetMemberValue("Width", matches[0].Value);
         rootWindowNode.SetMemberValue("Height", matches[1].Value);
     }
 }
Beispiel #31
0
        protected static void SetColor(XamlDomObject domObject, XElement color, XamlMember colorMember)
        {
            var colorType = color.Attribute(XName.Get("key")).Value;
            //XamlMember colorMember = GetColorMember(domObject.Type, colorType);

            //Image doesn't have a background but the XIB file allows setting it
            if (colorMember == null && domObject.Type.UnderlyingType == typeof(Image))
            {
                return;
            }

            var colorSpace = int.Parse(GetElementWithMatchingAttribute(color, "key", "NSColorSpace").Value);
            string value = null;
            switch (colorSpace)
            {
                case 1: //NSRGB
                {
                    var values =
                        XamlLegacyXibReader.DecodeFromBase64(GetElementWithMatchingAttribute(color, "key", "NSRGB").Value)
                            .Split(' ');

                    var color2 = Color.FromRgb((byte) (double.Parse(values[0])*255),
                        (byte) (double.Parse(values[1])*255),
                        (byte) (double.Parse(values[2])*255));
                    value = color2.ToString();
                }
                    break;
                case 2:
                case 3:
                {
                    var searchKey = colorSpace == 2 ? "NSRGB" : "NSWhite";
                    var asciiDecodedString =
                        XamlLegacyXibReader.DecodeFromBase64(GetElementWithMatchingAttribute(color, "key", searchKey).Value)
                            .Replace("\0", "");
                    var values = asciiDecodedString.Split(' ');

                    var doubleValues = colorSpace == 2 ? new double[4] : new double[3];
                    if (values.Length >= 1)
                    {
                        doubleValues[0] = double.Parse(values[0]);
                    }
                    if (values.Length >= 2)
                    {
                        doubleValues[1] = double.Parse(values[1]);
                    }
                    if (values.Length >= 3)
                    {
                        doubleValues[2] = double.Parse(values[2]);
                    }
                    if (colorSpace == 2)
                    {
                        if (values.Length == 4)
                        {
                            doubleValues[3] = double.Parse(values[3]);
                        }
                        Debug.Assert(values.Length <= 4);
                    }
                    else
                    {
                        Debug.Assert(values.Length <= 3);
                    }

                    byte[] rgbValues = null;
                    if (colorSpace == 2)
                    {
                        rgbValues = ColorConverters.CMYKtoRGB(doubleValues[0], doubleValues[1], doubleValues[2],
                            doubleValues[3]);
                    }
                    else if (colorSpace == 3)
                    {
                        rgbValues = ColorConverters.LabToRGB(doubleValues[0], doubleValues[1], doubleValues[2]);
                    }

                    var color2 = Color.FromRgb(rgbValues[0], rgbValues[1], rgbValues[2]);

                    value = color2.ToString();
                }
                    break;
                default:
                    throw new NotImplementedException("Doesn't suppor colorspace: " + colorSpace);
            }
            Debug.Assert(value != null);
            domObject.SetMemberValue(colorMember, value);
        }
Beispiel #32
0
 //static protected void GetNormalTitle(XElement element, XamlDomObject domObject)
 //{
 //    GetAndSetValue(element, domObject, "IBUINormalTitle", domObject.Type.ContentProperty);
 ////}
 //private void GetText(XElement element, XamlDomObject domObject)
 //{
 //    GetAndSetValue(element, domObject, "IBUIText", domObject.Type.ContentProperty);
 //}
 protected static void GetAndSetValue(XElement element, XamlDomObject domObject, string key, XamlMember member)
 {
     var valueElement = GetElementWithMatchingAttribute(element, "key", key);
     if (valueElement != null && !string.IsNullOrEmpty(valueElement.Value))
     {
         var attr = valueElement.Attribute(XName.Get("type"));
         var textValue = valueElement.Value;
         if (attr != null)
         {
             if (attr.Value.Equals("base64-UTF8", StringComparison.InvariantCultureIgnoreCase))
             {
                 var sb = new StringBuilder();
                 var newlines = textValue.Split('\n');
                 foreach (var line in newlines)
                 {
                     sb.Append(XamlLegacyXibReader.DecodeFromBase64(line));
                 }
                 textValue = sb.ToString();
             }
         }
         domObject.SetMemberValue(member, textValue);
     }
 }
Beispiel #33
0
        protected static void SetColor(XamlDomObject domObject, XElement color, XamlMember colorMember)
        {
            var colorType = color.Attribute(XName.Get("key")).Value;

            //XamlMember colorMember = GetColorMember(domObject.Type, colorType);

            //Image doesn't have a background but the XIB file allows setting it
            if (colorMember == null && domObject.Type.UnderlyingType == typeof(Image))
            {
                return;
            }

            var    colorSpace = int.Parse(GetElementWithMatchingAttribute(color, "key", "NSColorSpace").Value);
            string value      = null;

            switch (colorSpace)
            {
            case 1:     //NSRGB
            {
                var values =
                    XamlLegacyXibReader.DecodeFromBase64(GetElementWithMatchingAttribute(color, "key", "NSRGB").Value)
                    .Split(' ');

                var color2 = Color.FromRgb((byte)(double.Parse(values[0]) * 255),
                                           (byte)(double.Parse(values[1]) * 255),
                                           (byte)(double.Parse(values[2]) * 255));
                value = color2.ToString();
            }
            break;

            case 2:
            case 3:
            {
                var searchKey          = colorSpace == 2 ? "NSRGB" : "NSWhite";
                var asciiDecodedString =
                    XamlLegacyXibReader.DecodeFromBase64(GetElementWithMatchingAttribute(color, "key", searchKey).Value)
                    .Replace("\0", "");
                var values = asciiDecodedString.Split(' ');

                var doubleValues = colorSpace == 2 ? new double[4] : new double[3];
                if (values.Length >= 1)
                {
                    doubleValues[0] = double.Parse(values[0]);
                }
                if (values.Length >= 2)
                {
                    doubleValues[1] = double.Parse(values[1]);
                }
                if (values.Length >= 3)
                {
                    doubleValues[2] = double.Parse(values[2]);
                }
                if (colorSpace == 2)
                {
                    if (values.Length == 4)
                    {
                        doubleValues[3] = double.Parse(values[3]);
                    }
                    Debug.Assert(values.Length <= 4);
                }
                else
                {
                    Debug.Assert(values.Length <= 3);
                }

                byte[] rgbValues = null;
                if (colorSpace == 2)
                {
                    rgbValues = ColorConverters.CMYKtoRGB(doubleValues[0], doubleValues[1], doubleValues[2],
                                                          doubleValues[3]);
                }
                else if (colorSpace == 3)
                {
                    rgbValues = ColorConverters.LabToRGB(doubleValues[0], doubleValues[1], doubleValues[2]);
                }

                var color2 = Color.FromRgb(rgbValues[0], rgbValues[1], rgbValues[2]);

                value = color2.ToString();
            }
            break;

            default:
                throw new NotImplementedException("Doesn't suppor colorspace: " + colorSpace);
            }
            Debug.Assert(value != null);
            domObject.SetMemberValue(colorMember, value);
        }