示例#1
0
        private static XamlDomObject CreateView(XElement viewTag, XamlSchemaContext schemaContext)
        {
            Debug.Assert(viewTag != null);

            // Create the view and canvas
            var canvas = new XamlDomObject(schemaContext.GetXamlType(typeof(Canvas)));
            var canvasChildrenMember = new XamlDomMember(schemaContext.GetXamlType(typeof(Canvas)).ContentProperty);

            SetFrameSize(viewTag, canvas);

            // Add children
            var subViews = viewTag.Element(XName.Get("subviews"));

            if (subViews != null)
            {
                foreach (var element in subViews.Elements(XName.Get("object")))
                {
                    AddControlToTree(canvasChildrenMember, element);
                }
            }

            if (canvasChildrenMember.Items != null && canvasChildrenMember.Items.Count > 0)
            {
                canvas.MemberNodes.Add(canvasChildrenMember);
            }

            return(canvas);
        }
        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"));
        }
示例#3
0
        private static XamlDomObject CreateView(XElement viewTag, XamlSchemaContext schemaContext)
        {
            Debug.Assert(viewTag != null);

            // Create the view and canvas
            var canvas = new XamlDomObject(schemaContext.GetXamlType(typeof(Canvas)));
            var canvasChildrenMember = new XamlDomMember(schemaContext.GetXamlType(typeof(Canvas)).ContentProperty);

            SetFrameSize(viewTag, canvas);

            var backgroundColor = GetElementWithMatchingAttribute(viewTag, "key", "IBUIBackgroundColor");
            //GetColor(canvas.Type, canvas, backgroundColor);

            // Add children
            var subViews = GetElementWithMatchingAttribute(viewTag, "key", "NSSubviews");

            if (subViews != null)
            {
                foreach (var element in subViews.Elements(XName.Get("object")))
                {
                    AddControlToTree(canvasChildrenMember, element);
                }
            }

            // TODO: Fix XamlToolkit to not choke on members with nothing inside of it
            if (canvasChildrenMember.Items != null && canvasChildrenMember.Items.Count > 0)
            {
                canvas.MemberNodes.Add(canvasChildrenMember);
            }

            return(canvas);
        }
        public static T GetAttatchedPropertyValueOrDefault <T>(this XamlDomObject sourceObject, DependencyProperty property)
        {
            T value;

            sourceObject.TryGetAttatchedPropertyValue(property, out value);
            return(value);
        }
示例#5
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"));
        }
示例#6
0
        /// <summary>
        /// Gets types list which declared into XAML markup.
        /// </summary>
        /// <returns>Returns <see cref="Lardite.RefAssistant.ObjectModel.Checkers.XamlTypeDeclaration"/> collection.</returns>
        public IEnumerable <XamlTypeDeclaration> GetDeclaredTypes()
        {
            XamlDomObject rootNode = XamlDomServices.Load(_xamlReader) as XamlDomObject;

            return((rootNode != null)
                ? rootNode.DescendantsAndSelf().Select(t => new XamlTypeDeclaration(t.Type))
                : new List <XamlTypeDeclaration>());
        }
示例#7
0
        protected static void SetBackground(XElement element, XamlDomObject domObject)
        {
            var backgroundColor = GetElementWithMatchingAttribute(element, "key", "backgroundColor");

            if (backgroundColor != null)
            {
                SetColor(domObject, backgroundColor, domObject.Type.GetMember("Background"));
            }
        }
示例#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");
            }
        }
示例#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);
            }
        }
示例#10
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());
        }
示例#11
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());
        }
        private void WireNamesAndEvents(XamlDomObject rootDomObject, XDocument xDocument)
        {
            // Handle fields
            foreach (var outletElement in
                     from objectNode in xDocument.Descendants(XName.Get("object"))
                     let classMember = objectNode.Attribute(XName.Get("class"))
                                       where classMember != null && classMember.Value == "IBCocoaTouchOutletConnection"
                                       select objectNode)
            {
                var sourceId =
                    GetElementWithMatchingAttribute(outletElement, "key", "source", false)
                    .Attribute(XName.Get("ref"))
                    .Value;
                var destinationId =
                    GetElementWithMatchingAttribute(outletElement, "key", "destination", false)
                    .Attribute(XName.Get("ref"))
                    .Value;

                XamlDomObject targetObject;
                if (IdToObjectMap.TryGetValue(destinationId, out targetObject))
                {
                    var name = GetElementWithMatchingAttribute(outletElement, "key", "label").Value;
                    targetObject.MemberNodes.Insert(0, new XamlDomMember(XamlLanguage.Name, name));
                }
            }

            // Handle Events
            foreach (var eventElement in
                     from objectNode in xDocument.Descendants(XName.Get("object"))
                     let classMember = objectNode.Attribute(XName.Get("class"))
                                       where classMember != null && classMember.Value == "IBCocoaTouchEventConnection"
                                       select objectNode)
            {
                var sourceId =
                    GetElementWithMatchingAttribute(eventElement, "key", "source", false)
                    .Attribute(XName.Get("ref"))
                    .Value;
                var destinationId =
                    GetElementWithMatchingAttribute(eventElement, "key", "destination", false)
                    .Attribute(XName.Get("ref"))
                    .Value;

                XamlDomObject sourceObject;
                if (IdToObjectMap.TryGetValue(sourceId, out sourceObject))
                {
                    var name = GetElementWithMatchingAttribute(eventElement, "key", "label").Value;
                    if (name.Contains(":"))
                    {
                        name = name.Replace(":", "");
                    }
                    sourceObject.MemberNodes.Insert(0, new XamlDomMember(GetEvent(eventElement, sourceObject), name));
                }
            }
        }
示例#13
0
        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());
        }
示例#14
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());
        }
示例#15
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);
         }
     }
 }
示例#16
0
 public static void Save(XamlDomObject rootObjectNode, string fileName)
 {
     var schemaContext = rootObjectNode.Type.SchemaContext;
     var dr = new XamlDomReader(rootObjectNode, schemaContext);
     var xws = new XmlWriterSettings();
     xws.Indent = true;
     using (var xw = XmlWriter.Create(fileName, xws))
     {
         var xxw = new XamlXmlWriter(xw, schemaContext);
         XamlServices.Transform(dr, xxw);
     }
 }
        private XamlDomObject CreateXamlDom(XDocument xDocument)
        {
            _document = xDocument;
            var schemaContext = new XamlSchemaContext();

            var rootObjectsTag = GetElementWithMatchingAttribute(xDocument.Root.Element(XName.Get("data")), "key", "IBDocument.RootObjects");
            var windowTag      = GetElementWithMatchingAttribute(rootObjectsTag, "class", "IBUIWindow");

            XamlDomObject rootDomObject;

            if (windowTag != null)
            {
                rootDomObject = ViewHandler.CreateObject(windowTag, schemaContext)[0];
            }
            else // No window so there's one or more views
            {
                rootDomObject = new XamlDomObject(schemaContext.GetXamlType(typeof(UserControl)));
                var canvas = new XamlDomObject(schemaContext.GetXamlType(typeof(Canvas)));

                // TODO: We should make the DOM handle string based lookup of content here correctly.  Null refs currently
                rootDomObject.MemberNodes.Add(
                    new XamlDomMember(schemaContext.GetXamlType(typeof(UserControl)).ContentProperty, canvas));
                var canvasChildrenMember = new XamlDomMember(schemaContext.GetXamlType(typeof(Canvas)).ContentProperty);
                canvas.MemberNodes.Add(canvasChildrenMember);

                foreach (var viewTag in from objectTag in rootObjectsTag.Elements()
                         let attriNode = objectTag.Attribute(XName.Get("class"))
                                         where attriNode != null
                                         select objectTag)
                {
                    if (viewTag.Attribute(XName.Get("class")).Value == "IBProxyObject" ||
                        viewTag.Attribute(XName.Get("class")).Value == "IBUICustomObject")
                    {
                        continue;
                    }
                    ViewHandler.AddControlToTree(canvasChildrenMember, viewTag);
                }
            }

            // Scale to make it the right dimensions
            rootDomObject.MemberNodes.Add(
                new XamlDomMember(rootDomObject.Type.GetMember("RenderTransform"),
                                  new XamlDomObject(typeof(ScaleTransform),
                                                    new XamlDomMember("CenterX", (IPHONE_WIDTH / 2).ToString()),
                                                    new XamlDomMember("CenterY", (IPHONE_HEIGHT / 2).ToString()),
                                                    new XamlDomMember("ScaleX", WIDTHMULTIPLIER.ToString()),
                                                    new XamlDomMember("ScaleY", HEIGHTMULTIPLIER.ToString()))));

            WireNamesAndEvents(rootDomObject, xDocument);

            return(rootDomObject);
        }
示例#18
0
        internal static new void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            // TextBlock doesn't like Inlines as content in attribute form...
            GetAndSetValue(tag, domObject, "IBUIText", domObject.Type.GetMember("Text"));

            var backgroundColor = GetElementWithMatchingAttribute(tag, "key", "IBUITextColor");
            if (backgroundColor != null)
            {
                SetColor(domObject, backgroundColor, domObject.Type.GetMember("Foreground"));
            }
        }
示例#19
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);
                }
            }
        }
示例#20
0
        internal new static List <XamlDomObject> CreateObject(XElement tag, XamlSchemaContext schema)
        {
            var domObjects = new List <XamlDomObject>();

            Debug.Assert(tag != null);

            // Create the view and canvas
            var listBoxItem = new XamlDomObject(schema.GetXamlType(typeof(ListBoxItem)));

            SetCommonProperties(tag, listBoxItem);
            domObjects.Add(listBoxItem);

            return(domObjects);
        }
示例#21
0
        internal new static void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            // TextBlock doesn't like Inlines as content in attribute form...
            GetAndSetValue(tag, domObject, "IBUIText", domObject.Type.GetMember("Text"));

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

            if (backgroundColor != null)
            {
                SetColor(domObject, backgroundColor, domObject.Type.GetMember("Foreground"));
            }
        }
示例#22
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");
                }
            }
        }
示例#23
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);
            }
        }
示例#24
0
        protected static void SetName(XElement element, XamlDomObject domObject)
        {
            // Mark IDs so we can wire events and names properly. We need to strip them before sending to XXW though.
            var idAttr = element.Attribute(XName.Get("id"));

            if (idAttr != null)
            {
                XamlXibReader.IdToObjectMap.Add(idAttr.Value, domObject);

                // Modify the ID attrib so it doesn't contain dashes
                var name = idAttr.Value.Replace("-", "");
                domObject.MemberNodes.Insert(0, new XamlDomMember(XamlLanguage.Name, name));
            }
        }
示例#25
0
        internal static new List<XamlDomObject> CreateObject(XElement tag, XamlSchemaContext schema)
        {
            var domObjects = new List<XamlDomObject>();

            Debug.Assert(tag != null);

            // Create the view and canvas
            var listBox = new XamlDomObject(schema.GetXamlType(typeof(ListBox)));

            SetCommonProperties(tag, listBox);
            domObjects.Add(listBox);

            return domObjects;
        }
示例#26
0
        internal static List <XamlDomObject> CreateObject(XElement tag, XamlSchemaContext schema)
        {
            Debug.Assert(tag != null);

            var domObjects = new List <XamlDomObject>();

            // Create the view and canvas
            var canvas = new XamlDomObject(schema.GetXamlType(typeof(Canvas)));

            SetCommonProperties(tag, canvas);
            AddChildren(tag, schema.GetXamlType(typeof(Canvas)).ContentProperty, canvas);
            domObjects.Add(canvas);

            return(domObjects);
        }
 internal static XamlMember GetEvent(XElement eventElement, XamlDomObject domObject)
 {
     if (domObject.Type.CanAssignTo(domObject.SchemaContext.GetXamlType(typeof(Slider))))
     {
         return(domObject.Type.GetMember("ValueChanged"));
     }
     if (domObject.Type.CanAssignTo(domObject.SchemaContext.GetXamlType(typeof(TextBox))))
     {
         return(domObject.Type.GetMember("TextChanged"));
     }
     if (domObject.Type.CanAssignTo(domObject.SchemaContext.GetXamlType(typeof(Button))))
     {
         return(domObject.Type.GetMember("Click"));
     }
     throw new NotImplementedException();
 }
示例#28
0
        public static bool TryGetAttatchedPropertyValue <T>(this XamlDomObject sourceObject, DependencyProperty property, out T value)
        {
            Debug.Assert(typeof(T).IsAssignableFrom(property.PropertyType));
            var demoMember = sourceObject.GetAttachableMemberNode(property.OwnerType, property.Name);

            if (demoMember != null && demoMember.Item is XamlDomValue)
            {
                var item = (XamlDomValue)demoMember.Item;
                value = (T)item.Value;
                return(true);
            }
            else
            {
                value = default(T);
                return(false);
            }
        }
示例#29
0
        protected static void AddChildren(XElement tag, XamlMember contentMember, XamlDomObject domObject)
        {
            var contentMemberNode = new XamlDomMember(contentMember);

            // Add children
            var subViews = tag.Element(XName.Get("subviews"));

            if (subViews != null)
            {
                foreach (var element in subViews.Elements(XName.Get("object")))
                {
                    AddControlToTree(contentMemberNode, element);
                }
            }

            domObject.MemberNodes.Add(contentMemberNode);
        }
示例#30
0
        internal static void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            Debug.Assert(tag != null && domObject != null);

            SetName(tag, domObject);

            SetFrameSize(tag, domObject);

            SetOpacity(tag, domObject);

            SetBackground(tag, domObject);

            GetDimensions(tag, domObject);

            // TODO: Re-enable once we figure out why the bindings do not permit single quotes in them
            //SetBindings(tag, domObject);
        }
示例#31
0
        internal static void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            Debug.Assert(tag != null && domObject != null);

            // Mark ids so we can wire events and names properly.
            // We need to strip them before sending to XXW though.
            var idAttr = tag.Attribute(XName.Get("id"));

            if (idAttr != null)
            {
                XamlLegacyXibReader.IdToObjectMap.Add(idAttr.Value, domObject);
            }

            SetFrameSize(tag, domObject);

            SetOpacity(tag, domObject);

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

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

            GetDimensions(tag, domObject);

            //var colors = from nsColor in element.Elements(XName.Get("object"))
            //             where nsColor.Attribute(XName.Get("class")).Value == "NSColor"
            //             select nsColor;

            //foreach (var color in colors)
            //{
            //    GetColor(controlType, domObject, color);
            //}

            //GetNormalTitle(element, domObject);

            //GetFont(element, controlType, domObject);

            //GetOpacity(element, controlType, domObject);

            //GetText(element, domObject);

            //GetImage(element, domObject);
        }
示例#32
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);
            }
        }
示例#33
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);
                }
            }
        }
示例#34
0
        protected static void SetBindings(XElement element, XamlDomObject domObject)
        {
            var connections = element.Element(XName.Get("connections"));

            if (connections != null)
            {
                foreach (var action in connections.Elements(XName.Get("action")))
                {
                    var selector = action.Attribute(XName.Get("selector"));
                    if (selector != null)
                    {
                        var selectorValue = selector.Value;
                        if (selectorValue.Contains(":"))
                        {
                            var bindingDelegate = string.Format(XBindFormatString, selectorValue);
                            domObject.MemberNodes.Insert(0, new XamlDomMember(GetEvent(domObject), bindingDelegate));
                        }
                    }
                }
            }
        }
示例#35
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);
            }
        }
示例#36
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);
        }
示例#37
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);
            }
        }
示例#38
0
        internal static new List<XamlDomObject> CreateObject(XElement tag, XamlSchemaContext schema)
        {
            var domObjects = new List<XamlDomObject>();

            var listBox = new XamlDomObject(schema.GetXamlType(typeof(ListBox)));
            var childrenMember = new XamlDomMember(listBox.Type.ContentProperty);
            listBox.MemberNodes.Add(childrenMember);

            var titles = GetElementWithMatchingAttribute(tag, "key", "IBSegmentTitles");
            Debug.Assert(titles != null);

            foreach (var title in titles.Elements(XName.Get("string")))
            {
                childrenMember.Items.Add(new XamlDomObject(schema.GetXamlType(typeof(ListBoxItem)),
                    new XamlDomMember(XamlLanguage.Initialization, title.Value)));
            }

            SetCommonProperties(tag, listBox);
            domObjects.Add(listBox);

            return domObjects;
        }
示例#39
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);
        }
示例#40
0
        private void WireNamesAndEvents(XamlDomObject rootDomObject, XDocument xDocument)
        {
            // Handle fields
            foreach (var outletElement in
                from objectNode in xDocument.Descendants(XName.Get("object"))
                let classMember = objectNode.Attribute(XName.Get("class"))
                where classMember != null && classMember.Value == "IBCocoaTouchOutletConnection"
                select objectNode)
            {
                var sourceId =
                    GetElementWithMatchingAttribute(outletElement, "key", "source", false)
                        .Attribute(XName.Get("ref"))
                        .Value;
                var destinationId =
                    GetElementWithMatchingAttribute(outletElement, "key", "destination", false)
                        .Attribute(XName.Get("ref"))
                        .Value;

                XamlDomObject targetObject;
                if (IdToObjectMap.TryGetValue(destinationId, out targetObject))
                {
                    var name = GetElementWithMatchingAttribute(outletElement, "key", "label").Value;
                    targetObject.MemberNodes.Insert(0, new XamlDomMember(XamlLanguage.Name, name));
                }
            }

            // Handle Events
            foreach (var eventElement in
                from objectNode in xDocument.Descendants(XName.Get("object"))
                let classMember = objectNode.Attribute(XName.Get("class"))
                where classMember != null && classMember.Value == "IBCocoaTouchEventConnection"
                select objectNode)
            {
                var sourceId =
                    GetElementWithMatchingAttribute(eventElement, "key", "source", false)
                        .Attribute(XName.Get("ref"))
                        .Value;
                var destinationId =
                    GetElementWithMatchingAttribute(eventElement, "key", "destination", false)
                        .Attribute(XName.Get("ref"))
                        .Value;

                XamlDomObject sourceObject;
                if (IdToObjectMap.TryGetValue(sourceId, out sourceObject))
                {
                    var name = GetElementWithMatchingAttribute(eventElement, "key", "label").Value;
                    if (name.Contains(":"))
                    {
                        name = name.Replace(":", "");
                    }
                    sourceObject.MemberNodes.Insert(0, new XamlDomMember(GetEvent(eventElement, sourceObject), name));
                }
            }
        }
示例#41
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);
            }
        }
示例#42
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);
        }
示例#43
0
        private static XamlDomObject CreateView(XElement viewTag, XamlSchemaContext schemaContext)
        {
            Debug.Assert(viewTag != null);

            // Create the view and canvas
            var canvas = new XamlDomObject(schemaContext.GetXamlType(typeof(Canvas)));
            var canvasChildrenMember = new XamlDomMember(schemaContext.GetXamlType(typeof(Canvas)).ContentProperty);

            SetFrameSize(viewTag, canvas);

            var backgroundColor = GetElementWithMatchingAttribute(viewTag, "key", "IBUIBackgroundColor");
            //GetColor(canvas.Type, canvas, backgroundColor);

            // Add children
            var subViews = GetElementWithMatchingAttribute(viewTag, "key", "NSSubviews");
            if (subViews != null)
            {
                foreach (var element in subViews.Elements(XName.Get("object")))
                {
                    AddControlToTree(canvasChildrenMember, element);
                }
            }

            // TODO: Fix XamlToolkit to not choke on members with nothing inside of it
            if (canvasChildrenMember.Items != null && canvasChildrenMember.Items.Count > 0)
            {
                canvas.MemberNodes.Add(canvasChildrenMember);
            }

            return canvas;
        }
示例#44
0
        private XamlDomObject CreateXamlDom(XDocument xDocument)
        {
            _document = xDocument;
            var schemaContext = new XamlSchemaContext();

            var rootObjectsTag = GetElementWithMatchingAttribute(xDocument.Root.Element(XName.Get("data")), "key", "IBDocument.RootObjects");
            var windowTag = GetElementWithMatchingAttribute(rootObjectsTag, "class", "IBUIWindow");

            XamlDomObject rootDomObject;
            if (windowTag != null)
            {
                rootDomObject = ViewHandler.CreateObject(windowTag, schemaContext)[0];
            }
            else // No window so there's one or more views
            {
                rootDomObject = new XamlDomObject(schemaContext.GetXamlType(typeof(UserControl)));
                var canvas = new XamlDomObject(schemaContext.GetXamlType(typeof(Canvas)));

                // TODO: We should make the DOM handle string based lookup of content here correctly.  Null refs currently
                rootDomObject.MemberNodes.Add(
                    new XamlDomMember(schemaContext.GetXamlType(typeof(UserControl)).ContentProperty, canvas));
                var canvasChildrenMember = new XamlDomMember(schemaContext.GetXamlType(typeof(Canvas)).ContentProperty);
                canvas.MemberNodes.Add(canvasChildrenMember);

                foreach (var viewTag in from objectTag in rootObjectsTag.Elements()
                    let attriNode = objectTag.Attribute(XName.Get("class"))
                    where attriNode != null
                    select objectTag)
                {
                    if (viewTag.Attribute(XName.Get("class")).Value == "IBProxyObject" ||
                        viewTag.Attribute(XName.Get("class")).Value == "IBUICustomObject")
                    {
                        continue;
                    }
                    ViewHandler.AddControlToTree(canvasChildrenMember, viewTag);
                }
            }

            // Scale to make it the right dimensions
            rootDomObject.MemberNodes.Add(
                new XamlDomMember(rootDomObject.Type.GetMember("RenderTransform"),
                    new XamlDomObject(typeof(ScaleTransform),
                        new XamlDomMember("CenterX", (IPHONE_WIDTH/2).ToString()),
                        new XamlDomMember("CenterY", (IPHONE_HEIGHT/2).ToString()),
                        new XamlDomMember("ScaleX", WIDTHMULTIPLIER.ToString()),
                        new XamlDomMember("ScaleY", HEIGHTMULTIPLIER.ToString()))));

            WireNamesAndEvents(rootDomObject, xDocument);

            return rootDomObject;
        }
示例#45
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);
     }
 }
示例#46
0
        private IEnumerable<XamlNode> WriteElementMembers(XamlDomObject objectNode)
        {
            foreach (var memberNode in objectNode.MemberNodes)
            {
                if (IsAttribute(memberNode))
                {
                    continue;
                }

                foreach (var node in ReadMemberNode(memberNode))
                {
                    yield return node;
                }
            }
        }
示例#47
0
        private IEnumerable<XamlNode> ReadObjectNode(XamlDomObject objectNode)
        {
            foreach (var nsNode in objectNode.Namespaces)
            {
                yield return XamlNode.GetNamespaceDeclaration(nsNode);
            }

            yield return XamlNode.GetStartObject(objectNode);

            // We want to write out simple things that could be attributes out first if setting is set
            // We write out single values and things that are MEs
            if (!_doNotReorder)
            {
                foreach (var node in WritePossibleAttributes(objectNode))
                {
                    yield return node;
                }

                foreach (var node in WriteElementMembers(objectNode))
                {
                    yield return node;
                }
            }
            else
            {
                foreach (var memberNode in objectNode.MemberNodes)
                {
                    foreach (var node in ReadMemberNode(memberNode))
                    {
                        yield return node;
                    }
                }
            }

            yield return XamlNode.GetEndObject(objectNode);
        }
示例#48
0
        internal static new void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            // Find the normal state which translates into the default attributes on a XAML button
            var state = GetElementWithMatchingAttribute(tag, "key", "normal");
            if (state != null)
            {
                GetAndSetValue(state, domObject, "title", domObject.Type.ContentProperty);

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

            var normalTitle = GetValueWithMatchingAttribute(tag, "key", "normalTitle");
            var highlightedTitle = GetValueWithMatchingAttribute(tag, "key", "highlightedTitle");
            var disabledTitle = GetValueWithMatchingAttribute(tag, "key", "disabledTitle");
            var selectedTitle = GetValueWithMatchingAttribute(tag, "key", "selectedTitle");

            if (highlightedTitle != normalTitle && !string.IsNullOrEmpty(highlightedTitle))
            {
                throw new NotImplementedException();
            }
            if (disabledTitle != normalTitle && !string.IsNullOrEmpty(disabledTitle))
            {
                throw new NotImplementedException();
            }
            if (selectedTitle != normalTitle && !string.IsNullOrEmpty(selectedTitle))
            {
                throw new NotImplementedException();
            }

            string normalImagePath = null;
            string selectedImagePath = null;
            string disabledImagePath = null;
            string highlightedImagePath = null;

            // Check for images
            var normalImage = GetElementWithMatchingAttribute(tag, "key", "normalImage");
            if (normalImage != null)
            {
                Debug.Assert("NSImage" == GetElementWithMatchingAttribute(normalImage, "key", "NSClassName").Value);
                normalImagePath = GetElementWithMatchingAttribute(normalImage, "key", "NSResourceName").Value;
            }

            var selectedImage = GetElementWithMatchingAttribute(tag, "key", "selectedImage");
            if (selectedImage != null)
            {
                Debug.Assert("NSImage" == GetElementWithMatchingAttribute(normalImage, "key", "NSClassName").Value);
                selectedImagePath = GetElementWithMatchingAttribute(normalImage, "key", "NSResourceName").Value;
            }

            var disabledImage = GetElementWithMatchingAttribute(tag, "key", "selectedImage");
            if (disabledImage != null)
            {
                Debug.Assert("NSImage" == GetElementWithMatchingAttribute(normalImage, "key", "NSClassName").Value);
                disabledImagePath = GetElementWithMatchingAttribute(normalImage, "key", "NSResourceName").Value;
            }

            var highlightedImage = GetElementWithMatchingAttribute(tag, "key", "selectedImage");
            if (highlightedImage != null)
            {
                Debug.Assert("NSImage" == GetElementWithMatchingAttribute(normalImage, "key", "NSClassName").Value);
                highlightedImagePath = GetElementWithMatchingAttribute(normalImage, "key", "NSResourceName").Value;
            }

            if (highlightedImagePath != normalImagePath)
            {
                throw new NotImplementedException();
            }

            if (disabledImagePath != normalImagePath)
            {
                throw new NotImplementedException();
            }

            if (selectedImagePath != normalImagePath)
            {
                throw new NotImplementedException();
            }

            Debug.Assert(string.IsNullOrEmpty(normalImagePath) || string.IsNullOrEmpty(normalTitle));

            if (normalImagePath != null)
            {
                var controlTemplateObject =
                    new XamlDomObject(domObject.SchemaContext.GetXamlType(typeof(ControlTemplate)),
                        new XamlDomMember("TargetType", "Button"),
                        new XamlDomMember(domObject.SchemaContext.GetXamlType(typeof(ControlTemplate)).ContentProperty,
                            new XamlDomObject(typeof(Image),
                                new XamlDomMember("Source", normalImagePath)
                                )
                            )
                        );

                var sourceMember = new XamlDomMember(domObject.Type.GetMember("Template"));
                sourceMember.Items.Add(controlTemplateObject);

                domObject.MemberNodes.Add(sourceMember);
            }
        }
示例#49
0
 public PostProcessor(XamlDomObject objectNode)
 {
     _rootNode = objectNode;
 }
示例#50
0
        internal static List<XamlDomObject> CreateObject(XElement tag, XamlSchemaContext schema)
        {
            var domObjects = new List<XamlDomObject>();

            Debug.Assert(tag != null);

            // Create the view and canvas
            var canvas = new XamlDomObject(schema.GetXamlType(typeof(Canvas)));

            SetCommonProperties(tag, canvas);

            AddChildren(tag, schema.GetXamlType(typeof(Canvas)).ContentProperty, canvas);

            domObjects.Add(canvas);

            return domObjects;
        }
示例#51
0
 private IEnumerable<XamlNode> WritePossibleAttributes(XamlDomObject objectNode)
 {
     foreach (var memberNode in objectNode.MemberNodes)
     {
         if (IsAttribute(memberNode))
         {
             foreach (var node in ReadMemberNode(memberNode))
             {
                 yield return node;
             }
         }
     }
 }
示例#52
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");
         }
     }
 }
示例#53
0
 public static XamlNode GetStartObject(XamlDomObject objectNode)
 {
     _xamlNode.Clear();
     if (objectNode.IsGetObject)
     {
         _xamlNode.NodeType = XamlNodeType.GetObject;
     }
     else
     {
         _xamlNode.NodeType = XamlNodeType.StartObject;
         _xamlNode.Type = objectNode.Type;
     }
     _xamlNode.LineNumber = objectNode.StartLineNumber;
     _xamlNode.LinePosition = objectNode.StartLinePosition;
     return _xamlNode;
 }
示例#54
0
 internal static XamlNode GetEndObject(XamlDomObject objectNode)
 {
     _xamlNode.Clear();
     _xamlNode.NodeType = XamlNodeType.EndObject;
     _xamlNode.LineNumber = objectNode.EndLineNumber;
     _xamlNode.LinePosition = objectNode.EndLinePosition;
     return _xamlNode;
 }
 internal static new void SetCommonProperties(XElement tag, XamlDomObject domObject)
 {
     ViewHandler.SetCommonProperties(tag, domObject);
 }
示例#56
0
        internal static new void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            GetAndSetValue(tag, domObject, "title", domObject.Type.ContentProperty);
        }
示例#57
0
        protected static void AddChildren(XElement tag, XamlMember contentMember, XamlDomObject domObject)
        {
            var contentMemberNode = new XamlDomMember(contentMember);

            // Add children
            var subViews = GetElementWithMatchingAttribute(tag, "key", "NSSubviews");
            if (subViews != null)
            {
                foreach (var element in subViews.Elements(XName.Get("object")))
                {
                    AddControlToTree(contentMemberNode, element);
                }
            }

            domObject.MemberNodes.Add(contentMemberNode);
        }
示例#58
0
        internal static void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            Debug.Assert(tag != null && domObject != null);

            // Mark ids so we can wire events and names properly.
            // We need to strip them before sending to XXW though.
            var idAttr = tag.Attribute(XName.Get("id"));
            if (idAttr != null)
            {
                XamlLegacyXibReader.IdToObjectMap.Add(idAttr.Value, domObject);
            }

            SetFrameSize(tag, domObject);

            SetOpacity(tag, domObject);

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

            GetDimensions(tag, domObject);

            //var colors = from nsColor in element.Elements(XName.Get("object"))
            //             where nsColor.Attribute(XName.Get("class")).Value == "NSColor"
            //             select nsColor;

            //foreach (var color in colors)
            //{
            //    GetColor(controlType, domObject, color);
            //}

            //GetNormalTitle(element, domObject);

            //GetFont(element, controlType, domObject);

            //GetOpacity(element, controlType, domObject);

            //GetText(element, domObject);

            //GetImage(element, domObject);
        }
示例#59
0
        internal static new void SetCommonProperties(XElement tag, XamlDomObject domObject)
        {
            ViewHandler.SetCommonProperties(tag, domObject);

            AddChildren(tag, domObject.Type.ContentProperty, domObject);
        }
示例#60
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);
     }
 }