📄 mvdoctemplate.cpp
字号:
// Created by: Yog Sothoth
// Company: The Old Ones
// More Info: Azathoth@Cyberdude.com
// Home Page: http://www.geocities.com/SiliconValley/Peaks/2976/
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @doc
// @module MvDocTemplate.cpp |
// This module allow you to use document with multiple views. It
// can be multiple document interface or single document interface.
// @End -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Include file section.
// ------------------------------------------------------------------------
// Precompile header.
#include "stdafx.h"
// Class definition file.
#include "MvDocTemplate.hpp"
// Afx privae include file.
#include <AfxPriv.h>
#define GET_RTCNAME( Object ) Object->GetRuntimeClass()->m_lpszClassName
// @End -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Constructor. Those information are directly passed to the
// base class that will manage the document creation.
CSDIMVDocTemplate::CSDIMVDocTemplate(
UINT _nIDResource,
CRuntimeClass* _pDocClass,
BOOL _bAutoDelete /* = TRUE */ )
: CMvDocTemplate( _nIDResource, _pDocClass, _bAutoDelete )
{
// Init value to prevent error.
m_pDocument = NULL;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CSDIMVDocTemplate::~CSDIMVDocTemplate( void )
{
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Document related method. Those method are needed by the
// sdi concept. To support SDI.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This method is called by the CDocTemplate class when opening a
// document. Because we only have 1 docucument we first close the
// one we got, the we set the current to the one we receive in
// parameter.
void CSDIMVDocTemplate::AddDocument( CDocument* _pDoc )
{
// Validate the new document.
if ( !_pDoc )
{
ASSERT ( _pDoc );
TRACE( "Invalid document parameter in the AddDocument method in %s at %d.\n", THIS_FILE, __LINE__ );
return;
}
// Make sure the document is valid.
ASSERT_VALID( _pDoc );
// Call the add document method of our parent class. We don't call the
// multidoc add document because we don't want a multi doc application.
CDocTemplate::AddDocument( _pDoc );
// If a document is already open, we must close it.
if ( m_pDocument )
{
// Already have a document.
// Must close it.
CloseAllDocuments( FALSE );
}
// Store the document pointer for later use.
m_pDocument = _pDoc;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This method is called by the CDocTemplate class when closing a
// document. Because we only have 1 docucument we only set the
// current one to NULL.
void CSDIMVDocTemplate::RemoveDocument( CDocument* _pDoc )
{
// Validate the document to remove.
if ( !_pDoc )
{
ASSERT ( _pDoc );
TRACE( "Invalid document parameter in the RemoveDocument method in %s at %d.\n", THIS_FILE, __LINE__ );
return;
}
// Since we only got one document to remove, must be the same we keep.
else if ( m_pDocument != _pDoc )
{
// Not the same.
ASSERT( m_pDocument == _pDoc );
TRACE( "Document to remove is not the same as the one we got in the \
RemoveDocument method in %s at %d.\n", THIS_FILE, __LINE__ );
}
// Make sure the document is valid.
ASSERT_VALID( _pDoc );
// Clean the memory.
CleanDocument( _pDoc );
// Call the base class method. Call the CDocTemplate since we manage the doc
// ourselves.
CDocTemplate::RemoveDocument( _pDoc );
// Set the current document to NULL to avoid pointer problem.
m_pDocument = NULL;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This method is called by the CDocTemplate class when managing
// the document. Because we only have 1 document, we can't return
// the position of the first one. We must return a special ID.
//
// Return: Special id to identify the first document.
POSITION CSDIMVDocTemplate::GetFirstDocPosition( void ) const
{
return ( m_pDocument == NULL ) ? NULL : BEFORE_START_POSITION;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This method is called by the CDocTemplate class when managing
// the document. Because we only have 1 document, we only return
// the currrent document, depending on the position pass in
// parameter. When returning, we set the current position to NULL,
// because there is no more document in the list.
//
// Return: The document pointer.
CDocument* CSDIMVDocTemplate::GetNextDoc( POSITION& _rPos ) const
{
// Got only 1 document at the same time. We set the next position to
// null. When the framework ask the next document, we will return NULL
CDocument* pReturnDoc = NULL;
// Validate the position requested.
if ( _rPos == BEFORE_START_POSITION )
{
// The position correspond to the first document, our only one.
// Return it.
pReturnDoc = m_pDocument;
}
// The position is invalid.
_rPos = NULL;
return pReturnDoc;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Constructor. Those information are directly passed to the
// base class that will manage the document creation.
CMDIMVDocTemplate::CMDIMVDocTemplate(
UINT _nIDResource,
CRuntimeClass* _pDocClass,
BOOL _bAutoDelete /* = TRUE */)
: CMvDocTemplate( _nIDResource, _pDocClass, _bAutoDelete )
{
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CMDIMVDocTemplate::~CMDIMVDocTemplate( void )
{
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// This method is called by the CDocTemplate class when closing a
// document. Must overload to clean the allocated memory associated
// with that document.
void CMDIMVDocTemplate::RemoveDocument( CDocument* _pDoc )
{
// Validate the document to remove.
if ( !_pDoc )
{
ASSERT ( _pDoc );
TRACE( "Invalid document parameter in the RemoveDocument method in %s at %d.\n", THIS_FILE, __LINE__ );
return;
}
// Make sure the document is valid.
ASSERT_VALID( _pDoc );
// Clean the memory.
CleanDocument( _pDoc );
// Call the base class method. Call the CDocTemplate since we manage the doc
// ourselves.
CMultiDocTemplate::RemoveDocument( _pDoc );
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Helpfull class to get the document associated document frame manager.
CDocFrameMgr* CMvDocTemplate::GetAssociatedDocFrameMgr( CDocument* _pDoc )
{
POSITION pos = m_DocumentFrameList.GetHeadPosition();
while ( pos )
{
CDocFrameMgr* pDocFrameMgr = m_DocumentFrameList.GetNext( pos );
if ( pDocFrameMgr->GetDocument() == _pDoc )
{
return pDocFrameMgr;
}
}
// Not found.
return NULL;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Constructor. Those information are directly passed to the
// base class that will manage the document creation.
CMvDocTemplate::CMvDocTemplate(
UINT _nIDResource,
CRuntimeClass* _pDocClass,
BOOL _bAutoDelete /* = TRUE */ )
: CMultiDocTemplate( _nIDResource, _pDocClass, NULL, NULL )
{
m_bAutoDelete = _bAutoDelete;
m_pFrameToActivate = NULL;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CMvDocTemplate::~CMvDocTemplate( void )
{
// Must clean all memory allocated.
while ( m_FrameTemplateList.GetCount() )
{
delete m_FrameTemplateList.RemoveTail();
}
// Must clean all memory allocated.
while ( m_DocumentFrameList.GetCount() )
{
delete m_DocumentFrameList.RemoveTail();
}
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// We overload the open document method to prepare and open all frame.
CDocument* CMvDocTemplate::OpenDocumentFile(
LPCTSTR _lpszPathName,
BOOL _bMakeVisible )
{
// Create the document instance and validate it.
CDocument* pDocument = CreateNewDocument();
if ( !pDocument )
{
// The document is invalid.
// Inform the user of the error, and exit the method.
AfxMessageBox( AFX_IDP_FAILED_TO_CREATE_DOC );
TRACE( "Unable of creating the document in OpenDocumentFile \
in %s at %d.\n", THIS_FILE, __LINE__ );
return NULL;
}
// Validate the document.
ASSERT_VALID( pDocument );
// The document is valid. Set the autodelete flag.
pDocument->m_bAutoDelete = m_bAutoDelete;
// Verify if we are creating a new document, or opening an exesting one.
if ( _lpszPathName == NULL )
{
// Xreate a new document - with default document name
SetDefaultTitle( pDocument );
// Avoid creating temporary compound file when starting up invisible
if ( !_bMakeVisible )
{
pDocument->m_bEmbedded = TRUE;
}
// Initialize the document.
if ( !pDocument->OnNewDocument() )
{
// Unable to initialize the document.
TRACE( "Unable to initialize the new document in OpenDocumentFile \
in %s at %d.\n", THIS_FILE, __LINE__ );
return NULL;
}
// Increment the document counter.
m_nUntitledCount++;
}
else
{
// Open an existing document
CWaitCursor wait;
if ( !pDocument->OnOpenDocument( _lpszPathName ) )
{
// Unable to open the document.
TRACE( "Unable to open the document in OpenDocumentFile \
in %s at %d.\n", THIS_FILE, __LINE__ );
// We must delete the document instance.
RemoveDocument( pDocument );
delete pDocument;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -