Exemple #1
0
void CColorButtonCtrl::DrawBevelInset(CDC* pDC, CRect& rc)
{
    CPen penLight(PS_SOLID, 1, ::GetSysColor(COLOR_3DHILIGHT));
    CPen penShadow(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));

    DrawBevel(pDC, rc, penShadow, penLight);
}
Exemple #2
0
/*******************************************************************************
  Function Name  : DrawItem
  Input(s)       : LPDRAWITEMSTRUCT
  Output         : -
  Functionality  : overrided for drawing the Arrow direction for sort in
                   Column header field.
  Member of      : CListHdrCtrl
  Author(s)      : Arunkumar K
  Date Created   : 20-05-2010
  Modifications  :
*******************************************************************************/
void CRxMsgList::CListHdrCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    //Attach the column header HDC.
    CDC dc;
    dc.Attach(lpDrawItemStruct->hDC);
    // save device context.
    const int nSavedDCState = dc.SaveDC();
    // get the column rect.
    CRect rc(lpDrawItemStruct->rcItem);
    // set the clipping region to limit drawing within the column.
    CRgn rgn;
    rgn.CreateRectRgnIndirect(&rc);
    dc.SelectObject(&rgn);
    rgn.DeleteObject();
    // draw the background,
    CBrush brush(GetSysColor(COLOR_3DFACE));
    dc.FillRect(rc, &brush);
    // get the column text and format.
    char szText[ 256 ];
    HD_ITEM hditem;
    hditem.mask = HDI_TEXT | HDI_FORMAT;
    hditem.pszText = szText;
    hditem.cchTextMax = 255;
    GetItem(lpDrawItemStruct->itemID, &hditem);
    // determine the format for drawing the column label.
    UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS ;

    if(hditem.fmt & HDF_CENTER)
    {
        uFormat |= DT_CENTER;
    }
    else if(hditem.fmt & HDF_RIGHT)
    {
        uFormat |= DT_RIGHT;
    }
    else
    {
        uFormat |= DT_LEFT;
    }

    // adjust the rect if the mouse button is pressed on it.
    if(lpDrawItemStruct->itemState == ODS_SELECTED)
    {
        rc.left++;
        rc.top += 2;
        rc.right++;
    }

    CRect rcIcon(lpDrawItemStruct->rcItem);
    const int nOffset = (rcIcon.bottom - rcIcon.top) / 4;

    // adjust the rect further if the sort arrow is to be displayed.
    if(lpDrawItemStruct->itemID == (UINT)m_nSortCol)
    {
        rc.right -= 3 * nOffset;
    }

    rc.left += nOffset;
    rc.right -= nOffset;

    // draw the column label.
    if(rc.left < rc.right)
    {
        dc.DrawText(szText, -1, rc, uFormat);
    }

    // draw the sort arrow.
    if(lpDrawItemStruct->itemID == (UINT)m_nSortCol)
    {
        // set up the pens to use for drawing the arrow.
        CPen penLight(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
        CPen penShadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
        CPen* pOldPen = dc.SelectObject(&penLight);
        CDC dcMem;
        BITMAP bm;
        CBitmap bmpArrowDir;
        COLORMAP cm = {RGB(0, 0, 0), GetSysColor(COLOR_BTNTEXT)};
        dcMem.CreateCompatibleDC(&dc);

        if(m_bIsAscendingSort)
        {
            bmpArrowDir.LoadMappedBitmap(IDB_HDRUP, 0, &cm, 1);
            bmpArrowDir.GetBitmap(&bm);
            dcMem.SelectObject(&bmpArrowDir);
            dc.SetStretchBltMode(HALFTONE);
            dc.SetBkMode(TRANSPARENT);
            dc.StretchBlt(rcIcon.right-15, rcIcon.top+5, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCAND);
        }
        else
        {
            bmpArrowDir.LoadMappedBitmap(IDB_HDRDOWN, 0, &cm, 1);
            bmpArrowDir.GetBitmap(&bm);
            dcMem.SelectObject(&bmpArrowDir);
            dc.SetStretchBltMode(HALFTONE);
            dc.SetBkMode(TRANSPARENT);
            dc.StretchBlt(rcIcon.right-15, rcIcon.top+5, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCAND);
        }

        bmpArrowDir.DeleteObject();
        // restore the pen.
        dc.SelectObject(pOldPen);
    }

    // restore the stored device context state.
    dc.RestoreDC(nSavedDCState);
    // detach the HDC before exit.
    dc.Detach();
}
void CMyHeaderCtrl::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	CDC dc;
	VERIFY( dc.Attach( lpDrawItemStruct->hDC ) );
	const int iSavedDC = dc.SaveDC();
	CRect rc( lpDrawItemStruct->rcItem );
	CRgn rgn;
	VERIFY( rgn.CreateRectRgnIndirect( &rc ) );
	(void)dc.SelectObject( &rgn );
	VERIFY( rgn.DeleteObject() );
	CBrush brush( GetSysColor( COLOR_3DFACE ) );
	dc.SetBkMode(TRANSPARENT);
		int r1=GetRValue(m_clrBack);
		int g1=GetGValue(m_clrBack);
		int b1=GetBValue(m_clrBack);
		for(int i=rc.Height()/2;i>0;i--)
		{
			r1=(r1+5)>255?255:(r1+5);
			g1=(g1+5)>255?255:(g1+5);
			b1=(b1+5)>255?255:(b1+5);
			CPen pen(PS_SOLID, 1, RGB(r1, g1, b1));
			CPen *old = dc.SelectObject(&pen);
			dc.MoveTo(rc.left,rc.top+i);
			dc.LineTo(rc.right,rc.top+i);
			dc.MoveTo(rc.left,rc.bottom-i);
			dc.LineTo(rc.right,rc.bottom-i);
			dc.SelectObject(old);
		}	
	TCHAR szText[ 256 ];
	HD_ITEM hditem;
	hditem.mask = HDI_TEXT | HDI_FORMAT;
	hditem.pszText = szText;
	hditem.cchTextMax = 255;
	VERIFY( GetItem( lpDrawItemStruct->itemID, &hditem ) );
	UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS ;
	if( hditem.fmt & HDF_CENTER)
		uFormat |= DT_CENTER;
	else if( hditem.fmt & HDF_RIGHT)
		uFormat |= DT_RIGHT;
	else
		uFormat |= DT_LEFT;
	if( lpDrawItemStruct->itemState == ODS_SELECTED )
	{
		rc.left++;
		rc.top += 2;
		rc.right++;
	}
	CRect rcIcon( lpDrawItemStruct->rcItem );
	const int iOffset = ( rcIcon.bottom - rcIcon.top ) / 4;
	if( lpDrawItemStruct->itemID == (UINT)m_iSortColumn )
		rc.right -= 3 * iOffset;

	rc.left += iOffset;
	rc.right -= iOffset;
	if( rc.left < rc.right )
		(void)dc.DrawText( szText, -1, rc, uFormat );
	if( lpDrawItemStruct->itemID == (UINT)m_iSortColumn )
	{
		CPen penLight( PS_SOLID, 1,m_clrLeft);
		CPen penShadow( PS_SOLID, 1,m_clrRight);
		CPen* pOldPen = dc.SelectObject( &penLight );
		if( m_bSortAscending )
		{
			dc.MoveTo( rcIcon.right - 2 * iOffset, iOffset);
			dc.LineTo( rcIcon.right - iOffset, rcIcon.bottom - iOffset - 1 );
			dc.LineTo( rcIcon.right - 3 * iOffset - 2, rcIcon.bottom - iOffset - 1 );
			(void)dc.SelectObject( &penShadow );
			dc.MoveTo( rcIcon.right - 3 * iOffset - 1, rcIcon.bottom - iOffset - 1 );
			dc.LineTo( rcIcon.right - 2 * iOffset, iOffset - 1);		
		}
		else
		{
			dc.MoveTo( rcIcon.right - iOffset - 1, iOffset );
			dc.LineTo( rcIcon.right - 2 * iOffset - 1, rcIcon.bottom - iOffset );
			(void)dc.SelectObject( &penShadow );
			dc.MoveTo( rcIcon.right - 2 * iOffset - 2, rcIcon.bottom - iOffset );
			dc.LineTo( rcIcon.right - 3 * iOffset - 1, iOffset );
			dc.LineTo( rcIcon.right - iOffset - 1, iOffset );		
		}
		(void)dc.SelectObject( pOldPen );
	}
	VERIFY( dc.RestoreDC( iSavedDC ) );
	(void)dc.Detach();
}
void CSortHeaderCtrl::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	// attath to the device context.
	CDC dc;
	VERIFY( dc.Attach( lpDrawItemStruct->hDC ) );

	// save the device context.
	const int iSavedDC = dc.SaveDC();

	// get the column rect.
	CRect rc( lpDrawItemStruct->rcItem );

	// set the clipping region to limit drawing within the column.
	CRgn rgn;
	VERIFY( rgn.CreateRectRgnIndirect( &rc ) );
	(void)dc.SelectObject( &rgn );
	VERIFY( rgn.DeleteObject() );

	// draw the background,
	CBrush brush( GetSysColor( COLOR_3DFACE ) );
	dc.FillRect( rc, &brush );

	// get the column text and format.
	TCHAR szText[ 256 ];
	HD_ITEM hditem;

	hditem.mask = HDI_TEXT | HDI_FORMAT;
	hditem.pszText = szText;
	hditem.cchTextMax = 255;

	VERIFY( GetItem( lpDrawItemStruct->itemID, &hditem ) );

	// determine the format for drawing the column label.
	UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS ;

	if( hditem.fmt & HDF_CENTER)
		uFormat |= DT_CENTER;
	else if( hditem.fmt & HDF_RIGHT)
		uFormat |= DT_RIGHT;
	else
		uFormat |= DT_LEFT;

	// adjust the rect if the mouse button is pressed on it.
	if( lpDrawItemStruct->itemState == ODS_SELECTED )
	{
		rc.left++;
		rc.top += 2;
		rc.right++;
	}

	CRect rcIcon( lpDrawItemStruct->rcItem );
	const int iOffset = ( rcIcon.bottom - rcIcon.top ) / 4;

	// adjust the rect further if the sort arrow is to be displayed.
	if( lpDrawItemStruct->itemID == (UINT)m_iSortColumn )
		rc.right -= 3 * iOffset;

	rc.left += iOffset;
	rc.right -= iOffset;

	// draw the column label.
	if( rc.left < rc.right )
		(void)dc.DrawText( szText, -1, rc, uFormat );

	// draw the sort arrow.
	if( lpDrawItemStruct->itemID == (UINT)m_iSortColumn )
	{
		// set up the pens to use for drawing the arrow.
		CPen penLight( PS_SOLID, 1, GetSysColor( COLOR_3DHILIGHT ) );
		CPen penShadow( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ) );
		CPen* pOldPen = dc.SelectObject( &penLight );

		if( m_bSortAscending )
		{
			// draw the arrow pointing upwards.
			dc.MoveTo( rcIcon.right - 2 * iOffset, iOffset);
			dc.LineTo( rcIcon.right - iOffset, rcIcon.bottom - iOffset - 1 );
			dc.LineTo( rcIcon.right - 3 * iOffset - 2, rcIcon.bottom - iOffset - 1 );
			(void)dc.SelectObject( &penShadow );
			dc.MoveTo( rcIcon.right - 3 * iOffset - 1, rcIcon.bottom - iOffset - 1 );
			dc.LineTo( rcIcon.right - 2 * iOffset, iOffset - 1);		
		}
		else
		{
			// draw the arrow pointing downwards.
			dc.MoveTo( rcIcon.right - iOffset - 1, iOffset );
			dc.LineTo( rcIcon.right - 2 * iOffset - 1, rcIcon.bottom - iOffset );
			(void)dc.SelectObject( &penShadow );
			dc.MoveTo( rcIcon.right - 2 * iOffset - 2, rcIcon.bottom - iOffset );
			dc.LineTo( rcIcon.right - 3 * iOffset - 1, iOffset );
			dc.LineTo( rcIcon.right - iOffset - 1, iOffset );		
		}

		// restore the pen.
		(void)dc.SelectObject( pOldPen );
	}

	// restore the previous device context.
	VERIFY( dc.RestoreDC( iSavedDC ) );

	// detach the device context before returning.
	(void)dc.Detach();
}
void COXGridHeader::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	if (m_UxTheme.IsUxThemeLoaded())
	{
		HTHEME hTheme = m_UxTheme.GetWindowTheme(m_hWnd);
		if (hTheme != NULL)
		{

			// Draw the item background
			int iState = HIS_NORMAL;
			if (lpDrawItemStruct->itemState == ODS_SELECTED)
				iState = HIS_PRESSED;
			else
			{
				POINT ptCursor;
				::GetCursorPos(&ptCursor);
				ScreenToClient(&ptCursor);
				CRect rectItem(lpDrawItemStruct->rcItem);
				if (rectItem.PtInRect(ptCursor))
					iState = HIS_HOT;
			}
			m_UxTheme.DrawThemeBackground(hTheme,
				lpDrawItemStruct->hDC,
				HP_HEADERITEM,
				iState,
				&lpDrawItemStruct->rcItem,
				NULL);

			BOOL bDrawArrow;
			if (m_nSortOrder!=0 && lpDrawItemStruct->itemID == (UINT)m_nSortCol)
				bDrawArrow = TRUE;
			else
				bDrawArrow = FALSE;


			// Get the column text and format	
			TCHAR buf[256];	
			HD_ITEM hditem;	
			hditem.mask = HDI_TEXT | HDI_FORMAT;	
			hditem.pszText = buf;
			hditem.cchTextMax = 255;	
			GetItem( lpDrawItemStruct->itemID, &hditem );

			RECT rectText = lpDrawItemStruct->rcItem;
			rectText.left += 9;
			rectText.right -= 9;

			// Determine format for drawing column label
			UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | 
				DT_VCENTER | DT_END_ELLIPSIS ;
			UINT uArrowFormat = DT_SINGLELINE | DT_VCENTER;
			if( hditem.fmt & HDF_CENTER)
			{
				uFormat |= DT_CENTER;
				uArrowFormat |= DT_RIGHT;
				if (bDrawArrow)
					rectText.right -= 12;
			}
			else if( hditem.fmt & HDF_RIGHT)
			{
				uFormat |= DT_RIGHT;
				uArrowFormat |= DT_LEFT;
				if (bDrawArrow)
					rectText.left += 12;
			}
			else
			{
				uFormat |= DT_LEFT;
				uArrowFormat |= DT_RIGHT;
				if (bDrawArrow)
					rectText.right -= 12;
			}

			m_UxTheme.DrawThemeText(hTheme,
				lpDrawItemStruct->hDC,
				HP_HEADERITEM,
				HIS_NORMAL,
				buf,
				-1,
				uFormat,
				0,
				&rectText);

			// Draw the Sort arrow	
			if (bDrawArrow)	
			{
				CDC dc;
				dc.Attach(lpDrawItemStruct->hDC);
				int nSavedDC = dc.SaveDC();
				CFont fontMarlett;
				fontMarlett.CreatePointFont(120, _T("Marlett"));
				dc.SelectObject(&fontMarlett);
				dc.SetBkMode(TRANSPARENT);
				dc.SetTextColor(RGB(128, 128, 128));

				CRect rectArrow = lpDrawItemStruct->rcItem;
				rectArrow.DeflateRect(5, 0, 5, 0);

				if (m_nSortOrder == 1)
					dc.DrawText(_T("5"), -1, &rectArrow, uArrowFormat);
				else
					dc.DrawText(_T("6"), -1, &rectArrow, uArrowFormat);

				// Restore dc	
				dc.RestoreDC(nSavedDC);
				// Detach the dc before returning	
				dc.Detach();
			}
			return;
		}
	}

	CDC dc;
	dc.Attach( lpDrawItemStruct->hDC );	
	// Get the column rect
	CRect rcLabel( lpDrawItemStruct->rcItem );	
	// Save DC
	int nSavedDC = dc.SaveDC();
	// Set clipping region to limit drawing within column	
	CRgn rgn;
	rgn.CreateRectRgnIndirect( &rcLabel );	
	dc.SelectObject( &rgn );
	rgn.DeleteObject(); 
	// Draw the background
	CBrush brush(::GetSysColor(COLOR_3DFACE));
	dc.FillRect(rcLabel,&brush);	
	// Labels are offset by a certain amount  
	// This offset is related to the width of a space character
	int offset = dc.GetTextExtent(_T(" "), 1 ).cx*2;
	// Get the column text and format	
	TCHAR buf[256];	
	HD_ITEM hditem;	
	hditem.mask = HDI_TEXT | HDI_FORMAT;	
	hditem.pszText = buf;
	hditem.cchTextMax = 255;	
	GetItem( lpDrawItemStruct->itemID, &hditem );
	// Determine format for drawing column label
	UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | 
		DT_VCENTER | DT_END_ELLIPSIS ;	
	if( hditem.fmt & HDF_CENTER)
		uFormat |= DT_CENTER;	
	else if( hditem.fmt & HDF_RIGHT)
		uFormat |= DT_RIGHT;
	else
		uFormat |= DT_LEFT;
	// Adjust the rect if the mouse button is pressed on it
	if( lpDrawItemStruct->itemState == ODS_SELECTED )	
	{		
		rcLabel.left++;
		rcLabel.top += 2;		
		rcLabel.right++;	
	}
	// Adjust the rect further if Sort arrow is to be displayed
	if( lpDrawItemStruct->itemID == (UINT)m_nSortCol )	
	{
		rcLabel.right -= 3 * offset;	
	}
	rcLabel.left += offset;
	rcLabel.right -= offset;	
	// Draw column label
	if( rcLabel.left < rcLabel.right )
		dc.DrawText(buf,-1,rcLabel, uFormat);
	// Draw the Sort arrow	
	if( m_nSortOrder!=0 && lpDrawItemStruct->itemID == (UINT)m_nSortCol )	
	{
		CRect rcIcon( lpDrawItemStruct->rcItem );
		// Set up pens to use for drawing the triangle
		CPen penLight(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
		CPen penShadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
		CPen *pOldPen = dc.SelectObject( &penLight );		
		if( m_nSortOrder==1 )		
		{
			// Draw triangle pointing upwards
			dc.MoveTo( rcIcon.right - 2*offset, offset-1);
			dc.LineTo( rcIcon.right - 3*offset/2, rcIcon.bottom - offset );
			dc.LineTo( rcIcon.right - 5*offset/2-2, rcIcon.bottom - offset );
			dc.MoveTo( rcIcon.right - 5*offset/2-1, rcIcon.bottom - offset-1 );
			dc.SelectObject( &penShadow );
			dc.LineTo( rcIcon.right - 2*offset, offset-2);		
		}
		else		
		{
			// Draw triangle pointing downwords
			dc.MoveTo( rcIcon.right - 3*offset/2, offset-1);
			dc.LineTo( rcIcon.right - 2*offset-1, rcIcon.bottom - offset + 1 );
			dc.MoveTo( rcIcon.right - 2*offset-1, rcIcon.bottom - offset );
			dc.SelectObject( &penShadow );
			dc.LineTo( rcIcon.right - 5*offset/2-1, offset -1 );
			dc.LineTo( rcIcon.right - 3*offset/2, offset -1);		
		}
		// Restore the pen
		dc.SelectObject( pOldPen );	
	}	
	// Restore dc	
	dc.RestoreDC( nSavedDC );
	// Detach the dc before returning	
	dc.Detach();
}
void CHeaderCtrlEx::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	CDC dc;

	dc.Attach( lpDrawItemStruct->hDC );

	// Get the column rect
	CRect rcLabel( lpDrawItemStruct->rcItem );

	// Save DC
	int nSavedDC = dc.SaveDC();

	// Set clipping region to limit drawing within column
	CRgn rgn;
	rgn.CreateRectRgnIndirect( &rcLabel );
	dc.SelectObject( &rgn );
	rgn.DeleteObject();

		// Draw the background
		dc.FillRect(rcLabel, &CBrush(::GetSysColor(COLOR_3DFACE)));
	
	// Labels are offset by a certain amount  
	// This offset is related to the width of a space character
	int offset = dc.GetTextExtent(L" ", 1 ).cx*2;


	// Get the column text and format
	wchar_t buf[256];
	HD_ITEM hditem;
	
	hditem.mask = HDI_TEXT | HDI_FORMAT;
	hditem.pszText = buf;
	hditem.cchTextMax = 255;

	GetItem( lpDrawItemStruct->itemID, &hditem );

	// Determine format for drawing column label
	UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP 
						| DT_VCENTER | DT_END_ELLIPSIS ;

	if( hditem.fmt & HDF_CENTER)
		uFormat |= DT_CENTER;
	else if( hditem.fmt & HDF_RIGHT)
		uFormat |= DT_RIGHT;
	else
		uFormat |= DT_LEFT;

	// Adjust the rect if the mouse button is pressed on it
	if( lpDrawItemStruct->itemState == ODS_SELECTED )
	{
		rcLabel.left++;
		rcLabel.top += 2;
		rcLabel.right++;
	}

	// Adjust the rect further if Sort arrow is to be displayed
	if( lpDrawItemStruct->itemID == (UINT)m_nSortCol )
	{
		rcLabel.right -= 3 * offset;
	}

	rcLabel.left += offset;
	rcLabel.right -= offset;

	// Draw column label
    if( rcLabel.left <rcLabel.right ) dc.DrawText(buf,-1,rcLabel, uFormat); // Draw the Sort arrow if( lpDrawItemStruct->itemID == (UINT)m_nSortCol )
	{
		CRect rcIcon( lpDrawItemStruct->rcItem );

		// Set up pens to use for drawing the triangle
		CPen penLight(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
		CPen penShadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
		CPen *pOldPen = dc.SelectObject( &penLight );

		if( m_bSortAsc )
		{
			// Draw triangle pointing upwards
			dc.MoveTo( rcIcon.right - 2*offset, offset-1);
			dc.LineTo( rcIcon.right - 3*offset/2, rcIcon.bottom - offset );
			dc.LineTo( rcIcon.right - 5*offset/2-2, rcIcon.bottom - offset );
			dc.MoveTo( rcIcon.right - 5*offset/2-1, rcIcon.bottom - offset-1 );

			dc.SelectObject( &penShadow );
			dc.LineTo( rcIcon.right - 2*offset, offset-2);
		}
		else
		{
			// Draw triangle pointing downwords
			dc.MoveTo( rcIcon.right - 3*offset/2, offset-1);
			dc.LineTo( rcIcon.right - 2*offset-1, rcIcon.bottom - offset + 1 );
			dc.MoveTo( rcIcon.right - 2*offset-1, rcIcon.bottom - offset );

			dc.SelectObject( &penShadow );
			dc.LineTo( rcIcon.right - 5*offset/2-1, offset -1 );
			dc.LineTo( rcIcon.right - 3*offset/2, offset -1);
		}

		// Restore the pen
		dc.SelectObject( pOldPen );
	}

	// Restore dc
	dc.RestoreDC( nSavedDC );

	// Detach the dc before returning
	dc.Detach();
}
Exemple #7
0
void CDockingBar::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	COLORREF rgb_background= ::GetSysColor(COLOR_APPWORKSPACE);

	CMemoryDC mem_dc(dc, this, rgb_background);
	mem_dc.SelectStockObject(DEFAULT_GUI_FONT);

	CRect rect;
	GetClientRect(rect);

	mem_dc.Draw3dRect(rect, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DHILIGHT));
	rect.DeflateRect(1, 1);
	mem_dc.Draw3dRect(rect, ::GetSysColor(COLOR_3DDKSHADOW), rgb_background);
	rect.DeflateRect(1, 0);
	rect.top++;

	const int GAP= rect.Height() / 2;
	const int ICON= 18;
	COLORREF rgb_black= ::GetSysColor(COLOR_BTNTEXT);
	COLORREF rgb_dark= ::GetSysColor(COLOR_3DDKSHADOW);
	COLORREF rgb_light= ::GetSysColor(COLOR_3DHILIGHT);
	COLORREF rgb_gray= GetLighterColor(rgb_background, 13.0); // 13.0% brighter

	CPen penBlack(PS_SOLID, 0, rgb_black);
	CPen penDark(PS_SOLID, 0, rgb_dark);
	CPen penLight(PS_SOLID, 0, rgb_light);
	CPen penGray(PS_SOLID, 0, rgb_gray);
	CBrush brGray(::GetSysColor(COLOR_3DFACE));
	CBrush* brush= mem_dc.SelectObject(&brGray);
	mem_dc.SetBkMode(OPAQUE);

	CalcWidth(tabs_, mem_dc, rect);

	for (int index= 0; index < tabs_.size(); ++index)
	{
		CTab& tab= tabs_[index];
		CRect text_rect= tab.location_rect_;
		text_rect.left += ICON;

		COLORREF rgb_tab= tab.active_ ? ::GetSysColor(COLOR_3DFACE) : rgb_background;

		if (tab.active_)		// active tab--taller, gray backgnd
		{
			CRect rect= tab.location_rect_;
			rect.top++;
			rect.right++;
			rect.bottom = rect.top + 1;
			// draw two lines on the top
			mem_dc.FillSolidRect(rect, rgb_dark);
			rect.OffsetRect(0, 1);
			mem_dc.FillSolidRect(rect, rgb_light);
			rect.top++;
			rect.bottom = tab.location_rect_.bottom + 1;
			mem_dc.FillSolidRect(rect, rgb_tab);

			text_rect.top = rect.top;

			rect.top--;
			int bottom= tab.location_rect_.bottom - 1;
			int gap= (bottom - rect.top) / 2;

			POINT vptLeftTriangle[]=
			{
				{ rect.left, rect.top }, { rect.left, bottom + 2 },
				{ rect.left - gap - 1, bottom + 2 }, { rect.left, rect.top }
			};
			mem_dc.SelectStockObject(NULL_PEN);
			mem_dc.Polygon(vptLeftTriangle, array_count(vptLeftTriangle));

			POINT vptRightTriangle[]=
			{
				{ rect.right, rect.top }, { rect.right, bottom + 2 },
				{ rect.right + gap, bottom + 2 },  { rect.right + gap, bottom },
				{ rect.right, rect.top }
			};
			mem_dc.Polygon(vptRightTriangle, array_count(vptRightTriangle));

			// draw slanted line on the right side
			CPen* pen= mem_dc.SelectObject(&penBlack);
			mem_dc.MoveTo(rect.right, rect.top);
			mem_dc.LineTo(rect.right + gap, bottom);
			mem_dc.LineTo(rect.right + gap + 1, bottom);

			// draw slanted line on the left side
			mem_dc.SelectObject(&penDark);
			int left= rect.left - 1;
			mem_dc.MoveTo(left, rect.top);
			mem_dc.LineTo(left - gap, bottom);
			mem_dc.LineTo(left - gap + 1, bottom);

			// draw light slanted line on the left side
			mem_dc.SelectObject(&penLight);
			left++;
			mem_dc.MoveTo(left, rect.top);
			mem_dc.LineTo(left - gap, bottom);
			mem_dc.LineTo(left - gap, bottom + 2);
		}
		else		// inactive tab (smaller, dark background)
		{
			CRect rect= tab.location_rect_;
			rect.left++;
			rect.right++;
			rect.top += 2;
			rect.bottom = rect.top + 1;
			// draw two lines on the top
			mem_dc.FillSolidRect(rect, rgb_dark);
			rect.OffsetRect(0, 1);
			mem_dc.FillSolidRect(rect, rgb_gray);

			// draw slanted line on the right side
			CPen* pen= mem_dc.SelectObject(&penBlack);
			int right= rect.right - 0;
			mem_dc.MoveTo(right, rect.top);
			int bottom= tab.location_rect_.bottom - 1;
			int gap= (bottom - rect.top) / 2;
			mem_dc.LineTo(right + gap, bottom + 1);

			// draw short slanted line on the left side
			mem_dc.SelectObject(&penDark);
			int left= rect.left - 1;
			mem_dc.MoveTo(left, rect.top);
			if (index == 0)	// first tab?
			{
				mem_dc.LineTo(left - gap, bottom);	// in the first tab whole edge is visible
				mem_dc.LineTo(left - gap, bottom + 1);
				// draw light slanted line on the left side
				mem_dc.SelectObject(&penGray);
				mem_dc.MoveTo(left + 1, rect.top);
				mem_dc.LineTo(left - gap + 1, bottom);
				mem_dc.LineTo(left - gap + 1, bottom + 1);
			}
			else
			{
				int left_half= left - gap / 2;
				int bottom_half= (rect.top + bottom) / 2;
				mem_dc.LineTo(left_half, bottom_half);
				mem_dc.LineTo(left_half, bottom_half + 1);
				// draw light slanted line on the left side
				mem_dc.SelectObject(&penGray);
				mem_dc.MoveTo(left + 1, rect.top);
				mem_dc.LineTo(left_half, bottom_half + 2);
				// previous tab is not active?
//				if (index > 0 && !tabs_[index - 1].active_)
//					mem_dc.LineTo(left_half, bottom_half + 3);
			}


			mem_dc.SelectObject(pen);

			text_rect.top = rect.top + 1;
		}

		mem_dc.SetBkColor(rgb_tab);
		mem_dc.DrawText(tab.name_, text_rect, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_NOPREFIX | DT_EXPANDTABS | DT_END_ELLIPSIS);

		int offset= tab.active_ ? 0 : 12;
		CPoint icon(tab.location_rect_.left + 1, text_rect.top);

		if (tab.icon_ >= 0)
			image_list_.Draw(&mem_dc, offset + tab.icon_, icon, ILD_NORMAL);
	}

	mem_dc.SelectObject(brush);

	mem_dc.BitBlt();
}