Пример #1
0
void CXTPTaskPanelGroup::OnCalcClientHeight(CDC* pDC, CRect rc)
{
	CXTPTaskPanelPaintManager* pPaintManager = GetPaintManager();
	CRect rcMarginsOuter = pPaintManager->GetGroupOuterMargins(this);
	CRect rcMarginsInner = pPaintManager->GetGroupInnerMargins(this);

	rc.DeflateRect(rcMarginsOuter);
	CRect rcItems(rc);

	rcItems.DeflateRect(rcMarginsInner);
	m_nItemsInRow = 1;
	int nItemCount = GetItemCount();

	if (GetItemLayout() == xtpTaskItemLayoutImages)
	{
		CSize szIcon = GetItemIconSize();
		CRect rcInnerMargins(pPaintManager->m_rcImageLayoutIconPadding);
		CSize szButton(szIcon.cx + rcInnerMargins.right + rcInnerMargins.left,
			szIcon.cy + rcInnerMargins.top + rcInnerMargins.bottom);

		int nRowIcons = max(1, rcItems.Width() / szButton.cx), x = 0, y = 0;
		BOOL bWrap = FALSE;

		for (int i = 0; i < nItemCount; i++)
		{
			CXTPTaskPanelGroupItem* pItem = GetAt(i);

			if (!pItem->IsVisible())
				continue;

			if (bWrap)
			{
				x = 0;
				y++;
				bWrap = FALSE;
			}

			CRect rcItem(CPoint(rcItems.left + x * szButton.cx, rcItems.top + y * szButton.cy), szButton);
			pItem->OnReposition(rcItem);

			if (++x == nRowIcons)
				bWrap = TRUE;
		}
		rcItems.bottom = rcItems.top + rcMarginsInner.bottom + szButton.cy * (y + 1);
		m_nItemsInRow = nRowIcons;

		SetOffsetItem(m_nScrollOffset);
	}
	else
	{
		BOOL bMultiColumn = m_pPanel->IsMultiColumn();
		int nRowHeight = 0;
		CRect rcItemOuterMargins(0, 0, 0, 0);
		int nColumnWidth = m_pPanel->GetColumnWidth();
		ASSERT(nColumnWidth > 0);
		int x = 0;
		BOOL bWrap = FALSE;

		int nRowIcons = max(1, rcItems.Width() / nColumnWidth);

		for (int i = 0; i < nItemCount; i++)
		{
			CXTPTaskPanelGroupItem* pItem = GetAt(i);

			if (!pItem->IsVisible())
				continue;

			if (bMultiColumn)
			{
				if (bWrap)
				{
					rcItems.top += nRowHeight;

					nRowHeight = 0;
					x = 0;
					bWrap = FALSE;
				}

				CRect rcItem = pItem->OnReposition(CRect(rcItems.left + x * nColumnWidth, rcItems.top, rcItems.left + (x + 1) * nColumnWidth, rcItems.bottom));


				rcItemOuterMargins = pPaintManager->GetItemOuterMargins(pItem);

				nRowHeight = max(nRowHeight, rcItem.Height() + rcItemOuterMargins.bottom);

				if (++x == nRowIcons)
					bWrap = TRUE;
			}
			else
			{
				CRect rcItem = pItem->OnReposition(rcItems);
				rcItems.top = rcItem.bottom + pPaintManager->GetItemOuterMargins(pItem).bottom;
			}
		}
		if (bMultiColumn)
		{
			rcItems.top += nRowHeight;
			m_nItemsInRow = nRowIcons;
		}
		rcItems.bottom = rcItems.top + rcMarginsInner.bottom;
	}

	int nMinClientHeight = GetMinimumClientHeight();
	if (rcItems.bottom - rc.top < nMinClientHeight)
		rcItems.bottom = rc.top + nMinClientHeight;

	m_nExpandedClientHeight = rcItems.bottom - rc.top;

	m_nCaptionHeight = pPaintManager->DrawGroupCaption(pDC, this, FALSE);
}