public MarkupNode(MarkupNode parent) { mNodeName = ""; mParentNode = parent; mListChildNode = new List <MarkupNode>(); mListAttribute = new List <XMLAttribute>(); { if (parent != null) { List <MarkupNode> listChild = parent.getChildList(); listChild.Add(this); } } }
public bool release() { if (mRootNode != null) { Stack <MarkupNode> stackNode = new Stack <MarkupNode>(); stackNode.Push(mRootNode); { while (stackNode.Count() > 0) { MarkupNode node = stackNode.Peek(); List <MarkupNode> listNode = node.getChildList(); if (listNode.Count() > 0) { stackNode.Push(listNode[0]); continue; } MarkupNode nodeDiscard = stackNode.Pop(); if (stackNode.Count() > 0) { MarkupNode nodeParent = stackNode.Peek(); nodeParent.removeChild(0); } nodeDiscard.release(); nodeDiscard = null; } } stackNode.Clear(); stackNode = null; mRootNode = null; } return(true); }
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); }
// 广度优先搜索XML节点树创建相应的控件树,过滤非控件节点 protected ControlUI parse(ref MarkupNode parentNode, ref ControlUI parentControl, ref PaintManagerUI manager) { if (parentNode == null) { throw new Exception("对象未赋值"); } ControlUI ctlParent = null; { //parentControl.setManager(manager, null); Queue <MarkupNode> queueNode = new Queue <MarkupNode>(); Queue <ControlUI> queueControl = new Queue <ControlUI>(); queueNode.Enqueue(parentNode); queueControl.Enqueue(parentControl); while (queueNode.Count > 0) { MarkupNode curNode = queueNode.Dequeue(); ControlUI curParentControl = queueControl.Dequeue(); List <MarkupNode> listNode = curNode.getChildList(); // 访问根节点 if (listNode != null && listNode.Count > 0) { // 子节点入队 foreach (var node in listNode) { // 过滤非控件节点 if (node.getName() == "Window" || node.getName() == "Image" || node.getName() == "Font" || node.getName() == "Default") { continue; } ControlUI newControl = null; { queueNode.Enqueue(node); // 创建控件,加入控件树后入队 newControl = getControl(node.getName()); if (newControl != null && newControl is ControlUI) { queueControl.Enqueue(newControl); newControl.setManager(manager, curParentControl); if (curParentControl != null) { IContainerUI container = (IContainerUI)curParentControl.getInterface("IContainer"); container.add(newControl); } else { if (ctlParent != null) { throw new Exception("不能有两个根容器"); } ctlParent = newControl; } } else if (mCallback != null) { newControl = mCallback.createControl(node.getName(), manager); if (newControl == null) { throw new Exception("未知控件类型"); } queueControl.Enqueue(newControl); newControl.setManager(manager, curParentControl); if (curParentControl != null) { IContainerUI container = (IContainerUI)curParentControl.getInterface("IContainer"); container.add(newControl); } else { if (ctlParent != null) { throw new Exception("不能有两个根容器"); } ctlParent = newControl; } } else { throw new Exception("未知控件类型"); } } { // 设置属性 if (manager != null) { //newControl.setManager(manager, curParentControl); string defaultAttributes = manager.getDefaultAttributeList(node.getName()); if (defaultAttributes != "") { newControl.applyAttributeList(defaultAttributes); } } List <XMLAttribute> listAttr = node.getAttributeList(); foreach (var attr in listAttr) { newControl.addAttribute(attr.getName(), attr.getValue()); newControl.setAttribute(attr.getName(), attr.getValue()); } } } } } } return(ctlParent); }