Leaked source code of windows server 2003
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.

625 lines
18 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2002 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. DDV_RequiredText(pDX, IDC_PP_RESTYPE_DISPLAY_NAME, IDC_PP_RESTYPE_DISPLAY_NAME_LABEL, m_strDisplayName);
  274. try
  275. {
  276. PciResType()->ValidateCommonProperties(
  277. m_strDisplayName,
  278. m_strDesc,
  279. m_nLooksAlive,
  280. m_nIsAlive
  281. );
  282. } // try
  283. catch (CException * pe)
  284. {
  285. pe->ReportError();
  286. pe->Delete();
  287. pDX->Fail();
  288. } // catch: CException
  289. } // if: not read only
  290. } // if: saving data
  291. else
  292. {
  293. if (PciResType()->BAvailable())
  294. {
  295. DDX_Number(pDX, IDC_PP_RESTYPE_LOOKS_ALIVE, m_nLooksAlive, CLUSTER_RESTYPE_MINIMUM_LOOKS_ALIVE, CLUSTER_RESTYPE_MAXIMUM_LOOKS_ALIVE);
  296. DDX_Number(pDX, IDC_PP_RESTYPE_IS_ALIVE, m_nIsAlive, CLUSTER_RESTYPE_MINIMUM_IS_ALIVE, CLUSTER_RESTYPE_MAXIMUM_IS_ALIVE);
  297. } // if: resource type properties are available
  298. else
  299. {
  300. m_editLooksAlive.SetWindowText(_T(""));
  301. m_editIsAlive.SetWindowText(_T(""));
  302. m_editQuorumCapable.SetWindowText(_T(""));
  303. } // else: resource type properties are NOT available
  304. FillPossibleOwners();
  305. } // else: setting data to dialog
  306. } //*** CResTypeGeneralPage::DoDataExchange()
  307. /////////////////////////////////////////////////////////////////////////////
  308. //++
  309. //
  310. // CResTypeGeneralPage::FillPossibleOwners
  311. //
  312. // Routine Description:
  313. // Fill the Possible Owners list box.
  314. //
  315. // Arguments:
  316. // None.
  317. //
  318. // Return Value:
  319. // None.
  320. //
  321. //--
  322. /////////////////////////////////////////////////////////////////////////////
  323. void CResTypeGeneralPage::FillPossibleOwners(void)
  324. {
  325. POSITION posPci;
  326. CClusterNode * pciNode;
  327. int iitem;
  328. m_lbPossibleOwners.ResetContent();
  329. posPci = LpciPossibleOwners().GetHeadPosition();
  330. while (posPci != NULL)
  331. {
  332. pciNode = (CClusterNode *) LpciPossibleOwners().GetNext(posPci);
  333. iitem = m_lbPossibleOwners.AddString(pciNode->StrName());
  334. if (iitem >= 0)
  335. m_lbPossibleOwners.SetItemDataPtr(iitem, pciNode);
  336. } // for: each string in the list
  337. } //*** CResTypeGeneralPage::FillPossibleOwners()
  338. /////////////////////////////////////////////////////////////////////////////
  339. //++
  340. //
  341. // CResTypeGeneralPage::OnInitDialog
  342. //
  343. // Routine Description:
  344. // Handler for the WM_INITDIALOG message.
  345. //
  346. // Arguments:
  347. // None.
  348. //
  349. // Return Value:
  350. // TRUE Focus needs to be set.
  351. // FALSE Focus already set.
  352. //
  353. //--
  354. /////////////////////////////////////////////////////////////////////////////
  355. BOOL CResTypeGeneralPage::OnInitDialog(void)
  356. {
  357. CBasePropertyPage::OnInitDialog();
  358. // Set the static edit controls ReadOnly
  359. m_editName.SetReadOnly(TRUE);
  360. m_editResDLL.SetReadOnly(TRUE);
  361. m_editQuorumCapable.SetReadOnly(TRUE);
  362. // If read-only, set all controls to be either disabled or read-only.
  363. if (BReadOnly())
  364. {
  365. m_editDisplayName.SetReadOnly(TRUE);
  366. m_editDesc.SetReadOnly(TRUE);
  367. m_editLooksAlive.SetReadOnly(TRUE);
  368. m_editIsAlive.SetReadOnly(TRUE);
  369. } // if: sheet is read-only
  370. return TRUE; // return TRUE unless you set the focus to a control
  371. // EXCEPTION: OCX Property Pages should return FALSE
  372. } //*** CResTypeGeneralPage::OnInitDialog()
  373. /////////////////////////////////////////////////////////////////////////////
  374. //++
  375. //
  376. // CResTypeGeneralPage::OnApply
  377. //
  378. // Routine Description:
  379. // Handler for the PSN_APPLY message.
  380. //
  381. // Arguments:
  382. // None.
  383. //
  384. // Return Value:
  385. // TRUE Page successfully applied.
  386. // FALSE Error applying page.
  387. //
  388. //--
  389. /////////////////////////////////////////////////////////////////////////////
  390. BOOL CResTypeGeneralPage::OnApply(void)
  391. {
  392. // Set the data from the page in the cluster item.
  393. try
  394. {
  395. CWaitCursor wc;
  396. PciResType()->SetCommonProperties(
  397. m_strDisplayName,
  398. m_strDesc,
  399. m_nLooksAlive,
  400. m_nIsAlive
  401. );
  402. } // try
  403. catch (CException * pe)
  404. {
  405. pe->ReportError();
  406. pe->Delete();
  407. return FALSE;
  408. } // catch: CException
  409. return CBasePropertyPage::OnApply();
  410. } //*** CResTypeGeneralPage::OnApply()
  411. /////////////////////////////////////////////////////////////////////////////
  412. //++
  413. //
  414. // CResTypeGeneralPage::OnKillFocusDisplayName
  415. //
  416. // Routine Description:
  417. // Handler for the WM_KILLFOCUS message on the Display Name edit control.
  418. //
  419. // Arguments:
  420. // None.
  421. //
  422. // Return Value:
  423. // None.
  424. //
  425. //--
  426. /////////////////////////////////////////////////////////////////////////////
  427. void CResTypeGeneralPage::OnKillFocusDisplayName(void)
  428. {
  429. CString strName;
  430. m_editDisplayName.GetWindowText(strName);
  431. SetObjectTitle(strName);
  432. Ppsht()->SetCaption(strName);
  433. } //*** CResTypeGeneralPage::OnKillFocusDisplayName()
  434. /////////////////////////////////////////////////////////////////////////////
  435. //++
  436. //
  437. // CResTypeGeneralPage::OnProperties
  438. //
  439. // Routine Description:
  440. // Handler for the BN_CLICKED message on the Properties button.
  441. //
  442. // Arguments:
  443. // None.
  444. //
  445. // Return Value:
  446. // None.
  447. //
  448. //--
  449. /////////////////////////////////////////////////////////////////////////////
  450. void CResTypeGeneralPage::OnProperties(void)
  451. {
  452. int iitem;
  453. CClusterNode * pciNode;
  454. // Get the item with the focus.
  455. iitem = m_lbPossibleOwners.GetCurSel();
  456. ASSERT(iitem >= 0);
  457. if (iitem >= 0)
  458. {
  459. // Get the node pointer.
  460. pciNode = (CClusterNode *) m_lbPossibleOwners.GetItemDataPtr(iitem);
  461. ASSERT_VALID(pciNode);
  462. // Set properties of that item.
  463. if (pciNode->BDisplayProperties())
  464. {
  465. } // if: properties changed
  466. } // if: found an item with focus
  467. } //*** CResTypeGeneralPage::OnProperties()
  468. /////////////////////////////////////////////////////////////////////////////
  469. //++
  470. //
  471. // CResTypeGeneralPage::OnContextMenu
  472. //
  473. // Routine Description:
  474. // Handler for the WM_CONTEXTMENU method.
  475. //
  476. // Arguments:
  477. // pWnd Window in which the user right clicked the mouse.
  478. // point Position of the cursor, in screen coordinates.
  479. //
  480. // Return Value:
  481. // None.
  482. //
  483. //--
  484. /////////////////////////////////////////////////////////////////////////////
  485. void CResTypeGeneralPage::OnContextMenu(CWnd * pWnd, CPoint point)
  486. {
  487. BOOL bHandled = FALSE;
  488. CMenu * pmenu = NULL;
  489. CListBox * pListBox = (CListBox *) pWnd;
  490. CString strMenuName;
  491. CWaitCursor wc;
  492. // If focus is not in the list control, don't handle the message.
  493. if (pWnd == &m_lbPossibleOwners)
  494. {
  495. // Create the menu to display.
  496. try
  497. {
  498. pmenu = new CMenu;
  499. if (pmenu->CreatePopupMenu())
  500. {
  501. UINT nFlags = MF_STRING;
  502. // If there are no items in the list, disable the menu item.
  503. if (pListBox->GetCount() == 0)
  504. nFlags |= MF_GRAYED;
  505. // Add the Properties item to the menu.
  506. strMenuName.LoadString(IDS_MENU_PROPERTIES);
  507. if (pmenu->AppendMenu(nFlags, ID_FILE_PROPERTIES, strMenuName))
  508. {
  509. bHandled = TRUE;
  510. if (pListBox->GetCurSel() == -1)
  511. pListBox->SetCurSel(0);
  512. } // if: successfully added menu item
  513. } // if: menu created successfully
  514. } // try
  515. catch (CException * pe)
  516. {
  517. pe->ReportError();
  518. pe->Delete();
  519. } // catch: CException
  520. } // if: focus is on list control
  521. if (bHandled)
  522. {
  523. // Display the menu.
  524. if (!pmenu->TrackPopupMenu(
  525. TPM_LEFTALIGN | TPM_RIGHTBUTTON,
  526. point.x,
  527. point.y,
  528. this
  529. ))
  530. {
  531. } // if: unsuccessfully displayed the menu
  532. } // if: there is a menu to display
  533. else
  534. CBasePropertyPage::OnContextMenu(pWnd, point);
  535. delete pmenu;
  536. } //*** CResTypeGeneralPage::OnContextMenu()
  537. /////////////////////////////////////////////////////////////////////////////
  538. //++
  539. //
  540. // CResTypeGeneralPage::OnDblClkPossibleOwners
  541. //
  542. // Routine Description:
  543. // Handler for the LBN_DBLCLK message on the Possible Owners listbox.
  544. //
  545. // Arguments:
  546. // None.
  547. //
  548. // Return Value:
  549. // None.
  550. //
  551. //--
  552. /////////////////////////////////////////////////////////////////////////////
  553. void CResTypeGeneralPage::OnDblClkPossibleOwners(void)
  554. {
  555. OnProperties();
  556. } //*** CResTypeGeneralPage::OnDblClkPossibleOwners()