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

📄 oledocob.cpp

📁 vc6.0完整版
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					}
				}

				if (!bFound)
					continue;
			}

			pThis->DoPrepareDC(pView, &dcPrint, &printInfo);

			// check for end of print
			if (!printInfo.m_bContinuePrinting)
				break;

			// set up drawing rect to entire page (in logical coordinates)
			printInfo.m_rectDraw.SetRect(0, 0,
				dcPrint.GetDeviceCaps(HORZRES),
				dcPrint.GetDeviceCaps(VERTRES));
			dcPrint.DPtoLP(&printInfo.m_rectDraw);

			// attempt to start the current page
			if (dcPrint.StartPage() < 0)
			{
				bError = TRUE;
				break;
			}

			// must call OnPrepareDC on newer versions of Windows because
			// StartPage now resets the device attributes.
			if (afxData.bMarked4)
				pThis->DoPrepareDC(pView, &dcPrint, &printInfo);

			ASSERT(printInfo.m_bContinuePrinting);

			hrContinue = S_OK;

			if (pCallback != NULL)
			{
				hrContinue = pCallback->FContinuePrinting(printInfo.m_nCurPage,
					printInfo.m_nCurPage + printInfo.m_nOffsetPage, NULL);
			}

			// page successfully started, so now render the page
			pThis->DoPrint(pView, &dcPrint, &printInfo);
			if (dcPrint.EndPage() < 0 ||
				!_AfxAbortProc(dcPrint.m_hDC, 0) ||
				hrContinue != S_OK)
			{
				bError = TRUE;
				break;
			}

			// increment count
			(*pcPagesPrinted)++;
		}

		// cleanup document printing process
		if (!bError)
			dcPrint.EndDoc();
		else
			dcPrint.AbortDoc();

		AfxGetMainWnd()->EnableWindow();    // enable main window

		// clean up after printing
		pThis->DoEndPrinting(pView, &dcPrint, &printInfo);
		dcPrint.Detach();   // will be cleaned up by CPrintInfo destructor

		if (bError)
		{
			if (hrContinue != S_OK)
				return PRINT_E_CANCELLED;
			else
				return E_UNEXPECTED;
		}
	}

	return S_OK;
}

/////////////////////////////////////////////////////////////////////////////
// IOleDocument interface

STDMETHODIMP_(ULONG) CDocObjectServer::XOleDocument::AddRef()
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleDocument)
	return pThis->m_pOwner->ExternalAddRef();
}

STDMETHODIMP_(ULONG) CDocObjectServer::XOleDocument::Release()
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleDocument)
	return pThis->m_pOwner->ExternalRelease();
}

STDMETHODIMP CDocObjectServer::XOleDocument::QueryInterface(
	REFIID iid, LPVOID* ppvObj)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleDocument)
	return pThis->ExternalQueryInterface(&iid, ppvObj);
}

STDMETHODIMP CDocObjectServer::XOleDocument::CreateView(
   LPOLEINPLACESITE pipsite, LPSTREAM pstm,
   DWORD dwReserved, LPOLEDOCUMENTVIEW* ppview)
{
   METHOD_PROLOGUE_EX(CDocObjectServer, OleDocument)
   ASSERT_VALID(pThis);

   *ppview = NULL;

   HRESULT hr = E_FAIL;

   if (dwReserved == 0 && pThis->m_pDocSite != NULL)
   {
	  // We only support a single view...so if view site is already
	  // set, fail.
	  if (pThis->m_pViewSite == NULL)
	  {
		 LPOLEDOCUMENTVIEW pView =
			(LPOLEDOCUMENTVIEW)pThis->GetInterface(&IID_IOleDocumentView);
		 ASSERT(pView != NULL);

		 // Set the site for the view
		 hr = pView->SetInPlaceSite(pipsite);
		 if (hr == NOERROR)
		 {
			// Return the IOleDocumentView pointer
			pView->AddRef();
			*ppview = pView;
		 }

		 // If a saved view state is provided, restore the view state
		 if (pstm)
			hr = pView->ApplyViewState(pstm);
	  }
	  else
		 TRACE0("CDocObjectServer::XOleDocument::CreateView view already exists!\n");
   }

   return hr;
}

STDMETHODIMP CDocObjectServer::XOleDocument::GetDocMiscStatus(
   LPDWORD pdwStatus)
{
   METHOD_PROLOGUE_EX(CDocObjectServer, OleDocument)
   ASSERT_VALID(pThis);
   ASSERT(pdwStatus != NULL);

   // Our implementation of DocObjects can't create multiple views,
   // does not support complex rectangles, supports open editing,
   // and supports read/write to a file. Thus DOCMISC == 0.
   *pdwStatus = 0;

   return NOERROR;
}

STDMETHODIMP CDocObjectServer::XOleDocument::EnumViews(
   LPENUMOLEDOCUMENTVIEWS* ppEnumView, LPOLEDOCUMENTVIEW* ppView)
{
   METHOD_PROLOGUE_EX(CDocObjectServer, OleDocument)
   ASSERT_VALID(pThis);
   ASSERT(ppEnumView != NULL);
   ASSERT(ppView != NULL);

   // We only support a single view
   *ppEnumView = NULL;
   HRESULT hr = QueryInterface(IID_IOleDocumentView, (LPVOID*)ppView);
   return hr;
}

/////////////////////////////////////////////////////////////////////////////
// IOleObject interface

STDMETHODIMP_(ULONG) CDocObjectServer::XOleObject::AddRef()
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	return pThis->m_pOwner->ExternalAddRef();
}

STDMETHODIMP_(ULONG) CDocObjectServer::XOleObject::Release()
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	return pThis->m_pOwner->ExternalRelease();
}

STDMETHODIMP CDocObjectServer::XOleObject::QueryInterface(
	REFIID iid, LPVOID* ppvObj)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	return pThis->m_pOwner->ExternalQueryInterface(&iid, ppvObj);
}

STDMETHODIMP CDocObjectServer::XOleObject::SetClientSite(
	LPOLECLIENTSITE pClientSite)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	HRESULT hr = NOERROR;

	// Perform normal SetClientSite processing.
	hr = pThis->m_pOwner->m_xOleObject.SetClientSite(pClientSite);
	if (hr != S_OK)
		return hr;

	// If we currently have a document site pointer,
	// release it.

	pThis->ReleaseDocSite();

	// Check to see whether this object should act
	// as a document object by querying for
	// IOleDocumentSite.
	if (pClientSite != NULL)
		hr = pClientSite->QueryInterface(IID_IOleDocumentSite,
			(LPVOID*)&pThis->m_pDocSite);
	return hr;
}

STDMETHODIMP CDocObjectServer::XOleObject::GetClientSite(
	LPOLECLIENTSITE* ppClientSite)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.GetClientSite(ppClientSite);
}

STDMETHODIMP CDocObjectServer::XOleObject::SetHostNames(
	LPCOLESTR lpszContainerApp, LPCOLESTR lpszContainerObj)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.SetHostNames(lpszContainerApp,
										   lpszContainerObj);
}

STDMETHODIMP CDocObjectServer::XOleObject::Close(DWORD dwSaveOption)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.Close(dwSaveOption);
}

STDMETHODIMP CDocObjectServer::XOleObject::SetMoniker(
	DWORD dwWhichMoniker, LPMONIKER pmk)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.SetMoniker(dwWhichMoniker, pmk);
}

STDMETHODIMP CDocObjectServer::XOleObject::GetMoniker(
	DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER* ppMoniker)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.GetMoniker(dwAssign, dwWhichMoniker,
										 ppMoniker);
}

STDMETHODIMP CDocObjectServer::XOleObject::InitFromData(
	LPDATAOBJECT pDataObject, BOOL bCreation, DWORD dwReserved)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.InitFromData(pDataObject, bCreation,
										   dwReserved);
}

STDMETHODIMP CDocObjectServer::XOleObject::GetClipboardData(
	DWORD dwReserved, LPDATAOBJECT* ppDataObject)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.GetClipboardData(dwReserved,
											   ppDataObject);

}

STDMETHODIMP CDocObjectServer::XOleObject::DoVerb(
	LONG iVerb, LPMSG lpmsg, LPOLECLIENTSITE pActiveSite, LONG lindex,
	HWND hwndParent, LPCRECT lpPosRect)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.DoVerb(iVerb, lpmsg,
		pActiveSite, lindex, hwndParent, lpPosRect);
}

STDMETHODIMP CDocObjectServer::XOleObject::EnumVerbs(
	IEnumOLEVERB** ppenumOleVerb)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.EnumVerbs(ppenumOleVerb);
}

STDMETHODIMP CDocObjectServer::XOleObject::Update()
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.Update();
}

STDMETHODIMP CDocObjectServer::XOleObject::IsUpToDate()
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.IsUpToDate();
}

STDMETHODIMP CDocObjectServer::XOleObject::GetUserClassID(CLSID* lpClassID)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.GetUserClassID(lpClassID);
}

STDMETHODIMP CDocObjectServer::XOleObject::GetUserType(
	DWORD dwFormOfType, LPOLESTR* ppszUserType)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.GetUserType(dwFormOfType, ppszUserType);
}

STDMETHODIMP CDocObjectServer::XOleObject::SetExtent(
	DWORD dwDrawAspect, LPSIZEL lpsizel)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);

	// DocObjects ignore SetExtent calls, so returne E_FAIL
	if (pThis->m_pOwner->IsDocObject())
		return E_FAIL;

	// Otherwise, just do the normal processing
	return pThis->m_pOwner->m_xOleObject.SetExtent(dwDrawAspect, lpsizel);
}

STDMETHODIMP CDocObjectServer::XOleObject::GetExtent(
	DWORD dwDrawAspect, LPSIZEL lpsizel)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.GetExtent(dwDrawAspect, lpsizel);
}

STDMETHODIMP CDocObjectServer::XOleObject::Advise(
	LPADVISESINK pAdvSink, DWORD* pdwConnection)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.Advise(pAdvSink, pdwConnection);
}

STDMETHODIMP CDocObjectServer::XOleObject::Unadvise(DWORD dwConnection)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.Unadvise(dwConnection);
}

STDMETHODIMP CDocObjectServer::XOleObject::EnumAdvise(
	LPENUMSTATDATA* ppenumStatData)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.EnumAdvise(ppenumStatData);
}

STDMETHODIMP CDocObjectServer::XOleObject::GetMiscStatus(
	DWORD dwAspect, DWORD* pdwStatus)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.GetMiscStatus(dwAspect, pdwStatus);
}

STDMETHODIMP CDocObjectServer::XOleObject::SetColorScheme(LPLOGPALETTE lpLogpal)
{
	METHOD_PROLOGUE_EX(CDocObjectServer, OleObject)
	ASSERT_VALID(pThis);
	return pThis->m_pOwner->m_xOleObject.SetColorScheme(lpLogpal);
}


/////////////////////////////////////////////////////////////////////////////
// CDocObjectServer diagnostics

#ifdef _DEBUG
void CDocObjectServer::AssertValid() const
{
	ASSERT(m_pOwner != NULL);
	CCmdTarget::AssertValid();
}

void CDocObjectServer::Dump(CDumpContext& dc) const
{
	CCmdTarget::Dump(dc);
	dc << "m_pDocSite = " << m_pDocSite << "\n";
	dc << "m_pViewSite = " << m_pViewSite << "\n";
}
#endif //_DEBUG


/////////////////////////////////////////////////////////////////////////////
// CDocObjectServerItem implementation

IMPLEMENT_DYNAMIC(CDocObjectServerItem, COleServerItem)

CDocObjectServerItem::CDocObjectServerItem(COleServerDoc* pServerDoc, BOOL bAutoDelete)
	: COleServerItem(pServerDoc, bAutoDelete)
{
}

CDocObjectServerItem::~CDocObjectServerItem()
{
}

void CDocObjectServerItem::OnDoVerb(LONG iVerb)
{
   COleServerDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);

   if (pDoc->IsDocObject() && (iVerb == OLEIVERB_INPLACEACTIVATE || iVerb == OLEIVERB_SHOW) )
	  OnShow();
   else
	  COleServerItem::OnDoVerb(iVerb);
}

void CDocObjectServerItem::OnHide()
{
   COleServerDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);

   if (pDoc->IsDocObject())
	  AfxThrowOleException(OLEOBJ_E_INVALIDVERB);
   else
	  COleServerItem::OnHide();
}

void CDocObjectServerItem::OnOpen()
{
   COleServerDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);

   if (pDoc->IsDocObject())
	  pDoc->ActivateDocObject();
   else
	  COleServerItem::OnOpen();
}

void CDocObjectServerItem::OnShow()
{
   COleServerDoc* pDoc = GetDocument();
   ASSERT_VALID(pDoc);

   if (pDoc->IsDocObject())
	  pDoc->ActivateDocObject();
   else
	  COleServerItem::OnShow();
}

#ifdef _DEBUG
void CDocObjectServerItem::AssertValid() const
{
	COleServerItem::AssertValid();
}

void CDocObjectServerItem::Dump(CDumpContext& dc) const
{
	COleServerItem::Dump(dc);
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -