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

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