/// <summary>
        /// Attempts to create a new HTMLData.  This can return null if the DataObject
        /// couldn't be created based upon the IDataObject.
        /// </summary>
        /// <param name="iDataObject">The IDataObject from which to create the HTML Data Object</param>
        /// <returns>The HTMLData, null if it couldn't be created.</returns>
        public static HTMLData Create(IDataObject iDataObject)
        {
            string[] loser = iDataObject.GetFormats();

            if (OleDataObjectHelper.GetDataPresentSafe(iDataObject, DataFormats.Html))
            {
                try
                {
                    HTMLData data = new HTMLData(iDataObject, null);
                    return(string.IsNullOrEmpty(data.HTML) ? null : data);
                }
                catch (FormatException)
                {
                    // EML files with HTML inside of them report that they are HTML
                    // However, when we try to read the format, we have problems reading it
                    // So we will skip loading html that we cannot load
                    return(null);
                }
            }
            else if (HtmlDocumentClassFormatPresent(iDataObject))
            {
                return(new HTMLData(iDataObject, (IHTMLDocument2)iDataObject.GetData(typeof(HTMLDocumentClass))));
            }
            else
            {
                return(null);
            }
        }
 /// <summary>
 /// Creates an ImageData
 /// </summary>
 /// <param name="iDataObject">The IDataObject from which to create the ImageData</param>
 /// <returns>The ImageData, null if no ImageData could be created</returns>
 public static ImageData Create(IDataObject iDataObject)
 {
     if (!OleDataObjectHelper.GetDataPresentSafe(iDataObject, DataFormats.Dib) && !OleDataObjectHelper.GetDataPresentSafe(iDataObject, DataFormats.EnhancedMetafile))
     {
         return(null);
     }
     else
     {
         return(new ImageData(iDataObject));
     }
 }
        public static LightWeightHTMLDocumentData Create(IDataObject iDataObject)
        {
            string[] loser = iDataObject.GetFormats();

            if (OleDataObjectHelper.GetDataPresentSafe(iDataObject, LightWeightHTMLDataObject.LIGHTWEIGHTHTMLDOCUMENTFORMAT))
            {
                LightWeightHTMLDocument document = (LightWeightHTMLDocument)iDataObject.GetData(LightWeightHTMLDataObject.LIGHTWEIGHTHTMLDOCUMENTFORMAT);
                return(new LightWeightHTMLDocumentData(document));
            }
            else
            {
                return(null);
            }
        }
Example #4
0
 /// <summary>
 /// Returns a list of FileItemFormats for a given dataobject
 /// </summary>
 private static ArrayList GetFormatsForDataObject(IDataObject dataObject)
 {
     // Mozilla often time is very sketchy about their filedrops.  They
     // may place null in the filedrop format, or they may place paths
     // to files that are highly transient and may or may not be available
     // when you need then (many images will get reset to 0 byte files)
     // As a result of this, we prefer FileContents when using Mozilla
     if (OleDataObjectHelper.GetDataPresentSafe(dataObject, MOZILLA_MARKER))
     {
         return(mozillaFileItemFormats);
     }
     else
     {
         return(fileItemFormats);
     }
 }
Example #5
0
        /// <summary>
        /// Creates a TextData from an IDataObject
        /// </summary>
        /// <param name="iDataObject">The IDataObject from which to create a TextData</param>
        /// <returns>The TextData, null if no TextData could be created.</returns>
        public static TextData Create(IDataObject iDataObject)
        {
            // Note: Using getData or getDataPresent here will sometimes return text
            // even when the text isn't in the list of formats exposed by getFormats
            foreach (string format in iDataObject.GetFormats())
            {
                if (format == DataFormats.UnicodeText || format == DataFormats.Text || format == DataFormats.StringFormat)
                {
                    // Suppress the text from an outlook data object, the text is useless
                    if (OleDataObjectHelper.GetDataPresentSafe(iDataObject, OUTLOOK_FORMAT_IGNORE_TEXT))
                    {
                        return(null);
                    }

                    return(new TextData(iDataObject));
                }
            }
            return(null);
        }
Example #6
0
        /// <summary>
        /// Creates a URLData based upon an IDataObject
        /// </summary>
        /// <param name="iDataObject">The IDataObject from which to create the URLData</param>
        /// <returns>The URLData, null if no URLData could be created</returns>
        public static URLData Create(IDataObject iDataObject)
        {
            // WinLive Bug 198371: Look at rolling the fix for WinLive 182698 into the OleDataObjectHelper.GetDataPresentSafe method
            // For now, we keep the changes targeted.
            bool canGetDataPresentDirectlyFromIDataObject = false;

            try
            {
                canGetDataPresentDirectlyFromIDataObject = iDataObject.GetDataPresent(DataFormatsEx.URLFormat) &&
                                                           iDataObject.GetDataPresent(DataFormatsEx.FileGroupDescriptorWFormat);
            }
            catch (Exception e)
            {
                Debug.Fail(e.ToString());
            }

            // Validate required format
            // WinLive Bug 182698: Assert when pasting a hyperlink from IE
            if (canGetDataPresentDirectlyFromIDataObject &&
                OleDataObjectHelper.GetDataPresentSafe(iDataObject, DataFormatsEx.URLFormat) &&
                OleDataObjectHelper.GetDataPresentSafe(iDataObject, DataFormatsEx.FileGroupDescriptorWFormat))
            {
                return(new URLData(iDataObject));
            }
            else
            {
                //check to see if the dataObject contains a single .url file,
                //if so, create the URLData from that.
                FileData fileData = FileData.Create(iDataObject);
                if (fileData != null && fileData.Files.Length == 1)
                {
                    string filePath = fileData.Files[0].ContentsPath;
                    if (PathHelper.IsPathUrlFile(filePath))
                    {
                        URLData urlData = new URLData(iDataObject, UrlHelper.GetUrlFromShortCutFile(filePath), Path.GetFileNameWithoutExtension(filePath));
                        urlData.DateCreated  = File.GetCreationTime(filePath);
                        urlData.DateModified = File.GetLastWriteTime(filePath);
                        return(urlData);
                    }
                }
            }
            return(null);
        }
Example #7
0
 /// <summary>
 /// Does the passed data object have this format?
 /// </summary>
 /// <param name="dataObject">data object</param>
 /// <returns>true if the data object has the format, otherwise false</returns>
 public bool CanCreateFrom(IDataObject dataObject)
 {
     return(OleDataObjectHelper.GetDataPresentSafe(dataObject, DataFormats.FileDrop) && dataObject.GetData(DataFormats.FileDrop) != null);
 }
Example #8
0
 /// <summary>
 /// Does the passed data object have this format?
 /// </summary>
 /// <param name="dataObject">data object</param>
 /// <returns>true if the data object has the format, otherwise false</returns>
 public bool CanCreateFrom(IDataObject dataObject)
 {
     return(OleDataObjectHelper.GetDataPresentSafe(dataObject, typeof(FileItem[])));
 }
 public bool GetDataPresent(Type format)
 {
     Validate();
     return(OleDataObjectHelper.GetDataPresentSafe(m_dataObject, format));
 }
Example #10
0
 private static bool HtmlDocumentClassFormatPresent(IDataObject iDataObject)
 {
     return(OleDataObjectHelper.GetDataPresentSafe(iDataObject, typeof(HTMLDocumentClass)));
 }