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

对话框与窗口

开发平台:

Visual C++

  1. // PropertyGripInplaceEdit.cpp : implementation of the CPropertyGripInplaceEdit 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 "XTPPropertyGridInplaceEdit.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. // CXTPPropertyGridInplaceEdit
  37. CXTPPropertyGridInplaceEdit::CXTPPropertyGridInplaceEdit()
  38. : m_pItem(0)
  39. , m_pGrid(0)
  40. {
  41. m_clrBack = 0;
  42. m_bDelayCreate = FALSE;
  43. m_bCreated = FALSE;
  44. m_bCancel = FALSE;
  45. m_bEditMode = FALSE;
  46. m_bCheckAutoComplete = FALSE;
  47. m_bIgnoreEditChanged = FALSE;
  48. }
  49. CXTPPropertyGridInplaceEdit::~CXTPPropertyGridInplaceEdit()
  50. {
  51. }
  52. IMPLEMENT_DYNAMIC(CXTPPropertyGridInplaceEdit, CEdit)
  53. BEGIN_MESSAGE_MAP(CXTPPropertyGridInplaceEdit, CXTMaskEditT<CEdit>)
  54. ON_MASKEDIT_REFLECT()
  55. //{{AFX_MSG_MAP(CXTPPropertyGridInplaceEdit)
  56. ON_WM_CTLCOLOR_REFLECT()
  57. ON_CONTROL_REFLECT(EN_KILLFOCUS, OnEnKillfocus)
  58. ON_CONTROL_REFLECT(EN_SETFOCUS, OnEnSetfocus)
  59. ON_CONTROL_REFLECT(EN_CHANGE, OnEnChange)
  60. ON_WM_LBUTTONDBLCLK()
  61. ON_WM_KEYDOWN()
  62. ON_WM_GETDLGCODE()
  63. ON_WM_CHAR()
  64. ON_WM_SYSKEYDOWN()
  65. ON_WM_STYLECHANGED()
  66. //}}AFX_MSG_MAP
  67. END_MESSAGE_MAP()
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CXTPPropertyGridInplaceEdit message handlers
  70. void CXTPPropertyGridInplaceEdit::SetValue(LPCTSTR strValue)
  71. {
  72. m_strValue = strValue;
  73. }
  74. void CXTPPropertyGridInplaceEdit::HideWindow()
  75. {
  76. if (m_hWnd)
  77. {
  78. ShowWindow(SW_HIDE);
  79. }
  80. }
  81. void CXTPPropertyGridInplaceEdit::OnStyleChanged(int nStyleType, LPSTYLESTRUCT lpStyleStruct)
  82. {
  83. if (nStyleType == GWL_EXSTYLE && lpStyleStruct->styleNew & WS_EX_LAYOUTRTL)
  84. {
  85. HideWindow();
  86. m_bDelayCreate = TRUE;
  87. }
  88. CEdit::OnStyleChanged(nStyleType, lpStyleStruct);
  89. }
  90. void CXTPPropertyGridInplaceEdit::Create(CXTPPropertyGridItem* pItem, CRect rect)
  91. {
  92. ASSERT(pItem && pItem->GetGrid());
  93. if (!pItem || !pItem->GetGrid())
  94. return;
  95. m_pGrid = pItem->GetGrid();
  96. m_pItem = pItem;
  97. m_bCreated = FALSE;
  98. m_bEditMode = FALSE;
  99. m_bCancel = FALSE;
  100. m_bCheckAutoComplete = FALSE;
  101. DWORD dwEditStyle = m_pItem->GetEditStyle();
  102. if (m_hWnd)
  103. {
  104. DWORD dwStyle = (WS_CHILD | WS_VISIBLE | ES_READONLY) | (m_pGrid->GetExStyle() & WS_EX_LAYOUTRTL ? ES_RIGHT : 0);
  105. if ((GetStyle() | dwStyle) != (dwEditStyle | dwStyle))
  106. m_bDelayCreate = TRUE;
  107. if (GetExStyle() & WS_EX_LAYOUTRTL)
  108. m_bDelayCreate = TRUE;
  109. if (m_bDelayCreate)
  110. DestroyWindow();
  111. }
  112. if (!m_hWnd)
  113. {
  114. CEdit::Create(dwEditStyle, rect, m_pGrid, 0);
  115. }
  116. m_bDelayCreate = FALSE;
  117. if (m_pItem->m_bPassword)
  118. CEdit::SetPasswordChar(pItem->m_chPrompt);
  119. if (m_pItem->GetMetrics(TRUE, FALSE))
  120. {
  121. CEdit::SetLimitText(m_pItem->GetMetrics(TRUE, FALSE)->m_nMaxLength);
  122. }
  123. else
  124. {
  125. CEdit::SetLimitText(0);
  126. }
  127. SetFont(m_pGrid->GetPaintManager()->GetItemFont(pItem, TRUE));
  128. SetWindowText(m_strValue);
  129. SetWindowPos(0, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOZORDER | SWP_SHOWWINDOW);
  130. SetMargins(3, 3);
  131. SetUseMask(m_pItem->m_bUseMask);
  132. if (m_pItem->m_bUseMask)
  133. {
  134. SetEditMask(m_pItem->m_strMask, m_pItem->m_strLiteral, m_pItem->m_strValue);
  135. SetPromptChar(m_pItem->m_chPrompt);
  136. }
  137. m_bCreated = TRUE;
  138. }
  139. HBRUSH CXTPPropertyGridInplaceEdit::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
  140. {
  141. CXTPPropertyGridPaintManager* pPaintManager = m_pGrid ? m_pGrid->GetPaintManager() : 0;
  142. if (!m_pItem || !pPaintManager)
  143. return 0;
  144. pDC->SetTextColor(pPaintManager->GetItemTextColor(m_pItem, TRUE));
  145. COLORREF clr = pPaintManager->GetItemBackColor(m_pItem, TRUE);
  146. if (clr != m_clrBack || !m_brBack.GetSafeHandle())
  147. {
  148. m_brBack.DeleteObject();
  149. m_brBack.CreateSolidBrush(clr);
  150. m_clrBack = clr;
  151. }
  152. pDC->SetBkColor(m_clrBack);
  153. return m_brBack;
  154. }
  155. void CXTPPropertyGridInplaceEdit::OnEnSetfocus()
  156. {
  157. if (!m_pGrid)
  158. return;
  159. m_pGrid->Invalidate(FALSE);
  160. if (m_pItem && !m_pItem->OnRequestEdit())
  161. m_pGrid->SetFocus();
  162. m_bEditMode = TRUE;
  163. }
  164. void CXTPPropertyGridInplaceEdit::OnEnKillfocus()
  165. {
  166. if (!m_pGrid)
  167. return;
  168. if (m_pItem)
  169. {
  170. m_pItem->OnValidateEdit();
  171. if (m_pGrid) m_pGrid->Invalidate(FALSE);
  172. }
  173. }
  174. void CXTPPropertyGridInplaceEdit::OnEnChange()
  175. {
  176. if (!m_bCreated || m_bIgnoreEditChanged)
  177. return;
  178. if (m_pItem && m_pGrid && !m_pItem->GetReadOnly() && m_pItem->m_bAutoComplete
  179. && !m_pItem->GetConstraintEdit() && m_bCheckAutoComplete)
  180. {
  181. m_bCheckAutoComplete = FALSE;
  182. CXTPPropertyGridItemConstraints* pList = m_pItem->GetConstraints();
  183. if (!pList->IsEmpty())
  184. {
  185. CString strWindowText;
  186. GetWindowText(strWindowText);
  187. int nLength = strWindowText.GetLength();
  188. // Currently selected range
  189. int nStart = 0, nEnd = 0;
  190. GetSel(nStart, nEnd);
  191. if (nStart == nEnd && nLength == nEnd && nLength > 0)
  192. {
  193. for (int nIndex = 0; nIndex < pList->GetCount(); nIndex += 1)
  194. {
  195. CString strWindowTextNew = pList->GetAt(nIndex);
  196. if (strWindowTextNew.GetLength() > nLength &&
  197. strWindowText.CompareNoCase(strWindowTextNew.Left(nLength)) == 0)
  198. {
  199. m_bIgnoreEditChanged = TRUE;
  200. SetWindowText(strWindowTextNew);
  201. SetSel(strWindowTextNew.GetLength(), nLength);
  202. m_bIgnoreEditChanged = FALSE;
  203. break;
  204. }
  205. }
  206. }
  207. }
  208. }
  209. if (m_pItem && m_pGrid)
  210. {
  211. ASSERT(m_pItem);
  212. m_pGrid->SendNotifyMessage(XTP_PGN_EDIT_CHANGED, (LPARAM)this);
  213. }
  214. }
  215. UINT CXTPPropertyGridInplaceEdit::OnGetDlgCode()
  216. {
  217. return DLGC_WANTALLKEYS;
  218. }
  219. void CXTPPropertyGridInplaceEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  220. {
  221. if (nChar == VK_TAB) return;
  222. if ((nChar == VK_RETURN) && (GetStyle() & ES_WANTRETURN))
  223. {
  224. CXTMaskEditT<CEdit>::OnChar(nChar, nRepCnt, nFlags);
  225. return;
  226. }
  227. if (nChar == VK_ESCAPE || nChar == VK_RETURN)
  228. {
  229. m_pGrid->SetFocus();
  230. return;
  231. }
  232. if (m_pItem && !m_pItem->GetReadOnly() && m_pItem->GetConstraintEdit())
  233. {
  234. CXTPPropertyGridItemConstraints* pList = m_pItem->GetConstraints();
  235. if (!pList->IsEmpty())
  236. {
  237. CString strWindowText;
  238. GetWindowText(strWindowText);
  239. int nIndex = pList->FindConstraint(strWindowText);
  240. int nIndexStart = nIndex == -1 ? pList->GetCount() - 1 : nIndex;
  241. CString strSeach ((TCHAR)nChar);
  242. do
  243. {
  244. nIndex = nIndex < pList->GetCount() - 1 ? nIndex + 1 : 0;
  245. CString str = pList->GetAt(nIndex);
  246. if (strSeach.CompareNoCase(str.Left(1)) == 0)
  247. {
  248. SetWindowText(str);
  249. pList->SetCurrent(nIndex);
  250. SetSel(0, -1);
  251. return;
  252. }
  253. }
  254. while (nIndex != nIndexStart);
  255. return;
  256. }
  257. }
  258. m_bCheckAutoComplete = (nChar != VK_DELETE) && (nChar != VK_BACK);
  259. CXTMaskEditT<CEdit>::OnChar(nChar, nRepCnt, nFlags);
  260. }
  261. void CXTPPropertyGridInplaceEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  262. {
  263. if (!m_pItem)
  264. return;
  265. if (nChar == VK_TAB && m_pGrid)
  266. {
  267. ((CXTPPropertyGrid*)m_pGrid->GetParent())->OnNavigate(
  268. xtpGridUIInplaceEdit, GetKeyState(VK_SHIFT) >= 0, m_pItem);
  269. return;
  270. }
  271. else if (nChar == VK_ESCAPE)
  272. {
  273. m_bCancel = TRUE;
  274. m_bCheckAutoComplete = FALSE;
  275. SetWindowText(m_strValue);
  276. return ;
  277. }
  278. else if (nChar == VK_RETURN)
  279. {
  280. return ;
  281. }
  282. else if (nChar == VK_F4)
  283. {
  284. CXTPPropertyGridInplaceButton* pButton = m_pItem->GetInplaceButtons()->Find(XTP_ID_PROPERTYGRID_COMBOBUTTON);
  285. if (pButton)
  286. m_pItem->OnInplaceButtonDown(pButton);
  287. }
  288. else if (nChar == VK_DOWN || nChar == VK_UP)
  289. {
  290. if (m_pItem != NULL && !m_pItem->GetReadOnly())
  291. {
  292. if (SelectConstraint(nChar == VK_DOWN ? +1 : -1, FALSE))
  293. {
  294. SetSel(0, -1);
  295. return ;
  296. }
  297. }
  298. }
  299. m_bCheckAutoComplete = (nChar != VK_DELETE) && (nChar != VK_BACK);
  300. CXTMaskEditT<CEdit>::OnKeyDown(nChar, nRepCnt, nFlags);
  301. }
  302. void CXTPPropertyGridInplaceEdit::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  303. {
  304. if ((nChar == VK_DOWN || nChar == VK_UP) && m_pItem)
  305. {
  306. CXTPPropertyGridInplaceButton* pButton = m_pItem->GetInplaceButtons()->Find(XTP_ID_PROPERTYGRID_COMBOBUTTON);
  307. if (pButton)
  308. m_pItem->OnInplaceButtonDown(pButton);
  309. }
  310. CXTMaskEditT<CEdit>::OnSysKeyDown(nChar, nRepCnt, nFlags);
  311. }
  312. BOOL CXTPPropertyGridInplaceEdit::SelectConstraint(int nDirection, BOOL bCircle)
  313. {
  314. CXTPPropertyGridItemConstraints* pList = m_pItem->GetConstraints();
  315. if (pList->IsEmpty())
  316. return FALSE;
  317. CString str;
  318. GetWindowText(str);
  319. int nIndex = pList->FindConstraint(str);
  320. if (nIndex == -1)
  321. return FALSE;
  322. nIndex += nDirection;
  323. if (nIndex >= pList->GetCount()) nIndex = bCircle ? 0 : (ULONG)pList->GetCount() - 1;
  324. if (nIndex < 0) nIndex = bCircle ? (ULONG)pList->GetCount() - 1 : 0;
  325. m_bCheckAutoComplete = FALSE;
  326. SetWindowText(pList->GetAt(nIndex));
  327. pList->SetCurrent(nIndex);
  328. return TRUE;
  329. }
  330. void CXTPPropertyGridInplaceEdit::OnLButtonDblClk(UINT nFlags, CPoint point)
  331. {
  332. if (m_pGrid && m_pItem != NULL && !m_pItem->GetReadOnly() && SelectConstraint(+1, TRUE))
  333. {
  334. m_pGrid->SetFocus();
  335. return;
  336. }
  337. CXTMaskEditT<CEdit>::OnLButtonDblClk(nFlags, point);
  338. }
  339. void CXTPPropertyGridInplaceEdit::DestroyItem()
  340. {
  341. // reset variables to defaults.
  342. m_pItem = NULL;
  343. m_pGrid = NULL;
  344. m_strValue.Empty();
  345. m_brBack.DeleteObject();
  346. // destroy the window.
  347. //DestroyWindow();
  348. if (::IsWindow(m_hWnd)) ShowWindow(SW_HIDE);
  349. }
  350. BOOL CXTPPropertyGridInplaceEdit::PreTranslateMessage(MSG* pMsg)
  351. {
  352. if (pMsg->message == WM_KEYDOWN && IsDialogMessage(pMsg))
  353. return TRUE;
  354. return CXTMaskEditT<CEdit>::PreTranslateMessage(pMsg);
  355. }
  356. //////////////////////////////////////////////////////////////////////////
  357. // CXTPPropertyGridInplaceControl
  358. CXTPPropertyGridInplaceControl::CXTPPropertyGridInplaceControl(CXTPPropertyGridItem* pItem)
  359. {
  360. m_pItem = pItem;
  361. m_nWidth = 0;
  362. }
  363. void CXTPPropertyGridInplaceControl::OnFinalRelease()
  364. {
  365. if (m_hWnd != NULL)
  366. DestroyWindow();
  367. CCmdTarget::OnFinalRelease();
  368. }
  369. void CXTPPropertyGridInplaceControl::OnDestroyWindow()
  370. {
  371. DestroyWindow();
  372. }
  373. void CXTPPropertyGridInplaceControl::OnValueChanged()
  374. {
  375. }
  376. BEGIN_MESSAGE_MAP(CXTPPropertyGridInplaceControl, CWnd)
  377. ON_WM_CHAR()
  378. ON_WM_KEYDOWN()
  379. ON_WM_GETDLGCODE()
  380. END_MESSAGE_MAP()
  381. UINT CXTPPropertyGridInplaceControl::OnGetDlgCode()
  382. {
  383. return CWnd::OnGetDlgCode() | DLGC_WANTTAB;
  384. }
  385. void CXTPPropertyGridInplaceControl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  386. {
  387. if (nChar == VK_TAB) return;
  388. CWnd::OnChar(nChar, nRepCnt, nFlags);
  389. }
  390. void CXTPPropertyGridInplaceControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  391. {
  392. if (nChar == VK_TAB && m_pItem)
  393. {
  394. ((CXTPPropertyGrid*)m_pItem->GetGrid()->GetParent())->OnNavigate(
  395. xtpGridUIInplaceControl, GetKeyState(VK_SHIFT) >= 0, m_pItem);
  396. return;
  397. }
  398. CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
  399. }
  400. //////////////////////////////////////////////////////////////////////////
  401. // CXTPPropertyGridInplaceSlider
  402. CXTPPropertyGridInplaceSlider::CXTPPropertyGridInplaceSlider(CXTPPropertyGridItem* pItem)
  403. : CXTPPropertyGridInplaceControl(pItem)
  404. {
  405. m_nMin = 0;
  406. m_nMax = 100;
  407. m_nValue = 0;
  408. m_clrBack = COLORREF_NULL;
  409. }
  410. BEGIN_MESSAGE_MAP(CXTPPropertyGridInplaceSlider, CXTPPropertyGridInplaceControl)
  411. ON_WM_CTLCOLOR_REFLECT()
  412. ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
  413. END_MESSAGE_MAP()
  414. int CXTPPropertyGridInplaceSlider::CalcualteEditWidth()
  415. {
  416. if (m_nWidth != 0)
  417. return m_nWidth;
  418. CWindowDC dc(m_pItem->GetGrid());
  419. CXTPFontDC font (&dc, m_pItem->GetGrid()->GetFont());
  420. CString strMax;
  421. strMax.Format(_T("%i"), m_nMax);
  422. CString strMin;
  423. strMin.Format(_T("%i"), m_nMin);
  424. int nWidth = max(dc.GetTextExtent(strMax).cx, dc.GetTextExtent(strMin).cx) + 6;
  425. return nWidth;
  426. }
  427. void CXTPPropertyGridInplaceSlider::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
  428. {
  429. LPNMCUSTOMDRAW lpCustDraw = (LPNMCUSTOMDRAW)pNMHDR;
  430. if(lpCustDraw->dwDrawStage == CDDS_PREPAINT)
  431. {
  432. int nValue = GetSliderCtrl()->GetPos();
  433. if (nValue != m_nValue)
  434. {
  435. m_nValue = nValue;
  436. CString strValue;
  437. strValue.Format(_T("%i"), nValue);
  438. m_pItem->SetValue(strValue);
  439. m_pItem->OnValueChanged(strValue);
  440. m_pItem->GetGrid()->Invalidate(FALSE);
  441. }
  442. }
  443. *pResult = CDRF_DODEFAULT;
  444. }
  445. void CXTPPropertyGridInplaceSlider::OnCreateWindow(CRect& rcValue)
  446. {
  447. CRect rcSlider(rcValue);
  448. if (m_nWidth > 0)
  449. {
  450. rcSlider.left = rcSlider.right - m_nWidth;
  451. if (rcSlider.left < rcValue.left)
  452. return;
  453. rcValue.right -= m_nWidth;
  454. }
  455. else
  456. {
  457. int nWidth = CalcualteEditWidth();
  458. rcSlider.left += nWidth;
  459. if (rcSlider.right < rcSlider.left)
  460. return;
  461. rcValue.right = rcValue.left + nWidth;
  462. }
  463. if (!m_hWnd)
  464. {
  465. VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTL_BAR_REG));
  466. Create(TRACKBAR_CLASS, NULL, WS_CHILD | TBS_HORZ | WS_TABSTOP, rcSlider, (CWnd*)m_pItem->GetGrid(), 0);
  467. }
  468. m_nValue = _ttol(m_pItem->GetValue());
  469. GetSliderCtrl()->SetRange(m_nMin, m_nMax, TRUE);
  470. GetSliderCtrl()->SetPos(m_nValue);
  471. GetSliderCtrl()->EnableWindow(!m_pItem->GetReadOnly());
  472. MoveWindow(rcSlider);
  473. ShowWindow(SW_SHOW);
  474. }
  475. HBRUSH CXTPPropertyGridInplaceSlider::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
  476. {
  477. CXTPPropertyGridView* pGrid = m_pItem ? m_pItem->GetGrid() : 0;
  478. CXTPPropertyGridPaintManager* pPaintManager = pGrid ? pGrid->GetPaintManager() : 0;
  479. if (!m_pItem || !pPaintManager)
  480. return 0;
  481. pDC->SetTextColor(pPaintManager->GetItemTextColor(m_pItem, TRUE));
  482. COLORREF clr = pPaintManager->GetItemBackColor(m_pItem, TRUE);
  483. if (clr != m_clrBack || !m_brBack.GetSafeHandle())
  484. {
  485. m_brBack.DeleteObject();
  486. m_brBack.CreateSolidBrush(clr);
  487. m_clrBack = clr;
  488. }
  489. pDC->SetBkColor(m_clrBack);
  490. return m_brBack;
  491. }
  492. void CXTPPropertyGridInplaceSlider::OnAdjustValueRect(CRect& rcValue)
  493. {
  494. if (!m_hWnd)
  495. return;
  496. if (m_nWidth > 0)
  497. {
  498. rcValue.right -= m_nWidth;
  499. return;
  500. }
  501. int nWidth = CalcualteEditWidth();
  502. if (rcValue.left + nWidth > rcValue.right)
  503. return;
  504. rcValue.right = rcValue.left + nWidth;
  505. }
  506. void CXTPPropertyGridInplaceSlider::OnValueChanged()
  507. {
  508. int nValue = _ttol(m_pItem->GetValue());
  509. int nValueRange = max(m_nMin, min(m_nMax, nValue));
  510. if (nValueRange != m_nValue || nValueRange != nValue)
  511. {
  512. m_nValue = nValueRange;
  513. CString str;
  514. str.Format(_T("%i"), nValueRange);
  515. m_pItem->SetValue(str);
  516. if (m_hWnd) GetSliderCtrl()->SetPos(m_nValue);
  517. }
  518. }
  519. //////////////////////////////////////////////////////////////////////////
  520. // CXTPPropertyGridInplaceSpinButton
  521. CXTPPropertyGridInplaceSpinButton::CXTPPropertyGridInplaceSpinButton(CXTPPropertyGridItem* pItem)
  522. : CXTPPropertyGridInplaceControl(pItem)
  523. {
  524. m_nMin = 0;
  525. m_nMax = 100;
  526. m_nWidth = GetSystemMetrics(SM_CXVSCROLL);
  527. }
  528. BEGIN_MESSAGE_MAP(CXTPPropertyGridInplaceSpinButton, CXTPPropertyGridInplaceControl)
  529. ON_NOTIFY_REFLECT(UDN_DELTAPOS, OnDeltapos)
  530. END_MESSAGE_MAP()
  531. #define AFX_WNDCOMMCTL_UPDOWN_REG 0x00040
  532. void CXTPPropertyGridInplaceSpinButton::OnCreateWindow(CRect& rcValue)
  533. {
  534. CRect rcButton(rcValue);
  535. rcButton.left = rcButton.right - m_nWidth;
  536. rcValue.right -= m_nWidth;
  537. if (!m_hWnd)
  538. {
  539. VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTL_UPDOWN_REG));
  540. Create(UPDOWN_CLASS, NULL, WS_CHILD | UDS_ARROWKEYS, rcButton, (CWnd*)m_pItem->GetGrid(), 0);
  541. }
  542. int nValue = _ttol(m_pItem->GetValue());
  543. GetSpinButtonCtrl()->SetPos(nValue);
  544. GetSpinButtonCtrl()->SendMessage(UDM_SETRANGE32, (WPARAM)m_nMin, (LPARAM)m_nMax);
  545. GetSpinButtonCtrl()->EnableWindow(!m_pItem->GetReadOnly());
  546. MoveWindow(rcButton);
  547. ShowWindow(SW_SHOW);
  548. }
  549. void CXTPPropertyGridInplaceSpinButton::OnDeltapos(NMHDR *pNMHDR, LRESULT *pResult)
  550. {
  551. LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
  552. m_pItem->OnValidateEdit();
  553. long nValue = _ttol(m_pItem->GetValue()) + pNMUpDown->iDelta;
  554. nValue = max(m_nMin, min(m_nMax, nValue));
  555. CString str;
  556. str.Format(_T("%i"), nValue);
  557. m_pItem->OnValueChanged(str);
  558. *pResult = 1;
  559. }
  560. void CXTPPropertyGridInplaceSpinButton::OnAdjustValueRect(CRect& rcValue)
  561. {
  562. if (m_hWnd)
  563. {
  564. rcValue.right -= m_nWidth;
  565. }
  566. }
  567. void CXTPPropertyGridInplaceSpinButton::OnValueChanged()
  568. {
  569. int nValue = _ttol(m_pItem->GetValue());
  570. int nValueRange = max(m_nMin, min(m_nMax, nValue));
  571. if (nValue != nValueRange)
  572. {
  573. CString str;
  574. str.Format(_T("%i"), nValueRange);
  575. m_pItem->SetValue(str);
  576. }
  577. }
  578. //////////////////////////////////////////////////////////////////////////
  579. // CXTPPropertyGridInplaceControls
  580. CXTPPropertyGridInplaceControls::CXTPPropertyGridInplaceControls()
  581. {
  582. }
  583. CXTPPropertyGridInplaceControls::~CXTPPropertyGridInplaceControls()
  584. {
  585. RemoveAll();
  586. }
  587. void CXTPPropertyGridInplaceControls::RemoveAll()
  588. {
  589. for (int i = 0; i < (int)m_arrControls.GetSize(); i++)
  590. {
  591. m_arrControls[i]->InternalRelease();
  592. }
  593. m_arrControls.RemoveAll();
  594. }
  595. int CXTPPropertyGridInplaceControls::GetCount() const
  596. {
  597. return (int)m_arrControls.GetSize();
  598. }
  599. void CXTPPropertyGridInplaceControls::Add(CXTPPropertyGridInplaceControl* pWindow)
  600. {
  601. m_arrControls.Add(pWindow);
  602. }
  603. CXTPPropertyGridInplaceControl* CXTPPropertyGridInplaceControls::GetAt(int nIndex)
  604. {
  605. return m_arrControls[nIndex];
  606. }