📄 swlisdoc.cpp
字号:
// swlisdoc.cpp : implementation of the CSWListerDoc class
//
#include "stdafx.h"
#include "swlister.h"
#include "swlisdoc.h"
#include "swadddlg.h"
#include "swprodct.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSWListerDoc
IMPLEMENT_DYNCREATE(CSWListerDoc, CDocument)
BEGIN_MESSAGE_MAP(CSWListerDoc, CDocument)
//{{AFX_MSG_MAP(CSWListerDoc)
ON_COMMAND(ID_LIST_ADD, OnListAdd)
ON_COMMAND(ID_ITERATOR_INITIALIZE, OnIteratorInitialize)
ON_COMMAND(ID_ITERATOR_NEXT, OnIteratorNext)
ON_UPDATE_COMMAND_UI(ID_ITERATOR_NEXT, OnUpdateIteratorNext)
ON_COMMAND(ID_LIST_MODIFY, OnListModify)
ON_UPDATE_COMMAND_UI(ID_LIST_MODIFY, OnUpdateListModify)
ON_COMMAND(ID_LIST_DUMP, OnListDump)
ON_UPDATE_COMMAND_UI(ID_LIST_DUMP, OnUpdateListDump)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSWListerDoc construction/destruction
CSWListerDoc::CSWListerDoc()
{
// TODO: add one-time construction code here
}
CSWListerDoc::~CSWListerDoc()
{
CObject* pOb;
POSITION Pos = m_TheList.GetHeadPosition();
while (Pos != NULL)
{
pOb = m_TheList.GetNext(Pos);
delete pOb;
}
m_TheList.RemoveAll();
}
BOOL CSWListerDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
m_nIteratorIndex = 0;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CSWListerDoc serialization
void CSWListerDoc::Serialize(CArchive& ar)
{
m_TheList.Serialize(ar);
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CSWListerDoc diagnostics
#ifdef _DEBUG
void CSWListerDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CSWListerDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSWListerDoc commands
void CSWListerDoc::OnListAdd()
{
CSWAddDlg Dlg;
CSWProduct* pSW = new CSWProduct();
Dlg.m_pSW = pSW;
if (Dlg.DoModal() == IDOK)
m_TheList.AddTail(pSW);
else
delete pSW;
}
void CSWListerDoc::OnIteratorInitialize()
{
m_nIteratorIndex = 0;
}
void CSWListerDoc::OnIteratorNext()
{
m_nIteratorIndex++;
}
void CSWListerDoc::OnUpdateIteratorNext(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_TheList.GetCount() > m_nIteratorIndex);
}
void CSWListerDoc::OnListModify()
{
POSITION Pos = m_TheList.FindIndex(m_nIteratorIndex);
CSWProduct* pSW = (CSWProduct*)m_TheList.GetAt(Pos);
CSWAddDlg Dlg;
Dlg.m_pSW = pSW;
Dlg.DoModal();
}
void CSWListerDoc::OnUpdateListModify(CCmdUI* pCmdUI)
{
POSITION Pos = m_TheList.FindIndex(m_nIteratorIndex);
if (Pos == NULL)
{
pCmdUI->SetText("&Modify");
pCmdUI->Enable(FALSE);
return;
}
CSWProduct* pSW = (CSWProduct*)m_TheList.GetAt(Pos);
pCmdUI->SetText("&Modify: " + pSW->m_strTitle);
pCmdUI->Enable(TRUE);
}
void CSWListerDoc::OnListDump()
{
TRACE1 ("The SW Product List contains %i items (as shown):\n",
m_TheList.GetCount());
#ifdef _DEBUG
POSITION Pos = m_TheList.GetHeadPosition();
CSWProduct* pSW;
while (Pos != NULL)
{
pSW = (CSWProduct*)m_TheList.GetNext(Pos);
pSW->Dump(afxDump);
}
#endif
}
void CSWListerDoc::OnUpdateListDump(CCmdUI* pCmdUI)
{
#ifdef _DEBUG
pCmdUI->Enable(TRUE);
#else
pCmdUI->Enable(FALSE);
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -