Ignore:
Timestamp:
Jan 12, 2011, 4:13:08 PM (15 years ago)
Author:
dmik
Message:

user32: Fixed a crash during DnD when the dragged object was moved through the title over the window frame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/pmwindow.cpp

    r21543 r21556  
    11101110        dprintf(("OS2: DM_DRAGOVER %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop));
    11111111
    1112         if(fDragDropDisabled) {
     1112        /* Get access to the DRAGINFO data structure */
     1113        if(!DrgAccessDraginfo(pDragInfo)) {
    11131114            rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
    11141115            break;
    11151116        }
    11161117
    1117         //does this window accept dropped files?
    1118         if(!DragDropAccept(win32wnd->getWindowHandle())) {
    1119             rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
    1120             break;
    1121         }
    1122 
    1123         if(PMDragValidate(pDragInfo) == FALSE) {
    1124             rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
    1125             break;
    1126         }
    1127         if(win32wnd->isDragDropActive() == FALSE) {
    1128             ULONG ulBytes, cItems;
    1129             char *pszFiles;
    1130 
    1131             pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes);
    1132             if(pszFiles) {
    1133                 POINT point = {sxDrop, syDrop};
    1134                 if(DragDropDragEnter(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes, DROPEFFECT_COPY_W) == FALSE) {
     1118        /* We send DM_DRAGOVER/DM_DROP events to ourselves using WinSendMsg()
     1119         * in OSLibDragOver()/OSLibDragDrop() but this is not correct to the
     1120         * extent that it does not set up some internal PM structures so that
     1121         * DrgFreeDraginfo() called to pair DrgAccessDraginfo() in this message
     1122         * handler actually frees the structure whilie it is still in use by
     1123         * DoDragDrop() and causes a crash upon the next access. We avoid to
     1124         * do a free call in this case. This solution may have side effects...
     1125         */
     1126        BOOL freeDragInfo = TRUE;
     1127        PID pid;
     1128        TID tid;
     1129        if (WinQueryWindowProcess(pDragInfo->hwndSource, &pid, &tid)) {
     1130            PPIB ppib;
     1131            DosGetInfoBlocks(0, &ppib);
     1132            dprintf(("OS2: DM_DRAGOVER source PID %d, this PID %d", pid, ppib->pib_ulpid));
     1133            if (ppib->pib_ulpid == pid)
     1134                freeDragInfo = FALSE;
     1135        }
     1136
     1137        do {
     1138            if(fDragDropDisabled) {
     1139                rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
     1140                break;
     1141            }
     1142
     1143            //does this window accept dropped files?
     1144            if(!DragDropAccept(win32wnd->getWindowHandle())) {
     1145                rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
     1146                break;
     1147            }
     1148
     1149            if(PMDragValidate(pDragInfo) == FALSE) {
     1150                rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
     1151                break;
     1152            }
     1153            if(win32wnd->isDragDropActive() == FALSE) {
     1154                ULONG ulBytes, cItems;
     1155                char *pszFiles;
     1156
     1157                pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes);
     1158                if(pszFiles) {
     1159                    POINT point = {sxDrop, syDrop};
     1160                    if(DragDropDragEnter(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes, DROPEFFECT_COPY_W) == FALSE) {
     1161                        rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
     1162                    }
     1163                    else {
     1164                        fDragDropActive = TRUE;
     1165                        rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
     1166                        win32wnd->setDragDropActive(TRUE);
     1167                    }
     1168                    free(pszFiles);
     1169                }
     1170                else {
    11351171                    rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
    11361172                }
    1137                 else {
    1138                     fDragDropActive = TRUE;
    1139                     rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
    1140                     win32wnd->setDragDropActive(TRUE);
     1173            }
     1174            else {
     1175                if(DragDropDragOver(win32wnd->getWindowHandle(), DROPEFFECT_COPY_W) == FALSE) {
     1176                        rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
    11411177                }
    1142                 free(pszFiles);
    1143             }
    1144             else {
    1145                 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
    1146             }
    1147         }
    1148         else {
    1149             if(DragDropDragOver(win32wnd->getWindowHandle(), DROPEFFECT_COPY_W) == FALSE) {
    1150                     rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
    1151             }
    1152             else    rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
    1153         }
     1178                else    rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
     1179            }
     1180            break;
     1181        } while (0);
     1182
     1183        /* Release the draginfo data structure */
     1184        if (freeDragInfo)
     1185            DrgFreeDraginfo(pDragInfo);
     1186
    11541187        break;
    11551188    }
     
    11851218        dprintf(("OS2: DM_DROP %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop));
    11861219
    1187         fDragDropActive = FALSE;
    1188         rc = (MRFROM2SHORT (DOR_NODROP, 0));
    1189 
    1190         if(fDragDropDisabled) {
     1220        /* Get access to the DRAGINFO data structure */
     1221        if(!DrgAccessDraginfo(pDragInfo)) {
    11911222            rc = (MRFROM2SHORT (DOR_NODROP, 0));
    11921223            break;
    11931224        }
    11941225
    1195         //does this window accept dropped files?
    1196         if(!DragDropAccept(win32wnd->getWindowHandle())) {
     1226        /* We send DM_DRAGOVER/DM_DROP events to ourselves using WinSendMsg()
     1227         * in OSLibDragOver()/OSLibDragDrop() but this is not correct to the
     1228         * extent that it does not set up some internal PM structures so that
     1229         * DrgFreeDraginfo() called to pair DrgAccessDraginfo() in this message
     1230         * handler actually frees the structure whilie it is still in use by
     1231         * DoDragDrop() and causes a crash upon the next access. We avoid to
     1232         * do a free call in this case. This solution may have side effects...
     1233         */
     1234        BOOL freeDragInfo = TRUE;
     1235        PID pid;
     1236        TID tid;
     1237        if (WinQueryWindowProcess(pDragInfo->hwndSource, &pid, &tid)) {
     1238            PPIB ppib;
     1239            DosGetInfoBlocks(0, &ppib);
     1240            dprintf(("OS2: DM_DRAGOVER source PID %d, this PID %d", pid, ppib->pib_ulpid));
     1241            if (ppib->pib_ulpid == pid)
     1242                freeDragInfo = FALSE;
     1243        }
     1244
     1245        do {
     1246            fDragDropActive = FALSE;
     1247            rc = (MRFROM2SHORT (DOR_NODROP, 0));
     1248
     1249            if(fDragDropDisabled) {
     1250                rc = (MRFROM2SHORT (DOR_NODROP, 0));
     1251                break;
     1252            }
     1253
     1254            //does this window accept dropped files?
     1255            if(!DragDropAccept(win32wnd->getWindowHandle())) {
     1256                break;
     1257            }
     1258
     1259            ULONG ulBytes, cItems;
     1260            char *pszFiles;
     1261
     1262            pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes);
     1263            if(pszFiles) {
     1264                POINT point = {sxDrop, syDrop};
     1265                if(DragDropFiles(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes) == FALSE) {
     1266                    rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
     1267                }
     1268                else {
     1269                    rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
     1270                    win32wnd->setDragDropActive(FALSE);
     1271                }
     1272                free(pszFiles);
     1273            }
     1274            else {
     1275                rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
     1276            }
    11971277            break;
    1198         }
    1199 
    1200         ULONG ulBytes, cItems;
    1201         char *pszFiles;
    1202 
    1203         pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes);
    1204         if(pszFiles) {
    1205             POINT point = {sxDrop, syDrop};
    1206             if(DragDropFiles(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes) == FALSE) {
    1207                 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
    1208             }
    1209             else {
    1210                 rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
    1211                 win32wnd->setDragDropActive(FALSE);
    1212             }
    1213             free(pszFiles);
    1214         }
    1215         else {
    1216             rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
    1217         }
     1278        } while (0);
     1279
     1280        /* Release the draginfo data structure */
     1281        if (freeDragInfo)
     1282            DrgFreeDraginfo(pDragInfo);
     1283
    12181284        break;
    12191285    }
     
    25542620    char     *pszCurFile = NULL;
    25552621
    2556     /* Get access to the DRAGINFO data structure */
    2557     if(!DrgAccessDraginfo(pDragInfo)) {
    2558         return NULL;
    2559     }
    2560 
    25612622    cItems = DrgQueryDragitemCount(pDragInfo);
    25622623
     
    26042665    }
    26052666
    2606     /* Release the draginfo data structure */
    2607     DrgFreeDraginfo(pDragInfo);
    2608 
    26092667    *pulBytes = bufsize;
    26102668    *pcItems  = cItems;
     
    26132671
    26142672failure:
    2615     /* Release the draginfo data structure */
    2616     DrgFreeDraginfo(pDragInfo);
    26172673    if(pszFiles) {
    26182674        free(pszFiles);
     
    26332689
    26342690    /* Get access to the DRAGINFO data structure */
    2635     if(!DrgAccessDraginfo(pDragInfo)) {
    2636         return FALSE;
    2637     }
    26382691
    26392692    /* Can we accept this drop? */
     
    26792732    }
    26802733    /* Release the draginfo data structure */
    2681     DrgFreeDraginfo(pDragInfo);
    26822734    return TRUE;
    26832735
    26842736failure:
    2685     DrgFreeDraginfo(pDragInfo);
    26862737    return FALSE;
    26872738}
Note: See TracChangeset for help on using the changeset viewer.