Ejemplo n.º 1
0
        /// <summary>
        /// SynchronizeCellVisualsCollection.
        /// </summary>
        /// <param name="cellVisualsCollection">Collection to synchromize.</param>
        /// <param name="firstIndex">Index to start syncronization from.</param>
        /// <param name="visual">Visual that still alive.</param>
        private void SynchronizeCellVisualsCollection(
            VisualCollection cellVisualsCollection,
            int firstIndex,
            Visual visual)
        {
            //  quick check to see if collection is already synchronized
            if ((cellVisualsCollection[firstIndex]) != visual)
            {
                int lastIndex = firstIndex;
                int count = cellVisualsCollection.Count;

                while (++lastIndex < count)
                {
                    if (cellVisualsCollection[lastIndex] == visual) break;
                }

                cellVisualsCollection.RemoveRange(firstIndex, lastIndex - firstIndex);
            }
        }
Ejemplo n.º 2
0
        // ------------------------------------------------------------------
        // Update visuals for list of paragraphs.
        // ------------------------------------------------------------------
        internal static void UpdateParaListVisuals(
            PtsContext ptsContext,
            VisualCollection visualCollection,
            PTS.FSKUPDATE fskupdInherited,
            PTS.FSPARADESCRIPTION [] arrayParaDesc)
        {
            // For each paragraph, do following:
            // (1) Retrieve ParaClient object
            // (3) Update visual, if necessary
            for (int index = 0; index < arrayParaDesc.Length; index++)
            {
                // (1) Retrieve ParaClient object
                BaseParaClient paraClient = ptsContext.HandleToObject(arrayParaDesc[index].pfsparaclient) as BaseParaClient;
                PTS.ValidateHandle(paraClient);

                // (2) Update visual, if necessary
                PTS.FSKUPDATE fskupd = arrayParaDesc[index].fsupdinf.fskupd;
                if (fskupd == PTS.FSKUPDATE.fskupdInherited)
                {
                    fskupd = fskupdInherited;
                }
                if (fskupd == PTS.FSKUPDATE.fskupdNew)
                {
                    // Disconnect visual from its old parent, if necessary.
                    Visual currentParent = VisualTreeHelper.GetParent(paraClient.Visual) as Visual;
                    if(currentParent != null)
                    {
                        ContainerVisual parent = currentParent as ContainerVisual;
                        Invariant.Assert(parent != null, "parent should always derives from ContainerVisual");
                        parent.Children.Remove(paraClient.Visual);                         
                    }                                          

                    // New paragraph - insert new visual node
                    visualCollection.Insert(index, paraClient.Visual);

                    paraClient.ValidateVisual(fskupd);
                }
                else
                {
                    // Remove visuals for non-existing paragraphs
                    while (visualCollection[index] != paraClient.Visual)
                    {
                        visualCollection.RemoveAt(index);
                        Invariant.Assert(index < visualCollection.Count);
                    }

                    if(fskupd == PTS.FSKUPDATE.fskupdChangeInside || fskupd == PTS.FSKUPDATE.fskupdShifted)
                    {
                        paraClient.ValidateVisual(fskupd);
                    }
                }
            }
            // Remove obsolete visuals
            if (arrayParaDesc.Length < visualCollection.Count)
            {
                visualCollection.RemoveRange(arrayParaDesc.Length, visualCollection.Count - arrayParaDesc.Length);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// SynchronizeRowVisualsCollection.
        /// </summary>
        /// <param name="rowVisualsCollection">Collection to synchromize.</param>
        /// <param name="firstIndex">Index to start syncronization from.</param>
        /// <param name="row">Row that still alive.</param>
        private void SynchronizeRowVisualsCollection(
            VisualCollection rowVisualsCollection,
            int firstIndex,
            TableRow row)
        {
            //  quick check to see if collection is already synchronized
            if (((RowVisual)(rowVisualsCollection[firstIndex])).Row != row)
            {
                int lastIndex = firstIndex;
                int count = rowVisualsCollection.Count;

                while (++lastIndex < count)
                {
                    RowVisual rowVisual = (RowVisual)(rowVisualsCollection[lastIndex]);
                    if (rowVisual.Row == row)   break;
                }

                rowVisualsCollection.RemoveRange(firstIndex, lastIndex - firstIndex);
            }
        }
Ejemplo n.º 4
0
        private void SyncUpdateDeferredLineVisuals(VisualCollection lineVisuals, ref PTS.FSTEXTDETAILSFULL textDetails, bool ignoreUpdateInfo) 
        { 
            Debug.Assert(!PTS.ToBoolean(textDetails.fLinesComposite));
 
            try
            {
                if (!PTS.ToBoolean(textDetails.fUpdateInfoForLinesPresent) || ignoreUpdateInfo)
                { 
                    // _lineIndexFirstVisual will be updated based on the size of this list, so clearing is sufficient here.
                    lineVisuals.Clear(); 
                } 
                else if (_lineIndexFirstVisual != -1)
                { 
                    PTS.FSLINEDESCRIPTIONSINGLE[] arrayLineDesc;
                    PtsHelper.LineListSimpleFromTextPara(PtsContext, _paraHandle.Value, ref textDetails, out arrayLineDesc);

                    int lineIndexToBeginRemoval = textDetails.cLinesBeforeChange; 
                    int cLinesToRemove = textDetails.cLinesChanged - textDetails.dcLinesChanged;
                    int insertionIndex = -1; 
 
                    // Shift lines before change
                    if(textDetails.dvrShiftBeforeChange != 0) 
                    {
                        int countVisualsShiftBeforeChange = Math.Min(Math.Max(lineIndexToBeginRemoval - _lineIndexFirstVisual, 0), lineVisuals.Count);
                        for(int index = 0; index < countVisualsShiftBeforeChange; index++)
                        { 
                            // Shift line's visual
                            ContainerVisual lineVisual = (ContainerVisual) lineVisuals[index]; 
                            Vector offset = lineVisual.Offset; 
                            offset.Y += TextDpi.FromTextDpi(textDetails.dvrShiftBeforeChange);
                            lineVisual.Offset = offset; 
                        }
                    }

                    // If the line index to begin removal is before our first visual, then the overlap will look like 
                    //      |---------------|  (Committed visual range)
                    // |------|                (Range to remove) 
                    if (lineIndexToBeginRemoval < _lineIndexFirstVisual) 
                    {
                        // Determine the amount of overlap, and remove. 
                        int actualLinesToRemove = Math.Min(Math.Max(lineIndexToBeginRemoval - _lineIndexFirstVisual + cLinesToRemove, 0), lineVisuals.Count);

                        if (actualLinesToRemove > 0)
                        { 
                            lineVisuals.RemoveRange(0, actualLinesToRemove);
                        } 
 
                        if (lineVisuals.Count == 0)
                        { 
                            lineVisuals.Clear();
                            _lineIndexFirstVisual = -1;
                        }
                        else 
                        {
                            insertionIndex = 0; 
                            _lineIndexFirstVisual = lineIndexToBeginRemoval; 
                        }
                    } 
                    else if (lineIndexToBeginRemoval < _lineIndexFirstVisual + lineVisuals.Count)
                    {
                        // Else case for overlap
                        //  |---------------|  (Committed visual range) 
                        //       |-----|                (Range to remove)
                        // Or 
                        //  |---------------| 
                        //           |--------------|
 
                        // Removing from the middle
                        int actualLinesToRemove = Math.Min(cLinesToRemove, lineVisuals.Count - (lineIndexToBeginRemoval - _lineIndexFirstVisual));

                        lineVisuals.RemoveRange(lineIndexToBeginRemoval - _lineIndexFirstVisual, actualLinesToRemove); 

                        insertionIndex = lineIndexToBeginRemoval - _lineIndexFirstVisual; // Insertion index is relative to committed visual range 
                    } 

                    int shiftIndex = -1; 

                    if (insertionIndex != -1)
                    {
                        // Add new lines 
                        // Insertion must occur at some point along our committed visual range
                        Debug.Assert(insertionIndex >= 0 && insertionIndex <= lineVisuals.Count); 
 
                        for (int index = textDetails.cLinesBeforeChange; index < textDetails.cLinesBeforeChange + textDetails.cLinesChanged; index++)
                        { 
                            PTS.FSLINEDESCRIPTIONSINGLE lineDesc = arrayLineDesc[index];

                            ContainerVisual lineVisual = CreateLineVisual(ref arrayLineDesc[index], Paragraph.ParagraphStartCharacterPosition);
 
                            lineVisuals.Insert(insertionIndex + (index - textDetails.cLinesBeforeChange), lineVisual);
                            lineVisual.Offset = new Vector(TextDpi.FromTextDpi(lineDesc.urStart), TextDpi.FromTextDpi(lineDesc.vrStart)); 
                        } 

                        shiftIndex = insertionIndex + textDetails.cLinesChanged; 
                    }

                    // Any committed visuals after our inserted section must be shifted
                    if (shiftIndex != -1) 
                    {
                        // Shift remaining lines 
                        for (int index = shiftIndex; index < lineVisuals.Count; index++) 
                        {
                            // Shift line's visual 
                            ContainerVisual lineVisual = (ContainerVisual) lineVisuals[index];
                            Vector offset = lineVisual.Offset;
                            offset.Y += TextDpi.FromTextDpi(textDetails.dvrShiftAfterChange);
                            lineVisual.Offset = offset; 
                        }
                    } 
                } 
            }
 
            finally
            {
                // If no visuals, committed range is nonexistant, so -1
                if (lineVisuals.Count == 0) 
                {
                    _lineIndexFirstVisual = -1; 
                } 
            }
 
#if VERIFY_VISUALS
            // Verify our visuals are in-[....] with the actual line visuals.
            VerifyVisuals(ref textDetails);
#endif 
        }