Exemplo n.º 1
0
void CXTPTabPaintManager::RepositionTabControlMultiRow(CXTPTabManager* pTabManager, CDC* pDC, CRect rcClient)
{

	pTabManager->m_rcHeaderRect = RepositionNavigateButtons(pTabManager, rcClient);
	pTabManager->m_nHeaderOffset = 0;

	if (pTabManager->GetItemCount() == 0)
		return;

	CRect rcHeaderMargin = m_pAppearanceSet->GetHeaderMargin();
	int nButtonHeight = m_pAppearanceSet->GetButtonHeight(pTabManager);

	if (pTabManager->IsHorizontalPosition())
	{
		int nWidth = pTabManager->m_rcHeaderRect.Width() - (rcHeaderMargin.left + rcHeaderMargin.right);
		CreateMultiRowIndexer(pTabManager, pDC, nWidth);

		int nRowCount = pTabManager->GetRowCount();
		int nTop = 0;

		if (pTabManager->GetPosition() == xtpTabPositionBottom)
		{
			nTop = rcClient.bottom - (nButtonHeight * nRowCount + m_pAppearanceSet->m_nRowMargin * (nRowCount - 1))
				- rcHeaderMargin.top;
		}
		else
		{
			nTop = rcClient.top +  (nButtonHeight * (nRowCount - 1) + m_pAppearanceSet->m_nRowMargin * (nRowCount - 1))
				+ rcHeaderMargin.top;
		}

		int nBottom = nTop + nButtonHeight;

		int nOffset = pTabManager->GetPosition() == xtpTabPositionBottom ?
			nButtonHeight + m_pAppearanceSet->m_nRowMargin: -(nButtonHeight + m_pAppearanceSet->m_nRowMargin);


		CXTPTabManager::ROW_ITEMS* pRowItems = pTabManager->m_pRowIndexer->GetRowItems();
		int i;

		BOOL bSizeToFit = nRowCount > 1 && m_bMultiRowJustified;

		for (int nRow = 0; nRow < nRowCount; nRow++)
		{
			int nTotalLength = 0;

			int nItemInRow = pRowItems[nRow].nLastItem - pRowItems[nRow].nFirstItem + 1;
			int nFirstItem = pRowItems[nRow].nFirstItem;

			if (bSizeToFit)
			{
				for (i = 0; i < nItemInRow; i++)
				{
					nTotalLength += pTabManager->GetItem(nFirstItem + i)->GetButtonLength();
				}
			}

			int nTotalWidth = nWidth;

			int x = pTabManager->m_rcHeaderRect.left + rcHeaderMargin.left;

			for (i = 0; i < nItemInRow; i++)
			{
				CXTPTabManagerItem* pItem = pTabManager->GetItem(nFirstItem + i);
				ASSERT(pItem);
				if (!pItem)
					continue;
				int nButtonLength = pItem->m_nButtonLength;

				if (bSizeToFit)
				{
					int nLength = nButtonLength + (nTotalWidth - nTotalLength) / (nItemInRow - i);
					nTotalWidth -= nLength;
					nTotalLength -= nButtonLength;

					pItem->m_nButtonLength = nButtonLength = nLength;
				}

				pItem->SetRect(CRect(x, nTop, x + nButtonLength, nBottom));
				pItem->m_nItemRow = nRow;


				x += nButtonLength;
			}
			nTop += nOffset;
			nBottom += nOffset;
		}
	}
	else
	{
		int nWidth = pTabManager->m_rcHeaderRect.Height() - (rcHeaderMargin.left + rcHeaderMargin.right);
		CreateMultiRowIndexer(pTabManager, pDC, nWidth);


		int nRowCount = pTabManager->GetRowCount();
		int nLeft = 0;

		if (pTabManager->GetPosition() == xtpTabPositionRight)
		{
			nLeft = rcClient.right - (nButtonHeight * nRowCount + m_pAppearanceSet->m_nRowMargin * (nRowCount - 1))
				- rcHeaderMargin.top;
		}
		else
		{
			nLeft = rcClient.left +  (nButtonHeight * (nRowCount - 1) + m_pAppearanceSet->m_nRowMargin * (nRowCount - 1))
				+ rcHeaderMargin.top;
		}

		int nRight = nLeft + nButtonHeight;

		int nOffset = pTabManager->GetPosition() == xtpTabPositionRight ?
			nButtonHeight + m_pAppearanceSet->m_nRowMargin: -(nButtonHeight + m_pAppearanceSet->m_nRowMargin);


		CXTPTabManager::ROW_ITEMS* pRowItems = pTabManager->m_pRowIndexer->GetRowItems();
		int i;

		BOOL bSizeToFit = nRowCount > 1 && m_bMultiRowJustified;

		for (int nRow = 0; nRow < nRowCount; nRow++)
		{
			int nTotalLength = 0;

			int nItemInRow = pRowItems[nRow].nLastItem - pRowItems[nRow].nFirstItem + 1;
			int nFirstItem = pRowItems[nRow].nFirstItem;

			if (bSizeToFit)
			{
				for (i = 0; i < nItemInRow; i++)
				{
					nTotalLength += pTabManager->GetItem(nFirstItem + i)->GetButtonLength();
				}
			}

			int nTotalWidth = nWidth;

			int y = pTabManager->m_rcHeaderRect.top + rcHeaderMargin.left;

			for (i = 0; i < nItemInRow; i++)
			{
				CXTPTabManagerItem* pItem = pTabManager->GetItem(nFirstItem + i);
				ASSERT(pItem);
				if (!pItem)
					continue;
				int nButtonLength = pItem->m_nButtonLength;

				if (bSizeToFit)
				{
					int nLength = nButtonLength + (nTotalWidth - nTotalLength) / (nItemInRow - i);
					nTotalWidth -= nLength;
					nTotalLength -= nButtonLength;

					pItem->m_nButtonLength = nButtonLength = nLength;
				}

				pItem->SetRect(CRect(nLeft, y, nRight, y + nButtonLength));
				pItem->m_nItemRow = nRow;


				y += nButtonLength;
			}
			nLeft += nOffset;
			nRight += nOffset;
		}
	}
	pTabManager->m_rcHeaderRect = RepositionNavigateButtons(pTabManager, rcClient);
}
Exemplo n.º 2
0
void CXTPTabPaintManager::RepositionTabControlEx(CXTPTabManager* pTabManager, CDC* pDC, CRect rcClient)
{
	if (pTabManager->IsDrawStaticFrame())
	{
		CAppearanceSet::DeflateRectEx(rcClient, CRect(2, 1, 2, 2), pTabManager->GetPosition());
	}

	CAppearanceSet::DeflateRectEx(rcClient, m_rcControlMargin, pTabManager->GetPosition());

	int i;

	if (!m_bShowTabs)
	{
		pTabManager->m_rcHeaderRect.SetRectEmpty();
		for (i = 0; i < pTabManager->GetItemCount(); i++)
		{
			CXTPTabManagerItem* pItem = pTabManager->GetItem(i);
			pItem->SetRect(CRect(0, 0, 0, 0));
		}

		for (i = pTabManager->GetNavigateButtonCount() - 1; i >= 0; i--)
			pTabManager->GetNavigateButton(i)->SetRect(CRect(0, 0, 0, 0));

		return;
	}
	if (pTabManager->GetLayout() == xtpTabLayoutMultiRow)
	{
		RepositionTabControlMultiRow(pTabManager, pDC, rcClient);
		return;
	}

	for (i = 0; i < pTabManager->GetItemCount(); i++)
	{
		CXTPTabManagerItem* pItem = pTabManager->GetItem(i);

		pItem->m_nButtonLength = pItem->m_nContentLength =
			pItem->IsVisible() ? m_pAppearanceSet->GetButtonLength(pDC, pItem) : 0;

		if (pItem->IsVisible())
			pItem->m_nButtonLength += m_nButtonExtraLength;
	}

	pTabManager->m_rcHeaderRect = m_pAppearanceSet->GetHeaderRect(rcClient, pTabManager);

	if (pTabManager->GetItemCount() == 0)
	{
		RepositionNavigateButtons(pTabManager, rcClient);
		return;
	}

	CRect rcHeaderMargin = m_pAppearanceSet->GetHeaderMargin();
	int nButtonHeight = m_pAppearanceSet->GetButtonHeight(pTabManager);


	if (pTabManager->IsHorizontalPosition())
	{
		int nTop = rcClient.top + rcHeaderMargin.top;

		if (pTabManager->GetPosition() == xtpTabPositionBottom)
		{
			nTop = rcClient.bottom - nButtonHeight - rcHeaderMargin.top;
		}

		int nBottom = nTop + nButtonHeight;


		if (pTabManager->GetLayout() == xtpTabLayoutSizeToFit)
		{
			int nWidth = rcClient.Width() - (rcHeaderMargin.right + rcHeaderMargin.left);

			for (i = pTabManager->GetNavigateButtonCount() - 1; i >= 0; i--)
				pTabManager->GetNavigateButton(i)->AdjustWidth(nWidth);

			SizeToFit(pTabManager, nWidth);
		}

		pTabManager->m_rcHeaderRect = RepositionNavigateButtons(pTabManager, rcClient);

		if (pTabManager->m_nHeaderOffset < 0)
		{
			int nLength = pTabManager->GetItemsLength();
			int nNavigateButtonsWidth = pTabManager->m_rcHeaderRect.Width() - rcHeaderMargin.left - rcHeaderMargin.right;

			if (nLength + pTabManager->m_nHeaderOffset < nNavigateButtonsWidth)
			{
				pTabManager->m_nHeaderOffset = min(0, nNavigateButtonsWidth - nLength);
				pTabManager->m_rcHeaderRect = RepositionNavigateButtons(pTabManager, rcClient);
			}
		}

		int x = pTabManager->m_rcHeaderRect.left + rcHeaderMargin.left + pTabManager->GetHeaderOffset();

		if (pTabManager->GetLayout() == xtpTabLayoutRotated)
		{
			if (pTabManager->GetPosition() == xtpTabPositionTop)
			{
				nBottom = pTabManager->m_rcHeaderRect.bottom - rcHeaderMargin.bottom;
			}
			else
			{
				nTop = pTabManager->m_rcHeaderRect.top + rcHeaderMargin.bottom;

			}

			for (i = 0; i < pTabManager->GetItemCount(); i++)
			{
				CXTPTabManagerItem* pItem = pTabManager->GetItem(i);
				if (!pItem->IsVisible()) continue;

				if (pTabManager->GetPosition() == xtpTabPositionTop)
				{
					pItem->SetRect(CRect(x, nBottom - pItem->m_nButtonLength, x + nButtonHeight, nBottom));
				}
				else
				{
					pItem->SetRect(CRect(x, nTop, x + nButtonHeight, nTop + pItem->m_nButtonLength));

				}
				x += nButtonHeight;
			}
		}
		else
		{

			for (i = 0; i < pTabManager->GetItemCount(); i++)
			{
				CXTPTabManagerItem* pItem = pTabManager->GetItem(i);

				pItem->SetRect(CRect(x, nTop, x + pItem->m_nButtonLength, nBottom));
				x += pItem->m_nButtonLength;
			}
		}

	}
	else
	{
		int nLeft = rcClient.left + rcHeaderMargin.top;

		if (pTabManager->GetPosition() == xtpTabPositionRight)
		{
			nLeft = rcClient.right - nButtonHeight - rcHeaderMargin.top;
		}

		int nRight = nLeft + nButtonHeight;

		if (pTabManager->GetLayout() == xtpTabLayoutSizeToFit)
		{
			int nWidth = rcClient.Height() - (rcHeaderMargin.right + rcHeaderMargin.left);

			for (i = pTabManager->GetNavigateButtonCount() - 1; i >= 0; i--)
				pTabManager->GetNavigateButton(i)->AdjustWidth(nWidth);

			SizeToFit(pTabManager, nWidth);
		}

		pTabManager->m_rcHeaderRect = RepositionNavigateButtons(pTabManager, rcClient);

		if (pTabManager->m_nHeaderOffset < 0)
		{
			int nLength = pTabManager->GetItemsLength();
			int nNavigateButtonsWidth = pTabManager->m_rcHeaderRect.Height() - rcHeaderMargin.left - rcHeaderMargin.right;

			if (nLength + pTabManager->m_nHeaderOffset < nNavigateButtonsWidth)
			{
				pTabManager->m_nHeaderOffset = min(0, nNavigateButtonsWidth - nLength);
				pTabManager->m_rcHeaderRect = RepositionNavigateButtons(pTabManager, rcClient);
			}
		}

		int y = pTabManager->m_rcHeaderRect.top + rcHeaderMargin.left + pTabManager->GetHeaderOffset();

		if (pTabManager->GetLayout() == xtpTabLayoutRotated)
		{
			if (pTabManager->GetPosition() == xtpTabPositionLeft)
			{
				nRight = pTabManager->m_rcHeaderRect.right - rcHeaderMargin.bottom;
			}
			else
			{
				nLeft = pTabManager->m_rcHeaderRect.left + rcHeaderMargin.bottom;

			}

			for (i = 0; i < pTabManager->GetItemCount(); i++)
			{
				CXTPTabManagerItem* pItem = pTabManager->GetItem(i);
				if (!pItem->IsVisible()) continue;

				if (pTabManager->GetPosition() == xtpTabPositionLeft)
				{
					pItem->SetRect(CRect(nRight - pItem->m_nButtonLength, y, nRight, y + nButtonHeight));
				}
				else
				{
					pItem->SetRect(CRect(nLeft, y, nLeft + pItem->m_nButtonLength, y + nButtonHeight));

				}
				y += nButtonHeight;
			}
		}
		else
		{
			for (i = 0; i < pTabManager->GetItemCount(); i++)
			{
				CXTPTabManagerItem* pItem = pTabManager->GetItem(i);

				pItem->SetRect(CRect(nLeft, y, nRight, y + pItem->m_nButtonLength));
				y += pItem->m_nButtonLength;
			}
		}
	}
}