[!if RIBBON_TOOLBAR] // This MFC Samples source code demonstrates using MFC Microsoft Office Fluent User Interface // (the "Fluent UI") and is provided only as referential material to supplement the // Microsoft Foundation Classes Reference and related electronic documentation // included with the MFC C++ library software. // License terms to copy, use or distribute the Fluent UI are available separately. // To learn more about our Fluent UI licensing program, please visit // https://go.microsoft.com/fwlink/?LinkId=238214. // // Copyright (C) Microsoft Corporation // All rights reserved. [!endif] // $docimpl$ : implementation of the $docclass$ class // #include "pch.h" #include "framework.h" // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail // and search filter handlers and allows sharing of document code with that project. #ifndef SHARED_HANDLERS #include "$appheader$" #endif [!if OLEDB_RECORD_VIEW || ODBC_RECORD_VIEW] #include "$rowsetheader$" [!endif] #include "$docheader$" [!if CONTAINER || CONTAINER_SERVER] #include "$containeritemheader$" [!endif] [!if MINI_SERVER || FULL_SERVER || CONTAINER_SERVER] #include "$serveritemheader$" [!endif] #include #ifdef _DEBUG #define new DEBUG_NEW #endif // $docclass$ IMPLEMENT_DYNCREATE($docclass$, $docbaseclass$) BEGIN_MESSAGE_MAP($docclass$, $docbaseclass$) [!if CONTAINER || CONTAINER_SERVER] // Enable default OLE container implementation [!if !RICH_EDIT_VIEW] ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, &$docbaseclass$::OnUpdatePasteMenu) ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_LINK, &$docbaseclass$::OnUpdatePasteLinkMenu) ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_CONVERT, &$docbaseclass$::OnUpdateObjectVerbMenu) ON_COMMAND(ID_OLE_EDIT_CONVERT, &$docbaseclass$::OnEditConvert) [!endif] ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, &$docbaseclass$::OnUpdateEditLinksMenu) ON_UPDATE_COMMAND_UI(ID_OLE_VERB_POPUP, &$docclass$::OnUpdateObjectVerbPopup) ON_COMMAND(ID_OLE_EDIT_LINKS, &$docbaseclass$::OnEditLinks) ON_UPDATE_COMMAND_UI_RANGE(ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, &$docbaseclass$::OnUpdateObjectVerbMenu) [!endif] [!if MAPI] ON_COMMAND(ID_FILE_SEND_MAIL, &$docclass$::OnFileSendMail) ON_UPDATE_COMMAND_UI(ID_FILE_SEND_MAIL, &$docclass$::OnUpdateFileSendMail) [!endif] END_MESSAGE_MAP() [!if AUTOMATION] BEGIN_DISPATCH_MAP($docclass$, $docbaseclass$) END_DISPATCH_MAP() // Note: we add support for IID_I$safeprojectidentifiername$ to support typesafe binding // from VBA. This IID must match the GUID that is attached to the // dispinterface in the .IDL file. // {$guid_disp_iid$} static const IID IID_I$safeprojectidentifiername$ = $guid_disp_iid_staticconst$; BEGIN_INTERFACE_MAP($docclass$, $docbaseclass$) INTERFACE_PART($docclass$, IID_I$safeprojectidentifiername$, Dispatch) END_INTERFACE_MAP() [!endif] // $docclass$ construction/destruction $docclass$::$docclass$() noexcept { [!if SUPPORT_COMPOUND_FILES && !COMPOUND_DOC_NONE] // Use OLE compound files EnableCompoundFile(); [!endif] // TODO: add one-time construction code here [!if AUTOMATION] EnableAutomation(); AfxOleLockApp(); [!endif] } $docclass$::~$docclass$() { [!if AUTOMATION] AfxOleUnlockApp(); [!endif] } BOOL $docclass$::OnNewDocument() { if (!$docbaseclass$::OnNewDocument()) return FALSE; [!if APP_TYPE_SDI] [!if EDIT_VIEW] if (!m_viewList.IsEmpty()) { [!if PROJECT_STYLE_EXPLORER] POSITION pos = GetFirstViewPosition(); GetNextView(pos); // skip the tree view reinterpret_cast(GetNextView(pos))->SetWindowText(nullptr); [!else] reinterpret_cast(m_viewList.GetHead())->SetWindowText(nullptr); [!endif] } [!endif] [!endif] // TODO: add reinitialization code here // (SDI documents will reuse this document) return TRUE; } [!if RICH_EDIT_VIEW] $containeritembaseclass$* $docclass$::CreateClientItem(REOBJECT* preo) const { return new $containeritemclass$(preo, const_cast<$docclass$*>(this)); } [!endif] [!if MINI_SERVER || FULL_SERVER || CONTAINER_SERVER] // $docclass$ server implementation COleServerItem* $docclass$::OnGetEmbeddedItem() { // OnGetEmbeddedItem is called by the framework to get the COleServerItem // that is associated with the document. It is only called when necessary. $serveritemclass$* pItem = new $serveritemclass$(this); ASSERT_VALID(pItem); return pItem; } [!endif] [!if ACTIVE_DOC_SERVER] // $docclass$ Active Document server implementation CDocObjectServer *$docclass$::GetDocObjectServer(LPOLEDOCUMENTSITE pDocSite) { return new CDocObjectServer(this, pDocSite); } [!endif] [!if !DB_VIEW_NO_FILE && !HTML_EDITVIEW] // $docclass$ serialization void $docclass$::Serialize(CArchive& ar) { [!if EDIT_VIEW] // CEditView contains an edit control which handles all serialization if (!m_viewList.IsEmpty()) { [!if PROJECT_STYLE_EXPLORER] POSITION pos = GetFirstViewPosition(); GetNextView(pos); // skip the tree view reinterpret_cast(GetNextView(pos))->SerializeRaw(ar); [!else] reinterpret_cast(m_viewList.GetHead())->SerializeRaw(ar); [!endif] } #ifdef SHARED_HANDLERS if (m_viewList.IsEmpty() && ar.IsLoading()) { CFile* pFile = ar.GetFile(); pFile->Seek(0, FILE_BEGIN); ULONGLONG nFileSizeBytes = pFile->GetLength(); ULONGLONG nFileSizeChars = nFileSizeBytes/sizeof(TCHAR); LPTSTR lpszText = (LPTSTR)malloc(((size_t)nFileSizeChars + 1) * sizeof(TCHAR)); if (lpszText != nullptr) { ar.Read(lpszText, (UINT)nFileSizeBytes); lpszText[nFileSizeChars] = '\0'; m_strThumbnailContent = lpszText; m_strSearchContent = lpszText; } } #endif [!else] if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } [!if CONTAINER || CONTAINER_SERVER] // Calling the base class $docbaseclass$ enables serialization // of the container document's COleClientItem objects. [!if RICH_EDIT_VIEW] // TODO: set CRichEditDoc::m_bRTF = FALSE if you are serializing as text [!endif] $docbaseclass$::Serialize(ar); [!if ACTIVE_DOC_CONTAINER] // activate the first one if (!ar.IsStoring()) { POSITION posItem = GetStartPosition(); if (posItem != nullptr) { CDocItem* pItem = GetNextItem(posItem); POSITION posView = GetFirstViewPosition(); COleDocObjectItem *pDocObjectItem = DYNAMIC_DOWNCAST(COleDocObjectItem, pItem); if (posView != nullptr && pDocObjectItem != nullptr) { CView* pView = GetNextView(posView); pDocObjectItem->DoVerb(OLEIVERB_SHOW, pView); } } } [!endif] [!endif] [!endif] } [!endif] #ifdef SHARED_HANDLERS // Support for thumbnails void $docclass$::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds) { // Modify this code to draw the document's data dc.FillSolidRect(lprcBounds, RGB(255, 255, 255)); [!if !EDIT_VIEW] CString strText = _T("TODO: implement thumbnail drawing here"); [!endif] LOGFONT lf; CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)); pDefaultGUIFont->GetLogFont(&lf); lf.lfHeight = 36; CFont fontDraw; fontDraw.CreateFontIndirect(&lf); CFont* pOldFont = dc.SelectObject(&fontDraw); [!if !EDIT_VIEW] dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK); [!else] dc.DrawText(m_strThumbnailContent, lprcBounds, DT_CENTER | DT_WORDBREAK); [!endif] dc.SelectObject(pOldFont); } // Support for Search Handlers void $docclass$::InitializeSearchContent() { [!if !EDIT_VIEW] CString strSearchContent; [!endif] // Set search contents from document's data. // The content parts should be separated by ";" [!if !EDIT_VIEW] // For example: strSearchContent = _T("point;rectangle;circle;ole object;"); SetSearchContent(strSearchContent); [!else] // Use the entire text file content as the search content. SetSearchContent(m_strSearchContent); [!endif] } void $docclass$::SetSearchContent(const CString& value) { if (value.IsEmpty()) { RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid); } else { CMFCFilterChunkValueImpl *pChunk = nullptr; ATLTRY(pChunk = new CMFCFilterChunkValueImpl); if (pChunk != nullptr) { pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT); SetChunkValue(pChunk); } } } #endif // SHARED_HANDLERS // $docclass$ diagnostics #ifdef _DEBUG void $docclass$::AssertValid() const { $docbaseclass$::AssertValid(); } void $docclass$::Dump(CDumpContext& dc) const { $docbaseclass$::Dump(dc); } #endif //_DEBUG // $docclass$ commands