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

对话框与窗口

开发平台:

Visual C++

  1. // DelphiGridPage.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO 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 "ownerdraw.h"
  22. #include "DelphiGridPage.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CDelphiGridPage property page
  30. IMPLEMENT_DYNCREATE(CDelphiGridPage, CPropertyPage)
  31. CDelphiGridPage::CDelphiGridPage() : CPropertyPage(CDelphiGridPage::IDD)
  32. {
  33. //{{AFX_DATA_INIT(CDelphiGridPage)
  34. // NOTE: the ClassWizard will add member initialization here
  35. //}}AFX_DATA_INIT
  36. }
  37. CDelphiGridPage::~CDelphiGridPage()
  38. {
  39. }
  40. void CDelphiGridPage::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CPropertyPage::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CDelphiGridPage)
  44. // NOTE: the ClassWizard will add DDX and DDV calls here
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CDelphiGridPage, CPropertyPage)
  48. //{{AFX_MSG_MAP(CDelphiGridPage)
  49. //}}AFX_MSG_MAP
  50. ON_MESSAGE(XTPWM_PROPERTYGRID_NOTIFY, OnGridNotify)
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CDelphiGridPage message handlers
  54. LRESULT CDelphiGridPage::OnGridNotify(WPARAM wParam, LPARAM lParam)
  55. {
  56. if (wParam == XTP_PGN_DRAWITEM)
  57. {
  58. DrawItem((LPDRAWITEMSTRUCT)lParam);
  59. return TRUE;
  60. }
  61. return FALSE;
  62. }
  63. BOOL CDelphiGridPage::OnInitDialog()
  64. {
  65. CPropertyPage::OnInitDialog();
  66. // get the size of the place holder, this will be used when creating the grid.
  67. CWnd* pPlaceHolder = GetDlgItem(IDC_PLACEHOLDER);
  68. CRect rc;
  69. pPlaceHolder->GetWindowRect( &rc );
  70. ScreenToClient( &rc );
  71. // create the property grid.
  72. if ( m_wndPropertyGrid.Create( rc, this, 100))
  73. {
  74. m_wndPropertyGrid.ModifyStyle(0, XTP_PGS_OWNERDRAW);
  75. LOGFONT lf;
  76. GetFont()->GetLogFont( &lf );
  77. // create document settings category.
  78. CXTPPropertyGridItem* pSettings        = m_wndPropertyGrid.AddCategory(_T("Document Settings"));
  79. // add child items to category.
  80. CXTPPropertyGridItem* pItemSaveOnClose = pSettings->AddChildItem(new CXTPPropertyGridItemBool(_T("SaveOnClose"), TRUE));
  81. pSettings->AddChildItem(new CXTPPropertyGridItemFont(_T("WindowFont"), lf));
  82. pSettings->AddChildItem(new CXTPPropertyGridItemSize(_T("WindowSize"), CSize(100, 100)));
  83. pSettings->Expand();
  84. pItemSaveOnClose->Select();
  85. // create global settings category.
  86. CXTPPropertyGridItem* pGlobals      = m_wndPropertyGrid.AddCategory(_T("Global Settings"));
  87. // add child items to category.
  88. CXTPPropertyGridItem* pItemGreeting = pGlobals->AddChildItem(new CXTPPropertyGridItem(_T("Greeting Text"), _T("Welcome to your application!")));
  89. pGlobals->AddChildItem(new CXTPPropertyGridItemNumber(_T("ItemsInMRUList"), 4));
  90. CXTPPropertyGridItem* pItemRate     = pGlobals->AddChildItem(new CXTPPropertyGridItemNumber(_T("MaxRepeatRate"), 10));
  91. pGlobals->AddChildItem(new CXTPPropertyGridItemColor(_T("ToolbarColor"), RGB(255, 192,128)));
  92. pItemGreeting->SetReadOnly(TRUE);
  93. pItemRate->SetDescription(_T("The rate in milliseconds that the text will repeat."));
  94. // create version category.
  95. CXTPPropertyGridItem* pVersion      = m_wndPropertyGrid.AddCategory(_T("Version"));
  96. // add child items to category.
  97. CXTPPropertyGridItem* pItemVersion  = pVersion->AddChildItem(new CXTPPropertyGridItem(_T("AppVersion"), _T("1.0")));
  98. pItemVersion->SetReadOnly(TRUE);
  99. pVersion->Expand();
  100. m_wndPropertyGrid.SetPropertySort(xtpGridSortNoSort);
  101. m_wndPropertyGrid.SetCustomColors(GetSysColor(COLOR_3DFACE), 0, GetSysColor(COLOR_3DFACE), GetSysColor(COLOR_3DFACE), RGB(0, 0, 128));
  102. }
  103. return TRUE;  // return TRUE unless you set the focus to a control
  104.               // EXCEPTION: OCX Property Pages should return FALSE
  105. }
  106. void CDelphiGridPage::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  107. {
  108. CXTPPropertyGridItem* pItem = (CXTPPropertyGridItem*)lpDrawItemStruct->itemData;
  109. COLORREF clrWindow = GetSysColor(COLOR_3DFACE);
  110. ASSERT(pItem != NULL);
  111. CXTPPropertyGridView* pGrid = pItem->GetGrid();
  112. CXTPWindowRect rcWindow(pGrid);
  113. CRect rc = lpDrawItemStruct->rcItem;
  114. CXTPPropertyGridItemMetrics* pMetrics = pGrid->GetPaintManager()->GetItemMetrics();
  115. CXTPBufferDC dc(lpDrawItemStruct->hDC, rc);
  116. CXTPFontDC font(&dc, pItem->IsCategory()? &pMetrics->m_fontBold: &pMetrics->m_fontNormal);
  117. dc.FillSolidRect(rc, clrWindow);
  118. dc.SetBkMode(TRANSPARENT);
  119. CRect rcCaption(rc.left, rc.top, rc.left + pGrid->GetDividerPos(), rc.bottom);
  120. COLORREF clrFore = GetSysColor(COLOR_BTNTEXT);
  121. COLORREF clrShadow = GetSysColor(COLOR_3DSHADOW);
  122. COLORREF clrLight = GetSysColor(COLOR_BTNHIGHLIGHT);
  123. {
  124. if (!pItem->IsCategory())
  125. {
  126. dc.SetTextColor(pItem->GetReadOnly()? GetSysColor(COLOR_GRAYTEXT): RGB(0, 0, 128));
  127. CRect rcValue(rc);
  128. rcValue.left = rcCaption.right + 4;
  129. rcValue.bottom -= 1;
  130. if (!pItem->OnDrawItemValue(dc, rcValue))
  131. {
  132. dc.DrawText( pItem->GetValue(), rcValue,  DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX);
  133. }
  134. }
  135. dc.SetTextColor(clrFore);
  136. dc.Draw3dRect(rcCaption.right - 1, rc.top, 1, rc.Height(), clrShadow, clrShadow);
  137. dc.Draw3dRect(rcCaption.right, rc.top, 1, rc.Height(), clrLight, clrLight);
  138. BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
  139. BOOL bFocused = bSelected && GetFocus() && ((GetFocus() == pGrid) || (GetFocus()->GetParent() == pGrid) || (GetFocus()->GetOwner() == pGrid));
  140. if (bFocused || bSelected)
  141. {
  142. dc.Draw3dRect(rc, clrFore, clrLight);
  143. }
  144. else
  145. {
  146. // somebody! optimize me!
  147. for (int i = 0; i < rc.right; i += 2)
  148. dc.SetPixel(i, rc.bottom - 1, clrShadow);
  149. }
  150. CRect rcText(rc);
  151. rcText.left = max(1, pItem->GetIndent()) * XTP_PGI_EXPAND_BORDER + 3;
  152. rcText.right = rcCaption.right - 1;
  153. rcText.bottom -= 1;
  154. dc.DrawText( pItem->GetCaption(),   rcText,  DT_SINGLELINE|DT_VCENTER);
  155. CRect rcValue(rcCaption.right, rc.top, rc.right, rc.bottom - 1);
  156. if (!pItem->IsCategory() && bSelected)
  157. pGrid->GetPaintManager()->DrawInplaceButtons(&dc, pItem, rcValue);
  158. }
  159. if (pItem->HasChilds())
  160. {
  161. CRgn rgn;
  162. rgn.CreateRectRgnIndirect(&rcCaption);
  163. dc.SelectClipRgn(&rgn);
  164. CRect rcSign(CPoint(XTP_PGI_EXPAND_BORDER / 2 - 5, rc.CenterPoint().y - 4), CSize(9, 9));
  165. if (pItem->GetIndent() > 1)
  166. rcSign.OffsetRect((pItem->GetIndent() - 1) * XTP_PGI_EXPAND_BORDER, 0);
  167. CPoint pt = rcSign.CenterPoint();
  168. CXTPBrushDC brush (dc,  GetSysColor(COLOR_WINDOW));
  169. CXTPPenDC pen (dc,  clrFore);
  170. dc.Rectangle(rcSign);
  171. dc.MoveTo(pt.x - 2, pt.y);
  172. dc.LineTo(pt.x + 3, pt.y);
  173. if(!pItem->IsExpanded())
  174. {
  175. dc.MoveTo(pt.x, pt.y - 2);
  176. dc.LineTo(pt.x, pt.y + 3);
  177. }
  178. dc.SelectClipRgn(NULL);
  179. }
  180. }