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

  1. // -------------------------------------------------------------------------
  2. // Copyright @ 1997 TCK Software, Incorporated
  3. // All Rights Reserved
  4. // -------------------------------------------------------------------------
  5.  
  6. // VfHexView.cpp : implementation of the CVfHexView class
  7. //
  8.  
  9. #include "stdafx.h"
  10. #include "VfHex.h"
  11.  
  12. #include "VfHexDoc.h"
  13. #include "VfHexView.h"
  14.  
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CVfHexView
  23.  
  24. IMPLEMENT_DYNCREATE(CVfHexView, CView)
  25.  
  26. BEGIN_MESSAGE_MAP(CVfHexView, CView)
  27.     //{{AFX_MSG_MAP(CVfHexView)
  28.     ON_WM_CREATE()
  29.     ON_WM_ERASEBKGND()
  30.     ON_WM_SIZE()
  31.     ON_WM_SETFOCUS()
  32.     ON_COMMAND(ID_FILE_PRINT_SCREEN, OnFilePrintScreen)
  33.     ON_COMMAND(ID_FILE_PRINT_ALL, OnFilePrintAll)
  34.     ON_COMMAND(ID_FILE_PRINT_SELECTED, OnFilePrintSelected)
  35.     //}}AFX_MSG_MAP
  36.     // Standard printing commands
  37.     ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  38.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  39.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  40. END_MESSAGE_MAP()
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CVfHexView construction/destruction
  44.  
  45. CVfHexView::CVfHexView()
  46. {
  47.     // TODO: add construction code here
  48.  
  49. }
  50.  
  51. CVfHexView::~CVfHexView()
  52. {
  53. }
  54.  
  55. BOOL CVfHexView::PreCreateWindow(CREATESTRUCT& cs)
  56. {
  57.     // TODO: Modify the Window class or styles here by modifying
  58.     //  the CREATESTRUCT cs
  59.  
  60.     return CView::PreCreateWindow(cs);
  61. }
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CVfHexView drawing
  65.  
  66. void CVfHexView::OnDraw(CDC* pDC)
  67. {
  68.     CVfHexDoc* pDoc = GetDocument();
  69.     ASSERT_VALID(pDoc);
  70.  
  71.     // TODO: add draw code for native data here
  72. }
  73.  
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CVfHexView printing
  76.  
  77. void CVfHexView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
  78. {
  79.     m_vfFile.DoPrint(pDC, pInfo);    
  80.     // CView::OnPrint(pDC, pInfo);
  81. }
  82.  
  83.  
  84. BOOL CVfHexView::OnPreparePrinting(CPrintInfo* pInfo)
  85. {
  86.     return m_vfFile.DoPreparePrinting(this, pInfo);
  87.     // return DoPreparePrinting(pInfo);
  88. }
  89.  
  90. void CVfHexView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  91. {
  92.     // Set the page info again, since the user may have changed the printer since
  93.     // we set it up in OnPreparePrinting
  94.     m_vfFile.CalcPageInfo(pDC, pInfo);
  95. }
  96.  
  97. void CVfHexView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  98. {
  99.     // TODO: add cleanup after printing
  100. }
  101.  
  102. void CVfHexView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
  103. {
  104.     CView::OnPrepareDC(pDC, pInfo);
  105.     m_vfFile.DoPrepareDC(pDC, pInfo);
  106. }
  107.  
  108. void CVfHexView::OnFilePrintScreen() 
  109. {
  110.     m_vfFile.PrintStyle(VFPRINT_SCREEN);
  111.     CView::OnFilePrintPreview();
  112. }
  113.  
  114. void CVfHexView::OnFilePrintAll() 
  115. {
  116.     m_vfFile.PrintStyle(VFPRINT_ALL);
  117.     CView::OnFilePrintPreview();
  118. }
  119.  
  120. void CVfHexView::OnFilePrintSelected() 
  121. {
  122.     m_vfFile.PrintStyle(VFPRINT_SELECTED);
  123.     CView::OnFilePrintPreview();
  124. }
  125.  
  126. /////////////////////////////////////////////////////////////////////////////
  127. // CVfHexView diagnostics
  128.  
  129. #ifdef _DEBUG
  130. void CVfHexView::AssertValid() const
  131. {
  132.     CView::AssertValid();
  133. }
  134.  
  135. void CVfHexView::Dump(CDumpContext& dc) const
  136. {
  137.     CView::Dump(dc);
  138. }
  139.  
  140. CVfHexDoc* CVfHexView::GetDocument() // non-debug version is inline
  141. {
  142.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVfHexDoc)));
  143.     return (CVfHexDoc*)m_pDocument;
  144. }
  145. #endif //_DEBUG
  146.  
  147. /////////////////////////////////////////////////////////////////////////////
  148. // CVfHexView message handlers
  149.  
  150. int CVfHexView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  151. {
  152.     if (CView::OnCreate(lpCreateStruct) == -1)
  153.         return -1;
  154.  
  155.     int rc;
  156.     CRect rectFileVF;
  157.  
  158.     GetClientRect(rectFileVF);
  159.     m_vfFile.AllowAdd(FALSE);        // No adding of records
  160.     m_vfFile.Init(GetDocument());
  161.  
  162.     rc = m_vfFile.Create("File VForm", rectFileVF, this, IDC_FILE_VFORM);
  163.     if(!rc)
  164.         MessageBox("Could not create File VForm", "Error"); 
  165.  
  166.     m_vfFile.SetFocus();
  167.     return 0;
  168. }
  169.  
  170. BOOL CVfHexView::OnEraseBkgnd(CDC* pDC) 
  171. {
  172.     CBrush backBrush(GetSysColor(COLOR_3DFACE));
  173.     CBrush* pOldBrush = pDC->SelectObject(&backBrush);
  174.  
  175.     CRect rect;
  176.     pDC->GetClipBox(&rect);     // Erase the area needed
  177.     pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
  178.     pDC->SelectObject(pOldBrush);
  179.  
  180.     return TRUE;    
  181. }
  182.  
  183. void CVfHexView::OnSize(UINT nType, int cx, int cy) 
  184. {
  185.     CView::OnSize(nType, cx, cy);
  186.     m_vfFile.ResizeToParent();
  187. }
  188.  
  189. void CVfHexView::OnSetFocus(CWnd* pOldWnd) 
  190. {
  191.     m_vfFile.SetFocus();
  192. }
  193.  
  194. void CVfHexView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
  195. {
  196.     CVfHexDoc *pDoc = GetDocument();
  197.     long nRecCount = pDoc->RecCountHigh();
  198.     int nRecSize = pDoc->RecSize();
  199.     m_vfFile.ResetWidth(nRecSize);
  200.     m_vfFile.ResetNumRows(nRecCount);
  201.     // m_vfFile.RefreshData();                    // refresh current rows data
  202. }
  203.  
  204.  
  205. void CVfHexView::OnInitialUpdate() 
  206. {
  207.     static BOOL bFirst = TRUE;
  208.  
  209.     CView::OnInitialUpdate();
  210.     
  211.     if(bFirst)
  212.     {
  213.         bFirst = FALSE;
  214.         CVfHexDoc *pDoc = GetDocument();
  215.         pDoc->InitTB();                        // Initialize toolbar controls
  216.     }
  217. }
  218.  
  219.