CaptionTextAttributes.cpp
上传用户:zhoushen
上传日期:2022-06-15
资源大小:84k
文件大小:3k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // Class providing text attributes for a window caption.
  2. // Text attributes are active and inactive fonts and
  3. // active and inactive colours.
  4. //
  5. // Used by custom caption class CCaption and its derived classes.
  6. //
  7. // Author: Dave Lorde (dlorde@cix.compulink.co.uk)
  8. //
  9. //          Copyright January 2000
  10. //
  11. #include "StdAfx.h"
  12. #include "CaptionTextAttributes.h"
  13. CSystemCaptionFont CCaptionTextAttributes::m_SystemFont;
  14. CCaptionTextAttributes::CCaptionTextAttributes()
  15. :m_ActiveColor(-1), m_InactiveColor(-1)
  16. {
  17. }
  18. CCaptionTextAttributes::CCaptionTextAttributes(const CCaptionTextAttributes& cta)
  19. :m_ActiveColor(cta.m_ActiveColor), m_InactiveColor(cta.m_InactiveColor)
  20. {
  21. // Need const casts because MS did not declare GetLogFont() const
  22. //
  23. LOGFONT lf;
  24. const_cast<CFont&>(cta.m_ActiveFont).GetLogFont(&lf);
  25. SetActiveFont(lf);
  26. const_cast<CFont&>(cta.m_InactiveFont).GetLogFont(&lf);
  27. SetInactiveFont(lf);
  28. }
  29. CCaptionTextAttributes::~CCaptionTextAttributes()
  30. {
  31. if (m_ActiveFont.m_hObject)
  32. m_ActiveFont.DeleteObject();
  33. if (m_InactiveFont.m_hObject)
  34. m_InactiveFont.DeleteObject();
  35. }
  36. COLORREF CCaptionTextAttributes::GetActiveColor() const
  37. {
  38. return m_ActiveColor == -1 ? GetSysColor(COLOR_CAPTIONTEXT) : m_ActiveColor;
  39. }
  40. COLORREF CCaptionTextAttributes::GetInactiveColor() const
  41. {
  42. return m_InactiveColor == -1 ? GetSysColor(COLOR_INACTIVECAPTIONTEXT) : m_InactiveColor;
  43. }
  44. CFont* CCaptionTextAttributes::GetActiveFont()
  45. {
  46. return (!m_ActiveFont.m_hObject) ? GetSystemFont() : &m_ActiveFont;
  47. }
  48. CFont* CCaptionTextAttributes::GetInactiveFont()
  49. {
  50. return (!m_InactiveFont.m_hObject) ? GetSystemFont() : &m_InactiveFont;
  51. }
  52. CFont* CCaptionTextAttributes::GetSystemFont()
  53. {
  54. return m_SystemFont();
  55. }
  56. void CCaptionTextAttributes::UseSystemActiveColor()
  57. {
  58. m_ActiveColor = -1;
  59. }
  60. void CCaptionTextAttributes::UseSystemInactiveColor()
  61. {
  62. m_InactiveColor = -1;
  63. }
  64. void CCaptionTextAttributes::UseSystemColors()
  65. {
  66. UseSystemActiveColor();
  67. UseSystemInactiveColor();
  68. }
  69. void CCaptionTextAttributes::UseSystemActiveFont()
  70. {
  71. if (m_ActiveFont.m_hObject)
  72. m_ActiveFont.DeleteObject();
  73. }
  74. void CCaptionTextAttributes::UseSystemInactiveFont()
  75. {
  76. if (m_InactiveFont.m_hObject)
  77. m_InactiveFont.DeleteObject();
  78. }
  79. void CCaptionTextAttributes::UseSystemFonts()
  80. {
  81. UseSystemActiveFont();
  82. UseSystemInactiveFont();
  83. }
  84. void CCaptionTextAttributes::SetActiveColor(COLORREF activeColor)
  85. {
  86. m_ActiveColor = activeColor;
  87. }
  88. void CCaptionTextAttributes::SetInactiveColor(COLORREF inactiveColor)
  89. {
  90. m_InactiveColor = inactiveColor;
  91. }
  92. void CCaptionTextAttributes::SetCustomColors(COLORREF activeColor, COLORREF inactiveColor)
  93. {
  94. SetActiveColor(activeColor);
  95. SetInactiveColor(inactiveColor);
  96. }
  97. void CCaptionTextAttributes::SetActiveFont(CFont& font)
  98. {
  99. LOGFONT lf;
  100. font.GetLogFont(&lf);
  101. SetActiveFont(lf);
  102. }
  103. void CCaptionTextAttributes::SetActiveFont(const LOGFONT& lf)
  104. {
  105. if (m_ActiveFont.m_hObject)
  106. m_ActiveFont.DeleteObject();
  107. m_ActiveFont.CreateFontIndirect(&lf);
  108. }
  109. void CCaptionTextAttributes::SetInactiveFont(CFont& font)
  110. {
  111. LOGFONT lf;
  112. font.GetLogFont(&lf);
  113. SetInactiveFont(lf);
  114. }
  115. void CCaptionTextAttributes::SetInactiveFont(const LOGFONT& lf)
  116. {
  117. if (m_InactiveFont.m_hObject)
  118. m_InactiveFont.DeleteObject();
  119. m_InactiveFont.CreateFontIndirect(&lf);
  120. }