コード例 #1
0
        private void RemoveAt(int index, bool repairIndex)
        {
            var wrapper        = m_ranges[index];
            var rangeWithItems = wrapper.Value;

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

            if (!rangeWithItems.IsEmpty)
            {
                var removed = m_map.Remove(SelectedItemsStorage.GetArea(rangeWithItems), wrapper);
                Debug.Assert(removed, "Failed to remove the selection range.");

                // Since there should be only a single instance of the wrapper within the collection, try an altenate strategy.
                if (!removed)
                {
                    var entry = m_map.FirstOrDefault(e => e.Item == wrapper);
                    if (entry.Item == wrapper)
                    {
                        removed = m_map.Remove(entry);
                    }

                    Debug.Assert(removed, "Failed to find the selection range.");
                }
            }

            m_ranges.RemoveAt(index);

            if (repairIndex)
            {
                this.RepairIndex(index);
            }
        }
コード例 #2
0
    public void Visit( DataGridContext sourceContext, ref bool stopVisit )
    {
      object[] items;
      CollectionView itemsCollection = sourceContext.Items;
      int count = itemsCollection.Count;

      if( count == 0 )
        return;

      if( sourceContext.ItemsSourceCollection is DataGridVirtualizingCollectionViewBase )
      {
        items = null;
      }
      else
      {
        items = new object[ count ];

        for( int i = 0; i < count; i++ )
        {
          items[ i ] = itemsCollection.GetItemAt( i );
        }
      }

      SelectionRange itemRange = new SelectionRange( 0, count - 1 );

      if( sourceContext.DataGridControl.SelectionUnit == SelectionUnit.Row )
      {
        sourceContext.DataGridControl.SelectionChangerManager.SelectItems(
          sourceContext,
          new SelectionRangeWithItems( itemRange, items ) );
      }
      else
      {
        HashedLinkedList<ColumnBase> columnsByVisiblePosition = sourceContext.ColumnsByVisiblePosition;
        SelectedItemsStorage selectedColumnStore = new SelectedItemsStorage( null, 8 );
        SelectionRange fullColumnRange = new SelectionRange( 0, columnsByVisiblePosition.Count - 1 );
        selectedColumnStore.Add( new SelectionRangeWithItems( fullColumnRange, null ) );
        int index = 0;

        foreach( ColumnBase column in columnsByVisiblePosition )
        {
          if( !column.Visible )
          {
            selectedColumnStore.Remove( new SelectionRangeWithItems( new SelectionRange( index ), null ) );
          }

          index++;
        }

        int columnRangeCount = selectedColumnStore.Count;

        for( int i = 0; i < columnRangeCount; i++ )
        {
          sourceContext.DataGridControl.SelectionChangerManager.SelectCells(
            sourceContext,
            new SelectionCellRangeWithItems( itemRange, items, selectedColumnStore[ i ].Range ) );
        }
      }
    }
コード例 #3
0
 public SelectionChanger( DataGridContext owner )
 {
   m_owner = owner;
   m_itemsToSelect = new SelectedItemsStorage( owner, 2 );
   m_itemsToUnselect = new SelectedItemsStorage( owner, 2 );
   m_cellsToSelect = new SelectedCellsStorage( owner, 2 );
   m_cellsToUnselect = new SelectedCellsStorage( owner, 2 );
   m_toDeferSelect = new List<object>( 1 );
   m_sourceChanges = new List<SourceChangeInfo>( 2 );
 }
コード例 #4
0
        public void Insert(int index, SelectionRangeWithItems rangeWithItems)
        {
            Debug.Assert(!this.Contains(rangeWithItems.Range));
            m_itemsCount += rangeWithItems.Length;

            SelectedItemsStorage.UpdateSelectionRangeWithItemsFromAdd(
                m_dataGridContext, rangeWithItems, ref rangeWithItems);

            m_list.Insert(index, rangeWithItems);
        }
コード例 #5
0
 internal SelectionChanger(DataGridContext owner)
 {
     m_owner           = owner;
     m_itemsToSelect   = new SelectedItemsStorage(owner);
     m_itemsToUnselect = new SelectedItemsStorage(owner);
     m_cellsToSelect   = new SelectedCellsStorage(owner);
     m_cellsToUnselect = new SelectedCellsStorage(owner);
     m_toDeferSelect   = new List <object>(1);
     m_sourceChanges   = new List <SourceChangeInfo>(2);
 }
コード例 #6
0
        public void Add(SelectionCellRangeWithItems rangeWithItems)
        {
            Debug.Assert(m_unsortedRanges.All(r => r.Value.CellRange.Intersect(rangeWithItems.CellRange).IsEmpty), "Part of this range is already selected");

            var itemRangeWithItems = rangeWithItems.ItemRangeWithItems;

            SelectedItemsStorage.UpdateSelectionRangeWithItemsFromAdd(m_dataGridContext, itemRangeWithItems, ref itemRangeWithItems);

            var newRangeWithItems = new SelectionCellRangeWithItems(itemRangeWithItems.Range, itemRangeWithItems.Items, rangeWithItems.ColumnRange);

            this.Insert(this.Count, newRangeWithItems, true);
        }
コード例 #7
0
        public object Clone()
        {
            var copy = new SelectedItemsStorage(m_dataGridContext);

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

            copy.m_itemsCount = m_itemsCount;

            return(copy);
        }
コード例 #8
0
        public int Add(SelectionCellRangeWithItems cellRangeWithItems)
        {
            m_cellsCount += cellRangeWithItems.Length;
            SelectionRangeWithItems itemRangeWithItems = cellRangeWithItems.ItemRangeWithItems;

            SelectedItemsStorage.UpdateSelectionRangeWithItemsFromAdd(
                m_dataGridContext, itemRangeWithItems, ref itemRangeWithItems);

            m_list.Add(new SelectionCellRangeWithItems(
                           itemRangeWithItems.Range, itemRangeWithItems.Items, cellRangeWithItems.ColumnRange));

            return(m_list.Count - 1);
        }
コード例 #9
0
        public void Insert(int index, SelectionCellRangeWithItems cellRangeWithItems)
        {
            Debug.Assert(!this.Contains(cellRangeWithItems.CellRange));
            m_cellsCount += cellRangeWithItems.Length;

            SelectionRangeWithItems itemRangeWithItems = cellRangeWithItems.ItemRangeWithItems;

            SelectedItemsStorage.UpdateSelectionRangeWithItemsFromAdd(
                m_dataGridContext, itemRangeWithItems, ref itemRangeWithItems);

            m_list.Insert(
                index, new SelectionCellRangeWithItems(
                    itemRangeWithItems.Range, itemRangeWithItems.Items, cellRangeWithItems.ColumnRange));
        }
コード例 #10
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 ) );
 }
コード例 #11
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));
 }
コード例 #12
0
        private void Insert(int index, SelectionRangeWithItems item, bool repairIndex)
        {
            var wrapper = new SelectionRangeWithItemsWrapper(item, index);

            m_ranges.Insert(index, wrapper);

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

            if (!item.IsEmpty)
            {
                m_map.Add(SelectedItemsStorage.GetArea(item), wrapper);
            }
        }
コード例 #13
0
        private IEnumerable <int> IndexOfOverlap(SelectionRangeWithItems rangeWithItems)
        {
            foreach (var entry in m_map.GetEntriesWithin(SelectedItemsStorage.GetArea(rangeWithItems)))
            {
                var candidate = entry.Item;
                var target    = candidate.Value;
                var overlap   = rangeWithItems.Range.Intersect(target.Range);

                Debug.Assert(!overlap.IsEmpty);

                if (!overlap.IsEmpty && (rangeWithItems.IsItemsEqual(overlap, target)))
                {
                    yield return(candidate.Index);
                }
            }
        }
コード例 #14
0
        public bool SelectJustThisItem(int itemIndex, object item)
        {
            bool selectionDone = true;

            m_toDeferSelect.Clear();

            SelectionRangeWithItems rangeWithItemsToSelect = new SelectionRangeWithItems(itemIndex, item);
            SelectionRange          range = rangeWithItemsToSelect.Range;

            if (m_itemsToSelect.Contains(range))
            {
                selectionDone = false;
            }

            m_itemsToSelect.Clear();
            SelectedItemsStorage selectedItemsInChange = m_owner.SelectedItemsStore;

            if (selectedItemsInChange.Contains(range))
            {
                if (!m_itemsToUnselect.Contains(range))
                {
                    selectionDone = false;
                }

                m_itemsToUnselect.Clear();

                foreach (SelectionRangeWithItems selectedRangeWithItems in selectedItemsInChange)
                {
                    m_itemsToUnselect.Add(selectedRangeWithItems);
                }

                m_itemsToUnselect.Remove(rangeWithItemsToSelect);
            }
            else
            {
                m_itemsToSelect.Add(rangeWithItemsToSelect);
                m_itemsToUnselect.Clear();

                foreach (SelectionRangeWithItems selectedRangeWithItems in selectedItemsInChange)
                {
                    m_itemsToUnselect.Add(selectedRangeWithItems);
                }
            }

            this.UnselectAllCells();
            return(selectionDone);
        }
コード例 #15
0
        public int Add(SelectionRangeWithItems rangeWithItems)
        {
            Debug.Assert(!this.Contains(rangeWithItems.Range));

            m_itemsCount += rangeWithItems.Length;
            int count = m_list.Count;

            if (count > 0)
            {
                int lastIndex = count - 1;
                SelectionRangeWithItems lastRangeWithItems = m_list[lastIndex];
                SelectionRange          lastRange          = lastRangeWithItems.Range;

                if ((lastRange.EndIndex + 1) == rangeWithItems.Range.StartIndex)
                {
                    Debug.Assert(rangeWithItems.Range.EndIndex > lastRange.EndIndex);

                    SelectedItemsStorage.UpdateSelectionRangeWithItemsFromAdd(
                        m_dataGridContext, rangeWithItems, ref lastRangeWithItems);

                    m_list[lastIndex] = lastRangeWithItems;
                    return(lastIndex);
                }
                else if ((lastRange.EndIndex - 1) == rangeWithItems.Range.StartIndex)
                {
                    Debug.Assert(rangeWithItems.Range.EndIndex < lastRange.EndIndex);

                    SelectedItemsStorage.UpdateSelectionRangeWithItemsFromAdd(
                        m_dataGridContext, rangeWithItems, ref lastRangeWithItems);

                    m_list[lastIndex] = lastRangeWithItems;
                    return(lastIndex);
                }
            }

            SelectedItemsStorage.UpdateSelectionRangeWithItemsFromAdd(
                m_dataGridContext, rangeWithItems, ref rangeWithItems);

            m_list.Add(rangeWithItems);
            return(m_list.Count - 1);
        }
コード例 #16
0
        public void Add(SelectionRangeWithItems rangeWithItems)
        {
            Debug.Assert(!this.Contains(rangeWithItems.Range));

            m_itemsCount += rangeWithItems.Length;

            if (this.Count > 0)
            {
                var lastIndex          = this.Count - 1;
                var lastRangeWithItems = this[lastIndex];
                var lastRange          = lastRangeWithItems.Range;

                if ((lastRange.EndIndex + 1) == rangeWithItems.Range.StartIndex)
                {
                    Debug.Assert(rangeWithItems.Range.EndIndex > lastRange.EndIndex);

                    SelectedItemsStorage.UpdateSelectionRangeWithItemsFromAdd(m_dataGridContext, rangeWithItems, ref lastRangeWithItems);

                    this[lastIndex] = lastRangeWithItems;
                    return;
                }
                else if ((lastRange.EndIndex - 1) == rangeWithItems.Range.StartIndex)
                {
                    Debug.Assert(rangeWithItems.Range.EndIndex < lastRange.EndIndex);

                    SelectedItemsStorage.UpdateSelectionRangeWithItemsFromAdd(m_dataGridContext, rangeWithItems, ref lastRangeWithItems);

                    this[lastIndex] = lastRangeWithItems;
                    return;
                }
            }

            SelectedItemsStorage.UpdateSelectionRangeWithItemsFromAdd(m_dataGridContext, rangeWithItems, ref rangeWithItems);

            this.Insert(this.Count, rangeWithItems, true);
        }
コード例 #17
0
        public bool UnselectItems(SelectionRangeWithItems rangeWithItems)
        {
            if (!(m_owner.ItemsSourceCollection is DataGridVirtualizingCollectionViewBase))
            {
                if (m_toDeferSelect.Count > 0)
                {
                    foreach (object item in rangeWithItems.Items)
                    {
                        m_toDeferSelect.Remove(item);
                    }
                }
            }

            SelectionRange range = rangeWithItems.Range;

            if (range.IsEmpty)
            {
                // We have no index we have to remove based on item
                bool selectionChanged = false;

                List <SelectionRangeWithItems> itemsRangeToRemove = new List <SelectionRangeWithItems>();
                List <object> itemsToUnselect = new List <object>(rangeWithItems.Items);
                int           count           = itemsToUnselect.Count;

                for (int i = count - 1; i >= 0; i--)
                {
                    object itemToUnselect = itemsToUnselect[i];
                    bool   selectionAdded = false;

                    foreach (SelectionRangeWithItems existingSelectionRangeWithItems in m_itemsToSelect)
                    {
                        int index = Array.IndexOf(existingSelectionRangeWithItems.Items, itemToUnselect);

                        if (index > -1)
                        {
                            selectionAdded = true;

                            itemsRangeToRemove.Add(
                                new SelectionRangeWithItems(
                                    existingSelectionRangeWithItems.Range.GetIndexFromItemOffset(index),
                                    itemToUnselect));
                        }
                    }

                    if (selectionAdded)
                    {
                        itemsToUnselect.RemoveAt(i);
                    }
                }

                // Remove the currently unselected item from the new range to select
                foreach (SelectionRangeWithItems itemRangeToRemove in itemsRangeToRemove)
                {
                    selectionChanged |= m_itemsToSelect.Remove(itemRangeToRemove);
                }

                count = itemsToUnselect.Count;

                for (int i = 0; i < count; i++)
                {
                    object itemToUnselect = itemsToUnselect[i];

                    foreach (SelectionRangeWithItems existingSelectionRangeWithItems in m_owner.SelectedItemsStore)
                    {
                        int index = Array.IndexOf(existingSelectionRangeWithItems.Items, itemToUnselect);

                        if (index >= 0)
                        {
                            index = existingSelectionRangeWithItems.Range.GetIndexFromItemOffset(index);

                            if (!m_itemsToUnselect.Contains(index))
                            {
                                selectionChanged = true;
                                m_itemsToUnselect.Add(new SelectionRangeWithItems(index, itemToUnselect));
                            }
                        }
                    }
                }

                return(selectionChanged);
            }

            if (range.Length == 1)
            {
                if (!m_itemsToSelect.Remove(rangeWithItems))
                {
                    if (!m_owner.SelectedItemsStore.Contains(range))
                    {
                        return(false);
                    }

                    if (m_itemsToUnselect.Contains(range))
                    {
                        return(false);
                    }

                    m_itemsToUnselect.Add(rangeWithItems);
                }

                return(true);
            }
            else
            {
                SelectedItemsStorage tempStorage = new SelectedItemsStorage(m_owner);
                tempStorage.Add(rangeWithItems);

                // Remove the currently selected item from the new range to select
                foreach (SelectionRangeWithItems existingSelectionRangeWithItems in m_itemsToSelect)
                {
                    if (!range.Intersect(existingSelectionRangeWithItems.Range).IsEmpty)
                    {
                        tempStorage.Remove(existingSelectionRangeWithItems);
                    }
                }

                bool selectionChanged = m_itemsToSelect.Remove(rangeWithItems);

                if (tempStorage.Count > 0)
                {
                    selectionChanged = true;

                    foreach (SelectionRangeWithItems rangeWithItemsToAdd in tempStorage)
                    {
                        Debug.Assert(!m_itemsToUnselect.Contains(rangeWithItemsToAdd.Range));
                        m_itemsToUnselect.Add(rangeWithItemsToAdd);
                    }
                }

                return(selectionChanged);
            }
        }
コード例 #18
0
 internal SelectedItemsStorage(SelectedItemsStorage collection)
 {
     m_dataGridContext = collection.m_dataGridContext;
     m_list            = new List <SelectionRangeWithItems>(collection.m_list);
     m_itemsCount      = collection.m_itemsCount;
 }
コード例 #19
0
 internal SelectionItemCollection(SelectedItemsStorage collection)
 {
     m_storage = collection;
 }
コード例 #20
0
    public SelectionInfo GetSelectionInfo()
    {
      List<SelectionRangeWithItems> removedRangeWithItems;
      List<SelectionRangeWithItems> unselectedItemsFromRemove = this.GetUnselectedItemsFromRemove( out removedRangeWithItems );
      List<SelectionCellRangeWithItems> removedCellsRangeWithItems;
      List<SelectionCellRangeWithItems> unselectedCellsFromRemove = this.GetUnselectedCellsFromRemove( out removedCellsRangeWithItems );

      SelectedItemsStorage itemsToUnselect = new SelectedItemsStorage( m_itemsToUnselect );
      SelectedCellsStorage cellsToUnselect = new SelectedCellsStorage( m_cellsToUnselect );

      foreach( SelectionRangeWithItems rangeWithItems in unselectedItemsFromRemove )
      {
        itemsToUnselect.Add( rangeWithItems );
      }

      foreach( SelectionCellRangeWithItems cellRangeWithItems in unselectedCellsFromRemove )
      {
        cellsToUnselect.Add( cellRangeWithItems );
      }

      return new SelectionInfo(
        m_owner, itemsToUnselect, new SelectedItemsStorage( m_itemsToSelect ),
        cellsToUnselect, new SelectedCellsStorage( m_cellsToSelect ) );
    }
コード例 #21
0
    public bool UnselectItems( SelectionRangeWithItems rangeWithItems )
    {
      if( !( m_owner.ItemsSourceCollection is DataGridVirtualizingCollectionViewBase ) )
      {
        if( m_toDeferSelect.Count > 0 )
        {
          foreach( object item in rangeWithItems.Items )
          {
            m_toDeferSelect.Remove( item );
          }
        }
      }

      SelectionRange range = rangeWithItems.Range;

      if( range.IsEmpty )
      {
        // We have no index we have to remove based on item
        bool selectionChanged = false;

        List<SelectionRangeWithItems> itemsRangeToRemove = new List<SelectionRangeWithItems>();
        List<object> itemsToUnselect = new List<object>( rangeWithItems.Items );
        int count = itemsToUnselect.Count;

        for( int i = count - 1; i >= 0; i-- )
        {
          object itemToUnselect = itemsToUnselect[ i ];
          bool selectionAdded = false;

          foreach( SelectionRangeWithItems existingSelectionRangeWithItems in m_itemsToSelect )
          {
            int index = Array.IndexOf( existingSelectionRangeWithItems.Items, itemToUnselect );

            if( index > -1 )
            {
              selectionAdded = true;

              itemsRangeToRemove.Add(
                new SelectionRangeWithItems(
                  existingSelectionRangeWithItems.Range.GetIndexFromItemOffset( index ),
                  itemToUnselect ) );
            }
          }

          if( selectionAdded )
          {
            itemsToUnselect.RemoveAt( i );
          }
        }

        // Remove the currently unselected item from the new range to select
        foreach( SelectionRangeWithItems itemRangeToRemove in itemsRangeToRemove )
        {
          selectionChanged |= m_itemsToSelect.Remove( itemRangeToRemove );
        }

        count = itemsToUnselect.Count;

        for( int i = 0; i < count; i++ )
        {
          object itemToUnselect = itemsToUnselect[ i ];

          foreach( SelectionRangeWithItems existingSelectionRangeWithItems in m_owner.SelectedItemsStore )
          {
            int index = Array.IndexOf( existingSelectionRangeWithItems.Items, itemToUnselect );

            if( index > -1 )
            {
              index = existingSelectionRangeWithItems.Range.GetIndexFromItemOffset( index );

              if( !m_itemsToUnselect.Contains( index ) )
              {
                selectionChanged = true;
                m_itemsToUnselect.Add( new SelectionRangeWithItems( index, itemToUnselect ) );
              }
            }
          }
        }

        return selectionChanged;
      }

      if( range.Length == 1 )
      {
        if( !m_itemsToSelect.Remove( rangeWithItems ) )
        {
          if( !m_owner.SelectedItemsStore.Contains( range ) )
            return false;

          if( m_itemsToUnselect.Contains( range ) )
            return false;

          m_itemsToUnselect.Add( rangeWithItems );
        }

        return true;
      }
      else
      {
        SelectedItemsStorage tempStorage = new SelectedItemsStorage( m_owner, 8 );
        tempStorage.Add( rangeWithItems );

        // Remove the currently selected item from the new range to select
        foreach( SelectionRangeWithItems existingSelectionRangeWithItems in m_itemsToSelect )
        {
          if( !range.Intersect( existingSelectionRangeWithItems.Range ).IsEmpty )
          {
            tempStorage.Remove( existingSelectionRangeWithItems );
          }
        }

        bool selectionChanged = m_itemsToSelect.Remove( rangeWithItems );

        if( tempStorage.Count > 0 )
        {
          selectionChanged = true;

          foreach( SelectionRangeWithItems rangeWithItemsToAdd in tempStorage )
          {
            Debug.Assert( !m_itemsToUnselect.Contains( rangeWithItemsToAdd.Range ) );
            m_itemsToUnselect.Add( rangeWithItemsToAdd );
          }
        }

        return selectionChanged;
      }
    }
コード例 #22
0
        public void Visit(DataGridContext sourceContext, ref bool stopVisit)
        {
            object[]       items;
            CollectionView itemsCollection = sourceContext.Items;
            int            count           = itemsCollection.Count;

            if (count == 0)
            {
                return;
            }

            if (sourceContext.ItemsSourceCollection is DataGridVirtualizingCollectionViewBase)
            {
                items = null;
            }
            else
            {
                items = new object[count];

                for (int i = 0; i < count; i++)
                {
                    items[i] = itemsCollection.GetItemAt(i);
                }
            }

            SelectionRange itemRange = new SelectionRange(0, count - 1);

            if (sourceContext.DataGridControl.SelectionUnit == SelectionUnit.Row)
            {
                sourceContext.DataGridControl.SelectionChangerManager.SelectItems(
                    sourceContext,
                    new SelectionRangeWithItems(itemRange, items));
            }
            else
            {
                HashedLinkedList <ColumnBase> columnsByVisiblePosition = sourceContext.ColumnsByVisiblePosition;
                SelectedItemsStorage          selectedColumnStore      = new SelectedItemsStorage(null);
                SelectionRange fullColumnRange = new SelectionRange(0, columnsByVisiblePosition.Count - 1);
                selectedColumnStore.Add(new SelectionRangeWithItems(fullColumnRange, null));
                int index = 0;

                foreach (ColumnBase column in columnsByVisiblePosition)
                {
                    if (!column.Visible)
                    {
                        selectedColumnStore.Remove(new SelectionRangeWithItems(new SelectionRange(index), null));
                    }

                    index++;
                }

                int columnRangeCount = selectedColumnStore.Count;

                for (int i = 0; i < columnRangeCount; i++)
                {
                    sourceContext.DataGridControl.SelectionChangerManager.SelectCells(
                        sourceContext,
                        new SelectionCellRangeWithItems(itemRange, items, selectedColumnStore[i].Range));
                }
            }
        }
コード例 #23
0
 private static RSTree1D <SelectionRangeWithItemsWrapper> .Area GetArea(SelectionRangeWithItems range)
 {
     return(SelectedItemsStorage.GetArea(range.Range));
 }
コード例 #24
0
 public SelectionItemRangeCollection(SelectedItemsStorage list)
 {
     m_list = list;
 }
コード例 #25
0
 internal SelectedItemsStorage( SelectedItemsStorage collection )
 {
   m_dataGridContext = collection.m_dataGridContext;
   m_list = new List<SelectionRangeWithItems>( collection.m_list );
   m_itemsCount = collection.m_itemsCount;
 }
コード例 #26
0
    public bool SelectItems( SelectionRangeWithItems rangeWithItems )
    {
      SelectionRange range = rangeWithItems.Range;

      if( !( m_owner.ItemsSourceCollection is DataGridVirtualizingCollectionViewBase ) )
      {
        if( range.IsEmpty )
        {
          foreach( object item in rangeWithItems.Items )
          {
            if( !m_toDeferSelect.Contains( item ) )
              m_toDeferSelect.Add( item );
          }

          return false;
        }
      }
      else
      {
        if( range.IsEmpty )
          throw new ArgumentException( "rangeWithItems.Range can't be empty when we are using a DataGridVirtualizingCollectionView", "rangeWithItems" );
      }

      if( rangeWithItems.Length == 1 )
      {
        if( !m_itemsToUnselect.Remove( rangeWithItems ) )
        {
          if( m_owner.SelectedItemsStore.Contains( rangeWithItems ) )
            return false;

          if( m_itemsToSelect.Contains( range ) )
            return false;

          this.m_itemsToSelect.Add( rangeWithItems );
        }

        return true;
      }
      else
      {
        bool selectionChanged = m_itemsToUnselect.Remove( rangeWithItems );

        SelectedItemsStorage tempStorage = new SelectedItemsStorage( m_owner, 8 );
        tempStorage.Add( rangeWithItems );

        // Remove the currently selected item from the new range to select
        foreach( SelectionRangeWithItems existingSelectionRangeWithItems in m_owner.SelectedItemsStore )
        {
          tempStorage.Remove( existingSelectionRangeWithItems );
        }

        // Remove the pending item to be selected from the new range to select
        foreach( SelectionRangeWithItems existingSelectionRangeWithItems in m_itemsToSelect )
        {
          tempStorage.Remove( existingSelectionRangeWithItems );
        }

        if( tempStorage.Count > 0 )
        {
          selectionChanged = true;

          foreach( SelectionRangeWithItems rangeWithItemsToAdd in tempStorage )
          {
            m_itemsToSelect.Add( rangeWithItemsToAdd );
          }
        }

        return selectionChanged;
      }
    }
コード例 #27
0
        public bool SelectItems(SelectionRangeWithItems rangeWithItems)
        {
            SelectionRange range = rangeWithItems.Range;

            if (!(m_owner.ItemsSourceCollection is DataGridVirtualizingCollectionViewBase))
            {
                if (range.IsEmpty)
                {
                    foreach (object item in rangeWithItems.Items)
                    {
                        if (!m_toDeferSelect.Contains(item))
                        {
                            m_toDeferSelect.Add(item);
                        }
                    }

                    return(false);
                }
            }
            else
            {
                if (range.IsEmpty)
                {
                    throw new ArgumentException("rangeWithItems.Range can't be empty when we are using a DataGridVirtualizingCollectionView", "rangeWithItems");
                }
            }

            if (rangeWithItems.Length == 1)
            {
                if (!m_itemsToUnselect.Remove(rangeWithItems))
                {
                    if (m_owner.SelectedItemsStore.Contains(rangeWithItems))
                    {
                        return(false);
                    }

                    if (m_itemsToSelect.Contains(range))
                    {
                        return(false);
                    }

                    this.m_itemsToSelect.Add(rangeWithItems);
                }

                return(true);
            }
            else
            {
                bool selectionChanged = m_itemsToUnselect.Remove(rangeWithItems);

                SelectedItemsStorage tempStorage = new SelectedItemsStorage(m_owner);
                tempStorage.Add(rangeWithItems);

                // Remove the currently selected item from the new range to select
                foreach (SelectionRangeWithItems existingSelectionRangeWithItems in m_owner.SelectedItemsStore)
                {
                    tempStorage.Remove(existingSelectionRangeWithItems);
                }

                // Remove the pending item to be selected from the new range to select
                foreach (SelectionRangeWithItems existingSelectionRangeWithItems in m_itemsToSelect)
                {
                    tempStorage.Remove(existingSelectionRangeWithItems);
                }

                if (tempStorage.Count > 0)
                {
                    selectionChanged = true;

                    foreach (SelectionRangeWithItems rangeWithItemsToAdd in tempStorage)
                    {
                        m_itemsToSelect.Add(rangeWithItemsToAdd);
                    }
                }

                return(selectionChanged);
            }
        }
コード例 #28
0
    private void DoRangeSelection(
      DataGridContext oldCurrentDataGridContext,
      object oldCurrentItem,
      int oldCurrentColumnIndex,
      DataGridContext dataGridContext,
      int sourceDataItemIndex,
      object item,
      int columnIndex,
      bool keepPreviousSelection,
      bool fromRowSelector )
    {
      if( item == null )
        return;

      IDataGridContextVisitable visitable = ( IDataGridContextVisitable )m_owner.DataGridContext;

      if( m_rangeSelectionItemStartAnchor == -1 )
      {
        if( ( oldCurrentDataGridContext != null ) && ( oldCurrentItem != null ) )
        {
          m_rangeSelectionItemStartAnchor = m_owner.GetGlobalGeneratorIndexFromItem( oldCurrentDataGridContext, oldCurrentItem );
          m_rangeSelectionColumnStartAnchor = oldCurrentColumnIndex;
        }
        else
        {
          m_rangeSelectionItemStartAnchor = m_owner.GetGlobalGeneratorIndexFromItem( dataGridContext, item );
          m_rangeSelectionColumnStartAnchor = columnIndex;
        }
      }

      if( !keepPreviousSelection )
      {
        this.UnselectAll();
      }

      int starting_index = m_rangeSelectionItemStartAnchor;
      int ending_index = m_owner.GetGlobalGeneratorIndexFromItem( dataGridContext, item );

      int min = Math.Min( starting_index, ending_index );
      int max = Math.Max( starting_index, ending_index );

      // here I need to normalize the values to ensure that I'm not catching the Fixed Headers or Fixed Footers
      if( ( min != -1 ) && ( max != -1 ) )
      {
        SelectionRange[] selectedColumns;

        if( m_owner.SelectionUnit == SelectionUnit.Row )
        {
          selectedColumns = null;
        }
        else
        {
          SelectionRange fullColumnRange;

          // If called from a RowSelector, we do a range
          // selection using all the columns no matter
          // what was the previous anchor
          if( fromRowSelector )
          {
            m_rangeSelectionColumnStartAnchor = 0;
            fullColumnRange = new SelectionRange( 0, Math.Max( 0, dataGridContext.ColumnsByVisiblePosition.Count - 1 ) );
          }
          else
          {
            if( m_rangeSelectionColumnStartAnchor == -1 )
              m_rangeSelectionColumnStartAnchor = 0;

            if( columnIndex == -1 )
              return;

            fullColumnRange = new SelectionRange( m_rangeSelectionColumnStartAnchor, columnIndex );
          }

          SelectedItemsStorage selectedColumnStore = new SelectedItemsStorage( null, 8 );
          selectedColumnStore.Add( new SelectionRangeWithItems( fullColumnRange, null ) );
          int index = 0;

          foreach( ColumnBase column in dataGridContext.ColumnsByVisiblePosition )
          {
            if( !column.Visible )
            {
              selectedColumnStore.Remove( new SelectionRangeWithItems( new SelectionRange( index ), null ) );
            }

            index++;
          }

          selectedColumns = selectedColumnStore.ToSelectionRangeArray();
        }

        bool visitWasStopped;

        visitable.AcceptVisitor(
          min, max,
          new RangeSelectionVisitor( selectedColumns ),
          DataGridContextVisitorType.ItemsBlock, out visitWasStopped );
      }
    }
コード例 #29
0
 public bool Contains(SelectionRange range)
 {
     return(m_map.Overlaps(SelectedItemsStorage.GetArea(range)));
 }
コード例 #30
0
        public void UpdateSelectionAfterSourceDataItemReplaced(NotifyCollectionChangedEventArgs e)
        {
            Debug.Assert(e.OldItems.Count == e.NewItems.Count);
            Debug.Assert(e.OldStartingIndex == e.NewStartingIndex);

            SelectedItemsStorage selectedItemsStorage = m_owner.SelectedItemsStore;
            SelectedCellsStorage selectedCellsStorage = m_owner.SelectedCellsStore;
            int   oldItemIndex      = e.OldStartingIndex;
            IList oldItems          = e.OldItems;
            IList newItems          = e.NewItems;
            int   replacedItemCount = oldItems.Count;
            int   cellRangeCount    = selectedCellsStorage.Count;

            if (oldItemIndex >= 0)
            {
                int itemIndex = oldItemIndex;

                for (int i = 0; i < replacedItemCount; i++)
                {
                    object newItem = newItems[i];

                    if (selectedItemsStorage.Contains(itemIndex))
                    {
                        this.UnselectItems(new SelectionRangeWithItems(itemIndex, oldItems[i]));
                        this.SelectItems(new SelectionRangeWithItems(itemIndex, newItem));
                    }

                    SelectionCellRange replacedCellRange = new SelectionCellRange(
                        new SelectionRange(itemIndex), new SelectionRange(0, int.MaxValue - 1));

                    for (int j = 0; j < cellRangeCount; j++)
                    {
                        SelectionCellRangeWithItems cellRangeWithItems = selectedCellsStorage[j];
                        SelectionCellRange          cellRange          = cellRangeWithItems.CellRange;

                        if (!cellRange.Intersect(replacedCellRange).IsEmpty)
                        {
                            object[] items = cellRangeWithItems.ItemRangeWithItems.Items;

                            if (items != null)
                            {
                                items[cellRange.ItemRange.GetOffsetFromItemIndex(itemIndex)] = newItem;
                            }
                        }
                    }

                    itemIndex++;
                }
            }
            else
            {
                CollectionView sourceItems = m_owner.Items;

                for (int i = 0; i < replacedItemCount; i++)
                {
                    object newItem   = newItems[i];
                    int    itemIndex = sourceItems.IndexOf(newItem);

                    if (itemIndex < 0)
                    {
                        continue;
                    }

                    if (selectedItemsStorage.Contains(itemIndex))
                    {
                        this.UnselectItems(new SelectionRangeWithItems(itemIndex, oldItems[i]));
                        this.SelectItems(new SelectionRangeWithItems(itemIndex, newItem));
                    }

                    SelectionCellRange replacedCellRange = new SelectionCellRange(
                        new SelectionRange(itemIndex), new SelectionRange(0, int.MaxValue - 1));

                    for (int j = 0; j < cellRangeCount; j++)
                    {
                        SelectionCellRangeWithItems cellRangeWithItems = selectedCellsStorage[j];
                        SelectionCellRange          cellRange          = cellRangeWithItems.CellRange;

                        if (!cellRange.Intersect(replacedCellRange).IsEmpty)
                        {
                            object[] items = cellRangeWithItems.ItemRangeWithItems.Items;

                            if (items != null)
                            {
                                items[cellRange.ItemRange.GetOffsetFromItemIndex(itemIndex)] = newItem;
                            }
                        }
                    }
                }
            }
        }
コード例 #31
0
        internal SelectionItemRangeCollection(SelectedItemsStorage collection)
        {
            Debug.Assert(collection != null);

            m_storage = collection;
        }