[32] | 1 | // CntrItem.cpp : implementation of the CTestProgCntrItem class
|
---|
| 2 | //
|
---|
| 3 |
|
---|
| 4 | #include "stdafx.h"
|
---|
| 5 | #include "TestProg.h"
|
---|
| 6 |
|
---|
| 7 | #include "TestProgDoc.h"
|
---|
| 8 | #include "TestProgView.h"
|
---|
| 9 | #include "CntrItem.h"
|
---|
| 10 |
|
---|
| 11 | #ifdef _DEBUG
|
---|
| 12 | #define new DEBUG_NEW
|
---|
| 13 | #endif
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 | // CTestProgCntrItem implementation
|
---|
| 17 |
|
---|
| 18 | IMPLEMENT_SERIAL(CTestProgCntrItem, COleClientItem, 0)
|
---|
| 19 |
|
---|
| 20 | CTestProgCntrItem::CTestProgCntrItem(CTestProgDoc* pContainer)
|
---|
| 21 | : COleClientItem(pContainer)
|
---|
| 22 | {
|
---|
| 23 | // TODO: add one-time construction code here
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | CTestProgCntrItem::~CTestProgCntrItem()
|
---|
| 27 | {
|
---|
| 28 | // TODO: add cleanup code here
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | void CTestProgCntrItem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)
|
---|
| 32 | {
|
---|
| 33 | ASSERT_VALID(this);
|
---|
| 34 |
|
---|
| 35 | COleClientItem::OnChange(nCode, dwParam);
|
---|
| 36 |
|
---|
| 37 | // When an item is being edited (either in-place or fully open)
|
---|
| 38 | // it sends OnChange notifications for changes in the state of the
|
---|
| 39 | // item or visual appearance of its content.
|
---|
| 40 |
|
---|
| 41 | // TODO: invalidate the item by calling UpdateAllViews
|
---|
| 42 | // (with hints appropriate to your application)
|
---|
| 43 |
|
---|
| 44 | GetDocument()->UpdateAllViews(NULL);
|
---|
| 45 | // for now just update ALL views/no hints
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | BOOL CTestProgCntrItem::OnChangeItemPosition(const CRect& rectPos)
|
---|
| 49 | {
|
---|
| 50 | ASSERT_VALID(this);
|
---|
| 51 |
|
---|
| 52 | // During in-place activation CTestProgCntrItem::OnChangeItemPosition
|
---|
| 53 | // is called by the server to change the position of the in-place
|
---|
| 54 | // window. Usually, this is a result of the data in the server
|
---|
| 55 | // document changing such that the extent has changed or as a result
|
---|
| 56 | // of in-place resizing.
|
---|
| 57 | //
|
---|
| 58 | // The default here is to call the base class, which will call
|
---|
| 59 | // COleClientItem::SetItemRects to move the item
|
---|
| 60 | // to the new position.
|
---|
| 61 |
|
---|
| 62 | if (!COleClientItem::OnChangeItemPosition(rectPos))
|
---|
| 63 | return FALSE;
|
---|
| 64 |
|
---|
| 65 | // TODO: update any cache you may have of the item's rectangle/extent
|
---|
| 66 |
|
---|
| 67 | return TRUE;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | void CTestProgCntrItem::OnGetItemPosition(CRect& rPosition)
|
---|
| 71 | {
|
---|
| 72 | ASSERT_VALID(this);
|
---|
| 73 |
|
---|
| 74 | // During in-place activation, CTestProgCntrItem::OnGetItemPosition
|
---|
| 75 | // will be called to determine the location of this item. Usually, this
|
---|
| 76 | // rectangle would reflect the current position of the item relative to the
|
---|
| 77 | // view used for activation. You can obtain the view by calling
|
---|
| 78 | // CTestProgCntrItem::GetActiveView.
|
---|
| 79 |
|
---|
| 80 | // TODO: return correct rectangle (in pixels) in rPosition
|
---|
| 81 |
|
---|
| 82 | CSize size;
|
---|
| 83 | rPosition.SetRectEmpty();
|
---|
| 84 | if (GetExtent(&size, m_nDrawAspect))
|
---|
| 85 | {
|
---|
| 86 | CTestProgView* pView = GetActiveView();
|
---|
| 87 | ASSERT_VALID(pView);
|
---|
| 88 | if (!pView)
|
---|
| 89 | return;
|
---|
| 90 | CDC *pDC = pView->GetDC();
|
---|
| 91 | ASSERT(pDC);
|
---|
| 92 | if (!pDC)
|
---|
| 93 | return;
|
---|
| 94 | pDC->HIMETRICtoLP(&size);
|
---|
| 95 | rPosition.SetRect(10, 10, size.cx + 10, size.cy + 10);
|
---|
| 96 | }
|
---|
| 97 | else
|
---|
| 98 | rPosition.SetRect(10, 10, 210, 210);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | void CTestProgCntrItem::OnActivate()
|
---|
| 102 | {
|
---|
| 103 | // Allow only one inplace activate item per frame
|
---|
| 104 | CTestProgView* pView = GetActiveView();
|
---|
| 105 | ASSERT_VALID(pView);
|
---|
| 106 | if (!pView)
|
---|
| 107 | return;
|
---|
| 108 | COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(pView);
|
---|
| 109 | if (pItem != NULL && pItem != this)
|
---|
| 110 | pItem->Close();
|
---|
| 111 |
|
---|
| 112 | COleClientItem::OnActivate();
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | void CTestProgCntrItem::OnDeactivateUI(BOOL bUndoable)
|
---|
| 116 | {
|
---|
| 117 | COleClientItem::OnDeactivateUI(bUndoable);
|
---|
| 118 |
|
---|
| 119 | DWORD dwMisc = 0;
|
---|
| 120 | m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc);
|
---|
| 121 | if (dwMisc & OLEMISC_INSIDEOUT)
|
---|
| 122 | DoVerb(OLEIVERB_HIDE, NULL);
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | void CTestProgCntrItem::Serialize(CArchive& ar)
|
---|
| 126 | {
|
---|
| 127 | ASSERT_VALID(this);
|
---|
| 128 |
|
---|
| 129 | // Call base class first to read in COleClientItem data.
|
---|
| 130 | // Since this sets up the m_pDocument pointer returned from
|
---|
| 131 | // CTestProgCntrItem::GetDocument, it is a good idea to call
|
---|
| 132 | // the base class Serialize first.
|
---|
| 133 | COleClientItem::Serialize(ar);
|
---|
| 134 |
|
---|
| 135 | // now store/retrieve data specific to CTestProgCntrItem
|
---|
| 136 | if (ar.IsStoring())
|
---|
| 137 | {
|
---|
| 138 | // TODO: add storing code here
|
---|
| 139 | }
|
---|
| 140 | else
|
---|
| 141 | {
|
---|
| 142 | // TODO: add loading code here
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | BOOL CTestProgCntrItem::CanActivate()
|
---|
| 147 | {
|
---|
| 148 | // Editing in-place while the server itself is being edited in-place
|
---|
| 149 | // does not work and is not supported. So, disable in-place
|
---|
| 150 | // activation in this case.
|
---|
| 151 | CTestProgDoc* pDoc = GetDocument();
|
---|
| 152 | ASSERT_VALID(pDoc);
|
---|
| 153 | if (!pDoc)
|
---|
| 154 | return FALSE;
|
---|
| 155 | ASSERT_KINDOF(COleServerDoc, pDoc);
|
---|
| 156 | if (!pDoc->IsKindOf(RUNTIME_CLASS(COleServerDoc)))
|
---|
| 157 | {
|
---|
| 158 | return FALSE;
|
---|
| 159 | }
|
---|
| 160 | if (pDoc->IsInPlaceActive())
|
---|
| 161 | return FALSE;
|
---|
| 162 |
|
---|
| 163 | // otherwise, rely on default behavior
|
---|
| 164 | return COleClientItem::CanActivate();
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 | // CTestProgCntrItem diagnostics
|
---|
| 169 |
|
---|
| 170 | #ifdef _DEBUG
|
---|
| 171 | void CTestProgCntrItem::AssertValid() const
|
---|
| 172 | {
|
---|
| 173 | COleClientItem::AssertValid();
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | void CTestProgCntrItem::Dump(CDumpContext& dc) const
|
---|
| 177 | {
|
---|
| 178 | COleClientItem::Dump(dc);
|
---|
| 179 | }
|
---|
| 180 | #endif
|
---|
| 181 |
|
---|