예제 #1
0
        protected bool parseWindowAttributes(ref MarkupNode root, ref PaintManagerUI manager)
        {
            if (manager != null)
            {
                string className = root.getName();
                if (className == "Window")
                {
                    List <MarkupNode> listNode     = root.getChildList();
                    string            imageName    = "";
                    string            imageResType = "";
                    uint mask = 0;
                    foreach (var node in listNode)
                    {
                        if (node.getName() == "Image")
                        {
                            List <XMLAttribute> listAttr = node.getAttributeList();
                            foreach (var attr in listAttr)
                            {
                                if (attr.getName() == "name")
                                {
                                    imageName = attr.getValue();
                                }
                                else if (attr.getName() == "restype")
                                {
                                    imageResType = attr.getValue();
                                }
                                else if (attr.getName() == "mask")
                                {
                                    string sMask = attr.getValue();
                                    sMask = sMask.TrimStart('#');
                                    mask  = uint.Parse(sMask);
                                }
                            }

                            if (imageName != "")
                            {
                                manager.addImage(imageName, imageResType, (int)mask);
                            }
                        }
                        else if (node.getName() == "Font")
                        {
                            string fontName        = "";
                            int    size            = 10;
                            bool   bold            = false;
                            bool   underline       = false;
                            bool   italic          = false;
                            bool   defaultfont     = false;
                            bool   defaultboldfont = false;
                            bool   defaultlinkfont = false;

                            List <XMLAttribute> listAttr = node.getAttributeList();

                            foreach (var attr in listAttr)
                            {
                                if (attr.getName() == "name")
                                {
                                    fontName = attr.getValue();
                                }
                                else if (attr.getName() == "size")
                                {
                                    size = int.Parse(attr.getValue());
                                }
                                else if (attr.getName() == "bold")
                                {
                                    bold = attr.getValue() == "true";
                                }
                                else if (attr.getName() == "underline")
                                {
                                    underline = attr.getValue() == "true";
                                }
                                else if (attr.getName() == "italic")
                                {
                                    italic = attr.getValue() == "true";
                                }
                                else if (attr.getName() == "default")
                                {
                                    defaultfont = attr.getValue() == "true";
                                }
                                else if (attr.getName() == "defaultbold")
                                {
                                    defaultboldfont = attr.getValue() == "true";
                                }
                                else if (attr.getName() == "defaultlink")
                                {
                                    defaultlinkfont = attr.getValue() == "true";
                                }
                            }

                            if (fontName != "")
                            {
                                Font font = manager.addFont(fontName, size - 3, bold, underline, italic);
                                if (font != null)
                                {
                                    if (defaultfont)
                                    {
                                        manager.setDefaultFont(font);
                                    }
                                    if (defaultboldfont)
                                    {
                                        manager.setDefaultBoldFont(font);
                                    }
                                    if (defaultlinkfont)
                                    {
                                        manager.setDefaultLinkFont(font);
                                    }
                                }
                            }
                        }
                        else if (node.getName() == "Default")
                        {
                            List <XMLAttribute> listAttr = node.getAttributeList();
                            string ctlName  = "";
                            string ctlValue = "";

                            foreach (var attr in listAttr)
                            {
                                if (attr.getName() == "name")
                                {
                                    ctlName = attr.getValue();
                                }
                                else if (attr.getName() == "value")
                                {
                                    ctlValue = attr.getValue();
                                }
                            }
                            if (ctlName != "")
                            {
                                manager.addDefaultAttributeList(ctlName, ctlValue);
                            }
                        }
                    }

                    if (manager.getPaintWindow() != null)
                    {
                        List <XMLAttribute> listAttr = root.getAttributeList();
                        foreach (var attr in listAttr)
                        {
                            if (attr.getName() == "size")
                            {
                                string[] listValue = attr.getValue().Split(',');
                                if (listValue.Length != 2)
                                {
                                    throw new Exception("窗口大小参数值有误");
                                }
                                int cx = int.Parse(listValue[0]);
                                int cy = int.Parse(listValue[1]);
                                manager.setInitSize(cx, cy);
                            }
                            else if (attr.getName() == "sizebox")
                            {
                                string[] listValue = attr.getValue().Split(',');
                                if (listValue.Length != 4)
                                {
                                    throw new Exception("窗口大小参数值有误");
                                }
                                int left   = int.Parse(listValue[0]);
                                int top    = int.Parse(listValue[1]);
                                int right  = int.Parse(listValue[2]);
                                int bottom = int.Parse(listValue[3]);

                                Rectangle rect = new Rectangle(left, top, right - left, bottom - top);
                                manager.setSizeBox(ref rect);
                            }
                            else if (attr.getName() == "caption")
                            {
                                string[] listValue = attr.getValue().Split(',');
                                if (listValue.Length != 4)
                                {
                                    throw new Exception("标题大小参数值有误");
                                }
                                int left   = int.Parse(listValue[0]);
                                int top    = int.Parse(listValue[1]);
                                int right  = int.Parse(listValue[2]);
                                int bottom = int.Parse(listValue[3]);

                                Rectangle rect = new Rectangle(left, top, right - left, bottom - top);
                                manager.setCaptionRect(ref rect);
                            }
                            else if (attr.getName() == "roundcorner")
                            {
                                string[] listValue = attr.getValue().Split(',');
                                if (listValue.Length < 2)
                                {
                                    throw new Exception("窗口边框圆角半径参数值有误");
                                }
                                int cx = int.Parse(listValue[0]);
                                int cy = int.Parse(listValue[1]);
                                manager.setRoundCorner(cx, cy);
                            }
                            else if (attr.getName() == "mininfo")
                            {
                                string[] listValue = attr.getValue().Split(',');
                                if (listValue.Length != 2)
                                {
                                    throw new Exception("窗口大小最小值参数值有误");
                                }
                                int cx = int.Parse(listValue[0]);
                                int cy = int.Parse(listValue[1]);
                                manager.setMinMaxInfo(cx, cy);
                            }
                            else if (attr.getName() == "showdirty")
                            {
                                manager.setShowUpdateRect(attr.getValue() == "true");
                            }
                        }
                    }
                }
            }

            return(true);
        }