[!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] // $containeritemimpl$ : implementation of the $containeritemclass$ class // #include "pch.h" #include "framework.h" #include "$appheader$" [!if OLEDB_RECORD_VIEW || ODBC_RECORD_VIEW] #include "$rowsetheader$" [!endif] #include "$docheader$" #include "$viewheader$" #include "$containeritemheader$" #ifdef _DEBUG #define new DEBUG_NEW #endif // $containeritemclass$ implementation IMPLEMENT_SERIAL($containeritemclass$, $containeritembaseclass$, 0) [!if RICH_EDIT_VIEW] $containeritemclass$::$containeritemclass$(REOBJECT* preo, $docclass$* pContainer) : $containeritembaseclass$(preo, pContainer) [!else] $containeritemclass$::$containeritemclass$($docclass$* pContainer) : $containeritembaseclass$(pContainer) [!endif] { // TODO: add one-time construction code here } $containeritemclass$::~$containeritemclass$() { // TODO: add cleanup code here } [!if !RICH_EDIT_VIEW] void $containeritemclass$::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam) { ASSERT_VALID(this); $containeritembaseclass$::OnChange(nCode, dwParam); // When an item is being edited (either in-place or fully open) // it sends OnChange notifications for changes in the state of the // item or visual appearance of its content. // TODO: invalidate the item by calling UpdateAllViews // (with hints appropriate to your application) GetDocument()->UpdateAllViews(nullptr); // for now just update ALL views/no hints } BOOL $containeritemclass$::OnChangeItemPosition(const CRect& rectPos) { ASSERT_VALID(this); // During in-place activation $containeritemclass$::OnChangeItemPosition // is called by the server to change the position of the in-place // window. Usually, this is a result of the data in the server // document changing such that the extent has changed or as a result // of in-place resizing. // // The default here is to call the base class, which will call // $containeritembaseclass$::SetItemRects to move the item // to the new position. if (!$containeritembaseclass$::OnChangeItemPosition(rectPos)) return FALSE; // TODO: update any cache you may have of the item's rectangle/extent return TRUE; } BOOL $containeritemclass$::OnShowControlBars(CFrameWnd* pFrameWnd, BOOL bShow) { [!if APP_TYPE_MDI] CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, pFrameWnd); [!else] CFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CFrameWndEx, pFrameWnd); [!endif] if (pMainFrame != nullptr) { ASSERT_VALID(pMainFrame); return pMainFrame->OnShowPanes(bShow); } return FALSE; } [!if !ACTIVE_DOC_CONTAINER] void $containeritemclass$::OnGetItemPosition(CRect& rPosition) { ASSERT_VALID(this); // During in-place activation, $containeritemclass$::OnGetItemPosition // will be called to determine the location of this item. Usually, this // rectangle would reflect the current position of the item relative to the // view used for activation. You can obtain the view by calling // $containeritemclass$::GetActiveView. // TODO: return correct rectangle (in pixels) in rPosition CSize size; rPosition.SetRectEmpty(); if (GetExtent(&size, m_nDrawAspect)) { $viewclass$* pView = GetActiveView(); ASSERT_VALID(pView); if (!pView) return; CDC *pDC = pView->GetDC(); ASSERT(pDC); if (!pDC) return; pDC->HIMETRICtoLP(&size); rPosition.SetRect(10, 10, size.cx + 10, size.cy + 10); } else rPosition.SetRect(10, 10, 210, 210); } [!endif] void $containeritemclass$::OnActivate() { [!if !ACTIVE_DOC_CONTAINER] // Allow only one inplace activate item per frame $viewclass$* pView = GetActiveView(); ASSERT_VALID(pView); if (!pView) return; COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(pView); if (pItem != nullptr && pItem != this) pItem->Close(); $containeritembaseclass$::OnActivate(); [!endif] } void $containeritemclass$::OnDeactivateUI(BOOL bUndoable) { $containeritembaseclass$::OnDeactivateUI(bUndoable); DWORD dwMisc = 0; m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc); if (dwMisc & OLEMISC_INSIDEOUT) DoVerb(OLEIVERB_HIDE, nullptr); } void $containeritemclass$::Serialize(CArchive& ar) { ASSERT_VALID(this); // Call base class first to read in $containeritembaseclass$ data. // Since this sets up the m_pDocument pointer returned from // $containeritemclass$::GetDocument, it is a good idea to call // the base class Serialize first. $containeritembaseclass$::Serialize(ar); // now store/retrieve data specific to $containeritemclass$ if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } [!if CONTAINER_SERVER] BOOL $containeritemclass$::CanActivate() { // Editing in-place while the server itself is being edited in-place // does not work and is not supported. So, disable in-place // activation in this case. $docclass$* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return FALSE; ASSERT_KINDOF(COleServerDoc, pDoc); if (!pDoc->IsKindOf(RUNTIME_CLASS(COleServerDoc))) { return FALSE; } if (pDoc->IsInPlaceActive()) return FALSE; // otherwise, rely on default behavior return COleClientItem::CanActivate(); } [!endif] [!endif] // $containeritemclass$ diagnostics #ifdef _DEBUG void $containeritemclass$::AssertValid() const { $containeritembaseclass$::AssertValid(); } void $containeritemclass$::Dump(CDumpContext& dc) const { $containeritembaseclass$::Dump(dc); } #endif