public virtual string[] GetFormats(bool autoConvert)
            {
                Debug.Assert(_innerData is not null, "You must have an innerData on all DataObjects");

                IEnumFORMATETC?enumFORMATETC = null;

                // Since we are only adding elements to the HashSet, the order will be preserved.
                HashSet <string> distinctFormats = new HashSet <string>();

                try
                {
                    enumFORMATETC = _innerData.EnumFormatEtc(DATADIR.DATADIR_GET);
                }
                catch
                {
                }

                if (enumFORMATETC is not null)
                {
                    enumFORMATETC.Reset();

                    FORMATETC[] formatetc = new FORMATETC[] { new FORMATETC() };
                    int[]       retrieved = new int[] { 1 };

                    while (retrieved[0] > 0)
                    {
                        retrieved[0] = 0;
                        try
                        {
                            enumFORMATETC.Next(1, formatetc, retrieved);
                        }
                        catch
                        {
                        }

                        if (retrieved[0] > 0)
                        {
                            string name = DataFormats.GetFormat(formatetc[0].cfFormat).Name;
                            if (autoConvert)
                            {
                                string[] mappedFormats = GetMappedFormats(name) !;
                                for (int i = 0; i < mappedFormats.Length; i++)
                                {
                                    distinctFormats.Add(mappedFormats[i]);
                                }
                            }
                            else
                            {
                                distinctFormats.Add(name);
                            }
                        }
                    }
                }

                return(distinctFormats.ToArray());
            }
Beispiel #2
0
            public virtual string[] GetFormats(bool autoConvert)
            {
                Debug.Assert(innerData != null, "You must have an innerData on all DataObjects");

                IEnumFORMATETC enumFORMATETC = null;
                ArrayList      formats       = new ArrayList();

                try
                {
                    enumFORMATETC = innerData.EnumFormatEtc(DATADIR.DATADIR_GET);
                }
                catch
                {
                }

                if (enumFORMATETC != null)
                {
                    enumFORMATETC.Reset();

                    FORMATETC[] formatetc = new FORMATETC[] { new FORMATETC() };
                    int[]       retrieved = new int[] { 1 };

                    while (retrieved[0] > 0)
                    {
                        retrieved[0] = 0;
                        try
                        {
                            enumFORMATETC.Next(1, formatetc, retrieved);
                        }
                        catch
                        {
                        }

                        if (retrieved[0] > 0)
                        {
                            string name = DataFormats.GetFormat(formatetc[0].cfFormat).Name;
                            if (autoConvert)
                            {
                                string[] mappedFormats = GetMappedFormats(name);
                                for (int i = 0; i < mappedFormats.Length; i++)
                                {
                                    formats.Add(mappedFormats[i]);
                                }
                            }
                            else
                            {
                                formats.Add(name);
                            }
                        }
                    }
                }

                string[] temp = new string[formats.Count];
                formats.CopyTo(temp, 0);
                return(GetDistinctStrings(temp));
            }
Beispiel #3
0
        int OleInterop.IDataObject.EnumFormatEtc(uint dwDirection, out OleInterop.IEnumFORMATETC ppenumFormatEtc)
        {
            if (null != oleData)
            {
                return(oleData.EnumFormatEtc(dwDirection, out ppenumFormatEtc));
            }

            BclComTypes.IEnumFORMATETC bclEnum = bclData.EnumFormatEtc((BclComTypes.DATADIR)dwDirection);
            if (null == bclEnum)
            {
                ppenumFormatEtc = null;
            }
            else
            {
                ppenumFormatEtc = bclEnum as OleInterop.IEnumFORMATETC;
                if (null == ppenumFormatEtc)
                {
                    ppenumFormatEtc = (OleInterop.IEnumFORMATETC)(new EnumFORMATETC(bclEnum));
                }
            }
            return(NativeMethods.S_OK);
        }
        private IEnumerable <string> GetDataFormatsCore()
        {
            var enumFormat = _wrapped.EnumFormatEtc(DATADIR.DATADIR_GET);

            if (enumFormat != null)
            {
                enumFormat.Reset();
                FORMATETC[] formats = new FORMATETC[1];
                int[]       fetched = { 1 };
                while (fetched[0] > 0)
                {
                    fetched[0] = 0;
                    if (enumFormat.Next(1, formats, fetched) == 0 && fetched[0] > 0)
                    {
                        if (formats[0].ptd != IntPtr.Zero)
                        {
                            Marshal.FreeCoTaskMem(formats[0].ptd);
                        }

                        yield return(ClipboardFormats.GetFormat(formats[0].cfFormat));
                    }
                }
            }
        }
Beispiel #5
0
            long MsHtmHstInterop.IDropTarget.Drop(
                [In] System.Runtime.InteropServices.ComTypes.IDataObject pDataObject,
                [In] int grfKeyState,
                [In] POINTL pt,
                [In, Out] ref uint pdwEffect
                )
            {
                System.Runtime.InteropServices.ComTypes.IEnumFORMATETC pEnum = (System.Runtime.InteropServices.ComTypes.IEnumFORMATETC)pDataObject.EnumFormatEtc(DATADIR.DATADIR_GET);
                pEnum.Reset();
                FORMATETC[] etcs         = new FORMATETC[1];
                int[]       pceltFetched = new int[1];
                while (pEnum.Next(1, etcs, pceltFetched) == 0)
                {
                    if (etcs[0].cfFormat == 15)
                    {
                        STGMEDIUM data;
                        pDataObject.GetData(ref etcs[0], out data);
                        if (data.tymed == TYMED.TYMED_HGLOBAL)
                        {
                            string[] items = null;
                            IntPtr   pData = GlobalLock(data.unionmember);
                            try
                            {
                                int size = (int)GlobalSize(data.unionmember);
                                int len  = 0;
                                unsafe
                                {
                                    Int32 *pOffset    = (Int32 *)pData;
                                    Int16 *pFileNames = (Int16 *)((Int32)pData + (*pOffset));
                                    size -= *pOffset;
                                    while (true)
                                    {
                                        if (len >= size || (pFileNames[len] == 0 && pFileNames[len + 1] == 0))
                                        {
                                            break;
                                        }
                                        len += 2;
                                    }
                                    String s = Marshal.PtrToStringUni((IntPtr)pFileNames, len);
                                    items = s.Split(new char[] { (char)0 });
                                }
                            }
                            finally
                            {
                                GlobalUnlock(data.unionmember);
                            }
                            StringBuilder files = new StringBuilder();
                            foreach (string file in items)
                            {
                                if (System.IO.File.Exists(file))
                                {
                                    if (files.Length > 0)
                                    {
                                        files.Append('\0');
                                    }
                                    files.Append(file);
                                }
                            }
                            if (files.Length > 0)
                            {
                                _window.IWindow.OnDropFiles.Call(files.ToString());
                                return(S_OK);
                            }
                        }
                    }
                    else if (etcs[0].cfFormat == 13)
                    {
                        STGMEDIUM data;
                        pDataObject.GetData(ref etcs[0], out data);
                        String text = null;

                        if (data.tymed == TYMED.TYMED_HGLOBAL)
                        {
                            IntPtr hData = GlobalLock(data.unionmember);
                            try
                            {
                                int size = (int)GlobalSize(data.unionmember);
                                text = Marshal.PtrToStringUni(hData);
                            }
                            finally
                            {
                                GlobalUnlock(data.unionmember);
                            }
                        }

                        Hashtable data_json = null;
                        try
                        {
                            data_json = Utility.ParseJson(text) as Hashtable;
                        }
                        catch
                        {
                            data_json = null;
                        }

                        if (data_json != null && data_json.ContainsKey("__Type") && data_json.ContainsKey("__Data"))
                        {
                            string drop_type = data_json["__Type"].ToString();
                            string drop_data = data_json["__Data"].ToString();
                            _window.IWindow.OnDrop.CallAll(drop_type, drop_data);
                            return(S_OK);
                        }
                    }
                }
                if (m_pPreDropTarget != null)
                {
                    m_pPreDropTarget.Drop(pDataObject, grfKeyState, pt, ref pdwEffect);
                }
                return(S_OK);
            }