#include "StdAfx.h" #include "PropertyGridInplaceEdit.h" #include "PropertyGridInplaceButton.h" #include "PropertyGridInplaceList.h" #include "PropertyGridItem.h" #include "PropertyGridItemSubSelect.h" #include "PropertyGridItemColor.h" #include "PropertyGridItemButton.h" #include "PropertyGrid_DrawHelpers.h" const TCHAR TRUE_VALUE[] = _T("True"); const TCHAR FALSE_VALUE[] = _T("False"); ///////////////////////////////////////////////////////////////////////////// // CPropertyGridItemSize::CPropertyGridItemSizeWidth class CPropertyGridItemSubSelect::CPropertyGridItemSubSelectColor : public CPropertyGridItemColor { public: CPropertyGridItemSubSelectColor(CString strCaption) : CPropertyGridItemColor(strCaption) {} virtual void OnValueChanged(COLORREF clr) { ((CPropertyGridItemSubSelect*)m_pParent)->SetColor(clr); } }; ///////////////////////////////////////////////////////////////////////////// // CPropertyGridItemSize::CPropertyGridItemSizeHeight class CPropertyGridItemSubSelect::CPropertyGridItemSubSelectString : public CPropertyGridItemButton { public: CPropertyGridItemSubSelectString(CString strCaption,HWND hNotifyWnd, UINT nNotifyMsg) : CPropertyGridItemButton(strCaption,hNotifyWnd,nNotifyMsg) {} //virtual void OnValueChanged(CString strName) //{ // ((CPropertyGridItemSubSelect*)m_pParent)->SetDescription(strName); //} // 当用户点击按钮时,调用此虚函数,(未写) virtual void OnInplaceButtonDown() { // m_pGrid->SetFocus(); // // CColorDialog dlg( m_clrValue); // if ( dlg.DoModal( ) == IDOK ) // OnValueChanged( RGBToString( dlg.GetColor( ) ) ); CPropertyGridItemButton::OnInplaceButtonDown(); } }; ///////////////////////////////////////////////////////////////////////////// // CPropertyGridItemSize CPropertyGridItemSubSelect::CPropertyGridItemSubSelect(CString strCaption ,HWND hNotifyWnd, UINT nNotifyMsg, BOOL bValue) : CPropertyGridItem(strCaption) { //ASSERT(hNotifyWnd); _Init(bValue); m_hNotifyWnd = hNotifyWnd; m_nNotifyMsg = nNotifyMsg; } CPropertyGridItemSubSelect::CPropertyGridItemSubSelect(UINT nID ,HWND hNotifyWnd, UINT nNotifyMsg, BOOL bValue) : CPropertyGridItem(nID) { _Init(bValue); m_hNotifyWnd = hNotifyWnd; m_nNotifyMsg = nNotifyMsg; } CPropertyGridItemSubSelect::~CPropertyGridItemSubSelect(void) { } ///////////////////////////////////////////////////////////////////////////// // void CPropertyGridItemSubSelect::_Init(BOOL bValue) { m_pBindBool = NULL; SetBool(bValue); m_nFlags = pgitemHasComboButton | pgitemHasEdit; m_lstContraints.AddConstraint(TRUE_VALUE); m_lstContraints.AddConstraint(FALSE_VALUE); } void CPropertyGridItemSubSelect::OnAddChildItem() { m_itemColor = (CPropertyGridItemSubSelectColor*)AddChildItem(new CPropertyGridItemSubSelectColor(_T("Color"))); m_itemString = (CPropertyGridItemSubSelectString*)AddChildItem(new CPropertyGridItemSubSelectString(_T("String"), m_hNotifyWnd, m_nNotifyMsg)); UpdateChilds(); } // CString CPropertyGridItemSubSelect::SizeToString(CSize size) // { // CString str; // str.Format(_T("%i; %i"), size.cx, size.cy); // return str; // } // CSize CPropertyGridItemSubSelect::StringToSize(CString str) // { // CString strWidth, strHeight; // // AfxExtractSubString(strWidth, str, 0, _T(';') ); // AfxExtractSubString(strHeight, str, 1, _T(';') ); // // return CSize(_ttoi(strWidth), _ttoi(strHeight)); // } void CPropertyGridItemSubSelect::SetValue(CString strValue) { SetBool(strValue.CompareNoCase(TRUE_VALUE) == 0); } void CPropertyGridItemSubSelect::SetBool(BOOL bValue) { m_bValue = bValue; CPropertyGridItem::SetValue(bValue? TRUE_VALUE: FALSE_VALUE); if (m_pBindBool) *m_pBindBool = m_bValue; } void CPropertyGridItemSubSelect::UpdateChilds() { //m_itemColor->SetColor(); //m_itemString->SetEditText(); } void CPropertyGridItemSubSelect::SetColor(COLORREF clr) { //OnValueChanged(RGBToString(CSize(_ttoi(strWidth), m_szValue.cy))); m_itemColor->SetColor(clr); } void CPropertyGridItemSubSelect::SetString(CString strName) { //OnValueChanged(SizeToString(CSize(m_szValue.cx, _ttoi(strHeight)))); //m_itemString->SetEditText(strName); m_itemString->SetDescription(strName); }