public bool onMessageHandle(int uMsg, ref object wParam, ref object lParam, ref int lRes) { if (uMsg == (int)WindowMessage.WM_CREATE) { Form frm = this; mManager.init(ref frm); // 给下拉列表子控件树重新设置父容器以及资源管理器,在组合框窗口关闭后需要还原该子树控件的父容器以及资源管理器 mVerticalLayout = new VerticalLayoutUI(); mManager.useParentResource(mOwner.getManager()); mVerticalLayout.setManager(mManager, null); string pDefaultAttributes = mOwner.getManager().getDefaultAttributeList("VerticalLayout"); if (pDefaultAttributes != "") { mVerticalLayout.applyAttributeList(pDefaultAttributes); } mVerticalLayout.setInset(new Rectangle(2, 2, 0, 0)); mVerticalLayout.setBackColor(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF)); mVerticalLayout.setBorderColor(Color.FromArgb(0xFF, 0x85, 0xE4, 0xFF)); mVerticalLayout.setBorderSize(2); mVerticalLayout.setAutoDestroy(false); mVerticalLayout.enableScrollBar(); mVerticalLayout.applyAttributeList(mOwner.getDropBoxAttributeList()); for (int i = 0; i < mOwner.getCount(); i++) { mVerticalLayout.add((ControlUI)mOwner.getItemAt(i)); } ControlUI rootNode = (ControlUI)mVerticalLayout; mManager.attachDialog(ref rootNode); this.ClientSize = new Size(mRectClient.Width, mRectClient.Height); return(true); } else if (uMsg == (int)WindowMessage.WM_SIZE) { this.ClientSize = new Size(mRectClient.Width, mRectClient.Height); return(true); } else if (uMsg == (int)WindowMessage.WM_ERASEBKGND) { lRes = 1; return(true); } else if (uMsg == (int)WindowMessage.WM_CLOSE) { mOwner.setManager(mOwner.getManager(), mOwner.getParent()); mOwner.setPos(mOwner.getPos()); mOwner.setFocus(); } else if (uMsg == (int)WindowMessage.WM_LBUTTONUP) { Point pt = Control.MousePosition; pt = mManager.getPaintWindow().PointToClient(pt); ControlUI pControl = mManager.findControl(ref pt); if (pControl != null && pControl.getClass() != "ScrollbarUI") { PaintManagerUI.PostMessage(this.Handle, (int)WindowMessage.WM_KILLFOCUS, 0, 0); } } else if (uMsg == (int)WindowMessage.WM_KEYDOWN) { IntPtr ptr = (IntPtr)wParam; int c = (int)ptr; char cc = (char)int.Parse(c.ToString()); switch ((Keys)cc) { case Keys.Escape: mOwner.selectItem(mOldSel); ensureVisible(mOldSel); PaintManagerUI.PostMessage(this.Handle, (int)WindowMessage.WM_KILLFOCUS, 0, 0); break; case Keys.Return: PaintManagerUI.PostMessage(this.Handle, (int)WindowMessage.WM_KILLFOCUS, 0, 0); break; default: TEventUI newEvent = new TEventUI(); newEvent.mType = (int)EVENTTYPE_UI.UIEVENT_KEYDOWN; newEvent.mKey = cc; mOwner.eventProc(ref newEvent); ensureVisible(mOwner.getCurSel()); return(true); } } else if (uMsg == (int)WindowMessage.WM_MOUSEWHEEL) { IntPtr ptr = (IntPtr)wParam; int c = (int)ptr; int zDelta = (int)(short)HIWORD(c); TEventUI newEvent = new TEventUI(); newEvent.mType = (int)EVENTTYPE_UI.UIEVENT_SCROLLWHEEL; newEvent.mWParam = makeLong(zDelta < 0 ? (int)ScrollBarCommands.SB_LINEDOWN : (int)ScrollBarCommands.SB_LINEUP, 0); newEvent.mLParam = lParam; newEvent.mTimestamp = PaintManagerUI.GetTickCount(); mOwner.eventProc(ref newEvent); ensureVisible(mOwner.getCurSel()); return(true); } else if (uMsg == (int)WindowMessage.WM_KILLFOCUS) { close(); } if (mManager != null && mManager.messageHandler((uint)uMsg, ref wParam, ref lParam, ref lRes)) { return(true); } return(false); }
public virtual void setManager(PaintManagerUI manager, ControlUI parent) { mManager = manager; mParent = parent; }
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 && mIsMainWindow) { 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); }
public ControlUI createFromMem(ref char[] buffer, int count, IDialogBuilderCallback callback = null, PaintManagerUI manager = null) { if (mXML.loadFromMem(ref buffer, buffer.Length) == false) { return(null); } MarkupNode root = mXML.getRoot(); ControlUI control = null; parseWindowAttributes(ref root, ref manager); ControlUI rootNode = parse(ref root, ref control, ref manager); root.release(); return(rootNode); }
public ControlUI createFromFile(string xmlFile, IDialogBuilderCallback callback = null, PaintManagerUI manager = null) { if (mXML.loadFromFile(xmlFile, manager) == false) { return(null); } mCallback = callback; MarkupNode root = mXML.getRoot(); parseWindowAttributes(ref root, ref manager); ControlUI control = null; ControlUI rootNode = parse(ref root, ref control, ref manager); root.release(); return(rootNode); }
// 广度优先搜索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); }