[10185] | 1 | /* $Id: dragdrop.cpp,v 1.4 2003-07-28 11:27:45 sandervl Exp $ */
|
---|
[8542] | 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>
|
---|
[8553] | 13 | #include <oledd.h>
|
---|
[8542] | 14 |
|
---|
| 15 | #define DBG_LOCALLOG DBG_dragdrop
|
---|
| 16 | #include "dbglocal.h"
|
---|
| 17 |
|
---|
[8553] | 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 |
|
---|
[8542] | 25 | //******************************************************************************
|
---|
| 26 | //******************************************************************************
|
---|
[8553] | 27 | ULONG DragDropFiles(HWND hwnd, POINT point, UINT cFiles, LPSTR pszFiles, UINT cbszFiles, BOOL fNonClient)
|
---|
[8542] | 28 | {
|
---|
| 29 | DROPFILES *pDropFile;
|
---|
| 30 | HGLOBAL hDropFile;
|
---|
| 31 | DWORD dwExStyle;
|
---|
[8553] | 32 | HWND orghwnd = hwnd;
|
---|
[10185] | 33 |
|
---|
| 34 | dprintf(("DragDropFiles %x (%d,%d) %d %s %d %d", hwnd, point.x, point.y, cFiles, pszFiles, cbszFiles, fNonClient));
|
---|
| 35 |
|
---|
[8735] | 36 | dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
|
---|
[8542] | 37 |
|
---|
[8553] | 38 | //TODO: Is it correct if the window or parent accepts files or must we check the top parent?
|
---|
[8542] | 39 | hwnd = (dwExStyle & WS_EX_ACCEPTFILES) ? hwnd : GetParent(hwnd);
|
---|
[8735] | 40 | dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
|
---|
[8542] | 41 |
|
---|
[8553] | 42 | if(!(dwExStyle & WS_EX_ACCEPTFILES)) {
|
---|
| 43 | if(pfnDropFiles) {
|
---|
[8735] | 44 | return pfnDropFiles(orghwnd);
|
---|
[8553] | 45 | }
|
---|
| 46 | return FALSE;
|
---|
[8542] | 47 | }
|
---|
[8735] | 48 |
|
---|
[8553] | 49 | cbszFiles++; //extra terminating 0
|
---|
[8542] | 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;
|
---|
[8553] | 58 | pDropFile->fWide = FALSE;
|
---|
[8542] | 59 | pDropFile->pt = point;
|
---|
[8553] | 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 | {
|
---|
[10185] | 70 | dprintf(("DragDropDragOver %x %x", hwnd, dwEffect));
|
---|
[8553] | 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 |
|
---|
[10185] | 84 | dprintf(("DragDropDragEnter %x (%d,%d) %d %s %d %d", hwnd, point.x, point.y, cFiles, pszFiles, cbszFiles, fNonClient));
|
---|
| 85 |
|
---|
[8553] | 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;
|
---|
[8542] | 93 | }
|
---|
[8553] | 94 | pDropFile->pFiles = sizeof(DROPFILES);
|
---|
| 95 | pDropFile->fNC = fNonClient;
|
---|
| 96 | pDropFile->fWide = FALSE;
|
---|
| 97 | pDropFile->pt = point;
|
---|
[8542] | 98 | //copy strings (excluding terminating 0)
|
---|
| 99 | memcpy((pDropFile+1), pszFiles, cbszFiles-1);
|
---|
[8553] | 100 | GlobalUnlock(hDropFile);
|
---|
| 101 |
|
---|
| 102 | return pfnDragEnter(hwnd, hDropFile, dwEffect);
|
---|
[8542] | 103 | }
|
---|
[8553] | 104 | return TRUE; //ignore
|
---|
[8542] | 105 | }
|
---|
| 106 | //******************************************************************************
|
---|
| 107 | //******************************************************************************
|
---|
[8553] | 108 | BOOL DragDropDragLeave(HWND hwnd)
|
---|
| 109 | {
|
---|
[10185] | 110 | dprintf(("DragDropDragLeave %x", hwnd));
|
---|
[8553] | 111 | if(pfnDragLeave) {
|
---|
| 112 | return pfnDragLeave(hwnd);
|
---|
| 113 | }
|
---|
| 114 | return TRUE; //ignore
|
---|
| 115 | }
|
---|
| 116 | //******************************************************************************
|
---|
| 117 | //******************************************************************************
|
---|
[8542] | 118 | BOOL DragDropAccept(HWND hwnd)
|
---|
| 119 | {
|
---|
| 120 | DWORD dwExStyle;
|
---|
| 121 |
|
---|
[10185] | 122 | dprintf(("DragDropDragAccept %x", hwnd));
|
---|
| 123 |
|
---|
[8542] | 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)) {
|
---|
[8553] | 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 | }
|
---|
[8542] | 156 | return FALSE;
|
---|
| 157 | }
|
---|
| 158 | return TRUE;
|
---|
| 159 | }
|
---|
| 160 | //******************************************************************************
|
---|
| 161 | //******************************************************************************
|
---|
| 162 |
|
---|