// MagDoc.cpp : implementation of the CMagGlassDoc class // #include "stdafx.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CMagGlassApp theApp; ///////////////////////////////////////////////////////////////////////////// // CMagGlassDoc IMPLEMENT_DYNCREATE(CMagGlassDoc, CDocument) BEGIN_MESSAGE_MAP(CMagGlassDoc, CDocument) //{{AFX_MSG_MAP(CMagGlassDoc) ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMagGlassDoc construction/destruction CMagGlassDoc::CMagGlassDoc() { } CMagGlassDoc::~CMagGlassDoc() { } CView * CMagGlassDoc::GetView() { POSITION pos = GetFirstViewPosition(); return(GetNextView(pos)); } ///////////////////////////////////////////////////////////////////////////// // CMagGlassDoc serialization void CMagGlassDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CMagGlassDoc diagnostics #ifdef _DEBUG void CMagGlassDoc::AssertValid() const { CDocument::AssertValid(); } void CMagGlassDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMagGlassDoc commands BOOL CMagGlassDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; int nRet; char szTitle[256]=""; CLead* pLead = NULL; static int nPasteNo = 0; pLead = theApp.GetMainFrameLead(); if (!pLead) { theApp.DisplayLEADError(ERROR_INV_PARAMETER); return FALSE; } nRet = pLead->Paste(0); if (nRet) { theApp.DisplayLEADError(nRet); return FALSE; } if (pLead->GetRgnHandle()) pLead->FreeRgn(); wsprintf(szTitle, "Clipboard Data %d", ++nPasteNo); SetTitle(szTitle); return TRUE; } BOOL CMagGlassDoc::OnOpenDocument(LPCTSTR lpszPathName) { int nRet; CLead* pLead = NULL; if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; if (!lpszPathName) { theApp.DisplayLEADError(ERROR_INV_PARAMETER); return FALSE; } pLead = theApp.GetMainFrameLead(); if (!pLead) { theApp.DisplayLEADError(ERROR_INV_PARAMETER); return FALSE; } nRet = pLead->Load(lpszPathName, 0, theApp.m_nPage, 1); if(nRet) { theApp.DisplayLEADError(nRet); return FALSE; } return TRUE; } BOOL CMagGlassDoc::OnSaveDocument(LPCTSTR lpszPathName) { int nRet; CLead* pLead = NULL; if(!lpszPathName) { theApp.DisplayLEADError(ERROR_INV_PARAMETER); return FALSE; } pLead = theApp.GetMainFrameLead(); if (!pLead) { theApp.DisplayLEADError(ERROR_INV_PARAMETER); return FALSE; } nRet = pLead->Save((LPSTR)lpszPathName, m_nFormat, m_nBits, m_nQFactor, m_nMultipage); if(nRet) { theApp.DisplayLEADError(nRet); return FALSE; } SetModifiedFlag(FALSE); return TRUE; } void CMagGlassDoc::OnFileSaveAs() { CString sFileName; int nRet; CMagGlassApp * pTheApp = (CMagGlassApp*) AfxGetApp(); theApp.m_pRasterFileDlg->PutEnableMethodErrors(FALSE); theApp.m_pRasterFileDlg->PutFileDlgFlags(0); theApp.m_pRasterFileDlg->PutSaveQFactor(2); theApp.m_pRasterFileDlg->PutPageNumber(1); theApp.m_pRasterFileDlg->PutDialogTitle("Save File"); theApp.m_pRasterFileDlg->PutUIFlags(SAVE_SHOW_FILEOPTIONS_MULTIPAGE | SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | SAVE_SHOW_FILEOPTIONS_QFACTOR| SAVE_SHOW_FILEOPTIONS_STAMP | SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| SAVE_SHOW_FILEOPTIONS_J2KOPTIONS); nRet = theApp.m_pRasterFileDlg->ShowSaveDlg((long)pTheApp->m_pMainWnd->GetSafeHwnd()); if(nRet == 0 && theApp.m_pRasterFileDlg->GetDialogStatus() == DLG_OK) { sFileName = theApp.m_pRasterFileDlg->GetFileName().copy(); m_nFormat = theApp.m_pRasterFileDlg->GetSaveFormat(); m_nBits = theApp.m_pRasterFileDlg->GetSaveBitsPerPixel(); m_nQFactor = theApp.m_pRasterFileDlg->GetSaveQFactor(); m_nMultipage = theApp.m_pRasterFileDlg->GetSaveMulti(); long nPage=1; switch(m_nMultipage) { case SAVE_APPEND: nPage = 2; break; case SAVE_OVERWRITE: nPage = 1; break; case SAVE_REPLACE: case SAVE_INSERT: nPage = theApp.m_pRasterFileDlg->GetPageNumber(); break; } pTheApp->GetMainFrameLead()->SetSaveInterlaced(theApp.m_pRasterFileDlg->GetSaveInterlaced()); OnSaveDocument((LPCTSTR)sFileName); } else theApp.DisplayLEADError(nRet); return; } void CMagGlassDoc::OnCloseDocument() { CMagGlassView* pView = (CMagGlassView*) GetView(); // make sure we have a valid pointer if (pView) { // if mag glass was started then stop it before closing the document if (pView->m_Lead.GetHasMagGlass()) pView->StopMagGlass(); } CDocument::OnCloseDocument(); }