Example #1
0
void 
CNBTreeListView::DrawTreeItem(LPNMTVCUSTOMDRAW lptvcd, UINT iState, const RECT& rcItem)
{
	CDCHandle dc = lptvcd->nmcd.hdc;
	HTREEITEM hItem = (HTREEITEM) lptvcd->nmcd.dwItemSpec;

	tMapItem* pVal = m_mapItems.Lookup(hItem);
	if( pVal == NULL ) return;

	// NOTE: Having an ImageList attached to the TreeView control seems
	//       to produce some extra WM_ERASEBKGND msgs, which we can use to
	//       optimize the painting...
	CImageList il = m_ctrlTree.GetImageList(TVSIL_NORMAL);

	// If the item had focus then draw it
	// NOTE: Only when images are used (see note above)
	// FIX-BY-PATRIA: DrawFocusRect should be done later
	//if( (iState & CDIS_FOCUS) != 0 && !il.IsNull() ) {
	//	RECT rcFocus = rcItem;
	//	rcFocus.left = 1;
	//	dc.SetTextColor(::GetSysColor(COLOR_BTNTEXT));
	//	dc.DrawFocusRect(&rcFocus);
	//}

	// If it's selected, paint the selection background
	if( iState & CDIS_SELECTED  && iState & CDIS_FOCUS) {
		RECT rcHigh = rcItem;
		dc.FillSolidRect(&rcHigh, ::GetSysColor(COLOR_HIGHLIGHT));
	}
	else if( il.IsNull() ) {
		RECT rcHigh = rcItem;
		dc.FillSolidRect(&rcHigh, lptvcd->clrTextBk);
	}

	// Always write text with background
	dc.SetBkMode(OPAQUE);
	dc.SetBkColor(::GetSysColor((iState & CDIS_SELECTED) != 0 ? COLOR_HIGHLIGHT : COLOR_WINDOW));

	// Draw all columns of the item
	RECT rc = rcItem;
	int cnt = pVal->GetSize();
	for( int i = 0; i < cnt; i++ ) {
		LPTLVITEM pItem = (*pVal)[i];
		ATLASSERT(pItem);

		if( i != 0 ) rc.left = m_rcColumns[i].left;
		rc.right = m_rcColumns[i].right;

		if( pItem->mask & TLVIF_IMAGE ) {
			ATLASSERT(!il.IsNull());
			int cx, cy;
			il.GetIconSize(cx, cy);
			il.DrawEx(
				pItem->iImage, 
				dc, 
				rc.left, rc.top, 
				MIN(cx, rc.right - rc.left), cy,
				CLR_NONE, CLR_NONE,
				ILD_TRANSPARENT);
			rc.left += cx;
		}

		if( pItem->mask & TLVIF_TEXT ) {

			rc.left += 2;

			COLORREF clrText = lptvcd->clrText;
			if( pItem->mask & TLVIF_TEXTCOLOR ) clrText = pItem->clrText;
			if( iState & CDIS_SELECTED ) clrText = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
			dc.SetTextColor(clrText);

			CFont font;
			HFONT hOldFont = NULL;
			if( pItem->mask & TLVIF_STATE ) {
				LOGFONT lf;
				::GetObject(m_ctrlTree.GetFont(), sizeof(LOGFONT), &lf);
				if( pItem->state & TLVIS_BOLD ) lf.lfWeight += FW_BOLD - FW_NORMAL;
				if( pItem->state & TLVIS_ITALIC ) lf.lfItalic = TRUE;
				if( pItem->state & TLVIS_UNDERLINE ) lf.lfUnderline = TRUE;
				if( pItem->state & TLVIS_STRIKEOUT ) lf.lfStrikeOut = TRUE;
				font.CreateFontIndirect(&lf);
				ATLASSERT(!font.IsNull());
				hOldFont = dc.SelectFont(font);
			}

			UINT format = pItem->mask & TLVIF_FORMAT ? pItem->format : 0;

			if (0 == i)
			{
				CNBDevice* pDevice = (CNBDevice*) m_ctrlTree.GetItemData(hItem);
				if (NULL != pDevice && pDevice->GetIDString(_T('*')).GetLength() > 0)
				{
					CString strBottom = pDevice->GetIDString(m_chHidden);

					CRect rcTop = rc; rcTop.DeflateRect(0, 0, 0, rcTop.Height() / 2);
					CRect rcBottom = rc; rcBottom.top = rcTop.bottom;
					
					dc.FillSolidRect(&rc, lptvcd->clrTextBk);

					LOGFONT lf;
					CFontHandle fontHandle = dc.GetCurrentFont();
					fontHandle.GetLogFont(&lf);
					lf.lfWeight = FW_BOLD;
					CFont font; 
					font.CreateFontIndirect(&lf);
					ATLASSERT(!font.IsNull());

					HFONT hOldFont = dc.SelectFont(font);
					dc.DrawText(pItem->pszText, -1, &rcTop, DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS | format);
					dc.SelectFont(hOldFont);

					COLORREF clrText = dc.GetTextColor();
					clrText = RGB(
						(GetRValue(clrText) + 0x40) & 0xFF, 
						(GetGValue(clrText) + 0x40) & 0xFF,
						(GetBValue(clrText) + 0x40) & 0xFF);
					clrText = dc.SetTextColor(clrText);
					dc.DrawText(strBottom, -1, &rcBottom, DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS | format);
					dc.SetTextColor(clrText);
				}
				else
				{
					dc.FillSolidRect(&rc, lptvcd->clrTextBk);

					LOGFONT lf;
					CFontHandle fontHandle = dc.GetCurrentFont();
					fontHandle.GetLogFont(&lf);
					lf.lfWeight = FW_BOLD;
					CFont font; 
					font.CreateFontIndirect(&lf);
					ATLASSERT(!font.IsNull());
					HFONT hOldFont = dc.SelectFont(font);
					dc.DrawText(pItem->pszText, 
						-1, 
						&rc, 
						DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS | format);
					dc.SelectFont(hOldFont);
				}
			}
			else
			{
				dc.DrawText(pItem->pszText, 
					-1, 
					&rc, 
					DT_VCENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS | format);
			}

			if( pItem->mask & TLVIF_STATE ) dc.SelectFont(hOldFont);
		}
	}
	// FIX-BY-PATRIA: DrawFocusRect should be done here
	if( (iState & CDIS_FOCUS) != 0 && !il.IsNull() ) {
		RECT rcFocus = rcItem;
		rcFocus.left = 1;
		dc.SetTextColor(::GetSysColor(COLOR_BTNTEXT));
		dc.DrawFocusRect(&rcFocus);
	}

}
void CButtonST::DrawItem(UINT ctrlID, LPDRAWITEMSTRUCT lpDIS)
{
	CDCHandle pDC = lpDIS->hDC;

	CPenHandle	pOldPen;

	// Checkbox or Radiobutton style ?
	if (m_bIsCheckBox)
		{
		m_bIsPressed  =  (lpDIS->itemState & ODS_SELECTED) || m_nCheck;
		}
	// Normal button OR other button style ...
	else
		{
		m_bIsPressed = (lpDIS->itemState & ODS_SELECTED);
		}

	m_bIsFocused  = (lpDIS->itemState & ODS_FOCUS) != 0;
	m_bIsDisabled = (lpDIS->itemState & ODS_DISABLED) != 0;
	
	CRect itemRect = lpDIS->rcItem;

	pDC.SetBkMode(TRANSPARENT);

	if (!m_bIsFlat)
		{
		if (m_bIsFocused || GetDefault())
			{
			CBrush br;
			br.CreateSolidBrush(RGB(0,0,0));  
			pDC.FrameRect(&itemRect, br);
			itemRect.DeflateRect(1, 1);
			}
		}

	// Prepare draw... paint button background

	// Draw transparent?
	if (m_bDrawTransparent)
		{
		PaintBk(pDC);
		}
	else
		{
		OnDrawBackground(pDC, &itemRect);
		}

	// Draw pressed button
	if (m_bIsPressed)
		{
		if (m_bIsFlat)
			{
			if (m_bDrawBorder)
				{
				OnDrawBorder(pDC, &itemRect);
				}
			}
		else    
			{
			CBrush brBtnShadow;
			brBtnShadow.CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
			pDC.FrameRect(&itemRect, brBtnShadow);
			}
		}
	else // ...else draw non pressed button
		{
		CPen penBtnHiLight; // White
		CPen pen3DLight;       // Light gray
		CPen penBtnShadow;   // Dark gray
		CPen pen3DDKShadow; // Black

		penBtnHiLight.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_BTNHILIGHT)); // White
		pen3DLight.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_3DLIGHT));       // Light gray
		penBtnShadow.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_BTNSHADOW));   // Dark gray
		pen3DDKShadow.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_3DDKSHADOW)); // Black

		if (m_bIsFlat)
			{
			if (m_bMouseOnButton && m_bDrawBorder)
				{
				pDC.Draw3dRect(itemRect, ::GetSysColor(COLOR_BTNHILIGHT), ::GetSysColor(COLOR_BTNSHADOW));
				}
			}
		else
			{
			// Draw top-left borders
			// White line
			pOldPen = pDC.SelectPen(penBtnHiLight);
			pDC.MoveTo(itemRect.left, itemRect.bottom-1);
			pDC.LineTo(itemRect.left, itemRect.top);
			pDC.LineTo(itemRect.right, itemRect.top);
			// Light gray line
			pDC.SelectPen(pen3DLight);
			pDC.MoveTo(itemRect.left+1, itemRect.bottom-1);
			pDC.LineTo(itemRect.left+1, itemRect.top+1);
			pDC.LineTo(itemRect.right, itemRect.top+1);
			// Draw bottom-right borders
			// Black line
			pDC.SelectPen(pen3DDKShadow);
			pDC.MoveTo(itemRect.left, itemRect.bottom-1);
			pDC.LineTo(itemRect.right-1, itemRect.bottom-1);
			pDC.LineTo(itemRect.right-1, itemRect.top-1);
			// Dark gray line
			pDC.SelectPen(penBtnShadow);
			pDC.MoveTo(itemRect.left+1, itemRect.bottom-2);
			pDC.LineTo(itemRect.right-2, itemRect.bottom-2);
			pDC.LineTo(itemRect.right-2, itemRect.top);
			//
			pDC.SelectPen(pOldPen);
			}
		}

	// Read the button's title
	CString sTitle;
	int nLen = GetWindowTextLength();
	int nRetLen = GetWindowText(sTitle.GetBufferSetLength(nLen), nLen + 1);

	CRect captionRect = lpDIS->rcItem;

	// Draw the icon
	if (m_csIcons[0].hIcon != 0)
		{
		DrawTheIcon(pDC, !sTitle.IsEmpty(), lpDIS->rcItem, captionRect, m_bIsPressed, m_bIsDisabled);
		}

	if (m_csBitmaps[0].hBitmap != 0)
		{
		pDC.SetBkColor(RGB(255,255,255));
		DrawTheBitmap(pDC, !sTitle.IsEmpty(), lpDIS->rcItem, captionRect, m_bIsPressed, m_bIsDisabled);
		}

	// Write the button title (if any)
	if (!sTitle.IsEmpty())
		{
		// Draw the button's title
		// If button is pressed then "press" title also
		if (m_bIsPressed && !m_bIsCheckBox)
			{
			captionRect.OffsetRect(1, 1);
			}
		// Center text
		CRect centerRect = captionRect;
		pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER | DT_CALCRECT);
		captionRect.OffsetRect((centerRect.Width() - captionRect.Width())/2, (centerRect.Height() - captionRect.Height())/2);
		pDC.SetBkMode(TRANSPARENT);
		if (m_bIsDisabled)
			{
			captionRect.OffsetRect(1, 1);
			pDC.SetTextColor(::GetSysColor(COLOR_3DHILIGHT));
			pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
			captionRect.OffsetRect(-1, -1);
			pDC.SetTextColor(::GetSysColor(COLOR_3DSHADOW));
			pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
			}
		else
			{
			if (m_bMouseOnButton || m_bIsPressed) 
				{
				pDC.SetTextColor(m_crColors[BTNST_COLOR_FG_IN]);
				pDC.SetBkColor(m_crColors[BTNST_COLOR_BK_IN]);
				} 
			else 
				{
				pDC.SetTextColor(m_crColors[BTNST_COLOR_FG_OUT]);
				pDC.SetBkColor(m_crColors[BTNST_COLOR_BK_OUT]);
				}
			pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
			}
		}
	if (!m_bIsFlat || (m_bIsFlat && m_bDrawFlatFocus))
		{
		// Draw the focus rect
		if (m_bIsFocused)
			{
			CRect focusRect = itemRect;
			focusRect.DeflateRect(3, 3);
			pDC.DrawFocusRect(&focusRect);
			}
		}
}
Example #3
0
LRESULT CLayerOptionsDlg::OnDrawItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	UINT idCtl = (UINT) wParam;             // control identifier 
	LPDRAWITEMSTRUCT lpDrawItemStruct = (LPDRAWITEMSTRUCT) lParam; // item-drawing information 

	CDCHandle pDC = lpDrawItemStruct->hDC;
	CRect rc = lpDrawItemStruct->rcItem;

	if (idCtl == IDC_LAYER_COLOR)
	{
		pDC.DrawEdge(&rc, (lpDrawItemStruct->itemState & ODS_SELECTED)? EDGE_SUNKEN : EDGE_RAISED, BF_RECT | BF_ADJUST);

		rc.InflateRect(-1,-1);
		pDC.FillSolidRect(&rc, m_color);
	}
	else
	{
		int w = 12;
		int h = 12;

		int id = lpDrawItemStruct->itemID;

		if (id >= 0)
		{
			COLORREF	ref;

			if (lpDrawItemStruct->itemState & ODS_SELECTED)
				ref = ::GetSysColor(COLOR_HIGHLIGHT);
			else
				ref = ::GetSysColor(COLOR_WINDOW);

		//	pDC->FillSolidRect(rc.left+1, rc.top+1, rc.Width()-1, rc.Height()-1, ref);
			pDC.FillSolidRect(&rc, ref);

			if (lpDrawItemStruct->itemState & ODS_FOCUS)
				pDC.DrawFocusRect(&rc);

			if (id < gNumLayerColors)
			{
				HBRUSH hOldBrush = pDC.SelectBrush((HBRUSH)GetStockObject(NULL_BRUSH));
				pDC.Rectangle(rc.left+1, rc.top+1, rc.left+w+3, rc.top+h+3);
				pDC.SelectBrush(hOldBrush);

				CBrush brush;
				brush.CreateSolidBrush(gLayerColors[id].color);

				CRect	r(rc.left+2, rc.top+2, rc.left+2+w, rc.top+2+h);
				pDC.FillRect(&r, brush);
			}

			if (lpDrawItemStruct->itemState & ODS_SELECTED)
			{
				pDC.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
				pDC.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
			}
			else
			{
				pDC.SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
				pDC.SetBkColor(::GetSysColor(COLOR_WINDOW));
			}

			pDC.TextOut(rc.left+((id < gNumLayerColors)? (w+6): 4), rc.top+2, (LPCTSTR)lpDrawItemStruct->itemData);
		}
	}
	
	return 0;
}
Example #4
0
BOOL CDxDatePickerDay::DrawDay(CDCHandle dc)
{
    // check this day item
    BOOL bThisMonthItem = FALSE;
    BOOL bNextMonthItem = FALSE;
    BOOL bPreviousMonthItem = FALSE;

    CDxMonthPicker* pControl = GetDatePicker();
    CDxDatePickerMonth* pMonth = GetMonth();

    COleDateTime dtDay = GetDate();
    CRect rcDay = GetRect();

    if (dtDay.GetYear() > pMonth->GetMonth().GetYear())
    {
        bNextMonthItem = TRUE;
    }
    else if (dtDay.GetYear() < pMonth->GetMonth().GetYear())
    {
        bPreviousMonthItem = TRUE;
    }
    else
    {
        // years the same
        if (dtDay.GetMonth() > pMonth->GetMonth().GetMonth())
            bNextMonthItem = TRUE;
        else if (dtDay.GetMonth() < pMonth->GetMonth().GetMonth())
            bPreviousMonthItem = TRUE;
        else // months the same
            bThisMonthItem = TRUE;
    }

    if (bPreviousMonthItem && !pMonth->GetShowDaysBefore())
        return FALSE;

    if (bNextMonthItem && !pMonth->GetShowDaysAfter())
        return FALSE;


    // apply settings to the DC
    dc.SetBkMode(TRANSPARENT);
    dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
    dc.FillSolidRect(rcDay, GetSysColor(COLOR_WINDOW));

    // change default drawing metrics if day is selected
    if (pControl->IsSelected(dtDay))
    {
        dc.SetTextColor(GetSysColor(COLOR_WINDOW));
        dc.FillSolidRect(rcDay, GetSysColor(COLOR_WINDOWTEXT));
    }

    // make a text for drawing
    CString strText;
    strText.Format(_T("%i"), dtDay.GetDay());

    // draw item content
    {
        // draw item text
        HFONT hFontOld = (HFONT)dc.SelectFont(CDxFontManager::GetSingleton().GetFont(DUIF_DEFAULTFONT));
        dc.DrawText(strText, strText.GetLength(), &rcDay, DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_NOCLIP);
    }

    CRect rcFocus = rcDay;
    BOOL bToday = FALSE;

    // highlight today item
    if (IsToday(dtDay))
    {
        dc.Draw3dRect(rcDay, GetSysColor(COLOR_HIGHLIGHT), GetSysColor(COLOR_HIGHLIGHT));
        bToday = TRUE;
    }

    if (pControl->IsSelected(dtDay))
    {
        if (!bToday)
        {
            dc.SetTextColor(0);
            dc.SetBkColor(RGB(255, 255, 255));
            dc.DrawFocusRect(&rcFocus);
        }
        else
        {
            COLORREF clrFocus = GetSysColor(COLOR_HIGHLIGHT);
            clrFocus = clrFocus ^ RGB(255, 128, 128);

            rcFocus.DeflateRect(0, 0, 1, 1);

            CPen pen1;
            pen1.CreatePen(PS_DOT, 1, clrFocus);

            HPEN hOldPen = dc.SelectPen(pen1);

            dc.MoveTo(rcFocus.TopLeft());
            dc.LineTo(rcFocus.right, rcFocus.top);
            dc.LineTo(rcFocus.right, rcFocus.bottom);
            dc.LineTo(rcFocus.left, rcFocus.bottom);
            dc.LineTo(rcFocus.left, rcFocus.top);

            dc.SelectPen(hOldPen);
        }
    }

    return TRUE;
}