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

  1. // VfbExView.cpp : implementation of the CVfbExView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "VfbEx.h"
  6.  
  7. #include "VfbExDoc.h"
  8. #include "VfbExView.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CVfbExView
  18.  
  19. IMPLEMENT_DYNCREATE(CVfbExView, CScrollView)
  20.  
  21. BEGIN_MESSAGE_MAP(CVfbExView, CScrollView)
  22.     //{{AFX_MSG_MAP(CVfbExView)
  23.     ON_WM_CREATE()
  24.     ON_WM_SIZE()
  25.     ON_WM_SETFOCUS()
  26.     ON_WM_ERASEBKGND()
  27.     ON_COMMAND(ID_PRINTSCRN_ALL, OnPrintscrnAll)
  28.     ON_COMMAND(ID_PRINTSCRN_SEL, OnPrintscrnSel)
  29.     ON_COMMAND(ID_PRINTSCRN_SCREEN, OnPrintscrnScreen)
  30.     ON_COMMAND(ID_PRINTRPT_ALL, OnPrintrptAll)
  31.     ON_COMMAND(ID_PRINTRPT_SEL, OnPrintrptSel)
  32.     ON_COMMAND(ID_PRINTRPT_SCREEN, OnPrintrptScreen)
  33.     ON_COMMAND(ID_PREVIEWSCRN_ALL, OnPreviewscrnAll)
  34.     ON_COMMAND(ID_PREVIEWSCRN_SEL, OnPreviewscrnSel)
  35.     ON_COMMAND(ID_PREVIEWSCRN_SCREEN, OnPreviewscrnScreen)
  36.     ON_COMMAND(ID_PREVIEWRPT_ALL, OnPreviewrptAll)
  37.     ON_COMMAND(ID_PREVIEWRPT_SEL, OnPreviewrptSel)
  38.     ON_COMMAND(ID_PREVIEWRPT_SCREEN, OnPreviewrptScreen)
  39.     ON_COMMAND(ID_VIEW_GRIDMODE, OnViewGridmode)
  40.     ON_UPDATE_COMMAND_UI(ID_VIEW_GRIDMODE, OnUpdateViewGridmode)
  41.     //}}AFX_MSG_MAP
  42.     // Standard printing commands
  43.     ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
  44.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
  45.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
  46. END_MESSAGE_MAP()
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CVfbExView construction/destruction
  50.  
  51. CVfbExView::CVfbExView()
  52. {
  53.     m_vForm.PrintStyle(VFPRINT_ALL);
  54. }
  55.  
  56. CVfbExView::~CVfbExView()
  57. {
  58. }
  59.  
  60. BOOL CVfbExView::PreCreateWindow(CREATESTRUCT& cs)
  61. {
  62.     // TODO: Modify the Window class or styles here by modifying
  63.     //  the CREATESTRUCT cs
  64.  
  65.     return CScrollView::PreCreateWindow(cs);
  66. }
  67.  
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CVfbExView drawing
  70.  
  71. void CVfbExView::OnDraw(CDC* pDC)
  72. {
  73.     CVfbExDoc* pDoc = GetDocument();
  74.     ASSERT_VALID(pDoc);
  75.  
  76.     // TODO: add draw code for native data here
  77. }
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CVfbExView printing
  81. void CVfbExView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
  82. {
  83.     m_vForm.DoPrint(pDC, pInfo);    
  84.     // CScrollView::OnPrint(pDC, pInfo);
  85. }
  86.  
  87. BOOL CVfbExView::OnPreparePrinting(CPrintInfo* pInfo)
  88. {
  89.     return m_vForm.DoPreparePrinting(this, pInfo);
  90.     // return DoPreparePrinting(pInfo);
  91. }
  92.  
  93. void CVfbExView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  94. {
  95.     // Set the page info again, since the user may have changed
  96.     // the printer since we set it up in OnPreparePrinting
  97.     m_vForm.CalcPageInfo(pDC, pInfo);
  98. }
  99.  
  100. void CVfbExView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  101. {
  102.     // TODO: add cleanup after printing
  103. }
  104.  
  105. void CVfbExView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
  106. {
  107.     CScrollView::OnPrepareDC(pDC, pInfo);
  108.     m_vForm.DoPrepareDC(pDC, pInfo);
  109. }
  110.  
  111.  
  112. /////////////////////////////////////////////////////////////////////////////
  113. // CVfbExView diagnostics
  114.  
  115. #ifdef _DEBUG
  116. void CVfbExView::AssertValid() const
  117. {
  118.     CScrollView::AssertValid();
  119. }
  120.  
  121. void CVfbExView::Dump(CDumpContext& dc) const
  122. {
  123.     CScrollView::Dump(dc);
  124. }
  125.  
  126. CVfbExDoc* CVfbExView::GetDocument() // non-debug version is inline
  127. {
  128.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVfbExDoc)));
  129.     return (CVfbExDoc*)m_pDocument;
  130. }
  131. #endif //_DEBUG
  132.  
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CVfbExView message handlers
  135.  
  136. int CVfbExView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  137. {
  138.     if (CScrollView::OnCreate(lpCreateStruct) == -1)
  139.         return -1;
  140.  
  141.     CRect rect(10, 10, 400, 400);
  142.     if(!m_vForm.Create("TestVf", rect, this, 101))
  143.         AfxMessageBox("Could not create VForm"); 
  144.  
  145.     return 0;
  146. }
  147.  
  148. void CVfbExView::OnSize(UINT nType, int cx, int cy) 
  149. {
  150.     CScrollView::OnSize(nType, cx, cy);
  151.  
  152.     // Must be at position 0,0 before calling ResizeToParent
  153.     // - because ResizeToParent will move the VForm
  154.     if(m_nMapMode > 0)
  155.         ScrollToPosition(CPoint(0,0));
  156.     m_vForm.ResizeToParent();
  157.  
  158.     // Reset Scrolling if VForm size is larger than the view
  159.     // - This could happen if the View is smaller than the minimum form size
  160.     SetScrollByVForm();
  161. }
  162.  
  163. void CVfbExView::SetScrollByVForm() 
  164. {
  165.     CRect rc, rcVF;
  166.     GetClientRect(&rc);
  167.     m_vForm.GetWindowRect(&rcVF);
  168.     ScreenToClient(&rcVF);
  169.  
  170.     CSize sizeTotal(100, rcVF.Height());
  171.     CSize sizePage(100, rc.Height());
  172.     SetScrollSizes(MM_TEXT, sizeTotal, sizePage);
  173. }
  174.  
  175. void CVfbExView::OnSetFocus(CWnd* pOldWnd) 
  176. {
  177.     CScrollView::OnSetFocus(pOldWnd);
  178.     m_vForm.SetFocus();    
  179. }
  180.  
  181. BOOL CVfbExView::OnEraseBkgnd(CDC* pDC) 
  182. {
  183.     CRect rect, rcVF;
  184.  
  185.     // --- To avoid flicker, we will only draw where the child VForm is not
  186.     pDC->GetClipBox(&rect);
  187.     m_vForm.GetWindowRect(&rcVF);
  188.     ScreenToClient(&rcVF);
  189.  
  190.     if(rcVF.bottom >= rect.bottom)    return TRUE;    // Nothing to draw
  191.  
  192.     rect.top = rcVF.bottom;                            // Only draw what we need
  193.  
  194.     CBrush brBack(GetSysColor(COLOR_APPWORKSPACE));
  195.     pDC->FillRect(&rect, &brBack);
  196.  
  197.     return TRUE;                            // Eliminates Flicker when sizing
  198. }
  199.  
  200. BOOL CVfbExView::LoadVfbFile(LPCTSTR lpszPathName) 
  201. {
  202.     if(!m_vForm.LoadVfbFile(lpszPathName))
  203.         return FALSE;
  204.  
  205.     m_vForm.ResetFieldCount();                // Reset our field count
  206.  
  207.     // Reset Scrolling if VForm size is larger than the view
  208.     // - This could happen if the View smaller than the minimum form size
  209.     SetScrollByVForm();
  210.  
  211.     // Set our Color Palette (makes a big difference on 256 color displays)
  212.     CPalette* pPal = m_vForm.GetBackgroundPalette();
  213.     if (!m_palMsgHandler.IsHooked())
  214.         m_palMsgHandler.Install(this, pPal);
  215.     else
  216.         m_palMsgHandler.SetPalette(pPal);
  217.  
  218.     m_palMsgHandler.DoRealizePalette(TRUE);
  219.  
  220.     return TRUE;
  221. }
  222.  
  223. void CVfbExView::OnPrintscrnAll() 
  224. {
  225.     m_vForm.PrintStyle(VFPRINT_ALL);
  226.     m_vForm.UseRptForm(FALSE);
  227.     CScrollView::OnFilePrint();
  228. }
  229.  
  230. void CVfbExView::OnPrintscrnSel() 
  231. {
  232.     m_vForm.PrintStyle(VFPRINT_SELECTED);
  233.     m_vForm.UseRptForm(FALSE);
  234.     CScrollView::OnFilePrint();
  235. }
  236.  
  237. void CVfbExView::OnPrintscrnScreen() 
  238. {
  239.     m_vForm.PrintStyle(VFPRINT_SCREEN);
  240.     m_vForm.UseRptForm(FALSE);
  241.     CScrollView::OnFilePrint();
  242. }
  243.  
  244. void CVfbExView::OnPrintrptAll() 
  245. {
  246.     m_vForm.PrintStyle(VFPRINT_ALL);
  247.     m_vForm.UseRptForm(TRUE);
  248.     CScrollView::OnFilePrint();
  249. }
  250.  
  251. void CVfbExView::OnPrintrptSel() 
  252. {
  253.     m_vForm.PrintStyle(VFPRINT_SELECTED);
  254.     m_vForm.UseRptForm(TRUE);
  255.     CScrollView::OnFilePrint();
  256. }
  257.  
  258. void CVfbExView::OnPrintrptScreen() 
  259. {
  260.     m_vForm.PrintStyle(VFPRINT_SCREEN);
  261.     m_vForm.UseRptForm(TRUE);
  262.     CScrollView::OnFilePrint();
  263. }
  264.  
  265. void CVfbExView::OnPreviewscrnAll() 
  266. {
  267.     m_vForm.PrintStyle(VFPRINT_ALL);
  268.     m_vForm.UseRptForm(FALSE);
  269.     CScrollView::OnFilePrintPreview();
  270. }
  271.  
  272. void CVfbExView::OnPreviewscrnSel() 
  273. {
  274.     m_vForm.PrintStyle(VFPRINT_SELECTED);
  275.     m_vForm.UseRptForm(FALSE);
  276.     CScrollView::OnFilePrintPreview();
  277. }
  278.  
  279. void CVfbExView::OnPreviewscrnScreen() 
  280. {
  281.     m_vForm.PrintStyle(VFPRINT_SCREEN);
  282.     m_vForm.UseRptForm(FALSE);
  283.     CScrollView::OnFilePrintPreview();
  284. }
  285.  
  286. void CVfbExView::OnPreviewrptAll() 
  287. {
  288.     m_vForm.PrintStyle(VFPRINT_ALL);
  289.     m_vForm.UseRptForm(TRUE);
  290.     CScrollView::OnFilePrintPreview();
  291. }
  292.  
  293. void CVfbExView::OnPreviewrptSel() 
  294. {
  295.     m_vForm.PrintStyle(VFPRINT_SELECTED);
  296.     m_vForm.UseRptForm(TRUE);
  297.     CScrollView::OnFilePrintPreview();
  298. }
  299.  
  300. void CVfbExView::OnPreviewrptScreen() 
  301. {
  302.     m_vForm.PrintStyle(VFPRINT_SCREEN);
  303.     m_vForm.UseRptForm(TRUE);
  304.     CScrollView::OnFilePrintPreview();
  305. }
  306.  
  307. void CVfbExView::OnViewGridmode() 
  308. {
  309.     BOOL bNewMode = !m_vForm.GridMode();
  310.     m_vForm.GridMode(bNewMode);
  311. }
  312.  
  313. void CVfbExView::OnUpdateViewGridmode(CCmdUI* pCmdUI) 
  314. {
  315.     pCmdUI->SetCheck(m_vForm.GridMode());
  316. }
  317.