示例#1
0
void CExtMdiWindowsListDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDIS) 
{
	if (nIDCtl == IDC_EXT_LISTBOX_WINDOWS)
	{
		if (lpDIS->itemID == LB_ERR)
			return;

		CDC* pDC = CDC::FromHandle(lpDIS->hDC);
		CRect rcItem = lpDIS->rcItem;
	
		COLORREF clrBackground = g_PaintManager->GetColor(COLOR_WINDOW);
		COLORREF clrText = g_PaintManager->GetColor(COLOR_WINDOWTEXT);
		
		if( lpDIS->itemState & ODS_SELECTED )
		{ 
			clrText = g_PaintManager->GetColor(COLOR_HIGHLIGHTTEXT); 
			clrBackground = g_PaintManager->GetColor(COLOR_HIGHLIGHT); 
		} // if( lpDIS->itemState & ODS_SELECTED )

		CSize szIcon(
			::GetSystemMetrics(SM_CXSMICON),
			::GetSystemMetrics(SM_CYSMICON)
			);
		
		CRect rcText( rcItem );
		rcText.left += szIcon.cx + 3;
		
		if( lpDIS->itemAction & (ODA_DRAWENTIRE | ODA_SELECT) )
			pDC->FillSolidRect( rcText, clrBackground ); 
		
		if( lpDIS->itemAction & ODA_FOCUS )
			pDC->DrawFocusRect( &rcText );
		
		int	nOldBkMode = pDC->SetBkMode( TRANSPARENT ); 
		COLORREF clrOldText = pDC->SetTextColor( clrText ); 
		
		CString strBuffer;
		m_ListWindows.GetText(lpDIS->itemID, strBuffer);
		
		rcItem.left += szIcon.cx + 4;
		pDC->DrawText(
			strBuffer, 
			-1, 
			&rcItem,
			DT_LEFT | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE
			);
		rcItem.left = lpDIS->rcItem.left;
		
		HICON hIcon = 
			(HICON)::SendMessage(
				(HWND)lpDIS->itemData, 
				WM_GETICON, 
				FALSE, 
				0
				);
		if (hIcon == NULL) 
			hIcon = (HICON)::GetClassLong((HWND)lpDIS->itemData, GCL_HICONSM);
		if (hIcon == NULL) 
			hIcon = AfxGetApp()->LoadStandardIcon(IDI_WINLOGO);

		CRect rcIcon(
			rcItem.left, 
			rcItem.top, 
			rcItem.left + szIcon.cx + 3, 
			rcItem.top + szIcon.cy
			);
		pDC->FillSolidRect( 
			rcIcon, 
			g_PaintManager->GetColor(COLOR_WINDOW) 
			); 
		
		::DrawIconEx(
			pDC->m_hDC, 
			rcItem.left + 2, 
			rcItem.top, 
			hIcon,
			szIcon.cx, 
			szIcon.cy, 
			0, 
			NULL, 
			DI_NORMAL
			);
		
		pDC->SetTextColor( clrOldText );
		pDC->SetBkMode( nOldBkMode );

		return;
	} // if (nIDCtl == IDC_EXT_LISTBOX_WINDOWS)
	CExtResizableDialog::OnDrawItem(nIDCtl, lpDIS);
}
int CXTPTabPaintManager::DrawSingleButtonIconAndText(CDC* pDC, CXTPTabManagerItem* pItem, CRect rcItem, BOOL bDraw)
{
	CXTPTabManager* pManager = pItem->GetTabManager();

	XTPTabLayoutStyle layout = pManager->GetLayout();

	BOOL bVertical = !pManager->IsHorizontalPosition();
	if (layout == xtpTabLayoutRotated) bVertical = !bVertical;

	CString strItem = pItem->GetCaption();

	CFont* pFont = m_bBoldSelected && pItem->IsSelected() && pManager->IsActive() ? GetBoldFont(bVertical) : GetFont(bVertical);
	CXTPFontDC fnt(pDC, pFont);


	CSize szIcon(m_szIcon);
	BOOL bDrawIcon = pManager->DrawIcon(pDC, 0, pItem, FALSE, szIcon);
	BOOL bDrawText = layout != xtpTabLayoutCompressed || pItem->IsSelected();

	int nNavigateButtonsLength = 0;
	if (bDrawText && pItem->GetNavigateButtons()->GetSize() > 0)
	{
		nNavigateButtonsLength = 0;
		for (int i = 0; i < (int)pItem->GetNavigateButtons()->GetSize(); i++)
		{
			CXTPTabManagerNavigateButton* pButton = pItem->GetNavigateButtons()->GetAt(i);
			if (pManager->IsNavigateButtonVisible(pButton))
			{
				CSize sz = pButton->GetSize();
				nNavigateButtonsLength += bVertical ? sz.cy : sz.cx;
			}
		}

		if (nNavigateButtonsLength > 0) nNavigateButtonsLength += 3;
	}


	if (bDraw)
	{
		if (nNavigateButtonsLength > 0)
		{
			m_pColorSet->SetTextColor(pDC, pItem);

			if (bVertical) rcItem.bottom -= 3; else rcItem.right -= 3;

			for (int i = (int)pItem->GetNavigateButtons()->GetSize() - 1; i >= 0; i--)
			{
				CXTPTabManagerNavigateButton* pButton = pItem->GetNavigateButtons()->GetAt(i);
				if (pManager->IsNavigateButtonVisible(pButton))
				{
					CSize szButton = pButton->GetSize();
					if (!bVertical)
					{
						pButton->SetRect(CRect(rcItem.right - szButton.cx,
							rcItem.CenterPoint().y + szButton.cy / 2 - szButton.cy, rcItem.right,
							rcItem.CenterPoint().y + szButton.cy / 2));
						rcItem.right -= szButton.cx;
					}
					else
					{
						pButton->SetRect(CRect(rcItem.CenterPoint().x - szButton.cx / 2,
							rcItem.bottom - szButton.cy, rcItem.CenterPoint().x - szButton.cx / 2 + szButton.cx, rcItem.bottom));
						rcItem.bottom -= szButton.cy;
					}
					pItem->GetNavigateButtons()->GetAt(i)->Draw(pDC);
				}
			}
		}

		m_pColorSet->SetTextColor(pDC, pItem);

		CRect rcFocus(rcItem);

		if (bVertical)
		{
			int nAvailLength = pItem->GetButtonLength() - pItem->GetContentLength();
			if (nAvailLength > 0)
			{
				rcItem.DeflateRect(0, nAvailLength / 2);
			}

			rcItem.top += m_rcButtonTextPadding.left + m_rcButtonMargin.left;
			if (pManager->GetPosition() == xtpTabPositionRight)
				rcItem.DeflateRect(m_rcButtonMargin.bottom, 0, m_rcButtonMargin.top, 0);
			else
				rcItem.DeflateRect(m_rcButtonMargin.top, 0, m_rcButtonMargin.bottom, 0);

			if (bDrawIcon)
			{
				CPoint pt(rcItem.CenterPoint().x - szIcon.cx/2, rcItem.top - 1);
				if (rcItem.Height() > szIcon.cy) pManager->DrawIcon(pDC, pt, pItem, TRUE, szIcon);
				rcItem.top += szIcon.cy + 2;
			}
			if (bDrawText && rcItem.bottom > rcItem.top + 8)
			{
				CSize szText = pDC->GetTextExtent(strItem);
				rcItem.left = rcItem.right - (rcItem.Width() - szText.cy - (pManager->GetPosition() == xtpTabPositionRight ? 1 : 0)) / 2;
				rcItem.right = rcItem.left + rcItem.Height();
				rcItem.bottom -= m_rcButtonMargin.right + max(0, m_rcButtonTextPadding.right - 4);

				if (!m_bDrawTextNoPrefix)
					StripMnemonics(strItem);

				if (m_bDrawTextPathEllipsis)
				{
					DrawTextPathEllipsis(pDC, pManager, strItem, rcItem, DT_SINGLELINE | DT_NOCLIP | DT_NOPREFIX);
				}
				else
				{
					m_pAppearanceSet->DrawText(pDC, pManager, strItem, &rcItem, DT_SINGLELINE | DT_NOCLIP |
						DT_NOPREFIX | (m_bDrawTextEndEllipsis ? DT_END_ELLIPSIS : 0));
				}
			}

		}
		else
		{
			int nAvailLength = pItem->GetButtonLength() - pItem->GetContentLength();
			if (nAvailLength > 0)
			{
				rcItem.DeflateRect(nAvailLength / 2, 0);
			}

			rcItem.left += m_rcButtonTextPadding.left + m_rcButtonMargin.left;

			if (pManager->GetPosition() == xtpTabPositionBottom)
				rcItem.DeflateRect(0, m_rcButtonMargin.bottom, 0, m_rcButtonMargin.top);
			else
				rcItem.DeflateRect(0, m_rcButtonMargin.top, 0, m_rcButtonMargin.bottom);

			if (bDrawIcon)
			{
				CPoint pt(rcItem.left - 1, rcItem.CenterPoint().y - szIcon.cy/2);
				if (rcItem.Width() > szIcon.cx) pManager->DrawIcon(pDC, pt, pItem, TRUE, szIcon);
				rcItem.left += szIcon.cx + 2;
			}

			if (bDrawText && rcItem.right > rcItem.left)
			{
				rcItem.right -= m_rcButtonTextPadding.right + m_rcButtonMargin.right - (bDrawIcon ? 2 : 0);

				if (pItem->GetMarkupUIElement())
				{
					XTPMarkupSetDefaultFont(pItem->GetTabManager()->GetMarkupContext(), (HFONT)pFont->GetSafeHandle(), pDC->GetTextColor());

					CRect rcText(rcItem);

					if (m_nDrawTextFormat & DT_VCENTER)
					{
						CSize szText = XTPMarkupMeasureElement(pItem->GetMarkupUIElement());
						rcText.top = (rcText.top + rcText.bottom - szText.cy) / 2;
						rcText.bottom = rcText.top + szText.cy;
					}

					XTPMarkupRenderElement(pItem->GetMarkupUIElement(), pDC->GetSafeHdc(), rcText);
				}
				else if (m_bDrawTextPathEllipsis)
				{
					DrawTextPathEllipsis(pDC, pManager, strItem, rcItem, DT_SINGLELINE | m_nDrawTextFormat | (m_bDrawTextNoPrefix ? DT_NOPREFIX : 0));
				}
				else
				{
					if (m_bDrawTextHidePrefix)
						StripMnemonics(strItem);

					m_pAppearanceSet->DrawText(pDC, pManager, strItem, rcItem, DT_SINGLELINE | m_nDrawTextFormat |
						(m_bDrawTextHidePrefix || m_bDrawTextNoPrefix ? DT_NOPREFIX : 0) | (m_bDrawTextEndEllipsis ? DT_END_ELLIPSIS : 0));
				}
			}
		}

		if (pItem->IsFocused())
		{
			DrawFocusRect(pDC, pItem, rcFocus);
		}
		return 0;
	}
	else
	{
		if (layout == xtpTabLayoutFixed)
		{
			return _GetButtonLength(m_nFixedTabWidth, m_nMinTabWidth, m_nMaxTabWidth);
		}

		if (layout == xtpTabLayoutCompressed)
		{
			if (!bDrawText)
				return _GetButtonLength(8 + (bVertical ? szIcon.cy : szIcon.cx), m_nMinTabWidth, m_nMaxTabWidth) ;

			CXTPFontDC fntItems(pDC, m_bBoldSelected && pManager->IsActive() ? GetBoldFont(bVertical) : GetFont(bVertical));

			int nLength = 0;

			for (int i = 0; i < pManager->GetItemCount(); i++)
			{
				CRect rcItemText(0, 0, 0, 0);
				m_pAppearanceSet->DrawText(pDC, pManager, pManager->GetItem(i)->GetCaption(), rcItemText, DT_SINGLELINE | DT_CALCRECT | DT_NOCLIP | (m_bDrawTextNoPrefix ? DT_NOPREFIX : 0));
				nLength = max(nLength, rcItemText.Width());
			}
			return _GetButtonLength(nNavigateButtonsLength + nLength + m_rcButtonTextPadding.left + m_rcButtonTextPadding.right +
				(!bDrawIcon ? 0: bVertical ? szIcon.cy : szIcon.cx), m_nMinTabWidth, m_nMaxTabWidth);
		}

		CSize szText(0);
		if (pItem->GetMarkupUIElement())
		{
			XTPMarkupSetDefaultFont(pManager->GetMarkupContext(), (HFONT)pFont->GetSafeHandle(), pDC->GetTextColor());
			szText = XTPMarkupMeasureElement(pItem->GetMarkupUIElement());
		}
		else
		{
			m_pAppearanceSet->DrawText(pDC, pManager, strItem, rcItem, DT_SINGLELINE | DT_CALCRECT | DT_NOCLIP | (m_bDrawTextNoPrefix ? DT_NOPREFIX : 0));
			szText = rcItem.Size();
		}

		return _GetButtonLength(nNavigateButtonsLength + szText.cx + m_rcButtonTextPadding.left + m_rcButtonTextPadding.right +
			(!bDrawIcon ? 0: bVertical ? szIcon.cy : szIcon.cx), m_nMinTabWidth, m_nMaxTabWidth);
	}
}