📄 document.cpp
字号:
po=*ppo;
ppo=&po;
//If there's an object here, make sure type is right.
if (ppo->fe.cfFormat==m_cfEmbeddedObject)
tType=TENANTTYPE_EMBEDDEDOBJECTFROMDATA;
if (ppo->fe.cfFormat==m_cfLinkSource)
tType=TENANTTYPE_LINKEDOBJECTFROMDATA;
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)
{
SETDefFormatEtc(fe, m_cfObjectDescriptor, TYMED_HGLOBAL);
hr=pIDataObject->GetData(&fe, &stm);
if (FAILED(hr))
{
SETDefFormatEtc(fe, m_cfLinkSrcDescriptor
, TYMED_HGLOBAL);
hr=pIDataObject->GetData(&fe, &stm);
}
if (SUCCEEDED(hr))
{
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;
}
}
}
fRet=m_pPG->TenantCreate(tType, pIDataObject, pFE, ppo, dwData);
//Release the stm from the last GetData
if (fRelease)
ReleaseStgMedium(&stm);
if (fRet)
{
//Disable Printer Setup once we've created a tenant.
m_fPrintSetup=FALSE;
FDirtySet(TRUE);
}
return fRet;
}
/*
* CPatronDoc::FQueryEnableEditLinks
*
* Purpose:
* Determines whether or not the Edit Links menu item should be
* enabled on the frame window menu.
*
* Parameters:
* None
*
* Return Value:
* BOOL TRUE to enable the item, FALSE otherwise.
*/
BOOL CPatronDoc::FQueryEnableEditLinks(void)
{
return m_pPG->FQueryLinksInPage();
}
/*
* CPatronDoc::EditLinks
*
* Purpose:
* Invokes the links dialog in which the end-user can manipulate
* all the links in the current page.
*
* Parameters:
* hWndFrame HWND of the frame window to use as the dialog
* parent.
*
* Return Value:
* BOOL TRUE if the function was successful,
* FALSE otherwise.
*/
BOOL CPatronDoc::EditLinks(HWND hWndFrame)
{
UINT uRet;
OLEUIEDITLINKS el;
PCIOleUILinkContainer pIUILinks;
memset(&el, 0, sizeof(el));
el.cbStruct=sizeof(el);
el.hWndOwner=hWndFrame;
if (!m_pPG->GetUILinkContainer(&pIUILinks))
return FALSE;
el.lpOleUILinkContainer=pIUILinks;
uRet=OleUIEditLinks(&el);
//Only the IOleUILinkContainer interface will know dirtying.
m_fDirty=pIUILinks->m_fDirty;
el.lpOleUILinkContainer->Release();
return TRUE;
}
/*
* CPatronDoc::ShowOrQueryObjectTypes
*
* Purpose:
* If querying, we return whether or not ShowObjects is active
* in this document. Otherwise pass-through to
* CPages::ShowObjectTypes.
*
* Parameters:
* fQuery BOOL indicating query or set.
* fShow BOOL indicating to show the type or not.
*
* Return Value:
* None
*/
BOOL CPatronDoc::ShowOrQueryObjectTypes(BOOL fQuery, BOOL fShow)
{
if (fQuery)
return m_fShowTypes;
m_fShowTypes=fShow;
m_pPG->ShowObjectTypes(fShow);
return TRUE;
}
/*
* 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);
}
/*
* 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)
{
LPMONIKER pmk;
//We don't need to change the base class, just augment...
CDocument::Rename(pszFile);
//Unregister the old moniker (m_dwRegROT set to zero).
INOLE_RevokeAsRunning(&m_dwRegROT);
if (NULL==pszFile)
return;
CreateFileMoniker(pszFile, &pmk);
if (NULL!=pmk)
{
LPMONIKER pmkAll;
INOLE_RegisterAsRunning(this, pmk, 0, &m_dwRegROT);
//Give a moniker to linked objects in tenants.
m_pPG->NotifyTenantsOfRename(pszFile, pmk);
//Register a File!"\" wildcard moniker as well
CreateItemMoniker(TEXT("!"), TEXT("\\"), &pmkAll);
if (NULL!=pmkAll)
{
LPMONIKER pmkWild;
INOLE_RevokeAsRunning(&m_dwRegROTWild);
pmk->ComposeWith(pmkAll, FALSE, &pmkWild);
if (NULL!=pmkWild)
{
INOLE_RegisterAsRunning(this, pmk, 0
, &m_dwRegROTWild);
pmkWild->Release();
}
pmkAll->Release();
}
//No need for us to hold on to this.
pmk->Release();
}
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;
//We now support linking, so remove the IOF_DISABLELINK flag.
io.dwFlags=IOF_SELECTCREATENEW;
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
{
if (io.dwFlags & IOF_CHECKLINK)
tType=TENANTTYPE_LINKEDFILE;
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.
* pMSG LPMSG that caused the activation.
*
* Return Value:
* None
*/
//CHAPTER22MOD
void CPatronDoc::ActivateObject(LONG iVerb, LPMSG pMSG)
{
m_pPG->ActivateObject(iVerb, pMSG);
return;
}
//End CHAPTER22MOD
/*
* 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);
}
//CHAPTER22MOD
/*
* CPatronDoc::NoObjectFrameTools
*
* Purpose:
* Saves/retrieves a flag with the document that says whether or
* not the object active in this document has *frame* tools. We
* need this to tell the frame what to do when document activation
* switches.
*
* Parameters:
* fNoTools BOOL TRUE to indicate the object has no tools.
* FALSE says the object has tools.
* fSet BOOL indicating if this is a set (TRUE) or get
* (FALSE) operation.
*
* Return Value:
* BOOL Value of flag for Get operations, previous value
* for Set operations.
*/
BOOL CPatronDoc::NoObjectFrameTools(BOOL fNoTools, BOOL fSet)
{
BOOL fLast=m_fNoObjectFrameTools;
if (fSet)
m_fNoObjectFrameTools=fNoTools;
return fLast;
}
//End CHAPTER22MOD
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -