source: trunk/src/user32/dragdrop.cpp@ 8735

Last change on this file since 8735 was 8735, checked in by sandervl, 23 years ago

drag & drop fix; added SetDragDrop; enabled drag & drop

File size: 5.5 KB
Line 
1/* $Id: dragdrop.cpp,v 1.3 2002-06-20 14:18:14 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
18static PFN_DRAGENTER pfnDragEnter = NULL;
19static PFN_DRAGLEAVE pfnDragLeave = NULL;
20static PFN_DROPFILES pfnDropFiles = NULL;
21static PFN_DRAGOVER pfnDragOver = NULL;
22static PFN_ACCEPTSDRAGDROP pfnAcceptsDragDrop = NULL;
23static HANDLE hOLE32 = 0;
24
25//******************************************************************************
26//******************************************************************************
27ULONG 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 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
35
36 //TODO: Is it correct if the window or parent accepts files or must we check the top parent?
37 hwnd = (dwExStyle & WS_EX_ACCEPTFILES) ? hwnd : GetParent(hwnd);
38 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
39
40 if(!(dwExStyle & WS_EX_ACCEPTFILES)) {
41 if(pfnDropFiles) {
42 return pfnDropFiles(orghwnd);
43 }
44 return FALSE;
45 }
46
47 cbszFiles++; //extra terminating 0
48 hDropFile = GlobalAlloc(0, sizeof(DROPFILES)+cbszFiles);
49 pDropFile = (DROPFILES *)GlobalLock(hDropFile);
50 if(pDropFile == NULL) {
51 DebugInt3();
52 return 0;
53 }
54 pDropFile->pFiles = sizeof(DROPFILES);
55 pDropFile->fNC = fNonClient;
56 pDropFile->fWide = FALSE;
57 pDropFile->pt = point;
58 //copy strings (excluding terminating 0)
59 memcpy((pDropFile+1), pszFiles, cbszFiles-1);
60 GlobalUnlock(hDropFile);
61 SendMessageA(hwnd, WM_DROPFILES, hDropFile, 0);
62 return 0;
63}
64//******************************************************************************
65//******************************************************************************
66BOOL DragDropDragOver(HWND hwnd, DWORD dwEffect)
67{
68 if(pfnDragOver) {
69 return pfnDragOver(hwnd, dwEffect);
70 }
71 return TRUE; //ignore
72}
73//******************************************************************************
74//******************************************************************************
75BOOL DragDropDragEnter(HWND hwnd, POINT point, UINT cFiles, LPSTR pszFiles, UINT cbszFiles,
76 DWORD dwEffect, BOOL fNonClient)
77{
78 DROPFILES *pDropFile;
79 HGLOBAL hDropFile;
80
81 if(pfnDragEnter) {
82 cbszFiles++; //extra terminating 0
83 hDropFile = GlobalAlloc(0, sizeof(DROPFILES)+cbszFiles);
84 pDropFile = (DROPFILES *)GlobalLock(hDropFile);
85 if(pDropFile == NULL) {
86 DebugInt3();
87 return FALSE;
88 }
89 pDropFile->pFiles = sizeof(DROPFILES);
90 pDropFile->fNC = fNonClient;
91 pDropFile->fWide = FALSE;
92 pDropFile->pt = point;
93 //copy strings (excluding terminating 0)
94 memcpy((pDropFile+1), pszFiles, cbszFiles-1);
95 GlobalUnlock(hDropFile);
96
97 return pfnDragEnter(hwnd, hDropFile, dwEffect);
98 }
99 return TRUE; //ignore
100}
101//******************************************************************************
102//******************************************************************************
103BOOL DragDropDragLeave(HWND hwnd)
104{
105 if(pfnDragLeave) {
106 return pfnDragLeave(hwnd);
107 }
108 return TRUE; //ignore
109}
110//******************************************************************************
111//******************************************************************************
112BOOL DragDropAccept(HWND hwnd)
113{
114 DWORD dwExStyle;
115
116 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
117 //Is it correct if the window or parent accepts files or must we check the topparent parent?
118 if(dwExStyle & WS_EX_ACCEPTFILES) {
119 return TRUE;
120 }
121 DWORD dwStyle = GetWindowLongA(GetParent(hwnd), GWL_EXSTYLE);
122 if(!(dwStyle & WS_EX_ACCEPTFILES)) {
123 if(pfnAcceptsDragDrop == NULL) {
124 //check for OLE drag & drop
125
126 hOLE32 = GetModuleHandleA("OLE32.DLL");
127 if(hOLE32 == 0) {
128 //if ole32.dll isn't loaded, then ole drag and drop can't be active
129 return FALSE;
130 }
131 //make sure the dll doesn't get unloaded
132 hOLE32 = LoadLibraryA("OLE32.DLL");
133
134 pfnAcceptsDragDrop = (PFN_ACCEPTSDRAGDROP)GetProcAddress(hOLE32, "OLEDD_AcceptsDragDrop");
135 pfnDragOver = (PFN_DRAGOVER)GetProcAddress(hOLE32, "OLEDD_DragOver");
136 pfnDragLeave = (PFN_DRAGLEAVE)GetProcAddress(hOLE32, "OLEDD_DragLeave");
137 pfnDragEnter = (PFN_DRAGENTER)GetProcAddress(hOLE32, "OLEDD_DragEnter");
138 pfnDropFiles = (PFN_DROPFILES)GetProcAddress(hOLE32, "OLEDD_DropFiles");
139 if(!pfnAcceptsDragDrop || !pfnDragOver || !pfnDragLeave || !pfnDragEnter || !pfnDropFiles) {
140 dprintf(("OLE DD functions not found!!"));
141 DebugInt3();
142 return FALSE;
143 }
144 }
145 if(pfnAcceptsDragDrop) {
146 return pfnAcceptsDragDrop(hwnd);
147 }
148 return FALSE;
149 }
150 return TRUE;
151}
152//******************************************************************************
153//******************************************************************************
154
Note: See TracBrowser for help on using the repository browser.