/** * @file XTPCaptionTheme.cpp * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #include "StdAfx.h" #include "Common/XTPTypeId.h" #include "Common/XTPFramework.h" #include "Common/XTPSystemHelpers.h" #include "Common/XTPSynchro.h" #include "Common/XTPApplication.h" #include "Common/XTPSingleton.h" #include "Common/XTPGdiObjects.h" #include "Common/XTPDrawHelpers.h" #include "Common/XTPColorManager.h" #include "Controls/Util/XTPControlTheme.h" #include "Controls/Button/XTPButtonTheme.h" #include "Controls/Button/XTPButton.h" #include "Controls/Static/XTPCaption.h" #include "Controls/Static/XTPCaptionTheme.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CXTPCaptionTheme CXTPCaptionTheme::CXTPCaptionTheme() { } void CXTPCaptionTheme::RefreshMetrics(CXTPCaption* /*pCaption*/) { m_clrEdgeShadow.SetStandardValue(GetXtremeColor(COLOR_3DSHADOW)); m_clrEdgeLight.SetStandardValue(GetXtremeColor(COLOR_3DHILIGHT)); } void CXTPCaptionTheme::DrawCaptionBack(CDC* pDC, CXTPCaption* pCaption, CRect& rcItem) { CRect rc = rcItem; // Set the background mode to transparent. pDC->SetBkMode(TRANSPARENT); // repaint the background. pDC->FillSolidRect(rc, pCaption->m_clrBorder); // draw the caption border. if (pCaption->m_dwExStyle & CPWS_EX_GROOVE_EDGE) { pDC->Draw3dRect(rc, m_clrEdgeShadow, m_clrEdgeLight); rc.DeflateRect(1, 1); pDC->Draw3dRect(rc, m_clrEdgeLight, m_clrEdgeShadow); if (pCaption->m_nBorder == 0) { rc.DeflateRect(1, 1); } } else if (pCaption->m_dwExStyle & CPWS_EX_RAISED_EDGE) { pDC->Draw3dRect(rc, m_clrEdgeLight, m_clrEdgeShadow); if (pCaption->m_nBorder == 0) { rc.DeflateRect(1, 1); } } // draw the caption banner border. rc.DeflateRect(pCaption->m_nBorder, pCaption->m_nBorder); pDC->FillSolidRect(rc, pCaption->m_clrFace); } void CXTPCaptionTheme::DrawCaptionText(CDC* pDC, CXTPCaption* pCaption) { // if the caption text is empty, return. if (pCaption->GetCaptionText().IsEmpty()) { return; } // Get the display area for the text. CRect rcText(pCaption->GetTextRect()); // Set the text color and select the caption font. CXTPFontDC fontDC(pDC, pCaption->GetFont()); pDC->SetTextColor(pCaption->m_clrText); CXTPClientRect rc(pCaption); if (pCaption->HasCloseButton()) rc.right -= pCaption->GetButtonRect().Width(); switch (pCaption->GetStyle() & (SS_LEFT | SS_CENTER | SS_RIGHT)) { case SS_LEFT: rcText.OffsetRect(0, 0); break; case SS_CENTER: rcText.OffsetRect((rc.Width() - rcText.Width()) / 2, 0); break; case SS_RIGHT: rcText.OffsetRect(rc.Width() - rcText.Width(), 0); break; } // draw the text, and select the original font. pDC->DrawText(pCaption->GetCaptionText(), rcText, DT_SINGLELINE | DT_END_ELLIPSIS | DT_VCENTER | DT_CENTER | DT_NOPREFIX); } void CXTPCaptionTheme::DrawCaptionIcon(CDC* pDC, CXTPCaption* pCaption, CRect& rcItem) { // If no icon was defined, just return. if (pCaption->m_hIcon == NULL) return; CRect rc = rcItem; rc.left = (rc.right - pCaption->m_sizeIcon.cx) - (pCaption->m_nBorder + XTP_DPI_X(2)); // stop the icon at the left hand border if (rc.left < pCaption->m_nBorder) { rc.left = pCaption->m_nBorder; } rc.top = (rcItem.Height() - pCaption->m_sizeIcon.cy) / 2; rc.right = rc.left + pCaption->m_sizeIcon.cx; rc.bottom = rc.top + pCaption->m_sizeIcon.cy; // Only draw the icon if it will fit into the space between the borders if (rc.right < rcItem.right - pCaption->m_nBorder) { // draw the icon associated with the caption. ::DrawIconEx(pDC->GetSafeHdc(), rc.left, rc.top, pCaption->m_hIcon, rc.Width(), rc.Height(), NULL, (HBRUSH)NULL, DI_NORMAL); } } ///////////////////////////////////////////////////////////////////////////// // CXTPCaptionThemeOfficeXP CXTPCaptionThemeOfficeXP::CXTPCaptionThemeOfficeXP() { m_nTheme = xtpControlThemeOfficeXP; } void CXTPCaptionThemeOfficeXP::DrawCaptionBack(CDC* pDC, CXTPCaption* pCaption, CRect& rcItem) { CRect rc = rcItem; pDC->SetBkMode(TRANSPARENT); // repaint the background. pDC->FillSolidRect(rc, pCaption->m_clrBorder); if (!pCaption->IsAppCaption()) { pDC->Draw3dRect(rc, GetXtremeColor(COLOR_3DHILIGHT), GetXtremeColor(COLOR_3DSHADOW)); } else { // draw the caption banner border. rc.DeflateRect(pCaption->m_nBorder, pCaption->m_nBorder); pDC->FillSolidRect(rc, pCaption->m_clrFace); } } ///////////////////////////////////////////////////////////////////////////// // CXTPCaptionThemeOffice2003 CXTPCaptionThemeOffice2003::CXTPCaptionThemeOffice2003() { m_nTheme = xtpControlThemeOffice2003; } void CXTPCaptionThemeOffice2003::DrawCaptionBack(CDC* pDC, CXTPCaption* pCaption, CRect& rcItem) { pDC->SetBkMode(TRANSPARENT); if (pCaption->IsAppCaption()) { XTPDrawHelpers()->GradientFill(pDC, rcItem, XTPColorManager()->grcCaption, FALSE); pDC->Draw3dRect(rcItem, GetXtremeColor(XPCOLOR_FRAME), GetXtremeColor(XPCOLOR_FRAME)); } else { XTPDrawHelpers()->GradientFill(pDC, rcItem, XTPColorManager()->grcToolBar, FALSE); pDC->FillSolidRect(rcItem.left, rcItem.bottom - XTP_DPI_Y(1), rcItem.Width(), XTP_DPI_Y(1), GetXtremeColor(XPCOLOR_FRAME)); } } ///////////////////////////////////////////////////////////////////////////// // CXTPCaptionButtonTheme CXTPCaptionButtonTheme::CXTPCaptionButtonTheme() { m_bOffsetHiliteText = FALSE; } void CXTPCaptionButtonTheme::DrawButtonBackground(CDC* pDC, CXTPButton* pButton) { CRect rcItem = pButton->GetButtonRect(); CXTPCaption* pCaption = ((CXTPCaptionButton*)pButton)->GetCaption(); // Paint the background. if (pButton->IsHighlighted() || (pButton->IsPushed() || pButton->GetChecked())) { pDC->FillSolidRect(rcItem, GetXtremeColor(COLOR_3DFACE)); COLORREF clrTopLeft = GetXtremeColor(COLOR_3DHILIGHT); COLORREF clrBottomRight = GetXtremeColor(COLOR_3DSHADOW); if (pButton->IsPushed() || pButton->GetChecked()) { COLORREF c = clrTopLeft; clrTopLeft = clrBottomRight; clrBottomRight = c; } pDC->Draw3dRect(rcItem, clrTopLeft, clrBottomRight); } else { if (::IsWindow(pCaption->GetSafeHwnd())) { m_crBack = pCaption->m_clrFace; } pDC->FillSolidRect(rcItem, m_crBack); } } COLORREF CXTPCaptionButtonTheme::GetTextColor(CXTPButton* pButton) { if (!pButton->IsWindowEnabled()) return GetXtremeColor(COLOR_GRAYTEXT); if (pButton->IsPushed() || pButton->GetChecked() || pButton->IsHighlighted()) return GetXtremeColor(COLOR_BTNTEXT); CXTPCaption* pCaption = ((CXTPCaptionButton*)pButton)->GetCaption(); if (::IsWindow(pCaption->GetSafeHwnd())) { return pCaption->m_clrText; } return m_crText; } void CXTPCaptionButtonTheme::DrawButtonText(CDC* pDC, CXTPButton* pButton) { CXTPCaption* pCaption = ((CXTPCaptionButton*)pButton)->GetCaption(); if (::IsWindow(pCaption->GetSafeHwnd())) { if (pCaption->IsAppCaption() && !pCaption->GetCaptionText().IsEmpty()) { // select font into device context. CXTPFontDC fontDC(pDC, pButton->GetFont()); pDC->SetTextColor(GetTextColor(pButton)); CXTPClientRect rcItem(pButton); if (pButton->IsHighlighted() && m_bOffsetHiliteText) rcItem.OffsetRect(XTP_DPI_X(1), XTP_DPI_Y(1)); // draw the text, and select the original font. pDC->DrawText(pCaption->GetCaptionText(), rcItem, DT_SINGLELINE | DT_END_ELLIPSIS | DT_VCENTER | DT_CENTER | DT_NOPREFIX); } } }