📄 wordpdoc.cpp
字号:
TRACE0("Warning: failed to delete file after failed SaveAs\n");
}
END_CATCH_ALL
}
// restore orginal document type
SetDocType(nOrigDocType, TRUE);
EndWaitCursor();
return FALSE;
}
EndWaitCursor();
if (bReplace)
{
int nType = m_nDocType;
SetDocType(nOrigDocType, TRUE);
SetDocType(nType);
// Reset the title and change the document name
SetPathName(newName, TRUE);
ASSERT(m_strPathName == newName); // must be set
}
else // SaveCopyAs
{
SetDocType(nOrigDocType, TRUE);
SetModifiedFlag(bModified);
}
return TRUE; // success
}
class COIPF : public COleIPFrameWnd
{
public:
CFrameWnd* GetMainFrame() { return m_pMainFrame;}
CFrameWnd* GetDocFrame() { return m_pDocFrame;}
};
void CWordPadDoc::OnDeactivateUI(BOOL bUndoable)
{
if (GetView()->m_bDelayUpdateItems)
UpdateAllItems(NULL);
SaveState(m_nDocType);
CRichEditDoc::OnDeactivateUI(bUndoable);
COIPF* pFrame = (COIPF*)m_pInPlaceFrame;
if (pFrame != NULL)
{
if (pFrame->GetMainFrame() != NULL)
ForceDelayed(pFrame->GetMainFrame());
if (pFrame->GetDocFrame() != NULL)
ForceDelayed(pFrame->GetDocFrame());
}
}
void CWordPadDoc::ForceDelayed(CFrameWnd* pFrameWnd)
{
ASSERT_VALID(this);
ASSERT_VALID(pFrameWnd);
POSITION pos = pFrameWnd->m_listControlBars.GetHeadPosition();
while (pos != NULL)
{
// show/hide the next control bar
CControlBar* pBar =
(CControlBar*)pFrameWnd->m_listControlBars.GetNext(pos);
BOOL bVis = pBar->GetStyle() & WS_VISIBLE;
UINT swpFlags = 0;
if ((pBar->m_nStateFlags & CControlBar::delayHide) && bVis)
swpFlags = SWP_HIDEWINDOW;
else if ((pBar->m_nStateFlags & CControlBar::delayShow) && !bVis)
swpFlags = SWP_SHOWWINDOW;
pBar->m_nStateFlags &= ~(CControlBar::delayShow|CControlBar::delayHide);
if (swpFlags != 0)
{
pBar->SetWindowPos(NULL, 0, 0, 0, 0, swpFlags|
SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CWordPadDoc Attributes
CLSID CWordPadDoc::GetClassID()
{
return (m_pFactory == NULL) ? CLSID_NULL : m_pFactory->GetClassID();
}
void CWordPadDoc::SetDocType(int nNewDocType, BOOL bNoOptionChange)
{
ASSERT(nNewDocType != -1);
if (nNewDocType == m_nDocType)
return;
m_bRTF = !IsTextType(nNewDocType);
if (bNoOptionChange)
m_nDocType = nNewDocType;
else
{
SaveState(m_nDocType);
m_nDocType = nNewDocType;
RestoreState(m_nDocType);
}
}
CWordPadView* CWordPadDoc::GetView()
{
POSITION pos = GetFirstViewPosition();
return (CWordPadView* )GetNextView( pos );
}
/////////////////////////////////////////////////////////////////////////////
// CWordPadDoc Operations
CFile* CWordPadDoc::GetFile(LPCTSTR pszPathName, UINT nOpenFlags, CFileException* pException)
{
CTrackFile* pFile = NULL;
CFrameWnd* pWnd = GetView()->GetParentFrame();
#ifdef CONVERTERS
ScanForConverters();
// if writing use current doc type otherwise use new doc type
int nType = (nOpenFlags & CFile::modeReadWrite) ? m_nDocType : m_nNewDocType;
// m_nNewDocType will be same as m_nDocType except when opening a new file
if (doctypes[nType].pszConverterName != NULL)
pFile = new CConverter(doctypes[nType].pszConverterName, pWnd);
else
#endif
if (nType == RD_OEMTEXT)
pFile = new COEMFile(pWnd);
else
pFile = new CTrackFile(pWnd);
if (!pFile->Open(pszPathName, nOpenFlags, pException))
{
delete pFile;
return NULL;
}
if (nOpenFlags & (CFile::modeWrite | CFile::modeReadWrite))
pFile->m_dwLength = 0; // can't estimate this
else
pFile->m_dwLength = pFile->GetLength();
return pFile;
}
CRichEditCntrItem* CWordPadDoc::CreateClientItem(REOBJECT* preo) const
{
// cast away constness of this
return new CWordPadCntrItem(preo, (CWordPadDoc*)this);
}
/////////////////////////////////////////////////////////////////////////////
// CWordPadDoc server implementation
COleServerItem* CWordPadDoc::OnGetEmbeddedItem()
{
// OnGetEmbeddedItem is called by the framework to get the COleServerItem
// that is associated with the document. It is only called when necessary.
CEmbeddedItem* pItem = new CEmbeddedItem(this);
ASSERT_VALID(pItem);
return pItem;
}
/////////////////////////////////////////////////////////////////////////////
// CWordPadDoc serialization
/////////////////////////////////////////////////////////////////////////////
// CWordPadDoc diagnostics
#ifdef _DEBUG
void CWordPadDoc::AssertValid() const
{
CRichEditDoc::AssertValid();
}
void CWordPadDoc::Dump(CDumpContext& dc) const
{
CRichEditDoc::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWordPadDoc commands
int CWordPadDoc::MapType(int nType)
{
if (nType == RD_OEMTEXT)
nType = RD_TEXT;
else if (!IsInPlaceActive() && nType == RD_EMBEDDED)
nType = RD_RICHTEXT;
return nType;
}
void CWordPadDoc::OnViewOptions()
{
int nType = MapType(m_nDocType);
int nFirstPage = 3;
if (nType == RD_TEXT)
nFirstPage = 1;
else if (nType == RD_RICHTEXT)
nFirstPage = 2;
else if (nType == RD_WRITE)
nFirstPage = 4;
else if (nType == RD_EMBEDDED)
nFirstPage = 5;
SaveState(nType);
COptionSheet sheet(IDS_OPTIONS, NULL, nFirstPage);
if (sheet.DoModal() == IDOK)
{
CWordPadView* pView = GetView();
if (theApp.m_bWordSel)
pView->GetRichEditCtrl().SetOptions(ECOOP_OR, ECO_AUTOWORDSELECTION);
else
{
pView->GetRichEditCtrl().SetOptions(ECOOP_AND,
~(DWORD)ECO_AUTOWORDSELECTION);
}
RestoreState(nType);
}
}
void CWordPadDoc::OnUpdateOleVerbPopup(CCmdUI* pCmdUI)
{
pCmdUI->m_pParentMenu = pCmdUI->m_pMenu;
CRichEditDoc::OnUpdateObjectVerbMenu(pCmdUI);
}
BOOL CWordPadDoc::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
if (nCode == CN_COMMAND && nID == ID_OLE_VERB_POPUP)
nID = ID_OLE_VERB_FIRST;
return CRichEditDoc::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
void CWordPadDoc::SaveState(int nType)
{
if (nType == -1)
return;
nType = MapType(nType);
CWordPadView* pView = GetView();
if (pView != NULL)
{
CFrameWnd* pFrame = pView->GetParentFrame();
ASSERT(pFrame != NULL);
// save current state
pFrame->SendMessage(WPM_BARSTATE, 0, nType);
theApp.GetDocOptions(nType).m_nWordWrap = pView->m_nWordWrap;
}
}
void CWordPadDoc::RestoreState(int nType)
{
if (nType == -1)
return;
nType = MapType(nType);
CWordPadView* pView = GetView();
if (pView != NULL)
{
CFrameWnd* pFrame = pView->GetParentFrame();
ASSERT(pFrame != NULL);
// set new state
pFrame->SendMessage(WPM_BARSTATE, 1, nType);
int nWrapNew = theApp.GetDocOptions(nType).m_nWordWrap;
if (pView->m_nWordWrap != nWrapNew)
{
pView->m_nWordWrap = nWrapNew;
pView->WrapChanged();
}
}
}
void CWordPadDoc::OnCloseDocument()
{
SaveState(m_nDocType);
CRichEditDoc::OnCloseDocument();
}
void CWordPadDoc::PreCloseFrame(CFrameWnd* pFrameArg)
{
CRichEditDoc::PreCloseFrame(pFrameArg);
SaveState(m_nDocType);
}
void CWordPadDoc::OnFileSendMail()
{
if (m_strTitle.Find('.') == -1)
{
// add the extension because the default extension will be wrong
CString strOldTitle = m_strTitle;
m_strTitle += GetExtFromType(m_nDocType);
CRichEditDoc::OnFileSendMail();
m_strTitle = strOldTitle;
}
else
CRichEditDoc::OnFileSendMail();
}
void CWordPadDoc::OnUpdateIfEmbedded(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!IsEmbedded());
}
void CWordPadDoc::OnTestPaperSele()
{
// TODO: Add your command handler code here
CTestSeleDlg dlg;
dlg.DoModal();
}
void CWordPadDoc::OnManSele()
{
CManSeleDlg dlg;
dlg.DoModal();
}
void CWordPadDoc::OnTestEdit()
{
CTestDlg dlg;
dlg.DoModal(); // TODO: Add your command handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -