Esempio n. 1
0
        // 根据传入的相对坐标,得到击中的Visual对象
        // parameters:
        //      p           传入的相对坐标
        //      retVisual   out参数,返回击中的visual
        // return:
        //      -1  坐标不在本区域
        //      0   文字区
        //      1   空白
        //      2   缝隙上
		public override int HitTest(Point p,
			out Visual retVisual)
		{
			if (this.bExpand == false)
			{
				return this.MyText.HitTest(p,out retVisual);
			}
			else
			{
				return base.HitTest(p,out retVisual);
			}
		}
Esempio n. 2
0
        // 根据传入的相对坐标,得到击中的Visual对象
        // parameters:
        //      p           传入的相对坐标
        //      retVisual   out参数,返回击中的visual
        // return:
        //      -1  坐标不在本区域
        //      0   文字区
        //      1   空白
        //      2   缝隙上
		public override int HitTest(Point p,
			out Visual retVisual)
		{
			retVisual = null;
			int nResizeAreaWidth = 4;   //缝隙的宽度
			//在缝上
			if ( p.X >= this.Rect.X + this.Rect.Width - (nResizeAreaWidth/2)
				&& p.X < this.Rect.X + this.Rect.Width + (nResizeAreaWidth/2)) 
			{
				retVisual = this;
				return  2;
			}

			//不在区域
			if (p.X < this.Rect.X 
				|| p.Y < this.Rect.Y )
			{
				return -1;
			}
			if (p.X > this.Rect.X + this.Rect.Width 
				|| p.Y > this.Rect.Y + this.Rect.Height )
			{
				return -1;
			}

			//在线条和空白
			//1. 左线条空白处
			if (p.X > this.Rect.X 
				&& p.X < this.Rect.X + this.LeftResWidth
				&& p.Y > this.Rect.Y
				&& p.Y < this.Rect.Y + this.Rect.Height)
			{
				retVisual = this;
				return -1;
			}

			// 2.右线条空白处
			if (p.X > this.Rect.X + this.Rect.Width - this.RightResWidth
				&& p.X < this.Rect.X + this.Rect.Width
				&& p.Y > this.Rect.Y
				&& p.Y < this.Rect.Y + this.Rect.Height)
			{
				retVisual = this;
				return -1;
			}
			// 3.上线条空白处
			if (p.Y > this.Rect.Y
				&& p.Y < this.Rect.Y + this.TopResHeight
				&& p.X > this.Rect.X
				&& p.X < this.Rect.X + this.Rect.Width)
			{
				retVisual = this;
				return -1;
			}
			// 4.下线条空白处
			if (p.Y > this.Rect.Y + this.Rect.Height - this.BottomResHeight
				&& p.Y < this.Rect.Y + this.Rect.Height
				&& p.X > this.Rect.X
				&& p.X < this.Rect.X + this.Rect.Width)
			{
				retVisual = this;
				return -1;
			}

			
			//在文字区
			if (p.X >= this.Rect.X + this.LeftResWidth 
				&& p.Y >= this.Rect.Y + this.TopResHeight 
				&& p.X < this.Rect.X + this.Rect.Width - this.RightResWidth
				&& p.Y < this.Rect.Y + this.Rect.Height - this.BottomResHeight)
			{
				retVisual = this;
				return 0;
			}
			return -1;
		}
Esempio n. 3
0
		public override int HitTest(Point p,
			out Visual retVisual)
		{
			retVisual = null;
			
			//有儿子时,先看儿子
			if (this.childrenVisual != null)
			{
				Point p1 = new Point (p.X - this.Rect.X,
					p.Y - this.Rect.Y);

				//先认弱者,这里是没有必要的,因为线条归各自的区域管,
				Visual visual = null;
				int nCount = this.childrenVisual.Count ;
				for(int i = nCount -1;i>=0;i--)
				{
					visual = (Visual)childrenVisual[i];

					if (p1.X >= visual.Rect.X 
						&& p1.X < (visual.Rect.X + visual.Rect.Width)
						&& p1.Y >= visual.Rect.Y 
						&& p1.Y < (visual.Rect.Y + visual.Rect.Height ))
					{
						// int nRet = -1;
						return visual.HitTest(p1,out retVisual);
						
					}
				}
			}

			//当没儿子,或者儿子一个都不符合,那么就看自己了


			retVisual = null;
			int nResizeAreaWidth = 4;   //缝隙的宽度
			//在缝上
			if ( p.X >= this.Rect.X + this.Rect.Width - (nResizeAreaWidth/2)
				&& p.X < this.Rect.X + this.Rect.Width + (nResizeAreaWidth/2)) 
			{
				retVisual = this;
				return  2;
			}

			//不在区域
			if (p.X < this.Rect.X 
				|| p.Y < this.Rect.Y )
			{
				return -1;
			}
			if (p.X > this.Rect.X + this.Rect.Width 
				|| p.Y > this.Rect.Y + this.Rect.Height )
			{
				return -1;
			}

			//在线条和空白
			//1. 左线条空白处
			if (p.X > this.Rect.X 
				&& p.X < this.Rect.X + this.LeftResWidth
				&& p.Y >= this.Rect.Y
				&& p.Y < this.Rect.Y + this.Rect.Height)
			{
				retVisual = this;
				return -1;
			}

			// 2.右线条空白处
			if (p.X > this.Rect.X + this.Rect.Width - this.RightResWidth
				&& p.X < this.Rect.X + this.Rect.Width
				&& p.Y >= this.Rect.Y
				&& p.Y < this.Rect.Y + this.Rect.Height)
			{
				retVisual = this;
				return -1;
			}
			// 3.上线条空白处
			if (p.Y >= this.Rect.Y
				&& p.Y < this.Rect.Y + this.TopResHeight
				&& p.X >= this.Rect.X
				&& p.X < this.Rect.X + this.Rect.Width)
			{
				retVisual = this;
				return -1;
			}
			// 4.下线条空白处
			if (p.Y >= this.Rect.Y + this.Rect.Height - this.BottomResHeight
				&& p.Y < this.Rect.Y + this.Rect.Height
				&& p.X >= this.Rect.X
				&& p.X < this.Rect.X + this.Rect.Width)
			{
				retVisual = this;
				return -1;
			}

			
			//在文字区
			if (p.X >= this.Rect.X + this.LeftResWidth 
				&& p.Y >= this.Rect.Y + this.TopResHeight 
				&& p.X < this.Rect.X + this.Rect.Width - this.RightResWidth
				&& p.Y < this.Rect.Y + this.Rect.Height - this.BottomResHeight)
			{
				retVisual = this;
				return 0;
			}
			return -1;
		}
Esempio n. 4
0
        // 判断visual是否从TextVisual类派生
		public static bool IsDerivedFromTextVisual(Visual visual)
		{
			ArrayList aDeriveTypes = null;
			Type t = visual.GetType ();
			while(true)
			{
				if (t.Name == "Object")
					break;
				if (aDeriveTypes == null)
					aDeriveTypes = new ArrayList ();
				aDeriveTypes.Add (t);
				t = t.BaseType ;
			}

			if (aDeriveTypes != null)
			{
				for(int i= 0; i < aDeriveTypes.Count ;i++)
				{
					string strName1 = ((Type)aDeriveTypes[i]).FullName;
					string strName2 = typeof(TextVisual).FullName;
					if (strName1 == strName2)
						return true;
				}
			}
			return false;
		}
Esempio n. 5
0
		public   ArrayList childrenVisual = null;   //包含的visual,并不是数据的层次


		// 加一个子visual
		public void AddChildVisual(Visual visual)
		{
			if (childrenVisual == null)
				childrenVisual = new ArrayList ();
			childrenVisual.Add (visual);
		}
Esempio n. 6
0
        // 向上递归布局
		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 );
			}
		}
Esempio n. 7
0
        // 改变兄弟布局
        // parameters:
        //      startVisual 起始visual
        //      nWidth      宽度 -1无效
        //      nHeight     高度 -1无效
        // return:
        //      void
		public static void ChangeSibling(Visual startVisual,
			int nWidth,
			int nHeight)
		{
			Box myContainer = (Box)(startVisual.container );
			if (myContainer == null)
				return;

			int nRetWidth,nRetHeight;

			if (nHeight != -1)
			{
				foreach(Visual child in myContainer.childrenVisual )
				{
					if (child.Equals (startVisual) == true)
						continue;
					child.Layout (child.Rect.X,
						child.Rect.Y,
						child.Rect.Width,
						nHeight,
						-1,
						out nRetWidth,
						out nRetHeight,
						LayoutMember.EnLargeHeight );
				}
			}

			if (nWidth != -1)
			{
				foreach(Visual child in myContainer.childrenVisual )
				{
					if (child.Equals (startVisual) == true)
						continue;
					child.Layout (child.Rect.X,
						child.Rect.Y,
						nWidth,
						child.Rect.Height,
						-1,
						out nRetWidth,
						out nRetHeight,
						LayoutMember.EnlargeWidth );
				}
			}

		}
Esempio n. 8
0
		// 鼠标按下的相关事情
		protected override void OnMouseDown(MouseEventArgs e)
		{
			if (this.VirtualRoot == null)
			{
				base.OnMouseDown(e);
				return;
			}

			this.Capture = true;

			Point p = new Point(e.X, e.Y);
			//换算成相对doucment的坐标
			p = new Point (p.X - this.nDocumentOrgX ,
				p.Y - this.nDocumentOrgY );

			Visual visual = null;
			int nRet = this.VirtualRoot.HitTest(p,out visual);

			if (visual == null)
				goto FINISH;
			if (nRet == -1)
				goto FINISH;

			Item item = visual.GetItem();



			//**************************************
			//单击到展开按钮
			//***************************************
			ExpandStyle expandChildren = ExpandStyle.None;
			ExpandStyle expandAttrs = ExpandStyle.None;

			ExpandStyle oldChildrenExpand = ExpandStyle.None;
			ExpandStyle oldAttrsExpand = ExpandStyle.None;

			if (visual.IsExpandHandle() == true)
			{
				this.EditControlTextToVisual();

				ElementItem element = (ElementItem)item;	// 既然是可展开的,则必然是ElementItem

				expandChildren = element.m_childrenExpand;
				expandAttrs = element.m_attrsExpand;

				//3.根据展开按钮的名称判断出哪里换了状态
				ExpandHandle myExpandHandle = ((ExpandHandle)visual);
				if (myExpandHandle.Name == "ExpandContent")
				{
					if (expandChildren == ExpandStyle.None)
					{
						Debug.Assert(false, "");
					}
					else 
					{
						expandChildren = (expandChildren == ExpandStyle.Expand) ? ExpandStyle.Collapse : ExpandStyle.Expand;
					}
				}
				else if (myExpandHandle.Name == "ExpandAttributes")
				{
					if (expandAttrs == ExpandStyle.None)
					{
						Debug.Assert(false, "");
					}
					else 
					{
						expandAttrs = (expandAttrs == ExpandStyle.Expand) ? ExpandStyle.Collapse : ExpandStyle.Expand;
					}
				}

				
				oldChildrenExpand = element.m_childrenExpand;
				oldAttrsExpand = element.m_attrsExpand;

				element.ExpandAttrsOrChildren(expandAttrs,
					expandChildren,
					true);


				goto END1;
			}

			//*****************************************
			//在缝上
			//*****************************************
			if (nRet == 2) 
			{
				dragVisual = visual;

				//-----------------------------------------
				//做测试用,意思是把拖动的visual失效,从而变成红色
				dragVisual.bDrag = true;
				Rectangle rectTemp = new Rectangle (dragVisual.RectAbs.X + this.nDocumentOrgX ,
					dragVisual.RectAbs .Y + this.nDocumentOrgY ,
					dragVisual.RectAbs .Width ,
					dragVisual.RectAbs .Height);
				this.Invalidate ( rectTemp);
				//------------------------------------------

				// 第一次
				nLastTrackerX = e.X;
				DrawTracker();
				goto END1;
			}

			END1:

				//m_clickVisual = visual;
				if (visual != null )
				{
					//失效前一个
					if (this.m_selectedItem != null)
					{
						Rectangle rectTemp = new Rectangle (
							this.m_selectedItem.RectAbs.X + this.nDocumentOrgX ,
							this.m_selectedItem.RectAbs .Y + this.nDocumentOrgY ,
							this.m_selectedItem.RectAbs .Width ,
							this.m_selectedItem.RectAbs .Height);
						this.Invalidate (rectTemp);
					}

					this.EditControlTextToVisual();

					//this.m_selectedItem = item;
					if (visual is XmlText)
					{
						this.SetCurText(item,(XmlText)visual);
					}
					else
					{
						this.SetCurText(item,null);
					}
					this.SetActiveItem(item);

					if (this.m_selectedItem != null)
					{
						Rectangle rectTemp = new Rectangle (
							this.m_selectedItem.RectAbs.X + this.nDocumentOrgX ,
							this.m_selectedItem.RectAbs .Y + this.nDocumentOrgY ,
							this.m_selectedItem.RectAbs .Width ,
							this.m_selectedItem.RectAbs .Height);
						this.Invalidate (rectTemp);
					}
				}

			//在文本上
			if ((visual is XmlText) &&  (nRet == 0))
			{
				//这里模拟单击一下,但位置跑了一大截
				curEdit.Focus();

				int x = e.X - curEdit.Location.X;
				int y = e.Y - curEdit.Location.Y;

				API.SendMessage(curEdit.Handle, 
					API.WM_LBUTTONDOWN, 
					new UIntPtr(API.MK_LBUTTON),	//	UIntPtr wParam,
					API.MakeLParam(x,y));
			
			}

			FINISH:
				base.OnMouseDown (e);
		}
Esempio n. 9
0
		// 根据传入的相对坐标,得到击中的Visual对象
        // parameters:
		//      p           传入的相对坐标
		//      retVisual   out参数,返回击中的visual
        // return:
        //      -1  坐标不在本区域
        //      0   文字区
        //      1   空白
        //      2   缝隙上
		public virtual int HitTest(Point p,
			out Visual retVisual)
		{
			retVisual = null;
			return -1;
		}
Esempio n. 10
0
		// 拖拽放开时
		private void DragUp()
		{
			this.Capture = false;

			if (dragVisual != null) 
			{
				// 消最后残余的一根
				DrawTracker();
				Item item = dragVisual.GetItem ();

				//得坐相对文档的x
				//再转化成相对窗口的x
				int x0 = dragVisual.getAbsX() + dragVisual.Rect.Width;
				x0 += this.nDocumentOrgX ;
				
				// 计算差额
				int delta = nLastTrackerX - x0;
				if (item != null)
				{
					int nTemp = dragVisual.Rect.Width + delta;
					if (nTemp <= 0)
						nTemp = 2;
					//把新宽度设到数组里,设宽度值的过程中,会把级别号升高
					item.SetValue(dragVisual.GetType().Name,
						nTemp);

					PartWidth partWidth = item.GetPartWidth (dragVisual.GetType ().Name );
					if (partWidth != null )
					{
						if (partWidth.nGradeNo >0)
						{
							//当本宽度级别号大于0时,将所有的级别上升,以致当拖动固定宽度时,不会影响其它宽度
							ItemWidth itemWidth = this.widthList .GetItemWidth (item.GetLevel());
							foreach(PartWidth part in itemWidth )
							{
								part.UpGradeNo ();
							}
						}
						else
						{
							partWidth.UpGradeNo ();
						}
					}
					
					//改变visual的宽度
					dragVisual.Rect.Width = nTemp;// dragVisual.rect .Width + delta;

					//从而layout及下级
					int nWidth,nHeight;
					dragVisual.Layout(dragVisual.Rect.X,
						dragVisual.Rect.Y,
						dragVisual.Rect.Width,
						dragVisual.Rect.Height,
						nTimeStampSeed,
						out nWidth,
						out nHeight,
						LayoutMember.Layout | LayoutMember.Up );
						
					Visual tempContainer = dragVisual.container ;
					if (tempContainer != null)
					{
						//MessageBox.Show (tempContainer.rect .ToString ());
					}

					nTimeStampSeed++;
				{
					//先将当前对象的级别号降到缺省值
					partWidth = item.GetPartWidth (dragVisual.GetType ().Name );
					if (partWidth != null)
						partWidth.BackDefaultGradeNo ();

					//将所有的宽度的级别号降到缺省值
					ItemWidth itemWidth = this.widthList .GetItemWidth (item.GetLevel());
					foreach(PartWidth part in itemWidth )
					{
						part.BackDefaultGradeNo  ();
					}
				}

					//curText从属的Item在被变化的范围内才重设,但改变列宽后,所有的Item都影响到了,所以这儿不用做判断了
					SetEditPos();

					//文档尺寸变化,做一些善后事情
					this.AfterDocumentChanged (ScrollBarMember.Both );

					this.Invalidate ();
				}
				dragVisual.bDrag = false;
				this.dragVisual = null;

				nLastTrackerX = -1;
			}
		}
Esempio n. 11
0
		// 让visual块的rectCaret尺寸可见
		private void EnsureVisible(Visual visual,
			Rectangle rectCaret)
		{
			if (visual == null)
				return;

			int nDelta = visual.RectAbs.Y + visual.Rect.Height
				+ this.nDocumentOrgX 
				+ rectCaret.Y;

			if (nDelta + rectCaret.Height >= this.ClientSize.Height) 
			{
				if (rectCaret.Height >= this.ClientSize.Height) 
					DocumentOrgY = DocumentOrgY - (nDelta + rectCaret.Height) + ClientSize.Height + /*调整系数*/ (rectCaret.Height/2) - (this.ClientSize.Height/2);
				else
					DocumentOrgY = DocumentOrgY - (nDelta + rectCaret.Height) + ClientSize.Height;
			}
			else if (nDelta < 0)
			{
				if (rectCaret.Height >= this.ClientSize.Height) 
					DocumentOrgY = DocumentOrgY - (nDelta) - /*调整系数*/ ( (rectCaret.Height/2) - (this.ClientSize.Height/2));
				else 
					DocumentOrgY = DocumentOrgY - (nDelta);
			}
			else 
			{
				// y不需要卷滚
			}

			////
			// 水平方向
			nDelta = 0;

			nDelta = visual.RectAbs .X + visual.Rect.Width 
				+ this.nDocumentOrgX 
				+ rectCaret.X ;
			

			if (nDelta + rectCaret.Width >= this.ClientSize.Width) 
			{
				if (rectCaret.Width >= this.ClientSize.Width) 
					DocumentOrgX = DocumentOrgX - (nDelta + rectCaret.Width) + ClientSize.Width + /*调整系数*/ (rectCaret.Width/2) - (this.ClientSize.Width/2);
				else
					DocumentOrgX = DocumentOrgX - (nDelta + rectCaret.Width) + ClientSize.Width;
			}
			else if (nDelta < 0)
			{
				if (rectCaret.Width >= this.ClientSize.Width) 
					DocumentOrgX = DocumentOrgX - (nDelta) - /*调整系数*/ ( (rectCaret.Width/2) - (this.ClientSize.Width/2));
				else 
					DocumentOrgX = DocumentOrgX - (nDelta);
			}
			else 
			{
				// x不需要卷滚
			}

		}
Esempio n. 12
0
        // 向上递归布局
        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);
            }
        }
Esempio n. 13
0
 // 根据传入的相对坐标,得到击中的Visual对象
 // parameters:
 //      p           传入的相对坐标
 //      retVisual   out参数,返回击中的visual
 // return:
 //      -1  坐标不在本区域
 //      0   文字区
 //      1   空白
 //      2   缝隙上
 public virtual int HitTest(Point p,
                            out Visual retVisual)
 {
     retVisual = null;
     return(-1);
 }
Esempio n. 14
0
        // 当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);
            }
        }
Esempio n. 15
0
        // return:
        //      -1  坐标不在本区域
        //      0   文字区
        //      1   空白
        //      2   缝隙
        public override int HitTest(Point p,
                                    out Visual retVisual)
        {
            retVisual = null;
            int nResizeAreaWidth = 4;               //缝隙的宽度

            //在缝上
            if (p.X >= this.Rect.X + this.Rect.Width - (nResizeAreaWidth / 2) &&
                p.X < this.Rect.X + this.Rect.Width + (nResizeAreaWidth / 2))
            {
                retVisual = this;
                return(2);
            }

            //不在区域
            if (p.X < this.Rect.X ||
                p.Y < this.Rect.Y)
            {
                return(-1);
            }
            if (p.X > this.Rect.X + this.Rect.Width ||
                p.Y > this.Rect.Y + this.Rect.Height)
            {
                return(-1);
            }

            //在线条和空白
            //1. 左线条空白处
            if (p.X > this.Rect.X &&
                p.X < this.Rect.X + this.LeftResWidth &&
                p.Y > this.Rect.Y &&
                p.Y < this.Rect.Y + this.Rect.Height)
            {
                retVisual = this;
                return(-1);
            }

            // 2.右线条空白处
            if (p.X > this.Rect.X + this.Rect.Width - this.RightResWidth &&
                p.X < this.Rect.X + this.Rect.Width &&
                p.Y > this.Rect.Y &&
                p.Y < this.Rect.Y + this.Rect.Height)
            {
                retVisual = this;
                return(-1);
            }
            // 3.上线条空白处
            if (p.Y > this.Rect.Y &&
                p.Y < this.Rect.Y + this.TopResHeight &&
                p.X > this.Rect.X &&
                p.X < this.Rect.X + this.Rect.Width)
            {
                retVisual = this;
                return(-1);
            }
            // 4.下线条空白处
            if (p.Y > this.Rect.Y + this.Rect.Height - this.BottomResHeight &&
                p.Y < this.Rect.Y + this.Rect.Height &&
                p.X > this.Rect.X &&
                p.X < this.Rect.X + this.Rect.Width)
            {
                retVisual = this;
                return(-1);
            }


            //在文字区
            if (p.X >= this.Rect.X + this.LeftResWidth &&
                p.Y >= this.Rect.Y + this.TopResHeight &&
                p.X < this.Rect.X + this.Rect.Width - this.RightResWidth &&
                p.Y < this.Rect.Y + this.Rect.Height - this.BottomResHeight)
            {
                retVisual = this;
                return(0);
            }
            return(-1);
        }
Esempio n. 16
0
        // edit高度发生变化
        private void AfterEditControlHeightChanged(Visual visual)
        {
            if (visual == null)
                return;
            int nOldHeight = 0;
            nOldHeight = visual.Rect.Height;

            //把文字送入item
            // ??????引向未完整的数据变成xml,抛出错误
            //this.EditControlTextToVisual();

            //重新计算
            int nRetWidth, nRetHeight;
            visual.Layout(visual.Rect.X,
                visual.Rect.Y,
                visual.Rect.Width,
                this.Size.Height,// + visual.TopBlank + visual.BottomBlank + 2*visual.BorderHorzHeight ,//visual.rect .Height ,
                this.XmlEditor.nTimeStampSeed++,
                out nRetWidth,
                out nRetHeight,
                LayoutMember.Layout);


            // ???????设当前edit的大小及位置



            int nNewHeight = visual.Rect.Height;

            int nDelta = nNewHeight - nOldHeight;

            if (nDelta != 0)
            {
                //上级
                Visual containerVisual = visual.container;
                nNewHeight += containerVisual.TotalRestHeight;

                if (containerVisual != null)
                {
                    containerVisual.Layout(containerVisual.Rect.X,
                        containerVisual.Rect.Y,
                        containerVisual.Rect.Width,
                        nNewHeight,
                        this.XmlEditor.nTimeStampSeed,
                        out nRetWidth,
                        out nRetHeight,
                        LayoutMember.EnLargeHeight | LayoutMember.Up);
                }
                //Visual.ChangeSibling (visual,-1,nNewHeight);
            }

            if (nDelta != 0
                && this.XmlEditor.m_curText != null)
            {
                //这里优先,使用ScrollWindowEx
            }

            if (nDelta != 0)
            {
                this.XmlEditor.AfterDocumentChanged(ScrollBarMember.Vert);
            }

            this.XmlEditor.Invalidate();

            //也需要做优化的事情
        }