virtual void UpdateChildrenPosition() { CRect rcClient = GetClientRect(); rcClient.DeflateRect(m_rcMargin.left,m_rcMargin.top,m_rcMargin.right,m_rcMargin.bottom); SWindow *pChild = GetWindow(GSW_FIRSTCHILD); CRect rcItem = rcClient; rcItem.bottom = rcItem.top; while(pChild) { CSize szItem = pChild->GetDesiredSize(rcClient); rcItem.top = rcItem.bottom; rcItem.bottom += szItem.cy; pChild->Move(rcItem); pChild = pChild->GetWindow(GSW_NEXTSIBLING); } }
//nWidth,nHeight == -1:wrap_content CSize SLinearLayout::MeasureChildren(SWindow * pParent,int nWidth,int nHeight) const { CSize *pSize = new CSize [pParent->GetChildrenCount()]; ILayoutParam * pParentLayoutParam = pParent->GetLayoutParam(); int iChild = 0; SWindow *pChild = pParent->GetNextLayoutChild(NULL); while(pChild) { SLinearLayoutParam *pLinearLayoutParam = pChild->GetLayoutParamT<SLinearLayoutParam>(); int nScale = pChild->GetScale(); CSize szChild(SIZE_WRAP_CONTENT,SIZE_WRAP_CONTENT); if(pLinearLayoutParam->IsMatchParent(Horz)) { if(!pParentLayoutParam->IsWrapContent(Horz)) szChild.cx = nWidth; } else if(pLinearLayoutParam->IsSpecifiedSize(Horz)) { szChild.cx = pLinearLayoutParam->GetSpecifiedSize(Horz).toPixelSize(nScale); szChild.cx += pLinearLayoutParam->extend_left.toPixelSize(nScale) + pLinearLayoutParam->extend_right.toPixelSize(nScale); } if(pLinearLayoutParam->IsMatchParent(Vert)) { if(!pParentLayoutParam->IsWrapContent(Vert)) szChild.cy = nHeight; } else if(pLinearLayoutParam->IsSpecifiedSize(Vert)) { szChild.cy = pLinearLayoutParam->GetSpecifiedSize(Vert).toPixelSize(nScale); szChild.cy += pLinearLayoutParam->extend_top.toPixelSize(nScale) + pLinearLayoutParam->extend_bottom.toPixelSize(nScale); } if(szChild.cx == SIZE_WRAP_CONTENT || szChild.cy == SIZE_WRAP_CONTENT) { int nWid = szChild.cx, nHei = szChild.cy; if(nWid == SIZE_WRAP_CONTENT) nWid = nWidth * pParentLayoutParam->IsWrapContent(Horz)?-1:1; //把父窗口的WrapContent属性通过-1标志传递给GetDesiredSize if(nHei == SIZE_WRAP_CONTENT) nHei = nHeight * pParentLayoutParam->IsWrapContent(Vert)?-1:1;//把父窗口的WrapContent属性通过-1标志传递给GetDesiredSize CSize szCalc = pChild->GetDesiredSize(nWid,nHei); if(szChild.cx == SIZE_WRAP_CONTENT) { szChild.cx = szCalc.cx; szChild.cx += pLinearLayoutParam->extend_left.toPixelSize(nScale) + pLinearLayoutParam->extend_right.toPixelSize(nScale); } if(szChild.cy == SIZE_WRAP_CONTENT) { szChild.cy = szCalc.cy; szChild.cy += pLinearLayoutParam->extend_top.toPixelSize(nScale) + pLinearLayoutParam->extend_bottom.toPixelSize(nScale); } } pSize [iChild++] = szChild; pChild = pParent->GetNextLayoutChild(pChild); } CSize szRet; for(int i=0;i<iChild;i++) { if(m_orientation == Horz) { szRet.cx += pSize[i].cx; szRet.cy = (std::max)(szRet.cy,pSize[i].cy); }else { szRet.cx = (std::max)(szRet.cx,pSize[i].cx); szRet.cy += pSize[i].cy; } } delete []pSize; return szRet; }