PositionToCellRange() public method

This method converts a Position to the real range of the cell. This is usefull when RowSpan or ColumnSpan is greater than 1. For example suppose to have at grid[0,0] a cell with ColumnSpan equal to 2. If you call this method with the position 0,0 returns 0,0-0,1 and if you call this method with 0,1 return again 0,0-0,1.
public PositionToCellRange ( Position pPosition ) : Range
pPosition Position
return Range
Exemplo n.º 1
0
        /// <summary>
        /// Measures the current row when drawn with the specified cells.
        /// </summary>
        /// <param name="row"></param>
        /// <param name="useColumnWidth">True to fix the column width when calculating the required height of the row.</param>
        /// <param name="StartCol">Start column to measure</param>
        /// <param name="EndCol">End column to measure</param>
        /// <returns>Returns the required height</returns>
        public int MeasureRowHeight(int row, bool useColumnWidth, int StartCol, int EndCol)
        {
            int min = Grid.MinimumHeight;

            if ((GetAutoSizeMode(row) & AutoSizeMode.MinimumSize) == AutoSizeMode.MinimumSize)
            {
                return(min);
            }

            for (int c = StartCol; c <= EndCol; c++)
            {
                Cells.ICellVirtual cell = Grid.GetCell(row, c);
                if (cell != null)
                {
                    Position cellPosition = new Position(row, c);

                    Size maxLayout = Size.Empty;
                    //Use the width of the actual cell (considering spanned cells)
                    if (useColumnWidth)
                    {
                        maxLayout.Width = Grid.RangeToSize(Grid.PositionToCellRange(cellPosition)).Width;
                    }

                    CellContext cellContext = new CellContext(Grid, cellPosition, cell);
                    Size        cellSize    = cellContext.Measure(maxLayout);
                    if (cellSize.Height > min)
                    {
                        min = cellSize.Height;
                    }
                }
            }
            return(min);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Measures the current column when drawn with the specified cells.
        /// </summary>
        /// <param name="column"></param>
        /// <param name="useRowHeight">True to fix the row height when measure the column width.</param>
        /// <param name="StartRow">Start row to measure</param>
        /// <param name="EndRow">End row to measure</param>
        /// <returns>Returns the required width</returns>
        public int MeasureColumnWidth(int column, bool useRowHeight, int StartRow, int EndRow)
        {
            int min = Grid.MinimumWidth;

            if ((GetAutoSizeMode(column) & AutoSizeMode.MinimumSize) == AutoSizeMode.MinimumSize)
            {
                return(min);
            }

            for (int r = StartRow; r <= EndRow; r++)
            {
                Cells.ICellVirtual cell = Grid.GetCell(r, column);
                if (cell != null)
                {
                    Position cellPosition = new Position(r, column);

                    Size maxLayout = Size.Empty;
                    //Use the width of the actual cell (considering spanned cells)
                    if (useRowHeight)
                    {
                        maxLayout.Height = Grid.RangeToSize(Grid.PositionToCellRange(cellPosition)).Height;
                    }

                    CellContext cellContext = new CellContext(Grid, cellPosition, cell);
                    Size        cellSize    = cellContext.Measure(maxLayout);
                    if (cellSize.Width > min)
                    {
                        min = cellSize.Width;
                    }
                }
            }
            return(min);
        }
Exemplo n.º 3
0
        private void RecalcBorderRange()
        {
            if (IsEmpty())
            {
                mRangeHighlight.Range = Range.Empty;
            }
            else
            {
                if (BorderMode == SelectionBorderMode.FocusCell)
                {
                    if (m_ActivePosition.IsEmpty() == false)
                    {
                        mRangeHighlight.Range = Grid.PositionToCellRange(m_ActivePosition);
                    }
                    else
                    {
                        mRangeHighlight.Range = Range.Empty;
                    }
                }
                else if (BorderMode == SelectionBorderMode.FocusRange)
                {
                    RangeCollection selectedRanges = GetRanges();
                    for (int i = 0; i < selectedRanges.Count; i++)
                    {
                        Range range = selectedRanges[i];
                        if (range.Contains(m_ActivePosition))
                        {
                            mRangeHighlight.Range = range;
                            return;
                        }
                    }
                    mRangeHighlight.Range = Range.Empty;
                }
                else if (BorderMode == SelectionBorderMode.UniqueRange)
                {
                    RangeCollection selectedRanges = GetRanges();
                    if (selectedRanges.Count == 1)
                    {
                        mRangeHighlight.Range = selectedRanges[0];
                    }
                    else
                    {
                        mRangeHighlight.Range = Range.Empty;
                    }
                }
                else if (BorderMode == SelectionBorderMode.Auto)
                {
                    RangeCollection selectedRanges = GetRanges();
                    if (selectedRanges.Count == 1)
                    {
                        mRangeHighlight.Range = selectedRanges[0];
                    }
                    else if (m_ActivePosition.IsEmpty() == false)
                    {
                        mRangeHighlight.Range = Grid.PositionToCellRange(m_ActivePosition);
                    }
                    else
                    {
                        mRangeHighlight.Range = Range.Empty;
                    }
                }
                else
                {
                    mRangeHighlight.Range = Range.Empty;
                }

                //Set if the selected cells have the OwnerDrawSelectionBorder enabled.
                if (mRangeHighlight.Range.ColumnsCount == 1 && mRangeHighlight.Range.RowsCount == 1)
                {
                    SourceGrid.Cells.ICellVirtual cell = Grid.GetCell(mRangeHighlight.Range.Start);
                    if (cell != null && cell.View.OwnerDrawSelectionBorder)
                    {
                        mRangeHighlight.Range = Range.Empty;
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Draw the selection using the SelectionColor property over the selected cells. Draw a Border around the selection using Border and BorderMode properties.
        /// </summary>
        /// <param name="p_Panel"></param>
        /// <param name="graphics"></param>
        /// <param name="pRangeToRedraw">The range of cells that must be redrawed. Consider that can contains also not selected cells.</param>
        public virtual void DrawSelectionMask(GridSubPanel p_Panel, DevAge.Drawing.GraphicsCache graphics, Range pRangeToRedraw)
        {
            if (IsEmpty())
            {
                return;
            }

            Region     oldClip       = graphics.Graphics.Clip;
            SolidBrush brushFillMask = graphics.BrushsCache.GetBrush(BackColor);

            try
            {
                graphics.Graphics.Clip = new Region(graphics.ClipRectangle);

                Range     rangeFocus = Range.Empty;
                Rectangle rectFocus  = Rectangle.Empty;
                if (m_ActivePosition.IsEmpty() == false && pRangeToRedraw.Contains(m_ActivePosition))
                {
                    rectFocus  = p_Panel.RectangleGridToPanel(Grid.PositionToRectangle(m_ActivePosition));
                    rangeFocus = Grid.PositionToCellRange(m_ActivePosition);
                }
                Cells.ICellVirtual cellFocus = Grid.GetCell(m_ActivePosition);

                //Draw selection mask and border
                //Draw each cell separately
                if ((m_MaskStyle & SelectionMaskStyle.DrawOnlyInitializedCells) == SelectionMaskStyle.DrawOnlyInitializedCells &&
                    (MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells)                      //Draw Over cells enabled?
                {
                    PositionCollection selectedCells = GetCellsPositions();
                    for (int i = 0; i < selectedCells.Count; i++)
                    {
                        //if must be redrawed, is is not the cell with the focus and contains a cell
                        if (pRangeToRedraw.Contains(selectedCells[i]) && rangeFocus.Contains(selectedCells[i]) == false &&
                            Grid.GetCell(selectedCells[i]) != null)
                        {
                            Rectangle rect = p_Panel.RectangleGridToPanel(Grid.PositionToRectangle(selectedCells[i]));
                            graphics.Graphics.FillRectangle(brushFillMask, rect);
                        }
                    }
                }
                //draw all the selected ranges (Default) //Draw Over cells enabled?
                else if ((MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells)
                {
                    RangeCollection selectedRanges = GetRanges();
                    for (int i = 0; i < selectedRanges.Count; i++)
                    {
                        Range range = selectedRanges[i];
                        if (range.IntersectsWith(pRangeToRedraw))
                        {
                            Rectangle rect = p_Panel.RectangleGridToPanel(Grid.RangeToRectangle(range));

                            if (range.Contains(m_ActivePosition))
                            {
                                Region region = new Region(rect);
                                region.Exclude(rectFocus);
                                graphics.Graphics.FillRegion(brushFillMask, region);
                            }
                            else
                            {
                                graphics.Graphics.FillRectangle(brushFillMask, rect);
                            }
                        }
                    }
                }

                //Draw focus mask and focus border (only if there is a fucus cell and is not in editng mode)
                CellContext focusCellContext = new CellContext(Grid, m_ActivePosition, cellFocus);
                if (cellFocus != null && focusCellContext.IsEditing() == false &&
                    pRangeToRedraw.Contains(m_ActivePosition))
                {
                    //Draw Over cells enabled?
                    if ((MaskStyle & SelectionMaskStyle.DrawSeletionOverCells) == SelectionMaskStyle.DrawSeletionOverCells)
                    {
                        if (m_FocusBackColor != Color.Transparent)
                        {
                            Brush focusBrush = graphics.BrushsCache.GetBrush(m_FocusBackColor);
                            graphics.Graphics.FillRectangle(focusBrush, rectFocus);
                        }
                    }
                }

                if (focusCellContext.IsEditing() == false)
                {
                    mRangeHighlight.DrawHighlight(p_Panel, graphics, pRangeToRedraw);
                }
            }
            finally
            {
                graphics.Graphics.Clip = oldClip;
            }
        }