www.pudn.com > SCIDE.rar > SCDoc.cpp


// SCDoc.cpp : implementation of the CSCDoc class 
// 
 
#include "stdafx.h" 
#include "SCIDE.h" 
#include "MainFrm.h" 
 
#include "SCDoc.h" 
#include "SCView.h" 
#include "ChildFrm.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CSCDoc 
 
IMPLEMENT_DYNCREATE(CSCDoc, CDocument) 
 
BEGIN_MESSAGE_MAP(CSCDoc, CDocument) 
	//{{AFX_MSG_MAP(CSCDoc) 
		// 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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CSCDoc construction/destruction 
 
#pragma warning(disable:4355) 
CSCDoc::CSCDoc() : m_xTextBuffer(this) 
{ 
	// TODO: add one-time construction code here 
	CFont font; 
	font.CreateFont(10, 0, 0, 0, FW_REGULAR, 0, 0, 0, GB2312_CHARSET,  
		0, 0, 0, FIXED_PITCH | FF_MODERN, "Fixedsys"); 
	font.GetLogFont(&m_lf); 
} 
 
CSCDoc::~CSCDoc() 
{ 
} 
 
BOOL CSCDoc::OnNewDocument() 
{ 
	if (!CDocument::OnNewDocument()) 
		return FALSE; 
	 
	CMainFrame *pMainWnd = (CMainFrame *)(AfxGetApp()->m_pMainWnd); 
	pMainWnd->AddTreeNode(this, NULL, "新文件.sc"); 
	TCHAR szDir[_MAX_PATH]; 
	GetCurrentDirectory(_MAX_PATH, szDir); 
	CString szFileName = szDir; 
	if (szFileName[szFileName.GetLength()-1] != '\\') 
		szFileName += '\\'; 
	szFileName += "新文件.sc"; 
	SetPathName(szFileName); 
 
	m_xTextBuffer.InitNew(); 
	return TRUE; 
} 
 
void CSCDoc::OpenView() 
{ 
	CMainFrame *pMainWnd = (CMainFrame *)(AfxGetApp()->m_pMainWnd); 
 
	POSITION pos = GetFirstViewPosition(); 
 
	CSCView *pView = (CSCView *)GetNextView(pos); 
	if (NULL == pView) 
		return; 
 
	CMDIChildWnd *pWnd=(CMDIChildWnd *)pView->GetParentFrame();  
	pWnd->MDIActivate(); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CSCDoc serialization 
 
void CSCDoc::Serialize(CArchive& ar) 
{ 
	if (ar.IsStoring()) 
	{ 
		// TODO: add storing code here 
	} 
	else 
	{ 
		// TODO: add loading code here 
	} 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CSCDoc diagnostics 
 
#ifdef _DEBUG 
void CSCDoc::AssertValid() const 
{ 
	CDocument::AssertValid(); 
} 
 
void CSCDoc::Dump(CDumpContext& dc) const 
{ 
	CDocument::Dump(dc); 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CSCDoc commands 
 
void CSCDoc::DeleteContents()  
{ 
	CDocument::DeleteContents(); 
 
	m_xTextBuffer.FreeAll(); 
} 
 
BOOL CSCDoc::OnOpenDocument(LPCTSTR lpszPathName)  
{ 
	if (!CDocument::OnOpenDocument(lpszPathName)) 
		return FALSE; 
 
	CMainFrame *pMainWnd = (CMainFrame *)(AfxGetApp()->m_pMainWnd); 
	pMainWnd->AddTreeNode(this, NULL, lpszPathName); 
 
	return m_xTextBuffer.LoadFromFile(lpszPathName); 
} 
 
BOOL CSCDoc::OnSaveDocument(LPCTSTR lpszPathName)  
{ 
	m_xTextBuffer.SaveToFile(lpszPathName); 
	 
	CMainFrame *pMainWnd = (CMainFrame *)(AfxGetApp()->m_pMainWnd); 
	pMainWnd->UpdateTreeNode(this, NULL, lpszPathName); 
 
	return TRUE;	//	Note - we didn't call inherited member! 
} 
 
void CSCDoc::OnCloseDocument()  
{ 
	// TODO: Add your specialized code here and/or call the base class	 
	CMainFrame *pMainWnd = (CMainFrame *)(AfxGetApp()->m_pMainWnd); 
	pMainWnd->DeleteTreeNode(this); 
 
	CDocument::OnCloseDocument(); 
}