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

对话框与窗口

开发平台:

Visual C++

  1. // XTPPropertyGridPaintManager.cpp : implementation of the CXTPPropertyGridPaintManager 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 "Common/XTPOffice2007Image.h"
  25. #include "Common/XTPMarkupRender.h"
  26. #include "XTPPropertyGridPaintManager.h"
  27. #include "XTPPropertyGridInplaceEdit.h"
  28. #include "XTPPropertyGridInplaceButton.h"
  29. #include "XTPPropertyGridInplaceList.h"
  30. #include "XTPPropertyGridItem.h"
  31. #include "XTPPropertyGrid.h"
  32. #include "XTPPropertyGridItemBool.h"
  33. #ifdef _DEBUG
  34. #undef THIS_FILE
  35. static char THIS_FILE[] = __FILE__;
  36. #define new DEBUG_NEW
  37. #endif
  38. CXTPPropertyGridItemMetrics::CXTPPropertyGridItemMetrics(CXTPPropertyGridPaintManager* pPaintManager)
  39. : m_pPaintManager(pPaintManager)
  40. {
  41. m_nImage = -1;
  42. m_uDrawTextFormat = DT_VCENTER | DT_SINGLELINE;
  43. m_nMaxLength = 0;
  44. }
  45. void CXTPPropertyGridItemMetrics::SetDefaultValues()
  46. {
  47. m_clrHelpBack.SetDefaultValue();
  48. m_clrHelpFore.SetDefaultValue();
  49. m_clrLine.SetDefaultValue();
  50. m_clrBack.SetDefaultValue();
  51. m_clrFore.SetDefaultValue();
  52. m_clrReadOnlyFore.SetDefaultValue();
  53. m_clrCategoryFore.SetDefaultValue();
  54. m_clrVerbFace.SetDefaultValue();
  55. }
  56. COLORREF CXTPPropertyGridPaintManager::GetItemTextColor(CXTPPropertyGridItem* pItem, BOOL bValuePart)
  57. {
  58. ASSERT(pItem);
  59. if (!pItem)
  60. return m_pMetrics->m_clrFore;
  61. CXTPPropertyGridItemMetrics* pMetrics = pItem->GetMetrics(bValuePart, FALSE);
  62. if (pMetrics && !pMetrics->m_clrFore.IsDefaultValue())
  63. return pMetrics->m_clrFore;
  64. return pItem->IsCategory() ? m_pMetrics->m_clrCategoryFore :
  65. pItem->GetReadOnly() ? m_pMetrics->m_clrReadOnlyFore : m_pMetrics->m_clrFore;
  66. }
  67. COLORREF CXTPPropertyGridPaintManager::GetItemBackColor(CXTPPropertyGridItem* pItem, BOOL bValuePart)
  68. {
  69. ASSERT(pItem);
  70. if (!pItem)
  71. return m_pMetrics->m_clrBack;
  72. CXTPPropertyGridItemMetrics* pMetrics = pItem->GetMetrics(bValuePart, FALSE);
  73. if (pMetrics && !pMetrics->m_clrBack.IsDefaultValue())
  74. return pMetrics->m_clrBack;
  75. return m_pMetrics->m_clrBack;
  76. }
  77. CFont* CXTPPropertyGridPaintManager::GetItemFont(CXTPPropertyGridItem* pItem, BOOL bValuePart)
  78. {
  79. ASSERT(pItem);
  80. if (!pItem)
  81. return &m_pMetrics->m_fontNormal;
  82. CXTPPropertyGridItemMetrics* pMetrics = pItem->GetMetrics(bValuePart, FALSE);
  83. if (pMetrics && pMetrics->m_fontNormal.GetSafeHandle())
  84. return &pMetrics->m_fontNormal;
  85. if (pItem->IsCategory())
  86. return &m_pMetrics->m_fontBold;
  87. if (bValuePart && m_pGrid->IsHighlightChangedItems() && pItem->IsValueChanged())
  88. return &m_pMetrics->m_fontBold;
  89. return &m_pMetrics->m_fontNormal;
  90. }
  91. //////////////////////////////////////////////////////////////////////
  92. // Construction/Destruction
  93. //////////////////////////////////////////////////////////////////////
  94. CXTPPropertyGridPaintManager::CXTPPropertyGridPaintManager(CXTPPropertyGrid* pGrid)
  95. : m_pGrid(pGrid)
  96. {
  97. m_buttonsStyle = xtpGridButtonsDefault;
  98. LOGFONT lfIcon;
  99. VERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfIcon), &lfIcon, 0));
  100. lfIcon.lfWeight = FW_NORMAL;
  101. lfIcon.lfItalic = FALSE;
  102. VERIFY(m_fntVerbNormal.CreateFontIndirect(&lfIcon));
  103. lfIcon.lfUnderline = TRUE;
  104. VERIFY(m_fntVerbUnderline.CreateFontIndirect(&lfIcon));
  105. m_pMetrics = new CXTPPropertyGridItemMetrics(this);
  106. m_bTransparent = FALSE;
  107. }
  108. CXTPPropertyGridPaintManager::~CXTPPropertyGridPaintManager()
  109. {
  110. CMDTARGET_RELEASE(m_pMetrics);
  111. }
  112. void CXTPPropertyGridPaintManager::RefreshMetrics()
  113. {
  114. RefreshXtremeColors();
  115. m_clrHighlight.SetStandardValue(GetXtremeColor(COLOR_HIGHLIGHT));
  116. m_clrHighlightText.SetStandardValue(GetXtremeColor(COLOR_HIGHLIGHTTEXT));
  117. m_clrFace.SetStandardValue(GetXtremeColor(COLOR_3DFACE));
  118. m_clrShadow.SetStandardValue(GetXtremeColor(COLOR_3DSHADOW));
  119. m_pMetrics->m_clrVerbFace.SetStandardValue(GetXtremeColor(COLOR_ACTIVECAPTION));
  120. m_pMetrics->m_clrHelpBack.SetStandardValue(m_clrFace);
  121. m_pMetrics->m_clrHelpFore.SetStandardValue(GetXtremeColor(COLOR_BTNTEXT));
  122. m_pMetrics->m_clrLine.SetStandardValue(GetSysColor(COLOR_SCROLLBAR));
  123. m_pMetrics->m_clrCategoryFore.SetStandardValue(GetXtremeColor(COLOR_GRAYTEXT));
  124. m_pMetrics->m_clrBack.SetStandardValue(GetXtremeColor(COLOR_WINDOW));
  125. m_pMetrics->m_clrFore.SetStandardValue(GetXtremeColor(COLOR_WINDOWTEXT));
  126. m_pMetrics->m_clrReadOnlyFore.SetStandardValue(GetXtremeColor(COLOR_GRAYTEXT));
  127. HWND hWnd = AfxGetMainWnd() ? AfxGetMainWnd()->GetSafeHwnd() : 0;
  128. m_themeTree.OpenThemeData(hWnd, L"TREEVIEW");
  129. m_themeButton.OpenThemeData(hWnd, L"BUTTON");
  130. m_themeCombo.OpenThemeData(hWnd, L"COMBOBOX");
  131. }
  132. void CXTPPropertyGridPaintManager::FillPropertyGrid(CDC* pDC)
  133. {
  134. CXTPClientRect rc(m_pGrid);
  135. HBRUSH hBrush = NULL;
  136. if (m_bTransparent || m_clrFace == GetXtremeColor(COLOR_3DFACE))
  137. {
  138. hBrush = (HBRUSH)m_pGrid->GetParent()->SendMessage(WM_CTLCOLORSTATIC, (WPARAM)pDC->GetSafeHdc(), (LPARAM)m_pGrid->m_hWnd);
  139. }
  140. if (hBrush)
  141. {
  142. ::FillRect(pDC->GetSafeHdc(), rc, hBrush);
  143. }
  144. else
  145. {
  146. pDC->FillSolidRect(rc, m_clrFace);
  147. }
  148. pDC->SetBkMode(TRANSPARENT);
  149. if (m_pGrid->IsHelpVisible())
  150. {
  151. CXTPPropertyGridItem* pItem = m_pGrid->GetSelectedItem();
  152. CRect rcHelp(rc);
  153. rcHelp.top = rc.bottom - m_pGrid->m_nHelpHeight;
  154. if (!hBrush || !m_bTransparent) pDC->FillSolidRect(rcHelp, m_pMetrics->m_clrHelpBack);
  155. DrawPropertyGridBorder(pDC, rcHelp, FALSE);
  156. CXTPFontDC fontCaption(pDC, &m_pMetrics->m_fontBold);
  157. if (pItem)
  158. {
  159. pDC->SetTextColor(m_pMetrics->m_clrHelpFore);
  160. pDC->SetBkMode(TRANSPARENT);
  161. CRect rcCaption(rcHelp);
  162. rcCaption.DeflateRect(6, 3);
  163. if (pItem->GetMarkupUIElement())
  164. {
  165. XTPMarkupSetDefaultFont(XTPMarkupElementContext(pItem->GetMarkupUIElement()),
  166. (HFONT)m_pMetrics->m_fontBold, pDC->GetTextColor());
  167. CSize sz = XTPMarkupMeasureElement(pItem->GetMarkupUIElement(), INT_MAX, INT_MAX);
  168. XTPMarkupRenderElement(pItem->GetMarkupUIElement(), pDC->GetSafeHdc(),
  169. CRect(rcCaption.TopLeft(), sz));
  170. }
  171. else
  172. {
  173. pDC->DrawText(pItem->GetCaption(), rcCaption, DT_SINGLELINE | DT_NOPREFIX);
  174. }
  175. CString strDesc = pItem->GetDescription();
  176. if (!strDesc.IsEmpty())
  177. {
  178. CXTPFontDC fontDescription(pDC, &m_pMetrics->m_fontNormal);
  179. CXTPEmptyRect rcCaptionHeight;
  180. pDC->DrawText(pItem->GetCaption(), rcCaptionHeight, DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
  181. CRect rcDesc(rcHelp);
  182. rcDesc.DeflateRect(6, 3 + rcCaptionHeight.Height() + 3, 6, 3);
  183. pDC->DrawText(strDesc, rcDesc, DT_WORDBREAK | DT_NOPREFIX);
  184. }
  185. }
  186. rc.bottom -= m_pGrid->m_nHelpHeight + 3;
  187. }
  188. if (m_pGrid->IsVerbsVisible())
  189. {
  190. CRect rcVerbs(rc);
  191. rcVerbs.top = rc.bottom - m_pGrid->m_nVerbsHeight;
  192. if (!hBrush || !m_bTransparent) pDC->FillSolidRect(rcVerbs, m_pMetrics->m_clrHelpBack);
  193. DrawPropertyGridBorder(pDC, rcVerbs, FALSE);
  194. HitTestVerbs(pDC, rcVerbs, CPoint(0));
  195. }
  196. }
  197. int CXTPPropertyGridPaintManager::HitTestVerbs(CDC* pDC, CRect rcVerbs, CPoint pt)
  198. {
  199. #define DRAWTEXTPART(strCaption)
  200. CRect rcText(CRect(x, y, min(x + nTextWidth, rcVerbs.right), min(y + nTextHeight, rcVerbs.bottom)));
  201. if (bDraw)
  202. {
  203. pVerb->SetPart(rcText);
  204. pDC->SetTextColor(m_pMetrics->m_clrVerbFace);
  205. pDC->DrawText(strCaption, rcText, DT_SINGLELINE | DT_NOPREFIX);
  206. if (pVerb->IsFocused())
  207. {
  208. pDC->SetTextColor(m_pMetrics->m_clrHelpBack);
  209. pDC->SetBkColor(0);
  210. rcText.bottom++;
  211. pDC->DrawFocusRect(rcText);
  212. }
  213. }
  214. else if (rcText.PtInRect(pt)) return i;
  215. BOOL bDraw = (pt == CPoint(0));
  216. CXTPFontDC font(pDC, &m_fntVerbUnderline);
  217. rcVerbs.DeflateRect(6, 4);
  218. int nCount = m_pGrid->GetVerbs()->GetCount();
  219. int x = rcVerbs.left, y = rcVerbs.top, nWidth = rcVerbs.Width();
  220. int nTextHeight = pDC->GetTextExtent(_T("XXX"), 3).cy;
  221. for (int i = 0; i < nCount; i++)
  222. {
  223. CXTPPropertyGridVerb* pVerb = m_pGrid->GetVerbs()->GetAt(i);
  224. CString strCaption = pVerb->GetCaption();
  225. for (;;)
  226. {
  227. if (strCaption.IsEmpty())
  228. break;
  229. int nTextWidth = pDC->GetTextExtent(strCaption).cx;
  230. if (x + nTextWidth < nWidth)
  231. {
  232. DRAWTEXTPART(strCaption);
  233. x += nTextWidth;
  234. break;
  235. }
  236. else
  237. {
  238. int nStartIndex = (strCaption.GetLength() - 1) * (nWidth - x) / nTextWidth;
  239. int nIndex = nStartIndex;
  240. if ((nStartIndex < 1) && (x == rcVerbs.left))
  241. {
  242. i = nCount - 1;
  243. break;
  244. }
  245. for (; nIndex >= 0; nIndex--)
  246. {
  247. if (strCaption[nIndex] == _T(' ') || strCaption[nIndex] == _T(',') || strCaption[nIndex] == _T('-'))
  248. break;
  249. }
  250. if (nIndex > 0 || (x == rcVerbs.left))
  251. {
  252. if (nIndex <= 0) nIndex = nStartIndex;
  253. CString strLeft = strCaption.Left(nIndex + 1);
  254. CString strRight = strCaption.Mid(nIndex + 1);
  255. nTextWidth = pDC->GetTextExtent(strLeft).cx;
  256. DRAWTEXTPART(strLeft);
  257. x = rcVerbs.left;
  258. y += nTextHeight;
  259. strCaption = strRight;
  260. }
  261. else
  262. {
  263. y += nTextHeight;
  264. x = rcVerbs.left;
  265. }
  266. }
  267. if (y >= rcVerbs.bottom)
  268. break;
  269. }
  270. if ((y >= rcVerbs.bottom) || (i == nCount - 1))
  271. break;
  272. if (bDraw)
  273. {
  274. font.SetFont(&m_fntVerbNormal);
  275. pDC->SetTextColor(m_pMetrics->m_clrHelpFore);
  276. pDC->DrawText(_T(","), 1, CRect(x, y, x + 8, min(y + nTextHeight, rcVerbs.bottom)), DT_SINGLELINE | DT_NOPREFIX);
  277. font.SetFont(&m_fntVerbUnderline);
  278. }
  279. x += 8;
  280. }
  281. return -1;
  282. }
  283. void CXTPPropertyGridPaintManager::DrawPropertyGridBorder(CDC* pDC, RECT& rc, BOOL bAdjustRect)
  284. {
  285. XTPPropertyGridBorderStyle borderStyle = m_pGrid->GetBorderStyle();
  286. if (pDC)
  287. {
  288. switch (borderStyle)
  289. {
  290. case xtpGridBorderStaticEdge:
  291. pDC->Draw3dRect(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
  292. m_clrShadow, m_clrShadow);
  293. break;
  294. case xtpGridBorderFlat:
  295. pDC->Draw3dRect(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
  296. GetXtremeColor(COLOR_WINDOWFRAME), GetXtremeColor(COLOR_WINDOWFRAME));
  297. break;
  298. case xtpGridBorderClientEdge:
  299. pDC->Draw3dRect(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
  300. GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DHIGHLIGHT));
  301. pDC->Draw3dRect(rc.left + 1, rc.top + 1, rc.right - rc.left - 2, rc.bottom - rc.top - 2,
  302. GetXtremeColor(COLOR_3DDKSHADOW), GetXtremeColor(COLOR_3DFACE));
  303. break;
  304. }
  305. }
  306. if (bAdjustRect)
  307. {
  308. int nSize = borderStyle == xtpGridBorderClientEdge ? 2 :
  309. borderStyle == xtpGridBorderStaticEdge || borderStyle == xtpGridBorderFlat ? 1 : 0;
  310. rc.left   += nSize;
  311. rc.top    += nSize;
  312. rc.right  -= nSize;
  313. rc.bottom -= nSize;
  314. }
  315. }
  316. void CXTPPropertyGridPaintManager::FillPropertyGridView(CDC* pDC)
  317. {
  318. CXTPPropertyGridView* pView = &m_pGrid->GetGridView();
  319. CXTPClientRect rc(pView);
  320. pDC->FillSolidRect(rc, m_pMetrics->m_clrBack);
  321. }
  322. void CXTPPropertyGridPaintManager::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
  323. {
  324. CXTPPropertyGridView* pView = &m_pGrid->GetGridView();
  325. if (pView->GetStyle() & LBS_OWNERDRAWVARIABLE)
  326. {
  327. CXTPPropertyGridItem* pItem = (CXTPPropertyGridItem*)lpMeasureItemStruct->itemData;
  328. pItem->MeasureItem(lpMeasureItemStruct);
  329. }
  330. }
  331. void CXTPPropertyGridPaintManager::DrawCategoryCaptionBackground(CDC* pDC, CXTPPropertyGridItem* /*pItem*/, CRect rc)
  332. {
  333. pDC->FillSolidRect(rc, m_pMetrics->m_clrLine);
  334. }
  335. void CXTPPropertyGridPaintManager::DrawInplaceListItem(CDC* pDC, CXTPPropertyGridItemConstraint* pConstraint, CRect rc, BOOL bSelected)
  336. {
  337. pDC->SetBkMode(TRANSPARENT);
  338. if (bSelected)
  339. {
  340. pDC->SetTextColor(m_clrHighlightText);
  341. pDC->FillSolidRect(rc, m_clrHighlight);
  342. }
  343. else
  344. {
  345. pDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
  346. pDC->FillSolidRect(rc, GetXtremeColor(COLOR_WINDOW));
  347. }
  348. CRect rcText(rc.left + 2, rc.top, rc.right - 2, rc.bottom);
  349. CXTPImageManagerIcon* pImage = pConstraint->GetImage();
  350. if (pImage)
  351. {
  352. int nHeight = min(pImage->GetHeight(), rc.Height());
  353. int nWidth = pImage->GetWidth();
  354. CPoint pt(rcText.left, rcText.CenterPoint().y - nHeight/2);
  355. pImage->Draw(pDC, pt, CSize(nWidth, nHeight));
  356. rcText.left += nWidth + 4;
  357. }
  358. // Draw the text.
  359. pDC->DrawText(pConstraint->m_strConstraint, rcText, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
  360. }
  361. void CXTPPropertyGridPaintManager::AdjustItemValueRect(CXTPPropertyGridItem* pItem, CRect& rcValue)
  362. {
  363. CXTPPropertyGridItemMetrics* pMetrics = pItem->GetMetrics(TRUE, FALSE);
  364. if (pMetrics && pMetrics->m_nImage != -1)
  365. {
  366. CXTPImageManagerIcon* pImage = m_pGrid->GetImageManager()->GetImage(pMetrics->m_nImage, 0);
  367. if (pImage)
  368. {
  369. int nWidth = pImage->GetWidth();
  370. rcValue.left += nWidth + 4;
  371. }
  372. }
  373. }
  374. void CXTPPropertyGridPaintManager::AdjustItemCaptionRect(CXTPPropertyGridItem* pItem, CRect& rcCaption)
  375. {
  376. CXTPPropertyGridItemMetrics* pMetrics = pItem->GetMetrics(FALSE, FALSE);
  377. if (pMetrics && pMetrics->m_nImage != -1)
  378. {
  379. CXTPImageManagerIcon* pImage = m_pGrid->GetImageManager()->GetImage(pMetrics->m_nImage, 0);
  380. if (pImage)
  381. {
  382. int nWidth = pImage->GetWidth();
  383. rcCaption.left += nWidth + 4;
  384. }
  385. }
  386. }
  387. void CXTPPropertyGridPaintManager::DrawItemValue(CDC* pDC, CXTPPropertyGridItem* pItem, CRect rcValue)
  388. {
  389. pDC->SetTextColor(GetItemTextColor(pItem, TRUE));
  390. pDC->FillSolidRect(rcValue, GetItemBackColor(pItem, TRUE));
  391. rcValue.left += 4;
  392. if (pItem->OnDrawItemValue(*pDC, rcValue))
  393. return;
  394. CXTPPropertyGridItemMetrics* pMetrics = pItem->GetMetrics(TRUE, FALSE);
  395. if (pMetrics && pMetrics->m_nImage != -1)
  396. {
  397. CXTPImageManagerIcon* pImage = m_pGrid->GetImageManager()->GetImage(pMetrics->m_nImage, 0);
  398. if (pImage)
  399. {
  400. int nHeight = min(pImage->GetHeight(), rcValue.Height());
  401. int nWidth = pImage->GetWidth();
  402. CPoint pt(rcValue.left, rcValue.CenterPoint().y - nHeight/2);
  403. pImage->Draw(pDC, pt, CSize(nWidth, nHeight));
  404. rcValue.left += nWidth + 4;
  405. }
  406. }
  407. rcValue.DeflateRect(0, 1);
  408. UINT nFormat = pMetrics ? pMetrics->m_uDrawTextFormat : DT_VCENTER | DT_SINGLELINE;
  409. if (pItem->IsMultiLine()) nFormat = (nFormat | DT_WORDBREAK) & ~DT_SINGLELINE;
  410. pDC->DrawText(pItem->GetViewValue(), rcValue, DT_NOPREFIX | nFormat);
  411. }
  412. void CXTPPropertyGridPaintManager::DrawItemCaption(CDC* pDC, CXTPPropertyGridItem* pItem, CRect rcCaption)
  413. {
  414. CRect rcText(rcCaption);
  415. rcText.left = (pItem->GetIndent() + (pItem->IsCategory() ? 1 : 0)) * XTP_PGI_EXPAND_BORDER + 3;
  416. rcText.right = rcCaption.right - 1;
  417. rcText.bottom -= 1;
  418. CXTPPropertyGridItemMetrics* pMetrics = pItem->GetMetrics(FALSE, FALSE);
  419. if (pMetrics && pMetrics->m_nImage != -1)
  420. {
  421. CXTPImageManagerIcon* pImage = m_pGrid->GetImageManager()->GetImage(pMetrics->m_nImage, 0);
  422. if (pImage)
  423. {
  424. int nHeight = min(pImage->GetHeight(), rcText.Height());
  425. int nWidth = pImage->GetWidth();
  426. CPoint pt(rcText.left, rcText.CenterPoint().y - nHeight/2);
  427. pImage->Draw(pDC, pt, CSize(nWidth, nHeight));
  428. rcText.left += nWidth + 4;
  429. }
  430. }
  431. if (pItem->GetMarkupUIElement())
  432. {
  433. XTPMarkupSetDefaultFont(XTPMarkupElementContext(pItem->GetMarkupUIElement()),
  434. (HFONT)GetItemFont(pItem, FALSE)->GetSafeHandle(), pDC->GetTextColor());
  435. XTPMarkupMeasureElement(pItem->GetMarkupUIElement(), INT_MAX, INT_MAX);
  436. XTPMarkupRenderElement(pItem->GetMarkupUIElement(), pDC->GetSafeHdc(), rcText);
  437. }
  438. else
  439. {
  440. UINT nFormat = pMetrics ? pMetrics->m_uDrawTextFormat : DT_VCENTER | DT_SINGLELINE;
  441. pDC->DrawText(pItem->GetCaption(), rcText, DT_NOPREFIX | nFormat);
  442. }
  443. }
  444. void CXTPPropertyGridPaintManager::DrawInplaceButtons(CDC* pDC, CXTPPropertyGridItem* pItem, CRect rcValue)
  445. {
  446. if (pItem->GetReadOnly())
  447. return;
  448. int nRight = rcValue.right;
  449. for (int i = pItem->GetInplaceButtons()->GetCount() - 1; i >= 0; i--)
  450. {
  451. CXTPPropertyGridInplaceButton* pButton = pItem->GetInplaceButtons()->GetAt(i);
  452. int nWidth = pButton->GetWidth();
  453. CRect rcButton(nRight - nWidth, rcValue.top, nRight, rcValue.bottom);
  454. pButton->OnDraw(pDC, rcButton);
  455. nRight -= nWidth;
  456. }
  457. }
  458. void CXTPPropertyGridPaintManager::DrawItem(PDRAWITEMSTRUCT lpDrawItemStruct)
  459. {
  460. CXTPPropertyGridView* pView = &m_pGrid->GetGridView();
  461. CXTPPropertyGridItem* pItem = (CXTPPropertyGridItem*)lpDrawItemStruct->itemData;
  462. CXTPWindowRect rcWindow(pView);
  463. CRect rc = lpDrawItemStruct->rcItem;
  464. CXTPBufferDC dc(lpDrawItemStruct->hDC, rc);
  465. CXTPFontDC font(&dc, GetItemFont(pItem, TRUE));
  466. dc.FillSolidRect(rc, GetItemBackColor(pItem, FALSE));
  467. dc.SetBkMode(TRANSPARENT);
  468. CRect rcCaption(rc.left, rc.top, rc.left + pView->GetDividerPos(), rc.bottom);
  469. if (pItem->IsCategory())
  470. {
  471. DrawCategoryCaptionBackground(&dc, pItem, rc);
  472. font.SetFont(GetItemFont(pItem, FALSE));
  473. dc.SetTextColor(GetItemTextColor(pItem, FALSE));
  474. CRect rcText(((pItem->GetIndent() + 1) * XTP_PGI_EXPAND_BORDER) + 3, rc.top, rc.right, rc.bottom - 1);
  475. CXTPPropertyGridItemMetrics* pMetrics = pItem->GetMetrics(FALSE, FALSE);
  476. if (pMetrics && pMetrics->m_nImage != -1)
  477. {
  478. CXTPImageManagerIcon* pImage = m_pGrid->GetImageManager()->GetImage(pMetrics->m_nImage, 0);
  479. if (pImage)
  480. {
  481. int nHeight = min(pImage->GetHeight(), rc.Height());
  482. int nWidth = pImage->GetWidth();
  483. CPoint pt(rcText.left, rcText.CenterPoint().y - nHeight/2);
  484. pImage->Draw(&dc, pt, CSize(nWidth, nHeight));
  485. rcText.OffsetRect(nWidth + 4, 0);
  486. }
  487. }
  488. dc.DrawText(pItem->GetCaption(), rcText, DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_LEFT);
  489. if (lpDrawItemStruct->itemState & ODS_FOCUS)
  490. {
  491. CXTPEmptyRect rcFocus;
  492. dc.DrawText(pItem->GetCaption(), rcFocus, DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_CALCRECT);
  493. rcFocus.SetRect(rcText.left - 3, rcText.top + 1, rcText.left + rcFocus.Width() + 3, rcText.bottom - 1);
  494. dc.SetTextColor(0);
  495. dc.DrawFocusRect(rcFocus);
  496. }
  497. BOOL bSelected = (lpDrawItemStruct->itemState & (ODS_SELECTED | ODS_FOCUS));
  498. if (bSelected || m_pGrid->GetShowInplaceButtonsAlways()) DrawInplaceButtons(&dc, pItem, rcText);
  499. }
  500. else
  501. {
  502. CRect rcValue(rcCaption.right, rc.top, rc.right, rc.bottom - 1);
  503. DrawItemValue(&dc, pItem, rcValue);
  504. dc.SetTextColor(GetItemTextColor(pItem, FALSE));
  505. font.SetFont(GetItemFont(pItem, FALSE));
  506. BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
  507. BOOL bFocused = bSelected && CWnd::GetFocus() && ((CWnd::GetFocus() == pView) || (CWnd::GetFocus()->GetParent() == pView) || (CWnd::GetFocus()->GetOwner() == pView));
  508. if (bFocused)
  509. {
  510. dc.SetTextColor(m_clrHighlightText);
  511. dc.FillSolidRect(rcCaption, m_clrHighlight);
  512. }
  513. else if (bSelected && !m_pGrid->m_bHideSelection)
  514. {
  515. dc.FillSolidRect(rcCaption, m_pMetrics->m_clrLine);
  516. }
  517. CXTPPropertyGridItem* pCategory = pItem->GetParentItem();
  518. while (pCategory != NULL)
  519. {
  520. if (pCategory->IsCategory())
  521. dc.FillSolidRect(rc.left + pCategory->GetIndent() * XTP_PGI_EXPAND_BORDER, rc.top, XTP_PGI_EXPAND_BORDER, rc.Height(), m_pMetrics->m_clrLine);
  522. pCategory = pCategory->GetParentItem();
  523. }
  524. CXTPPenDC pen(dc, m_pMetrics->m_clrLine);
  525. dc.MoveTo(0, rc.bottom - 1); dc.LineTo(rc.right, rc.bottom - 1);
  526. dc.MoveTo(rcCaption.right, rc.top); dc.LineTo(rcCaption.right, rc.bottom - 1);
  527. DrawItemCaption(&dc, pItem, rcCaption);
  528. if (bSelected || m_pGrid->GetShowInplaceButtonsAlways()) DrawInplaceButtons(&dc, pItem, rcValue);
  529. }
  530. CXTPPropertyGridItem* pNext = pView->GetItem(lpDrawItemStruct->itemID + 1);
  531. if (pNext && pNext->IsCategory() && pNext->IsVisible())
  532. {
  533. dc.FillSolidRect(pNext->GetIndent() * XTP_PGI_EXPAND_BORDER, rc.bottom - 1, rc.Width(), 1, m_clrFace);
  534. }
  535. if (pItem->HasVisibleChilds())
  536. {
  537. CRgn rgn;
  538. if (!pItem->IsCategory())
  539. {
  540. rgn.CreateRectRgnIndirect(&rcCaption);
  541. dc.SelectClipRgn(&rgn);
  542. }
  543. DrawExpandButton(dc, pItem, rcCaption);
  544. dc.SelectClipRgn(NULL);
  545. }
  546. }
  547. void CXTPPropertyGridPaintManager::DrawExpandButton(CDC& dc, CXTPPropertyGridItem* pItem, CRect rcCaption)
  548. {
  549. if (!pItem->IsExpandable())
  550. return;
  551. CRect rcSign(CPoint(XTP_PGI_EXPAND_BORDER / 2 - 5, rcCaption.CenterPoint().y - 4), CSize(9, 9));
  552. if (pItem->GetIndent() > 0)
  553. rcSign.OffsetRect((pItem->GetIndent() - (pItem->IsCategory() ? 0 : 1)) * XTP_PGI_EXPAND_BORDER, 0);
  554. if (m_buttonsStyle == xtpGridButtonsThemed && m_themeTree.IsAppThemed())
  555. {
  556. m_themeTree.DrawThemeBackground(dc, TVP_GLYPH, pItem->IsExpanded() ? GLPS_OPENED : GLPS_CLOSED, &rcSign, 0);
  557. }
  558. else
  559. {
  560. CPoint pt = rcSign.CenterPoint();
  561. if (!pItem->IsCategory()) dc.FillSolidRect(rcSign, m_pMetrics->m_clrBack);
  562. dc.Draw3dRect(rcSign, m_pMetrics->m_clrFore, m_pMetrics->m_clrFore);
  563. CXTPPenDC pen (dc, m_pMetrics->m_clrFore);
  564. dc.MoveTo(pt.x - 2, pt.y);
  565. dc.LineTo(pt.x + 3, pt.y);
  566. if (!pItem->IsExpanded())
  567. {
  568. dc.MoveTo(pt.x, pt.y - 2);
  569. dc.LineTo(pt.x, pt.y + 3);
  570. }
  571. }
  572. }
  573. void CXTPPropertyGridPaintManager::FillInplaceButton(CDC* pDC, CXTPPropertyGridInplaceButton* pButton)
  574. {
  575. CRect rect(pButton->GetRect());
  576. CPoint ptDots(rect.CenterPoint().x , rect.CenterPoint().y + 3);
  577. COLORREF clrText = GetXtremeColor(pButton->GetEnabled() ? COLOR_BTNTEXT : COLOR_GRAYTEXT);
  578. if (m_buttonsStyle == xtpGridButtonsThemed && m_themeButton.IsAppThemed() && m_themeCombo.IsAppThemed())
  579. {
  580. pDC->FillSolidRect(rect, m_pMetrics->m_clrBack);
  581. if (pButton->GetID() != XTP_ID_PROPERTYGRID_COMBOBUTTON)
  582. {
  583. m_themeButton.DrawThemeBackground(*pDC, BP_PUSHBUTTON, !pButton->GetEnabled() ? PBS_DISABLED : pButton->IsPressed() && pButton->IsHot() ? PBS_PRESSED :
  584. pButton->IsHot() ? PBS_HOT: pButton->IsFocused() ? PBS_DEFAULTED : PBS_NORMAL, rect, 0);
  585. }
  586. else
  587. {
  588. m_themeCombo.DrawThemeBackground(*pDC, CP_DROPDOWNBUTTON, !pButton->GetEnabled() ? CBXS_DISABLED :
  589. pButton->IsPressed() && pButton->IsHot() ? CBXS_PRESSED: pButton->IsHot() ? CBXS_HOT : CBXS_NORMAL, rect, 0);
  590. }
  591. }
  592. else
  593. {
  594. if (m_buttonsStyle == xtpGridButtonsOfficeXP)
  595. {
  596. pDC->FillSolidRect(rect, GetXtremeColor(pButton->IsPressed() && pButton->IsHot() ? XPCOLOR_HIGHLIGHT_PUSHED :
  597. pButton->IsHot() ? XPCOLOR_HIGHLIGHT : XPCOLOR_TOOLBAR_FACE));
  598. COLORREF clrBorder = GetXtremeColor(pButton->IsPressed() && pButton->IsHot() ? XPCOLOR_HIGHLIGHT_PUSHED_BORDER :
  599. pButton->IsHot() ? XPCOLOR_HIGHLIGHT_BORDER : COLOR_3DSHADOW);
  600. pDC->Draw3dRect(rect, clrBorder, clrBorder);
  601. }
  602. else
  603. {
  604. pDC->FillSolidRect(rect, GetXtremeColor(COLOR_3DFACE));
  605. if (pButton->IsPressed() && pButton->IsHot())
  606. pDC->Draw3dRect(rect, GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DSHADOW));
  607. else
  608. {
  609. pDC->Draw3dRect(rect, GetXtremeColor(COLOR_3DFACE), GetXtremeColor(COLOR_3DDKSHADOW));
  610. rect.DeflateRect(1, 1);
  611. pDC->Draw3dRect(rect, GetXtremeColor(COLOR_WINDOW), GetXtremeColor(COLOR_3DSHADOW));
  612. }
  613. }
  614. if (pButton->GetID() == XTP_ID_PROPERTYGRID_COMBOBUTTON)
  615. {
  616. CPoint pt = rect.CenterPoint();
  617. CXTPDrawHelpers::Triangle(pDC, CPoint(pt.x -3, pt.y -1), CPoint(pt.x + 3, pt.y -1), CPoint(pt.x, pt.y +2), clrText);
  618. }
  619. }
  620. BOOL bCustom = FALSE;
  621. if (pButton->GetID() != XTP_ID_PROPERTYGRID_COMBOBUTTON)
  622. {
  623. CXTPImageManagerIcon* pIcon = pButton->GetImage();
  624. if (pIcon)
  625. {
  626. CSize sz(pIcon->GetWidth(), pIcon->GetHeight());
  627. CPoint pt((rect.left + rect.right - sz.cx) / 2, (rect.top + rect.bottom - sz.cy) / 2);
  628. pIcon->Draw(pDC, pt, sz);
  629. bCustom = TRUE;
  630. }
  631. else if (!pButton->GetCaption().IsEmpty())
  632. {
  633. CXTPFontDC font(pDC, GetItemFont(pButton->GetItem(), TRUE));
  634. pDC->SetTextColor(clrText);
  635. pDC->DrawText(pButton->GetCaption(), rect, DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_NOPREFIX);
  636. bCustom = TRUE;
  637. }
  638. }
  639. if (!bCustom && pButton->GetID() == XTP_ID_PROPERTYGRID_EXPANDBUTTON)
  640. {
  641. pDC->FillSolidRect(ptDots.x - 4, ptDots.y, 2, 2, clrText);
  642. pDC->FillSolidRect(ptDots.x, ptDots.y, 2, 2, clrText);
  643. pDC->FillSolidRect(ptDots.x + 4, ptDots.y, 2, 2, clrText);
  644. }
  645. if (pButton->IsFocused())
  646. {
  647. pDC->SetTextColor(GetXtremeColor(COLOR_BTNTEXT));
  648. pDC->SetBkColor(GetXtremeColor(COLOR_3DFACE));
  649. rect.DeflateRect(2, 2);
  650. pDC->DrawFocusRect(rect);
  651. }
  652. }
  653. //////////////////////////////////////////////////////////////////////
  654. //
  655. CXTPPropertyGridNativeXPTheme::CXTPPropertyGridNativeXPTheme(CXTPPropertyGrid* pGrid)
  656. : CXTPPropertyGridPaintManager(pGrid)
  657. {
  658. m_buttonsStyle = xtpGridButtonsThemed;
  659. }
  660. void CXTPPropertyGridNativeXPTheme::RefreshMetrics()
  661. {
  662. CXTPPropertyGridPaintManager::RefreshMetrics();
  663. m_clrShadow.SetStandardValue(GetXtremeColor(XPCOLOR_STATICFRAME));
  664. }
  665. //////////////////////////////////////////////////////////////////////
  666. // CXTPPropertyGridOffice2003Theme
  667. CXTPPropertyGridOffice2003Theme::CXTPPropertyGridOffice2003Theme(CXTPPropertyGrid* pGrid)
  668. : CXTPPropertyGridPaintManager(pGrid)
  669. {
  670. m_bLunaTheme = FALSE;
  671. m_buttonsStyle = xtpGridButtonsThemed;
  672. }
  673. void CXTPPropertyGridOffice2003Theme::RefreshMetrics()
  674. {
  675. CXTPPropertyGridPaintManager::RefreshMetrics();
  676. m_bLunaTheme = FALSE;
  677. if (!XTPColorManager()->IsLunaColorsDisabled())
  678. {
  679. XTPCurrentSystemTheme systemTheme = XTPColorManager()->GetCurrentSystemTheme();
  680. switch (systemTheme)
  681. {
  682. case xtpSystemThemeRoyale:
  683. case xtpSystemThemeAero:
  684. case xtpSystemThemeBlue:
  685. m_clrFace.SetStandardValue(RGB(221, 236, 254));
  686. m_clrShadow.SetStandardValue(RGB(123, 164, 224));
  687. m_pMetrics->m_clrHelpBack.SetStandardValue(m_clrFace);
  688. m_pMetrics->m_clrLine.SetStandardValue(RGB(169, 199, 240));
  689. m_pMetrics->m_clrCategoryFore.SetStandardValue(0);
  690. m_bLunaTheme = TRUE;
  691. break;
  692. case xtpSystemThemeOlive:
  693. m_clrFace.SetStandardValue(RGB(243, 242, 231));
  694. m_clrShadow.SetStandardValue(RGB(188, 187, 177));
  695. m_pMetrics->m_clrHelpBack.SetStandardValue(m_clrFace);
  696. m_pMetrics->m_clrLine.SetStandardValue(RGB(197, 212, 159));
  697. m_pMetrics->m_clrCategoryFore.SetStandardValue(0);
  698. m_bLunaTheme = TRUE;
  699. break;
  700. case xtpSystemThemeSilver:
  701. m_clrFace.SetStandardValue(RGB(238, 238, 244));
  702. m_clrShadow.SetStandardValue(RGB(161, 160, 187));
  703. m_pMetrics->m_clrHelpBack.SetStandardValue(m_clrFace);
  704. m_pMetrics->m_clrLine.SetStandardValue(RGB(192, 192, 211));
  705. m_pMetrics->m_clrCategoryFore.SetStandardValue(0);
  706. m_bLunaTheme = TRUE;
  707. break;
  708. }
  709. }
  710. }
  711. //////////////////////////////////////////////////////////////////////
  712. // CXTPPropertyGridOffice2007Theme
  713. CXTPPropertyGridOffice2007Theme::CXTPPropertyGridOffice2007Theme(CXTPPropertyGrid* pGrid)
  714. : CXTPPropertyGridOffice2003Theme(pGrid)
  715. {
  716. }
  717. void CXTPPropertyGridOffice2007Theme::RefreshMetrics()
  718. {
  719. CXTPPropertyGridPaintManager::RefreshMetrics();
  720. m_bLunaTheme = FALSE;
  721. m_pMetrics->m_clrBack.SetCustomValue(RGB(255, 255, 255));
  722. m_pMetrics->m_clrFore.SetCustomValue(RGB(0, 0, 0));
  723. CXTPOffice2007Image* pImage = XTPOffice2007Images()->LoadFile(_T("PUSHBUTTON"));
  724. if (pImage)
  725. {
  726. m_clrFace.SetStandardValue(XTPOffice2007Images()->GetImageColor(_T("PropertyGrid"), _T("Background")));
  727. m_clrShadow.SetStandardValue(XTPOffice2007Images()->GetImageColor(_T("PropertyGrid"), _T("Shadow")));
  728. m_pMetrics->m_clrHelpBack.SetStandardValue(XTPOffice2007Images()->GetImageColor(_T("PropertyGrid"), _T("HelpBack")));
  729. m_pMetrics->m_clrHelpFore.SetStandardValue(XTPOffice2007Images()->GetImageColor(_T("PropertyGrid"), _T("HelpFore")));
  730. m_pMetrics->m_clrLine.SetStandardValue(XTPOffice2007Images()->GetImageColor(_T("PropertyGrid"), _T("GridLine")));
  731. m_pMetrics->m_clrCategoryFore.SetStandardValue(XTPOffice2007Images()->GetImageColor(_T("PropertyGrid"), _T("CategoryText")));
  732. m_clrHighlightText.SetStandardValue(XTPOffice2007Images()->GetImageColor(_T("PropertyGrid"), _T("HighlightText")));
  733. m_clrHighlight.SetStandardValue(XTPOffice2007Images()->GetImageColor(_T("PropertyGrid"), _T("Highlight")));
  734. }
  735. else
  736. {
  737. m_clrFace.SetStandardValue(RGB(173, 209, 255));
  738. m_clrShadow.SetStandardValue(RGB(101, 147, 207));
  739. m_pMetrics->m_clrHelpBack.SetStandardValue(RGB(214, 232, 255));
  740. m_pMetrics->m_clrHelpFore.SetStandardValue(RGB(0, 0, 0));
  741. m_pMetrics->m_clrLine.SetStandardValue(RGB(214, 232, 255));
  742. m_pMetrics->m_clrCategoryFore.SetStandardValue(RGB(21, 66, 139));
  743. m_clrHighlightText.SetStandardValue(0);
  744. m_clrHighlight.SetStandardValue(RGB(179, 200, 232));
  745. }
  746. }
  747. void CXTPPropertyGridPaintManager::DrawCheckBox(CDC* pDC, CXTPPropertyGridItemBool* pItem)
  748. {
  749. CRect rcValue = pItem->GetValueRect();
  750. CRect rcSample(rcValue.left + 2, rcValue.CenterPoint().y - 6, rcValue.left + 2 + 13, rcValue.CenterPoint().y + 7);
  751. CXTPPropertyGridPaintManager* pPaintManager = m_pGrid->GetPaintManager();
  752. if (pPaintManager->m_buttonsStyle == xtpGridButtonsThemed && pPaintManager->m_themeButton.IsAppThemed())
  753. {
  754. pPaintManager->m_themeButton.DrawThemeBackground(pDC->GetSafeHdc(), BP_CHECKBOX,
  755. pItem->GetReadOnly() ? (pItem->GetBool() ? CBS_CHECKEDDISABLED : CBS_UNCHECKEDDISABLED) :
  756. (pItem->GetBool() ? CBS_CHECKEDNORMAL : CBS_UNCHECKEDNORMAL),
  757. rcSample, 0);
  758. }
  759. else
  760. {
  761. pDC->DrawFrameControl(rcSample, DFC_BUTTON, DFCS_BUTTONCHECK |
  762. (pItem->GetReadOnly() ? DFCS_INACTIVE : 0) | (pItem->GetBool() ? DFCS_CHECKED : 0));
  763. }
  764. }
  765. void CXTPPropertyGridOffice2007Theme::DrawCheckBox(CDC* pDC, CXTPPropertyGridItemBool* pItem)
  766. {
  767. CXTPOffice2007Image* pImage = XTPOffice2007Images()->LoadFile(_T("TOOLBARBUTTONCHECKBOX"));
  768. if (!pImage)
  769. {
  770. CXTPPropertyGridOffice2003Theme::DrawCheckBox(pDC, pItem);
  771. return;
  772. }
  773. int nState = pItem->GetReadOnly() ? 3 : 0;
  774. if (pItem->GetBool()) nState += 4;
  775. CRect rcSrc(pImage->GetSource(nState, 12));
  776. CRect rcValue = pItem->GetValueRect();
  777. CRect rcSample(CPoint(rcValue.left + 2, rcValue.CenterPoint().y - rcSrc.Height() / 2), rcSrc.Size());
  778. pImage->DrawImage(pDC, rcSample, rcSrc, CRect(0, 0, 0, 0));
  779. }
  780. void CXTPPropertyGridOffice2007Theme::FillInplaceButton(CDC* pDC, CXTPPropertyGridInplaceButton* pButton)
  781. {
  782. CRect rect(pButton->GetRect());
  783. CPoint ptDots(rect.CenterPoint().x , rect.CenterPoint().y + 3);
  784. COLORREF clrText = GetXtremeColor(pButton->GetEnabled() ? COLOR_BTNTEXT : COLOR_GRAYTEXT);
  785. CXTPOffice2007Image* pImage = XTPOffice2007Images()->LoadFile(_T("PUSHBUTTON"));
  786. if (pImage)
  787. {
  788. int nState = pButton->IsPressed() && pButton->IsHot() ? 2 : pButton->IsHot() ? 1 : 0;
  789. pImage->DrawImage(pDC, rect, pImage->GetSource(nState, 5), CRect(3, 3, 3, 3), 0xFF00FF);
  790. }
  791. else
  792. {
  793. pDC->FillSolidRect(rect, pButton->IsPressed() && pButton->IsHot() ? RGB(255, 171, 63) :
  794. pButton->IsHot() ? RGB(255, 231, 162) : m_clrFace);
  795. COLORREF clrBorder = GetXtremeColor(pButton->IsPressed() && pButton->IsHot() ? RGB(251, 140, 60) :
  796. pButton->IsHot() ? RGB(255, 189, 105) : m_clrShadow);
  797. pDC->Draw3dRect(rect, clrBorder, clrBorder);
  798. }
  799. if (pButton->GetID() == XTP_ID_PROPERTYGRID_COMBOBUTTON)
  800. {
  801. CPoint pt = rect.CenterPoint();
  802. CXTPDrawHelpers::Triangle(pDC, CPoint(pt.x -3, pt.y -1), CPoint(pt.x + 3, pt.y -1), CPoint(pt.x, pt.y +2), clrText);
  803. }
  804. BOOL bCustom = FALSE;
  805. if (pButton->GetID() != XTP_ID_PROPERTYGRID_COMBOBUTTON)
  806. {
  807. CXTPImageManagerIcon* pIcon = pButton->GetImage();
  808. if (pIcon)
  809. {
  810. CSize sz(pIcon->GetWidth(), pIcon->GetHeight());
  811. CPoint pt((rect.left + rect.right - sz.cx) / 2, (rect.top + rect.bottom - sz.cy) / 2);
  812. pIcon->Draw(pDC, pt, sz);
  813. bCustom = TRUE;
  814. }
  815. else if (!pButton->GetCaption().IsEmpty())
  816. {
  817. CXTPFontDC font(pDC, GetItemFont(pButton->GetItem(), TRUE));
  818. pDC->SetTextColor(clrText);
  819. pDC->DrawText(pButton->GetCaption(), rect, DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_NOPREFIX);
  820. bCustom = TRUE;
  821. }
  822. }
  823. if (!bCustom && pButton->GetID() == XTP_ID_PROPERTYGRID_EXPANDBUTTON)
  824. {
  825. pDC->FillSolidRect(ptDots.x - 4, ptDots.y, 2, 2, clrText);
  826. pDC->FillSolidRect(ptDots.x, ptDots.y, 2, 2, clrText);
  827. pDC->FillSolidRect(ptDots.x + 4, ptDots.y, 2, 2, clrText);
  828. }
  829. if (pButton->IsFocused())
  830. {
  831. pDC->SetTextColor(GetXtremeColor(COLOR_BTNTEXT));
  832. pDC->SetBkColor(GetXtremeColor(COLOR_3DFACE));
  833. rect.DeflateRect(2, 2);
  834. pDC->DrawFocusRect(rect);
  835. }
  836. }
  837. //////////////////////////////////////////////////////////////////////
  838. // CXTPPropertyGridCoolTheme
  839. CXTPPropertyGridCoolTheme::CXTPPropertyGridCoolTheme(CXTPPropertyGrid* pGrid)
  840. : CXTPPropertyGridPaintManager(pGrid)
  841. {
  842. }
  843. void CXTPPropertyGridCoolTheme::RefreshMetrics()
  844. {
  845. CXTPPropertyGridPaintManager::RefreshMetrics();
  846. m_pMetrics->m_clrLine.SetStandardValue(GetXtremeColor(COLOR_3DFACE));
  847. }
  848. void CXTPPropertyGridCoolTheme::DrawItem(PDRAWITEMSTRUCT lpDrawItemStruct)
  849. {
  850. CXTPPropertyGridView* pView = &m_pGrid->GetGridView();
  851. CXTPPropertyGridItem* pItem = (CXTPPropertyGridItem*)lpDrawItemStruct->itemData;
  852. ASSERT(pItem != NULL);
  853. if (!pItem)
  854. return;
  855. CXTPWindowRect rcWindow(pView);
  856. CRect rc = lpDrawItemStruct->rcItem;
  857. CXTPBufferDC dc(lpDrawItemStruct->hDC, rc);
  858. CXTPFontDC font(&dc, GetItemFont(pItem, TRUE));
  859. dc.FillSolidRect(rc, GetItemBackColor(pItem, FALSE));
  860. dc.SetBkMode(TRANSPARENT);
  861. CRect rcCaption(rc.left, rc.top, rc.left + pView->GetDividerPos(), rc.bottom);
  862. COLORREF clrLine = m_pMetrics->m_clrLine;
  863. COLORREF clrShadow = GetXtremeColor(COLOR_3DSHADOW);
  864. if (pItem->IsCategory())
  865. {
  866. dc.FillSolidRect(rc, clrLine);
  867. font.SetFont(GetItemFont(pItem, FALSE));
  868. dc.SetTextColor(GetItemTextColor(pItem, FALSE));
  869. int nIndent = XTP_PGI_EXPAND_BORDER * (pItem->GetIndent() + 1);
  870. if (lpDrawItemStruct->itemState & ODS_FOCUS)
  871. {
  872. dc.SetTextColor(m_clrHighlightText);
  873. dc.FillSolidRect(CRect(nIndent - 1, rc.top , rc.right, rc.bottom), m_clrHighlight);
  874. }
  875. CRect rcText(nIndent + 3, rc.top , rc.right, rc.bottom - 1);
  876. CXTPPropertyGridItemMetrics* pMetrics = pItem->GetMetrics(FALSE, FALSE);
  877. if (pMetrics && pMetrics->m_nImage != -1)
  878. {
  879. CXTPImageManagerIcon* pImage = m_pGrid->GetImageManager()->GetImage(pMetrics->m_nImage, 0);
  880. if (pImage)
  881. {
  882. int nHeight = min(pImage->GetHeight(), rc.Height());
  883. int nWidth = pImage->GetWidth();
  884. CPoint pt(rcText.left, rcText.CenterPoint().y - nHeight/2);
  885. pImage->Draw(&dc, pt, CSize(nWidth, nHeight));
  886. rcText.OffsetRect(nWidth + 4, 0);
  887. }
  888. }
  889. dc.DrawText(pItem->GetCaption(), rcText, DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER);
  890. dc.FillSolidRect((pItem->GetIndent() + (pItem->IsExpanded() ? 1 : 0)) * XTP_PGI_EXPAND_BORDER - 1, rc.bottom - 1, rc.Width(), 1, clrShadow);
  891. BOOL bSelected = (lpDrawItemStruct->itemState & (ODS_SELECTED | ODS_FOCUS));
  892. if (bSelected || m_pGrid->GetShowInplaceButtonsAlways()) DrawInplaceButtons(&dc, pItem, rcText);
  893. CXTPPropertyGridItem* pCategory = pItem->GetParentItem();
  894. while (pCategory != NULL)
  895. {
  896. if (pCategory->IsCategory())
  897. {
  898. dc.FillSolidRect(rc.left + pCategory->GetIndent() * XTP_PGI_EXPAND_BORDER, rc.top, XTP_PGI_EXPAND_BORDER, rc.Height(), clrLine);
  899. dc.FillSolidRect(rc.left + (pCategory->GetIndent() + 1) * XTP_PGI_EXPAND_BORDER - 1, rc.top, 1, rc.Height() + 2, clrShadow);
  900. }
  901. pCategory = pCategory->GetParentItem();
  902. }
  903. }
  904. else
  905. {
  906. CRect rcValue(rcCaption.right, rc.top, rc.right, rc.bottom - 1);
  907. DrawItemValue(&dc, pItem, rcValue);
  908. dc.SetTextColor(GetItemTextColor(pItem, FALSE));
  909. font.SetFont(GetItemFont(pItem, FALSE));
  910. BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
  911. BOOL bFocused = bSelected && CWnd::GetFocus() && ((CWnd::GetFocus() == pView) || (CWnd::GetFocus()->GetParent() == pView) || (CWnd::GetFocus()->GetOwner() == pView));
  912. if (bFocused)
  913. {
  914. dc.SetTextColor(m_clrHighlightText);
  915. dc.FillSolidRect(rcCaption, m_clrHighlight);
  916. }
  917. else if (bSelected && !m_pGrid->m_bHideSelection)
  918. {
  919. dc.FillSolidRect(rcCaption, clrLine);
  920. }
  921. CXTPPenDC pen(dc, clrLine);
  922. dc.MoveTo(0, rc.bottom - 1);
  923. dc.LineTo(rc.right, rc.bottom - 1);
  924. dc.MoveTo(rcCaption.right, rc.top);
  925. dc.LineTo(rcCaption.right, rc.bottom - 1);
  926. CXTPPropertyGridItem* pCategory = pItem->GetParentItem();
  927. while (pCategory != NULL)
  928. {
  929. if (pCategory->IsCategory())
  930. {
  931. dc.FillSolidRect(rc.left + pCategory->GetIndent() * XTP_PGI_EXPAND_BORDER, rc.top, XTP_PGI_EXPAND_BORDER, rc.Height(), clrLine);
  932. dc.FillSolidRect(rc.left + (pCategory->GetIndent() + 1) * XTP_PGI_EXPAND_BORDER - 1, rc.top, 1, rc.Height() + 2, clrShadow);
  933. }
  934. pCategory = pCategory->GetParentItem();
  935. }
  936. DrawItemCaption(&dc, pItem, rcCaption);
  937. if (bSelected || m_pGrid->GetShowInplaceButtonsAlways()) DrawInplaceButtons(&dc, pItem, rcValue);
  938. }
  939. CXTPPropertyGridItem* pNext = (CXTPPropertyGridItem*)pView->GetItemDataPtr(lpDrawItemStruct->itemID + 1);
  940. if (((ULONG_PTR)pNext == (ULONG_PTR)(-1)))
  941. dc.FillSolidRect(0, rc.bottom - 1, rc.Width(), 1, clrShadow);
  942. else if (pNext && pNext->IsCategory() && pNext->IsVisible())
  943. {
  944. dc.FillSolidRect(pNext->GetIndent() * XTP_PGI_EXPAND_BORDER, rc.bottom - 1, rc.Width(), 1, clrShadow);
  945. }
  946. CXTPPropertyGridItem* pPrev = pItem;
  947. if (!pPrev)
  948. return;
  949. CXTPPropertyGridItem* pCategory = pPrev->GetParentItem();
  950. while (pCategory != NULL)
  951. {
  952. if (pItem->HasChilds() && pItem->IsExpanded())
  953. break;
  954. if (pCategory->IsCategory() && pCategory->IsVisible() && pCategory->GetChilds()->GetAt(pCategory->GetChilds()->GetCount() - 1) == pPrev)
  955. {
  956. dc.FillSolidRect(pCategory->GetIndent() * XTP_PGI_EXPAND_BORDER, rc.bottom - 1, rc.Width(), 1, clrShadow);
  957. }
  958. else
  959. break;
  960. pPrev = pCategory;
  961. pCategory = pPrev->GetParentItem();
  962. }
  963. if (pItem->HasVisibleChilds())
  964. {
  965. CRgn rgn;
  966. if (!pItem->IsCategory())
  967. {
  968. rgn.CreateRectRgnIndirect(&rcCaption);
  969. dc.SelectClipRgn(&rgn);
  970. }
  971. DrawExpandButton(dc, pItem, rcCaption);
  972. dc.SelectClipRgn(NULL);
  973. }
  974. }
  975. //////////////////////////////////////////////////////////////////////
  976. // CXTPPropertyGridSimpleTheme
  977. CXTPPropertyGridSimpleTheme::CXTPPropertyGridSimpleTheme(CXTPPropertyGrid* pGrid)
  978. : CXTPPropertyGridPaintManager(pGrid)
  979. {
  980. }
  981. void CXTPPropertyGridSimpleTheme::RefreshMetrics()
  982. {
  983. CXTPPropertyGridPaintManager::RefreshMetrics();
  984. m_pMetrics->m_clrLine.SetStandardValue(GetXtremeColor(COLOR_3DFACE));
  985. }
  986. void CXTPPropertyGridSimpleTheme::DrawItem(PDRAWITEMSTRUCT lpDrawItemStruct)
  987. {
  988. CXTPPropertyGridView* pView = &m_pGrid->GetGridView();
  989. CXTPPropertyGridItem* pItem = (CXTPPropertyGridItem*)lpDrawItemStruct->itemData;
  990. ASSERT(pItem != NULL);
  991. if (!pItem)
  992. return;
  993. CXTPWindowRect rcWindow(pView);
  994. CRect rc = lpDrawItemStruct->rcItem;
  995. CXTPBufferDC dc(lpDrawItemStruct->hDC, rc);
  996. CXTPFontDC font(&dc, GetItemFont(pItem, FALSE));
  997. dc.FillSolidRect(rc, GetItemBackColor(pItem, FALSE));
  998. dc.SetBkMode(TRANSPARENT);
  999. CRect rcCaption(rc.left, rc.top, rc.left + pView->GetDividerPos(), rc.bottom);
  1000. COLORREF clrLine = m_pMetrics->m_clrLine;
  1001. {
  1002. if (!pItem->IsCategory())
  1003. {
  1004. CXTPFontDC fontValue(&dc, GetItemFont(pItem, TRUE));
  1005. CRect rcValue(rcCaption.right, rc.top, rc.right, rc.bottom - 1);
  1006. DrawItemValue(&dc, pItem, rcValue);
  1007. }
  1008. dc.SetTextColor(GetItemTextColor(pItem, FALSE));
  1009. BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
  1010. BOOL bFocused = bSelected && CWnd::GetFocus() && ((CWnd::GetFocus() == pView) || (CWnd::GetFocus()->GetParent() == pView) || (CWnd::GetFocus()->GetOwner() == pView));
  1011. if (bFocused)
  1012. {
  1013. dc.SetTextColor(m_clrHighlightText);
  1014. dc.FillSolidRect(CRect(XTP_PGI_EXPAND_BORDER, rcCaption.top, rcCaption.right, rcCaption.bottom), m_clrHighlight);
  1015. }
  1016. else if (bSelected && !m_pGrid->m_bHideSelection)
  1017. {
  1018. dc.FillSolidRect(CRect(XTP_PGI_EXPAND_BORDER, rcCaption.top, rcCaption.right, rcCaption.bottom), clrLine);
  1019. }
  1020. dc.FillSolidRect(XTP_PGI_EXPAND_BORDER - 1, rc.top, 1, rc.Height(), clrLine);
  1021. CXTPPenDC pen(dc, clrLine);
  1022. dc.MoveTo(XTP_PGI_EXPAND_BORDER, rc.bottom - 1);
  1023. dc.LineTo(rc.right, rc.bottom - 1);
  1024. dc.MoveTo(rcCaption.right, rc.top);
  1025. dc.LineTo(rcCaption.right, rc.bottom - 1);
  1026. DrawItemCaption(&dc, pItem, rcCaption);
  1027. CRect rcValue(rcCaption.right, rc.top, rc.right, rc.bottom - 1);
  1028. if (bSelected || m_pGrid->GetShowInplaceButtonsAlways())
  1029. DrawInplaceButtons(&dc, pItem, rcValue);
  1030. }
  1031. if (pView->GetCount() == (int)lpDrawItemStruct->itemID + 1)
  1032. dc.FillSolidRect(0, rc.bottom - 1, rc.Width(), 1, clrLine);
  1033. if (pItem->HasVisibleChilds())
  1034. {
  1035. CRgn rgn;
  1036. rgn.CreateRectRgnIndirect(&rcCaption);
  1037. dc.SelectClipRgn(&rgn);
  1038. DrawExpandButton(dc, pItem, rcCaption);
  1039. dc.SelectClipRgn(NULL);
  1040. }
  1041. }
  1042. //////////////////////////////////////////////////////////////////////
  1043. // CXTPPropertyGridDelphiTheme
  1044. CXTPPropertyGridDelphiTheme::CXTPPropertyGridDelphiTheme(CXTPPropertyGrid* pGrid)
  1045. : CXTPPropertyGridPaintManager(pGrid)
  1046. {
  1047. }
  1048. void CXTPPropertyGridDelphiTheme::DrawItem(PDRAWITEMSTRUCT lpDrawItemStruct)
  1049. {
  1050. CXTPPropertyGridView* pView = &m_pGrid->GetGridView();
  1051. CXTPPropertyGridItem* pItem = (CXTPPropertyGridItem*)lpDrawItemStruct->itemData;
  1052. ASSERT(pItem != NULL);
  1053. if (!pItem)
  1054. return;
  1055. CXTPWindowRect rcWindow(pView);
  1056. CRect rc = lpDrawItemStruct->rcItem;
  1057. CXTPBufferDC dc(lpDrawItemStruct->hDC, rc);
  1058. CXTPFontDC font(&dc, GetItemFont(pItem, FALSE));
  1059. dc.FillSolidRect(rc, GetItemBackColor(pItem, FALSE));
  1060. dc.SetBkMode(TRANSPARENT);
  1061. CRect rcCaption(rc.left, rc.top, rc.left + pView->GetDividerPos(), rc.bottom);
  1062. COLORREF clrFore = m_pMetrics->m_clrFore;
  1063. COLORREF clrShadow = GetXtremeColor(COLOR_3DSHADOW);
  1064. COLORREF clrLight = GetXtremeColor(COLOR_BTNHIGHLIGHT);
  1065. {
  1066. if (!pItem->IsCategory())
  1067. {
  1068. CXTPFontDC fontValue(&dc, GetItemFont(pItem, TRUE));
  1069. CRect rcValue(rcCaption.right, rc.top, rc.right, rc.bottom - 1);
  1070. DrawItemValue(&dc, pItem, rcValue);
  1071. }
  1072. dc.SetTextColor(GetItemTextColor(pItem, FALSE));
  1073. dc.Draw3dRect(rcCaption.right - 1, rc.top, 1, rc.Height(), clrShadow, clrShadow);
  1074. dc.Draw3dRect(rcCaption.right, rc.top, 1, rc.Height(), clrLight, clrLight);
  1075. BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
  1076. BOOL bFocused = bSelected && CWnd::GetFocus() && ((CWnd::GetFocus() == pView) || (CWnd::GetFocus()->GetParent() == pView) || (CWnd::GetFocus()->GetOwner() == pView));
  1077. if (bFocused || (bSelected && !m_pGrid->m_bHideSelection))
  1078. {
  1079. dc.Draw3dRect(rc, clrFore, clrLight);
  1080. }
  1081. else
  1082. {
  1083. for (int i = 0; i < rc.right; i += 2)
  1084. dc.SetPixel(i, rc.bottom - 1, clrShadow);
  1085. }
  1086. DrawItemCaption(&dc, pItem, rcCaption);
  1087. CRect rcValue(rcCaption.right, rc.top, rc.right, rc.bottom - 1);
  1088. if (bSelected || m_pGrid->GetShowInplaceButtonsAlways())
  1089. DrawInplaceButtons(&dc, pItem, rcValue);
  1090. }
  1091. if (pItem->HasVisibleChilds())
  1092. {
  1093. CRgn rgn;
  1094. rgn.CreateRectRgnIndirect(&rcCaption);
  1095. dc.SelectClipRgn(&rgn);
  1096. DrawExpandButton(dc, pItem, rcCaption);
  1097. dc.SelectClipRgn(NULL);
  1098. }
  1099. }
  1100. void CXTPPropertyGridDelphiTheme::RefreshMetrics()
  1101. {
  1102. CXTPPropertyGridPaintManager::RefreshMetrics();
  1103. m_pMetrics->m_clrBack.SetStandardValue(GetXtremeColor(COLOR_3DFACE));
  1104. m_pMetrics->m_clrFore.SetStandardValue(RGB(0, 0, 128));
  1105. }
  1106. //////////////////////////////////////////////////////////////////////////
  1107. // CXTPPropertyGridWhidbeyTheme
  1108. CXTPPropertyGridOfficeXPTheme::CXTPPropertyGridOfficeXPTheme(CXTPPropertyGrid* pGrid)
  1109. : CXTPPropertyGridPaintManager(pGrid)
  1110. {
  1111. m_buttonsStyle = xtpGridButtonsOfficeXP;
  1112. }
  1113. void CXTPPropertyGridOfficeXPTheme::RefreshMetrics()
  1114. {
  1115. CXTPPropertyGridPaintManager::RefreshMetrics();
  1116. m_pMetrics->m_clrCategoryFore.SetStandardValue(GetXtremeColor(COLOR_BTNTEXT));
  1117. m_pMetrics->m_clrLine.SetStandardValue(GetXtremeColor(XPCOLOR_TOOLBAR_FACE));
  1118. }
  1119. //////////////////////////////////////////////////////////////////////////
  1120. // CXTPPropertyGridWhidbeyTheme
  1121. CXTPPropertyGridWhidbeyTheme::CXTPPropertyGridWhidbeyTheme(CXTPPropertyGrid* pGrid)
  1122. : CXTPPropertyGridPaintManager(pGrid)
  1123. {
  1124. m_buttonsStyle = xtpGridButtonsThemed;
  1125. }
  1126. void CXTPPropertyGridWhidbeyTheme::DrawCategoryCaptionBackground(CDC* pDC, CXTPPropertyGridItem* /*pItem*/, CRect rc)
  1127. {
  1128. pDC->FillSolidRect(rc, m_pMetrics->m_clrLine);
  1129. XTPDrawHelpers()->GradientFill(pDC,
  1130. CRect(rc.left, rc.bottom - 2, rc.right, rc.bottom - 1), m_pMetrics->m_clrLine, GetXtremeColor(COLOR_3DHIGHLIGHT), TRUE);
  1131. }
  1132. void CXTPPropertyGridWhidbeyTheme::RefreshMetrics()
  1133. {
  1134. CXTPPropertyGridPaintManager::RefreshMetrics();
  1135. m_pMetrics->m_clrLine.SetStandardValue(GetXtremeColor(COLOR_3DFACE));
  1136. m_pMetrics->m_clrCategoryFore.SetStandardValue(GetXtremeColor(COLOR_BTNTEXT));
  1137. m_clrShadow.SetStandardValue(GetXtremeColor(XPCOLOR_STATICFRAME));
  1138. }
  1139. void CXTPPropertyGridWhidbeyTheme::DrawExpandButton(CDC& dc, CXTPPropertyGridItem* pItem, CRect rcCaption)
  1140. {
  1141. if (!pItem->IsExpandable())
  1142. return;
  1143. CRect rcButton(CPoint(XTP_PGI_EXPAND_BORDER / 2 - 5, rcCaption.CenterPoint().y - 4), CSize(9, 9));
  1144. if (pItem->GetIndent() > 0)
  1145. rcButton.OffsetRect((pItem->GetIndent() - (pItem->IsCategory() ? 0 : 1)) * XTP_PGI_EXPAND_BORDER, 0);
  1146. CDC* pDC = &dc;
  1147. COLORREF clrButton = GetXtremeColor(COLOR_3DFACE);
  1148. COLORREF clrFrame = GetXtremeColor(COLOR_3DSHADOW);
  1149. pDC->FillSolidRect(rcButton.left + 1, rcButton.top + 1, 7, 7, clrButton);
  1150. pDC->FillSolidRect(rcButton.left + 1, rcButton.top, 9 - 2, 1, clrFrame);
  1151. pDC->FillSolidRect(rcButton.left + 1, rcButton.bottom - 1, 9 - 2, 1, clrFrame);
  1152. pDC->FillSolidRect(rcButton.left, rcButton.top + 1, 1, 9 - 2, clrFrame);
  1153. pDC->FillSolidRect(rcButton.right - 1, rcButton.top + 1, 1, 9 - 2, clrFrame);
  1154. pDC->FillSolidRect(rcButton.left + 1, rcButton.top + 1, 9 - 2, 3, 0xFFFFFF);
  1155. pDC->FillSolidRect(rcButton.left + 1, rcButton.top + 4, 9 - 4, 2, 0xFFFFFF);
  1156. pDC->FillSolidRect(rcButton.left + 2, rcButton.top + 4, 9 - 4, 1, 0);
  1157. if (!pItem->IsExpanded())
  1158. pDC->FillSolidRect(rcButton.left + 4, rcButton.top + 2, 1, 9 - 4, 0);
  1159. }