#include "stdafx.h" #include "Resource.h" #include "DLGArribtEdit.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif CDLGArribtEdit::CDLGArribtEdit(AecDbObjXDataMap* pmapXData, CWnd* pParent) : CDialog(CDLGArribtEdit::IDD, pParent), m_pmapXData(pmapXData) { //{{AFX_DATA_INIT(CDLGArribtEdit) //}}AFX_DATA_INIT } void CDLGArribtEdit::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDLGArribtEdit) DDX_Control(pDX, IDC_LST_ATTRIB, m_wndLstAttrib); DDX_Control(pDX, IDC_EDT_ATTRIB, m_wndEdtAttrib); DDX_Control(pDX, IDOK, m_wndBtnOk); DDX_Control(pDX, IDCANCEL, m_wndBtnCancel); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDLGArribtEdit, CDialog) //{{AFX_MSG_MAP(CDLGArribtEdit) ON_NOTIFY(NM_CLICK, IDC_LST_ATTRIB, OnClickLstAttrib) ON_EN_KILLFOCUS(IDC_EDT_ATTRIB, OnKillfocusEdtAttrib) ON_EN_CHANGE(IDC_EDT_ATTRIB, OnChangeEdtAttrib) ON_WM_MOUSEACTIVATE() ON_WM_SIZE() //}}AFX_MSG_MAP END_MESSAGE_MAP() BOOL CDLGArribtEdit::OnInitDialog() { CDialog::OnInitDialog(); m_wndLstAttrib.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); m_wndLstAttrib.ModifyStyle(0, WS_CLIPSIBLINGS); m_wndLstAttrib.InsertColumn(0, _T("ÏîÃû"), LVCFMT_LEFT, 100); m_wndLstAttrib.InsertColumn(1, _T("Êý¾Ý"), LVCFMT_LEFT, 200); ASSERT(NULL != m_pmapXData); int iIndex; CString sKey; AecXData cVal; memset(&cVal,0,sizeof(AecXData)); AecDbObjXDataMap::It it = m_pmapXData->Begin(); AecDbObjXDataMap::It end = m_pmapXData->End(); for (; it != end; m_pmapXData->GetNext(it,sKey,cVal)) { iIndex = m_wndLstAttrib.InsertItem(0, sKey); if (cVal.nVt == VT_BSTR) sKey.Format(_T("%s"), cVal.pszVal); else if (cVal.nVt == VT_I4) sKey.Format(_T("%d"), cVal.nVal); else if (cVal.nVt == VT_R8) sKey.Format(_T("%g"), cVal.dVal[0]); else if (cVal.nVt == (VT_BYREF | VT_R8)) sKey.Format(_T("%g,%g,%g"), cVal.dVal[0], cVal.dVal[1], cVal.dVal[2]); m_wndLstAttrib.SetItemText(iIndex, 1, sKey); m_wndLstAttrib.SetItemData(iIndex, cVal.nVt); } PostMessage(WM_SIZE, SIZE_RESTORED); return TRUE; } void CDLGArribtEdit::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); if (!IsWindow(m_wndLstAttrib.m_hWnd)) return; CRect rc; GetClientRect(&rc); rc.DeflateRect(10, 10); CRect rcOk; m_wndBtnOk.GetWindowRect(&rcOk); ScreenToClient(&rcOk); CRect rcCancel; m_wndBtnCancel.GetWindowRect(&rcCancel); ScreenToClient(&rcCancel); int iOff = (rc.Width() - (rcCancel.right - rcOk.left)) / 2; iOff -= (rcOk.left - rc.left); rcOk.OffsetRect(iOff, rc.bottom - rcOk.bottom); m_wndBtnOk.MoveWindow(rcOk); rcCancel.OffsetRect(iOff, rc.bottom - rcCancel.bottom); m_wndBtnCancel.MoveWindow(rcCancel); rc.bottom = (rcOk.top - 10); m_wndLstAttrib.MoveWindow(rc); } void CDLGArribtEdit::OnClickLstAttrib(NMHDR* pNMHDR, LRESULT* pResult) { *pResult = 0; CPoint pt; GetCursorPos(&pt); m_wndLstAttrib.ScreenToClient(&pt); int iIndex = m_wndLstAttrib.HitTest(pt); if (iIndex < 0 || iIndex != m_wndLstAttrib.GetNextItem(-1, LVNI_SELECTED)) return; m_wndLstAttrib.EnsureVisible(iIndex, FALSE); CString sText = m_wndLstAttrib.GetItemText(iIndex, 1); m_wndEdtAttrib.SetWindowText(sText); CRect rc; m_wndLstAttrib.GetSubItemRect(iIndex, 1, LVIR_BOUNDS, rc); m_wndLstAttrib.ClientToScreen(&rc); ScreenToClient(&rc); CRect rcLst; m_wndLstAttrib.GetClientRect(&rcLst); m_wndLstAttrib.ClientToScreen(&rcLst); ScreenToClient(&rcLst); rc.left += 6; rc.bottom--; if (rc.right > rcLst.right) rc.right = rcLst.right; m_wndEdtAttrib.SetWindowPos(NULL, rc.left, rc.top, rc.Width(), rc.Height(), SWP_NOZORDER | SWP_SHOWWINDOW); m_wndEdtAttrib.SetFocus(); m_wndEdtAttrib.SetSel(0, -1); } void CDLGArribtEdit::OnKillfocusEdtAttrib() { m_wndEdtAttrib.ShowWindow(SW_HIDE); } void CDLGArribtEdit::OnChangeEdtAttrib() { if (!m_wndEdtAttrib.IsWindowVisible()) return; CRect rc; m_wndEdtAttrib.GetWindowRect(&rc); m_wndLstAttrib.ScreenToClient(&rc); int iIndex = m_wndLstAttrib.HitTest(rc.CenterPoint()); if (iIndex < 0) return; CString sText; m_wndEdtAttrib.GetWindowText(sText); m_wndLstAttrib.SetItemText(iIndex, 1, sText); } int CDLGArribtEdit::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message) { CRect rc; m_wndLstAttrib.GetHeaderCtrl()->GetWindowRect(&rc); int iHeader = rc.Height(); m_wndLstAttrib.GetClientRect(&rc); m_wndLstAttrib.ClientToScreen(&rc); rc.top += iHeader; CPoint pt; GetCursorPos(&pt); if (!rc.PtInRect(pt)) { m_wndEdtAttrib.ShowWindow(SW_HIDE); } return CDialog::OnMouseActivate(pDesktopWnd, nHitTest, message); } void CDLGArribtEdit::OnOK() { int iVt; AcGePoint3d pt; CString sKey, sValue; int iPos = m_wndLstAttrib.GetItemCount(); while ((--iPos) >= 0) { sKey = m_wndLstAttrib.GetItemText(iPos, 0); sValue = m_wndLstAttrib.GetItemText(iPos, 1); iVt = m_wndLstAttrib.GetItemData(iPos); if (iVt == VT_BSTR) m_pmapXData->SetAt(sKey, sValue); else if (iVt == VT_I4) m_pmapXData->SetAt(sKey, (int)_ttol(sValue)); else if (iVt == VT_R8) m_pmapXData->SetAt(sKey, _tcstod(sValue, NULL)); else if (iVt == (VT_BYREF | VT_R8)) { pt.x = pt.y = pt.z = 0.0; _stscanf(sValue, _T("%lf,%lf,%lf"), &(pt.x), &(pt.y), &(pt.z)); m_pmapXData->SetAt(sKey, pt); } } CDialog::OnOK(); }