📄 emfexplorerview.cpp
字号:
if (m_pEMFDoc->SCHasSettings())
strTitle.LoadString(IDS_DLG_TITLE_DOCSETTINGS);
else
strTitle.LoadString(IDS_DLG_TITLE_UNSAVEDDOCSETTINGS);
CSCEMFDlgOptions dlgOpt(strTitle, this, this, eSettingsDoc);
if (IDOK==dlgOpt.DoModal())
{
OnChangeOptions(WPARAM(dlgOpt.SCGetDocModified()), 0);
}
}
LRESULT CEMFexplorerView::OnChangeOptions(WPARAM wParam, LPARAM lParam)
{
if ((BOOL)wParam) // doc modified
{
SCSaveDocSettings();
ASSERT(m_pEMFDoc);
if (m_pEMFDoc->SCGetDocModified())
{
CEMFexplorerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->SetModifiedFlag();
}
}
SCUpdateToolbar(SC_TBUPDATE_ZOOM|SC_TBUPDATE_COLOR);
ASSERT(m_pFrame);
if (m_pFrame)
{
m_pFrame->SCEnableGDIPlus(m_CtlImage.SCGetGDIplusEnabled());
m_pFrame->UpdateWindow();
}
SCGotoPage(m_iCurPage, FALSE);
return 0;
}
BOOL CEMFexplorerView::SCCanSave()
{
return (m_pEMFTxtDlg) ? (!m_pEMFTxtDlg->SCIsCracking()) : TRUE;
}
void CEMFexplorerView::SCSavePages(LPCTSTR lpszPathname, int iType, BOOL bSaveAll/*=FALSE*/)
{
if (m_pEMFTxtDlg)
{// Save text
m_pEMFTxtDlg->SCSaveDocument(lpszPathname, (SC_FILETYPE_RTF==iType));
return;
}
// Or save EMF(s)
BOOL bSaveAsIs = (AfxGetApp()->GetProfileInt(s_szAppSection, SC_EMFREG_ON_DOCSAVE,
CSCEMFOptGenPane::SCE_DSSettingsWysiwyg)==
CSCEMFOptGenPane::SCE_DSSettingsWysiwyg);
m_CtlImage.SCSaveDocument(lpszPathname, iType, bSaveAll, bSaveAsIs);
}
///
/// Note: image must be rendered. So this saving task's best placed is in the view.
///
void CEMFexplorerView::SCFileSavePageAs(BOOL bSaveAll/*=FALSE*/)
{
BOOL bTxtMode = SCIsInTextMode();
CString sFilters((bTxtMode) ? SC_BRKMODE_FILTERS : SC_EMFMODE_FILTERS_IMG);
CFileDialog dlg(FALSE, NULL, ((bTxtMode) ? _T("*.rtf") : _T("*.emf")),
OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT,
(LPCTSTR)sFilters);
if (dlg.DoModal() != IDOK)
return;
CString strPath = dlg.GetPathName();
if (-1==strPath.ReverseFind(_T('.')))
{
int iPos = 0;
for (UINT i=0; i<dlg.m_ofn.nFilterIndex; i++, iPos += 7)
{
iPos = sFilters.Find(_T(")|*."), iPos);
}
int iStart = iPos - 4;
while (sFilters[iPos] != _T('|'))
iPos++;
strPath += sFilters.Mid(iStart, iPos-iStart);
}
int iType = SC_FTYPE_UKN;
if (bTxtMode)
{
switch (dlg.m_ofn.nFilterIndex)
{
case 1: iType = SC_FILETYPE_RTF; break;
case 2: iType = SC_FILETYPE_TXT; break;
default:
ASSERT(0);
return;
}
} else
{
iType = SCFileTypeFromFilterIndexImg(dlg.m_ofn.nFilterIndex);
}
ASSERT(iType != SC_FTYPE_UKN);
SCSavePages(LPCTSTR(strPath), iType, bSaveAll);
}
void CEMFexplorerView::OnFileSavePage()
{
SCFileSavePageAs();
}
void CEMFexplorerView::OnUpdateFileSavePage(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0 && SCCanSave());
}
void CEMFexplorerView::OnFileSaveAll()
{
SCFileSavePageAs(TRUE);
}
void CEMFexplorerView::OnUpdateFileSaveAll(CCmdUI* pCmdUI)
{
OnUpdateFileSavePage(pCmdUI);
}
///
/// In this version, copy the whole page (there is no selection).
///
void CEMFexplorerView::OnEditCopy()
{
if (m_pEMFTxtDlg)
{// Copy text
m_pEMFTxtDlg->SCCopy();
return;
}
// Or copy EMF
m_CtlImage.SCCopyToClipBoard();
}
void CEMFexplorerView::OnUpdateEditCopy(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0);
}
///
/// Paste the clipboard content as a full page
/// (no partial paste is provided in this version)
///
void CEMFexplorerView::OnEditPaste()
{
int iOldNbPages = SCGetNumPages();
m_CtlImage.SCPasteFromClipBoard();
int iNbPages = SCGetNumPages();
if (iNbPages>iOldNbPages)
{
if (0==iOldNbPages)
{
SCResetToolbars();
} else
{
ASSERT(m_pFrame);
CEMFToolBar& rToolBar = m_pFrame->SCGetToolbar();
rToolBar.SCSetNbPages(SCGetNumPages());
}
CEMFexplorerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->SetModifiedFlag();
SCGotoPage(iNbPages);
}
}
void CEMFexplorerView::OnUpdateEditPaste(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bCanPaste);
}
void CEMFexplorerView::OnDrawClipboard()
{
CView::OnDrawClipboard();
// message handler code here
m_bCanPaste = ((IsClipboardFormatAvailable(CF_ENHMETAFILE)) ||
(IsClipboardFormatAvailable(CF_BITMAP)) ||
(IsClipboardFormatAvailable(s_cfRTF)) ||
(IsClipboardFormatAvailable(CF_UNICODETEXT)) ||
(IsClipboardFormatAvailable(CF_TIFF))
);
}
void CEMFexplorerView::OnDestroy()
{
ChangeClipboardChain(m_hWndNext);
CView::OnDestroy();
// message handler code here
}
void CEMFexplorerView::OnChangeCbChain(HWND hWndRemove, HWND hWndAfter)
{
CView::OnChangeCbChain(hWndRemove, hWndAfter);
// message handler code here
::SendMessage(m_hWndNext, WM_CHANGECBCHAIN, (WPARAM)hWndRemove, (LPARAM)hWndAfter);
if (m_hWndNext==hWndRemove)
m_hWndNext = hWndAfter;
}
void CEMFexplorerView::OnTbdocReflow()
{
CSCDocReflow dlgReflow;
ASSERT(m_pEMFDoc);
dlgReflow.SCSetEMFDoc(m_pEMFDoc);
if (IDOK==dlgReflow.DoModal())
{// Save master
int iNbPages = SCGetNumPages();
ASSERT(m_pFrame);
CEMFToolBar& rToolBar = m_pFrame->SCGetToolbar();
rToolBar.SCSetNbPages(iNbPages);
ASSERT(m_pEMFDoc);
if (m_pEMFDoc->SCGetDocModified())
{
CEMFexplorerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->SetModifiedFlag();
}
if (m_iCurPage>iNbPages)
m_iCurPage=iNbPages;
SCGotoPage(m_iCurPage);
}
}
void CEMFexplorerView::OnUpdateTbdocReflow(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0);
}
void CEMFexplorerView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
if (m_iCurPage)
SCRefresh();
}
void CEMFexplorerView::OnToolsPageUrl()
{
if (m_pEMFDoc && m_iCurPage)
{
CString strURL = m_pEMFDoc->SCGetPageURL(m_iCurPage-1);
ASSERT(!strURL.IsEmpty());
if (!strURL.IsEmpty())
ShellExecute( NULL, _T("open"), strURL,
NULL, NULL, SW_SHOWNORMAL );
}
}
void CEMFexplorerView::OnUpdateToolsPageUrl(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_pEMFDoc && m_bCreditURL);
}
void CEMFexplorerView::SCInsertFiles(CStringList& rFilesList)
{
ASSERT(m_pEMFDoc);
// Filter out files in other directories
CString strDocDir = SCMakeupDocDir(m_pEMFDoc->SCGetUniDocName());
int iCount = rFilesList.GetCount();
BOOL bSetDir = strDocDir.IsEmpty();
SCFilterDocDirFileList(rFilesList, strDocDir, FALSE);
int iNbFailure = iCount - rFilesList.GetCount();
BOOL bDirMismatch = (iNbFailure>0);
// Insert remaining files
int iOldNbPages = SCGetNumPages();
BOOL bInsertFailure = FALSE;
POSITION pos = rFilesList.GetHeadPosition();
while (pos)
{
if (!m_pEMFDoc->SCInsertFile(rFilesList.GetNext(pos)))
{
iNbFailure++;
bInsertFailure = TRUE;
}
}
strDocDir = SCMakeupDocDir(m_pEMFDoc->SCGetUniDocName());
bSetDir = (bSetDir && !strDocDir.IsEmpty());
if (iNbFailure)
{
CString strAdd;
CString strMsg;
if (1==iCount)
strMsg.LoadString(IDS_FILE_INSERTONE_FAILED);
else
strMsg.LoadString(IDS_FILE_INSERTMANY_FAILED);
if (bInsertFailure)
{
strAdd.LoadString(IDS_FILE_INSERTTYPE_ERR);
strMsg += _T("\n") + strAdd;
}
if (bDirMismatch)
{
strAdd.LoadString(IDS_FILEMIX_ERR);
strMsg += _T("\n") + strAdd;
}
AfxMessageBox(strMsg);
}
int iNbPages = SCGetNumPages();
if (iNbPages>iOldNbPages)
{
if (bSetDir)
m_pEMFDoc->SCSetDocDir(strDocDir);
if (0==iOldNbPages)
{
SCResetToolbars();
} else
{
ASSERT(m_pFrame);
CEMFToolBar& rToolBar = m_pFrame->SCGetToolbar();
rToolBar.SCSetNbPages(SCGetNumPages());
}
CEMFexplorerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->SetModifiedFlag();
SCGotoPage(iNbPages);
}
}
void CEMFexplorerView::OnTbdocAddPages()
{
ASSERT(m_pEMFDoc);
if (!m_pEMFDoc)
return;
CStringList strLFiles;
if (!SCGetFilesInsertList(strLFiles,
(m_iCurPage>0)? m_pEMFDoc->SCGetPageFName(m_iCurPage - 1): (LPCTSTR)NULL))
return;
if (strLFiles.IsEmpty())
AfxMessageBox(IDS_EMFXMERGE_ERR);
else
SCInsertFiles(strLFiles);
}
void CEMFexplorerView::OnUpdateTbdocAddPages(CCmdUI* pCmdUI)
{
pCmdUI->Enable((m_pEMFDoc!=NULL));
}
void CEMFexplorerView::OnTbdocRemovePage()
{
ASSERT(m_pEMFDoc);
if (!m_pEMFDoc)
return;
m_pEMFDoc->SCRemovePage(m_iCurPage-1);
CEMFexplorerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->SetModifiedFlag();
int iNbPages = SCGetNumPages();
if (m_iCurPage>iNbPages)
m_iCurPage--;
ASSERT(m_iCurPage>=0 && m_iCurPage<=iNbPages);
CEMFToolBar& rToolBar = m_pFrame->SCGetToolbar();
rToolBar.SCSetNbPages(iNbPages);
if (m_iCurPage)
SCGotoPage(m_iCurPage);
else
{
SCResetView();
SCResetToolbars();
pDoc->SCUpdateTitle(0);
m_CtlImage.SCRefresh();
}
}
void CEMFexplorerView::OnUpdateTbdocRemovePage(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0);
}
void CEMFexplorerView::OnEditCut()
{
OnTbdocRemovePage();
}
void CEMFexplorerView::OnUpdateEditCut(CCmdUI* pCmdUI)
{
pCmdUI->Enable(SCGetNumPages()>0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -