/// <summary>
        /// Determines whether the data object is capable of rendering the data described
        /// in the passed clipboard format and storage type(s). Objects attempting a
        /// paste or drop operation can call this method before calling GetData
        /// to get an indication of whether the operation may be successful
        /// </summary>
        /// <param name="clipFormat">Name of clipboard format requested</param>
        /// <param name="types">type(s) requested</param>
        /// <returns>true if the subseqent call to GetData would likely be
        /// successful, otherwise false</returns>
        public bool QueryGetData(string clipFormat, TYMED types)
        {
            // populate contents of FORMATETC structure
            FORMATETC formatEtc = new FORMATETC();

            OleDataObjectHelper.PopulateFORMATETC(clipFormat, types, ref formatEtc);

            // try to successfully query for the data
            int result = m_dataObject.QueryGetData(ref formatEtc);

            // data is available
            if (result == HRESULT.S_OK)
            {
                return(true);
            }

            // data is not available
            else if (result == DV_E.FORMATETC)
            {
                return(false);
            }

            // unexpected error
            else
            {
                Marshal.ThrowExceptionForHR(result);
                return(false); // keep compiler happy
            }
        }
        /// <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 #5
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 #6
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 #7
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 #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, DataFormats.FileDrop) && dataObject.GetData(DataFormats.FileDrop) != null);
 }
Example #9
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[])));
 }
        /// <summary>
        /// Extract the date from within an OleDataObject. Pass in the requested
        /// clipboard format and type (or types ORed together) that you want
        /// the data in. The method will return an OleStgMedium for the type(s)
        /// requested if it is available, otherwise it will return null.
        /// If a single type is requested then the return value can be safely
        /// cast to the requested OleStgMedium subclasss. If multiple types
        /// are requested then the return value will represent the object's
        /// preferred storage representation and client code will need to use
        /// the 'is' operator to determine what type was returned.
        /// </summary>
        /// <param name="lindex">Index of item to retreive</param>
        /// <param name="clipFormat">Name of clipboard format requested</param>
        /// <param name="types">type(s) requested</param>
        /// <returns>OleStgMedium instance if format and requested storage type
        /// are available, otherwise null</returns>
        public OleStgMedium GetData(int lindex, string clipFormat, TYMED types)
        {
            // populate contents of FORMATETC structure
            FORMATETC formatEtc = new FORMATETC();

            OleDataObjectHelper.PopulateFORMATETC(lindex, clipFormat, types, ref formatEtc);

            // attempt to get the data using the requested format
            STGMEDIUM stgMedium = new STGMEDIUM();

            if (m_dataObject != null)
            {
                int result = m_dataObject.GetData(ref formatEtc, ref stgMedium);

                // check for errors
                if (result != HRESULT.S_OK)
                {
                    // data format not supported (expected error condition)
                    if (result == DV_E.FORMATETC)
                    {
                        return(null);
                    }

                    // unexpected error condition
                    else
                    {
                        Marshal.ThrowExceptionForHR(result);
                    }
                }

                // return the correct OleStgMedium subclass depending upon the type
                switch (stgMedium.tymed)
                {
                case TYMED.NULL:
                    return(null);

                case TYMED.HGLOBAL:
                    return(new OleStgMediumHGLOBAL(stgMedium));

                case TYMED.FILE:
                    return(new OleStgMediumFILE(stgMedium));

                case TYMED.GDI:
                    return(new OleStgMediumGDI(stgMedium));

                case TYMED.MFPICT:
                    return(new OleStgMediumMFPICT(stgMedium));

                case TYMED.ENHMF:
                    return(new OleStgMediumENHMF(stgMedium));

                case TYMED.ISTREAM:
                    return(new OleStgMediumISTREAM(stgMedium));

                case TYMED.ISTORAGE:
                    return(new OleStgMediumISTORAGE(stgMedium));

                default:
                    Debug.Assert(false, "Invalid TYMED value");
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
 /// <summary>
 /// Helper function to populate the contents of a FORMATETC structure
 /// using the passed clipboard format and type(s).
 /// </summary>
 /// <param name="clipFormat">Name of clipboard format requested</param>
 /// <param name="types">type(s) requested</param>
 /// <param name="formatEtc">FORMATETC structure to be populated</param>
 public static void PopulateFORMATETC(
     string clipFormat, TYMED types, ref FORMATETC formatEtc)
 {
     OleDataObjectHelper.PopulateFORMATETC(-1, clipFormat, types, ref formatEtc);
 }
 public bool GetDataPresent(Type format)
 {
     Validate();
     return(OleDataObjectHelper.GetDataPresentSafe(m_dataObject, format));
 }
Example #13
0
 private static bool HtmlDocumentClassFormatPresent(IDataObject iDataObject)
 {
     return(OleDataObjectHelper.GetDataPresentSafe(iDataObject, typeof(HTMLDocumentClass)));
 }