home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n04
/
olecont.exe
/
CONTITEM.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-01
|
5KB
|
227 lines
// contitem.cpp : implementation of the CContainerItem class
//
#include "stdafx.h"
#include "contain.h"
#include "cntlinfo.h"
#include "contdoc.h"
#include "cntlitem.h"
#include "contitem.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CContainerItem implementation
IMPLEMENT_SERIAL(CContainerItem, CControlItem, 0)
CContainerItem::CContainerItem(CContainerDoc* pContainer)
: CControlItem(pContainer)
{
m_rect.SetRect(10, 10, 50, 50); // An Initial Size for the control
m_extent = CSize(0, 0); // Set extent to zero
}
CContainerItem::~CContainerItem()
{
// TODO: add cleanup code here
}
void CContainerItem::Invalidate(CView* pNotThisView)
{
GetDocument()->UpdateAllViews(pNotThisView, 0, this);
}
void CContainerItem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)
{
ASSERT_VALID(this);
CControlItem::OnChange(nCode, dwParam);
switch (nCode)
{
case OLE_CHANGED:
UpdateExtent();
Invalidate();
break;
case OLE_CHANGED_ASPECT:
case OLE_CHANGED_STATE:
Invalidate();
break;
}
}
BOOL CContainerItem::OnChangeItemPosition(const CRect& rectPos)
{
ASSERT_VALID(this);
if (!CControlItem::OnChangeItemPosition(rectPos))
return FALSE;
// Erase the old image of the item, set the new position and draw again.
Invalidate();
m_rect = rectPos;
Invalidate();
// mark document as dirty
GetDocument()->SetModifiedFlag();
return TRUE;
}
void CContainerItem::OnGetItemPosition(CRect& rPosition)
{
ASSERT_VALID(this);
if (m_rect.Size() == CSize(0,0))
UpdateItemExtentFromServer();
// copy m_rect, which is in document coordinates
rPosition = m_rect;
// TODO: Change any document coordinates here.
return;
}
void CContainerItem::OnDeactivateUI(BOOL bUndoable)
{
CControlItem::OnDeactivateUI(bUndoable);
// Close an in-place active item whenever it removes the user
// interface. The action here should match as closely as possible
// to the handling of the escape key in the view.
Deactivate(); // nothing fancy here -- just deactivate the object
}
void CContainerItem::OnUpdateFrameTitle()
{
// Do Nothing. A Good OCX Container doesn't display the name
// of its UIActive control.
// Optionally, you could switch on the registry entry of the UIActive
// item to determine if it is not a control and then call the base
// class to update the title properly.
}
void CContainerItem::Serialize(CArchive& ar)
{
ASSERT_VALID(this);
// Call base class first to read in CControlItem data.
// Since this sets up the m_pDocument pointer returned from
// CContainerItem::GetDocument, it is a good idea to call
// the base class Serialize first.
CControlItem::Serialize(ar);
// now store/retrieve data specific to CContainerItem
if (ar.IsStoring())
{
ar << m_rect << m_extent;
}
else
{
ar >> m_rect << m_extent;
}
}
/////////////////////////////////////////////////////////////////////////////
// Operations
BOOL CContainerItem::UpdateExtent()
{
CSize size;
if (GetExtent(&size))
{
// OLE returns the extent in HIMETRIC units -- we need pixels
CClientDC dc(NULL);
dc.HIMETRICtoDP(&size);
// only invalidate if it has actually changed
if (size != m_rect.Size())
{
// invalidate old, update, invalidate new
Invalidate();
m_rect.bottom = m_rect.top + size.cy;
m_rect.right = m_rect.left + size.cx;
Invalidate();
// mark document as modified
GetDocument()->SetModifiedFlag();
}
return TRUE;
}
else
return FALSE;
}
void CContainerItem::Move(CRect &rc)
{
// invalidate old rect
Invalidate();
// invalidate new
m_rect = rc;
Invalidate();
// update item rect when in-place active
if (IsInPlaceActive())
SetItemRects();
}
BOOL CContainerItem::UpdateItemExtentFromServer()
{
// get size in pixels
CSize size;
if (!GetExtent(&size))
return FALSE; // blank
if (size == m_extent)
return FALSE;
// if new object (i.e. m_extent is empty) setup position
if (m_extent == CSize(0,0))
{
m_rect.right = m_rect.left + MulDiv(size.cx,10,254);
m_rect.bottom = m_rect.top - MulDiv(size.cy,10,254);
}
else
{
if (!IsInPlaceActive() && size != m_extent)
{
// data changed and not inplace, so scale up rect as well
m_rect.right = m_rect.left +
MulDiv(m_rect.Width(),size.cx,m_extent.cx);
m_rect.bottom = m_rect.top +
MulDiv(m_rect.Height(),size.cy,m_extent.cy);
}
}
m_extent = size;
Invalidate(); // as well as the new size/position
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CContainerItem diagnostics
#ifdef _DEBUG
void CContainerItem::AssertValid() const
{
CControlItem::AssertValid();
}
void CContainerItem::Dump(CDumpContext& dc) const
{
CControlItem::Dump(dc);
}
#endif
/////////////////////////////////////////////////////////////////////////////