home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SAMPLES / VBCHART / CHARTDOC.CP_ / CHARTDOC.CP
Encoding:
Text File  |  1993-02-08  |  4.5 KB  |  148 lines

  1. // chartdoc.cpp : implementation of the CChartDoc class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and Microsoft
  9. // QuickHelp and/or WinHelp documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13.  
  14.  
  15. #include "stdafx.h"
  16. #include "vbchart.h"
  17.  
  18. #include "chartdoc.h"
  19. #include "gridentr.h"
  20.  
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char BASED_CODE THIS_FILE[] = __FILE__;
  24. #endif
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CChartDoc
  28.  
  29. IMPLEMENT_DYNCREATE(CChartDoc, CDocument)
  30.  
  31. BEGIN_MESSAGE_MAP(CChartDoc, CDocument)
  32.     //{{AFX_MSG_MAP(CChartDoc)
  33.     //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CChartDoc construction/destruction
  38.  
  39. CChartDoc::CChartDoc()
  40. {
  41.     m_pDocGrid = NULL;
  42.     m_bDirtyGraph = FALSE;
  43. }
  44.  
  45. CChartDoc::~CChartDoc()
  46. {
  47. }
  48.  
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CChartDoc serialization
  52.  
  53. void CChartDoc::Serialize(CArchive& ar)
  54. {
  55.     if (ar.IsStoring())
  56.     {
  57.         CVBControl* pGrid = m_pDocGrid->m_pGrid;
  58.         m_pDocGrid->m_bEventLockout = TRUE;
  59.  
  60.         // Get and Save current selection state
  61.         int nSelStartRowSave = (int)pGrid->GetNumProperty("SelStartRow");
  62.         int nSelStartColSave = (int)pGrid->GetNumProperty("SelStartCol");
  63.         int nSelEndRowSave   = (int)pGrid->GetNumProperty("SelEndRow");
  64.         int nSelEndColSave   = (int)pGrid->GetNumProperty("SelEndCol");
  65.         int nFixedRowsSave   = (int)pGrid->GetNumProperty("FixedRows");
  66.         int nFixedColsSave   = (int)pGrid->GetNumProperty("FixedCols");
  67.  
  68.         int nRows = (int)pGrid->GetNumProperty("Rows");
  69.         int nCols = (int)pGrid->GetNumProperty("Cols");
  70.  
  71.         // Select entire grid
  72.         pGrid->SetNumProperty("FixedRows", 0);
  73.         pGrid->SetNumProperty("FixedCols", 0);
  74.         pGrid->SetNumProperty("SelStartRow", 0);
  75.         pGrid->SetNumProperty("SelStartCol", 0);
  76.         pGrid->SetNumProperty("SelEndRow", nRows - 1);
  77.         pGrid->SetNumProperty("SelEndCol", nCols - 1);
  78.  
  79.         // Save Everything
  80.         ar << (WORD&)nFixedRowsSave << (WORD&)nFixedColsSave
  81.            << (WORD&)nRows << (WORD&)nCols;
  82.  
  83.         ar << pGrid->GetStrProperty("Clip");
  84.  
  85.         // Reselect original selection to Doc grid
  86.         pGrid->SetNumProperty("FixedRows",   nFixedRowsSave);
  87.         pGrid->SetNumProperty("FixedCols",   nFixedColsSave);
  88.         pGrid->SetNumProperty("SelStartRow", nSelStartRowSave);
  89.         pGrid->SetNumProperty("SelStartCol", nSelStartColSave);
  90.         pGrid->SetNumProperty("SelEndRow",   nSelEndRowSave);
  91.         pGrid->SetNumProperty("SelEndCol",   nSelEndColSave);
  92.         m_pDocGrid->m_bEventLockout = FALSE;
  93.     }
  94.     else
  95.     {
  96.         // Find the first Grid View (first view)
  97.         POSITION pos = GetFirstViewPosition();
  98.         CGridEntry* pGridView = (CGridEntry*) GetNextView(pos);
  99.  
  100.         ASSERT(pGridView != NULL);
  101.         ASSERT(pGridView->IsKindOf(RUNTIME_CLASS(CGridEntry)));
  102.  
  103.         m_pDocGrid = pGridView;     // connect Doc to View
  104.  
  105.         CVBControl* pGrid = (CVBControl*)m_pDocGrid->GetDlgItem(IDC_GRID);
  106.         ASSERT(pGrid != NULL);
  107.         ASSERT(pGrid->IsKindOf(RUNTIME_CLASS(CVBControl)));
  108.  
  109.         m_pDocGrid->m_bEventLockout = TRUE;
  110.         m_pDocGrid->m_bInitialized = TRUE;
  111.  
  112.         int nFixedRowsSave;
  113.         int nFixedColsSave;
  114.         int nRows;
  115.         int nCols;
  116.         CString s;
  117.  
  118.         ar >> (WORD&)nFixedRowsSave >> (WORD&)nFixedColsSave
  119.            >> (WORD&)nRows >> (WORD&)nCols;
  120.         ar >> s;
  121.  
  122.         // Set up grid to proper dimensions
  123.         pGrid->SetNumProperty("Rows", nRows);
  124.         pGrid->SetNumProperty("Cols", nCols);
  125.         pGrid->SetNumProperty("FixedRows", 0);
  126.         pGrid->SetNumProperty("FixedCols", 0);
  127.         pGrid->SetNumProperty("SelStartRow", 0);
  128.         pGrid->SetNumProperty("SelStartCol", 0);
  129.         pGrid->SetNumProperty("SelEndRow", nRows - 1);
  130.         pGrid->SetNumProperty("SelEndCol", nCols - 1);
  131.  
  132.         // Fill all Cells
  133.         pGrid->SetStrProperty("Clip", s);
  134.  
  135.         // Select first cell
  136.         pGrid->SetNumProperty("FixedRows",   nFixedRowsSave);
  137.         pGrid->SetNumProperty("FixedCols",   nFixedColsSave);
  138.         pGrid->SetNumProperty("SelStartRow", nFixedRowsSave);
  139.         pGrid->SetNumProperty("SelStartCol", nFixedColsSave);
  140.         pGrid->SetNumProperty("SelEndRow",   nFixedRowsSave);
  141.         pGrid->SetNumProperty("SelEndCol",   nFixedColsSave);
  142.         m_pDocGrid->m_bEventLockout = FALSE;
  143.     }
  144. }
  145.  
  146.  
  147. /////////////////////////////////////////////////////////////////////////////
  148.