PropertyGridItemSubSelect.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include "StdAfx.h"
  2. #include "PropertyGridInplaceEdit.h"
  3. #include "PropertyGridInplaceButton.h"
  4. #include "PropertyGridInplaceList.h"
  5. #include "PropertyGridItem.h"
  6. #include "PropertyGridItemSubSelect.h"
  7. #include "PropertyGridItemColor.h"
  8. #include "PropertyGridItemButton.h"
  9. #include "PropertyGrid_DrawHelpers.h"
  10. const TCHAR TRUE_VALUE[] = _T("True");
  11. const TCHAR FALSE_VALUE[] = _T("False");
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CPropertyGridItemSize::CPropertyGridItemSizeWidth
  14. class CPropertyGridItemSubSelect::CPropertyGridItemSubSelectColor : public CPropertyGridItemColor
  15. {
  16. public:
  17. CPropertyGridItemSubSelectColor(CString strCaption)
  18. : CPropertyGridItemColor(strCaption) {}
  19. virtual void OnValueChanged(COLORREF clr)
  20. {
  21. ((CPropertyGridItemSubSelect*)m_pParent)->SetColor(clr);
  22. }
  23. };
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CPropertyGridItemSize::CPropertyGridItemSizeHeight
  26. class CPropertyGridItemSubSelect::CPropertyGridItemSubSelectString : public CPropertyGridItemButton
  27. {
  28. public:
  29. CPropertyGridItemSubSelectString(CString strCaption,HWND hNotifyWnd, UINT nNotifyMsg)
  30. : CPropertyGridItemButton(strCaption,hNotifyWnd,nNotifyMsg) {}
  31. //virtual void OnValueChanged(CString strName)
  32. //{
  33. // ((CPropertyGridItemSubSelect*)m_pParent)->SetDescription(strName);
  34. //}
  35. // 当用户点击按钮时,调用此虚函数,(未写)
  36. virtual void OnInplaceButtonDown()
  37. {
  38. // m_pGrid->SetFocus();
  39. //
  40. // CColorDialog dlg( m_clrValue);
  41. // if ( dlg.DoModal( ) == IDOK )
  42. // OnValueChanged( RGBToString( dlg.GetColor( ) ) );
  43. CPropertyGridItemButton::OnInplaceButtonDown();
  44. }
  45. };
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CPropertyGridItemSize
  48. CPropertyGridItemSubSelect::CPropertyGridItemSubSelect(CString strCaption ,HWND hNotifyWnd, UINT nNotifyMsg, BOOL bValue)
  49. : CPropertyGridItem(strCaption)
  50. {
  51. //ASSERT(hNotifyWnd);
  52. _Init(bValue);
  53. m_hNotifyWnd = hNotifyWnd;
  54. m_nNotifyMsg = nNotifyMsg;
  55. }
  56. CPropertyGridItemSubSelect::CPropertyGridItemSubSelect(UINT nID ,HWND hNotifyWnd, UINT nNotifyMsg, BOOL bValue)
  57. : CPropertyGridItem(nID)
  58. {
  59. _Init(bValue);
  60. m_hNotifyWnd = hNotifyWnd;
  61. m_nNotifyMsg = nNotifyMsg;
  62. }
  63. CPropertyGridItemSubSelect::~CPropertyGridItemSubSelect(void)
  64. {
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. //
  68. void CPropertyGridItemSubSelect::_Init(BOOL bValue)
  69. {
  70. m_pBindBool = NULL;
  71. SetBool(bValue);
  72. m_nFlags = pgitemHasComboButton | pgitemHasEdit;
  73. m_lstContraints.AddConstraint(TRUE_VALUE);
  74. m_lstContraints.AddConstraint(FALSE_VALUE);
  75. }
  76. void CPropertyGridItemSubSelect::OnAddChildItem()
  77. {
  78. m_itemColor = (CPropertyGridItemSubSelectColor*)AddChildItem(new CPropertyGridItemSubSelectColor(_T("Color")));
  79. m_itemString = (CPropertyGridItemSubSelectString*)AddChildItem(new CPropertyGridItemSubSelectString(_T("String"), m_hNotifyWnd, m_nNotifyMsg));
  80. UpdateChilds();
  81. }
  82. // CString CPropertyGridItemSubSelect::SizeToString(CSize size)
  83. // {
  84. // CString str;
  85. // str.Format(_T("%i; %i"), size.cx, size.cy);
  86. // return str;
  87. // }
  88. // CSize CPropertyGridItemSubSelect::StringToSize(CString str)
  89. // {
  90. // CString strWidth, strHeight;
  91. //
  92. // AfxExtractSubString(strWidth, str, 0, _T(';') );
  93. // AfxExtractSubString(strHeight, str, 1, _T(';') );
  94. //
  95. // return CSize(_ttoi(strWidth), _ttoi(strHeight));
  96. // }
  97. void CPropertyGridItemSubSelect::SetValue(CString strValue)
  98. {
  99. SetBool(strValue.CompareNoCase(TRUE_VALUE) == 0);
  100. }
  101. void CPropertyGridItemSubSelect::SetBool(BOOL bValue)
  102. {
  103. m_bValue = bValue;
  104. CPropertyGridItem::SetValue(bValue? TRUE_VALUE: FALSE_VALUE);
  105. if (m_pBindBool)
  106. *m_pBindBool = m_bValue;
  107. }
  108. void CPropertyGridItemSubSelect::UpdateChilds()
  109. {
  110. //m_itemColor->SetColor();
  111. //m_itemString->SetEditText();
  112. }
  113. void CPropertyGridItemSubSelect::SetColor(COLORREF clr)
  114. {
  115. //OnValueChanged(RGBToString(CSize(_ttoi(strWidth), m_szValue.cy)));
  116. m_itemColor->SetColor(clr);
  117. }
  118. void CPropertyGridItemSubSelect::SetString(CString strName)
  119. {
  120. //OnValueChanged(SizeToString(CSize(m_szValue.cx, _ttoi(strHeight))));
  121. //m_itemString->SetEditText(strName);
  122. m_itemString->SetDescription(strName);
  123. }