XTPPropertyGridItemFont.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:5k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // XTPPropertyGridItemFont.cpp : implementation of the CXTPPropertyGridItemFont class.
  2. //
  3. // This file is a part of the XTREME PROPERTYGRID MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Common/XTPVC80Helpers.h"
  22. #include "Common/XTPDrawHelpers.h"
  23. #include "XTPPropertyGridInplaceEdit.h"
  24. #include "XTPPropertyGridInplaceButton.h"
  25. #include "XTPPropertyGridInplaceList.h"
  26. #include "XTPPropertyGridItem.h"
  27. #include "XTPPropertyGridItemFont.h"
  28. #include "XTPPropertyGrid.h"
  29. #include "XTPPropertyGridDefines.h"
  30. #ifdef _DEBUG
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CXTPPropertyGridItemFont
  37. IMPLEMENT_DYNAMIC(CXTPPropertyGridItemFont, CXTPPropertyGridItem)
  38. CXTPPropertyGridItemFont::CXTPPropertyGridItemFont(LPCTSTR strCaption, LOGFONT& font)
  39. : CXTPPropertyGridItem(strCaption)
  40. {
  41. SetFont(font);
  42. m_nFlags = xtpGridItemHasExpandButton;
  43. m_clrValue = (COLORREF)-1;
  44. EnableAutomation();
  45. m_strDefaultValue = m_strValue;
  46. }
  47. CXTPPropertyGridItemFont::CXTPPropertyGridItemFont(UINT nID, LOGFONT& font)
  48. : CXTPPropertyGridItem(nID)
  49. {
  50. SetFont(font);
  51. m_nFlags = xtpGridItemHasExpandButton;
  52. m_clrValue = (COLORREF)-1;
  53. EnableAutomation();
  54. m_strDefaultValue = m_strValue;
  55. }
  56. CXTPPropertyGridItemFont::~CXTPPropertyGridItemFont()
  57. {
  58. }
  59. /////////////////////////////////////////////////////////////////////////////
  60. //
  61. void CXTPPropertyGridItemFont::SetFont(LOGFONT& font)
  62. {
  63. MEMCPY_S(&m_lfValue, &font, sizeof(LOGFONT));
  64. m_strValue = FontToString(m_lfValue);
  65. }
  66. CString CXTPPropertyGridItemFont::FontToString(const LOGFONT& lfValue)
  67. {
  68. CWindowDC dc(CWnd::GetDesktopWindow());
  69. int nHeight = -MulDiv(lfValue.lfHeight, 72, dc.GetDeviceCaps(LOGPIXELSY));
  70. CString strValue;
  71. strValue.Format(_T("%s; %ipt"), lfValue.lfFaceName, nHeight);
  72. if (lfValue.lfWeight == FW_BOLD)
  73. strValue += _T("; bold");
  74. return strValue;
  75. }
  76. BOOL CXTPPropertyGridItemFont::OnDrawItemValue(CDC& dc, CRect rcValue)
  77. {
  78. if (m_clrValue == (COLORREF)-1)
  79. return CXTPPropertyGridItem::OnDrawItemValue(dc, rcValue);
  80. COLORREF clr = dc.GetTextColor();
  81. CRect rcSample(rcValue.left - 2, rcValue.top + 1, rcValue.left + 18, rcValue.bottom - 1);
  82. CXTPPenDC pen(dc, clr);
  83. CXTPBrushDC brush(dc, m_clrValue);
  84. dc.Rectangle(rcSample);
  85. CRect rcText(rcValue);
  86. rcText.left += 25;
  87. dc.DrawText(m_strValue, rcText, DT_SINGLELINE | DT_VCENTER);
  88. return TRUE;
  89. }
  90. CRect CXTPPropertyGridItemFont::GetValueRect()
  91. {
  92. CRect rcValue(CXTPPropertyGridItem::GetValueRect());
  93. if (m_clrValue != (COLORREF)-1) rcValue.left += 25;
  94. return rcValue;
  95. }
  96. UINT_PTR CALLBACK CXTPPropertyGridItemFont::FontDlgProc(HWND hWnd, UINT message, WPARAM, LPARAM)
  97. {
  98. // special case for WM_INITDIALOG
  99. if (message == WM_INITDIALOG)
  100. {
  101. HWND hWndCombo = GetDlgItem(hWnd, 1139);
  102. if (hWndCombo)
  103. EnableWindow(hWndCombo, FALSE);
  104. CDialog* pDlg = DYNAMIC_DOWNCAST(CDialog, CWnd::FromHandlePermanent(hWnd));
  105. if (pDlg != NULL)
  106. return (UINT_PTR)pDlg->OnInitDialog();
  107. else
  108. return 1;
  109. }
  110. return 0;
  111. }
  112. void CXTPPropertyGridItemFont::OnInplaceButtonDown(CXTPPropertyGridInplaceButton* pButton)
  113. {
  114. if (m_pGrid->SendNotifyMessage(XTP_PGN_INPLACEBUTTONDOWN, (LPARAM)pButton) == TRUE)
  115. return;
  116. if (!OnRequestEdit())
  117. return;
  118. InternalAddRef();
  119. CFontDialog dlg(&m_lfValue, CF_EFFECTS | CF_SCREENFONTS, NULL, m_pGrid);
  120. if (m_clrValue == (COLORREF)-1)
  121. {
  122. dlg.m_cf.lpfnHook = FontDlgProc;
  123. }
  124. else
  125. {
  126. dlg.m_cf.rgbColors = m_clrValue;
  127. }
  128. if (dlg.DoModal() == IDOK)
  129. {
  130. LOGFONT lf;
  131. dlg.GetCurrentFont(&lf);
  132. CString strValue = FontToString(lf);
  133. if (OnAfterEdit(strValue))
  134. {
  135. SetFont(lf);
  136. if (m_clrValue != (COLORREF)-1)
  137. m_clrValue = dlg.GetColor();
  138. OnValueChanged(strValue);
  139. SAFE_INVALIDATE(m_pGrid);
  140. }
  141. }
  142. else
  143. {
  144. OnCancelEdit();
  145. }
  146. InternalRelease();
  147. }
  148. void CXTPPropertyGridItemFont::SetColor(COLORREF clr)
  149. {
  150. m_clrValue = clr;
  151. SAFE_INVALIDATE(m_pGrid);
  152. }
  153. COLORREF CXTPPropertyGridItemFont::GetColor()
  154. {
  155. return m_clrValue;
  156. }
  157. void CXTPPropertyGridItemFont::GetFont(LOGFONT* lf)
  158. {
  159. ASSERT(lf != NULL);
  160. MEMCPY_S(lf, &m_lfValue, sizeof(LOGFONT));
  161. }