Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

624 lines
18 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ResTProp.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the resource type property sheet and pages.
  10. //
  11. // Author:
  12. // David Potter (davidp) May 14, 1996
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "ResTProp.h"
  21. #include "ResType.h"
  22. #include "DDxDDv.h"
  23. #include "HelpData.h" // for g_rghelpmap*
  24. #include "resource.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CResTypePropSheet
  32. /////////////////////////////////////////////////////////////////////////////
  33. IMPLEMENT_DYNAMIC(CResTypePropSheet, CBasePropertySheet)
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Message Maps
  36. BEGIN_MESSAGE_MAP(CResTypePropSheet, CBasePropertySheet)
  37. //{{AFX_MSG_MAP(CResTypePropSheet)
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. //++
  42. //
  43. // CResTypePropSheet::CResTypePropSheet
  44. //
  45. // Routine Description:
  46. // Constructor.
  47. //
  48. // Arguments:
  49. // pci [IN OUT] Cluster item whose properties are to be displayed.
  50. // pParentWnd [IN OUT] Parent window for this property sheet.
  51. // iSelectPage [IN] Page to show first.
  52. //
  53. // Return Value:
  54. // None.
  55. //
  56. //--
  57. /////////////////////////////////////////////////////////////////////////////
  58. CResTypePropSheet::CResTypePropSheet(
  59. IN OUT CWnd * pParentWnd,
  60. IN UINT iSelectPage
  61. )
  62. : CBasePropertySheet(pParentWnd, iSelectPage)
  63. {
  64. m_rgpages[0] = &PageGeneral();
  65. } //*** CResTypePropSheet::CResTypePropSheet()
  66. /////////////////////////////////////////////////////////////////////////////
  67. //++
  68. //
  69. // CResTypePropSheet::BInit
  70. //
  71. // Routine Description:
  72. // Initialize the property sheet.
  73. //
  74. // Arguments:
  75. // pci [IN OUT] Cluster item whose properties are to be displayed.
  76. // iimgIcon [IN] Index in the large image list for the image to use
  77. // as the icon on each page.
  78. //
  79. // Return Value:
  80. // TRUE Property sheet initialized successfully.
  81. // FALSE Error initializing property sheet.
  82. //
  83. //--
  84. /////////////////////////////////////////////////////////////////////////////
  85. BOOL CResTypePropSheet::BInit(
  86. IN OUT CClusterItem * pci,
  87. IN IIMG iimgIcon
  88. )
  89. {
  90. // Call the base class method.
  91. if (!CBasePropertySheet::BInit(pci, iimgIcon))
  92. return FALSE;
  93. // Set the read-only flag.
  94. m_bReadOnly = PciResType()->BReadOnly();
  95. return TRUE;
  96. } //*** CResTypePropSheet::BInit()
  97. /////////////////////////////////////////////////////////////////////////////
  98. //++
  99. //
  100. // CResTypePropSheet::Ppages
  101. //
  102. // Routine Description:
  103. // Returns the array of pages to add to the property sheet.
  104. //
  105. // Arguments:
  106. // None.
  107. //
  108. // Return Value:
  109. // Page array.
  110. //
  111. //--
  112. /////////////////////////////////////////////////////////////////////////////
  113. CBasePropertyPage ** CResTypePropSheet::Ppages(void)
  114. {
  115. return m_rgpages;
  116. } //*** CResTypePropSheet::Ppages()
  117. /////////////////////////////////////////////////////////////////////////////
  118. //++
  119. //
  120. // CResTypePropSheet::Cpages
  121. //
  122. // Routine Description:
  123. // Returns the count of pages in the array.
  124. //
  125. // Arguments:
  126. // None.
  127. //
  128. // Return Value:
  129. // Count of pages in the array.
  130. //
  131. //--
  132. /////////////////////////////////////////////////////////////////////////////
  133. int CResTypePropSheet::Cpages(void)
  134. {
  135. return sizeof(m_rgpages) / sizeof(CBasePropertyPage *);
  136. } //*** CResTypePropSheet::Cpages()
  137. //*************************************************************************//
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CResTypeGeneralPage property page
  140. /////////////////////////////////////////////////////////////////////////////
  141. IMPLEMENT_DYNCREATE(CResTypeGeneralPage, CBasePropertyPage)
  142. /////////////////////////////////////////////////////////////////////////////
  143. // Message Maps
  144. BEGIN_MESSAGE_MAP(CResTypeGeneralPage, CBasePropertyPage)
  145. //{{AFX_MSG_MAP(CResTypeGeneralPage)
  146. ON_EN_KILLFOCUS(IDC_PP_RESTYPE_DISPLAY_NAME, OnKillFocusDisplayName)
  147. ON_LBN_DBLCLK(IDC_PP_RESTYPE_POSSIBLE_OWNERS, OnDblClkPossibleOwners)
  148. ON_WM_CONTEXTMENU()
  149. //}}AFX_MSG_MAP
  150. ON_EN_CHANGE(IDC_PP_RESTYPE_DISPLAY_NAME, CBasePropertyPage::OnChangeCtrl)
  151. ON_EN_CHANGE(IDC_PP_RESTYPE_DESC, CBasePropertyPage::OnChangeCtrl)
  152. ON_EN_CHANGE(IDC_PP_RESTYPE_LOOKS_ALIVE, CBasePropertyPage::OnChangeCtrl)
  153. ON_EN_CHANGE(IDC_PP_RESTYPE_IS_ALIVE, CBasePropertyPage::OnChangeCtrl)
  154. ON_COMMAND(ID_FILE_PROPERTIES, OnProperties)
  155. END_MESSAGE_MAP()
  156. /////////////////////////////////////////////////////////////////////////////
  157. //++
  158. //
  159. // CResTypeGeneralPage::CResTypeGeneralPage
  160. //
  161. // Routine Description:
  162. // Constructor.
  163. //
  164. // Arguments:
  165. // None.
  166. //
  167. // Return Value:
  168. // None.
  169. //
  170. //--
  171. /////////////////////////////////////////////////////////////////////////////
  172. CResTypeGeneralPage::CResTypeGeneralPage(void)
  173. : CBasePropertyPage(IDD, g_aHelpIDs_IDD_PP_RESTYPE_GENERAL)
  174. {
  175. //{{AFX_DATA_INIT(CResTypeGeneralPage)
  176. m_strDisplayName = _T("");
  177. m_strDesc = _T("");
  178. m_strName = _T("");
  179. m_strResDLL = _T("");
  180. m_strQuorumCapable = _T("");
  181. //}}AFX_DATA_INIT
  182. } //*** CResTypeGeneralPage::CResTypePropSheet()
  183. /////////////////////////////////////////////////////////////////////////////
  184. //++
  185. //
  186. // CGroupFailoverPage::BInit
  187. //
  188. // Routine Description:
  189. // Initialize the page.
  190. //
  191. // Arguments:
  192. // psht [IN OUT] Property sheet to which this page belongs.
  193. //
  194. // Return Value:
  195. // TRUE Page initialized successfully.
  196. // FALSE Page failed to initialize.
  197. //
  198. //--
  199. /////////////////////////////////////////////////////////////////////////////
  200. BOOL CResTypeGeneralPage::BInit(IN OUT CBaseSheet * psht)
  201. {
  202. BOOL bSuccess;
  203. ASSERT_KINDOF(CResTypePropSheet, psht);
  204. bSuccess = CBasePropertyPage::BInit(psht);
  205. if (bSuccess)
  206. {
  207. m_strDisplayName = PciResType()->StrDisplayName();
  208. m_strDesc = PciResType()->StrDescription();
  209. m_nLooksAlive = PciResType()->NLooksAlive();
  210. m_nIsAlive = PciResType()->NIsAlive();
  211. m_strName = PciResType()->StrName();
  212. m_strResDLL = PciResType()->StrResDLLName();
  213. if (PciResType()->BQuorumCapable())
  214. m_strQuorumCapable.LoadString(IDS_YES);
  215. else
  216. m_strQuorumCapable.LoadString(IDS_NO);
  217. // Duplicate the possible owners list.
  218. {
  219. POSITION pos;
  220. CClusterNode * pciNode;
  221. pos = PciResType()->LpcinodePossibleOwners().GetHeadPosition();
  222. while (pos != NULL)
  223. {
  224. pciNode = (CClusterNode *) PciResType()->LpcinodePossibleOwners().GetNext(pos);
  225. ASSERT_VALID(pciNode);
  226. m_lpciPossibleOwners.AddTail(pciNode);
  227. } // while: more nodes in the list
  228. } // Duplicate the possible owners list
  229. } // if: base class method was successful
  230. return bSuccess;
  231. } //*** CResTypeGeneralPage::BInit()
  232. /////////////////////////////////////////////////////////////////////////////
  233. //++
  234. //
  235. // CResTypeGeneralPage::DoDataExchange
  236. //
  237. // Routine Description:
  238. // Do data exchange between the dialog and the class.
  239. //
  240. // Arguments:
  241. // pDX [IN OUT] Data exchange object
  242. //
  243. // Return Value:
  244. // None.
  245. //
  246. //--
  247. /////////////////////////////////////////////////////////////////////////////
  248. void CResTypeGeneralPage::DoDataExchange(CDataExchange * pDX)
  249. {
  250. CString strValue;
  251. CBasePropertyPage::DoDataExchange(pDX);
  252. //{{AFX_DATA_MAP(CResTypeGeneralPage)
  253. DDX_Control(pDX, IDC_PP_RESTYPE_QUORUM_CAPABLE, m_editQuorumCapable);
  254. DDX_Control(pDX, IDC_PP_RESTYPE_RESDLL, m_editResDLL);
  255. DDX_Control(pDX, IDC_PP_RESTYPE_NAME, m_editName);
  256. DDX_Control(pDX, IDC_PP_RESTYPE_POSSIBLE_OWNERS, m_lbPossibleOwners);
  257. DDX_Control(pDX, IDC_PP_RESTYPE_IS_ALIVE, m_editIsAlive);
  258. DDX_Control(pDX, IDC_PP_RESTYPE_LOOKS_ALIVE, m_editLooksAlive);
  259. DDX_Control(pDX, IDC_PP_RESTYPE_DESC, m_editDesc);
  260. DDX_Control(pDX, IDC_PP_RESTYPE_DISPLAY_NAME, m_editDisplayName);
  261. DDX_Text(pDX, IDC_PP_RESTYPE_NAME, m_strName);
  262. DDX_Text(pDX, IDC_PP_RESTYPE_DISPLAY_NAME, m_strDisplayName);
  263. DDX_Text(pDX, IDC_PP_RESTYPE_DESC, m_strDesc);
  264. DDX_Text(pDX, IDC_PP_RESTYPE_RESDLL, m_strResDLL);
  265. DDX_Text(pDX, IDC_PP_RESTYPE_QUORUM_CAPABLE, m_strQuorumCapable);
  266. //}}AFX_DATA_MAP
  267. if (pDX->m_bSaveAndValidate)
  268. {
  269. if (!BReadOnly())
  270. {
  271. DDX_Number(pDX, IDC_PP_RESTYPE_LOOKS_ALIVE, m_nLooksAlive, 10, 0xffffffff);
  272. DDX_Number(pDX, IDC_PP_RESTYPE_IS_ALIVE, m_nIsAlive, 10, 0xffffffff);
  273. try
  274. {
  275. PciResType()->ValidateCommonProperties(
  276. m_strDisplayName,
  277. m_strDesc,
  278. m_nLooksAlive,
  279. m_nIsAlive
  280. );
  281. } // try
  282. catch (CException * pe)
  283. {
  284. pe->ReportError();
  285. pe->Delete();
  286. pDX->Fail();
  287. } // catch: CException
  288. } // if: not read only
  289. } // if: saving data
  290. else
  291. {
  292. if (PciResType()->BAvailable())
  293. {
  294. DDX_Number(pDX, IDC_PP_RESTYPE_LOOKS_ALIVE, m_nLooksAlive, CLUSTER_RESTYPE_MINIMUM_LOOKS_ALIVE, CLUSTER_RESTYPE_MAXIMUM_LOOKS_ALIVE);
  295. DDX_Number(pDX, IDC_PP_RESTYPE_IS_ALIVE, m_nIsAlive, CLUSTER_RESTYPE_MINIMUM_IS_ALIVE, CLUSTER_RESTYPE_MAXIMUM_IS_ALIVE);
  296. } // if: resource type properties are available
  297. else
  298. {
  299. m_editLooksAlive.SetWindowText(_T(""));
  300. m_editIsAlive.SetWindowText(_T(""));
  301. m_editQuorumCapable.SetWindowText(_T(""));
  302. } // else: resource type properties are NOT available
  303. FillPossibleOwners();
  304. } // else: setting data to dialog
  305. } //*** CResTypeGeneralPage::DoDataExchange()
  306. /////////////////////////////////////////////////////////////////////////////
  307. //++
  308. //
  309. // CResTypeGeneralPage::FillPossibleOwners
  310. //
  311. // Routine Description:
  312. // Fill the Possible Owners list box.
  313. //
  314. // Arguments:
  315. // None.
  316. //
  317. // Return Value:
  318. // None.
  319. //
  320. //--
  321. /////////////////////////////////////////////////////////////////////////////
  322. void CResTypeGeneralPage::FillPossibleOwners(void)
  323. {
  324. POSITION posPci;
  325. CClusterNode * pciNode;
  326. int iitem;
  327. m_lbPossibleOwners.ResetContent();
  328. posPci = LpciPossibleOwners().GetHeadPosition();
  329. while (posPci != NULL)
  330. {
  331. pciNode = (CClusterNode *) LpciPossibleOwners().GetNext(posPci);
  332. iitem = m_lbPossibleOwners.AddString(pciNode->StrName());
  333. if (iitem >= 0)
  334. m_lbPossibleOwners.SetItemDataPtr(iitem, pciNode);
  335. } // for: each string in the list
  336. } //*** CResTypeGeneralPage::FillPossibleOwners()
  337. /////////////////////////////////////////////////////////////////////////////
  338. //++
  339. //
  340. // CResTypeGeneralPage::OnInitDialog
  341. //
  342. // Routine Description:
  343. // Handler for the WM_INITDIALOG message.
  344. //
  345. // Arguments:
  346. // None.
  347. //
  348. // Return Value:
  349. // TRUE Focus needs to be set.
  350. // FALSE Focus already set.
  351. //
  352. //--
  353. /////////////////////////////////////////////////////////////////////////////
  354. BOOL CResTypeGeneralPage::OnInitDialog(void)
  355. {
  356. CBasePropertyPage::OnInitDialog();
  357. // Set the static edit controls ReadOnly
  358. m_editName.SetReadOnly(TRUE);
  359. m_editResDLL.SetReadOnly(TRUE);
  360. m_editQuorumCapable.SetReadOnly(TRUE);
  361. // If read-only, set all controls to be either disabled or read-only.
  362. if (BReadOnly())
  363. {
  364. m_editDisplayName.SetReadOnly(TRUE);
  365. m_editDesc.SetReadOnly(TRUE);
  366. m_editLooksAlive.SetReadOnly(TRUE);
  367. m_editIsAlive.SetReadOnly(TRUE);
  368. } // if: sheet is read-only
  369. return TRUE; // return TRUE unless you set the focus to a control
  370. // EXCEPTION: OCX Property Pages should return FALSE
  371. } //*** CResTypeGeneralPage::OnInitDialog()
  372. /////////////////////////////////////////////////////////////////////////////
  373. //++
  374. //
  375. // CResTypeGeneralPage::OnApply
  376. //
  377. // Routine Description:
  378. // Handler for the PSN_APPLY message.
  379. //
  380. // Arguments:
  381. // None.
  382. //
  383. // Return Value:
  384. // TRUE Page successfully applied.
  385. // FALSE Error applying page.
  386. //
  387. //--
  388. /////////////////////////////////////////////////////////////////////////////
  389. BOOL CResTypeGeneralPage::OnApply(void)
  390. {
  391. // Set the data from the page in the cluster item.
  392. try
  393. {
  394. CWaitCursor wc;
  395. PciResType()->SetCommonProperties(
  396. m_strDisplayName,
  397. m_strDesc,
  398. m_nLooksAlive,
  399. m_nIsAlive
  400. );
  401. } // try
  402. catch (CException * pe)
  403. {
  404. pe->ReportError();
  405. pe->Delete();
  406. return FALSE;
  407. } // catch: CException
  408. return CBasePropertyPage::OnApply();
  409. } //*** CResTypeGeneralPage::OnApply()
  410. /////////////////////////////////////////////////////////////////////////////
  411. //++
  412. //
  413. // CResTypeGeneralPage::OnKillFocusDisplayName
  414. //
  415. // Routine Description:
  416. // Handler for the WM_KILLFOCUS message on the Display Name edit control.
  417. //
  418. // Arguments:
  419. // None.
  420. //
  421. // Return Value:
  422. // None.
  423. //
  424. //--
  425. /////////////////////////////////////////////////////////////////////////////
  426. void CResTypeGeneralPage::OnKillFocusDisplayName(void)
  427. {
  428. CString strName;
  429. m_editDisplayName.GetWindowText(strName);
  430. SetObjectTitle(strName);
  431. Ppsht()->SetCaption(strName);
  432. } //*** CResTypeGeneralPage::OnKillFocusDisplayName()
  433. /////////////////////////////////////////////////////////////////////////////
  434. //++
  435. //
  436. // CResTypeGeneralPage::OnProperties
  437. //
  438. // Routine Description:
  439. // Handler for the BN_CLICKED message on the Properties button.
  440. //
  441. // Arguments:
  442. // None.
  443. //
  444. // Return Value:
  445. // None.
  446. //
  447. //--
  448. /////////////////////////////////////////////////////////////////////////////
  449. void CResTypeGeneralPage::OnProperties(void)
  450. {
  451. int iitem;
  452. CClusterNode * pciNode;
  453. // Get the item with the focus.
  454. iitem = m_lbPossibleOwners.GetCurSel();
  455. ASSERT(iitem >= 0);
  456. if (iitem >= 0)
  457. {
  458. // Get the node pointer.
  459. pciNode = (CClusterNode *) m_lbPossibleOwners.GetItemDataPtr(iitem);
  460. ASSERT_VALID(pciNode);
  461. // Set properties of that item.
  462. if (pciNode->BDisplayProperties())
  463. {
  464. } // if: properties changed
  465. } // if: found an item with focus
  466. } //*** CResTypeGeneralPage::OnProperties()
  467. /////////////////////////////////////////////////////////////////////////////
  468. //++
  469. //
  470. // CResTypeGeneralPage::OnContextMenu
  471. //
  472. // Routine Description:
  473. // Handler for the WM_CONTEXTMENU method.
  474. //
  475. // Arguments:
  476. // pWnd Window in which the user right clicked the mouse.
  477. // point Position of the cursor, in screen coordinates.
  478. //
  479. // Return Value:
  480. // None.
  481. //
  482. //--
  483. /////////////////////////////////////////////////////////////////////////////
  484. void CResTypeGeneralPage::OnContextMenu(CWnd * pWnd, CPoint point)
  485. {
  486. BOOL bHandled = FALSE;
  487. CMenu * pmenu = NULL;
  488. CListBox * pListBox = (CListBox *) pWnd;
  489. CString strMenuName;
  490. CWaitCursor wc;
  491. // If focus is not in the list control, don't handle the message.
  492. if (pWnd == &m_lbPossibleOwners)
  493. {
  494. // Create the menu to display.
  495. try
  496. {
  497. pmenu = new CMenu;
  498. if (pmenu->CreatePopupMenu())
  499. {
  500. UINT nFlags = MF_STRING;
  501. // If there are no items in the list, disable the menu item.
  502. if (pListBox->GetCount() == 0)
  503. nFlags |= MF_GRAYED;
  504. // Add the Properties item to the menu.
  505. strMenuName.LoadString(IDS_MENU_PROPERTIES);
  506. if (pmenu->AppendMenu(nFlags, ID_FILE_PROPERTIES, strMenuName))
  507. {
  508. bHandled = TRUE;
  509. if (pListBox->GetCurSel() == -1)
  510. pListBox->SetCurSel(0);
  511. } // if: successfully added menu item
  512. } // if: menu created successfully
  513. } // try
  514. catch (CException * pe)
  515. {
  516. pe->ReportError();
  517. pe->Delete();
  518. } // catch: CException
  519. } // if: focus is on list control
  520. if (bHandled)
  521. {
  522. // Display the menu.
  523. if (!pmenu->TrackPopupMenu(
  524. TPM_LEFTALIGN | TPM_RIGHTBUTTON,
  525. point.x,
  526. point.y,
  527. this
  528. ))
  529. {
  530. } // if: unsuccessfully displayed the menu
  531. } // if: there is a menu to display
  532. else
  533. CBasePropertyPage::OnContextMenu(pWnd, point);
  534. delete pmenu;
  535. } //*** CResTypeGeneralPage::OnContextMenu()
  536. /////////////////////////////////////////////////////////////////////////////
  537. //++
  538. //
  539. // CResTypeGeneralPage::OnDblClkPossibleOwners
  540. //
  541. // Routine Description:
  542. // Handler for the LBN_DBLCLK message on the Possible Owners listbox.
  543. //
  544. // Arguments:
  545. // None.
  546. //
  547. // Return Value:
  548. // None.
  549. //
  550. //--
  551. /////////////////////////////////////////////////////////////////////////////
  552. void CResTypeGeneralPage::OnDblClkPossibleOwners(void)
  553. {
  554. OnProperties();
  555. } //*** CResTypeGeneralPage::OnDblClkPossibleOwners()