void QWindowsClipboard::setMimeData(QMimeData *mimeData, QClipboard::Mode mode) { if (QWindowsContext::verboseOLE) qDebug() << __FUNCTION__ << mode << *mimeData; if (mode != QClipboard::Clipboard) return; const bool newData = !m_data || m_data->mimeData() != mimeData; if (newData) { releaseIData(); if (mimeData) m_data = new QWindowsOleDataObject(mimeData); } const HRESULT src = OleSetClipboard(m_data); if (src != S_OK) { QString mimeDataFormats = mimeData ? mimeData->formats().join(QStringLiteral(", ")) : QString(QStringLiteral("NULL")); qErrnoWarning("OleSetClipboard: Failed to set mime data (%s) on clipboard: %s", qPrintable(mimeDataFormats), QWindowsContext::comErrorString(src).constData()); releaseIData(); return; } }
void QClipboard::setMimeData(QMimeData *src, Mode mode) { if (mode != Clipboard) { delete src; return; } QClipboardData *d = clipboardData(); if (!(d->iData && d->iData->mimeData() == src)) { d->releaseIData(); d->iData = new QOleDataObject(src); } if (OleSetClipboard(d->iData) != S_OK) { d->releaseIData(); qErrnoWarning("QClipboard::setMimeData: Failed to set data on clipboard"); return; } #if defined(Q_OS_WINCE) // As WinCE does not support notifications we send the signal here // We will get no event when the clipboard changes outside... emit dataChanged(); emit changed(Clipboard); #endif }
IDataObject* SetClipboard(CLIPFORMAT format, HGLOBAL data) { DataObject* object = new DataObject(format, data); uint32 result = OleSetClipboard(object); object->Release(); return SUCCEEDED(result) ? object : NULL; }
void wxClipboard::Clear() { #if wxUSE_OLE_CLIPBOARD HRESULT hr = OleSetClipboard(NULL); if ( FAILED(hr) ) { wxLogApiError(wxT("OleSetClipboard(NULL)"), hr); } #endif // wxUSE_OLE_CLIPBOARD }
/************************************************************************** * DoCopyOrCut * * copies the currently selected items into the clipboard */ static void DoCopyOrCut(ContextMenu *This, HWND hwnd, BOOL cut) { IDataObject *dataobject; TRACE("(%p)->(wnd=%p, cut=%d)\n", This, hwnd, cut); if (SUCCEEDED(IShellFolder_GetUIObjectOf(This->parent, hwnd, This->cidl, (LPCITEMIDLIST*)This->apidl, &IID_IDataObject, 0, (void**)&dataobject))) { OleSetClipboard(dataobject); IDataObject_Release(dataobject); } }
void QClipboard::clear(Mode mode) { if (mode != Clipboard) return; QClipboardData *d = clipboardData(); d->releaseIData(); if (OleSetClipboard(0) != S_OK) { qErrnoWarning("QClipboard::clear: Failed to clear data on clipboard"); return; } }
//+------------------------------------------------------------------------- // // Member: FormSetClipboard(IDataObject *pdo) // // Synopsis: helper function to set the clipboard contents // //-------------------------------------------------------------------------- HRESULT FormSetClipboard(IDataObject* pdo) { HRESULT hr; hr = OleSetClipboard(pdo); if(!hr && !GetPrimaryObjectCount()) { hr = OleFlushClipboard(); } else { TLS(pDataClip) = pdo; } RRETURN(hr); }
void QClipboard::setMimeData(QMimeData *src, Mode mode) { if (mode != Clipboard) return; QClipboardData *d = clipboardData(); if (!(d->iData && d->iData->mimeData() == src)) { d->releaseIData(); d->iData = new QOleDataObject(src); } if (OleSetClipboard(d->iData) != S_OK) { d->releaseIData(); qErrnoWarning("QClipboard::setMimeData: Failed to set data on clipboard"); return; } }
void wxClipboard::Clear() { #if wxUSE_OLE_CLIPBOARD if (m_lastDataObject) { // don't touch data set by other applications HRESULT hr = OleIsCurrentClipboard(m_lastDataObject); if (S_OK == hr) { hr = OleSetClipboard(NULL); if ( FAILED(hr) ) { wxLogApiError(wxT("OleSetClipboard(NULL)"), hr); } } m_lastDataObject = NULL; } #endif // wxUSE_OLE_CLIPBOARD }
void QClipboard::clear(Mode mode) { if (mode != Clipboard) return; QClipboardData *d = clipboardData(); d->releaseIData(); if (OleSetClipboard(0) != S_OK) { qErrnoWarning("QClipboard::clear: Failed to clear data on clipboard"); return; } #if defined(Q_OS_WINCE) // As WinCE does not support notifications we send the signal here // We will get no event when the clipboard changes outside... emit dataChanged(); emit changed(Clipboard); #endif }
/************************************************************************** * DoCopyOrCut * * copies the currently selected items into the clipboard */ static BOOL DoCopyOrCut(ItemCmImpl *This, HWND hwnd, BOOL bCut) { LPSHELLBROWSER lpSB; LPSHELLVIEW lpSV; LPDATAOBJECT lpDo; TRACE("(%p)->(wnd=%p,bCut=0x%08x)\n",This, hwnd, bCut); /* get the active IShellView */ if ((lpSB = (LPSHELLBROWSER)SendMessageA(hwnd, CWM_GETISHELLBROWSER,0,0))) { if (SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV))) { if (SUCCEEDED(IShellView_GetItemObject(lpSV, SVGIO_SELECTION, &IID_IDataObject, (LPVOID*)&lpDo))) { OleSetClipboard(lpDo); IDataObject_Release(lpDo); } IShellView_Release(lpSV); } } return TRUE; }
bool wxClipboard::AddData( wxDataObject *data ) { wxCHECK_MSG( data, false, wxT("data is invalid") ); #if wxUSE_OLE_CLIPBOARD HRESULT hr = OleSetClipboard(data->GetInterface()); if ( FAILED(hr) ) { wxLogSysError(hr, _("Failed to put data on the clipboard")); // don't free anything in this case return false; } // we have a problem here because we should delete wxDataObject, but we // can't do it because IDataObject which we just gave to the clipboard // would try to use it when it will need the data. IDataObject is ref // counted and so doesn't suffer from such problem, so we release it now // and tell it to delete wxDataObject when it is deleted itself. data->SetAutoDelete(); // we have to call either OleSetClipboard(NULL) or OleFlushClipboard() when // using OLE clipboard when the app terminates - by default, we call // OleSetClipboard(NULL) which won't waste RAM, but the app can call // wxClipboard::Flush() to chaneg this m_clearOnExit = true; return true; #elif wxUSE_DATAOBJ wxCHECK_MSG( wxIsClipboardOpened(), false, wxT("clipboard not open") ); wxDataFormat format = data->GetPreferredFormat(); switch ( format ) { case wxDF_TEXT: case wxDF_OEMTEXT: { wxTextDataObject* textDataObject = (wxTextDataObject*) data; wxString str(textDataObject->GetText()); return wxSetClipboardData(format, str.c_str()); } case wxDF_BITMAP: case wxDF_DIB: { wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data; wxBitmap bitmap(bitmapDataObject->GetBitmap()); return wxSetClipboardData(data->GetPreferredFormat(), &bitmap); } #if wxUSE_METAFILE case wxDF_METAFILE: { #if 1 // TODO wxLogError(wxT("Not implemented because wxMetafileDataObject does not contain width and height values.")); return false; #else wxMetafileDataObject* metaFileDataObject = (wxMetafileDataObject*) data; wxMetafile metaFile = metaFileDataObject->GetMetafile(); return wxSetClipboardData(wxDF_METAFILE, &metaFile, metaFileDataObject->GetWidth(), metaFileDataObject->GetHeight()); #endif } #endif // wxUSE_METAFILE default: { // This didn't compile, of course // return wxSetClipboardData(data); // TODO wxLogError(wxT("Not implemented.")); return false; } } #else // !wxUSE_DATAOBJ return false; #endif // wxUSE_DATAOBJ/!wxUSE_DATAOBJ }
void QWindowsClipboard::clear() { const HRESULT src = OleSetClipboard(0); if (src != S_OK) qErrnoWarning("OleSetClipboard: Failed to clear the clipboard: 0x%lx", src); }
static LRESULT CALLBACK cliprdr_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { static cliprdrContext *cliprdr = NULL; switch (Msg) { case WM_CREATE: cliprdr = (cliprdrContext *)((CREATESTRUCT *)lParam)->lpCreateParams; cliprdr->hwndNextViewer = SetClipboardViewer(hWnd); if (cliprdr->hwndNextViewer == NULL && GetLastError() != 0) { DEBUG_CLIPRDR("error: SetClipboardViewer failed with 0x%0x.", GetLastError()); } cliprdr->hwndClipboard = hWnd; break; case WM_CLOSE: ChangeClipboardChain(hWnd, cliprdr->hwndNextViewer); break; case WM_CHANGECBCHAIN: if (cliprdr->hwndNextViewer == (HWND)wParam) { cliprdr->hwndNextViewer = (HWND)lParam; } else if (cliprdr->hwndNextViewer != NULL) { SendMessage(cliprdr->hwndNextViewer, Msg, wParam, lParam); } break; case WM_DRAWCLIPBOARD: if (cliprdr->channel_initialized) { if ((GetClipboardOwner() != cliprdr->hwndClipboard) && (S_FALSE == OleIsCurrentClipboard(cliprdr->data_obj))) { if (!cliprdr->hmem) { cliprdr->hmem = GlobalFree(cliprdr->hmem); } cliprdr_send_format_list(cliprdr); } } if (cliprdr->hwndNextViewer != NULL && cliprdr->hwndNextViewer != hWnd) SendMessage(cliprdr->hwndNextViewer, Msg, wParam, lParam); break; case WM_RENDERALLFORMATS: /* discard all contexts in clipboard */ if (!OpenClipboard(cliprdr->hwndClipboard)) { DEBUG_CLIPRDR("OpenClipboard failed with 0x%x", GetLastError()); break; } EmptyClipboard(); CloseClipboard(); break; case WM_RENDERFORMAT: if (cliprdr_send_data_request(cliprdr, (UINT32)wParam) != 0) { DEBUG_CLIPRDR("error: cliprdr_send_data_request failed."); break; } if (SetClipboardData((UINT) wParam, cliprdr->hmem) == NULL) { DEBUG_CLIPRDR("SetClipboardData failed with 0x%x", GetLastError()); cliprdr->hmem = GlobalFree(cliprdr->hmem); } /* Note: GlobalFree() is not needed when success */ break; case WM_CLIPRDR_MESSAGE: switch (wParam) { case OLE_SETCLIPBOARD: if (wf_create_file_obj(cliprdr, &cliprdr->data_obj)) if (OleSetClipboard(cliprdr->data_obj) != S_OK) wf_destroy_file_obj(cliprdr->data_obj); break; default: break; } break; case WM_CLIPBOARDUPDATE: case WM_DESTROYCLIPBOARD: case WM_ASKCBFORMATNAME: case WM_HSCROLLCLIPBOARD: case WM_PAINTCLIPBOARD: case WM_SIZECLIPBOARD: case WM_VSCROLLCLIPBOARD: default: return DefWindowProc(hWnd, Msg, wParam, lParam); } return 0; }
LRESULT C_Edit::OnDrop(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { try { IDataObject* pdto = *reinterpret_cast<IDataObject**>(lParam); if (pdto) { HRESULT hres = E_FAIL; FORMATETC fmte = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; STGMEDIUM medium; int files = 0; if (pdto && SUCCEEDED (pdto->GetData(&fmte, &medium))) { //char szFileDropped [MAX_PATH]; files = DragQueryFile((HDROP)medium.hGlobal, 0xFFFFFFFF, NULL, 0); } OleSetClipboard(pdto); OleFlushClipboard(); C_ClipboardPtr clipboard; clipboard.Create(); if (clipboard) { if (0 == files) { clipboard->Load(CF_TEXT); short s = -1; clipboard->get_Type(&s); switch (s) { case CF_OEMTEXT: case CF_TEXT: BSTR bs = NULL; clipboard->get_Text(&bs); String s(bs); String::FreeBSTR(&bs); int len = s.GetLength(); SetFocus(); TCHAR t[1024]; SendMessage(WM_GETTEXT, 1023, reinterpret_cast<LPARAM>(t)); String old(t); POINT p = { reinterpret_cast<POINT*>(wParam)->x, reinterpret_cast<POINT*>(wParam)->y }; ScreenToClient(&p); int selpos = LOWORD(SendMessage(EM_CHARFROMPOS, 0, MAKELPARAM(p.x, p.y))); if (selpos >= 0 && selpos < old.GetLength()) { s = old.Left(selpos) + s + old.Right(old.GetLength() - selpos); } if (selpos < m_dwSelEnd) { m_dwSelStart += len; m_dwSelEnd += len; } SendMessage(WM_SETTEXT, 0, reinterpret_cast<LPARAM>(s.toLPCTSTR())); SendMessage(EM_SETSEL, selpos, selpos + len); } } } } OnDragLeave(uMsg, wParam, lParam, bHandled); } catch (C_STLNonStackException const &exception) { exception.Log(_T("Exception in C_Edit::OnCanDrop")); } return S_OK; }
HRESULT CSimpleDataObjectImpl::SetClipboard() { RETURNIFFAILED(OleSetClipboard(this)); RETURNIFFAILED(OleFlushClipboard()); return S_OK; }
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); }
static LRESULT CALLBACK cliprdr_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { static wfClipboard* clipboard = NULL; switch (Msg) { case WM_CREATE: DEBUG_CLIPRDR("info: WM_CREATE"); clipboard = (wfClipboard*)((CREATESTRUCT*) lParam)->lpCreateParams; if (!AddClipboardFormatListener(hWnd)) { DEBUG_CLIPRDR("error: AddClipboardFormatListener failed with %#x.", GetLastError()); } clipboard->hwnd = hWnd; break; case WM_CLOSE: DEBUG_CLIPRDR("info: WM_CLOSE"); RemoveClipboardFormatListener(hWnd); break; case WM_CLIPBOARDUPDATE: DEBUG_CLIPRDR("info: WM_CLIPBOARDUPDATE"); if (clipboard->sync) { if ((GetClipboardOwner() != clipboard->hwnd) && (S_FALSE == OleIsCurrentClipboard(clipboard->data_obj))) { if (clipboard->hmem) { GlobalFree(clipboard->hmem); clipboard->hmem = NULL; } cliprdr_send_format_list(clipboard); } } break; case WM_RENDERALLFORMATS: DEBUG_CLIPRDR("info: WM_RENDERALLFORMATS"); /* discard all contexts in clipboard */ if (!OpenClipboard(clipboard->hwnd)) { DEBUG_CLIPRDR("OpenClipboard failed with 0x%x", GetLastError()); break; } EmptyClipboard(); CloseClipboard(); break; case WM_RENDERFORMAT: DEBUG_CLIPRDR("info: WM_RENDERFORMAT"); if (cliprdr_send_data_request(clipboard, (UINT32) wParam) != 0) { DEBUG_CLIPRDR("error: cliprdr_send_data_request failed."); break; } if (!SetClipboardData((UINT) wParam, clipboard->hmem)) { DEBUG_CLIPRDR("SetClipboardData failed with 0x%x", GetLastError()); if (clipboard->hmem) { GlobalFree(clipboard->hmem); clipboard->hmem = NULL; } } /* Note: GlobalFree() is not needed when success */ break; case WM_CLIPRDR_MESSAGE: DEBUG_CLIPRDR("info: WM_CLIPRDR_MESSAGE"); switch (wParam) { case OLE_SETCLIPBOARD: DEBUG_CLIPRDR("info: OLE_SETCLIPBOARD"); if (wf_create_file_obj(clipboard, &clipboard->data_obj)) { if (OleSetClipboard(clipboard->data_obj) != S_OK) { wf_destroy_file_obj(clipboard->data_obj); clipboard->data_obj = NULL; } } break; default: break; } break; case WM_DESTROYCLIPBOARD: case WM_ASKCBFORMATNAME: case WM_HSCROLLCLIPBOARD: case WM_PAINTCLIPBOARD: case WM_SIZECLIPBOARD: case WM_VSCROLLCLIPBOARD: default: return DefWindowProc(hWnd, Msg, wParam, lParam); } return 0; }