Пример #1
0
        public bool Contains(SelectionCellRangeWithItems rangeWithItems)
        {
            if ((m_unsortedRanges.Count <= 0) || (SelectedCellsStorage.IsEmpty(rangeWithItems)))
            {
                return(false);
            }

            if (rangeWithItems.Length == 1)
            {
                return(this.IndexOfOverlap(rangeWithItems).Any());
            }

            var store = new SelectedCellsStorage(null);

            store.Add(rangeWithItems);

            foreach (var match in this.IndexOfOverlap(rangeWithItems))
            {
                store.Remove(m_unsortedRanges[match].Value);

                if (store.Count == 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        public bool Contains(SelectionCellRange range)
        {
            if ((m_unsortedRanges.Count <= 0) || (SelectedCellsStorage.IsEmpty(range)))
            {
                return(false);
            }

            return(this.Contains(new SelectionCellRangeWithItems(range.ItemRange, null, range.ColumnRange)));
        }
Пример #3
0
        public object Clone()
        {
            var copy = new SelectedCellsStorage(m_dataGridContext);

            for (int i = 0; i < m_unsortedRanges.Count; i++)
            {
                copy.Insert(i, m_unsortedRanges[i].Value, false);
            }

            return(copy);
        }
Пример #4
0
            internal ItemComparer(SelectionCellRangeWithItemsWrapper target)
            {
                if (target == null)
                {
                    throw new ArgumentNullException("target");
                }

                if (SelectedCellsStorage.IsEmpty(target.Value))
                {
                    throw new ArgumentException("The selection range must not be empty.", "target");
                }

                m_target = target;
            }
Пример #5
0
 internal SelectionInfo(
     DataGridContext dataGridContext,
     SelectedItemsStorage removedItems,
     SelectedItemsStorage addedItems,
     SelectedCellsStorage removedCells,
     SelectedCellsStorage addedCells)
 {
     this.DataGridContext   = dataGridContext;
     this.AddedItems        = new ReadOnlyCollection <object>(new SelectionItemCollection(addedItems));
     this.RemovedItems      = new ReadOnlyCollection <object>(new SelectionItemCollection(removedItems));
     this.AddedItemRanges   = new ReadOnlyCollection <SelectionRange>(new SelectionItemRangeCollection(addedItems));
     this.RemovedItemRanges = new ReadOnlyCollection <SelectionRange>(new SelectionItemRangeCollection(removedItems));
     this.AddedCellRanges   = new ReadOnlyCollection <SelectionCellRange>(new SelectionCellRangeCollection(addedCells));
     this.RemovedCellRanges = new ReadOnlyCollection <SelectionCellRange>(new SelectionCellRangeCollection(removedCells));
 }
Пример #6
0
        private IEnumerable <int> IndexOfOverlap(SelectionCellRange target)
        {
            if ((m_sortedRanges.Count <= 0) || SelectedCellsStorage.IsEmpty(target))
            {
                yield break;
            }

            var comparer = new ItemRangeComparer(target.ItemRange);

            var index = this.FindIndex(comparer);

            if (index < 0)
            {
                yield break;
            }

            while (index > 0)
            {
                if (comparer.Compare(m_sortedRanges[index - 1]) != 0)
                {
                    break;
                }

                index--;
            }

            for (int i = index; i < m_sortedRanges.Count; i++)
            {
                var wrapper = m_sortedRanges[i];
                if (comparer.Compare(wrapper) != 0)
                {
                    break;
                }

                var currentRangeWithItems = wrapper.Value;
                var overlap = target.Intersect(currentRangeWithItems.CellRange);

                if (!SelectedCellsStorage.IsEmpty(overlap))
                {
                    yield return(wrapper.Index);
                }
            }
        }
Пример #7
0
        private void Insert(int index, SelectionCellRangeWithItems item, bool repairIndex)
        {
            var wrapper = new SelectionCellRangeWithItemsWrapper(item, index);

            m_unsortedRanges.Insert(index, wrapper);

            if (repairIndex)
            {
                this.RepairIndex(index + 1);
            }

            if (!SelectedCellsStorage.IsEmpty(item))
            {
                var insertionIndex = ~this.FindIndex(new ItemComparer(wrapper));
                Debug.Assert(insertionIndex >= 0);

                m_sortedRanges.Insert(insertionIndex, wrapper);
            }
        }
Пример #8
0
        private void RemoveAt(int index, bool repairIndex)
        {
            var wrapper = m_unsortedRanges[index];

            Debug.Assert(wrapper.Index == index);

            if (!SelectedCellsStorage.IsEmpty(wrapper.Value))
            {
                var removalIndex = this.FindIndex(new ItemComparer(wrapper));
                Debug.Assert(removalIndex >= 0);

                m_sortedRanges.RemoveAt(removalIndex);
            }

            m_unsortedRanges.RemoveAt(index);

            if (repairIndex)
            {
                this.RepairIndex(index);
            }
        }
Пример #9
0
 public SelectionCellRangeCollection(SelectedCellsStorage list)
 {
     m_list = list;
 }