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

对话框与窗口

开发平台:

Visual C++

  1. // XTPPropertyGridInplaceButton.cpp : implementation of the CXTPPropertyGridInplaceButton 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 "Common/XTPImageManager.h"
  24. #include "XTPPropertyGridInplaceEdit.h"
  25. #include "XTPPropertyGridInplaceButton.h"
  26. #include "XTPPropertyGridInplaceList.h"
  27. #include "XTPPropertyGridItem.h"
  28. #include "XTPPropertyGridInplaceButton.h"
  29. #include "XTPPropertyGridInplaceEdit.h"
  30. #include "XTPPropertyGrid.h"
  31. #include "XTPPropertyGridPaintManager.h"
  32. #ifdef _DEBUG
  33. #define new DEBUG_NEW
  34. #undef THIS_FILE
  35. static char THIS_FILE[] = __FILE__;
  36. #endif
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CXTColorPicker
  39. CXTPPropertyGridInplaceButton::CXTPPropertyGridInplaceButton(UINT nID)
  40. {
  41. m_pItem = NULL;
  42. m_nID = nID;
  43. m_pGrid = NULL;
  44. m_rcButton.SetRectEmpty();
  45. m_nIndex = -1;
  46. m_bPressed = FALSE;
  47. m_nWidth = GetSystemMetrics(SM_CXHTHUMB);
  48. m_nIconIndex = -1;
  49. m_bEnabled = TRUE;
  50. }
  51. CXTPPropertyGridInplaceButton::~CXTPPropertyGridInplaceButton()
  52. {
  53. }
  54. CXTPImageManagerIcon* CXTPPropertyGridInplaceButton::GetImage() const
  55. {
  56. ASSERT(m_pItem);
  57. if (!m_pItem)
  58. return NULL;
  59. if (m_nIconIndex == -1)
  60. return NULL;
  61. return m_pGrid->GetImageManager()->GetImage(m_nIconIndex, 0);
  62. }
  63. void CXTPPropertyGridInplaceButton::SetCaption(LPCTSTR lpszCaption)
  64. {
  65. m_strCaption = lpszCaption;
  66. CWindowDC dc(NULL);
  67. CXTPFontDC font(&dc, m_pGrid->GetPaintManager()->GetItemFont(m_pItem, TRUE));
  68. m_nWidth = dc.GetTextExtent(m_strCaption).cx + 6;
  69. }
  70. int CXTPPropertyGridInplaceButton::GetIndex() const
  71. {
  72. return m_nIndex;
  73. }
  74. BOOL CXTPPropertyGridInplaceButton::IsFocused() const
  75. {
  76. return m_pGrid->m_pFocusedButton == this;
  77. }
  78. BOOL CXTPPropertyGridInplaceButton::IsHot() const
  79. {
  80. return m_pGrid->m_pHotButton == this && m_bEnabled;
  81. }
  82. BOOL CXTPPropertyGridInplaceButton::IsPressed() const
  83. {
  84. return m_bPressed;
  85. }
  86. BOOL CXTPPropertyGridInplaceButton::GetEnabled() const
  87. {
  88. return m_bEnabled;
  89. }
  90. void CXTPPropertyGridInplaceButton::SetEnabled(BOOL bEnabled)
  91. {
  92. m_bEnabled = bEnabled;
  93. SAFE_INVALIDATE(m_pGrid);
  94. }
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CXTPPropertyGridInplaceButton message handlers
  97. void CXTPPropertyGridInplaceButton::OnDraw(CDC* pDC, CRect rc)
  98. {
  99. m_rcButton = rc;
  100. m_pGrid->GetPaintManager()->FillInplaceButton(pDC, this);
  101. }
  102. void CXTPPropertyGridInplaceButton::OnLButtonDown(UINT, CPoint)
  103. {
  104. if (!m_bEnabled)
  105. return;
  106. m_bPressed = TRUE;
  107. m_pGrid->SetFocus();
  108. m_pGrid->Invalidate(FALSE);
  109. m_pGrid->SetCapture();
  110. BOOL bClick = TRUE;
  111. while (::GetCapture() == m_pGrid->GetSafeHwnd())
  112. {
  113. MSG msg;
  114. VERIFY(::GetMessage(&msg, NULL, 0, 0));
  115. if (msg.message == WM_LBUTTONUP)
  116. {
  117. bClick = IsHot();
  118. break;
  119. }
  120. if (msg.message == WM_MOUSEMOVE)
  121. {
  122. CPoint pt = CPoint(LOWORD(msg.lParam), HIWORD(msg.lParam));
  123. CXTPPropertyGridInplaceButton* pHotButton = m_rcButton.PtInRect(pt) ? this : NULL;
  124. if (m_pGrid->m_pHotButton != pHotButton)
  125. {
  126. m_pGrid->m_pHotButton = pHotButton;
  127. m_pGrid->Invalidate(FALSE);
  128. }
  129. continue;
  130. }
  131. DispatchMessage (&msg);
  132. }
  133. m_bPressed = FALSE;
  134. ReleaseCapture();
  135. m_pGrid->Invalidate(FALSE);
  136. if (bClick)
  137. {
  138. m_pItem->OnInplaceButtonDown(this);
  139. }
  140. }
  141. int CXTPPropertyGridInplaceButton::GetWidth()
  142. {
  143. return m_nWidth;
  144. }
  145. void CXTPPropertyGridInplaceButton::SetWidth(int nWidth)
  146. {
  147. m_nWidth = nWidth;
  148. }
  149. void CXTPPropertyGridInplaceButton::OnKeyDown(UINT nChar)
  150. {
  151. if (m_pItem && m_bEnabled && (nChar == VK_SPACE || nChar == VK_DOWN || nChar == VK_RETURN || nChar == VK_F4))
  152. {
  153. m_pItem->OnInplaceButtonDown(this);
  154. return;
  155. }
  156. }
  157. //////////////////////////////////////////////////////////////////////////
  158. // CXTPPropertyGridInplaceButtons
  159. CXTPPropertyGridInplaceButtons::CXTPPropertyGridInplaceButtons(CXTPPropertyGridItem* pItem)
  160. {
  161. m_pItem = pItem;
  162. }
  163. CXTPPropertyGridInplaceButtons::~CXTPPropertyGridInplaceButtons()
  164. {
  165. RemoveAll();
  166. }
  167. void CXTPPropertyGridInplaceButtons::RemoveAll()
  168. {
  169. for (int i = 0; i < GetCount(); i++)
  170. {
  171. m_arrButtons[i]->InternalRelease();
  172. }
  173. m_arrButtons.RemoveAll();
  174. }
  175. void CXTPPropertyGridInplaceButtons::UpdateIndexes()
  176. {
  177. for (int i = 0; i < GetCount(); i++)
  178. {
  179. m_arrButtons[i]->m_nIndex = i;
  180. }
  181. }
  182. void CXTPPropertyGridInplaceButtons::Remove(CXTPPropertyGridInplaceButton* pButton)
  183. {
  184. if (!pButton)
  185. return;
  186. for (int i = 0; i < GetCount(); i++)
  187. {
  188. if (m_arrButtons[i] == pButton)
  189. {
  190. RemoveAt(i);
  191. return;
  192. }
  193. }
  194. }
  195. void CXTPPropertyGridInplaceButtons::Remove(UINT nID)
  196. {
  197. Remove(Find(nID));
  198. }
  199. void CXTPPropertyGridInplaceButtons::RemoveAt(long nIndex)
  200. {
  201. if (nIndex >= 0 && nIndex < GetCount())
  202. {
  203. CXTPPropertyGridInplaceButton* pButton = m_arrButtons[nIndex];
  204. m_arrButtons.RemoveAt(nIndex);
  205. pButton->InternalRelease();
  206. UpdateIndexes();
  207. }
  208. }
  209. CXTPPropertyGridInplaceButton* CXTPPropertyGridInplaceButtons::AddButton(CXTPPropertyGridInplaceButton* pButton)
  210. {
  211. pButton->m_pItem = m_pItem;
  212. pButton->m_pGrid = m_pItem->GetGrid();
  213. m_arrButtons.Add(pButton);
  214. UpdateIndexes();
  215. return pButton;
  216. }
  217. void CXTPPropertyGridInplaceButtons::AddComboButton()
  218. {
  219. if (Find(XTP_ID_PROPERTYGRID_COMBOBUTTON) == NULL)
  220. {
  221. AddButton(new CXTPPropertyGridInplaceButton(XTP_ID_PROPERTYGRID_COMBOBUTTON));
  222. }
  223. }
  224. void CXTPPropertyGridInplaceButtons::AddExpandButton()
  225. {
  226. if (Find(XTP_ID_PROPERTYGRID_EXPANDBUTTON) == NULL)
  227. {
  228. AddButton(new CXTPPropertyGridInplaceButton(XTP_ID_PROPERTYGRID_EXPANDBUTTON));
  229. }
  230. }
  231. CXTPPropertyGridInplaceButton* CXTPPropertyGridInplaceButtons::Find(UINT nID) const
  232. {
  233. for (int i = 0; i < GetCount(); i++)
  234. {
  235. if (m_arrButtons[i]->GetID() == nID)
  236. return m_arrButtons[i];
  237. }
  238. return NULL;
  239. }
  240. CXTPPropertyGridInplaceButton* CXTPPropertyGridInplaceButtons::HitTest(CPoint point) const
  241. {
  242. if (!m_pItem->IsInplaceButtonsVisible())
  243. return NULL;
  244. for (int i = 0; i < GetCount(); i++)
  245. {
  246. if (m_arrButtons[i]->GetRect().PtInRect(point))
  247. return m_arrButtons[i];
  248. }
  249. return NULL;
  250. }