示例#1
0
文件: vlbox.cpp 项目: hgwells/tive
void wxVListBox::OnPaint(wxPaintEvent& WXUNUSED(event))
{
    wxSize clientSize = GetClientSize();

    wxAutoBufferedPaintDC dc(this);

    // the update rectangle
    wxRect rectUpdate = GetUpdateClientRect();

    // fill it with background colour
    dc.SetBackground(GetBackgroundColour());
    dc.Clear();

    // the bounding rectangle of the current line
    wxRect rectLine;
    rectLine.width = clientSize.x;

    // iterate over all visible lines
    const size_t lineMax = GetVisibleEnd();
    for ( size_t line = GetFirstVisibleLine(); line < lineMax; line++ )
    {
        const wxCoord hLine = OnGetLineHeight(line);

        rectLine.height = hLine;

        // and draw the ones which intersect the update rect
        if ( rectLine.Intersects(rectUpdate) )
        {
            // don't allow drawing outside of the lines rectangle
            wxDCClipper clip(dc, rectLine);

            wxRect rect = rectLine;
            OnDrawBackground(dc, rect, line);

            OnDrawSeparator(dc, rect, line);

            rect.Deflate(m_ptMargins.x, m_ptMargins.y);
            OnDrawItem(dc, rect, line);
        }
        else // no intersection
        {
            if ( rectLine.GetTop() > rectUpdate.GetBottom() )
            {
                // we are already below the update rect, no need to continue
                // further
                break;
            }
            //else: the next line may intersect the update rect
        }

        rectLine.y += hLine;
    }
}
示例#2
0
//*****************************************************************************
void CBCGPCaptionBar::DoPaint(CDC* pDCIn)
{
	ASSERT_VALID(this);
	ASSERT_VALID(pDCIn);

	CBCGPMemDC memDC(*pDCIn, this);
	CDC* pDC = &memDC.GetDC();

	CRect rectClient;
	GetClientRect(rectClient);

	OnDrawBackground (pDC, rectClient);

	int nOldBkMode = pDC->SetBkMode (TRANSPARENT);
	COLORREF clrOldText = 
		pDC->SetTextColor (m_clrBarText != (COLORREF) -1 ? m_clrBarText : 
		CBCGPVisualManager::GetInstance ()->GetCaptionBarTextColor (this));

	CFont* pOldFont = pDC->SelectObject (
		m_hFont == NULL ? &globalData.fontRegular : CFont::FromHandle (m_hFont));

	CRect rectButton = m_rectButton;
	rectButton.top = max(rectClient.top + 1, rectButton.top);
	rectButton.bottom = min(rectClient.bottom - 1, rectButton.bottom);

	OnDrawButton (pDC, rectButton, m_strBtnText, m_bBtnEnabled);
	OnDrawText (pDC, m_rectDrawText, m_strText);

	if (!m_rectImage.IsRectEmpty ())
	{
		OnDrawImage (pDC, m_rectImage);
	}

	if (!m_rectClose.IsRectEmpty ())
	{
		COLORREF clrText = CBCGPVisualManager::GetInstance ()->OnFillCaptionBarButton (pDC, this,
			m_rectClose, m_bIsCloseBtnPressed, m_bIsCloseBtnHighlighted, FALSE,
			FALSE, TRUE);

		CBCGPVisualManager::GetInstance ()->OnDrawCaptionBarCloseButton(pDC, this, 
			m_rectClose, m_bIsCloseBtnPressed, m_bIsCloseBtnHighlighted, clrText);

		CBCGPVisualManager::GetInstance ()->OnDrawCaptionBarButtonBorder (pDC, this,
			m_rectClose, m_bIsCloseBtnPressed, m_bIsCloseBtnHighlighted, FALSE,
			FALSE, TRUE);
	}

	pDC->SelectObject (pOldFont);
	pDC->SetTextColor (clrOldText);
	pDC->SetBkMode (nOldBkMode);
}
示例#3
0
void CXTPMarqueeCtrl::OnPaint()
{
    if (IsMarquee())
    {
        CXTPClientRect rcClient(this);

        CPaintDC dc(this);
        CXTPBufferDC dcMem(dc);

        OnDrawBackground(&dcMem, rcClient);
        OnDrawMarquee(&dcMem, rcClient);
    }
    else
    {
        CProgressCtrl::OnPaint();
    }
}
示例#4
0
void CButtonST::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
    CDC*    pDC = CDC::FromHandle(lpDIS->hDC);

    CPen    *pOldPen;

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

    m_bIsFocused  = (lpDIS->itemState & ODS_FOCUS);
    m_bIsDisabled = (lpDIS->itemState & ODS_DISABLED);

    CRect itemRect = lpDIS->rcItem;

    pDC->SetBkMode(TRANSPARENT);

    if (m_bIsFlat == FALSE)
    {
        if (m_bIsFocused || (GetDefault() == TRUE))
        {
            CBrush br(RGB(0,0,0));  
            pDC->FrameRect(&itemRect, &br);
            itemRect.DeflateRect(1, 1);
        } // if
    } // if

    // Prepare draw... paint button background

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

    // Draw pressed button
    if (m_bIsPressed)
    {
		CRect captionRect1 = lpDIS->rcItem;
        if (m_bIsFlat == TRUE)
        {
            if (m_bDrawBorder)
            {
                OnDrawBorder(pDC, &itemRect);
		
            }
        }
        else    
        {
            CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
            pDC->FrameRect(&itemRect, &brBtnShadow);
        }
    }
    else // ...else draw non pressed button
    {
        CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // White
        CPen pen3DLight(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT));       // Light gray
        CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW));   // Dark gray
        CPen pen3DDKShadow(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); // Black

        if (m_bIsFlat == TRUE)
        {
            if (m_bMouseOnButton && m_bDrawBorder)
            {
                OnDrawBorder(pDC, &itemRect);
            }
        }
        else
        {
            // Draw top-left borders
            // White line
            pOldPen = pDC->SelectObject(&penBtnHiLight);
            pDC->MoveTo(itemRect.left, itemRect.bottom-1);
            pDC->LineTo(itemRect.left, itemRect.top);
            pDC->LineTo(itemRect.right, itemRect.top);
            // Light gray line
            pDC->SelectObject(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->SelectObject(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->SelectObject(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->SelectObject(pOldPen);
        }
    }

    // Read the button's title
    CString sTitle;
    GetWindowText(sTitle);

    CRect captionRect = lpDIS->rcItem;

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

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

    // Write the button title (if any)
    if (sTitle.IsEmpty() == FALSE)
    {
        // Draw the button's title
        // If button is pressed then "press" title also
        if (m_bIsPressed && m_bIsCheckBox == FALSE)
        {
            //将偏移1像素的粗体显示效果去除。
            captionRect.OffsetRect(0, 0);
        }
    
        // ONLY FOR DEBUG 
        //CBrush brBtnShadow(RGB(255, 0, 0));
        //pDC->FrameRect(&captionRect, &brBtnShadow);

        /*
        if ((m_bMouseOnButton == TRUE) || (bIsPressed)) 
        {
            pDC->SetTextColor(GetActiveFgColor());
            pDC->SetBkColor(GetActiveBgColor());
        } 
        else 
        {
            pDC->SetTextColor(GetInactiveFgColor());
            pDC->SetBkColor(GetInactiveBgColor());
        }
        */
        // 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);
        /* RFU
        captionRect.OffsetRect(0, (centerRect.Height() - captionRect.Height())/2);
        captionRect.OffsetRect((centerRect.Width() - captionRect.Width())-4, (centerRect.Height() - captionRect.Height())/2);
        */

        pDC->SetBkMode(TRANSPARENT);
        /*
        pDC->DrawState(captionRect.TopLeft(), captionRect.Size(), (LPCTSTR)sTitle, (bIsDisabled ? DSS_DISABLED : DSS_NORMAL), 
                        TRUE, 0, (CBrush*)NULL);
        */
        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]);
            }

            if(m_bBigDaddy)
            {
                if(m_bIsFlat == TRUE)
                {
                    if (m_bDrawBorder)
                    {
                        OnDrawBorder(pDC, &itemRect);
                    }
                }
                else
                {
                    CBrush brBtnShadow(RGB(255,255,0));
                    pDC->FrameRect(&itemRect, &brBtnShadow);
                }
            }
            pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
        }
    }

    if (m_bIsFlat == FALSE || (m_bIsFlat == TRUE && m_bDrawFlatFocus == TRUE))
    {
        // Draw the focus rect
        if (m_bIsFocused)
        {
            CRect focusRect = itemRect;
            focusRect.DeflateRect(3, 3);
            pDC->DrawFocusRect(&focusRect);
        } // if
    } // if
} // End of DrawItem
void CXTPHeaderCtrlTheme::DrawHeader(CDC* pDC, CXTPHeaderCtrl* pHeaderCtrl)
{
	ASSERT_VALID(pHeaderCtrl);

	CXTPClientRect rcClient(pHeaderCtrl);

	DRAWITEMSTRUCT dis;
	dis.CtlType = ODT_BUTTON;
	dis.CtlID = 0;
	dis.itemID = 0;
	dis.itemAction = ODA_DRAWENTIRE;
	dis.itemState = 0;
	dis.hwndItem = pHeaderCtrl->m_hWnd;
	dis.hDC = pDC->m_hDC;
	dis.rcItem = rcClient;
	dis.itemData = 0;

	// draw background.
	if (!m_bUseWinThemes || !OnDrawBackgroundWinThemed(&dis))
		OnDrawBackground(&dis);

	// set text attributes.
	CXTPFontDC fontDC(pDC, pHeaderCtrl->GetFont());
	pDC->SetBkColor(m_cr3DFace);
	pDC->SetTextColor(m_crText);
	pDC->SetBkMode(TRANSPARENT);

	// Set up the header item order array.
	HD_ITEM hdi;
	::ZeroMemory(&hdi, sizeof(HD_ITEM));

	hdi.fmt = HDF_STRING | HDF_LEFT | HDF_BITMAP;
	hdi.mask = HDI_WIDTH | HDI_TEXT | HDI_FORMAT | HDI_ORDER | HDI_BITMAP | HDI_LPARAM;

	int cxy = 0;
	int iItem = 0;
	int iItemCount = pHeaderCtrl->GetItemCount();
	int *plItems = new int[iItemCount];

	for (iItem = 0; iItem < iItemCount; iItem++)
	{
		pHeaderCtrl->GetItem(iItem, &hdi);
		plItems[hdi.iOrder] = iItem;
	}

	hdi.fmt = HDF_STRING | HDF_LEFT | HDF_BITMAP;
	hdi.mask = HDI_WIDTH | HDI_TEXT | HDI_FORMAT | HDI_BITMAP | HDI_LPARAM;

	// get cursor position.
	CPoint point;
	::GetCursorPos(&point);
	pHeaderCtrl->ScreenToClient(&point);

	// Draw each header item
	for (iItem = 0; iItem < iItemCount; ++iItem)
	{
		// Get the header item text and format
		TCHAR szBuffer[256];
		hdi.pszText = szBuffer;
		hdi.cchTextMax = 255;
		pHeaderCtrl->GetItem(plItems[iItem], &hdi);

		// initialize draw item structure.
		dis.itemID = plItems[iItem];
		dis.itemState = 0;
		dis.rcItem = rcClient;
		dis.rcItem.left = cxy;
		dis.rcItem.right = dis.rcItem.left + hdi.cxy;
		dis.itemData = (DWORD_PTR)&hdi;

		// if hot tracking is enabled, set the state.
		if (GetDrawStyle() & HDR_XTP_HOTTRACKING)
		{
			if (pHeaderCtrl->HitTest(point) == plItems[iItem])
				dis.itemState = ODS_HOTLIGHT;
		}

		// check if the item is selected
		if (pHeaderCtrl->ItemPressed(plItems[iItem]))
			dis.itemState = ODS_SELECTED;

		// draw the item background.
		if (!m_bUseWinThemes || !OnDrawItemBackgroundWinThemed(&dis))
			OnDrawItemBackground(&dis);

		// draw the item text.
		OnDrawItemText(&dis, pHeaderCtrl);
		cxy += hdi.cxy;
	}

	delete [] plItems;
}
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);
			}
		}
}