本文代码来自Adding New Theme Variations to the MFC Ribbon (CMFCVisualManager) - CodeProject
下面的主要类代码出自上述文章,涉及权力由该作者所有
1. 头文件 MFCVisualManagerDeviant.h
#pragma once
// CMFCVisualManagerDeviant command target
class CMFCVisualManagerDeviant : public CMFCVisualManagerOffice2007
{
DECLARE_DYNCREATE(CMFCVisualManagerDeviant)
public:
CMFCVisualManagerDeviant();
virtual ~CMFCVisualManagerDeviant();
//virtual void OnUpdateSystemColors();
virtual COLORREF OnDrawRibbonPanel(CDC* pDC, CMFCRibbonPanel* pPanel, CRect rectPanel, CRect rectCaption);
virtual void OnDrawRibbonCategory(CDC* pDC, CMFCRibbonCategory* pCategory, CRect rectCategory);
virtual void OnFillBarBackground(CDC* pDC, CBasePane* pBar, CRect rectClient, CRect rectClip, BOOL bNCArea = FALSE);
virtual COLORREF OnDrawRibbonCategoryTab(CDC* pDC, CMFCRibbonTab* pTab, BOOL bIsActive);
void OnDrawRibbonDefaultPaneButton(CDC* pDC, CMFCRibbonButton* pButton);
COLORREF OnFillRibbonButton(CDC * pDC, CMFCRibbonButton * pButton);
COLORREF OnDrawMenuLabel(CDC* pDC, CRect rect);
// Accessor functions for ribbon panel colours
COLORREF GetClrRibbonPanelBkBottom() const { return m_clrRibbonPanelBkBottom; }
void SetClrRibbonPanelBkBottom(COLORREF val) { m_clrRibbonPanelBkBottom = val; }
COLORREF GetClrRibbonPanelBkTop() const { return m_clrRibbonPanelBkTop; }
void SetClrRibbonPanelBkTop(COLORREF val) { m_clrRibbonPanelBkTop = val; }
COLORREF GetClrRibbonPanelTextPB() const { return m_clrRibbonPanelTextPB; }
void SetClrRibbonPanelTextPB(COLORREF val) { m_clrRibbonPanelTextPB = val; }
COLORREF GetClrRibbonPanelCaptionTextPB() const { return m_clrRibbonPanelCaptionTextPB; }
void SetClrRibbonPanelCaptionTextPB(COLORREF val) { m_clrRibbonPanelCaptionTextPB = val; }
COLORREF GetClrRibbonPanelCaptionTextHighlightedPB() const { return m_clrRibbonPanelCaptionTextHighlightedPB; }
void SetClrRibbonPanelCaptionTextHighlightedPB(COLORREF val) { m_clrRibbonPanelCaptionTextHighlightedPB = val; }
// Ribbon menu bar background
COLORREF GetClrRibbonBarBackground() const { return m_clrRibbonBarBackground; }
void SetClrRibbonBarBackground(COLORREF val) { m_clrRibbonBarBackground = val; }
COLORREF GetClrRibbonBarTextPB() const { return m_clrRibbonBarTextPB; }
void SetClrRibbonBarTextPB(COLORREF val) { m_clrRibbonBarTextPB = val; }
COLORREF GetClrRibbonBarTextHighlightedPB() const { return m_clrRibbonBarTextHighlightedPB; }
void SetClrRibbonBarTextHighlightedPB(COLORREF val) { m_clrRibbonBarTextHighlightedPB = val; }
// Ribbon category colours
COLORREF GetClrRibbonCategoryBkBottom() const { return m_clrRibbonCategoryBkBottom; }
void SetClrRibbonCategoryBkBottom(COLORREF val) { m_clrRibbonCategoryBkBottom = val; }
COLORREF GetClrRibbonCategoryBkTop() const { return m_clrRibbonCategoryBkTop; }
void SetClrRibbonCategoryBkTop(COLORREF val) { m_clrRibbonCategoryBkTop = val; }
// Ribbon panel outline colour
COLORREF GetClrRibbonPanelOutline() const { return m_clrRibbonPanelOutline; }
void SetClrRibbonPanelOutline(COLORREF val) { m_clrRibbonPanelOutline = val; }
// Ribbon panel label background area colour
COLORREF GetClrRibbonPanelCaptionBk() const { return m_clrRibbonPanelCaptionBk; }
void SetClrRibbonPanelCaptionBk(COLORREF val) { m_clrRibbonPanelCaptionBk = val; }
// MDI Client area background
virtual BOOL OnEraseMDIClientArea(CDC* pDC, CRect rectClient);
COLORREF GetClrMDIClientArea() const { return m_clrMDIClientArea; }
void SetClrMDIClientArea(COLORREF val) { m_clrMDIClientArea = val; m_bCustomMDIClientAreaClr = TRUE; }
BOOL GetCustomMDIClientAreaClr() const { return m_bCustomMDIClientAreaClr; }
void SetCustomMDIClientAreaClr(BOOL val) { m_bCustomMDIClientAreaClr = val; }
protected:
// Utility fns to lighten or darken colour
COLORREF LightenColor(long lScale, COLORREF lColor);
COLORREF DarkenColor(long lScale, COLORREF lColor);
// Ribbon panel colours
COLORREF m_clrRibbonPanelBkBottom;
COLORREF m_clrRibbonPanelBkTop;
COLORREF m_clrRibbonPanelCaptionBk;
COLORREF m_clrRibbonPanelTextPB;
COLORREF m_clrRibbonPanelCaptionTextPB;
COLORREF m_clrRibbonPanelCaptionTextHighlightedPB;
COLORREF m_clrRibbonPanelOutline;
// Ribbon category colours
COLORREF m_clrRibbonCategoryBkBottom;
COLORREF m_clrRibbonCategoryBkTop;
// Ribbon menu bar background
COLORREF m_clrRibbonBarBackground;
COLORREF m_clrRibbonBarTextPB;
COLORREF m_clrRibbonBarTextHighlightedPB;
// MDI background colour
BOOL m_bCustomMDIClientAreaClr;
COLORREF m_clrMDIClientArea;
};
2. cpp文件 MFCVisualManagerDeviant.cpp
// MFCVisualManagerDeviant.cpp : implementation file
//
#include "stdafx.h"
#include "MFCVisualManagerDeviant.h"
// CMFCVisualManagerDeviant
IMPLEMENT_DYNCREATE(CMFCVisualManagerDeviant, CMFCVisualManagerOffice2007)
CMFCVisualManagerDeviant::CMFCVisualManagerDeviant()
: CMFCVisualManagerOffice2007()
, m_clrRibbonPanelBkBottom(RGB(255, 255, 255))
, m_clrRibbonPanelBkTop(RGB(255, 214, 51))
, m_clrRibbonPanelCaptionBk(m_clrRibbonPanelBkTop)
, m_clrRibbonPanelTextPB(RGB(204, 0, 51))
, m_clrRibbonPanelCaptionTextPB(RGB(102, 51, 204))
, m_clrRibbonPanelCaptionTextHighlightedPB(RGB(0, 0, 0))
, m_clrRibbonCategoryBkBottom(RGB(255, 255, 255))
, m_clrRibbonCategoryBkTop(RGB(255, 244, 204))
, m_clrRibbonBarBackground(RGB(204, 0, 51))
, m_clrRibbonPanelOutline(RGB(192,192,192))
, m_clrRibbonBarTextPB(RGB(255,255,255))
, m_clrRibbonBarTextHighlightedPB(RGB(64, 64, 255))
, m_bCustomMDIClientAreaClr(FALSE)
{
}
CMFCVisualManagerDeviant::~CMFCVisualManagerDeviant()
{
}
// CMFCVisualManagerDeviant member functions
COLORREF CMFCVisualManagerDeviant::OnDrawRibbonPanel(CDC* pDC, CMFCRibbonPanel* pPanel, CRect rectPanel, CRect rectCaption)
{
if (!pPanel->IsCollapsed())
{
// Fill panel with main gradient
+= 1;
rectPanel.right -= 1;
rectPanel.left += 1;
CDrawingManager dm(*pDC);
dm.FillGradient2(rectPanel, m_clrRibbonPanelBkBottom, m_clrRibbonPanelBkTop, 90);
// Fill the panel label area
CRect rectPanelBottom(rectPanel);
= rectPanelBottom.bottom - (rectPanelBottom.Height()*.2);
rectPanelBottom.bottom -= 1;
dm.FillGradient2(rectPanelBottom, m_clrRibbonPanelCaptionBk, m_clrRibbonPanelCaptionBk, 90);
// Draw surrounding rounded rectangle
rectPanel.right += 1;
rectPanel.left -= 1;
-= 1;
CPen mypen(PS_SOLID, 1, m_clrRibbonPanelOutline);
CPen* pOldPen=pDC->SelectObject(&mypen);
CBrush* pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
pDC->RoundRect(rectPanel, CPoint(5, 5));
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
// Squirrel overridden colours.
m_clrRibbonPanelCaptionText = m_clrRibbonPanelCaptionTextPB;
m_clrRibbonPanelCaptionTextHighlighted = m_clrRibbonPanelCaptionTextHighlightedPB;
}
return m_clrRibbonPanelTextPB;
}
void CMFCVisualManagerDeviant::OnDrawRibbonCategory(CDC* pDC, CMFCRibbonCategory* pCategory, CRect rectCategory)
{
CDrawingManager dm(*pDC);
dm.FillGradient2(rectCategory, m_clrRibbonCategoryBkBottom, m_clrRibbonCategoryBkTop, 90);
}
void CMFCVisualManagerDeviant::OnFillBarBackground(CDC* pDC, CBasePane* pBar, CRect rectClient, CRect rectClip, BOOL bNCArea /*= FALSE*/)
{
CBrush br(m_clrRibbonBarBackground);
pDC->FillRect(rectClient, &br);
}
COLORREF CMFCVisualManagerDeviant::OnDrawRibbonCategoryTab(CDC* pDC, CMFCRibbonTab* pTab, BOOL bIsActive)
{
if (!CanDrawImage())
{
return CMFCVisualManagerOffice2003::OnDrawRibbonCategoryTab(pDC, pTab, bIsActive);
}
ASSERT_VALID(pDC);
ASSERT_VALID(pTab);
CMFCRibbonCategory* pCategory = pTab->GetParentCategory();
ASSERT_VALID(pCategory);
CMFCRibbonBar* pBar = pCategory->GetParentRibbonBar();
ASSERT_VALID(pBar);
// Get state of this tab
bIsActive = bIsActive && ((pBar->GetHideFlags() & AFX_RIBBONBAR_HIDE_ELEMENTS) == 0 || pTab->GetDroppedDown() != NULL);
const BOOL bPressed = pTab->IsPressed();
const BOOL bIsFocused = pTab->IsFocused() && (pBar->GetHideFlags() & AFX_RIBBONBAR_HIDE_ELEMENTS);
const BOOL bIsHighlight = (pTab->IsHighlighted() || bIsFocused) && !pTab->IsDroppedDown(); // If TRUE, mouse is hovering over tab
COLORREF clrText = GetClrRibbonBarTextPB();
COLORREF clrTextHighlighted = m_clrRibbonBarTextHighlightedPB;
// Get rect we need to draw
CRect rectTab = pCategory->GetTabRect();
TRACE(_T("\nDrawing tab '%s'. Active=%d, Pressed=%d, Focused=%d, Highlighted=%d"), pCategory->GetName(), bIsActive, bPressed, bIsFocused, bIsHighlight);
if (pCategory->IsActive())
{
CDrawingManager dm(*pDC);
dm.FillGradient2(rectTab, m_clrRibbonPanelBkTop, m_clrRibbonPanelBkBottom, 90);
}
else
{
CBrush br(m_clrRibbonBarBackground);
pDC->FillRect(rectTab, &br);
}
return bIsActive ? clrTextHighlighted : clrText;
}
// Draws collapsed buttons. Code stolen from CMFCVisualManagerOffice2007::OnDrawRibbonDefaultPaneButton except where stated
void CMFCVisualManagerDeviant::OnDrawRibbonDefaultPaneButton(CDC* pDC, CMFCRibbonButton* pButton)
{
if (!CanDrawImage())
{
CMFCVisualManagerOffice2003::OnDrawRibbonDefaultPaneButton(pDC, pButton);
return;
}
ASSERT_VALID(pDC);
ASSERT_VALID(pButton);
// Changed by Pete
// OnFillRibbonButton(pDC, pButton);
CRect rect(pButton->GetRect());
CDrawingManager dm(*pDC);
dm.FillGradient2(rect, m_clrRibbonPanelBkBottom, m_clrRibbonPanelBkTop, 90);
pDC->Draw3dRect(rect, RGB(192, 192, 192), RGB(192, 192, 192));
// End of changed by Pete
BOOL bIsQATMode = pButton->IsQATMode();
CRect rectFrame(pButton->GetRect());
if (!bIsQATMode)
{
if (m_ctrlRibbonBtnDefaultIcon.IsValid())
{
const CSize sizeImage = pButton->GetImageSize(CMFCRibbonButton::RibbonImageSmall);
const int nMarginX = 11;
const int nMarginY = 10;
+= nMarginY / 2;
rectFrame.bottom = + sizeImage.cy + 2 * nMarginY;
-= 2;
rectFrame.left = rectFrame.CenterPoint().x - sizeImage.cx / 2 - nMarginX;
rectFrame.right = rectFrame.left + sizeImage.cx + 2 * nMarginX;
m_ctrlRibbonBtnDefaultIcon.Draw(pDC, rectFrame);
}
}
else
{
if (m_ctrlRibbonBtnDefaultQAT.IsValid())
{
int index = 0;
if (pButton->IsDroppedDown())
{
index = 2;
}
else if (pButton->IsPressed())
{
if (pButton->IsHighlighted())
{
index = 2;
}
}
else if (pButton->IsHighlighted() || pButton->IsFocused())
{
index = 1;
}
m_ctrlRibbonBtnDefaultQAT.Draw(pDC, rectFrame, index);
}
else if (m_ctrlRibbonBtnDefaultQATIcon.IsValid())
{
int nHeight = m_ctrlRibbonBtnDefaultQATIcon.GetParams().m_rectImage.Height();
if (rectFrame.Height() < nHeight)
{
nHeight = rectFrame.Height() / 2;
}
rectFrame.DeflateRect(1, 0);
= rectFrame.bottom - nHeight;
m_ctrlRibbonBtnDefaultQATIcon.Draw(pDC, rectFrame);
}
}
OnDrawRibbonDefaultPaneButtonContext(pDC, pButton);
}
// Function splits a color into its RGB components and
// transforms the color using a scale 0..255
COLORREF CMFCVisualManagerDeviant::LightenColor(long lScale, COLORREF lColor)
{
long R = MulDiv(255 - GetRValue(lColor), lScale, 255) + GetRValue(lColor);
long G = MulDiv(255 - GetGValue(lColor), lScale, 255) + GetGValue(lColor);
long B = MulDiv(255 - GetBValue(lColor), lScale, 255) + GetBValue(lColor);
return RGB(R, G, B);
}
// Function splits a color into its RGB components and
// transforms the color using a scale 0..255
COLORREF CMFCVisualManagerDeviant::DarkenColor(long lScale, COLORREF lColor)
{
long red = MulDiv(GetRValue(lColor), (255 - lScale), 255);
long green = MulDiv(GetGValue(lColor), (255 - lScale), 255);
long blue = MulDiv(GetBValue(lColor), (255 - lScale), 255);
return RGB(red, green, blue);
}
// Draws uncollapsed buttons. Code stolen from CMFCVisualManagerOffice2007::OnFillRibbonButton except where stated
COLORREF CMFCVisualManagerDeviant::OnFillRibbonButton(CDC* pDC, CMFCRibbonButton* pButton)
{
if (!CanDrawImage())
{
return CMFCVisualManagerOffice2003::OnFillRibbonButton(pDC, pButton);
}
ASSERT_VALID(pDC);
ASSERT_VALID(pButton);
const BOOL bIsMenuMode = pButton->IsMenuMode();
CRect rect(pButton->GetRect());
CMFCControlRenderer* pRenderer = NULL;
CMFCVisualManagerBitmapCache* pCache = NULL;
int index = 0;
BOOL bDisabled = pButton->IsDisabled();
BOOL bFocused = pButton->IsFocused();
BOOL bDroppedDown = pButton->IsDroppedDown();
BOOL bPressed = pButton->IsPressed() && !bIsMenuMode;
BOOL bChecked = pButton->IsChecked();
BOOL bHighlighted = pButton->IsHighlighted() || bFocused;
BOOL bDefaultPanelButton = pButton->IsDefaultPanelButton() && !pButton->IsQATMode();
if (bFocused)
{
bDisabled = FALSE;
}
if (pButton->IsDroppedDown() && !bIsMenuMode)
{
bChecked = TRUE;
bPressed = FALSE;
bHighlighted = FALSE;
}
CMFCRibbonBaseElement::RibbonElementLocation location = pButton->GetLocationInGroup();
if (pButton->IsKindOf(RUNTIME_CLASS(CMFCRibbonEdit)))
{
rect.left = pButton->GetCommandRect().left;
COLORREF color1 = m_clrRibbonEdit;
if (bDisabled)
{
color1 = m_clrRibbonEditDisabled;
}
else if (bChecked || bHighlighted)
{
color1 = m_clrRibbonEditHighlighted;
}
COLORREF color2 = color1;
{
CDrawingManager dm(*pDC);
dm.FillGradient(rect, color1, color2, TRUE);
}
return(COLORREF)-1;
}
if (bChecked && bIsMenuMode && !pButton->IsGalleryIcon())
{
bChecked = FALSE;
}
if (location != CMFCRibbonBaseElement::RibbonElementNotInGroup && pButton->IsShowGroupBorder())
{
if (!pButton->GetMenuRect().IsRectEmpty())
{
CRect rectC = pButton->GetCommandRect();
CRect rectM = pButton->GetMenuRect();
CMFCControlRenderer* pRendererC = NULL;
CMFCControlRenderer* pRendererM = NULL;
CMFCVisualManagerBitmapCache* pCacheC = NULL;
CMFCVisualManagerBitmapCache* pCacheM = NULL;
if (location == CMFCRibbonBaseElement::RibbonElementSingleInGroup)
{
pRendererC = &m_ctrlRibbonBtnGroupMenu_F[0];
pRendererM = &m_ctrlRibbonBtnGroupMenu_L[1];
pCacheC = &m_cacheRibbonBtnGroupMenu_F[0];
pCacheM = &m_cacheRibbonBtnGroupMenu_L[1];
}
else if (location == CMFCRibbonBaseElement::RibbonElementFirstInGroup)
{
pRendererC = &m_ctrlRibbonBtnGroupMenu_F[0];
pRendererM = &m_ctrlRibbonBtnGroupMenu_F[1];
pCacheC = &m_cacheRibbonBtnGroupMenu_F[0];
pCacheM = &m_cacheRibbonBtnGroupMenu_F[1];
}
else if (location == CMFCRibbonBaseElement::RibbonElementLastInGroup)
{
pRendererC = &m_ctrlRibbonBtnGroupMenu_L[0];
pRendererM = &m_ctrlRibbonBtnGroupMenu_L[1];
pCacheC = &m_cacheRibbonBtnGroupMenu_L[0];
pCacheM = &m_cacheRibbonBtnGroupMenu_L[1];
}
else
{
pRendererC = &m_ctrlRibbonBtnGroupMenu_M[0];
pRendererM = &m_ctrlRibbonBtnGroupMenu_M[1];
pCacheC = &m_cacheRibbonBtnGroupMenu_M[0];
pCacheM = &m_cacheRibbonBtnGroupMenu_M[1];
}
int indexC = 0;
int indexM = 0;
BOOL bHighlightedC = pButton->IsCommandAreaHighlighted();
BOOL bHighlightedM = pButton->IsMenuAreaHighlighted();
if (IsBeta())
{
if (bChecked)
{
indexC = 3;
}
if (bDisabled)
{
indexC = 0;
}
else
{
if (pButton->IsDroppedDown() && !bIsMenuMode)
{
indexC = pButton->IsChecked() ? 3 : 0;
indexM = 3;
}
else
{
if (bPressed)
{
if (bHighlightedC)
{
indexM = 1;
indexC = 2;
}
}
else if (bHighlighted)
{
indexC++;
indexM = 1;
}
}
}
}
else
{
if (bChecked)
{
indexC = 3;
if (bHighlighted)
{
indexM = 5;
}
}
if (bDisabled)
{
if (bChecked)
{
indexC = 5;
indexM = 4;
}
}
else
{
if (pButton->IsDroppedDown() && !bIsMenuMode)
{
indexC = pButton->IsChecked() ? 3 : 6;
indexM = 3;
}
else
{
if (bFocused)
{
indexC = 6;
indexM = 5;
}
if (bHighlightedC || bHighlightedM)
{
if (bChecked)
{
indexC = bHighlightedC ? 4 : 3;
}
else
{
indexC = bHighlightedC ? 1 : 6;
}
indexM = bHighlightedM ? 1 : 5;
}
if (bPressed)
{
if (bHighlightedC)
{
indexC = 2;
}
}
}
}
}
if (indexC != -1 && indexM != -1)
{
int nCacheIndex = -1;
if (pCacheC != NULL)
{
CSize size(rectC.Size());
nCacheIndex = pCacheC->FindIndex(size);
if (nCacheIndex == -1)
{
nCacheIndex = pCacheC->Cache(size, *pRendererC);
}
}
if (nCacheIndex != -1)
{
pCacheC->Get(nCacheIndex)->Draw(pDC, rectC, indexC);
}
else
{
pRendererC->Draw(pDC, rectC, indexC);
}
nCacheIndex = -1;
if (pCacheM != NULL)
{
CSize size(rectM.Size());
nCacheIndex = pCacheM->FindIndex(size);
if (nCacheIndex == -1)
{
nCacheIndex = pCacheM->Cache(size, *pRendererM);
}
}
if (nCacheIndex != -1)
{
pCacheM->Get(nCacheIndex)->Draw(pDC, rectM, indexM);
}
else
{
pRendererM->Draw(pDC, rectM, indexM);
}
}
return(COLORREF)-1;
}
else
{
if (location == CMFCRibbonBaseElement::RibbonElementSingleInGroup)
{
pRenderer = &m_ctrlRibbonBtnGroup_S;
pCache = &m_cacheRibbonBtnGroup_S;
}
else if (location == CMFCRibbonBaseElement::RibbonElementFirstInGroup)
{
pRenderer = &m_ctrlRibbonBtnGroup_F;
pCache = &m_cacheRibbonBtnGroup_F;
}
else if (location == CMFCRibbonBaseElement::RibbonElementLastInGroup)
{
pRenderer = &m_ctrlRibbonBtnGroup_L;
pCache = &m_cacheRibbonBtnGroup_L;
}
else
{
pRenderer = &m_ctrlRibbonBtnGroup_M;
pCache = &m_cacheRibbonBtnGroup_M;
}
if (bChecked)
{
index = 3;
}
if (bDisabled && !bFocused)
{
index = 0;
}
else
{
if (bPressed)
{
if (bHighlighted)
{
index = 2;
}
}
else if (bHighlighted)
{
index++;
}
}
}
}
else if (bDefaultPanelButton)
{
if (bPressed)
{
if (bHighlighted)
{
index = 2;
}
}
else if (bHighlighted)
{
index = 1;
}
else if (bChecked)
{
index = 2;
}
if (bFocused && !bDroppedDown && m_ctrlRibbonBtnDefault.GetImageCount() > 3)
{
index = 3;
}
if (index != -1)
{
pRenderer = &m_ctrlRibbonBtnDefault;
CMFCVisualManagerBitmapCache* pCacheDefault = &m_cacheRibbonBtnDefault;
CMFCRibbonCategory* pCategory = pButton->GetParentCategory();
ASSERT_VALID(pCategory);
if (pCategory->GetTabColor() != AFX_CategoryColor_None)
{
CMFCRibbonContextCategory& context = m_ctrlRibbonContextCategory[pCategory->GetTabColor() - 1];
pRenderer = &context.m_ctrlBtnDefault;
pCacheDefault = &context.m_cacheBtnDefault;
}
const CMFCControlRendererInfo& params = pRenderer->GetParams();
int nCacheIndex = -1;
if (pCacheDefault != NULL)
{
CSize size(params.m_rectImage.Width(), rect.Height());
nCacheIndex = pCacheDefault->FindIndex(size);
if (nCacheIndex == -1)
{
nCacheIndex = pCacheDefault->CacheY(size.cy, *pRenderer);
}
}
if (nCacheIndex != -1)
{
pCacheDefault->Get(nCacheIndex)->DrawY(pDC, rect, CSize(params.m_rectInter.left, params.m_rectImage.right - params.m_rectInter.right), index);
return m_clrToolBarBtnTextHighlighted;
}
}
}
else if ((!bDisabled && (bPressed || bChecked || bHighlighted)) || (bDisabled && bFocused))
{
if (!pButton->GetMenuRect().IsRectEmpty()/* && (pButton->IsHighlighted() || bChecked)*/)
{
CRect rectC = pButton->GetCommandRect();
CRect rectM = pButton->GetMenuRect();
CMFCControlRenderer* pRendererC = pButton->IsMenuOnBottom() ? &m_ctrlRibbonBtnMenuV[0] : &m_ctrlRibbonBtnMenuH[0];
CMFCControlRenderer* pRendererM = pButton->IsMenuOnBottom() ? &m_ctrlRibbonBtnMenuV[1] : &m_ctrlRibbonBtnMenuH[1];
int indexC = -1;
int indexM = -1;
BOOL bDropped = pButton->IsDroppedDown();
BOOL bHighlightedC = pButton->IsCommandAreaHighlighted();
BOOL bHighlightedM = pButton->IsMenuAreaHighlighted();
if (IsBeta())
{
if (bChecked)
{
indexC = 2;
indexM = 2;
}
if (bDisabled)
{
if (bChecked)
{
}
}
else
{
if (bDropped && !bIsMenuMode)
{
indexC = bChecked ? 2 : 4;
indexM = 2;
}
else
{
if (bPressed)
{
if (bHighlighted)
{
if (bHighlightedC)
{
indexC = 1;
}
else
{
indexC = bChecked ? indexC : 0;
}
indexM = bChecked ? indexM : 0;
}
}
else if (bHighlighted)
{
indexC++;
indexM++;
}
}
}
}
else
{
if (bDisabled)
{
if (bHighlightedC || bHighlightedM)
{
indexC = 4;
indexM = 4;
if (bHighlightedM)
{
indexM = 0;
if (bDropped && !bIsMenuMode)
{
indexC = 5;
indexM = 2;
}
else if (bPressed)
{
indexM = 1;
}
}
}
}
else
{
if (bDropped && !bIsMenuMode)
{
indexC = 5;
indexM = 2;
}
else
{
if (bFocused)
{
indexC = 5;
indexM = 4;
}
if (bChecked)
{
indexC = 2;
indexM = 2;
}
if (bHighlightedC || bHighlightedM)
{
indexM = 4;
if (bPressed)
{
if (bHighlightedC)
{
indexC = 1;
}
else if (bHighlightedM)
{
indexC = bChecked ? 3 : 5;
}
}
else
{
indexC = bChecked ? 3 : 0;
if (bHighlightedM)
{
indexC = bChecked ? 3 : 5;
indexM = 0;
}
}
}
}
}
}
if (indexC != -1)
{
pRendererC->Draw(pDC, rectC, indexC);
}
if (indexM != -1)
{
pRendererM->Draw(pDC, rectM, indexM);
}
return(COLORREF)-1;
}
else
{
index = -1;
pRenderer = &m_ctrlRibbonBtn[0];
if (rect.Height() > pRenderer->GetParams().m_rectImage.Height() * 1.5 && m_ctrlRibbonBtn[1].IsValid())
{
pRenderer = &m_ctrlRibbonBtn[1];
}
if (bDisabled && bFocused)
{
if (pRenderer->GetImageCount() > 4)
{
index = 4;
}
else
{
index = 0;
}
}
if (!bDisabled)
{
if (bChecked)
{
index = 2;
}
if (bPressed)
{
if (bHighlighted)
{
index = 1;
}
}
else if (bHighlighted)
{
index++;
}
}
}
}
COLORREF clrText = bDisabled ? m_clrToolBarBtnTextDisabled : COLORREF(-1);
if (pRenderer != NULL)
{
if (index != -1)
{
int nCacheIndex = -1;
if (pCache != NULL)
{
CSize size(rect.Size());
nCacheIndex = pCache->FindIndex(size);
if (nCacheIndex == -1)
{
nCacheIndex = pCache->Cache(size, *pRenderer);
}
}
if (nCacheIndex != -1)
{
pCache->Get(nCacheIndex)->Draw(pDC, rect, index);
}
else
{
// Adapted by Pete
// pRenderer->Draw(pDC, rect, index);
CDrawingManager dm(*pDC);
dm.FillGradient2(rect, m_clrRibbonPanelBkTop, m_clrRibbonPanelBkBottom, 90);
pDC->Draw3dRect(rect, RGB(192, 192, 192), RGB(192, 192, 192));
// End of Pete adaptation
}
if (!bDisabled)
{
clrText = m_clrToolBarBtnTextHighlighted;
}
}
}
return clrText;
}
// Draws (most of) orb menu at top left of application (stolen and adapted from CMFCVisualManagerOffice 2007::OnDrawMenuLabel())
COLORREF CMFCVisualManagerDeviant::OnDrawMenuLabel(CDC* pDC, CRect rect)
{
ASSERT_VALID(pDC);
pDC->FillRect(rect, &CBrush(m_clrRibbonBarBackground));
CRect rectSeparator = rect;
= rectSeparator.bottom - 2;
DrawSeparator(pDC, rectSeparator, TRUE);
return m_clrRibbonBarTextPB;
}
BOOL CMFCVisualManagerDeviant::OnEraseMDIClientArea(CDC* pDC, CRect rectClient)
{
if (m_bCustomMDIClientAreaClr)
pDC->FillSolidRect(&rectClient, m_clrMDIClientArea);
else
CMFCVisualManagerOffice2007::OnEraseMDIClientArea(pDC, rectClient);
return TRUE;
}
3. 调用处
void CMainFrame::OnAppLook(UINT id)
{
CDockingManager::SetDockingMode (DT_SMART);
m_nAppLook = id;
CTabbedPane::m_StyleTabWnd = CMFCTabCtrl::STYLE_3D;
switch (m_nAppLook)
{
case ID_VIEW_APPLOOK_2007:
case ID_VIEW_APPLOOK_2007_1:
case ID_VIEW_APPLOOK_2007_2:
case ID_VIEW_APPLOOK_2007_3:
case ID_VIEW_APPLOOK_DEVIANT: // <-- Added to support deviant themes!
// enable Office 2007 look:
switch (m_nAppLook)
{
case ID_VIEW_APPLOOK_2007:
CMFCVisualManagerOffice2007::SetStyle (CMFCVisualManagerOffice2007::Office2007_LunaBlue);
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007)); // <--Added to support deviant themes!
break;
case ID_VIEW_APPLOOK_2007_1:
CMFCVisualManagerOffice2007::SetStyle (CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007)); // <--Added to support deviant themes!
break;
case ID_VIEW_APPLOOK_2007_2:
CMFCVisualManagerOffice2007::SetStyle (CMFCVisualManagerOffice2007::Office2007_Silver);
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007)); // <--Added to support deviant themes!
break;
case ID_VIEW_APPLOOK_2007_3:
CMFCVisualManagerOffice2007::SetStyle (CMFCVisualManagerOffice2007::Office2007_Aqua);
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007)); // <--Added to support deviant themes!
break;
case ID_VIEW_APPLOOK_DEVIANT: // Added to support deviant themes!
CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua);
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerDeviant));
CMFCVisualManagerDeviant* pVisMan = (CMFCVisualManagerDeviant*)CMFCVisualManager::GetInstance();
if (pVisMan->GetRuntimeClass() == RUNTIME_CLASS(CMFCVisualManagerDeviant))
{
// Ribbon Bar properties
pVisMan->SetClrRibbonBarBackground(RGB(0, 160, 0));
pVisMan->SetClrRibbonBarTextPB(RGB(255, 255, 255));
pVisMan->SetClrRibbonBarTextHighlightedPB(RGB(255, 66, 0));
// Ribbon Category Properties
pVisMan->SetClrRibbonCategoryBkTop(RGB(255, 255, 255));
pVisMan->SetClrRibbonCategoryBkBottom(RGB(0, 192, 64));
// Ribbon Panel Properties
pVisMan->SetClrRibbonPanelBkTop(RGB(255, 251, 240));
pVisMan->SetClrRibbonPanelBkBottom(RGB(0, 128, 0));
pVisMan->SetClrRibbonPanelCaptionBk(RGB(0, 128, 0));
pVisMan->SetClrRibbonPanelCaptionTextPB(RGB(255, 251, 240));
pVisMan->SetClrRibbonPanelCaptionTextHighlightedPB(RGB(255, 255, 255));
pVisMan->SetClrRibbonPanelTextPB(RGB(0, 0, 128));
// Ribbon Panel outline colour
pVisMan->SetClrRibbonPanelOutline(RGB(255, 255, 255));
}
break;
}
// CMFCVisualManager::SetDefaultManager (RUNTIME_CLASS (CMFCVisualManagerOffice2007)); <-- Removed to support deviant themes!
CDockingManager::SetDockingMode (DT_SMART);
break;
default:
ASSERT (FALSE);
}
CDockingManager* pDockManager = GetDockingManager ();
if (pDockManager != NULL)
{
ASSERT_VALID (pDockManager);
pDockManager->AdjustPaneFrames ();
}
CTabbedPane::ResetTabs ();
RecalcLayout ();
RedrawWindow (NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
theApp.WriteInt (_T("ApplicationLook"), m_nAppLook);
}
4. 显示效果