Example #1
0
    internal Group( GroupGeneratorNode node, CollectionViewGroup group, IList<GroupLevelDescription> groupLevelDescriptions, DataGridContext dataGridContext )
    {
      if( node == null )
        throw new ArgumentNullException( "node" );

      if( group == null )
        throw new ArgumentNullException( "group" );

      if( groupLevelDescriptions == null )
        throw new ArgumentNullException( "groupLevelDescriptions" );

      if( dataGridContext == null )
        throw new ArgumentNullException( "dataGridContext" );

      m_generatorNode = node;
      m_collectionViewGroup = group;
      m_groupDescriptionsCollection = groupLevelDescriptions;
      m_dataGridContext = dataGridContext;

      //In case no late bingding is to happen, and if we already have everything to get the groupLevelDescription immediately, let's do!
      int level = m_generatorNode.Level;
      if( m_groupDescriptionsCollection.Count > level )
      {
        m_groupLevelDescription = m_groupDescriptionsCollection[ level ];
      }
      m_lateGroupLevelDescriptionBindingPerformed = false;

      m_generatorNode.TotalLeafCountChanged += OnTotalItemCountChanged;
      m_generatorNode.IsExpandedChanged += OnIsExpandedChanged;
    }
    public ColumnStretchingManager( DataGridContext dataGridContext )
    {
      if( dataGridContext == null )
        throw new ArgumentNullException( "dataGridContext" );

      m_dataGridContext = dataGridContext;
    }
    public static bool HasGroup( DataGridContext dataGridContext )
    {
      if( dataGridContext.GroupLevelDescriptions.Count > 0 )
        return true;

      return GroupingHelper.HasGroup( dataGridContext.DetailConfigurations );
    }
    internal static int GetNextVisibleFocusableColumnIndex( DataGridContext dataGridContext, Row targetRow, ColumnBase targetColumn )
    {
      if( ( dataGridContext == null ) || ( targetRow == null ) || ( targetColumn == null ) )
        return -1;

      var columns = dataGridContext.VisibleColumns;
      if( ( columns == null ) || ( columns.Count <= 0 ) )
        return -1;

      var columnIndex = columns.IndexOf( targetColumn );
      if( columnIndex < 0 )
        return -1;

      if( !dataGridContext.IsAFlattenDetail )
        return NavigationHelper.GetNextVisibleFocusableColumnIndex( dataGridContext, targetRow, columnIndex + 1 );

      var columnMap = dataGridContext.ItemPropertyMap;
      var masterColumnName = default( string );

      if( !columnMap.TryGetColumnFieldName( targetColumn, out masterColumnName ) )
        return -1;

      var masterDataGridContext = dataGridContext.RootDataGridContext;
      var masterColumn = masterDataGridContext.Columns[ masterColumnName ];

      if( masterColumn == null )
        return -1;

      var masterColumnIndex = masterDataGridContext.VisibleColumns.IndexOf( masterColumn );
      if( masterColumnIndex < 0 )
        return -1;

      return NavigationHelper.GetNextVisibleFocusableDetailColumnIndexFromMasterColumnIndex( dataGridContext, targetRow, masterColumnIndex + 1 );
    }
    internal static CustomItemContainerGenerator CreateGenerator( DataGridControl parentGridControl, CollectionView collectionView, DataGridContext dataGridContext )
    {
      CustomItemContainerGenerator newGenerator = new CustomItemContainerGenerator( collectionView, dataGridContext, parentGridControl );
      dataGridContext.SetGenerator( newGenerator );

      return newGenerator;
    }
    internal static int GetLastVisibleFocusableColumnIndex( DataGridContext dataGridContext )
    {
      if( dataGridContext == null )
        return -1;

      return NavigationHelper.GetLastVisibleFocusableColumnIndex( dataGridContext, dataGridContext.CurrentRow );
    }
    internal DataGridContextAutomationPeer(
      DataGridControl dataGridControl,
      DataGridContext parentDataGridContext,
      object parentItem,
      DetailConfiguration detailConfiguration )
    {
      if( dataGridControl == null )
        throw new ArgumentNullException( "dataGridControl" );

      if( parentDataGridContext == null )
      {
        m_dataGridContext = dataGridControl.DataGridContext;
      }
      else
      {
        m_dataGridContext = parentDataGridContext.GetChildContext( parentItem, detailConfiguration );
      }

      if( m_dataGridContext != null )
        m_dataGridContext.Peer = this;

      m_dataGridControl = dataGridControl;
      m_parentDataGridContext = parentDataGridContext;
      m_parentItem = parentItem;
      m_detailConfiguration = detailConfiguration;

      m_dataChildren = new Hashtable( 0 );
      m_headerFooterChildren = new Hashtable( 0 );
    }
    internal Group(
      GroupGeneratorNode node,
      CollectionViewGroup group,
      LateGroupLevelDescription groupLevelDescription,
      DataGridContext dataGridContext )
    {
      if( node == null )
        throw new ArgumentNullException( "node" );

      if( group == null )
        throw new ArgumentNullException( "group" );

      if( groupLevelDescription == null )
        throw new ArgumentNullException( "groupLevelDescription" );

      if( dataGridContext == null )
        throw new ArgumentNullException( "dataGridContext" );

      m_collectionViewGroup = group;

      // Initialization is done through setters to register for events.
      this.DataGridContext = dataGridContext;
      this.GeneratorNode = node;
      this.GroupLevelDescription = groupLevelDescription;
    }
    public void Visit( DataGridContext sourceContext, int sourceDataItemIndex, object item, ref bool stopVisit )
    {
      if( !m_isTableFlowView )
      {
        m_item = item;
        m_parentDataGridContext = sourceContext;
        m_success = true;
        stopVisit = true;
        return;
      }

      UIElement dataRow = sourceContext.CustomItemContainerGenerator.ContainerFromItem( item ) as UIElement;

      if( dataRow != null )
      {
        if( !ScrollTip.IsItemInView( dataRow, sourceContext.DataGridControl.ItemsHost ) )
        {
          stopVisit = true;
        }
        else if( !ScrollTip.IsDataItemHiddenBySticky( sourceContext, item ) )
        {
          m_item = item;
          m_parentDataGridContext = sourceContext;
          m_success = true;
          stopVisit = true;
        }
      }
    }
Example #10
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 ) );
        }
      }
    }
Example #11
0
        protected override void StartDataItem( DataGridContext dataGridContext, object dataItem )
        {
            if (!string.IsNullOrEmpty(_indentationString))
                WriteToBaseStream(_indentationString);

            // The next StartDataItemField will be considered as first column
            _isFirstColumn = true;
        }
    internal void Prepare( DataGridContext dataGridContext, object dataItem )
    {
      m_containersPrepared = true;
      m_dataGridContext = dataGridContext;
      m_dataItem = dataItem;

      this.Update();
    }
 internal DataGridCurrentChangedEventArgs( DataGridContext oldDataGridContext, object oldCurrent, DataGridContext newDataGridContext, object newCurrent )
   : base( DataGridControl.CurrentChangedEvent )
 {
   this.OldDataGridContext = oldDataGridContext;
   this.OldCurrent = oldCurrent;
   this.NewDataGridContext = newDataGridContext;
   this.NewCurrent = newCurrent;
 }
 internal DataGridCurrentChangingEventArgs( DataGridContext oldDataGridContext, object oldCurrent, DataGridContext newDataGridContext, object newCurrent, bool isCancelable )
   : base( DataGridControl.CurrentChangingEvent )
 {
   this.IsCancelable = isCancelable;
   this.OldDataGridContext = oldDataGridContext;
   this.OldCurrent = oldCurrent;
   this.NewDataGridContext = newDataGridContext;
   this.NewCurrent = newCurrent;
 }
    public void Visit( DataGridContext sourceContext, int startSourceDataItemIndex, int endSourceDataItemIndex, ref bool stopVisit )
    {
      SelectionManager selectionChangerManager = sourceContext.DataGridControl.SelectionChangerManager;

      if( m_selectedColumns != null )
      {
        int columnCount = sourceContext.Columns.Count;

        if( columnCount == 0 )
          return;

        SelectionRange contextColumnMaxRange = new SelectionRange( 0, columnCount - 1 );

        for( int i = 0; i < m_selectedColumns.Length; i++ )
        {
          SelectionRange selectionRange = m_selectedColumns[ i ];
          SelectionRange intersectionSelectionRange = selectionRange.Intersect( contextColumnMaxRange );

          if( intersectionSelectionRange.IsEmpty )
            continue;

#if DEBUG
          string action = ( m_unselect ) ? "Removing" : "Adding";
          Debug.WriteLine( "Selection : " + action + " cell : (" + startSourceDataItemIndex.ToString() + " - " + endSourceDataItemIndex.ToString() + ") - ("
             + intersectionSelectionRange.StartIndex.ToString() + " - " + intersectionSelectionRange.EndIndex.ToString() + ")" );
#endif

          var cellRange = new SelectionCellRangeWithItems( new SelectionRange( startSourceDataItemIndex, endSourceDataItemIndex ), null, intersectionSelectionRange );

          if( m_unselect )
          {
            selectionChangerManager.UnselectCells( sourceContext, cellRange );
          }
          else
          {
            selectionChangerManager.SelectCells( sourceContext, cellRange );
          }
        }
      }
      else
      {
#if DEBUG
        string action = ( m_unselect ) ? "Removing" : "Adding";
        Debug.WriteLine( "Selection : " + action + " Adding item : " + startSourceDataItemIndex.ToString() + " - " + endSourceDataItemIndex.ToString() );
#endif
        var itemRange = new SelectionRangeWithItems( new SelectionRange( startSourceDataItemIndex, endSourceDataItemIndex ), null );

        if( m_unselect )
        {
          selectionChangerManager.UnselectItems( sourceContext, itemRange );
        }
        else
        {
          selectionChangerManager.SelectItems( sourceContext, itemRange );
        }
      }
    }
    internal static int GetLastVisibleFocusableColumnIndex( DataGridContext dataGridContext, Row targetRow )
    {
      if( dataGridContext == null )
        return -1;

      if( dataGridContext.IsAFlattenDetail )
        return NavigationHelper.GetPreviousVisibleFocusableDetailColumnIndexFromMasterColumnIndex( dataGridContext, targetRow, int.MaxValue );

      return NavigationHelper.GetPreviousVisibleFocusableColumnIndex( dataGridContext, targetRow, int.MaxValue );
    }
Example #17
0
 public override void EndInit()
 {
     base.EndInit();
     _context = DataGridControl.GetDataGridContext(this);
     _context.DataGridControl.Columns.CollectionChanged += Columns_CollectionChanged;
     AddColumns(_context.DataGridControl.Columns);
     ObservableCollection<MergedHeader> mergedHeaders = DataGridControlBehaviors.GetMergedHeaders(_context.DataGridControl);
     mergedHeaders.CollectionChanged += mergedHeaders_CollectionChanged;
     AddMergedHeaders(mergedHeaders);
 }
Example #18
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 );
 }
Example #19
0
        protected override void StartDataItemField(DataGridContext dataGridContext, Column column, object fieldValue)
        {
            // We always insert the separator before the value except for the first item
            if( !_isFirstColumn )
                WriteToBaseStream(FormatSettings.Separator);
            else
                _isFirstColumn = false;

            string fieldValueString = FormatCsvData(null, fieldValue);
            WriteToBaseStream(fieldValueString);
        }
    public void Visit( DataGridContext sourceContext, System.Windows.Data.CollectionViewGroup group, object[] namesTree, int groupLevel, bool isExpanded, bool isComputedExpanded, ref bool stopVisit )
    {
      if( this.Group == null )
      {
        GroupNamesTreeKey currentGroupKey = new GroupNamesTreeKey( namesTree );

        if( currentGroupKey.Equals( m_groupNamesTreeKey ) == true )
          this.Group = group;

      }
    }
    public DataGridItemAutomationPeer( object item, DataGridContext dataGridContext, int index )
    {
      // if index = -1, it will be calculated later calling indexof on dataGridContext.Items.

      if( dataGridContext == null )
        throw new ArgumentNullException( "dataGridContext" );

      m_item = item;
      m_dataGridContext = dataGridContext;
      m_index = index;
      m_dataChildren = new Hashtable( 0 );
    }
    public DetailGeneratorNode( DataGridContext context, CustomItemContainerGenerator generator )
      : base( null )
    {
      if( generator == null )
        throw new ArgumentNullException( "generator" );

      if( context == null )
        throw new ArgumentNullException( "context" );

      m_generator = generator;
      m_context = context;
      m_itemCount = generator.ItemCount;
    }
    public HeaderFooterItemAutomationPeer( DataGridContext dataGridContext, object owner )
    {
      if( dataGridContext == null )
        throw new ArgumentNullException( "dataGridContext" );

      if( owner == null )
        throw new ArgumentNullException( "owner" );

      Debug.Assert( ( owner is GroupHeaderFooterItem ) || ( owner is DataTemplate ) || ( owner is HeaderFooterItem ) );

      m_owner = owner;
      m_dataGridContext = dataGridContext;
    }
    internal DetailConfiguration( DataGridContext synchronizedParent )
      : this( true )
    {
      m_shouldCreateColumns = false;

      this.SetColumns( synchronizedParent.Columns );
      this.SetVisibleColumns( synchronizedParent.VisibleColumns );
      m_columnsByVisiblePosition = synchronizedParent.ColumnsByVisiblePosition;

      m_sortDescriptions = synchronizedParent.Items.SortDescriptions;
      m_groupDescriptions = synchronizedParent.Items.GroupDescriptions;

      this.SetGroupLevelDescriptions( synchronizedParent.GroupLevelDescriptions );
    }
    public ColumnVirtualizationManager( DataGridContext dataGridContext )
    {
      Debug.Assert( dataGridContext != null );
      m_dataGridContext = dataGridContext;

      // Assign the ColumnVirtualizationManager to the DataGridContext
      ColumnVirtualizationManager.SetColumnVirtualizationManager( m_dataGridContext, this );

      this.Initialize();

      unchecked
      {
        m_version++;
      }
    }
 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 ) );
 }
Example #27
0
    public CurrencyManager( DataGridContext dataGridContext, CollectionView collectionView )
    {
      if( dataGridContext == null )
        throw new ArgumentNullException( "dataGridContext" );

      if( collectionView == null )
        throw new ArgumentNullException( "collectionView" );

      m_dataGridContext = dataGridContext;
      m_collectionView = collectionView;

      System.Diagnostics.Debug.Assert( m_dataGridContext.CurrentItem == m_collectionView.CurrentItem );

      this.RegisterListeners();
    }
        public static IEnumerable <ColumnBase> EnumerateColumns(this DataGridContext gridContext, SelectionRange columnRange)
        {
            var startIndex = Math.Min(columnRange.StartIndex, columnRange.EndIndex);
            var endIndex   = Math.Max(columnRange.StartIndex, columnRange.EndIndex);

            for (var i = startIndex; i <= endIndex; i++)
            {
                foreach (var column in gridContext.Columns)
                {
                    if (column.VisiblePosition == i)
                    {
                        yield return(column);
                    }
                }
            }
        }
        public static void SelectItem(this DataGridContext gridContext, object item)
        {
            var gridControl = gridContext.DataGridControl;

            if (gridControl.SelectionUnit == SelectionUnit.Row)
            {
            }
            else
            {
                gridContext.SelectedCellRanges.Clear();
                var index       = gridContext.Items.IndexOf(item);
                var columnCount = gridContext.VisibleColumns.Count;
                var range       = new SelectionCellRange(new SelectionRange(index), new SelectionRange(0, columnCount - 1));
                gridContext.SelectedCellRanges.Add(range);
            }
        }
        public static ModernDataCell GetCurrentCell(this DataGridContext gridContext)
        {
            if (gridContext.CurrentItem == null || gridContext.CurrentColumn == null)
            {
                return(null);
            }

            var row = gridContext.GetContainerFromItem(gridContext.CurrentItem) as ModernDataRow;

            if (row == null)
            {
                return(null);
            }

            return(row.Cells[gridContext.CurrentColumn] as ModernDataCell);
        }
    private void RecursiveSaveDataGridContextsState( DataGridContext dataGridContext )
    {
      SaveRestoreDataGridContextStateVisitor saveRestoreDataGridContextStateVisitor
        = new SaveRestoreDataGridContextStateVisitor( true, int.MaxValue, m_stopAtFirstCollapsedGroup );

      saveRestoreDataGridContextStateVisitor.SaveState( dataGridContext as IDataGridContextVisitable );

      m_dataGridContextsStateDictionary.Add( new WeakDataGridContextKey( dataGridContext ), saveRestoreDataGridContextStateVisitor );

      IEnumerable<DataGridContext> subDataGridContexts = dataGridContext.GetChildContexts();

      foreach( DataGridContext subDataGridContext in subDataGridContexts )
      {
        this.RecursiveSaveDataGridContextsState( subDataGridContext );
      }
    }
Example #32
0
        public static SelectionRangePoint TryCreateFromCurrent(DataGridContext dataGridContext)
        {
            if (dataGridContext == null)
            {
                return(null);
            }

            var column      = dataGridContext.CurrentColumn;
            int columnIndex = (column != null) ? column.VisiblePosition : -1;

            var oldPosition = SelectionRangePoint.TryCreateRangePoint(
                dataGridContext, dataGridContext.CurrentItem,
                dataGridContext.CurrentItemIndex, columnIndex);

            return(oldPosition);
        }
        private void UpdateContentTemplate()
        {
            Column mainColumn = this.MainColumn as Column;

            if (mainColumn == null)
            {
                return;
            }

            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            UIViewBase uiViewBase = null;

            if (dataGridContext != null)
            {
                DataGridControl dataGridControl = dataGridContext.DataGridControl;

                if (dataGridControl != null)
                {
                    uiViewBase = dataGridControl.GetView() as UIViewBase;
                }
            }

            if (uiViewBase != null)
            {
                if (uiViewBase.ScrollTipContentTemplate != null)
                {
                    this.ContentTemplate = uiViewBase.ScrollTipContentTemplate;
                }
                else
                {
                    this.ContentTemplateSelector = uiViewBase.ScrollTipContentTemplateSelector;
                }
            }

            if ((this.ContentTemplate == null) && (this.ContentTemplateSelector == null))
            {
                if (mainColumn.CellContentTemplate != null)
                {
                    this.ContentTemplate = mainColumn.CellContentTemplate;
                }
                else
                {
                    this.ContentTemplateSelector = mainColumn.CellContentTemplateSelector;
                }
            }
        }
            // Parse all the expanded details recursively
            private void GetVisiblePositionsForContextDetailLevel(
                DataGridContext dataGridContext,
                int desiredDetailLevel,
                HashSet <int> exportedColumnPositions)
            {
                int dataGridContextDetailLevel = dataGridContext.DetailLevel;

                // The detail level is too deep, return immediately
                if (dataGridContextDetailLevel > desiredDetailLevel)
                {
                    return;
                }

                // The desired detail level is reached get the exportedColumnPositions
                if (dataGridContextDetailLevel == desiredDetailLevel)
                {
                    DataGridContext parentDataGridContext = dataGridContext.ParentDataGridContext;

                    if (parentDataGridContext == null)
                    {
                        this.GetVisibleColumnsVisiblePositionForDataGridContext(dataGridContext,
                                                                                exportedColumnPositions);
                    }
                    else
                    {
                        foreach (DataGridContext childContext in parentDataGridContext.GetChildContexts())
                        {
                            if (this.GetVisibleColumnsVisiblePositionForDataGridContext(childContext,
                                                                                        exportedColumnPositions))
                            {
                                // All columns need to be exported, stop parsing child DataGridContexts
                                break;
                            }
                        }
                    }
                }
                else
                {
                    // The detail level differs, parse the child contexts recursively
                    foreach (DataGridContext childContext in dataGridContext.GetChildContexts())
                    {
                        this.GetVisiblePositionsForContextDetailLevel(childContext,
                                                                      desiredDetailLevel,
                                                                      exportedColumnPositions);
                    }
                }
            }
        internal bool CanDoSort()
        {
            ColumnManagerRow parentRow = this.ParentRow as ColumnManagerRow;

            if (parentRow != null)
            {
                if (!parentRow.AllowSort)
                {
                    return(false);
                }
            }

            DataGridContext dataGridContext = this.DataGridContext;

            if (dataGridContext == null)
            {
                return(false);
            }

            // When details are flatten, only the ColumnManagerCell at the master level may do the sort.
            if (dataGridContext.IsAFlattenDetail)
            {
                return(false);
            }

            if (dataGridContext.SourceDetailConfiguration == null)
            {
                if (!dataGridContext.Items.CanSort)
                {
                    return(false);
                }
            }

            if (!this.IsEnabled)
            {
                return(false);
            }

            ColumnBase parentColumn = this.ParentColumn;

            if ((parentColumn == null) || (!parentColumn.AllowSort))
            {
                return(false);
            }

            return(true);
        }
Example #36
0
            private HashSet <int> GetIntersectedRangesForIndex(DataGridContext dataGridContext, int itemIndex, int[] exportedVisiblePositions, int correctedExportedVisiblePositionsCount)
            {
                HashSet <int> intersectedIndexes = null;

                if (correctedExportedVisiblePositionsCount == 0)
                {
                    return(intersectedIndexes);
                }

                SelectionItemRangeCollection selectedRanges = dataGridContext.SelectedItemRanges as SelectionItemRangeCollection;

                if (selectedRanges.Contains(itemIndex))
                {
                    intersectedIndexes = new HashSet <int>(exportedVisiblePositions);
                }
                else
                {
                    intersectedIndexes = new HashSet <int>();

                    SelectionCellRange columnsRange = new SelectionCellRange(itemIndex, exportedVisiblePositions[0], itemIndex,
                                                                             exportedVisiblePositions[correctedExportedVisiblePositionsCount - 1]);

                    IEnumerable <SelectionRange> intersectedRanges = dataGridContext.SelectedCellsStore.GetIntersectedColumnRanges(columnsRange);

                    foreach (SelectionRange range in intersectedRanges)
                    {
                        int startIndex = range.StartIndex;
                        int endIndex   = range.EndIndex;

                        if (startIndex > endIndex)
                        {
                            startIndex = range.EndIndex;
                            endIndex   = range.StartIndex;
                        }

                        for (int i = startIndex; i <= endIndex; i++)
                        {
                            if (!intersectedIndexes.Contains(i))
                            {
                                intersectedIndexes.Add(i);
                            }
                        }
                    }
                }

                return(intersectedIndexes);
            }
        protected override void StartHeaderField(DataGridContext dataGridContext, Column column)
        {
            // We always insert the separator before the value except for the first item
            if (!m_isFirstColumn)
            {
                this.WriteToBaseStream(this.FormatSettings.Separator);
            }
            else
            {
                m_isFirstColumn = false;
            }

            object columnHeader     = ((this.UseFieldNamesInHeader) || (column.Title == null)) ? column.FieldName : column.Title;
            string fieldValueString = UnicodeCsvClipboardExporter.FormatCsvData(null, columnHeader, this.FormatSettings);

            this.WriteToBaseStream(fieldValueString);
        }
Example #38
0
        public static IEnumerable <DiffItemInfo> GetVisibleItems(DataGridContext gridContext)
        {
            foreach (var item in gridContext.Headers)
            {
                yield return(new DiffItemInfo(gridContext, item));
            }

            foreach (var item in gridContext.Items)
            {
                yield return(new DiffItemInfo(gridContext, item));
            }

            foreach (var item in gridContext.Footers)
            {
                yield return(new DiffItemInfo(gridContext, item));
            }
        }
        public void CopyTo(object[] array, int arrayIndex)
        {
            DataGridContext dataGridContext = m_list.DataGridContext;
            int             count           = m_list.Count;

            for (int i = 0; i < count; i++)
            {
                SelectionRangeWithItems rangeWithItems = m_list[i];
                int rangeLength = rangeWithItems.Length;

                for (int j = 0; j < rangeLength; j++)
                {
                    array[arrayIndex] = rangeWithItems.GetItem(dataGridContext, j);
                    arrayIndex++;
                }
            }
        }
        void ICollection.CopyTo(Array array, int arrayIndex)
        {
            DataGridContext dataGridContext = m_list.DataGridContext;
            int             count           = m_list.Count;

            for (int i = 0; i < count; i++)
            {
                SelectionRangeWithItems rangeWithItems = m_list[i];
                int rangeLength = rangeWithItems.Length;

                for (int j = 0; j < rangeLength; j++)
                {
                    array.SetValue(rangeWithItems.GetItem(dataGridContext, j), arrayIndex);
                    arrayIndex++;
                }
            }
        }
        public HeaderFooterItemAutomationPeer(DataGridContext dataGridContext, object owner)
        {
            if (dataGridContext == null)
            {
                throw new ArgumentNullException("dataGridContext");
            }

            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }

            Debug.Assert((owner is GroupHeaderFooterItem) || (owner is DataTemplate) || (owner is HeaderFooterItem));

            m_owner           = owner;
            m_dataGridContext = dataGridContext;
        }
Example #42
0
    internal static bool IsDataItemHiddenBySticky( DataGridContext dataGridContext, object tempValue )
    {
      // We only want to do special handling for a TableflowItemsHost.
      TableflowViewItemsHost itemsHost = dataGridContext.DataGridControl.ItemsHost as TableflowViewItemsHost;

      if( itemsHost == null )
        return false;

      int index = dataGridContext.CustomItemContainerGenerator.FindIndexForItem( tempValue, dataGridContext );

      if( index > -1 )
      {
        return itemsHost.IsDataItemHiddenBySticky( index );
      }

      return false;
    }
Example #43
0
        private static void TestMinimapItem(object item, DataGridContext gridContext, List <DiffMinimapItemInfo> itemInfoList, ref DiffMinimapItemInfo itemInfo)
        {
            var rowState = GetDiffState(item);

            if (rowState != itemInfo.DiffState || itemInfo.GridContext != gridContext)
            {
                if (itemInfo.Count != 0)
                {
                    itemInfoList.Add(itemInfo);
                    itemInfo = new DiffMinimapItemInfo();
                }
            }

            itemInfo.GridContext = gridContext;
            itemInfo.DiffState   = rowState;
            itemInfo.Count++;
        }
            private void ExportDetailForMasterIndex(
                DataGridContext dataGridContext,
                int detailLevel,
                int masterIndexForDetail)
            {
                object item = dataGridContext.Items.GetItemAt(masterIndexForDetail);

                IEnumerable <DataGridContext> dataGridContexts =
                    dataGridContext.CustomItemContainerGenerator.GetChildContextsForMasterItem(item);

                foreach (DataGridContext childContext in dataGridContexts)
                {
                    this.Export(childContext);
                }

                this.UpdateExporterIndentation(detailLevel);
            }
        public static IEnumerable <object> GetScrollableItems(this DataGridContext gridContext)
        {
            foreach (var item in gridContext.Headers)
            {
                yield return(item);
            }

            foreach (var item in gridContext.Items)
            {
                yield return(item);
            }

            foreach (var item in gridContext.Footers)
            {
                yield return(item);
            }
        }
Example #46
0
        public DetailGeneratorNode(DataGridContext context, CustomItemContainerGenerator generator)
            : base(null)
        {
            if (generator == null)
            {
                throw new ArgumentNullException("generator");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            m_generator = generator;
            m_context   = context;
            m_itemCount = generator.ItemCount;
        }
        public ColumnSortDirectionChangingEventArgs(RoutedEvent routedEvent, ColumnBase column, DataGridContext dataGridContext, SortDirection currentSortDirection, SortDirection nextSortDirection)
            : base(routedEvent, column)
        {
            if (column == null)
            {
                throw new ArgumentNullException("column");
            }

            if (dataGridContext == null)
            {
                throw new ArgumentNullException("dataGridContext");
            }

            m_dataGridContext = dataGridContext;
            m_current         = currentSortDirection;
            m_next            = nextSortDirection;
        }
Example #48
0
        protected async override void PrepareContainer(DataGridContext dataGridContext, object item)
        {
            base.PrepareContainer(dataGridContext, item);
            var gridControl = dataGridContext.DataGridControl as DomainDataGridControl;

            if (this.domain == null)
            {
                var domain = gridControl.Domain;
                if (domain != null)
                {
                    await domain.Dispatcher.InvokeAsync(() =>
                    {
                        this.domain = domain;
                        this.domain.MemberLocationChanged += Domain_MemberLocationChanged;
                        this.domain.MemberEditBegun       += Domain_MemberEditBegun;
                        this.domain.MemberEditEnded       += Domain_MemberEditEnded;
                        this.domain.MemberRemoved         += Domain_MemberRemoved;
                        this.domain.Deleted += Domain_Deleted;
                        // if (this.domain.GetService(typeof(ICremaHost)) is ICremaHost cremaHost)
                        // {
                        //     this.UserID = cremaHost.UserID;
                        // }
                    });
                }
            }

            this.UserInfos.Clear();

            if (this.domain != null)
            {
                var domain = this.domain;
                var infos  = await domain.Dispatcher.InvokeAsync(() => domain.Members.Select(i => new DomainMemberMetaData()
                {
                    DomainMemberInfo = i.DomainMemberInfo,
                    DomainMemberState = i.DomainMemberState,
                }).ToArray());

                foreach (var i in infos)
                {
                    if (HashUtility.Equals(this.keys, i.DomainLocationInfo.Keys) == true && this.tableName == i.DomainLocationInfo.TableName)
                    {
                        this.UserInfos.Set(i.DomainMemberInfo, i.DomainMemberState, i.DomainLocationInfo);
                    }
                }
            }
        }
Example #49
0
        public SelectionRangePoint(DataGridContext dataGridContext, object item, int itemIndex, int columnPosition)
        {
            if (dataGridContext == null)
            {
                throw new ArgumentNullException();
            }

            if (item == null)
            {
                throw new ArgumentNullException();
            }

            m_localIndex         = itemIndex;
            this.Item            = item;
            this.ColumnIndex     = columnPosition;
            this.DataGridContext = dataGridContext;
        }
Example #50
0
        private void ShowDropMark(Point mousePosition, DropMarkAlignment defaultAlignment, bool forceDefaultAlignment)
        {
            if (m_dropMarkAdorner == null)
            {
                DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

                DataGridControl grid = (dataGridContext != null)
          ? dataGridContext.DataGridControl
          : null;

                Pen pen = UIViewBase.GetDropMarkPen(this);

                if ((pen == null) && (grid != null))
                {
                    UIViewBase uiViewBase = grid.GetView() as UIViewBase;
                    pen = uiViewBase.DefaultDropMarkPen;
                }

                DropMarkOrientation orientation = Nequeo.Wpf.DataGrid.Views.UIViewBase.GetDropMarkOrientation(this);

                if ((orientation == DropMarkOrientation.Default) && (grid != null))
                {
                    UIViewBase uiViewBase = grid.GetView() as UIViewBase;

                    orientation = uiViewBase.DefaultDropMarkOrientation;
                }

                m_dropMarkAdorner = new DropMarkAdorner(this, pen, orientation);

                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);

                if (adornerLayer != null)
                {
                    adornerLayer.Add(m_dropMarkAdorner);
                }
            }

            if (forceDefaultAlignment)
            {
                m_dropMarkAdorner.ForceAlignment(defaultAlignment);
            }
            else
            {
                m_dropMarkAdorner.UpdateAlignment(mousePosition);
            }
        }
Example #51
0
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            // m_dragSourceManager.ProcessMouseLeftButtonUp() will release the capture,
            // so we need to check the IsMouseCaptured and IsPressed states before calling it.
            bool isMouseCaptured = this.IsMouseCaptured;
            bool isPressed       = this.IsPressed;

            if (m_dragSourceManager != null)
            {
                m_dragSourceManager.ProcessMouseLeftButtonUp(e);
            }

            if (isMouseCaptured)
            {
                bool click = isPressed;

                this.ReleaseMouseCapture();
                this.SetIsPressed(false);

                if (click)
                {
                    this.DoSort(((Keyboard.Modifiers & ModifierKeys.Shift) != ModifierKeys.Shift));
                }

                e.Handled = true;
            }

            // Focus must be done only on mouse up ( after the sort is done ... etc )
            // we have to focus the grid.

            // We don't need to set PreserveEditorFocus to true since clicking on another element will automatically
            // set the Cell/Row IsBeingEdited to false and try to make it leave edition.
            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            if (dataGridContext != null)
            {
                DataGridControl dataGridControl = dataGridContext.DataGridControl;

                if ((dataGridControl != null) && (!dataGridControl.IsKeyboardFocusWithin))
                {
                    dataGridControl.Focus();
                }
            }

            base.OnMouseLeftButtonUp(e);
        }
Example #52
0
        protected override Size MeasureOverride(Size availableSize)
        {
            Size            restrictedMeasureSize;
            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            if (this.Orientation == Orientation.Vertical)
            {
                restrictedMeasureSize = new Size(availableSize.Width, double.PositiveInfinity);

                if (availableSize.Width != Double.PositiveInfinity)
                {
                    dataGridContext.FixedHeaderFooterViewPortSize = restrictedMeasureSize;
                }
            }
            else
            {
                restrictedMeasureSize = new Size(double.PositiveInfinity, availableSize.Height);

                if (availableSize.Height != Double.PositiveInfinity)
                {
                    dataGridContext.FixedHeaderFooterViewPortSize = restrictedMeasureSize;
                }
            }

            foreach (UIElement child in this.Children)
            {
                if ((child is HeaderFooterItem) && (typeof(Row).IsAssignableFrom((( HeaderFooterItem )child).VisualRootElementType)))
                {
                    dataGridContext.ColumnStretchingManager.ColumnStretchingCalculated = false;

                    // Calling Measure with the Viewport's width will have the effect of
                    // distributing the extra space (see FixedCellPanel's MeasureOverride).
                    // Eventually, the FixedCellPanel will receive an adjusted viewport
                    // width (where GroupLevelIndicator's width et al will be substracted).
                    child.Measure(restrictedMeasureSize);

                    if (dataGridContext.ColumnStretchingManager.ColumnStretchingCalculated)
                    {
                        break;
                    }
                }
            }

            return(base.MeasureOverride(availableSize));
        }
Example #53
0
        private void DragScrollBegin(Orientation orientation)
        {
            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            if (dataGridContext == null)
            {
                return;
            }

            DataGridControl parentGridControl = dataGridContext.DataGridControl;

            if (parentGridControl == null || dataGridContext.DataGridControl.ScrollViewer == null)
            {
                return;
            }

            if (parentGridControl.ItemScrollingBehavior == ItemScrollingBehavior.Deferred)
            {
                IDeferableScrollInfoRefresh panel = this.ScrollInfo as IDeferableScrollInfoRefresh;

                if (panel != null)
                {
                    if (m_deferScrollInfoRefresh != null)
                    {
                        foreach (IDeferableScrollChanged deferable in m_deferableChilds)
                        {
                            deferable.DeferScrollChanged = false;
                        }

                        m_deferScrollInfoRefresh.Dispose();
                        m_deferScrollInfoRefresh = null;
                    }

                    m_deferScrollInfoRefresh = panel.DeferScrollInfoRefresh(orientation);

                    if (m_deferScrollInfoRefresh != null)
                    {
                        foreach (IDeferableScrollChanged deferable in m_deferableChilds)
                        {
                            deferable.DeferScrollChanged = true;
                        }
                    }
                }
            }
        }
        public void RemoveAt(int index)
        {
            if ((index < 0) || (index >= m_list.ItemsCount))
            {
                throw new ArgumentOutOfRangeException("index", index, "index must be greater than or equal to zero and less than Count.");
            }

            int oldIndexOffset = 0;
            int indexOffset    = 0;
            int count          = m_list.Count;
            SelectionRangeWithItems rangeWithItemsFound = SelectionRangeWithItems.Empty;

            for (int i = 0; i < count; i++)
            {
                SelectionRangeWithItems rangeWithItems = m_list[i];
                indexOffset += rangeWithItems.Length;

                if (index < indexOffset)
                {
                    rangeWithItemsFound = rangeWithItems; // .GetItem( dataGridContext, index - oldIndexOffset );
                    break;
                }

                oldIndexOffset = indexOffset;
            }

            if (!rangeWithItemsFound.IsEmpty)
            {
                DataGridContext  dataGridContext  = m_list.DataGridContext;
                SelectionManager selectionManager = dataGridContext.DataGridControl.SelectionChangerManager;
                selectionManager.Begin();

                try
                {
                    selectionManager.UnselectItems(dataGridContext,
                                                   new SelectionRangeWithItems(
                                                       rangeWithItemsFound.Range.GetIndexFromItemOffset(index - oldIndexOffset),
                                                       rangeWithItemsFound.GetItem(dataGridContext, index - oldIndexOffset)));
                }
                finally
                {
                    selectionManager.End(false, true, true);
                }
            }
        }
        // This function fills a list of objects of type 'DataGridContext'
        // This object is similar in members to the type 'Process' but it has nullable integer types
        public List <DataGridContext> CreateDataGridContext()
        {
            List <DataGridContext> dgcList = new List <DataGridContext>();

            idCounter = 1;

            for (int i = 0; i < originalProcesses.Count; i++)
            {
                DataGridContext dgc = new DataGridContext(originalProcesses[i].ID,
                                                          originalProcesses[i].ArrivalTime,
                                                          originalProcesses[i].ProccesingTime,
                                                          originalProcesses[i].Priority);
                dgcList.Add(dgc);
                idCounter++;
            }

            return(dgcList);
        }
        public DomainTextClipboardPaster(DataGridContext gridContext)
        {
            this.gridContext = gridContext;
            this.columns     = gridContext.GetSelectedColumns().ToArray();
            this.items       = gridContext.GetSelectedItems().ToArray();

            var typedList = gridContext.Items.SourceCollection as ITypedList;

            if (typedList == null)
            {
                var source = (gridContext.Items.SourceCollection as CollectionView).SourceCollection;
                typedList = source as ITypedList;
            }

            this.props       = typedList.GetItemProperties(null);
            this.tableName   = CremaDataTable.GetTableName(typedList.GetListName(null));
            this.columnNames = CremaDataRowUtility.GetColumnNames(typedList);
        }
Example #57
0
        private void ColumnResizerThumb_DragStarted(object sender, DragStartedEventArgs e)
        {
            ColumnBase parentColumn = this.ParentColumn;

            if (parentColumn == null)
            {
                return;
            }

            m_originalWidth = parentColumn.ActualWidth;

            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            if ((dataGridContext != null) && (TableView.GetRemoveColumnStretchingOnResize(dataGridContext)))
            {
                dataGridContext.ColumnStretchingManager.DisableColumnStretching();
            }
        }
Example #58
0
        public ModernTextClipboardParser(DataGridContext gridContext)
        {
            this.gridContext = gridContext;
            this.Columns     = gridContext.Columns.ToArray();

            if (gridContext.Items.SourceCollection is not ITypedList typedList)
            {
                var source = (gridContext.Items.SourceCollection as CollectionView).SourceCollection;
                typedList = source as ITypedList;
            }

            this.props       = typedList.GetItemProperties(null);
            this.columnNames = new string[props.Count];
            for (var i = 0; i < props.Count; i++)
            {
                this.columnNames[i] = props[i].Name;
            }
        }
    public WeakDataGridContextKey( DataGridContext dataGridContext )
    {
      DataGridContext parentDataGridContext = dataGridContext.ParentDataGridContext;
      int level = 0;
      while( parentDataGridContext != null )
      {
        level++;
        parentDataGridContext = parentDataGridContext.ParentDataGridContext;
      }

      System.Diagnostics.Debug.Assert( ( ( level == 0 ) || ( dataGridContext.SourceDetailConfiguration != null ) ),
        "A child dataGridContext must have a SourceDetailConfiguration." );

      m_sourceDetailConfigurationRelationName = ( dataGridContext.SourceDetailConfiguration != null ) ?
        dataGridContext.SourceDetailConfiguration.RelationName : string.Empty;

      if( level > 0 )
      {
        // We are NOT dealing with the root DataGridContext.

        // Build the tree of master items.
        m_weakItemsTree = new WeakReference[ level ];

        DataGridContext tempDataGridContext = dataGridContext;
        for( int i = level - 1; i >= 0; i-- )
        {
          // Ensure to get a reference to the System.Data.DataRow when doing a 
          // save/restore of a System.Data.DataRowView since the view is recreated
          // for every detail views
          object parentItem = ItemsSourceHelper.TryGetDataRowFromDataItem( tempDataGridContext.ParentItem );

          m_weakItemsTree[ i ] = new WeakReference( parentItem );

          tempDataGridContext = tempDataGridContext.ParentDataGridContext;
        }
      }

      this.Initialize();
    }
    internal static SelectionRange GetRange( this CollectionViewGroup collectionViewGroup, DataGridContext dataGridContext )
    {
      int startIndex = -1;
      int endIndex = -1;

      DataGridVirtualizingCollectionViewGroupBase dataGridVirtualizingCollectionViewGroupBase = collectionViewGroup as DataGridVirtualizingCollectionViewGroupBase;
      DataGridCollectionViewGroup dataGridCollectionViewGroup = collectionViewGroup as DataGridCollectionViewGroup;

      if( dataGridVirtualizingCollectionViewGroupBase != null )
      {
        startIndex = dataGridVirtualizingCollectionViewGroupBase.StartGlobalIndex;
        endIndex = startIndex + dataGridVirtualizingCollectionViewGroupBase.VirtualItemCount - 1;
      }
      else if( dataGridCollectionViewGroup != null )
      {
        startIndex = dataGridCollectionViewGroup.GetFirstRawItemGlobalSortedIndex();
        endIndex = startIndex + dataGridCollectionViewGroup.GlobalRawItemCount - 1;
      }
      else if(collectionViewGroup.ItemCount > 0)
      {
        if( dataGridContext == null )
          throw new DataGridInternalException( "This collectionViewGroup require a DataGridContext instance" );

        var firstItem = collectionViewGroup.GetFirstLeafItem();
        var lastItem = collectionViewGroup.GetLastLeafItem();

        if( firstItem != null && lastItem != null )
        {
          startIndex = dataGridContext.Items.IndexOf( firstItem );
          endIndex = dataGridContext.Items.IndexOf( lastItem );
        }
      }

      return (startIndex >= 0 ) && (startIndex <= endIndex)
        ? new SelectionRange(startIndex, endIndex)
        : SelectionRange.Empty;
    }