1 | /* $Id: dragdrop.cpp,v 1.4 2003-07-28 11:27:45 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Win32 Drag 'n Drop functions for OS/2
|
---|
5 | *
|
---|
6 | * Copyright 2002 Sander van Leeuwen
|
---|
7 | *
|
---|
8 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
9 | *
|
---|
10 | */
|
---|
11 | #include <windows.h>
|
---|
12 | #include <dbglog.h>
|
---|
13 | #include <oledd.h>
|
---|
14 |
|
---|
15 | #define DBG_LOCALLOG DBG_dragdrop
|
---|
16 | #include "dbglocal.h"
|
---|
17 |
|
---|
18 | static PFN_DRAGENTER pfnDragEnter = NULL;
|
---|
19 | static PFN_DRAGLEAVE pfnDragLeave = NULL;
|
---|
20 | static PFN_DROPFILES pfnDropFiles = NULL;
|
---|
21 | static PFN_DRAGOVER pfnDragOver = NULL;
|
---|
22 | static PFN_ACCEPTSDRAGDROP pfnAcceptsDragDrop = NULL;
|
---|
23 | static HANDLE hOLE32 = 0;
|
---|
24 |
|
---|
25 | //******************************************************************************
|
---|
26 | //******************************************************************************
|
---|
27 | ULONG DragDropFiles(HWND hwnd, POINT point, UINT cFiles, LPSTR pszFiles, UINT cbszFiles, BOOL fNonClient)
|
---|
28 | {
|
---|
29 | DROPFILES *pDropFile;
|
---|
30 | HGLOBAL hDropFile;
|
---|
31 | DWORD dwExStyle;
|
---|
32 | HWND orghwnd = hwnd;
|
---|
33 |
|
---|
34 | dprintf(("DragDropFiles %x (%d,%d) %d %s %d %d", hwnd, point.x, point.y, cFiles, pszFiles, cbszFiles, fNonClient));
|
---|
35 |
|
---|
36 | dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
|
---|
37 |
|
---|
38 | //TODO: Is it correct if the window or parent accepts files or must we check the top parent?
|
---|
39 | hwnd = (dwExStyle & WS_EX_ACCEPTFILES) ? hwnd : GetParent(hwnd);
|
---|
40 | dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
|
---|
41 |
|
---|
42 | if(!(dwExStyle & WS_EX_ACCEPTFILES)) {
|
---|
43 | if(pfnDropFiles) {
|
---|
44 | return pfnDropFiles(orghwnd);
|
---|
45 | }
|
---|
46 | return FALSE;
|
---|
47 | }
|
---|
48 |
|
---|
49 | cbszFiles++; //extra terminating 0
|
---|
50 | hDropFile = GlobalAlloc(0, sizeof(DROPFILES)+cbszFiles);
|
---|
51 | pDropFile = (DROPFILES *)GlobalLock(hDropFile);
|
---|
52 | if(pDropFile == NULL) {
|
---|
53 | DebugInt3();
|
---|
54 | return 0;
|
---|
55 | }
|
---|
56 | pDropFile->pFiles = sizeof(DROPFILES);
|
---|
57 | pDropFile->fNC = fNonClient;
|
---|
58 | pDropFile->fWide = FALSE;
|
---|
59 | pDropFile->pt = point;
|
---|
60 | //copy strings (excluding terminating 0)
|
---|
61 | memcpy((pDropFile+1), pszFiles, cbszFiles-1);
|
---|
62 | GlobalUnlock(hDropFile);
|
---|
63 | SendMessageA(hwnd, WM_DROPFILES, hDropFile, 0);
|
---|
64 | return 0;
|
---|
65 | }
|
---|
66 | //******************************************************************************
|
---|
67 | //******************************************************************************
|
---|
68 | BOOL DragDropDragOver(HWND hwnd, DWORD dwEffect)
|
---|
69 | {
|
---|
70 | dprintf(("DragDropDragOver %x %x", hwnd, dwEffect));
|
---|
71 | if(pfnDragOver) {
|
---|
72 | return pfnDragOver(hwnd, dwEffect);
|
---|
73 | }
|
---|
74 | return TRUE; //ignore
|
---|
75 | }
|
---|
76 | //******************************************************************************
|
---|
77 | //******************************************************************************
|
---|
78 | BOOL DragDropDragEnter(HWND hwnd, POINT point, UINT cFiles, LPSTR pszFiles, UINT cbszFiles,
|
---|
79 | DWORD dwEffect, BOOL fNonClient)
|
---|
80 | {
|
---|
81 | DROPFILES *pDropFile;
|
---|
82 | HGLOBAL hDropFile;
|
---|
83 |
|
---|
84 | dprintf(("DragDropDragEnter %x (%d,%d) %d %s %d %d", hwnd, point.x, point.y, cFiles, pszFiles, cbszFiles, fNonClient));
|
---|
85 |
|
---|
86 | if(pfnDragEnter) {
|
---|
87 | cbszFiles++; //extra terminating 0
|
---|
88 | hDropFile = GlobalAlloc(0, sizeof(DROPFILES)+cbszFiles);
|
---|
89 | pDropFile = (DROPFILES *)GlobalLock(hDropFile);
|
---|
90 | if(pDropFile == NULL) {
|
---|
91 | DebugInt3();
|
---|
92 | return FALSE;
|
---|
93 | }
|
---|
94 | pDropFile->pFiles = sizeof(DROPFILES);
|
---|
95 | pDropFile->fNC = fNonClient;
|
---|
96 | pDropFile->fWide = FALSE;
|
---|
97 | pDropFile->pt = point;
|
---|
98 | //copy strings (excluding terminating 0)
|
---|
99 | memcpy((pDropFile+1), pszFiles, cbszFiles-1);
|
---|
100 | GlobalUnlock(hDropFile);
|
---|
101 |
|
---|
102 | return pfnDragEnter(hwnd, hDropFile, dwEffect);
|
---|
103 | }
|
---|
104 | return TRUE; //ignore
|
---|
105 | }
|
---|
106 | //******************************************************************************
|
---|
107 | //******************************************************************************
|
---|
108 | BOOL DragDropDragLeave(HWND hwnd)
|
---|
109 | {
|
---|
110 | dprintf(("DragDropDragLeave %x", hwnd));
|
---|
111 | if(pfnDragLeave) {
|
---|
112 | return pfnDragLeave(hwnd);
|
---|
113 | }
|
---|
114 | return TRUE; //ignore
|
---|
115 | }
|
---|
116 | //******************************************************************************
|
---|
117 | //******************************************************************************
|
---|
118 | BOOL DragDropAccept(HWND hwnd)
|
---|
119 | {
|
---|
120 | DWORD dwExStyle;
|
---|
121 |
|
---|
122 | dprintf(("DragDropDragAccept %x", hwnd));
|
---|
123 |
|
---|
124 | dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
|
---|
125 | //Is it correct if the window or parent accepts files or must we check the topparent parent?
|
---|
126 | if(dwExStyle & WS_EX_ACCEPTFILES) {
|
---|
127 | return TRUE;
|
---|
128 | }
|
---|
129 | DWORD dwStyle = GetWindowLongA(GetParent(hwnd), GWL_EXSTYLE);
|
---|
130 | if(!(dwStyle & WS_EX_ACCEPTFILES)) {
|
---|
131 | if(pfnAcceptsDragDrop == NULL) {
|
---|
132 | //check for OLE drag & drop
|
---|
133 |
|
---|
134 | hOLE32 = GetModuleHandleA("OLE32.DLL");
|
---|
135 | if(hOLE32 == 0) {
|
---|
136 | //if ole32.dll isn't loaded, then ole drag and drop can't be active
|
---|
137 | return FALSE;
|
---|
138 | }
|
---|
139 | //make sure the dll doesn't get unloaded
|
---|
140 | hOLE32 = LoadLibraryA("OLE32.DLL");
|
---|
141 |
|
---|
142 | pfnAcceptsDragDrop = (PFN_ACCEPTSDRAGDROP)GetProcAddress(hOLE32, "OLEDD_AcceptsDragDrop");
|
---|
143 | pfnDragOver = (PFN_DRAGOVER)GetProcAddress(hOLE32, "OLEDD_DragOver");
|
---|
144 | pfnDragLeave = (PFN_DRAGLEAVE)GetProcAddress(hOLE32, "OLEDD_DragLeave");
|
---|
145 | pfnDragEnter = (PFN_DRAGENTER)GetProcAddress(hOLE32, "OLEDD_DragEnter");
|
---|
146 | pfnDropFiles = (PFN_DROPFILES)GetProcAddress(hOLE32, "OLEDD_DropFiles");
|
---|
147 | if(!pfnAcceptsDragDrop || !pfnDragOver || !pfnDragLeave || !pfnDragEnter || !pfnDropFiles) {
|
---|
148 | dprintf(("OLE DD functions not found!!"));
|
---|
149 | DebugInt3();
|
---|
150 | return FALSE;
|
---|
151 | }
|
---|
152 | }
|
---|
153 | if(pfnAcceptsDragDrop) {
|
---|
154 | return pfnAcceptsDragDrop(hwnd);
|
---|
155 | }
|
---|
156 | return FALSE;
|
---|
157 | }
|
---|
158 | return TRUE;
|
---|
159 | }
|
---|
160 | //******************************************************************************
|
---|
161 | //******************************************************************************
|
---|
162 |
|
---|