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.

586 lines
17 KiB

  1. /*++
  2. Module Name:
  3. frsAdv.cpp
  4. Abstract:
  5. This module contains the Implementation of CFRSAdvanced.
  6. This class displays the FRS Advanced Dialog.
  7. */
  8. #include "stdafx.h"
  9. #include "frsAdv.h"
  10. #include "utils.h"
  11. #include "dfshelp.h"
  12. #include "ldaputils.h"
  13. #include <htmlhelp.h>
  14. int g_FRS_ADVANCED_Last_SortColumn = 1;
  15. #define NUM_OF_FRS_ADVANCED_COLUMNS 4
  16. /////////////////////////////////////////////////////////////////////////////
  17. //
  18. // CFRSAdvanced
  19. //
  20. CFRSAdvanced::CFRSAdvanced() :
  21. m_pMemberList(NULL),
  22. m_pConnectionList(NULL),
  23. m_pFrsAdvConnection(NULL)
  24. {
  25. }
  26. CFRSAdvanced::~CFRSAdvanced()
  27. {
  28. if (m_pFrsAdvConnection)
  29. free(m_pFrsAdvConnection);
  30. }
  31. LRESULT CFRSAdvanced::OnInitDialog
  32. (
  33. UINT uMsg,
  34. WPARAM wParam,
  35. LPARAM lParam,
  36. BOOL& bHandled
  37. )
  38. {
  39. int nControlID = 0;
  40. //
  41. // set columns of the inbound connections list box
  42. //
  43. nControlID = IDC_FRS_ADVANCED_INBOUND_CONNS;
  44. HWND hwndControl = GetDlgItem(nControlID);
  45. AddLVColumns(hwndControl, IDS_FRS_ADVANCED_COL_SYNC, NUM_OF_FRS_ADVANCED_COLUMNS);
  46. ListView_SetExtendedListViewStyle(hwndControl, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);
  47. //
  48. // insert the new priority combobox
  49. //
  50. nControlID = IDC_FRS_ADVANCED_NEW_PRIORITY;
  51. int i = 0;
  52. SendDlgItemMessage(nControlID, CB_INSERTSTRING, i++, (LPARAM)_T(""));
  53. SendDlgItemMessage(nControlID, CB_INSERTSTRING, i++, (LPARAM)(BSTR)m_bstrPriorityHigh);
  54. SendDlgItemMessage(nControlID, CB_INSERTSTRING, i++, (LPARAM)(BSTR)m_bstrPriorityMedium);
  55. SendDlgItemMessage(nControlID, CB_INSERTSTRING, i, (LPARAM)(BSTR)m_bstrPriorityLow);
  56. SendDlgItemMessage(nControlID, CB_SETCURSEL, 0, 0);
  57. //
  58. // insert server combobox
  59. //
  60. nControlID = IDC_FRS_ADVANCED_SERVER;
  61. hwndControl = GetDlgItem(nControlID);
  62. int index = 0;
  63. CCusTopMemberList::iterator itMem;
  64. for (i = 0, itMem = m_pMemberList->begin(); itMem != m_pMemberList->end(); i++, itMem++)
  65. {
  66. SendDlgItemMessage(nControlID, CB_INSERTSTRING, i, (LPARAM)(BSTR)(*itMem)->m_bstrServer);
  67. if (!lstrcmpi(m_bstrToServer, (*itMem)->m_bstrServer))
  68. index = i;
  69. }
  70. //
  71. // select the proper server
  72. //
  73. SendDlgItemMessage(nControlID, CB_SETCURSEL, index, 0);
  74. // has to send CBN_SELCHANGE message because it is not sent when
  75. // the current selection is set using the CB_SETCURSEL message.
  76. SendNotifyMessage(WM_COMMAND, MAKEWPARAM(nControlID, CBN_SELCHANGE), (LPARAM)hwndControl);
  77. ::SetFocus(GetDlgItem(IDC_FRS_ADVANCED_SERVER));
  78. return FALSE; // Set focus to the combo box
  79. }
  80. /*++
  81. This function is called when a user clicks the ? in the top right of a property sheet
  82. and then clciks a control, or when they hit F1 in a control.
  83. --*/
  84. LRESULT CFRSAdvanced::OnCtxHelp(
  85. IN UINT i_uMsg,
  86. IN WPARAM i_wParam,
  87. IN LPARAM i_lParam,
  88. IN OUT BOOL& io_bHandled
  89. )
  90. {
  91. LPHELPINFO lphi = (LPHELPINFO) i_lParam;
  92. if (!lphi || lphi->iContextType != HELPINFO_WINDOW || lphi->iCtrlId < 0)
  93. return FALSE;
  94. ::WinHelp((HWND)(lphi->hItemHandle),
  95. DFS_CTX_HELP_FILE,
  96. HELP_WM_HELP,
  97. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_FRS_ADVANCED);
  98. return TRUE;
  99. }
  100. /*++
  101. This function handles "What's This" help when a user right clicks the control
  102. --*/
  103. LRESULT CFRSAdvanced::OnCtxMenuHelp(
  104. IN UINT i_uMsg,
  105. IN WPARAM i_wParam,
  106. IN LPARAM i_lParam,
  107. IN OUT BOOL& io_bHandled
  108. )
  109. {
  110. ::WinHelp((HWND)i_wParam,
  111. DFS_CTX_HELP_FILE,
  112. HELP_CONTEXTMENU,
  113. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_FRS_ADVANCED);
  114. return TRUE;
  115. }
  116. HRESULT CFRSAdvanced::_InsertConnection(FRSADV_CONNECTION *pFrsAdvConn)
  117. {
  118. RETURN_INVALIDARG_IF_NULL(pFrsAdvConn);
  119. HWND hwndControl = GetDlgItem(IDC_FRS_ADVANCED_INBOUND_CONNS);
  120. LVITEM lvItem;
  121. ZeroMemory(&lvItem, sizeof(lvItem));
  122. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  123. lvItem.lParam = (LPARAM)pFrsAdvConn;
  124. lvItem.pszText = _T("");
  125. lvItem.iSubItem = 0;
  126. int iItemIndex = ListView_InsertItem(hwndControl, &lvItem);
  127. lvItem.mask = LVIF_TEXT;
  128. lvItem.iItem = iItemIndex;
  129. lvItem.pszText = pFrsAdvConn->pConn->m_bstrFromServer;
  130. lvItem.iSubItem = 1;
  131. ListView_SetItem(hwndControl, &lvItem);
  132. lvItem.mask = LVIF_TEXT;
  133. lvItem.iItem = iItemIndex;
  134. lvItem.pszText = pFrsAdvConn->pConn->m_bstrFromSite;
  135. lvItem.iSubItem = 2;
  136. ListView_SetItem(hwndControl, &lvItem);
  137. lvItem.mask = LVIF_TEXT;
  138. lvItem.iItem = iItemIndex;
  139. lvItem.iSubItem = 3;
  140. switch (pFrsAdvConn->nPriority)
  141. {
  142. case PRIORITY_HIGH:
  143. lvItem.pszText = m_bstrPriorityHigh;
  144. break;
  145. case PRIORITY_MEDIUM:
  146. lvItem.pszText = m_bstrPriorityMedium;
  147. break;
  148. default:
  149. lvItem.pszText = m_bstrPriorityLow;
  150. break;
  151. }
  152. ListView_SetItem(hwndControl, &lvItem);
  153. ListView_SetCheckState(hwndControl, iItemIndex, pFrsAdvConn->bSyncImmediately);
  154. ListView_Update(hwndControl, iItemIndex);
  155. return S_OK;
  156. }
  157. void CFRSAdvanced::_SaveCheckStateOnConnections()
  158. {
  159. HWND hwnd = GetDlgItem(IDC_FRS_ADVANCED_INBOUND_CONNS);
  160. FRSADV_CONNECTION *pFrsAdvConn = NULL;
  161. int nIndex = -1;
  162. while (-1 != (nIndex = ListView_GetNextItem(hwnd, nIndex, LVNI_ALL)))
  163. {
  164. if (pFrsAdvConn = (FRSADV_CONNECTION *)GetListViewItemData(hwnd, nIndex))
  165. {
  166. pFrsAdvConn->bSyncImmediately = ListView_GetCheckState(hwnd, nIndex);
  167. }
  168. }
  169. }
  170. LRESULT CFRSAdvanced::OnServer
  171. (
  172. WORD wNotifyCode,
  173. WORD wID,
  174. HWND hWndCtl,
  175. BOOL& bHandled
  176. )
  177. {
  178. if (CBN_SELCHANGE != wNotifyCode)
  179. return 0;
  180. HWND hwnd = GetDlgItem(IDC_FRS_ADVANCED_INBOUND_CONNS);
  181. // reset the site, inbound connections listbox, and the new priority field
  182. SetDlgItemText(IDC_FRS_ADVANCED_SITE, _T(""));
  183. _SaveCheckStateOnConnections();
  184. ListView_DeleteAllItems(hwnd);
  185. SendDlgItemMessage(IDC_FRS_ADVANCED_NEW_PRIORITY, CB_SETCURSEL, 0, 0);
  186. // has to send CBN_SELCHANGE message because it is not sent when
  187. // the current selection is set using the CB_SETCURSEL message.
  188. SendNotifyMessage(WM_COMMAND,
  189. MAKEWPARAM(IDC_FRS_ADVANCED_NEW_PRIORITY, CBN_SELCHANGE),
  190. (LPARAM)GetDlgItem(IDC_FRS_ADVANCED_NEW_PRIORITY));
  191. // get the current selected server
  192. int index = SendDlgItemMessage(IDC_FRS_ADVANCED_SERVER, CB_GETCURSEL, 0, 0);
  193. int len = SendDlgItemMessage(IDC_FRS_ADVANCED_SERVER, CB_GETLBTEXTLEN, index, 0);
  194. PTSTR pszServer = (PTSTR)calloc(len + 1, sizeof(TCHAR));
  195. if (!pszServer)
  196. {
  197. DisplayMessageBoxForHR(E_OUTOFMEMORY);
  198. return 0;
  199. }
  200. SendDlgItemMessage(IDC_FRS_ADVANCED_SERVER, CB_GETLBTEXT, index, (LPARAM)pszServer);
  201. for (CCusTopMemberList::iterator it = m_pMemberList->begin(); it != m_pMemberList->end(); it++)
  202. {
  203. if (!lstrcmpi(pszServer, (*it)->m_bstrServer))
  204. {
  205. SetDlgItemText(IDC_FRS_ADVANCED_SITE, (*it)->m_bstrSite);
  206. break;
  207. }
  208. }
  209. int i = 0;
  210. for (i = 0; i < m_cConns; i++)
  211. {
  212. if (!lstrcmpi(pszServer, (m_pFrsAdvConnection + i)->pConn->m_bstrToServer))
  213. {
  214. // insert this inbound connection into the listbox
  215. _InsertConnection(m_pFrsAdvConnection + i);
  216. }
  217. }
  218. free(pszServer);
  219. ListView_SortItems( hwnd,
  220. InboundConnectionsListCompareProc,
  221. (LPARAM)g_FRS_ADVANCED_Last_SortColumn);
  222. /*
  223. UINT uiState = ListView_GetItemState(hwnd, 0, LVIS_STATEIMAGEMASK);
  224. ListView_SetItemState(hwnd, 0, uiState | LVIS_SELECTED | LVIS_FOCUSED, 0xffffffff);
  225. // has to send LVN_ITEMCHANGED message.
  226. NMHDR nmhdr = {hwnd, IDC_FRS_ADVANCED_INBOUND_CONNS, LVN_ITEMCHANGED};
  227. SendNotifyMessage(WM_NOTIFY,
  228. (WPARAM)IDC_FRS_ADVANCED_INBOUND_CONNS,
  229. (LPARAM)&nmhdr);
  230. */
  231. return 1;
  232. }
  233. LRESULT CFRSAdvanced::OnNewPriority
  234. (
  235. WORD wNotifyCode,
  236. WORD wID,
  237. HWND hWndCtl,
  238. BOOL& bHandled
  239. )
  240. {
  241. if (CBN_SELCHANGE != wNotifyCode)
  242. return 0;
  243. // get the current selected new priority
  244. int index = SendDlgItemMessage(IDC_FRS_ADVANCED_NEW_PRIORITY, CB_GETCURSEL, 0, 0);
  245. ::EnableWindow(GetDlgItem(IDC_FRS_ADVANCED_CHANGE), index);
  246. switch (index)
  247. {
  248. case 1:
  249. SetDlgItemText(IDC_FRS_ADVANCED_NEW_PRIORITY_DESC, m_bstrPriorityHighDesc);
  250. break;
  251. case 2:
  252. SetDlgItemText(IDC_FRS_ADVANCED_NEW_PRIORITY_DESC, m_bstrPriorityMediumDesc);
  253. break;
  254. case 3:
  255. SetDlgItemText(IDC_FRS_ADVANCED_NEW_PRIORITY_DESC, m_bstrPriorityLowDesc);
  256. break;
  257. default:
  258. SetDlgItemText(IDC_FRS_ADVANCED_NEW_PRIORITY_DESC, _T(""));
  259. break;
  260. }
  261. return 1;
  262. }
  263. LRESULT CFRSAdvanced::OnChange
  264. (
  265. WORD wNotifyCode,
  266. WORD wID,
  267. HWND hWndCtl,
  268. BOOL& bHandled
  269. )
  270. {
  271. LVITEM lvItem;
  272. ZeroMemory(&lvItem, sizeof(LVITEM));
  273. lvItem.mask = LVIF_TEXT;
  274. lvItem.iSubItem = 3;
  275. Connection_Priority nNewPriority = PRIORITY_LOW;
  276. int index = SendDlgItemMessage(IDC_FRS_ADVANCED_NEW_PRIORITY, CB_GETCURSEL, 0, 0);
  277. switch (index)
  278. {
  279. case 1:
  280. lvItem.pszText = m_bstrPriorityHigh;
  281. nNewPriority = PRIORITY_HIGH;
  282. break;
  283. case 2:
  284. lvItem.pszText = m_bstrPriorityMedium;
  285. nNewPriority = PRIORITY_MEDIUM;
  286. break;
  287. case 3:
  288. lvItem.pszText = m_bstrPriorityLow;
  289. nNewPriority = PRIORITY_LOW;
  290. break;
  291. default:
  292. return 1;
  293. }
  294. HWND hwnd = GetDlgItem(IDC_FRS_ADVANCED_INBOUND_CONNS);
  295. FRSADV_CONNECTION * pFrsAdvConn = NULL;
  296. int nIndex = -1;
  297. while (-1 != (nIndex = ListView_GetNextItem(hwnd, nIndex, LVNI_ALL | LVNI_SELECTED)))
  298. {
  299. if (pFrsAdvConn = (FRSADV_CONNECTION *)GetListViewItemData(hwnd, nIndex))
  300. {
  301. pFrsAdvConn->nPriority = nNewPriority;
  302. lvItem.iItem = nIndex;
  303. ListView_SetItem(hwnd, &lvItem);
  304. ListView_Update(hwnd, nIndex);
  305. }
  306. }
  307. return 1;
  308. }
  309. LRESULT CFRSAdvanced::OnOK
  310. (
  311. WORD wNotifyCode,
  312. WORD wID,
  313. HWND hWndCtl,
  314. BOOL& bHandled
  315. )
  316. {
  317. CWaitCursor wait;
  318. _SaveCheckStateOnConnections();
  319. int i = 0;
  320. for (i = 0; i < m_cConns; i++)
  321. {
  322. (m_pFrsAdvConnection + i)->pConn->m_bSyncImmediatelyNew = (m_pFrsAdvConnection + i)->bSyncImmediately;
  323. (m_pFrsAdvConnection + i)->pConn->m_nPriorityNew = (m_pFrsAdvConnection + i)->nPriority;
  324. }
  325. EndDialog(S_OK);
  326. return TRUE;
  327. }
  328. LRESULT CFRSAdvanced::OnCancel
  329. (
  330. WORD wNotifyCode,
  331. WORD wID,
  332. HWND hWndCtl,
  333. BOOL& bHandled
  334. )
  335. {
  336. /*++
  337. Routine Description:
  338. Called OnCancel. Ends the dialog with S_FALSE;
  339. */
  340. EndDialog(S_FALSE);
  341. return(true);
  342. }
  343. LRESULT
  344. CFRSAdvanced::OnNotify(
  345. IN UINT i_uMsg,
  346. IN WPARAM i_wParam,
  347. IN LPARAM i_lParam,
  348. IN OUT BOOL& io_bHandled
  349. )
  350. {
  351. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)i_lParam;
  352. io_bHandled = FALSE; // So that the base class gets this notify too
  353. HWND hwndList = GetDlgItem(IDC_FRS_ADVANCED_INBOUND_CONNS);
  354. if (IDC_FRS_ADVANCED_EXPLANATION == pNMListView->hdr.idFrom)
  355. {
  356. if (NM_CLICK == pNMListView->hdr.code ||
  357. NM_RETURN == pNMListView->hdr.code)
  358. {
  359. CWaitCursor wait;
  360. ::HtmlHelp(0, _T("dfconcepts.chm"), HH_DISPLAY_TOPIC,
  361. (DWORD_PTR)(_T("sag_DFconceptsFRSPriorities.htm")));
  362. }
  363. return io_bHandled;
  364. }
  365. if (IDC_FRS_ADVANCED_INBOUND_CONNS == pNMListView->hdr.idFrom)
  366. {
  367. if (LVN_COLUMNCLICK == pNMListView->hdr.code)
  368. {
  369. // sort items
  370. ListView_SortItems( hwndList,
  371. InboundConnectionsListCompareProc,
  372. (LPARAM)(pNMListView->iSubItem));
  373. io_bHandled = TRUE;
  374. } else if (LVN_ITEMCHANGED == pNMListView->hdr.code)
  375. {
  376. UINT cSelected = ListView_GetSelectedCount(hwndList);
  377. // update New Priority field
  378. int n = 0;
  379. if (1 == cSelected)
  380. {
  381. FRSADV_CONNECTION *pFrsAdvConn = NULL;
  382. int nIndex = ListView_GetNextItem(hwndList, -1, LVNI_ALL | LVNI_SELECTED);
  383. if (-1 != nIndex &&
  384. (pFrsAdvConn = (FRSADV_CONNECTION *)GetListViewItemData(hwndList, nIndex)))
  385. {
  386. switch (pFrsAdvConn->nPriority)
  387. {
  388. case PRIORITY_LOW:
  389. n = 3; // low
  390. break;
  391. case PRIORITY_MEDIUM:
  392. n = 2; // Medium;
  393. break;
  394. default:
  395. n = 1; // High;
  396. break;
  397. }
  398. }
  399. }
  400. SendDlgItemMessage(IDC_FRS_ADVANCED_NEW_PRIORITY, CB_SETCURSEL, n, 0);
  401. // has to send CBN_SELCHANGE message because it is not sent when
  402. // the current selection is set using the CB_SETCURSEL message.
  403. SendNotifyMessage(WM_COMMAND,
  404. MAKEWPARAM(IDC_FRS_ADVANCED_NEW_PRIORITY, CBN_SELCHANGE),
  405. (LPARAM)GetDlgItem(IDC_FRS_ADVANCED_NEW_PRIORITY));
  406. ::EnableWindow(GetDlgItem(IDC_FRS_ADVANCED_NEW_PRIORITY), cSelected > 0);
  407. }
  408. }
  409. return io_bHandled;
  410. }
  411. HRESULT CFRSAdvanced::Initialize(
  412. CCusTopMemberList* i_pMemberList,
  413. CCusTopConnectionList* i_pConnectionList,
  414. LPCTSTR i_pszToServer /* = NULL */)
  415. {
  416. if (!i_pMemberList || !i_pConnectionList)
  417. return E_INVALIDARG;
  418. m_pMemberList = i_pMemberList;
  419. m_pConnectionList = i_pConnectionList;
  420. // we deal with only the connections that appear in the list box of the CustomTopology dialog, which
  421. // is a subset of i_pConnectionList.
  422. m_cConns = 0;
  423. CCusTopConnectionList::iterator it;
  424. for (it = m_pConnectionList->begin(); it != m_pConnectionList->end(); it++)
  425. {
  426. if ((*it)->m_opType != CONNECTION_OPTYPE_DEL)
  427. m_cConns++;
  428. }
  429. if (0 == m_cConns)
  430. return E_INVALIDARG; // shouldn't happen since Advanced button should have been disabled
  431. if (m_pFrsAdvConnection)
  432. free(m_pFrsAdvConnection);
  433. m_pFrsAdvConnection = (FRSADV_CONNECTION *)calloc(m_cConns, sizeof(FRSADV_CONNECTION));
  434. if (!m_pFrsAdvConnection)
  435. return E_OUTOFMEMORY;
  436. int i = 0;
  437. for (it = m_pConnectionList->begin(); it != m_pConnectionList->end(); it++)
  438. {
  439. if ((*it)->m_opType != CONNECTION_OPTYPE_DEL)
  440. {
  441. (m_pFrsAdvConnection + i)->pConn = (*it);
  442. (m_pFrsAdvConnection + i)->bSyncImmediately = (*it)->m_bSyncImmediatelyNew;
  443. (m_pFrsAdvConnection + i)->nPriority = (*it)->m_nPriorityNew;
  444. i++;
  445. }
  446. }
  447. if (i_pszToServer && *i_pszToServer)
  448. m_bstrToServer = i_pszToServer;
  449. else
  450. m_bstrToServer = _T("");
  451. LoadStringFromResource(IDS_FRS_ADVANCED_PRIORITY_HIGH, &m_bstrPriorityHigh);
  452. LoadStringFromResource(IDS_FRS_ADVANCED_PRIORITY_MEDIUM, &m_bstrPriorityMedium);
  453. LoadStringFromResource(IDS_FRS_ADVANCED_PRIORITY_LOW, &m_bstrPriorityLow);
  454. LoadStringFromResource(IDS_FRS_ADVANCED_PRIORITY_HIGH_DESC, &m_bstrPriorityHighDesc);
  455. LoadStringFromResource(IDS_FRS_ADVANCED_PRIORITY_MEDIUM_DESC, &m_bstrPriorityMediumDesc);
  456. LoadStringFromResource(IDS_FRS_ADVANCED_PRIORITY_LOW_DESC, &m_bstrPriorityLowDesc);
  457. return S_OK;
  458. }
  459. int CALLBACK InboundConnectionsListCompareProc(
  460. IN LPARAM lParam1,
  461. IN LPARAM lParam2,
  462. IN LPARAM lParamColumn)
  463. {
  464. FRSADV_CONNECTION* pItem1 = (FRSADV_CONNECTION *)lParam1;
  465. FRSADV_CONNECTION* pItem2 = (FRSADV_CONNECTION *)lParam2;
  466. int iResult = 0;
  467. if (pItem1 && pItem2)
  468. {
  469. g_FRS_ADVANCED_Last_SortColumn = lParamColumn;
  470. switch (lParamColumn)
  471. {
  472. case 0: // Sort by bSyncImmediately.
  473. iResult = pItem1->bSyncImmediately - pItem2->bSyncImmediately;
  474. break;
  475. case 1: // Sort by From Server.
  476. iResult = lstrcmpi(pItem1->pConn->m_bstrFromServer, pItem2->pConn->m_bstrFromServer);
  477. break;
  478. case 2: // Sort by From Site.
  479. iResult = lstrcmpi(pItem1->pConn->m_bstrFromSite, pItem2->pConn->m_bstrFromSite);
  480. break;
  481. case 3: // Sort by Priority
  482. iResult = pItem1->nPriority - pItem2->nPriority;
  483. break;
  484. default:
  485. iResult = 0;
  486. break;
  487. }
  488. }
  489. return(iResult);
  490. }