|
// Class providing text attributes for a window caption.
// Text attributes are active and inactive fonts and
// active and inactive colours.
//
// Used by custom caption class CCaption and its derived classes.
//
// Author: Dave Lorde (dlorde@cix.compulink.co.uk)
//
// Copyright January 2000
//
#include "StdAfx.h"
#include "CaptionTextAttributes.h"
CSystemCaptionFont CCaptionTextAttributes::m_SystemFont;
CCaptionTextAttributes::CCaptionTextAttributes()
:m_ActiveColor(-1), m_InactiveColor(-1)
{
}
CCaptionTextAttributes::CCaptionTextAttributes(const CCaptionTextAttributes& cta)
:m_ActiveColor(cta.m_ActiveColor), m_InactiveColor(cta.m_InactiveColor)
{
// Need const casts because MS did not declare GetLogFont() const
//
LOGFONT lf;
const_cast<CFont&>(cta.m_ActiveFont).GetLogFont(&lf);
SetActiveFont(lf);
const_cast<CFont&>(cta.m_InactiveFont).GetLogFont(&lf);
SetInactiveFont(lf);
}
CCaptionTextAttributes::~CCaptionTextAttributes()
{
if (m_ActiveFont.m_hObject)
m_ActiveFont.DeleteObject();
if (m_InactiveFont.m_hObject)
m_InactiveFont.DeleteObject();
}
COLORREF CCaptionTextAttributes::GetActiveColor() const
{
return m_ActiveColor == -1 ? GetSysColor(COLOR_CAPTIONTEXT) : m_ActiveColor;
}
COLORREF CCaptionTextAttributes::GetInactiveColor() const
{
return m_InactiveColor == -1 ? GetSysColor(COLOR_INACTIVECAPTIONTEXT) : m_InactiveColor;
}
CFont* CCaptionTextAttributes::GetActiveFont()
{
return (!m_ActiveFont.m_hObject) ? GetSystemFont() : &m_ActiveFont;
}
CFont* CCaptionTextAttributes::GetInactiveFont()
{
return (!m_InactiveFont.m_hObject) ? GetSystemFont() : &m_InactiveFont;
}
CFont* CCaptionTextAttributes::GetSystemFont()
{
return m_SystemFont();
}
void CCaptionTextAttributes::UseSystemActiveColor()
{
m_ActiveColor = -1;
}
void CCaptionTextAttributes::UseSystemInactiveColor()
{
m_InactiveColor = -1;
}
void CCaptionTextAttributes::UseSystemColors()
{
UseSystemActiveColor();
UseSystemInactiveColor();
}
void CCaptionTextAttributes::UseSystemActiveFont()
{
if (m_ActiveFont.m_hObject)
m_ActiveFont.DeleteObject();
}
void CCaptionTextAttributes::UseSystemInactiveFont()
{
if (m_InactiveFont.m_hObject)
m_InactiveFont.DeleteObject();
}
void CCaptionTextAttributes::UseSystemFonts()
{
UseSystemActiveFont();
UseSystemInactiveFont();
}
void CCaptionTextAttributes::SetActiveColor(COLORREF activeColor)
{
m_ActiveColor = activeColor;
}
void CCaptionTextAttributes::SetInactiveColor(COLORREF inactiveColor)
{
m_InactiveColor = inactiveColor;
}
void CCaptionTextAttributes::SetCustomColors(COLORREF activeColor, COLORREF inactiveColor)
{
SetActiveColor(activeColor);
SetInactiveColor(inactiveColor);
}
void CCaptionTextAttributes::SetActiveFont(CFont& font)
{
LOGFONT lf;
font.GetLogFont(&lf);
SetActiveFont(lf);
}
void CCaptionTextAttributes::SetActiveFont(const LOGFONT& lf)
{
if (m_ActiveFont.m_hObject)
m_ActiveFont.DeleteObject();
m_ActiveFont.CreateFontIndirect(&lf);
}
void CCaptionTextAttributes::SetInactiveFont(CFont& font)
{
LOGFONT lf;
font.GetLogFont(&lf);
SetInactiveFont(lf);
}
void CCaptionTextAttributes::SetInactiveFont(const LOGFONT& lf)
{
if (m_InactiveFont.m_hObject)
m_InactiveFont.DeleteObject();
m_InactiveFont.CreateFontIndirect(&lf);
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.