home *** CD-ROM | disk | FTP | other *** search
- // ServDDoc.cpp : implementation of the CServDemoDoc class
- //
-
- #include "stdafx.h"
- #include "ServDemo.h"
-
- #include "ServDDoc.h"
- #include "SrvrItem.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CServDemoDoc
-
- IMPLEMENT_DYNCREATE(CServDemoDoc, COleServerDoc)
-
- BEGIN_MESSAGE_MAP(CServDemoDoc, COleServerDoc)
- //{{AFX_MSG_MAP(CServDemoDoc)
- ON_COMMAND(ID_EDIT_CLEAR_ALL, OnEditClearAll)
- ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR_ALL, OnUpdateEditClearAll)
- ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
- ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CServDemoDoc construction/destruction
-
- CServDemoDoc::CServDemoDoc()
- {
- // Use OLE compound files
- EnableCompoundFile();
-
- // TODO: add one-time construction code here
-
- }
-
- CServDemoDoc::~CServDemoDoc()
- {
- }
-
- BOOL CServDemoDoc::OnNewDocument()
- {
- if (!COleServerDoc::OnNewDocument())
- return FALSE;
-
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
-
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CServDemoDoc server implementation
-
- COleServerItem* CServDemoDoc::OnGetEmbeddedItem()
- {
- // OnGetEmbeddedItem is called by the framework to get the COleServerItem
- // that is associated with the document. It is only called when necessary.
-
- CServDemoSrvrItem* pItem = new CServDemoSrvrItem(this);
- ASSERT_VALID(pItem);
- return pItem;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CServDemoDoc serialization
-
- void CServDemoDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- m_LineArray.Serialize (ar);
- }
- else
- {
- // TODO: add loading code here
- m_LineArray.Serialize (ar);
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CServDemoDoc diagnostics
-
- #ifdef _DEBUG
- void CServDemoDoc::AssertValid() const
- {
- COleServerDoc::AssertValid();
- }
-
- void CServDemoDoc::Dump(CDumpContext& dc) const
- {
- COleServerDoc::Dump(dc);
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CServDemoDoc commands
-
- IMPLEMENT_SERIAL (CLine, CObject, 1)
-
- void CLine::Draw (CDC *PDC)
- {
- PDC->MoveTo (m_X1, m_Y1);
- PDC->LineTo (m_X2, m_Y2);
- }
-
- void CLine::Serialize (CArchive& ar)
- {
- if (ar.IsStoring())
- ar << m_X1 << m_Y1 << m_X2 << m_Y2;
- else
- ar >> m_X1 >> m_Y1 >> m_X2 >> m_Y2;
- }
-
- void CServDemoDoc::AddLine (int X1, int Y1, int X2, int Y2)
- {
- CLine *PLine = new CLine (X1, Y1, X2, Y2);
- m_LineArray.Add (PLine);
- SetModifiedFlag ();
- }
-
- CLine *CServDemoDoc::GetLine (int Index)
- {
- if (Index < 0 || Index > m_LineArray.GetUpperBound ())
- return 0;
- return m_LineArray.GetAt (Index);
- }
-
- int CServDemoDoc::GetNumLines ()
- {
- return m_LineArray.GetSize ();
- }
-
- void CServDemoDoc::DeleteContents()
- {
- // TODO: Add your specialized code here and/or call the base class
-
- int Index = m_LineArray.GetSize ();
- while (Index--)
- delete m_LineArray.GetAt (Index);
- m_LineArray.RemoveAll ();
- }
-
- void CServDemoDoc::OnEditClearAll()
- {
- // TODO: Add your command handler code here
-
- DeleteContents ();
- UpdateAllViews (0);
- SetModifiedFlag ();
- }
-
- void CServDemoDoc::OnUpdateEditClearAll(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- pCmdUI->Enable (m_LineArray.GetSize ());
- }
-
- void CServDemoDoc::OnEditUndo()
- {
- // TODO: Add your command handler code here
-
- int Index = m_LineArray.GetUpperBound ();
- if (Index > -1)
- {
- delete m_LineArray.GetAt (Index);
- m_LineArray.RemoveAt (Index);
- }
- UpdateAllViews (0);
- SetModifiedFlag ();
- }
-
- void CServDemoDoc::OnUpdateEditUndo(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- pCmdUI->Enable (m_LineArray.GetSize ());
- }
-