home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / VFORM.ZIP / Samples / vfTest / MorphView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-10  |  6.1 KB  |  233 lines

  1. // -------------------------------------------------------------------------
  2. // Copyright @ 1997 TCK Software, Incorporated
  3. // All Rights Reserved
  4. // -------------------------------------------------------------------------
  5. // PersonView.cpp : implementation of the CMorphView class
  6. //
  7.  
  8. #include "stdafx.h"
  9. #include "vfTest.h"
  10.  
  11. #include "vfTestDoc.h"
  12. #include "MorphView.h"
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. #define IDC_VFORM    100
  21. #define IDC_VFORM2    101
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CMorphView
  25.  
  26. IMPLEMENT_DYNCREATE(CMorphView, CView)
  27.  
  28. BEGIN_MESSAGE_MAP(CMorphView, CView)
  29.     //{{AFX_MSG_MAP(CMorphView)
  30.     ON_WM_CREATE()
  31.     ON_WM_ERASEBKGND()
  32.     ON_WM_SIZE()
  33.     ON_WM_SETFOCUS()
  34.     ON_COMMAND(ID_FILE_PRINT_SCREEN, OnFilePrintScreen)
  35.     ON_COMMAND(ID_FILE_PRINT_ALL, OnFilePrintAll)
  36.     ON_COMMAND(ID_FILE_PRINT_SELECTED, OnFilePrintSelected)
  37.     //}}AFX_MSG_MAP
  38.     // Standard printing commands
  39.     ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  40.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  41.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  42. END_MESSAGE_MAP()
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CMorphView construction/destruction
  46.  
  47. CMorphView::CMorphView()
  48. {
  49.     // TODO: add construction code here
  50.  
  51. }
  52.  
  53. CMorphView::~CMorphView()
  54. {
  55. }
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CMorphView drawing
  59.  
  60. void CMorphView::OnDraw(CDC* pDC)
  61. {
  62.     CVfTestDoc* pDoc = GetDocument();
  63.     ASSERT_VALID(pDoc);
  64. }
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CMorphView printing
  68.  
  69. void CMorphView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
  70. {
  71.     m_vForm.DoPrint(pDC, pInfo);    
  72.     // CView::OnPrint(pDC, pInfo);
  73. }
  74.  
  75. BOOL CMorphView::OnPreparePrinting(CPrintInfo* pInfo)
  76. {
  77.     return m_vForm.DoPreparePrinting(this, pInfo);
  78.     // return DoPreparePrinting(pInfo);
  79. }
  80.  
  81. void CMorphView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  82. {
  83.     // Set the page info again, since the user may have changed the printer since
  84.     // we set it up in OnPreparePrinting
  85.     m_vForm.CalcPageInfo(pDC, pInfo);
  86. }
  87.  
  88. void CMorphView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  89. {
  90.     // TODO: add cleanup after printing
  91. }
  92.  
  93. void CMorphView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
  94. {
  95.     CView::OnPrepareDC(pDC, pInfo);
  96.     m_vForm.DoPrepareDC(pDC, pInfo);
  97. }
  98.  
  99. void CMorphView::OnFilePrintScreen() 
  100. {
  101.     m_vForm.PrintStyle(VFPRINT_SCREEN);
  102.     CView::OnFilePrintPreview();
  103. }
  104.  
  105. void CMorphView::OnFilePrintAll() 
  106. {
  107.     m_vForm.PrintStyle(VFPRINT_ALL);
  108.     CView::OnFilePrintPreview();
  109. }
  110.  
  111. void CMorphView::OnFilePrintSelected() 
  112. {
  113.     m_vForm.PrintStyle(VFPRINT_SELECTED);
  114.     CView::OnFilePrintPreview();    
  115. }
  116.  
  117. /////////////////////////////////////////////////////////////////////////////
  118. // CMorphView diagnostics
  119.  
  120. #ifdef _DEBUG
  121. void CMorphView::AssertValid() const
  122. {
  123.     CView::AssertValid();
  124. }
  125.  
  126. void CMorphView::Dump(CDumpContext& dc) const
  127. {
  128.     CView::Dump(dc);
  129. }
  130.  
  131. CVfTestDoc* CMorphView::GetDocument() // non-debug version is inline
  132. {
  133.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVfTestDoc)));
  134.     return (CVfTestDoc*)m_pDocument;
  135. }
  136. #endif //_DEBUG
  137.  
  138. void CMorphView::ResetPalette()
  139. {
  140.     m_palMsgHandler.DoRealizePalette(TRUE);
  141. }
  142.  
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CMorphView message handlers
  145.  
  146. int CMorphView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  147. {
  148.     int rc;
  149.     CRect rect(10, 10, 400, 400);
  150.  
  151.     if (CView::OnCreate(lpCreateStruct) == -1)
  152.         return -1;
  153.  
  154.     m_vForm.SetPalMH(&m_palMsgHandler);
  155.     rc = m_vForm.Create(_T("VForm"), rect, this, IDC_VFORM);
  156.     if(!rc)
  157.         MessageBox(_T("Could not create VForm"), _T("Error")); 
  158.  
  159. /*  ---- Example of creating 2 VForms in same window ---
  160.     m_vForm.Register();
  161.     rc = m_vForm.CreateEx(WS_EX_CLIENTEDGE,
  162.             m_vForm.ClassName(), _T("VForm"),
  163.             WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL,
  164.             10, 10, 400, 400,
  165.             this->GetSafeHwnd(),(HMENU)IDC_VFORM);
  166.  
  167.  
  168.     rc = m_vForm2.CreateEx(WS_EX_CLIENTEDGE,
  169.             m_vForm.ClassName(), _T("VForm2"),
  170.             WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL,
  171.             415, 10, 400, 340,
  172.             this->GetSafeHwnd(),(HMENU)IDC_VFORM2);
  173.     if(!rc)
  174.         MessageBox(_T("Could not create form 2"), _T("Error")); 
  175. */
  176.     return 0;
  177. }
  178.  
  179.  
  180. // -------------------------------------------------------------------------
  181. // OnEraseBkgnd - overridden to draw gray background where VForm does not fit
  182. //  on the bottom -> VForm will always be a row heigh multiple + header and
  183. //  footer height.  If the window height is not on one of these multiples, a
  184. //  small area will be displayed below the footer.  
  185. //  This just makes that area gray.
  186. // -------------------------------------------------------------------------
  187. BOOL CMorphView::OnEraseBkgnd(CDC* pDC) 
  188. {
  189. /*    // --- Only use if using snap resize 
  190.     // --- this will cause flicker when sizing
  191.     CBrush backBrush(GetSysColor(COLOR_3DFACE));
  192.     CBrush* pOldBrush = pDC->SelectObject(&backBrush);
  193.  
  194.     CRect rect;
  195.     pDC->GetClipBox(&rect);     // Erase the area needed
  196.     pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
  197.     pDC->SelectObject(pOldBrush);
  198. */
  199.     return TRUE;    
  200. //    return CView::OnEraseBkgnd(pDC);
  201. }
  202.  
  203. void CMorphView::OnSize(UINT nType, int cx, int cy) 
  204. {
  205.     CView::OnSize(nType, cx, cy);
  206.     
  207.     m_vForm.ResizeToParent();
  208. }
  209.  
  210. void CMorphView::OnSetFocus(CWnd* pOldWnd) 
  211. {
  212.     // CView::OnSetFocus(pOldWnd);
  213.     m_vForm.SetFocus();
  214. }
  215.  
  216. void CMorphView::OnInitialUpdate() 
  217. {
  218.     CView::OnInitialUpdate();
  219.  
  220.     VBitmap* pBmp = m_vForm.GetBmp();
  221.     if (pBmp) 
  222.     {
  223.         if (!m_palMsgHandler.IsHooked())
  224.             m_palMsgHandler.Install(this, pBmp->GetPalette());
  225.  
  226.         // The following line is required because MFC does not send
  227.         // WM_INITIALUPDATE through normal channels. Only realize in
  228.         // foreground if I have the focus (could be updating all views
  229.         // from OnFontChange)
  230.         m_palMsgHandler.DoRealizePalette(m_hWnd==::GetFocus());
  231.     }    
  232. }
  233.