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

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