示例#1
0
        /// <summary>
        /// Private helper to used to determine if the current selection
        /// is different than the selection passed
        /// </summary>
        /// <param name="strokes">strokes</param>
        /// <param name="strokesAreDifferent">strokesAreDifferent</param>
        /// <param name="elements">elements</param>
        /// <param name="elementsAreDifferent">elementsAreDifferent</param>
        internal void SelectionIsDifferentThanCurrent(StrokeCollection strokes,
                                                      out bool strokesAreDifferent,
                                                      IList <UIElement> elements,
                                                      out bool elementsAreDifferent)
        {
            strokesAreDifferent  = false;
            elementsAreDifferent = false;

            if (SelectedStrokes.Count == 0)
            {
                if (strokes.Count > 0)
                {
                    strokesAreDifferent = true;
                }
            }
            else if (!InkCanvasSelection.StrokesAreEqual(SelectedStrokes, strokes))
            {
                strokesAreDifferent = true;
            }

            if (SelectedElements.Count == 0)
            {
                if (elements.Count > 0)
                {
                    elementsAreDifferent = true;
                }
            }
            else if (!InkCanvasSelection.FrameworkElementArraysAreEqual(elements, SelectedElements))
            {
                elementsAreDifferent = true;
            }
        }
示例#2
0
        //-------------------------------------------------------------------------------
        //
        // Private Methods
        //
        //-------------------------------------------------------------------------------

        #region Private Methods

        /// <summary>
        /// Copy the current Selection in XAML format.
        /// Called by :
        ///             CopySelectedData
        /// </summary>
        /// <param name="dataObject"></param>
        /// <param name="strokes"></param>
        /// <param name="elements"></param>
        /// <param name="transform"></param>
        /// <param name="size"></param>
        /// <returns>True if the copy is succeeded</returns>
        private bool CopySelectionInXAML(IDataObject dataObject, StrokeCollection strokes, List <UIElement> elements, Matrix transform, Size size)
        {
            InkCanvas inkCanvas = new InkCanvas();

            // We already transform the Strokes in CopySelectedData.
            if (strokes.Count != 0)
            {
                inkCanvas.Strokes = strokes;
            }

            int elementCount = elements.Count;

            if (elementCount != 0)
            {
                InkCanvasSelection inkCanvasSelection = InkCanvas.InkCanvasSelection;

                for (int i = 0; i < elementCount; i++)
                {
                    // NOTICE-2005/05/05-WAYNEZEN,
                    // An element can't be added to two visual trees.
                    // So, we cannot add the elements to the new container since they have been added to the current InkCanvas.
                    // Here we have to do is according to the suggestion from Avalon team -
                    //      1. Presist the elements to Xaml
                    //      2. Load the xaml to create the new instances of the elements.
                    //      3. Add the new instances to the new container.
                    string xml = XamlWriter.Save(elements[i]);

                    UIElement newElement = XamlReader.Load(new XmlTextReader(new StringReader(xml))) as UIElement;
                    ((IAddChild)inkCanvas).AddChild(newElement);

                    // Now we tranform the element.
                    inkCanvasSelection.UpdateElementBounds(elements[i], newElement, transform);
                }
            }

            if (inkCanvas != null)
            {
                inkCanvas.Width  = size.Width;
                inkCanvas.Height = size.Height;

                ClipboardData data = new XamlClipboardData(new UIElement[] { inkCanvas });

                try
                {
                    data.CopyToDataObject(dataObject);
                }
                catch (SecurityException)
                {
                    // If we hit a SecurityException under the PartialTrust, we should just fail the copy
                    // operation.
                    inkCanvas = null;
                }
            }

            return(inkCanvas != null);
        }
        private bool CopySelectionInXAML(IDataObject dataObject, StrokeCollection strokes, List <UIElement> elements, Matrix transform, Size size)
        {
            if (!SecurityHelper.CheckUnmanagedCodePermission())
            {
                return(false);
            }
            InkCanvas inkCanvas = new InkCanvas();

            if (strokes.Count != 0)
            {
                inkCanvas.Strokes = strokes;
            }
            int count = elements.Count;

            if (count != 0)
            {
                InkCanvasSelection inkCanvasSelection = this.InkCanvas.InkCanvasSelection;
                for (int i = 0; i < count; i++)
                {
                    try
                    {
                        string    s         = XamlWriter.Save(elements[i]);
                        UIElement uielement = XamlReader.Load(new XmlTextReader(new StringReader(s))) as UIElement;
                        ((IAddChild)inkCanvas).AddChild(uielement);
                        inkCanvasSelection.UpdateElementBounds(elements[i], uielement, transform);
                    }
                    catch (SecurityException)
                    {
                        inkCanvas = null;
                        break;
                    }
                }
            }
            if (inkCanvas != null)
            {
                inkCanvas.Width  = size.Width;
                inkCanvas.Height = size.Height;
                ClipboardData clipboardData = new XamlClipboardData(new UIElement[]
                {
                    inkCanvas
                });
                try
                {
                    clipboardData.CopyToDataObject(dataObject);
                }
                catch (SecurityException)
                {
                    inkCanvas = null;
                }
            }
            return(inkCanvas != null);
        }
        internal InkCanvasClipboardDataFormats CopySelectedData(IDataObject dataObject)
        {
            InkCanvasClipboardDataFormats inkCanvasClipboardDataFormats = InkCanvasClipboardDataFormats.None;
            InkCanvasSelection            inkCanvasSelection            = this.InkCanvas.InkCanvasSelection;
            StrokeCollection strokeCollection = inkCanvasSelection.SelectedStrokes;

            if (strokeCollection.Count > 1)
            {
                StrokeCollection strokeCollection2 = new StrokeCollection();
                StrokeCollection strokes           = this.InkCanvas.Strokes;
                int num = 0;
                while (num < strokes.Count && strokeCollection.Count != strokeCollection2.Count)
                {
                    for (int i = 0; i < strokeCollection.Count; i++)
                    {
                        if (strokes[num] == strokeCollection[i])
                        {
                            strokeCollection2.Add(strokeCollection[i]);
                            break;
                        }
                    }
                    num++;
                }
                strokeCollection = strokeCollection2.Clone();
            }
            else
            {
                strokeCollection = strokeCollection.Clone();
            }
            List <UIElement> list            = new List <UIElement>(inkCanvasSelection.SelectedElements);
            Rect             selectionBounds = inkCanvasSelection.SelectionBounds;

            if (strokeCollection.Count != 0 || list.Count != 0)
            {
                Matrix identity = Matrix.Identity;
                identity.OffsetX = -selectionBounds.Left;
                identity.OffsetY = -selectionBounds.Top;
                if (strokeCollection.Count != 0)
                {
                    inkCanvasSelection.TransformStrokes(strokeCollection, identity);
                    ClipboardData clipboardData = new ISFClipboardData(strokeCollection);
                    clipboardData.CopyToDataObject(dataObject);
                    inkCanvasClipboardDataFormats |= InkCanvasClipboardDataFormats.ISF;
                }
                if (this.CopySelectionInXAML(dataObject, strokeCollection, list, identity, selectionBounds.Size))
                {
                    inkCanvasClipboardDataFormats |= InkCanvasClipboardDataFormats.XAML;
                }
            }
            return(inkCanvasClipboardDataFormats);
        }
示例#5
0
        // Token: 0x06006D8B RID: 28043 RVA: 0x001F7600 File Offset: 0x001F5800
        private void MoveSelection(Rect previousRect, Rect newRect)
        {
            Matrix            matrix           = InkCanvasSelection.MapRectToRect(newRect, previousRect);
            int               count            = this.SelectedElements.Count;
            IList <UIElement> selectedElements = this.SelectedElements;

            for (int i = 0; i < count; i++)
            {
                this.UpdateElementBounds(selectedElements[i], matrix);
            }
            if (this.SelectedStrokes.Count > 0)
            {
                this.TransformStrokes(this.SelectedStrokes, matrix);
                this._areStrokesChanged = true;
            }
            if (this.SelectedElements.Count == 0)
            {
                this.UpdateSelectionAdorner();
            }
            this._inkCanvas.BringIntoView(newRect);
        }
示例#6
0
        /// <summary>
        /// Private helper that moves all selected elements from the previous location
        /// to the new one
        /// </summary>
        /// <param name="previousRect"></param>
        /// <param name="newRect"></param>
        private void MoveSelection(Rect previousRect, Rect newRect)
        {
            //
            // compute our transform, but first remove our artificial border
            //
            Matrix matrix = InkCanvasSelection.MapRectToRect(newRect, previousRect);

            //
            // transform the elements
            //
            int count = SelectedElements.Count;
            IList <UIElement> elements = SelectedElements;

            for (int i = 0; i < count; i++)
            {
                UpdateElementBounds(elements[i], matrix);
            }

            //
            // transform the strokes
            //
            if (SelectedStrokes.Count > 0)
            {
                TransformStrokes(SelectedStrokes, matrix);
                // Flag the change
                _areStrokesChanged = true;
            }

            if (SelectedElements.Count == 0)
            {
                // If there is no element in the current selection, the inner canvas won't have layout changes.
                // So there is no LayoutUpdated event. We have to manually update the selection bounds.
                UpdateSelectionAdorner();
            }

            // NTRAID:WINDOWSOS#1565058-2006/03/20-WAYNEZEN,
            // Always bring the new selection rectangle into the current view when the InkCanvas is hosted inside a ScrollViewer.
            _inkCanvas.BringIntoView(newRect);
        }
示例#7
0
        /// <summary>
        /// The method copies the current selection to the IDataObject if there is any
        /// Called by :
        ///             InkCanvas.CopyToDataObject
        /// </summary>
        /// <param name="dataObject">The IDataObject instance</param>
        /// <returns>true if there is data being copied. Otherwise return false</returns>
        internal InkCanvasClipboardDataFormats CopySelectedData(IDataObject dataObject)
        {
            InkCanvasClipboardDataFormats copiedDataFormat   = InkCanvasClipboardDataFormats.None;
            InkCanvasSelection            inkCanvasSelection = InkCanvas.InkCanvasSelection;

            StrokeCollection strokes = inkCanvasSelection.SelectedStrokes;

            if (strokes.Count > 1)
            {
                //
                // order the strokes so they are in the correct z-order
                // they appear in on the InkCanvas, or else they will be inconsistent
                // if copied / pasted
                StrokeCollection orderedStrokes   = new StrokeCollection();
                StrokeCollection inkCanvasStrokes = InkCanvas.Strokes; //cache to avoid multiple property gets
                for (int i = 0; i < inkCanvasStrokes.Count && strokes.Count != orderedStrokes.Count; i++)
                {
                    for (int j = 0; j < strokes.Count; j++)
                    {
                        if (inkCanvasStrokes[i] == strokes[j])
                        {
                            orderedStrokes.Add(strokes[j]);
                            break;
                        }
                    }
                }

                Debug.Assert(inkCanvasSelection.SelectedStrokes.Count == orderedStrokes.Count);
                //Make a copy collection since we will alter the transform before copying the data.
                strokes = orderedStrokes.Clone();
            }
            else
            {
                //we only have zero or one stroke so we don't need to order, but we
                //do need to clone.
                strokes = strokes.Clone();
            }

            List <UIElement> elements = new List <UIElement>(inkCanvasSelection.SelectedElements);
            Rect             bounds   = inkCanvasSelection.SelectionBounds;

            // Now copy the selection in the below orders.
            if (strokes.Count != 0 || elements.Count != 0)
            {
                //
                // The selection should be translated to the origin (0, 0) related to its bounds.
                // Get the translate transform as a relative bounds.
                Matrix transform = Matrix.Identity;
                transform.OffsetX = -bounds.Left;
                transform.OffsetY = -bounds.Top;

                // Add ISF data first.
                if (strokes.Count != 0)
                {
                    // Transform the strokes first.
                    inkCanvasSelection.TransformStrokes(strokes, transform);

                    ClipboardData data = new ISFClipboardData(strokes);
                    data.CopyToDataObject(dataObject);
                    copiedDataFormat |= InkCanvasClipboardDataFormats.ISF;
                }

                // Then add XAML data.
                if (CopySelectionInXAML(dataObject, strokes, elements, transform, bounds.Size))
                {
                    // We have to create an InkCanvas as a container and add all the selection to it.
                    copiedDataFormat |= InkCanvasClipboardDataFormats.XAML;
                }
            }
            else
            {
                Debug.Assert(false, "CopySelectData: InkCanvas should have a selection!");
            }

            return(copiedDataFormat);
        }