예제 #1
0
        private void ParseWidget(List <Widget> _widgets, XmlNode _node, Widget _parent, Widget _root, string _prefix)
        {
            string style = "", type = "", skin = "", name = "", layer = "", align = "", position = "";

            foreach (XmlAttribute attribute in _node.Attributes)
            {
                switch (attribute.Name)
                {
                case "style": style = attribute.Value; break;

                case "type": type = attribute.Value; break;

                case "skin": skin = attribute.Value; break;

                case "name": name = attribute.Value; break;

                case "layer": layer = attribute.Value; break;

                case "align": align = attribute.Value; break;

                case "position": position = attribute.Value; break;
                }

                if (type == "Sheet")
                {
                    type = "TabItem";
                }
            }

            if ((0 == type.Length) || (0 == skin.Length))
            {
                return;
            }

            if ((0 != name.Length) && (0 != _prefix.Length))
            {
                name = _prefix + name;
            }

            string[] coord = position.Split();

            WidgetStyle wstyle = WidgetStyle.Overlapped;

            if (_parent != null)
            {
                layer  = "";
                wstyle = (style != string.Empty) ? (WidgetStyle)Enum.Parse(typeof(WidgetStyle), style) : WidgetStyle.Child;
            }

            Align walign = Align.Default;

            if (align != string.Empty)
            {
                walign = Align.Center;
                string[] mass = align.Split();
                foreach (string item in mass)
                {
                    walign |= (Align)Enum.Parse(typeof(Align), item);
                }
            }

            Widget widget = (Widget)mMapCreator[type](
                _parent,
                wstyle,
                skin,
                ((coord.Length == 4) ? new IntCoord(int.Parse(coord[0]), int.Parse(coord[1]), int.Parse(coord[2]), int.Parse(coord[3])) : new IntCoord()),
                walign,
                layer,
                name);

            if (null == _root)
            {
                _root = widget;
                _widgets.Add(_root);
            }

            foreach (XmlNode node in _node)
            {
                if ("Widget" == node.Name)
                {
                    ParseWidget(_widgets, node, widget, _root, _prefix);
                }
                else if ("Property" == node.Name)
                {
                    string key = "", value = "";
                    foreach (XmlAttribute attribute in node.Attributes)
                    {
                        if ("key" == attribute.Name)
                        {
                            key = attribute.Value;
                        }
                        else if ("value" == attribute.Name)
                        {
                            value = attribute.Value;
                        }
                    }
                    if ((0 == key.Length) || (0 == value.Length))
                    {
                        continue;
                    }

                    SetProperty(widget, key, value);
                }
                else if ("UserString" == node.Name)
                {
                    string key = "", value = "";
                    foreach (XmlAttribute attribute in node.Attributes)
                    {
                        if ("key" == attribute.Name)
                        {
                            key = attribute.Value;
                        }
                        else if ("value" == attribute.Name)
                        {
                            value = attribute.Value;
                        }
                    }
                    if ((0 == key.Length) || (0 == value.Length))
                    {
                        continue;
                    }
                    widget.SetUserString(key, value);

                    if (EventParserUserData != null)
                    {
                        EventParserUserData(widget, key, value);
                    }
                }
            }
        }