| 1 |  | 
|---|
| 2 | /*********************************************************************** | 
|---|
| 3 |  | 
|---|
| 4 | $Id: draglist.c 364 2006-07-27 00:44:53Z root $ | 
|---|
| 5 |  | 
|---|
| 6 | Drag drop support | 
|---|
| 7 |  | 
|---|
| 8 | Copyright (c) 1993-98 M. Kimes | 
|---|
| 9 | Copyright (c) 2001, 2002 Steven H.Levine | 
|---|
| 10 |  | 
|---|
| 11 | 16 Oct 02 SHL DoFileDrag: don't free stack | 
|---|
| 12 | 26 Jul 06 SHL Check more run time errors | 
|---|
| 13 |  | 
|---|
| 14 | ***********************************************************************/ | 
|---|
| 15 |  | 
|---|
| 16 | #define INCL_DOS | 
|---|
| 17 | #define INCL_WIN | 
|---|
| 18 | #include <os2.h> | 
|---|
| 19 |  | 
|---|
| 20 | #include <stdio.h> | 
|---|
| 21 | #include <stdlib.h> | 
|---|
| 22 | #include <string.h> | 
|---|
| 23 | #include <ctype.h> | 
|---|
| 24 |  | 
|---|
| 25 | #include "fm3dll.h" | 
|---|
| 26 |  | 
|---|
| 27 | static PSZ pszSrcFile = __FILE__; | 
|---|
| 28 |  | 
|---|
| 29 | #pragma alloc_text(DRAGLIST,DragOne,DoFileDrag,DragList,PickUp) | 
|---|
| 30 |  | 
|---|
| 31 | HWND DragOne (HWND hwndCnr,HWND hwndObj,CHAR *filename,BOOL moveok) { | 
|---|
| 32 |  | 
|---|
| 33 | DRAGITEM    DItem; | 
|---|
| 34 | HWND        hDrop = 0; | 
|---|
| 35 | DRAGIMAGE   fakeicon; | 
|---|
| 36 | PDRAGINFO   pDInfo; | 
|---|
| 37 | FILESTATUS3 fs3; | 
|---|
| 38 | CHAR        szDir[CCHMAXPATH],szFile[CCHMAXPATH],*p; | 
|---|
| 39 |  | 
|---|
| 40 | if(filename && *filename) { | 
|---|
| 41 | if((IsRoot(filename) && IsValidDrive(*filename)) || | 
|---|
| 42 | !DosQueryPathInfo(filename,FIL_STANDARD,&fs3,sizeof(fs3))) { | 
|---|
| 43 | strcpy(szDir,filename); | 
|---|
| 44 | p = szDir; | 
|---|
| 45 | while(*p) { | 
|---|
| 46 | if(*p == '/') | 
|---|
| 47 | *p = '\\'; | 
|---|
| 48 | p++; | 
|---|
| 49 | } | 
|---|
| 50 | p = strrchr(szDir,'\\'); | 
|---|
| 51 | if(p) { | 
|---|
| 52 | *p = 0; | 
|---|
| 53 | p++; | 
|---|
| 54 | strcpy(szFile,p); | 
|---|
| 55 | strcat(szDir,"\\"); | 
|---|
| 56 | } | 
|---|
| 57 | else { | 
|---|
| 58 | strcpy(szFile,filename); | 
|---|
| 59 | *szDir = 0; | 
|---|
| 60 | } | 
|---|
| 61 | memset(&fakeicon,0,sizeof(DRAGIMAGE)); | 
|---|
| 62 | fakeicon.hImage = (IsRoot(filename) || | 
|---|
| 63 | (fs3.attrFile & FILE_DIRECTORY) != 0) ? | 
|---|
| 64 | hptrDir : hptrFile; | 
|---|
| 65 | memset(&DItem,0,sizeof(DRAGITEM)); | 
|---|
| 66 | DItem.hwndItem = (hwndObj) ? hwndObj : hwndCnr; /* Initialize DRAGITEM */ | 
|---|
| 67 | // DItem.hwndItem = hwndCnr; | 
|---|
| 68 | DItem.ulItemID = 1; | 
|---|
| 69 | DItem.hstrType = DrgAddStrHandle(DRT_UNKNOWN); | 
|---|
| 70 | DItem.hstrRMF = | 
|---|
| 71 | DrgAddStrHandle(DRMDRFLIST); | 
|---|
| 72 | DItem.hstrContainerName = DrgAddStrHandle(szDir); | 
|---|
| 73 | DItem.hstrSourceName = DrgAddStrHandle(szFile); | 
|---|
| 74 | DItem.hstrTargetName = DrgAddStrHandle(szFile); | 
|---|
| 75 | DItem.fsControl = 0; | 
|---|
| 76 | if(IsRoot(filename) || (fs3.attrFile & FILE_DIRECTORY) != 0) | 
|---|
| 77 | DItem.fsControl |= DC_CONTAINER; | 
|---|
| 78 | if(IsFullName(filename) && | 
|---|
| 79 | (driveflags[toupper(*filename) - 'A'] & DRIVE_REMOVABLE)) | 
|---|
| 80 | DItem.fsControl |= DC_REMOVEABLEMEDIA; | 
|---|
| 81 | DItem.fsSupportedOps = DO_COPYABLE | DO_LINKABLE; | 
|---|
| 82 | if(moveok && IsFullName(filename) && | 
|---|
| 83 | !(driveflags[toupper(*filename) - 'A'] & DRIVE_NOTWRITEABLE)) | 
|---|
| 84 | DItem.fsSupportedOps |= DO_MOVEABLE; | 
|---|
| 85 | if(IsRoot(filename)) | 
|---|
| 86 | DItem.fsSupportedOps = DO_LINKABLE; | 
|---|
| 87 | fakeicon.cb = sizeof(DRAGIMAGE); | 
|---|
| 88 | fakeicon.cptl = 0; | 
|---|
| 89 | fakeicon.fl = DRG_ICON; | 
|---|
| 90 | fakeicon.sizlStretch.cx = 32; | 
|---|
| 91 | fakeicon.sizlStretch.cy = 32; | 
|---|
| 92 | fakeicon.cxOffset = -16; | 
|---|
| 93 | fakeicon.cyOffset = 0; | 
|---|
| 94 | pDInfo = DrgAllocDraginfo(1);     /* Allocate DRAGINFO */ | 
|---|
| 95 | if(pDInfo) { | 
|---|
| 96 | if(IsFullName(filename) && | 
|---|
| 97 | (driveflags[toupper(*filename) - 'A'] & DRIVE_NOTWRITEABLE)) | 
|---|
| 98 | pDInfo->usOperation = DO_COPY; | 
|---|
| 99 | else | 
|---|
| 100 | pDInfo->usOperation = DO_DEFAULT; | 
|---|
| 101 | if(IsRoot(filename)) | 
|---|
| 102 | pDInfo->usOperation = DO_LINK; | 
|---|
| 103 | pDInfo->hwndSource = (hwndObj) ? hwndObj : hwndCnr; | 
|---|
| 104 | // pDInfo->hwndSource = hwndCnr; | 
|---|
| 105 | DrgSetDragitem(pDInfo,            /* Set item in DRAGINFO  */ | 
|---|
| 106 | &DItem,            /* Pointer to DRAGITEM   */ | 
|---|
| 107 | sizeof(DRAGITEM),  /* Size of DRAGITEM      */ | 
|---|
| 108 | 0);                /* Index of DRAGITEM     */ | 
|---|
| 109 | WinSetFocus(HWND_DESKTOP,HWND_DESKTOP); | 
|---|
| 110 | hDrop = DrgDrag(hwndCnr,              /* Initiate drag         */ | 
|---|
| 111 | pDInfo,               /* DRAGINFO structure    */ | 
|---|
| 112 | &fakeicon, | 
|---|
| 113 | 1L, | 
|---|
| 114 | VK_ENDDRAG,           /* End of drag indicator */ | 
|---|
| 115 | (PVOID)NULL);         /* Reserved              */ | 
|---|
| 116 |  | 
|---|
| 117 | DrgFreeDraginfo(pDInfo);              /* Free DRAGINFO struct  */ | 
|---|
| 118 | WinSetWindowPos(hwndCnr,HWND_TOP,0,0,0,0,SWP_ACTIVATE); | 
|---|
| 119 | } | 
|---|
| 120 | } | 
|---|
| 121 | } | 
|---|
| 122 | return hDrop; | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 |  | 
|---|
| 126 | HWND DoFileDrag (HWND hwndCnr,HWND hwndObj,PCNRDRAGINIT pcd,CHAR *arcfile, | 
|---|
| 127 | CHAR *directory,BOOL moveok) | 
|---|
| 128 | { | 
|---|
| 129 | /* drag files from a container */ | 
|---|
| 130 |  | 
|---|
| 131 | BOOL           isdir,rooting = FALSE; | 
|---|
| 132 | PCNRITEM       pci; | 
|---|
| 133 | register CHAR  *p; | 
|---|
| 134 | INT            attribute = CRA_CURSORED; | 
|---|
| 135 | PDRAGINFO      pDInfo = NULL; | 
|---|
| 136 | DRAGITEM       **ppDItem = NULL,**ppTest; | 
|---|
| 137 | PCNRITEM       pciRec = (PCNRITEM)pcd->pRecord; | 
|---|
| 138 | HWND           hDrop = 0; | 
|---|
| 139 | register ULONG ulNumfiles = 0L,numdragalloc = 0L,Select,ulNumIcon = 0; | 
|---|
| 140 | CHAR           szFile[CCHMAXPATH],szBuffer[CCHMAXPATH]; | 
|---|
| 141 | DRAGIMAGE      *padiIcon = NULL,*padiTest,diFakeIcon; | 
|---|
| 142 |  | 
|---|
| 143 | if(!pciRec && directory && *directory) | 
|---|
| 144 | return DragOne(hwndCnr,hwndObj,directory,moveok); | 
|---|
| 145 |  | 
|---|
| 146 | if(!pciRec) { | 
|---|
| 147 | pci = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORDEMPHASIS, | 
|---|
| 148 | MPFROMLONG(CMA_FIRST), | 
|---|
| 149 | MPFROMSHORT(attribute)); | 
|---|
| 150 | if(pci && (INT)pci > -1) { | 
|---|
| 151 | if(pci->rc.flRecordAttr & CRA_SELECTED) { | 
|---|
| 152 | attribute = CRA_SELECTED; | 
|---|
| 153 | pci = WinSendMsg(hwndCnr,CM_QUERYRECORDEMPHASIS,MPFROMLONG(CMA_FIRST), | 
|---|
| 154 | MPFROMSHORT(attribute)); | 
|---|
| 155 | } | 
|---|
| 156 | } | 
|---|
| 157 | } | 
|---|
| 158 | else { | 
|---|
| 159 | pci = pciRec; | 
|---|
| 160 | attribute = (pci->rc.flRecordAttr & CRA_SELECTED) ? CRA_SELECTED : 0; | 
|---|
| 161 | if(attribute) { | 
|---|
| 162 | pci = WinSendMsg(hwndCnr,CM_QUERYRECORDEMPHASIS,MPFROMLONG(CMA_FIRST), | 
|---|
| 163 | MPFROMSHORT(attribute)); | 
|---|
| 164 | } | 
|---|
| 165 | } | 
|---|
| 166 |  | 
|---|
| 167 | Select = 0L; | 
|---|
| 168 | while( pci && (INT)pci > -1) { | 
|---|
| 169 | if(!(pci->rc.flRecordAttr & CRA_FILTERED)) { | 
|---|
| 170 | if(IsRoot(pci->szFileName) && !IsValidDrive(*pci->szFileName)) | 
|---|
| 171 | goto Continuing; | 
|---|
| 172 | if(!arcfile) { | 
|---|
| 173 | strcpy(szBuffer,pci->szFileName); | 
|---|
| 174 | p = strrchr(szBuffer,'\\'); | 
|---|
| 175 | if(p) { | 
|---|
| 176 | p++; | 
|---|
| 177 | strcpy(szFile,p); | 
|---|
| 178 | *p = 0; | 
|---|
| 179 | } | 
|---|
| 180 | else | 
|---|
| 181 | goto Continuing; | 
|---|
| 182 | } | 
|---|
| 183 | else | 
|---|
| 184 | strcpy(szFile,pci->szFileName); | 
|---|
| 185 | } | 
|---|
| 186 | if(!arcfile) { | 
|---|
| 187 | // Filesystem object | 
|---|
| 188 | isdir = ((pci->attrFile & FILE_DIRECTORY) != 0); | 
|---|
| 189 | if(ulNumfiles + 2L > numdragalloc) { | 
|---|
| 190 | if (!padiIcon) { | 
|---|
| 191 | padiTest = xrealloc(padiIcon,sizeof(DRAGIMAGE) * (numdragalloc + 4L), pszSrcFile, __LINE__); | 
|---|
| 192 | if(padiTest) | 
|---|
| 193 | padiIcon = padiTest; | 
|---|
| 194 | else | 
|---|
| 195 | break; | 
|---|
| 196 | } | 
|---|
| 197 | else if(!ulNumIcon) { | 
|---|
| 198 | padiIcon[ulNumfiles].cb = sizeof(DRAGIMAGE); | 
|---|
| 199 | padiIcon[ulNumfiles].cptl = 0; | 
|---|
| 200 | padiIcon[ulNumfiles].hImage = hptrLast; | 
|---|
| 201 | padiIcon[ulNumfiles].fl = DRG_ICON; | 
|---|
| 202 | padiIcon[ulNumfiles].sizlStretch.cx = 32; | 
|---|
| 203 | padiIcon[ulNumfiles].sizlStretch.cy = 32; | 
|---|
| 204 | padiIcon[ulNumfiles].cxOffset = -16 + (ulNumfiles * 4); | 
|---|
| 205 | padiIcon[ulNumfiles].cyOffset = 0 + (ulNumfiles * 7); | 
|---|
| 206 | ulNumIcon = ulNumfiles + 1; | 
|---|
| 207 | } | 
|---|
| 208 | ppTest = xrealloc(ppDItem,sizeof(DRAGITEM *) * (numdragalloc + 4L), pszSrcFile, __LINE__); | 
|---|
| 209 | if (ppTest) { | 
|---|
| 210 | ppDItem = ppTest; | 
|---|
| 211 | numdragalloc += 4L; | 
|---|
| 212 | } | 
|---|
| 213 | else | 
|---|
| 214 | break; | 
|---|
| 215 | } | 
|---|
| 216 | ppDItem[ulNumfiles] = xmalloc(sizeof(DRAGITEM), pszSrcFile, __LINE__); | 
|---|
| 217 | if (ppDItem[ulNumfiles]) { | 
|---|
| 218 | if (!ulNumIcon) { | 
|---|
| 219 | padiIcon[ulNumfiles].cb = sizeof(DRAGIMAGE); | 
|---|
| 220 | padiIcon[ulNumfiles].cptl = 0; | 
|---|
| 221 | padiIcon[ulNumfiles].hImage = pci->rc.hptrIcon; | 
|---|
| 222 | if(!padiIcon[ulNumfiles].hImage) | 
|---|
| 223 | padiIcon[ulNumfiles].hImage = (isdir) ? hptrDir : hptrFile; | 
|---|
| 224 | padiIcon[ulNumfiles].fl = DRG_ICON; | 
|---|
| 225 | padiIcon[ulNumfiles].sizlStretch.cx = 32; | 
|---|
| 226 | padiIcon[ulNumfiles].sizlStretch.cy = 32; | 
|---|
| 227 | padiIcon[ulNumfiles].cxOffset = -16 + (ulNumfiles * 3); | 
|---|
| 228 | padiIcon[ulNumfiles].cyOffset = 0 + (ulNumfiles * 6); | 
|---|
| 229 | } | 
|---|
| 230 | memset(ppDItem[ulNumfiles],0,sizeof(DRAGITEM)); | 
|---|
| 231 | ppDItem[ulNumfiles]->hwndItem = (hwndObj) ? hwndObj : hwndCnr; /* Initialize DRAGITEM   */ | 
|---|
| 232 | ppDItem[ulNumfiles]->hwndItem = hwndCnr; | 
|---|
| 233 | ppDItem[ulNumfiles]->ulItemID = (ULONG)pci; | 
|---|
| 234 | ppDItem[ulNumfiles]->hstrType = DrgAddStrHandle(DRT_UNKNOWN); | 
|---|
| 235 | ppDItem[ulNumfiles]->hstrRMF = DrgAddStrHandle(DRMDRFLIST); | 
|---|
| 236 | ppDItem[ulNumfiles]->hstrContainerName = DrgAddStrHandle(szBuffer); | 
|---|
| 237 | ppDItem[ulNumfiles]->hstrSourceName = DrgAddStrHandle(szFile); | 
|---|
| 238 | ppDItem[ulNumfiles]->hstrTargetName = DrgAddStrHandle(szFile); | 
|---|
| 239 | ppDItem[ulNumfiles]->fsControl = (isdir) ? DC_CONTAINER : 0; | 
|---|
| 240 | if(IsFullName(pci->szFileName) && | 
|---|
| 241 | (driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_REMOVABLE)) | 
|---|
| 242 | ppDItem[ulNumfiles]->fsControl |= DC_REMOVEABLEMEDIA; | 
|---|
| 243 | ppDItem[ulNumfiles]->fsSupportedOps = DO_COPYABLE | DO_LINKABLE; | 
|---|
| 244 | if(moveok && IsFullName(pci->szFileName) && | 
|---|
| 245 | !(driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOTWRITEABLE)) | 
|---|
| 246 | ppDItem[ulNumfiles]->fsSupportedOps |= DO_MOVEABLE; | 
|---|
| 247 | if(IsRoot(pci->szFileName)) { | 
|---|
| 248 | ppDItem[ulNumfiles]->fsSupportedOps = DO_LINKABLE; | 
|---|
| 249 | rooting = TRUE; | 
|---|
| 250 | } | 
|---|
| 251 | ulNumfiles++; | 
|---|
| 252 | ppDItem[ulNumfiles] = NULL; | 
|---|
| 253 | } | 
|---|
| 254 | else | 
|---|
| 255 | break; | 
|---|
| 256 | } | 
|---|
| 257 | else { | 
|---|
| 258 | // Archive object | 
|---|
| 259 | if(ulNumfiles + 3L > numdragalloc) { | 
|---|
| 260 | ppTest = xrealloc(ppDItem,sizeof(DRAGITEM *) * (numdragalloc + 5L), pszSrcFile, __LINE__); | 
|---|
| 261 | if (!ppTest) | 
|---|
| 262 | break; | 
|---|
| 263 | else { | 
|---|
| 264 | ppDItem = ppTest; | 
|---|
| 265 | numdragalloc += 5L; | 
|---|
| 266 | } | 
|---|
| 267 | } | 
|---|
| 268 | ppDItem[ulNumfiles] = xmalloc(sizeof(DRAGITEM), pszSrcFile, __LINE__); | 
|---|
| 269 | if (!ppDItem[ulNumfiles]) | 
|---|
| 270 | break; | 
|---|
| 271 | else { | 
|---|
| 272 | diFakeIcon.hImage = hptrFile; | 
|---|
| 273 | memset(ppDItem[ulNumfiles],0,sizeof(DRAGITEM)); | 
|---|
| 274 | ppDItem[ulNumfiles]->hwndItem = (hwndObj) ? hwndObj : hwndCnr; /* Initialize DRAGITEM   */ | 
|---|
| 275 | ppDItem[ulNumfiles]->hwndItem = hwndCnr; | 
|---|
| 276 | ppDItem[ulNumfiles]->ulItemID = (ULONG)pci; | 
|---|
| 277 | ppDItem[ulNumfiles]->hstrType = DrgAddStrHandle(DRT_UNKNOWN); | 
|---|
| 278 | ppDItem[ulNumfiles]->hstrRMF = DrgAddStrHandle(DRMDRFOS2FILE); | 
|---|
| 279 | ppDItem[ulNumfiles]->hstrContainerName = DrgAddStrHandle(arcfile); | 
|---|
| 280 | ppDItem[ulNumfiles]->hstrSourceName = DrgAddStrHandle(szFile); | 
|---|
| 281 | ppDItem[ulNumfiles]->hstrTargetName = DrgAddStrHandle(szFile); | 
|---|
| 282 | ppDItem[ulNumfiles]->fsControl = DC_PREPARE; | 
|---|
| 283 | if(IsFullName(arcfile) && | 
|---|
| 284 | (driveflags[toupper(*arcfile) - 'A'] & DRIVE_REMOVABLE)) | 
|---|
| 285 | ppDItem[ulNumfiles]->fsControl |= DC_REMOVEABLEMEDIA; | 
|---|
| 286 | ppDItem[ulNumfiles]->fsSupportedOps = DO_COPYABLE; | 
|---|
| 287 | ulNumfiles++; | 
|---|
| 288 | ppDItem[ulNumfiles] = xmalloc(sizeof(DRAGITEM), pszSrcFile, __LINE__); | 
|---|
| 289 | if (ppDItem[ulNumfiles]) { | 
|---|
| 290 | diFakeIcon.hImage = hptrFile; | 
|---|
| 291 | memset(ppDItem[ulNumfiles],0,sizeof(DRAGITEM)); | 
|---|
| 292 | ppDItem[ulNumfiles]->hwndItem = (hwndObj) ? hwndObj : hwndCnr; /* Initialize DRAGITEM   */ | 
|---|
| 293 | ppDItem[ulNumfiles]->hwndItem = hwndCnr; | 
|---|
| 294 | ppDItem[ulNumfiles]->ulItemID = Select++; | 
|---|
| 295 | ppDItem[ulNumfiles]->hstrType = DrgAddStrHandle(DRT_UNKNOWN); | 
|---|
| 296 | ppDItem[ulNumfiles]->hstrRMF = DrgAddStrHandle(DRMDRFFM2ARC); | 
|---|
| 297 | ppDItem[ulNumfiles]->hstrContainerName = DrgAddStrHandle(arcfile); | 
|---|
| 298 | ppDItem[ulNumfiles]->hstrSourceName = DrgAddStrHandle(szFile); | 
|---|
| 299 | ppDItem[ulNumfiles]->hstrTargetName = DrgAddStrHandle(szFile); | 
|---|
| 300 | ppDItem[ulNumfiles]->fsControl = 0; | 
|---|
| 301 | if(IsFullName(arcfile) && | 
|---|
| 302 | (driveflags[toupper(*arcfile) - 'A'] & DRIVE_REMOVABLE)) | 
|---|
| 303 | ppDItem[ulNumfiles]->fsControl |= DC_REMOVEABLEMEDIA; | 
|---|
| 304 | ppDItem[ulNumfiles]->fsSupportedOps = DO_COPYABLE; | 
|---|
| 305 | ulNumfiles++; | 
|---|
| 306 | } | 
|---|
| 307 | ppDItem[ulNumfiles] = NULL; | 
|---|
| 308 | } | 
|---|
| 309 | } | 
|---|
| 310 | WinSendMsg(hwndCnr,CM_SETRECORDEMPHASIS,MPFROMP(pci), | 
|---|
| 311 | MPFROM2SHORT(TRUE,CRA_SOURCE)); | 
|---|
| 312 |  | 
|---|
| 313 | Continuing: | 
|---|
| 314 |  | 
|---|
| 315 | if(!attribute) | 
|---|
| 316 | break; | 
|---|
| 317 | pci = WinSendMsg(hwndCnr,CM_QUERYRECORDEMPHASIS,MPFROMP(pci), | 
|---|
| 318 | MPFROMSHORT(attribute)); | 
|---|
| 319 | } // while | 
|---|
| 320 |  | 
|---|
| 321 | if(ulNumfiles) { | 
|---|
| 322 | pDInfo = DrgAllocDraginfo(ulNumfiles);  /* Allocate DRAGINFO */ | 
|---|
| 323 | if(pDInfo) { | 
|---|
| 324 | if((arcfile && *arcfile) || (IsFullName(szBuffer) && | 
|---|
| 325 | (driveflags[toupper(*szBuffer) - 'A'] & DRIVE_NOTWRITEABLE))) | 
|---|
| 326 | pDInfo->usOperation = DO_COPY; | 
|---|
| 327 | else | 
|---|
| 328 | pDInfo->usOperation = DO_DEFAULT; | 
|---|
| 329 | if((!arcfile || !*arcfile) && rooting) | 
|---|
| 330 | pDInfo->usOperation = DO_LINK; | 
|---|
| 331 | pDInfo->hwndSource = (hwndObj) ? hwndObj : hwndCnr; | 
|---|
| 332 | // pDInfo->hwndSource = hwndCnr; | 
|---|
| 333 | for(Select = 0L;Select < ulNumfiles;Select++) { | 
|---|
| 334 | DrgSetDragitem(pDInfo,                  /* Set item in DRAGINFO  */ | 
|---|
| 335 | ppDItem[Select],         /* Pointer to DRAGITEM   */ | 
|---|
| 336 | sizeof(DRAGITEM),        /* Size of DRAGITEM      */ | 
|---|
| 337 | Select);                 /* Index of DRAGITEM     */ | 
|---|
| 338 | free(ppDItem[Select]); | 
|---|
| 339 | } | 
|---|
| 340 | #ifdef __DEBUG_ALLOC__ | 
|---|
| 341 | _heap_check(); | 
|---|
| 342 | #endif | 
|---|
| 343 | free(ppDItem); | 
|---|
| 344 | ppDItem = NULL; | 
|---|
| 345 | DosPostEventSem(CompactSem); | 
|---|
| 346 |  | 
|---|
| 347 | if(arcfile) { | 
|---|
| 348 | diFakeIcon.cb = sizeof(DRAGIMAGE); | 
|---|
| 349 | diFakeIcon.cptl = 0; | 
|---|
| 350 | if(ulNumfiles > 1) | 
|---|
| 351 | diFakeIcon.hImage = hptrFile; | 
|---|
| 352 | diFakeIcon.fl = DRG_ICON; | 
|---|
| 353 | diFakeIcon.sizlStretch.cx = 32; | 
|---|
| 354 | diFakeIcon.sizlStretch.cy = 32; | 
|---|
| 355 | diFakeIcon.cxOffset = -16; | 
|---|
| 356 | diFakeIcon.cyOffset = 0; | 
|---|
| 357 | padiIcon = &diFakeIcon; | 
|---|
| 358 | } | 
|---|
| 359 | if(!arcfile) { | 
|---|
| 360 | if(!ulNumIcon) | 
|---|
| 361 | ulNumIcon = ulNumfiles; | 
|---|
| 362 | } | 
|---|
| 363 | else | 
|---|
| 364 | ulNumIcon = 1L; | 
|---|
| 365 |  | 
|---|
| 366 | WinSetFocus(HWND_DESKTOP,HWND_DESKTOP); | 
|---|
| 367 | hDrop = DrgDrag(hwndCnr,              /* Initiate drag         */ | 
|---|
| 368 | pDInfo,               /* DRAGINFO structure    */ | 
|---|
| 369 | padiIcon, | 
|---|
| 370 | ulNumIcon, | 
|---|
| 371 | VK_ENDDRAG,           /* End of drag indicator */ | 
|---|
| 372 | (PVOID)NULL);         /* Reserved              */ | 
|---|
| 373 |  | 
|---|
| 374 | DrgFreeDraginfo(pDInfo);              /* Free DRAGINFO struct  */ | 
|---|
| 375 | if(padiIcon && padiIcon != &diFakeIcon) | 
|---|
| 376 | free(padiIcon); | 
|---|
| 377 | padiIcon = NULL; | 
|---|
| 378 | WinSetWindowPos(hwndCnr,HWND_TOP,0,0,0,0,SWP_ACTIVATE); | 
|---|
| 379 | DosPostEventSem(CompactSem); | 
|---|
| 380 | } | 
|---|
| 381 | } | 
|---|
| 382 | if(ppDItem) | 
|---|
| 383 | free(ppDItem); | 
|---|
| 384 | if(padiIcon && padiIcon != &diFakeIcon) | 
|---|
| 385 | free(padiIcon); | 
|---|
| 386 | MarkAll(hwndCnr,TRUE,FALSE,TRUE); | 
|---|
| 387 | return hDrop; | 
|---|
| 388 | } | 
|---|
| 389 |  | 
|---|
| 390 |  | 
|---|
| 391 | HWND DragList (HWND hwnd,HWND hwndObj,CHAR **list,BOOL moveok) { | 
|---|
| 392 |  | 
|---|
| 393 | /* drag a linked list of files */ | 
|---|
| 394 |  | 
|---|
| 395 | BOOL           isdir; | 
|---|
| 396 | register CHAR  *p; | 
|---|
| 397 | PDRAGINFO      pDInfo = NULL; | 
|---|
| 398 | DRAGITEM       **ppDItem = NULL,**ppTest; | 
|---|
| 399 | HWND           hDrop = (HWND)0; | 
|---|
| 400 | register ULONG ulNumfiles = 0L,numdragalloc = 0L,Select,ulNumIcon = 0; | 
|---|
| 401 | CHAR           szFile[CCHMAXPATH],szBuffer[CCHMAXPATH]; | 
|---|
| 402 | DRAGIMAGE      *padiIcon = NULL,*padiTest; | 
|---|
| 403 | FILESTATUS3    fs3; | 
|---|
| 404 |  | 
|---|
| 405 | if(!list || !list[0]) | 
|---|
| 406 | return hDrop; | 
|---|
| 407 | for(Select = 0;list[Select];Select++) { | 
|---|
| 408 | if((!IsRoot(list[Select]) || !IsValidDrive(*list[Select])) && | 
|---|
| 409 | DosQueryPathInfo(list[Select],FIL_STANDARD,&fs3,sizeof(fs3))) | 
|---|
| 410 | continue; | 
|---|
| 411 | strcpy(szBuffer,list[Select]); | 
|---|
| 412 | p = strrchr(szBuffer,'\\'); | 
|---|
| 413 | if(p) { | 
|---|
| 414 | p++; | 
|---|
| 415 | strcpy(szFile,p); | 
|---|
| 416 | *p = 0; | 
|---|
| 417 | } | 
|---|
| 418 | else | 
|---|
| 419 | continue; | 
|---|
| 420 | if(*szFile) { | 
|---|
| 421 | isdir = (IsRoot(list[Select])) ? TRUE : | 
|---|
| 422 | ((fs3.attrFile & FILE_DIRECTORY) != 0); | 
|---|
| 423 | if(ulNumfiles + 2L > numdragalloc) { | 
|---|
| 424 | if (!padiIcon) { | 
|---|
| 425 | padiTest = xrealloc(padiIcon,sizeof(DRAGIMAGE) * (numdragalloc + 4L), pszSrcFile, __LINE__); | 
|---|
| 426 | if (!padiTest) | 
|---|
| 427 | break; | 
|---|
| 428 | else | 
|---|
| 429 | padiIcon = padiTest; | 
|---|
| 430 | } | 
|---|
| 431 | else if(!ulNumIcon) { | 
|---|
| 432 | padiIcon[ulNumfiles].cb = sizeof(DRAGIMAGE); | 
|---|
| 433 | padiIcon[ulNumfiles].cptl = 0; | 
|---|
| 434 | padiIcon[ulNumfiles].hImage = hptrLast; | 
|---|
| 435 | padiIcon[ulNumfiles].fl = DRG_ICON; | 
|---|
| 436 | padiIcon[ulNumfiles].sizlStretch.cx = 32; | 
|---|
| 437 | padiIcon[ulNumfiles].sizlStretch.cy = 32; | 
|---|
| 438 | padiIcon[ulNumfiles].cxOffset = -16 + (ulNumfiles * 4); | 
|---|
| 439 | padiIcon[ulNumfiles].cyOffset = 0 + (ulNumfiles * 7); | 
|---|
| 440 | ulNumIcon = ulNumfiles + 1; | 
|---|
| 441 | } | 
|---|
| 442 | ppTest = xrealloc(ppDItem,sizeof(DRAGITEM *) * (numdragalloc + 4L), pszSrcFile, __LINE__); | 
|---|
| 443 | if (!ppTest) | 
|---|
| 444 | break; | 
|---|
| 445 | else { | 
|---|
| 446 | ppDItem = ppTest; | 
|---|
| 447 | numdragalloc += 4L; | 
|---|
| 448 | } | 
|---|
| 449 | } | 
|---|
| 450 | ppDItem[ulNumfiles] = xmalloc(sizeof(DRAGITEM), pszSrcFile, __LINE__); | 
|---|
| 451 | if (!ppDItem[ulNumfiles]) | 
|---|
| 452 | break; | 
|---|
| 453 | else { | 
|---|
| 454 | if(!ulNumIcon) { | 
|---|
| 455 | padiIcon[ulNumfiles].cb = sizeof(DRAGIMAGE); | 
|---|
| 456 | padiIcon[ulNumfiles].cptl = 0; | 
|---|
| 457 | padiIcon[ulNumfiles].hImage = (isdir) ? hptrDir : hptrFile; | 
|---|
| 458 | padiIcon[ulNumfiles].fl = DRG_ICON; | 
|---|
| 459 | padiIcon[ulNumfiles].sizlStretch.cx = 32; | 
|---|
| 460 | padiIcon[ulNumfiles].sizlStretch.cy = 32; | 
|---|
| 461 | padiIcon[ulNumfiles].cxOffset = -16 + (ulNumfiles * 3); | 
|---|
| 462 | padiIcon[ulNumfiles].cyOffset = 0 + (ulNumfiles * 6); | 
|---|
| 463 | } | 
|---|
| 464 | memset(ppDItem[ulNumfiles],0,sizeof(DRAGITEM)); | 
|---|
| 465 | ppDItem[ulNumfiles]->hwndItem = (hwndObj) ? hwndObj : hwnd; /* Initialize DRAGITEM */ | 
|---|
| 466 | // ppDItem[ulNumfiles]->hwndItem = hwnd; | 
|---|
| 467 | ppDItem[ulNumfiles]->ulItemID = (ULONG)Select; | 
|---|
| 468 | ppDItem[ulNumfiles]->hstrType = DrgAddStrHandle(DRT_UNKNOWN); | 
|---|
| 469 | ppDItem[ulNumfiles]->hstrRMF = DrgAddStrHandle(DRMDRFLIST); | 
|---|
| 470 | ppDItem[ulNumfiles]->hstrContainerName = DrgAddStrHandle(szBuffer); | 
|---|
| 471 | ppDItem[ulNumfiles]->hstrSourceName = DrgAddStrHandle(szFile); | 
|---|
| 472 | ppDItem[ulNumfiles]->hstrTargetName = DrgAddStrHandle(szFile); | 
|---|
| 473 | ppDItem[ulNumfiles]->fsControl = (isdir) ? DC_CONTAINER : 0; | 
|---|
| 474 | if(IsFullName(list[Select]) && | 
|---|
| 475 | (driveflags[toupper(*list[Select]) - 'A'] & DRIVE_REMOVABLE)) | 
|---|
| 476 | ppDItem[ulNumfiles]->fsControl |= DC_REMOVEABLEMEDIA; | 
|---|
| 477 | ppDItem[ulNumfiles]->fsSupportedOps = DO_COPYABLE | DO_LINKABLE; | 
|---|
| 478 | if(moveok && IsFullName(list[Select]) && | 
|---|
| 479 | !(driveflags[toupper(*list[Select]) - 'A'] & DRIVE_NOTWRITEABLE)) | 
|---|
| 480 | ppDItem[ulNumfiles]->fsSupportedOps |= DO_MOVEABLE; | 
|---|
| 481 | if(IsRoot(list[Select])) | 
|---|
| 482 | ppDItem[ulNumfiles]->fsControl = DO_LINKABLE; | 
|---|
| 483 | ulNumfiles++; | 
|---|
| 484 | ppDItem[ulNumfiles] = NULL; | 
|---|
| 485 | } | 
|---|
| 486 | } | 
|---|
| 487 | } // for | 
|---|
| 488 |  | 
|---|
| 489 | if (ulNumfiles) { | 
|---|
| 490 | pDInfo = DrgAllocDraginfo(ulNumfiles);  /* Allocate DRAGINFO */ | 
|---|
| 491 | if (pDInfo) { | 
|---|
| 492 | if ((IsFullName(szBuffer) && | 
|---|
| 493 | (driveflags[toupper(*szBuffer) - 'A'] & DRIVE_NOTWRITEABLE))) | 
|---|
| 494 | pDInfo->usOperation = DO_COPY; | 
|---|
| 495 | else | 
|---|
| 496 | pDInfo->usOperation = DO_DEFAULT; | 
|---|
| 497 | if (IsRoot(list[0])) | 
|---|
| 498 | pDInfo->usOperation = DO_LINK; | 
|---|
| 499 | pDInfo->hwndSource = (hwndObj) ? hwndObj : hwnd; | 
|---|
| 500 | // pDInfo->hwndSource = hwnd; | 
|---|
| 501 | for (Select = 0L;Select < ulNumfiles;Select++) { | 
|---|
| 502 | DrgSetDragitem(pDInfo,            /* Set item in DRAGINFO  */ | 
|---|
| 503 | ppDItem[Select],     /* Pointer to DRAGITEM   */ | 
|---|
| 504 | sizeof(DRAGITEM),  /* Size of DRAGITEM      */ | 
|---|
| 505 | Select);           /* Index of DRAGITEM     */ | 
|---|
| 506 | free(ppDItem[Select]); | 
|---|
| 507 | } // for | 
|---|
| 508 | #ifdef __DEBUG_ALLOC__ | 
|---|
| 509 | _heap_check(); | 
|---|
| 510 | #endif | 
|---|
| 511 | free(ppDItem); | 
|---|
| 512 | ppDItem = NULL; | 
|---|
| 513 | DosPostEventSem(CompactSem); | 
|---|
| 514 |  | 
|---|
| 515 | if(!ulNumIcon) | 
|---|
| 516 | ulNumIcon = ulNumfiles; | 
|---|
| 517 |  | 
|---|
| 518 | WinSetFocus(HWND_DESKTOP,HWND_DESKTOP); | 
|---|
| 519 | hDrop = DrgDrag(hwnd,                 /* Initiate drag         */ | 
|---|
| 520 | pDInfo,               /* DRAGINFO structure    */ | 
|---|
| 521 | padiIcon, | 
|---|
| 522 | ulNumIcon, | 
|---|
| 523 | VK_ENDDRAG,           /* End of drag indicator */ | 
|---|
| 524 | (PVOID)NULL);         /* Reserved              */ | 
|---|
| 525 |  | 
|---|
| 526 | DrgFreeDraginfo(pDInfo);              /* Free DRAGINFO struct  */ | 
|---|
| 527 | free(padiIcon); | 
|---|
| 528 | padiIcon = NULL; | 
|---|
| 529 | WinSetWindowPos(hwnd,HWND_TOP,0,0,0,0,SWP_ACTIVATE); | 
|---|
| 530 | DosPostEventSem(CompactSem); | 
|---|
| 531 | } | 
|---|
| 532 | } | 
|---|
| 533 | if(ppDItem) | 
|---|
| 534 | free(ppDItem); | 
|---|
| 535 | if(padiIcon) | 
|---|
| 536 | free(padiIcon); | 
|---|
| 537 | return hDrop; | 
|---|
| 538 | } | 
|---|
| 539 |  | 
|---|
| 540 |  | 
|---|
| 541 | #ifdef NEVER | 
|---|
| 542 |  | 
|---|
| 543 | BOOL PickUp (HWND hwndCnr,HWND hwndObj,PCNRDRAGINIT pcd) { | 
|---|
| 544 |  | 
|---|
| 545 | PCNRITEM  pci; | 
|---|
| 546 | BOOL      loop = TRUE; | 
|---|
| 547 | PDRAGINFO pdinfoOld = NULL,pdinfoCurrent = NULL; | 
|---|
| 548 | ULONG     cditem = 0; | 
|---|
| 549 | DRAGITEM  ditem; | 
|---|
| 550 | DRAGIMAGE diFakeIcon; | 
|---|
| 551 | CHAR      szDir[CCHMAXPATH],szFile[CCHMAXPATH],*p; | 
|---|
| 552 |  | 
|---|
| 553 | pci = (PCNRITEM)pcd->pRecord; | 
|---|
| 554 | if(pci && (INT)pci != -1) { | 
|---|
| 555 | if(pci->rc.flRecordAttr & CRA_SELECTED) { | 
|---|
| 556 | loop = TRUE; | 
|---|
| 557 | pci = WinSendMsg(hwndCnr,CM_QUERYRECORDEMPHASIS, | 
|---|
| 558 | MPFROMLONG(CMA_FIRST),MPFROMSHORT(CRA_SELECTED)); | 
|---|
| 559 | } | 
|---|
| 560 | while(pci && (INT)pci != -1 && *pci->szFileName) { | 
|---|
| 561 | if(pdinfoOld || DrgQueryDragStatus() & DGS_LAZYDRAGINPROGRESS) { | 
|---|
| 562 | if(!pdinfoOld) | 
|---|
| 563 | pdinfoOld = DrgQueryDraginfoPtr(NULL); | 
|---|
| 564 | if(pdinfoOld) { | 
|---|
| 565 | cditem = pdinfoOld->cditem + 1; | 
|---|
| 566 | pdinfoCurrent = DrgReallocDraginfo(pdinfoOld,cditem); | 
|---|
| 567 | pdinfoOld = pdinfoCurrent; | 
|---|
| 568 | } | 
|---|
| 569 | } | 
|---|
| 570 | else | 
|---|
| 571 | pdinfoCurrent = pdinfoOld = DrgAllocDraginfo(1); | 
|---|
| 572 | if(pdinfoCurrent) { | 
|---|
| 573 | strcpy(szDir,pci->szFileName); | 
|---|
| 574 | p = szDir; | 
|---|
| 575 | while(*p) { | 
|---|
| 576 | if(*p == '/') | 
|---|
| 577 | *p = '\\'; | 
|---|
| 578 | p++; | 
|---|
| 579 | } | 
|---|
| 580 | p = strrchr(szDir,'\\'); | 
|---|
| 581 | if(p) { | 
|---|
| 582 | *p = 0; | 
|---|
| 583 | p++; | 
|---|
| 584 | strcpy(szFile,p); | 
|---|
| 585 | strcat(szDir,"\\"); | 
|---|
| 586 | } | 
|---|
| 587 | else { | 
|---|
| 588 | strcpy(szFile,pci->szFileName); | 
|---|
| 589 | *szDir = 0; | 
|---|
| 590 | } | 
|---|
| 591 | ditem.ulItemID = (ULONG)pci; | 
|---|
| 592 | ditem.hwndItem = (hwndObj) ? hwndObj : hwndCnr; | 
|---|
| 593 | ditem.hstrType = DrgAddStrHandle(DRT_UNKNOWN); | 
|---|
| 594 | ditem.hstrRMF = | 
|---|
| 595 | DrgAddStrHandle(DRMDRFLIST); | 
|---|
| 596 | ditem.hstrContainerName = DrgAddStrHandle(szDir); | 
|---|
| 597 | ditem.hstrSourceName = DrgAddStrHandle(szFile); | 
|---|
| 598 | ditem.hstrTargetName = DrgAddStrHandle(szFile); | 
|---|
| 599 | ditem.fsControl = 0; | 
|---|
| 600 | if(IsRoot(pci->szFileName) || (pci->attrFile & FILE_DIRECTORY) != 0) | 
|---|
| 601 | ditem.fsControl |= DC_CONTAINER; | 
|---|
| 602 | if(IsFullName(pci->szFileName) && | 
|---|
| 603 | (driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_REMOVABLE)) | 
|---|
| 604 | ditem.fsControl |= DC_REMOVEABLEMEDIA; | 
|---|
| 605 | ditem.fsSupportedOps = DO_COPYABLE | DO_LINKABLE; | 
|---|
| 606 | if(IsFullName(pci->szFileName) && | 
|---|
| 607 | !(driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOTWRITEABLE)) | 
|---|
| 608 | ditem.fsSupportedOps |= DO_MOVEABLE; | 
|---|
| 609 | if(IsRoot(pci->szFileName)) | 
|---|
| 610 | ditem.fsSupportedOps = DO_LINKABLE; | 
|---|
| 611 | memset(&diFakeIcon,0,sizeof(DRAGIMAGE)); | 
|---|
| 612 | diFakeIcon.hImage = pci->rc.hptrIcon; | 
|---|
| 613 | diFakeIcon.cb = sizeof(DRAGIMAGE); | 
|---|
| 614 | diFakeIcon.cptl = 0; | 
|---|
| 615 | diFakeIcon.fl = DRG_ICON; | 
|---|
| 616 | diFakeIcon.sizlStretch.cx = 32; | 
|---|
| 617 | diFakeIcon.sizlStretch.cy = 32; | 
|---|
| 618 | diFakeIcon.cxOffset = -16; | 
|---|
| 619 | diFakeIcon.cyOffset = 0; | 
|---|
| 620 | if(IsFullName(pci->szFileName) && | 
|---|
| 621 | (driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOTWRITEABLE)) | 
|---|
| 622 | pdinfoCurrent->usOperation = DO_COPY; | 
|---|
| 623 | else | 
|---|
| 624 | pdinfoCurrent->usOperation = DO_DEFAULT; | 
|---|
| 625 | if(IsRoot(pci->szFileName)) | 
|---|
| 626 | pdinfoCurrent->usOperation = DO_LINK; | 
|---|
| 627 | pdinfoCurrent->hwndSource = (hwndObj) ? hwndObj : hwndCnr; | 
|---|
| 628 | DrgSetDragitem(pdinfoCurrent, | 
|---|
| 629 | &ditem, | 
|---|
| 630 | sizeof(DRAGITEM), | 
|---|
| 631 | cditem); | 
|---|
| 632 | } | 
|---|
| 633 | if(!loop) | 
|---|
| 634 | break; | 
|---|
| 635 | pci = WinSendMsg(hwndCnr,CM_QUERYRECORDEMPHASIS, | 
|---|
| 636 | MPFROMP(pci),MPFROMSHORT(CRA_SELECTED)); | 
|---|
| 637 | } | 
|---|
| 638 | if(pdinfoCurrent) | 
|---|
| 639 | return DrgLazyDrag(hwndCnr,pdinfoCurrent,&diFakeIcon,1,NULL); | 
|---|
| 640 | } | 
|---|
| 641 | return FALSE; | 
|---|
| 642 | } | 
|---|
| 643 |  | 
|---|
| 644 | #endif // NEVER | 
|---|