HANDLE CNCaptureView::CopyRectToHandle(const CRect& rect)
{
	HANDLE hMem = NULL;
	if (m_pImage)
	{
		BOOL bRet = FALSE;
		CRect rcImage(0, 0, m_pImage->GetWidth(), m_pImage->GetHeight());
		CRect rcRealSrc;
		rcRealSrc.IntersectRect(&rect, rcImage);
		if (!rcRealSrc.IsRectEmpty())
		{
			CCanvas canvas;
			bRet = canvas.Create(NULL, rcRealSrc.Width(), rcRealSrc.Height());
			if (bRet)
			{
				for (DrawObjectList::iterator iter = m_allObjects.begin();
					iter != m_allObjects.end();
					++iter)
				{
					CDrawObject* pObj = *iter;
					if(pObj)
					{
						pObj->Draw(m_canvasImage, FALSE);
					}
				}
				BitBlt(canvas.GetMemoryDC(), 0, 0, rcRealSrc.Width(), rcRealSrc.Height(), 
					m_canvasImage.GetMemoryDC(), rcRealSrc.left, rcRealSrc.top, SRCCOPY);
				hMem = canvas.CopyToHandle();
			}
		}
	}
	return hMem;
}
void CNCaptureView::PrepareDC(CDCHandle dc)
{
	ATLASSERT(m_sizeAll.cx >= 0 && m_sizeAll.cy >= 0);
	dc.SetMapMode(MM_ANISOTROPIC);
	dc.SetWindowExt(m_sizeLogAll);
	dc.SetViewportExt(m_sizeAll);
	dc.SetViewportOrg(-m_ptOffset.x, -m_ptOffset.y);

	if (m_pImage)
	{
		CRect rcPaintAll(CPoint(0), m_sizeAll);	//device unit
		if (m_sizeClient.cx > m_sizeAll.cx)
		{
			rcPaintAll.right = m_sizeClient.cx;
		}
		if (m_sizeClient.cy > m_sizeAll.cy)
		{
			rcPaintAll.bottom = m_sizeClient.cy;
		}

		dc.DPtoLP((LPPOINT)(&rcPaintAll), 2);  //change to logical
		CRect rcImage(0, 0, m_pImage->GetWidth(), m_pImage->GetHeight());
		m_rcDrawTarget = _GetPhotoRect(rcPaintAll, &(rcImage.Size()));
	}

	dc.SetWindowOrg(-m_rcDrawTarget.left, -m_rcDrawTarget.top);
}
Пример #3
0
void CXTPSkinObjectTab::DrawTabIcon(CDC* pDC, CRect& rcItem, int iItem)
{
	CTabCtrl* pTabCtrl = (CTabCtrl*)this;

	TC_ITEM tci;
	tci.mask = TCIF_IMAGE;

	BOOL bResult = pTabCtrl->GetItem(iItem, &tci);

#ifdef _UNICODE
	if (!bResult)
	{
		TC_ITEMA tcia;
		::ZeroMemory(&tcia, sizeof(TC_ITEMA));

		tcia.mask = TCIF_IMAGE;

		bResult = (BOOL)::SendMessage(pTabCtrl->m_hWnd, TCM_GETITEMA, iItem, (LPARAM)&tcia);
		tci.iImage = tcia.iImage;
	}
#endif
	if (!bResult)
		return;

	CImageList* pImageList = pTabCtrl->GetImageList();
	if (!pImageList || tci.iImage < 0)
		return;

	CPoint point = rcItem.TopLeft();

	DWORD dwStyle = GetStyle();

	if (IsHorz(dwStyle))
	{
		point.Offset(GetMetrics()->m_cxEdge * 2, IsTop(dwStyle) ? GetMetrics()->m_cyEdge : 1);
	}
	else
	{
		point.Offset(IsLeft(dwStyle) ? GetMetrics()->m_cxEdge : 1, GetMetrics()->m_cyEdge * 2);
	}

	// Draw any associated icons.
	pImageList->Draw(pDC, tci.iImage, point, ILD_TRANSPARENT);

	IMAGEINFO info;
	::ZeroMemory(&info, sizeof(info));

	pImageList->GetImageInfo(tci.iImage, &info);
	CRect rcImage(info.rcImage);

	if (IsHorz(dwStyle))
	{
		rcItem.left += rcImage.Width() + GetMetrics()->m_cxEdge;
	}
	else
	{
		rcItem.top += rcImage.Height() + GetMetrics()->m_cyEdge;
	}
}
BOOL CNCaptureView::GetImageByRect(const CRect& rcSrc, CImage& Image)
{
	if (m_pImage)
	{
		CImageDC dcImage(Image);
		DrawObjects(m_canvasImage.GetMemoryDC());
		BitBlt(dcImage, 0, 0, rcSrc.Width(), rcSrc.Height(), m_canvasImage.GetMemoryDC(), rcSrc.left, rcSrc.top, SRCCOPY);
		CRect rcImage(0, 0, m_pImage->GetWidth(), m_pImage->GetHeight());
		m_pImage->Draw(m_canvasImage, rcImage);
		return TRUE;
	}
	return FALSE;
}
Пример #5
0
void COpenView::OnPaint()
{
	CPaintDC dc(this);
	CSize size = m_picture.GetImageSize(&dc);
	CRect rcImage(0, 0, size.cx * GetSystemMetrics(SM_CXSMICON) / 16, size.cy * GetSystemMetrics(SM_CYSMICON) / 16);
	CRect rc;
	m_picture.Render(&dc, rcImage);
	GetClientRect(&rc);
    dc.PatBlt(rcImage.Width(), 0, rc.Width() - rcImage.Width(), rcImage.Height(), PATCOPY);

	rc.left = rc.right - GetSystemMetrics(SM_CXVSCROLL);
	rc.top = rc.bottom - GetSystemMetrics(SM_CYHSCROLL);
	dc.DrawFrameControl(&rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);

	CFormView::OnPaint();
}
Пример #6
0
void CBalloonTip::InitIconImage()
{
	HICON hIcon = LoadIcon(CPaintManagerUI::GetResourceDll(),MAKEINTRESOURCE(m_nIcon));
	if (hIcon)
	{
		ICONINFO icInfo = { 0 };
		if (::GetIconInfo(hIcon, &icInfo))
		{
			BITMAP bitmap; 
			GetObject(icInfo.hbmColor, sizeof(BITMAP), &bitmap);

			Bitmap* pBitmap = NULL;
			Bitmap* pWrapBitmap = NULL;
			if (bitmap.bmBitsPixel != 32)
			{   
				pBitmap = Bitmap::FromHICON(hIcon);
			} 
			else
			{
				pWrapBitmap = Bitmap::FromHBITMAP(icInfo.hbmColor, NULL);
				BitmapData bitmapData;
				Rect rcImage(0,0, pWrapBitmap->GetWidth(), pWrapBitmap->GetHeight());
				pWrapBitmap->LockBits(&rcImage, ImageLockModeRead, pWrapBitmap->GetPixelFormat(), &bitmapData); 

				pBitmap = new Bitmap(bitmapData.Width, bitmapData.Height, bitmapData.Stride,  PixelFormat32bppARGB, (BYTE*)bitmapData.Scan0);

				pWrapBitmap->UnlockBits(&bitmapData);
			}

			//lpIconImage = pBitmap->Clone(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight(), PixelFormat32bppARGB);

			HBITMAP hBit ;

			pBitmap->GetHBITMAP(ARGB(0,0,0,0),&hBit);

			m_pPM->AddImage(_T("BalloonIcon"),hBit,pBitmap->GetWidth(),pBitmap->GetHeight(),TRUE);

			DeleteObject(icInfo.hbmColor); 
			DeleteObject(icInfo.hbmMask); 
		}
		DeleteObject(hIcon);
	}
}
CRect CNCaptureView::_GetSelectRect(const CPoint& ptLogical)
{
	CRect rcSelect;
	rcSelect.SetRectEmpty();

	//already has select rect
	DrawObjectList& drawObjList = GetSelection();
	if (drawObjList.size() == 1)
	{
		CDrawObject* pDrawObj = drawObjList.front();
		FTLASSERT(pDrawObj);
		if (dotSelectRect == pDrawObj->GetDrawObjType())
		{
			rcSelect = pDrawObj->GetPosition();
			if (!rcSelect.PtInRect(ptLogical) && !IsCapture())
			{
				rcSelect.SetRectEmpty();
			}
		}
	}
	else
	{
		if (IsCapture())
		{
			rcSelect.SetRect(GetMouseDownLogicalPoint(), GetMouseLastLogicalPoint());
			rcSelect.NormalizeRect();
		}
	}

	CRect rcImage(0, 0, m_pImage->GetWidth(), m_pImage->GetHeight());
	rcSelect.IntersectRect(rcSelect, rcImage);

	//FTLTRACE(TEXT("ptLogical=[%d,%d], rcSelect=[%d,%d]-[%d,%d]\n"),
	//	ptLogical.x, ptLogical.y , rcSelect.left, rcSelect.top, rcSelect.right, rcSelect.bottom);

	return rcSelect;
}
Пример #8
0
void CElcStatic::OnPaint()
{
	CPaintDC dc(this);

	DWORD dwStyle = GetStyle();
	DWORD dwStaticType = (dwStyle & SS_TYPEMASK);

	CRect rect;
	GetClientRect(rect);

	CElcMemDC dcMem(&dc, rect);

	if (m_bUseBackgndColor) {
		dcMem.FillSolidRect(rect, m_crBackgnd);
	}
	else if (GetParent()) {
		HBRUSH hBrush = (HBRUSH)GetParent()->SendMessage(WM_CTLCOLORSTATIC, (WPARAM)dcMem.GetSafeHdc(), (LPARAM)m_hWnd);
		if (hBrush)
			::FillRect(dcMem.GetSafeHdc(), rect, hBrush);
	}

	if (m_bUseTextColor) {
		dcMem.SetTextColor(m_crText);
	}

	if (m_pImage) {
		Graphics g(dcMem.GetSafeHdc());

		Rect rcImage(0, 0, m_pImage->GetWidth(), m_pImage->GetHeight());
		Rect rcDest;
		if (dwStyle & SS_CENTERIMAGE) {
			rcDest.X = rect.left + (rect.Width() - rcImage.Width) / 2;
			rcDest.Y = rect.top + (rect.Height() - rcImage.Height) / 2;
			rcDest.Width = rcImage.Width;
			rcDest.Height = rcImage.Height;
		}
		else {
			rcDest.X = rect.left;
			rcDest.Y = rect.top;
			rcDest.Width = rect.Width();
			rcDest.Height = rect.Height();
		}

		thePainter.DrawStretchImage(&g, m_pImage, &rcDest, &rcImage, 0);
	}
	else if (dwStaticType == SS_ICON
		|| dwStaticType == SS_BITMAP
		|| dwStaticType == SS_OWNERDRAW
		|| dwStaticType == SS_USERITEM
		|| dwStaticType == SS_ENHMETAFILE) 
	{
		// not support type
		// pls use SetImage() to replace
		ASSERT(0);
		return;
	}
	else if (dwStaticType == SS_BLACKRECT
		|| dwStaticType == SS_GRAYRECT
		|| dwStaticType == SS_WHITERECT
		|| dwStaticType == SS_BLACKFRAME
		|| dwStaticType == SS_GRAYFRAME
		|| dwStaticType == SS_WHITEFRAME)
	{
		// not support
		// pls use Standard MFC class : CStatic
		ASSERT(0);
		return;
	}
	else { 
		if (dwStaticType == SS_ETCHEDHORZ) {
			CPen pen1(PS_SOLID, 1, m_crEtched1);
			CPen * pOld = dcMem.SelectObject(&pen1);
			dcMem.MoveTo(rect.left, rect.top);
			dcMem.LineTo(rect.right - 2, rect.top);

			CPen pen2(PS_SOLID, 1, m_crEtched2);
			dcMem.SelectObject(&pen2);
			dcMem.MoveTo(rect.left + 2, rect.top+1);
			dcMem.LineTo(rect.right, rect.top+1);

			dcMem.SelectObject(&pOld);
		}
		else if (dwStaticType == SS_ETCHEDVERT) {
			CPen pen1(PS_SOLID, 1, m_crEtched1);
			CPen * pOld = dcMem.SelectObject(&pen1);
			dcMem.MoveTo(rect.left, rect.top);
			dcMem.LineTo(rect.left, rect.bottom - 2);

			CPen pen2(PS_SOLID, 1, m_crEtched2);
			dcMem.SelectObject(&pen2);
			dcMem.MoveTo(rect.left + 1, rect.top + 2);
			dcMem.LineTo(rect.left + 1, rect.bottom);

			dcMem.SelectObject(&pOld);
		}
		else if (dwStaticType == SS_ETCHEDFRAME) {
			// not implement
			// support later...
			ASSERT(0);
		}
		else {
			CFont* pOldFont = dcMem.SelectObject(GetFont());
			UINT nFormat = 0;
			
			if (dwStaticType == SS_LEFT) {
				nFormat = DT_LEFT | DT_NOFULLWIDTHCHARBREAK | DT_WORDBREAK;
			}
			else if (dwStaticType == SS_CENTER) {
				nFormat = DT_CENTER | DT_NOFULLWIDTHCHARBREAK | DT_WORDBREAK;
			}
			else if (dwStaticType == SS_RIGHT) {
				nFormat = DT_RIGHT | DT_NOFULLWIDTHCHARBREAK | DT_WORDBREAK;
			}
			else if (dwStaticType == SS_SIMPLE) {
				nFormat = DT_SINGLELINE | DT_VCENTER;
			}
			else if (dwStaticType == SS_LEFTNOWORDWRAP) {
				nFormat = DT_SINGLELINE;
			}

			/*
			// these codes are been commented because something errors are not been fiexd yet
			if (dwStyle & SS_ENDELLIPSIS) {
				nFormat |= DT_MODIFYSTRING | DT_END_ELLIPSIS | DT_WORD_ELLIPSIS;
			}
			if (dwStyle & SS_PATHELLIPSIS) {
				nFormat |= DT_MODIFYSTRING | DT_PATH_ELLIPSIS | DT_WORD_ELLIPSIS;
			}*/

			if (dwStyle & SS_NOPREFIX) {
				nFormat |= DT_NOPREFIX;
			}

			if (dwStyle & SS_EDITCONTROL) {
				nFormat |= DT_EDITCONTROL;
			}

			CString strText;
			GetWindowText(strText);
			dcMem.DrawText(strText, rect, nFormat);

			dcMem.SelectObject(pOldFont);
		}
	}

	dcMem.DrawMe();
}
Пример #9
0
bool CMenuSpawn::DrawItem(LPDRAWITEMSTRUCT lp)
{
	bool res = false;
	//pDC1.Draw3dRect(rcClient,CDrawLayer::GetRGBColorFace(),CDrawLayer::GetRGBColorShadow());
	if (lp->CtlType == ODT_MENU)
	{
		UINT id = lp->itemID;
		UINT state = lp->itemState;
		bool bEnab = !(state & ODS_DISABLED);
		bool bSelect = (state & ODS_SELECTED) ? true : false;
		bool bChecked = (state & ODS_CHECKED) ? true : false;
		bool bHotLight =(state & ODS_HOTLIGHT) ? true : false;
		CGDI  pDC(lp->hDC);
		SpawnItem * pItem = (SpawnItem *) lp->itemData;
		if (pItem)
		{
			CFont  pft=((HFONT) hMenuFont ? hMenuFont : hGuiFont);
			CFont  of=(pDC.SelectObject(pft));
			CRect rc=lp->rcItem;
			CRect rcImage(rc), rcText(rc);
			rcImage.right = rcImage.left + rc.Height();
			rcImage.bottom = rc.bottom;

			CBrush brush;
			brush.CreateSolidBrush(CDrawLayer::GetRGBColorFace());
			
			CRect rcImg=rcImage;
			rcImg.right+=1;
			pDC.FillRect(rcImg,&brush);
			if (pItem->iCmd != -4)
			{
				CGradient M(CSize(rcImg.Width(),rcImg.Height()));	
				M.PrepareHorizontal(&pDC,CDrawLayer::GetRGBColorWhite(),CDrawLayer::GetRGBColorFace());
				M.Draw(&pDC,rcImg.left,rcImg.top,0,0,rcImg.Width()+2,rcImg.Height(),SRCCOPY);	
			}
			if (bBackBitmap) 
			{
				CGDI tempDC;
				tempDC.CreateCompatibleDC(pDC);
				tempDC.FillSolidRect(rcText, crMenu);
				CBitmap  ob = tempDC.SelectObject(&bmpBack);
				pDC.FillSolidRect(rcText, crMenu);
				pDC.BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), tempDC, rc.left, rc.top, SRCCOPY );
			}
			int obk = pDC.SetBkMode(TRANSPARENT);
			if (pItem->iCmd == -3) // is a separator
			{
				CBrush brush;
				CRect m_rc=rc;
				brush.CreateSolidBrush(CDrawLayer::GetRGBSkinMenu());
				rc.left+=rcImage.Width()+15;
				pDC.FillRect(rc,&brush);
				rc.top += rc.Height()>>1;	
				rc.left+= 5;
				brush.DeleteObject();
				pDC.DrawEdge(rc, EDGE_ETCHED, BF_TOP);	
				rcImg.right= rc.left-4;
				CGradient M(CSize(rcImg.Width(),rcImg.Height()));	
				M.PrepareHorizontal(&pDC);
				M.Draw(&pDC,rcImg.left,rcImg.top,0,0,rcImg.Width()-1,rcImg.Height(),SRCCOPY);	
				fltMenu.iCmd=-1;
		
			}
			else if (pItem->iCmd == -4) // is a title item
Пример #10
0
void CGfxPopupMenu::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	if (lpDrawItemStruct->CtlType == ODT_MENU)
	{
		UINT id = lpDrawItemStruct->itemID;
		UINT state = lpDrawItemStruct->itemState;
		bool bEnab = !(state & ODS_DISABLED);
		bool bSelect = (state & ODS_SELECTED) ? true : false;
		bool bChecked = (state & ODS_CHECKED) ? true : false;
		bool bBold = (state & ODS_DEFAULT) ? true : false;

		SpawnItem * pItem = (SpawnItem *) lpDrawItemStruct->itemData;
		if (pItem)
		{
			CDC * pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
			CFont * pft;
			if (!bBold) pft = CFont::FromHandle((HFONT) hMenuFont ? hMenuFont : hGuiFont);
			else pft = CFont::FromHandle((HFONT) hMenuBoldFont ? hMenuBoldFont : hGuiFont);
			CFont * of = pDC->SelectObject(pft);

			CRect rc(lpDrawItemStruct->rcItem);
			CRect rcImage(rc), rcText(rc);
			rcImage.right = rcImage.left + rc.Height();
			rcImage.bottom = rc.bottom;

			if (pItem->iCmd == -3) // is a separator
			{
				CPen pnDk(PS_SOLID,1,cr3dShadow);
				CPen pnLt(PS_SOLID,1,cr3dHilight);
				CPen * opn = pDC->SelectObject(&pnDk);
				pDC->MoveTo(rc.left + 2, rc.top + 2);
				pDC->LineTo(rc.right - 2, rc.top + 2);
				pDC->SelectObject(&pnLt);
				pDC->MoveTo(rc.left + 2, rc.top + 3);
				pDC->LineTo(rc.right - 2, rc.top + 3);
				pDC->SelectObject(opn);
			}
			else if (pItem->iCmd == -4) // is a title item
			{
				CString cs(pItem->cText), cs1;
				CRect rcBdr(rcText);

				if (bSelect && bEnab)
				{
					rcText.top ++;
					rcText.left += 2;
				}
				pDC->FillSolidRect(rcText, crMenu);
				pDC->DrawText(cs, rcText, DT_VCENTER|DT_CENTER|DT_SINGLELINE);
				if (bSelect && bEnab) pDC->Draw3dRect(rcBdr,cr3dShadow,cr3dHilight);
			}
			else
			{
				rcText.left += rcImage.right + 1;

				int obk = pDC->SetBkMode(TRANSPARENT);
				
				COLORREF ocr;
				if (bSelect)
				{
					if (pItem->iImageIdx >= 0 || (state & ODS_CHECKED))
						pDC->FillSolidRect(rcText, crHighlight);
					else
						pDC->FillSolidRect(rc, crHighlight);

					ocr = pDC->SetTextColor(crMenuTextSel);
				}
				else
				{
					if (pItem->iImageIdx >= 0 || (state & ODS_CHECKED))
						pDC->FillSolidRect(rcText, crMenu);
					else
						pDC->FillSolidRect(rc/*rcText*/, crMenu);
					ocr = pDC->SetTextColor(crMenuText);
				}

				if (pItem->iImageIdx >= 0)
				{
					int ay = (rcImage.Height() - szImage.cy) / 2;
					int ax = (rcImage.Width()  - szImage.cx) / 2;

					if (bSelect && bEnab)
						pDC->Draw3dRect(rcImage,cr3dHilight,cr3dShadow);
					else
					{
						pDC->Draw3dRect(rcImage,crMenu,crMenu);
					}


					if (bEnab)
					{
						ilList.Draw(pDC, pItem->iImageIdx, CPoint(rcImage.left + ax, rcImage.top +ay), ILD_NORMAL);
					}
					else
					{
						HICON hIcon = ilList.ExtractIcon( pItem->iImageIdx );
						pDC->DrawState( CPoint(rcImage.left + ax, rcImage.top + ay ), szImage, (HICON)hIcon, DST_ICON | DSS_DISABLED, (CBrush *)NULL );
					}
				}
				else
				{
					if (bChecked)
					{
						int ay = (rcImage.Height() - szImage.cy) / 2;
						int ax = (rcImage.Width()  - szImage.cx) / 2;

						ilOther.Draw(pDC, 0, CPoint(rcImage.left + ax, rcImage.top + ay - 2), ILD_NORMAL);
					}
				}

				CString cs(pItem->cText), cs1;
				CSize sz;
				sz = pDC->GetTextExtent(cs);
				int ay1 = (rcText.Height() - sz.cy) / 2;
				rcText.top += ay1;
				rcText.left += 2;
				rcText.right -= 15;

				int tf = cs.Find('\t');
				if (tf >= 0)
				{
					cs1 = cs.Right(cs.GetLength() - tf - 1);
					cs = cs.Left(tf);
					if (!bEnab)
					{
						if (!bSelect)
						{
							CRect rcText1(rcText);
							rcText1.InflateRect(-1,-1);
							pDC->SetTextColor(cr3dHilight);
							pDC->DrawText(cs, rcText1, DT_VCENTER|DT_LEFT);
							pDC->DrawText(cs1, rcText1, DT_VCENTER|DT_RIGHT);
							pDC->SetTextColor(crGrayText);
							pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT);
							pDC->DrawText(cs1, rcText, DT_VCENTER|DT_RIGHT);
						}
						else
						{
							pDC->SetTextColor(crMenu);
							pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT);
							pDC->DrawText(cs1, rcText, DT_VCENTER|DT_RIGHT);
						}
					}
					else
					{
						pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT);
						pDC->DrawText(cs1, rcText, DT_VCENTER|DT_RIGHT);
					}
				}
				else 
				{
					if (!bEnab)
					{
						if (!bSelect)
						{
							CRect rcText1(rcText);
							rcText1.InflateRect(-1,-1);
							pDC->SetTextColor(cr3dHilight);
							pDC->DrawText(cs, rcText1, DT_VCENTER|DT_LEFT|DT_EXPANDTABS);
							pDC->SetTextColor(crGrayText);
							pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT|DT_EXPANDTABS);
						}
						else
						{
							pDC->SetTextColor(crMenu);
							pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT|DT_EXPANDTABS);
						}
					}
					else
						pDC->DrawText(cs, rcText, DT_VCENTER|DT_LEFT|DT_EXPANDTABS);
				}
				pDC->SetTextColor(ocr);
				pDC->SetBkMode(obk);
			}

			pDC->SelectObject(of);
		}
	}
}
void CXTPHeaderCtrlThemeResource::OnDrawItemText(LPDRAWITEMSTRUCT lpDIS, CXTPHeaderCtrl* pHeaderCtrl)
{
	ASSERT_VALID(pHeaderCtrl);

	CDC* pDC = CDC::FromHandle(lpDIS->hDC);
	LPHDITEM lpHDI = (LPHDITEM)lpDIS->itemData;

	// prepare the device context to draw text.
	CXTPFontDC fontDC(pDC, pHeaderCtrl->GetFont());

	// construct text size.
	CRect rcItem(lpDIS->rcItem);
	rcItem.DeflateRect(m_sizePadding.cx, 0);

	BOOL bSortAsc;
	UINT nSortItem = pHeaderCtrl->GetSortedCol(&bSortAsc);
	if (nSortItem == lpDIS->itemID)
		rcItem.right -= m_sizeArrow.cx + m_iArrowPadding*2;

	CRect rcText(rcItem);
	CSize sizeText = pDC->GetTextExtent(lpHDI->pszText);

	rcText.top = (m_sizePadding.cy > 0) ?
		m_sizePadding.cy : (rcItem.Height()-sizeText.cy)/2;
	rcText.bottom = rcText.top + sizeText.cy;

	if ((lpHDI->fmt & HDF_BITMAP && lpHDI->hbm != NULL) || (lpHDI->fmt & HDF_IMAGE))
	{
		if (lpHDI->fmt & HDF_BITMAP_ON_RIGHT)
		{
			CRect rcImage(rcText);
			rcImage.left += sizeText.cx + m_sizePadding.cx;
			OnDrawItemBitmap(lpDIS, rcImage, pHeaderCtrl);
		}
		else
		{
			OnDrawItemBitmap(lpDIS, rcText, pHeaderCtrl);
		}
	}

	// determine justification for text.
	switch (lpHDI->fmt & HDF_JUSTIFYMASK)
	{
	case HDF_LEFT:
		rcText.right = rcText.left + sizeText.cx;
		break;
	case HDF_CENTER:
		rcText.left += (rcItem.Width()-sizeText.cx)/2;
		rcText.right = rcText.left + sizeText.cx;
		break;
	case HDF_RIGHT:
		rcText.left = rcText.right - sizeText.cx;
		break;
	}

	// size text to fit available display area.
	rcText.left = __max(rcText.left, rcItem.left);
	rcText.right = __min(rcText.right, rcItem.right);

	// check if we are sorting.
	if (HasSortArrow() && nSortItem == lpDIS->itemID)
	{
		lpDIS->rcItem = rcText;
		OnDrawItemSortArrow(lpDIS, bSortAsc);
	}

	if (rcText.Width() > 0)
	{
		// draw text.
		pDC->DrawText(lpHDI->pszText, &rcText,
			DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
	}
}
Пример #12
0
void TrackListCtrl::DrawItem(Gdiplus::Graphics& g, INT nItem, Gdiplus::Rect& itemRC)
{
	HDC hdc = g.GetHDC();
	if (hdc == 0)
	{
		TRACE(_T("@1 TrackListCtrl::DrawItem. Cant get HDC\r\n"));
		return;		
	}
	CDC* pDC = CDC::FromHandle(hdc);
	PrgAPI* pAPI = PRGAPI();
	//Calculate Colors
	BOOL bSelected = IsItemSelected(nItem);
	COLORREF clrText = m_colors[COL_Text];
	COLORREF clrBk = m_colors[COL_Bk];
	if (bSelected)
	{
		clrText =  m_colors[COL_TextSel];
		clrBk = m_colors[COL_TextSelBk];
	}

	CRect rcSubItem(itemRC.X, itemRC.Y, itemRC.GetRight(), itemRC.GetBottom());
	pDC->SetTextColor(clrText);
	pDC->FillSolidRect(rcSubItem, clrBk);

	const INT cMargin = 2;

	FullTrackRecordSP& rec = (*m_pCollection)[nItem];

	pDC->SetBkMode(TRANSPARENT);

	INT curx = cMargin;


	CRect rcFirstLine(rcSubItem);
	rcFirstLine.bottom = rcFirstLine.top + 20;
	rcFirstLine.left = cMargin;
	rcFirstLine.right -= cMargin;
	CRect rcSecondLine(rcSubItem);
	rcSecondLine.top = rcFirstLine.bottom;
	rcSecondLine.left = cMargin;
	rcSecondLine.right -= cMargin;


	if (m_bDrawPictures)
	{
		INT imgHeight = 32;//rcSubItem.Height() - 2 * cMargin;
		INT cury = rcSubItem.top + cMargin;
		LocalPictureManager* pLM = PRGAPI()->GetLocalPictureManager();
		Gdiplus::Rect rcImage(curx, cury, imgHeight, imgHeight);
		Graphics g2(hdc);
		BOOL bRet = pLM->DrawAlbumThumbnail(rec->artist.name.c_str(), rec->album.name.c_str(), g2, rcImage);
		if (!bRet)
			bRet = pLM->DrawArtistThumbnail(rec->artist.name.c_str(), g2, rcImage);
		if (!bRet)
			bRet = pLM->DrawDefaultThumbnail(IIT_AlbumPicture, g2, rcImage);

		curx += 32 + cMargin ;

	}

	rcSecondLine.left = curx;
	//=== Draw the icon
	INT cury = rcFirstLine.top + (rcFirstLine.Height() - 16) / 2;
	pDC->SetTextColor(clrText);
	DrawIconEx(pDC->m_hDC, curx, cury, pAPI->GetIconForTrackType(rec->track.trackType), 16, 16, 0, 0, DI_NORMAL);
	curx += 16 + cMargin;


	//=== Draw the title
	CRect rcTitle(rcFirstLine);
	rcTitle.left = curx;
	CFont* pOldFont = pDC->SelectObject(m_pBoldFont);
	pDC->DrawText(rec->track.name.c_str(), rec->track.name.size(), &rcTitle, DT_END_ELLIPSIS | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
	pDC->DrawText(rec->track.name.c_str(), rec->track.name.size(), &rcTitle, DT_END_ELLIPSIS | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);

	//=== Draw the artist
	CRect rcArtist(rcFirstLine);
	rcArtist.left = rcTitle.right + cMargin;
	pDC->DrawText(rec->artist.name.c_str(), rec->artist.name.size(), &rcArtist, DT_END_ELLIPSIS | DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);

	pDC->SelectObject(m_pNormalFont);

	//=== Next line
	//=== Draw the rating (if exists)
	if (rec->track.rating > 0 && rec->track.rating < 256)
	{
		FLOAT fStars = Rating2Stars(rec->track.rating);
		if (fStars > 0.0f && fStars <=1.0f)
		{
			DrawIconEx(hdc, rcSecondLine.left, rcSecondLine.top, pAPI->GetIcon(ICO_StarBad16), 16, 16, 0, 0, DI_NORMAL);
			rcSecondLine.left += 17;
		}
		while (fStars > 1.0f)
		{
			DrawIconEx(hdc, rcSecondLine.left, rcSecondLine.top, pAPI->GetIcon(ICO_StarGold16), 16, 16, 0, 0, DI_NORMAL);
			fStars -= 1.0f;
			rcSecondLine.left += 17;
		}
	}

	TCHAR time[500];
	UINT len = _sntprintf(time, 500, _T("%d:%02d | %s: %s | %s: %s"), 
		INT (rec->track.duration / 60), INT(rec->track.duration) % 60,
		pAPI->GetString(IDS_ALBUM), rec->album.name.c_str(),
		pAPI->GetString(IDS_LOCATION), rec->track.location.c_str()
		);
	pDC->DrawText(time, len, &rcSecondLine, DT_END_ELLIPSIS | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);

	pDC->SelectObject(pOldFont);

	g.ReleaseHDC(pDC->m_hDC);
}
Пример #13
0
void CHTMLListCtrl::DrawItem(CDC *pDC, CRect rcItem, HTMLLIST_ITEM *pItem, BOOL bSelected)
{
	CRect rcClipBox;
	pDC->GetClipBox(&rcClipBox);

	if(!IsRectVisible(rcClipBox,rcItem))
	{
		return;
	}

	COLORREF clrText = RGB(0,0,0);
	COLORREF clrOld;
	CRect rcImage(0,0,0,0);
		
	if(bSelected)
	{
		clrText = m_clrTextSelectedItem;
		pDC->FillSolidRect(&rcItem,m_clrBkSelectedItem);
	}
	else
	{
		clrText = m_clrTextCtrlItem;
		pDC->FillSolidRect(&rcItem,m_clrBkCtrlItem);
	}

	if(m_dwExtendedStyles & HTMLLIST_STYLE_GRIDLINES)
	{
		pDC->DrawEdge(&rcItem,BDR_SUNKENINNER,BF_LEFT|BF_BOTTOM|BF_FLAT);
	}
	
	CPoint ptCheckBox = rcItem.TopLeft();

	if(m_dwExtendedStyles & HTMLLIST_STYLE_CHECKBOX)
	{
		ptCheckBox.x += ITEM_PADDING_CHECKBOX_LEFT;
		ptCheckBox.y += rcItem.Height() / 2 - 8;
		
		m_ImageList.Draw(pDC,pItem->bChecked?1:0,ptCheckBox,ILD_TRANSPARENT);
		ptCheckBox.x += ITEM_CHECKBOX_WIDTH;
	}
	
	//Draw image if an imagelist is attached
	if(m_dwExtendedStyles & HTMLLIST_STYLE_IMAGES)
	{
		if(m_pImageList)
		{
			IMAGEINFO imgInfo = {0};
			m_pImageList->GetImageInfo(0,&imgInfo);
			rcImage = imgInfo.rcImage;
			
			CPoint pt = ptCheckBox;
			pt.x += ITEM_IMAGE_PADDING_LEFT;
			pt.y = rcItem.top;
			pt.y += rcItem.Height() / 2 - rcImage.Height()/2;
			
			m_pImageList->Draw(pDC,pItem->uiImage,pt,ILD_TRANSPARENT);			
		}
	}
	
	if(pItem->nStyle == NORMAL_TEXT)
	{
		clrOld = pDC->SetTextColor(clrText);
		
		CRect rc = rcItem;
		
		if(rcImage.Width())
		{
			//make space for the Image already drawn
			rc.DeflateRect(rcImage.Width() + ITEM_IMAGE_PADDING_LEFT + ITEM_IMAGE_PADDING_RIGHT,0,0,0);
		}
		
		if(m_dwExtendedStyles & HTMLLIST_STYLE_CHECKBOX)
		{
			rc.left += ITEM_PADDING_LEFT + ITEM_CHECKBOX_WIDTH;
		}
		else
		{
			rc.left += ITEM_PADDING_LEFT;
		}
		
		if(!pItem->bHeightSpecified)
			rc.top += ITEM_PADDING_TOP;
		
		pDC->DrawText(pItem->sItemText,pItem->sItemText.GetLength(),&rc,
			DT_LEFT|DT_WORDBREAK);
	}
	else if(pItem->nStyle == HTML_TEXT)
	{
		//Draw HTML
		clrOld = pDC->SetTextColor(clrText);
		
		CRect rc = rcItem;
		if(rcImage.Width())
		{
			//make space for the Image already drawn
			rc.DeflateRect(rcImage.Width() + ITEM_IMAGE_PADDING_LEFT + ITEM_IMAGE_PADDING_RIGHT,0,0,0);
		}
		if(m_dwExtendedStyles & HTMLLIST_STYLE_CHECKBOX)
		{
			rc.left += ITEM_PADDING_LEFT + ITEM_CHECKBOX_WIDTH;
		}
		else
		{
			rc.left += ITEM_PADDING_LEFT;
		}
		
		if(!pItem->bHeightSpecified)
			rc.top += ITEM_PADDING_TOP;
		
		DrawHTML(pDC->GetSafeHdc(),pItem->sItemText,pItem->sItemText.GetLength(),
			&rc,DT_LEFT|DT_WORDBREAK);
	}
	else if(pItem->nStyle == SINGLE_LINE_TEXT)
	{
		clrOld = pDC->SetTextColor(clrText);
		
		CRect rc = rcItem;
		if(rcImage.Width())
		{
			//make space for the Image already drawn
			rc.DeflateRect(rcImage.Width() + ITEM_IMAGE_PADDING_LEFT + ITEM_IMAGE_PADDING_RIGHT,0,0,0);
		}
		if(m_dwExtendedStyles & HTMLLIST_STYLE_CHECKBOX)
		{
			rc.left += ITEM_PADDING_LEFT + ITEM_CHECKBOX_WIDTH;
		}
		else
		{
			rc.left += ITEM_PADDING_LEFT;
		}
		
		if(!pItem->bHeightSpecified)
			rc.top += ITEM_PADDING_TOP;
		
		//See if we can fit the text in one line
		char szBuffer[_MAX_PATH];
		memset(szBuffer,0,_MAX_PATH);
		
		_tcscpy(szBuffer,pItem->sItemText);
		
		if(PathCompactPath(pDC->GetSafeHdc(),szBuffer,rc.Width()))
		{
			pDC->DrawText(szBuffer,_tcslen(szBuffer),&rc,
				DT_LEFT|DT_SINGLELINE|DT_VCENTER);	
		}
		else
		{
			pDC->DrawText(pItem->sItemText,pItem->sItemText.GetLength(),&rc,
				DT_LEFT|DT_SINGLELINE|DT_VCENTER);
		}
	}
	
	pDC->SetTextColor(clrOld);
	
	//Draw the focus rect if focused
	if(m_bHasFocus && (bSelected))
	{
		pDC->DrawFocusRect(&rcItem);
	}
}
void CNCaptureView::DoPaint(CDCHandle dc)
{
	FUNCTION_BLOCK_TRACE(20);
	if ( m_bIsDrawing )
	{
		return;
	}

	m_bIsDrawing = TRUE;
	BOOL bRet = FALSE;

	CRect rcClientLogical;
	GetClientRect(rcClientLogical);
	dc.DPtoLP(rcClientLogical);

	rcClientLogical.InflateRect(4, 4);	//fix scroll brush display error

	//CRect rcClient;
	//GetClientRect(&rcClient);
	//CWindowDC WndDc(m_hWnd);
	//WndDc.FillRect(&rcClient, m_brBackground);

	{
		//make sure MemDC bitblt

		//CMemoryDC memDC(dc.m_hDC, rcClient);
		CZoomScrollMemDC memDC (dc.m_hDC, rcClientLogical);
		PrepareDC(memDC.m_hDC);
		memDC.SetBrushOrg( -m_ptOffset.x , -m_ptOffset.y);

		//API_VERIFY(memDC.FillRect(&rcClip, m_brBackground));
		//API_VERIFY(memDC.FillRect(&rcClientLogical, m_brBackground));
		memDC.FillSolidRect(&rcClientLogical, NCAPTUREVIEW_BACKGROUND_CLR);
		if (m_pImage)
		{
			CRect rcImage(0, 0, m_pImage->GetWidth(), m_pImage->GetHeight());
			if (m_canvasImage.IsCanvasChanged(rcImage) || m_bImageChanged)
			{
				m_canvasImage.Release();
				API_VERIFY(m_canvasImage.Create(m_hWnd, rcImage.Width(), rcImage.Height()));

				m_bImageChanged = FALSE;
				//API_VERIFY(m_pImage->Draw(m_canvasImage, rcImage));
			}
			API_VERIFY(m_pImage->Draw(m_canvasImage, rcImage));
			DrawObjects(m_canvasImage.GetMemoryDC());
			{
				//When Capture image size multiply by zoom bigger than 32767, GDI CAN NOT display the image
				memDC.SetStretchBltMode(HALFTONE); //HALFTONE);

				bRet = memDC.BitBlt(
					0, 0, //rcClientLogical.left, rcClientLogical.top
					rcImage.Width(), rcImage.Height(),// rcClientLogical.Width(), rcClientLogical.Height(),
					m_canvasImage.GetMemoryDC(), 
					0, 0, //rcClientLogical.left, rcClientLogical.top, 
					SRCCOPY);
				if(!bRet)
				{
					FTLTRACE(TEXT("%s StretchBlt Failed, LastError=%d\n"), __FILE__LINE__, ::GetLastError());
				}
			}
			DrawTextObject(memDC.m_hDC);
			{
				CFMMTextDCGuard mmTextDCGuard(memDC);

				if (!m_pImage && m_pDefaultImage)
				{
					//no image ,just draw default image
					CRect rcClientDevice;
					GetClientRect(&rcClientDevice);
					CSize szDefaultImage(m_pDefaultImage->GetWidth(), m_pDefaultImage->GetHeight());
					CRect rcDefaultImageTarget = m_pCalcRect->GetPhotoRect(rcClientDevice, &szDefaultImage, 1.0f, FALSE, FALSE);
					NDGraphics::DrawGdiplusImage(memDC, m_pDefaultImage, rcDefaultImageTarget.left, rcDefaultImageTarget.top,
						rcDefaultImageTarget.Width(), rcDefaultImageTarget.Height());
				}
				DrawObjectsTracker(memDC.m_hDC);
			}
		}
	}


	//FTLTRACE(TEXT("DoPaint, m_rcDrawTarget=[%d,%d]x[%d,%d]\n"), m_rcDrawTarget.left, m_rcDrawTarget.top,
	//	m_rcDrawTarget.right, m_rcDrawTarget.bottom);
	//CClientDC clientDC(m_hWnd);

	m_bIsDrawing = FALSE;
}
Пример #15
0
void ClsXPMenu::RenderItem( ClsDC *pDC, LPDRAWITEMSTRUCT pdis, ItemData *pData )
{
	// Determine the image, checkbox and text parts of the menu.
	ClsRect  rcCaption( pdis->rcItem ), rcImage( pdis->rcItem ), rcCheck;
	rcImage.Right() = rcImage.Left() + m_cxBitmap + 8;
	rcCaption.Left() += m_cxBitmap + 8;
	rcCheck = rcImage;
	rcCheck.Deflate( 1, 1 );
	rcCheck.Right()--;

	// A toplevel item?
	if ( pData->m_bToplevel )
	{
		// Selected or hot?
		if ( pdis->itemState & ODS_SELECTED || pdis->itemState & ODS_HOTLIGHT )
		{
			// Select appropiate colors.
			COLORREF crFg, crBg;
			if ( pdis->itemState & ODS_HOTLIGHT || ! IsDropped())
			{
				crFg = XPColors.GetXPColor( ClsXPColors::XPC_OUTER_SELECTION);
				crBg = XPColors.GetXPColor( ClsXPColors::XPC_INNER_SELECTION );
			}
			else
			{
				crFg = XPColors.GetXPColor( ClsXPColors::XPC_IMAGE_DISABLED );
				crBg = XPColors.GetXPColor( ClsXPColors::XPC_IMAGE_BACKGROUND );
			}
			// Render the background.
			pDC->OutlinedRectangle( &pdis->rcItem, crFg, crBg );
		}
		else
			// Simply clear background.
			pDC->FillRect( &pdis->rcItem, ( HBRUSH )( COLOR_BTNFACE + 1 ));

		// Adjust the caption rectangle.
		rcCaption = pdis->rcItem;
		rcCaption.Offset( 6, 0 );
	}
	else
	{
		// Is the item selected?
		if (( pdis->itemState & ODS_SELECTED ) && pData->m_bSeparator == FALSE )
		{
			// Determine background color.
			COLORREF crBkgnd;

			// Is the item disabled or not?
			if ( ! ( pdis->itemState & ODS_DISABLED ))
				crBkgnd = XPColors.GetXPColor( ClsXPColors::XPC_INNER_SELECTION );
			else
			{
				// See if either the up or the down arrow key is pressed.
				// If so the item is selected using one of these keys. In
				// That case we render the item differently.
				//
				// Sorry about the goto...
				if ( ! ISKEYDOWN( VK_UP ) && ! ISKEYDOWN( VK_DOWN ) && ! ISKEYDOWN( VK_LEFT ) && ! ISKEYDOWN( VK_RIGHT )) goto normal;
				crBkgnd = XPColors.GetXPColor( ClsXPColors::XPC_TEXT_BACKGROUND );
			}
			// Render the selection rectangle.
			pDC->OutlinedRectangle( &pdis->rcItem, XPColors.GetXPColor( ClsXPColors::XPC_OUTER_SELECTION ), crBkgnd );
		}
		else
		{
normal:
			// Render the image background.
			ClsBrush brush( XPColors.GetXPColor( ClsXPColors::XPC_IMAGE_BACKGROUND ));
			pDC->FillRect( rcImage, &brush );

			// render the text background.
			brush.Delete();
			brush.CreateSolidBrush( XPColors.GetXPColor( ClsXPColors::XPC_TEXT_BACKGROUND ));
			pDC->FillRect( rcCaption, &brush );
		}

		// Is the item checked?
		if ( pdis->itemState & ODS_CHECKED )
		{
			// Disabled?
			COLORREF crBk, crFg;
			if ( ! ( pdis->itemState & ODS_DISABLED ))
			{
				// Select colors to use.
				crBk = XPColors.GetXPColor( pdis->itemState & ODS_SELECTED ? ClsXPColors::XPC_INNER_CHECKED_SELECTED : ClsXPColors::XPC_INNER_CHECKED );
				crFg = XPColors.GetXPColor( ClsXPColors::XPC_OUTER_CHECKED );
			}
			else
			{
				// Select colors to use.
				crBk = XPColors.GetXPColor( ClsXPColors::XPC_IMAGE_BACKGROUND );
				crFg = XPColors.GetXPColor( ClsXPColors::XPC_IMAGE_DISABLED );
			}
			// Render checkbox image.
			pDC->OutlinedRectangle( rcCheck, crFg, crBk );

			// Does this item have a bitmap?
			if ( pData->m_iBitmap == -1 )
			{
				// Get the item type and checkmark information.
				ClsMenuItemInfo	mi;
				mi.fMask = MIIM_CHECKMARKS | MIIM_TYPE;
				if ( GetItemInfo( pdis->itemID, &mi ))
				{
					// Radiobutton?
					if ( mi.fType & MFT_RADIOCHECK )
						// Render the radiobutton.
						RenderRadioBullet( pDC,
									rcCheck,
									XPColors.GetXPColor( pdis->itemState & ODS_DISABLED ? ClsXPColors::XPC_IMAGE_DISABLED : ClsXPColors::XPC_TEXT ),
									pdis->itemState );
					else
						// Render the checkmark or checkmark bitmap.
						RenderCheckmark( pDC,
									rcCheck,
									XPColors.GetXPColor( pdis->itemState & ODS_DISABLED ? ClsXPColors::XPC_IMAGE_DISABLED : ClsXPColors::XPC_TEXT ),
									XPColors.GetXPColor( ClsXPColors::XPC_TEXT ),
									pdis->itemState & ~ODS_DISABLED,
									&mi );
				}
			}
		}
		// If we do not have a bitmap and we are
		// not a seperator we check to see if we
		// are a Radio-check item.
		else if ( pData->m_iBitmap == -1 && pData->m_bSeparator == FALSE )
		{
			// Radio item?
			ClsMenuItemInfo	mi;
			mi.fMask = MIIM_CHECKMARKS | MIIM_TYPE;
			if ( GetItemInfo( pdis->itemID, &mi ) && mi.fType & MFT_RADIOCHECK )
			{
				// Render the radiobutton.
				RenderRadioBullet( pDC,
							rcCheck,
							XPColors.GetXPColor( pdis->itemState & ODS_DISABLED ? ClsXPColors::XPC_IMAGE_DISABLED : ClsXPColors::XPC_TEXT ),
							pdis->itemState );
			}
		}

		// Item data present?
		if ( pData )
		{
			// Separator?
			if ( pData->m_bSeparator == TRUE )
			{
				// Create and select pen to render the separator.
				ClsPen pen( PS_SOLID, 1, XPColors.GetXPColor( ClsXPColors::XPC_SEPARATOR ));
				ClsSelector s( pDC, pen );

				// Render the separator.
				rcCaption.Top() += rcCaption.Height() / 2;
				rcCaption.Left() += 8;
				pDC->MoveTo( rcCaption.TopLeft());
				pDC->LineTo( rcCaption.Right(), rcCaption.Top());
			}
			else
			{
				// Does the item have a bitmap assigned to it?
				if ( pData->m_iBitmap >= 0 && reinterpret_cast<ClsXPMenu *>( pData->m_pOwner )->m_hImageList )
				{
					// Adjust image position.
					rcImage.Offset( -1, 0 );

					// Determine image rendering flags. The disabled flag is only used
					// when the item is disabled and we do not have a disabled imagelist.
					DWORD dwFlags = 0;
					if ( pdis->itemState & ODS_SELECTED && ( ! ( pdis->itemState & ODS_DISABLED )) && ( ! ( pdis->itemState & ODS_CHECKED )))
						dwFlags |= ClsDrawTools::CDSF_HOT;
					if ( pdis->itemState & ODS_DISABLED && reinterpret_cast<ClsXPMenu *>( pData->m_pOwner )->m_hDisabledImageList == NULL )
						dwFlags |= ClsDrawTools::CDSF_DISABLED;

					// Determine the image list to use, normal or disabled.
					HIMAGELIST himl = ( pdis->itemState & ODS_DISABLED && reinterpret_cast<ClsXPMenu *>( pData->m_pOwner )->m_hDisabledImageList ) ? reinterpret_cast<ClsXPMenu *>( pData->m_pOwner )->m_hDisabledImageList : reinterpret_cast<ClsXPMenu *>( pData->m_pOwner )->m_hImageList;

					// Render image...
					ClsDrawTools::RenderXPBitmap( *pDC, himl, pData->m_iBitmap, rcImage, dwFlags | ClsDrawTools::CDSF_TRANSPARENT );

					// Restore image rectangle position.
					rcImage.Offset( 1, 0 );
				}
			}
		}
	}

	if ( pData )
	{
		// Any text?
		if ( pData->m_strItemName )
		{
			// Setup text color and draw mode.
			pDC->SetTextColor( pdis->itemState & ODS_INACTIVE ? ::GetSysColor( COLOR_GRAYTEXT ) : ( XPColors.GetXPColor( pdis->itemState & ODS_DISABLED ? ClsXPColors::XPC_TEXT_DISABLED : ClsXPColors::XPC_TEXT )));
			pDC->SetBkMode( TRANSPARENT );

			// Adjust the rectangle.
			if ( ! pData->m_bToplevel )
			{
				rcCaption.Left() += 8;
				rcCaption.Right() -= 6;
			}

			// Skip checkmark width.
			if ( ! pData->m_bToplevel )
				rcCaption.Right() -= ::GetSystemMetrics( SM_CXMENUCHECK );

			// Split caption in a left an right part.
			ClsString Left, Right;
			SplitCaption( pData->m_strItemName, Left, Right );

			// Render the parts.
			if ( Left.GetStringLength())  ClsDrawTools::RenderText( *pDC, Left,  rcCaption, ClsDrawTools::CDSF_LEFTALIGN | ( pdis->itemState & ODS_NOACCEL ? ClsDrawTools::CDSF_HIDEACCEL : 0 ));
			if ( Right.GetStringLength()) ClsDrawTools::RenderText( *pDC, Right, rcCaption, ClsDrawTools::CDSF_RIGHTALIGN );
		}
	}
}
Пример #16
0
// Draws an item label (icon, text) in all parts of the WinDirStat view
// the rest is drawn by DrawItem()
void COwnerDrawnListItem::DrawLabel(COwnerDrawnListControl *list, CImageList *il, CDC *pdc, CRect& rc, UINT state, int *width, int *focusLeft, bool indent) const
{
    CRect rcRest = rc;
    // Increase indentation according to tree-level
    if(indent)
    {
        rcRest.left += GENERAL_INDENT;
    }

    // Prepare to draw the file/folder icon
    ASSERT(GetImage() < il->GetImageCount());

    IMAGEINFO ii;
    il->GetImageInfo(GetImage(), &ii);
    CRect rcImage(ii.rcImage);

    if(width == NULL)
    {
        // Draw the color with transparent background
        CPoint pt(rcRest.left, rcRest.top + rcRest.Height() / 2 - rcImage.Height() / 2);
        il->SetBkColor(CLR_NONE);
        il->Draw(pdc, GetImage(), pt, ILD_NORMAL);
    }

    // Decrease size of the remainder rectangle from left
    rcRest.left += rcImage.Width();

    CSelectObject sofont(pdc, list->GetFont());

    rcRest.DeflateRect(list->GetTextXMargin(), 0);

    CRect rcLabel = rcRest;
    pdc->DrawText(GetText(0), rcLabel, DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_CALCRECT | DT_NOPREFIX);

    rcLabel.InflateRect(LABEL_INFLATE_CX, 0);
    rcLabel.top = rcRest.top + LABEL_Y_MARGIN;
    rcLabel.bottom = rcRest.bottom - LABEL_Y_MARGIN;

    CSetBkMode bk(pdc, TRANSPARENT);
    COLORREF textColor = ::GetSysColor(COLOR_WINDOWTEXT);
    if(width == NULL && (state & ODS_SELECTED) != 0 && (list->HasFocus() || list->IsShowSelectionAlways()))
    {
        // Color for the text in a highlighted item (usually white)
        textColor = list->GetHighlightTextColor();

        CRect selection = rcLabel;
        // Depending on "FullRowSelection" style
        if(list->IsFullRowSelection())
        {
            selection.right = rc.right;
        }
        // Fill the selection rectangle background (usually dark blue)
        pdc->FillSolidRect(selection, list->GetHighlightColor());
    }
    else
    {
        // Use the color designated for this item
        // This is currently only for encrypted and compressed items
        textColor = GetItemTextColor();
    }

    // Set text color for device context
    CSetTextColor stc(pdc, textColor);

    if(width == NULL)
    {
        // Draw the actual text
        pdc->DrawText(GetText(0), rcRest, DT_SINGLELINE | DT_VCENTER | DT_WORD_ELLIPSIS | DT_NOPREFIX);
    }

    rcLabel.InflateRect(1, 1);

    *focusLeft = rcLabel.left;

    if((state & ODS_FOCUS) != 0 && list->HasFocus() && width == NULL && !list->IsFullRowSelection())
    {
        pdc->DrawFocusRect(rcLabel);
    }

    if(width == NULL)
    {
        DrawAdditionalState(pdc, rcLabel);
    }

    rcLabel.left = rc.left;
    rc = rcLabel;

    if(width != NULL)
    {
        *width = rcLabel.Width() + 5; // Don't know, why +5
    }
}