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);
        }
        // Token: 0x06006D0E RID: 27918 RVA: 0x001F5420 File Offset: 0x001F3620
        internal bool PasteData(IDataObject dataObject, ref StrokeCollection newStrokes, ref List <UIElement> newElements)
        {
            foreach (KeyValuePair <InkCanvasClipboardFormat, ClipboardData> keyValuePair in this._preferredClipboardData)
            {
                InkCanvasClipboardFormat key   = keyValuePair.Key;
                ClipboardData            value = keyValuePair.Value;
                if (value.CanPaste(dataObject))
                {
                    switch (key)
                    {
                    case InkCanvasClipboardFormat.InkSerializedFormat:
                    {
                        ISFClipboardData isfclipboardData = (ISFClipboardData)value;
                        isfclipboardData.PasteFromDataObject(dataObject);
                        newStrokes = isfclipboardData.Strokes;
                        break;
                    }

                    case InkCanvasClipboardFormat.Text:
                    {
                        TextClipboardData textClipboardData = (TextClipboardData)value;
                        textClipboardData.PasteFromDataObject(dataObject);
                        newElements = textClipboardData.Elements;
                        break;
                    }

                    case InkCanvasClipboardFormat.Xaml:
                    {
                        XamlClipboardData xamlClipboardData = (XamlClipboardData)value;
                        xamlClipboardData.PasteFromDataObject(dataObject);
                        List <UIElement> elements = xamlClipboardData.Elements;
                        if (elements != null && elements.Count != 0)
                        {
                            if (elements.Count == 1 && ClipboardProcessor.InkCanvasDType.IsInstanceOfType(elements[0]))
                            {
                                this.TearDownInkCanvasContainer((InkCanvas)elements[0], ref newStrokes, ref newElements);
                            }
                            else
                            {
                                newElements = elements;
                            }
                        }
                        break;
                    }
                    }
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The method returns the Strokes or UIElement array if there is the supported data in the IDataObject
        /// </summary>
        /// <param name="dataObject">The IDataObject instance</param>
        /// <param name="newStrokes">The strokes which are converted from the data in the IDataObject</param>
        /// <param name="newElements">The elements array which are converted from the data in the IDataObject</param>
        internal bool PasteData(IDataObject dataObject, ref StrokeCollection newStrokes, ref List <UIElement> newElements)
        {
            Debug.Assert(dataObject != null && _preferredClipboardData != null);

            // We honor the order in our preferred list.
            foreach (KeyValuePair <InkCanvasClipboardFormat, ClipboardData> pair in _preferredClipboardData)
            {
                InkCanvasClipboardFormat format = pair.Key;
                ClipboardData            data   = pair.Value;

                if (data.CanPaste(dataObject))
                {
                    switch (format)
                    {
                    case InkCanvasClipboardFormat.Xaml:
                    {
                        XamlClipboardData xamlData = (XamlClipboardData)data;
                        xamlData.PasteFromDataObject(dataObject);

                        List <UIElement> elements = xamlData.Elements;

                        if (elements != null && elements.Count != 0)
                        {
                            // If the Xaml data has been set in an InkCanvas, the top element will be a container InkCanvas.
                            // In this case, the new elements will be the children of the container.
                            // Otherwise, the new elements will be whatever data from the data object.
                            if (elements.Count == 1 && ClipboardProcessor.InkCanvasDType.IsInstanceOfType(elements[0]))
                            {
                                TearDownInkCanvasContainer((InkCanvas)(elements[0]), ref newStrokes, ref newElements);
                            }
                            else
                            {
                                // The new elements are the data in the data object.
                                newElements = elements;
                            }
                        }
                        break;
                    }

                    case InkCanvasClipboardFormat.InkSerializedFormat:
                    {
                        // Retrieve the stroke data.
                        ISFClipboardData isfData = (ISFClipboardData)data;
                        isfData.PasteFromDataObject(dataObject);

                        newStrokes = isfData.Strokes;
                        break;
                    }

                    case InkCanvasClipboardFormat.Text:
                    {
                        // Convert the text data in the data object to a text box element.
                        TextClipboardData textData = (TextClipboardData)data;
                        textData.PasteFromDataObject(dataObject);
                        newElements = textData.Elements;
                        break;
                    }
                    }

                    // Once we've done pasting, just return now.
                    return(true);
                }
            }

            // Nothing gets pasted.
            return(false);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        internal InkCanvasClipboardDataFormats CopySelectedData(IDataObject dataObject)
        {
            InkCanvasClipboardDataFormats copiedDataFormat = InkCanvasClipboardDataFormats.None;
            InkCanvasSelection inkCanvasSelection = InkCanvas.InkCanvasSelection;

            StrokeCollection strokes = inkCanvasSelection.SelectedStrokes;
            if (strokes.Count > 1)
            {
                // NTRAID#WINDOWS-1541633-2006/03/03-SAMGEO,
                // 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 )
            {
                // NTRAID-WINDOWS#1412097-2005/12/08-WAYNEZEN,
                // 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;
        }