BOOL CRectItem::UpdateExtent() { // get size in pixels CSize size; if (!GetCachedExtent(&size)) return FALSE; // blank Invalidate(); // invalidate the old size/position CSize sizeBase = GetBaseSize(); if (size == sizeBase) // no change return FALSE; // if new object (i.e. m_extent is empty) setup position if (sizeBase == CSize(0,0)) { // convert to document coords CSize sizeNew(MulDiv(size.cx, 10, 254), - MulDiv(size.cy, 10, 254)); SetSize(sizeNew); } else { if (!IsInPlaceActive() && size != sizeBase) { // data changed and not inplace, so scale up rect as well CSize sizeCur = GetSize(); sizeCur.cx = MulDiv(sizeCur.cx, size.cx, sizeBase.cx); sizeCur.cy = - MulDiv(-sizeCur.cy, size.cy, sizeBase.cy); SetSize(sizeCur); } } SetBaseSize(size); Invalidate(); // as well as the new size/position return TRUE; }
////////////////////////////////////////////////////////////////////////////////// //功 能: ////////////////////////////////////////////////////////////////////////////////// BOOL CCtrlItem::UpdateExtent() { if (m_lpViewObject == NULL) return TRUE; CSize size; //下行调用m_lpViewObject,此时m_lpViewObject对部分控件可能为空 if (GetCachedExtent(&size)) { // OLE returns the extent in HIMETRIC units -- we need pixels. CClientDC dc(NULL); dc.HIMETRICtoDP(&size); // Only invalidate if it has actually changed and also only if it is not // in-place active. CSize szTmp; szTmp.cx = int(m_pCtrlObj->m_position.Size().cx); szTmp.cy = int(m_pCtrlObj->m_position.Size().cy); if ((size != szTmp) && !IsInPlaceActive()) { // Invalidate old, update, invalidate new. m_pCtrlObj->Invalidate(); m_pCtrlObj->m_position.bottom = m_pCtrlObj->m_position.top + size.cy; m_pCtrlObj->m_position.right = m_pCtrlObj->m_position.left + size.cx; m_pCtrlObj->Invalidate(); // mark document as modified. GetDocument()->SetModifiedFlag(); } } return TRUE; }
void CContainerItem::UpdateFromServerExtent() { CSize size; if (GetCachedExtent(&size)) { // OLE returns the extent in HIMETRIC units -- we need pixels CClientDC dc(NULL); dc.HIMETRICtoDP(&size); // Only invalidate if it has actually changed, and also // only if it is not in-place active. When in-place active, the // container item size should sync with the "window size" of the // object. Only when not in-place active should the container // item size should sync with the natural size of the object. if ((size != m_rect.Size()) && !IsInPlaceActive()) { // invalidate old, update, invalidate new InvalidateItem(); m_rect.bottom = m_rect.top + size.cy; m_rect.right = m_rect.left + size.cx; InvalidateItem(); // mark document as modified GetDocument()->SetModifiedFlag(); } } }