Esempio n. 1
0
        protected static bool HasUrl(DataObjectMeister data)
        {
            // Firefox places Urldata on the clipboard when copying HTML selections. As a result
            // we need to ignore the urldata if there is html data and let the htmldata fall through
            if (data.HTMLData != null)
                return false;

            return (data.URLData != null || IsTextUrl(GetText(data)));
        }
Esempio n. 2
0
 protected static string ExtractUrl(DataObjectMeister data)
 {
     if (data.URLData != null)
         return data.URLData.URL;
     else if (IsTextUrl(GetText(data)))
         return data.TextData.Text;
     else
         return null;
 }
Esempio n. 3
0
 protected static string ExtractTitle(DataObjectMeister data)
 {
     if (data.URLData != null)
         return data.URLData.Title;
     else if (IsTextUrl(GetText(data)))
         return data.TextData.Text; //note: don't use TextData.Title as it returns a truncated string (bug 328059)
     else
         return null;
 }
Esempio n. 4
0
        private static string GetText(DataObjectMeister data)
        {
            string text = null;
            if (data != null && data.TextData != null)
                text = data.TextData.Text;

            if (text == null)
                text = string.Empty;

            return text;
        }
        /// <summary>
        /// Check whether we can create a handler from the passed context/meister
        /// </summary>
        /// <param name="dataMeister">data object meister</param>
        /// <returns>true if can create from, otherwise false</returns>
        public bool CanCreateFrom(DataObjectMeister dataMeister)
        {
            // cycle through our registered handlers and see if anyone can create from the data object
            foreach (IDataFormatHandlerFactory handlerFactory in GetDataFormatHandlers())
            {
                try
                {
                    // check if the handler can convert/handle the data
                    if (handlerFactory.CanCreateFrom(dataMeister))
                        return true;
                }
                catch (Exception e)
                {
                    Debug.Fail(String.Format(CultureInfo.InvariantCulture, "Unexpected error querying data format handler factory {0}: {1}", handlerFactory.GetType().Name, e.Message));
                }
            }

            // no-one could create from this data object, return false
            return false;
        }
Esempio n. 6
0
        /// <summary>
        /// Is there URL data in the passed data object?
        /// </summary>
        /// <param name="data">data</param>
        /// <returns>true if there is url data, else false</returns>
        public static bool CanCreateFrom(DataObjectMeister data)
        {
            // see if there are files at the top-level of the file data
            FileData fileData = data.FileData;
            if (fileData != null && fileData.Files.Length > 0)
            {
                // if there are any directories in the file data then we can't create from
                foreach (FileItem file in fileData.Files)
                {
                    if (file.IsDirectory)
                        return false;
                }

                // no directories found, we can create
                return true;
            }
            else  // no file data
            {
                return false;
            }
        }
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM.PASTE)
            {
                try
                {
                    IDataObject dataObject = Clipboard.GetDataObject();
                    if (dataObject != null)
                    {
                        DataObjectMeister meister = new DataObjectMeister(Clipboard.GetDataObject());

                        // if there is no text data then surpress paste
                        if (meister.TextData == null)
                            return;

                        // if the text-data can't be parsed into an integer then supress paste
                        try
                        {
                            int.Parse(meister.TextData.Text, CultureInfo.InvariantCulture);
                        }
                        catch
                        {
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.Fail("Unexpected exception filtering WM_PASTE: " + ex.ToString());
                    return;
                }
            }

            // default processing
            base.WndProc(ref m);
        }
 public DataFormatHandler CreateFrom(DataObjectMeister dataMeister, DataFormatHandlerContext handlerContext)
 {
     return dataFormatRegistry.CreateFrom(dataMeister, handlerContext);
 }
 protected virtual bool CanCreateUrlFormatHandler(DataObjectMeister dataObject)
 {
     return editorContext.MarshalUrlSupported && UrlHandler.CanCreateFrom(dataObject);
 }
 /// <summary>
 /// Is there text data in the passed data object?
 /// </summary>
 /// <param name="data">data</param>
 /// <returns>true if there is text data, else false</returns>
 public static bool CanCreateFrom(DataObjectMeister data)
 {
     return data.TextData != null;
 }
 public new static bool CanCreateFrom(DataObjectMeister data)
 {
     return IsPasteFromSharedCanvas(data) && (GetSourceTable(data) != null);
 }
 /// <summary>
 /// Constructor for data format handlers.
 /// </summary>
 /// <param name="dataObject"></param>
 protected DataFormatHandler(DataObjectMeister dataObject, DataFormatHandlerContext handlerContext)
 {
     this.dataMeister = dataObject;
     this.handlerContext = handlerContext;
 }
        /// <summary>
        /// Create a data format handler
        /// </summary>
        /// <param name="dataMeister">data to handle</param>
        /// <returns>new data format handler (or null if none could be created)</returns>
        public virtual DataFormatHandler CreateFrom(DataObjectMeister dataMeister, DataFormatHandlerContext handlerContext)
        {
            // cycle through our registered handlers and see who wants it
            foreach (IDataFormatHandlerFactory handlerFactory in GetDataFormatHandlers())
            {
                // check if the handler can convert/handle the data
                if (handlerFactory.CanCreateFrom(dataMeister))
                {
                    // create a data format handler and return it
                    DataFormatHandler dataFormatHandler = handlerFactory.CreateFrom(dataMeister, handlerContext);
                    return dataFormatHandler;
                }
            }

            // nobody wanted it!
            return null;
        }
 public virtual bool CanCreateFrom(DataObjectMeister data)
 {
     return dataFormatRegistry.CanCreateFrom(data);
 }
 protected virtual bool CanCreateHtmlFormatHandler(DataObjectMeister dataObject)
 {
     return (editorContext.MarshalHtmlSupported || editorContext.MarshalTextSupported) && HtmlHandler.CanCreateFrom(dataObject);
 }
Esempio n. 16
0
 public FileHandler(DataObjectMeister dataObject, DataFormatHandlerContext handlerContext, IHtmlMarshallingTarget editorContext)
     : base(dataObject, handlerContext, editorContext)
 {
 }
 protected virtual DataFormatHandler CreateImageOnlyHtmlDataFormatHandler(DataObjectMeister dataMeister, DataFormatHandlerContext handlerContext)
 {
     return new ImageOnlyHtmlHandler(dataMeister, handlerContext, editorContext);
 }
Esempio n. 18
0
 public virtual bool CanDrop(IHTMLElement scope, DataObjectMeister meister)
 {
     return false;
 }
Esempio n. 19
0
        private void PasteOverSelection(IHtmlEditorSelection selection)
        {
            if (!IsValidContentInsertionPoint(selection.SelectedMarkupRange))
                return;

            try
            {
                // get the current contents of the clipboard
                DataObjectMeister clipboardMeister = new DataObjectMeister(Clipboard.GetDataObject());

                // see if one of our data handlers wants to handle the paste
                using (DataFormatHandler dataFormatHandler = DataFormatHandlerFactory.CreateFrom(clipboardMeister, DataFormatHandlerContext.ClipboardPaste))
                {
                    if (dataFormatHandler != null)
                    {
                        using (new WaitCursor())
                        {
                            // get selection
                            MarkupRange selectionRange = selection.SelectedMarkupRange.Clone();
                            selectionRange.Start.Cling = false;
                            selectionRange.Start.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Left;
                            selectionRange.End.Cling = false;
                            selectionRange.End.Gravity = _POINTER_GRAVITY.POINTER_GRAVITY_Right;

                            // do the paste
                            dataFormatHandler.InsertData(DataAction.Copy, selectionRange.Start, selectionRange.End);

                            MarkupRange newMarkUpRange = MarkupServices.CreateMarkupRange(selectionRange.End.Clone(), selectionRange.End.Clone());
                            MarkupPointerMoveHelper.DriveSelectionToLogicalPosition(newMarkUpRange, PostBodyElement, false);

                            // update selection
                            selectionRange.Start.MoveToPointer(newMarkUpRange.Start);
                            selectionRange.End.MoveToPointer(newMarkUpRange.Start);
                            selectionRange.ToTextRange().select();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //avoid throwing up error dialogs if paste fails.
                Trace.Fail("failed to paste content: " + ex.Message, ex.StackTrace);
            }
        }
Esempio n. 20
0
        void IHtmlEditorCommandSource.PasteSpecial()
        {
            using (new WaitCursor())
            {
                DataObjectMeister dataObject = new DataObjectMeister(Clipboard.GetDataObject());
                string html, baseUrl;
                if (dataObject.HTMLData != null)
                {
                    html = dataObject.HTMLData.HTMLSelection;
                    baseUrl = UrlHelper.GetBaseUrl(dataObject.HTMLData.SourceURL);
                    using (PasteSpecialForm pasteSpecialForm = new PasteSpecialForm())
                    {
                        if (pasteSpecialForm.ShowDialog(_mainFrameWindow) == DialogResult.OK)
                        {
                            PasteSpecialForm.PasteType formatting = pasteSpecialForm.ChosenFormatting;

                            switch (formatting)
                            {
                                //this is just the standard paste
                                case PasteSpecialForm.PasteType.Standard:
                                    using (ApplicationPerformance.LogEvent("StandardHtmlPasteSpecial"))
                                    {
                                        //special case: paste from within writer--standard paste
                                        //keeps formatting, and we want to thin
                                        if (HtmlHandler.IsPasteFromSharedCanvas(dataObject))
                                        {
                                            html = HtmlCleaner.CleanupHtml(html, baseUrl, true, false);
                                            break;
                                        }
                                        Paste();
                                    }
                                    return;
                                //just strip any scripts
                                case PasteSpecialForm.PasteType.KeepFormatting:
                                    using (ApplicationPerformance.LogEvent("KeepFormattingHtmlPasteSpecial"))
                                    {
                                        PasteKeepFormatting();
                                        return;
                                    }
                                //remove all formatting except for line breaks
                                case PasteSpecialForm.PasteType.RemoveFormatting:
                                    using (ApplicationPerformance.LogEvent("RemoveFormattingHtmlPasteSpecial"))
                                        html = HtmlCleaner.CleanupHtml(html, baseUrl, true, true, false);
                                    break;
                            }
                            html = UnsafeHtmlFragmentHelper.SterilizeHtml(html, UnsafeHtmlFragmentHelper.Flag.RemoveDocumentTags);
                            using (IUndoUnit undo = CreateUndoUnit())
                            {
                                InsertHtml(html, true);
                                undo.Commit();
                            }
                        }
                    }

                }
                else if (dataObject.TextData != null)
                {
                    html = dataObject.TextData.Text;
                    using (PasteSpecialFormText pasteSpecialForm = new PasteSpecialFormText())
                    {
                        if (pasteSpecialForm.ShowDialog(_mainFrameWindow) == DialogResult.OK)
                        {
                            PasteSpecialFormText.PasteType formatting = pasteSpecialForm.ChosenFormatting;

                            switch (formatting)
                            {
                                //this is just the standard paste
                                case PasteSpecialFormText.PasteType.Standard:
                                    using (ApplicationPerformance.LogEvent("StandardTextPasteSpecial"))
                                    using (IUndoUnit undo = CreateUndoUnit())
                                    {
                                        string htmlFromText = TextHelper.GetHTMLFromText(html, true, this.DefaultBlockElement);
                                        InsertHtml(htmlFromText, true);
                                        undo.Commit();
                                    }
                                    break;
                                //insert as is
                                case PasteSpecialFormText.PasteType.KeepFormatting:
                                    using (ApplicationPerformance.LogEvent("TextAsHtmlPasteSpecial"))
                                    {
                                        using (IUndoUnit undo = CreateUndoUnit())
                                        {
                                            html = HtmlCleaner.PreserveFormatting(html, String.Empty);
                                            InsertHtml(html, true);
                                            undo.Commit();
                                        }
                                    }
                                    break;
                            }
                        }
                    }

                }
                else
                {
                    //non html or text data on clipboard--file, etc.
                    DisplayMessage.Show(MessageId.PasteSpecialInvalidData, _mainFrameWindow);
                }
            }
        }
 protected virtual bool CanCreateImageOnlyHtmlFormatHandler(DataObjectMeister dataObject)
 {
     return editorContext.MarshalImagesSupported && ImageOnlyHtmlHandler.CanCreateFrom(dataObject);
 }
        private static IHTMLTable GetSourceTable(DataObjectMeister dataMeister)
        {
            // find our post body div
            IHTMLElement body = GetPostBodyElement(dataMeister.HTMLData.HTMLDocument);

            // look for a single table which constitutes the entire selection
            if (body != null)
            {
                IHTMLElementCollection tables = (body as IHTMLElement2).getElementsByTagName("table");
                if (tables.length >= 1)
                {
                    IHTMLElement table = tables.item(0, 0) as IHTMLElement;
                    if (table.innerText == (body as IHTMLElement).innerText)
                    {
                        if (TableHelper.TableElementIsEditable(table))
                        {
                            return table as IHTMLTable;
                        }
                    }
                }
            }

            // didn't find a single table
            return null;
        }
 protected virtual bool CanCreateFileFormatHandler(DataObjectMeister dataObject)
 {
     return editorContext.MarshalFilesSupported && FileHandler.CanCreateFrom(dataObject);
 }
 public bool CanCreateFrom(DataObjectMeister data)
 {
     return _filter(data);
 }
 protected virtual bool CanCreateTextFormatHandler(DataObjectMeister dataObject)
 {
     return editorContext.MarshalTextSupported && PlainTextHandler.CanCreateFrom(dataObject);
 }
 public DataFormatHandler CreateFrom(DataObjectMeister dataMeister, DataFormatHandlerContext handlerContext)
 {
     DataFormatHandler dataFormatHandler;
     dataFormatHandler = Activator.CreateInstance(_dataFormatHandlerType) as DataFormatHandler;
     return dataFormatHandler;
 }
 protected virtual DataFormatHandler CreateTextDataFormatHandler(DataObjectMeister dataMeister, DataFormatHandlerContext handlerContext)
 {
     return new PlainTextHandler(dataMeister, handlerContext, editorContext);
 }
Esempio n. 28
0
 public UrlHandler(DataObjectMeister dataObject, DataFormatHandlerContext handlerContext, IHtmlMarshallingTarget editorContext)
     : base(dataObject, handlerContext, editorContext)
 {
     _url = ExtractUrl(dataObject);
     _title = ExtractTitle(dataObject);
 }
Esempio n. 29
0
 /// <summary>
 /// Is there URL data in the passed data object?
 /// </summary>
 /// <param name="data">data</param>
 /// <returns>true if there is url data, else false</returns>
 public static bool CanCreateFrom(DataObjectMeister data)
 {
     return HasUrl(data);
 }
 protected FreeTextHandler(DataObjectMeister dataObject, DataFormatHandlerContext handlerContext, IHtmlMarshallingTarget editorContext)
     : base(dataObject, handlerContext, editorContext)
 {
     caretPointer = editorContext.MarkupServices.CreateMarkupPointer();
 }