📄 emfexplorerview.cpp
字号:
void CEMFexplorerView::SCSetZoom(int iZoom, BOOL bUpdateToolbar/*=TRUE*/)
{
if (SC_ZOOM_FITWITDH==iZoom)
m_CtlImage.SCSetFitMode(SC_FIT_WIDTH);
else
if (SC_ZOOM_FITPAGE==iZoom)
m_CtlImage.SCSetFitMode(SC_FIT_PAGE);
else
{
ASSERT(iZoom>=SC_MIN_ZOOM && iZoom<=SC_MAX_ZOOM);
m_CtlImage.SCSetCurZoom(iZoom);
}
SCRefresh();
if (bUpdateToolbar)
SCUpdateToolbar(SC_TBUPDATE_ZOOM);
}
void CEMFexplorerView::SCSetBkColor(COLORREF crColor)
{
// Note: dialog and toolbar return RGB. So we must update color style accordingly.
m_CtlImage.SCSetPaperColorStyle(SC_COLOR_RGBVALUE, crColor);
SCRefresh();
}
int CEMFexplorerView::SCGetNearsetZoom(BOOL bGrow)
{
int iZoom = m_CtlImage.SCGetCurZoom();
if (bGrow)
{
for (int i=0; (i<cs_usZoomCount); i++)
{
if (sc_ZoomList[i].ze_iValue<0)
break;
if (sc_ZoomList[i].ze_iValue>iZoom)
return sc_ZoomList[i].ze_iValue;
}
} else
{
for (int i=cs_usZoomCount-1; (i>=0); i--)
{
if (sc_ZoomList[i].ze_iValue<0)
continue;
if (sc_ZoomList[i].ze_iValue<iZoom)
return sc_ZoomList[i].ze_iValue;
}
}
return iZoom;
}
void CEMFexplorerView::SCOnAttributesChanged()
{
SCRefresh();
}
//////////////////////////////////////////////////////////////////////////////////
// Page navigation events
//
void CEMFexplorerView::OnUpdateTbnavFirst(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_iCurPage>1);
}
void CEMFexplorerView::OnTbnavFirst()
{
SCGotoPage(1);
}
void CEMFexplorerView::OnUpdateTbnavPrev(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_iCurPage>1);
}
void CEMFexplorerView::OnTbnavPrev()
{
if (m_iCurPage>1)
SCGotoPage(m_iCurPage-1);
}
void CEMFexplorerView::OnUpdateTbnavNext(CCmdUI* pCmdUI)
{
int iNbPages = SCGetNumPages();
pCmdUI->Enable(iNbPages>0 && m_iCurPage<iNbPages);
}
void CEMFexplorerView::OnTbnavNext()
{
if (m_iCurPage<SCGetNumPages())
SCGotoPage(m_iCurPage+1);
}
void CEMFexplorerView::OnUpdateTbnavLast(CCmdUI* pCmdUI)
{
OnUpdateTbnavNext(pCmdUI);
}
void CEMFexplorerView::OnTbnavLast()
{
SCGotoPage(SCGetNumPages());
}
//////////////////////////////////////////////////////////////////////////////////
// Creation/background events
//
int CEMFexplorerView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CEMFexplorerView::SCSetView(this);
// create controls
DWORD dwStyle = WS_CHILD|WS_VISIBLE|WS_BORDER|WS_CLIPCHILDREN;
if (!m_CtlImage.Create(NULL, _T("EMFCtlImage"),
dwStyle,
CRect(10,10,150,50), this, IDC_WND_EMFIMG))
{
TRACE0("Could not create image control 1\n");
return -1;
}
m_CtlImage.SCSetColorScheme(SC_DFLT_VIEWCSHM);
m_CtlImage.SCSetCtlColor(SC_DFLT_CTLCOLOR);
// Contextual menu
m_CtlImage.SCSetCtlOwner(this);
CMenu menu;
if (menu.LoadMenu(IDR_CTX_MENU))
{
CMenu *pSubMenu = menu.GetSubMenu(MNU_IDX_TRACKPOPUP1);
if (pSubMenu)
{
m_CtlImage.SCSetCtxMenu(pSubMenu->m_hMenu);
}
m_hPopupMenu = menu.Detach();
}
m_hWndNext = SetClipboardViewer();
return 0;
}
BOOL CEMFexplorerView::OnEraseBkgnd(CDC* pDC)
{
return TRUE; // do not erase
//return CView::OnEraseBkgnd(pDC);
}
//////////////////////////////////////////////////////////////////////////////////
// Zoom/DPI events
//
void CEMFexplorerView::OnUpdateTbDpiDec(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_CtlImage.SCGetCurZoom()>SC_MIN_ZOOM && SCGetNumPages()>0);
}
void CEMFexplorerView::OnTbDpiDec()
{
SCSetZoom(SCGetNearsetZoom(FALSE));
}
void CEMFexplorerView::OnUpdateTbDpiInc(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_CtlImage.SCGetCurZoom()<SC_MAX_ZOOM && SCGetNumPages()>0);
}
void CEMFexplorerView::OnTbDpiInc()
{
SCSetZoom(SCGetNearsetZoom(TRUE));
}
void CEMFexplorerView::OnUpdateTbDpi100(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0);
}
void CEMFexplorerView::OnTbDpi100()
{
SCSetZoom(SC_ZOOM100);
}
void CEMFexplorerView::OnUpdateTbDpiMonitor(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0);
}
void CEMFexplorerView::OnTbDpiMonitor()
{
CDC* pDC = this->GetDC();
int iDpi = pDC->GetDeviceCaps(LOGPIXELSX);
this->ReleaseDC(pDC);
int iZoom = MulDiv(SC_ZOOM100, iDpi, 72);
SCSetZoom(iZoom);
}
//////////////////////////////////////////////////////////////////////////////////
// Rotation events
//
void CEMFexplorerView::OnUpdateTbPageRotateleft(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0);
}
void CEMFexplorerView::OnTbPageRotateleft()
{
m_CtlImage.SCRotateLeft();
}
void CEMFexplorerView::OnUpdateTbPageRotateright(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0);
}
void CEMFexplorerView::OnTbPageRotateright()
{
m_CtlImage.SCRotateRight();
}
//////////////////////////////////////////////////////////////////////////////////
// Color events
//
void CEMFexplorerView::OnUpdateTbdocBkcolor(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0);
}
void CEMFexplorerView::OnUpdateTbPageReversevideo(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0);
pCmdUI->SetCheck(m_CtlImage.SCGetReverseVideo()); // stay pressed if reverse video on
}
void CEMFexplorerView::OnTbPageReversevideo()
{
m_CtlImage.SCSetReverseVideo(!m_CtlImage.SCGetReverseVideo());
}
/////////////////////////////////////////////////////////////////////////////
// Other utilities
//
/////////////////////////////////////////////////////////////////////////////
// CEMFexplorerView printing
BOOL CEMFexplorerView::OnPreparePrinting(CPrintInfo* pInfo)
{
if (m_pEMFTxtDlg)
{
UINT uiPages = m_pEMFTxtDlg->SCCountPages(NULL, pInfo);
pInfo->SetMaxPage(uiPages);
} else
{
pInfo->SetMaxPage(SCGetNumPages());
pInfo->m_nCurPage = m_iCurPage;
}
// default preparation
return DoPreparePrinting(pInfo);
}
void CEMFexplorerView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
if (m_pEMFTxtDlg)
{
UINT uiPages = m_pEMFTxtDlg->SCCountPages(pDC, pInfo);
pInfo->SetMaxPage(uiPages);
return;
}
}
void CEMFexplorerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// cleanup after printing
m_CtlImage.SCGetDrawingAttributes().fPageScale = 1;
}
void CEMFexplorerView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnPrepareDC(pDC, pInfo);
}
void CEMFexplorerView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
if (m_pEMFTxtDlg)
{
m_pEMFTxtDlg->SCPrint(pDC, pInfo);
return;
}
// Print header
// TODO:
//SCPrintHeader(pDC, rectPrintArea);
// Print body
m_CtlImage.SCPrintImage(pDC, pInfo, TRUE); // TODO: ask for fitting
// Print footer
// TODO:
//SCPrintFooter(pDC, rectPrintArea);
}
// override MFC to supply our preview class, which handles scaling factor
void CEMFexplorerView::OnFilePrintPreview()
{
// Add your command handler code here
// In derived classes, implement special window handling here
// Be sure to Unhook Frame Window close if hooked.
// must not create this on the frame. Must outlive this function
CPrintPreviewState* pState = new CPrintPreviewState;
// DoPrintPreview's return value does not necessarily indicate that
// Print preview succeeded or failed, but rather what actions are necessary
// at this point. If DoPrintPreview returns TRUE, it means that
// OnEndPrintPreview will be (or has already been) called and the
// pState structure will be/has been deleted.
// If DoPrintPreview returns FALSE, it means that OnEndPrintPreview
// WILL NOT be called and that cleanup, including deleting pState
// must be done here.
if (!DoPrintPreview(AFX_IDD_PREVIEW_TOOLBAR, this,
RUNTIME_CLASS(CSCPreviewView), pState))
{
// In derived classes, reverse special window handling here for
// Preview failure case
TRACE0("Error: DoPrintPreview failed.\n");
AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
delete pState; // preview failed to initialize, delete State now
}
}
void CEMFexplorerView::OnUpdateViewEmfAstext(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0);
pCmdUI->SetCheck((m_pEMFTxtDlg!=NULL)); // stay pressed if reverse video on
}
void CEMFexplorerView::OnViewEmfAstext()
{
#if 0
// if you activte this, don't forget to update the dialog template accordingly
CSCEMFInspectDlg dlg(this);
dlg.SCSetEMF(m_hEmf);
dlg.DoModal();
#else
if (m_pEMFTxtDlg)
{
m_CtlImage.ShowWindow(SW_SHOW);
m_pEMFTxtDlg->ShowWindow(SW_HIDE);
m_pEMFTxtDlg->DestroyWindow();
delete m_pEMFTxtDlg;
m_pEMFTxtDlg = NULL;
return;
}
m_pEMFTxtDlg = new CSCEMFInspectDlg;
if (!m_pEMFTxtDlg)
return;
if (!m_pEMFTxtDlg->Create(IDD_SCEMFINSPECT_DIALOG, this))
{
ASSERT(0);
delete m_pEMFTxtDlg;
m_pEMFTxtDlg = NULL;
return;
}
CRect rc;
GetClientRect(&rc);
m_pEMFTxtDlg->MoveWindow(&rc);
m_pEMFTxtDlg->ShowWindow(SW_SHOW);
m_CtlImage.ShowWindow(SW_HIDE);
// launch parser
m_pEMFTxtDlg->SCSetEMF(m_CtlImage.SCGetCurEMF());
#endif
}
void CEMFexplorerView::OnUpdateTbdocUseGDIp(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0);
pCmdUI->SetCheck((SC_ENGINE_GDIP==m_CtlImage.SCGetRasEngine())); // stay pressed if GDI+ on
}
void CEMFexplorerView::OnTbdocUseGDIp()
{
BOOL bEnable = (!m_CtlImage.SCGetGDIplusEnabled());
ASSERT(m_pFrame);
if (m_pFrame)
m_pFrame->SCEnableGDIPlus(bEnable);
m_CtlImage.SCEnableGDIp(bEnable);
//SCRefresh();
}
void CEMFexplorerView::OnToolsOptions()
{
CString strTitle;
strTitle.LoadString(IDS_DLG_TITLE_OPTIONS);
CSCEMFDlgOptions dlgOpt(strTitle, this, this);
if (IDOK==dlgOpt.DoModal())
{
OnChangeOptions(WPARAM(dlgOpt.SCGetDocModified()), 0);
}
}
void CEMFexplorerView::OnUpdateTbdocSettings(CCmdUI* pCmdUI)
{
pCmdUI->Enable((SCGetNumPages()>0));
}
void CEMFexplorerView::OnTbdocSettings()
{
CString strTitle;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -