// (c) R.I.Allen 2002
// You may use this code in anyway that you feel, no guarantees or waranties are implied
// please keep all headers with any source used.
//
// AppPlugInCoreDoc.cpp : implementation of the CPIDoc class
//
#include "stdafx.h"
#include "PIDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPIDoc
IMPLEMENT_DYNCREATE(CPIDoc, CDocument)
BEGIN_MESSAGE_MAP(CPIDoc, CDocument)
//{{AFX_MSG_MAP(CPIDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPIDoc construction/destruction
CPIDoc::CPIDoc()
{
m_pMaps = NULL;
m_MapCount = 0;
}
CPIDoc::~CPIDoc()
{
// release message map pointers
for (int i = 0; i < m_MapCount; ++i)
{
delete m_pMaps[i];
m_pMaps[i] = NULL;
}
delete []m_pMaps;
m_pMaps = NULL;
m_state.SetDestroyed();
}
void CPIDoc::InitialisePlugIns()
{
CPlugInApp *pApp = static_cast<CPlugInApp*>(AfxGetApp());
// get our pointers to any plug in maps
m_pMaps = pApp->GetMessageMaps(this, m_MapCount);
}
/////////////////////////////////////////////////////////////////////////////
// CPIDoc serialization
void CPIDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CPIDoc diagnostics
#ifdef _DEBUG
void CPIDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CPIDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPIDoc commands
BOOL CPIDoc::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// check to see whether any of the plug-in DLL's
// want to intercept this message and process it before the application class
CPlugInApp *pApp = static_cast<CPlugInApp*>(AfxGetApp());
CPIState stateCopy(m_state);
ASSERT(pApp);
BOOL ret_pre = FALSE;
BOOL ret_app = FALSE;
BOOL ret_post = FALSE;
m_bSuppressThisMessage = false;
// allow DLL's to process this message before the exe
ret_pre = pApp->ProcessCommandMessageMaps(stateCopy, true, &m_bSuppressThisMessage, m_pMaps, m_MapCount, nID, nCode, pExtra, pHandlerInfo);
if (!m_bSuppressThisMessage)
{
// allow the exe to process the message is it hasn't been suppressed by a DLL
ret_app = CDocument::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
// allow DLL to process the message after the exe
// note that DLLs get to do this whether the message has been supressed or not
if (!stateCopy.IsDestroyed())
{
ret_post = pApp->ProcessCommandMessageMaps(stateCopy, false, &m_bSuppressThisMessage, m_pMaps, m_MapCount, nID, nCode, pExtra, pHandlerInfo);
}
}
if (ret_pre || ret_app || ret_post)
return TRUE;
return FALSE;
}