www.pudn.com > CHA03.rar   To Read all the content


[file head]:
// CntrItem.cpp : implementation of the CDrawItem class
//

#include "stdafx.h"
#include "DrawCli.h"

#include "DrawDoc.h"
#include "DrawVw.h"
#include "DrawObj.h"
#include "CntrItem.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDrawItem implementation

IMPLEMENT_SERIAL(CDrawItem, COleClientItem, 0)
/*
CDrawItem::CDrawItem(CDrawDoc* pContainer)
: COleClientItem(pContainer)
{
// TODO: add one-time construction code here
}
*/
CDrawItem::CDrawItem(CDrawDoc* pContainer, CDrawOleObj* pDrawObj)
: COleClientItem(pContainer)
{
m_pDrawObj = pDrawObj;
}

CDrawItem::~CDrawItem()
{
// TODO: add cleanup code here

}

void CDrawItem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)
{
ASSERT_VALID(this);

COleClientItem::OnChange(nCode, dwParam);

// When an item is being edited (either in-place or fully open)

... ...

[file tail]:
... ...
////////////////////////////////////////
BOOL CDrawItem::UpdateExtent()
{
CSize size;
if (!GetExtent(&amt;size) || size == m_pDrawObj->m_extent)
return FALSE; // blank

// if new object (i.e. m_extent is empty) setup position
if (m_pDrawObj->m_extent == CSize(0, 0))
{
m_pDrawObj->m_position.right =
m_pDrawObj->m_position.left + MulDiv(size.cx, 10, 254);
m_pDrawObj->m_position.bottom =
m_pDrawObj->m_position.top - MulDiv(size.cy, 10, 254);
}
// else data changed so scale up rect as well
else if (!IsInPlaceActive() &amt;&amt; size != m_pDrawObj->m_extent)
{
m_pDrawObj->m_position.right = m_pDrawObj->m_position.left +
MulDiv(m_pDrawObj->m_position.Width(), size.cx, m_pDrawObj->m_extent.cx);
m_pDrawObj->m_position.bottom = m_pDrawObj->m_position.top +
MulDiv(m_pDrawObj->m_position.Height(), size.cy, m_pDrawObj->m_extent.cy);
}

m_pDrawObj->m_extent = size;
m_pDrawObj->Invalidate(); // redraw to the new size/position
return TRUE;
}