//***************************************************************************** void CBCGPCaptionBar::OnNcPaint() { CWindowDC dcWin (this); CRect rectClient; GetClientRect(rectClient); CRect rectWindow; GetWindowRect(rectWindow); CRect rectBorder = rectWindow; ScreenToClient(rectWindow); rectClient.OffsetRect(-rectWindow.left, -rectWindow.top); dcWin.ExcludeClipRect (rectClient); rectBorder.OffsetRect(-rectBorder.left, -rectBorder.top); int nBorderSize = m_bIsMessageBarMode ? 0 : m_nBorderSize; int nTop = rectBorder.top; rectBorder.top = rectBorder.bottom - nBorderSize; OnDrawBorder (&dcWin, rectBorder); rectBorder.top = nTop; rectBorder.bottom = rectBorder.top + nBorderSize; OnDrawBorder (&dcWin, rectBorder); dcWin.SelectClipRgn (NULL); }
//***************************************************************************** void CBCGPCaptionBar::DoNcPaint(CDC* pDC) { ASSERT_VALID(pDC); CRect rectClient; GetClientRect(rectClient); CRect rectWindow; GetWindowRect(rectWindow); CRect rectBorder = rectWindow; ScreenToClient(rectWindow); rectClient.OffsetRect(-rectWindow.left, -rectWindow.top); pDC->ExcludeClipRect (rectClient); rectBorder.OffsetRect(-rectBorder.left, -rectBorder.top); int nBorderSize = m_bIsMessageBarMode ? 0 : m_nBorderSize; int nTop = rectBorder.top; rectBorder.top = rectBorder.bottom - nBorderSize; OnDrawBorder(pDC, rectBorder); rectBorder.top = nTop; rectBorder.bottom = rectBorder.top + nBorderSize; OnDrawBorder(pDC, rectBorder); pDC->SelectClipRgn (NULL); }
//******************************************************************************* void CBCGPRibbonStatusBarPane::OnDraw (CDC* pDC) { ASSERT_VALID (this); ASSERT_VALID (pDC); if (m_AnimImages.GetCount () == 0) { CBCGPRibbonButton::OnDraw (pDC); return; } if (m_rect.IsRectEmpty ()) { return; } OnFillBackground (pDC); if (m_nAnimationIndex < 0) { CString strText = m_strText; m_strText.Empty (); CBCGPRibbonButton::OnDraw (pDC); m_strText = strText; } else { m_AnimImages.DrawEx (pDC, m_rect, m_nAnimationIndex, CBCGPToolBarImages::ImageAlignHorzCenter, CBCGPToolBarImages::ImageAlignVertCenter); } OnDrawBorder (pDC); }
//*************************************************************************************** void CBCGPToolBoxButton::OnDraw (CDC* pDC) { ASSERT_VALID (this); ASSERT_VALID (pDC); ASSERT_VALID (m_pPage); if (m_Rect.IsRectEmpty ()) { return; } OnFillBackground (pDC, m_Rect); OnDrawBorder (pDC, m_Rect, 0); CRect rectText = m_Rect; if (m_pPage->GetMode () != CBCGPToolBoxPage::ToolBoxPageMode_Images) { rectText.left += rectText.Height(); } if (m_pImages != NULL && m_iImageIndex >= 0) { ASSERT_VALID (m_pImages); CSize sizeImage = m_pImages->GetImageSize (); if (globalData.GetRibbonImageScale () != 1.) { double dblImageScale = globalData.GetRibbonImageScale (); sizeImage = CSize ((int)(.5 + sizeImage.cx * dblImageScale), (int)(.5 + sizeImage.cy * dblImageScale)); } CRect rectImage = rectText; if (m_pPage->GetMode () != CBCGPToolBoxPage::ToolBoxPageMode_Images) { rectImage.right = rectImage.left + sizeImage.cx + 4; } m_pImages->Draw (pDC, rectImage.left + (rectImage.Width () - sizeImage.cx) / 2, rectImage.top + (rectImage.Height () - sizeImage.cy) / 2, m_iImageIndex); rectText.left = rectImage.right; } if (m_pPage->GetMode () == CBCGPToolBoxPage::ToolBoxPageMode_Images) { return; } rectText.DeflateRect(6, 0); pDC->SetTextColor (CBCGPVisualManager::GetInstance ()->GetToolBoxButtonTextColor (this)); pDC->DrawText (m_strLabel, rectText, DT_SINGLELINE | DT_VCENTER | DT_LEFT); }
void CBCGPToolTipCtrl::OnPaint() { if (m_Params.m_bBallonTooltip) { CToolTipCtrl::OnPaint (); return; } CPaintDC dcPaint(this); // device context for painting CBCGPMemDC memDC (dcPaint, this); CDC* pDC = &memDC.GetDC (); CRect rect; GetClientRect (rect); CRect rectMargin; GetMargin (rectMargin); CRect rectText = rect; rectText.DeflateRect (rectMargin); rectText.DeflateRect (m_ptMargin.x, m_ptMargin.y); COLORREF clrLine = m_Params.m_clrBorder == (COLORREF)-1 ? ::GetSysColor (COLOR_INFOTEXT) : m_Params.m_clrBorder; COLORREF clrText = m_Params.m_clrText == (COLORREF)-1 ? ::GetSysColor (COLOR_INFOTEXT) : m_Params.m_clrText; //----------------- // Fill background: //----------------- OnFillBackground (pDC, rect, clrText, clrLine); CPen penLine (PS_SOLID, 1, clrLine); CPen* pOldPen = pDC->SelectObject (&penLine); //------------- // Draw border: //------------- OnDrawBorder (pDC, rect, clrLine); //----------- // Draw icon: //----------- if (m_sizeImage != CSize (0, 0) && m_Params.m_bDrawIcon) { CRect rectImage = rectText; rectImage.right = rectImage.left + m_sizeImage.cx; rectImage.bottom = rectImage.top + m_sizeImage.cy; OnDrawIcon (pDC, rectImage); rectText.left += m_sizeImage.cx + m_ptMargin.x; } pDC->SetBkMode (TRANSPARENT); pDC->SetTextColor (clrText); //------------ // Draw label: //------------ int nTextHeight = OnDrawLabel (pDC, rectText, FALSE).cy; //------------------------------ // Draw separator + description: //------------------------------ if (!m_strDescription.IsEmpty () && m_Params.m_bDrawDescription) { CRect rectDescr = rectText; rectDescr.top += nTextHeight + 3 * m_ptMargin.y / 2; if (m_Params.m_bDrawSeparator) { OnDrawSeparator (pDC, rectDescr.left, rectDescr.right, rectDescr.top - m_ptMargin.y / 2); } OnDrawDescription (pDC, rectDescr, FALSE); } pDC->SelectObject (pOldPen); }
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 CBCGPAutoHideButton::OnDraw (CDC* pDC) { ASSERT_VALID (this); const BOOL bIsOverlapped = (CBCGPVisualManager::GetInstance ()->HasOverlappedAutoHideButtons ()) || m_bOverlappingTabs; const int nTextMargin = bIsOverlapped ? (IsHorizontal () ? 5 : 7) : m_nTextMargin; CSize size = GetSize (); m_rect.SetRect (0, 0, size.cx, size.cy); // calculate border size and draw the border CRect rectBorderSize (m_nBorderSize, 0, m_nBorderSize, m_nBorderSize); switch (m_dwAlignment & CBRS_ALIGN_ANY) { case CBRS_ALIGN_RIGHT: globalUtils.FlipRect (rectBorderSize, 90); break; case CBRS_ALIGN_BOTTOM: globalUtils.FlipRect (rectBorderSize, 180); break; case CBRS_ALIGN_LEFT: globalUtils.FlipRect (rectBorderSize, -90); break; } if (bIsOverlapped && !m_pParentBar->m_bFirstInGroup) { CRect rectPrev = m_rect; switch (m_dwAlignment & CBRS_ALIGN_ANY) { case CBRS_ALIGN_RIGHT: case CBRS_ALIGN_LEFT: rectPrev.OffsetRect (0, -m_rect.Height () + size.cx / 2); break; case CBRS_ALIGN_TOP: case CBRS_ALIGN_BOTTOM: rectPrev.OffsetRect (-m_rect.Width () + size.cy / 2, 0); break; } OnFillBackground (pDC, rectPrev); OnDrawBorder (pDC, rectPrev, rectBorderSize); } OnFillBackground (pDC, m_rect); OnDrawBorder (pDC, m_rect, rectBorderSize); if (m_pAutoHideWindow == NULL) { return; } ASSERT_VALID (m_pAutoHideWindow); CRect rectDraw = m_rect; if (!bIsOverlapped) { rectDraw.DeflateRect (rectBorderSize); } rectDraw.DeflateRect (m_nMarginSize, m_nMarginSize); if (m_pAutoHideWindow != NULL) { // draw the icon (if any) HICON hIcon = m_pAutoHideWindow->GetBarIcon (FALSE); if (hIcon != NULL || bIsOverlapped) { CSize sizeIcon (globalData.m_sizeSmallIcon); int dx = IsHorizontal () ? 0 : (rectDraw.Width () - sizeIcon.cx) / 2; int dy = IsHorizontal () ? (rectDraw.Height () - sizeIcon.cy) / 2 : 0; if (bIsOverlapped && !m_bOverlappingTabs) { if (IsHorizontal () ) { dx += rectDraw.Height () / 2 + 1; } else { dy += rectDraw.Width () / 2 + 1; } } if (hIcon != NULL) { ::DrawIconEx (pDC->GetSafeHdc (), rectDraw.left + dx, rectDraw.top + dy, hIcon, sizeIcon.cx, sizeIcon.cy, 0, NULL, DI_NORMAL); } else { #ifndef BCGP_EXCLUDE_RIBBON CBCGPVisualManager::GetInstance ()-> OnDrawDefaultRibbonImage (pDC, CRect (CPoint (rectDraw.left + dx, rectDraw.top + dy), sizeIcon)); #endif } if (IsHorizontal ()) { rectDraw.left += nTextMargin + sizeIcon.cx + dx; } else { rectDraw.top += nTextMargin + sizeIcon.cy + dy; } } else { if (IsHorizontal ()) { rectDraw.left += m_nMarginSize; } else { rectDraw.top += m_nMarginSize; } } // Draw text: CString strText; m_pAutoHideWindow->GetWindowText (strText); if (!strText.IsEmpty () && m_pParentBar->m_bActiveInGroup || !m_bOverlappingTabs) { int nOldMode = pDC->SetBkMode (TRANSPARENT); CFont* pFontOld = (CFont*) pDC->SelectObject (IsHorizontal () ? &globalData.fontRegular : &globalData.fontVert); ASSERT(pFontOld != NULL); pDC->SetTextColor ( CBCGPVisualManager::GetInstance ()->GetAutoHideButtonTextColor (this)); if (IsHorizontal ()) { pDC->DrawText (strText, &rectDraw, DT_SINGLELINE | DT_VCENTER | DT_CENTER); } else { TEXTMETRIC tm; pDC->GetTextMetrics (&tm); CRect rectText = rectDraw; rectText.left = rectText.right - (rectDraw.Width () - tm.tmHeight + 1) / 2; rectText.bottom = rectDraw.top + nTextMargin; pDC->DrawText (strText, &rectText, DT_SINGLELINE | DT_NOCLIP); } pDC->SelectObject (pFontOld); pDC->SetBkMode (nOldMode); } } }
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); } } }