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

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

added ole drag and drop (wps -> odin app) support

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