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.

897 lines
27 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1996.
  5. //
  6. // File: wizsel.cxx
  7. //
  8. // Contents: Task wizard Onestop selection property page implementation.
  9. //
  10. // Classes: CSelectItemsPage
  11. //
  12. // History: 11-21-1997 SusiA
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "precomp.h"
  16. // temporariy define new mstask flag in case hasn't
  17. // propogated to sdk\inc
  18. //for CS help
  19. extern TCHAR szSyncMgrHelp[];
  20. extern ULONG g_aContextHelpIds[];
  21. extern LANGID g_LangIdSystem; // LangId of system we are running on.
  22. CSelectItemsPage *g_pSelectItemsPage = NULL;
  23. //+-------------------------------------------------------------------------------
  24. // FUNCTION: SchedWizardConnectionDlgProc(HWND, UINT, WPARAM, LPARAM)
  25. //
  26. // PURPOSE: Callback dialog procedure for the property page
  27. //
  28. // PARAMETERS:
  29. // hDlg - Dialog box window handle
  30. // uMessage - current message
  31. // wParam - depends on message
  32. // lParam - depends on message
  33. //
  34. // RETURN VALUE:
  35. //
  36. // Depends on message. In general, return TRUE if we process it.
  37. //
  38. // COMMENTS:
  39. //
  40. //--------------------------------------------------------------------------------
  41. INT_PTR CALLBACK SchedWizardConnectionDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  42. {
  43. WORD wNotifyCode = HIWORD(wParam); // notification code
  44. switch (uMessage)
  45. {
  46. case WM_INITDIALOG:
  47. if (g_pSelectItemsPage)
  48. g_pSelectItemsPage->Initialize(hDlg);
  49. InitPage(hDlg,lParam);
  50. break;
  51. case WM_DESTROY:
  52. if (g_pSelectItemsPage)
  53. {
  54. g_pSelectItemsPage->FreeItemsFromListView();
  55. g_pSelectItemsPage->FreeRas();
  56. if (g_pSelectItemsPage->m_pListView)
  57. {
  58. delete g_pSelectItemsPage->m_pListView;
  59. }
  60. }
  61. break;
  62. case WM_HELP:
  63. {
  64. LPHELPINFO lphi = (LPHELPINFO)lParam;
  65. if (lphi->iContextType == HELPINFO_WINDOW)
  66. {
  67. WinHelp ( (HWND) lphi->hItemHandle,
  68. szSyncMgrHelp,
  69. HELP_WM_HELP,
  70. (ULONG_PTR) g_aContextHelpIds);
  71. }
  72. return TRUE;
  73. }
  74. case WM_CONTEXTMENU:
  75. {
  76. WinHelp ((HWND)wParam,
  77. szSyncMgrHelp,
  78. HELP_CONTEXTMENU,
  79. (ULONG_PTR)g_aContextHelpIds);
  80. return TRUE;
  81. }
  82. case WM_PAINT:
  83. WmPaint(hDlg, uMessage, wParam, lParam);
  84. break;
  85. case WM_PALETTECHANGED:
  86. WmPaletteChanged(hDlg, wParam);
  87. break;
  88. case WM_QUERYNEWPALETTE:
  89. return( WmQueryNewPalette(hDlg) );
  90. break;
  91. case WM_ACTIVATE:
  92. return( WmActivate(hDlg, wParam, lParam) );
  93. break;
  94. case WM_NOTIFYLISTVIEWEX:
  95. if (g_pSelectItemsPage)
  96. {
  97. int idCtrl = (int) wParam;
  98. LPNMHDR pnmhdr = (LPNMHDR) lParam;
  99. if ( (IDC_SCHEDUPDATELIST != idCtrl) || (NULL == g_pSelectItemsPage->m_pListView))
  100. {
  101. Assert(IDC_SCHEDUPDATELIST == idCtrl);
  102. Assert(g_pSelectItemsPage->m_pListView);
  103. break;
  104. }
  105. switch (pnmhdr->code)
  106. {
  107. case LVNEX_ITEMCHECKCOUNT:
  108. {
  109. LPNMLISTVIEWEXITEMCHECKCOUNT pnmvCheckCount = (LPNMLISTVIEWEXITEMCHECKCOUNT) lParam;
  110. g_pSelectItemsPage->SetItemCheckState(pnmvCheckCount->iCheckCount);
  111. break;
  112. }
  113. default:
  114. break;
  115. }
  116. }
  117. break;
  118. case WM_NOTIFY:
  119. if (g_pSelectItemsPage)
  120. {
  121. int idCtrl = (int) wParam;
  122. LPNMHDR pnmhdr = (LPNMHDR) lParam;
  123. // if notification for UpdateListPass it on.
  124. if ((IDC_SCHEDUPDATELIST == idCtrl) && g_pSelectItemsPage->m_pListView)
  125. {
  126. g_pSelectItemsPage->m_pListView->OnNotify(pnmhdr);
  127. break;
  128. }
  129. }
  130. switch (((NMHDR FAR *)lParam)->code)
  131. {
  132. case PSN_KILLACTIVE:
  133. break;
  134. case PSN_RESET:
  135. break;
  136. case PSN_SETACTIVE:
  137. if (g_pSelectItemsPage->m_pListView
  138. && (0 == g_pSelectItemsPage->m_pListView->GetCheckedItemsCount()) )
  139. {
  140. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK ) ;
  141. }
  142. else
  143. {
  144. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  145. }
  146. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, 0);
  147. break;
  148. case PSN_WIZNEXT:
  149. //shouldn't save this until finish
  150. //this guy is only called if the dialog is a wizard
  151. break;
  152. default:
  153. break;
  154. }
  155. break;
  156. case WM_COMMAND:
  157. switch (LOWORD(wParam))
  158. {
  159. case IDC_SCHEDUPDATECOMBO:
  160. {
  161. if (wNotifyCode == CBN_SELCHANGE)
  162. {
  163. HWND hwndCombo = (HWND) lParam;
  164. if (g_pSelectItemsPage)
  165. {
  166. g_pSelectItemsPage->SetConnectionDirty();
  167. g_pSelectItemsPage->ShowItemsOnThisConnection
  168. (ComboBox_GetCurSel(hwndCombo), FALSE);
  169. }
  170. }
  171. }
  172. break;
  173. case IDC_AUTOCONNECT:
  174. {
  175. if (wNotifyCode == BN_CLICKED)
  176. {
  177. PropSheet_Changed(GetParent(hDlg), hDlg);
  178. HWND hwndCtrl = (HWND) lParam;
  179. g_pSelectItemsPage->SetCheck(LOWORD(wParam),
  180. Button_GetCheck(hwndCtrl));
  181. }
  182. }
  183. break;
  184. default:
  185. break;
  186. }
  187. break;
  188. default:
  189. return FALSE;
  190. }
  191. return TRUE;
  192. }
  193. //+--------------------------------------------------------------------------
  194. //
  195. // Member: CSelectItemsPage::CSelectItemsPage
  196. //
  197. // Synopsis: ctor
  198. //
  199. // [phPSP] - filled with prop page handle
  200. //
  201. // History: 11-21-1997 SusiA
  202. //
  203. //---------------------------------------------------------------------------
  204. CSelectItemsPage::CSelectItemsPage(
  205. HINSTANCE hinst,
  206. BOOL *pfSaved,
  207. ISyncSchedule *pISyncSched,
  208. HPROPSHEETPAGE *phPSP,
  209. int iDialogResource)
  210. {
  211. ZeroMemory(&m_psp, sizeof(m_psp));
  212. Assert(pISyncSched);
  213. m_psp.dwSize = sizeof (PROPSHEETPAGE);
  214. m_psp.dwFlags = PSH_DEFAULT;
  215. m_psp.hInstance = hinst;
  216. m_psp.pszTemplate = MAKEINTRESOURCE(iDialogResource);
  217. m_psp.pszIcon = NULL;
  218. m_psp.pfnDlgProc = SchedWizardConnectionDlgProc;
  219. m_psp.lParam = 0;
  220. m_iCreationKind = iDialogResource;
  221. g_pSelectItemsPage = this;
  222. m_pISyncSched = pISyncSched;
  223. m_pISyncSched->AddRef();
  224. m_pfSaved = pfSaved;
  225. *m_pfSaved = FALSE;
  226. m_pListView = NULL;
  227. m_fItemsChanged = FALSE;
  228. m_fConnectionFlagChanged = FALSE;
  229. m_fConnectionChanged = FALSE;
  230. // attempt to get our private interface
  231. if (NOERROR != pISyncSched->QueryInterface(IID_ISyncSchedulep,(void **) &m_pISyncSchedp))
  232. {
  233. m_pISyncSchedp = NULL;
  234. }
  235. *phPSP = CreatePropertySheetPage(&m_psp);
  236. }
  237. CSelectItemsPage::~CSelectItemsPage()
  238. {
  239. if (m_pISyncSchedp)
  240. {
  241. m_pISyncSchedp->Release();
  242. }
  243. }
  244. //+--------------------------------------------------------------------------
  245. //
  246. // Member: CSelectItemsPage::FreeRas()
  247. //
  248. // History: 12-Mar-1998 SusiA
  249. //
  250. //---------------------------------------------------------------------------
  251. void CSelectItemsPage::FreeRas()
  252. {
  253. if (m_pRas)
  254. delete m_pRas;
  255. }
  256. //+--------------------------------------------------------------------------
  257. //
  258. // Member: CSelectItemsPage::Initialize(HWND hwnd)
  259. //
  260. // Synopsis: initialize the item selection page and set the task name to a unique
  261. // new onestop name
  262. //
  263. // History: 11-21-1997 SusiA
  264. //
  265. //---------------------------------------------------------------------------
  266. BOOL CSelectItemsPage::Initialize(HWND hwnd)
  267. {
  268. m_hwnd = hwnd;
  269. // Initialize Ras Combo box
  270. m_pRas= new CRasUI();
  271. if (NULL == m_pRas || FALSE == m_pRas->Initialize())
  272. {
  273. if (m_pRas)
  274. delete m_pRas;
  275. return FALSE;
  276. }
  277. m_hwndRasCombo = GetDlgItem(m_hwnd,IDC_SCHEDUPDATECOMBO);
  278. m_pRas->FillRasCombo(m_hwndRasCombo,FALSE,TRUE);
  279. InitializeItems();
  280. //initialize the item list
  281. HWND hwndList = GetDlgItem(m_hwnd,IDC_SCHEDUPDATELIST);
  282. LV_COLUMN columnInfo;
  283. HIMAGELIST himage;
  284. INT iItem = -1;
  285. UINT ImageListflags;
  286. m_pListView = new CListView(hwndList,m_hwnd,IDC_SCHEDUPDATELIST,WM_NOTIFYLISTVIEWEX);
  287. if (NULL == m_pListView)
  288. {
  289. return FALSE;
  290. }
  291. m_pListView->SetExtendedListViewStyle(LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP );
  292. ImageListflags = ILC_COLOR | ILC_MASK;
  293. if (IsHwndRightToLeft(hwnd))
  294. {
  295. ImageListflags |= ILC_MIRROR;
  296. }
  297. // create an imagelist
  298. himage = ImageList_Create( GetSystemMetrics(SM_CXSMICON),
  299. GetSystemMetrics(SM_CYSMICON),ImageListflags,5,20);
  300. if (himage)
  301. {
  302. m_pListView->SetImageList(himage,LVSIL_SMALL);
  303. }
  304. // Insert the Proper columns
  305. columnInfo.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
  306. columnInfo.fmt = LVCFMT_LEFT;
  307. columnInfo.cx = CalcListViewWidth(hwndList,295);
  308. columnInfo .pszText = TEXT("");
  309. columnInfo.cchTextMax = 1;
  310. columnInfo.iSubItem = 0;
  311. m_pListView->InsertColumn(0,&columnInfo);
  312. ShowItemsOnThisConnection(ComboBox_GetCurSel(m_hwndRasCombo), FALSE);
  313. //Wizard creation
  314. if (m_iCreationKind != IDD_SCHEDPAGE_ITEMS)
  315. {
  316. SetConnectionDirty();
  317. }
  318. ShowWindow(m_hwnd, /* nCmdShow */ SW_SHOWNORMAL );
  319. UpdateWindow(m_hwnd);
  320. return TRUE;
  321. }
  322. //+-------------------------------------------------------------------------------
  323. //
  324. // FUNCTION: BOOL CSelectItemsPage::InitializeItems()
  325. //
  326. // PURPOSE: initialize the handler for the schedule wizard page
  327. //
  328. // RETURN VALUE: return TRUE if we process it ok.
  329. //
  330. //+-------------------------------------------------------------------------------
  331. BOOL CSelectItemsPage::InitializeItems()
  332. {
  333. int i,
  334. iConnectionCount;
  335. TCHAR ptszComboConnName[RAS_MaxEntryName + 1];
  336. TCHAR ptszConnectionName[RAS_MaxEntryName + 1];
  337. WCHAR pwszConnectionName[RAS_MaxEntryName + 1];
  338. DWORD cchConnectionName = ARRAYSIZE(pwszConnectionName);
  339. DWORD dwConnType;
  340. m_fItemsChanged = FALSE;
  341. m_fConnectionFlagChanged = FALSE;
  342. m_fConnectionChanged = FALSE;
  343. if (FAILED(m_pISyncSched->GetConnection(&cchConnectionName,pwszConnectionName, &dwConnType)) ||
  344. FAILED(StringCchCopy(ptszConnectionName, ARRAYSIZE(ptszConnectionName), pwszConnectionName)))
  345. {
  346. return FALSE;
  347. }
  348. iConnectionCount= ComboBox_GetCount(m_hwndRasCombo);
  349. //Initialize the Schedule connection settings
  350. COMBOBOXEXITEM comboItem;
  351. for (i=0; i< iConnectionCount; i++)
  352. {
  353. comboItem.mask = CBEIF_TEXT;
  354. comboItem.cchTextMax = ARRAYSIZE(ptszComboConnName);
  355. comboItem.pszText = ptszComboConnName;
  356. comboItem.iItem = i;
  357. // Review, handle failures.
  358. SendMessage(m_hwndRasCombo, CBEM_GETITEM, (WPARAM) 0, (LPARAM) &comboItem);
  359. m_SchedConnectionNum = 0;
  360. if (lstrcmp(ptszComboConnName, ptszConnectionName) == 0)
  361. {
  362. //Current connection to sync over for the schedule.
  363. m_SchedConnectionNum = i;
  364. ComboBox_SetCurSel(m_hwndRasCombo, i);
  365. break;
  366. }
  367. }
  368. //Set the default autoconnect check state
  369. m_pISyncSched->GetFlags(&m_dwFlags);
  370. Button_SetCheck(GetDlgItem(m_hwnd,IDC_AUTOCONNECT),
  371. m_dwFlags & SYNCSCHEDINFO_FLAGS_AUTOCONNECT);
  372. return TRUE;
  373. }
  374. //--------------------------------------------------------------------------------
  375. //
  376. // FUNCTION: CSelectItemsPage::SetConnectionDirty()
  377. //
  378. // PURPOSE: we have changed the connection info
  379. //
  380. // COMMENTS: Only called frm prop sheet; not wizard
  381. //
  382. //--------------------------------------------------------------------------------
  383. void CSelectItemsPage::SetConnectionDirty()
  384. {
  385. m_fConnectionChanged = TRUE;
  386. }
  387. //--------------------------------------------------------------------------------
  388. //
  389. // FUNCTION: CSelectItemsPage::CommitChanges()
  390. //
  391. // PURPOSE: Write all the current Schedule Settings to the registry
  392. //
  393. // COMMENTS: Implemented on main thread.
  394. //
  395. //--------------------------------------------------------------------------------
  396. HRESULT CSelectItemsPage::CommitChanges()
  397. {
  398. HRESULT hr = S_OK;
  399. if (m_fConnectionFlagChanged)
  400. {
  401. m_pISyncSched->SetFlags(m_dwFlags);
  402. }
  403. if (m_fConnectionChanged)
  404. {
  405. m_pISyncSched->SetConnection(m_pwszConnectionName, m_dwConnType);
  406. }
  407. if (m_fItemsChanged)
  408. {
  409. int iTotalItems = m_pListView->GetItemCount();
  410. //Now set the check state with ISyncSched
  411. BOOL fChecked;
  412. int iItem;
  413. for (iItem=0;iItem < iTotalItems;iItem++)
  414. {
  415. fChecked = (LVITEMEXSTATE_CHECKED == m_pListView->GetCheckState(iItem)) ? TRUE : FALSE;
  416. LVITEMEX lvItem;
  417. ZeroMemory(&lvItem, sizeof(lvItem));
  418. lvItem.mask = LVIF_PARAM;
  419. lvItem.maskEx = 0;
  420. lvItem.iItem = iItem;
  421. lvItem.lParam = 0;
  422. if (m_pListView->GetItem(&lvItem) && lvItem.lParam) // lparam is zero for toplevel items
  423. {
  424. LPSYNC_HANDLER_ITEM_INFO pHandlerItem = (LPSYNC_HANDLER_ITEM_INFO) lvItem.lParam;
  425. if (fChecked)
  426. {
  427. m_pISyncSched->SetItemCheck(pHandlerItem->handlerID,
  428. &(pHandlerItem->itemID),
  429. SYNCMGRITEMSTATE_CHECKED);
  430. }
  431. else
  432. {
  433. m_pISyncSched->SetItemCheck(pHandlerItem->handlerID,
  434. &(pHandlerItem->itemID),
  435. SYNCMGRITEMSTATE_UNCHECKED);
  436. }
  437. }
  438. }
  439. }
  440. hr = m_pISyncSched->Save();
  441. if (hr == S_OK)
  442. {
  443. *m_pfSaved = TRUE;
  444. }
  445. return hr;
  446. }
  447. //+-------------------------------------------------------------------------------
  448. //
  449. // FUNCTION: BOOL CSelectItemsPage::SetItemCheckState()
  450. //
  451. // PURPOSE: set the selected check state
  452. //
  453. // RETURN VALUE: return TRUE if we process it ok.
  454. //
  455. //+-------------------------------------------------------------------------------
  456. BOOL CSelectItemsPage::SetItemCheckState(int iCheckCount)
  457. {
  458. int iConnectionItem = ComboBox_GetCurSel(m_hwndRasCombo);
  459. //The check state is message is getting flagged by us programmatically setting it,
  460. // until after we are done initializing.
  461. if (m_Initialized)
  462. {
  463. BOOL fAnyChecked = iCheckCount ? TRUE : FALSE;
  464. //Enable the prompt me first according to what items selected
  465. //EnableWindow(GetDlgItem(m_hwnd,IDC_AUTOPROMPT_ME_FIRST), m_fAnyChecked);
  466. PropSheet_Changed(GetParent(m_hwnd), m_hwnd);
  467. //Enable the next button according to what items are selected
  468. // should only be disabled iff ALL connection items are
  469. // unselected, not just the current connections selection's
  470. if (fAnyChecked)
  471. PropSheet_SetWizButtons(GetParent(m_hwnd), PSWIZB_BACK | PSWIZB_NEXT);
  472. else
  473. PropSheet_SetWizButtons(GetParent(m_hwnd), PSWIZB_BACK);
  474. m_fItemsChanged = TRUE;
  475. }
  476. return TRUE;
  477. }
  478. //+-------------------------------------------------------------------------------
  479. //
  480. // FUNCTION: BOOL CSelectItemsPage::SetCheck(WORD wParam,DWORD dwCheckState)
  481. //
  482. // PURPOSE: set the selected check state
  483. //
  484. // RETURN VALUE: return TRUE if we process it ok.
  485. //
  486. //+-------------------------------------------------------------------------------
  487. BOOL CSelectItemsPage::SetCheck(WORD wParam,DWORD dwCheckState)
  488. {
  489. if (wParam == IDC_AUTOCONNECT)
  490. {
  491. int iConnectionItem = ComboBox_GetCurSel(m_hwndRasCombo);
  492. //preserve Readonly state
  493. m_dwFlags &= SYNCSCHEDINFO_FLAGS_READONLY;
  494. //set new autoconnect state
  495. if (dwCheckState)
  496. {
  497. m_dwFlags |= SYNCSCHEDINFO_FLAGS_AUTOCONNECT;
  498. }
  499. if (m_Initialized)
  500. {
  501. m_fConnectionFlagChanged = TRUE;
  502. }
  503. }
  504. return TRUE;
  505. }
  506. //+-------------------------------------------------------------------------------
  507. //
  508. // FUNCTION: BOOL CSelectItemsPage::FreeItemsFromListView()
  509. //
  510. // PURPOSE: free the items on this Schedule
  511. //
  512. // RETURN VALUE: return TRUE if we process it ok.
  513. //
  514. //+-------------------------------------------------------------------------------
  515. BOOL CSelectItemsPage::FreeItemsFromListView()
  516. {
  517. int iItem;
  518. int iItemCount;
  519. HWND hwndListView = GetDlgItem(m_hwnd,IDC_SCHEDUPDATELIST);
  520. iItemCount = m_pListView->GetItemCount();
  521. for(iItem = 0; iItem < iItemCount; iItem++)
  522. {
  523. LPSYNC_HANDLER_ITEM_INFO pHandlerItem;
  524. LVITEMEX lvItem;
  525. ZeroMemory(&lvItem, sizeof(lvItem));
  526. lvItem.mask = LVIF_PARAM;
  527. lvItem.maskEx = 0;
  528. lvItem.iItem = iItem;
  529. if (m_pListView->GetItem(&lvItem) && lvItem.lParam)
  530. {
  531. pHandlerItem = (LPSYNC_HANDLER_ITEM_INFO) lvItem.lParam;
  532. FREE(pHandlerItem);
  533. }
  534. }
  535. return TRUE;
  536. }
  537. //+-------------------------------------------------------------------------------
  538. //
  539. // FUNCTION: BOOL CSelectItemsPage::ShowItemsOnThisConnection()
  540. //
  541. // PURPOSE: List the items on this connection for the Schedule page
  542. //
  543. // RETURN VALUE: return TRUE if we process it ok.
  544. //
  545. //+-------------------------------------------------------------------------------
  546. BOOL CSelectItemsPage::ShowItemsOnThisConnection(int iItem, BOOL fClear)
  547. {
  548. TCHAR ptszConnectionName[RAS_MaxEntryName + 1];
  549. // set up the list view
  550. if (!m_pListView || !m_pISyncSchedp)
  551. {
  552. return FALSE;
  553. }
  554. HIMAGELIST himage;
  555. LVITEMEX itemInfo;
  556. m_Initialized = FALSE;
  557. //Note: Use text to "uniquely" identify connection on RAS
  558. //change to using GUID on connection objects
  559. int iNumConnections = ComboBox_GetCount(m_hwndRasCombo);
  560. m_SchedConnectionNum = iItem;
  561. COMBOBOXEXITEM comboItem;
  562. comboItem.mask = CBEIF_TEXT | CBEIF_LPARAM;
  563. comboItem.cchTextMax = ARRAYSIZE(ptszConnectionName);
  564. comboItem.pszText = ptszConnectionName;
  565. comboItem.iItem = iItem;
  566. // Review, handle failures.
  567. SendMessage(m_hwndRasCombo, CBEM_GETITEM, 0, (LPARAM) &comboItem);
  568. //SetConnectionName
  569. if (FAILED(StringCchCopy(m_pwszConnectionName, ARRAYSIZE(m_pwszConnectionName), ptszConnectionName)))
  570. {
  571. return FALSE;
  572. }
  573. m_dwConnType = (DWORD) comboItem.lParam;
  574. // if don't need to clear and listview contains items then we are done
  575. if (!fClear && m_pListView->GetItemCount())
  576. {
  577. m_Initialized = TRUE;
  578. return TRUE;
  579. }
  580. //first clear out the list view
  581. FreeItemsFromListView();
  582. m_pListView->DeleteAllItems();
  583. // Review, dont' clear ImageList so just keeps getting bigger as change connections.
  584. himage = m_pListView->GetImageList(LVSIL_SMALL );
  585. //Enumerate the Items
  586. IEnumSyncItems *pIEnum;
  587. LPSYNC_HANDLER_ITEM_INFO pHandlerItem = (LPSYNC_HANDLER_ITEM_INFO)
  588. ALLOC(sizeof(SYNC_HANDLER_ITEM_INFO));
  589. ULONG ulFetched;
  590. if (FAILED(m_pISyncSchedp->EnumItems(GUID_NULL, &pIEnum)))
  591. {
  592. return FALSE;
  593. }
  594. while (pHandlerItem && S_OK == pIEnum->Next(1,pHandlerItem, &ulFetched))
  595. {
  596. LVHANDLERITEMBLOB lvHandlerItemBlob;
  597. int iParentItemId;
  598. BOOL fHandlerParent = TRUE; // always have a parent for now.
  599. // Check if item is already in the ListView and if so
  600. // go on
  601. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  602. lvHandlerItemBlob.clsidServer = pHandlerItem->handlerID;
  603. lvHandlerItemBlob.ItemID = pHandlerItem->itemID;
  604. if (-1 != m_pListView->FindItemFromBlob((LPLVBLOB) &lvHandlerItemBlob))
  605. {
  606. // already in ListView, go on to the next item.
  607. continue;
  608. }
  609. if (!fHandlerParent)
  610. {
  611. iParentItemId = LVI_ROOT;
  612. }
  613. else
  614. {
  615. // need to add to list so find parent and if one doesn't exist, create it.
  616. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  617. lvHandlerItemBlob.clsidServer = pHandlerItem->handlerID;
  618. lvHandlerItemBlob.ItemID = GUID_NULL;
  619. iParentItemId = m_pListView->FindItemFromBlob((LPLVBLOB) &lvHandlerItemBlob);
  620. if (-1 == iParentItemId)
  621. {
  622. LVITEMEX itemInfoParent;
  623. SYNCMGRHANDLERINFO *pSyncMgrHandlerInfo;
  624. // if can't get the ParentInfo then don't add the Item
  625. if (NOERROR != m_pISyncSchedp->GetHandlerInfo(pHandlerItem->handlerID,&pSyncMgrHandlerInfo) )
  626. {
  627. continue;
  628. }
  629. // Insert the Parent.
  630. itemInfoParent.mask = LVIF_TEXT | LVIF_PARAM;
  631. itemInfoParent.iItem = LVI_LAST;
  632. itemInfoParent.iSubItem = 0;
  633. itemInfoParent.lParam = 0;
  634. itemInfoParent.iImage = -1;
  635. itemInfoParent.pszText = pSyncMgrHandlerInfo->wszHandlerName;
  636. if (himage)
  637. {
  638. HICON hIcon = pSyncMgrHandlerInfo->hIcon ? pSyncMgrHandlerInfo->hIcon : pHandlerItem->hIcon;
  639. // if have toplevel handler info icon use this else use the
  640. // items icon
  641. if (hIcon && (itemInfoParent.iImage =
  642. ImageList_AddIcon(himage,hIcon)) )
  643. {
  644. itemInfoParent.mask |= LVIF_IMAGE ;
  645. }
  646. }
  647. // save the blob
  648. itemInfoParent.maskEx = LVIFEX_BLOB;
  649. itemInfoParent.pBlob = (LPLVBLOB) &lvHandlerItemBlob;
  650. iParentItemId = m_pListView->InsertItem(&itemInfoParent);
  651. CoTaskMemFree(pSyncMgrHandlerInfo);
  652. // if parent insert failed go onto the next item
  653. if (-1 == iParentItemId)
  654. {
  655. continue;
  656. }
  657. }
  658. }
  659. itemInfo.mask = LVIF_TEXT | LVIF_PARAM;
  660. itemInfo.maskEx = LVIFEX_PARENT | LVIFEX_BLOB;
  661. itemInfo.iItem = LVI_LAST;
  662. itemInfo.iSubItem = 0;
  663. itemInfo.lParam = (LPARAM)pHandlerItem;
  664. itemInfo.pszText = pHandlerItem->wszItemName;
  665. itemInfo.iImage = -1; // index of the list view item?s icon
  666. if (himage && pHandlerItem->hIcon)
  667. {
  668. itemInfo.iImage =
  669. ImageList_AddIcon(himage,pHandlerItem->hIcon);
  670. itemInfo.mask |= LVIF_IMAGE;
  671. }
  672. itemInfo.iParent = iParentItemId;
  673. // setup the blob
  674. lvHandlerItemBlob.ItemID = pHandlerItem->itemID;
  675. itemInfo.pBlob = (LPLVBLOB) &lvHandlerItemBlob;
  676. itemInfo.iItem = m_pListView->InsertItem(&itemInfo);
  677. if (-1 == itemInfo.iItem)
  678. {
  679. continue;
  680. }
  681. //Set the check state of the item
  682. itemInfo.mask = LVIF_STATE;
  683. itemInfo.stateMask= LVIS_STATEIMAGEMASK;
  684. if (fClear)
  685. {
  686. itemInfo.state = LVIS_STATEIMAGEMASK_UNCHECK;
  687. m_fItemsChanged = TRUE;
  688. }
  689. else
  690. {
  691. itemInfo.state = pHandlerItem->dwCheckState == SYNCMGRITEMSTATE_UNCHECKED ?
  692. LVIS_STATEIMAGEMASK_UNCHECK : LVIS_STATEIMAGEMASK_CHECK ;
  693. }
  694. m_pListView->SetItem(&itemInfo);
  695. pHandlerItem = (LPSYNC_HANDLER_ITEM_INFO) ALLOC(sizeof(SYNC_HANDLER_ITEM_INFO));
  696. }
  697. if (m_pListView->GetItemCount())
  698. {
  699. m_pListView->SetItemState(0,
  700. LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  701. }
  702. //free the last one we created, we didn't use it.
  703. if (pHandlerItem)
  704. {
  705. FREE(pHandlerItem);
  706. }
  707. pIEnum->Release();
  708. m_Initialized = TRUE;
  709. if (m_pListView->GetCheckedItemsCount())
  710. {
  711. PropSheet_SetWizButtons(GetParent(m_hwnd), PSWIZB_BACK | PSWIZB_NEXT);
  712. }
  713. else
  714. {
  715. PropSheet_SetWizButtons(GetParent(m_hwnd), PSWIZB_BACK);
  716. }
  717. return TRUE;
  718. }