//PaintVw.cpp:implementationoftheCPaintViewclass // #include "stdafx.h" #include "Paint.h" #include "PPaint.h" #include "PaintDoc.h" #include "PaintVw.h" #include "MainFrm.h" //nclude "anntoolb.h" #include "paintcon.h" #include "tbbutton.h" #include "toolbar.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CPaintApp theApp; ///////////////////////////////////////////////////////////////////////////// // CPaintView IMPLEMENT_DYNCREATE(CPaintView, CFormView) BEGIN_MESSAGE_MAP(CPaintView, CFormView) //{{AFX_MSG_MAP(CPaintView) ON_MESSAGE(WM_DOREALIZE, OnDoRealize) ON_WM_SIZE() ON_COMMAND(ID_EDIT_COPY, OnEditCopy) ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) ON_WM_DESTROY() //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPaintView construction/destruction CPaintView::CPaintView() : CFormView(CPaintView::IDD) { //{{AFX_DATA_INIT(CPaintView) //}}AFX_DATA_INIT // TODO: add construction code here m_bDrawing = FALSE; m_nPointCount=0; m_bFirstDraw=FALSE; m_nStartY= (float)0.0; m_nStartX= (float)0.0; m_nEndX=(float)0.0; m_nEndY=(float)0.0; m_bButtonDown = FALSE; m_crBorder = RGB(0,0,0); m_pMWnd=NULL; m_pMWnd = ((CMainFrame*)theApp.GetMainWnd()); } CPaintView::~CPaintView() { } void CPaintView::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPaintView) DDX_Control(pDX, IDC_LEADCTRL1, m_Lead); //}}AFX_DATA_MAP } BOOL CPaintView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CFormView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CPaintView printing BOOL CPaintView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CPaintView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CPaintView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } void CPaintView::OnPrint(CDC* pDC, CPrintInfo*) { m_pMWnd->m_LeadPaint.AutoRender(0); // TODO: add code to print the controls } ///////////////////////////////////////////////////////////////////////////// // CPaintView diagnostics #ifdef _DEBUG void CPaintView::AssertValid() const { CFormView::AssertValid(); } void CPaintView::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } CPaintDoc* CPaintView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPaintDoc))); return (CPaintDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CPaintView message handlers void CPaintView::OnInitialUpdate() { CFormView::OnInitialUpdate(); CPaintDoc *pDoc = (CPaintDoc *)GetDocument(); //Set TRUE to reference source controls bitmap pDoc->m_LeadDoc.SetRefBitmap(FALSE); //Assign m_Lead control the bitmap in m_LeadDoc m_Lead.SetBitmap(pDoc->m_LeadDoc.GetBitmap()); //Get Height and Width of source bitmap int xExt = (int)pDoc->m_LeadDoc.GetBitmapWidth(), yExt = (int)pDoc->m_LeadDoc.GetBitmapHeight(); // Make the CLead control to fit the bitmap and disable CLead's scrolling // Make the form scroll if the window becomes smaller than the bitmap SetScrollSizes(MM_TEXT,CSize(xExt,yExt)); // Make the window fit the image GetParentFrame()->RecalcLayout(); ResizeParentToFit(); // now disable the scroll bars SetScrollSizes(MM_TEXT,CSize(1,1)); pDoc->m_LeadDoc.SetAutoPan(TRUE); pDoc->m_LeadDoc.SetBackErase(FALSE); //Associate lead main control with paint control UpdatePaintMetrics(); m_Lead.SetRgnFrameType(RGNFRAME_ANIMATED); //Create an automation container m_pMWnd->m_LeadPaint.CreateAutoContainer((long)m_Lead.m_hWnd, (long)m_Lead.GetBitmap()); //disable the LEAD Main Control's Region marking //Paint Automation will handle this m_Lead.SetRgnFrameType(RGNFRAME_NONE); } void CPaintView::OnSize(UINT nType, int cx, int cy) { CFormView::OnSize(nType, cx, cy); if( IsWindow(m_Lead.m_hWnd) ) { m_Lead.MoveWindow(0, 0, cx, cy); m_Lead.SetBackErase(FALSE); if(m_Lead.GetBitmap()) { m_pMWnd->m_LeadPaint.SetEnableMethodErrors(FALSE); if(m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd)) { UpdateScalar(); UpdateXForm(); } } } } BEGIN_EVENTSINK_MAP(CPaintView, CFormView) //{{AFX_EVENTSINK_MAP(CPaintView) ON_EVENT(CPaintView, IDC_LEADCTRL1, 3 /* Scroll */, OnScrollLeadctrl1, VTS_NONE) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() void CPaintView::UpdateStatusBar(int nPane, char *pszMsg) { if (pszMsg == NULL) pszMsg = ""; CMainFrame *pMainFrame = ((CMainFrame*)theApp.GetMainWnd()); pMainFrame->UpdateStatusBar( pszMsg, nPane); } void CPaintView::UpdateXForm() { if (m_Lead.GetBitmap()) { if(m_pMWnd->m_LeadPaint.GetPaintUserMode() == PAINT_USERMODE_AUTO) { m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetLimitLeft(0); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetLimitTop(0); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetLimitWidth((long)m_Lead.GetBitmapWidth()); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetLimitHeight((long)m_Lead.GetBitmapHeight()); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetOffsetX((long)-m_Lead.GetDstLeft()); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetOffsetY((long)-m_Lead.GetDstTop()); } } } void CPaintView::UpdateScalar() { float zf; if (m_Lead.GetBitmap()) { zf = m_Lead.GetPaintZoomFactor(); if(zf >= 100.0f) { float zf2 = zf / 100.0f; m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetScalarNumX(zf2); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetScalarNumY(zf2); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetScalarDenX(1); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetScalarDenY(1); } else { float zf2 = 100.0f / zf; m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetScalarNumX(1); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetScalarNumY(1); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetScalarDenX(zf2); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetScalarDenY(zf2); } } } void CPaintView::OnScrollLeadctrl1() { if(m_Lead.GetBitmap() != 0) UpdateXForm(); } void CPaintView::UpdatePaintMetrics() { m_pMWnd->m_LeadPaint.SetMetrics(m_Lead.GetHWnd(), m_Lead.GetBitmap()); } void CPaintView::OnEditCopy() { BeginWaitCursor(); m_Lead.Copy(COPY_DIB | COPY_DDB | COPY_PALETTE); EndWaitCursor(); } void CPaintView::OnFileSaveAs() { CString sFileName; int nRet; theApp.m_pRasterFileDlg->PutEnableMethodErrors(FALSE); theApp.m_pRasterFileDlg->PutFileDlgFlags(0); theApp.m_pRasterFileDlg->PutDialogTitle("Save File"); theApp.m_pRasterFileDlg->PutUIFlags(SAVE_SHOW_FILEOPTIONS_STAMP | SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS | SAVE_SHOW_FILEOPTIONS_J2KOPTIONS | SAVE_SHOW_FILEOPTIONS_MULTIPAGE | SAVE_SHOW_FILEOPTIONS_QFACTOR | SAVE_SHOW_FILEOPTIONS_STAMP); nRet = theApp.m_pRasterFileDlg->ShowSaveDlg((long)theApp.m_pMainWnd->m_hWnd); if(nRet == 0 && theApp.m_pRasterFileDlg->GetDialogStatus() == DLG_OK) { sFileName = (LPTSTR)theApp.m_pRasterFileDlg->GetFileName(); int nFormat = theApp.m_pRasterFileDlg->GetSaveFormat(); int nBits = theApp.m_pRasterFileDlg->GetSaveBitsPerPixel(); int nQFactor = theApp.m_pRasterFileDlg->GetSaveQFactor(); int nMultipage = theApp.m_pRasterFileDlg->GetSaveMulti(); long nPage=1; switch(nMultipage) { case SAVE_APPEND: nPage = 2; break; case SAVE_OVERWRITE: nPage = 1; break; case SAVE_REPLACE: case SAVE_INSERT: nPage = theApp.m_pRasterFileDlg->GetPageNumber(); break; } switch(nFormat) { case FILE_J2K : case FILE_JP2 : case FILE_CMW : case FILE_TIF_J2K : case FILE_TIF_CMW : BOOL oldVal = m_Lead.GetEnableMethodErrors(); m_Lead.SetEnableMethodErrors(FALSE); SetJ2KOptions(); m_Lead.SetEnableMethodErrors(oldVal); break; } m_Lead.SetSavePage((short)nPage); m_Lead.SetSaveInterlaced(theApp.m_pRasterFileDlg->GetSaveInterlaced()); if(theApp.m_pRasterFileDlg->SaveWithStamp) { int nStampWidth,nStampHeight,nStampBits; nStampWidth = theApp.m_pRasterFileDlg->SaveStampWidth; nStampHeight = theApp.m_pRasterFileDlg->SaveStampHeight; nStampBits = theApp.m_pRasterFileDlg->SaveStampBits; nRet = m_Lead.SaveWithStamp(sFileName, nFormat, nBits, nQFactor,(float)nStampWidth,(float)nStampHeight,nStampBits); } else { nRet = m_Lead.Save(sFileName, nFormat, nBits, nQFactor, nMultipage); } if(nRet) { theApp.DisplayLEADError(nRet); } } else theApp.DisplayLEADError(nRet); return; } void CPaintView::SetJ2KOptions() { m_Lead.SetJ2KUseColorTransform(theApp.m_pRasterFileDlg->SaveJ2KUseColorTransform); m_Lead.SetJ2KDerivedQuantization(theApp.m_pRasterFileDlg->SaveJ2KDerivedQuantization); m_Lead.SetJ2KCompressionControl(theApp.m_pRasterFileDlg->GetSaveJ2KCompressionControl()); m_Lead.SetJ2KCompressionRatio(theApp.m_pRasterFileDlg->SaveJ2KCompressionRatio); m_Lead.SetJ2KTargetFileSize(theApp.m_pRasterFileDlg->SaveJ2KTargetFileSize); m_Lead.SetJ2KXOsiz(theApp.m_pRasterFileDlg->SaveJ2KXOsiz); m_Lead.SetJ2KYOsiz(theApp.m_pRasterFileDlg->SaveJ2KYOsiz); m_Lead.SetJ2KXTsiz(theApp.m_pRasterFileDlg->SaveJ2KXTsiz); m_Lead.SetJ2KYTsiz(theApp.m_pRasterFileDlg->SaveJ2KYTsiz); m_Lead.SetJ2KXTOsiz(theApp.m_pRasterFileDlg->SaveJ2KXTOsiz); m_Lead.SetJ2KYTOsiz(theApp.m_pRasterFileDlg->SaveJ2KYTOsiz); m_Lead.SetJ2KDecompLevel(theApp.m_pRasterFileDlg->SaveJ2KDecompLevel); m_Lead.SetJ2KProgressOrder(theApp.m_pRasterFileDlg->GetSaveJ2KProgressOrder()); m_Lead.SetJ2KCodBlockWidth(theApp.m_pRasterFileDlg->SaveJ2KCodBlockWidth); m_Lead.SetJ2KCodBlockHeight(theApp.m_pRasterFileDlg->SaveJ2KCodBlockHeight); m_Lead.SetJ2KCBS_SelectiveACBypass(theApp.m_pRasterFileDlg->SaveJ2KCBS_SelectiveACBypass); m_Lead.SetJ2KCBS_ResetContextOnBoundaries(theApp.m_pRasterFileDlg->SaveJ2KCBS_ResetContextOnBoundaries); m_Lead.SetJ2KCBS_TerminationOnEachPass(theApp.m_pRasterFileDlg->SaveJ2KCBS_TerminationOnEachPass); m_Lead.SetJ2KCBS_VerticallyCausalContext(theApp.m_pRasterFileDlg->SaveJ2KCBS_VerticallyCausalContext); m_Lead.SetJ2KCBS_PredictableTermination(theApp.m_pRasterFileDlg->SaveJ2KCBS_PredictableTermination); m_Lead.SetJ2KCBS_ErrorResilienceSymbol(theApp.m_pRasterFileDlg->SaveJ2KCBS_ErrorResilienceSymbol); m_Lead.SetJ2KGuardBits(theApp.m_pRasterFileDlg->SaveJ2KGuardBits); m_Lead.SetJ2KDerivedBaseMantissa(theApp.m_pRasterFileDlg->SaveJ2KDerivedBaseMantissa); m_Lead.SetJ2KDerivedBaseExponent(theApp.m_pRasterFileDlg->SaveJ2KDerivedBaseExponent); m_Lead.SetJ2KUseSOPMarker(theApp.m_pRasterFileDlg->SaveJ2KUseSOPMarker); m_Lead.SetJ2KUseEPHMarker(theApp.m_pRasterFileDlg->SaveJ2KUseEPHMarker); } void CPaintView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView); if(m_Lead.GetBitmap() && bActivate) { UpdateXForm(); UpdateScalar(); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetActive(); m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd).SetEnabled(TRUE); ASSERT(pActivateView == this); OnDoRealize((WPARAM)theApp.m_pMainWnd->m_hWnd, (LPARAM) FALSE); // same as SendMessage(WM_DOREALIZE); } } void CPaintView::OnDestroy() { UpdateStatusBar(); m_pMWnd->m_LeadPaint.SetEnableMethodErrors(FALSE); if(m_pMWnd->m_LeadPaint.GetAutoContainer((long)m_Lead.m_hWnd)) m_pMWnd->m_LeadPaint.DeleteAutoContainer((long)m_Lead.m_hWnd); CFormView::OnDestroy(); } LRESULT CPaintView::OnDoRealize(WPARAM wParam, LPARAM lParam) { if( !IsWindow(m_Lead.m_hWnd) || !m_Lead.GetBitmap() ) return FALSE; if(lParam) { return m_Lead.SendMessage(WM_PALETTECHANGED, wParam); } else { return m_Lead.SendMessage(WM_QUERYNEWPALETTE,0); } }