?? document.cpp
字號:
if (FAILED(hr))
return DOCERR_WRITEFAILURE;
//If successful, the Commit below finishes the save.
pIStorage=m_pIStorage;
m_pIStorage->AddRef(); //Matches Release below
}
}
Rename(pszFile); //Update caption bar.
pIStorage->Commit(STGC_DEFAULT);
/*
* Revert changes on the original storage. If this was a temp
* file, it's deleted since we used STGM_DELETEONRELEASE.
*/
m_pIStorage->Release();
//Make this new storage current
m_pIStorage=pIStorage;
m_pPG->StorageSet(pIStorage, TRUE, FALSE);
FDirtySet(FALSE);
return DOCERR_NONE;
}
/*
* CPatronDoc::Clip
*
* Purpose:
* Places a private format, a metafile, and a bitmap of the display
* on the clipboard, optionally implementing Cut by deleting the
* data in the current window after rendering.
*
* Parameters:
* hWndFrame HWND of the main window.
* fCut BOOL indicating cut (TRUE) or copy (FALSE).
*
* Return Value:
* BOOL TRUE if successful, FALSE otherwise.
*/
BOOL CPatronDoc::Clip(HWND hWndFrame, BOOL fCut)
{
if (NULL==m_pPG)
return FALSE;
return m_pPG->TenantClip(fCut);
}
/*
* CPatronDoc::Paste
*
* Purpose:
* Retrieves the private data format from the clipboard and sets it
* to the current figure in the editor window.
*
* Note that if this function is called, then the clipboard format
* is available because the Paste menu item is only enabled if the
* format is present.
*
* Parameters:
* hWndFrame HWND of the main window.
*
* Return Value:
* BOOL TRUE if successful, FALSE otherwise.
*/
BOOL CPatronDoc::Paste(HWND hWndFrame)
{
LPDATAOBJECT pIDataObject;
BOOL fRet=FALSE;
FORMATETC fe;
TENANTTYPE tType;
if (NULL==m_pPG)
return FALSE;
if (FAILED(OleGetClipboard(&pIDataObject)))
return FALSE;
//Go get type and format we *can* paste, then actually paste it.
if (FQueryPasteFromData(pIDataObject, &fe, &tType))
{
fRet=PasteFromData(pIDataObject, &fe, tType, NULL
, 0L, TRUE);
}
pIDataObject->Release();
return fRet;
}
/*
* CPatronDoc::FQueryPaste
*
* Purpose:
* Determines if we can paste data from the clipboard.
*
* Parameters:
* None
*
* Return Value:
* BOOL TRUE if data is available, FALSE otherwise.
*/
BOOL CPatronDoc::FQueryPaste(void)
{
LPDATAOBJECT pIDataObject;
BOOL fRet;
if (FAILED(OleGetClipboard(&pIDataObject)))
return FALSE;
fRet=FQueryPasteFromData(pIDataObject, NULL, NULL);
//CHAPTER20MOD
fRet |= FQueryPasteLinkFromData(pIDataObject, NULL, NULL);
//End CHAPTER20MOD
pIDataObject->Release();
return fRet;
}
/*
* CPatronDoc::PasteSpecial
*
* Purpose:
* Retrieves a specific data format from the clipboard and sends
* it to the editor window appropriately.
*
* Note that if this function is called, then the appropriate
* format is available because the Paste menu item is only
* enabled if the format is present.
*
* Parameters:
* hWndFrame HWND of the main window
*
* Return Value:
* BOOL TRUE if successful, FALSE otherwise.
*/
BOOL CPatronDoc::PasteSpecial(HWND hWndFrame)
{
OLEUIPASTESPECIAL ps;
//CHAPTER20MOD
OLEUIPASTEENTRY rgPaste[6];
UINT rgcf[1]; //For ps.m_arrLinkTypes
//End CHAPTER20MOD
DWORD dwData=0;
UINT uTemp;
BOOL fRet=FALSE;
if (NULL==m_pPG)
return FALSE;
memset(&ps, 0, sizeof(ps));
if (FAILED(OleGetClipboard(&ps.lpSrcDataObj)))
return FALSE;
ps.cbStruct=sizeof(ps);
ps.hWndOwner=hWndFrame;
ps.dwFlags=PSF_SELECTPASTE;
ps.arrPasteEntries=rgPaste;
//Set up Paste Special descriptor arrays.
SETDefFormatEtc(rgPaste[0].fmtetc, m_cf, TYMED_HGLOBAL);
rgPaste[0].lpstrFormatName=PSZ(IDS_CLIPBOARDFORMAT);
rgPaste[0].lpstrResultText=PSZ(IDS_PASTEASPATRON);
rgPaste[0].dwFlags=OLEUIPASTE_PASTEONLY;
//Embedded objects can be iconic displays if the user wants.
SETDefFormatEtc(rgPaste[1].fmtetc, m_cfEmbeddedObject
, TYMED_ISTORAGE);
rgPaste[1].lpstrFormatName=PSZ(IDS_PASTEOBJECT);
rgPaste[1].lpstrResultText=PSZ(IDS_PASTEASOBJECT);
/*
* CAUTION: Use OLEUI_PASTE with embedded objects or else
* this item will not show up in the dialog. I learned this the
* hard way (that is, after about 6 hours of pulling hair!).
*/
rgPaste[1].dwFlags=OLEUIPASTE_PASTE | OLEUIPASTE_ENABLEICON;
SETDefFormatEtc(rgPaste[2].fmtetc,CF_METAFILEPICT,TYMED_MFPICT);
rgPaste[2].lpstrFormatName=PSZ(IDS_PASTEMETAFILE);
rgPaste[2].lpstrResultText=PSZ(IDS_PASTEASMETAFILE);
rgPaste[2].dwFlags=OLEUIPASTE_PASTEONLY;
SETDefFormatEtc(rgPaste[3].fmtetc, CF_DIB, TYMED_HGLOBAL);
rgPaste[3].lpstrFormatName=PSZ(IDS_PASTEDIB);
rgPaste[3].lpstrResultText=PSZ(IDS_PASTEASDIB);
rgPaste[3].dwFlags=OLEUIPASTE_PASTEONLY;
SETDefFormatEtc(rgPaste[4].fmtetc, CF_BITMAP, TYMED_GDI);
rgPaste[4].lpstrFormatName=PSZ(IDS_PASTEBITMAP);
rgPaste[4].lpstrResultText=PSZ(IDS_PASTEASBITMAP);
rgPaste[4].dwFlags=OLEUIPASTE_PASTEONLY;
//CHAPTER20MOD
SETDefFormatEtc(rgPaste[5].fmtetc,m_cfLinkSource,TYMED_ISTREAM);
rgPaste[5].lpstrFormatName=PSZ(IDS_PASTELINK);
rgPaste[5].lpstrResultText=PSZ(IDS_PASTEASLINK);
rgPaste[5].dwFlags=OLEUIPASTE_LINKTYPE1 | OLEUIPASTE_ENABLEICON;
//Types we can Paste Link from the clipboard.
rgcf[0]=m_cfLinkSource;
ps.arrLinkTypes=rgcf;
ps.cLinkTypes=1;
ps.cPasteEntries=6;
//End CHAPTER20MOD
uTemp=OleUIPasteSpecial(&ps);
if (OLEUI_OK==uTemp)
{
UINT i=ps.nSelectedIndex;
TENANTTYPE tType;
//CHAPTER20MOD
if (ps.fLink)
tType=TENANTTYPE_LINKEDOBJECTFROMDATA;
else
{
if (1==ps.nSelectedIndex)
tType=TENANTTYPE_EMBEDDEDOBJECTFROMDATA;
else
tType=TENANTTYPE_STATIC;
}
//End CHAPTER20MOD
//CHAPTER20MOD
//Handle iconic aspects...from links as well
if ((1==i || ps.fLink) && (PSF_CHECKDISPLAYASICON
& ps.dwFlags) && NULL!=ps.hMetaPict)
//End CHAPTER20MOD
{
rgPaste[i].fmtetc.dwAspect=DVASPECT_ICON;
dwData=(DWORD)(UINT)ps.hMetaPict;
}
fRet=PasteFromData(ps.lpSrcDataObj, &rgPaste[i].fmtetc
, tType, NULL, dwData, FALSE);
//Always free this regardless of what we do with it.
INOLE_MetafilePictIconFree(ps.hMetaPict);
}
ps.lpSrcDataObj->Release();
return fRet;
}
/*
* CPatronDoc::FQueryPasteFromData
* (Protected)
*
* Purpose:
* Determines if we can paste data from a data object.
*
* Parameters:
* pIDataObject LPDATAOBJECT from which we might want to paste.
* pFE LPFORMATETC in which to return the first format
* we can use. Ignored if NULL.
* ptType PTENANTTYPE in which to store the type of
* object we can paste. Ignored if NULL.
*
* Return Value:
* BOOL TRUE if data is available, FALSE otherwise.
*/
BOOL CPatronDoc::FQueryPasteFromData(LPDATAOBJECT pIDataObject
, LPFORMATETC pFE, PTENANTTYPE ptType)
{
FORMATETC fe;
HRESULT hr, hr2;
if (NULL!=(LPVOID)ptType)
*ptType=TENANTTYPE_STATIC;
//Any of our specific data here?
SETDefFormatEtc(fe, m_cf, TYMED_HGLOBAL);
hr=pIDataObject->QueryGetData(&fe);
//If embedded object data is available, set the appropriate type
hr2=OleQueryCreateFromData(pIDataObject);
if (NOERROR==hr2)
{
if (NULL!=pFE)
{
/*
* Default to content. Paste will use
* CFSTR_OBJECTDESCRIPTOR to figure the actual aspect.
*/
SETDefFormatEtc(*pFE, m_cfEmbeddedObject
, TYMED_ISTORAGE);
}
if (NULL!=(LPVOID)ptType)
*ptType=TENANTTYPE_EMBEDDEDOBJECTFROMDATA;
/*
* Return now if PatronObject wasn't available, otherwise
* break out so that pFE gets PatronObject format.
*/
if (NOERROR!=hr)
return TRUE;
}
if (NOERROR!=hr && NOERROR!=hr2)
{
//Try metafile, DIB, then bitmap, setting fe each time
SETDefFormatEtc(fe, CF_METAFILEPICT, TYMED_MFPICT);
hr=pIDataObject->QueryGetData(&fe);
if (NOERROR!=hr)
{
SETDefFormatEtc(fe, CF_DIB, TYMED_HGLOBAL);
hr=pIDataObject->QueryGetData(&fe);
if (NOERROR!=hr)
{
SETDefFormatEtc(fe, CF_BITMAP, TYMED_GDI);
hr=pIDataObject->QueryGetData(&fe);
}
}
}
if (NOERROR==hr && NULL!=pFE)
*pFE=fe;
return (NOERROR==hr);
}
//CHAPTER20MOD
/*
* CPatronDoc::FQueryPasteLinkFromData
* (Protected)
*
* Purpose:
* Determines if we can paste link from a data object.
*
* Parameters:
* pIDataObject LPDATAOBJECT from which we might want to paste.
* pFE LPFORMATETC in which to return the first format
* we can use. Ignored if NULL.
* ptType PTENANTTYPE in which to store the type of object
* we can paste. Ignored if NULL.
*
* Return Value:
* BOOL TRUE if data is available, FALSE otherwise.
*/
BOOL CPatronDoc::FQueryPasteLinkFromData(LPDATAOBJECT pIDataObject
, LPFORMATETC pFE, PTENANTTYPE ptType)
{
HRESULT hr;
if (NULL==pIDataObject)
return FALSE;
hr=OleQueryLinkFromData(pIDataObject);
if (NOERROR!=hr)
return FALSE;
if (NULL!=pFE)
SETDefFormatEtc(*pFE, m_cfLinkSource, TYMED_ISTREAM);
if (NULL!=(LPVOID)ptType)
*ptType=TENANTTYPE_LINKEDOBJECTFROMDATA;
return TRUE;
}
//End CHAPTER20MOD
/*
* CPatronDoc::PasteFromData
* (Protected)
*
* Purpose:
* Retrieves the private data format from a data object and sets
* it to the current figure in the editor window.
*
* Parameters:
* pIDataObject LPDATAOBJECT from which to paste.
* pFE LPFORMATETC to use in the paste. Cannot be NULL.
* tType TENANTTYPE to paste.
* ppo PPATRONOBJECT containing placement data.
* dwData DWORD extra data sensitive to tType
* fUseObjDesc BOOL indicating to use CFSTR_OBJECTDESCRIPTOR
* format for determining the aspect of the object
* if the format is available.
*
* Return Value:
* BOOL TRUE if successful, FALSE otherwise.
*/
BOOL CPatronDoc::PasteFromData(LPDATAOBJECT pIDataObject
, LPFORMATETC pFE, TENANTTYPE tType, PPATRONOBJECT ppo
, DWORD dwData, BOOL fUseObjDesc)
{
BOOL fRet;
HRESULT hr;
PATRONOBJECT po;
STGMEDIUM stm;
LPOBJECTDESCRIPTOR pOD;
FORMATETC fe;
BOOL fRelease=FALSE;
if (NULL==pFE)
return FALSE;
//If not given any placement data, see if we can retrieve it
if (pFE->cfFormat==m_cf && NULL==ppo)
{
hr=pIDataObject->GetData(pFE, &stm);
if (SUCCEEDED(hr))
{
ppo=(PPATRONOBJECT)GlobalLock(stm.hGlobal);
po=*ppo;
ppo=&po;
//If there's an object here, make sure type is right.
if (ppo->fe.cfFormat==m_cfEmbeddedObject)
tType=TENANTTYPE_EMBEDDEDOBJECTFROMDATA;
//CHAPTER20MOD
if (ppo->fe.cfFormat==m_cfLinkSource)
tType=TENANTTYPE_LINKEDOBJECTFROMDATA;
//End CHAPTER20MOD
GlobalUnlock(stm.hGlobal);
ReleaseStgMedium(&stm);
}
}
/*
* If we're told to look at CFSTR_OBJECTDESCRIPTOR, then try to get
* the data and copy the aspect out of it. We're not interested
* in any other part of it, however.
*/
if (fUseObjDesc)
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -