/// <summary> /// handle the case when an anchor is modified /// </summary> /// <param name="annotation">the annotation which anchor was affected</param> /// <param name="anchor">the modified anchor</param> /// <returns></returns> private AttachedAnnotationChangedEventArgs AnchorModified(Annotation annotation, AnnotationResource anchor) { Invariant.Assert(annotation != null && anchor != null, "Parameter 'annotation' or 'anchor' is null."); AttachedAnnotationChangedEventArgs args = null; AttachmentLevel newAttachmentLevel; bool previouslyAttached = false; // anchor has changed, need to find new attached anchor object newAttachedAnchor = FindAttachedAnchor(anchor, out newAttachmentLevel); // Since we will be modifying this collection, we make a copy of it to iterate on IList<IAttachedAnnotation> annotations = _annotationMap.GetAttachedAnnotations(annotation.Id); IAttachedAnnotation[] list = new IAttachedAnnotation[annotations.Count]; annotations.CopyTo(list, 0); foreach (IAttachedAnnotation attachedAnnotation in list) { if (attachedAnnotation.Anchor == anchor) { previouslyAttached = true; if (newAttachmentLevel != AttachmentLevel.Unresolved) { Invariant.Assert(newAttachedAnchor != null, "AttachedAnnotation with AttachmentLevel != Unresolved should have non-null AttachedAnchor."); object oldAttachedAnchor = attachedAnnotation.AttachedAnchor; AttachmentLevel oldAttachmentLevel = attachedAnnotation.AttachmentLevel; ((AttachedAnnotation)attachedAnnotation).Update(newAttachedAnchor, newAttachmentLevel, null); // Update the full anchor FullyResolveAnchor(attachedAnnotation); // No need to update map - we just changed the AttachedAnnotation in-place args = AttachedAnnotationChangedEventArgs.Modified(attachedAnnotation, oldAttachedAnchor, oldAttachmentLevel); } else { // the new modified anchor doesn't resolve // we need to delete the original attached annotation DoRemoveAttachedAnnotation(attachedAnnotation); args = AttachedAnnotationChangedEventArgs.Deleted(attachedAnnotation); } break; } } // If it wasn't previously attached, but can be resolved now we create an AttachedAnnotation if (!previouslyAttached && newAttachmentLevel != AttachmentLevel.Unresolved && newAttachmentLevel != AttachmentLevel.Incomplete) { Invariant.Assert(newAttachedAnchor != null, "AttachedAnnotation with AttachmentLevel != Unresolved should have non-null AttachedAnchor."); AttachedAnnotation attachedAnnotation = new AttachedAnnotation( this.LocatorManager, annotation, anchor, newAttachedAnchor, newAttachmentLevel); DoAddAttachedAnnotation(attachedAnnotation); args = AttachedAnnotationChangedEventArgs.Added(attachedAnnotation); } return args; }
/// <summary> /// handle the case when a new anchor is added to the annotation /// </summary> /// <param name="annotation">the annotation which anchor was affected</param> /// <param name="anchor">the deleted anchor</param> /// <returns></returns> private AttachedAnnotationChangedEventArgs AnchorAdded(Annotation annotation, AnnotationResource anchor) { Invariant.Assert(annotation != null && anchor != null, "Parameter 'annotation' or 'anchor' is null."); AttachedAnnotationChangedEventArgs args = null; AttachmentLevel attachmentLevel; object attachedAnchor = FindAttachedAnchor(anchor, out attachmentLevel); if (attachmentLevel != AttachmentLevel.Unresolved && attachmentLevel != AttachmentLevel.Incomplete) { Invariant.Assert(attachedAnchor != null, "Must have a valid attached anchor."); AttachedAnnotation attachedAnnotation = new AttachedAnnotation( this.LocatorManager, annotation, anchor, attachedAnchor, attachmentLevel); DoAddAttachedAnnotation(attachedAnnotation); args = AttachedAnnotationChangedEventArgs.Added(attachedAnnotation); } return args; }