Esempio n. 1
0
        public GridLayer(RenderElement owner, int nColumns, int nRows, CellSizeStyle cellSizeStyle)
            : base(owner)
        {
            this.cellSizeStyle = cellSizeStyle;
            this.gridTable = new GridTable();
            gridRows = gridTable.Rows;
            gridCols = gridTable.Columns;
            int columnWidth = owner.Width;
            if (nColumns > 0)
            {
                columnWidth = columnWidth / nColumns;
                uniformCellWidth = columnWidth;
                if (columnWidth < 1)
                {
                    columnWidth = 1;
                }
            }

            //------------------------------------------------------------             
            int cx = 0;
            for (int c = 0; c < nColumns; c++)
            {
                GridColumn col = new GridColumn(columnWidth);
                col.Width = columnWidth;
                col.Left = cx;
                cx += columnWidth;
                gridCols.Add(col);
            }
            //------------------------------------------------------------

            if (nRows > 0)
            {
                int rowHeight = owner.Height / nRows;
                int cy = 0;
                for (int r = 0; r < nRows; r++)
                {
                    var row = new GridRow(rowHeight);
                    gridRows.Add(row);
                    row.Height = rowHeight;
                    row.Top = cy;
                    cy += rowHeight;
                }
                uniformCellHeight = rowHeight;
            }
            //------------------------------------------------------------
        }
Esempio n. 2
0
 internal GridCell CreateGridItemForRow(GridRow row)
 {
     GridCell gridItem = new GridCell(
         this,
         row);
     cells.Add(gridItem);
     return gridItem;
 }
Esempio n. 3
0
 public void InsertAfter(GridRow afterThisRow, GridRow row)
 {
     InsertAfter(afterThisRow.RowIndex, row);
 }
Esempio n. 4
0
            internal void InsertAfter(int afterRowId, GridRow row)
            {
                int newRowHeight = row.Height;
                row.SetOwnerParentRowCollection(this);
                row.RowIndex = afterRowId + 1;
                rows.Insert(afterRowId + 1, row);
                foreach (GridColumn coldef in table.GetColumnIter())
                {
                    coldef.InsertAfter(afterRowId, row);
                }

                int j = rows.Count;
                for (int i = afterRowId + 2; i < j; i++)
                {
                    GridRow r = rows[i];
                    r.RowIndex = i;
                }
            }
Esempio n. 5
0
 public void InsertRowAfter(GridRow afterThisRow, GridRow row)
 {
     gridRows.InsertAfter(afterThisRow, row);
 }
Esempio n. 6
0
 internal IEnumerable<GridCell> GetCellIter(GridRow rowdef)
 {
     int rowId = rowdef.RowIndex;
     if (rowId > -1 && rowId < rows.Count)
     {
         foreach (GridColumn coldef in table.GetColumnIter())
         {
             yield return coldef.GetCell(rowId);
         }
     }
 }
Esempio n. 7
0
 internal void RemoveRow(GridRow row)
 {
     if (cells.Count == 0)
     {
         return;
     }
     int rowid = row.RowIndex;
     GridCell removedGridItem = cells[rowid];
     cells.RemoveAt(rowid);
 }
Esempio n. 8
0
 internal GridCell(GridColumn column, GridRow row)
 {
     this.row = row;
     this.column = column;
 }
Esempio n. 9
0
 public void InsertRowAfter(GridRow afterThisRow, GridRow row)
 {
     gridRows.InsertAfter(afterThisRow, row);
 }
Esempio n. 10
0
        public GridCell GetGridItemByPosition(int x, int y)
        {
            if (y < 0)
            {
                y = 0;
            }
            if (x < 0)
            {
                x = 0;
            }

            switch (cellSizeStyle)
            {
            case CellSizeStyle.UniformWidth:
            {
                var     cell0     = this.GetCell(0, 0);
                var     cellWidth = cell0.Width;
                GridRow row       = gridRows.GetRowAtPos(y);
                if (row != null)
                {
                    int columnNumber = x / cellWidth;
                    if (columnNumber >= gridCols.Count)
                    {
                        columnNumber = gridCols.Count - 1;
                    }

                    GridColumn column = gridCols[columnNumber];
                    if (column == null)
                    {
                        column = gridCols.Last;
                    }
                    if (column != null)
                    {
                        return(column.GetCell(row.RowIndex));
                    }
                }
            }
            break;

            case CellSizeStyle.UniformHeight:
            {
                var cell0      = this.GetCell(0, 0);
                var cellHeight = cell0.Height;
                int rowNumber  = y / cellHeight;
                if (rowNumber >= gridRows.Count)
                {
                    rowNumber = gridRows.Count - 1;
                }
                GridRow row = gridRows[rowNumber];
                if (row != null)
                {
                    GridColumn column = gridCols.GetColumnAtPosition(x);
                    if (column == null)
                    {
                        column = gridCols.Last;
                    }
                    if (column != null)
                    {
                        return(column.GetCell(row.RowIndex));
                    }
                }
            }
            break;

            case CellSizeStyle.UniformCell:
            {
                //find cell height
                var cell0      = this.GetCell(0, 0);
                var cellWidth  = cell0.Width;
                var cellHeight = cell0.Height;
                int rowNumber  = y / cellHeight;
                if (rowNumber >= gridRows.Count)
                {
                    rowNumber = gridRows.Count - 1;
                }

                GridRow row = gridRows[rowNumber];
                if (row != null)
                {
                    int columnNumber = x / cellWidth;
                    if (columnNumber >= gridCols.Count)
                    {
                        columnNumber = gridCols.Count - 1;
                    }
                    GridColumn column = gridCols[columnNumber];
                    if (column == null)
                    {
                        column = gridCols.Last;
                    }
                    if (column != null)
                    {
                        return(column.GetCell(row.RowIndex));
                    }
                }
            }
            break;

            default:
            {
                GridRow row = gridRows.GetRowAtPos(y);
                if (row == null)
                {
                    row = gridRows.Last;
                }
                if (row != null)
                {
                    GridColumn column = gridCols.GetColumnAtPosition(x);
                    if (column == null)
                    {
                        column = gridCols.Last;
                    }
                    if (column != null)
                    {
                        return(column.GetCell(row.RowIndex));
                    }
                }
            }
            break;
            }
            return(null);
        }
Esempio n. 11
0
        public GridLayer(RenderElement owner, CellSizeStyle cellSizeStyle, GridTable gridTable)
            : base(owner)
        {
            _cellSizeStyle = cellSizeStyle;
            _gridTable     = gridTable;

            _gridRows = gridTable.Rows;
            _gridCols = gridTable.Columns;


            int nColumns = gridTable.ColumnCount;

            if (cellSizeStyle == CellSizeStyle.ColumnAndRow)
            {
                int cx = 0;
                for (int c = 0; c < nColumns; c++)
                {
                    GridColumn col   = _gridCols.GetColumn(c);
                    int        col_w = col.Width;
                    col.Left = cx;
                    cx      += col_w;
                }
                //------------------------------------------------------------
                int nRows = gridTable.RowCount;
                if (nRows > 0)
                {
                    int cy    = 0;
                    int row_h = 1;
                    for (int r = 0; r < nRows; r++)
                    {
                        GridRow row = _gridRows.GetRow(r);
                        row_h      = row.Height;
                        row.Height = row_h;
                        row.Top    = cy;
                        cy        += row_h;
                    }
                    _uniformCellHeight = row_h;
                }
            }
            else
            {
                int columnWidth = owner.Width;
                if (nColumns > 0)
                {
                    columnWidth       = columnWidth / nColumns;
                    _uniformCellWidth = columnWidth;
                    if (columnWidth < 1)
                    {
                        columnWidth = 1;
                    }
                }
                //------------------------------------------------------------
                int cx = 0;
                for (int c = 0; c < nColumns; c++)
                {
                    GridColumn col = _gridCols.GetColumn(c);
                    col.Width = columnWidth;
                    col.Left  = cx;
                    cx       += columnWidth;
                }
                //------------------------------------------------------------
                int nRows = gridTable.RowCount;
                if (nRows > 0)
                {
                    int rowHeight = owner.Height / nRows;
                    int cy        = 0;
                    for (int r = 0; r < nRows; r++)
                    {
                        GridRow row = _gridRows.GetRow(r);
                        row.Height = rowHeight;
                        row.Top    = cy;
                        cy        += rowHeight;
                    }
                    _uniformCellHeight = rowHeight;
                }
            }


            //------------------------------------------------------------
        }
Esempio n. 12
0
 internal GridCell(GridColumn column, GridRow row)
 {
     this.row    = row;
     this.column = column;
 }
Esempio n. 13
0
 public void InsertAfter(GridRow afterThisRow, GridRow row)
 {
     InsertAfter(afterThisRow.RowIndex, row);
 }
Esempio n. 14
0
 public void MoveRowAfter(GridRow fromRow, GridRow toRow)
 {
     this.gridRows.MoveRowAfter(fromRow, toRow);
     this.OwnerInvalidateGraphic();
 }
Esempio n. 15
0
 public void AddRow(GridRow row)
 {
     gridRows.Add(row);
 }
Esempio n. 16
0
 internal void InsertAfter(int index, GridRow row)
 {
     GridCell gridItem = new GridCell(
         this, row);
     cells.Insert(index + 1, gridItem);
 }
Esempio n. 17
0
 internal void MoveRowAfter(GridRow fromRow, GridRow toRow)
 {
     int destRowIndex = toRow.RowIndex;
     if (destRowIndex > fromRow.RowIndex)
     {
         destRowIndex -= 1;
     }
     GridCell fromGridItem = cells[fromRow.RowIndex];
     cells.RemoveAt(fromRow.RowIndex);
     cells.Insert(destRowIndex, fromGridItem);
 }
Esempio n. 18
0
 public void AddRow(GridRow row)
 {
     gridRows.Add(row);
 }
Esempio n. 19
0
            public void MoveRowAfter(GridRow fromRow, GridRow toRow)
            {
                int toRowIndex = toRow.RowIndex;
                if (fromRow.RowIndex < toRowIndex)
                {
                    toRowIndex -= 1;
                }

                foreach (GridColumn col in table.GetColumnIter())
                {
                    col.MoveRowAfter(fromRow, toRow);
                }

                rows.RemoveAt(fromRow.RowIndex);
                rows.Insert(toRowIndex, fromRow);
                UpdateRowIndex(fromRow, toRow);
            }
Esempio n. 20
0
 public void MoveRowAfter(GridRow fromRow, GridRow toRow)
 {
     this.gridRows.MoveRowAfter(fromRow, toRow);
     this.OwnerInvalidateGraphic();
 }
Esempio n. 21
0
 void UpdateRowIndex(GridRow row1, GridRow row2)
 {
     if (row1.RowIndex < row2.RowIndex)
     {
         int stopRowIndex = row2.RowIndex;
         for (int i = row1.RowIndex; i <= stopRowIndex; i++)
         {
             rows[i].RowIndex = i;
         }
     }
     else
     {
         int stopRowIndex = row1.RowIndex;
         for (int i = row2.RowIndex; i <= stopRowIndex; i++)
         {
             rows[i].RowIndex = i;
         }
     }
 }
Esempio n. 22
0
        public override void DrawChildContent(Canvas canvas, Rectangle updateArea)
        {
            //GridCell leftTopGridItem = GetGridItemByPosition(updateArea.Left, updateArea.Top);
            //if (leftTopGridItem == null)
            //{
            //    return;

            //}
            //GridCell rightBottomGridItem = GetGridItemByPosition(updateArea.Right, updateArea.Bottom);
            //if (rightBottomGridItem == null)
            //{
            //    return;
            //}


            //TODO: temp fixed, review here again,
            GridCell leftTopGridItem = this.GetCell(0, 0);

            if (leftTopGridItem == null)
            {
                return;
            }
            GridCell rightBottomGridItem = this.GetCell(this.RowCount - 1, this.ColumnCount - 1);

            if (rightBottomGridItem == null)
            {
                return;
            }
            this.BeginDrawingChildContent();
            GridColumn startColumn   = leftTopGridItem.column;
            GridColumn currentColumn = startColumn;
            GridRow    startRow      = leftTopGridItem.row;
            GridColumn stopColumn    = rightBottomGridItem.column.NextColumn;
            GridRow    stopRow       = rightBottomGridItem.row.NextRow;
            int        startRowId    = startRow.RowIndex;
            int        stopRowId     = 0;

            if (stopRow == null)
            {
                stopRowId = gridRows.Count;
            }
            else
            {
                stopRowId = stopRow.RowIndex;
            }
            int n         = 0;
            var prevColor = canvas.StrokeColor;

            canvas.StrokeColor = Color.Gray;
            //canvas.DrawLine(0, 0, 100, 100);
            //canvas.DrawLine(0, 100, 100, 0);

            //if (startRowId > 0)
            //{
            //    Console.WriteLine(startRowId);
            //}

            //canvas.DrawRectangle(Color.Red, updateArea.Left, updateArea.Top, updateArea.Width, updateArea.Height);

            do
            {
                GridCell startGridItemInColumn = currentColumn.GetCell(startRowId);
                GridCell stopGridItemInColumn  = currentColumn.GetCell(stopRowId - 1);
                //draw vertical line
                canvas.DrawLine(
                    startGridItemInColumn.Right,
                    startGridItemInColumn.Y,
                    stopGridItemInColumn.Right,
                    stopGridItemInColumn.Bottom);
                if (n == 0)
                {
                    //draw horizontal line
                    int horizontalLineWidth = rightBottomGridItem.Right - startGridItemInColumn.X;
                    for (int i = startRowId; i < stopRowId; i++)
                    {
                        GridCell gridItem = currentColumn.GetCell(i);
                        int      x        = gridItem.X;
                        int      gBottom  = gridItem.Bottom;
                        canvas.DrawLine(
                            x, gBottom,
                            x + horizontalLineWidth, gBottom);
                    }
                    n = 1;
                }
                currentColumn = currentColumn.NextColumn;
            } while (currentColumn != stopColumn);
            canvas.StrokeColor = prevColor;
            currentColumn      = startColumn;
            //----------------------------------------------------------------------------
            do
            {
                for (int i = startRowId; i < stopRowId; i++)
                {
                    GridCell gridItem = currentColumn.GetCell(i);
                    if (gridItem != null && gridItem.HasContent)
                    {
                        int x = gridItem.X;
                        int y = gridItem.Y;
                        canvas.OffsetCanvasOrigin(x, y);
                        updateArea.Offset(-x, -y);
                        var renderContent = gridItem.ContentElement as RenderElement;
                        if (renderContent != null)
                        {
                            if (canvas.PushClipAreaRect(gridItem.Width, gridItem.Height, ref updateArea))
                            {
                                renderContent.DrawToThisCanvas(canvas, updateArea);
                            }
                            canvas.PopClipAreaRect();
                        }


                        canvas.OffsetCanvasOrigin(-x, -y);
                        updateArea.Offset(x, y);
                    }
#if DEBUG
                    else
                    {
                        canvas.DrawText(new char[] { '.' }, gridItem.X, gridItem.Y);
                    }
#endif
                }

                currentColumn = currentColumn.NextColumn;
            } while (currentColumn != stopColumn);
            this.FinishDrawingChildContent();
        }
Esempio n. 23
0
            public void Add(GridRow row)
            {
                int lastcount = rows.Count;
                row.RowIndex = lastcount;
                if (lastcount > 0)
                {
                    row.Top = rows[lastcount - 1].Bottom;
                }

                rows.Add(row);
                if (!row.IsBoundToGrid)
                {
                    foreach (GridColumn column in table.GetColumnIter())
                    {
                        column.CreateGridItemForRow(row);
                    }
                }
                row.SetOwnerParentRowCollection(this);
                OwnerInvalidateGraphicAndStartBubbleUp();
            }
Esempio n. 24
0
            public GridRow AddRowAfter(int afterRowId, int rowHeight)
            {
                int newrowId = afterRowId + 1;
                GridRow newGridRow = null;
                if (afterRowId == -1)
                {
                    newGridRow = new GridRow(rowHeight);
                    newGridRow.Top = 0;
                    Add(newGridRow);
                }
                else
                {
                    GridRow refRowDefinition = rows[afterRowId];
                    newGridRow = new GridRow(rowHeight);
                    newGridRow.Top = refRowDefinition.Top + refRowDefinition.Height;
                    InsertAfter(afterRowId, newGridRow);
                }

                return newGridRow;
            }