Implementing the Client Item Rectangle
The AppWizard-provided implementation of CContainerItem
does most of the work needed for Container, but some of its functionality needs to be enhanced.
To implement the client item rectangle
Declare
m_rect
in the public attributes section of ContainerItem.h:CRect m_rect; // position within the document
The AppWizard-provided implementation of
CContainerItem
assumed an arbitrary rectangle that locates the object in the container document. A CRect is needed to store the location and size of the object.Use ClassView to jump to the
CContainerItem
constructor in ContainerItem.cpp and initializem_rect
. Replace the //TODO comment with the following code:m_rect.SetRect(10, 10, 50, 50);
Use ClassView to jump to
OnGetItemPosition
and replace its default implementation with the following code (leave theASSERT_VALID(this)
line):// return rect relative to client area of view rPosition = m_rect;
The AppWizard-provided implementation arbitrarily sets the rectangle to (10, 10, 210, 210) when requested by the framework. Because the rectangle for each
CContainerItem
item is now being tracked by CRectTracker, the frameworkâs request is satisfied by returning the CRect member,m_rect
.In Container Step 2, this implementation is replaced with one that allows the server to negotiate the size of the object.
The framework calls COleClientItem::OnChangeItemPosition on behalf of a server to change the position of the in-place window. The
CContainerItem
updates its CRectm_rect
according to the value requested by the framework. This means that the container document has changed. Thus views need to be notified and the document needs to be marked as dirty according to normal framework document/view rules.In Container Step 2, the simple UpdateAllViews call is replaced with smart invalidation.
Complete the implementation of
OnChangeItemPosition
by adding the following code in place of the //TODO comment:GetDocument()->UpdateAllViews(NULL); m_rect = rectPos; // mark document as dirty GetDocument()->SetModifiedFlag();
Serialize the CRect
m_rect
member variable inCContainerItem::Serialize
.- Replace the //TODO comment for storing code with:
ar << m_rect;
- Replace the //TODO comment for loading code with:
ar >> m_rect;
Save the header and implementation files.