// [!output CONTAINER_ITEM_IMPL] : implementation of the [!output CONTAINER_ITEM_CLASS] class // #include "stdafx.h" #include "[!output APP_HEADER]" [!if OLEDB_RECORD_VIEW || ODBC_RECORD_VIEW] #include "[!output ROWSET_HEADER]" [!endif] #include "[!output DOC_HEADER]" #include "[!output VIEW_HEADER]" #include "[!output CONTAINER_ITEM_HEADER]" #ifdef _DEBUG #define new DEBUG_NEW #endif // [!output CONTAINER_ITEM_CLASS] implementation IMPLEMENT_SERIAL([!output CONTAINER_ITEM_CLASS], [!output CONTAINER_ITEM_BASE_CLASS], 0) [!if RICH_EDIT_VIEW] [!output CONTAINER_ITEM_CLASS]::[!output CONTAINER_ITEM_CLASS](REOBJECT* preo, [!output DOC_CLASS]* pContainer) : [!output CONTAINER_ITEM_BASE_CLASS](preo, pContainer) [!else] [!output CONTAINER_ITEM_CLASS]::[!output CONTAINER_ITEM_CLASS]([!output DOC_CLASS]* pContainer) : [!output CONTAINER_ITEM_BASE_CLASS](pContainer) [!endif] { // TODO: add one-time construction code here } [!output CONTAINER_ITEM_CLASS]::~[!output CONTAINER_ITEM_CLASS]() { // TODO: add cleanup code here } [!if !RICH_EDIT_VIEW] void [!output CONTAINER_ITEM_CLASS]::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam) { ASSERT_VALID(this); [!output CONTAINER_ITEM_BASE_CLASS]::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(NULL); // for now just update ALL views/no hints } BOOL [!output CONTAINER_ITEM_CLASS]::OnChangeItemPosition(const CRect& rectPos) { ASSERT_VALID(this); // During in-place activation [!output CONTAINER_ITEM_CLASS]::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 // [!output CONTAINER_ITEM_BASE_CLASS]::SetItemRects to move the item // to the new position. if (![!output CONTAINER_ITEM_BASE_CLASS]::OnChangeItemPosition(rectPos)) return FALSE; // TODO: update any cache you may have of the item's rectangle/extent return TRUE; } [!if !ACTIVE_DOC_CONTAINER] void [!output CONTAINER_ITEM_CLASS]::OnGetItemPosition(CRect& rPosition) { ASSERT_VALID(this); // During in-place activation, [!output CONTAINER_ITEM_CLASS]::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 // [!output CONTAINER_ITEM_CLASS]::GetActiveView. // TODO: return correct rectangle (in pixels) in rPosition CSize size; rPosition.SetRectEmpty(); if (SUCCEEDED(GetExtent(&size, m_nDrawAspect))) { [!output VIEW_CLASS]* pView = GetActiveView(); ASSERT_VALID(pView); if (!pView) return; CDC *pDC = pView->GetDC(); _ASSERTE(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 [!output CONTAINER_ITEM_CLASS]::OnActivate() { [!if !ACTIVE_DOC_CONTAINER] // Allow only one inplace activate item per frame [!output VIEW_CLASS]* pView = GetActiveView(); ASSERT_VALID(pView); if (!pView) return; COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(pView); if (pItem != NULL && pItem != this) pItem->Close(); [!output CONTAINER_ITEM_BASE_CLASS]::OnActivate(); [!endif] } void [!output CONTAINER_ITEM_CLASS]::OnDeactivateUI(BOOL bUndoable) { [!output CONTAINER_ITEM_BASE_CLASS]::OnDeactivateUI(bUndoable); DWORD dwMisc = 0; m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc); if (dwMisc & OLEMISC_INSIDEOUT) DoVerb(OLEIVERB_HIDE, NULL); } void [!output CONTAINER_ITEM_CLASS]::Serialize(CArchive& ar) { ASSERT_VALID(this); // Call base class first to read in [!output CONTAINER_ITEM_BASE_CLASS] data. // Since this sets up the m_pDocument pointer returned from // [!output CONTAINER_ITEM_CLASS]::GetDocument, it is a good idea to call // the base class Serialize first. [!output CONTAINER_ITEM_BASE_CLASS]::Serialize(ar); // now store/retrieve data specific to [!output CONTAINER_ITEM_CLASS] if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } [!if CONTAINER_SERVER] BOOL [!output CONTAINER_ITEM_CLASS]::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. [!output DOC_CLASS]* 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] // [!output CONTAINER_ITEM_CLASS] diagnostics #ifdef _DEBUG void [!output CONTAINER_ITEM_CLASS]::AssertValid() const { [!output CONTAINER_ITEM_BASE_CLASS]::AssertValid(); } void [!output CONTAINER_ITEM_CLASS]::Dump(CDumpContext& dc) const { [!output CONTAINER_ITEM_BASE_CLASS]::Dump(dc); } #endif