Exemplo n.º 1
0
        //
        //////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////
        // Reset
        int OleInterop.IEnumFORMATETC.Reset()
        {
            if (null != oleEnum)
            {
                return(oleEnum.Reset());
            }
            return(bclEnum.Reset());
        }
Exemplo n.º 2
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);
            }