Ignore:
Timestamp:
Jun 2, 2002, 9:34:36 PM (23 years ago)
Author:
sandervl
Message:

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

File:
1 edited

Legend:

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

    r8542 r8553  
    1 /* $Id: pmwindow.cpp,v 1.175 2002-06-02 10:07:57 sandervl Exp $ */
     1/* $Id: pmwindow.cpp,v 1.176 2002-06-02 19:34:28 sandervl Exp $ */
    22/*
    33 * Win32 Window Managment Code for OS/2
     
    8484
    8585
     86static char *PMDragExtractFiles(PDRAGINFO pDragInfo, ULONG *pcItems, ULONG *pulBytes);
     87static BOOL  PMDragValidate(PDRAGINFO pDragInfo);
    8688
    8789MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
     
    787789        USHORT    sxDrop = SHORT1FROMMP(mp2);
    788790        USHORT    syDrop = SHORT2FROMMP(mp2);
    789         USHORT    usIndicator, usOp;
    790         ULONG     ulBytes;
    791         int       i, cItems;
    792         BOOL      ret;
    793         char      szFileName[CCHMAXPATH];
    794         char      szContainerName[CCHMAXPATH];
    795791
    796792        dprintf(("OS2: DM_DRAGOVER %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop));
     
    801797            break;
    802798        }
    803         /* Get access to the DRAGINFO data structure */
    804         if(!DrgAccessDraginfo(pDragInfo)) {
    805                 rc = (MRFROM2SHORT (DOR_NODROP, 0));
     799
     800        if(PMDragValidate(pDragInfo) == FALSE) {
     801                rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
    806802            break;
    807803        }
    808 
    809         /* Can we accept this drop? */
    810         switch (pDragInfo->usOperation) {
    811         /* Return DOR_NODROPOP if current operation */
    812         /* is link or unknown                       */
    813             case DO_LINK:
    814         case DO_COPY:
    815         case DO_UNKNOWN:
    816             DrgFreeDraginfo(pDragInfo);
    817             rc = (MRFROM2SHORT (DOR_NODROPOP, 0));
    818             break;
    819  
    820         /* Our default operation is Move */
    821         case DO_MOVE:
    822         case DO_DEFAULT:
    823             pDragItem = DrgQueryDragitemPtr(pDragInfo, 0);
    824             ulBytes   = DrgQueryStrName(pDragItem->hstrContainerName,
    825                                         sizeof(szContainerName),
    826                                         szContainerName);
    827             ulBytes   = DrgQueryStrName(pDragItem->hstrSourceName,
    828                                         sizeof(szFileName),
    829                                         szFileName);
    830             if (!ulBytes) {
    831                 rc = (MRFROM2SHORT (DOR_NODROPOP, 0));
    832                 break;
    833             }
    834             else usOp =  DO_MOVE;
    835 
    836             dprintf(("dropped file %s%s", szContainerName, szFileName));
    837             break;
    838         }
    839         if(rc == MRFROM2SHORT (DOR_NODROPOP, 0)) {
    840             break;
    841         }
    842 
    843         usIndicator = (USHORT)DOR_DROP;
    844         cItems = DrgQueryDragitemCount(pDragInfo);
    845  
    846         /* Now, we need to look at each item in turn */
    847         for (i = 0; i < cItems; i++) {
    848             pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
    849  
    850             /* Make sure we can move for a Move request */
    851             if ((pDragItem->fsSupportedOps & DO_MOVEABLE)   &&
    852                (usOp == (USHORT)DO_MOVE))
    853             {
    854                 usIndicator = DOR_DROP;
     804        if(win32wnd->isDragDropActive() == FALSE) {
     805            ULONG ulBytes, cItems;
     806            char *pszFiles;
     807
     808            win32wnd->setDragDropActive(TRUE);
     809
     810            pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes);
     811            if(pszFiles) {
     812                POINT point = {sxDrop, syDrop};
     813                if(DragDropDragEnter(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes, DROPEFFECT_COPY_W) == FALSE) {
     814                        rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
     815                }
     816                else    rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
     817                free(pszFiles);
    855818            }
    856819            else {
    857                 dprintf(("item %d not accepted", i));
    858                 usIndicator = DOR_NODROPOP;
    859                 break;
    860             }
    861         }
    862         /* Release the draginfo data structure */
    863         DrgFreeDraginfo(pDragInfo);
    864  
    865         dprintf(("return %x", MRFROM2SHORT(usIndicator, usOp)));
    866         rc = (MRFROM2SHORT(usIndicator, usOp));
     820                rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
     821            }
     822        }
     823        else {
     824            if(DragDropDragOver(win32wnd->getWindowHandle(), DROPEFFECT_COPY_W) == FALSE) {
     825                    rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
     826            }
     827            else    rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
     828        }
    867829        break;
    868830    }
     
    871833    {
    872834        dprintf(("OS2: DM_DRAGLEAVE %x", win32wnd->getWindowHandle()));
     835        DragDropDragLeave(win32wnd->getWindowHandle());
     836        win32wnd->setDragDropActive(FALSE);
    873837        break;
    874838    }
     
    881845        USHORT    syDrop = SHORT2FROMMP(mp2);
    882846        USHORT    usIndicator, usOp;
    883         ULONG     ulBytes;
    884         int       i, cItems;
    885         BOOL      ret;
    886         char      szFileName[CCHMAXPATH];
    887         char      szContainerName[CCHMAXPATH];
    888847
    889848        dprintf(("OS2: DM_DROP %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop));
     849
     850        rc = (MRFROM2SHORT (DOR_NODROP, 0));
    890851
    891852        //does this window accept dropped files?
    892853        if(!DragDropAccept(win32wnd->getWindowHandle())) {
    893             rc = 0;
    894854            break;
    895855        }
    896         /* Get access to the DRAGINFO data structure */
    897         if(!DrgAccessDraginfo(pDragInfo)) {
    898             rc = 0;
    899             break;
    900         }
    901 
    902         usIndicator = (USHORT)DOR_DROP;
    903         cItems = DrgQueryDragitemCount(pDragInfo);
    904856 
    905         //computer memory required to hold all filenames
    906         int bufsize = 0;       
    907         for (i = 0; i < cItems; i++) {
    908             pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
    909  
    910             bufsize += DrgQueryStrNameLen(pDragItem->hstrContainerName) + DrgQueryStrNameLen(pDragItem->hstrSourceName);
    911             bufsize++;  //0 terminator
    912             bufsize++;  //+ potential missing backslash
    913         }
    914         //copy all filenames
    915         char *pszFiles   = (char *)malloc(bufsize);
    916         if(pszFiles == NULL) {
    917             dprintf(("Out of memory!!"));
    918             DebugInt3();
    919             break;
    920         }
    921         char *pszCurFile = pszFiles;
    922 
    923         for (i = 0; i < cItems; i++) {
    924             char *pszTemp = pszCurFile;
    925 
    926             pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
    927  
    928             ulBytes = DrgQueryStrNameLen(pDragItem->hstrContainerName);
    929 
    930             ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
    931                                       ulBytes, pszCurFile);
    932             if(pszCurFile[ulBytes-1] != '\\') {
    933                 pszCurFile[ulBytes] = '\\';
    934                 pszCurFile++;
    935             }
    936             pszCurFile += ulBytes;
    937 
    938             ulBytes = DrgQueryStrNameLen(pDragItem->hstrSourceName);
    939             ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
    940                                       ulBytes+1, pszCurFile);
    941             pszCurFile += ulBytes + 1;  //+ terminator
    942 
    943             dprintf(("dropped file %s", pszTemp));
    944         }
    945         POINT point = {sxDrop, syDrop};
    946         DragDropFiles(win32wnd->getWindowHandle(), cItems, point, pszFiles, bufsize);
    947         free(pszFiles);
    948 
    949         /* Release the draginfo data structure */
    950         DrgFreeDraginfo(pDragInfo);
    951  
    952         rc = 0;
     857        ULONG ulBytes, cItems;
     858        char *pszFiles;
     859
     860        pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes);
     861        if(pszFiles) {
     862            POINT point = {sxDrop, syDrop};
     863            if(DragDropFiles(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes) == FALSE) {
     864                    rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
     865            }
     866            else    rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
     867            free(pszFiles);
     868        }
     869        else {
     870            rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
     871        } 
    953872        break;
    954873    }
     
    20501969//******************************************************************************
    20511970//******************************************************************************
     1971static char *PMDragExtractFiles(PDRAGINFO pDragInfo, ULONG *pcItems, ULONG *pulBytes)
     1972{
     1973    PDRAGITEM pDragItem;
     1974    int       i, cItems;
     1975    BOOL      ret;
     1976    char      szFileName[CCHMAXPATH];
     1977    char      szContainerName[CCHMAXPATH];
     1978    ULONG     ulBytes;
     1979    char     *pszCurFile = NULL;
     1980
     1981    /* Get access to the DRAGINFO data structure */
     1982    if(!DrgAccessDraginfo(pDragInfo)) {
     1983        return NULL;
     1984    }
     1985
     1986    cItems = DrgQueryDragitemCount(pDragInfo);
     1987
     1988    //computer memory required to hold all filenames
     1989    int bufsize = 0;       
     1990    for (i = 0; i < cItems; i++) {
     1991        pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
     1992
     1993        bufsize += DrgQueryStrNameLen(pDragItem->hstrContainerName) + DrgQueryStrNameLen(pDragItem->hstrSourceName);
     1994        bufsize++;  //0 terminator
     1995        bufsize++;  //+ potential missing backslash
     1996    }
     1997    bufsize++;  //extra 0 terminator
     1998    char *pszFiles = (char *)malloc(bufsize);
     1999    if(pszFiles == NULL) {
     2000        dprintf(("Out of memory!!"));
     2001        DebugInt3();
     2002        goto failure;
     2003    }
     2004    memset(pszFiles, 0, bufsize);
     2005
     2006    pszCurFile = pszFiles;
     2007
     2008    //copy all filenames
     2009    for (i = 0; i < cItems; i++) {
     2010        char *pszTemp = pszCurFile;
     2011
     2012        pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
     2013
     2014        ulBytes = DrgQueryStrNameLen(pDragItem->hstrContainerName);
     2015        ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
     2016                                  ulBytes, pszCurFile);
     2017        if(pszCurFile[ulBytes-1] != '\\') {
     2018            pszCurFile[ulBytes] = '\\';
     2019            pszCurFile++;
     2020        }
     2021        pszCurFile += ulBytes;
     2022
     2023        ulBytes = DrgQueryStrNameLen(pDragItem->hstrSourceName);
     2024        ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
     2025                                  ulBytes+1, pszCurFile);
     2026        pszCurFile += ulBytes + 1;  //+ terminator
     2027
     2028        dprintf(("dropped file %s", pszTemp));
     2029    }
     2030
     2031    /* Release the draginfo data structure */
     2032    DrgFreeDraginfo(pDragInfo);
     2033
     2034    *pulBytes = bufsize;
     2035    *pcItems  = cItems;
     2036
     2037    return pszFiles;
     2038
     2039failure:
     2040    /* Release the draginfo data structure */
     2041    DrgFreeDraginfo(pDragInfo);
     2042    if(pszFiles) {
     2043        free(pszFiles);
     2044    }
     2045    return NULL;
     2046}
     2047//******************************************************************************
     2048//******************************************************************************
     2049static BOOL PMDragValidate(PDRAGINFO pDragInfo)
     2050{
     2051    PDRAGITEM pDragItem;
     2052    ULONG     ulBytes;
     2053    int       i, cItems;
     2054    BOOL      ret;
     2055    char      szFileName[CCHMAXPATH];
     2056    char      szContainerName[CCHMAXPATH];
     2057    USHORT    usOp = DO_MOVE;
     2058
     2059    /* Get access to the DRAGINFO data structure */
     2060    if(!DrgAccessDraginfo(pDragInfo)) {
     2061        return FALSE;
     2062    }
     2063
     2064    /* Can we accept this drop? */
     2065    switch (pDragInfo->usOperation) {
     2066    /* Return DOR_NODROPOP if current operation */
     2067    /* is link or unknown                       */
     2068    case DO_LINK:
     2069    case DO_COPY:
     2070    case DO_UNKNOWN:
     2071        goto failure;
     2072
     2073    /* Our default operation is Move */
     2074    case DO_MOVE:
     2075    case DO_DEFAULT:
     2076        pDragItem = DrgQueryDragitemPtr(pDragInfo, 0);
     2077        ulBytes   = DrgQueryStrName(pDragItem->hstrContainerName,
     2078                                    sizeof(szContainerName),
     2079                                    szContainerName);
     2080        ulBytes   = DrgQueryStrName(pDragItem->hstrSourceName,
     2081                                    sizeof(szFileName),
     2082                                    szFileName);
     2083        if (!ulBytes) {
     2084            goto failure;
     2085        }
     2086
     2087        dprintf(("dropped file %s%s", szContainerName, szFileName));
     2088        break;
     2089    }
     2090
     2091    cItems = DrgQueryDragitemCount(pDragInfo);
     2092
     2093    /* Now, we need to look at each item in turn */
     2094    for (i = 0; i < cItems; i++) {
     2095        pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
     2096
     2097        /* Make sure we can move for a Move request */
     2098        if (!((pDragItem->fsSupportedOps & DO_MOVEABLE)   &&
     2099           (usOp == (USHORT)DO_MOVE)))
     2100        {
     2101            dprintf(("item %d not accepted", i));
     2102            goto failure;
     2103        }
     2104    }
     2105    /* Release the draginfo data structure */
     2106    DrgFreeDraginfo(pDragInfo);
     2107    return TRUE;
     2108
     2109failure:
     2110    DrgFreeDraginfo(pDragInfo);
     2111    return FALSE;   
     2112}
     2113//******************************************************************************
     2114//******************************************************************************
     2115
Note: See TracChangeset for help on using the changeset viewer.