// parameters: // style 初始化风格。暂未使用。 public override void InitialVisualSpecial(Box boxTotal) { XmlText text = new XmlText (); text.Name = "TextOfAttrItem"; text.container = boxTotal; Debug.Assert(this.m_paraValue1 != null,"m_paraValue是用来传递参数,不能为null"); text.Text = this.GetValue();//this.m_paraValue; boxTotal.AddChildVisual(text); // 是否可以用SetValue() this.m_paraValue1 = null; if (this.IsNamespace == true) text.Editable = false; this.m_strTempURI = null; }
// parameters: // style 初始化风格。暂未使用。 public override void InitialVisualSpecial(Box boxTotal) { XmlText text = new XmlText (); text.Name = "TextOfTextItem"; text.container = boxTotal; Debug.Assert(this.m_paraValue1 != null,"初始值不能为null"); text.Text = this.GetValue(); //this.m_paraValue;; boxTotal.AddChildVisual(text); this.m_paraValue1 = null; /* if (this.parent .ReadOnly == true || this.ReadOnly == true) { text.Editable = false; } */ }
// 本函数对于派生类来说一般不要重载。一般重载InitialVisualSpecial()即可。 // 因为本函数代码前后部分基本是共用的,只有中段采用调用InitialVisualSpecial()的办法。 // 不过如果重载了本函数,并且不想在其中调用InitialVisualSpecial(),则需要自行实现全部功能 public override void InitialVisual() { if (this.childrenVisual != null) this.childrenVisual.Clear(); // 加Label XmlLabel label = new XmlLabel(); label.container = this; InitialLabelText(label); this.AddChildVisual(label); // 定义一个总框 Box boxTotal = new Box (); boxTotal.Name = "BoxTotal"; boxTotal.container = this; this.AddChildVisual (boxTotal); // 外面总框的layoutStyle样式为竖排 boxTotal.LayoutStyle = LayoutStyle.Vertical; /// InitialVisualSpecial(boxTotal); /// //如果boxTotal只有一个box,则设为横排 if (boxTotal.childrenVisual != null && boxTotal.childrenVisual .Count == 1) boxTotal.LayoutStyle = LayoutStyle.Horizontal ; /* Comment comment = new Comment (); comment.container = this; this.AddChildVisual(comment); */ }
public Box GetBoxContent(Box boxTotal) { if (boxTotal.childrenVisual == null) return null; Box boxContent = null; for(int i=0;i<boxTotal.childrenVisual.Count;i++) { Visual visual = (Visual)boxTotal.childrenVisual[i]; if (visual.Name == "BoxContent") { boxContent = (Box)visual; break; } } return boxContent; }
public Box GetBoxAttributes(Box boxTotal) { if (boxTotal.childrenVisual == null) return null; Box boxAttributes = null; for(int i=0;i<boxTotal.childrenVisual.Count;i++) { Visual visual = (Visual)boxTotal.childrenVisual[i]; if (visual.Name == "BoxAttributes") { boxAttributes = (Box)visual; break; } } return boxAttributes; }
public override void InitialVisualSpecial(Box boxTotal) { boxTotal.LayoutStyle = LayoutStyle.Vertical; if (this.m_bWantAttrsInitial == 1) { // 找到旧的BoxAttributes,删掉 Box oldBoxAttributes = this.GetBoxAttributes(boxTotal); if (oldBoxAttributes != null) boxTotal.childrenVisual.Remove(oldBoxAttributes); if (this.m_attrsExpand != ExpandStyle.None) { if (this.m_attrsExpand == ExpandStyle.Expand && this.attrs.Count == 0) { goto SKIPATTRS; } //定义包含展开按钮和属性的大框 Box boxAttrs = new Box (); boxAttrs.Name = "BoxAttributes"; boxAttrs.LayoutStyle = LayoutStyle.Horizontal; boxAttrs.container = boxTotal; //定义展开按钮 ExpandHandle expandAttributesHandle = new ExpandHandle (); expandAttributesHandle.Name = "ExpandAttributes"; expandAttributesHandle.container = boxAttrs; boxAttrs.AddChildVisual(expandAttributesHandle); //定义属性框 Attributes attributes = new Attributes(); attributes.container = boxAttrs; attributes.LayoutStyle = LayoutStyle.Vertical; //一般子元素都是竖排,横排只需修改这里 boxAttrs.AddChildVisual(attributes); // 属性大框加到总大框里 // 属性大框永远排在总大框的第一位 if (boxTotal.childrenVisual == null) boxTotal.childrenVisual = new ArrayList(); boxTotal.childrenVisual.Insert(0,boxAttrs);//.AddChildVisual (boxAttrs); //属性框初始化 attributes.InitialVisual(); //这句话很重要 } } SKIPATTRS: if (this.m_bWantChildInitial == 1) { // 找到旧的BoxContent,删掉 Box oldBoxContent = this.GetBoxContent(boxTotal); if (oldBoxContent != null) boxTotal.childrenVisual.Remove(oldBoxContent); if (this.m_childrenExpand != ExpandStyle.None) { if (this.m_childrenExpand == ExpandStyle.Expand && this.children.Count == 0) { return; } Box boxContent = new Box (); boxContent.Name = "BoxContent"; boxContent.container = boxTotal; boxContent.LayoutStyle = LayoutStyle.Horizontal; ExpandHandle expandContentHandle = new ExpandHandle(); expandContentHandle.Name = "ExpandContent"; expandContentHandle.container = boxContent; boxContent.AddChildVisual(expandContentHandle); Content content = new Content(); content.container = boxContent; content.LayoutStyle = LayoutStyle.Vertical ;//Vertical ; boxContent.AddChildVisual(content); boxTotal.AddChildVisual(boxContent); //调入contna的初始化visual函数 content.InitialVisual(); } } }
// 完成重载基类的InitialVisual() public override void InitialVisual() { bool bHasVisual = false; XmlLabel label = this.GetLable(); if (label == null) { // 加Label label = new XmlLabel(); label.container = this; label.Text = this.Name; this.AddChildVisual(label); } else { label.Text = this.Name; bHasVisual = true; } Box boxTotal = null; if (bHasVisual == false) { // 定义一个总框 boxTotal = new Box (); boxTotal.Name = "BoxTotal"; boxTotal.container = this; this.AddChildVisual (boxTotal); // 外面总框的layoutStyle样式为竖排 boxTotal.LayoutStyle = LayoutStyle.Vertical; } else { boxTotal = this.GetBoxTotal(); if (boxTotal == null) { Debug.Assert(false,"有Lable对象,不可能没有BoxTotal对象"); throw new Exception("有Lable对象,不可能没有BoxTotal对象"); } } /// if (boxTotal != null) InitialVisualSpecial(boxTotal); /// /* if (bHasLable == false) { //如果boxTotal只有一个box,则设为横排 if (boxTotal.childrenVisual != null && boxTotal.childrenVisual .Count == 1) boxTotal.LayoutStyle = LayoutStyle.Horizontal ; Comment comment = new Comment (); comment.container = this; this.AddChildVisual(comment); } */ this.m_strTempURI = null; }
// 此函数等待派生类重写 public virtual void InitialVisualSpecial(Box boxtotal) { }
// 向上递归布局 public static void UpLayout(Visual visual, int nTimeStamp) { Box myContainer = (Box)(visual.container); if (myContainer != null) { int nMyRetWidth, nMyRetHeight; int nWidth = 0; int nHeight = 0; if (myContainer.LayoutStyle == LayoutStyle.Horizontal) { nWidth = 0; nHeight = 0; foreach (Visual child in myContainer.childrenVisual) { nWidth += child.Rect.Width; child.Layout(child.Rect.X, child.Rect.Y, child.Rect.Width, 0, nTimeStamp, out nMyRetWidth, out nMyRetHeight, LayoutMember.Layout); if (child.Rect.Height > nHeight) { nHeight = child.Rect.Height; } } foreach (Visual child in myContainer.childrenVisual) { child.Rect.Height = nHeight; } } else if (myContainer.LayoutStyle == LayoutStyle.Vertical) { nWidth = visual.Rect.Width; nHeight = visual.Rect.Height; //先把兄弟计算一下 foreach (Visual child in myContainer.childrenVisual) { if (child.Equals(visual) == true) { continue; } child.Layout(child.Rect.X, child.Rect.Y, visual.Rect.Width, 0, nTimeStamp, out nMyRetWidth, out nMyRetHeight, LayoutMember.Layout); if (child.Rect.Width > nWidth) { nWidth = child.Rect.Width; } nHeight += child.Rect.Height; } } myContainer.Rect.Width = nWidth + myContainer.TotalRestWidth; myContainer.Rect.Height = nHeight + myContainer.TotalRestHeight; //设兄弟坐标 int nXDelta = myContainer.LeftResWidth; int nYDelta = myContainer.TopResHeight; if (myContainer.LayoutStyle == LayoutStyle.Horizontal) { foreach (Visual childVisual in myContainer.childrenVisual) { childVisual.Rect.X = nXDelta; childVisual.Rect.Y = nYDelta; nXDelta += childVisual.Rect.Width; } } else if (myContainer.LayoutStyle == LayoutStyle.Vertical) { foreach (Visual childVisual in myContainer.childrenVisual) { childVisual.Rect.X = nXDelta; childVisual.Rect.Y = nYDelta; nYDelta += childVisual.Rect.Height; } } myContainer.Layout(myContainer.Rect.X, myContainer.Rect.Y, myContainer.Rect.Width, myContainer.Rect.Height, nTimeStamp, out nMyRetWidth, out nMyRetHeight, LayoutMember.Up); } }
// 当layoutMember为CalcuWidth不给rectange赋值,实际布局才赋值 // parameters: // x x坐标 // y y坐标 // nInitialWidth 初始宽度 // nInitialHeight 初始高度 // nRetWidth 返回需要的宽度 // nRectHeight 返回需要的高度 // layoutMember 功能参数 public virtual void Layout(int x, int y, int nInitialWidth, int nInitialHeight, int nTimeStamp, out int nRetWidth, out int nRetHeight, LayoutMember layoutMember) { nRetWidth = nInitialWidth; nRetHeight = nInitialHeight; /////////////////////////////////////////// //1.首先判断是否为Enlarge参数/////////////////// /////////////////////////////////////////// bool bEnlargeWidth = false; if ((layoutMember & LayoutMember.EnlargeWidth) == LayoutMember.EnlargeWidth) { bEnlargeWidth = true; } bool bEnlargeHeight = false; if ((layoutMember & LayoutMember.EnLargeHeight) == LayoutMember.EnLargeHeight) { bEnlargeHeight = true; } if (bEnlargeWidth == true || bEnlargeHeight == true) { //父亲和兄弟都影响了 if ((layoutMember & LayoutMember.Up) == LayoutMember.Up) { if (bEnlargeHeight == true) { this.Rect.Height = nInitialHeight; Box myContainer = (Box)(this.container); if (myContainer == null) { return; } if (myContainer.LayoutStyle == LayoutStyle.Horizontal) { //影响兄弟 foreach (Visual child in myContainer.childrenVisual) { if (child.Equals(this) == true) { continue; } child.Layout( child.Rect.X, child.Rect.Y, child.Rect.Width, this.Rect.Height, nTimeStamp, out nRetWidth, out nRetHeight, LayoutMember.EnLargeHeight); } int nMyHeight = this.Rect.Height; foreach (Visual child in myContainer.childrenVisual) { if (child.Rect.Height > nMyHeight) { nMyHeight = child.Rect.Height; } } nMyHeight += myContainer.TotalRestHeight; myContainer.Layout( myContainer.Rect.X, myContainer.Rect.Y, myContainer.Rect.Width, nMyHeight, nTimeStamp, out nRetWidth, out nRetHeight, layoutMember); } if (myContainer.LayoutStyle == LayoutStyle.Vertical) { int nTempTotalHeight = 0; foreach (Visual childVisual in myContainer.childrenVisual) { nTempTotalHeight += childVisual.Rect.Height; } nTempTotalHeight += myContainer.TotalRestHeight; myContainer.Layout( myContainer.Rect.X, myContainer.Rect.Y, myContainer.Rect.Width, nTempTotalHeight, nTimeStamp, out nRetWidth, out nRetHeight, layoutMember); //设兄弟坐标 int nXDelta = myContainer.LeftResWidth; int nYDelta = myContainer.TopResHeight; foreach (Visual childVisual in myContainer.childrenVisual) { childVisual.Rect.X = nXDelta; childVisual.Rect.Y = nYDelta; nYDelta += childVisual.Rect.Height; } } return; } } if (bEnlargeHeight == true) { this.Rect.Height = nInitialHeight; } if (bEnlargeHeight == true) { this.Rect.Width = nInitialWidth; } return; } //2.输入信息/////////////////////////////////////// Item item = this.GetItem(); Debug.Assert(item != null, ""); item.m_document.nTime++; string strTempInfo = ""; int nTempLevel = this.GetVisualLevel(); string strLevelString = this.GetStringFormLevel(nTempLevel); if (this.IsWriteInfo == true) { strTempInfo = "\r\n" + strLevelString + "******************************\r\n" + strLevelString + "这是第" + nTempLevel + "层的" + this.GetType().Name + "调layout开始\r\n" + strLevelString + "参数为:\r\n" + strLevelString + "x=" + x + "\r\n" + strLevelString + "y=" + y + "\r\n" + strLevelString + "nInitialWidth=" + nInitialWidth + "\r\n" + strLevelString + "nInitialHeight=" + nInitialHeight + "\r\n" + strLevelString + "nTimeStamp=" + nTimeStamp + "\r\n" + strLevelString + "layoutMember=" + layoutMember.ToString() + "\r\n" + strLevelString + "LayoutStyle=无\r\n" + strLevelString + "使总次数变为" + item.m_document.nTime + "\r\n"; StreamUtil.WriteText("I:\\debug.txt", strTempInfo); } //3.Catch/////////////////////////////////// if (Catch == true) { //当输入参数相同时,直接返回catch内容 if (sizeCatch.nInitialWidth == nInitialWidth && sizeCatch.nInitialHeight == nInitialHeight && (sizeCatch.layoutMember == layoutMember)) { if (this.IsWriteInfo == true) { strTempInfo = "\r\n" + strLevelString + "------------------" + strLevelString + "与缓存时相同\r\n" + strLevelString + "传入的值: initialWidth:" + nInitialWidth + " initialHeight:" + nInitialHeight + " timeStamp: " + nTimeStamp + " layoutMember:" + layoutMember.ToString() + "\r\n" + strLevelString + "缓存的值: initialWidth:" + sizeCatch.nInitialWidth + " initialHeight:" + sizeCatch.nInitialHeight + " timeStamp: " + sizeCatch.nTimeStamp + " layoutMember:" + sizeCatch.layoutMember.ToString() + "\r\n"; } if ((layoutMember & LayoutMember.Layout) != LayoutMember.Layout) { if (this.IsWriteInfo == true) { strTempInfo += strLevelString + "不是实做,直接返回缓冲区值\r\n"; } nRetWidth = sizeCatch.nRetWidth; nRetHeight = sizeCatch.nRetHeight; if (this.IsWriteInfo == true) { strTempInfo += strLevelString + "----------结束------\r\n"; StreamUtil.WriteText("I:\\debug.txt", strTempInfo); } goto END1; } else { if (this.IsWriteInfo == true) { strTempInfo += strLevelString + "包含实做,向下继续\r\n"; } } if (this.IsWriteInfo == true) { strTempInfo += strLevelString + "----------结束------\r\n"; StreamUtil.WriteText("I:\\debug.txt", strTempInfo); } } else { if (this.IsWriteInfo == true) { strTempInfo = "\r\n" + strLevelString + "------------------" + strLevelString + "与缓存时不同\r\n" + strLevelString + "传入的值: initialWidth:" + nInitialWidth + " initialHeight:" + nInitialHeight + " timeStamp: " + nTimeStamp + " layoutMember:" + layoutMember.ToString() + "\r\n" + strLevelString + "缓存的值: initialWidth:" + sizeCatch.nInitialWidth + " initialHeight:" + sizeCatch.nInitialHeight + " timeStamp: " + sizeCatch.nTimeStamp + " layoutMember:" + sizeCatch.layoutMember.ToString() + "\r\n"; strTempInfo += strLevelString + "----------结束------\r\n"; StreamUtil.WriteText("I:\\debug.txt", strTempInfo); } } } //4.下面进行各项测量或实算////////////////////////// nRetWidth = nInitialWidth; nRetHeight = nInitialHeight; //得到宽度 int nTempWidth = GetWidth(); /* * if (nRetWidth < 0) //(nTempWidth > nRetWidth) * nRetWidth = 0; * //nRetWidth = nTempWidth; */ if (nRetWidth < nTempWidth) { nRetWidth = nTempWidth; } //1)只测宽度 if (layoutMember == LayoutMember.CalcuWidth) //测宽度 { goto END1; } //得到高度 int nTempHeight = GetHeight(nRetWidth - this.TotalRestWidth); if (nTempHeight > nRetHeight) { nRetHeight = nTempHeight; } if (nRetHeight < 0) { nRetHeight = 0; } //2)测高度(两种情况,只测高度 或 即测高度又测宽度) if ((layoutMember & LayoutMember.CalcuHeight) == LayoutMember.CalcuHeight) { goto END1; } //3)实算 if ((layoutMember & LayoutMember.Layout) == LayoutMember.Layout) //真正布局 { this.Rect = new Rectangle(x, y, nRetWidth, nRetHeight); //把宽度记到数组里 item.SetValue(this.GetType().Name, nRetWidth); //goto END1; } if ((layoutMember & LayoutMember.Up) == LayoutMember.Up) { Visual.UpLayout(this, nTimeStamp); } END1: //***做得catch*** sizeCatch.SetValues(nInitialWidth, nInitialHeight, nRetWidth, nRetHeight, nTimeStamp, layoutMember); if (this.IsWriteInfo == true) { strTempInfo = ""; strTempInfo = "\r\n" + strLevelString + "这是第" + nTempLevel + "层的" + this.GetType().Name + "调layout结束\r\n" + strLevelString + "返回值为: \r\n" + strLevelString + "x=" + x + "\r\n" + strLevelString + "y=" + y + "\r\n" + strLevelString + "nRetWidth=" + nRetWidth + "\r\n" + strLevelString + "nRetHeight=" + nRetHeight + "\r\n" + strLevelString + "Rect.X=" + this.Rect.X + "\r\n" + strLevelString + "Rect.Y=" + this.Rect.Y + "\r\n" + strLevelString + "Rect.Width=" + this.Rect.Width + "\r\n" + strLevelString + "Rect.Height=" + this.Rect.Height + "\r\n" + strLevelString + "****************************\r\n\r\n"; StreamUtil.WriteText("I:\\debug.txt", strTempInfo); } }