Пример #1
0
        public void Draw(
            GridRange range,
            GridPoints points)
        {
            DrawingContext drawingContext = RenderOpen();
            DoubleCollection xCollection = new DoubleCollection();
            DoubleCollection yCollection = new DoubleCollection();

            try {
                // vertical line
                double renderHeight = points.GetHeight(range.Rows);
                Rect verticalLineRect = new Rect(new Size(GridLineThickness, renderHeight));
                foreach (int i in range.Columns.GetEnumerable()) {
                    verticalLineRect.X = points.xPosition(i + 1) - GridLineThickness;
                    drawingContext.DrawRectangle(GridLineBrush, null, verticalLineRect);
                    xCollection.Add(verticalLineRect.X);
                }

                // horizontal line
                double renderWidth = points.GetWidth(range.Columns);
                Rect horizontalLineRect = new Rect(new Size(renderWidth, GridLineThickness));
                foreach (int i in range.Rows.GetEnumerable()) {
                    horizontalLineRect.Y = points.yPosition(i + 1) - GridLineThickness;
                    drawingContext.DrawRectangle(GridLineBrush, null, horizontalLineRect);
                    yCollection.Add(horizontalLineRect.Y);
                }

                XSnappingGuidelines = xCollection;
                YSnappingGuidelines = yCollection;
            } finally {
                drawingContext.Close();
            }
        }
Пример #2
0
        internal void DrawVisuals(GridRange newViewport, IGrid<string> data)
        {
            Children.Clear();

            var orgViewport = _dataViewport;
            var orgGrid = _cells;
            _cells = new Grid<GridPanelCell>(
                newViewport,
                (r, c) => {
                    if (orgViewport.Contains(r, c)) {
                        return orgGrid[r, c];
                    }
                    var visual = new GridPanelCell();
                    visual.Row = r;
                    visual.Column = c;
                    visual.Text = data[r, c];

                    return visual;
                });
            _dataViewport = newViewport;

            Size infiniteSize = new Size(double.PositiveInfinity, double.PositiveInfinity);

            foreach (int r in newViewport.Rows.GetEnumerable()) {
                foreach (int c in newViewport.Columns.GetEnumerable()) {
                    GridPanelCell textBlock = _cells[r, c];
                    textBlock.Measure(infiniteSize);

                    Points.SetWidth(c, textBlock.DesiredSize.Width);
                    Points.SetHeight(r, textBlock.DesiredSize.Height);

                    Children.Add(textBlock);
                }
            }

            foreach (GridPanelCell child in Children) {
                child.SetValue(Canvas.LeftProperty, Points.xPosition(child.Column));
                child.SetValue(Canvas.TopProperty, Points.yPosition(child.Row));

                child.Inflate(Points.GetWidth(child.Column), Points.GetHeight(child.Row));
            }
        }
Пример #3
0
 public GridRange Intersect(GridRange range)
 {
     throw new NotImplementedException();
 }
Пример #4
0
        private void DrawVisuals(GridRange dataViewport, IGridData<string> data) {
            if (DataGrid != null) {
                DataGrid.DrawVisuals(dataViewport, data.Grid);
            }

            if (ColumnHeader != null) {
                GridRange columnViewport = new GridRange(
                    new Range(0, 1),
                    dataViewport.Columns);
                ColumnHeader.DrawVisuals(columnViewport, new Grid<string>(columnViewport, data.ColumnHeader)); // TODO: new data
            }

            if (RowHeader != null) {
                GridRange rowViewport = new GridRange(
                    dataViewport.Rows,
                    new Range(0, 1));
                RowHeader.DrawVisuals(rowViewport, new Grid<string>(rowViewport, data.RowHeader));    // TODO: new data
            }
        }
Пример #5
0
        private void DrawCells(GridRange newViewport, IGrid<string> data)
        {
            var orgGrid = _visualGrid;
            _visualGrid = new Grid<TextVisual>(
                newViewport,
                (r, c) => {
                    if (_dataViewport.Contains(r, c)) {
                        return orgGrid[r, c];
                    }
                    var visual = new TextVisual();
                    visual.Row = r;
                    visual.Column = c;
                    visual.Text = data[r, c];
                    visual.Typeface = Typeface;
                    visual.FontSize = FontSize * (96.0 / 72.0);  // TODO: test in High DPI
                    return visual;
                });

            _visualChildren.Clear();
            foreach (int c in newViewport.Columns.GetEnumerable()) {
                foreach (int r in newViewport.Rows.GetEnumerable()) {
                    var visual = _visualGrid[r, c];

                    double width = Points.GetWidth(c) - GridLineThickness;
                    double height = Points.GetHeight(r) - GridLineThickness;
                    if (visual.Draw(new Size(width, height))) {
                        Points.SetWidth(c, Math.Max(width, visual.Size.Width + GridLineThickness));
                        Points.SetHeight(r, Math.Max(height, visual.Size.Height + GridLineThickness));
                    }

                    _visualChildren.Add(_visualGrid[r, c]);
                }
            }

            foreach (int c in newViewport.Columns.GetEnumerable()) {
                foreach (int r in newViewport.Rows.GetEnumerable()) {
                    var visual = _visualGrid[r, c];

                    var transform = visual.Transform as TranslateTransform;
                    if (transform == null) {
                        visual.Transform = new TranslateTransform(xPosition(visual), yPosition(visual));
                    } else {
                        transform.X = xPosition(visual);
                        transform.Y = yPosition(visual);
                    }
                }
            }
            _dataViewport = newViewport;

            // special handling for Row/Column header's size: this will layout system (measure/arrange) to know the size of component properly.
            if (GridType == GridType.ColumnHeader && RowCount > 0) {
                Height = Points.GetHeight(0);
            } else if (GridType == GridType.RowHeader && ColumnCount > 0) {
                Width = Points.GetWidth(0);
            }
        }
Пример #6
0
        internal void DrawVisuals(GridRange newViewport, IGrid<string> data)
        {
            DrawCells(newViewport, data);

            DrawGridLine();
        }