home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / leadtools / ocx32.lt / MFCDEDOC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-19  |  5.2 KB  |  228 lines

  1. // mfcdedoc.cpp : implementation of the CMfcdemoDoc class
  2. // Copyright (C) 1996 LEAD Technologies, Inc.
  3. // All rights reserved.
  4.  
  5. #include "stdafx.h"
  6. #include "mfcdemo.h"
  7. #include "colormer.h"
  8. #include "openopt.h"
  9. #include "saveopt.h"
  10.  
  11. #include "mfcdedoc.h"
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static char BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. extern CMfcdemoApp theApp;
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CMfcdemoDoc
  21.  
  22. IMPLEMENT_DYNCREATE(CMfcdemoDoc, CDocument)
  23.  
  24. BEGIN_MESSAGE_MAP(CMfcdemoDoc, CDocument)
  25.    //{{AFX_MSG_MAP(CMfcdemoDoc)
  26.       // NOTE - the ClassWizard will add and remove mapping macros here.
  27.       //    DO NOT EDIT what you see in these blocks of generated code!
  28.    //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CMfcdemoDoc construction/destruction
  33.  
  34. CMfcdemoDoc::CMfcdemoDoc()
  35. {
  36.    CRect rcClient;
  37.    theApp.m_pMainWnd->GetClientRect(rcClient);
  38.  
  39.    m_Lead.CreateInstance(&m_LeadContainer, theApp.m_pMainWnd, rcClient);
  40.    m_Lead.ShowWindow(SW_HIDE);
  41.    m_Lead.SetAutoRepaint(FALSE);
  42.     /* m_Lead2 is used for supporting the floater bitmap in the view */
  43.    m_Lead2.CreateInstance(&m_LeadContainer, theApp.m_pMainWnd, rcClient);
  44.    m_Lead2.ShowWindow(SW_HIDE);
  45.    m_Lead2.SetAutoRepaint(FALSE);
  46.    m_LeadUndo.CreateInstance(&m_LeadContainer, theApp.m_pMainWnd, rcClient);
  47.    m_LeadUndo.ShowWindow(SW_HIDE);
  48.    m_LeadUndo.SetAutoRepaint(FALSE);
  49. }
  50.  
  51. CMfcdemoDoc::~CMfcdemoDoc()
  52. {
  53. }
  54.  
  55. BOOL CMfcdemoDoc::OnNewDocument()
  56. {
  57.    if (!CDocument::OnNewDocument())
  58.       return FALSE;
  59.  
  60.  
  61.    switch(theApp.m_nOpenMode)
  62.    {
  63.    case OPENMODE_COLORMERGE:
  64.           return(OnOpenColorMerge());
  65.           break;
  66.    case OPENMODE_TWAIN:
  67.           return(OnOpenTwain());
  68.           break;
  69.    case OPENMODE_BITMAP:
  70.           return(OnOpenBitmap());
  71.           break;
  72.    case OPENMODE_CAPTURE:
  73.           return(OnOpenCapture());
  74.           break;
  75.    case OPENMODE_PASTE:
  76.           return(OnOpenPaste());
  77.           break;
  78.    default:
  79.           break;
  80.    }
  81.    // TODO: add reinitialization code here
  82.    // (SDI documents will reuse this document)
  83.  
  84.    return TRUE;
  85. }
  86.  
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CMfcdemoDoc serialization
  89.  
  90. void CMfcdemoDoc::Serialize(CArchive& ar)
  91. {
  92.    if (ar.IsStoring())
  93.    {
  94.       // TODO: add storing code here
  95.    }
  96.    else
  97.    {
  98.       // TODO: add loading code here
  99.    }
  100. }
  101.  
  102. /////////////////////////////////////////////////////////////////////////////
  103. // CMfcdemoDoc diagnostics
  104.  
  105. #ifdef _DEBUG
  106. void CMfcdemoDoc::AssertValid() const
  107. {
  108.    CDocument::AssertValid();
  109. }
  110.  
  111. void CMfcdemoDoc::Dump(CDumpContext& dc) const
  112. {
  113.    CDocument::Dump(dc);
  114. }
  115. #endif //_DEBUG
  116.  
  117. /////////////////////////////////////////////////////////////////////////////
  118. // CMfcdemoDoc commands
  119.  
  120.  
  121. #ifdef WIN32
  122. BOOL CMfcdemoDoc::OnOpenDocument(LPCTSTR lpszPathName) 
  123. #else
  124. BOOL CMfcdemoDoc::OnOpenDocument(const char *lpszPathName) 
  125. #endif
  126. {
  127.    COpenOptDlg dlg;
  128.    int nRet;
  129.    if (!CDocument::OnOpenDocument(lpszPathName))
  130.       return FALSE;
  131.  
  132.    if(dlg.DoModal() == IDOK)
  133.    {
  134.       nRet = m_Lead.Load(lpszPathName, dlg.m_nBitsPerPixel, dlg.m_nPage, -1);
  135.       if(nRet)
  136.       {
  137.          theApp.DisplayLEADError(nRet);
  138.          return(FALSE);
  139.       }
  140.       return(TRUE);
  141.    }
  142.    return(FALSE);
  143. }
  144.  
  145. void CMfcdemoDoc::OnCloseDocument() 
  146. {
  147.    CDocument::OnCloseDocument();
  148. }
  149.  
  150.  
  151.  
  152. #ifdef WIN32
  153. BOOL CMfcdemoDoc::OnSaveDocument(LPCTSTR lpszPathName) 
  154. #else
  155. BOOL CMfcdemoDoc::OnSaveDocument(const char* lpszPathName) 
  156. #endif
  157. {
  158.    CSaveOptDlg dlg;
  159.    int nRet;
  160.    
  161.    dlg.m_nBitsPerPixel = m_Lead.GetBitmapBits();
  162.    if(dlg.DoModal() == IDOK)
  163.    {
  164.       nRet = m_Lead.Save((LPSTR) lpszPathName, dlg.m_nFormat, dlg.m_nBitsPerPixel, dlg.m_nQFactor, dlg.m_fAppend);
  165.       if(nRet)
  166.       {
  167.          theApp.DisplayLEADError(nRet);
  168.          return(FALSE);
  169.       }
  170.       SetModifiedFlag(FALSE);
  171.       return(TRUE);
  172.    }
  173.    return(FALSE);
  174. }
  175.  
  176. BOOL CMfcdemoDoc::OnOpenCapture() 
  177. {
  178.    theApp.m_pMainWnd->ShowWindow (SW_HIDE);
  179.    theApp.m_pMainWnd->UpdateWindow ();
  180. #ifdef WIN32
  181.    Sleep(1000);
  182. #else
  183.    Yield ();
  184. #endif
  185.    CClientDC cdc(theApp.m_pMainWnd->GetDesktopWindow());
  186.    m_Lead.Capture((OLE_HANDLE) cdc.m_hDC, 0.0f, 0.0f,
  187.          (float) cdc.GetDeviceCaps (HORZRES), (float) cdc.GetDeviceCaps (VERTRES));
  188.    theApp.m_pMainWnd->ShowWindow (SW_SHOW);
  189.    return(TRUE);        
  190. }
  191.  
  192. BOOL CMfcdemoDoc::OnOpenPaste() 
  193. {
  194.    m_Lead.Paste(0);
  195.    return(TRUE);        
  196. }
  197.  
  198. BOOL CMfcdemoDoc::OnOpenBitmap()
  199. {
  200.    m_Lead.SetBitmap(theApp.m_Bitmap);
  201.    return(TRUE);        
  202. }
  203.  
  204. BOOL CMfcdemoDoc::OnOpenTwain()
  205. {
  206.    if(m_Lead.TwainAcquire((OLE_HANDLE) theApp.m_pMainWnd->m_hWnd))
  207.       return(FALSE);        
  208.    return(TRUE);
  209. }
  210.  
  211. BOOL CMfcdemoDoc::OnOpenColorMerge()
  212. {
  213.    CColorMergeDlg dlg(NULL,this);
  214.  
  215.    if(dlg.DoModal() == IDOK)
  216.    {
  217.       int i;
  218.       for(i = 0; i < 4; i++)
  219.          m_Lead.SetColorPlanes(i, ((CMfcdemoDoc*)dlg.m_pDocument[i])->m_Lead.GetBitmap());
  220.       m_Lead.ColorMerge(dlg.m_dwFlags);
  221.       for(i = 0; i < 4; i++)
  222.          m_Lead.SetColorPlanes(i, 0);
  223.       return(TRUE);
  224.    }
  225.    return(FALSE);
  226. }
  227.  
  228.