| 1 | /* $Id: oslibdnd.cpp,v 1.1 2003-07-28 11:28:10 sandervl Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Window Drag and Drop functions for OS/2 | 
|---|
| 4 | * | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 2003 Sander van Leeuwen (sandervl@innotek.de) | 
|---|
| 7 | * | 
|---|
| 8 | * | 
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 10 | * | 
|---|
| 11 | */ | 
|---|
| 12 | #define  INCL_WIN | 
|---|
| 13 | #define  INCL_WINSTDDRAG | 
|---|
| 14 | #define  INCL_PM | 
|---|
| 15 | #include <os2wrap.h> | 
|---|
| 16 | #include <stdlib.h> | 
|---|
| 17 | #include <string.h> | 
|---|
| 18 | #include <stdio.h> | 
|---|
| 19 |  | 
|---|
| 20 | #include <dbglog.h> | 
|---|
| 21 | #include <winconst.h> | 
|---|
| 22 | #include <win32api.h> | 
|---|
| 23 | #include <winuser32.h> | 
|---|
| 24 |  | 
|---|
| 25 | #include "oslibdnd.h" | 
|---|
| 26 |  | 
|---|
| 27 | static char *pszFile = NULL; | 
|---|
| 28 | static HWND  hwndTarget = 0; | 
|---|
| 29 | static PDRAGINFO curDragInfo = NULL; | 
|---|
| 30 | static char *pszCurDragData = NULL; | 
|---|
| 31 |  | 
|---|
| 32 | #if 0 | 
|---|
| 33 | FILE *tmpfile; | 
|---|
| 34 | tmpfile = fopen(pszFile, "wb+"); | 
|---|
| 35 | fwrite(lpszDnDString, 1, strlen(lpszDnDString)+1, tmpfile); | 
|---|
| 36 | fclose(tmpfile); | 
|---|
| 37 | #endif | 
|---|
| 38 | //****************************************************************************** | 
|---|
| 39 | //****************************************************************************** | 
|---|
| 40 | LPVOID OSLibCreateDragStruct(HWND hwndWin32, DWORD x, DWORD y, LPSTR lpszDnDString) | 
|---|
| 41 | { | 
|---|
| 42 | PDRAGINFO  pdinfo;       /* Pointer to DRAGINFO structure        */ | 
|---|
| 43 | HWND       hwnd;         /* Handle of calling (source) window    */ | 
|---|
| 44 | BOOL       flResult;     /* Result indicator                     */ | 
|---|
| 45 | DRAGITEM   ditem;        /* DRAGITEM structure                   */ | 
|---|
| 46 | RECTL      rectl; | 
|---|
| 47 | ULONG      ScreenHeight; | 
|---|
| 48 |  | 
|---|
| 49 | WinQueryWindowRect(HWND_DESKTOP, &rectl); | 
|---|
| 50 | ScreenHeight = rectl.yTop; | 
|---|
| 51 |  | 
|---|
| 52 | pdinfo = DrgAllocDraginfo(1); /* Create the DRAGINFO structure   */ | 
|---|
| 53 | /* Set the drag item               */ | 
|---|
| 54 | if(pdinfo == NULL) { | 
|---|
| 55 | dprintf(("DrgAllocDraginfo FAILED!!")); | 
|---|
| 56 | return NULL; | 
|---|
| 57 | } | 
|---|
| 58 | pdinfo->usOperation  = DO_DEFAULT; | 
|---|
| 59 | pdinfo->hwndSource   = Win32ToOS2Handle(hwndWin32); | 
|---|
| 60 | pdinfo->xDrop        = x; | 
|---|
| 61 | pdinfo->yDrop        = ScreenHeight - y; | 
|---|
| 62 |  | 
|---|
| 63 | char szDir[CCHMAXPATH*4]; | 
|---|
| 64 |  | 
|---|
| 65 | pszFile = (char *)malloc(CCHMAXPATH+1); | 
|---|
| 66 | if(pszFile == NULL) { | 
|---|
| 67 | DebugInt3(); | 
|---|
| 68 | DrgFreeDraginfo(pdinfo); | 
|---|
| 69 | return NULL; | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | tmpnam(pszFile); | 
|---|
| 73 | strcpy(szDir, pszFile); | 
|---|
| 74 |  | 
|---|
| 75 | char *tmp = strrchr(szDir, '\\'); | 
|---|
| 76 | *tmp = 0; | 
|---|
| 77 | tmp++; | 
|---|
| 78 |  | 
|---|
| 79 | dprintf(("temporary file %s", pszFile)); | 
|---|
| 80 |  | 
|---|
| 81 | strcat(szDir, "\\"); | 
|---|
| 82 |  | 
|---|
| 83 | ditem.hwndItem       = pdinfo->hwndSource; | 
|---|
| 84 | ditem.ulItemID       = 0; | 
|---|
| 85 | ditem.hstrType       = DrgAddStrHandle(DRT_TEXT); | 
|---|
| 86 | ditem.hstrRMF        = DrgAddStrHandle("<DRM_OS2FILE, DRF_TEXT>"); | 
|---|
| 87 | ditem.hstrContainerName  = DrgAddStrHandle(szDir); | 
|---|
| 88 | ditem.hstrSourceName = 0; //done during rendering | 
|---|
| 89 | ditem.hstrTargetName = 0; | 
|---|
| 90 | ditem.cxOffset       = 0; | 
|---|
| 91 | ditem.cyOffset       = 0; | 
|---|
| 92 | ditem.fsControl      = 0; | 
|---|
| 93 | ditem.fsSupportedOps = DO_COPYABLE | DO_MOVEABLE; | 
|---|
| 94 |  | 
|---|
| 95 | flResult= DrgSetDragitem(pdinfo, &ditem, (ULONG)sizeof(ditem), 0); | 
|---|
| 96 | if(!flResult) dprintf(("DrgSetDragitem failed for %x", &ditem)); | 
|---|
| 97 |  | 
|---|
| 98 | return pdinfo; | 
|---|
| 99 | } | 
|---|
| 100 | //****************************************************************************** | 
|---|
| 101 | //****************************************************************************** | 
|---|
| 102 | void OSLibFreeDragStruct(LPVOID lpDragStruct) | 
|---|
| 103 | { | 
|---|
| 104 | PDRAGINFO pdinfo = (PDRAGINFO)lpDragStruct; | 
|---|
| 105 | BOOL       flResult;     /* Result indicator                     */ | 
|---|
| 106 |  | 
|---|
| 107 | flResult = DrgDeleteDraginfoStrHandles(pdinfo); | 
|---|
| 108 | if(!flResult) dprintf(("DrgDeleteDraginfoStrHandles failed for %x", lpDragStruct)); | 
|---|
| 109 |  | 
|---|
| 110 | flResult = DrgFreeDraginfo(pdinfo); | 
|---|
| 111 | if(!flResult) dprintf(("DrgFreeDragInfo failed for %x", lpDragStruct)); | 
|---|
| 112 |  | 
|---|
| 113 | return; | 
|---|
| 114 | } | 
|---|
| 115 | //****************************************************************************** | 
|---|
| 116 | //****************************************************************************** | 
|---|
| 117 | DWORD OSLibDragOver(LPVOID lpDragStruct, DWORD x, DWORD y) | 
|---|
| 118 | { | 
|---|
| 119 | PDRAGINFO pdinfo = (PDRAGINFO)lpDragStruct; | 
|---|
| 120 | RECTL      rectl; | 
|---|
| 121 | ULONG      ScreenHeight, ret; | 
|---|
| 122 | HWND       hwnd; | 
|---|
| 123 | POINTL     pointl; | 
|---|
| 124 |  | 
|---|
| 125 | WinQueryWindowRect(HWND_DESKTOP, &rectl); | 
|---|
| 126 | ScreenHeight = rectl.yTop; | 
|---|
| 127 |  | 
|---|
| 128 | pdinfo->xDrop = x; | 
|---|
| 129 | pdinfo->yDrop = ScreenHeight - y; | 
|---|
| 130 |  | 
|---|
| 131 | pointl.x = pdinfo->xDrop; | 
|---|
| 132 | pointl.y = pdinfo->yDrop; | 
|---|
| 133 | hwnd = WinWindowFromPoint(HWND_DESKTOP, &pointl, TRUE); | 
|---|
| 134 | if(hwnd == 0) return DROPEFFECT_NONE_W; | 
|---|
| 135 |  | 
|---|
| 136 | if(hwnd != hwndTarget) { | 
|---|
| 137 | OSLibDragLeave(lpDragStruct); | 
|---|
| 138 | dprintf(("Post DM_DRAGOVER to %x (%x)", OS2ToWin32Handle(hwnd), hwnd)); | 
|---|
| 139 | } | 
|---|
| 140 | hwndTarget = hwnd; | 
|---|
| 141 |  | 
|---|
| 142 | ret = (ULONG)WinSendMsg(hwnd, DM_DRAGOVER, (MPARAM)pdinfo, MPFROM2SHORT(pdinfo->xDrop, pdinfo->yDrop)); | 
|---|
| 143 |  | 
|---|
| 144 | if(LOWORD(ret) != DOR_DROP) { | 
|---|
| 145 | return DROPEFFECT_NONE_W; | 
|---|
| 146 | } | 
|---|
| 147 | if(HIWORD(ret) == DO_LINK) { | 
|---|
| 148 | return DROPEFFECT_LINK_W; | 
|---|
| 149 | } | 
|---|
| 150 | if(HIWORD(ret) == DO_MOVE) { | 
|---|
| 151 | return DROPEFFECT_MOVE_W; | 
|---|
| 152 | } | 
|---|
| 153 | return DROPEFFECT_COPY_W; | 
|---|
| 154 | } | 
|---|
| 155 | //****************************************************************************** | 
|---|
| 156 | //****************************************************************************** | 
|---|
| 157 | DWORD OSLibDragLeave(LPVOID lpDragStruct) | 
|---|
| 158 | { | 
|---|
| 159 | PDRAGINFO  pdinfo = (PDRAGINFO)lpDragStruct; | 
|---|
| 160 | ULONG      ret; | 
|---|
| 161 |  | 
|---|
| 162 | if(hwndTarget) { | 
|---|
| 163 | dprintf(("Post DM_DRAGLEAVE to %x (%x)", OS2ToWin32Handle(hwndTarget), hwndTarget)); | 
|---|
| 164 | ret = (ULONG)WinSendMsg(hwndTarget, DM_DRAGLEAVE, (MPARAM)pdinfo, 0); | 
|---|
| 165 | } | 
|---|
| 166 | return DROPEFFECT_NONE_W; | 
|---|
| 167 | } | 
|---|
| 168 | //****************************************************************************** | 
|---|
| 169 | //****************************************************************************** | 
|---|
| 170 | DWORD OSLibDragDrop(LPVOID lpDragStruct, DWORD x, DWORD y, LPSTR lpszDnDString) | 
|---|
| 171 | { | 
|---|
| 172 | PDRAGINFO pdinfo = (PDRAGINFO)lpDragStruct; | 
|---|
| 173 | RECTL      rectl; | 
|---|
| 174 | ULONG      ScreenHeight, ret; | 
|---|
| 175 | HWND       hwnd; | 
|---|
| 176 | POINTL     pointl; | 
|---|
| 177 |  | 
|---|
| 178 | WinQueryWindowRect(HWND_DESKTOP, &rectl); | 
|---|
| 179 | ScreenHeight = rectl.yTop; | 
|---|
| 180 |  | 
|---|
| 181 | pdinfo->xDrop = x; | 
|---|
| 182 | pdinfo->yDrop = ScreenHeight - y; | 
|---|
| 183 |  | 
|---|
| 184 | pointl.x = pdinfo->xDrop; | 
|---|
| 185 | pointl.y = pdinfo->yDrop; | 
|---|
| 186 | hwnd = WinWindowFromPoint(HWND_DESKTOP, &pointl, TRUE); | 
|---|
| 187 | if(hwnd == 0) return DROPEFFECT_NONE_W; | 
|---|
| 188 |  | 
|---|
| 189 | hwndTarget = hwnd; | 
|---|
| 190 | curDragInfo = pdinfo; | 
|---|
| 191 | pszCurDragData = lpszDnDString; | 
|---|
| 192 |  | 
|---|
| 193 | dprintf(("dnd data %s", pszCurDragData)); | 
|---|
| 194 |  | 
|---|
| 195 | ret = (ULONG)WinSendMsg(hwnd, DM_DROP, (MPARAM)pdinfo, 0); | 
|---|
| 196 |  | 
|---|
| 197 | pszCurDragData = NULL; | 
|---|
| 198 | curDragInfo = NULL; | 
|---|
| 199 | hwndTarget = 0; | 
|---|
| 200 | return DROPEFFECT_COPY_W; | 
|---|
| 201 | } | 
|---|
| 202 | //****************************************************************************** | 
|---|
| 203 | //****************************************************************************** | 
|---|
| 204 | BOOL OSLibRenderFormat(PDRAGTRANSFER pDragTransfer) | 
|---|
| 205 | { | 
|---|
| 206 | PDRAGITEM pDragItem = pDragTransfer->pditem; | 
|---|
| 207 | int size = 0, ulBytes; | 
|---|
| 208 | char *tmp; | 
|---|
| 209 |  | 
|---|
| 210 | #ifdef DEBUG | 
|---|
| 211 | size = DrgQueryStrNameLen(pDragTransfer->hstrSelectedRMF); | 
|---|
| 212 | tmp = (char *)malloc(size+2); | 
|---|
| 213 | if(tmp == NULL) { | 
|---|
| 214 | DebugInt3(); | 
|---|
| 215 | return FALSE; | 
|---|
| 216 | } | 
|---|
| 217 | size = DrgQueryStrName(pDragTransfer->hstrSelectedRMF, size+1, tmp); | 
|---|
| 218 | dprintf(("Rendering method %s", tmp)); | 
|---|
| 219 | free(tmp); | 
|---|
| 220 | #endif | 
|---|
| 221 |  | 
|---|
| 222 | size = DrgQueryStrNameLen(pDragTransfer->hstrRenderToName); | 
|---|
| 223 | tmp = (char *)malloc(size+2); | 
|---|
| 224 | if(tmp == NULL) { | 
|---|
| 225 | DebugInt3(); | 
|---|
| 226 | return FALSE; | 
|---|
| 227 | } | 
|---|
| 228 | size = DrgQueryStrName(pDragTransfer->hstrRenderToName, size+1, tmp); | 
|---|
| 229 |  | 
|---|
| 230 | dprintf(("Render to file %s", tmp)); | 
|---|
| 231 |  | 
|---|
| 232 | dprintf(("dnd data %s", pszCurDragData)); | 
|---|
| 233 |  | 
|---|
| 234 | FILE *tmpfile; | 
|---|
| 235 | tmpfile = fopen(tmp, "wb+"); | 
|---|
| 236 | fwrite(pszCurDragData, 1, strlen(pszCurDragData), tmpfile); | 
|---|
| 237 | fclose(tmpfile); | 
|---|
| 238 |  | 
|---|
| 239 | DrgPostTransferMsg(pDragTransfer->hwndClient, DM_RENDERCOMPLETE, pDragTransfer, | 
|---|
| 240 | DMFL_RENDEROK, 0, TRUE); | 
|---|
| 241 |  | 
|---|
| 242 | DrgFreeDragtransfer(pDragTransfer); | 
|---|
| 243 | free(tmp); | 
|---|
| 244 | return TRUE; | 
|---|
| 245 | } | 
|---|
| 246 | //****************************************************************************** | 
|---|
| 247 | //****************************************************************************** | 
|---|
| 248 | ULONG OSLibEndConversation() | 
|---|
| 249 | { | 
|---|
| 250 | return 0; | 
|---|
| 251 | } | 
|---|
| 252 | //****************************************************************************** | 
|---|
| 253 | //****************************************************************************** | 
|---|