home *** CD-ROM | disk | FTP | other *** search
- // VfbExView.cpp : implementation of the CVfbExView class
- //
-
- #include "stdafx.h"
- #include "VfbEx.h"
-
- #include "VfbExDoc.h"
- #include "VfbExView.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CVfbExView
-
- IMPLEMENT_DYNCREATE(CVfbExView, CScrollView)
-
- BEGIN_MESSAGE_MAP(CVfbExView, CScrollView)
- //{{AFX_MSG_MAP(CVfbExView)
- ON_WM_CREATE()
- ON_WM_SIZE()
- ON_WM_SETFOCUS()
- ON_WM_ERASEBKGND()
- ON_COMMAND(ID_PRINTSCRN_ALL, OnPrintscrnAll)
- ON_COMMAND(ID_PRINTSCRN_SEL, OnPrintscrnSel)
- ON_COMMAND(ID_PRINTSCRN_SCREEN, OnPrintscrnScreen)
- ON_COMMAND(ID_PRINTRPT_ALL, OnPrintrptAll)
- ON_COMMAND(ID_PRINTRPT_SEL, OnPrintrptSel)
- ON_COMMAND(ID_PRINTRPT_SCREEN, OnPrintrptScreen)
- ON_COMMAND(ID_PREVIEWSCRN_ALL, OnPreviewscrnAll)
- ON_COMMAND(ID_PREVIEWSCRN_SEL, OnPreviewscrnSel)
- ON_COMMAND(ID_PREVIEWSCRN_SCREEN, OnPreviewscrnScreen)
- ON_COMMAND(ID_PREVIEWRPT_ALL, OnPreviewrptAll)
- ON_COMMAND(ID_PREVIEWRPT_SEL, OnPreviewrptSel)
- ON_COMMAND(ID_PREVIEWRPT_SCREEN, OnPreviewrptScreen)
- ON_COMMAND(ID_VIEW_GRIDMODE, OnViewGridmode)
- ON_UPDATE_COMMAND_UI(ID_VIEW_GRIDMODE, OnUpdateViewGridmode)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CVfbExView construction/destruction
-
- CVfbExView::CVfbExView()
- {
- m_vForm.PrintStyle(VFPRINT_ALL);
- }
-
- CVfbExView::~CVfbExView()
- {
- }
-
- BOOL CVfbExView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return CScrollView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CVfbExView drawing
-
- void CVfbExView::OnDraw(CDC* pDC)
- {
- CVfbExDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- // TODO: add draw code for native data here
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CVfbExView printing
- void CVfbExView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
- {
- m_vForm.DoPrint(pDC, pInfo);
- // CScrollView::OnPrint(pDC, pInfo);
- }
-
- BOOL CVfbExView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- return m_vForm.DoPreparePrinting(this, pInfo);
- // return DoPreparePrinting(pInfo);
- }
-
- void CVfbExView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
- {
- // Set the page info again, since the user may have changed
- // the printer since we set it up in OnPreparePrinting
- m_vForm.CalcPageInfo(pDC, pInfo);
- }
-
- void CVfbExView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
-
- void CVfbExView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
- {
- CScrollView::OnPrepareDC(pDC, pInfo);
- m_vForm.DoPrepareDC(pDC, pInfo);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CVfbExView diagnostics
-
- #ifdef _DEBUG
- void CVfbExView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
-
- void CVfbExView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
-
- CVfbExDoc* CVfbExView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVfbExDoc)));
- return (CVfbExDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CVfbExView message handlers
-
- int CVfbExView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CScrollView::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- CRect rect(10, 10, 400, 400);
- if(!m_vForm.Create("TestVf", rect, this, 101))
- AfxMessageBox("Could not create VForm");
-
- return 0;
- }
-
- void CVfbExView::OnSize(UINT nType, int cx, int cy)
- {
- CScrollView::OnSize(nType, cx, cy);
-
- // Must be at position 0,0 before calling ResizeToParent
- // - because ResizeToParent will move the VForm
- if(m_nMapMode > 0)
- ScrollToPosition(CPoint(0,0));
- m_vForm.ResizeToParent();
-
- // Reset Scrolling if VForm size is larger than the view
- // - This could happen if the View is smaller than the minimum form size
- SetScrollByVForm();
- }
-
- void CVfbExView::SetScrollByVForm()
- {
- CRect rc, rcVF;
- GetClientRect(&rc);
- m_vForm.GetWindowRect(&rcVF);
- ScreenToClient(&rcVF);
-
- CSize sizeTotal(100, rcVF.Height());
- CSize sizePage(100, rc.Height());
- SetScrollSizes(MM_TEXT, sizeTotal, sizePage);
- }
-
- void CVfbExView::OnSetFocus(CWnd* pOldWnd)
- {
- CScrollView::OnSetFocus(pOldWnd);
- m_vForm.SetFocus();
- }
-
- BOOL CVfbExView::OnEraseBkgnd(CDC* pDC)
- {
- CRect rect, rcVF;
-
- // --- To avoid flicker, we will only draw where the child VForm is not
- pDC->GetClipBox(&rect);
- m_vForm.GetWindowRect(&rcVF);
- ScreenToClient(&rcVF);
-
- if(rcVF.bottom >= rect.bottom) return TRUE; // Nothing to draw
-
- rect.top = rcVF.bottom; // Only draw what we need
-
- CBrush brBack(GetSysColor(COLOR_APPWORKSPACE));
- pDC->FillRect(&rect, &brBack);
-
- return TRUE; // Eliminates Flicker when sizing
- }
-
- BOOL CVfbExView::LoadVfbFile(LPCTSTR lpszPathName)
- {
- if(!m_vForm.LoadVfbFile(lpszPathName))
- return FALSE;
-
- m_vForm.ResetFieldCount(); // Reset our field count
-
- // Reset Scrolling if VForm size is larger than the view
- // - This could happen if the View smaller than the minimum form size
- SetScrollByVForm();
-
- // Set our Color Palette (makes a big difference on 256 color displays)
- CPalette* pPal = m_vForm.GetBackgroundPalette();
- if (!m_palMsgHandler.IsHooked())
- m_palMsgHandler.Install(this, pPal);
- else
- m_palMsgHandler.SetPalette(pPal);
-
- m_palMsgHandler.DoRealizePalette(TRUE);
-
- return TRUE;
- }
-
- void CVfbExView::OnPrintscrnAll()
- {
- m_vForm.PrintStyle(VFPRINT_ALL);
- m_vForm.UseRptForm(FALSE);
- CScrollView::OnFilePrint();
- }
-
- void CVfbExView::OnPrintscrnSel()
- {
- m_vForm.PrintStyle(VFPRINT_SELECTED);
- m_vForm.UseRptForm(FALSE);
- CScrollView::OnFilePrint();
- }
-
- void CVfbExView::OnPrintscrnScreen()
- {
- m_vForm.PrintStyle(VFPRINT_SCREEN);
- m_vForm.UseRptForm(FALSE);
- CScrollView::OnFilePrint();
- }
-
- void CVfbExView::OnPrintrptAll()
- {
- m_vForm.PrintStyle(VFPRINT_ALL);
- m_vForm.UseRptForm(TRUE);
- CScrollView::OnFilePrint();
- }
-
- void CVfbExView::OnPrintrptSel()
- {
- m_vForm.PrintStyle(VFPRINT_SELECTED);
- m_vForm.UseRptForm(TRUE);
- CScrollView::OnFilePrint();
- }
-
- void CVfbExView::OnPrintrptScreen()
- {
- m_vForm.PrintStyle(VFPRINT_SCREEN);
- m_vForm.UseRptForm(TRUE);
- CScrollView::OnFilePrint();
- }
-
- void CVfbExView::OnPreviewscrnAll()
- {
- m_vForm.PrintStyle(VFPRINT_ALL);
- m_vForm.UseRptForm(FALSE);
- CScrollView::OnFilePrintPreview();
- }
-
- void CVfbExView::OnPreviewscrnSel()
- {
- m_vForm.PrintStyle(VFPRINT_SELECTED);
- m_vForm.UseRptForm(FALSE);
- CScrollView::OnFilePrintPreview();
- }
-
- void CVfbExView::OnPreviewscrnScreen()
- {
- m_vForm.PrintStyle(VFPRINT_SCREEN);
- m_vForm.UseRptForm(FALSE);
- CScrollView::OnFilePrintPreview();
- }
-
- void CVfbExView::OnPreviewrptAll()
- {
- m_vForm.PrintStyle(VFPRINT_ALL);
- m_vForm.UseRptForm(TRUE);
- CScrollView::OnFilePrintPreview();
- }
-
- void CVfbExView::OnPreviewrptSel()
- {
- m_vForm.PrintStyle(VFPRINT_SELECTED);
- m_vForm.UseRptForm(TRUE);
- CScrollView::OnFilePrintPreview();
- }
-
- void CVfbExView::OnPreviewrptScreen()
- {
- m_vForm.PrintStyle(VFPRINT_SCREEN);
- m_vForm.UseRptForm(TRUE);
- CScrollView::OnFilePrintPreview();
- }
-
- void CVfbExView::OnViewGridmode()
- {
- BOOL bNewMode = !m_vForm.GridMode();
- m_vForm.GridMode(bNewMode);
- }
-
- void CVfbExView::OnUpdateViewGridmode(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_vForm.GridMode());
- }
-