📄 document.cpp
字号:
* 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;
//CHAPTER17MOD
OLEUIPASTEENTRY rgPaste[5];
DWORD dwData=0;
//End CHAPTER17MOD
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;
//CHAPTER17MOD
ps.cPasteEntries=5;
//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;
uTemp=OleUIPasteSpecial(&ps);
if (OLEUI_OK==uTemp)
{
UINT i=ps.nSelectedIndex;
TENANTTYPE tType;
if (1==ps.nSelectedIndex)
tType=TENANTTYPE_EMBEDDEDOBJECTFROMDATA;
else
tType=TENANTTYPE_STATIC;
//Handle iconic aspects...
if ((1==i) && (PSF_CHECKDISPLAYASICON & ps.dwFlags)
&& NULL!=ps.hMetaPict)
{
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);
}
//End CHAPTER17MOD
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;
//CHAPTER17MOD
HRESULT hr, hr2;
//End CHAPTER17MOD
if (NULL!=(LPVOID)ptType)
*ptType=TENANTTYPE_STATIC;
//Any of our specific data here?
SETDefFormatEtc(fe, m_cf, TYMED_HGLOBAL);
hr=pIDataObject->QueryGetData(&fe);
//CHAPTER17MOD
//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)
//End CHAPTER17MOD
{
//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);
}
/*
* 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.
*/
//CHAPTER17MOD
BOOL CPatronDoc::PasteFromData(LPDATAOBJECT pIDataObject
, LPFORMATETC pFE, TENANTTYPE tType, PPATRONOBJECT ppo
, DWORD dwData, BOOL fUseObjDesc)
//End CHAPTER17MOD
{
BOOL fRet;
HRESULT hr;
PATRONOBJECT po;
STGMEDIUM stm;
//CHAPTER17MOD
LPOBJECTDESCRIPTOR pOD;
FORMATETC fe;
BOOL fRelease=FALSE;
//End CHAPTER17MOD
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;
//CHAPTER17MOD
//If there's an object here, make sure type is right.
if (ppo->fe.cfFormat==m_cfEmbeddedObject)
tType=TENANTTYPE_EMBEDDEDOBJECTFROMDATA;
//End CHAPTER17MOD
GlobalUnlock(stm.hGlobal);
ReleaseStgMedium(&stm);
}
}
//CHAPTER17MOD
/*
* 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)
{
SETDefFormatEtc(fe, m_cfObjectDescriptor, TYMED_HGLOBAL);
if (SUCCEEDED(pIDataObject->GetData(&fe, &stm)))
{
pOD=(LPOBJECTDESCRIPTOR)GlobalLock(stm.hGlobal);
pFE->dwAspect=pOD->dwDrawAspect;
if (NULL!=ppo)
ppo->fe.dwAspect=pFE->dwAspect;
GlobalUnlock(stm.hGlobal);
ReleaseStgMedium(&stm);
/*
* Furthermore, if pFE->dwAspect is DVASPECT_ICON, get
* the metafile which will always be the icon
* representation.
*/
SETFormatEtc(fe, CF_METAFILEPICT, DVASPECT_ICON, NULL
, TYMED_MFPICT, -1);
if (SUCCEEDED(pIDataObject->GetData(&fe, &stm)))
{
dwData=(DWORD)(UINT)stm.hGlobal;
fRelease=TRUE;
}
}
}
//End CHAPTER17MOD
fRet=m_pPG->TenantCreate(tType, pIDataObject, pFE, ppo, dwData);
//CHAPTER17MOD
//Release the stm from the last GetData
if (fRelease)
ReleaseStgMedium(&stm);
//End CHAPTER17MOD
if (fRet)
{
//Disable Printer Setup once we've created a tenant.
m_fPrintSetup=FALSE;
FDirtySet(TRUE);
}
return fRet;
}
/*
* CPatronDoc::NewPage
*
* Purpose:
* Creates a new page in the document's pages control after the
* current page.
*
* Parameters:
* None
*
* Return Value:
* UINT Index of the new page.
*/
UINT CPatronDoc::NewPage(void)
{
FDirtySet(TRUE);
return m_pPG->PageInsert(0);
}
/*
* CPatronDoc::DeletePage
*
* Purpose:
* Deletes the current page from the document.
*
* Parameters:
* None
*
* Return Value:
* UINT Index of the now current page.
*/
UINT CPatronDoc::DeletePage(void)
{
FDirtySet(TRUE);
return m_pPG->PageDelete(0);
}
/*
* CPatronDoc::NextPage
*
* Purpose:
* Shows the next page in the pages window.
*
* Parameters:
* None
*
* Return Value:
* UINT Index of the new page.
*/
UINT CPatronDoc::NextPage(void)
{
UINT iPage;
iPage=m_pPG->CurPageGet();
return m_pPG->CurPageSet(++iPage);
}
/*
* CPatronDoc::PreviousPage
*
* Purpose:
* Shows the previous page in the pages window.
*
* Parameters:
* None
*
* Return Value:
* UINT Index of the new page.
*/
UINT CPatronDoc::PreviousPage(void)
{
UINT iPage;
//If iPage is zero, then we wrap around to the end.
iPage=m_pPG->CurPageGet();
return m_pPG->CurPageSet(--iPage);
}
/*
* CPatronDoc::FirstPage
*
* Purpose:
* Shows the first page page in the pages window.
*
* Parameters:
* None
*
* Return Value:
* UINT Index of the new page.
*/
UINT CPatronDoc::FirstPage(void)
{
return m_pPG->CurPageSet(0);
}
/*
* CPatronDoc::LastPage
*
* Purpose:
* Shows the last page in the pages window.
*
* Parameters:
* None
*
* Return Value:
* UINT Index of the last page.
*/
UINT CPatronDoc::LastPage(void)
{
return m_pPG->CurPageSet(NOVALUE);
}
//CHAPTER17MOD
/*
* CPatronDoc::Rename
*
* Purpose:
* Overrides the normal rename to include notification of tenants
* in this document of the new name. This is so embedded objects
* are told the correct name through IOleObject::SetHostNames.
*
* Parameters:
* pszFile LPTSTR to the new filename.
*
* Return Value:
* None
*/
void CPatronDoc::Rename(LPTSTR pszFile)
{
//We don't need to change the base class, just augment...
CDocument::Rename(pszFile);
m_pPG->NotifyTenantsOfRename(pszFile, NULL);
return;
}
/*
* CPatronDoc::InsertObject
*
* Purpose:
* Retrieves a CLSID or a filename from the Insert Object dialog
* box and creates an object using those identifiers.
*
* Parameters:
* hWndFrame HWND of the main window
*
* Return Value:
* BOOL TRUE if successful, FALSE otherwise.
*/
BOOL CPatronDoc::InsertObject(HWND hWndFrame)
{
OLEUIINSERTOBJECT io;
DWORD dwData=0;
TCHAR szFile[CCHPATHMAX];
UINT uTemp;
BOOL fRet=FALSE;
if (NULL==m_pPG)
return FALSE;
memset(&io, 0, sizeof(io));
io.cbStruct=sizeof(io);
io.hWndOwner=hWndFrame;
szFile[0]=0;
io.lpszFile=szFile;
io.cchFile=CCHPATHMAX;
io.dwFlags=IOF_SELECTCREATENEW | IOF_DISABLELINK;
uTemp=OleUIInsertObject(&io);
if (OLEUI_OK==uTemp)
{
TENANTTYPE tType;
LPVOID pv;
FORMATETC fe;
SETDefFormatEtc(fe, 0, TYMED_NULL);
if (io.dwFlags & IOF_SELECTCREATENEW)
{
tType=TENANTTYPE_EMBEDDEDOBJECT;
pv=&io.clsid;
}
else
{
tType=TENANTTYPE_EMBEDDEDFILE;
pv=szFile;
}
if ((io.dwFlags & IOF_CHECKDISPLAYASICON)
&& NULL!=io.hMetaPict)
{
fe.dwAspect=DVASPECT_ICON;
dwData=(DWORD)(UINT)io.hMetaPict;
}
fRet=m_pPG->TenantCreate(tType, pv, &fe, NULL, dwData);
//Free this regardless of what we do with it.
INOLE_MetafilePictIconFree(io.hMetaPict);
if (fRet)
{
//Disable Printer Setup once we've created a tenant.
m_fPrintSetup=FALSE;
FDirtySet(TRUE);
}
}
return fRet;
}
/*
* CPatronDoc::ActivateObject
*
* Purpose:
* Executes a verb on the currently selected object.
*
* Parameters:
* iVerb LONG of the selected verb.
*
* Return Value:
* None
*/
void CPatronDoc::ActivateObject(LONG iVerb)
{
m_pPG->ActivateObject(iVerb);
return;
}
/*
* CPatronDoc::ConvertObject
*
* Purpose:
* Invokes the Convert dialog on the current object. Here it's
* just a pass-through to the pages.
*
* Parameters:
* hWndFrame HWND of the frame window.
*
* Return Value:
* BOOL TRUE if the function is successful, FALSE otherwise.
*/
BOOL CPatronDoc::ConvertObject(HWND hWndFrame)
{
return m_pPG->ConvertObject(hWndFrame);
}
//End CHAPTER17MOD
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -