213 pParent->GetChildrenLayoutRect(&rcParent);
215 SIZE *pSize =
new SIZE[pParent->GetChildrenCount()];
216 IWindow **pChilds =
new IWindow *[pParent->GetChildrenCount()];
217 memset(pSize, 0,
sizeof(SIZE) * pParent->GetChildrenCount());
222 float fWeight = 0.0f;
228 IWindow *pChild = pParent->GetNextLayoutIChild(NULL);
233 int nScale = pChild->GetScale();
235 CSize szChild(SIZE_WRAP_CONTENT, SIZE_WRAP_CONTENT);
237 szChild.cx = rcParent.Width();
241 szChild.cx += pLinearLayoutParam->extend_left.
toPixelSize(nScale) + pLinearLayoutParam->extend_right.
toPixelSize(nScale);
245 szChild.cy = rcParent.Height();
249 szChild.cy += pLinearLayoutParam->extend_top.
toPixelSize(nScale) + pLinearLayoutParam->extend_bottom.
toPixelSize(nScale);
252 if (pLinearLayoutParam->weight > 0.0f)
254 fWeight += pLinearLayoutParam->weight;
257 if (szChild.cx == SIZE_WRAP_CONTENT || szChild.cy == SIZE_WRAP_CONTENT)
260 pChild->GetDesiredSize(&szCalc, szChild.cx, szChild.cy);
261 if (szChild.cx == SIZE_WRAP_CONTENT)
263 szChild.cx = szCalc.cx;
264 szChild.cx += pLinearLayoutParam->extend_left.
toPixelSize(nScale) + pLinearLayoutParam->extend_right.
toPixelSize(nScale);
266 if (szChild.cy == SIZE_WRAP_CONTENT)
268 szChild.cy = szCalc.cy;
269 szChild.cy += pLinearLayoutParam->extend_top.
toPixelSize(nScale) + pLinearLayoutParam->extend_bottom.
toPixelSize(nScale);
273 pChilds[iChild] = pChild;
274 pSize[iChild] = szChild;
275 offset += m_orientation == Vert ? szChild.cy : szChild.cx;
278 pChild = pParent->GetNextLayoutIChild(pChild);
284 int size = m_orientation == Vert ? rcParent.Height() : rcParent.Width();
285 int interval = m_interval.toPixelSize(pParent->GetScale());
288 offset += (nChilds - 1) * interval;
290 ORIENTATION orienOther = m_orientation == Vert ? Horz : Vert;
295 int nRemain = size - offset;
297 for (
int iChild = 0; iChild < nChilds; iChild++)
301 IWindow *pChild = pChilds[iChild];
303 int nScale = pChild->GetScale();
304 if (pLinearLayoutParam->weight > 0.0f)
306 int extra = int(nRemain * pLinearLayoutParam->weight / fWeight + 0.5f);
307 LONG &szChild = m_orientation == Vert ? pSize[iChild].cy : pSize[iChild].cx;
310 fWeight -= pLinearLayoutParam->weight;
314 ILayoutParam *backup = pLinearLayoutParam->
Clone();
316 int nWid = pSize[iChild].cx, nHei = pSize[iChild].cy;
318 if (orienOther == Vert)
319 nHei = SIZE_WRAP_CONTENT;
321 nWid = SIZE_WRAP_CONTENT;
324 pChild->GetDesiredSize(&szCalc, nWid, nHei);
325 if (orienOther == Vert)
327 szCalc.cy += pLinearLayoutParam->extend_top.
toPixelSize(nScale) + pLinearLayoutParam->extend_bottom.
toPixelSize(nScale);
328 pSize[iChild].cy = szCalc.cy;
332 szCalc.cx += pLinearLayoutParam->extend_left.
toPixelSize(nScale) + pLinearLayoutParam->extend_right.
toPixelSize(nScale);
333 pSize[iChild].cx = szCalc.cx;
335 pChild->SetLayoutParam(backup);
341 else if (interval < 0)
344 if (interval == SIZE_WRAP_CONTENT && nChilds > 1)
345 interval = (size - offset) / (nChilds - 1);
346 else if (interval == SIZE_MATCH_PARENT)
348 interval = (size - offset) / (nChilds + 1);
349 if (m_orientation == Vert)
350 rcParent.DeflateRect(0, interval, 0, interval);
352 rcParent.DeflateRect(interval, 0, interval, 0);
360 for (
int iChild = 0; iChild < nChilds; iChild++)
366 Gravity gravity = pLinearLayoutParam->gravity == G_Undefined ? m_gravity : pLinearLayoutParam->gravity;
367 if (gravity == G_Undefined)
370 if (m_orientation == Vert)
372 CRect rcChild(CPoint(0, offset), pSize[iChild]);
373 rcChild.OffsetRect(rcParent.TopLeft());
374 if (gravity == G_Center)
375 rcChild.OffsetRect((rcParent.Width() - rcChild.Width()) / 2, 0);
376 else if (gravity == G_Right)
377 rcChild.OffsetRect(rcParent.Width() - rcChild.Width(), 0);
379 CRect rcChild2 = rcChild;
380 rcChild2.DeflateRect(pLinearLayoutParam->extend_left.
toPixelSize(nScale), pLinearLayoutParam->extend_top.
toPixelSize(nScale), pLinearLayoutParam->extend_right.
toPixelSize(nScale), pLinearLayoutParam->extend_bottom.
toPixelSize(nScale));
384 offset += rcChild.Height();
388 CRect rcChild(CPoint(offset, 0), pSize[iChild]);
389 rcChild.OffsetRect(rcParent.TopLeft());
390 if (gravity == G_Center)
391 rcChild.OffsetRect(0, (rcParent.Height() - rcChild.Height()) / 2);
392 else if (gravity == G_Right)
393 rcChild.OffsetRect(0, rcParent.Height() - rcChild.Height());
395 CRect rcChild2 = rcChild;
396 rcChild2.DeflateRect(pLinearLayoutParam->extend_left.
toPixelSize(nScale), pLinearLayoutParam->extend_top.
toPixelSize(nScale), pLinearLayoutParam->extend_right.
toPixelSize(nScale), pLinearLayoutParam->extend_bottom.
toPixelSize(nScale));
400 offset += rcChild.Width();
413 int nChildCount = pParent->GetChildrenCount();
414 SIZE *pSize =
new SIZE[nChildCount];
415 memset(pSize, -1,
sizeof(SIZE) * nChildCount);
416 const IWindow **ppChilds =
new const IWindow *[nChildCount];
417 memset(ppChilds, 0,
sizeof(IWindow *) * nChildCount);
418 const ILayoutParam *pParentLayoutParam = (
const ILayoutParam *)pParent->GetLayoutParam();
420 bool bWaitingForLimit =
true;
428 const IWindow *pChild = pParent->GetNextLayoutIChild(NULL);
431 while (!ppChilds[iChild])
434 int nScale = pChild->GetScale();
435 CSize szChild(SIZE_WRAP_CONTENT, SIZE_WRAP_CONTENT);
438 if (!pParentLayoutParam->IsWrapContent(Horz))
442 else if (bWaitingForLimit && nWidth == SIZE_WRAP_CONTENT && m_orientation == Vert)
451 szChild.cx += pLinearLayoutParam->extend_left.
toPixelSize(nScale) + pLinearLayoutParam->extend_right.
toPixelSize(nScale);
455 if (!pParentLayoutParam->IsWrapContent(Vert))
457 szChild.cy = nHeight;
459 else if (bWaitingForLimit && nHeight == SIZE_WRAP_CONTENT && m_orientation == Horz)
468 szChild.cy += pLinearLayoutParam->extend_top.
toPixelSize(nScale) + pLinearLayoutParam->extend_bottom.
toPixelSize(nScale);
470 if (szChild.cx == SIZE_WRAP_CONTENT || szChild.cy == SIZE_WRAP_CONTENT)
472 int nWid = szChild.cx, nHei = szChild.cy;
475 ((IWindow *)pChild)->GetDesiredSize(&szCalc, nWid, nHei);
476 if (szChild.cx == SIZE_WRAP_CONTENT)
478 szChild.cx = szCalc.cx;
479 szChild.cx += pLinearLayoutParam->extend_left.
toPixelSize(nScale) + pLinearLayoutParam->extend_right.
toPixelSize(nScale);
481 if (szChild.cy == SIZE_WRAP_CONTENT)
483 szChild.cy = szCalc.cy;
484 szChild.cy += pLinearLayoutParam->extend_top.
toPixelSize(nScale) + pLinearLayoutParam->extend_bottom.
toPixelSize(nScale);
487 fWeight += pLinearLayoutParam->weight;
489 ppChilds[iChild] = pChild;
490 pSize[iChild] = szChild;
493 pChild = pParent->GetNextLayoutIChild(pChild);
502 if (m_orientation == Vert)
504 SASSERT(nWidth == SIZE_WRAP_CONTENT);
505 for (
int i = 0; i < nChilds; i++)
507 nWidth = smax(pSize[i].cx, nWidth);
509 bWaitingForLimit =
false;
515 SASSERT(nHeight == SIZE_WRAP_CONTENT);
516 for (
int i = 0; i < nChilds; i++)
518 nHeight = smax(pSize[i].cy, nHeight);
520 bWaitingForLimit =
false;
526 int size = m_orientation == Vert ? nHeight : nWidth;
527 int nInterval = m_interval.toPixelSize(pParent->GetScale());
533 for (
int i = 0; i < nChilds; i++)
535 offset += m_orientation == Vert ? pSize[i].cy : pSize[i].cx;
537 offset += nInterval * (nChilds - 1);
540 int nRemain = size - offset;
542 ORIENTATION orienOther = m_orientation == Vert ? Horz : Vert;
543 for (
int iChild = 0; iChild < nChilds; iChild++)
545 if (
SLayoutSize::fequal(fWeight, 0.0f) && pSize[iChild].cx != -1 && pSize[iChild].cy != -1)
547 IWindow *pChild = (IWindow *)ppChilds[iChild];
549 int nScale = pChild->GetScale();
550 if (pLinearLayoutParam->weight > 0.0f)
552 int extra = int(nRemain * pLinearLayoutParam->weight / fWeight + 0.5f);
553 LONG &szChild = m_orientation == Vert ? pSize[iChild].cy : pSize[iChild].cx;
556 fWeight -= pLinearLayoutParam->weight;
561 ILayoutParam *backup = pLinearLayoutParam->
Clone();
564 int nWid = pSize[iChild].cx, nHei = pSize[iChild].cy;
566 if (orienOther == Vert)
567 nHei = SIZE_WRAP_CONTENT;
569 nWid = SIZE_WRAP_CONTENT;
572 pChild->GetDesiredSize(&szCalc, nWid, nHei);
573 if (orienOther == Vert)
575 szCalc.cy += pLinearLayoutParam->extend_top.
toPixelSize(nScale) + pLinearLayoutParam->extend_bottom.
toPixelSize(nScale);
576 pSize[iChild].cy = szCalc.cy;
580 szCalc.cx += pLinearLayoutParam->extend_left.
toPixelSize(nScale) + pLinearLayoutParam->extend_right.
toPixelSize(nScale);
581 pSize[iChild].cx = szCalc.cx;
583 pChild->SetLayoutParam(backup);
592 for (
int i = 0; i < nChilds; i++)
594 if (m_orientation == Horz)
596 szRet.cy = smax(szRet.cy, pSize[i].cy);
597 szRet.cx += pSize[i].cx;
601 szRet.cx = smax(szRet.cx, pSize[i].cx);
602 szRet.cy += pSize[i].cy;
606 if (m_orientation == Horz)
608 szRet.cx += nInterval * (nChilds - 1);
612 szRet.cy += nInterval * (nChilds - 1);