📄 dsofauto.cpp
字号:
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::(put_HostName/get_HostName)
//
// String setting used for host application name (used in embedding)
//
STDMETHODIMP CDsoFramerControl::put_HostName(BSTR bstr)
{
TRACE1("CDsoFramerControl::put_HostName(%S)\n", bstr);
SAFE_FREESTRING(m_pwszHostName);
if ((bstr) && (SysStringLen(bstr) > 0))
m_pwszHostName = DsoCopyString(bstr);
return S_OK;
}
STDMETHODIMP CDsoFramerControl::get_HostName(BSTR* pbstr)
{
ODS("CDsoFramerControl::get_HostName\n");
if (pbstr)
*pbstr = SysAllocString((m_pwszHostName ? m_pwszHostName : L"DsoFramerControl"));
return S_OK;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::get_DocumentFullName
//
// Gets FullName of embedded source file (where default save will save to).
//
STDMETHODIMP CDsoFramerControl::get_DocumentFullName(BSTR* pbstr)
{
ODS("CDsoFramerControl::get_DocumentFullName\n");
CHECK_NULL_RETURN(pbstr, E_POINTER);
// Ask doc object site for the source name...
*pbstr = (m_pDocObjFrame) ? SysAllocString(m_pDocObjFrame->GetSourceName()) : NULL;
return S_OK;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::get_DocumentName
//
// Gets just the file name of embedded source file.
//
STDMETHODIMP CDsoFramerControl::get_DocumentName(BSTR* pbstr)
{
ODS("CDsoFramerControl::get_DocumentName\n");
CHECK_NULL_RETURN(pbstr, E_POINTER);
// Ask doc object site for the source doc name...
*pbstr = (m_pDocObjFrame) ? SysAllocString(m_pDocObjFrame->GetSourceDocName()) : NULL;
return S_OK;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::get_IsReadOnly
//
// Returns if file open read-only.
//
STDMETHODIMP CDsoFramerControl::get_IsReadOnly(VARIANT_BOOL* pbool)
{
ODS("CDsoFramerControl::get_IsReadOnly\n");
CHECK_NULL_RETURN(pbool, E_POINTER);
CHECK_NULL_RETURN(m_pDocObjFrame, ProvideErrorInfo(DSO_E_DOCUMENTNOTOPEN));
*pbool = (m_pDocObjFrame->IsReadOnly() ? VARIANT_TRUE : VARIANT_FALSE);
return S_OK;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::get_IsDirty
//
// Returns TRUE if doc object says it has changes.
//
STDMETHODIMP CDsoFramerControl::get_IsDirty(VARIANT_BOOL* pbool)
{
ODS("CDsoFramerControl::get_IsDirty\n");
CHECK_NULL_RETURN(pbool, E_POINTER);
CHECK_NULL_RETURN(m_pDocObjFrame, ProvideErrorInfo(DSO_E_DOCUMENTNOTOPEN));
*pbool = (m_pDocObjFrame->IsDirty() ? VARIANT_TRUE : VARIANT_FALSE);
return S_OK;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::LockServer
//
// Allows host to temporarily lock the current document server running,
// so that when closing and reopening files using the same server doesn't
// suffer startup/shutdown penelty of the server going away between calls.
//
STDMETHODIMP CDsoFramerControl::put_LockServer(VARIANT_BOOL vbool)
{
BOOL fLock = (vbool != VARIANT_FALSE);
TRACE1("CDsoFramerControl::put_LockServer(%d)\n", (DWORD)vbool);
// We must have a server open to set a lock...
if ((fLock) && (m_pDocObjFrame == NULL))
return ProvideErrorInfo(DSO_E_DOCUMENTNOTOPEN);
return SetTempServerLock(fLock);
}
STDMETHODIMP CDsoFramerControl::get_LockServer(VARIANT_BOOL* pvbool)
{
ODS("CDsoFramerControl::get_LockServer\n");
CHECK_NULL_RETURN(pvbool, E_POINTER);
*pvbool = (VARIANT_BOOL)((m_pServerLock) ? VARIANT_TRUE : VARIANT_FALSE);
return S_OK;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::GetDataObjectContent
//
// Allows caller to get data from document in clipboard format but without
// using the clipboard (instead it uses IDataObject). The server has to
// support the request format to return the data. Data is returned as byte array.
//
// NOTE: This only gets the document body content, not the entire document. If
// you want the entire document, use the Save method with temp filename to save to.
//
STDMETHODIMP CDsoFramerControl::GetDataObjectContent(VARIANT ClipFormatNameOrNumber, VARIANT *pvResults)
{
ODS("CDsoFramerControl::GetDataObjectContent()\n");
CHECK_NULL_RETURN(pvResults, E_POINTER); VariantInit(pvResults);
CHECK_NULL_RETURN(m_pDocObjFrame, ProvideErrorInfo(DSO_E_DOCUMENTNOTOPEN));
// If the control is in modal state, we can't do anything...
if ((m_fModalState) || (m_fNoInteractive))
return ProvideErrorInfo(DSO_E_INMODALSTATE);
return m_pDocObjFrame->HrGetDataFromObject(&ClipFormatNameOrNumber, pvResults);
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::GetDataObjectContent
//
// Allows caller to set data into the document body (similar to a paste, but
// without using the clipboard). You must supply the format name or number and
// the data in a byte array format.
//
STDMETHODIMP CDsoFramerControl::SetDataObjectContent(VARIANT ClipFormatNameOrNumber, VARIANT DataByteArray)
{
ODS("CDsoFramerControl::SetDataObjectContent()\n");
CHECK_NULL_RETURN(m_pDocObjFrame, ProvideErrorInfo(DSO_E_DOCUMENTNOTOPEN));
// If the control is in modal state, we can't do anything...
if ((m_fModalState) || (m_fNoInteractive))
return ProvideErrorInfo(DSO_E_INMODALSTATE);
return m_pDocObjFrame->HrSetDataInObject(&ClipFormatNameOrNumber, &DataByteArray, TRUE);
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::put_ActivationPolicy
//
// Allows caller to set policy for how activation changes affect the embedded
// object. This is actually a bit flag, so user can OR settings.
//
STDMETHODIMP CDsoFramerControl::put_ActivationPolicy(dsoActivationPolicy lPolicy)
{
TRACE1("CDsoFramerControl::put_ActivationPolicy(%d)\n", lPolicy);
if (m_pDocObjFrame) return E_ACCESSDENIED;
if ((lPolicy < dsoDefaultBehavior) || (lPolicy > 0x0F))
return E_INVALIDARG;
m_lActivationPolicy = lPolicy;
return S_OK;
}
STDMETHODIMP CDsoFramerControl::get_ActivationPolicy(dsoActivationPolicy *plPolicy)
{if (plPolicy) *plPolicy = (dsoActivationPolicy)m_lActivationPolicy; return S_OK;}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::put_FrameHookPolicy
//
// Allows caller to set policy for the frame hook.
//
STDMETHODIMP CDsoFramerControl::put_FrameHookPolicy(dsoFrameHookPolicy lPolicy)
{
HRESULT hr = E_ACCESSDENIED;
TRACE1("CDsoFramerControl::put_FrameHookPolicy(%d)\n", lPolicy);
switch (lPolicy)
{
case dsoDisableHook:
if (m_pHookManager) break;
// else fallthrough...
case dsoNormalBehavior:
case dsoSetOnFirstOpen:
m_lHookPolicy = lPolicy; hr = S_OK;
break;
case dsoResetNow:
if (!FRunningInDesignMode())
hr = ResetFrameHook(0);
break;
default:
hr = E_INVALIDARG;
}
return hr;
}
STDMETHODIMP CDsoFramerControl::get_FrameHookPolicy(dsoFrameHookPolicy *plPolicy)
{if (plPolicy) *plPolicy = (dsoFrameHookPolicy)m_lHookPolicy; return S_OK;}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::put_MenuAccelerators
//
// Sets flag to determine if control should try to handle keys for menu
// shortcuts when the menus are displayed.
//
STDMETHODIMP CDsoFramerControl::put_MenuAccelerators(VARIANT_BOOL vbool)
{
ODS("CDsoFramerControl::put_MenuAccelerators\n");
m_fDisableMenuAccel = (vbool == VARIANT_FALSE);
return S_OK;
}
STDMETHODIMP CDsoFramerControl::get_MenuAccelerators(VARIANT_BOOL* pvbool)
{
ODS("CDsoFramerControl::get_MenuAccelerators\n");
CHECK_NULL_RETURN(pvbool, E_POINTER);
*pvbool = (m_fDisableMenuAccel ? VARIANT_FALSE : VARIANT_TRUE);
return S_OK;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::put_EventsEnabled
//
// Sets flag to determine if events are frozen or not.
//
STDMETHODIMP CDsoFramerControl::put_EventsEnabled(VARIANT_BOOL vbool)
{
ODS("CDsoFramerControl::put_EventsEnabled\n");
m_fFreezeEvents = (vbool == VARIANT_FALSE);
return S_OK;
}
STDMETHODIMP CDsoFramerControl::get_EventsEnabled(VARIANT_BOOL* pvbool)
{
ODS("CDsoFramerControl::get_EventsEnabled\n");
CHECK_NULL_RETURN(pvbool, E_POINTER);
*pvbool = (m_fFreezeEvents ? VARIANT_FALSE : VARIANT_TRUE);
return S_OK;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl - IDispatch Implementation
//
////////////////////////////////////////////////////////////////////////
// Control's IDispatch Functions
//
// These are largely standard and just forward calls to the functions
// above. The only interesting thing here is the "hack" in Invoke to
// tell VB/IE that the control is always "Enabled".
//
STDMETHODIMP CDsoFramerControl::GetTypeInfoCount(UINT* pctinfo)
{if (pctinfo) *pctinfo = 1; return S_OK;}
STDMETHODIMP CDsoFramerControl::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
{
HRESULT hr = S_OK;
ODS("CDsoFramerControl::GetTypeInfo\n");
CHECK_NULL_RETURN(ppTInfo, E_POINTER); *ppTInfo = NULL;
// We only support default interface late bound...
CHECK_NULL_RETURN((iTInfo == 0), DISP_E_BADINDEX);
// Load the type lib if we don't have the information already.
if (NULL == m_ptiDispType)
{
hr = DsoGetTypeInfoEx(LIBID_DSOFramer, 0, DSOFRAMERCTL_VERSION_MAJOR, DSOFRAMERCTL_VERSION_MINOR,
v_hModule, IID__FramerControl, &m_ptiDispType);
}
// Return interface with ref count (if we have it, otherwise error)...
SAFE_SET_INTERFACE(*ppTInfo, m_ptiDispType);
return hr;
}
STDMETHODIMP CDsoFramerControl::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
{
HRESULT hr;
ITypeInfo *pti;
ODS("CDsoFramerControl::GetIDsOfNames\n");
CHECK_NULL_RETURN((IID_NULL == riid), DISP_E_UNKNOWNINTERFACE);
// Get the type info for this dispinterface...
hr = GetTypeInfo(0, lcid, &pti);
RETURN_ON_FAILURE(hr);
// Ask OLE to translate the name...
hr = pti->GetIDsOfNames(rgszNames, cNames, rgDispId);
pti->Release();
return hr;
}
STDMETHODIMP CDsoFramerControl::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
HRESULT hr;
ITypeInfo *pti;;
// VB loves to check for this property (Enabled) during design time.
// We don't implement it for this control, but we'll return TRUE to
// to let it know if is enabled and don't bother with call to ITypeInfo...
if ((dispIdMember == DISPID_ENABLED) && (wFlags & DISPATCH_PROPERTYGET))
{
if (pVarResult) // We are always enabled...
{pVarResult->vt = VT_BOOL; pVarResult->boolVal = VARIANT_TRUE; }
return S_OK;
}
TRACE1("CDsoFramerControl::Invoke(dispid = %d)\n", dispIdMember);
CHECK_NULL_RETURN((IID_NULL == riid), DISP_E_UNKNOWNINTERFACE);
// Get the type info for this dispinterface...
hr = GetTypeInfo(0, lcid, &pti);
RETURN_ON_FAILURE(hr);
// Store pExcepInfo (to fill-in disp excepinfo if error occurs)...
m_pDispExcep = pExcepInfo;
// Call the method using TypeInfo (OLE will call v-table method for us)...
hr = pti->Invoke((PVOID)this, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
m_pDispExcep = NULL; // Don't need this anymore...
pti->Release();
return hr;
}
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::ProvideErrorInfo
//
// Fills in custom error information (as needed).
//
STDMETHODIMP CDsoFramerControl::ProvideErrorInfo(HRESULT hres)
{
// Don't need to do anything on success...
if ((hres == S_OK) || SUCCEEDED(hres))
return hres;
// Fill in the error information as needed...
return DsoReportError(hres, NULL, m_pDispExcep);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -