Скачиваний:
7
Добавлен:
01.05.2014
Размер:
4.3 Кб
Скачать
// CntrItem.cpp : implementation of the CPart32CntrItem class
//

#include "stdafx.h"
#include "part32.h"

#include "part32Doc.h"
#include "part32View.h"
#include "CntrItem.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPart32CntrItem implementation

IMPLEMENT_SERIAL(CPart32CntrItem, COleClientItem, 0)

CPart32CntrItem::CPart32CntrItem(CPart32Doc* pContainer)
	: COleClientItem(pContainer)
{
	// TODO: add one-time construction code here
	m_Rect=CRect(10, 10, 210, 210);
}

CPart32CntrItem::~CPart32CntrItem()
{
	// TODO: add cleanup code here
	
}

void CPart32CntrItem::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)
	//  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 CPart32CntrItem::OnChangeItemPosition(const CRect& rectPos)
{
	ASSERT_VALID(this);

	m_Rect=rectPos;
	GetDocument()->SetModifiedFlag();
	GetDocument()->UpdateAllViews(NULL);

	if (!COleClientItem::OnChangeItemPosition(rectPos))
		return FALSE;

	// TODO: update any cache you may have of the item's rectangle/extent

	return TRUE;
}

void CPart32CntrItem::OnGetItemPosition(CRect& rPosition)
{
	ASSERT_VALID(this);

	// During in-place activation, CPart32CntrItem::OnGetItemPosition
	//  will be called to determine the location of this item.  The default
	//  implementation created from AppWizard simply returns a hard-coded
	//  rectangle.  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 CPart32CntrItem::GetActiveView.

	// TODO: return correct rectangle (in pixels) in rPosition

//	rPosition.SetRect(10, 10, 210, 210);
	rPosition=m_Rect;
}

void CPart32CntrItem::OnActivate()
{
    // Allow only one inplace activate item per frame
    CPart32View* pView = GetActiveView();
    ASSERT_VALID(pView);
    COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(pView);
    if (pItem != NULL && pItem != this)
        pItem->Close();
    
    COleClientItem::OnActivate();
}

void CPart32CntrItem::OnDeactivateUI(BOOL bUndoable)
{
	COleClientItem::OnDeactivateUI(bUndoable);

    // Hide the object if it is not an outside-in object
    DWORD dwMisc = 0;
    m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc);
    if (dwMisc & OLEMISC_INSIDEOUT)
        DoVerb(OLEIVERB_HIDE, NULL);
}

void CPart32CntrItem::Serialize(CArchive& ar)
{
	ASSERT_VALID(this);

	// Call base class first to read in COleClientItem data.
	// Since this sets up the m_pDocument pointer returned from
	//  CPart32CntrItem::GetDocument, it is a good idea to call
	//  the base class Serialize first.
	COleClientItem::Serialize(ar);

	// now store/retrieve data specific to CPart32CntrItem
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		ar<<m_Rect;
	}
	else
	{
		// TODO: add loading code here
		ar>>m_Rect;
	}
}

BOOL CPart32CntrItem::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.
	CPart32Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(COleServerDoc)));
	if (pDoc->IsInPlaceActive())
		return FALSE;

	// otherwise, rely on default behavior
	return COleClientItem::CanActivate();
}

/////////////////////////////////////////////////////////////////////////////
// CPart32CntrItem diagnostics

#ifdef _DEBUG
void CPart32CntrItem::AssertValid() const
{
	COleClientItem::AssertValid();
}

void CPart32CntrItem::Dump(CDumpContext& dc) const
{
	COleClientItem::Dump(dc);
}
#endif

/////////////////////////////////////////////////////////////////////////////
Соседние файлы в папке part32