示例#1
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;
            }
        }