public bool Contains(SelectionRangeWithItems rangeWithItemsToCompare)
        {
            int            count          = m_list.Count;
            SelectionRange rangeToCompare = rangeWithItemsToCompare.Range;

            for (int i = 0; i < count; i++)
            {
                SelectionRangeWithItems rangeWithItem     = m_list[i];
                SelectionRange          rangeIntersection = rangeWithItem.Range.Intersect(rangeToCompare);

                if (!rangeIntersection.IsEmpty)
                {
                    if (rangeWithItemsToCompare.IsItemsEqual(rangeIntersection, rangeWithItem))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
예제 #2
0
        public bool Remove(SelectionCellRangeWithItems cellRangeWithItemsToRemove)
        {
            if (cellRangeWithItemsToRemove.CellRange.IsEmpty)
            {
                return(true);
            }

            bool removed = false;
            SelectionCellRange cellRangeToRemove = cellRangeWithItemsToRemove.CellRange;

            object[] itemsToRemove            = cellRangeWithItemsToRemove.ItemRangeWithItems.Items;
            int      itemsToRemoveCount       = (itemsToRemove == null) ? 0 : itemsToRemove.Length;
            int      itemOffsetToRemove       = 0;
            bool     itemRangeToRemoveIsEmpty = cellRangeToRemove.ItemRange.IsEmpty;

            do
            {
                for (int i = m_list.Count - 1; i >= 0; i--)
                {
                    SelectionCellRangeWithItems cellRangeWithItems = m_list[i];
                    SelectionRange          itemRange          = cellRangeWithItems.ItemRange;
                    SelectionCellRange      cellRange          = cellRangeWithItems.CellRange;
                    SelectionRangeWithItems itemRangeWithItems = cellRangeWithItems.ItemRangeWithItems;
                    SelectionCellRange      cellRangeIntersection;
                    object[] oldRangeItems = itemRangeWithItems.Items;

                    if (itemRangeToRemoveIsEmpty)
                    {
                        int itemOffset = Array.IndexOf(oldRangeItems, itemsToRemove[itemOffsetToRemove]);

                        if (itemOffset == -1)
                        {
                            continue;
                        }

                        int itemIndex = itemRange.GetIndexFromItemOffset(itemOffset);

                        cellRangeIntersection = new SelectionCellRange(
                            new SelectionRange(itemIndex, itemIndex),
                            cellRangeWithItems.ColumnRange.Intersect(cellRangeToRemove.ColumnRange));
                    }
                    else
                    {
                        cellRangeIntersection = cellRange.Intersect(cellRangeToRemove);

                        if (cellRangeIntersection.IsEmpty)
                        {
                            continue;
                        }

                        if (!itemRangeWithItems.IsItemsEqual(
                                cellRangeIntersection.ItemRange, cellRangeWithItemsToRemove.ItemRangeWithItems))
                        {
                            continue;
                        }
                    }

                    removed       = true;
                    m_cellsCount -= cellRangeIntersection.Length;
                    SelectionCellRange[] newCellRanges = cellRange.Exclude(cellRangeIntersection);

                    if (newCellRanges.Length == 0)
                    {
                        m_list.RemoveAt(i);
                    }
                    else
                    {
                        SelectionCellRange newCellRange = newCellRanges[0];

                        m_list[i] = new SelectionCellRangeWithItems(
                            newCellRange.ItemRange, itemRangeWithItems.GetItems(newCellRange.ItemRange), newCellRange.ColumnRange);

                        for (int j = 1; j < newCellRanges.Length; j++)
                        {
                            newCellRange = newCellRanges[j];

                            m_list.Insert(i + j, new SelectionCellRangeWithItems(
                                              newCellRange.ItemRange, itemRangeWithItems.GetItems(newCellRange.ItemRange), newCellRange.ColumnRange));
                        }
                    }
                }

                itemOffsetToRemove++;
            } while((itemRangeToRemoveIsEmpty) && (itemOffsetToRemove < itemsToRemoveCount));

            return(removed);
        }
예제 #3
0
    public bool Contains( SelectionRangeWithItems rangeWithItemsToCompare )
    {
      int count = m_list.Count;
      SelectionRange rangeToCompare = rangeWithItemsToCompare.Range;

      for( int i = 0; i < count; i++ )
      {
        SelectionRangeWithItems rangeWithItem = m_list[ i ];
        SelectionRange rangeIntersection = rangeWithItem.Range.Intersect( rangeToCompare );

        if( !rangeIntersection.IsEmpty )
        {
          if( rangeWithItemsToCompare.IsItemsEqual( rangeIntersection, rangeWithItem ) )
            return true;
        }
      }

      return false;
    }
        public bool Remove(SelectionRangeWithItems rangeWithItemsToRemove)
        {
            bool           removed       = false;
            SelectionRange rangeToRemove = rangeWithItemsToRemove.Range;

            object[] itemsToRemove        = rangeWithItemsToRemove.Items;
            int      itemsToRemoveCount   = (itemsToRemove == null) ? 0 : itemsToRemove.Length;
            int      itemOffsetToRemove   = 0;
            bool     rangeToRemoveIsEmpty = rangeToRemove.IsEmpty;

            do
            {
                for (int i = m_list.Count - 1; i >= 0; i--)
                {
                    SelectionRangeWithItems rangeWithItems = m_list[i];
                    SelectionRange          range          = rangeWithItems.Range;
                    SelectionRange          rangeIntersection;
                    object[] oldRangeItems = rangeWithItems.Items;

                    if (rangeToRemoveIsEmpty)
                    {
                        int itemOffset = Array.IndexOf(oldRangeItems, itemsToRemove[itemOffsetToRemove]);

                        if (itemOffset == -1)
                        {
                            continue;
                        }

                        rangeIntersection = new SelectionRange(range.GetIndexFromItemOffset(itemOffset));
                    }
                    else
                    {
                        rangeIntersection = range.Intersect(rangeToRemove);

                        if (rangeIntersection.IsEmpty)
                        {
                            continue;
                        }

                        if (!rangeWithItems.IsItemsEqual(rangeIntersection, rangeWithItemsToRemove))
                        {
                            continue;
                        }
                    }

                    removed       = true;
                    m_itemsCount -= rangeIntersection.Length;
                    SelectionRange[] newRanges = range.Exclude(rangeIntersection);

                    if (newRanges.Length == 0)
                    {
                        m_list.RemoveAt(i);
                    }
                    else
                    {
                        SelectionRange newRange = newRanges[0];
                        m_list[i] = new SelectionRangeWithItems(newRange, rangeWithItems.GetItems(newRange));

                        if (newRanges.Length > 1)
                        {
                            Debug.Assert(newRanges.Length == 2);
                            newRange = newRanges[1];
                            m_list.Insert(i + 1, new SelectionRangeWithItems(newRange, rangeWithItems.GetItems(newRange)));
                        }
                    }
                }

                itemOffsetToRemove++;
            } while((rangeToRemoveIsEmpty) && (itemOffsetToRemove < itemsToRemoveCount));

            return(removed);
        }