Exemplo n.º 1
0
		private LayoutCellInfo GetLayoutCellInfo()
		{
			if(m_LayoutCellInfo==null)
				m_LayoutCellInfo=new LayoutCellInfo();
			return m_LayoutCellInfo;
		}
Exemplo n.º 2
0
		public void LayoutSingleCell(LayoutCellInfo info)
		{
			SizeF textSize=SizeF.Empty;
			Font font=info.Font;
			int height=0;
			if(info.LayoutStyle.Font!=null)
				font=info.LayoutStyle.Font;

			info.ContextCell.OnLayoutCell();

			if(info.ContextCell.HostedControl!=null)
			{
				if(info.CellWidth==0)
					textSize=new SizeF(info.ContextCell.HostedControl.Width,info.ContextCell.HostedControl.Height);
				else
				{
					int availTextWidth=info.CellWidth-
						ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle);
					textSize=new SizeF(availTextWidth,info.ContextCell.HostedControl.Height);
				}
			}
			else
			{
				// Calculate Text Width and Height
				if(info.CellWidth==0)
				{
					string text=info.ContextCell.Text;
					if(text!="")
						textSize=info.Graphics.MeasureString(text,font);
				}
				else
				{
					int availTextWidth=info.CellWidth-
						ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle);

					availTextWidth-=info.ContextCell.Images.LargestImageSize.Width;
					if(info.ContextCell.CheckBoxVisible)
						availTextWidth-=CheckBoxSize.Width;
					int cellHeight=font.Height;

					if(info.LayoutStyle.WordWrap)
					{
						cellHeight=info.LayoutStyle.MaximumHeight-info.LayoutStyle.MarginTop-
							info.LayoutStyle.MarginBottom-info.LayoutStyle.PaddingTop-info.LayoutStyle.PaddingBottom;
						if(availTextWidth>0)
						{
							if(cellHeight>0)
								textSize=info.Graphics.MeasureString(info.ContextCell.Text,font,new SizeF(availTextWidth,cellHeight),info.LayoutStyle.StringFormat);
							else
								textSize=info.Graphics.MeasureString(info.ContextCell.Text,font,availTextWidth,info.LayoutStyle.StringFormat);
						}
						//info.ContextCell.WordWrap=true;
					}
					else
						textSize=new SizeF(availTextWidth,cellHeight);
				}
			}

			if(info.LayoutStyle.WordWrap)
				info.ContextCell.WordWrap=true;
			else
                info.ContextCell.WordWrap=false;

			height=(int)Math.Ceiling(textSize.Height);
			if(info.VerticalPartAlignment)
			{
				if(info.ContextCell.Images.LargestImageSize.Height>0)
					height+=info.ContextCell.Images.LargestImageSize.Height;
				if(info.ContextCell.CheckBoxVisible)
					height+=CheckBoxSize.Height;
			}
			else
			{
				if(info.ContextCell.Images.LargestImageSize.Height>height)
					height=info.ContextCell.Images.LargestImageSize.Height;
				if(info.ContextCell.CheckBoxVisible && CheckBoxSize.Height>height)
					height=CheckBoxSize.Height;
			}

			Rectangle r=new Rectangle(info.Left+ElementStyleLayout.LeftWhiteSpace(info.LayoutStyle),
				info.Top+ElementStyleLayout.TopWhiteSpace(info.LayoutStyle)
				,info.CellWidth,height);

			if(r.Width==0)
			{
				if(info.VerticalPartAlignment)
				{
					r.Width=(int)Math.Ceiling(textSize.Width);
					if(info.ContextCell.Images.LargestImageSize.Width>r.Width)
						r.Width=(info.ContextCell.Images.LargestImageSize.Width+this.ImageTextSpacing);
					if(info.ContextCell.CheckBoxVisible && CheckBoxSize.Width>r.Width)
						r.Width+=(CheckBoxSize.Width+this.ImageTextSpacing);
				}
				else
				{
					r.Width=(int)Math.Ceiling(textSize.Width);
					if(info.ContextCell.Images.LargestImageSize.Width>0)
						r.Width+=(info.ContextCell.Images.LargestImageSize.Width+this.ImageTextSpacing);
					if(info.ContextCell.CheckBoxVisible)
						r.Width+=(CheckBoxSize.Width+this.ImageTextSpacing);
				}
			}

			// Now that we have cell bounds store them
			Rectangle rCellBounds=new Rectangle(info.Left,info.Top,info.CellWidth,r.Height+info.LayoutStyle.MarginTop+info.LayoutStyle.MarginBottom+info.LayoutStyle.PaddingTop+info.LayoutStyle.PaddingBottom);
			if(rCellBounds.Width==0)
				rCellBounds.Width=r.Width+ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle);
			info.ContextCell.SetBounds(rCellBounds);

            // Set Position of the image
			if(!info.ContextCell.Images.LargestImageSize.IsEmpty)
			{
				eVerticalAlign va=GetVerticalAlign(info.ContextCell.ImageAlignment);
				eHorizontalAlign ha=GetHorizontalAlign(info.ContextCell.ImageAlignment,info.LeftToRight);
				if(info.VerticalPartAlignment)
					info.ContextCell.SetImageBounds(AlignContentVertical(info.ContextCell.Images.LargestImageSize, ref r, ha, va, this.ImageTextSpacing));
				else
					info.ContextCell.SetImageBounds(AlignContent(info.ContextCell.Images.LargestImageSize, ref r, ha, va, this.ImageTextSpacing));
			}
			else
				info.ContextCell.SetImageBounds(Rectangle.Empty);

			// Set position of the check box
			if(info.ContextCell.CheckBoxVisible)
			{
				eVerticalAlign va=GetVerticalAlign(info.ContextCell.CheckBoxAlignment);
				eHorizontalAlign ha=GetHorizontalAlign(info.ContextCell.CheckBoxAlignment,info.LeftToRight);
				if(info.VerticalPartAlignment)
					info.ContextCell.SetCheckBoxBounds(AlignContentVertical(this.CheckBoxSize, ref r, ha, va, this.ImageTextSpacing));
				else
					info.ContextCell.SetCheckBoxBounds(AlignContent(this.CheckBoxSize, ref r, ha, va, this.ImageTextSpacing));
			}
			else
				info.ContextCell.SetCheckBoxBounds(Rectangle.Empty);
			
            // Set position of the text
			//info.ContextCell.SetTextBounds(Rectangle.Empty);
			if(!textSize.IsEmpty)
				info.ContextCell.TextContentBounds=r;
			else
				info.ContextCell.TextContentBounds=Rectangle.Empty;
            
		}