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.

692 lines
18 KiB

  1. //+---------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 1997.
  5. //
  6. // File: defprot.cpp
  7. //
  8. // Contents: Implementation of Default protocols property page
  9. //
  10. // Classes: CDefaultProtocols
  11. //
  12. // Methods:
  13. //
  14. // History: ??-oct-97 RonanS Created.
  15. //
  16. //----------------------------------------------------------------------
  17. #include "stdafx.h"
  18. #include "olecnfg.h"
  19. #include "afxtempl.h"
  20. #include "CStrings.h"
  21. #include "CReg.h"
  22. #include "types.h"
  23. #include "datapkt.h"
  24. #include "util.h"
  25. #include "virtreg.h"
  26. #include "defprot.h"
  27. #include "epprops.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CDefaultProtocols property page
  35. IMPLEMENT_DYNCREATE(CDefaultProtocols, CPropertyPage)
  36. //+-------------------------------------------------------------------------
  37. //
  38. // Member: CDefaultProtocols::constructor
  39. //
  40. // Synopsis:
  41. //
  42. // Arguments:
  43. //
  44. // Returns:
  45. //
  46. // Algorithm: N/A
  47. //
  48. // History: 27-Oct-97 Ronans Created
  49. //
  50. //--------------------------------------------------------------------------
  51. CDefaultProtocols::CDefaultProtocols() : CPropertyPage(CDefaultProtocols::IDD)
  52. {
  53. //{{AFX_DATA_INIT(CDefaultProtocols)
  54. //}}AFX_DATA_INIT
  55. m_nSelected = -1;
  56. m_bChanged = FALSE;
  57. }
  58. //+-------------------------------------------------------------------------
  59. //
  60. // Member: CDefaultProtocols::destructor
  61. //
  62. // Synopsis:
  63. //
  64. // Arguments:
  65. //
  66. // Returns:
  67. //
  68. // Algorithm: N/A
  69. //
  70. // History: 27-Oct-97 Ronans Created
  71. //
  72. //--------------------------------------------------------------------------
  73. CDefaultProtocols::~CDefaultProtocols()
  74. {
  75. }
  76. //+-------------------------------------------------------------------------
  77. //
  78. // Member: CDefaultProtocols::DoDataExchange
  79. //
  80. // Synopsis: Called to update data automatically to / from controls
  81. //
  82. // Arguments:
  83. //
  84. // Returns:
  85. //
  86. // Algorithm: N/A
  87. //
  88. // History: 27-Oct-97 Ronans Created
  89. //
  90. //--------------------------------------------------------------------------
  91. void CDefaultProtocols::DoDataExchange(CDataExchange* pDX)
  92. {
  93. CPropertyPage::DoDataExchange(pDX);
  94. //{{AFX_DATA_MAP(CDefaultProtocols)
  95. DDX_Control(pDX, IDC_CMDUPDATE, m_btnProperties);
  96. DDX_Control(pDX, IDC_CMDREMOVE, m_btnRemove);
  97. DDX_Control(pDX, IDC_CMDMOVEUP, m_btnMoveUp);
  98. DDX_Control(pDX, IDC_CMDMOVEDOWN, m_btnMoveDown);
  99. DDX_Control(pDX, IDC_CMDADD, m_btnAdd);
  100. DDX_Control(pDX, IDC_LSTPROTSEQ, m_lstProtocols);
  101. //}}AFX_DATA_MAP
  102. if (pDX -> m_bSaveAndValidate && m_bChanged)
  103. {
  104. // update selection
  105. CRegMultiSzNamedValueDp * pCdp = (CRegMultiSzNamedValueDp*)g_virtreg.GetAt(m_nDefaultProtocolsIndex);
  106. CStringArray& rProtocols = pCdp -> Values();
  107. rProtocols.RemoveAll();
  108. // copy protocols
  109. int nIndex;
  110. for (nIndex = 0; nIndex < m_arrProtocols.GetSize(); nIndex++)
  111. {
  112. CEndpointData *pED = (CEndpointData *)m_arrProtocols.GetAt(nIndex);
  113. rProtocols.Add((LPCTSTR)pED -> m_szProtseq);
  114. }
  115. pCdp -> SetModified(TRUE);
  116. }
  117. }
  118. BEGIN_MESSAGE_MAP(CDefaultProtocols, CPropertyPage)
  119. //{{AFX_MSG_MAP(CDefaultProtocols)
  120. ON_BN_CLICKED(IDC_CMDADD, OnAddProtocol)
  121. ON_BN_CLICKED(IDC_CMDMOVEDOWN, OnMoveProtocolDown)
  122. ON_BN_CLICKED(IDC_CMDMOVEUP, OnMoveProtocolUp)
  123. ON_BN_CLICKED(IDC_CMDREMOVE, OnRemoveProtocol)
  124. ON_WM_KILLFOCUS()
  125. ON_NOTIFY(NM_CLICK, IDC_LSTPROTSEQ, OnSelectProtocol)
  126. ON_BN_CLICKED(IDC_CMDUPDATE, OnProperties)
  127. ON_NOTIFY(NM_DBLCLK, IDC_LSTPROTSEQ, OnPropertiesClick)
  128. ON_WM_HELPINFO()
  129. //}}AFX_MSG_MAP
  130. END_MESSAGE_MAP()
  131. /////////////////////////////////////////////////////////////////////////////
  132. // CDefaultProtocols message handlers
  133. //+-------------------------------------------------------------------------
  134. //
  135. // Member: CDefaultProtocols::OnInitDialog
  136. //
  137. // Synopsis: Called to initialize dialog before showing
  138. // (in response to WM_INITDIALOG)
  139. //
  140. // Arguments:
  141. //
  142. // Returns: BOOL - TRUE to set focus to Dialog, FALSE if
  143. // focus will be set to another control or window
  144. //
  145. // Algorithm: N/A
  146. //
  147. // History: 27-Oct-97 Ronans Created
  148. //
  149. //--------------------------------------------------------------------------
  150. BOOL CDefaultProtocols::OnInitDialog()
  151. {
  152. CPropertyPage::OnInitDialog();
  153. // setup image list control for dialog (for use with listview)
  154. m_imgNetwork.Create( IDB_IMGNETWORK, 16, 0, RGB(255,255,255));
  155. m_lstProtocols.SetImageList(&m_imgNetwork, LVSIL_SMALL);
  156. ASSERT(m_imgNetwork.GetImageCount() == 2);
  157. // Attempt to read HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RPC\DCOM Protocols
  158. int err;
  159. err = g_virtreg.ReadRegMultiSzNamedValue(HKEY_LOCAL_MACHINE,
  160. TEXT("SOFTWARE\\Microsoft\\RPC"),
  161. TEXT("DCOM Protocols"),
  162. &m_nDefaultProtocolsIndex);
  163. if (err == ERROR_SUCCESS)
  164. {
  165. CRegMultiSzNamedValueDp * pCdp = (CRegMultiSzNamedValueDp*)g_virtreg.GetAt(m_nDefaultProtocolsIndex);
  166. CStringArray& rProtocols = pCdp -> Values();
  167. // copy protocols
  168. int nIndex;
  169. for (nIndex = 0; nIndex < rProtocols.GetSize(); nIndex++)
  170. {
  171. CEndpointData *pED = new CEndpointData(rProtocols.GetAt(nIndex));
  172. m_arrProtocols.Add(pED);
  173. }
  174. // set selection to first item
  175. if (nIndex > 0)
  176. m_nSelected = 0;
  177. else
  178. m_nSelected = -1;
  179. RefreshProtocolList();
  180. }
  181. else if (err != ERROR_ACCESS_DENIED && err !=
  182. ERROR_FILE_NOT_FOUND)
  183. {
  184. g_util.PostErrorMessage();
  185. }
  186. SetModified(m_bChanged = FALSE);
  187. return TRUE; // return TRUE unless you set the focus to a control
  188. // EXCEPTION: OCX Property Pages should return FALSE
  189. }
  190. //+-------------------------------------------------------------------------
  191. //
  192. // Member: CDefaultProtocols::UpdateSelection
  193. //
  194. // Synopsis: Called to update UI after protocol selection
  195. //
  196. // Arguments:
  197. //
  198. // Returns:
  199. //
  200. // Algorithm: N/A
  201. //
  202. // History: 27-Oct-97 Ronans Created
  203. //
  204. //--------------------------------------------------------------------------
  205. void CDefaultProtocols::UpdateSelection()
  206. {
  207. BOOL bAllowGlobalProperties = FALSE;
  208. // get the corresponding endpoint data object
  209. if (m_nSelected != (-1))
  210. {
  211. CEndpointData *pEPD = (CEndpointData*)m_arrProtocols.GetAt(m_nSelected);
  212. bAllowGlobalProperties = pEPD -> AllowGlobalProperties();
  213. }
  214. m_btnAdd.EnableWindow(TRUE);
  215. m_btnRemove.EnableWindow(m_nSelected != -1);
  216. m_btnProperties.EnableWindow(bAllowGlobalProperties);
  217. m_btnMoveUp.EnableWindow(m_nSelected > 0);
  218. m_btnMoveDown.EnableWindow((m_nSelected < m_arrProtocols.GetUpperBound()) && (m_nSelected >=0));
  219. // set up initial selection
  220. if (m_nSelected != (-1))
  221. {
  222. m_lstProtocols.SetItemState(m_nSelected, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  223. m_lstProtocols.Update(m_nSelected);
  224. }
  225. UpdateData(FALSE);
  226. }
  227. //+-------------------------------------------------------------------------
  228. //
  229. // Member: CDefaultProtocols::RefreshProtocolList
  230. //
  231. // Synopsis: Called to refresh protocol list into dialog
  232. //
  233. // Arguments:
  234. //
  235. // Returns:
  236. //
  237. // Algorithm: N/A
  238. //
  239. // History: 27-Oct-97 Ronans Created
  240. //
  241. //--------------------------------------------------------------------------
  242. void CDefaultProtocols::RefreshProtocolList()
  243. {
  244. int nIndex;
  245. // clear the list controls current contents
  246. m_lstProtocols.DeleteAllItems();
  247. for (nIndex = 0; (nIndex < m_arrProtocols.GetSize()); nIndex++)
  248. {
  249. CEndpointData *pEPD = (CEndpointData*)m_arrProtocols.GetAt(nIndex);
  250. if (pEPD )
  251. {
  252. CString sTmp;
  253. pEPD -> GetDescription(sTmp);
  254. // insert item and store pointer to its associated CEndpointData
  255. m_lstProtocols.InsertItem(nIndex, sTmp, 0);
  256. m_lstProtocols.SetItemData(0, (DWORD_PTR)pEPD);
  257. }
  258. }
  259. UpdateSelection();
  260. }
  261. //+-------------------------------------------------------------------------
  262. //
  263. // Member: CDefaultProtocols::OnAddProtocol
  264. //
  265. // Synopsis: Called when user selects AddProtocol button
  266. //
  267. // Arguments:
  268. //
  269. // Returns:
  270. //
  271. // Algorithm: N/A
  272. //
  273. // History: 27-Oct-97 Ronans Created
  274. //
  275. //--------------------------------------------------------------------------
  276. void CDefaultProtocols::OnAddProtocol()
  277. {
  278. CAddProtocolDlg capd;
  279. if (capd.DoModal() == IDOK)
  280. {
  281. // create new endpoint
  282. CEndpointData *pNewProtocol = new CEndpointData();
  283. ASSERT(pNewProtocol);
  284. pNewProtocol = capd.GetEndpointData(pNewProtocol);
  285. ASSERT(pNewProtocol);
  286. // check if protocol is already in collection
  287. int nIndex;
  288. for (nIndex = 0; nIndex < m_arrProtocols.GetSize(); nIndex++)
  289. {
  290. CEndpointData *pEPD = (CEndpointData*)m_arrProtocols.GetAt(nIndex);
  291. if (pEPD -> m_pProtocol == pNewProtocol -> m_pProtocol)
  292. {
  293. delete pNewProtocol;
  294. pNewProtocol = NULL;
  295. AfxMessageBox((UINT)IDS_DUPLICATE_PROTSEQ);
  296. break;
  297. }
  298. }
  299. // only add the endpoint if its not already in collection
  300. if (pNewProtocol)
  301. {
  302. // reset old hilited item
  303. if (m_nSelected != -1)
  304. {
  305. m_lstProtocols.SetItemState(m_nSelected, 0, LVIS_SELECTED | LVIS_FOCUSED);
  306. m_lstProtocols.Update(m_nSelected);
  307. }
  308. // add new endpoint
  309. int nNewIndex = (int)m_arrProtocols.Add((CObject*)pNewProtocol);
  310. // set new item in list control
  311. CString sTmp;
  312. pNewProtocol -> GetDescription(sTmp);
  313. // insert item and store pointer to its associated CEndpointData
  314. m_nSelected = m_lstProtocols.InsertItem(nNewIndex, sTmp, 0);
  315. if (m_nSelected != -1)
  316. {
  317. m_lstProtocols.SetItemData(m_nSelected, (DWORD_PTR)pNewProtocol);
  318. UpdateSelection();
  319. // set modified flag to enable apply button
  320. SetModified(m_bChanged = TRUE);
  321. // This is a reboot event
  322. g_fReboot = TRUE;
  323. UpdateData(TRUE);
  324. }
  325. }
  326. }
  327. SetFocus();
  328. }
  329. //+-------------------------------------------------------------------------
  330. //
  331. // Member: CDefaultProtocols::OnMoveProtocolDown
  332. //
  333. // Synopsis: Called when user clicks MoveDown button
  334. //
  335. // Arguments:
  336. //
  337. // Returns:
  338. //
  339. // Algorithm: N/A
  340. //
  341. // History: 27-Oct-97 Ronans Created
  342. //
  343. //--------------------------------------------------------------------------
  344. void CDefaultProtocols::OnMoveProtocolDown()
  345. {
  346. if ((m_nSelected != -1) && (m_nSelected < m_arrProtocols.GetUpperBound()))
  347. {
  348. CEndpointData * p1, *p2;
  349. p1 = (CEndpointData * )m_arrProtocols.GetAt(m_nSelected);
  350. p2 = (CEndpointData * )m_arrProtocols.GetAt(m_nSelected + 1);
  351. m_arrProtocols.SetAt(m_nSelected,(CObject*)p2);
  352. m_arrProtocols.SetAt(m_nSelected+1,(CObject*)p1);
  353. m_nSelected = m_nSelected+1;
  354. // set modified flag to enable apply button
  355. SetModified(m_bChanged = TRUE);
  356. UpdateData(TRUE);
  357. // This is a reboot event
  358. g_fReboot = TRUE;
  359. RefreshProtocolList();
  360. SetFocus();
  361. }
  362. }
  363. //+-------------------------------------------------------------------------
  364. //
  365. // Member: CDefaultProtocols::OnMoveProtocolUp
  366. //
  367. // Synopsis: Called when user clicks MoveUp button
  368. //
  369. // Arguments:
  370. //
  371. // Returns:
  372. //
  373. // Algorithm: N/A
  374. //
  375. // History: 27-Oct-97 Ronans Created
  376. //
  377. //--------------------------------------------------------------------------
  378. void CDefaultProtocols::OnMoveProtocolUp()
  379. {
  380. if ((m_nSelected != -1) && (m_nSelected > 0))
  381. {
  382. CEndpointData * p1, *p2;
  383. p1 = (CEndpointData * )m_arrProtocols.GetAt(m_nSelected);
  384. p2 = (CEndpointData * )m_arrProtocols.GetAt(m_nSelected - 1);
  385. m_arrProtocols.SetAt(m_nSelected,(CObject*)p2);
  386. m_arrProtocols.SetAt(m_nSelected - 1 ,(CObject*)p1);
  387. m_nSelected = m_nSelected - 1;
  388. // set modified flag to enable apply button
  389. SetModified(m_bChanged = TRUE);
  390. UpdateData(TRUE);
  391. // This is a reboot event
  392. g_fReboot = TRUE;
  393. RefreshProtocolList();
  394. SetFocus();
  395. }
  396. }
  397. //+-------------------------------------------------------------------------
  398. //
  399. // Member: CDefaultProtocols::OnRemoveProtocol
  400. //
  401. // Synopsis: Called when user clicks Remove button
  402. //
  403. // Arguments:
  404. //
  405. // Returns:
  406. //
  407. // Algorithm: N/A
  408. //
  409. // History: 27-Oct-97 Ronans Created
  410. //
  411. //--------------------------------------------------------------------------
  412. void CDefaultProtocols::OnRemoveProtocol()
  413. {
  414. if (m_nSelected != -1)
  415. {
  416. CEndpointData * p1;
  417. p1 = (CEndpointData * )m_arrProtocols.GetAt(m_nSelected);
  418. m_arrProtocols.RemoveAt(m_nSelected);
  419. delete p1;
  420. if (!m_arrProtocols.GetSize())
  421. m_nSelected = -1;
  422. else if (m_nSelected > m_arrProtocols.GetUpperBound())
  423. m_nSelected = (int)m_arrProtocols.GetUpperBound();
  424. // set modified flag to enable apply button
  425. SetModified(m_bChanged = TRUE);
  426. UpdateData(TRUE);
  427. // This is a reboot event
  428. g_fReboot = TRUE;
  429. RefreshProtocolList();
  430. SetFocus();
  431. }
  432. }
  433. //+-------------------------------------------------------------------------
  434. //
  435. // Member: CDefaultProtocols::OnKillActive
  436. //
  437. // Synopsis: Called when Default protocols is no longer active pane
  438. //
  439. // Arguments:
  440. //
  441. // Returns:
  442. //
  443. // Algorithm: N/A
  444. //
  445. // History: 27-Oct-97 Ronans Created
  446. //
  447. //--------------------------------------------------------------------------
  448. BOOL CDefaultProtocols::OnKillActive()
  449. {
  450. return CPropertyPage::OnKillActive();
  451. }
  452. //+-------------------------------------------------------------------------
  453. //
  454. // Member: CDefaultProtocols::OnSetActive
  455. //
  456. // Synopsis: Called when Default protocols becomes active pane
  457. //
  458. // Arguments:
  459. //
  460. // Returns:
  461. //
  462. // Algorithm: N/A
  463. //
  464. // History: 27-Oct-97 Ronans Created
  465. //
  466. //--------------------------------------------------------------------------
  467. BOOL CDefaultProtocols::OnSetActive()
  468. {
  469. BOOL bRetval = CPropertyPage::OnSetActive();
  470. // force focus to be set for page
  471. PostMessage(WM_SETFOCUS);
  472. return bRetval;
  473. }
  474. //+-------------------------------------------------------------------------
  475. //
  476. // Member: CDefaultProtocols::OnKillFocus
  477. //
  478. // Synopsis: Called when Default protocols pane loses focus
  479. //
  480. // Arguments:
  481. //
  482. // Returns:
  483. //
  484. // Algorithm: N/A
  485. //
  486. // History: 27-Oct-97 Ronans Created
  487. //
  488. //--------------------------------------------------------------------------
  489. void CDefaultProtocols::OnKillFocus(CWnd* pNewWnd)
  490. {
  491. CPropertyPage::OnKillFocus(pNewWnd);
  492. }
  493. //+-------------------------------------------------------------------------
  494. //
  495. // Member: CDefaultProtocols::OnSetFocus
  496. //
  497. // Synopsis: Called when Default protocols pane gains focus
  498. //
  499. // Arguments:
  500. //
  501. // Returns:
  502. //
  503. // Algorithm: N/A
  504. //
  505. // History: 27-Oct-97 Ronans Created
  506. //
  507. //--------------------------------------------------------------------------
  508. void CDefaultProtocols::OnSetFocus(CWnd* pOldWnd)
  509. {
  510. CPropertyPage::OnSetFocus(pOldWnd);
  511. m_lstProtocols.SetFocus();
  512. if (m_nSelected != (-1))
  513. {
  514. m_lstProtocols.SetItemState(m_nSelected, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  515. m_lstProtocols.Update(m_nSelected);
  516. }
  517. else
  518. {
  519. TRACE(TEXT("Invalid state"));
  520. }
  521. }
  522. //+-------------------------------------------------------------------------
  523. //
  524. // Member: CDefaultProtocols::OnSelectProtocol
  525. //
  526. // Synopsis: Called when users selects protocol from list
  527. //
  528. // Arguments:
  529. //
  530. // Returns:
  531. //
  532. // Algorithm: N/A
  533. //
  534. // History: 27-Oct-97 Ronans Created
  535. //
  536. //--------------------------------------------------------------------------
  537. void CDefaultProtocols::OnSelectProtocol(NMHDR* pNMHDR, LRESULT* pResult)
  538. {
  539. m_nSelected = m_lstProtocols.GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
  540. UpdateSelection();
  541. *pResult = 0;
  542. }
  543. //+-------------------------------------------------------------------------
  544. //
  545. // Member: CDefaultProtocols::OnProperties
  546. //
  547. // Synopsis: Called when user clicks Properties button
  548. //
  549. // Arguments:
  550. //
  551. // Returns:
  552. //
  553. // Algorithm: N/A
  554. //
  555. // History: 27-Oct-97 Ronans Created
  556. //
  557. //--------------------------------------------------------------------------
  558. void CDefaultProtocols::OnProperties()
  559. {
  560. if (m_nSelected != (-1))
  561. {
  562. CPortRangesDlg cprd;
  563. cprd.DoModal();
  564. SetFocus();
  565. }
  566. }
  567. //+-------------------------------------------------------------------------
  568. //
  569. // Member: CDefaultProtocols::OnPropertiesClick
  570. //
  571. // Synopsis: Called when user double clicks protocol in list
  572. //
  573. // Arguments:
  574. //
  575. // Returns:
  576. //
  577. // Algorithm: N/A
  578. //
  579. // History: 27-Oct-97 Ronans Created
  580. //
  581. //--------------------------------------------------------------------------
  582. void CDefaultProtocols::OnPropertiesClick(NMHDR* pNMHDR, LRESULT* pResult)
  583. {
  584. m_nSelected = m_lstProtocols.GetNextItem(-1, LVIS_SELECTED | LVIS_FOCUSED);
  585. if (m_nSelected != (-1))
  586. {
  587. CEndpointData *pEPD = (CEndpointData*)m_arrProtocols.GetAt(m_nSelected);
  588. BOOL bAllowGlobalProperties = pEPD -> AllowGlobalProperties();
  589. if (bAllowGlobalProperties)
  590. OnProperties();
  591. }
  592. UpdateSelection();
  593. *pResult = 0;
  594. }
  595. BOOL CDefaultProtocols::OnHelpInfo(HELPINFO* pHelpInfo)
  596. {
  597. if(-1 != pHelpInfo->iCtrlId)
  598. {
  599. WORD hiWord = 0x8000 | CDefaultProtocols::IDD;
  600. WORD loWord = (WORD) pHelpInfo->iCtrlId;
  601. DWORD dwLong = MAKELONG(loWord,hiWord);
  602. WinHelp(dwLong, HELP_CONTEXTPOPUP);
  603. TRACE1("Help Id 0x%lx\n", dwLong);
  604. return TRUE;
  605. }
  606. else
  607. {
  608. return CPropertyPage::OnHelpInfo(pHelpInfo);
  609. }
  610. }
  611.