コード例 #1
0
        // Token: 0x0600785C RID: 30812 RVA: 0x0022494C File Offset: 0x00222B4C
        private void UpdateAttribute(XmlElement root, XmlToken token, string value)
        {
            string  xmlName       = SNCAnnotation.GetXmlName(token);
            XmlNode attributeNode = root.GetAttributeNode(xmlName, "http://schemas.microsoft.com/windows/annotations/2003/11/base");

            if (attributeNode == null)
            {
                if (value == null)
                {
                    return;
                }
                root.SetAttribute(xmlName, "http://schemas.microsoft.com/windows/annotations/2003/11/base", value);
                return;
            }
            else
            {
                if (value == null)
                {
                    root.RemoveAttribute(xmlName, "http://schemas.microsoft.com/windows/annotations/2003/11/base");
                    return;
                }
                if (attributeNode.Value != value)
                {
                    root.SetAttribute(xmlName, "http://schemas.microsoft.com/windows/annotations/2003/11/base", value);
                }
                return;
            }
        }
コード例 #2
0
        // Token: 0x06007854 RID: 30804 RVA: 0x002243FC File Offset: 0x002225FC
        public static void UpdateAnnotation(XmlToken token, StickyNoteControl snc, SNCAnnotation sncAnnotation)
        {
            AnnotationService annotationService = null;
            bool autoFlush = false;

            try
            {
                annotationService = AnnotationService.GetService(((IAnnotationComponent)snc).AnnotatedElement);
                if (annotationService != null && annotationService.Store != null)
                {
                    autoFlush = annotationService.Store.AutoFlush;
                    annotationService.Store.AutoFlush = false;
                }
                if ((token & XmlToken.Ink) != (XmlToken)0 && snc.Content.Type == StickyNoteType.Ink)
                {
                    sncAnnotation.UpdateContent(snc, true, XmlToken.Ink);
                }
                if ((token & XmlToken.Text) != (XmlToken)0 && snc.Content.Type == StickyNoteType.Text)
                {
                    sncAnnotation.UpdateContent(snc, true, XmlToken.Text);
                }
                if ((token & (XmlToken.Left | XmlToken.Top | XmlToken.XOffset | XmlToken.YOffset | XmlToken.Width | XmlToken.Height | XmlToken.IsExpanded | XmlToken.Author | XmlToken.ZOrder)) != (XmlToken)0)
                {
                    SNCAnnotation.UpdateMetaData(token, snc, sncAnnotation);
                }
            }
            finally
            {
                if (annotationService != null && annotationService.Store != null)
                {
                    annotationService.Store.AutoFlush = autoFlush;
                }
            }
        }
コード例 #3
0
        // Token: 0x0600785B RID: 30811 RVA: 0x002248A0 File Offset: 0x00222AA0
        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 & (XmlToken.MetaData | XmlToken.Left | XmlToken.Top | XmlToken.XOffset | XmlToken.YOffset | XmlToken.Width | XmlToken.Height | XmlToken.IsExpanded | XmlToken.Author | XmlToken.Text | XmlToken.Ink | XmlToken.ZOrder)) > (XmlToken)0, "No token specified.");
            string cargoName = SNCAnnotation.GetCargoName(token);

            newRoot  = false;
            newCargo = false;
            cargo    = annotation.FindCargo(cargoName);
            if (cargo != null)
            {
                root = SNCAnnotation.FindRootXmlElement(token, cargo);
                if (root == null)
                {
                    newRoot = true;
                    XmlDocument xmlDocument = new XmlDocument();
                    root = xmlDocument.CreateElement(SNCAnnotation.GetXmlName(token), "http://schemas.microsoft.com/windows/annotations/2003/11/base");
                    return;
                }
            }
            else
            {
                newCargo = true;
                cargo    = new AnnotationResource(cargoName);
                XmlDocument xmlDocument2 = new XmlDocument();
                root = xmlDocument2.CreateElement(SNCAnnotation.GetXmlName(token), "http://schemas.microsoft.com/windows/annotations/2003/11/base");
                cargo.Contents.Add(root);
            }
        }
コード例 #4
0
 // Token: 0x06007851 RID: 30801 RVA: 0x0022435C File Offset: 0x0022255C
 static SNCAnnotation()
 {
     foreach (object obj in Enum.GetValues(typeof(XmlToken)))
     {
         XmlToken token = (XmlToken)obj;
         SNCAnnotation.AddXmlTokenNames(token);
     }
 }
コード例 #5
0
        // Token: 0x06007863 RID: 30819 RVA: 0x00224D80 File Offset: 0x00222F80
        private static void UpdateMetaData(XmlToken token, StickyNoteControl snc, SNCAnnotation sncAnnotation)
        {
            AnnotationResource annotationResource;
            XmlElement         xmlElement;
            bool flag;
            bool flag2;

            SNCAnnotation.GetCargoAndRoot(sncAnnotation, XmlToken.MetaData, out annotationResource, out xmlElement, out flag, out flag2);
            if ((token & XmlToken.IsExpanded) != (XmlToken)0)
            {
                bool isExpanded = snc.IsExpanded;
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.IsExpanded, isExpanded.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.Height) != (XmlToken)0)
            {
                double num = (double)snc.GetValue(FrameworkElement.HeightProperty);
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.Height, num.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.Width) != (XmlToken)0)
            {
                double num2 = (double)snc.GetValue(FrameworkElement.WidthProperty);
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.Width, num2.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.Left) != (XmlToken)0)
            {
                double num3 = snc.PositionTransform.X;
                if (snc.FlipBothOrigins)
                {
                    num3 = -(num3 + snc.Width);
                }
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.Left, num3.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.Top) != (XmlToken)0)
            {
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.Top, snc.PositionTransform.Y.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.XOffset) != (XmlToken)0)
            {
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.XOffset, snc.XOffset.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.YOffset) != (XmlToken)0)
            {
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.YOffset, snc.YOffset.ToString(CultureInfo.InvariantCulture));
            }
            if ((token & XmlToken.ZOrder) != (XmlToken)0)
            {
                sncAnnotation.UpdateAttribute(xmlElement, XmlToken.ZOrder, ((IAnnotationComponent)snc).ZOrder.ToString(CultureInfo.InvariantCulture));
            }
            if (flag2)
            {
                annotationResource.Contents.Add(xmlElement);
            }
            if (flag)
            {
                sncAnnotation._annotation.Cargos.Add(annotationResource);
            }
        }
コード例 #6
0
        // Token: 0x06007860 RID: 30816 RVA: 0x00224AE8 File Offset: 0x00222CE8
        private static XmlElement FindRootXmlElement(XmlToken token, AnnotationResource cargo)
        {
            XmlElement result = null;
            string     value  = string.Empty;

            if (token <= XmlToken.YOffset)
            {
                if (token <= XmlToken.Left)
                {
                    if (token != XmlToken.MetaData && token != XmlToken.Left)
                    {
                        goto IL_77;
                    }
                }
                else if (token != XmlToken.Top && token != XmlToken.XOffset && token != XmlToken.YOffset)
                {
                    goto IL_77;
                }
            }
            else if (token <= XmlToken.IsExpanded)
            {
                if (token != XmlToken.Width && token != XmlToken.Height && token != XmlToken.IsExpanded)
                {
                    goto IL_77;
                }
            }
            else
            {
                if (token == XmlToken.Text || token == XmlToken.Ink)
                {
                    value = SNCAnnotation.GetXmlName(token);
                    goto IL_77;
                }
                if (token != XmlToken.ZOrder)
                {
                    goto IL_77;
                }
            }
            value = SNCAnnotation.GetXmlName(XmlToken.MetaData);
IL_77:
            foreach (XmlElement xmlElement in cargo.Contents)
            {
                if (xmlElement.Name.Equals(value))
                {
                    result = xmlElement;
                    break;
                }
            }
            return(result);
        }
コード例 #7
0
        // Token: 0x06007861 RID: 30817 RVA: 0x00224BB8 File Offset: 0x00222DB8
        private static object FindContent(XmlToken token, AnnotationResource cargo)
        {
            object     result     = null;
            XmlElement xmlElement = SNCAnnotation.FindRootXmlElement(token, cargo);

            if (xmlElement != null)
            {
                if (token <= XmlToken.Width)
                {
                    if (token <= XmlToken.Top)
                    {
                        if (token != XmlToken.Left && token != XmlToken.Top)
                        {
                            return(result);
                        }
                    }
                    else if (token != XmlToken.XOffset && token != XmlToken.YOffset && token != XmlToken.Width)
                    {
                        return(result);
                    }
                }
                else if (token <= XmlToken.IsExpanded)
                {
                    if (token != XmlToken.Height && token != XmlToken.IsExpanded)
                    {
                        return(result);
                    }
                }
                else
                {
                    if (token == XmlToken.Text || token == XmlToken.Ink)
                    {
                        return(xmlElement);
                    }
                    if (token != XmlToken.ZOrder)
                    {
                        return(result);
                    }
                }
                return(xmlElement.GetAttributeNode(SNCAnnotation.GetXmlName(token), "http://schemas.microsoft.com/windows/annotations/2003/11/base"));
            }
            return(result);
        }
コード例 #8
0
        // Token: 0x0600785A RID: 30810 RVA: 0x00224848 File Offset: 0x00222A48
        private object FindData(XmlToken token)
        {
            object obj = null;

            if (this._cachedXmlElements.ContainsKey(token))
            {
                obj = this._cachedXmlElements[token];
            }
            else
            {
                AnnotationResource annotationResource = this.FindCargo(SNCAnnotation.GetCargoName(token));
                if (annotationResource != null)
                {
                    obj = SNCAnnotation.FindContent(token, annotationResource);
                    if (obj != null)
                    {
                        this._cachedXmlElements.Add(token, obj);
                    }
                }
            }
            return(obj);
        }
コード例 #9
0
 // Token: 0x06007855 RID: 30805 RVA: 0x002244C0 File Offset: 0x002226C0
 public static void UpdateStickyNoteControl(XmlToken token, StickyNoteControl snc, SNCAnnotation sncAnnotation)
 {
     Invariant.Assert((token & (XmlToken.Left | XmlToken.Top | XmlToken.XOffset | XmlToken.YOffset | XmlToken.Width | XmlToken.Height | XmlToken.IsExpanded | XmlToken.Author | XmlToken.Text | XmlToken.Ink | XmlToken.ZOrder)) > (XmlToken)0, "No token specified.");
     Invariant.Assert(snc != null, "Sticky Note Control is null.");
     Invariant.Assert(sncAnnotation != null, "Annotation is null.");
     if ((token & XmlToken.Ink) != (XmlToken)0 && sncAnnotation.HasInkData)
     {
         sncAnnotation.UpdateContent(snc, false, XmlToken.Ink);
     }
     if ((token & XmlToken.Text) != (XmlToken)0 && sncAnnotation.HasTextData)
     {
         sncAnnotation.UpdateContent(snc, false, XmlToken.Text);
     }
     if ((token & XmlToken.Author) != (XmlToken)0)
     {
         int    count         = sncAnnotation._annotation.Authors.Count;
         string listSeparator = snc.Language.GetSpecificCulture().TextInfo.ListSeparator;
         string text          = string.Empty;
         for (int i = 0; i < count; i++)
         {
             if (i != 0)
             {
                 text = text + listSeparator + sncAnnotation._annotation.Authors[i];
             }
             else
             {
                 text += sncAnnotation._annotation.Authors[i];
             }
         }
         snc.SetValue(StickyNoteControl.AuthorPropertyKey, text);
     }
     if ((token & XmlToken.Height) != (XmlToken)0)
     {
         XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.Height);
         if (xmlAttribute != null)
         {
             double num = Convert.ToDouble(xmlAttribute.Value, CultureInfo.InvariantCulture);
             snc.SetValue(FrameworkElement.HeightProperty, num);
         }
         else
         {
             snc.ClearValue(FrameworkElement.HeightProperty);
         }
     }
     if ((token & XmlToken.Width) != (XmlToken)0)
     {
         XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.Width);
         if (xmlAttribute != null)
         {
             double num2 = Convert.ToDouble(xmlAttribute.Value, CultureInfo.InvariantCulture);
             snc.SetValue(FrameworkElement.WidthProperty, num2);
         }
         else
         {
             snc.ClearValue(FrameworkElement.WidthProperty);
         }
     }
     if ((token & XmlToken.IsExpanded) != (XmlToken)0)
     {
         XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.IsExpanded);
         if (xmlAttribute != null)
         {
             bool isExpanded = Convert.ToBoolean(xmlAttribute.Value, CultureInfo.InvariantCulture);
             snc.IsExpanded = isExpanded;
         }
         else
         {
             snc.ClearValue(StickyNoteControl.IsExpandedProperty);
         }
     }
     if ((token & XmlToken.ZOrder) != (XmlToken)0)
     {
         XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.ZOrder);
         if (xmlAttribute != null)
         {
             ((IAnnotationComponent)snc).ZOrder = Convert.ToInt32(xmlAttribute.Value, CultureInfo.InvariantCulture);
         }
     }
     if ((token & (XmlToken.Left | XmlToken.Top | XmlToken.XOffset | XmlToken.YOffset)) != (XmlToken)0)
     {
         TranslateTransform translateTransform = new TranslateTransform();
         if ((token & XmlToken.Left) != (XmlToken)0)
         {
             XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.Left);
             if (xmlAttribute != null)
             {
                 double num3 = Convert.ToDouble(xmlAttribute.Value, CultureInfo.InvariantCulture);
                 if (snc.FlipBothOrigins)
                 {
                     num3 = -(num3 + snc.Width);
                 }
                 translateTransform.X = num3;
             }
         }
         if ((token & XmlToken.Top) != (XmlToken)0)
         {
             XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.Top);
             if (xmlAttribute != null)
             {
                 double y = Convert.ToDouble(xmlAttribute.Value, CultureInfo.InvariantCulture);
                 translateTransform.Y = y;
             }
         }
         if ((token & XmlToken.XOffset) != (XmlToken)0)
         {
             XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.XOffset);
             if (xmlAttribute != null)
             {
                 snc.XOffset = Convert.ToDouble(xmlAttribute.Value, CultureInfo.InvariantCulture);
             }
         }
         if ((token & XmlToken.YOffset) != (XmlToken)0)
         {
             XmlAttribute xmlAttribute = (XmlAttribute)sncAnnotation.FindData(XmlToken.YOffset);
             if (xmlAttribute != null)
             {
                 snc.YOffset = Convert.ToDouble(xmlAttribute.Value, CultureInfo.InvariantCulture);
             }
         }
         snc.PositionTransform = translateTransform;
     }
 }
コード例 #10
0
        // Token: 0x06007862 RID: 30818 RVA: 0x00224C48 File Offset: 0x00222E48
        private void UpdateContent(StickyNoteControl snc, bool updateAnnotation, XmlToken token)
        {
            Invariant.Assert(snc != null, "Sticky Note Control is null.");
            Invariant.Assert((token & (XmlToken.Text | XmlToken.Ink)) > (XmlToken)0, "No token specified.");
            StickyNoteContentControl content = snc.Content;

            if (content == null)
            {
                return;
            }
            if ((token == XmlToken.Ink && content.Type != StickyNoteType.Ink) || (token == XmlToken.Text && content.Type != StickyNoteType.Text))
            {
                return;
            }
            XmlElement xmlElement = null;

            if (updateAnnotation)
            {
                AnnotationResource annotationResource = null;
                bool flag  = false;
                bool flag2 = false;
                if (!content.IsEmpty)
                {
                    SNCAnnotation.GetCargoAndRoot(this, token, out annotationResource, out xmlElement, out flag2, out flag);
                    content.Save(xmlElement);
                }
                else
                {
                    string cargoName = SNCAnnotation.GetCargoName(token);
                    annotationResource = this.FindCargo(cargoName);
                    if (annotationResource != null)
                    {
                        this._annotation.Cargos.Remove(annotationResource);
                        this._cachedXmlElements.Remove(token);
                    }
                }
                if (flag)
                {
                    Invariant.Assert(xmlElement != null, "XmlElement should have been created.");
                    Invariant.Assert(annotationResource != null, "Cargo should have been retrieved.");
                    annotationResource.Contents.Add(xmlElement);
                }
                if (flag2)
                {
                    Invariant.Assert(annotationResource != null, "Cargo should have been created.");
                    this._annotation.Cargos.Add(annotationResource);
                    return;
                }
            }
            else
            {
                XmlElement xmlElement2 = (XmlElement)this.FindData(token);
                if (xmlElement2 != null)
                {
                    content.Load(xmlElement2);
                    return;
                }
                if (!content.IsEmpty)
                {
                    content.Clear();
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// Update the metadata tokens specified in token.
        /// </summary>
        private static void UpdateMetaData(XmlToken token, StickyNoteControl snc, SNCAnnotation sncAnnotation)
        {
            bool newCargo, newRoot;
            AnnotationResource cargo;
            XmlElement root;

            GetCargoAndRoot(sncAnnotation, XmlToken.MetaData, out cargo, out root, out newCargo, out newRoot);

            // Update Expanded
            if ((token & XmlToken.IsExpanded) != 0)
            {
                bool expanded = snc.IsExpanded;
                sncAnnotation.UpdateAttribute(root, XmlToken.IsExpanded, expanded.ToString(CultureInfo.InvariantCulture));
            }

            // Update Height
            if ((token & XmlToken.Height) != 0)
            {
                Debug.Assert(snc.IsExpanded);
                double height = (double)snc.GetValue(FrameworkElement.HeightProperty);
                sncAnnotation.UpdateAttribute(root, XmlToken.Height, height.ToString(CultureInfo.InvariantCulture));
            }

            // Update Width
            if ((token & XmlToken.Width) != 0)
            {
                Debug.Assert(snc.IsExpanded);
                double width = (double)snc.GetValue(FrameworkElement.WidthProperty);
                sncAnnotation.UpdateAttribute(root, XmlToken.Width, width.ToString(CultureInfo.InvariantCulture));
            }

            // Update Left
            if ((token & XmlToken.Left) != 0)
            {
                double left = snc.PositionTransform.X;
                // All 'left' values are persisted assuming two things:
                //  1) the top-left corner (visually) of the StickyNote is the origin of its coordinate space
                //  2) the positive x-axis of its parent is to the right
                // This flag signals that we have a positive x-axis to the left and our
                // top-right corner (visually) is our origin.  So we need to flip the
                // value before persisting it.
                if (snc.FlipBothOrigins)
                {
                    left = -(left + snc.Width);
                }
                sncAnnotation.UpdateAttribute(root, XmlToken.Left, left.ToString(CultureInfo.InvariantCulture));
            }

            // Update Top
            if ((token & XmlToken.Top) != 0)
            {
                sncAnnotation.UpdateAttribute(root, XmlToken.Top, snc.PositionTransform.Y.ToString(CultureInfo.InvariantCulture));
            }

            // Update XOffset
            if ((token & XmlToken.XOffset) != 0)
            {
                sncAnnotation.UpdateAttribute(root, XmlToken.XOffset, snc.XOffset.ToString(CultureInfo.InvariantCulture));
            }

            // Update YOffset
            if ((token & XmlToken.YOffset) != 0)
            {
                sncAnnotation.UpdateAttribute(root, XmlToken.YOffset, snc.YOffset.ToString(CultureInfo.InvariantCulture));
            }

            // Update ZOrder
            if ((token & XmlToken.ZOrder) != 0)
            {
                sncAnnotation.UpdateAttribute(root, XmlToken.ZOrder, ((IAnnotationComponent)snc).ZOrder.ToString(CultureInfo.InvariantCulture));
            }

            if (newRoot)
            {
                cargo.Contents.Add(root);
            }
            if (newCargo)
            {
                sncAnnotation._annotation.Cargos.Add(cargo);
            }
        }
コード例 #12
0
        /// <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);
            }
        }
コード例 #13
0
        /// <summary>
        /// This static method will update a StickyNoteControl object with the specified data in an Annotation
        /// </summary>
        /// <param name="token">A flag which indicates the data needs to be updated. The flag can be combinated with the any valid bits.</param>
        /// <param name="snc">A StickyNoteControl instance</param>
        /// <param name="sncAnnotation">An SNCAnnotation object which contains a CAF annotation object</param>
        public static void UpdateStickyNoteControl(XmlToken token, StickyNoteControl snc, SNCAnnotation sncAnnotation)
        {
            Invariant.Assert((token & AllValues) != 0, "No token specified.");
            Invariant.Assert(snc != null, "Sticky Note Control is null.");
            Invariant.Assert(sncAnnotation != null, "Annotation is null.");

            // 




            XmlAttribute node;

            // Update Ink
            if ((token & XmlToken.Ink) != 0 && sncAnnotation.HasInkData)
            {
                sncAnnotation.UpdateContent(snc, false, XmlToken.Ink);
            }

            // Update Text
            if ((token & XmlToken.Text) != 0 && sncAnnotation.HasTextData)
            {
                sncAnnotation.UpdateContent(snc, false, XmlToken.Text);
            }

            // Update Author
            if ((token & XmlToken.Author) != 0)
            {
                int nCount = sncAnnotation._annotation.Authors.Count;
                // Get the culture specific text separator.
                string listSeparator = snc.Language.GetSpecificCulture().TextInfo.ListSeparator;
                string authors = string.Empty;
                for (int i = 0; i < nCount; i++)
                {
                    if (i != 0)
                    {
                        authors += listSeparator + sncAnnotation._annotation.Authors[i];
                    }
                    else
                    {
                        authors += sncAnnotation._annotation.Authors[i];
                    }
                }

                // Setting the author property will cause the UI to update
                snc.SetValue(StickyNoteControl.AuthorPropertyKey, authors);
            }

            // Update Height
            if ((token & XmlToken.Height) != 0)
            {
                node = (XmlAttribute)sncAnnotation.FindData(XmlToken.Height);
                if (node != null)
                {
                    double height = Convert.ToDouble(node.Value, CultureInfo.InvariantCulture);
                    snc.SetValue(FrameworkElement.HeightProperty, height);
                }
                else
                {
                    snc.ClearValue(FrameworkElement.HeightProperty);
                }
            }

            // Update Width
            if ((token & XmlToken.Width) != 0)
            {
                node = (XmlAttribute)sncAnnotation.FindData(XmlToken.Width);
                if (node != null)
                {
                    double width = Convert.ToDouble(node.Value, CultureInfo.InvariantCulture);
                    snc.SetValue(FrameworkElement.WidthProperty, width);
                }
                else
                {
                    snc.ClearValue(FrameworkElement.WidthProperty);
                }
            }

            // Update IsExpanded
            if ((token & XmlToken.IsExpanded) != 0)
            {
                node = (XmlAttribute)sncAnnotation.FindData(XmlToken.IsExpanded);
                if (node != null)
                {
                    bool expanded = Convert.ToBoolean(node.Value, CultureInfo.InvariantCulture);
                    snc.IsExpanded = expanded;
                }
                else
                {
                    snc.ClearValue(StickyNoteControl.IsExpandedProperty);
                }
            }

            // Update ZOrder
            if ((token & XmlToken.ZOrder) != 0)
            {
                node = (XmlAttribute)sncAnnotation.FindData(XmlToken.ZOrder);
                if (node != null)
                {
                    ((IAnnotationComponent)snc).ZOrder = Convert.ToInt32(node.Value, CultureInfo.InvariantCulture);
                }
            }

            // Update Position
            if ((token & PositionValues) != 0)
            {
                TranslateTransform transform = new TranslateTransform();
                if ((token & XmlToken.Left) != 0)
                {
                    node = (XmlAttribute)sncAnnotation.FindData(XmlToken.Left);
                    if (node != null)
                    {
                        double left = Convert.ToDouble(node.Value, CultureInfo.InvariantCulture);
                        // All 'left' values are persisted assuming two things:
                        //  1) the top-left corner (visually) of the StickyNote is the origin of its coordinate space
                        //  2) the positive x-axis of its parent is to the right
                        // This flag signals that we have a positive x-axis to the left and our
                        // top-right corner (visually) is our origin.  So we need to flip the
                        // value before using it.
                        if (snc.FlipBothOrigins)
                        {
                            left = -(left + snc.Width);
                        }
                        transform.X = left;
                    }
                }

                if ((token & XmlToken.Top) != 0)
                {
                    node = (XmlAttribute)sncAnnotation.FindData(XmlToken.Top);
                    if (node != null)
                    {
                        double top = Convert.ToDouble(node.Value, CultureInfo.InvariantCulture);
                        transform.Y = top;
                    }
                }

                // Now, we update the StickyNote offset
                if ((token & XmlToken.XOffset) != 0)
                {
                    node = (XmlAttribute)sncAnnotation.FindData(XmlToken.XOffset);
                    if (node != null)
                    {
                        snc.XOffset = Convert.ToDouble(node.Value, CultureInfo.InvariantCulture);
                    }
                }

                if ((token & XmlToken.YOffset) != 0)
                {
                    node = (XmlAttribute)sncAnnotation.FindData(XmlToken.YOffset);
                    if (node != null)
                    {
                        snc.YOffset = Convert.ToDouble(node.Value, CultureInfo.InvariantCulture);
                    }
                }

                // Set the adorner layer transform.
                snc.PositionTransform = transform;
            }
        }
コード例 #14
0
        /// <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);
            }
        }
コード例 #15
0
        // A registered handler for a bubble listening to the annotation store update event.
        //     obj  -   The sender of the event
        //     args -   event arguement
        private void OnAnnotationUpdated(object obj, AnnotationResourceChangedEventArgs args)
        {
            Debug.Assert(_attachedAnnotation != null && _attachedAnnotation.Annotation == args.Annotation);

            if (!InternalLocker.IsLocked(LockHelper.LockFlag.AnnotationChanged))
            {
                SNCAnnotation sncAnnotation = new SNCAnnotation(args.Annotation);
                _sncAnnotation = sncAnnotation;
                UpdateSNCWithAnnotation(SNCAnnotation.AllValues);
                IsDirty = true;
            }
        }
コード例 #16
0
        //-------------------------------------------------------------------------------
        //
        // Public Methods
        //
        //-------------------------------------------------------------------------------

        #region Public Methods

        /// <summary>
        /// This static method will update an Annotation object with the specified data in a StickyNoteControl
        /// </summary>
        /// <param name="token">A flag which indicates the data needs to be updated. The flag can be combinated with the any valid bits.</param>
        /// <param name="snc">A StickyNoteControl instance</param>
        /// <param name="sncAnnotation">An SNCAnnotation object which contains a CAF annotation object</param>
        public static void UpdateAnnotation(XmlToken token, StickyNoteControl snc, SNCAnnotation sncAnnotation)
        {
            AnnotationService service = null;
            bool autoFlush = false;
            try
            {
                service = AnnotationService.GetService(((IAnnotationComponent)snc).AnnotatedElement);
                if (service != null && service.Store != null)
                {
                    autoFlush = service.Store.AutoFlush;
                    // Temporarily turn off autoflush until we are done
                    // updating all the necessary values
                    service.Store.AutoFlush = false;
                }

                Debug.Assert((token & AllValues) != 0);

                // Update Ink
                if ((token & XmlToken.Ink) != 0 && snc.Content.Type == StickyNoteType.Ink)
                {
                    sncAnnotation.UpdateContent(snc, true, XmlToken.Ink);
                }

                // Update Text
                if ((token & XmlToken.Text) != 0 && snc.Content.Type == StickyNoteType.Text)
                {
                    sncAnnotation.UpdateContent(snc, true, XmlToken.Text);
                }


                // Update MetaData
                if ((token & NegativeAllContents) != 0)
                {
                    UpdateMetaData(token, snc, sncAnnotation);
                }
            }
            finally
            {
                if (service != null && service.Store != null)
                {
                    // If auto flush was true before, setting it to true again should cause a flush.
                    service.Store.AutoFlush = autoFlush;
                }
            }
        }