/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 14 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c)1991-2004 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ #include "stdafx.h" #include "ABC.h" #include "ABCDoc.h" #include "ABCView.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CABCApp theApp; ///////////////////////////////////////////////////////////////////////////// // CABCView IMPLEMENT_DYNCREATE(CABCView, CView) BEGIN_MESSAGE_MAP(CABCView, CView) //{{AFX_MSG_MAP(CABCView) ON_COMMAND(ID_VIEW_NORMAL, OnViewNormal) ON_UPDATE_COMMAND_UI(ID_VIEW_NORMAL, OnUpdateViewNormal) ON_COMMAND(ID_VIEW_FITIMAGETOWINDOW, OnViewFitimagetowindow) ON_UPDATE_COMMAND_UI(ID_VIEW_FITIMAGETOWINDOW, OnUpdateViewFitimagetowindow) ON_UPDATE_COMMAND_UI(ID_VIEW_SNAPWINDOWTOIMAGE, OnUpdateViewSnapwindowtoimage) ON_COMMAND(ID_VIEW_ZOOMIN2X, OnViewZoomin2x) ON_COMMAND(ID_VIEW_ZOOMOUT2X, OnViewZoomout2x) ON_WM_SETFOCUS() ON_WM_KILLFOCUS() ON_COMMAND(ID_NORMAL, OnNormal) ON_UPDATE_COMMAND_UI(ID_NORMAL, OnUpdateNormal) ON_COMMAND(ID_SCALETOGRAY, OnScaletogray) ON_UPDATE_COMMAND_UI(ID_SCALETOGRAY, OnUpdateScaletogray) ON_COMMAND(ID_FAVORBLCAK, OnFavorblcak) ON_UPDATE_COMMAND_UI(ID_FAVORBLCAK, OnUpdateFavorblcak) //}}AFX_MSG_MAP END_MESSAGE_MAP() /*--------------------------------------------------------------------------+ | Function :SetImageDataDefaults | Desc :set image data defaults | Return :bool | Notes : +--------------------------------------------------------------------------*/ L_VOID SetImageDataDefaults(LPIMAGEDATA lpImageData) { lpImageData->bFitImage = TRUE; //if TRUE then fit image to window lpImageData->cxClient = 0; //width of client area lpImageData->cyClient = 0; //height of client area SetRect(&lpImageData->rcView, 0, 0, 0, 0); lpImageData->pBitmap = NULL; lpImageData->pointStart.x = 0; lpImageData->pointStart.y = 0; } /*--------------------------------------------------------------------------+ | Function :GetDocument | Desc :inline function | Return :CABCDoc* | Notes : +--------------------------------------------------------------------------*/ inline CABCDoc* CABCView::GetDocument() { return (CABCDoc*)m_pDocument; } /*--------------------------------------------------------------------------+ | Function :CABCView | Desc :constructor | Return : | Notes : +--------------------------------------------------------------------------*/ CABCView::CABCView() { m_nZoom=100; SetImageDataDefaults( &m_Data ); m_bResizePlz = FALSE; Trace(TEXT("\n.........................New Image.")); } /*--------------------------------------------------------------------------+ | Function :OnInitialUpdate | Desc :on initial update | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnInitialUpdate() { CABCDoc *pDoc = GetDocument(); m_BtmpWnd.SetHandle(pDoc->m_LEADBitmap.GetHandle()); m_BtmpWnd.SetWndHandle(GetSafeHwnd()); CView::OnInitialUpdate(); m_nViewMode = VIEW_NORMAL; SetZoom(100); m_BtmpWnd.Region()->Free(); m_BtmpWnd.CancelRgn(); } /*--------------------------------------------------------------------------+ | Function :OnUpdate | Desc :on update | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { UINT uFlags = (UINT) lHint; if(uFlags & CHANGED_COLOR) OnSizeChange(); CView::OnUpdate(pSender, lHint, pHint); } /*--------------------------------------------------------------------------+ | Function :OnDraw | Desc :draw bitmap | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnDraw(CDC* pDC) { } /*--------------------------------------------------------------------------+ | Function :OnSizeChange | Desc :on size change | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnSizeChange() { CABCDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); m_BtmpWnd.SetZoomPercent(m_nZoom); LBitmapWindow* pBitmap = &m_BtmpWnd; CStatusBar *pStatusBar=NULL; CMainFrame * pMain=NULL; pMain = (CMainFrame*)AfxGetMainWnd(); if(pMain) pStatusBar = &pMain->m_wndStatusBar; if(pStatusBar) { pStatusBar->SetPaneText(2, TEXT(""), TRUE); CString cs; cs.Format(TEXT("%ux%u"), pBitmap->GetWidth(), pBitmap->GetHeight()); pStatusBar->SetPaneText(3, cs, TRUE); cs.Format(TEXT("%uBPP"), pBitmap->GetBitsPerPixel()); pStatusBar->SetPaneText(4, cs, TRUE); cs.Format(TEXT("Mem:%u"), pDoc->m_fi.SizeMem); pStatusBar->SetPaneText(5, cs, TRUE); cs.Format(TEXT("Disk:%u"), pDoc->m_fi.SizeDisk); pStatusBar->SetPaneText(6, cs, TRUE); } } /*--------------------------------------------------------------------------+ | Function :OnSetFocus | Desc :set focus | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnSetFocus(CWnd* pOldWnd) { CABCDoc* pDoc = GetDocument(); CView::OnSetFocus(pOldWnd); CStatusBar *pStatusBar=NULL; CMainFrame * pMain=NULL; pMain = (CMainFrame*)AfxGetMainWnd(); if(pMain) pStatusBar = &pMain->m_wndStatusBar; LBitmapWindow* pBitmap = &m_BtmpWnd; if(pStatusBar) { CString cs; cs.Format(TEXT("%ux%u"), pBitmap->GetWidth(), pBitmap->GetHeight()); pStatusBar->SetPaneText(3, cs, TRUE); cs.Format(TEXT("%uBPP"), pBitmap->GetBitsPerPixel()); pStatusBar->SetPaneText(4, cs, TRUE); cs.Format(TEXT("Mem:%u"), pDoc->m_fi.SizeMem); pStatusBar->SetPaneText(5, cs, TRUE); cs.Format(TEXT("Disk:%u"), pDoc->m_fi.SizeDisk); pStatusBar->SetPaneText(6, cs, TRUE); } } /*--------------------------------------------------------------------------+ | Function :OnKillFocus | Desc :On Kill Focus | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnKillFocus(CWnd* pNewWnd) { CView::OnKillFocus(pNewWnd); CMainFrame* pMain=NULL; CStatusBar *pStatusBar=NULL; pMain = (CMainFrame*)AfxGetMainWnd(); if(pMain) pStatusBar = &pMain->m_wndStatusBar; if(pStatusBar) { pStatusBar->SetPaneText(3, TEXT(" "), TRUE); pStatusBar->SetPaneText(4, TEXT(" "), TRUE); pStatusBar->SetPaneText(5, TEXT(" "), TRUE); pStatusBar->SetPaneText(6, TEXT(" "), TRUE); } } /*--------------------------------------------------------------------------+ | Function :SetZoom | Desc :set the zoom value | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::SetZoom(int nZoom) { CABCDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); m_nZoom = nZoom; OnSizeChange(); pDoc->UpdateAllViews(NULL); } /*--------------------------------------------------------------------------+ | Function :OnViewNormal | Desc :set the viewing mode to normal | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnViewNormal() { m_nViewMode = VIEW_NORMAL; SetZoom(100); } /*--------------------------------------------------------------------------+ | Function :OnUpdateViewNormal | Desc :check/uncheck the view normal control | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnUpdateViewNormal(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nViewMode==VIEW_NORMAL); } /*--------------------------------------------------------------------------+ | Function :Fitimagetowindow | Desc :fit the image to window | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::Fitimagetowindow() { OnViewFitimagetowindow(); } /*--------------------------------------------------------------------------+ | Function :OnViewFitimagetowindow | Desc :On View Fit image to window | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnViewFitimagetowindow() { CABCDoc* pDoc = GetDocument(); int cxZoom, cyZoom; LBitmapWindow* pBitmap = &m_BtmpWnd; RECT rcClient; GetClientRect(&rcClient); if( pBitmap->IsAllocated()) { cxZoom = (int) ((long) (rcClient.right-rcClient.left) * 100 / pBitmap->GetWidth()); cyZoom = (int) ((long) (rcClient.bottom-rcClient.top) * 100 / pBitmap->GetHeight()); } else { if( pDoc->m_fi.Width > 0 ) cxZoom = (int) ((long) (rcClient.right-rcClient.left) * 100 / pDoc->m_fi.Width ); if( pDoc->m_fi.Height > 0 ) cyZoom = (int) ((long) (rcClient.bottom-rcClient.top) * 100 / pDoc->m_fi.Height ); } m_nViewMode = VIEW_FIT; SetZoom(max( min(cxZoom, cyZoom), 1)); } /*--------------------------------------------------------------------------+ | Function :OnUpdateViewFitimagetowindow | Desc :On Update View Fit image to window | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnUpdateViewFitimagetowindow(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nViewMode==VIEW_FIT); } /*--------------------------------------------------------------------------+ | Function :OnUpdateViewSnapwindowtoimage | Desc :On Update View Snap window to image | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnUpdateViewSnapwindowtoimage(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_nViewMode==VIEW_SNAP); pCmdUI->Enable(m_nViewMode!=VIEW_FIT); } /*--------------------------------------------------------------------------+ | Function :OnViewZoomin2x | Desc :reduce the bitmap size twice | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnViewZoomin2x() { if( m_nZoom <= 800 ) m_nZoom = min( 800, m_nZoom * 2 ); if( m_nZoom == 100 ) m_nViewMode = VIEW_NORMAL; else m_nViewMode = VIEW_ZOOM; SetZoom(m_nZoom); } /*--------------------------------------------------------------------------+ | Function :OnViewZoomout2x | Desc :enlarge the bitmap size twice | Return :void | Notes : +--------------------------------------------------------------------------*/ void CABCView::OnViewZoomout2x() { if( m_nZoom >= 6 ) m_nZoom = max( 6, m_nZoom / 2); if( m_nZoom == 100 ) m_nViewMode = VIEW_NORMAL; else m_nViewMode = VIEW_ZOOM; SetZoom( m_nZoom ); } void CABCView::OnNormal() { theApp.m_nDisplayMode = 0; SetDisplayModeForAllViews( DISPLAYMODE_SCALETOGRAY | DISPLAYMODE_FAVORBLACK, 0) ; } void CABCView::OnFavorblcak() { theApp.m_nDisplayMode = DISPLAYMODE_FAVORBLACK; SetDisplayModeForAllViews( DISPLAYMODE_SCALETOGRAY | DISPLAYMODE_FAVORBLACK, DISPLAYMODE_FAVORBLACK) ; } void CABCView::OnScaletogray() { theApp.m_nDisplayMode = DISPLAYMODE_SCALETOGRAY; SetDisplayModeForAllViews( DISPLAYMODE_SCALETOGRAY | DISPLAYMODE_FAVORBLACK, DISPLAYMODE_SCALETOGRAY) ; } void CABCView::OnUpdateNormal(CCmdUI* pCmdUI) { pCmdUI->SetCheck( theApp.m_nDisplayMode == 0 ); } void CABCView::OnUpdateFavorblcak(CCmdUI* pCmdUI) { pCmdUI->SetCheck( theApp.m_nDisplayMode == DISPLAYMODE_FAVORBLACK ); } void CABCView::OnUpdateScaletogray(CCmdUI* pCmdUI) { pCmdUI->SetCheck( theApp.m_nDisplayMode == DISPLAYMODE_SCALETOGRAY ); } L_VOID CABCView::SetDisplayModeForAllViews(L_UINT32 unFlagPos, L_UINT32 unFlagSet) { POSITION pos = theApp.GetFirstDocTemplatePosition(); while( pos ) { CDocTemplate* pTemplate = (CDocTemplate*)theApp.GetNextDocTemplate(pos); POSITION pos2 = pTemplate->GetFirstDocPosition(); while( pos2 != NULL ) { CDocument* pDoc = pTemplate->GetNextDoc(pos2); POSITION pos = pDoc->GetFirstViewPosition(); CABCView* pFirstView = (CABCView*)pDoc->GetNextView( pos ); pFirstView->m_BtmpWnd.SetDisplayMode(unFlagPos, unFlagSet); } } }