예제 #1
0
파일: DTable.cs 프로젝트: bensenplus/breeze
 public WtCell CreateCells()
 {
     var cell = new WtCell() {OwnerRow = this, OwnerTable = OwnerTable};
     Cells.Add(cell);
     return cell;
 }
예제 #2
0
파일: DTable.cs 프로젝트: bensenplus/breeze
 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();
 }
예제 #3
0
파일: DTable.cs 프로젝트: bensenplus/breeze
        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;
        }
예제 #4
0
파일: DTable.cs 프로젝트: bensenplus/breeze
 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];
     }
 }
예제 #5
0
파일: DTable.cs 프로젝트: bensenplus/breeze
        /// <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);
                }
            }
        }
예제 #6
0
파일: DTable.cs 프로젝트: bensenplus/breeze
        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;
        }
예제 #7
0
파일: DTable.cs 프로젝트: bensenplus/breeze
 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();
 }
예제 #8
0
파일: DTable.cs 프로젝트: bensenplus/breeze
        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;
        }
예제 #9
0
파일: DTable.cs 프로젝트: bensenplus/breeze
        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];
            }
        }
예제 #10
0
파일: DTable.cs 프로젝트: bensenplus/breeze
        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);
        }
예제 #11
0
파일: DTable.cs 프로젝트: bensenplus/breeze
        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;
        }
예제 #12
0
파일: DTable.cs 프로젝트: bensenplus/breeze
        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;
        }
예제 #13
0
파일: DTable.cs 프로젝트: bensenplus/breeze
        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;
        }