home *** CD-ROM | disk | FTP | other *** search
- // mfcdedoc.cpp : implementation of the CMfcdemoDoc class
- // Copyright (C) 1996 LEAD Technologies, Inc.
- // All rights reserved.
-
- #include "stdafx.h"
- #include "mfcdemo.h"
- #include "colormer.h"
- #include "openopt.h"
- #include "saveopt.h"
-
- #include "mfcdedoc.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- extern CMfcdemoApp theApp;
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoDoc
-
- IMPLEMENT_DYNCREATE(CMfcdemoDoc, CDocument)
-
- BEGIN_MESSAGE_MAP(CMfcdemoDoc, CDocument)
- //{{AFX_MSG_MAP(CMfcdemoDoc)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoDoc construction/destruction
-
- CMfcdemoDoc::CMfcdemoDoc()
- {
- CRect rcClient;
- theApp.m_pMainWnd->GetClientRect(rcClient);
-
- m_Lead.CreateInstance(&m_LeadContainer, theApp.m_pMainWnd, rcClient);
- m_Lead.ShowWindow(SW_HIDE);
- m_Lead.SetAutoRepaint(FALSE);
- /* m_Lead2 is used for supporting the floater bitmap in the view */
- m_Lead2.CreateInstance(&m_LeadContainer, theApp.m_pMainWnd, rcClient);
- m_Lead2.ShowWindow(SW_HIDE);
- m_Lead2.SetAutoRepaint(FALSE);
- m_LeadUndo.CreateInstance(&m_LeadContainer, theApp.m_pMainWnd, rcClient);
- m_LeadUndo.ShowWindow(SW_HIDE);
- m_LeadUndo.SetAutoRepaint(FALSE);
- }
-
- CMfcdemoDoc::~CMfcdemoDoc()
- {
- }
-
- BOOL CMfcdemoDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
-
-
- switch(theApp.m_nOpenMode)
- {
- case OPENMODE_COLORMERGE:
- return(OnOpenColorMerge());
- break;
- case OPENMODE_TWAIN:
- return(OnOpenTwain());
- break;
- case OPENMODE_BITMAP:
- return(OnOpenBitmap());
- break;
- case OPENMODE_CAPTURE:
- return(OnOpenCapture());
- break;
- case OPENMODE_PASTE:
- return(OnOpenPaste());
- break;
- default:
- break;
- }
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
-
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoDoc serialization
-
- void CMfcdemoDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoDoc diagnostics
-
- #ifdef _DEBUG
- void CMfcdemoDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
-
- void CMfcdemoDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoDoc commands
-
-
- #ifdef WIN32
- BOOL CMfcdemoDoc::OnOpenDocument(LPCTSTR lpszPathName)
- #else
- BOOL CMfcdemoDoc::OnOpenDocument(const char *lpszPathName)
- #endif
- {
- COpenOptDlg dlg;
- int nRet;
- if (!CDocument::OnOpenDocument(lpszPathName))
- return FALSE;
-
- if(dlg.DoModal() == IDOK)
- {
- nRet = m_Lead.Load(lpszPathName, dlg.m_nBitsPerPixel, dlg.m_nPage, -1);
- if(nRet)
- {
- theApp.DisplayLEADError(nRet);
- return(FALSE);
- }
- return(TRUE);
- }
- return(FALSE);
- }
-
- void CMfcdemoDoc::OnCloseDocument()
- {
- CDocument::OnCloseDocument();
- }
-
-
-
- #ifdef WIN32
- BOOL CMfcdemoDoc::OnSaveDocument(LPCTSTR lpszPathName)
- #else
- BOOL CMfcdemoDoc::OnSaveDocument(const char* lpszPathName)
- #endif
- {
- CSaveOptDlg dlg;
- int nRet;
-
- dlg.m_nBitsPerPixel = m_Lead.GetBitmapBits();
- if(dlg.DoModal() == IDOK)
- {
- nRet = m_Lead.Save((LPSTR) lpszPathName, dlg.m_nFormat, dlg.m_nBitsPerPixel, dlg.m_nQFactor, dlg.m_fAppend);
- if(nRet)
- {
- theApp.DisplayLEADError(nRet);
- return(FALSE);
- }
- SetModifiedFlag(FALSE);
- return(TRUE);
- }
- return(FALSE);
- }
-
- BOOL CMfcdemoDoc::OnOpenCapture()
- {
- theApp.m_pMainWnd->ShowWindow (SW_HIDE);
- theApp.m_pMainWnd->UpdateWindow ();
- #ifdef WIN32
- Sleep(1000);
- #else
- Yield ();
- #endif
- CClientDC cdc(theApp.m_pMainWnd->GetDesktopWindow());
- m_Lead.Capture((OLE_HANDLE) cdc.m_hDC, 0.0f, 0.0f,
- (float) cdc.GetDeviceCaps (HORZRES), (float) cdc.GetDeviceCaps (VERTRES));
- theApp.m_pMainWnd->ShowWindow (SW_SHOW);
- return(TRUE);
- }
-
- BOOL CMfcdemoDoc::OnOpenPaste()
- {
- m_Lead.Paste(0);
- return(TRUE);
- }
-
- BOOL CMfcdemoDoc::OnOpenBitmap()
- {
- m_Lead.SetBitmap(theApp.m_Bitmap);
- return(TRUE);
- }
-
- BOOL CMfcdemoDoc::OnOpenTwain()
- {
- if(m_Lead.TwainAcquire((OLE_HANDLE) theApp.m_pMainWnd->m_hWnd))
- return(FALSE);
- return(TRUE);
- }
-
- BOOL CMfcdemoDoc::OnOpenColorMerge()
- {
- CColorMergeDlg dlg(NULL,this);
-
- if(dlg.DoModal() == IDOK)
- {
- int i;
- for(i = 0; i < 4; i++)
- m_Lead.SetColorPlanes(i, ((CMfcdemoDoc*)dlg.m_pDocument[i])->m_Lead.GetBitmap());
- m_Lead.ColorMerge(dlg.m_dwFlags);
- for(i = 0; i < 4; i++)
- m_Lead.SetColorPlanes(i, 0);
- return(TRUE);
- }
- return(FALSE);
- }
-
-