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.

1274 lines
32 KiB

  1. #include "precomp.h"
  2. #include "resource.h"
  3. #include "PropWnd2.h"
  4. #include "DsPropWnd2.h"
  5. #include "NmAkWiz.h"
  6. #include "EditServer.h"
  7. #include "WndProcs.h"
  8. //#include "poldata.h"
  9. #include "nmakreg.h"
  10. #include <algorithm>
  11. const int CDsPropWnd2::MAXSERVERS = 15;
  12. const TCHAR c_szMSServer[] = TEXT("logon.netmeeting.microsoft.com");
  13. CWebViewInfo* GetWebViewInfo()
  14. {
  15. static CWebViewInfo g_wvi;
  16. return(&g_wvi);
  17. }
  18. BOOL IsMSServer(LPCTSTR szServer) { return(0 == lstrcmp(szServer, c_szMSServer)); }
  19. // Read the WebView information, but only once
  20. void ReadWebViewSettings(CPropertyDataWindow2 *pData)
  21. {
  22. static BOOL g_bRead = FALSE;
  23. if (g_bRead)
  24. {
  25. return;
  26. }
  27. CWebViewInfo *pWebView = GetWebViewInfo();
  28. pData->ReadStringValue(KEYNAME_WEBVIEWNAME , pWebView->m_szWebViewName , CCHMAX(pWebView->m_szWebViewName ));
  29. pData->ReadStringValue(KEYNAME_WEBVIEWURL , pWebView->m_szWebViewURL , CCHMAX(pWebView->m_szWebViewURL ));
  30. pData->ReadStringValue(KEYNAME_WEBVIEWSERVER, pWebView->m_szWebViewServer, CCHMAX(pWebView->m_szWebViewServer));
  31. g_bRead = TRUE;
  32. }
  33. void WriteWebViewSettings(CPropertyDataWindow2 *pData)
  34. {
  35. CWebViewInfo *pWebView = GetWebViewInfo();
  36. // If the WebView is the default, write blanks to the file
  37. LPCTSTR szWVName = pWebView->m_szWebViewName ;
  38. LPCTSTR szWVURL = pWebView->m_szWebViewURL ;
  39. LPCTSTR szWVServer = pWebView->m_szWebViewServer;
  40. if (IsMSServer(szWVServer))
  41. {
  42. szWVName = szWVURL = szWVServer = TEXT("");
  43. }
  44. pData->WriteStringValue(KEYNAME_WEBVIEWNAME , szWVName );
  45. pData->WriteStringValue(KEYNAME_WEBVIEWURL , szWVURL );
  46. pData->WriteStringValue(KEYNAME_WEBVIEWSERVER, szWVServer);
  47. }
  48. void WriteWebViewToINF(HANDLE hFile, BOOL bWebViewAllowed)
  49. {
  50. CWebViewInfo *pWebView = GetWebViewInfo();
  51. // If the WebView is the default, write blanks to the file
  52. if (!bWebViewAllowed || IsMSServer(pWebView->m_szWebViewServer))
  53. {
  54. CPolicyData( CPolicyData::eKeyType_HKEY_CURRENT_USER,
  55. POLICIES_KEY,
  56. REGVAL_POL_INTRANET_WEBDIR_NAME,
  57. CPolicyData::OpDelete()
  58. ).SaveToINFFile( hFile );
  59. CPolicyData( CPolicyData::eKeyType_HKEY_CURRENT_USER,
  60. POLICIES_KEY,
  61. REGVAL_POL_INTRANET_WEBDIR_URL,
  62. CPolicyData::OpDelete()
  63. ).SaveToINFFile( hFile );
  64. CPolicyData( CPolicyData::eKeyType_HKEY_CURRENT_USER,
  65. POLICIES_KEY,
  66. REGVAL_POL_INTRANET_WEBDIR_SERVER,
  67. CPolicyData::OpDelete()
  68. ).SaveToINFFile( hFile );
  69. }
  70. else
  71. {
  72. CPolicyData( CPolicyData::eKeyType_HKEY_CURRENT_USER,
  73. POLICIES_KEY,
  74. REGVAL_POL_INTRANET_WEBDIR_NAME,
  75. pWebView->m_szWebViewName
  76. ).SaveToINFFile( hFile );
  77. CPolicyData( CPolicyData::eKeyType_HKEY_CURRENT_USER,
  78. POLICIES_KEY,
  79. REGVAL_POL_INTRANET_WEBDIR_URL,
  80. pWebView->m_szWebViewURL
  81. ).SaveToINFFile( hFile );
  82. CPolicyData( CPolicyData::eKeyType_HKEY_CURRENT_USER,
  83. POLICIES_KEY,
  84. REGVAL_POL_INTRANET_WEBDIR_SERVER,
  85. pWebView->m_szWebViewServer
  86. ).SaveToINFFile( hFile );
  87. }
  88. }
  89. void CWebViewInfo::SetWebView(LPCTSTR szServer, LPCTSTR szName, LPCTSTR szURL)
  90. {
  91. lstrcpy(m_szWebViewServer, szServer);
  92. if (NULL != szName)
  93. {
  94. lstrcpy(m_szWebViewName, szName);
  95. }
  96. if (NULL != szURL)
  97. {
  98. lstrcpy(m_szWebViewURL, szURL);
  99. }
  100. }
  101. CDsPropWnd2::CDsPropWnd2( HWND hwndParent, int iX, int iY, int iWidth, int iHeight )
  102. : CPropertyDataWindow2( hwndParent, IDD_CHILDPAGE_ILSGATEWAY, TEXT("IDD_CHILDPAGE_ILSGATEWAY"), (WNDPROC) DsPropWndProc, 0, iX, iY, iWidth, iHeight, FALSE )
  103. {
  104. SetWindowLong( m_hwnd, GWL_USERDATA, (long)this );
  105. Edit_LimitText( GetDlgItem( m_hwnd, IDC_EDIT_NEW_SERVER ), MAX_PATH );
  106. Edit_LimitText( GetDlgItem( m_hwnd, IDC_EDIT_GATEWAY ), MAX_PATH );
  107. m_hwndList = GetDlgItem( m_hwnd, IDC_LIST_SERVERS );
  108. ConnectControlsToCheck( IDC_CHECK_GATEWAY, 1,
  109. new CControlID(GetDlgItem(m_hwnd, IDC_CHECK_GATEWAY),
  110. IDC_CHECK_GATEWAY,
  111. IDC_EDIT_GATEWAY,
  112. CControlID::EDIT ) );
  113. PrepSettings(FALSE);
  114. SetButtons();
  115. }
  116. CDsPropWnd2::~CDsPropWnd2()
  117. {
  118. deque< LPTSTR >::iterator it;
  119. for( it = m_serverDQ.begin(); it != m_serverDQ.end(); ++it )
  120. {
  121. delete [] *it;
  122. }
  123. }
  124. void CDsPropWnd2::QueryWizNext(void)
  125. {
  126. bool bWarned = false;
  127. if (DirectoryEnabled())
  128. {
  129. CWebViewInfo *pWebView = GetWebViewInfo();
  130. if (('\0' == pWebView->m_szWebViewServer[0] ||
  131. IsMSServer(pWebView->m_szWebViewServer))
  132. && IsWebViewAllowed())
  133. {
  134. // Just using default Web View information; see if the default
  135. // server is there
  136. for (int i=m_serverDQ.size()-1; ; --i)
  137. {
  138. if (i < 0)
  139. {
  140. // Got through the list without finding the default server
  141. NmrkMessageBox(MAKEINTRESOURCE(IDS_WEBDIR_AUTOADD), NULL, MB_OK | MB_ICONINFORMATION);
  142. bWarned = true;
  143. break;
  144. }
  145. if (IsMSServer(m_serverDQ.at(i)))
  146. {
  147. // Found the default server; no need to proceed
  148. break;
  149. }
  150. }
  151. }
  152. // Note that the MID may be automatically added even if users are not
  153. // allowed to add servers
  154. if (!bWarned && 0 == CountServers())
  155. {
  156. if (AllowUserToAdd())
  157. {
  158. NmrkMessageBox(MAKEINTRESOURCE(IDS_DSLIST_EMPTY), NULL, MB_OK | MB_ICONINFORMATION);
  159. }
  160. else
  161. {
  162. NmrkMessageBox(MAKEINTRESOURCE(IDS_DS_WILL_BE_EMPTY), NULL, MB_OK | MB_ICONINFORMATION);
  163. }
  164. }
  165. }
  166. }
  167. LRESULT CALLBACK CDsPropWnd2::DsPropWndProc( HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
  168. {
  169. switch( uiMsg )
  170. {
  171. case WM_VSCROLL:
  172. case WM_VKEYTOITEM:
  173. case WM_COMMAND:
  174. {
  175. CDsPropWnd2 * pPropWnd = (CDsPropWnd2 *)GetWindowLong( hwnd, GWL_USERDATA );
  176. return pPropWnd->_WndProc( hwnd, uiMsg, wParam, lParam );
  177. break;
  178. }
  179. default:
  180. {
  181. return DefWindowProc( hwnd, uiMsg, wParam, lParam );
  182. break;
  183. }
  184. }
  185. }
  186. BOOL CDsPropWnd2::DoCommand(WPARAM wParam, LPARAM lParam)
  187. {
  188. return(_WndProc(m_hwnd, WM_COMMAND, wParam, lParam));
  189. }
  190. LRESULT CALLBACK CDsPropWnd2::_WndProc( HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
  191. {
  192. switch( uiMsg )
  193. {
  194. case WM_VSCROLL:
  195. {
  196. OnMsg_VScroll( hwnd, wParam );
  197. return 0;
  198. break;
  199. }
  200. case WM_VKEYTOITEM:
  201. {
  202. if( m_serverDQ.size() )
  203. {
  204. switch( LOWORD( wParam ) )
  205. {
  206. case VK_DELETE:
  207. {
  208. _DeleteCurSel();
  209. return 0;
  210. break;
  211. }
  212. }
  213. }
  214. break;
  215. }
  216. case WM_COMMAND:
  217. {
  218. switch (GET_WM_COMMAND_ID(wParam, lParam))
  219. {
  220. case IDC_LIST_SERVERS:
  221. {
  222. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  223. {
  224. case LBN_SELCHANGE:
  225. {
  226. SetButtons();
  227. return 0;
  228. break;
  229. }
  230. case LBN_DBLCLK:
  231. {
  232. _EditCurSel();
  233. return 0;
  234. break;
  235. }
  236. }
  237. break;
  238. }
  239. case IDC_BUTTON_SET_AS_DEFAULT:
  240. {
  241. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  242. {
  243. case BN_CLICKED:
  244. {
  245. _SetAsDefault( ListBox_GetCurSel( m_hwndList ) );
  246. return 0;
  247. break;
  248. }
  249. }
  250. break;
  251. }
  252. case IDC_BUTTON_EDIT:
  253. {
  254. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  255. {
  256. case BN_CLICKED:
  257. {
  258. _EditCurSel();
  259. return 0;
  260. break;
  261. }
  262. }
  263. break;
  264. }
  265. case IDC_BUTTON_SET_WEBVIEW:
  266. {
  267. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  268. {
  269. case BN_CLICKED:
  270. {
  271. _EditCurSelWebView();
  272. return 0;
  273. break;
  274. }
  275. }
  276. break;
  277. }
  278. case IDC_BUTTON_REMOVE:
  279. {
  280. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  281. {
  282. case BN_CLICKED:
  283. {
  284. _DeleteCurSel();
  285. return 0;
  286. break;
  287. }
  288. }
  289. break;
  290. }
  291. case IDC_BUTTON_UP:
  292. {
  293. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  294. {
  295. case BN_CLICKED:
  296. {
  297. _MoveCurSel( -1 );
  298. return 0;
  299. break;
  300. }
  301. }
  302. break;
  303. }
  304. case IDC_BUTTON_DOWN:
  305. {
  306. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  307. {
  308. case BN_CLICKED:
  309. {
  310. _MoveCurSel( 1 );
  311. return 0;
  312. break;
  313. }
  314. }
  315. break;
  316. }
  317. case IDC_BUTTON_ADDDIRECTORYSERVER:
  318. {
  319. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  320. {
  321. case BN_CLICKED:
  322. {
  323. HWND hwndEdit = GetDlgItem( m_hwnd, IDC_EDIT_NEW_SERVER );
  324. if( Edit_GetTextLength( hwndEdit ) )
  325. {
  326. LPTSTR szServer = new TCHAR[ MAX_PATH ];
  327. Edit_GetText( hwndEdit, szServer, MAX_PATH );
  328. _AddServer( szServer );
  329. Edit_SetText( hwndEdit, TEXT("") );
  330. }
  331. else
  332. {
  333. NmrkMessageBox( MAKEINTRESOURCE(IDS_DSNAME_INVALID), NULL,
  334. MB_OK | MB_ICONEXCLAMATION );
  335. }
  336. return 0;
  337. break;
  338. }
  339. }
  340. break;
  341. }
  342. case IDC_ALLOW_USER_TO_USE_DIRECTORY_SERVICES:
  343. {
  344. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  345. {
  346. case BN_CLICKED:
  347. {
  348. SetButtons();
  349. return 0;
  350. break;
  351. }
  352. }
  353. break;
  354. }
  355. case IDC_DISABLE_WEBDIR:
  356. {
  357. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  358. {
  359. case BN_CLICKED:
  360. {
  361. _UpdateServerList();
  362. SetButtons();
  363. return 0;
  364. break;
  365. }
  366. }
  367. break;
  368. }
  369. }
  370. break;
  371. }
  372. }
  373. return DefWindowProc( hwnd, uiMsg, wParam, lParam );
  374. }
  375. void CDsPropWnd2::SetButtons()
  376. {
  377. BOOL bEnable = DirectoryEnabled();
  378. HWND hwndFocus = GetFocus();
  379. BOOL bFocusEnabled = IsWindowEnabled(hwndFocus);
  380. if( m_serverDQ.size() )
  381. {
  382. int iCurSel = ListBox_GetCurSel( m_hwndList );
  383. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_UP ),
  384. bEnable && 1 < iCurSel && m_defaultServer != iCurSel );
  385. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_DOWN ),
  386. bEnable && (m_serverDQ.size() - 1) != iCurSel && m_defaultServer != iCurSel );
  387. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_SET_AS_DEFAULT ),
  388. bEnable && iCurSel != m_defaultServer );
  389. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_SET_WEBVIEW ),
  390. bEnable
  391. && IsWebViewAllowed()
  392. && !(IsWebView(iCurSel) && IsMSServer(GetWebViewInfo()->m_szWebViewServer)) );
  393. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_EDIT ),
  394. bEnable );
  395. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_REMOVE ),
  396. bEnable );
  397. }
  398. else
  399. {
  400. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_SET_AS_DEFAULT ),
  401. FALSE );
  402. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_SET_WEBVIEW ),
  403. FALSE );
  404. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_EDIT ),
  405. FALSE );
  406. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_REMOVE ),
  407. FALSE );
  408. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_UP ),
  409. FALSE );
  410. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_DOWN ),
  411. FALSE );
  412. }
  413. ::EnableWindow( GetDlgItem( m_hwnd, IDC_BUTTON_ADDDIRECTORYSERVER ),
  414. bEnable && m_serverDQ.size() != MAXSERVERS );
  415. ::EnableWindow( GetDlgItem( m_hwnd, IDC_EDIT_NEW_SERVER ),
  416. bEnable && m_serverDQ.size() != MAXSERVERS );
  417. ::EnableWindow( GetDlgItem( m_hwnd, IDC_PREVENT_THE_USER_FROM_ADDING_NEW_SERVERS ),
  418. bEnable );
  419. ::EnableWindow( GetDlgItem( m_hwnd, IDC_DISABLE_WEBDIR), bEnable);
  420. ::EnableWindow( m_hwndList, bEnable );
  421. if (bFocusEnabled && !IsWindowEnabled(hwndFocus))
  422. {
  423. // We seem to have disabled the focus window. Let's try to set the
  424. // focus to an enabled window
  425. if (IsWindowEnabled(m_hwndList))
  426. {
  427. FORWARD_WM_NEXTDLGCTL(m_hwndParent, m_hwndList, TRUE, SendMessage);
  428. }
  429. else
  430. {
  431. FORWARD_WM_NEXTDLGCTL(m_hwndParent, FALSE, FALSE, SendMessage);
  432. }
  433. }
  434. }
  435. void CDsPropWnd2::_AddServer( LPTSTR szServer )
  436. {
  437. int iSize = m_serverDQ.size();
  438. if( iSize > 0 && iSize < MAXSERVERS )
  439. {
  440. int iCurSel = ListBox_GetCurSel( m_hwndList );
  441. if( iCurSel == m_defaultServer )
  442. {
  443. ++iCurSel;
  444. }
  445. deque< LPTSTR >::iterator it = m_serverDQ.begin();
  446. for( int i = 0; i < iCurSel; ++i )
  447. {
  448. ++it;
  449. }
  450. m_serverDQ.insert( it, szServer );
  451. ListBox_InsertString( m_hwndList, iCurSel, szServer );
  452. ListBox_SetCurSel( m_hwndList, iCurSel );
  453. }
  454. else
  455. {
  456. m_serverDQ.push_front( szServer );
  457. ListBox_InsertString( m_hwndList, 0, szServer );
  458. _SetAsDefault( 0 );
  459. }
  460. SetButtons();
  461. }
  462. void CDsPropWnd2::_MoveCurSel( int iPlaces )
  463. {
  464. int iCurSel = ListBox_GetCurSel( m_hwndList );
  465. int iNewPos = iCurSel + iPlaces;
  466. if( iNewPos == m_defaultServer )
  467. {
  468. _SetAsDefault( iCurSel );
  469. }
  470. else if( iCurSel == m_defaultServer )
  471. {
  472. _SetAsDefault( iNewPos );
  473. }
  474. else
  475. {
  476. LPTSTR szCur = m_serverDQ.at( iCurSel );
  477. LPTSTR szNew = m_serverDQ.at( iNewPos );
  478. m_serverDQ.at( iCurSel ) = szNew;
  479. m_serverDQ.at( iNewPos ) = szCur;
  480. if( iPlaces > 0 )
  481. {
  482. ListBox_DeleteString( m_hwndList, iCurSel );
  483. ListBox_InsertString( m_hwndList, iCurSel, m_serverDQ.at( iCurSel ) );
  484. ListBox_DeleteString( m_hwndList, iNewPos );
  485. ListBox_InsertString( m_hwndList, iNewPos, m_serverDQ.at( iNewPos ) );
  486. }
  487. else
  488. {
  489. ListBox_DeleteString( m_hwndList, iNewPos );
  490. ListBox_InsertString( m_hwndList, iNewPos, m_serverDQ.at( iNewPos ) );
  491. ListBox_DeleteString( m_hwndList, iCurSel );
  492. ListBox_InsertString( m_hwndList, iCurSel, m_serverDQ.at( iCurSel ) );
  493. }
  494. }
  495. ListBox_SetCurSel( m_hwndList, iNewPos );
  496. _UpdateServerList();
  497. SetButtons();
  498. }
  499. void CDsPropWnd2::PrepSettings( BOOL fGkMode )
  500. {
  501. if (g_pWiz->m_IntroSheet.GetFilePane()->OptionEnabled())
  502. {
  503. ReadSettings();
  504. }
  505. else
  506. {
  507. deque <LPTSTR>::iterator it;
  508. for( it = m_serverDQ.begin(); it != m_serverDQ.end(); ++it )
  509. {
  510. delete [] *it;
  511. }
  512. m_serverDQ.erase( m_serverDQ.begin(), m_serverDQ.end() );
  513. LPTSTR szServerName = NULL;
  514. szServerName = new TCHAR[ MAX_PATH ];
  515. lstrcpy( szServerName, c_szMSServer );
  516. m_serverDQ.push_back( szServerName );
  517. m_defaultServer = 0;
  518. Button_SetCheck( GetDlgItem( m_hwnd, IDC_ALLOW_USER_TO_USE_DIRECTORY_SERVICES ), TRUE );
  519. Button_SetCheck( GetDlgItem( m_hwnd, IDC_PREVENT_THE_USER_FROM_ADDING_NEW_SERVERS ), FALSE );
  520. Button_SetCheck( GetDlgItem( m_hwnd, IDC_DISABLE_WEBDIR), FALSE);
  521. Button_SetCheck( GetDlgItem( m_hwnd, IDC_CHECK_GATEWAY), FALSE);
  522. }
  523. ListBox_ResetContent( m_hwndList );
  524. // Add Items to listbox
  525. deque< LPTSTR >::const_iterator it;
  526. int i = 0;
  527. for( it = m_serverDQ.begin(); it != m_serverDQ.end(); ++it, ++i )
  528. {
  529. ListBox_InsertString( m_hwndList, i, *it );
  530. }
  531. if( m_serverDQ.size() )
  532. {
  533. // This will do an _UpdateServerList for us
  534. _SetAsDefault( m_defaultServer );
  535. }
  536. }
  537. void CDsPropWnd2::_UpdateServerList()
  538. {
  539. int iSel = ListBox_GetCurSel(m_hwndList);
  540. // We only want to find one WebView
  541. BOOL bFoundWebView = FALSE;
  542. for (int index=ListBox_GetCount(m_hwndList)-1; index>=0; --index)
  543. {
  544. TCHAR szNewText[MAX_PATH];
  545. lstrcpy(szNewText, m_serverDQ.at(index));
  546. BOOL bWebView = FALSE;
  547. if (!bFoundWebView)
  548. {
  549. bWebView = IsWebView(szNewText);
  550. }
  551. if (IsDefault(index))
  552. {
  553. lstrcat(szNewText, TEXT(" (Default)"));
  554. }
  555. if (bWebView)
  556. {
  557. bFoundWebView = TRUE;
  558. if (IsWebViewAllowed())
  559. {
  560. lstrcat(szNewText, TEXT(" (WebView)"));
  561. }
  562. }
  563. TCHAR szOldText[MAX_PATH];
  564. ListBox_GetText(m_hwndList, index, szOldText);
  565. if (lstrcmp(szOldText, szNewText) != 0)
  566. {
  567. ListBox_DeleteString(m_hwndList, index);
  568. ListBox_InsertString(m_hwndList, index, szNewText);
  569. if (iSel == index)
  570. {
  571. ListBox_SetCurSel(m_hwndList, iSel);
  572. }
  573. }
  574. }
  575. if (!bFoundWebView && !IsMSServer(GetWebViewInfo()->m_szWebViewServer))
  576. {
  577. SetWebView(c_szMSServer);
  578. _UpdateServerList();
  579. }
  580. }
  581. void CDsPropWnd2::_EditCurSel()
  582. {
  583. int iCurSel = ListBox_GetCurSel( m_hwndList );
  584. LPTSTR szOldServer = m_serverDQ.at( iCurSel );
  585. CEditServer* pEditServer = new CEditServer( m_hwnd, szOldServer, MAX_PATH );
  586. if( pEditServer->ShowDialog() == IDOK )
  587. {
  588. LPTSTR szServer = new TCHAR[ MAX_PATH ];
  589. lstrcpy( szServer, pEditServer->GetServer() );
  590. m_serverDQ.at( iCurSel ) = szServer;
  591. if (IsWebView(szOldServer))
  592. {
  593. SetWebView(szServer);
  594. }
  595. _UpdateServerList();
  596. delete [] szOldServer;
  597. }
  598. ListBox_SetCurSel( m_hwndList, iCurSel );
  599. }
  600. void CDsPropWnd2::SetWebView(LPCTSTR szServer, LPCTSTR szName, LPCTSTR szURL)
  601. {
  602. GetWebViewInfo()->SetWebView(szServer, szName, szURL);
  603. _UpdateServerList();
  604. }
  605. void CDsPropWnd2::_EditCurSelWebView()
  606. {
  607. int iCurSel = ListBox_GetCurSel( m_hwndList );
  608. LPTSTR szServer = m_serverDQ.at( iCurSel );
  609. if (IsMSServer(szServer))
  610. {
  611. if (IDYES == NmrkMessageBox(MAKEINTRESOURCE(IDS_DEFAULT_WEBVIEW),
  612. MAKEINTRESOURCE(IDS_EDIT_WEBVIEW), MB_ICONEXCLAMATION | MB_YESNO))
  613. {
  614. SetWebView(szServer, TEXT(""), TEXT(""));
  615. SetButtons();
  616. }
  617. return;
  618. }
  619. CWebViewInfo *pWebView = GetWebViewInfo();
  620. LPCTSTR szWVName = TEXT("");
  621. LPCTSTR szWVURL = TEXT("");
  622. if (IsWebView(szServer))
  623. {
  624. szWVName = pWebView->m_szWebViewName;
  625. szWVURL = pWebView->m_szWebViewURL;
  626. }
  627. CEditWebView* pEditWebView = new CEditWebView(
  628. m_hwnd, szServer, szWVName, szWVURL, MAX_PATH );
  629. pEditWebView->SetEditServer(FALSE);
  630. if( pEditWebView->ShowDialog() == IDOK )
  631. {
  632. SetWebView(szServer, pEditWebView->GetName(), pEditWebView->GetURL());
  633. SetButtons();
  634. }
  635. delete pEditWebView;
  636. }
  637. BOOL CDsPropWnd2::_SetAsDefault( int iIndex )
  638. {
  639. if( iIndex < 0 || iIndex > m_serverDQ.size() )
  640. {
  641. return FALSE;
  642. }
  643. // Move default server to top of deque
  644. LPTSTR szNewZero = m_serverDQ.at( iIndex );
  645. m_serverDQ.erase( m_serverDQ.begin() + iIndex );
  646. ListBox_DeleteString( m_hwndList, iIndex );
  647. ListBox_InsertString( m_hwndList, 0, szNewZero );
  648. m_serverDQ.push_front( szNewZero );
  649. m_defaultServer = 0;
  650. ListBox_SetCurSel( m_hwndList, 0 );
  651. _UpdateServerList();
  652. SetButtons();
  653. return TRUE;
  654. }
  655. BOOL CDsPropWnd2::_DeleteCurSel()
  656. {
  657. int iCurSel = ListBox_GetCurSel( m_hwndList );
  658. LPTSTR szKill = m_serverDQ.at( iCurSel );
  659. TCHAR szBuffer[ MAX_PATH ];
  660. LoadString( IDS_ARE_YOU_SURE_YOU_WISH_TO_REMOVE, szBuffer, CCHMAX( szBuffer ) );
  661. TCHAR lpszMessage[ MAX_PATH ];
  662. wsprintf( lpszMessage, szBuffer, szKill );
  663. if( IDNO == NmrkMessageBox(lpszMessage, MAKEINTRESOURCE(IDS_VERIFY), MB_YESNO | MB_ICONQUESTION ) )
  664. {
  665. return FALSE;
  666. }
  667. m_serverDQ.erase( m_serverDQ.begin() + iCurSel );
  668. delete [] szKill;
  669. ListBox_DeleteString( m_hwndList, iCurSel );
  670. if( m_defaultServer == iCurSel )
  671. {
  672. if( m_serverDQ.size() > iCurSel )
  673. {
  674. _SetAsDefault( iCurSel );
  675. }
  676. else
  677. {
  678. _SetAsDefault( iCurSel - 1 );
  679. }
  680. }
  681. else
  682. {
  683. if( m_serverDQ.size() > iCurSel )
  684. {
  685. ListBox_SetCurSel( m_hwndList, iCurSel );
  686. }
  687. else if( iCurSel > 0 )
  688. {
  689. ListBox_SetCurSel( m_hwndList, iCurSel - 1);
  690. }
  691. }
  692. // Make sure all the WebView information is up-to-date
  693. _UpdateServerList();
  694. // Bug fix - I do not get a LBN_SELCHANGE message all the time when I want one
  695. // even though the string selected changes. So just for that I gotta do this
  696. SetButtons();
  697. return TRUE;
  698. }
  699. void CDsPropWnd2::ReadSettings( void )
  700. {
  701. TCHAR szValue[ MAX_PATH ];
  702. TCHAR szServerName[ MAX_PATH ];
  703. for( int i = 0; i < MAXSERVERS; i++ )
  704. {
  705. wsprintf( szValue, KEYNAME_ILSSERVER, i );
  706. ReadStringValue(szValue, szServerName, CCHMAX(szServerName));
  707. if (!szServerName[0])
  708. break;
  709. LPTSTR szServer = new TCHAR[ lstrlen( szServerName ) + 1 ];
  710. lstrcpy( szServer, szServerName );
  711. m_serverDQ.push_back( szServer );
  712. }
  713. ReadWebViewSettings(this);
  714. ReadNumberValue(KEYNAME_ILSDEFAULT, &m_defaultServer);
  715. _ReadCheckSetting( IDC_ALLOW_USER_TO_USE_DIRECTORY_SERVICES );
  716. _ReadCheckSetting( IDC_PREVENT_THE_USER_FROM_ADDING_NEW_SERVERS );
  717. _ReadCheckSetting( IDC_DISABLE_WEBDIR);
  718. _ReadCheckSetting( IDC_CHECK_GATEWAY );
  719. _ReadEditSetting ( IDC_EDIT_GATEWAY );
  720. }
  721. void CDsPropWnd2::WriteSettings( BOOL fGkMode )
  722. {
  723. TCHAR szValue[ MAX_PATH ];
  724. deque< LPTSTR >::const_iterator it;
  725. int i = 0;
  726. for( it = m_serverDQ.begin(); it != m_serverDQ.end(); ++it )
  727. {
  728. wsprintf( szValue, KEYNAME_ILSSERVER, i );
  729. WriteStringValue(szValue, (LPTSTR)*it);
  730. i++;
  731. }
  732. while( i < MAXSERVERS )
  733. {
  734. wsprintf( szValue, KEYNAME_ILSSERVER, i );
  735. WriteStringValue(szValue, TEXT(""));
  736. i++;
  737. }
  738. WriteWebViewSettings(this);
  739. WriteNumberValue(KEYNAME_ILSDEFAULT, m_defaultServer);
  740. _WriteCheckSetting( IDC_ALLOW_USER_TO_USE_DIRECTORY_SERVICES );
  741. _WriteCheckSetting( IDC_PREVENT_THE_USER_FROM_ADDING_NEW_SERVERS );
  742. _WriteCheckSetting( IDC_DISABLE_WEBDIR );
  743. _WriteCheckSetting( IDC_CHECK_GATEWAY );
  744. _WriteEditSetting( IDC_EDIT_GATEWAY );
  745. }
  746. BOOL CDsPropWnd2::WriteToINF(BOOL fGkMode, HANDLE hFile )
  747. {
  748. TCHAR szValue[ MAX_PATH ];
  749. deque< LPTSTR >::const_iterator it;
  750. int i = 0;
  751. for( it = m_serverDQ.begin(); it != m_serverDQ.end(); ++it, ++i )
  752. {
  753. wsprintf( szValue, TEXT("Name%d"), i );
  754. CPolicyData( CPolicyData::eKeyType_HKEY_CURRENT_USER,
  755. DIR_MRU_KEY,
  756. szValue,
  757. *it
  758. ).SaveToINFFile( hFile );
  759. }
  760. CPolicyData( CPolicyData::eKeyType_HKEY_CURRENT_USER,
  761. DIR_MRU_KEY,
  762. TEXT("Count"),
  763. (DWORD)m_serverDQ.size()
  764. ).SaveToINFFile( hFile );
  765. while( i < MAXSERVERS )
  766. {
  767. wsprintf( szValue, TEXT("Name%d"), i );
  768. CPolicyData( CPolicyData::eKeyType_HKEY_CURRENT_USER,
  769. DIR_MRU_KEY,
  770. szValue,
  771. CPolicyData::OpDelete()
  772. ).SaveToINFFile( hFile );
  773. i++;
  774. }
  775. if( m_serverDQ.size() )
  776. {
  777. CPolicyData( CPolicyData::eKeyType_HKEY_CURRENT_USER,
  778. ISAPI_CLIENT_KEY,
  779. REGVAL_SERVERNAME,
  780. m_serverDQ.at( m_defaultServer )
  781. ).SaveToINFFile( hFile );
  782. }
  783. //
  784. // Directory stuff
  785. //
  786. BOOL bCheckValues = !fGkMode && DirectoryEnabled();
  787. if (!fGkMode)
  788. {
  789. WriteWebViewToINF(hFile, IsWebViewAllowed());
  790. _WriteCheckToINF( hFile, IDC_DISABLE_WEBDIR, bCheckValues);
  791. }
  792. CPolicyData( ms_ClassMap[ IDC_ALLOW_USER_TO_USE_DIRECTORY_SERVICES ],
  793. ms_KeyMap[ IDC_ALLOW_USER_TO_USE_DIRECTORY_SERVICES ],
  794. ms_ValueMap[ IDC_ALLOW_USER_TO_USE_DIRECTORY_SERVICES ],
  795. !bCheckValues
  796. ).SaveToINFFile( hFile );
  797. CPolicyData( CPolicyData::eKeyType_HKEY_CURRENT_USER,
  798. POLICIES_KEY,
  799. REGVAL_POL_NO_DIRECTORY_SERVICES,
  800. !bCheckValues
  801. ).SaveToINFFile( hFile );
  802. _WriteCheckToINF( hFile, IDC_PREVENT_THE_USER_FROM_ADDING_NEW_SERVERS, bCheckValues );
  803. //
  804. // Gateway stuff
  805. //
  806. bCheckValues = !fGkMode & GatewayEnabled();
  807. _WriteCheckToINF( hFile, IDC_CHECK_GATEWAY, bCheckValues);
  808. _WriteEditToINF(hFile, IDC_EDIT_GATEWAY, bCheckValues);
  809. return TRUE;
  810. }
  811. int CDsPropWnd2::SpewToListBox( HWND hwndList, int iStartLine )
  812. {
  813. if( DirectoryEnabled() )
  814. {
  815. if( m_serverDQ.size() )
  816. {
  817. ListBox_InsertString( hwndList, iStartLine, TEXT("Adding Directory Servers:") );
  818. iStartLine++;
  819. deque< LPTSTR >::const_iterator it;
  820. for( it = m_serverDQ.begin(); it != m_serverDQ.end(); ++it )
  821. {
  822. LPTSTR sz = new TCHAR[ lstrlen( *it ) + 2 ];
  823. sz[ 0 ] = '\t'; sz[1] = '\0';
  824. lstrcat( sz, *it );
  825. ListBox_InsertString( hwndList, iStartLine, sz );
  826. iStartLine++;
  827. delete [] sz;
  828. }
  829. ListBox_InsertString( hwndList, iStartLine, TEXT("Default Server:") );
  830. iStartLine++;
  831. {
  832. LPTSTR sz = new TCHAR[ lstrlen( m_serverDQ.at( m_defaultServer ) ) + 2 ];
  833. sz[ 0 ] = '\t'; sz[1] = '\0';
  834. lstrcat( sz, m_serverDQ.at( m_defaultServer ) );
  835. ListBox_InsertString( hwndList, iStartLine, sz );
  836. iStartLine++;
  837. delete [] sz;
  838. }
  839. }
  840. if( !AllowUserToAdd() )
  841. {
  842. ListBox_InsertString( hwndList, iStartLine, TEXT("Prevent users from adding new servers to the list you provide") );
  843. iStartLine++;
  844. }
  845. if (!IsWebViewAllowed())
  846. {
  847. ListBox_InsertString( hwndList, iStartLine, TEXT("Prevent users from viewing web directory"));
  848. iStartLine++;
  849. }
  850. }
  851. else
  852. {
  853. ListBox_InsertString( hwndList, iStartLine, TEXT("Disable Directory Services") );
  854. iStartLine++;
  855. }
  856. if (GatewayEnabled())
  857. {
  858. TCHAR szGateway[MAX_PATH];
  859. ListBox_InsertString( hwndList, iStartLine, TEXT("Adding Gateway server:") );
  860. iStartLine++;
  861. szGateway[0] = '\t';
  862. GetDlgItemText(m_hwnd, IDC_EDIT_GATEWAY, szGateway+1,
  863. CCHMAX(szGateway)-1);
  864. ListBox_InsertString( hwndList, iStartLine, szGateway);
  865. iStartLine++;
  866. }
  867. return iStartLine;
  868. }
  869. //
  870. // GATEKEEPER STUFF
  871. //
  872. CGkPropWnd2::CGkPropWnd2( HWND hwndParent, int iX, int iY, int iWidth, int iHeight )
  873. : CPropertyDataWindow2( hwndParent, IDD_CHILDPAGE_GATEKEEPER, TEXT("IDD_CHILDPAGE_GATEKEEPER"), (WNDPROC) GkPropWndProc, 0, iX, iY, iWidth, iHeight, FALSE )
  874. {
  875. SetWindowLong( m_hwnd, GWL_USERDATA, (long)this );
  876. HWND hwndChild;
  877. // Calling method radio buttons
  878. hwndChild = GetDlgItem(m_hwnd, IDC_RADIO_GKMODE_ACCOUNT);
  879. SetWindowLong( hwndChild, GWL_USERDATA, GK_LOGON_USING_ACCOUNT );
  880. hwndChild = GetDlgItem(m_hwnd, IDC_RADIO_GKMODE_PHONE);
  881. SetWindowLong(hwndChild, GWL_USERDATA, GK_LOGON_USING_PHONENUM);
  882. hwndChild = GetDlgItem(m_hwnd, IDC_RADIO_GKMODE_BOTH);
  883. SetWindowLong(hwndChild, GWL_USERDATA, GK_LOGON_USING_BOTH);
  884. Edit_LimitText( GetDlgItem( m_hwnd, IDC_EDIT_GATEKEEPER ), MAX_PATH );
  885. ConnectControlsToCheck( IDC_CHECK_GATEKEEPER, 1,
  886. new CControlID(GetDlgItem(m_hwnd, IDC_CHECK_GATEKEEPER),
  887. IDC_CHECK_GATEKEEPER,
  888. IDC_EDIT_GATEKEEPER,
  889. CControlID::EDIT ) );
  890. PrepSettings(FALSE);
  891. SetButtons();
  892. }
  893. CGkPropWnd2::~CGkPropWnd2()
  894. {
  895. }
  896. void CGkPropWnd2::_EditCurSelWebView()
  897. {
  898. CWebViewInfo *pWebView = GetWebViewInfo();
  899. CEditWebView* pEditWebView = new CEditWebView(
  900. m_hwnd, pWebView->m_szWebViewServer, pWebView->m_szWebViewName, pWebView->m_szWebViewURL, MAX_PATH );
  901. if( pEditWebView->ShowDialog() == IDOK )
  902. {
  903. SetWebView(pEditWebView->GetServer(), pEditWebView->GetName(), pEditWebView->GetURL());
  904. SetButtons();
  905. }
  906. delete pEditWebView;
  907. }
  908. LRESULT CALLBACK CGkPropWnd2::GkPropWndProc( HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
  909. {
  910. switch( uiMsg )
  911. {
  912. case WM_VSCROLL:
  913. case WM_VKEYTOITEM:
  914. case WM_COMMAND:
  915. {
  916. CGkPropWnd2 * pPropWnd = (CGkPropWnd2 *)GetWindowLong( hwnd, GWL_USERDATA );
  917. return pPropWnd->_WndProc( hwnd, uiMsg, wParam, lParam );
  918. break;
  919. }
  920. default:
  921. {
  922. return DefWindowProc( hwnd, uiMsg, wParam, lParam );
  923. break;
  924. }
  925. }
  926. }
  927. BOOL CGkPropWnd2::DoCommand(WPARAM wParam, LPARAM lParam)
  928. {
  929. return(_WndProc(m_hwnd, WM_COMMAND, wParam, lParam));
  930. }
  931. LRESULT CALLBACK CGkPropWnd2::_WndProc( HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
  932. {
  933. switch( uiMsg )
  934. {
  935. case WM_VSCROLL:
  936. {
  937. OnMsg_VScroll( hwnd, wParam );
  938. return 0;
  939. break;
  940. }
  941. case WM_COMMAND:
  942. if (GET_WM_COMMAND_CMD(wParam, lParam) == BN_CLICKED)
  943. {
  944. switch (GET_WM_COMMAND_ID(wParam, lParam))
  945. {
  946. case IDC_BUTTON_SET_WEBVIEW:
  947. _EditCurSelWebView();
  948. break;
  949. case IDC_DISABLE_WEBDIR_GK:
  950. SetButtons();
  951. break;
  952. }
  953. }
  954. break;
  955. }
  956. return DefWindowProc( hwnd, uiMsg, wParam, lParam );
  957. }
  958. void CGkPropWnd2::SetButtons()
  959. {
  960. ::EnableWindow(GetDlgItem(m_hwnd, IDC_BUTTON_SET_WEBVIEW),
  961. !IsDlgButtonChecked(m_hwnd, IDC_DISABLE_WEBDIR_GK));
  962. }
  963. void CGkPropWnd2::PrepSettings( BOOL fGkMode )
  964. {
  965. if (g_pWiz->m_IntroSheet.GetFilePane()->OptionEnabled())
  966. {
  967. ReadSettings();
  968. }
  969. else
  970. {
  971. TCHAR szText[1];
  972. szText[0] = 0;
  973. SetDlgItemText(m_hwnd, IDC_EDIT_GATEKEEPER, szText);
  974. Button_SetCheck(GetDlgItem(m_hwnd, IDC_CHECK_GATEKEEPER), FALSE);
  975. Button_SetCheck(GetDlgItem(m_hwnd, IDC_RADIO_GKMODE_BOTH), BST_CHECKED);
  976. }
  977. }
  978. void CGkPropWnd2::ReadSettings( void )
  979. {
  980. int iRadio;
  981. _ReadEditSetting ( IDC_EDIT_GATEKEEPER );
  982. Button_SetCheck(GetDlgItem(m_hwnd, IDC_CHECK_GATEKEEPER),
  983. (GetWindowTextLength(GetDlgItem(m_hwnd, IDC_EDIT_GATEKEEPER)) != 0));
  984. for (iRadio = IDC_RADIO_GKMODE_FIRST; iRadio < IDC_RADIO_GKMODE_MAX; iRadio++)
  985. {
  986. _ReadCheckSetting(iRadio);
  987. }
  988. ReadWebViewSettings(this);
  989. _ReadCheckSetting( IDC_DISABLE_WEBDIR_GK);
  990. }
  991. void CGkPropWnd2::WriteSettings( BOOL fGkMode )
  992. {
  993. int iRadio;
  994. _WriteEditSetting( IDC_EDIT_GATEKEEPER );
  995. for (iRadio = IDC_RADIO_GKMODE_FIRST; iRadio < IDC_RADIO_GKMODE_MAX; iRadio++)
  996. {
  997. _WriteCheckSetting(iRadio);
  998. }
  999. WriteWebViewSettings(this);
  1000. _WriteCheckSetting( IDC_DISABLE_WEBDIR_GK );
  1001. }
  1002. BOOL CGkPropWnd2::WriteToINF( BOOL fGkMode, HANDLE hFile )
  1003. {
  1004. int iRadio;
  1005. _WriteEditToINF( hFile, IDC_EDIT_GATEKEEPER,
  1006. fGkMode && IsDlgButtonChecked(m_hwnd, IDC_CHECK_GATEKEEPER));
  1007. for (iRadio = IDC_RADIO_GKMODE_FIRST; iRadio < IDC_RADIO_GKMODE_MAX; iRadio++)
  1008. {
  1009. _WriteCheckToINF(hFile, iRadio, fGkMode);
  1010. }
  1011. if (fGkMode)
  1012. {
  1013. WriteWebViewToINF(hFile, IsWebViewAllowed());
  1014. _WriteCheckToINF( hFile, IDC_DISABLE_WEBDIR_GK, fGkMode );
  1015. }
  1016. return TRUE;
  1017. }
  1018. int CGkPropWnd2::SpewToListBox( HWND hwndList, int iStartLine )
  1019. {
  1020. TCHAR szTemp[MAX_PATH];
  1021. int iRadio;
  1022. if (IsDlgButtonChecked(m_hwnd, IDC_CHECK_GATEKEEPER))
  1023. {
  1024. ListBox_InsertString(hwndList, iStartLine, TEXT("Adding Gatekeeper server:") );
  1025. iStartLine++;
  1026. szTemp[0] = '\t';
  1027. GetDlgItemText(m_hwnd, IDC_EDIT_GATEKEEPER, szTemp+1,
  1028. CCHMAX(szTemp)-1);
  1029. ListBox_InsertString(hwndList, iStartLine, szTemp);
  1030. iStartLine++;
  1031. }
  1032. ListBox_InsertString(hwndList, iStartLine, TEXT("Gatekeeper addressing mode:") );
  1033. iStartLine++;
  1034. for (iRadio = IDC_RADIO_GKMODE_FIRST; iRadio < IDC_RADIO_GKMODE_MAX; iRadio++)
  1035. {
  1036. if (IsDlgButtonChecked(m_hwnd, iRadio))
  1037. {
  1038. szTemp[0] = '\t';
  1039. GetDlgItemText(m_hwnd, iRadio, szTemp+1, CCHMAX(szTemp)-1);
  1040. ListBox_InsertString(hwndList, iStartLine, szTemp);
  1041. iStartLine++;
  1042. break;
  1043. }
  1044. }
  1045. return(iStartLine);
  1046. }
  1047. void CGkPropWnd2::QueryWizNext(void)
  1048. {
  1049. }
  1050. void CGkPropWnd2::SetWebView(LPCTSTR szServer, LPCTSTR szName, LPCTSTR szURL)
  1051. {
  1052. GetWebViewInfo()->SetWebView(szServer, szName, szURL);
  1053. }