// ------------------------------------------------------------------ // 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); } }
// Replace objects in graphicsList with objects from clone list private static void ReplaceObjects(VisualCollection graphicsList, List<PropertiesGraphicsBase> list) { for (int i = 0; i < graphicsList.Count; i++) { PropertiesGraphicsBase replacement = null; foreach (PropertiesGraphicsBase o in list) { if (o.ID == ((GraphicsBase)graphicsList[i]).Id) { replacement = o; break; } } if (replacement != null) { // Replace object with its clone graphicsList.RemoveAt(i); graphicsList.Insert(i, replacement.CreateGraphics()); } } }