예제 #1
0
        /// <summary>
        /// 得到光标需要的状态VSplit或HSplit
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private string GetCursorNeedStatus(int x, int y, out TPTextCell dragCell)
        {
            Point p = new Point(x, y);

            dragCell = new TPTextCell();
            string cursorStatus = string.Empty;

            for (int i = 0; i < this.allRows.Count; i++)
            {
                //从第二列开始.cell的左边的边框总是存在的.
                for (int k = 1; k < this.allRows[i].Cells.Count; k++)
                {
                    TPTextCell cell = this.allRows[i].Cells[k];
                    if (cell.Merged == false)
                    {
                        if (p.X >= (cell.RealLeft - 5) && p.X <= (cell.RealLeft + 5) && p.Y >= (cell.RealTop) && p.Y <= (cell.RealTop + cell.Height))
                        {
                            cursorStatus = s_CursorVSplit;
                            dragCell     = cell;
                        }
                        if (p.X >= (cell.RealLeft) && p.X <= (cell.RealLeft + cell.Width) && p.Y >= (cell.RealTop - 5) && p.Y <= (cell.RealTop + 5))
                        {
                            cursorStatus = s_CursorHSplit;

                            //TODO: 鼠标调整高度,暂无实现;
                        }
                    }
                }
            }
            return(cursorStatus);
        }
예제 #2
0
 /// <summary>
 /// <para>获取当前单元格是否在被合并的cell所跨越行的范围内</para>
 /// <para>如果是则返回那个被行合并的cell,否则返回null</para>
 /// </summary>
 /// <returns></returns>
 internal TPTextCell IsInRowSpan(TPTextCell cell)
 {
     for (int row = 0; row < allRows.Count; row++)
     {
         int        rowSpan  = 0;
         TPTextCell spanCell = null;
         for (int col = 0; col < allRows[row].Cells.Count; col++)
         {
             if (allRows[row].Cells[col].Rowspan > 1)
             {
                 rowSpan  = allRows[row].Cells[col].Rowspan;
                 spanCell = allRows[row].Cells[col];
                 break;
             }
         }
         for (int i = row; i < row + rowSpan; i++)
         {
             for (int j = 0; j < allRows[i].Cells.Count; j++)
             {
                 if (cell == allRows[i].Cells[j])
                 {
                     return(spanCell);
                 }
             }
         }
         if (rowSpan != 0)
         {
             row = row + rowSpan - 1;
         }
     }
     return(null);
 }
예제 #3
0
        /// <summary>
        /// 在指定列处插入一个新列
        /// </summary>
        /// <param name="colIndex">Index of the col.</param>
        /// <param name="cell">The cell.</param>
        public void InsertColumns(int colIndex, TPTextCell cell)
        {
            this.columns        = this.absoluteWidths.Length + 1;
            this.absoluteWidths = new int[this.columns];
            SetTotalWidth(0);

            for (int i = 0; i < allRows.Count; i++)
            {
                allRows[i].InsertCell(colIndex, cell);
            }
        }
예제 #4
0
        /// <summary>
        /// 向表格的末尾添加一列
        /// </summary>
        /// <param name="aColumns"></param>
        public void AddColumns(TPTextCell cell)
        {
            this.columns        = this.absoluteWidths.Length + 1;
            this.absoluteWidths = new int[this.columns];
            SetTotalWidth(0);

            for (int i = 0; i < allRows.Count; i++)
            {
                allRows[i].AddCell(cell);
            }
        }
예제 #5
0
        /// <summary>
        /// 获得当前元素所在的单元格(当前正在操作的cell)
        /// </summary>
        /// <returns></returns>
        internal TPTextCell GetCurrentCell()
        {
            //获取当前元素
            ZYTextElement currentEle = OwnerDocument.Content.CurrentElement;
            TPTextCell    cell       = OwnerDocument.Content.GetParentByElement(currentEle, ZYTextConst.c_Cell) as TPTextCell;

            if (cell != null)
            {
                return(cell);
            }
            return(null);
        }
예제 #6
0
        /// <summary>
        /// 设置需要记录拖拽的单元格
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        private void SetRecordDragCell(int x, int y)
        {
            TPTextCell cell;
            string     cursorStatus = GetCursorNeedStatus(x, y, out cell);

            if (cursorStatus == s_CursorVSplit)
            {
                dragCell = cell;
            }
            else if (cursorStatus == s_CursorHSplit)
            {
                //TODO: 鼠标调整高度,暂无实现;
            }
        }
예제 #7
0
        public TPTextCell(TPTextCell cell)
        {
            this.colspan             = cell.Colspan;
            this.rowspan             = cell.Rowspan;
            this.horizontalAlignment = cell.HorizontalAlignment;
            this.verticalAlignment   = cell.VerticalAlignment;

            this.bolSelected = cell.Selected;

            this.Width  = cell.Width;
            this.Height = cell.Height;

            this.backgroundColor = cell.backgroundColor;

            this.PaddingTop    = cell.PaddingTop;
            this.PaddingRight  = cell.PaddingRight;
            this.PaddingBottom = cell.PaddingBottom;
            this.PaddingLeft   = cell.PaddingLeft;

            this.BorderWidth       = cell.BorderWidth;
            this.BorderWidthTop    = cell.BorderWidthTop;
            this.BorderWidthRight  = cell.BorderWidthRight;
            this.BorderWidthBottom = cell.BorderWidthBottom;
            this.BorderWidthLeft   = cell.BorderWidthLeft;

            this.BorderColor       = cell.BorderColor;
            this.BorderColorTop    = cell.BorderColorTop;
            this.BorderColorRight  = cell.BorderColorRight;
            this.BorderColorBottom = cell.BorderColorBottom;
            this.BorderColorLeft   = cell.BorderColorLeft;

            this.BorderStyle       = cell.BorderStyle;
            this.BorderStyleTop    = cell.BorderStyleTop;
            this.BorderStyleRight  = cell.BorderStyleRight;
            this.BorderStyleBottom = cell.BorderStyleBottom;
            this.BorderStyleLeft   = cell.BorderStyleLeft;

            this.ItalicLineStyleInCell = cell.ItalicLineStyleInCell;//Add by wwj 2012-05-29

            this.para   = new ZYTextParagraph();
            para.Parent = this;
            myChildElements.Add(para);
        }
예제 #8
0
        /// <summary>
        /// 单元格深度复制 Add by wwj 2012-05-30
        /// </summary>
        /// <returns></returns>
        public TPTextCell Clone()
        {
            TPTextCell newCell = new TPTextCell();

            newCell.myOwnerDocument = this.myOwnerDocument;

            newCell.myChildElements.Clear();

            newCell.colspan             = Colspan;
            newCell.rowspan             = Rowspan;
            newCell.horizontalAlignment = HorizontalAlignment;
            newCell.verticalAlignment   = VerticalAlignment;

            newCell.bolSelected = Selected;

            newCell.Width  = Width;
            newCell.Height = Height;

            newCell.backgroundColor = backgroundColor;

            newCell.PaddingTop    = PaddingTop;
            newCell.PaddingRight  = PaddingRight;
            newCell.PaddingBottom = PaddingBottom;
            newCell.PaddingLeft   = PaddingLeft;

            newCell.BorderWidth       = BorderWidth;
            newCell.BorderWidthTop    = BorderWidthTop;
            newCell.BorderWidthRight  = BorderWidthRight;
            newCell.BorderWidthBottom = BorderWidthBottom;
            newCell.BorderWidthLeft   = BorderWidthLeft;

            newCell.BorderColor       = BorderColor;
            newCell.BorderColorTop    = BorderColorTop;
            newCell.BorderColorRight  = BorderColorRight;
            newCell.BorderColorBottom = BorderColorBottom;
            newCell.BorderColorLeft   = BorderColorLeft;

            newCell.BorderStyle       = BorderStyle;
            newCell.BorderStyleTop    = BorderStyleTop;
            newCell.BorderStyleRight  = BorderStyleRight;
            newCell.BorderStyleBottom = BorderStyleBottom;
            newCell.BorderStyleLeft   = BorderStyleLeft;

            newCell.ContentHeight = ContentHeight;

            newCell.ItalicLineStyleInCell = ItalicLineStyleInCell;//Add by wwj 2012-05-29

            //***************************************
            newCell.ChildElements.Clear();

            for (int i = 0; i < myChildElements.Count; i++)//遍历单元格中的段落
            {
                ZYTextParagraph para = myChildElements[i] as ZYTextParagraph;
                if (para != null)
                {
                    ZYTextParagraph newPara = new ZYTextParagraph();
                    newPara.Parent        = newCell;
                    newPara.OwnerDocument = newCell.OwnerDocument;
                    newCell.myChildElements.Add(newPara);
                    StringBuilder sb = new StringBuilder();
                    para.GetFinalText(sb);
                    newPara.Align = para.Align;

                    foreach (ZYTextElement myElement in para.ChildElements) //遍历段落中的没有元素
                    {
                        if (myElement is ZYTextChar)                        //如果文本元素
                        {
                            ZYTextChar oldChar = myElement as ZYTextChar;
                            ZYTextChar NewChar = ZYTextChar.Create(oldChar.Char);
                            NewChar.OwnerDocument = newCell.OwnerDocument;
                            NewChar.Parent        = newPara;
                            newPara.InsertBefore(NewChar, newPara.LastElement);
                            NewChar.FontName = oldChar.FontName;
                            NewChar.FontSize = oldChar.FontSize;
                            NewChar.Height   = oldChar.Height;
                            NewChar.Width    = oldChar.Width;
                            NewChar.Sub      = oldChar.Sub;
                            NewChar.Sup      = oldChar.Sup;
                        }
                    }
                }
            }

            //***************************************

            newCell.UpdateBounds();
            return(newCell);
        }
예제 #9
0
        public override bool HandleMouseDown(int x, int y, MouseButtons Button)
        {
            //应该得到鼠标单击时,是单击的那个单元格.以便在MouseMove事件里,判断是否划选出了当前单元格边界
            if (Button == MouseButtons.Left)
            {
                LastMousePosition = new Point(x, y);
                //Debug.WriteLine("● Table大小=" + this.GetContentBounds().ToString());
                //如果是在表格内点击
                if (this.GetContentBounds().Contains(LastMousePosition) && OwnerDocument.OwnerControl.Cursor == Cursors.IBeam)
                {
                    for (int i = 0; i < this.allRows.Count; i++)
                    {
                        for (int k = 0; k < this.allRows[i].Cells.Count; k++)
                        {
                            //将已经选中的cell添加到无效区域内
                            if (this.allRows[i][k].Selected == true || this.allRows[i][k].CanAccess == true)
                            {
                                OwnerDocument.OwnerControl.AddInvalidateRect(this.allRows[i][k].GetContentBounds());
                                //使所有已经选中的cell设为没有选中的状态
                                this.allRows[i][k].Selected  = false;
                                this.allRows[i][k].CanAccess = false;
                            }

                            //找到当前点击的那个cell
                            if (this.allRows[i][k].IsContain(x, y))
                            {
                                currentCell           = this.allRows[i][k];
                                currentCell.CanAccess = true;
                                //Debug.WriteLine("● (" + i + "," + k +")被选择");
                                //Debug.WriteLine(IsInRowSpan(currentCell) ? "●在rowspan●" : "●no inside●");
                            }
                        }
                    }

                    //刷新无效区域
                    myOwnerDocument.OwnerControl.UpdateInvalidateRect();

                    return(false);
                }
                else if (this.GetContentBounds().Contains(LastMousePosition) && OwnerDocument.OwnerControl.Cursor == Cursors.VSplit)
                {
                    //得到要拖拽的单元格,在按下鼠标的时候记录下拖拽的单元格 Modified by wwj 2012-02-16
                    SetRecordDragCell(x, y);

                    //TODO: 当鼠标出于cell的边界处时.此时点击,应该显示一条全页范围内的的纵向虚线,用来拖拽. [ 虚线暂时弄不出来,以后再改 ]

                    //down时,根绝dragCell得到要调整的两列的所有格子(点击处左右两处的列)
                    int rightNum = GetColNum(dragCell);
                    int leftNum  = rightNum - 1;
                    foreach (TPTextRow row in this)
                    {
                        //在这i代表列号
                        for (int i = 0; i < row.Cells.Count; i++)
                        {
                            if (i == leftNum)
                            {
                                leftColCells.Add(row.Cells[i]);
                            }
                            if (i == rightNum)
                            {
                                rightColCells.Add(row.Cells[i]);
                            }
                        }
                    }
                    Debug.WriteLine("●调整列宽前●");
                    for (int i = 0; i < absoluteWidths.Length; i++)
                    {
                        Debug.WriteLine("第" + i + "列:" + absoluteWidths[i]);
                    }
                    //Rectangle drec = new Rectangle(dragCell.RealLeft, 0, 5, OwnerDocument.OwnerControl.CurrentPage.Height);
                }
                else // 在表格外点击
                {
                    foreach (TPTextRow row in this)
                    {
                        foreach (TPTextCell cell in row)
                        {
                            myOwnerDocument.OwnerControl.AddInvalidateRect(cell.GetContentBounds());
                            cell.Selected  = false;
                            cell.CanAccess = false;
                        }
                    }
                    currentCell = null;
                    myOwnerDocument.OwnerControl.UpdateInvalidateRect();
                }
            }

            return(false);
        }
예제 #10
0
 /// <summary>
 /// 获得cell在表格中的列号.
 /// </summary>
 /// <param name="cell"></param>
 /// <returns></returns>
 internal int GetColNum(TPTextCell cell)
 {
     return(cell.OwnerRow.IndexOf(cell));
 }
예제 #11
0
        public override bool HandleMouseUp(int x, int y, MouseButtons Button)
        {
            bool isDragDone = false;//表示是否处理过拖拽操作 是:返回true 否:返回false

            if (OwnerDocument.OwnerControl.Cursor == Cursors.VSplit)
            {
                if (dragCell != null)
                {
                    isDragDone = true;
                    //确定鼠标要调整的宽度,为正数则是向右拖拽,为负数则是向左拖拽
                    int moveWidth = x - dragCell.RealLeft;
                    Debug.WriteLine("●●●●调整的宽度: " + moveWidth);
                    int   acol     = GetColNum(dragCell);
                    int[] tmpWidth = new int[absoluteWidths.Length];
                    for (int i = 0; i < absoluteWidths.Length; i++)
                    {
                        if (i == (acol - 1))
                        {
                            tmpWidth[i] = absoluteWidths[i] + moveWidth;
                        }
                        else if (i == acol)
                        {
                            tmpWidth[i] = absoluteWidths[i] - moveWidth;
                        }
                        else
                        {
                            tmpWidth[i] = absoluteWidths[i];
                        }
                    }
                    SetWidth(tmpWidth);
                    foreach (TPTextRow row in this)
                    {
                        row.Widths = tmpWidth;
                    }
                    foreach (TPTextCell cell in leftColCells)
                    {
                        if (cell.Width != 0)
                        {
                            cell.Width = cell.Width + moveWidth;
                        }
                    }
                    foreach (TPTextCell cell in rightColCells)
                    {
                        if (cell.Width != 0)
                        {
                            cell.Width = cell.Width - moveWidth;
                        }
                    }
                    Debug.WriteLine("●调整列宽后●");
                    for (int i = 0; i < absoluteWidths.Length; i++)
                    {
                        Debug.WriteLine("第" + i + "列:" + absoluteWidths[i]);
                    }

                    OwnerDocument.ContentChanged();
                    OwnerDocument.Refresh();
                }
            }
            LastMousePosition = new Point(-1, -1);
            currentCell       = null;

            dragCell = null;
            leftColCells.Clear();
            rightColCells.Clear();
            return(isDragDone);
        }