Beispiel #1
0
 public WtCell CreateCells()
 {
     var cell = new WtCell() {OwnerRow = this, OwnerTable = OwnerTable};
     Cells.Add(cell);
     return cell;
 }
Beispiel #2
0
 public override void DragBegin(int x, int y)
 {
     var context = OwnerDocument.Context;
     var currentPage = ((EditorDocument) OwnerDocument).CurrentPage;
     if (!IsTouchRowBorder(y))
     {
         _dragCell = TouchCellBorder(x);
         if (_dragCell != null)
         {
             //控制向左拖动的位置
             if (context.MouseCurrentPosition.X <= _dragCell.X) return;
             //控制向右拖动的位置
             if ((_dragCell.NextCell != null &&
                  context.MouseCurrentPosition.X >= _dragCell.NextCell.X + _dragCell.NextCell.Width) ||
                 context.MouseCurrentPosition.X >
                 currentPage.X + currentPage.PaddingLeft + currentPage.BodyWidth) return;
             //以下设置拖动虚线的坐标和大小
             var page = ((EditorDocument)OwnerDocument).GetPage(_dragCell.X, _dragCell.Y);
             _isDragColBorder = true;
             _colBorderRectangle = new Rectangle(context.MouseCurrentPosition.X, page.Y + page.OffsetY, 1,
                                                 page.Height);
         }
         else
         {
             var wtCell = LocateCurrentCell(x, y);
             if (wtCell != null)
             {
                 wtCell.OwnerDocument.Drag(x, y);
             }
         }
     }
     else
     {
         //控制拖动的位置向上不超过该行的纵坐标
         if (context.MouseCurrentPosition.Y <= this.Y) return;
         //以下设置拖动虚线的坐标和大小
         var page = ((EditorDocument)OwnerDocument).GetPage(this.X, this.Y);
         _isDragRowBorder = true;
         _rowBorderRectangle = new Rectangle(page.X + page.OffsetX, context.MouseCurrentPosition.Y, page.Width, 1);
     }
     context.Invalidate();
 }
Beispiel #3
0
        private List<WtCell> SplitCell(int rowCount, int colCount, WtRow wtRow, WtCell cell)
        {
            var tempWidth = cell.Width / colCount;
            var lastWidth = cell.Width - tempWidth*(colCount - 1);

            var cells = new List<WtCell>();
            WtCell tempCell = null;
            for (var i = 0; i < colCount; i++)
            {
                if (i == 0)
                {
                    cell.Width = tempWidth;
                    tempCell = cell;
                }
                else
                {
                    tempCell = wtRow.InsertCellAfter(tempCell);
                    tempCell.Width = i < colCount - 1 ? tempWidth : lastWidth;
                    tempCell.Height = cell.Height;
                }
                cells.Add(tempCell);
            }
            wtRow.SetCellProperty();
            return cells;
        }
Beispiel #4
0
 public void Add(WtCell cell)
 {
     if (Cells.Contains(cell)) return;
     cell.OwnerRow = this;
     cell.OwnerTable = this.OwnerTable;
     Cells.Add(cell);
     var count = Cells.Count;
     if (count > 1)
     {
         Cells[count - 2].NextCell = Cells[count - 1];
         Cells[count - 1].PreCell = Cells[count - 2];
     }
 }
Beispiel #5
0
        /// <summary>
        /// 起始点在表格内的选择
        /// </summary>
        public void InnerSelect(WtCell startCell, WtCell endCell)
        {
            if (startCell == null || endCell == null) return;

            SelectedCells.Clear();

            var startX = startCell.X > endCell.X ? endCell.X : startCell.X;
            var startY = startCell.Y > endCell.Y ? endCell.Y : startCell.Y;
            var xRange = Math.Abs(startCell.X - endCell.X);
            var yRange = Math.Abs(startCell.Y - endCell.Y);

            foreach (var wtRow in Rows)
            {
                if (wtRow.Y < startY || wtRow.Y > startY + yRange) continue;
                var cells = wtRow.Cells;
                foreach (var wtCell in cells.Where(wtCell => wtCell.X >= startX && wtCell.X <= startX + xRange))
                {
                    wtCell.IsSelected = true;
                    SelectedCells.Add(wtCell);
                }
            }
        }
Beispiel #6
0
        public DTable Xml2Object(XmlElement xmlElement)
        {
            if (!"table".Equals(xmlElement.Name)) return this;

            Width = Convert.ToInt32(xmlElement.GetAttribute("width"));
            Height = Convert.ToInt32(xmlElement.GetAttribute("height"));

            var rowElements = xmlElement.ChildNodes;
            foreach (XmlNode rowNode in rowElements)
            {
                if (!"tRow".Equals(rowNode.Name)) continue;
                var rowElement = (XmlElement) rowNode;
                var row = new WtRow
                    {
                        Width = Convert.ToInt32(rowElement.GetAttribute("width")),
                        Height = Convert.ToInt32(rowElement.GetAttribute("height")),
                        OwnerTable = this
                    };

                var cellElements = rowElement.ChildNodes;
                foreach (XmlNode cellNode in cellElements)
                {
                    if(!"tCell".Equals(cellNode.Name)) continue;
                    var cellElement = (XmlElement) cellNode;
                    var cell = new WtCell
                        {
                            OwnerTable = this,
                            OwnerRow = row,
                            OwnerDocument = {Context = OwnerDocument.Context}
                        };
                    cell.Xml2Object(cellElement);
                    row.Add(cell);
                }
                row.SetCellsRelation();
                Rows.Add(row);
            }
            SetRowsRelation();
            return this;
        }
Beispiel #7
0
 public void Replace(List<WtCell> tCells)
 {
     if (tCells == null) return;
     for (var i = 0; i < tCells.Count;i++ )
     {
         var tempCell = new WtCell()
         {
             OwnerRow = this,
             OwnerTable = this.OwnerTable,
             Width = tCells[i].Width,
             Height = tCells[i].Height
         };
         var index = Cells.IndexOf(tCells[i]);
         Cells.RemoveAt(index);
         Cells.Insert(index, tempCell);
     }
     SetCellsRelation();
     SetCellProperty();
 }
Beispiel #8
0
        private bool IsOutContextHorizonal(WtCell wtCell, int dragWidth, out int suitableWidth)
        {
            suitableWidth = 0;
            if (wtCell.NextCell != null) return false;

            var page = ((EditorDocument)OwnerDocument).CurrentPage;
            var pageRange = page.X + page.PaddingLeft + page.BodyWidth;

            if (dragWidth > pageRange)
            {
                suitableWidth = pageRange - wtCell.X;
                return true;
            }

            var flag = false;
            var tempWidth = 0;
            var tempCell = wtCell.NextCell;

            while (tempCell != null)
            {
                dragWidth += tempCell.Width;
                if (dragWidth > pageRange)
                {
                    flag = true;
                }
                tempWidth += tempCell.Width;
                tempCell = tempCell.NextCell;
            }

            if (flag)
            {
                suitableWidth = pageRange - tempWidth - wtCell.X;
            }

            return flag;
        }
Beispiel #9
0
        public void Replace(WtCell removeCell, WtCell replaceCell)
        {
            var index = Cells.IndexOf(removeCell);
            if (index < 0) return;

            Remove(removeCell);
            Cells.Insert(index, replaceCell);

            if (index >= 1)
            {
                Cells[index - 1].NextCell = replaceCell;
                replaceCell.PreCell = Cells[index - 1];
            }

            if (index < Cells.Count - 1)
            {
                Cells[index + 1].PreCell = replaceCell;
                replaceCell.NextCell = Cells[index + 1];
            }
        }
Beispiel #10
0
        public void Remove(WtCell cell)
        {
            if (!Cells.Contains(cell)) return;

            if (cell.PreCell != null)
            {
                cell.PreCell.NextCell = cell.NextCell;
            }

            if (cell.NextCell != null)
            {
                cell.NextCell.PreCell = cell.PreCell;
            }

            cell.PreCell = null;
            cell.NextCell = null;

            Cells.Remove(cell);
        }
Beispiel #11
0
        public WtCell LocateCurrentCell(int x, int y)
        {
            var flag = false;
            foreach (var wtCell in Cells)
            {
                if (x <= wtCell.X && wtCell.PreCell == null)
                {
                    flag = true;
                }
                else if (x > wtCell.X + wtCell.Width && wtCell.NextCell == null)
                {
                    flag = true;
                }
                else if (x > wtCell.X && x <= wtCell.X + wtCell.Width)
                {
                    flag = true;
                }

                if (!flag) continue;
                CurrentCell = wtCell;
                wtCell.Locate(x, y);
                break;
            }
            return CurrentCell;
        }
Beispiel #12
0
        public WtCell InsertCellBefore(WtCell afterCell)
        {
            var index = Cells.IndexOf(afterCell);
            if (index < 0) return null;

            var cell = new WtCell() { OwnerTable = this.OwnerTable, OwnerRow = this };

            Cells.Insert(index, cell);

            if (index - 1 >= 0)
            {
                Cells[index - 1].NextCell = cell;
                cell.PreCell = Cells[index - 1];
            }

            if (index + 1 < Cells.Count)
            {
                Cells[index + 1].PreCell = cell;
                cell.NextCell = Cells[index + 1];
            }

            return cell;
        }
Beispiel #13
0
        public WtCell InsertCellAfter(WtCell beforeCell)
        {
            var index = Cells.IndexOf(beforeCell);
            if (index < 0) return null;

            var cell = new WtCell() {OwnerTable = this.OwnerTable,OwnerRow = this};

            Cells.Insert(index + 1, cell);

            Cells[index].NextCell = cell;
            cell.PreCell = Cells[index];

            if (index + 2 < Cells.Count)
            {
                Cells[index + 2].PreCell = cell;
                cell.NextCell = Cells[index + 2];
            }

            return cell;
        }