SPPPropertyGridItemFont.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /********************************************
  2. ** 工作室:S&P工作室
  3. ** 作者 :张东斌
  4. ** 日期 :2007年6月
  5. *********************************************/
  6. #include "stdafx.h"
  7. #include "SPVC80Helpers.h"
  8. #include "SPDrawHelpers.h"
  9. #include "SPPropertyGridInplaceEdit.h"
  10. #include "SPPropertyGridInplaceButton.h"
  11. #include "SPPropertyGridInplaceList.h"
  12. #include "SPPropertyGridItem.h"
  13. #include "SPPropertyGridItemFont.h"
  14. #include "SPPropertyGrid.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CSPPropertyGridItemFont
  22. IMPLEMENT_DYNAMIC( CSPPropertyGridItemFont , CSPPropertyGridItem )
  23. CSPPropertyGridItemFont::CSPPropertyGridItemFont( CString strCaption , LOGFONT & font ) : CSPPropertyGridItem( strCaption )
  24. {
  25. SetFont( font );
  26. m_nFlags = SPGridItemHasExpandButton;
  27. m_clrValue = ( COLORREF ) - 1;
  28. EnableAutomation();
  29. }
  30. CSPPropertyGridItemFont::CSPPropertyGridItemFont( UINT nID , LOGFONT & font ) : CSPPropertyGridItem( nID )
  31. {
  32. SetFont( font );
  33. m_nFlags = SPGridItemHasExpandButton;
  34. m_clrValue = ( COLORREF ) - 1;
  35. EnableAutomation();
  36. }
  37. CSPPropertyGridItemFont::~CSPPropertyGridItemFont()
  38. {
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. //
  42. void CSPPropertyGridItemFont::SetFont( LOGFONT & font )
  43. {
  44. MEMCPY_S( &m_lfValue,&font,sizeof( LOGFONT ) );
  45. CWindowDC dc ( CWnd::GetDesktopWindow() );
  46. int nHeight = -MulDiv( m_lfValue.lfHeight,72,dc.GetDeviceCaps( LOGPIXELSY ) );
  47. m_strValue.Format( _T( "%s; %ipt" ),m_lfValue.lfFaceName,nHeight );
  48. }
  49. BOOL CSPPropertyGridItemFont::OnDrawItemValue( CDC & dc , CRect rcValue )
  50. {
  51. if ( m_clrValue == ( COLORREF ) - 1 )
  52. {
  53. return CSPPropertyGridItem::OnDrawItemValue( dc,rcValue );
  54. }
  55. COLORREF clr = dc.GetTextColor();
  56. CRect rcSample ( rcValue.left - 2,rcValue.top + 1,rcValue.left + 18,rcValue.bottom - 1 );
  57. CSPPenDC pen ( dc,clr );
  58. CSPBrushDC brush ( dc,m_clrValue );
  59. dc.Rectangle( rcSample );
  60. CRect rcText ( rcValue );
  61. rcText.left += 25;
  62. dc.DrawText( m_strValue,rcText,DT_SINGLELINE | DT_VCENTER );
  63. return TRUE;
  64. }
  65. CRect CSPPropertyGridItemFont::GetValueRect()
  66. {
  67. CRect rcValue ( CSPPropertyGridItem::GetValueRect() );
  68. if ( m_clrValue != ( COLORREF ) - 1 )
  69. {
  70. rcValue.left += 25;
  71. }
  72. return rcValue;
  73. }
  74. UINT CALLBACK CSPPropertyGridItemFont::FontDlgProc( HWND hWnd , UINT message , WPARAM wParam , LPARAM lParam )
  75. {
  76. if ( message == WM_INITDIALOG )
  77. {
  78. HWND hWndCombo = GetDlgItem( hWnd,1139 );
  79. if ( hWndCombo )
  80. EnableWindow( hWndCombo,FALSE );
  81. //return (UINT)AfxDlgProc(hWnd, message, wParam, lParam);
  82. }
  83. return 0;
  84. }
  85. void CSPPropertyGridItemFont::OnInplaceButtonDown()
  86. {
  87. CFontDialog dlg ( &m_lfValue,CF_EFFECTS | CF_SCREENFONTS,NULL,m_pGrid );
  88. if ( m_clrValue == ( COLORREF ) - 1 )
  89. {
  90. dlg.m_cf.lpfnHook = FontDlgProc;
  91. }
  92. else
  93. {
  94. dlg.m_cf.rgbColors = m_clrValue;
  95. }
  96. if ( dlg.DoModal() == IDOK )
  97. {
  98. LOGFONT lf;
  99. dlg.GetCurrentFont( &lf );
  100. SetFont( lf );
  101. if ( m_clrValue != ( COLORREF ) - 1 )
  102. m_clrValue = dlg.GetColor();
  103. OnValueChanged( m_strValue );
  104. m_pGrid->Invalidate( FALSE );
  105. }
  106. }
  107. void CSPPropertyGridItemFont::SetColor( COLORREF clr )
  108. {
  109. m_clrValue = clr;
  110. if ( m_pGrid && m_pGrid->GetSafeHwnd() )
  111. {
  112. m_pGrid->Invalidate( FALSE );
  113. }
  114. }
  115. COLORREF CSPPropertyGridItemFont::GetColor()
  116. {
  117. return m_clrValue;
  118. }
  119. void CSPPropertyGridItemFont::GetFont( LOGFONT * lf )
  120. {
  121. ASSERT( lf != NULL );
  122. MEMCPY_S( lf,&m_lfValue,sizeof( LOGFONT ) );
  123. }