Changeset 8553 for trunk/src


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

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

Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ole32/ole2.c

    r8441 r8553  
    5757  HWND          hwndTarget;
    5858  IDropTarget*    dropTarget;
     59#ifdef __WIN32OS2__
     60  BOOL          fDragEnter;
     61  DWORD         dwEffect;
     62  IDataObject * pDataObject;
     63  HDROP         hDrop;
     64#endif
    5965  struct tagDropTargetNode* prevDropTarget;
    6066  struct tagDropTargetNode* nextDropTarget;
     
    22182224  }
    22192225}
     2226#ifdef __WIN32OS2__
     2227#include <dbglog.h>
     2228
     2229/***********************************************************************
     2230*   IEnumFORMATETC implementation
     2231*/
     2232
     2233typedef struct
     2234{
     2235    /* IUnknown fields */
     2236    ICOM_VFIELD(IEnumFORMATETC);
     2237    DWORD                        ref;
     2238    /* IEnumFORMATETC fields */
     2239    UINT        posFmt;
     2240    UINT        countFmt;
     2241    LPFORMATETC pFmt;
     2242} IEnumFORMATETCImpl;
     2243
     2244static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj);
     2245static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface);
     2246static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface);
     2247static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC* rgelt, ULONG* pceltFethed);
     2248static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt);
     2249static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface);
     2250static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum);
     2251
     2252static struct ICOM_VTABLE(IEnumFORMATETC) efvt =
     2253{
     2254    ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
     2255    IEnumFORMATETC_fnQueryInterface,
     2256    IEnumFORMATETC_fnAddRef,
     2257    IEnumFORMATETC_fnRelease,
     2258    IEnumFORMATETC_fnNext,
     2259    IEnumFORMATETC_fnSkip,
     2260    IEnumFORMATETC_fnReset,
     2261    IEnumFORMATETC_fnClone
     2262};
     2263
     2264LPENUMFORMATETC IEnumFORMATETC_Constructor(UINT cfmt, const FORMATETC afmt[])
     2265{
     2266        IEnumFORMATETCImpl* ef;
     2267        DWORD size=cfmt * sizeof(FORMATETC);
     2268       
     2269        ef=(IEnumFORMATETCImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumFORMATETCImpl));
     2270
     2271        if(ef)
     2272        {
     2273          ef->ref=1;
     2274          ICOM_VTBL(ef)=&efvt;
     2275
     2276          ef->countFmt = cfmt;
     2277          ef->pFmt = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
     2278
     2279          if (ef->pFmt)
     2280          {
     2281            memcpy(ef->pFmt, afmt, size);
     2282          }
     2283        }
     2284
     2285        TRACE("(%p)->(%u,%p)\n",ef, cfmt, afmt);
     2286        return (LPENUMFORMATETC)ef;
     2287}
     2288
     2289static HRESULT WINAPI IEnumFORMATETC_fnQueryInterface(LPENUMFORMATETC iface, REFIID riid, LPVOID* ppvObj)
     2290{
     2291        ICOM_THIS(IEnumFORMATETCImpl,iface);
     2292        TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
     2293
     2294        *ppvObj = NULL;
     2295
     2296        if(IsEqualIID(riid, &IID_IUnknown))
     2297        {
     2298          *ppvObj = This;
     2299        }
     2300        else if(IsEqualIID(riid, &IID_IEnumFORMATETC))
     2301        {
     2302          *ppvObj = (IEnumFORMATETC*)This;
     2303        }   
     2304
     2305        if(*ppvObj)
     2306        {
     2307          IUnknown_AddRef((IUnknown*)(*ppvObj));
     2308          TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
     2309          return S_OK;
     2310        }
     2311        TRACE("-- Interface: E_NOINTERFACE\n");
     2312        return E_NOINTERFACE;
     2313
     2314}
     2315
     2316static ULONG WINAPI IEnumFORMATETC_fnAddRef(LPENUMFORMATETC iface)
     2317{
     2318        ICOM_THIS(IEnumFORMATETCImpl,iface);
     2319        TRACE("(%p)->(count=%lu)\n",This, This->ref);
     2320        return ++(This->ref);
     2321}
     2322
     2323static ULONG WINAPI IEnumFORMATETC_fnRelease(LPENUMFORMATETC iface)
     2324{
     2325        ICOM_THIS(IEnumFORMATETCImpl,iface);
     2326        TRACE("(%p)->()\n",This);
     2327
     2328    if (!--(This->ref))
     2329        {
     2330          TRACE(" destroying IEnumFORMATETC(%p)\n",This);
     2331          if (This->pFmt)
     2332          {
     2333            HeapFree(GetProcessHeap(),0, This->pFmt);
     2334          }
     2335          HeapFree(GetProcessHeap(),0,This);
     2336          return 0;
     2337        }
     2338        return This->ref;
     2339}
     2340
     2341static HRESULT WINAPI IEnumFORMATETC_fnNext(LPENUMFORMATETC iface, ULONG celt, FORMATETC *rgelt, ULONG *pceltFethed)
     2342{
     2343        ICOM_THIS(IEnumFORMATETCImpl,iface);
     2344        int i;
     2345
     2346        TRACE("(%p)->(%lu,%p)\n", This, celt, rgelt);
     2347
     2348        if(!This->pFmt)return S_FALSE;
     2349        if(!rgelt) return E_INVALIDARG;
     2350        if (pceltFethed)  *pceltFethed = 0;
     2351
     2352        for(i = 0; This->posFmt < This->countFmt && celt > i; i++)
     2353        {
     2354          *rgelt++ = This->pFmt[This->posFmt++];
     2355        }
     2356
     2357        if (pceltFethed) *pceltFethed = i;
     2358
     2359        return ((i == celt) ? S_OK : S_FALSE);
     2360}
     2361
     2362static HRESULT WINAPI IEnumFORMATETC_fnSkip(LPENUMFORMATETC iface, ULONG celt)
     2363{
     2364        ICOM_THIS(IEnumFORMATETCImpl,iface);
     2365        TRACE("(%p)->(num=%lu)\n", This, celt);
     2366
     2367        if((This->posFmt + celt) >= This->countFmt) return S_FALSE;
     2368        This->posFmt += celt;
     2369        return S_OK;
     2370}
     2371
     2372static HRESULT WINAPI IEnumFORMATETC_fnReset(LPENUMFORMATETC iface)
     2373{
     2374        ICOM_THIS(IEnumFORMATETCImpl,iface);
     2375        TRACE("(%p)->()\n", This);
     2376
     2377    This->posFmt = 0;
     2378    return S_OK;
     2379}
     2380
     2381static HRESULT WINAPI IEnumFORMATETC_fnClone(LPENUMFORMATETC iface, LPENUMFORMATETC* ppenum)
     2382{
     2383        ICOM_THIS(IEnumFORMATETCImpl,iface);
     2384        TRACE("(%p)->(ppenum=%p)\n", This, ppenum);
     2385
     2386        if (!ppenum) return E_INVALIDARG;
     2387        *ppenum = IEnumFORMATETC_Constructor(This->countFmt, This->pFmt);
     2388        return S_OK;
     2389}
     2390
     2391/***********************************************************************
     2392*   IDataObject implementation
     2393*/
     2394
     2395
     2396typedef struct
     2397{
     2398        /* IUnknown fields */
     2399        ICOM_VFIELD(IDataObject);
     2400        DWORD           ref;
     2401
     2402        /* IDataObject fields */
     2403    LPFORMATETC pFormatEtc;
     2404    LPSTGMEDIUM pStgMedium;
     2405    DWORD       cDataCount;
     2406} IDataObjectImpl;
     2407
     2408static struct ICOM_VTABLE(IDataObject) dtovt;
     2409
     2410/**************************************************************************
     2411*  IDataObject_Constructor
     2412*/
     2413LPDATAOBJECT IDataObject_Constructor()
     2414{
     2415        IDataObjectImpl* dto;
     2416
     2417        dto = (IDataObjectImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDataObjectImpl));
     2418
     2419        if (dto)
     2420        {
     2421          dto->ref = 1;
     2422          ICOM_VTBL(dto) = &dtovt;
     2423        }
     2424       
     2425        return (LPDATAOBJECT)dto;
     2426}
     2427
     2428/***************************************************************************
     2429*  IDataObject_QueryInterface
     2430*/
     2431static HRESULT WINAPI IDataObject_fnQueryInterface(LPDATAOBJECT iface, REFIID riid, LPVOID * ppvObj)
     2432{
     2433        ICOM_THIS(IDataObjectImpl,iface);
     2434        dprintf(("IDataObject_fnQueryInterface (%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj));
     2435
     2436        *ppvObj = NULL;
     2437
     2438        if(IsEqualIID(riid, &IID_IUnknown))          /*IUnknown*/
     2439        {
     2440            *ppvObj = This;
     2441        }
     2442        else if(IsEqualIID(riid, &IID_IDataObject))  /*IDataObject*/
     2443        {
     2444            *ppvObj = (IDataObject*)This;
     2445        }   
     2446
     2447        if(*ppvObj)
     2448        {
     2449            IUnknown_AddRef((IUnknown*)*ppvObj);     
     2450            TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
     2451            return S_OK;
     2452        }
     2453        TRACE("-- Interface: E_NOINTERFACE\n");
     2454        return E_NOINTERFACE;
     2455}
     2456
     2457/**************************************************************************
     2458*  IDataObject_AddRef
     2459*/
     2460static ULONG WINAPI IDataObject_fnAddRef(LPDATAOBJECT iface)
     2461{
     2462        ICOM_THIS(IDataObjectImpl,iface);
     2463
     2464        dprintf(("IDataObject_fnAddRef (%p)->(count=%lu)\n",This, This->ref));
     2465
     2466        return ++(This->ref);
     2467}
     2468
     2469/**************************************************************************
     2470*  IDataObject_Release
     2471*/
     2472static ULONG WINAPI IDataObject_fnRelease(LPDATAOBJECT iface)
     2473{
     2474        ICOM_THIS(IDataObjectImpl,iface);
     2475        dprintf(("IDataObject_fnRelease (%p)->()\n",This));
     2476
     2477    if (!--(This->ref))
     2478        {
     2479          TRACE(" destroying IDataObject(%p)\n",This);
     2480          HeapFree(GetProcessHeap(),0,This);
     2481          return 0;
     2482        }
     2483        return This->ref;
     2484}
     2485
     2486/**************************************************************************
     2487* IDataObject_fnGetData
     2488*/
     2489static HRESULT WINAPI IDataObject_fnGetData(LPDATAOBJECT iface, LPFORMATETC pformatetcIn, STGMEDIUM *pmedium)
     2490{
     2491    int i;
     2492
     2493        ICOM_THIS(IDataObjectImpl,iface);
     2494
     2495    if(pformatetcIn == NULL || pmedium == NULL)
     2496        return E_INVALIDARG;
     2497
     2498    dprintf(("IDataObject_fnGetData %x %x", pformatetcIn, pmedium));
     2499
     2500        if(pformatetcIn->cfFormat != CF_HDROP)
     2501        {
     2502        FIXME("-- expected clipformat not implemented\n");
     2503        return (E_INVALIDARG);
     2504    }
     2505
     2506        /* check our formats table what we have */
     2507        for (i=0; i<This->cDataCount; i++)
     2508        {
     2509            if ((This->pFormatEtc[i].cfFormat == pformatetcIn->cfFormat)
     2510                 && (This->pFormatEtc[i].tymed == pformatetcIn->tymed))
     2511            {
     2512            pmedium->u.hGlobal = This->pStgMedium[i].u.hGlobal;
     2513                break;
     2514            }
     2515        }
     2516        if (pmedium->u.hGlobal)
     2517        {
     2518            pmedium->tymed = TYMED_HGLOBAL;
     2519            pmedium->pUnkForRelease = NULL;
     2520            return S_OK;
     2521        }
     2522        return E_OUTOFMEMORY;
     2523}
     2524
     2525static HRESULT WINAPI IDataObject_fnGetDataHere(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium)
     2526{
     2527        ICOM_THIS(IDataObjectImpl,iface);
     2528       
     2529    dprintf(("IDataObject_fnGetDataHere %x %x STUB", pformatetc, pmedium));
     2530        return E_NOTIMPL;
     2531}
     2532
     2533static HRESULT WINAPI IDataObject_fnQueryGetData(LPDATAOBJECT iface, LPFORMATETC pformatetc)
     2534{
     2535        ICOM_THIS(IDataObjectImpl,iface);
     2536        UINT i;
     2537       
     2538        dprintf(("IDataObject_fnQueryGetData (%p)->(fmt=0x%08x tym=0x%08lx)\n", This, pformatetc->cfFormat, pformatetc->tymed));
     2539       
     2540        if(!(DVASPECT_CONTENT & pformatetc->dwAspect))
     2541          return DV_E_DVASPECT;
     2542
     2543    if(This->pFormatEtc == NULL) {
     2544        return DV_E_TYMED;
     2545    }
     2546        /* check our formats table what we have */
     2547        for (i=0; i<This->cDataCount; i++)
     2548        {
     2549            if ((This->pFormatEtc[i].cfFormat == pformatetc->cfFormat)
     2550                && (This->pFormatEtc[i].tymed == pformatetc->tymed))
     2551            {
     2552            return S_OK;
     2553            }
     2554        }
     2555
     2556        return DV_E_TYMED;
     2557}
     2558
     2559static HRESULT WINAPI IDataObject_fnGetCanonicalFormatEtc(LPDATAOBJECT iface, LPFORMATETC pformatectIn, LPFORMATETC pformatetcOut)
     2560{
     2561        ICOM_THIS(IDataObjectImpl,iface);
     2562       
     2563    dprintf(("IDataObject_fnGetCanonicalFormatEtc STUB"));
     2564    return DATA_S_SAMEFORMATETC;
     2565}
     2566
     2567static HRESULT WINAPI IDataObject_fnSetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
     2568{
     2569    LPFORMATETC pfeNew, pfeTemp;
     2570    LPSTGMEDIUM psmNew, psmTemp;
     2571        ICOM_THIS(IDataObjectImpl,iface);
     2572
     2573    //no need for more than one item
     2574    if(This->cDataCount != 0) {
     2575        DebugInt3();
     2576        return E_OUTOFMEMORY;
     2577    }
     2578    This->cDataCount++;
     2579
     2580    pfeNew = malloc(sizeof(FORMATETC) * This->cDataCount);
     2581    psmNew = malloc(sizeof(STGMEDIUM) * This->cDataCount);
     2582
     2583    if(pfeNew && psmNew)
     2584    {
     2585        memset(pfeNew, 0, sizeof(FORMATETC) * This->cDataCount);
     2586        memset(psmNew, 0, sizeof(STGMEDIUM) * This->cDataCount);
     2587   
     2588        /* copy the existing data */
     2589        if(This->pFormatEtc)
     2590        {
     2591            memcpy(pfeNew, This->pFormatEtc, sizeof(FORMATETC) * (This->cDataCount - 1));
     2592        }
     2593        if(This->pStgMedium)
     2594        {
     2595            memcpy(psmNew, This->pStgMedium, sizeof(STGMEDIUM) * (This->cDataCount - 1));
     2596        }
     2597   
     2598        /* add the new data */
     2599        pfeNew[This->cDataCount - 1] = *pformatetc;
     2600        if(fRelease)
     2601        {
     2602            psmNew[This->cDataCount - 1] = *pmedium;
     2603        }
     2604        else
     2605        {
     2606            DebugInt3();
     2607//            CopyStgMedium(pmedium, &psmNew[This->cDataCount - 1]);
     2608        }
     2609
     2610        pfeTemp = This->pFormatEtc;
     2611        This->pFormatEtc = pfeNew;
     2612        pfeNew = pfeTemp;
     2613
     2614        psmTemp = This->pStgMedium;
     2615        This->pStgMedium = psmNew;
     2616        psmNew = psmTemp;
     2617    }
     2618
     2619    if(pfeNew)
     2620        free(pfeNew);
     2621
     2622    if(psmNew)
     2623        free(psmNew);
     2624
     2625    if(This->pFormatEtc && This->pStgMedium)
     2626        return S_OK;
     2627
     2628    return E_OUTOFMEMORY;
     2629}
     2630
     2631static HRESULT WINAPI IDataObject_fnEnumFormatEtc(LPDATAOBJECT iface, DWORD dwDirection, IEnumFORMATETC **ppenumFormatEtc)
     2632{
     2633        ICOM_THIS(IDataObjectImpl,iface);
     2634
     2635        TRACE("(%p)->()\n", This);
     2636        *ppenumFormatEtc=NULL;
     2637
     2638        /* only get data */
     2639        if (DATADIR_GET == dwDirection)
     2640        {
     2641          *ppenumFormatEtc = IEnumFORMATETC_Constructor(This->cDataCount, This->pFormatEtc);
     2642          return (*ppenumFormatEtc) ? S_OK : E_FAIL;
     2643        }
     2644       
     2645        return E_NOTIMPL;
     2646}
     2647
     2648static HRESULT WINAPI IDataObject_fnDAdvise(LPDATAOBJECT iface, FORMATETC *pformatetc, DWORD advf, IAdviseSink *pAdvSink, DWORD *pdwConnection)
     2649{
     2650        ICOM_THIS(IDataObjectImpl,iface);
     2651
     2652    dprintf(("IDataObject_fnDAdvise STUB"));
     2653        return E_NOTIMPL;
     2654}
     2655static HRESULT WINAPI IDataObject_fnDUnadvise(LPDATAOBJECT iface, DWORD dwConnection)
     2656{
     2657        ICOM_THIS(IDataObjectImpl,iface);
     2658   
     2659    dprintf(("IDataObject_fnDUnadvise STUB"));
     2660        return E_NOTIMPL;
     2661}
     2662static HRESULT WINAPI IDataObject_fnEnumDAdvise(LPDATAOBJECT iface, IEnumSTATDATA **ppenumAdvise)
     2663{
     2664        ICOM_THIS(IDataObjectImpl,iface);
     2665   
     2666    dprintf(("IDataObject_fnEnumDAdvise STUB"));
     2667    return OLE_E_ADVISENOTSUPPORTED;
     2668}
     2669
     2670static struct ICOM_VTABLE(IDataObject) dtovt =
     2671{
     2672        ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
     2673        IDataObject_fnQueryInterface,
     2674        IDataObject_fnAddRef,
     2675        IDataObject_fnRelease,
     2676        IDataObject_fnGetData,
     2677        IDataObject_fnGetDataHere,
     2678        IDataObject_fnQueryGetData,
     2679        IDataObject_fnGetCanonicalFormatEtc,
     2680        IDataObject_fnSetData,
     2681        IDataObject_fnEnumFormatEtc,
     2682        IDataObject_fnDAdvise,
     2683        IDataObject_fnDUnadvise,
     2684        IDataObject_fnEnumDAdvise
     2685};
     2686
     2687//******************************************************************************
     2688//******************************************************************************
     2689BOOL WINAPI OLEDD_AcceptsDragDrop(HWND hwnd)
     2690{
     2691    DropTargetNode *pTarget;
     2692
     2693    /*
     2694     * Find-out if there is a drag target under the mouse
     2695     */
     2696    HWND nexttar = hwnd;
     2697    do {
     2698        pTarget = OLEDD_FindDropTarget(nexttar);
     2699    }
     2700    while(!pTarget && (nexttar = GetParent(nexttar)) != 0);
     2701
     2702    if(pTarget != NULL) {
     2703        dprintf(("OLEDD_AcceptsDragDrop %x accepted", hwnd));
     2704        return TRUE;
     2705    }
     2706    dprintf(("OLEDD_AcceptsDragDrop %x refused", hwnd));
     2707    return FALSE;
     2708}
     2709//******************************************************************************
     2710//******************************************************************************
     2711BOOL WINAPI OLEDD_DropFiles(HWND hwnd)
     2712{
     2713    DropTargetNode *pTarget;
     2714    DWORD           keyState = 0;
     2715    POINTL          mousePosParam;
     2716    POINT           mousePos;
     2717    HWND            nexttar = hwnd;
     2718
     2719    dprintf(("OLEDD_DropFiles %x", hwnd));
     2720
     2721    do {
     2722        pTarget = OLEDD_FindDropTarget(nexttar);
     2723    }
     2724    while(!pTarget && (nexttar = GetParent(nexttar)) != 0);
     2725    if(pTarget == NULL) {
     2726        return FALSE;
     2727    }
     2728   
     2729    /*
     2730     * The documentation tells me that the coordinate should be in the target
     2731     * window's coordinate space. However, the tests I made tell me the
     2732     * coordinates should be in screen coordinates.
     2733     */
     2734    GetCursorPos(&mousePos);
     2735    mousePosParam.x = mousePos.x;
     2736    mousePosParam.y = mousePos.y;
     2737   
     2738    if(GetKeyState(VK_SHIFT)   & 0x8000) keyState |= MK_SHIFT;
     2739    if(GetKeyState(VK_CONTROL) & 0x8000) keyState |= MK_CONTROL;
     2740    if(GetKeyState(VK_MENU)    & 0x8000) keyState |= MK_ALT;
     2741    if(GetKeyState(VK_LBUTTON) & 0x8000) keyState |= MK_LBUTTON;
     2742    if(GetKeyState(VK_RBUTTON) & 0x8000) keyState |= MK_RBUTTON;
     2743    if(GetKeyState(VK_MBUTTON) & 0x8000) keyState |= MK_MBUTTON;
     2744
     2745    return IDropTarget_Drop(pTarget->dropTarget, pTarget->pDataObject,
     2746                            keyState, mousePosParam, &pTarget->dwEffect) == S_OK;
     2747}
     2748//******************************************************************************
     2749//******************************************************************************
     2750BOOL WIN32API OLEDD_DragOver(HWND hwnd, DWORD dwEffect)
     2751{
     2752    DropTargetNode *pTarget;
     2753    DWORD           keyState = 0;
     2754    POINTL          mousePosParam;
     2755    POINT           mousePos;
     2756    HWND            nexttar = hwnd;
     2757
     2758    dprintf(("OLEDD_DragOver %x %d", hwnd, dwEffect));
     2759
     2760    do {
     2761        pTarget = OLEDD_FindDropTarget(nexttar);
     2762    }
     2763    while(!pTarget && (nexttar = GetParent(nexttar)) != 0);
     2764    if(pTarget == NULL) {
     2765        return FALSE;
     2766    }
     2767   
     2768    /*
     2769     * The documentation tells me that the coordinate should be in the target
     2770     * window's coordinate space. However, the tests I made tell me the
     2771     * coordinates should be in screen coordinates.
     2772     */
     2773    GetCursorPos(&mousePos);
     2774    mousePosParam.x = mousePos.x;
     2775    mousePosParam.y = mousePos.y;
     2776   
     2777    if(GetKeyState(VK_SHIFT)   & 0x8000) keyState |= MK_SHIFT;
     2778    if(GetKeyState(VK_CONTROL) & 0x8000) keyState |= MK_CONTROL;
     2779    if(GetKeyState(VK_MENU)    & 0x8000) keyState |= MK_ALT;
     2780    if(GetKeyState(VK_LBUTTON) & 0x8000) keyState |= MK_LBUTTON;
     2781    if(GetKeyState(VK_RBUTTON) & 0x8000) keyState |= MK_RBUTTON;
     2782    if(GetKeyState(VK_MBUTTON) & 0x8000) keyState |= MK_MBUTTON;
     2783    return IDropTarget_DragOver(pTarget->dropTarget, keyState, mousePosParam, &dwEffect) == S_OK;
     2784}
     2785//******************************************************************************
     2786//******************************************************************************
     2787BOOL WIN32API OLEDD_DragEnter(HWND hwnd, HDROP hDrop, DWORD dwEffect)
     2788{
     2789    FORMATETC       fe;
     2790    STGMEDIUM       medium;
     2791    DropTargetNode *pTarget;
     2792    DWORD           keyState = 0;
     2793    POINTL          mousePosParam;
     2794    POINT           mousePos;
     2795    HWND            nexttar = hwnd;
     2796
     2797    dprintf(("OLEDD_DragEnter %x %x %d", hwnd, hDrop, dwEffect));
     2798
     2799    do {
     2800        pTarget = OLEDD_FindDropTarget(nexttar);
     2801    }
     2802    while(!pTarget && (nexttar = GetParent(nexttar)) != 0);
     2803    if(pTarget == NULL) {
     2804        return FALSE;
     2805    }
     2806   
     2807    /*
     2808     * The documentation tells me that the coordinate should be in the target
     2809     * window's coordinate space. However, the tests I made tell me the
     2810     * coordinates should be in screen coordinates.
     2811     */
     2812    GetCursorPos(&mousePos);
     2813    mousePosParam.x = mousePos.x;
     2814    mousePosParam.y = mousePos.y;
     2815   
     2816    if(GetKeyState(VK_SHIFT)   & 0x8000) keyState |= MK_SHIFT;
     2817    if(GetKeyState(VK_CONTROL) & 0x8000) keyState |= MK_CONTROL;
     2818    if(GetKeyState(VK_MENU)    & 0x8000) keyState |= MK_ALT;
     2819    if(GetKeyState(VK_LBUTTON) & 0x8000) keyState |= MK_LBUTTON;
     2820    if(GetKeyState(VK_RBUTTON) & 0x8000) keyState |= MK_RBUTTON;
     2821    if(GetKeyState(VK_MBUTTON) & 0x8000) keyState |= MK_MBUTTON;
     2822
     2823    fe.cfFormat = CF_HDROP;
     2824    fe.ptd      = NULL;
     2825    fe.dwAspect = DVASPECT_CONTENT; 
     2826    fe.lindex   = -1;
     2827    fe.tymed    = TYMED_HGLOBAL;
     2828
     2829    medium.u.hGlobal      = hDrop;
     2830    medium.tymed          = TYMED_HGLOBAL;
     2831    medium.pUnkForRelease = NULL;
     2832
     2833    pTarget->fDragEnter = TRUE;
     2834    pTarget->dwEffect   = dwEffect;
     2835
     2836    //just in case dragleave wasn't called...
     2837    if(pTarget->hDrop) {
     2838        GlobalFree(pTarget->hDrop);
     2839    }
     2840    if(pTarget->pDataObject) {
     2841        IDataObject_Release(pTarget->pDataObject);
     2842    }
     2843
     2844    pTarget->hDrop      = hDrop;
     2845    pTarget->pDataObject = IDataObject_Constructor();
     2846    IDataObject_AddRef(pTarget->pDataObject);
     2847    IDataObject_SetData(pTarget->pDataObject, &fe, &medium, TRUE);
     2848    return IDropTarget_DragEnter(pTarget->dropTarget, pTarget->pDataObject, keyState, mousePosParam, &dwEffect) == S_OK;
     2849}
     2850//******************************************************************************
     2851//******************************************************************************
     2852BOOL WIN32API OLEDD_DragLeave(HWND hwnd)
     2853{
     2854    DropTargetNode *pTarget;
     2855
     2856    dprintf(("OLEDD_DragLeave %x", hwnd));
     2857
     2858    pTarget = OLEDD_FindDropTarget(hwnd);
     2859    if(pTarget == NULL) {
     2860        return FALSE;
     2861    }
     2862    pTarget->fDragEnter = FALSE;
     2863    if(pTarget->hDrop) {
     2864        GlobalFree(pTarget->hDrop);
     2865        pTarget->hDrop = 0;
     2866    }
     2867    if(pTarget->pDataObject) {
     2868        IDataObject_Release(pTarget->pDataObject);
     2869        pTarget->pDataObject = NULL;
     2870    }
     2871    return IDropTarget_DragLeave(pTarget->dropTarget) == S_OK;
     2872}
     2873//******************************************************************************
     2874//******************************************************************************
     2875#endif
     2876
    22202877#ifndef __WIN32OS2__
    22212878/******************************************************************************
  • trunk/src/ole32/ole32.def

    r8007 r8553  
    217217    CLSIDFromString16          = _CLSIDFromString16@8        @1002  ; COMPOBJ.19
    218218
     219; private functions for drag and drop (used by user32\dragdrop.cpp)
     220    OLEDD_AcceptsDragDrop      = _OLEDD_AcceptsDragDrop@4    @1010
     221    OLEDD_DropFiles            = _OLEDD_DropFiles@4          @1011
     222    OLEDD_DragOver             = _OLEDD_DragOver@8           @1012
     223    OLEDD_DragEnter            = _OLEDD_DragEnter@12         @1013
     224    OLEDD_DragLeave            = _OLEDD_DragLeave@4          @1014
  • trunk/src/ole32/ole32dbg.def

    r8007 r8553  
    218218    CLSIDFromString16          = _DbgCLSIDFromString16@8        @1002  ; COMPOBJ.19
    219219
     220; private functions for drag and drop (used by user32\dragdrop.cpp)
     221    OLEDD_AcceptsDragDrop      = _OLEDD_AcceptsDragDrop@4    @1010
     222    OLEDD_DropFiles            = _OLEDD_DropFiles@4          @1011
     223    OLEDD_DragOver             = _OLEDD_DragOver@8           @1012
     224    OLEDD_DragEnter            = _OLEDD_DragEnter@12         @1013
     225    OLEDD_DragLeave            = _OLEDD_DragLeave@4          @1014
  • trunk/src/user32/dragdrop.cpp

    r8542 r8553  
    1 /* $Id: dragdrop.cpp,v 1.1 2002-06-02 10:08:09 sandervl Exp $ */
     1/* $Id: dragdrop.cpp,v 1.2 2002-06-02 19:34:25 sandervl Exp $ */
    22
    33/*
     
    1111#include <windows.h>
    1212#include <dbglog.h>
     13#include <oledd.h>
    1314
    1415#define DBG_LOCALLOG    DBG_dragdrop
    1516#include "dbglocal.h"
    1617
     18static PFN_DRAGENTER       pfnDragEnter       = NULL;
     19static PFN_DRAGLEAVE       pfnDragLeave       = NULL;
     20static PFN_DROPFILES       pfnDropFiles       = NULL;
     21static PFN_DRAGOVER        pfnDragOver        = NULL;
     22static PFN_ACCEPTSDRAGDROP pfnAcceptsDragDrop = NULL;
     23static HANDLE              hOLE32             = 0;
     24
    1725//******************************************************************************
    1826//******************************************************************************
    19 ULONG DragDropFiles(HWND hwnd, UINT cFiles, POINT point, LPSTR pszFiles, UINT cbszFiles, BOOL fNonClient)
     27ULONG DragDropFiles(HWND hwnd, POINT point, UINT cFiles, LPSTR pszFiles, UINT cbszFiles, BOOL fNonClient)
    2028{
    2129    DROPFILES *pDropFile;
    2230    HGLOBAL    hDropFile;
    2331    DWORD      dwExStyle;
     32    HWND       orghwnd = hwnd;
    2433
    2534    dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
    2635   
    27     //Is it correct if the window or parent accepts files or must we check the topparent parent?
     36    //TODO: Is it correct if the window or parent accepts files or must we check the top parent?
    2837    hwnd = (dwExStyle & WS_EX_ACCEPTFILES) ? hwnd : GetParent(hwnd);
     38
     39    dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
     40    if(!(dwExStyle & WS_EX_ACCEPTFILES)) {
     41        if(pfnDropFiles) {
     42            return pfnDropFiles(hwnd);
     43        }
     44        return FALSE;
     45    }
    2946    cbszFiles++;    //extra terminating 0
    30 
    31     if(IsWindowUnicode(hwnd)) {
    32         dprintf(("unicode dropfiles"));
    33         cbszFiles *= 2;
    34     }
    35 
    3647    hDropFile = GlobalAlloc(0, sizeof(DROPFILES)+cbszFiles);
    3748    pDropFile = (DROPFILES *)GlobalLock(hDropFile);
     
    4253    pDropFile->pFiles = sizeof(DROPFILES);
    4354    pDropFile->fNC    = fNonClient;
    44     pDropFile->fWide  = ::IsWindowUnicode(hwnd);
     55    pDropFile->fWide  = FALSE;
    4556    pDropFile->pt     = point;
    46     if(IsWindowUnicode(hwnd)) {
    47         LPWSTR lpszFilesW = (LPWSTR)(pDropFile+1);
    48         while(*pszFiles) {
    49             int len = strlen(pszFiles);
    50             MultiByteToWideChar(CP_ACP, 0, pszFiles, -1, lpszFilesW, len);
    51             pszFiles   += len + 1;
    52             lpszFilesW += len + 1;
    53         }
    54         *lpszFilesW = 0;
    55     }
    56     else {
    57         //copy strings (excluding terminating 0)
    58         memcpy((pDropFile+1), pszFiles, cbszFiles-1);
    59     }
     57    //copy strings (excluding terminating 0)
     58    memcpy((pDropFile+1), pszFiles, cbszFiles-1);
    6059    GlobalUnlock(hDropFile);
    6160    SendMessageA(hwnd, WM_DROPFILES, hDropFile, 0);
    6261    return 0;
     62}
     63//******************************************************************************
     64//******************************************************************************
     65BOOL DragDropDragOver(HWND hwnd, DWORD dwEffect)
     66{
     67    if(pfnDragOver) {
     68        return pfnDragOver(hwnd, dwEffect);
     69    }
     70    return TRUE;    //ignore
     71}
     72//******************************************************************************
     73//******************************************************************************
     74BOOL DragDropDragEnter(HWND hwnd, POINT point, UINT cFiles, LPSTR pszFiles, UINT cbszFiles,
     75                       DWORD dwEffect, BOOL fNonClient)
     76{
     77    DROPFILES *pDropFile;
     78    HGLOBAL    hDropFile;
     79
     80    if(pfnDragEnter) {
     81        cbszFiles++;    //extra terminating 0
     82        hDropFile = GlobalAlloc(0, sizeof(DROPFILES)+cbszFiles);
     83        pDropFile = (DROPFILES *)GlobalLock(hDropFile);
     84        if(pDropFile == NULL) {
     85            DebugInt3();
     86            return FALSE;
     87        }
     88        pDropFile->pFiles = sizeof(DROPFILES);
     89        pDropFile->fNC    = fNonClient;
     90        pDropFile->fWide  = FALSE;
     91        pDropFile->pt     = point;
     92        //copy strings (excluding terminating 0)
     93        memcpy((pDropFile+1), pszFiles, cbszFiles-1);
     94        GlobalUnlock(hDropFile);
     95
     96        return pfnDragEnter(hwnd, hDropFile, dwEffect);
     97    }
     98    return TRUE;    //ignore
     99}
     100//******************************************************************************
     101//******************************************************************************
     102BOOL DragDropDragLeave(HWND hwnd)
     103{
     104    if(pfnDragLeave) {
     105        return pfnDragLeave(hwnd);
     106    }
     107    return TRUE;    //ignore
    63108}
    64109//******************************************************************************
     
    75120    DWORD dwStyle = GetWindowLongA(GetParent(hwnd), GWL_EXSTYLE);
    76121    if(!(dwStyle & WS_EX_ACCEPTFILES)) {
     122        if(pfnAcceptsDragDrop == NULL) {
     123            //check for OLE drag & drop
     124
     125            hOLE32 = GetModuleHandleA("OLE32.DLL");
     126            if(hOLE32 == 0) {
     127                //if ole32.dll isn't loaded, then ole drag and drop can't be active
     128                return FALSE;
     129            }
     130            //make sure the dll doesn't get unloaded
     131            hOLE32 = LoadLibraryA("OLE32.DLL");
     132
     133            pfnAcceptsDragDrop = (PFN_ACCEPTSDRAGDROP)GetProcAddress(hOLE32, "OLEDD_AcceptsDragDrop");
     134            pfnDragOver        = (PFN_DRAGOVER)GetProcAddress(hOLE32, "OLEDD_DragOver");
     135            pfnDragLeave       = (PFN_DRAGLEAVE)GetProcAddress(hOLE32, "OLEDD_DragLeave");
     136            pfnDragEnter       = (PFN_DRAGENTER)GetProcAddress(hOLE32, "OLEDD_DragEnter");
     137            pfnDropFiles       = (PFN_DROPFILES)GetProcAddress(hOLE32, "OLEDD_DropFiles");
     138            if(!pfnAcceptsDragDrop || !pfnDragOver || !pfnDragLeave || !pfnDragEnter || !pfnDropFiles) {
     139                dprintf(("OLE DD functions not found!!"));
     140                DebugInt3();
     141                return FALSE;
     142            }
     143        }
     144        if(pfnAcceptsDragDrop) {
     145            return pfnAcceptsDragDrop(hwnd);
     146        }
    77147        return FALSE;
    78148    }
  • trunk/src/user32/dragdrop.h

    r8542 r8553  
    1 /* $Id: dragdrop.h,v 1.1 2002-06-02 10:08:10 sandervl Exp $ */
     1/* $Id: dragdrop.h,v 1.2 2002-06-02 19:34:27 sandervl Exp $ */
    22
    33/*
     
    1313
    1414BOOL  DragDropAccept(HWND hwnd);
    15 ULONG DragDropFiles(HWND hwnd, UINT cFiles, POINT point, LPSTR pszFiles, UINT cbszFiles, BOOL fNonClient = FALSE);
     15BOOL  DragDropDragOver(HWND hwnd, DWORD dwEffect);
     16BOOL  DragDropDragLeave(HWND hwnd);
     17BOOL  DragDropFiles(HWND hwnd, POINT point, UINT cFiles, LPSTR pszFiles, UINT cbszFiles, BOOL fNonClient = FALSE);
     18BOOL  DragDropDragEnter(HWND hwnd, POINT point, UINT cFiles, LPSTR pszFiles, UINT cbszFiles, DWORD dwEffect, BOOL fNonClient = FALSE);
    1619
    1720#endif //__DRAGDROP_H__
  • 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
  • trunk/src/user32/win32wbase.cpp

    r8542 r8553  
    1 /* $Id: win32wbase.cpp,v 1.326 2002-06-02 10:07:58 sandervl Exp $ */
     1/* $Id: win32wbase.cpp,v 1.327 2002-06-02 19:34:31 sandervl Exp $ */
    22/*
    33 * Win32 Window Base Class for OS/2
     
    179179  fEraseBkgndFlag  = TRUE;
    180180  fFakeWindow      = FALSE;
     181  fIsDragDropActive= FALSE;
    181182
    182183  state            = STATE_INIT;
  • trunk/src/user32/win32wbase.h

    r8542 r8553  
    1 /* $Id: win32wbase.h,v 1.142 2002-06-02 10:07:59 sandervl Exp $ */
     1/* $Id: win32wbase.h,v 1.143 2002-06-02 19:34:36 sandervl Exp $ */
    22/*
    33 * Win32 Window Base Class for OS/2
     
    183183         void   setLastActive(HWND _hwndLastActive)
    184184                                                { hwndLastActive = _hwndLastActive; };
     185         BOOL   isDragDropActive()              { return fIsDragDropActive; };
     186         void   setDragDropActive(BOOL fActive) { fIsDragDropActive = fActive; };
    185187
    186188 Win32WndClass *getWindowClass()                { return windowClass; };
     
    422424                 fVisibleRegionChanged:1, //set when visible region has changed -> erase background must be sent during next BeginPaint
    423425                 fEraseBkgndFlag:1,
     426                 fIsDragDropActive:1,
    424427                 fFakeWindow:1;
    425428
Note: See TracChangeset for help on using the changeset viewer.