⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsofauto.cpp

📁 用于在线office文档编辑的控件。可以在线新建文档、修改文档
💻 CPP
📖 第 1 页 / 共 3 页
字号:
////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::(put_ModalState/get_ModalState)
//
//  True/False. Disables the active object (if any) thereby setting it 
//  up to behave "modal". Any time a dialog or other blocking window 
//  on the same thread is called, the developer should set this to True
//  to let the IP object know it should stay modal in the background. 
//  Set it back to False when the dialog is removed.
//
//  Technically, this should be a counter to allow for nested modal states.
//  However, we thought that might be confusing to some VB/Web developers
//  and since this is only a sample, made it a Boolean property.
//
STDMETHODIMP CDsoFramerControl::put_ModalState(VARIANT_BOOL vbool)
{
	TRACE1("CDsoFramerControl::put_ModalState(%d)\n", vbool);

 // you can't force modal state change unless active...
    if ((m_fNoInteractive) || (!m_fComponentActive))
        return ProvideErrorInfo(E_ACCESSDENIED);

	if (m_fModalState != (WORD)(BOOL)vbool)
		UpdateModalState((vbool != VARIANT_FALSE), TRUE);

	return S_OK;
}

STDMETHODIMP CDsoFramerControl::get_ModalState(VARIANT_BOOL* pbool)
{
	ODS("CDsoFramerControl::get_ModalState\n");
	if (pbool) *pbool = ((m_fModalState) ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}


////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::ShowDialog
//
//  Uses IOleCommandTarget to get the embedded object to display one of
//  these standard dialogs for the user.
//
STDMETHODIMP CDsoFramerControl::ShowDialog(dsoShowDialogType DlgType)
{
	HRESULT hr = E_ACCESSDENIED;

	TRACE1("CDsoFramerControl::ShowDialog(%d)\n", DlgType);
	if ((DlgType < dsoFileNew) || (DlgType > dsoDialogProperties))
		return E_INVALIDARG;

 // Cannot access object if in modal condition...
    if ((m_fModalState) || (m_fNoInteractive))
        return ProvideErrorInfo(DSO_E_INMODALSTATE);

 // The first three dialog types we handle...
	if (DlgType < dsoDialogSaveCopy)
	{
		hr = DoDialogAction(DlgType);
	}
 // The others are provided by the server via IOleCommandTarget...
	else if (m_pDocObjFrame)
	{
		DWORD dwOleCmd;
		switch (DlgType)
		{
		case dsoDialogSaveCopy:   dwOleCmd = OLECMDID_SAVECOPYAS; break;
		case dsoDialogPageSetup:  dwOleCmd = OLECMDID_PAGESETUP;  break;
		case dsoDialogProperties: dwOleCmd = OLECMDID_PROPERTIES; break;
		default:                  dwOleCmd = OLECMDID_PRINT;
		}
		hr = m_pDocObjFrame->DoOleCommand(dwOleCmd, OLECMDEXECOPT_PROMPTUSER, NULL, NULL);
	}

	return ProvideErrorInfo(hr);
}


////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::(put_EnableFileCommand/get_EnableFileCommand)
//
//  True/False. This allows the developer to disable certain menu/toolbar
//  items that are considered "file-level" -- New, Save, Print, etc.
//
//  We use the Item parameter to set a bit flag which is used when
//  displaying the menu to enable/disable the item. The OnFileCommand
//  event will not fire for disabled commands.
//
STDMETHODIMP CDsoFramerControl::put_EnableFileCommand(dsoFileCommandType Item, VARIANT_BOOL vbool)
{
	TRACE2("CDsoFramerControl::put_EnableFileCommand(%d, %d)\n", Item, vbool);

	if ((Item < dsoFileNew) || (Item > dsoFilePrintPreview))
		return E_INVALIDARG;

 // You cannot access menu when in a modal condition...
    if ((m_fModalState) || (m_fNoInteractive))
        return ProvideErrorInfo(DSO_E_INMODALSTATE);

 // We keep bit flags for menu state. Just set the bit and a update
 // the embedded object as needed. User will see change next time menu is shown...
	UINT code = (1 << Item);
	if (vbool == 0)	m_wFileMenuFlags &= ~(code);
	else 		    m_wFileMenuFlags |= code;

	if (m_pDocObjFrame) // This should update toolbar icon (if server supports it)
		m_pDocObjFrame->DoOleCommand(OLECMDID_UPDATECOMMANDS, 0, NULL, NULL);

	return S_OK;
}

STDMETHODIMP CDsoFramerControl::get_EnableFileCommand(dsoFileCommandType Item, VARIANT_BOOL* pbool)
{
	TRACE1("CDsoFramerControl::get_EnableFileCommand(%d)\n", Item);

	if ((Item < dsoFileNew) || (Item > dsoFilePrintPreview))
		return E_INVALIDARG;

	UINT code = (1 << Item);
	if (pbool) *pbool = ((m_wFileMenuFlags & code) ? VARIANT_TRUE : VARIANT_FALSE);

	return S_OK;
}


////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::(put_BorderStyle/get_BorderStyle)
//
//  Change the border style for the control.
//
STDMETHODIMP CDsoFramerControl::put_BorderStyle(dsoBorderStyle style)
{
	ODS("CDsoFramerControl::put_BorderStyle\n");

	if ((style < dsoBorderNone) || (style > dsoBorder3DThin))
		return E_INVALIDARG;

    if (m_fModalState) // Cannot access object if in modal condition...
        return ProvideErrorInfo(DSO_E_INMODALSTATE);

	if (m_fBorderStyle != (DWORD)style)
	{
		m_fBorderStyle = style;
		m_fDirty = TRUE;
		OnResize();
		ViewChanged();
	}
	return S_OK;
}

STDMETHODIMP CDsoFramerControl::get_BorderStyle(dsoBorderStyle* pstyle)
{
	ODS("CDsoFramerControl::get_BorderStyle\n");
	if (pstyle)	*pstyle = (dsoBorderStyle)m_fBorderStyle;
	return S_OK;
}


////////////////////////////////////////////////////////////////////////
// Control Color Properties...
//
//
STDMETHODIMP CDsoFramerControl::put_BorderColor(OLE_COLOR clr)
{
	ODS("CDsoFramerControl::put_BorderColor\n");
	if (m_clrBorderColor != clr)
	{
		m_clrBorderColor = clr;
		m_fDirty = TRUE;
		ViewChanged();
	}
	return S_OK;
}

STDMETHODIMP CDsoFramerControl::get_BorderColor(OLE_COLOR* pclr)
{if (pclr) *pclr = m_clrBorderColor; return S_OK;}

STDMETHODIMP CDsoFramerControl::put_BackColor(OLE_COLOR clr)
{
	ODS("CDsoFramerControl::put_BackColor\n");
	if (m_clrBackColor != clr)
	{
		m_clrBackColor = clr;
		m_fDirty = TRUE;
		ViewChanged();
	}
	return S_OK;
}

STDMETHODIMP CDsoFramerControl::get_BackColor(OLE_COLOR* pclr)
{if (pclr) *pclr = m_clrBackColor; return S_OK;}

STDMETHODIMP CDsoFramerControl::put_ForeColor(OLE_COLOR clr)
{
	ODS("CDsoFramerControl::put_ForeColor\n");
	if (m_clrForeColor != clr)
	{
		m_clrForeColor = clr;
		m_fDirty = TRUE;
		ViewChanged();
	}
	return S_OK;
}

STDMETHODIMP CDsoFramerControl::get_ForeColor(OLE_COLOR* pclr)
{if (pclr) *pclr = m_clrForeColor; return S_OK;}

STDMETHODIMP CDsoFramerControl::put_TitlebarColor(OLE_COLOR clr)
{
	ODS("CDsoFramerControl::put_TitlebarColor\n");
	if (m_clrTBarColor != clr)
	{
		m_clrTBarColor = clr;
		m_fDirty = TRUE;
		ViewChanged();
	}
	return S_OK;
}

STDMETHODIMP CDsoFramerControl::get_TitlebarColor(OLE_COLOR* pclr)
{if (pclr) *pclr = m_clrTBarColor; return S_OK;}


STDMETHODIMP CDsoFramerControl::put_TitlebarTextColor(OLE_COLOR clr)
{
	ODS("CDsoFramerControl::put_TitlebarTextColor\n");
	if (m_clrTBarTextColor != clr)
	{
		m_clrTBarTextColor = clr;
		m_fDirty = TRUE;
		ViewChanged();
	}
	return S_OK;
}

STDMETHODIMP CDsoFramerControl::get_TitlebarTextColor(OLE_COLOR* pclr)
{if (pclr) *pclr = m_clrTBarTextColor; return S_OK;}


////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::(put_Menubar/get_Menubar)
//
//  True/False. Should we display menu bar?
//
STDMETHODIMP CDsoFramerControl::put_Menubar(VARIANT_BOOL vbool)
{
	TRACE1("CDsoFramerControl::put_Menubar(%d)\n", vbool);

 // If the control is in modal state, we can't do things that
 // will call the server directly, like toggle menu bar...
    if ((m_fModalState) || (m_fNoInteractive))
        return ProvideErrorInfo(DSO_E_INMODALSTATE);

	if (m_fShowMenuBar != (WORD)(BOOL)vbool)
	{
		m_fShowMenuBar = (BOOL)vbool;
		m_fDirty = TRUE;
		ViewChanged();
        OnResize();
	}
	return S_OK;
}

STDMETHODIMP CDsoFramerControl::get_Menubar(VARIANT_BOOL* pbool)
{
	ODS("CDsoFramerControl::get_Menubar\n");
	if (pbool) *pbool = (m_fShowMenuBar ? VARIANT_TRUE : VARIANT_FALSE);
	return S_OK;
}

////////////////////////////////////////////////////////////////////////
// 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_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->IsStorageDirty() ? VARIANT_TRUE : VARIANT_FALSE);
	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 + -