// Token: 0x0600627C RID: 25212 RVA: 0x001BA4A0 File Offset: 0x001B86A0 private void FireResourceEvent(AnnotationResource resource, AnnotationAction action, AnnotationResourceChangedEventHandler handlers) { Invariant.Assert(action >= AnnotationAction.Added && action <= AnnotationAction.Modified, "Unknown AnnotationAction"); this._modified = DateTime.Now; if (handlers != null) { handlers(this, new AnnotationResourceChangedEventArgs(this, action, resource)); } }
/// <summary> /// Create an instance of AttachedAnnotation with a specified parent. Takes an optional /// parent for the attached annotation. This is useful when the parent is known before /// hand and not available through the normal means (such as in printing). /// </summary> /// <param name="manager">the LocatorManager providing processors for this anchored annotation</param> /// <param name="annotation">the annotation itself</param> /// <param name="anchor">the annotation's anchor represented by the attached anchor</param> /// <param name="attachedAnchor">the attached anchor itself</param> /// <param name="attachmentLevel">the level of the attached anchor</param> /// <param name="parent">parent of the selection</param> internal AttachedAnnotation(LocatorManager manager, Annotation annotation, AnnotationResource anchor, Object attachedAnchor, AttachmentLevel attachmentLevel, DependencyObject parent) { Debug.Assert(manager != null, "LocatorManager can not be null"); Debug.Assert(annotation != null, "Annotation can not be null"); Debug.Assert(anchor != null, "Anchor can not be null"); Debug.Assert(attachedAnchor != null, "AttachedAnchor can not be null"); _annotation = annotation; _anchor = anchor; _locatorManager = manager; Update(attachedAnchor, attachmentLevel, parent); }
/// <summary> /// Fires a ResourceChanged event for the given resource and action. /// </summary> /// <param name="resource">the resource to notify about</param> /// <param name="action">the action that took place for that resource</param> /// <param name="handlers">the handlers to notify</param> private void FireResourceEvent(AnnotationResource resource, AnnotationAction action, AnnotationResourceChangedEventHandler handlers) { // resource can be null - we allow that because it could be added or removed from the annotation. Invariant.Assert(action >= AnnotationAction.Added && action <= AnnotationAction.Modified, "Unknown AnnotationAction"); // Always update the modification time before firing change events _modified = DateTime.Now; if (handlers != null) { handlers(this, new AnnotationResourceChangedEventArgs(this, action, resource)); } }
// Token: 0x060062DE RID: 25310 RVA: 0x001BC190 File Offset: 0x001BA390 private static void SetAnchor(AnnotationService service, Annotation annot, object selection) { Invariant.Assert(annot != null && selection != null, "null input parameter"); IList <ContentLocatorBase> list = service.LocatorManager.GenerateLocators(selection); Invariant.Assert(list != null && list.Count > 0, "No locators generated for selection."); AnnotationResource annotationResource = new AnnotationResource(); foreach (ContentLocatorBase item in list) { annotationResource.ContentLocators.Add(item); } annot.Anchors.Clear(); annot.Anchors.Add(annotationResource); }
// Token: 0x060062DC RID: 25308 RVA: 0x001BC0CC File Offset: 0x001BA2CC private static Annotation CreateHighlight(AnnotationService service, ITextRange textRange, string author, Color?color) { Invariant.Assert(textRange != null, "textRange is null"); Annotation annotation = AnnotationHelper.CreateAnnotationForSelection(service, textRange, HighlightComponent.TypeName, author); if (color != null) { ColorConverter colorConverter = new ColorConverter(); XmlDocument xmlDocument = new XmlDocument(); XmlElement xmlElement = xmlDocument.CreateElement("Colors", "http://schemas.microsoft.com/windows/annotations/2003/11/base"); xmlElement.SetAttribute("Background", colorConverter.ConvertToInvariantString(color.Value)); AnnotationResource annotationResource = new AnnotationResource("Highlight"); annotationResource.Contents.Add(xmlElement); annotation.Cargos.Add(annotationResource); } return(annotation); }
// Token: 0x06006279 RID: 25209 RVA: 0x001BA218 File Offset: 0x001B8418 private void OnAnchorsChanged(object sender, NotifyCollectionChangedEventArgs e) { AnnotationAction action = AnnotationAction.Added; IList list = null; switch (e.Action) { case NotifyCollectionChangedAction.Add: action = AnnotationAction.Added; list = e.NewItems; break; case NotifyCollectionChangedAction.Remove: action = AnnotationAction.Removed; list = e.OldItems; break; case NotifyCollectionChangedAction.Replace: foreach (object obj in e.OldItems) { AnnotationResource resource = (AnnotationResource)obj; this.FireResourceEvent(resource, AnnotationAction.Removed, this.AnchorChanged); } list = e.NewItems; break; case NotifyCollectionChangedAction.Move: case NotifyCollectionChangedAction.Reset: break; default: throw new NotSupportedException(SR.Get("UnexpectedCollectionChangeAction", new object[] { e.Action })); } if (list != null) { foreach (object obj2 in list) { AnnotationResource resource2 = (AnnotationResource)obj2; this.FireResourceEvent(resource2, action, this.AnchorChanged); } } }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors /// <summary> /// Creates an instance of AnnotationResourceChangedEventArgs. /// </summary> /// <param name="annotation">the Annotation firing the event</param> /// <param name="action">the action taken on the Resource</param> /// <param name="resource">the Resource that was changed</param> /// <exception cref="ArgumentNullException">annotation or action is null</exception> /// <exception cref="InvalidEnumArgumentException">action is not a valid value from AnnotationAction</exception> public AnnotationResourceChangedEventArgs(Annotation annotation, AnnotationAction action, AnnotationResource resource) { // The resource parameter can be null here - it is possible to add a null to // the list of resources and we must fire an event signalling a change in the collection. if (annotation == null) { throw new ArgumentNullException("annotation"); } if (action < AnnotationAction.Added || action > AnnotationAction.Modified) { throw new InvalidEnumArgumentException("action", (int)action, typeof(AnnotationAction)); } _annotation = annotation; _resource = resource; _action = action; }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors /// <summary> /// Creates an instance of AnnotationResourceChangedEventArgs. /// </summary> /// <param name="annotation">the Annotation firing the event</param> /// <param name="action">the action taken on the Resource</param> /// <param name="resource">the Resource that was changed</param> /// <exception cref="ArgumentNullException">annotation or action is null</exception> /// <exception cref="InvalidEnumArgumentException">action is not a valid value from AnnotationAction</exception> public AnnotationResourceChangedEventArgs(Annotation annotation, AnnotationAction action, AnnotationResource resource) { // The resource parameter can be null here - it is possible to add a null to // the list of resources and we must fire an event signalling a change in the collection. if (annotation == null) { throw new ArgumentNullException("annotation"); } if (action < AnnotationAction.Added || action > AnnotationAction.Modified) { throw new InvalidEnumArgumentException("action", (int)action, typeof(AnnotationAction)); } _annotation = annotation; _resource = resource; _action = action; }
private static void SetAnchor(AnnotationService service, Annotation annot, object selection) { Invariant.Assert(annot != null && selection != null, "null input parameter"); // Generate locators for the selection - add them to the anchor IList<ContentLocatorBase> locators = service.LocatorManager.GenerateLocators(selection); Invariant.Assert(locators != null && locators.Count > 0, "No locators generated for selection."); // Create an annotation with a single anchor AnnotationResource anchor = new AnnotationResource(); // Add the locators to the anchor foreach (ContentLocatorBase locator in locators) { anchor.ContentLocators.Add(locator); } annot.Anchors.Clear(); annot.Anchors.Add(anchor); }
/// <summary> /// Creates a highlight annotation with the specified color and author /// </summary> /// <param name="service">the AnnotationService</param> /// <param name="textRange">highlight anchor</param> /// <param name="author">highlight author</param> /// <param name="color">highlight brush</param> /// <returns>created annotation</returns> private static Annotation CreateHighlight(AnnotationService service, ITextRange textRange, string author, Nullable<Color> color) { Invariant.Assert(textRange != null, "textRange is null"); Annotation annotation = CreateAnnotationForSelection(service, textRange, HighlightComponent.TypeName, author); // Set the cargo with highlight color if (color != null) { ColorConverter converter = new ColorConverter(); XmlDocument doc = new XmlDocument(); XmlElement colorsElement = doc.CreateElement(HighlightComponent.ColorsContentName, AnnotationXmlConstants.Namespaces.BaseSchemaNamespace); colorsElement.SetAttribute(HighlightComponent.BackgroundAttributeName, converter.ConvertToInvariantString(color.Value)); AnnotationResource cargo = new AnnotationResource(HighlightComponent.HighlightResourceName); cargo.Contents.Add(colorsElement); annotation.Cargos.Add(cargo); } return annotation; }
/// <summary> /// Fires a ResourceChanged event for the given resource and action. /// </summary> /// <param name="resource">the resource to notify about</param> /// <param name="action">the action that took place for that resource</param> /// <param name="handlers">the handlers to notify</param> private void FireResourceEvent(AnnotationResource resource, AnnotationAction action, AnnotationResourceChangedEventHandler handlers) { // resource can be null - we allow that because it could be added or removed from the annotation. Invariant.Assert(action >= AnnotationAction.Added && action <= AnnotationAction.Modified, "Unknown AnnotationAction"); // Always update the modification time before firing change events _modified = DateTime.Now; if (handlers != null) { handlers(this, new AnnotationResourceChangedEventArgs(this, action, resource)); } }
/// <summary>Deserializes the <see cref="T:System.Windows.Annotations.Annotation" /> from a specified <see cref="T:System.Xml.XmlReader" />. </summary> /// <param name="reader">The XML reader to use to deserialize the annotation.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="reader" /> is <see langword="null" />.</exception> /// <exception cref="T:System.Xml.XmlException">The serialized XML for the <see cref="T:System.Windows.Annotations.Annotation" /> is not valid.</exception> // Token: 0x06006264 RID: 25188 RVA: 0x001B9954 File Offset: 0x001B7B54 public void ReadXml(XmlReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.DeserializeAnnotationBegin); try { XmlDocument xmlDocument = new XmlDocument(); this.ReadAttributes(reader); if (!reader.IsEmptyElement) { reader.Read(); while (XmlNodeType.EndElement != reader.NodeType || !("Annotation" == reader.LocalName)) { if ("Anchors" == reader.LocalName) { Annotation.CheckForNonNamespaceAttribute(reader, "Anchors"); if (!reader.IsEmptyElement) { reader.Read(); while (!("Anchors" == reader.LocalName) || XmlNodeType.EndElement != reader.NodeType) { AnnotationResource item = (AnnotationResource)Annotation.ResourceSerializer.Deserialize(reader); this._anchors.Add(item); } } reader.Read(); } else if ("Cargos" == reader.LocalName) { Annotation.CheckForNonNamespaceAttribute(reader, "Cargos"); if (!reader.IsEmptyElement) { reader.Read(); while (!("Cargos" == reader.LocalName) || XmlNodeType.EndElement != reader.NodeType) { AnnotationResource item2 = (AnnotationResource)Annotation.ResourceSerializer.Deserialize(reader); this._cargos.Add(item2); } } reader.Read(); } else { if (!("Authors" == reader.LocalName)) { throw new XmlException(SR.Get("InvalidXmlContent", new object[] { "Annotation" })); } Annotation.CheckForNonNamespaceAttribute(reader, "Authors"); if (!reader.IsEmptyElement) { reader.Read(); while (!("Authors" == reader.LocalName) || XmlNodeType.EndElement != reader.NodeType) { if (!("StringAuthor" == reader.LocalName) || XmlNodeType.Element != reader.NodeType) { throw new XmlException(SR.Get("InvalidXmlContent", new object[] { "Annotation" })); } XmlNode xmlNode = xmlDocument.ReadNode(reader); if (!reader.IsEmptyElement) { this._authors.Add(xmlNode.InnerText); } } } reader.Read(); } } } reader.Read(); } finally { EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.DeserializeAnnotationEnd); } }
/// <summary> /// Asks the LocatorManager to find the attached anchor for a certain anchor /// </summary> /// <param name="anchor">the anchor to be resolved</param> /// <param name="attachmentLevel">the attachment level of the resulting attached anchor</param> /// <returns></returns> private object FindAttachedAnchor(AnnotationResource anchor, out AttachmentLevel attachmentLevel) { Invariant.Assert(anchor != null, "Parameter 'anchor' is null."); attachmentLevel = AttachmentLevel.Unresolved; Object attachedAnchor = null; foreach (ContentLocatorBase locator in anchor.ContentLocators) { attachedAnchor = LocatorManager.FindAttachedAnchor(_root, null, locator, out attachmentLevel); if (attachedAnchor != null) break; } return attachedAnchor; }
/// <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>Initializes a new instance of the <see cref="M:System.Windows.Annotations.AnnotationResourceChangedEventArgs.#ctor(System.Windows.Annotations.Annotation,System.Windows.Annotations.AnnotationAction,System.Windows.Annotations.AnnotationResource)" /> class.</summary> /// <param name="annotation">The annotation that raised the event.</param> /// <param name="action">The action of the event.</param> /// <param name="resource">The <see cref="P:System.Windows.Annotations.Annotation.Anchors" /> or <see cref="P:System.Windows.Annotations.Annotation.Cargos" /> resource of the event.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="annotation" /> or <paramref name="action" /> is <see langword="null" />.</exception> /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException"> /// <paramref name="action" /> is not a valid <see cref="T:System.Windows.Annotations.AnnotationAction" /> value.</exception> // Token: 0x060062B7 RID: 25271 RVA: 0x001BB128 File Offset: 0x001B9328 public AnnotationResourceChangedEventArgs(Annotation annotation, AnnotationAction action, AnnotationResource resource) { if (annotation == null) { throw new ArgumentNullException("annotation"); } if (action < AnnotationAction.Added || action > AnnotationAction.Modified) { throw new InvalidEnumArgumentException("action", (int)action, typeof(AnnotationAction)); } this._annotation = annotation; this._resource = resource; this._action = action; }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors /// <summary> /// Create an instance of AttachedAnnotation. /// </summary> /// <param name="manager">the LocatorManager providing processors for this anchored annotation</param> /// <param name="annotation">the annotation itself</param> /// <param name="anchor">the annotation's anchor represented by the attached anchor</param> /// <param name="attachedAnchor">the attached anchor itself</param> /// <param name="attachmentLevel">the level of the attached anchor</param> internal AttachedAnnotation(LocatorManager manager, Annotation annotation, AnnotationResource anchor, Object attachedAnchor, AttachmentLevel attachmentLevel) : this(manager, annotation, anchor, attachedAnchor, attachmentLevel, null) { }
/// <summary> /// The method sets an instance of the IAttachedAnnotation to the StickyNoteControl. /// It will be called by IAnnotationComponent.AddAttachedAnnotation. /// </summary> /// <param name="attachedAnnotation">The instance of the IAttachedAnnotation</param> private void SetAnnotation(IAttachedAnnotation attachedAnnotation) { SNCAnnotation sncAnnotation = new SNCAnnotation(attachedAnnotation.Annotation); // Retrieve the data type. Then set the StickyNote to correct type. // If we have empty data, we won't change the current StickyNote type. bool hasInkData = sncAnnotation.HasInkData; bool hasTextData = sncAnnotation.HasTextData; if (hasInkData && hasTextData) { throw new ArgumentException(SR.Get(SRID.InvalidStickyNoteAnnotation), "attachedAnnotation"); } else if (hasInkData) { _stickyNoteType = StickyNoteType.Ink; } else if (hasTextData) { _stickyNoteType = StickyNoteType.Text; } // If we already created a Content control, make sure it matches our new type or // gets recreated to match. if (Content != null) { EnsureStickyNoteType(); } //create cargo if it is a new Annotation so it is not considered as new next time if (sncAnnotation.IsNewAnnotation) { AnnotationResource cargo = new AnnotationResource(SNBConstants.MetaResourceName); attachedAnnotation.Annotation.Cargos.Add(cargo); } // Set the internal variables _attachedAnnotation = attachedAnnotation; _attachedAnnotation.Annotation.CargoChanged += new AnnotationResourceChangedEventHandler(OnAnnotationUpdated); _attachedAnnotation.Annotation.AuthorChanged += new AnnotationAuthorChangedEventHandler(OnAuthorUpdated); _sncAnnotation = sncAnnotation; _anchor.AddAttachedAnnotation(attachedAnnotation); // Update all value UpdateSNCWithAnnotation(SNCAnnotation.AllValues); // The internal data is just [....]'ed to the store. So, reset the dirty to false. IsDirty = false; //now check if the SN must be seen if ((_attachedAnnotation.AttachmentLevel & AttachmentLevel.StartPortion) == 0) { //we do not need to show the StickyNote SetValue(UIElement.VisibilityProperty, Visibility.Collapsed); } else { //if it is seen we need to take care about bringing into view when needed RequestBringIntoView += new RequestBringIntoViewEventHandler(OnRequestBringIntoView); } }
/// <summary> /// Deserializes an Annotation from the XmlReader passed in. /// </summary> /// <param name="reader">reader to deserialize from</param> /// <exception cref="ArgumentNullException">reader is null</exception> public void ReadXml(XmlReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } //fire trace event EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.DeserializeAnnotationBegin); XmlDocument doc = null; try { doc = new XmlDocument(); ReadAttributes(reader); if (!reader.IsEmptyElement) { reader.Read(); // Read the remainder of the "Annotation" start tag while (!(XmlNodeType.EndElement == reader.NodeType && AnnotationXmlConstants.Elements.Annotation == reader.LocalName)) { if (AnnotationXmlConstants.Elements.AnchorCollection == reader.LocalName) { CheckForNonNamespaceAttribute(reader, AnnotationXmlConstants.Elements.AnchorCollection); if (!reader.IsEmptyElement) { reader.Read(); // Reads the "Anchors" start tag while (!(AnnotationXmlConstants.Elements.AnchorCollection == reader.LocalName && XmlNodeType.EndElement == reader.NodeType)) { AnnotationResource anchor = (AnnotationResource)ResourceSerializer.Deserialize(reader); _anchors.Add(anchor); } } reader.Read(); // Reads the "Anchors" end tag (or whole tag if it was empty) } else if (AnnotationXmlConstants.Elements.CargoCollection == reader.LocalName) { CheckForNonNamespaceAttribute(reader, AnnotationXmlConstants.Elements.CargoCollection); if (!reader.IsEmptyElement) { reader.Read(); // Reads the "Cargos" start tag while (!(AnnotationXmlConstants.Elements.CargoCollection == reader.LocalName && XmlNodeType.EndElement == reader.NodeType)) { AnnotationResource cargo = (AnnotationResource)ResourceSerializer.Deserialize(reader); _cargos.Add(cargo); } } reader.Read(); // Reads the "Cargos" end tag (or whole tag if it was empty) } else if (AnnotationXmlConstants.Elements.AuthorCollection == reader.LocalName) { CheckForNonNamespaceAttribute(reader, AnnotationXmlConstants.Elements.AuthorCollection); if (!reader.IsEmptyElement) { reader.Read(); // Reads the "Authors" start tag while (!(AnnotationXmlConstants.Elements.AuthorCollection == reader.LocalName && XmlNodeType.EndElement == reader.NodeType)) { if (!(AnnotationXmlConstants.Elements.StringAuthor == reader.LocalName && XmlNodeType.Element == reader.NodeType)) { throw new XmlException(SR.Get(SRID.InvalidXmlContent, AnnotationXmlConstants.Elements.Annotation)); } XmlNode node = doc.ReadNode(reader); // Reads the entire "StringAuthor" tag if (!reader.IsEmptyElement) { _authors.Add(node.InnerText); } } } reader.Read(); // Reads the "Authors" end tag (or whole tag if it was empty) } else { // The annotation must contain some invalid content which is not part of the schema. throw new XmlException(SR.Get(SRID.InvalidXmlContent, AnnotationXmlConstants.Elements.Annotation)); } } } reader.Read(); // Read the end of the "Annotation" tag (or the whole tag if its empty) } finally { //fire trace event EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordAnnotation, EventTrace.Event.DeserializeAnnotationEnd); } }
/// <summary> /// Find the specified data in a cargo. /// </summary> /// <param name="token">The specified data</param> /// <param name="cargo">The cargo which we are searhing in</param> /// <returns>The data object or null</returns> private static object FindContent(XmlToken token, AnnotationResource cargo) { object content = null; XmlElement root = SNCAnnotation.FindRootXmlElement(token, cargo); // If we found the root node, we should use XPath to query the node which contains the corresponding data. // The StickyNoteControl's xml schema can be found // in http://tabletpc/longhorn/Specs/WinFX%20StickyNoteControl%20M8.1.mht#_Toc79371211 if (root != null) { switch (token) { case XmlToken.Text: case XmlToken.Ink: return root; case XmlToken.IsExpanded: case XmlToken.ZOrder: case XmlToken.Top: case XmlToken.Left: case XmlToken.XOffset: case XmlToken.YOffset: case XmlToken.Width: case XmlToken.Height: return root.GetAttributeNode(GetXmlName(token), AnnotationXmlConstants.Namespaces.BaseSchemaNamespace); default: Debug.Assert(false); break; } } return content; }
/// <summary> /// The method returns the root node which contains the specified data in a cargo. /// </summary> /// <param name="token">The specified data</param> /// <param name="cargo">The specified cargo</param> /// <returns>The root node or null</returns> private static XmlElement FindRootXmlElement(XmlToken token, AnnotationResource cargo) { Debug.Assert(cargo != null); XmlElement element = null; string xmlName = string.Empty; // Get the xml name of the root node switch (token) { case XmlToken.Text: case XmlToken.Ink: xmlName = GetXmlName(token); break; case XmlToken.MetaData: case XmlToken.IsExpanded: case XmlToken.Width: case XmlToken.Height: case XmlToken.Top: case XmlToken.Left: case XmlToken.XOffset: case XmlToken.YOffset: case XmlToken.ZOrder: xmlName = GetXmlName(XmlToken.MetaData); break; default: Debug.Assert(false); break; } // Search the root in the cargo's contents. foreach (XmlElement node in cargo.Contents) { if (node.Name.Equals(xmlName)) { element = node; break; } } return element; }
/// <summary> /// Returns the AnnotationResource and the XML root for the given token from the passed in annotation. /// If the cargo or root do not exist they are created but not added to the annotation. The newCargo /// and newRoot flags specify whether they were created. The caller must use these to add the items /// to the annotation after they are done with their modifications. /// </summary> /// <param name="annotation">the current annotation</param> /// <param name="token">the token to be processed</param> /// <param name="cargo">the cargo for the token</param> /// <param name="root">the root XML element</param> /// <param name="newCargo">means a new root and new cargo was created. the root was already added to the cargo but the cargo was not added to the annotation</param> /// <param name="newRoot">means a new root was created. it has not been added to the cargo.</param> private static void GetCargoAndRoot( SNCAnnotation annotation, XmlToken token, out AnnotationResource cargo, out XmlElement root, out bool newCargo, out bool newRoot) { Invariant.Assert(annotation != null, "Annotation is null."); Invariant.Assert((token & (AllValues | XmlToken.MetaData)) != 0, "No token specified."); string cargoName = GetCargoName(token); newRoot = false; newCargo = false; cargo = annotation.FindCargo(cargoName); // Cargo exists if (cargo != null) { root = FindRootXmlElement(token, cargo); // Uncommon situation - cargo created without root XmlElement if (root == null) { newRoot = true; XmlDocument xmlDoc = new XmlDocument(); root = xmlDoc.CreateElement(GetXmlName(token), AnnotationXmlConstants.Namespaces.BaseSchemaNamespace); // Don't add it to the cargo yet - wait until all the // values are set on it } } else { newCargo = true; cargo = new AnnotationResource(cargoName); XmlDocument xmlDoc = new XmlDocument(); root = xmlDoc.CreateElement(GetXmlName(token), AnnotationXmlConstants.Namespaces.BaseSchemaNamespace); // Since the cargo is new, its safe to add the root to it // No events will make it to the annotation yet cargo.Contents.Add(root); } }
public AnnotationResourceChangedEventArgs(Annotation annotation, AnnotationAction action, AnnotationResource resource) { }
/// <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; }
/// <summary> /// handle the case when an anchor is removed from the annotation /// </summary> /// <param name="annotation">the annotation which anchor was affected</param> /// <param name="anchor">the removed anchor</param> /// <returns>EventArgs to use when firing an AttachedAnnotationChanged event</returns> private AttachedAnnotationChangedEventArgs AnchorRemoved(Annotation annotation, AnnotationResource anchor) { Invariant.Assert(annotation != null && anchor != null, "Parameter 'annotation' or 'anchor' is null."); AttachedAnnotationChangedEventArgs args = null; IList<IAttachedAnnotation> annotations = _annotationMap.GetAttachedAnnotations(annotation.Id); if (annotations.Count > 0) { // Since we will be modifying this collection, we make a copy of it to iterate on IAttachedAnnotation[] list = new IAttachedAnnotation[annotations.Count]; annotations.CopyTo(list, 0); foreach (IAttachedAnnotation attachedAnnotation in list) { if (attachedAnnotation.Anchor == anchor) { DoRemoveAttachedAnnotation(attachedAnnotation); args = AttachedAnnotationChangedEventArgs.Deleted(attachedAnnotation); break; } } } return args; }
public AnnotationResourceChangedEventArgs(Annotation annotation, AnnotationAction action, AnnotationResource resource) { }