void COleClientItem::SetLinkUpdateOptions(OLEUPDATE dwUpdateOpt) { ASSERT_VALID(this); ASSERT(m_lpObject != NULL); LPOLELINK lpOleLink = QUERYINTERFACE(m_lpObject, IOleLink); ASSERT(lpOleLink != NULL); // perhaps not a link? SCODE sc = lpOleLink->SetUpdateOptions(dwUpdateOpt); lpOleLink->Release(); CheckGeneral(sc); }
OLEUPDATE COleClientItem::GetLinkUpdateOptions() { ASSERT_VALID(this); ASSERT(m_lpObject != NULL); LPOLELINK lpOleLink = QUERYINTERFACE(m_lpObject, IOleLink); ASSERT(lpOleLink != NULL); // perhaps not a link? DWORD dwUpdateOpt; SCODE sc = lpOleLink->GetUpdateOptions(&dwUpdateOpt); lpOleLink->Release(); CheckGeneral(sc); // may throw an exception return (OLEUPDATE)dwUpdateOpt; }
STDMETHODIMP COleUILinkInfo::GetLinkSource( DWORD dwLink, LPTSTR* lplpszDisplayName, ULONG* lplenFileName, LPTSTR* lplpszFullLinkType, LPTSTR* lplpszShortLinkType, BOOL* lpfSourceAvailable, BOOL* lpfIsSelected) { COleClientItem* pItem = (COleClientItem*)dwLink; ASSERT_VALID(pItem); ASSERT_KINDOF(COleClientItem, pItem); ASSERT(pItem->GetType() == OT_LINK); // set OUT params to NULL ASSERT(lplpszDisplayName != NULL); *lplpszDisplayName = NULL; if (lplpszFullLinkType != NULL) *lplpszFullLinkType = NULL; if (lplpszShortLinkType != NULL) *lplpszShortLinkType = NULL; if (lplenFileName != NULL) *lplenFileName = 0; if (lpfSourceAvailable != NULL) *lpfSourceAvailable = !pItem->m_bLinkUnavail; // get IOleLink interface LPOLELINK lpOleLink = QUERYINTERFACE(pItem->m_lpObject, IOleLink); ASSERT(lpOleLink != NULL); // get moniker & object information LPMONIKER lpmk; if (lpOleLink->GetSourceMoniker(&lpmk) == S_OK) { if (lplenFileName != NULL) *lplenFileName = _AfxOleGetLenFilePrefixOfMoniker(lpmk); lpmk->Release(); } // attempt to get the type names of the link if (lplpszFullLinkType != NULL) { LPOLESTR lpOleStr = NULL; pItem->m_lpObject->GetUserType(USERCLASSTYPE_FULL, &lpOleStr); *lplpszFullLinkType = TASKSTRINGOLE2T(lpOleStr); if (*lplpszFullLinkType == NULL) { TCHAR szUnknown[256]; VERIFY(AfxLoadString(AFX_IDS_UNKNOWNTYPE, szUnknown) != 0); *lplpszFullLinkType = AfxAllocTaskString(szUnknown); } } if (lplpszShortLinkType != NULL) { LPOLESTR lpOleStr = NULL; pItem->m_lpObject->GetUserType(USERCLASSTYPE_SHORT, &lpOleStr); *lplpszShortLinkType = TASKSTRINGOLE2T(lpOleStr); if (*lplpszShortLinkType == NULL) { TCHAR szUnknown[256]; VERIFY(AfxLoadString(AFX_IDS_UNKNOWNTYPE, szUnknown) != 0); *lplpszShortLinkType = AfxAllocTaskString(szUnknown); } } // get source display name for moniker LPOLESTR lpOleStr = NULL; SCODE sc = lpOleLink->GetSourceDisplayName(&lpOleStr); *lplpszDisplayName = TASKSTRINGOLE2T(lpOleStr); lpOleLink->Release(); if (sc != S_OK) return sc; // see if item is selected if specified if (lpfIsSelected) { *lpfIsSelected = (m_pSelectedItem == pItem); } return S_OK; }
STDMETHODIMP COleUILinkInfo::SetLinkSource( DWORD dwLink, LPTSTR lpszDisplayName, ULONG lenFileName, ULONG* pchEaten, BOOL fValidateSource) { USES_CONVERSION; COleClientItem* pItem = (COleClientItem*)dwLink; ASSERT_VALID(pItem); ASSERT_KINDOF(COleClientItem, pItem); ASSERT(pItem->GetType() == OT_LINK); LPOLEOBJECT lpObject = NULL; CLSID clsid; // parse the portion known to be a file name into a file moniker TCHAR szName[_MAX_PATH]; lstrcpyn(szName, lpszDisplayName, (int)lenFileName + 1); LPMONIKER lpmk = NULL; SCODE sc = CreateFileMoniker(T2COLE(szName), &lpmk); if (lpmk == NULL) return sc; LPBC lpbc = NULL; if (fValidateSource) { sc = CreateBindCtx(0, &lpbc); if (sc != S_OK) { lpmk->Release(); return sc; } } // nUneaten is the number of chars left to parse UINT nUneaten = lstrlen(lpszDisplayName) - lenFileName; // lpszRemainder is the left over display name LPTSTR lpszRemainder = lpszDisplayName + lenFileName; *pchEaten = lenFileName; // parse the rest of the display name while (nUneaten > 0) { // attempt to parse next moniker ULONG nEaten = 0; LPMONIKER lpmkNext = NULL; sc = _AfxParseDisplayName(lpmk, lpbc, lpszRemainder, &nEaten, &lpmkNext); if (sc != S_OK) { lpmk->Release(); lpbc->Release(); return sc; } // advance through the display name nUneaten -= nEaten; *pchEaten += nEaten; lpszRemainder += nEaten; if (lpmkNext != NULL) { // create composite out of current and next LPMONIKER lpmkTemp = NULL; sc = CreateGenericComposite(lpmk, lpmkNext, &lpmkTemp); if (FAILED(sc)) { lpmk->Release(); lpmkNext->Release(); lpbc->Release(); return sc; } // make current = next lpmkNext->Release(); lpmk->Release(); lpmk = lpmkTemp; } } if (fValidateSource) { // attempt to bind the the object sc = lpmk->BindToObject(lpbc, NULL, IID_IOleObject, (LPLP)&lpObject); if (FAILED(sc)) { pItem->m_bLinkUnavail = TRUE; lpbc->Release(); lpmk->Release(); RELEASE(lpObject); return sc; } ASSERT(lpObject != NULL); // call GetUserClassID while bound so default handler updates lpObject->GetUserClassID(&clsid); pItem->m_bLinkUnavail = FALSE; } // get IOleLink interface LPOLELINK lpOleLink = QUERYINTERFACE(pItem->m_lpObject, IOleLink); ASSERT(lpOleLink != NULL); // set source from moniker sc = lpOleLink->SetSourceMoniker(lpmk, clsid); // update the cache if object was successfully bound if (lpObject != NULL) { lpObject->Update(); lpObject->Release(); } // cleanup lpOleLink->Release(); RELEASE(lpmk); RELEASE(lpbc); return sc; }
STDMETHODIMP COlePropertiesDialog::XOleUIObjInfo::GetObjectInfo( DWORD dwObject, DWORD* lpdwObjSize, LPTSTR* lplpszLabel, LPTSTR* lplpszType, LPTSTR* lplpszShortType, LPTSTR* lplpszLocation) { COleClientItem* pItem = (COleClientItem*)dwObject; ASSERT_VALID(pItem); BOOL bIsLink = (pItem->GetType() == OT_LINK); if (lpdwObjSize != NULL) { ASSERT(pItem->m_lpStorage != NULL); // try ILockBytes first, then IStorage STATSTG statStg; if ((pItem->m_lpLockBytes == NULL || pItem->m_lpLockBytes->Stat(&statStg, STATFLAG_NONAME) != S_OK) && pItem->m_lpStorage->Stat(&statStg, STATFLAG_NONAME) != S_OK) { *lpdwObjSize = 0xFFFFFFFF; } else { ASSERT(statStg.pwcsName == NULL); if (statStg.cbSize.HighPart > 0) *lpdwObjSize = 0xFFFFFFFE; else if (statStg.cbSize.LowPart == 0) *lpdwObjSize = 0xFFFFFFFF; else *lpdwObjSize = statStg.cbSize.LowPart; } } if (lplpszLabel != NULL) { TCHAR szFormatLink[128]; AfxLoadString(AFX_IDS_PASTELINKEDTYPE, szFormatLink, _countof(szFormatLink)); TCHAR szFormatObj[] = _T("%s"); LPTSTR lpszFormat = bIsLink ? szFormatLink : szFormatObj; CString strType; pItem->GetUserType(USERCLASSTYPE_FULL, strType); CString strResult; strResult.Format(lpszFormat, (LPCTSTR)strType); *lplpszLabel = AfxAllocTaskString(strResult); } if (lplpszType != NULL) { LPOLESTR lpOleStr; pItem->m_lpObject->GetUserType(USERCLASSTYPE_FULL, &lpOleStr); *lplpszType = TASKSTRINGOLE2T(lpOleStr); } if (lplpszShortType != NULL) { LPOLESTR lpOleStr; pItem->m_lpObject->GetUserType(USERCLASSTYPE_SHORT, &lpOleStr); *lplpszShortType = TASKSTRINGOLE2T(lpOleStr); } if (lplpszLocation != NULL) { if (bIsLink) { LPOLELINK lpOleLink = NULL; pItem->m_lpObject->QueryInterface(IID_IOleLink, (LPVOID*)&lpOleLink); ASSERT(lpOleLink != NULL); LPOLESTR lpOleStr; lpOleLink->GetSourceDisplayName(&lpOleStr); *lplpszLocation = TASKSTRINGOLE2T(lpOleStr); lpOleLink->Release(); } else { CDocument* pDoc = (CDocument*)pItem->GetDocument(); CString strLocation = pDoc->GetPathName(); if (strLocation.IsEmpty()) strLocation = pDoc->GetTitle(); *lplpszLocation = AfxAllocTaskString(strLocation); } } return S_OK; }
HGLOBAL AFXAPI _AfxOleGetObjectDescriptorData( LPOLEOBJECT lpOleObj, LPCOLESTR lpszSrcOfCopy, DWORD dwDrawAspect, POINTL pointl, LPSIZEL lpSizelHim) { USES_CONVERSION; CLSID clsid; LPOLESTR lpszFullUserTypeName = NULL; LPMONIKER lpSrcMonikerOfCopy = NULL; HGLOBAL hObjDesc = NULL; IBindCtx *pbc = NULL; SCODE sc; SIZEL sizelHim; BOOL bFreeSrcOfCopy = FALSE; LPVIEWOBJECT2 lpViewObj2; LPOLELINK lpOleLink; BOOL fIsLink; TCHAR szLinkedTypeFmt[80]; LPCOLESTR lpszLinkedTypeFmt; LPOLESTR lpszBuf = NULL; DWORD dwStatus = 0; // query for IOleLink lpOleLink = QUERYINTERFACE(lpOleObj, IOleLink); fIsLink = lpOleLink != NULL; // query for IViewObject2 lpViewObj2 = QUERYINTERFACE(lpOleObj, IViewObject2); // Get CLSID sc = lpOleObj->GetUserClassID(&clsid); if (sc != S_OK) clsid = CLSID_NULL; // Get FullUserTypeName sc = lpOleObj->GetUserType(USERCLASSTYPE_FULL, &lpszFullUserTypeName); // if object is a link, then expand usertypename to be "Linked %s" if (fIsLink && lpszFullUserTypeName != NULL) { // Note: If this LoadString call fails, it is likely that // _AFX_NO_OLE_RESOURCES is defined in your .RC file. // To correct the situation remove the following line from your // resource script: // #define _AFX_NO_OLE_RESOURCES // This should be done using the Resource.Set Includes... command. VERIFY(AfxLoadString(AFX_IDS_PASTELINKEDTYPE, szLinkedTypeFmt)); lpszLinkedTypeFmt = T2COLE(szLinkedTypeFmt); lpszBuf = (LPOLESTR)CoTaskMemAlloc((ocslen(lpszFullUserTypeName) + ocslen(lpszLinkedTypeFmt) + 1) * sizeof(OLECHAR)); if (lpszBuf != NULL) { #ifdef OLE2ANSI sprintf(lpszBuf, lpszLinkedTypeFmt, lpszFullUserTypeName); #else swprintf(lpszBuf, lpszLinkedTypeFmt, lpszFullUserTypeName); #endif CoTaskMemFree(lpszFullUserTypeName); lpszFullUserTypeName = lpszBuf; } } // get source of copy if (fIsLink) { sc = lpOleLink->GetSourceDisplayName((LPOLESTR*)&lpszSrcOfCopy); bFreeSrcOfCopy = TRUE; } else if (lpszSrcOfCopy == NULL) { sc = lpOleObj->GetMoniker( OLEGETMONIKER_TEMPFORUSER, OLEWHICHMK_OBJFULL, &lpSrcMonikerOfCopy); if (sc == S_OK) { CreateBindCtx(0, &pbc); lpSrcMonikerOfCopy->GetDisplayName(pbc, NULL, (LPOLESTR*)&lpszSrcOfCopy); RELEASE(pbc); bFreeSrcOfCopy = TRUE; } } if (lpSizelHim) { // Use extents passed by the caller sizelHim = *lpSizelHim; } else if (lpViewObj2) { // Get the current extents from the object sc = lpViewObj2->GetExtent(dwDrawAspect, -1, NULL, (LPSIZEL)&sizelHim); if (sc != S_OK) sizelHim.cx = sizelHim.cy = 0; } else { sizelHim.cx = sizelHim.cy = 0; } // Get dwStatus sc = lpOleObj->GetMiscStatus(dwDrawAspect, &dwStatus); if (sc != S_OK) dwStatus = 0; // Get OBJECTDESCRIPTOR hObjDesc = _AfxOleGetObjectDescriptorData(clsid, dwDrawAspect, sizelHim, pointl, dwStatus, lpszFullUserTypeName, lpszSrcOfCopy); // Clean up CoTaskMemFree(lpszFullUserTypeName); if (bFreeSrcOfCopy) CoTaskMemFree((LPOLESTR)lpszSrcOfCopy); RELEASE(lpSrcMonikerOfCopy); RELEASE(lpOleLink); RELEASE(lpViewObj2); return hObjDesc; }