Esempio n. 1
0
BOOL PASCAL COleClientItem::CanPasteLink()
{
    if (afxData.bWin31)
    {
        // We must use OleQueryLinkFromData on Win32s
        BOOL bCanPasteLink = FALSE;
        LPDATAOBJECT lpDataObject;
        if (::OleGetClipboard(&lpDataObject) == S_OK)
        {
            ASSERT(lpDataObject != NULL);
            SCODE sc = GetScode(::OleQueryLinkFromData(lpDataObject));
            bCanPasteLink = !FAILED(sc) && sc != S_FALSE;
            lpDataObject->Release();
        }
        return bCanPasteLink;
    }
    else
    {
        // it is faster and more reliable to use the Windows clipboard
        //  APIs instead of OleQueryCreateFromData.
        return IsClipboardFormatAvailable(_oleData.cfLinkSource) ||
               IsClipboardFormatAvailable(_oleData.cfFileName) ||
               IsClipboardFormatAvailable(_oleData.cfFileNameW) ||
               IsClipboardFormatAvailable(_oleData.cfObjectLink);
    }
}
Esempio n. 2
0
BOOL PASCAL COleClientItem::CanPaste()
{
    if (afxData.bWin31)
    {
        // We must use OleQueryCreateFromData on Win32s
        BOOL bCanPaste = FALSE;
        LPDATAOBJECT lpDataObject;
        if (::OleGetClipboard(&lpDataObject) == S_OK)
        {
            ASSERT(lpDataObject != NULL);
            SCODE sc = GetScode(::OleQueryCreateFromData(lpDataObject));
            bCanPaste = !FAILED(sc) && sc != S_FALSE;
            lpDataObject->Release();
        }
        return bCanPaste;
    }
    else
    {
        // it is faster and more reliable to use the Windows clipboard
        //  APIs instead of OleQueryCreateFromData.
        return IsClipboardFormatAvailable(_oleData.cfEmbedSource) ||
               IsClipboardFormatAvailable(_oleData.cfEmbeddedObject) ||
               IsClipboardFormatAvailable(_oleData.cfFileName) ||
               IsClipboardFormatAvailable(_oleData.cfFileNameW) ||
               IsClipboardFormatAvailable(CF_METAFILEPICT) ||
               IsClipboardFormatAvailable(CF_DIB) ||
               IsClipboardFormatAvailable(CF_BITMAP) ||
               (IsClipboardFormatAvailable(_oleData.cfOwnerLink) &&
                IsClipboardFormatAvailable(_oleData.cfNative));
    }
}
Esempio n. 3
0
BOOL AFXAPI _AfxLoadObjectFromStreamedPropset(LPUNKNOWN lpUnknown, LPSTREAM lpStream)
{
	ASSERT_POINTER(lpUnknown, IUnknown);
	ASSERT_POINTER(lpStream, IStream);

	BOOL bSuccess = FALSE;
	LPDATAOBJECT pDataObj = NULL;

	if (SUCCEEDED(lpUnknown->QueryInterface(IID_IDataObject,
			(LPVOID*)&pDataObj)))
	{
		ASSERT_POINTER(pDataObj, IDataObject);

		// Set the persistent propset format on the object.

		FORMATETC formatEtc;
		STGMEDIUM stgMedium;
		formatEtc.cfFormat = _AfxGetClipboardFormatPersistPropset();
		formatEtc.ptd = NULL;
		formatEtc.dwAspect = DVASPECT_CONTENT;
		formatEtc.lindex = -1;
		formatEtc.tymed = TYMED_ISTREAM;

		stgMedium.tymed = TYMED_ISTREAM;
		stgMedium.pstm = lpStream;
		stgMedium.pUnkForRelease = NULL;

		bSuccess = SUCCEEDED(pDataObj->SetData(&formatEtc, &stgMedium, FALSE));

		pDataObj->Release();
	}

	return bSuccess;
}
Esempio n. 4
0
void UDropTarget::FreeData()
{
    if(data) {
        data->Release();
        data = NULL;
    }
}
Esempio n. 5
0
	void CImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap)
	{
		SCODE sc;

		// Get the image data object
		//
		CImageDataObject *pods = new CImageDataObject;
		LPDATAOBJECT lpDataObject;
		pods->QueryInterface(IID_IDataObject, (void **)&lpDataObject);

		pods->SetBitmap(hBitmap);

		// Get the RichEdit container site
		//
		IOleClientSite *pOleClientSite;	
		pRichEditOle->GetClientSite(&pOleClientSite);

		// Initialize a Storage Object
		//
		IStorage *pStorage;	

		LPLOCKBYTES lpLockBytes = NULL;
		sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);
		if (sc != S_OK)
			AfxThrowOleException(sc);
		ASSERT(lpLockBytes != NULL);
		
		sc = ::StgCreateDocfileOnILockBytes(lpLockBytes,
			STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &pStorage);
		if (sc != S_OK)
		{
			VERIFY(lpLockBytes->Release() == 0);
			lpLockBytes = NULL;
			AfxThrowOleException(sc);
		}
		ASSERT(pStorage != NULL);

		// The final ole object which will be inserted in the richedit control
		//
		IOleObject *pOleObject; 
		pOleObject = pods->GetOleObject(pOleClientSite, pStorage);
		if(!pOleObject)
			AfxThrowOleException(sc);

		// all items are "contained" -- this makes our reference to this object
		//  weak -- which is needed for links to embedding silent update.
		OleSetContainedObject(pOleObject, TRUE);

		// Now Add the object to the RichEdit 
		//
		REOBJECT reobject;
		ZeroMemory(&reobject, sizeof(REOBJECT));
		reobject.cbStruct = sizeof(REOBJECT);
		
		CLSID clsid;
		sc = pOleObject->GetUserClassID(&clsid);
		if (sc != S_OK)
			AfxThrowOleException(sc);

		reobject.clsid = clsid;
		reobject.cp = REO_CP_SELECTION;
		reobject.dvaspect = DVASPECT_CONTENT;
		reobject.poleobj = pOleObject;
		reobject.polesite = pOleClientSite;
		reobject.pstg = pStorage;

		// Insert the bitmap at the current location in the richedit control
		//
		pRichEditOle->InsertObject(&reobject);

		// Release all unnecessary interfaces
		//
		pOleObject->Release();
		pOleClientSite->Release();
		pStorage->Release();
		lpDataObject->Release();
	}
Esempio n. 6
0
BOOL AFXAPI _AfxSaveObjectInPropset(LPUNKNOWN pUnk, CPropertySection& psec,
	DWORD dwPropID)
{
	if (pUnk == NULL)
		return FALSE;

	ASSERT_POINTER(pUnk, IUnknown);

	BOOL bSuccess = FALSE;
	LPDATAOBJECT pDataObj;

	if (SUCCEEDED(pUnk->QueryInterface(IID_IDataObject,
			(LPVOID*)&pDataObj)))
	{
		// Get the persistent propset format from object.

		FORMATETC formatEtc;
		STGMEDIUM stgMedium;
		formatEtc.cfFormat = _AfxGetClipboardFormatPersistPropset();
		formatEtc.ptd = NULL;
		formatEtc.dwAspect = DVASPECT_CONTENT;
		formatEtc.lindex = -1;
		formatEtc.tymed = TYMED_ISTREAM;

		stgMedium.tymed = TYMED_NULL;
		stgMedium.pUnkForRelease = NULL;

		if (SUCCEEDED(pDataObj->GetData(&formatEtc, &stgMedium)))
		{
			if (stgMedium.tymed == TYMED_ISTREAM)
			{
				LPSTREAM pstm = stgMedium.pstm;

				// Seek to start of stream.
				if (SUCCEEDED(pstm->Seek(_afxLargeZero, STREAM_SEEK_SET, NULL)))
				{
					// Create a "blobbed" propset from the stream
					bSuccess = _AfxSaveStreamDataAsBlobProp(stgMedium.pstm,
						psec, dwPropID, VT_BLOB_PROPSET);
				}
			}

			// Cleanup
			ReleaseStgMedium(&stgMedium);
		}

		pDataObj->Release();
	}

	LPPERSISTSTREAM pPersStm = NULL;

	if ((!bSuccess) &&
		SUCCEEDED(pUnk->QueryInterface(IID_IPersistStream,
			(LPVOID*)&pPersStm)))
	{
		// Get the object to save itself into a stream, then store that
		// streamed data as a blob.

		ASSERT_POINTER(pPersStm, IPersistStream);
		LPSTREAM pstm = _AfxCreateMemoryStream();
		if (pstm != NULL)
		{
			if (SUCCEEDED(::OleSaveToStream(pPersStm, pstm)) &&
				SUCCEEDED(pstm->Seek(_afxLargeZero, STREAM_SEEK_SET, NULL)))
			{
				bSuccess = _AfxSaveStreamDataAsBlobProp(pstm, psec,
					dwPropID, VT_BLOB);
			}

			pstm->Release();
		}

		pPersStm->Release();
	}

	return bSuccess;
}
Esempio n. 7
0
BOOL CMSOffice2007DemoView::InsertBitmap(UINT uiBmpResID)
{
	CWaitCursor wait;

	CBitmap bmp;
	if (!bmp.LoadBitmap(uiBmpResID))
	{
		return FALSE;
	}

	std::auto_ptr<COleDataSource> apDataSrc(new COleDataSource);
	std::auto_ptr<COleDataObject> apData(new COleDataObject);

	TRY
	{
		STGMEDIUM stgm;
		stgm.hGlobal = bmp.GetSafeHandle();
		stgm.tymed = TYMED_GDI;
		stgm.pUnkForRelease = NULL;

		apDataSrc->CacheData(CF_BITMAP, &stgm);

		LPDATAOBJECT lpdata;

		if (FAILED(apDataSrc->m_xDataObject.QueryInterface(IID_IDataObject,
			(LPVOID FAR*) &lpdata)))
		{
			AfxThrowUserException();
		}

		apData->Attach(lpdata);
		lpdata->Release();

		CMSOffice2007DemoDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);

		std::auto_ptr<CMSOffice2007DemoCntrItem> apItem(new CMSOffice2007DemoCntrItem(NULL, pDoc));
		ASSERT_VALID(apItem.get());

		if (!apItem->CreateStaticFromData(apData.release()))
		{
			AfxThrowUserException();
		}

		apItem->m_uiCategoryID = uiBmpResID;
		InsertItem(apItem.release());

		pDoc->UpdateAllViews(this);
	}
	CATCH(CException, e)
	{
		return FALSE;
	}
	END_CATCH

	CMainFrame* pMainFrame = ((CMainFrame*) GetTopLevelFrame());
	ASSERT_VALID(pMainFrame);

	pMainFrame->ActivateRibbonContextCategory(uiBmpResID);

	return TRUE;
}