示例#1
0
        public static HRESULT DoDragDrop(
            IDataObject pDataObj,
            IDropSource pDropSource,
            DROPEFFECT dwOKEffects,
            out DROPEFFECT pdwEffect)
        {
            var result = WinFormsComWrappers.Instance.TryGetComPointer(pDataObj, IID.IDataObject, out var dataObjectPtr);

            if (result.Failed())
            {
                pdwEffect = DROPEFFECT.NONE;
                return(result);
            }

            result = WinFormsComWrappers.Instance.TryGetComPointer(pDropSource, IID.IDropSource, out var dropSourcePtr);
            if (result.Failed())
            {
                Marshal.Release(dataObjectPtr);
                pdwEffect = DROPEFFECT.NONE;
                return(result);
            }

            result = DoDragDrop(dataObjectPtr, dropSourcePtr, dwOKEffects, out pdwEffect);
            return(result);
        }
        /// <summary>
        /// Helper method to call the Mshtml DragOver routine using .NET DragEventArgs
        /// </summary>
        /// <param name="e"></param>
        private void CallMshtmlDragOver(DragEventArgs e, bool allowEffects, bool allowExceptions)
        {
            if (mshtmlDropTargetImpl == null)
            {
                return;
            }

            try
            {
                // convert data types
                POINT      pt         = new POINT(); pt.x = e.X; pt.y = e.Y;
                DROPEFFECT dropEffect = ConvertDropEffect(e.AllowedEffect);
                MK         keyState   = ConvertKeyState(e.KeyState);

                // suppress effects if requested
                if (!allowEffects)
                {
                    dropEffect = DROPEFFECT.NONE;
                }

                // call mshtml
                mshtmlDropTargetImpl.DragOver(keyState, pt, ref dropEffect);

                // copy any changes to the dropEffect back into the event args
                e.Effect = ConvertDropEffect(dropEffect);
            }
            catch (Exception)
            {
                if (allowExceptions)
                {
                    throw;
                }
            }
        }
        /// <summary>
        /// Helper to cal the Mshtml DragDrop routine using .NET DragEventArgs
        /// </summary>
        /// <param name="e">event args</param>
        private void CallMshtmlDragDrop(DragEventArgs e, bool allowExceptions)
        {
            if (mshtmlDropTargetImpl == null)
            {
                return;
            }

            try
            {
                // extract ole data object
                IOleDataObject oleDataObject = SafeExtractOleDataObject(e.Data);

                // convert data types
                POINT      pt         = new POINT(); pt.x = e.X; pt.y = e.Y;
                DROPEFFECT dropEffect = ConvertDropEffect(e.AllowedEffect);
                MK         keyState   = ConvertKeyState(e.KeyState);

                // call mshtml
                mshtmlDropTargetImpl.Drop(oleDataObject, keyState, pt, ref dropEffect);

                // copy any changes to the dropEffect back into the event args
                e.Effect = ConvertDropEffect(dropEffect);
            }
            catch (Exception)
            {
                if (allowExceptions)
                {
                    throw;
                }
            }
        }
示例#4
0
        /// <inheritdoc/>
        HRESULT IDropTarget.DragOver(MouseButtonState grfKeyState, POINT pt, ref DROPEFFECT pdwEffect)
        {
            System.Diagnostics.Debug.WriteLine($"IDropTarget.DragOver: effect={pdwEffect}");
            var drgevent = CreateDragEventArgs(null, grfKeyState, pt, pdwEffect);

            DragOver?.Invoke(this, drgevent);
            lastEffect = pdwEffect = drgevent.Effect;
            return(HRESULT.S_OK);
        }
示例#5
0
 /// <summary>Initializes a new instance of the <see cref="DragEventArgs"/> class.</summary>
 /// <param name="data">The data associated with this event.</param>
 /// <param name="keyState">The current state of the SHIFT, CTRL, and ALT keys.</param>
 /// <param name="x">The x-coordinate of the mouse cursor in pixels.</param>
 /// <param name="y">The y-coordinate of the mouse cursor in pixels.</param>
 /// <param name="allowedEffect">One of the DROPEFFECT values.</param>
 /// <param name="lastEffect">One of the DROPEFFECT values.</param>
 public DragEventArgs(IDataObject data, MouseButtonState keyState, int x, int y, DROPEFFECT allowedEffect, DROPEFFECT lastEffect)
 {
     Data          = data;
     KeyState      = keyState;
     X             = x;
     Y             = y;
     AllowedEffect = allowedEffect;
     Effect        = lastEffect;
 }
示例#6
0
        /// <inheritdoc/>
        HRESULT IDropTarget.DragEnter(IDataObject pDataObj, MouseButtonState grfKeyState, Point pt, ref DROPEFFECT pdwEffect)
        {
            System.Diagnostics.Debug.WriteLine($"IDropTarget.DragEnter: effect={pdwEffect}");
            var drgevent = CreateDragEventArgs(pDataObj, grfKeyState, pt, pdwEffect);

            DragEnter?.Invoke(this, drgevent);
            lastEffect = pdwEffect = (DROPEFFECT)drgevent.Effect;
            return(HRESULT.S_OK);
        }
示例#7
0
        /// <inheritdoc/>
        HRESULT IDropTarget.Drop(IDataObject pDataObj, uint grfKeyState, Point pt, ref DROPEFFECT pdwEffect)
        {
            System.Diagnostics.Debug.WriteLine($"IDropTarget.Drop: effect={pdwEffect}");
            var drgevent = CreateDragEventArgs(pDataObj, grfKeyState, pt, pdwEffect);

            DragDrop?.Invoke(this, drgevent);
            pdwEffect = (DROPEFFECT)drgevent.Effect;
            CancelTimeout();
            return(HRESULT.S_OK);
        }
示例#8
0
        // this method is what is called to invoke the verb and is typically the only method that needs to be implemented this is the method
        // that is called to invoke the verb the data object represents the selection and is converted into a shell item array to address the
        // items being acted on.
        HRESULT IDropTarget.Drop(IDataObject pDataObj, uint grfKeyState, Point pt, ref DROPEFFECT pdwEffect)
        {
            _pdtobj = pDataObj;

            // capture state from the site, the HWND of the parent (that should not be used for a modal
            // window) but might be useful for positioning the UI of this verb
            IUnknown_GetWindow(_punkSite, out _hwnd);

            QueueAppCallback();

            pdwEffect = DROPEFFECT.DROPEFFECT_NONE;               // didn't move or copy the file
            return(HRESULT.S_OK);
        }
        /// <summary>
        /// Helper to convert Win32 drop effect into .NET drop effect
        /// </summary>
        /// <param name="dropEffect">drop effect to convert</param>
        /// <returns>converted effect</returns>
        public static DragDropEffects ConvertDropEffect(DROPEFFECT dropEffect)
        {
            DragDropEffects targetDropEffect = DragDropEffects.None;

            if ((dropEffect & DROPEFFECT.COPY) == DROPEFFECT.COPY)
            {
                targetDropEffect |= DragDropEffects.Copy;
            }
            if ((dropEffect & DROPEFFECT.LINK) == DROPEFFECT.LINK)
            {
                targetDropEffect |= DragDropEffects.Link;
            }
            if ((dropEffect & DROPEFFECT.MOVE) == DROPEFFECT.MOVE)
            {
                targetDropEffect |= DragDropEffects.Move;
            }
            if ((dropEffect & DROPEFFECT.SCROLL) == DROPEFFECT.SCROLL)
            {
                targetDropEffect |= DragDropEffects.Scroll;
            }
            return(targetDropEffect);
        }
        /// <summary>
        /// Helper to convert .NET drop-effect into Win32 drop effect
        /// </summary>
        /// <param name="dropEffect">drop effect to convert</param>
        /// <returns>converted effect</returns>
        public static DROPEFFECT ConvertDropEffect(DragDropEffects dropEffect)
        {
            DROPEFFECT targetDropEffect = DROPEFFECT.NONE;

            if ((dropEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
            {
                targetDropEffect |= DROPEFFECT.COPY;
            }
            if ((dropEffect & DragDropEffects.Link) == DragDropEffects.Link)
            {
                targetDropEffect |= DROPEFFECT.LINK;
            }
            if ((dropEffect & DragDropEffects.Move) == DragDropEffects.Move)
            {
                targetDropEffect |= DROPEFFECT.MOVE;
            }
            if ((dropEffect & DragDropEffects.Scroll) == DragDropEffects.Scroll)
            {
                targetDropEffect |= DROPEFFECT.SCROLL;
            }
            return(targetDropEffect);
        }
示例#11
0
        public override DragDropEffects ProvideDragFeedback(Point screenPoint, int keyState, DragDropEffects supportedEffects)
        {
            if (_unhandledDropTarget == null)
            {
                return(DragDropEffects.None);
            }

            _mkKeyState = MshtmlEditorDragAndDropTarget.ConvertKeyState(keyState);
            _effect     = MshtmlEditorDragAndDropTarget.ConvertDropEffect(supportedEffects);
            _point      = new POINT();
            _point.x    = screenPoint.X;
            _point.y    = screenPoint.Y;

            // We have to call begin drag here because we need the location and key state which we dont have in BeginDrag()
            if (!_hasCalledBeginDrag)
            {
                _hasCalledBeginDrag = true;
                _unhandledDropTarget.DragEnter(_oleDataObject, _mkKeyState, _point, ref _effect);
            }

            _unhandledDropTarget.DragOver(_mkKeyState, _point, ref _effect);

            return(MshtmlEditorDragAndDropTarget.ConvertDropEffect(_effect));
        }
示例#12
0
        private DragEventArgs CreateDragEventArgs(IDataObject pDataObj, MouseButtonState grfKeyState, Point pt, DROPEFFECT pdwEffect)
        {
            var data     = pDataObj == null ? lastDataObject : new DataObject(pDataObj);
            var drgevent = new DragEventArgs(data, (int)grfKeyState, pt.X, pt.Y, (DragDropEffects)pdwEffect, (DragDropEffects)lastEffect);

            lastDataObject = data;
            return(drgevent);
        }
        public override DragDropEffects ProvideDragFeedback(Point screenPoint, int keyState, DragDropEffects supportedEffects)
        {
            if (_unhandledDropTarget == null)
                return DragDropEffects.None;

            _mkKeyState = MshtmlEditorDragAndDropTarget.ConvertKeyState(keyState);
            _effect = MshtmlEditorDragAndDropTarget.ConvertDropEffect(supportedEffects);
            _point = new POINT();
            _point.x = screenPoint.X;
            _point.y = screenPoint.Y;

            // We have to call begin drag here because we need the location and key state which we dont have in BeginDrag()
            if (!_hasCalledBeginDrag)
            {
                _hasCalledBeginDrag = true;
                _unhandledDropTarget.DragEnter(_oleDataObject, _mkKeyState, _point, ref _effect);
            }

            _unhandledDropTarget.DragOver(_mkKeyState, _point, ref _effect);

            return MshtmlEditorDragAndDropTarget.ConvertDropEffect(_effect);
        }
 /// <summary>
 /// Helper to convert Win32 drop effect into .NET drop effect
 /// </summary>
 /// <param name="dropEffect">drop effect to convert</param>
 /// <returns>converted effect</returns>
 public static DragDropEffects ConvertDropEffect(DROPEFFECT dropEffect)
 {
     DragDropEffects targetDropEffect = DragDropEffects.None;
     if ((dropEffect & DROPEFFECT.COPY) == DROPEFFECT.COPY)
         targetDropEffect |= DragDropEffects.Copy;
     if ((dropEffect & DROPEFFECT.LINK) == DROPEFFECT.LINK)
         targetDropEffect |= DragDropEffects.Link;
     if ((dropEffect & DROPEFFECT.MOVE) == DROPEFFECT.MOVE)
         targetDropEffect |= DragDropEffects.Move;
     if ((dropEffect & DROPEFFECT.SCROLL) == DROPEFFECT.SCROLL)
         targetDropEffect |= DragDropEffects.Scroll;
     return targetDropEffect;
 }
示例#15
0
 public void SetParameters(uint KeyState, System.Drawing.Point pt, DataObject DropDataObject, uint Effect)
 {
     this.handled = false;
     this.keystate = KeyState;
     this.pt = pt;
     this.dropeffect = (DROPEFFECT)Effect;
     this.dataobject = DropDataObject;
 }
        /// <summary>
        /// Provides target feedback to the user and communicates the drop's effect to the DoDragDrop function so it can communicate the effect of the drop back to the source
        /// </summary>
        /// <param name="grfKeyState">Current state of the keyboard modifier keys on the keyboard</param>
        /// <param name="pt">POINTL structure containing the current cursor coordinates in screen coordinates</param>
        /// <param name="pdwEffect">Pointer to the current effect flag. Valid values are from the enumeration DROPEFFECT</param>
        void OpenLiveWriter.Interop.Com.IDropTarget.DragOver(MK grfKeyState, POINT pt, ref DROPEFFECT pdwEffect)
        {
            Debug.Fail("Unexpected call to IDropTarget.DragOver");

            if (mshtmlDropTargetImpl != null)
            {
                mshtmlDropTargetImpl.DragOver(grfKeyState, pt, ref pdwEffect);
            }
        }
示例#17
0
        private DragEventArgs CreateDragEventArgs(IDataObject pDataObj, MouseButtonState grfKeyState, POINT pt, DROPEFFECT pdwEffect)
        {
            var data     = pDataObj ?? lastDataObject;
            var drgevent = new DragEventArgs(data, grfKeyState, pt.X, pt.Y, pdwEffect, lastEffect);

            lastDataObject = data;
            return(drgevent);
        }
        /// <summary>
        /// Incorporates the source data into the target window, removes target feedback, and releases the data object
        /// </summary>
        /// <param name="pDataObj">Pointer to the IDataObject interface on the data object being transferred in the drag-and-drop operation</param>
        /// <param name="grfKeyState">Current state of the keyboard modifier keys on the keyboard</param>
        /// <param name="pt">POINTL structure containing the current cursor coordinates in screen coordinates</param>
        /// <param name="pdwEffect">Pointer to the current effect flag. Valid values are from the enumeration DROPEFFECT</param>
        void OpenLiveWriter.Interop.Com.IDropTarget.Drop(IOleDataObject pDataObj, MK grfKeyState, POINT pt, ref DROPEFFECT pdwEffect)
        {
            Debug.Fail("Unexpected call to IDropTarget.Drop");

            if (mshtmlDropTargetImpl != null)
            {
                mshtmlDropTargetImpl.Drop(pDataObj, grfKeyState, pt, ref pdwEffect);
            }
        }
示例#19
0
 public static extern HRESULT DoDragDrop(
     IDataObject pDataObj,
     IDropSource pDropSource,
     DROPEFFECT dwOKEffects,
     out DROPEFFECT pdwEffect);
示例#20
0
 // IDropTarget this is the required interface for a verb implemeting the DropTarget method DragEnter is called to enable the
 // implementaiton to zero the output dwEffect value, indicating that the verb does not accept the input data object. this is rarely used.
 HRESULT IDropTarget.DragOver(uint grfKeyState, Point pt, ref DROPEFFECT pdwEffect) => HRESULT.S_OK;
 HRESULT IDropTarget.DragEnter(IDataObject pDataObj, MouseButtonState grfKeyState, Point pt, ref DROPEFFECT pdwEffect) => HRESULT.S_OK;
        /// <summary>
        /// Provides target feedback to the user and communicates the drop's effect to the DoDragDrop function so it can communicate the effect of the drop back to the source
        /// </summary>
        /// <param name="grfKeyState">Current state of the keyboard modifier keys on the keyboard</param>
        /// <param name="pt">POINTL structure containing the current cursor coordinates in screen coordinates</param>
        /// <param name="pdwEffect">Pointer to the current effect flag. Valid values are from the enumeration DROPEFFECT</param>
        void OpenLiveWriter.Interop.Com.IDropTarget.DragOver(MK grfKeyState, POINT pt, ref DROPEFFECT pdwEffect)
        {
            Debug.Fail("Unexpected call to IDropTarget.DragOver");

            if (mshtmlDropTargetImpl != null)
            {
                mshtmlDropTargetImpl.DragOver(grfKeyState, pt, ref pdwEffect);
            }
        }
示例#23
0
 public static extern int DoDragDrop(
     IOleDataObject pDataObject, // Pointer to the data object
     IDropSource pDropSource,    // Pointer to the source
     DROPEFFECT dwOKEffect,      // Effects allowed by the source
     ref DROPEFFECT pdwEffect    // Pointer to effects on the source
     );
        /// <summary>
        /// Incorporates the source data into the target window, removes target feedback, and releases the data object
        /// </summary>
        /// <param name="pDataObj">Pointer to the IDataObject interface on the data object being transferred in the drag-and-drop operation</param>
        /// <param name="grfKeyState">Current state of the keyboard modifier keys on the keyboard</param>
        /// <param name="pt">POINTL structure containing the current cursor coordinates in screen coordinates</param>
        /// <param name="pdwEffect">Pointer to the current effect flag. Valid values are from the enumeration DROPEFFECT</param>
        void OpenLiveWriter.Interop.Com.IDropTarget.Drop(IOleDataObject pDataObj, MK grfKeyState, POINT pt, ref DROPEFFECT pdwEffect)
        {
            Debug.Fail("Unexpected call to IDropTarget.Drop");

            if (mshtmlDropTargetImpl != null)
            {
                mshtmlDropTargetImpl.Drop(pDataObj, grfKeyState, pt, ref pdwEffect);
            }
        }
示例#25
0
 private static extern HRESULT DoDragDrop(
     IntPtr pDataObj,
     IntPtr pDropSource,
     DROPEFFECT dwOKEffects,
     out DROPEFFECT pdwEffect);
 // IDropTarget this is the required interface for a verb implemeting the DropTarget method DragEnter is called to enable the
 // implementaiton to zero the output dwEffect value, indicating that the verb does not accept the input data object. this is rarely used.
 HRESULT IDropTarget.DragOver(MouseButtonState grfKeyState, Point pt, ref DROPEFFECT pdwEffect) => HRESULT.S_OK;
示例#27
0
 public static extern int DoDragDrop(
     IOleDataObject pDataObject,  // Pointer to the data object
     IDropSource pDropSource,	  // Pointer to the source
     DROPEFFECT dwOKEffect,       // Effects allowed by the source
     ref DROPEFFECT pdwEffect    // Pointer to effects on the source
     );