home *** CD-ROM | disk | FTP | other *** search
- // gridsdoc.cpp : implementation of the CGridSampleDoc class
- //
-
- // This is a part of the Objective Grid C++ Library.
- // Copyright (C) 1995,1996 ClassWorks, Stefan Hoenig.
- // All rights reserved.
- //
- // This source code is only intended as a supplement to
- // the Objective Grid Classes Reference and related
- // electronic documentation provided with the library.
- // See these sources for detailed information regarding
- // the Objective Grid product.
- //
-
- #include "stdafx.h"
- #include "gridapp.h"
-
- #include "gridsdoc.h"
-
- #ifndef _GXTWND_H_
- #include "gxtwnd.h"
- #endif
-
- #ifndef _GXVW_H_
- #include "gxvw.h"
- #endif
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSampleDoc
-
- IMPLEMENT_DYNCREATE(CGridSampleDoc, CDocument)
-
- #define new DEBUG_NEW
-
- BEGIN_MESSAGE_MAP(CGridSampleDoc, CDocument)
- //{{AFX_MSG_MAP(CGridSampleDoc)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSampleDoc construction/destruction
-
- CGridSampleDoc::CGridSampleDoc()
- {
- }
-
- CGridSampleDoc::~CGridSampleDoc()
- {
- DeleteContents();
- }
-
- void CGridSampleDoc::DeleteContents()
- {
- int nSize = m_ParamArray.GetSize();
-
- for (int i = 0; i < m_bOwnParamArray.GetSize(); i++)
- if (m_bOwnParamArray[i])
- delete m_ParamArray[i];
-
- m_ParamArray.RemoveAll();
- m_bOwnParamArray.RemoveAll();
- }
-
- BOOL CGridSampleDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
-
- SetModifiedFlag();
-
- return TRUE;
- }
-
- BOOL CGridSampleDoc::OnOpenDocument(LPCTSTR pszPathName)
- {
- // TRACE1("CDocument: OnOpenDocument(%s)\n", pszPathName);
-
- SetModifiedFlag(FALSE);
-
- if (!CDocument::OnOpenDocument(pszPathName))
- return FALSE;
-
- return TRUE;
- }
-
- BOOL CGridSampleDoc::OnSaveDocument(LPCTSTR pszPathName)
- {
- // TRACE1("CDocument: OnSaveDocument(%s)\n", pszPathName);
-
- // Ensure that each views current cell is stored
- CGXGridHint hint(gxHintTransferCurrentCell);
- hint.lParam = TRUE;
-
- UpdateAllViews(NULL, 0, &hint);
-
- // Now, I can save the document
- if (!CDocument::OnSaveDocument(pszPathName))
- return FALSE;
-
- SetModifiedFlag(FALSE);
-
- return TRUE;
- }
-
- BOOL CGridSampleDoc::CanCloseFrame(CFrameWnd* pFrame)
- {
- // Ensure that views can be deactivated
- CView* pView = pFrame->GetActiveView();
- if (pView && pView->SendMessage(WM_GX_CANACTIVATE, 0, 0))
- return FALSE;
-
- // Is it a grid?
- CGXGridCore* pGrid = NULL;
- if (pView->IsKindOf(RUNTIME_CLASS(CGXGridView)))
- pGrid = (CGXGridCore*) ((CGXGridView*) pView);
-
- else if (pView->IsKindOf(RUNTIME_CLASS(CGXGridHandleView)))
- pGrid = ((CGXGridHandleView*) pView)->GetGrid();
-
- if (pGrid)
- {
- // Ensure that the current cell can be stored
- if (!pGrid->TransferCurrentCell(TRUE, GX_UPDATENOW, FALSE))
- // grid state is invalid, don't close the frame
- return FALSE;
- }
-
- // Now, I can close the view
- return CDocument::CanCloseFrame(pFrame);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSampleDoc serialization
-
- void CGridSampleDoc::Serialize(CArchive& ar)
- {
- static const WORD wVersion = 1;
- WORD wActualVersion = wVersion;
-
- ASSERT_VALID( this );
-
- if (ar.IsStoring())
- {
- ar << wVersion;
- }
- else
- {
- // Check for version first
- ar >> wActualVersion;
- if( wActualVersion != wVersion )
- {
- // Wrong version
- #ifdef _DEBUG
- TRACE0("Incompatible format while reading CGridSampleDoc" );
- TRACE2("in %s at line %d\n", __FILE__, __LINE__);
- #endif
- AfxThrowArchiveException(CArchiveException::badSchema);
- return;
- }
- }
-
- m_ParamArray.Serialize( ar );
- m_bOwnParamArray.Serialize( ar );
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSampleDoc diagnostics
-
- #ifdef _DEBUG
- void CGridSampleDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
-
- void CGridSampleDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CGridSampleDoc commands
-
- CObject* CGridSampleDoc::GetParam(int nViewID)
- {
- CObject* pParam = NULL;
-
- if (m_ParamArray.GetUpperBound() >= nViewID && m_ParamArray[nViewID])
- pParam = m_ParamArray[nViewID];
-
- return pParam;
- }
-
- void CGridSampleDoc::SetParam(int nViewID, CObject* pParam, BOOL bMustDelete)
- {
- CObject* pDocParam = NULL;
-
- if (m_ParamArray.GetUpperBound() >= nViewID && m_ParamArray[nViewID])
- pDocParam = m_ParamArray[nViewID];
-
- if (pDocParam == NULL || pParam != NULL)
- {
- if (pDocParam)
- delete pDocParam;
-
- ASSERT_VALID(pParam);
-
- m_ParamArray.SetAtGrow(nViewID, pParam);
- m_bOwnParamArray.SetAtGrow(nViewID, (BYTE) bMustDelete);
- }
- }
-