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

对话框与窗口

开发平台:

Visual C++

  1. // PropertyGridDlg.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 "PropertyGrid.h"
  22. #include "PropertyGridDlg.h"
  23. #include "AboutDlg.h"
  24. #include "CustomItems.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CPropertyGridDlg dialog
  32. CPropertyGridDlg::CPropertyGridDlg(CWnd* pParent /*=NULL*/)
  33. : CPropertyGridDlgBase(CPropertyGridDlg::IDD, pParent)
  34. , m_bHelpVisible(TRUE)
  35. , m_bToolBarVisible(FALSE)
  36. , m_bCustomColors(FALSE)
  37. , m_bVerbsVisible(FALSE)
  38. {
  39. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  40. m_nSort = 0;
  41. m_bCollapse = FALSE;
  42. m_bDoubleFont = FALSE;
  43. m_bWinXPTheme = FALSE;
  44. m_nTheme = 0;
  45. m_bTabItems = FALSE;
  46. m_bHighlightChanged = FALSE;
  47. m_bShowButtons = FALSE;
  48. m_bRightToLeft = FALSE;
  49. // Enable/Disable XP GUI Mode
  50. XTAuxData().bXPMode = TRUE;
  51. }
  52. void CPropertyGridDlg::DoDataExchange(CDataExchange* pDX)
  53. {
  54. CPropertyGridDlgBase::DoDataExchange(pDX);
  55. //{{AFX_DATA_MAP(CPropertyGridDlg)
  56. DDX_Control(pDX, IDC_COMBO_THEME, m_cmbTheme);
  57. DDX_Control(pDX, IDC_COMBO_BORDER, m_cmbBorder);
  58. DDX_Control(pDX, IDC_PLACEHOLDER, m_wndPlaceHolder);
  59. DDX_CBIndex(pDX, IDC_COMBO_THEME, m_nTheme);
  60. DDX_Check(pDX, IDC_CHK_TABITEMS, m_bTabItems);
  61. //}}AFX_DATA_MAP
  62. DDX_Check(pDX, IDC_CHK_HELP, m_bHelpVisible);
  63. DDX_Check(pDX, IDC_CHK_VERBS, m_bVerbsVisible);
  64. DDX_Check(pDX, IDC_CHK_TOOLBAR, m_bToolBarVisible);
  65. DDX_Check(pDX, IDC_CHK_DOUBLE, m_bDoubleFont);
  66. DDX_Radio(pDX, IDC_SORT_CATEGORIES, m_nSort);
  67. DDX_Check(pDX, IDC_CHK_CUSTOMCOLORS, m_bCustomColors);
  68. DDX_Check(pDX, IDC_CHK_HIGHLIGHT, m_bHighlightChanged);
  69. DDX_Check(pDX, IDC_CHECK_SHOWBUTTONS, m_bShowButtons);
  70. DDX_Check(pDX, IDC_CHK_RIGHTTOLEFT, m_bRightToLeft);
  71. }
  72. BEGIN_MESSAGE_MAP(CPropertyGridDlg, CPropertyGridDlgBase)
  73. //{{AFX_MSG_MAP(CPropertyGridDlg)
  74. ON_WM_SYSCOMMAND()
  75. ON_WM_PAINT()
  76. ON_WM_QUERYDRAGICON()
  77. ON_BN_CLICKED(IDC_BUTTON_SWITCHSTATE, OnButtonSwitchstate)
  78. ON_CBN_SELCHANGE(IDC_COMBO_THEME, OnSelchangeComboTheme)
  79. ON_CBN_SELCHANGE(IDC_COMBO_BORDER, OnSelchangeComboBorder)
  80. ON_BN_CLICKED(IDC_CHK_TABITEMS, OnChkTabitems)
  81. //}}AFX_MSG_MAP
  82. ON_BN_CLICKED(IDC_CHK_TOOLBAR, OnClickedChkToolbar)
  83. ON_BN_CLICKED(IDC_CHK_HELP, OnClickedChkHelp)
  84. ON_BN_CLICKED(IDC_CHK_VERBS, OnClickedChkVerbs)
  85. ON_BN_CLICKED(IDC_CHK_DOUBLE, OnClickedChkDouble)
  86. ON_BN_CLICKED(IDC_CHK_WINXPTHEME, OnClickedWinXPTheme)
  87. ON_BN_CLICKED(IDC_CHK_HIGHLIGHT, OnClickedHighlightChanged)
  88. ON_BN_CLICKED(IDC_SORT_CATEGORIES, OnClickedSort)
  89. ON_BN_CLICKED(IDC_SORT_ALPHABETICAL, OnClickedSort)
  90. ON_BN_CLICKED(IDC_SORT_NOSORT, OnClickedSort)
  91. ON_BN_CLICKED(IDC_CHECK_SHOWBUTTONS, OnClickShowButtons)
  92. ON_BN_CLICKED(IDC_CHK_RIGHTTOLEFT, OnClickRightToLeft)
  93. ON_MESSAGE(XTPWM_PROPERTYGRID_NOTIFY, OnGridNotify)
  94. ON_BN_CLICKED(IDC_CHK_CUSTOMCOLORS, OnClickedCustomcolors)
  95. END_MESSAGE_MAP()
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CPropertyGridDlg message handlers
  98. BOOL CPropertyGridDlg::OnInitDialog()
  99. {
  100. CPropertyGridDlgBase::OnInitDialog();
  101. // Add "About..." menu item to system menu.
  102. // IDM_ABOUTBOX must be in the system command range.
  103. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  104. ASSERT(IDM_ABOUTBOX < 0xF000);
  105. CMenu* pSysMenu = GetSystemMenu(FALSE);
  106. if (pSysMenu != NULL)
  107. {
  108. CString strAboutMenu;
  109. strAboutMenu.LoadString(IDS_ABOUTBOX);
  110. if (!strAboutMenu.IsEmpty())
  111. {
  112. pSysMenu->AppendMenu(MF_SEPARATOR);
  113. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  114. }
  115. }
  116. // Set the icon for this dialog.  The framework does this automatically
  117. //  when the application's main window is not a dialog
  118. SetIcon(m_hIcon, TRUE);         // Set big icon
  119. SetIcon(m_hIcon, FALSE);        // Set small icon
  120. // get the size of the place holder, this will be used when creating the grid.
  121. CRect rc;
  122. m_wndPlaceHolder.GetWindowRect( &rc );
  123. ScreenToClient( &rc );
  124. // create the property grid.
  125. if ( m_wndPropertyGrid.Create( rc, this, IDC_PROPERTY_GRID ) )
  126. {
  127. m_wndPropertyGrid.SetVariableItemsHeight(TRUE);
  128. LOGFONT lf;
  129. GetFont()->GetLogFont( &lf );
  130. // create document settings category.
  131. CXTPPropertyGridItem* pSettings        = m_wndPropertyGrid.AddCategory(_T("Document Settings"));
  132. pSettings->SetTooltip(_T("Document Settings Category"));
  133. // add child items to category.
  134. CXTPPropertyGridItem* pItemSaveOnClose = pSettings->AddChildItem(new CXTPPropertyGridItemBool(_T("SaveOnClose"), TRUE));
  135. pSettings->AddChildItem(new CXTPPropertyGridItemFont(_T("WindowFont"), lf));
  136. pSettings->AddChildItem(new CXTPPropertyGridItemSize(_T("WindowSize"), CSize(100, 100)));
  137. pSettings->Expand();
  138. pItemSaveOnClose->Select();
  139. // create global settings category.
  140. CXTPPropertyGridItem* pGlobals      = m_wndPropertyGrid.AddCategory(_T("Global Settings"));
  141. // add child items to category.
  142. CXTPPropertyGridItem* pItemGreeting = pGlobals->AddChildItem(new CXTPPropertyGridItem(_T("Greeting Text"), _T("Welcome to your application!")));
  143. pGlobals->AddChildItem(new CXTPPropertyGridItemNumber(_T("ItemsInMRUList"), 4));
  144. CXTPPropertyGridItem* pItemRate     = pGlobals->AddChildItem(new CXTPPropertyGridItemNumber(_T("MaxRepeatRate"), 10));
  145. pGlobals->AddChildItem(new CXTPPropertyGridItemColor(_T("ToolbarColor"), RGB(255, 192,128)));
  146. pItemGreeting->SetReadOnly(TRUE);
  147. pItemRate->SetDescription(_T("The rate in milliseconds that the text will repeat."));
  148. //////////////////////////////////////////////////////////////////////////
  149. // Version category.
  150. CXTPPropertyGridItem* pVersion      = m_wndPropertyGrid.AddCategory(_T("Version"));
  151. // add child items to category.
  152. CXTPPropertyGridItem* pItemVersion  = pVersion->AddChildItem(new CXTPPropertyGridItem(_T("AppVersion"), _T("1.0")));
  153. CXTPPropertyGridItem* pItemLanguage = pVersion->AddChildItem(new CXTPPropertyGridItem(ID_ITEM_VERSION_LANGUAGE, _T("English (United States)")));
  154. pItemVersion->SetReadOnly(TRUE);
  155. pVersion->Expand();
  156. CXTPPropertyGridItemConstraints* pList = pItemLanguage->GetConstraints();
  157. pList->AddConstraint(_T("Neutral"));
  158. pList->AddConstraint(_T("Arabic"));
  159. pList->AddConstraint(_T("German"));
  160. pList->AddConstraint(_T("Chinese(Taiwan)"));
  161. pList->AddConstraint(_T("English (United Kingdom)"));
  162. pList->AddConstraint(_T("English (United States)"));
  163. pList->AddConstraint(_T("France"));
  164. pList->AddConstraint(_T("Russian"));
  165. pItemLanguage->SetFlags(xtpGridItemHasComboButton | xtpGridItemHasEdit);
  166. //////////////////////////////////////////////////////////////////////////
  167. // Dynamic Options
  168. CXTPPropertyGridItem* pCategoryDynamic = m_wndPropertyGrid.AddCategory(_T("Dynamic Options"));
  169. CXTPPropertyGridItemBool* pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
  170. new CXTPPropertyGridItemBool(_T("Advanced"), FALSE));
  171. pItemBool->SetID(501);
  172. pItemBool->SetCheckBoxStyle();
  173. pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
  174. new CXTPPropertyGridItemBool(_T("Option 1"), FALSE));
  175. pItemBool->SetHidden(TRUE);
  176. pItemBool->SetCheckBoxStyle();
  177. pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
  178. new CXTPPropertyGridItemBool(_T("Option 2"), FALSE));
  179. pItemBool->SetHidden(TRUE);
  180. pItemBool->SetCheckBoxStyle();
  181. pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
  182. new CXTPPropertyGridItemBool(_T("Option 3"), FALSE));
  183. pItemBool->SetHidden(TRUE);
  184. pItemBool->SetCheckBoxStyle();
  185. pItemBool = (CXTPPropertyGridItemBool*)pCategoryDynamic->AddChildItem(
  186. new CXTPPropertyGridItemBool(_T("Option 4"), TRUE));
  187. pItemBool->SetHidden(TRUE);
  188. pItemBool->SetCheckBoxStyle();
  189. pItemBool->SetReadOnly();
  190. // create standard items category.
  191. CXTPPropertyGridItem* pStandard   = m_wndPropertyGrid.AddCategory(_T("Standard Items"));
  192. pStandard->AddChildItem(new CXTPPropertyGridItem(_T("String item")));
  193. pStandard->AddChildItem(new CXTPPropertyGridItemMultilineString(_T("Multiline String item"), _T("1rn2")));
  194. pStandard->AddChildItem(new CXTPPropertyGridItemNumber(_T("Integer item")));
  195. pStandard->AddChildItem(new CXTPPropertyGridItemDouble(_T("Double item")));
  196. pStandard->AddChildItem(new CXTPPropertyGridItemColor(_T("Color item")));
  197. pStandard->AddChildItem(new CXTPPropertyGridItemBool(_T("Bool item")));
  198. pStandard->AddChildItem(new CXTPPropertyGridItemFont(_T("Font item"), lf));
  199. COleDateTime dates(1981, 1, 26, 0, 0, 0 );
  200. pStandard->AddChildItem(new CXTPPropertyGridItemDate(_T("Date item"), dates));
  201. pStandard->AddChildItem(new CXTPPropertyGridItemSize(_T("Size item")));
  202. CXTPPropertyGridItem* pItem = pStandard->AddChildItem(new CXTPPropertyGridItemEnum(_T("Enum item"), 2));
  203. pItem->GetConstraints()->AddConstraint(_T("Windows 98"), 1);
  204. pItem->GetConstraints()->AddConstraint(_T("Windows 2000"), 2);
  205. pItem->GetConstraints()->AddConstraint(_T("Windows XP"), 3);
  206. pItem = pStandard->AddChildItem(new CXTPPropertyGridItemFlags(_T("Flag item"), 1 + 2));
  207. pItem->GetConstraints()->AddConstraint(_T("All Windows"), 1 + 2 + 4);
  208. pItem->GetConstraints()->AddConstraint(_T("Windows 98"), 1);
  209. pItem->GetConstraints()->AddConstraint(_T("Windows 2000"), 2);
  210. pItem->GetConstraints()->AddConstraint(_T("Windows XP"), 4);
  211. //////////////////////////////////////////////////////////////////////////
  212. CXTPPropertyGridItem* pButtons   = m_wndPropertyGrid.AddCategory(_T("Standard Buttons"));
  213. pItem = pButtons->AddChildItem(new CXTPPropertyGridItemBool(_T("Combo Button")));
  214. pItem->SetFlags(xtpGridItemHasComboButton);
  215. pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("Expand Button")));
  216. pItem->SetFlags(xtpGridItemHasEdit | xtpGridItemHasExpandButton);
  217. pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("2 Buttons")));
  218. pItem->SetID(510);
  219. pItem->SetFlags(xtpGridItemHasEdit | xtpGridItemHasComboButton | xtpGridItemHasExpandButton);
  220. pItem->GetConstraints()->AddConstraint(_T("Windows 2000"), 1);
  221. pItem->GetConstraints()->AddConstraint(_T("Windows 98"), 2);
  222. pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("Text Button")));
  223. CXTPPropertyGridInplaceButton* pButton = pItem->GetInplaceButtons()->AddButton(new CXTPPropertyGridInplaceButton(1));
  224. pButton->SetCaption(_T("Find"));
  225. pItem = pButtons->AddChildItem(new CXTPPropertyGridItem(_T("Image Button")));
  226. pButton = pItem->GetInplaceButtons()->AddButton(new CXTPPropertyGridInplaceButton(1));
  227. pButton->SetIconIndex(100);
  228. UINT btnFilter[] = {100};
  229. m_wndPropertyGrid.GetImageManager()->SetIcons(IDB_BITMAP_FILTER, btnFilter, 1, 0);
  230. pButton->SetTooltip(_T("Set Filter for item"));
  231. pItem = pButtons->AddChildItem(new CXTPPropertyGridItemNumber(_T("Spin And Slider"), 60));
  232. pItem->AddSliderControl();
  233. pItem->AddSpinButton();
  234. //////////////////////////////////////////////////////////////////////////
  235. CXTPPropertyGridItem* pMetrics   = m_wndPropertyGrid.AddCategory(_T("Custom Metrics"));
  236. pItem = pMetrics->AddChildItem(new CXTPPropertyGridItem(_T("Value Colors"), _T("")));
  237. pItem->GetValueMetrics()->m_clrFore = 0xFF;
  238. pItem->GetValueMetrics()->m_clrBack = RGB(235, 235, 235);
  239. pItem = pMetrics->AddChildItem(new CXTPPropertyGridItem(_T("Caption Colors"), _T("")));
  240. pItem->GetCaptionMetrics()->m_clrFore = 0xFF0000;
  241. pItem->GetCaptionMetrics()->m_clrBack = RGB(235, 235, 235);
  242. pItem = pMetrics->AddChildItem(new CXTPPropertyGridItemEnum(_T("Images"), 2));
  243. pItem->GetConstraints()->AddConstraint(_T("Green"), 0, 0);
  244. pItem->GetConstraints()->AddConstraint(_T("Red"), 1, 1);
  245. pItem->GetConstraints()->AddConstraint(_T("Yellow"), 2, 2);
  246. pItem->GetConstraints()->AddConstraint(_T("Blue"), 3, 3);
  247. pItem->GetValueMetrics()->m_nImage = 2;
  248. pItem->GetCaptionMetrics()->m_nImage = 4;
  249. m_wndPropertyGrid.GetImageManager()->SetMaskColor(0xC0C0C0);
  250. m_wndPropertyGrid.GetImageManager()->SetIcons(IDB_BITMAP_CONSTRAINTS, 0, 5, CSize(20, 14));
  251. pItem = pMetrics->AddChildItem(new CXTPPropertyGridItem(_T("Variable Height"), _T("Item")));
  252. pItem->SetHeight(32);
  253. pItem->SetFlags(xtpGridItemHasComboButton);
  254. pItem = pMetrics->AddChildItem(new CXTPPropertyGridItem(_T("MultiLine"), _T("Codejock Softwarern428 Corunna AvenuernOwosso, Michigan 48867 USA")));
  255. pItem->SetMultiLinesCount(3);
  256. // create custom items category.
  257. CXTPPropertyGridItem* pCustom   = m_wndPropertyGrid.AddCategory(_T("Custom Items"));
  258. // add child items to category.
  259. CXTPPropertyGridItem* pItemIcon = pCustom->AddChildItem(new CCustomItemIcon(_T("Icon"), m_hIcon));
  260. CXTPPropertyGridItem* pItemDock = pCustom->AddChildItem(new CCustomItemChilds(_T("DockPadding"), CRect(100, 20, 400, 50)));
  261. pCustom->AddChildItem(new CCustomItemColor(_T("CustomCombolist"), RGB(0xFF, 0x80, 0x40)));
  262. pItemIcon->SetDescription(_T("This sample shows how to override draw function"));
  263. pItemDock->SetDescription(_T("This sample shows how to add item with childs"));
  264. pCustom->AddChildItem(new CCustomItemFileBox(_T("File Box")));
  265. CXTPPropertyGridItem* pItemMaskEdit = pCustom->AddChildItem(new CXTPPropertyGridItem(_T("Mask Edit"), _T("Phone No: (816) 220-0000")));
  266. pItemMaskEdit->SetMask(_T("Phone No: (000) 000-0000"), _T("Phone No: (___) ___-____"));
  267. CXTPPropertyGridItem* pItemPassword = pCustom->AddChildItem(new CXTPPropertyGridItem(_T("Password"), _T("Text")));
  268. pItemPassword->SetPasswordMask();
  269. COleDateTime date(1981, 1, 26, 0, 0, 0 );
  270. pCustom->AddChildItem(new CXTPPropertyGridItemDate(_T("Date"), date));
  271. pCustom->AddChildItem(new CCustomItemUpperCase(_T("UpperCase")));
  272. pCustom->AddChildItem(new CCustomItemIPAddress(_T("IP Address")));
  273. pCustom->AddChildItem(new CCustomItemMenu(_T("Popup Menu")));
  274. pCustom->AddChildItem(new CCustomItemEdit(_T("Output"), _T("Debug")));
  275. // add multi level tree node.
  276. CXTPPropertyGridItem* pCategoryOne    = pCustom->AddChildItem(new CXTPPropertyGridItemCategory(_T("First Sub Category")));
  277. CXTPPropertyGridItem* pCategoryTwo    = pCategoryOne->AddChildItem(new CXTPPropertyGridItemCategory(_T("Second Sub Category 1")));
  278. pCategoryTwo->AddChildItem(new CXTPPropertyGridItem(_T("Third Level 1"), _T("")));
  279. pCategoryTwo->AddChildItem(new CXTPPropertyGridItem(_T("Third Level 2"), _T("")));
  280. CXTPPropertyGridItem* pCategoryTwo2   = pCategoryOne->AddChildItem(new CXTPPropertyGridItemCategory(_T("Second Sub Category 2")));
  281. pCategoryTwo2->AddChildItem(new CXTPPropertyGridItem(_T("Third Level 1"), _T("")));
  282. CXTPPropertyGridItem* pItemOne    = pCustom->AddChildItem(new CXTPPropertyGridItem(_T("First Level"), _T("")));
  283. CXTPPropertyGridItem* pItemTwo    = pItemOne->AddChildItem(new CXTPPropertyGridItem(_T("Second Level"), _T("")));
  284. CXTPPropertyGridItem* pItemThird     = pItemTwo->AddChildItem(new CXTPPropertyGridItem(_T("Third Level"), _T("")));
  285. pItemThird->AddChildItem(new CXTPPropertyGridItem(_T("Fourth Level 1"), _T("")));
  286. pItemThird->AddChildItem(new CXTPPropertyGridItem(_T("Fourth Level 2"), _T("")));
  287. // create custom items category.
  288. pCustom   = m_wndPropertyGrid.AddCategory(_T("Custom Buttons"));
  289. CXTPPropertyGridItem* pItemSpin = pCustom->AddChildItem(new CCustomItemSpin(_T("SpinButton")));
  290. pItemSpin->SetDescription(_T("This sample shows how to add new button type"));
  291. pCustom->AddChildItem(new CCustomItemSlider(_T("Slider")));
  292. CCustomItemCheckBox* pItemCheckBox = (CCustomItemCheckBox*)pCustom->AddChildItem(new CCustomItemCheckBox(_T("Check Box")));
  293. pItemCheckBox->SetValue(_T("agree with conditions"));
  294. pItemCheckBox->SetBool(TRUE);
  295. pCustom->AddChildItem(new CCustomItemButton(_T("Left Origin"), FALSE, TRUE));
  296. pCustom->AddChildItem(new CCustomItemButton(_T("Right Origin"), FALSE, TRUE));
  297. pCustom->AddChildItem(new CCustomItemButton(_T("Pointer"), TRUE, TRUE));
  298. pCustom->AddChildItem(new CCustomItemButton(_T("Gradient"), TRUE, FALSE));
  299. }
  300. m_groupAppearance.SubclassDlgItem(IDC_GBOX_APPEAR, this);
  301. m_groupSort.SubclassDlgItem(IDC_GBOX_SORT, this);
  302. m_groupColor.SubclassDlgItem(IDC_GBOX_COLOR, this);
  303. // Set control resizing.
  304. SetResize(IDC_PROPERTY_GRID, SZ_TOP_LEFT, SZ_BOTTOM_RIGHT);
  305. SetResize(IDC_GBOX_APPEAR,       SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  306. SetResize(IDC_CHK_TOOLBAR,       SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  307. SetResize(IDC_CHK_HELP,          SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  308. SetResize(IDC_CHK_VERBS,         SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  309. SetResize(IDC_CHK_DOUBLE,        SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  310. SetResize(IDC_CHK_TABITEMS,      SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  311. SetResize(IDC_CHK_HIGHLIGHT,     SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  312. SetResize(IDC_COMBO_THEME,       SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  313. SetResize(IDC_GBOX_SORT,         SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  314. SetResize(IDC_SORT_CATEGORIES,   SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  315. SetResize(IDC_SORT_ALPHABETICAL, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  316. SetResize(IDC_SORT_NOSORT,       SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  317. SetResize(IDC_GBOX_COLOR,        SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  318. SetResize(IDC_CHK_CUSTOMCOLORS,  SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  319. SetResize(IDC_BUTTON_SWITCHSTATE,  SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  320. SetResize(IDC_COMBO_BORDER,      SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  321. SetResize(IDC_CHECK_SHOWBUTTONS, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  322. SetResize(IDC_CHK_RIGHTTOLEFT, SZ_TOP_RIGHT, SZ_TOP_RIGHT);
  323. // Load window placement
  324. AutoLoadPlacement(_T("PropertyGridSample"));
  325. m_cmbTheme.AddString(_T("xtpGridThemeDefault"));
  326. m_cmbTheme.AddString(_T("xtpGridThemeNativeWinXP"));
  327. m_cmbTheme.AddString(_T("xtpGridThemeOffice2003"));
  328. m_cmbTheme.AddString(_T("xtpGridThemeCool"));
  329. m_cmbTheme.AddString(_T("xtpGridThemeSimple"));
  330. m_cmbTheme.AddString(_T("xtpGridThemeDelphi"));
  331. m_cmbTheme.AddString(_T("xtpGridThemeWhidbey"));
  332. m_cmbTheme.AddString(_T("xtpGridThemeOfficeXP"));
  333. m_cmbTheme.AddString(_T("xtpGridThemeOffice2007"));
  334. m_cmbTheme.SetCurSel(0);
  335. m_cmbBorder.AddString(_T("xtpGridBorderNone"));
  336. m_cmbBorder.AddString(_T("xtpGridBorderFlat"));
  337. m_cmbBorder.AddString(_T("xtpGridBorderStaticEdge"));
  338. m_cmbBorder.AddString(_T("xtpGridBorderClientEdge"));
  339. m_cmbBorder.SetCurSel(3);
  340. return TRUE;  // return TRUE  unless you set the focus to a control
  341. }
  342. void CPropertyGridDlg::OnSysCommand(UINT nID, LPARAM lParam)
  343. {
  344. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  345. {
  346. CAboutDlg dlgAbout;
  347. dlgAbout.DoModal();
  348. }
  349. else
  350. {
  351. CPropertyGridDlgBase::OnSysCommand(nID, lParam);
  352. }
  353. }
  354. // If you add a minimize button to your dialog, you will need the code below
  355. //  to draw the icon.  For MFC applications using the document/view model,
  356. //  this is automatically done for you by the framework.
  357. void CPropertyGridDlg::OnPaint()
  358. {
  359. if (IsIconic())
  360. {
  361. CPaintDC dc(this); // device context for painting
  362. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  363. // Center icon in client rectangle
  364. int cxIcon = GetSystemMetrics(SM_CXICON);
  365. int cyIcon = GetSystemMetrics(SM_CYICON);
  366. CRect rect;
  367. GetClientRect(&rect);
  368. int x = (rect.Width() - cxIcon + 1) / 2;
  369. int y = (rect.Height() - cyIcon + 1) / 2;
  370. // Draw the icon
  371. dc.DrawIcon(x, y, m_hIcon);
  372. }
  373. else
  374. {
  375. CPropertyGridDlgBase::OnPaint();
  376. }
  377. }
  378. // The system calls this to obtain the cursor to display while the user drags
  379. //  the minimized window.
  380. HCURSOR CPropertyGridDlg::OnQueryDragIcon()
  381. {
  382. return (HCURSOR) m_hIcon;
  383. }
  384. void CPropertyGridDlg::OnClickedChkToolbar()
  385. {
  386. UpdateData();
  387. m_wndPropertyGrid.ShowToolBar(m_bToolBarVisible);
  388. }
  389. void CPropertyGridDlg::OnClickedChkHelp()
  390. {
  391. UpdateData();
  392. m_wndPropertyGrid.ShowHelp(m_bHelpVisible);
  393. }
  394. void CPropertyGridDlg::OnClickedChkVerbs()
  395. {
  396. UpdateData();
  397. if (m_bVerbsVisible)
  398. {
  399. m_wndPropertyGrid.GetVerbs()->Add(_T("Sample Verb"), 0);
  400. }
  401. else
  402. {
  403. m_wndPropertyGrid.GetVerbs()->RemoveAll();
  404. }
  405. }
  406. void CPropertyGridDlg::OnClickedSort()
  407. {
  408. UpdateData();
  409. m_wndPropertyGrid.SetPropertySort((XTPPropertyGridSortOrder)m_nSort);
  410. }
  411. LRESULT CPropertyGridDlg::OnGridNotify(WPARAM wParam, LPARAM lParam)
  412. {
  413. if (wParam == XTP_PGN_INPLACEBUTTONDOWN)
  414. {
  415. CXTPPropertyGridInplaceButton* pButton = (CXTPPropertyGridInplaceButton*)lParam;
  416. if (pButton->GetItem()->GetID() == 510 && pButton->GetID() == XTP_ID_PROPERTYGRID_EXPANDBUTTON) // 2 Buttons
  417. {
  418. AfxMessageBox(_T("Expand button"));
  419. return TRUE;
  420. }
  421. }
  422. if (wParam == XTP_PGN_SORTORDER_CHANGED)
  423. {
  424. m_nSort = m_wndPropertyGrid.GetPropertySort();
  425. UpdateData(FALSE);
  426. TRACE(_T("SortOrder Changed.n"));
  427. }
  428. if (wParam == XTP_PGN_ITEMVALUE_CHANGED)
  429. {
  430. CXTPPropertyGridItem* pItem = (CXTPPropertyGridItem*)lParam;
  431. TRACE(_T("Value Changed. Caption = %s, ID = %i, Value = %sn"), pItem->GetCaption(), pItem->GetID(), pItem->GetValue());
  432. if (DYNAMIC_DOWNCAST(CXTPPropertyGridItemEnum, pItem))
  433. {
  434. if (pItem->GetMetrics(TRUE, FALSE))
  435. {
  436. pItem->GetMetrics(TRUE, FALSE)->m_nImage = ((CXTPPropertyGridItemEnum*)pItem)->GetEnum();
  437. }
  438. }
  439. if (pItem->GetID() == 501) // Dynamic Options
  440. {
  441. CXTPPropertyGridItems* pSiblingItems = pItem->GetParentItem()->GetChilds();
  442. for (int i = 0; i < pSiblingItems->GetCount(); i++)
  443. {
  444. if (pSiblingItems->GetAt(i) != pItem)
  445. {
  446. pSiblingItems->GetAt(i)->SetHidden(!((CXTPPropertyGridItemBool*)pItem)->GetBool());
  447. }
  448. }
  449. }
  450. }
  451. if (wParam == XTP_PGN_SELECTION_CHANGED)
  452. {
  453. CXTPPropertyGridItem* pItem = (CXTPPropertyGridItem*)lParam;
  454. if (pItem)
  455. {
  456. if (pItem->IsKindOf(RUNTIME_CLASS(CXTPPropertyGridItemColor)))
  457. {
  458. TRACE(_T("Color Item. Selection Changed. Item = %sn"), pItem->GetCaption());
  459. }
  460. if (pItem->GetID() == ID_ITEM_VERSION_LANGUAGE)
  461. {
  462. //pItem->SetDescription(pItem->GetDescription() + "!");
  463. }
  464. }
  465. }
  466. if (wParam == XTP_PGN_EDIT_CHANGED)
  467. {
  468. CXTPPropertyGridInplaceEdit* pEdit = DYNAMIC_DOWNCAST(CXTPPropertyGridInplaceEdit, (CWnd*)lParam);
  469. if (pEdit && pEdit->GetItem())
  470. {
  471. // Custom Validation
  472. if (pEdit->GetItem()->GetID() == ID_ITEM_VERSION_LANGUAGE)
  473. {
  474. CString str;
  475. pEdit->CEdit::GetWindowText(str);
  476. if (str.GetLength() > 30)
  477. {
  478. MessageBeep((UINT)-1);
  479. pEdit->SetSel(0, -1);
  480. pEdit->ReplaceSel(str.Left(30));
  481. }
  482. }
  483. // Custom Validation
  484. if (pEdit->GetItem()->GetCaption() == _T("ItemsInMRUList"))
  485. {
  486. CString str;
  487. pEdit->CEdit::GetWindowText(str);
  488. int i = _ttoi(str);
  489. if (i > 20)
  490. {
  491. MessageBeep((UINT)-1);
  492. pEdit->SetSel(0, -1);
  493. pEdit->ReplaceSel(_T("20"));
  494. }
  495. }
  496. }
  497. }
  498. return 0;
  499. }
  500. void CPropertyGridDlg::OnClickedCustomcolors()
  501. {
  502. UpdateData();
  503. if (m_bCustomColors)
  504. {
  505. m_wndPropertyGrid.SetCustomColors( RGB(200, 200, 200), 0, RGB(182, 210, 189), RGB(247, 243, 233), 0);
  506. }
  507. else m_wndPropertyGrid.SetStandardColors();
  508. }
  509. void CPropertyGridDlg::OnOK()
  510. {
  511. CXTPPropertyGridItem* pItem = 0;
  512. pItem = m_wndPropertyGrid.FindItem(ID_ITEM_VERSION_LANGUAGE);
  513. TRACE(_T("%s - %sn"), pItem->GetCaption(), pItem->GetValue());
  514. pItem = m_wndPropertyGrid.FindItem(_T("SaveOnClose"));
  515. TRACE(_T("%s - %sn"), pItem->GetCaption(), pItem->GetValue());
  516. CPropertyGridDlgBase::OnOK();
  517. }
  518. typedef void (CXTPPropertyGridItem::*ITEMFUNCTIONPTR)();
  519. void _DoCollapseExpand(CXTPPropertyGridItems* pItems, ITEMFUNCTIONPTR pFunction)
  520. {
  521. for (int i = 0; i < pItems->GetCount(); i++)
  522. {
  523. CXTPPropertyGridItem* pItem = pItems->GetAt(i);
  524. if (pItem->HasChilds())
  525. {
  526. (pItem->*pFunction)();
  527. _DoCollapseExpand(pItem->GetChilds(), pFunction);
  528. }
  529. }
  530. }
  531. void CPropertyGridDlg::OnButtonSwitchstate()
  532. {
  533. if (m_bCollapse)
  534. {
  535. _DoCollapseExpand(m_wndPropertyGrid.GetCategories(), &CXTPPropertyGridItem::Collapse);
  536. }
  537. else
  538. {
  539. _DoCollapseExpand(m_wndPropertyGrid.GetCategories(), &CXTPPropertyGridItem::Expand);
  540. }
  541. m_bCollapse = !m_bCollapse;
  542. }
  543. void CPropertyGridDlg::OnClickedChkDouble()
  544. {
  545. UpdateData();
  546. LOGFONT lfIcon;
  547. VERIFY( ::SystemParametersInfo( SPI_GETICONTITLELOGFONT, sizeof( lfIcon ), &lfIcon, 0 ) );
  548. if (m_bDoubleFont) lfIcon.lfHeight *= 2;
  549. CFont fntNormal;
  550. fntNormal.CreateFontIndirect(&lfIcon );
  551. m_wndPropertyGrid.SetFont(&fntNormal);
  552. }
  553. void CPropertyGridDlg::OnClickedWinXPTheme()
  554. {
  555. UpdateData();
  556. m_wndPropertyGrid.SetTheme(m_bWinXPTheme? xtpGridThemeNativeWinXP: xtpGridThemeDefault);
  557. }
  558. void CPropertyGridDlg::OnSelchangeComboTheme()
  559. {
  560. UpdateData();
  561. m_wndPropertyGrid.SetTheme((XTPPropertyGridPaintTheme)m_nTheme);
  562. }
  563. void CPropertyGridDlg::OnSelchangeComboBorder()
  564. {
  565. UpdateData();
  566. m_wndPropertyGrid.SetBorderStyle((XTPPropertyGridBorderStyle)m_cmbBorder.GetCurSel());
  567. }
  568. void CPropertyGridDlg::OnChkTabitems()
  569. {
  570. UpdateData();
  571. m_wndPropertyGrid.NavigateItems(m_bTabItems);
  572. }
  573. void CPropertyGridDlg::OnClickedHighlightChanged()
  574. {
  575. UpdateData();
  576. m_wndPropertyGrid.HighlightChangedItems(m_bHighlightChanged);
  577. }
  578. void CPropertyGridDlg::OnClickShowButtons()
  579. {
  580. UpdateData();
  581. m_wndPropertyGrid.SetShowInplaceButtonsAlways(m_bShowButtons);
  582. }
  583. void CPropertyGridDlg::OnClickRightToLeft()
  584. {
  585. UpdateData();
  586. m_wndPropertyGrid.SetLayoutRTL(m_bRightToLeft);
  587. }