forked from MicrosoftEdge/WebView2Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDropTarget.cpp
67 lines (58 loc) · 2.13 KB
/
DropTarget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (C) Microsoft Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "stdafx.h"
#include "DropTarget.h"
#include "ViewComponent.h"
#include <ShlGuid.h>
#include <Shobjidl.h>
DropTarget::DropTarget() : m_window(nullptr) {}
DropTarget::~DropTarget()
{
}
void DropTarget::Init(
HWND window, ViewComponent* viewComponent,
ICoreWebView2CompositionController3* webViewCompositionController3)
{
m_webViewCompositionController3 = webViewCompositionController3;
m_viewComponent = viewComponent;
m_window = window;
::RegisterDragDrop(m_window, this);
}
//! [DragEnter]
HRESULT DropTarget::DragEnter(
IDataObject* dataObject, DWORD keyState, POINTL cursorPosition, DWORD* effect)
{
POINT point = {cursorPosition.x, cursorPosition.y};
// Convert the screen point to client coordinates add the WebView's offset.
m_viewComponent->OffsetPointToWebView(&point);
return m_webViewCompositionController3->DragEnter(dataObject, keyState, point, effect);
}
//! [DragEnter]
//! [DragOver]
HRESULT DropTarget::DragOver(DWORD keyState, POINTL cursorPosition, DWORD* effect)
{
POINT point = {cursorPosition.x, cursorPosition.y};
// Convert the screen point to client coordinates add the WebView's offset.
// This returns whether the resultant point is over the WebView visual.
m_viewComponent->OffsetPointToWebView(&point);
return m_webViewCompositionController3->DragOver(keyState, point, effect);
}
//! [DragOver]
//! [DragLeave]
HRESULT DropTarget::DragLeave()
{
return m_webViewCompositionController3->DragLeave();
}
//! [DragLeave]
//! [Drop]
HRESULT DropTarget::Drop(
IDataObject* dataObject, DWORD keyState, POINTL cursorPosition, DWORD* effect)
{
POINT point = {cursorPosition.x, cursorPosition.y};
// Convert the screen point to client coordinates add the WebView's offset.
// This returns whether the resultant point is over the WebView visual.
m_viewComponent->OffsetPointToWebView(&point);
return m_webViewCompositionController3->Drop(dataObject, keyState, point, effect);
}
//! [Drop]