www.pudn.com > 数控仿真与网络控制系统.rar > NoteXpadDoc.cpp


// NoteXpadDoc.cpp : implementation of the CNoteXpadDoc class 
// 
 
#include "stdafx.h" 
#include "NoteXpad.h" 
 
#include "NoteXpadDoc.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
extern CString CURRENT_FILE; 
extern BOOL CHANGED; 
///////////////////////////////////////////////////////////////////////////// 
// CNoteXpadDoc 
 
IMPLEMENT_DYNCREATE(CNoteXpadDoc, CDocument) 
 
BEGIN_MESSAGE_MAP(CNoteXpadDoc, CDocument) 
	//{{AFX_MSG_MAP(CNoteXpadDoc) 
	ON_UPDATE_COMMAND_UI(ID_SELECT_ALL, OnUpdateSelectAll) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CNoteXpadDoc construction/destruction 
 
CNoteXpadDoc::CNoteXpadDoc() 
{ 
	// TODO: add one-time construction code here 
 
} 
 
CNoteXpadDoc::~CNoteXpadDoc() 
{ 
} 
 
BOOL CNoteXpadDoc::OnNewDocument() 
{ 
	if (!CDocument::OnNewDocument()) 
		return FALSE; 
 
	((CEditView*)m_viewList.GetHead())->SetWindowText(NULL); 
 
	//Set value of global string CURRENT_FILE to Untitled 
	CURRENT_FILE = "Untitled"; 
	CDocument::SetTitle("Untitled"); 
 
	return TRUE; 
} 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CNoteXpadDoc serialization 
 
void CNoteXpadDoc::Serialize(CArchive& ar) 
{ 
	// CEditView contains an edit control which handles all serialization 
	((CEditView*)m_viewList.GetHead())->SerializeRaw(ar); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CNoteXpadDoc diagnostics 
 
#ifdef _DEBUG 
void CNoteXpadDoc::AssertValid() const 
{ 
	CDocument::AssertValid(); 
} 
 
void CNoteXpadDoc::Dump(CDumpContext& dc) const 
{ 
	CDocument::Dump(dc); 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CNoteXpadDoc commands 
 
BOOL CNoteXpadDoc::OnOpenDocument(LPCTSTR lpszPathName)  
{ 
	if (!CDocument::OnOpenDocument(lpszPathName)) 
		return FALSE; 
 
	//Set value of global string CURRENT_FILE to opened document's path 
	CURRENT_FILE = lpszPathName; 
	//Set global boolean CHANGED to FALSE 
	CHANGED = FALSE; 
	return TRUE; 
} 
 
BOOL CNoteXpadDoc::OnSaveDocument(LPCTSTR lpszPathName)  
{ 
	//Set global boolean CHANGED to FALSE 
	CHANGED = FALSE;	 
	//Set value of global string CURRENT_FILE to saved document's path 
	CURRENT_FILE = lpszPathName; 
	return CDocument::OnSaveDocument(lpszPathName); 
} 
 
void CNoteXpadDoc::SetTitle(LPCTSTR lpszTitle)  
{ 
	//Set title of document to global string CURRENT_FILE 
	lpszTitle = CURRENT_FILE; 
	if (CURRENT_FILE == "") 
	{ 
		CDocument::SetTitle(lpszTitle); 
		return; 
	} 
	CDocument::SetTitle(lpszTitle); 
} 
 
 
BOOL CNoteXpadDoc::SaveModified()  
{ 
	 
	BOOL THEBOOL = CDocument::SaveModified(); 
 
	if (!THEBOOL) 
	{ 
	CHANGED = FALSE; 
	} 
	 
	return THEBOOL; 
} 
 
void CNoteXpadDoc::OnUpdateSelectAll(CCmdUI* pCmdUI)  
{ 
	/*Disables/Enables the Select All Menu according 
	to the status of the view.*/ 
 
	CFrameWnd* theFrame  = (CFrameWnd*)AfxGetMainWnd(); 
	CEdit* theEdit = (CEdit*)theFrame->GetActiveView(); 
 
	if (theEdit->GetWindowTextLength() == 0) 
	{ 
		pCmdUI->Enable(FALSE); 
	} 
	else 
	{ 
		pCmdUI->Enable(TRUE); 
	} 
}