示例#1
0
        public TPTextRow(TPTextRow row)
        {
            this.columns = row.Columns;
            this.widths  = row.Widths;

            this.width  = row.Width;
            this.height = row.Height;

            for (int i = 0; i < row.Cells.Count; i++)
            {
                TPTextCell tmpCell = new TPTextCell(row.cells[i]);
                tmpCell.Parent   = this;
                tmpCell.OwnerRow = this;
                this.cells.Add(tmpCell);
                myChildElements.Add(tmpCell);
            }
            this.height = CalculateMinHeight();
        }
示例#2
0
        public TPTextRow Clone()
        {
            TPTextRow newRow = new TPTextRow();

            newRow.OwnerDocument = OwnerDocument;

            newRow.columns = Columns;
            newRow.widths  = Widths;

            newRow.width  = Width;
            newRow.height = Height;

            for (int i = 0; i < Cells.Count; i++)
            {
                TPTextCell tmpCell = cells[i].Clone();
                tmpCell.Parent   = newRow;
                tmpCell.OwnerRow = newRow;
                newRow.cells.Add(tmpCell);
                newRow.myChildElements.Add(tmpCell);
            }
            newRow.height = newRow.CalculateMinHeight();

            return(newRow);
        }
示例#3
0
        public override System.Collections.ArrayList RefreshLine()
        {
            RefreshClientWidth();

            myLines.Clear();

            ArrayList LastLine = new ArrayList();

            for (int i = 0; i < cells.Count; i++)
            {
                if (cells[i].Visible)
                {
                    cells[i].RefreshLine();
                    LastLine.Add(cells[i]);
                }
                else
                {
                    cells[i].OwnerLine = null;
                }
            }

            #region 这里决定各个cell的最终高度

            //几种高度变化的情况:
            // 0: 默认为行中没有行合并的cell
            // 1: 调整maxRowSpanCell的高度.
            // 2: 合并单元格的情况
            // 3: 调整有合并行情况的,非合并cell的cell
            int changeSituation = 0;

            //当前操作的单元格
            TPTextCell currentCell = ownerTable.GetCurrentCell();

            //如果有行合并的情况,则这个为合并的那个cell. 否则为null
            TPTextCell thatspanCell = ownerTable.IsInRowSpan(currentCell);

            if (thatspanCell == null)
            {
                //当前的行中是否包含正在处理cell
                bool trueLine = false;
                foreach (TPTextCell cell in this)
                {
                    if (cell == currentCell)
                    {
                        trueLine = true;
                        break;
                    }
                }
                //如果包含,则为没有行合并的正常行.
                // 否则为其它的行,基本到了后面都会不进行高度处理
                if (trueLine)
                {
                    changeSituation = 0;
                }
                else
                {
                    changeSituation = 1;
                }
            }
            else if (thatspanCell != null)
            {
                if (currentCell == thatspanCell)
                {
                    changeSituation = 1;
                }
                if (currentCell != thatspanCell)
                {
                    changeSituation = 3;
                }
            }

            if (changeSituation == 1)
            {
                //寻找本行中拥有最大的rowspan的cell
                int        tmpRowspan     = 1;
                TPTextCell maxRowSpanCell = null;
                foreach (TPTextCell cell in this)
                {
                    if (cell.Rowspan > tmpRowspan)
                    {
                        tmpRowspan     = cell.Rowspan;
                        maxRowSpanCell = cell;
                    }
                }

                if (maxRowSpanCell == null || tmpRowspan == 1)
                {
                    changeSituation = 2;
                    goto access;
                }
                List <TPTextRow> interRows = new List <TPTextRow>(); //用来存储rowspanCell占据的所有行
                int rowIndex = ownerTable.IndexOf(this);             //获取本行在表格中的索引
                //exceptHeight所包含所有行的总高度.用来判断到底是rowspan的cell增加了高度,还是其他的cell增加了高度d
                int exceptHeight = 0;
                for (int i = rowIndex; i < (rowIndex + tmpRowspan); i++)
                {
                    interRows.Add(ownerTable.AllRows[i]);
                    exceptHeight += ownerTable.AllRows[i].CalculateMinHeight();
                }
                //差的高度, 可能为正,也可能为负.为正时,是增加高度. 为负时,是减少高度.
                int loseHeight = maxRowSpanCell.Height - exceptHeight;
                if (loseHeight == 0)
                {
                    changeSituation = 2; //行合并的cell的高,和几个行的总高相同. 则为合并的情况
                    goto access;
                }
                if (loseHeight != 0)
                {
                    TPTextRow lastInterRow = interRows[interRows.Count - 1];
                    int       newHeight    = lastInterRow.CalculateMinHeight() + loseHeight;
                    foreach (TPTextCell cell in lastInterRow)
                    {
                        if (cell.Height != 0)
                        {
                            cell.Height = newHeight;
                        }
                    }
                    lastInterRow.height = lastInterRow.CalculateMinHeight();
                }
            }
            if (changeSituation == 3)
            {
                //那个合并的cell,是否属于本行
                bool inthis = false;
                foreach (TPTextCell cell in this)
                {
                    if (cell == thatspanCell)
                    {
                        inthis = true;
                        break;
                    }
                }
                if (inthis)
                {
                }
                else
                {
                    //TODO: 被rowspan包含的行,但是又不包含rowspan的那个cell
                }
            }
access:
            //设置行的高度
            switch (changeSituation)
            {
            case 0:
                //获得当前行的最大行高
                int xHeight = CalculateMaxLineHeight();

                //TODO  **************Modified by wwj 2012-02-17 修改单元格高度的算法*****************
                //int linerow = 1;
                //foreach (TPTextCell cell in this)
                //{
                //    if (linerow < cell.Lines.Count)
                //    {
                //        linerow = cell.Lines.Count;
                //    }
                //}
                //foreach (TPTextCell cell in this)
                //{
                //    cell.ContentHeight = xHeight + ((linerow - 1) * (cell.PaddingTop + cell.PaddingBottom));
                //}
                foreach (TPTextCell cell in this)
                {
                    if (cell.Merged)
                    {
                        continue;                 //Add By wwj 2012-02-20 解决打开表格时原先对单元格的合并操作失效的Bug
                    }
                    cell.ContentHeight = xHeight;
                }
                //**************************************END******************************************

                this.height = CalculateMinHeight();
                break;

            case 1:
                this.height = CalculateMinHeight();
                break;

            case 2:

                //Modified by wwj 2012-02-19 在进行单元格合并的时候,导致合并后的单元格的大小不正确
                //int xHeight2 = CalculateMaxLineHeight();
                //int linerow2 = 1;
                //foreach (TPTextCell cell in this)
                //{
                //    if (linerow2 < cell.Lines.Count)
                //    {
                //        linerow2 = cell.Lines.Count;
                //    }
                //}
                //foreach (TPTextCell cell in this)
                //{
                //    cell.ContentHeight = xHeight2 + ((linerow2 - 1) * (cell.PaddingTop + cell.PaddingBottom));
                //}
                //Add By wwj 2012-02-20 解决打开表格时表格全部重叠的Bug
                int minheight = CalculateMinHeight();
                if (minheight > this.height)
                {
                    this.height = minheight;
                }

                break;

            case 3:
                this.height = this.CalculateMinHeight();
                break;
            }


            #endregion

            ResetLine(LastLine);
            LastLine.Clear();

            UpdateBounds();

            return(myLines);
        }