コード例 #1
0
void CListViewCtrlEx::_DrawNormalItem( LPDRAWITEMSTRUCT lpdis, const TListItem *pItem )
{
    if (!pItem)
        return;

    int nItem = lpdis->itemID;

    CDCHandle dc;
    dc.Attach(lpdis->hDC);

    HFONT	hOldFont = dc.SelectFont(m_fontDef);

    BOOL bSelect = FALSE ;
    if ((lpdis->itemAction | ODA_SELECT) &&
            (lpdis->itemState & ODS_SELECTED))
    {
        bSelect = TRUE ;
    }

    if ( bSelect )
        dc.FillSolidRect( &lpdis->rcItem, RGB(185,219,255));
    else
        dc.FillSolidRect( &lpdis->rcItem, pItem->clrBg);

    // draw check box
    if( pItem->dwFlags&(LISTITEM_CHECKBOX|LISTITEM_RADIOBOX) )
        _DrawCheckBox(dc, lpdis->rcItem, _super::GetCheckState(nItem), pItem->dwFlags);

    COLORREF oldClr = dc.GetTextColor();
    for(int i=0; i<pItem->subItems.size(); ++i)
    {
        CRect	rcSubItem;
        DWORD	nMarginWidth = 0;
        CRect	rcBounds;
        GetSubItemRect(nItem, i, LVIR_LABEL, &rcSubItem);

        nMarginWidth = LEFT_MARGIN_TEXT_COLUMN+3;

        if(i==0)
        {
            if( pItem->dwFlags&(LISTITEM_CHECKBOX|LISTITEM_RADIOBOX) )
            {
                nMarginWidth+=rcSubItem.left;
            }
            else
            {
                rcSubItem.left -= 19;
                nMarginWidth+=5;
            }
        }

#define DT_FLAGS_DRAW_TEXT		(DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_END_ELLIPSIS|DT_VCENTER)

        rcSubItem.left += LEFT_MARGIN_TEXT_COLUMN;
        rcSubItem.right -= 3;
        const TListSubItem &subItem = pItem->subItems[i];
        if(subItem.type == SUBITEM_LINK)
        {
            dc.SelectFont(m_fontLink);
            dc.SetTextColor(COLOR_LIST_LINK);

            CRect	rcProbeItem;
            dc.DrawText( subItem.str, -1, &rcProbeItem, DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_VCENTER|DT_CALCRECT);
            dc.DrawText( subItem.str, -1, &rcSubItem, DT_FLAGS_DRAW_TEXT);

            DWORD nMaxWidth = rcProbeItem.Width()+nMarginWidth;
            _SetColumnNeedWidth(i,nMaxWidth);
        }
        else
        {
            if (subItem.type == SUBITEM_ICON && subItem.nImg != NULL)
            {
                dc.DrawIconEx( rcSubItem.left, rcSubItem.top + 3, (HICON)subItem.nImg, 16 , 16, 0, 0, DI_NORMAL );
                rcSubItem.left = rcSubItem.left + 18;
            }
            else if (subItem.type == SUBITEM_PNG)
            {
                Gdiplus::Image* pImg = BkPngPool::Get(subItem.nImg);
                if (pImg)
                {
                    Gdiplus::Graphics graphics(dc);

                    SIZE size = {0, 0};
                    if (pImg)
                    {
                        size.cx = pImg->GetWidth();
                        size.cy = pImg->GetHeight();
                    }

                    graphics.DrawImage(pImg, Gdiplus::Rect(rcSubItem.left, rcSubItem.top + 5, size.cx, size.cy));
                }
                rcSubItem.left = rcSubItem.left + 18;
            } else if(subItem.type==SUBITEM_COMBO)
            {
                CDC	dcTmp;
                dcTmp.CreateCompatibleDC(dc);
                HBITMAP hBmpOld	= dcTmp.SelectBitmap(m_bitmapCombo);
                dc.BitBlt(rcSubItem.right-20, rcSubItem.top + 3, 20, 20, dcTmp, 0, 0, SRCCOPY);
                dcTmp.SelectBitmap(hBmpOld);
                dcTmp.DeleteDC();
            }

            UINT uFormat = DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_PATH_ELLIPSIS|DT_VCENTER;
            if (i == 3)
            {
                if (pItem->nLevel == enumLevelRisk)
                {
                    rcSubItem.DeflateRect(2, 3);

                    CPen penBorder;
                    penBorder.CreatePen( PS_SOLID, 1, RGB(224, 0, 0) );
                    CBrush bshInterior;
                    bshInterior.CreateSolidBrush( RGB(224, 0, 0)  );

                    HPEN hOldPen = dc.SelectPen( penBorder );
                    HBRUSH hOldBrush = dc.SelectBrush( bshInterior );

                    dc.RoundRect( rcSubItem, CPoint( 3, 3 ) );
                    dc.SelectPen(hOldPen);
                    dc.SelectBrush(hOldBrush);
                    dc.SetTextColor( RGB(255, 255, 255) );
                }
                else if (pItem->nLevel == enumLevelUnknown)
                {
                    rcSubItem.DeflateRect(2, 3);

                    CPen penBorder;
                    penBorder.CreatePen( PS_SOLID, 1, RGB(250, 115, 5) );
                    CBrush bshInterior;
                    bshInterior.CreateSolidBrush( RGB(250, 115, 5)  );

                    HPEN hOldPen = dc.SelectPen( penBorder );
                    HBRUSH hOldBrush = dc.SelectBrush( bshInterior );

                    dc.RoundRect( rcSubItem, CPoint( 3, 3 ) );
                    dc.SelectPen(hOldPen);
                    dc.SelectBrush(hOldBrush);
                    dc.SetTextColor( RGB(255, 255, 255) );
                }
                else
                    dc.SetTextColor( subItem.clr );

                uFormat = DT_SINGLELINE|DT_CENTER|DT_NOPREFIX|DT_PATH_ELLIPSIS|DT_VCENTER;
            }
            else
                dc.SetTextColor( subItem.clr );

            dc.DrawText( subItem.str, -1, &rcSubItem, uFormat);
            if (subItem.type == SUBITEM_ICON || subItem.type == SUBITEM_PNG)
                rcSubItem.left = rcSubItem.left - 18;

            CRect	rcProbeItem;
            dc.DrawText( subItem.str, -1, &rcProbeItem, DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_VCENTER|DT_CALCRECT);
            DWORD nMaxWidth = rcProbeItem.Width()+nMarginWidth;
            _SetColumnNeedWidth(i,nMaxWidth);
        }
    }

    CPen	penx;
    penx.CreatePen(PS_SOLID,1,pItem->clrBtmGapLine);
    HPEN	penOld = dc.SelectPen(penx);
    dc.MoveTo( lpdis->rcItem.left, lpdis->rcItem.bottom-1 );
    CRect rcClient;
    GetClientRect(rcClient);

    dc.LineTo( lpdis->rcItem.left + rcClient.Width(), lpdis->rcItem.bottom-1);
    dc.SelectPen(penOld);

    dc.SelectFont(hOldFont);
    dc.SetTextColor(oldClr);
    dc.Detach();
}
コード例 #2
0
void CListViewCtrlEx::_DrawTitleItem( LPDRAWITEMSTRUCT lpdis, const TListItem *pItem )
{
    ATLASSERT(pItem);

    if(pItem->subItems.empty())
        return ;

    int	nWinWidth=lpdis->rcItem.right-lpdis->rcItem.left;
    CRect	rcWindows;
    GetWindowRect(rcWindows);
    if ( nWinWidth > rcWindows.Width())
        nWinWidth = rcWindows.Width()-20;

    int nItem = lpdis->itemID;

    CDCHandle dc;
    dc.Attach(lpdis->hDC);
    dc.FillSolidRect( &lpdis->rcItem, pItem->clrBg);
    HFONT	hOldFont = dc.SelectFont(m_fontDef);
    COLORREF clrOld = dc.GetTextColor();
    COLORREF clrDef = clrOld;

    //
    RECT rcItem = lpdis->rcItem;
    if( pItem->dwFlags&LISTITEM_EXPANDABLE )
    {
        //3 + 9 + 3
        if(rcItem.left>-12)
        {
            CDC	dcTmp;
            dcTmp.CreateCompatibleDC(dc);
            HBITMAP hBmpOld	= dcTmp.SelectBitmap(m_bitmapExpand);
            RECT rcMinus = _GetRectMinus(rcItem);
            dc.BitBlt( rcMinus.left, rcMinus.top, 9, 9, dcTmp, pItem->_isclapsed? 9:0, 0, SRCCOPY);
            dcTmp.SelectBitmap(hBmpOld);
        }
    }

    for ( int i = 0; i < pItem->subItems.size(); i++)
    {
        bool	bVCenter=TRUE;
        const TListSubItem& subItem = pItem->subItems[i];
        CRect rcItem = subItem.rcOffset;
        if ( i == 0 )
        {
            rcItem = lpdis->rcItem;

            if(pItem->nTopMargin>=0)
            {
                rcItem.top += pItem->nTopMargin;
                rcItem.bottom -= 0;
                bVCenter=FALSE;
            }
            else
            {
                rcItem.top += 2;
                rcItem.bottom -= 2;
            }
            rcItem.left+= pItem->nLeftmargin;
        }
        else
        {
            if ( rcItem.left < 0 )
            {
                rcItem.left = nWinWidth+rcItem.left;
            }
            if (rcItem.right < 0)
            {
                rcItem.right = nWinWidth+rcItem.right;
            }
            rcItem.OffsetRect( lpdis->rcItem.left, lpdis->rcItem.top);
        }

        if ( subItem.type == SUBITEM_TEXT )
        {
            dc.SetTextColor( subItem.clr);
            dc.SelectFont(m_fontDef);
        }
        else if ( subItem.type == SUBITEM_LINK )
        {
            dc.SelectFont(m_fontLink);
            dc.SetTextColor(COLOR_LIST_LINK);
        }
        else
        {
            dc.SetTextColor( subItem.clr);
            dc.SelectFont(m_fontDef);
        }

        CString strTitle = subItem.str;
        DWORD	nFlag=DT_SINGLELINE|DT_LEFT|DT_NOPREFIX|DT_END_ELLIPSIS;
        if(bVCenter)
            nFlag|=DT_VCENTER;

        if (i==0&&pItem->bBold||pItem->nHeightAdd!=0)
        {
            HFONT	fntOld=dc.SelectFont(BkFontPool::GetFont(pItem->bBold,FALSE,FALSE,pItem->nHeightAdd));
            dc.DrawText( strTitle, -1, &rcItem, nFlag);
            dc.SelectFont(fntOld);
        }
        else
            dc.DrawText( strTitle, -1, &rcItem, nFlag);
    }

    CPen	pex;
    pex.CreatePen(PS_SOLID,1,pItem->clrBtmGapLine);
    HPEN	penOld = dc.SelectPen(pex);
    dc.MoveTo( lpdis->rcItem.left, lpdis->rcItem.bottom-1 );
    dc.LineTo( lpdis->rcItem.right, lpdis->rcItem.bottom-1 );

    dc.SetTextColor(clrOld);
    dc.SelectPen(penOld);
    dc.SelectFont(hOldFont);
    dc.Detach();
}