📄 document.cpp
字号:
pIStorage=m_pIStorage;
m_pIStorage->AddRef(); //Matches Release below
}
}
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);
Rename(pszFile); //Update caption bar.
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);
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);
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;
OLEUIPASTEENTRY rgPaste[4];
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;
ps.cPasteEntries=4;
//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;
SETDefFormatEtc(rgPaste[1].fmtetc,CF_METAFILEPICT,TYMED_MFPICT);
rgPaste[1].lpstrFormatName=PSZ(IDS_PASTEMETAFILE);
rgPaste[1].lpstrResultText=PSZ(IDS_PASTEASMETAFILE);
rgPaste[1].dwFlags=OLEUIPASTE_PASTEONLY;
SETDefFormatEtc(rgPaste[2].fmtetc, CF_DIB, TYMED_HGLOBAL);
rgPaste[2].lpstrFormatName=PSZ(IDS_PASTEDIB);
rgPaste[2].lpstrResultText=PSZ(IDS_PASTEASDIB);
rgPaste[2].dwFlags=OLEUIPASTE_PASTEONLY;
SETDefFormatEtc(rgPaste[3].fmtetc, CF_BITMAP, TYMED_GDI);
rgPaste[3].lpstrFormatName=PSZ(IDS_PASTEBITMAP);
rgPaste[3].lpstrResultText=PSZ(IDS_PASTEASBITMAP);
rgPaste[3].dwFlags=OLEUIPASTE_PASTEONLY;
uTemp=OleUIPasteSpecial(&ps);
if (OLEUI_OK==uTemp)
{
fRet=PasteFromData(ps.lpSrcDataObj
, &rgPaste[ps.nSelectedIndex].fmtetc
, TENANTTYPE_STATIC, NULL, 0L);
}
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;
if (NULL!=(LPVOID)ptType)
*ptType=TENANTTYPE_STATIC;
//Any of our specific data here?
SETDefFormatEtc(fe, m_cf, TYMED_HGLOBAL);
hr=pIDataObject->QueryGetData(&fe);
if (NOERROR!=hr)
{
//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
*
* Return Value:
* BOOL TRUE if successful, FALSE otherwise.
*/
BOOL CPatronDoc::PasteFromData(LPDATAOBJECT pIDataObject
, LPFORMATETC pFE, TENANTTYPE tType, PPATRONOBJECT ppo
, DWORD dwData)
{
BOOL fRet;
HRESULT hr;
PATRONOBJECT po;
STGMEDIUM stm;
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;
GlobalUnlock(stm.hGlobal);
ReleaseStgMedium(&stm);
}
}
fRet=m_pPG->TenantCreate(tType, pIDataObject, pFE, ppo, dwData);
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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -