home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************/
- /* */
- /* TurboCAD for Windows */
- /* Copyright (c) 1993 - 2001 */
- /* International Microcomputer Software, Inc. */
- /* (IMSI) */
- /* All rights reserved. */
- /* */
- /******************************************************************/
-
- // VPWnd.cpp : implementation file
- // TurboCAD SDK: new class implementation
-
- #include "stdafx.h"
- #include "MakeDwg.h"
- #include "VPWnd.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CViewWnd
- // TurboCAD SDK: class created to manage view on dialog box
-
- CViewWnd::CViewWnd() :
- m_pView(NULL),
- m_pIDrawing(NULL)
- {
- }
-
- CViewWnd::~CViewWnd()
- {
- SetView(NULL);
- }
-
-
- BEGIN_MESSAGE_MAP(CViewWnd, CWnd)
- //{{AFX_MSG_MAP(CViewWnd)
- ON_WM_PAINT()
- ON_WM_ERASEBKGND()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- // TurboCAD SDK: set the view, if one already exists, delete and release it
- // before assigning the new one.
- void CViewWnd::SetView(View* pView)
- {
- if (m_pView != NULL)
- {
- // Delete view object
- m_pView->Delete();
-
- // Decrement reference count
- m_pView->Release();
- m_pView = NULL;
- if (m_pIDrawing != NULL)
- {
- m_pIDrawing->Release();
- m_pIDrawing = NULL;
- }
- }
-
- if (pView == NULL)
- return;
-
- m_pView = pView;
-
- // Increment reference count
- m_pView->AddRef();
-
- // Map window to view
- m_pView->put_HWND((long)m_hWnd);
-
- // Keep a reference to the drawing
- m_pView->get_Drawing(&m_pIDrawing);
-
- // zoom to drawing extents and invalidate the window
- ZoomAndInvalidate();
- }
-
- IDrawing* CViewWnd::GetDrawing()
- {
- if (m_pIDrawing != NULL)
- m_pIDrawing->AddRef();
- return m_pIDrawing;
- }
-
- Graphics* CViewWnd::GetGraphics()
- {
- Graphics* pGraphics = NULL;
- if (m_pIDrawing != NULL)
- m_pIDrawing->get_Graphics(&pGraphics);
- return pGraphics;
- }
-
- // TurboCAD SDK: zoom to drawing extents and invalidate the window
- void CViewWnd::ZoomAndInvalidate()
- {
- // No view, exit
- if (m_pView == NULL)
- return;
-
- // Zoom to extents
- HRESULT hRes = m_pView->ZoomToExtents();
- if (FAILED(hRes))
- {
- }
-
- // Invalidate window to force redraw
- Invalidate();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CViewWnd message handlers
-
- // TurboCAD SDK: override OnPaint to refresh the view
- void CViewWnd::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- if (m_pView == NULL)
- return;
-
- // Force redraw of view window
- HRESULT hRes = m_pView->Refresh();
- if (FAILED(hRes))
- {
- }
- }
-
- // TurboCAD SDK: override OnEraseBkgnd to reset the drawing area
- BOOL CViewWnd::OnEraseBkgnd(CDC* pDC)
- {
- CRect rect;
- GetClientRect(rect);
- pDC->FillSolidRect(rect, ::GetSysColor(COLOR_WINDOW));
- return TRUE;
- }
-