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

对话框与窗口

开发平台:

Visual C++

  1. // SimpleGridPage.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 "SimpleGridPage.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CSimpleGridPage property page
  30. IMPLEMENT_DYNCREATE(CSimpleGridPage, CPropertyPage)
  31. CSimpleGridPage::CSimpleGridPage() : CPropertyPage(CSimpleGridPage::IDD)
  32. {
  33. //{{AFX_DATA_INIT(CSimpleGridPage)
  34. // NOTE: the ClassWizard will add member initialization here
  35. //}}AFX_DATA_INIT
  36. }
  37. CSimpleGridPage::~CSimpleGridPage()
  38. {
  39. }
  40. void CSimpleGridPage::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CPropertyPage::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CSimpleGridPage)
  44. // NOTE: the ClassWizard will add DDX and DDV calls here
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CSimpleGridPage, CPropertyPage)
  48. //{{AFX_MSG_MAP(CSimpleGridPage)
  49. //}}AFX_MSG_MAP
  50. ON_MESSAGE(XTPWM_PROPERTYGRID_NOTIFY, OnGridNotify)
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CSimpleGridPage message handlers
  54. LRESULT CSimpleGridPage::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 CSimpleGridPage::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. }
  101. return TRUE;  // return TRUE unless you set the focus to a control
  102.               // EXCEPTION: OCX Property Pages should return FALSE
  103. }
  104. void CSimpleGridPage::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  105. {
  106. CXTPPropertyGridItem* pItem = (CXTPPropertyGridItem*)lpDrawItemStruct->itemData;
  107. COLORREF clrWindow = GetSysColor(COLOR_WINDOW);
  108. ASSERT(pItem != NULL);
  109. CXTPPropertyGridView* pGrid = pItem->GetGrid();
  110. CXTPPropertyGridItemMetrics* pMetrics = pGrid->GetPaintManager()->GetItemMetrics();
  111. CXTPWindowRect rcWindow(pGrid);
  112. CRect rc = lpDrawItemStruct->rcItem;
  113. CXTPBufferDC dc(lpDrawItemStruct->hDC, rc);
  114. CXTPFontDC font(&dc, pItem->IsCategory()? &pMetrics->m_fontBold: &pMetrics->m_fontNormal);
  115. dc.FillSolidRect(rc, clrWindow);
  116. dc.SetBkMode(TRANSPARENT);
  117. CRect rcCaption(rc.left, rc.top, rc.left + pGrid->GetDividerPos(), rc.bottom);
  118. COLORREF clrLine = GetSysColor(COLOR_3DFACE);
  119. COLORREF clrFore = GetSysColor(COLOR_BTNTEXT);
  120. {
  121. if (!pItem->IsCategory())
  122. {
  123. dc.SetTextColor(pItem->GetReadOnly()? GetSysColor(COLOR_GRAYTEXT): clrFore);
  124. CRect rcValue(rc);
  125. rcValue.left = rcCaption.right + 4;
  126. rcValue.bottom -= 1;
  127. if (!pItem->OnDrawItemValue(dc, rcValue))
  128. {
  129. dc.DrawText( pItem->GetValue(), rcValue,  DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX);
  130. }
  131. }
  132. dc.SetTextColor(clrFore);
  133. BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
  134. BOOL bFocused = bSelected && GetFocus() && ((GetFocus() == pGrid) || (GetFocus()->GetParent() == pGrid) || (GetFocus()->GetOwner() == pGrid));
  135. if (bFocused)
  136. {
  137. dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
  138. dc.FillSolidRect(CRect(XTP_PGI_EXPAND_BORDER, rcCaption.top, rcCaption.right, rcCaption.bottom), ::GetSysColor(COLOR_HIGHLIGHT));
  139. }
  140. else if (bSelected)
  141. {
  142. dc.FillSolidRect(CRect(XTP_PGI_EXPAND_BORDER, rcCaption.top, rcCaption.right, rcCaption.bottom), clrLine);
  143. }
  144. dc.FillSolidRect(XTP_PGI_EXPAND_BORDER - 1, rc.top, 1, rc.Height(), clrLine);
  145. CXTPPenDC pen(dc, clrLine);
  146. dc.MoveTo(XTP_PGI_EXPAND_BORDER, rc.bottom - 1); dc.LineTo(rc.right, rc.bottom - 1);
  147. dc.MoveTo(rcCaption.right, rc.top); dc.LineTo(rcCaption.right, rc.bottom - 1);
  148. CRect rcText(rc);
  149. rcText.left = max(1, pItem->GetIndent()) * XTP_PGI_EXPAND_BORDER + 3;
  150. rcText.right = rcCaption.right - 1;
  151. rcText.bottom -= 1;
  152. dc.DrawText( pItem->GetCaption(),   rcText,  DT_SINGLELINE|DT_VCENTER);
  153. CRect rcValue(rcCaption.right, rc.top, rc.right, rc.bottom - 1);
  154. if (!pItem->IsCategory() && bSelected)
  155. pGrid->GetPaintManager()->DrawInplaceButtons(&dc, pItem, rcValue);
  156. }
  157. if (pGrid->GetCount() == (int)lpDrawItemStruct->itemID + 1)
  158. dc.FillSolidRect(0, rc.bottom - 1, rc.Width(), 1, clrLine);
  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,  clrWindow);
  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. }