void DragData::asFilenames(Vector<String>& result) const { #if USE(CF) if (m_platformDragData) { WCHAR filename[MAX_PATH]; STGMEDIUM medium; if (FAILED(m_platformDragData->GetData(cfHDropFormat(), &medium))) return; HDROP hdrop = reinterpret_cast<HDROP>(GlobalLock(medium.hGlobal)); if (!hdrop) return; const unsigned numFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0); for (unsigned i = 0; i < numFiles; i++) { if (!DragQueryFileW(hdrop, i, filename, WTF_ARRAY_LENGTH(filename))) continue; result.append(static_cast<UChar*>(filename)); } // Free up memory from drag DragFinish(hdrop); GlobalUnlock(medium.hGlobal); return; } result = m_dragDataMap.get(cfHDropFormat()->cfFormat); #endif }
unsigned DragData::numberOfFiles() const { #if USE(CF) if (!m_platformDragData) return 0; STGMEDIUM medium; if (FAILED(m_platformDragData->GetData(cfHDropFormat(), &medium))) return 0; HDROP hdrop = static_cast<HDROP>(GlobalLock(medium.hGlobal)); if (!hdrop) return 0; unsigned numFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0); DragFinish(hdrop); GlobalUnlock(medium.hGlobal); return numFiles; #else return 0; #endif }
void DragData::asFilenames(Vector<String>& result) const { WCHAR filename[MAX_PATH]; STGMEDIUM medium; if (FAILED(m_platformDragData->GetData(cfHDropFormat(), &medium))) return; HDROP hdrop = (HDROP)GlobalLock(medium.hGlobal); if (!hdrop) return; const unsigned numFiles = DragQueryFileW(hdrop, 0xFFFFFFFF, 0, 0); for (unsigned i = 0; i < numFiles; i++) { if (!DragQueryFileW(hdrop, 0, filename, ARRAYSIZE(filename))) continue; result.append((UChar*)filename); } // Free up memory from drag DragFinish(hdrop); GlobalUnlock(medium.hGlobal); }
bool DragData::containsFiles() const { #if USE(CF) return (m_platformDragData) ? SUCCEEDED(m_platformDragData->QueryGetData(cfHDropFormat())) : m_dragDataMap.contains(cfHDropFormat()->cfFormat); #else return false; #endif }
static bool getWebLocData(IDataObject* dataObject, String& url, String* title) { bool succeeded = false; #if PLATFORM(CF) WCHAR filename[MAX_PATH]; WCHAR urlBuffer[INTERNET_MAX_URL_LENGTH]; STGMEDIUM medium; if (FAILED(dataObject->GetData(cfHDropFormat(), &medium))) return false; HDROP hdrop = static_cast<HDROP>(GlobalLock(medium.hGlobal)); if (!hdrop) return false; if (!DragQueryFileW(hdrop, 0, filename, ARRAYSIZE(filename))) goto exit; if (_wcsicmp(PathFindExtensionW(filename), L".url")) goto exit; if (!GetPrivateProfileStringW(L"InternetShortcut", L"url", 0, urlBuffer, ARRAYSIZE(urlBuffer), filename)) goto exit; if (title) { PathRemoveExtension(filename); *title = String((UChar*)filename); } url = String((UChar*)urlBuffer); succeeded = true; exit: // Free up memory. DragFinish(hdrop); GlobalUnlock(medium.hGlobal); #endif return succeeded; }
static JSValueRef beginDragWithFilesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) return JSValueMakeUndefined(context); JSObjectRef filesArray = JSValueToObject(context, arguments[0], 0); if (!filesArray) return JSValueMakeUndefined(context); JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length"); Vector<UChar> files; int filesCount = JSValueToNumber(context, JSObjectGetProperty(context, filesArray, lengthProperty, 0), 0); for (int i = 0; i < filesCount; ++i) { JSValueRef value = JSObjectGetPropertyAtIndex(context, filesArray, i, 0); JSStringRef file = JSValueToStringCopy(context, value, 0); files.append(JSStringGetCharactersPtr(file), JSStringGetLength(file)); files.append(0); JSStringRelease(file); } if (files.isEmpty()) return JSValueMakeUndefined(context); // We should append "0" in the end of |files| so that |DragQueryFileW| retrieved the number of files correctly from Ole Clipboard. files.append(0); STGMEDIUM hDropMedium = {0}; hDropMedium.tymed = TYMED_HGLOBAL; SIZE_T dropFilesSize = sizeof(DROPFILES) + (sizeof(WCHAR) * files.size()); hDropMedium.hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, dropFilesSize); DROPFILES* dropFiles = reinterpret_cast<DROPFILES*>(GlobalLock(hDropMedium.hGlobal)); memset(dropFiles, 0, sizeof(DROPFILES)); dropFiles->pFiles = sizeof(DROPFILES); dropFiles->fWide = TRUE; UChar* data = reinterpret_cast<UChar*>(reinterpret_cast<BYTE*>(dropFiles) + sizeof(DROPFILES)); for (size_t i = 0; i < files.size(); ++i) data[i] = files[i]; GlobalUnlock(hDropMedium.hGlobal); STGMEDIUM hFileNameMedium = {0}; hFileNameMedium.tymed = TYMED_HGLOBAL; SIZE_T hFileNameSize = sizeof(WCHAR) * files.size(); hFileNameMedium.hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, hFileNameSize); WCHAR* hFileName = static_cast<WCHAR*>(GlobalLock(hFileNameMedium.hGlobal)); for (size_t i = 0; i < files.size(); i++) hFileName[i] = files[i]; GlobalUnlock(hFileNameMedium.hGlobal); if (draggingInfo) { delete draggingInfo; draggingInfo = 0; } COMPtr<DRTDataObject> dataObeject; COMPtr<IDropSource> source; if (FAILED(DRTDataObject::createInstance(&dataObeject))) dataObeject = 0; if (FAILED(DRTDropSource::createInstance(&source))) source = 0; if (dataObeject && source) { draggingInfo = new DraggingInfo(dataObeject.get(), source.get()); draggingInfo->setPerformedDropEffect(DROPEFFECT_COPY); } if (draggingInfo) { draggingInfo->dataObject()->SetData(cfHDropFormat(), &hDropMedium, FALSE); draggingInfo->dataObject()->SetData(cfFileNameWFormat(), &hFileNameMedium, FALSE); draggingInfo->dataObject()->SetData(cfUrlWFormat(), &hFileNameMedium, FALSE); OleSetClipboard(draggingInfo->dataObject()); down = true; } JSStringRelease(lengthProperty); return JSValueMakeUndefined(context); }
bool DragData::containsFiles() const { return (m_platformDragData) ? SUCCEEDED(m_platformDragData->QueryGetData(cfHDropFormat())) : m_dragDataMap.contains(cfHDropFormat()->cfFormat); }
bool DragData::containsFiles() const { return SUCCEEDED(m_platformDragData->QueryGetData(cfHDropFormat())); }