Example #1
0
        /// <summary>
        /// Prende un range che è già stato filtrato con solo le celle presenti nell'attuale range
        /// </summary>
        /// <param name="pRange"></param>
        /// <returns></returns>
        private bool InternalRemove(RangeRegion pRange)
        {
            pRange = Intersect(pRange);
            if (pRange.IsEmpty())
            {
                return(true);                //il range non è presente
            }
            pRange.m_bValidated = true;

            RangeRegionCancelEventArgs e = new RangeRegionCancelEventArgs(pRange);

            OnRemovingRange(e);             //calling this method the range can change
            if (e.Cancel)
            {
                return(false);
            }

            if (pRange.m_bValidated == false)
            {
                pRange = Intersect(pRange);
                if (pRange.IsEmpty())
                {
                    return(true);                    //il range non è presente
                }
            }

            m_RangeCollection = Exclude(pRange).m_RangeCollection;

            OnRemovedRange(e);

            m_bValidated = false;

            return(true);
        }
Example #2
0
 /// <summary>
 /// Adds the elements of another RangeCollection to the end of this RangeCollection.
 /// </summary>
 /// <param name="items">
 /// The RangeCollection whose elements are to be added to the end of this RangeCollection.
 /// </param>
 public virtual void AddRange(RangeCollection items)
 {
     foreach (Range item in items)
     {
         this.List.Add(item);
     }
 }
Example #3
0
        private void Selection_RemovingRange(object sender, RangeRegionCancelEventArgs e)
        {
            //se è abilitato RowColSpan devo assicurarmi di selezionare la cella di origine e non quella che sfrutta il RowCol Span
            if (EnableRowColSpan)
            {
                RangeCollection rangesToRemove = e.RangeRegion.GetRanges();
                for (int iRange = 0; iRange < rangesToRemove.Count; iRange++)
                {
                    Range rng = rangesToRemove[iRange];
                    for (int r = rng.Start.Row; r <= rng.End.Row; r++)
                    {
                        for (int c = rng.Start.Column; c <= rng.End.Column; c++)
                        {
                            Cells.ICell l_Cell = this[r, c];                           //N.B. questo metodo mi restituisce la cella reale (anche se questa posizione è occupata slo perchè in mee con Row/Col Span)
                            if (l_Cell != null)
                            {
                                Range l_Range = l_Cell.Range;

                                if (l_Range != new Range(new Position(r, c)))                       //se la cella occupa più righe o colonne
                                {
                                    e.RangeRegion.Add(l_Range);                                     //la seleziono tutta
                                }
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Returns a Collection of range that represents the current class
        /// </summary>
        /// <returns></returns>
        public virtual RangeCollection GetRanges()
        {
            RangeCollection ranges = new RangeCollection();

            ranges.AddRange(m_RangeCollection);

            return(ranges);
        }
Example #5
0
        /// <summary>
        /// Invalidate all the selected cells
        /// </summary>
        public virtual void Invalidate()
        {
            RangeCollection ranges = GetRanges();

            for (int i = 0; i < ranges.Count; i++)
            {
                m_Grid.InvalidateRange(ranges[i]);
            }
        }
Example #6
0
        /// <summary>
        /// Returns all the selected rows index
        /// </summary>
        /// <returns></returns>
        public virtual int[] GetRowsIndex()
        {
            System.Collections.ArrayList indexList = new System.Collections.ArrayList();
            RangeCollection ranges = GetRanges();

            for (int iRange = 0; iRange < ranges.Count; iRange++)
            {
                for (int r = ranges[iRange].Start.Row; r <= ranges[iRange].End.Row; r++)
                {
                    if (indexList.Contains(r) == false)
                    {
                        indexList.Add(r);
                    }
                }
            }
            int[] ret = new int[indexList.Count];
            indexList.CopyTo(ret, 0);

            return(ret);
        }
Example #7
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;
                    }
                }
            }
        }
Example #8
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;
            }
        }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the RangeCollection class, containing elements
 /// copied from another instance of RangeCollection
 /// </summary>
 /// <param name="items">
 /// The RangeCollection whose elements are to be added to the new RangeCollection.
 /// </param>
 public RangeCollection(RangeCollection items)
 {
     this.AddRange(items);
 }
Example #10
0
 public Enumerator(RangeCollection collection)
 {
     this.wrapped = ((System.Collections.CollectionBase)collection).GetEnumerator();
 }