home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / CHKBOOK.PAK / BOOKVW.CPP next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.3 KB  |  161 lines

  1. // bookvw.cpp : implementation of the CBookView class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13.  
  14. #include "stdafx.h"
  15. #include "chkbook.h"
  16. #include <stdlib.h>
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. IMPLEMENT_DYNCREATE(CBookView, CRowView)
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. CBookView::CBookView()
  27. {
  28. }
  29.  
  30. /////////////////////////////////////////////////////////////////////////////
  31. // Overrides of CView and CRowView
  32.  
  33. void CBookView::OnUpdate(CView*, LPARAM lHint, CObject* pHint)
  34. {
  35.     // OnUpdate() is called whenever the document has changed and,
  36.     // therefore, the view needs to redisplay some or all of itself.
  37.  
  38.     if (DYNAMIC_DOWNCAST(CFixedLenRecHint, pHint) != NULL)
  39.     {
  40.         int nRow = LOWORD(lHint);
  41.         UpdateRow(nRow);
  42.     }
  43.     else
  44.     {
  45.         Invalidate();
  46.     }
  47. }
  48.  
  49. void CBookView::GetRowWidthHeight(CDC* pDC, int& nRowWidth, int& nRowHeight)
  50. {
  51.     TEXTMETRIC tm;
  52.     pDC->GetTextMetrics(&tm);
  53.     nRowWidth = tm.tmAveCharWidth * ROW_WIDTH;
  54.     nRowHeight = tm.tmHeight * 2; // 2 lines of text
  55. }
  56.  
  57. int CBookView::GetActiveRow()
  58. {
  59.     CChkBookDoc* pDoc = GetDocument();
  60.     return (pDoc->GetActiveCheckNo() - pDoc->GetFirstCheckNo());
  61. }
  62.  
  63. int CBookView::GetRowCount()
  64. {
  65.     CChkBookDoc* pDoc = GetDocument();
  66.     return (pDoc->GetLastCheckNo() - pDoc->GetFirstCheckNo() + 1);
  67. }
  68.  
  69. void CBookView::ChangeSelectionNextRow(BOOL bNext)
  70. {
  71.     GetDocument()->ChangeSelectionNextCheckNo(bNext);
  72. }
  73.  
  74. void CBookView::ChangeSelectionToRow(int nRow)
  75. {
  76.     CChkBookDoc* pDoc = GetDocument();
  77.     pDoc->ChangeSelectionToCheckNo(nRow + pDoc->GetFirstCheckNo());
  78. }
  79.  
  80. void CBookView::OnDrawRow(CDC* pDC, int nRow, int y, BOOL bSelected)
  81. {
  82.     // Prepare for highlighting or un-highlighting the check, depending
  83.     // on whether it is the currently selected check or not.  And
  84.     // paint the background (behind the text) accordingly.
  85.     CBrush brushBackground;
  86.  
  87. #ifndef _MAC
  88.     // save colors for drawing selected item on the screen
  89.     COLORREF crOldText = 0;
  90.     COLORREF crOldBackground = 0;
  91. #endif
  92.  
  93.     if (!pDC->IsPrinting())
  94.     {
  95. #ifndef _MAC
  96.         if (bSelected)
  97.         {
  98.             brushBackground.CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
  99.             crOldBackground = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
  100.             crOldText = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
  101.         }
  102.         else
  103. #endif
  104.         {
  105.             brushBackground.CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
  106.         }
  107.  
  108.         CRect rectSelection;
  109.         pDC->GetClipBox(&rectSelection);
  110.         rectSelection.top = y;
  111.         rectSelection.bottom = y + m_nRowHeight;
  112.         pDC->FillRect(&rectSelection, &brushBackground);
  113.     }
  114.  
  115.     // Get the data for the specific check.
  116.     DWORD dwCents;
  117.     CString strDate, strPayTo, strMemo;
  118.     int nCheckNo = nRow + GetDocument()->GetFirstCheckNo();
  119.  
  120.     GetDocument()->GetCheck(nCheckNo, dwCents, strPayTo, strDate, strMemo);
  121.  
  122.     TEXTMETRIC tm;
  123.     pDC->GetTextMetrics(&tm);
  124.  
  125.     // Display the check in two lines of text.
  126.     TCHAR num[10];
  127.     // line 1
  128.     wsprintf(num, _T("%u"), nCheckNo);
  129.     pDC->TextOut(CHECKNO_COL*tm.tmAveCharWidth, y, num, _tcslen(num));
  130.     pDC->TextOut(DATE_COL*tm.tmAveCharWidth, y, strDate);
  131.     pDC->TextOut(PAYTO_COL*tm.tmAveCharWidth, y, strPayTo);
  132.     CString strDollarCents;
  133.     strDollarCents = GetDollarsCentsFormatted(dwCents);
  134.     // right justify the check dollar/cent amount
  135.     pDC->TextOut(
  136.         (AMOUNT_COL + AMOUNT_LEN - strDollarCents.GetLength()) * tm.tmAveCharWidth,
  137.         y,
  138.         strDollarCents);
  139.     // line 2
  140.     pDC->TextOut(MEMO_COL*tm.tmAveCharWidth, y + tm.tmHeight, strMemo);
  141.  
  142. #ifdef _MAC
  143.     // Highlight the selection
  144.     if (!pDC->IsPrinting() && bSelected)
  145.     {
  146.         CRect rectSelection;
  147.         pDC->GetClipBox(&rectSelection);
  148.         rectSelection.top = y;
  149.         rectSelection.bottom = y + m_nRowHeight;
  150.         ::HilightRect(pDC->m_hDC, &rectSelection);
  151.     }
  152. #else
  153.     // Restore the DC.
  154.     if (!pDC->IsPrinting() && bSelected)
  155.     {
  156.         pDC->SetBkColor(crOldBackground);
  157.         pDC->SetTextColor(crOldText);
  158.     }
  159. #endif
  160. }
  161.