PropertyGridInplaceButton.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #include "stdafx.h"
  2. #include "PropertyGridInplaceEdit.h"
  3. #include "PropertyGridInplaceButton.h"
  4. #include "PropertyGridInplaceList.h"
  5. #include "PropertyGridItem.h"
  6. #include "PropertyGrid.h"
  7. #include "PropertyGrid_DrawHelpers.h"
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CPropertyGridInplaceButton
  10. CPropertyGridInplaceButton::CPropertyGridInplaceButton()
  11. : m_bPressed(FALSE)
  12. , m_bOver(FALSE)
  13. , m_pGrid(0)
  14. , m_pItem(0)
  15. {
  16. }
  17. CPropertyGridInplaceButton::~CPropertyGridInplaceButton()
  18. {
  19. }
  20. IMPLEMENT_DYNAMIC(CPropertyGridInplaceButton, CStatic)
  21. BEGIN_MESSAGE_MAP(CPropertyGridInplaceButton, CStatic)
  22. //{{AFX_MSG_MAP(CPropertyGridInplaceButton)
  23. ON_WM_PAINT()
  24. ON_WM_LBUTTONDOWN()
  25. ON_WM_LBUTTONUP()
  26. ON_WM_MOUSEMOVE()
  27. ON_WM_CAPTURECHANGED()
  28. //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30. void CPropertyGridInplaceButton::HideWindow()
  31. {
  32. if (m_hWnd)
  33. {
  34. ShowWindow(SW_HIDE);
  35. }
  36. }
  37. void CPropertyGridInplaceButton::Create(CPropertyGridItem* pItem, CRect rect)
  38. {
  39. ASSERT(pItem && pItem->GetGrid());
  40. m_pGrid = pItem->GetGrid();
  41. rect.left = rect.right - 15;
  42. rect.bottom -= 1;
  43. if (!m_hWnd)
  44. {
  45. CStatic::Create(_T(""), SS_NOTIFY|WS_CHILD, rect, m_pGrid);
  46. }
  47. SetWindowPos(0, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOZORDER|SWP_SHOWWINDOW);
  48. m_pItem = pItem;
  49. }
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CPropertyGridInplaceButton message handlers
  52. void CPropertyGridInplaceButton::OnPaint()
  53. {
  54. CPaintDC dc(this);
  55. CPGClientRect rect(this);
  56. dc.FillSolidRect(rect, GetSysColor(COLOR_3DFACE));
  57. CPGPenDC pen (dc, GetSysColor(COLOR_BTNTEXT));
  58. CPGBrushDC brush (dc, GetSysColor(COLOR_BTNTEXT));
  59. if (m_pItem->GetFlags() & pgitemHasComboButton)
  60. {
  61. CPoint pt = rect.CenterPoint();
  62. CPoint pts[3];
  63. pts[0] = CPoint(pt.x -3, pt.y -1);
  64. pts[1] = CPoint(pt.x + 3, pt.y -1);
  65. pts[2] = CPoint(pt.x, pt.y +2);
  66. dc.Polygon(pts, 3);
  67. } else
  68. {
  69. ASSERT(m_pItem->GetFlags() & pgitemHasExpandButton);
  70. dc.Rectangle(rect.left + 3, rect.bottom -5, rect.left + 5, rect.bottom -3);
  71. dc.Rectangle(rect.left + 7, rect.bottom -5, rect.left + 9, rect.bottom -3);
  72. dc.Rectangle(rect.left + 11, rect.bottom -5, rect.left + 13, rect.bottom -3);
  73. }
  74. if (m_bPressed && m_bOver) dc.Draw3dRect(rect, GetSysColor(COLOR_3DDKSHADOW), GetSysColor(COLOR_WINDOW));
  75. else
  76. {
  77. dc.Draw3dRect(rect, GetSysColor(COLOR_3DFACE), GetSysColor(COLOR_3DDKSHADOW));
  78. rect.DeflateRect(1, 1);
  79. dc.Draw3dRect(rect, GetSysColor(COLOR_WINDOW), GetSysColor(COLOR_3DSHADOW));
  80. }
  81. }
  82. void CPropertyGridInplaceButton::OnLButtonDown(UINT, CPoint)
  83. {
  84. m_bOver = m_bPressed = TRUE;
  85. Invalidate(FALSE);
  86. SetCapture();
  87. }
  88. void CPropertyGridInplaceButton::OnLButtonUp(UINT nFlags, CPoint point)
  89. {
  90. if (m_bPressed)
  91. {
  92. m_bPressed = FALSE;
  93. Invalidate(FALSE);
  94. ReleaseCapture();
  95. m_pItem->OnInplaceButtonDown();
  96. }
  97. CStatic::OnLButtonUp(nFlags, point);
  98. }
  99. void CPropertyGridInplaceButton::OnMouseMove(UINT nFlags, CPoint point)
  100. {
  101. if (m_bPressed)
  102. {
  103. CPGClientRect rect(this);
  104. if ((rect.PtInRect(point) && !m_bOver) ||
  105. (!rect.PtInRect(point) && m_bOver))
  106. {
  107. m_bOver = rect.PtInRect(point);
  108. Invalidate(FALSE);
  109. }
  110. }
  111. CStatic::OnMouseMove(nFlags, point);
  112. }
  113. void CPropertyGridInplaceButton::OnCaptureChanged(CWnd *pWnd)
  114. {
  115. m_bPressed = FALSE;
  116. Invalidate(FALSE);
  117. CStatic::OnCaptureChanged(pWnd);
  118. }
  119. void CPropertyGridInplaceButton::DestroyItem()
  120. {
  121. // reset variables to defaults.
  122. m_bPressed = FALSE;
  123. m_bOver = FALSE;
  124. m_pGrid = NULL;
  125. m_pItem = NULL;
  126. // destroy the window.
  127. DestroyWindow( );
  128. }