Changeset 471 for trunk/src


Ignore:
Timestamp:
Jan 25, 2010, 5:03:17 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

gui: DnD: Replaced r470 with a better solution (simpler and doesn't report a dummy mime type "" in the dropped mime data -- for compatibility with other platforms).

Location:
trunk/src/gui/kernel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/kernel/qdnd_pm.cpp

    r470 r471  
    611611            DrgFreeDraginfo(info);
    612612
     613            DEBUG(("DM_DRAGOVER: return %08lx default %08lx",
     614                   dropReply, toPmDragDropOp(dragData->lastAction)));
    613615            return MRFROM2SHORT(dropReply, toPmDragDropOp(dragData->lastAction));
    614616        }
     
    913915    }
    914916
    915     if (!mimeData->formats().count()) {
    916         // The drag source doesn't provide any format, so we've got no workers.
    917         // Although it may look strange, but it is a supported case: for
    918         // example, designer uses it a lot for in-process DnD. Instead of MIME
    919         // data, it works directly with the QMimeData object from the drag
    920         // source. We will go through the converters passing a special value of
    921         // QString::null as MIME type -- one of them (e.g. QPMAnyMime) should
    922         // take it over and return itself.
    923         Q_ASSERT(!workers.count());
    924         DEBUG(() << "QPMCoopDragWorker: Source provides NO data, looking for a "
    925                     "converter that can handle this");
    926         foreach (QPMMime *mime, QPMMime::all()) {
    927             DragWorker *wrk = mime->dragWorkerFor(QString::null, mimeData);
    928             if (wrk) {
    929                 workers.append(wrk);
    930                 break;
    931             }
    932         }
    933     }
    934 
    935917#if defined(QDND_DEBUG)
    936918    foreach (DragWorker *wrk, workers) {
     
    941923#endif
    942924
     925    if (!mimeData->formats().count()) {
     926        // The drag source doesn't provide any format, so we've got no workers.
     927        // Although it may look strange, it is a supported case: for example,
     928        // designer uses it a lot for in-process DnD. Instead of MIME data, it
     929        // works directly with the QMimeData object from the drag source. We
     930        // will handle this situation by providing a dummy DRAGINFO structure.
     931        DEBUG(() << "QPMCoopDragWorker: Source provides NO data, will use "
     932                    "dummy DRAGINFO");
     933        Q_ASSERT(!workers.count());
     934        return true;
     935    }
     936
    943937    Q_ASSERT(workers.count() > 0);
    944938    return workers.count() > 0;
     
    947941HWND QPMCoopDragWorker::hwnd() const
    948942{
    949     DragWorker *firstWorker = workers.first();
    950     Q_ASSERT(firstWorker);
    951     if (!firstWorker)
    952         return 0;
    953 
    954     if (firstWorker->isExclusive() && firstWorker->itemCount() == 0) {
    955         // this is a super exclusive worker that will do everything on its own
    956         return firstWorker->hwnd();
     943    if (!workers.count()) {
     944        // The drag source doesn't provide any format; will handle it ourselves
     945    } else {
     946        DragWorker *firstWorker = workers.first();
     947        if (firstWorker->isExclusive() && firstWorker->itemCount() == 0) {
     948            // this is a super exclusive worker that will do everything on its own
     949            return firstWorker->hwnd();
     950        }
    957951    }
    958952
     
    989983    if (info)
    990984        return 0;
     985
     986    if (!workers.count()) {
     987        // The drag source doesn't provide any format; provide a dummy DRAGINFO
     988        // with a null DRAGITEM that we will never render
     989        info = DrgAllocDraginfo(1);
     990        Q_ASSERT(info);
     991        if (!info)
     992            return 0;
     993
     994        DRAGITEM *item = DrgQueryDragitemPtr(info, 0);
     995        Q_ASSERT(item);
     996        if (!item) {
     997            DrgFreeDraginfo(info);
     998            info = 0;
     999            return 0;
     1000        }
     1001
     1002        item->hwndItem = hwnd();
     1003        item->ulItemID = 0;
     1004        item->hstrType = 0;
     1005        item->hstrRMF = 0;
     1006        item->hstrContainerName = 0;
     1007        item->hstrSourceName = 0;
     1008        item->hstrTargetName = 0;
     1009        item->cxOffset = 0;
     1010        item->cyOffset = 0;
     1011        item->fsControl = DC_PREPARE; // require DM_RENDERPREPARE from target
     1012        item->fsSupportedOps = supportedOps;
     1013
     1014        return info;
     1015    }
    9911016
    9921017    DragWorker *firstWorker = workers.first();
  • trunk/src/gui/kernel/qmime_pm.cpp

    r470 r471  
    365365        return formats;
    366366
    367     if (qstrcmp(formats, "DRF_NULL") == 0) {
    368         // special case, see QPMMimeAnyMime::dragWorkerFor()
    369         formats = "<DRM_NULL," + formats + ">";
    370     } else {
    371         // DRM_SHAREDMEM comes first to prevent native DRM_OS2FILE
    372         // rendering on the target side w/o involving the source.
    373         // Also, we add <DRM_SHAREDMEM,DRF_POINTERDATA> just like WPS does it
    374         // (however, it doesn't help when dropping objects to it -- WPS still
    375         // chooses DRM_OS2FILE).
    376         formats = "(DRM_SHAREDMEM,DRM_OS2FILE)x(" + formats + "),"
    377                   "<DRM_SHAREDMEM,DRF_POINTERDATA>";
    378     }
     367    // DRM_SHAREDMEM comes first to prevent native DRM_OS2FILE
     368    // rendering on the target side w/o involving the source.
     369    // Also, we add <DRM_SHAREDMEM,DRF_POINTERDATA> just like WPS does it
     370    // (however, it doesn't help when dropping objects to it -- WPS still
     371    // chooses DRM_OS2FILE).
     372    formats = "(DRM_SHAREDMEM,DRM_OS2FILE)x(" + formats + "),"
     373              "<DRM_SHAREDMEM,DRF_POINTERDATA>";
    379374
    380375    DEBUG(() << "DefaultDragWorker: formats" << formats
     
    832827    if (!provider)
    833828        return ret;
    834 
    835     if (mimeType.isEmpty()) {
    836         // special case, see QPMMimeAnyMime::dropWorkerFor()
    837         return ret;
    838     }
    839829
    840830    QByteArray drf = provider->drf(mimeType);
     
    11271117                                             Provider *provider)
    11281118{
    1129     // note: as a special case, mimeType may be null (see
    1130     // QPMCoopDragWorker::collectWorkers())
    1131 
    1132     Q_ASSERT(provider);
    1133     if (provider && !d->exclusive) {
     1119    Q_ASSERT(!mimeType.isEmpty() && provider);
     1120    if (!mimeType.isEmpty() && provider && !d->exclusive) {
    11341121        // ensure there are no dups (several providers for the same mime)
    11351122        if (!d->providerFor(mimeType))
     
    13041291{
    13051292    ULONG cf = WinAddAtom(WinQuerySystemAtomTable(), mime.toLocal8Bit());
     1293    if (!cf) {
    13061294#ifndef QT_NO_DEBUG
    1307     if (!cf)
    13081295        qWarning("QPMMime: WinAddAtom failed with 0x%lX",
    13091296                 WinGetLastError(NULLHANDLE));
    13101297#endif
     1298        return 0;
     1299    }
    13111300
    13121301    return cf;
     
    27342723                                               QString &type, QString &ext)
    27352724{
    2736     if (qstrcmp(drf, "DRF_NULL") == 0) {
    2737         // special case (see QPMMimeAnyMime::dragWorkerFor())
    2738         type = QString::null;
    2739     } else {
    2740         // file type = mime
    2741         type = format(drf);
    2742         Q_ASSERT(!type.isEmpty());
    2743     }
     2725    // file type = mime
     2726    type = format(drf);
     2727    Q_ASSERT(!type.isEmpty());
    27442728
    27452729    // no way to determine the extension
     
    27752759                                                   QMimeData *mimeData)
    27762760{
    2777     if (mimeType.isEmpty()) {
    2778         // special case: QMimeData with no formats() (see
    2779         // QPMCoopDragWorker::collectWorkers())
    2780         Q_ASSERT(!mimeData->formats().count());
    2781         // add an exclusive provider with a special format DRF_NULL. Note that
    2782         // any attemt to render this format should fail so we don't expect
    2783         // AnyDragProvider::format()/provide() to be actually called.
    2784         DefaultDragWorker *defWorker = defaultExclDragWorker();
    2785         defWorker->addProvider(QByteArray("DRF_NULL"), &anyDragProvider);
    2786         return defWorker;
    2787     }
    2788 
    27892761    ULONG cf = cfMap.value(mimeType);
    27902762    if (!cf)
     
    28162788        DefaultDropWorker *defWorker = defaultDropWorker();
    28172789        bool atLeastOneSupported = false;
    2818 
    2819         if (qstrcmp(queryHSTR(item->hstrRMF), "<DRM_NULL,DRF_NULL>") == 0) {
    2820             // special case: QMimeData with no formats() (see
    2821             // QPMCoopDragWorker::collectWorkers()), use a special MIME format
    2822             // value of null.  Note that any attemt to retrieve data in this
    2823             // format should fail so we don't expect AnyDropProvider::drf()/
    2824             // provide() to be actually called.
    2825             defWorker->addProvider(QString::null, &anyDropProvider);
    2826             return defWorker;
    2827         }
    28282790
    28292791        // check that we support one of DRMs and the format is CF_hhhhhhh
     
    29022864    if (atomStr.startsWith(mimePrefix)) {
    29032865        // the format represents the mime type we can recognize
     2866        // increase the reference count
     2867        ULONG cf = QPMMime::registerMimeType(atomStr);
     2868        Q_ASSERT(cf == format);
    29042869        // extract the real mime type (w/o our prefix)
    29052870        mime = atomStr.mid(mimePrefix.size());
    2906         Q_ASSERT(!mime.isEmpty());
    29072871        if (!mime.isEmpty()) {
    2908             // increase the reference count (will decrease on destruction)
    2909             ULONG cf = QPMMime::registerMimeType(atomStr);
    2910             Q_ASSERT(cf == format);
    29112872            cfMap[mime] = cf;
    29122873            mimeMap[cf] = mime;
Note: See TracChangeset for help on using the changeset viewer.