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.

1114 lines
32 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998.
  5. //
  6. // File: Settings.cpp
  7. //
  8. // Contents: Onestop settings routines
  9. //
  10. // Classes:
  11. //
  12. // Notes:
  13. //
  14. // History: 10-Nov-97 SusiA Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #include "precomp.h"
  18. extern HINSTANCE g_hmodThisDll; // Handle to this DLL itself.
  19. extern UINT g_cRefThisDll;
  20. extern CRITICAL_SECTION g_DllCriticalSection; // Global Critical Section for this DLL
  21. extern OSVERSIONINFOA g_OSVersionInfo; // osVersionInfo, setup by WinMain.
  22. // items for context sensitive help
  23. // Review -Should be string in resource.
  24. TCHAR szSyncMgrHelp[] = TEXT("mobsync.hlp");
  25. ULONG g_aContextHelpIds[] =
  26. {
  27. IDC_STATIC1, ((DWORD) -1),
  28. IDC_STATIC2, ((DWORD) -1),
  29. IDC_STATIC3, ((DWORD) -1),
  30. IDC_STATIC4, ((DWORD) -1),
  31. IDC_ADVANCEDIDLEOVERVIEWTEXT, ((DWORD) -1),
  32. IDC_ADVANCEDIDLEWAITTEXT, ((DWORD) -1),
  33. IDC_ADVANCEDIDLEMINUTESTEXT1, ((DWORD) -1),
  34. IDC_ADVANCEDIDLEMINUTESTEXT2, ((DWORD) -1),
  35. IDC_SP_SEPARATOR, ((DWORD) -1),
  36. IDS_CONNECTDESCRIPTION, ((DWORD) -1),
  37. IDC_SCHED_NAME, ((DWORD) -1),
  38. IDC_SCHED_STRING, ((DWORD) -1),
  39. IDC_LASTRUN, ((DWORD) -1),
  40. IDC_NEXTRUN, ((DWORD) -1),
  41. IDC_ConnectionText, ((DWORD) -1),
  42. IDC_RUNLOGGEDON, HIDC_RUNLOGGEDON,
  43. IDC_RUNALWAYS, HIDC_RUNALWAYS,
  44. IDC_RUNAS_TEXT, HIDC_RUNAS_TEXT,
  45. IDC_USERNAME, HIDC_USERNAME,
  46. IDC_PASSWORD_TEXT, HIDC_PASSWORD_TEXT,
  47. IDC_PASSWORD, HIDC_PASSWORD,
  48. IDC_CONFIRMPASSWORD_TEXT, HIDC_CONFIRMPASSWORD_TEXT,
  49. IDC_CONFIRMPASSWORD, HIDC_CONFIRMPASSWORD,
  50. IDC_ADVANCEDIDLE, HIDC_ADVANCEDIDLE,
  51. IDC_AUTOCONNECT, HIDC_AUTOCONNECT,
  52. IDC_AUTOLOGOFF, HIDC_AUTOLOGOFF,
  53. IDC_AUTOLOGON, HIDC_AUTOLOGON,
  54. IDC_AUTOPROMPT_ME_FIRST, HIDC_AUTOPROMPT_ME_FIRST,
  55. IDC_AUTOUPDATECOMBO, HIDC_AUTOUPDATECOMBO,
  56. IDC_AUTOUPDATELIST, HIDC_AUTOUPDATELIST,
  57. IDC_CHECKREPEATESYNC, HIDC_CHECKREPEATESYNC,
  58. IDC_CHECKRUNONBATTERIES, HIDC_CHECKRUNONBATTERIES,
  59. IDC_EDITIDLEREPEATMINUTES, HIDC_EDITIDLEREPEATMINUTES,
  60. IDC_EDITIWAITMINUTES, HIDC_EDITIWAITMINUTES,
  61. IDC_SPINIDLEREPEATMINUTES, HIDC_EDITIDLEREPEATMINUTES,
  62. IDC_SPINIDLEWAITMINUTES, HIDC_EDITIWAITMINUTES,
  63. IDC_IDLECHECKBOX, HIDC_IDLECHECKBOX,
  64. IDC_SCHEDADD, HIDC_SCHEDADD,
  65. IDC_SCHEDEDIT, HIDC_SCHEDEDIT,
  66. IDC_SCHEDLIST, HIDC_SCHEDLIST,
  67. IDC_SCHEDREMOVE, HIDC_SCHEDREMOVE,
  68. IDC_SCHEDUPDATECOMBO, HIDC_SCHEDUPDATECOMBO,
  69. IDC_SCHEDUPDATELIST, HIDC_SCHEDUPDATELIST,
  70. IDC_SCHED_NAME_EDITBOX, HIDC_SCHED_NAME_EDITBOX,
  71. 0,0
  72. };
  73. INT_PTR CALLBACK AutoSyncDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
  74. INT_PTR CALLBACK SchedSyncDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
  75. INT_PTR CALLBACK IdleSyncDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
  76. INT_PTR CALLBACK IdleAdvancedSettingsDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
  77. int CALLBACK PropSheetProc( HWND hwndDlg, UINT uMsg, LPARAM lParam);
  78. DWORD WINAPI SettingsThread( LPVOID lpArg );
  79. DWORD g_SettingsThreadID = NULL;
  80. HWND g_hwndPropSheet = NULL;
  81. CAutoSyncPage *g_pAutoSyncPage = NULL; // shared by AutoSync and IdleSyncDlg Procs
  82. CSchedSyncPage *g_pSchedSyncPage = NULL;
  83. BOOL g_fInSettingsDialog = FALSE;
  84. //+-------------------------------------------------------------------------------
  85. //
  86. // FUNCTION: IsSchedulingInstalled()
  87. //
  88. // PURPOSE: Determines is there is a task scheduler on the current workstation
  89. //
  90. //
  91. //--------------------------------------------------------------------------------
  92. BOOL IsSchedulingInstalled()
  93. {
  94. BOOL fInstalled = FALSE;
  95. ISchedulingAgent *pSchedAgent = NULL;
  96. // Review if there is a better way to test this.
  97. if (NOERROR == CoCreateInstance(CLSID_CSchedulingAgent,
  98. NULL,
  99. CLSCTX_INPROC_SERVER,
  100. IID_ISchedulingAgent,
  101. (LPVOID*)&pSchedAgent) )
  102. {
  103. fInstalled = TRUE;
  104. pSchedAgent->Release();
  105. }
  106. return fInstalled;
  107. }
  108. //+-------------------------------------------------------------------------------
  109. //
  110. // FUNCTION: IsIdleAvailable()
  111. //
  112. // PURPOSE: Determines is this machine supports can Idle
  113. //
  114. //
  115. //--------------------------------------------------------------------------------
  116. BOOL IsIdleAvailable()
  117. {
  118. BOOL fInstalled = FALSE;
  119. ISchedulingAgent *pSchedAgent = NULL;
  120. // Review if there is a better way to test this.
  121. if (NOERROR == CoCreateInstance(CLSID_CSchedulingAgent,
  122. NULL,
  123. CLSCTX_INPROC_SERVER,
  124. IID_ISchedulingAgent,
  125. (LPVOID*)&pSchedAgent) )
  126. {
  127. fInstalled = TRUE;
  128. pSchedAgent->Release();
  129. }
  130. return fInstalled;
  131. }
  132. //+-------------------------------------------------------------------------------
  133. //
  134. // FUNCTION: IsAutoSyncAvailable()
  135. //
  136. // PURPOSE: Determines is this machine supports AutoSync
  137. //
  138. //
  139. //--------------------------------------------------------------------------------
  140. BOOL IsAutoSyncAvailable()
  141. {
  142. return TRUE;
  143. }
  144. //+-------------------------------------------------------------------------------
  145. //
  146. // FUNCTION: DisplayOptions()
  147. //
  148. // PURPOSE: Display the Onestop autosync options
  149. //
  150. //
  151. //--------------------------------------------------------------------------------
  152. STDAPI DisplayOptions(HWND hwndOwner)
  153. {
  154. #define MAXNUMPROPSHEETS 3
  155. int hr = E_FAIL;
  156. DWORD dwError;
  157. // always use ANSI versions since doesn't matter
  158. PROPSHEETPAGE psp [MAXNUMPROPSHEETS];
  159. HPROPSHEETPAGE hpsp [MAXNUMPROPSHEETS];
  160. PROPSHEETHEADER psh;
  161. int nPages = 0;
  162. BOOL fIdleAvailable;
  163. CCriticalSection cCritSect(&g_DllCriticalSection,GetCurrentThreadId());
  164. cCritSect.Enter();
  165. if (g_fInSettingsDialog) // IF ALREADY DISPLAYING A DIALOG BOX, THEN JUST RETURN
  166. {
  167. HWND hwndSettings = g_hwndPropSheet;
  168. cCritSect.Leave();
  169. if (hwndSettings)
  170. {
  171. SetForegroundWindow(hwndSettings);
  172. }
  173. return NOERROR;
  174. }
  175. g_fInSettingsDialog = TRUE;
  176. cCritSect.Leave();
  177. hr = CoInitialize(NULL);
  178. if (SUCCEEDED(hr))
  179. {
  180. RegSetUserDefaults(); // Make Sure the UserDefaults are up to date
  181. ZeroMemory(psp,sizeof(psp));
  182. ZeroMemory(&psh, sizeof(psh));
  183. if (IsAutoSyncAvailable())
  184. {
  185. psp[nPages].dwSize = sizeof (psp[0]);
  186. psp[nPages].dwFlags = PSP_DEFAULT | PSP_USETITLE;
  187. psp[nPages].hInstance = g_hmodThisDll;
  188. psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_AUTOSYNC);
  189. psp[nPages].pszIcon = NULL;
  190. psp[nPages].pfnDlgProc = AutoSyncDlgProc;
  191. //Logon only on everything but NT5
  192. if ((VER_PLATFORM_WIN32_WINDOWS == g_OSVersionInfo.dwPlatformId) ||
  193. (g_OSVersionInfo.dwMajorVersion < 5))
  194. {
  195. psp[nPages].pszTitle = MAKEINTRESOURCE(IDS_LOGON_TAB);
  196. }
  197. else
  198. {
  199. psp[nPages].pszTitle = MAKEINTRESOURCE(IDS_LOGONLOGOFF_TAB);
  200. }
  201. psp[nPages].lParam = 0;
  202. hpsp[nPages] = CreatePropertySheetPage(&(psp[nPages]));
  203. ++nPages;
  204. }
  205. if (fIdleAvailable = IsIdleAvailable())
  206. {
  207. psp[nPages].dwSize = sizeof (psp[0]);
  208. psp[nPages].dwFlags = PSP_DEFAULT | PSP_USETITLE;
  209. psp[nPages].hInstance = g_hmodThisDll;
  210. psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_IDLESETTINGS);
  211. psp[nPages].pszIcon = NULL;
  212. psp[nPages].pfnDlgProc = IdleSyncDlgProc;
  213. psp[nPages].pszTitle = MAKEINTRESOURCE(IDS_ONIDLE_TAB);
  214. psp[nPages].lParam = 0;
  215. hpsp[nPages] = CreatePropertySheetPage(&(psp[nPages]));
  216. ++nPages;
  217. }
  218. // Review - if have idle have schedule, why not collapse
  219. // all these IsxxxAvailable into one call.
  220. if (fIdleAvailable /* IsSchedulingInstalled() */)
  221. {
  222. psp[nPages].dwSize = sizeof (psp[0]);
  223. psp[nPages].dwFlags = PSP_DEFAULT | PSP_USETITLE;
  224. psp[nPages].hInstance = g_hmodThisDll;
  225. psp[nPages].pszTemplate = MAKEINTRESOURCE(IDD_SCHEDSYNC);
  226. psp[nPages].pszIcon = NULL;
  227. psp[nPages].pfnDlgProc = SchedSyncDlgProc;
  228. psp[nPages].pszTitle = MAKEINTRESOURCE(IDS_SCHEDULED_TAB);
  229. psp[nPages].lParam = 0;
  230. hpsp[nPages] = CreatePropertySheetPage(&(psp[nPages]));
  231. ++nPages;
  232. }
  233. Assert(nPages <= MAXNUMPROPSHEETS);
  234. psh.dwSize = sizeof (psh);
  235. psh.dwFlags = PSH_DEFAULT | PSH_USECALLBACK | PSH_USEHICON;
  236. psh.hwndParent = hwndOwner;
  237. psh.hInstance = g_hmodThisDll;
  238. psh.pszIcon = NULL;
  239. psh.hIcon = LoadIcon(g_hmodThisDll, MAKEINTRESOURCE(IDI_SYNCMGR));
  240. psh.pszCaption = MAKEINTRESOURCE(IDS_SCHEDULED_TITLE);
  241. psh.nPages = nPages;
  242. psh.phpage = hpsp;
  243. psh.pfnCallback = PropSheetProc;
  244. psh.nStartPage = 0;
  245. hr = (int)PropertySheet(&psh);
  246. // remove global classes
  247. if (g_pAutoSyncPage)
  248. {
  249. delete g_pAutoSyncPage;
  250. g_pAutoSyncPage = NULL;
  251. }
  252. g_SettingsThreadID = NULL;
  253. if (g_pSchedSyncPage)
  254. {
  255. delete g_pSchedSyncPage;
  256. g_pSchedSyncPage = NULL;
  257. }
  258. g_hwndPropSheet = NULL;
  259. CoFreeUnusedLibraries();
  260. CoUninitialize();
  261. }
  262. if (hr == -1)
  263. {
  264. dwError = GetLastError();
  265. }
  266. cCritSect.Enter();
  267. g_fInSettingsDialog = FALSE; // allow another settings to be created.
  268. cCritSect.Leave();
  269. return hr;
  270. }
  271. //+-------------------------------------------------------------------------------
  272. // FUNCTION: AutoSyncDlgProc(HWND, UINT, WPARAM, LPARAM)
  273. //
  274. // PURPOSE: Callback dialog procedure for the property page
  275. //
  276. // PARAMETERS:
  277. // hDlg - Dialog box window handle
  278. // uMessage - current message
  279. // wParam - depends on message
  280. // lParam - depends on message
  281. //
  282. // RETURN VALUE:
  283. //
  284. // Depends on message. In general, return TRUE if we process it.
  285. //
  286. // COMMENTS:
  287. //
  288. //+-------------------------------------------------------------------------------
  289. INT_PTR CALLBACK AutoSyncDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  290. {
  291. WORD wNotifyCode = HIWORD(wParam); // notification code
  292. switch (uMessage)
  293. {
  294. case WM_INITDIALOG:
  295. {
  296. // if on NT 4.0 or Win9x hide the logoff
  297. // button
  298. //!!! warning, if you change platform logic must also change
  299. // logic for && out logoff flag in Register Interfaces.
  300. if ((VER_PLATFORM_WIN32_WINDOWS == g_OSVersionInfo.dwPlatformId)
  301. || (VER_PLATFORM_WIN32_NT == g_OSVersionInfo.dwPlatformId
  302. && g_OSVersionInfo.dwMajorVersion < 5) )
  303. {
  304. HWND hwndLogoff = GetDlgItem(hDlg,IDC_AUTOLOGOFF);
  305. if (hwndLogoff)
  306. {
  307. ShowWindow(hwndLogoff,SW_HIDE);
  308. EnableWindow(hwndLogoff,FALSE);
  309. }
  310. }
  311. if (NULL == g_pAutoSyncPage)
  312. {
  313. g_pAutoSyncPage = new CAutoSyncPage(g_hmodThisDll);
  314. }
  315. if (g_pAutoSyncPage)
  316. {
  317. g_pAutoSyncPage->SetAutoSyncHwnd(hDlg);
  318. g_pAutoSyncPage->InitializeHwnd(hDlg,SYNCTYPE_AUTOSYNC,0);
  319. return TRUE;
  320. }
  321. else
  322. {
  323. return FALSE;
  324. }
  325. }
  326. break;
  327. case WM_DESTROY:
  328. {
  329. if (g_pAutoSyncPage && g_pAutoSyncPage->m_pItemListViewAutoSync)
  330. {
  331. delete g_pAutoSyncPage->m_pItemListViewAutoSync;
  332. g_pAutoSyncPage->m_pItemListViewAutoSync = NULL;
  333. }
  334. }
  335. break;
  336. case WM_COMMAND:
  337. switch (LOWORD(wParam))
  338. {
  339. case IDC_AUTOUPDATECOMBO:
  340. {
  341. if (wNotifyCode == CBN_SELCHANGE)
  342. {
  343. HWND hwndCombo = (HWND) lParam;
  344. if (g_pAutoSyncPage)
  345. {
  346. g_pAutoSyncPage->ShowItemsOnThisConnection
  347. (hDlg,SYNCTYPE_AUTOSYNC,ComboBox_GetCurSel(hwndCombo));
  348. }
  349. }
  350. }
  351. break;
  352. case IDC_AUTOLOGON:
  353. case IDC_AUTOLOGOFF:
  354. case IDC_AUTOPROMPT_ME_FIRST:
  355. {
  356. if (wNotifyCode == BN_CLICKED)
  357. {
  358. PropSheet_Changed(g_hwndPropSheet, hDlg);
  359. HWND hwndCtrl = (HWND) lParam;
  360. g_pAutoSyncPage->SetConnectionCheck(hDlg,SYNCTYPE_AUTOSYNC,LOWORD(wParam),
  361. Button_GetCheck(hwndCtrl));
  362. }
  363. }
  364. break;
  365. default:
  366. break;
  367. }
  368. break;
  369. case WM_HELP:
  370. {
  371. LPHELPINFO lphi = (LPHELPINFO)lParam;
  372. if (lphi->iContextType == HELPINFO_WINDOW)
  373. {
  374. WinHelp ( (HWND) lphi->hItemHandle,
  375. szSyncMgrHelp,
  376. HELP_WM_HELP,
  377. (ULONG_PTR) g_aContextHelpIds);
  378. }
  379. return TRUE;
  380. }
  381. case WM_CONTEXTMENU:
  382. {
  383. WinHelp ((HWND)wParam,
  384. szSyncMgrHelp,
  385. HELP_CONTEXTMENU,
  386. (ULONG_PTR)g_aContextHelpIds);
  387. return TRUE;
  388. }
  389. case WM_NOTIFYLISTVIEWEX:
  390. if (g_pAutoSyncPage)
  391. {
  392. int idCtrl = (int) wParam;
  393. LPNMHDR pnmhdr = (LPNMHDR) lParam;
  394. if ( (IDC_AUTOUPDATELIST != idCtrl) || (NULL == g_pAutoSyncPage->m_pItemListViewAutoSync))
  395. {
  396. Assert(IDC_AUTOUPDATELIST == idCtrl);
  397. Assert(g_pAutoSyncPage->m_pItemListViewAutoSync);
  398. break;
  399. }
  400. switch (pnmhdr->code)
  401. {
  402. case LVNEX_ITEMCHECKCOUNT:
  403. {
  404. LPNMLISTVIEWEXITEMCHECKCOUNT pnmvCheckCount = (LPNMLISTVIEWEXITEMCHECKCOUNT) lParam;
  405. // pass along notification only if listView is done being initialized
  406. // since no need to set the CheckState or mark PSheet as Dirty
  407. if (g_pAutoSyncPage->m_pItemListViewAutoSyncInitialized)
  408. {
  409. g_pAutoSyncPage->SetItemCheckState(hDlg,SYNCTYPE_AUTOSYNC,
  410. pnmvCheckCount->iItemId,pnmvCheckCount->dwItemState
  411. ,pnmvCheckCount->iCheckCount);
  412. PropSheet_Changed(g_hwndPropSheet, hDlg);
  413. }
  414. break;
  415. }
  416. default:
  417. break;
  418. }
  419. }
  420. break;
  421. case WM_NOTIFY:
  422. if (g_pAutoSyncPage)
  423. {
  424. int idCtrl = (int) wParam;
  425. LPNMHDR pnmhdr = (LPNMHDR) lParam;
  426. // if notification for UpdateListPass it on.
  427. if ((IDC_AUTOUPDATELIST == idCtrl) && g_pAutoSyncPage->m_pItemListViewAutoSync)
  428. {
  429. g_pAutoSyncPage->m_pItemListViewAutoSync->OnNotify(pnmhdr);
  430. break;
  431. }
  432. }
  433. switch (((NMHDR FAR *)lParam)->code)
  434. {
  435. case PSN_SETACTIVE:
  436. break;
  437. case PSN_APPLY:
  438. //User has clicked the OK or Apply button so we'll
  439. //Save the current selections
  440. g_pAutoSyncPage->CommitAutoSyncChanges();
  441. break;
  442. default:
  443. break;
  444. }
  445. break;
  446. default:
  447. return FALSE;
  448. }
  449. return FALSE;
  450. }
  451. //+-------------------------------------------------------------------------------
  452. // FUNCTION: IdleSyncDlgProc(HWND, UINT, WPARAM, LPARAM)
  453. //
  454. // PURPOSE: Callback dialog procedure for the iDLE property page
  455. //
  456. // PARAMETERS:
  457. // hDlg - Dialog box window handle
  458. // uMessage - current message
  459. // wParam - depends on message
  460. // lParam - depends on message
  461. //
  462. // RETURN VALUE:
  463. //
  464. // Depends on message. In general, return TRUE if we process it.
  465. //
  466. // COMMENTS:
  467. //
  468. //+-------------------------------------------------------------------------------
  469. INT_PTR CALLBACK IdleSyncDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  470. {
  471. WORD wNotifyCode = HIWORD(wParam); // notification code
  472. switch (uMessage)
  473. {
  474. case WM_INITDIALOG:
  475. {
  476. /*
  477. RECT rc;
  478. HRESULT hr;
  479. hr = GetWindowRect(hDlg, &rc);
  480. hr = SetWindowPos(hDlg,
  481. NULL,
  482. ((GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2),
  483. ((GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2),
  484. 0,
  485. 0,
  486. SWP_NOSIZE | SWP_NOACTIVATE); */
  487. if (NULL == g_pAutoSyncPage)
  488. {
  489. g_pAutoSyncPage = new CAutoSyncPage(g_hmodThisDll);
  490. }
  491. if (g_pAutoSyncPage)
  492. {
  493. BOOL fConnectionsAvailable;
  494. g_pAutoSyncPage->SetIdleHwnd(hDlg);
  495. g_pAutoSyncPage->InitializeHwnd(hDlg,SYNCTYPE_IDLE,0);
  496. // there must be at least one connection or we disable
  497. // the advanced button.
  498. fConnectionsAvailable =
  499. g_pAutoSyncPage->GetNumConnections(hDlg,SYNCTYPE_IDLE)
  500. ? TRUE : FALSE;
  501. EnableWindow(GetDlgItem(hDlg,IDC_ADVANCEDIDLE),fConnectionsAvailable);
  502. return TRUE;
  503. }
  504. else
  505. {
  506. return FALSE;
  507. }
  508. }
  509. break;
  510. case WM_DESTROY:
  511. {
  512. if (g_pAutoSyncPage && g_pAutoSyncPage->m_pItemListViewIdle)
  513. {
  514. delete g_pAutoSyncPage->m_pItemListViewIdle;
  515. g_pAutoSyncPage->m_pItemListViewIdle = NULL;
  516. }
  517. // PostQuitMessage(0);
  518. // PostQuitMessage(0);
  519. }
  520. break;
  521. case WM_HELP:
  522. {
  523. LPHELPINFO lphi = (LPHELPINFO)lParam;
  524. if (lphi->iContextType == HELPINFO_WINDOW)
  525. {
  526. WinHelp ( (HWND) lphi->hItemHandle,
  527. szSyncMgrHelp,
  528. HELP_WM_HELP,
  529. (ULONG_PTR) g_aContextHelpIds);
  530. }
  531. return TRUE;
  532. }
  533. case WM_CONTEXTMENU:
  534. {
  535. WinHelp ((HWND)wParam,
  536. szSyncMgrHelp,
  537. HELP_CONTEXTMENU,
  538. (ULONG_PTR)g_aContextHelpIds);
  539. return TRUE;
  540. }
  541. case WM_COMMAND:
  542. switch (LOWORD(wParam))
  543. {
  544. case IDC_AUTOUPDATECOMBO:
  545. {
  546. if (wNotifyCode == CBN_SELCHANGE)
  547. {
  548. HWND hwndCombo = (HWND) lParam;
  549. if (g_pAutoSyncPage)
  550. {
  551. g_pAutoSyncPage->ShowItemsOnThisConnection
  552. (hDlg,SYNCTYPE_IDLE,ComboBox_GetCurSel(hwndCombo));
  553. }
  554. }
  555. }
  556. break;
  557. case IDC_IDLECHECKBOX:
  558. {
  559. if (wNotifyCode == BN_CLICKED)
  560. {
  561. PropSheet_Changed(g_hwndPropSheet, hDlg);
  562. HWND hwndCtrl = (HWND) lParam;
  563. g_pAutoSyncPage->SetConnectionCheck(hDlg,SYNCTYPE_IDLE,LOWORD(wParam),
  564. Button_GetCheck(hwndCtrl));
  565. }
  566. }
  567. break;
  568. case IDC_ADVANCEDIDLE:
  569. {
  570. if (wNotifyCode == BN_CLICKED)
  571. {
  572. // bring up the advanced idle dialog passing in the autoSyncPage class
  573. // as the owning class.
  574. DialogBoxParam(g_hmodThisDll,
  575. MAKEINTRESOURCE(IDD_ADVANCEDIDLESETTINGS),hDlg, IdleAdvancedSettingsDlgProc,
  576. (LPARAM) g_pAutoSyncPage);
  577. }
  578. }
  579. break;
  580. default:
  581. break;
  582. }
  583. break;
  584. case WM_NOTIFYLISTVIEWEX:
  585. if (g_pAutoSyncPage)
  586. {
  587. int idCtrl = (int) wParam;
  588. LPNMHDR pnmhdr = (LPNMHDR) lParam;
  589. if ( (IDC_AUTOUPDATELIST != idCtrl) || (NULL == g_pAutoSyncPage->m_pItemListViewIdle))
  590. {
  591. Assert(IDC_AUTOUPDATELIST == idCtrl);
  592. Assert(g_pAutoSyncPage->m_pItemListViewIdle);
  593. break;
  594. }
  595. switch (pnmhdr->code)
  596. {
  597. case LVNEX_ITEMCHECKCOUNT:
  598. {
  599. LPNMLISTVIEWEXITEMCHECKCOUNT pnmvCheckCount = (LPNMLISTVIEWEXITEMCHECKCOUNT) lParam;
  600. // pass along notification only if listView is done being initialized
  601. // since no need to set the CheckState or mark PSheet as Dirty
  602. if (g_pAutoSyncPage->m_fListViewIdleInitialized)
  603. {
  604. g_pAutoSyncPage->SetItemCheckState(hDlg,SYNCTYPE_IDLE,
  605. pnmvCheckCount->iItemId,pnmvCheckCount->dwItemState
  606. ,pnmvCheckCount->iCheckCount);
  607. PropSheet_Changed(g_hwndPropSheet, hDlg);
  608. }
  609. break;
  610. }
  611. default:
  612. break;
  613. }
  614. }
  615. break;
  616. case WM_NOTIFY:
  617. if (g_pAutoSyncPage)
  618. {
  619. int idCtrl = (int) wParam;
  620. LPNMHDR pnmhdr = (LPNMHDR) lParam;
  621. // if notification for UpdateListPass it on.
  622. if ((IDC_AUTOUPDATELIST == idCtrl) && g_pAutoSyncPage->m_pItemListViewIdle)
  623. {
  624. g_pAutoSyncPage->m_pItemListViewIdle->OnNotify(pnmhdr);
  625. break;
  626. }
  627. switch (((NMHDR FAR *)lParam)->code)
  628. {
  629. case PSN_SETACTIVE:
  630. break;
  631. case PSN_APPLY:
  632. //User has clicked the OK or Apply button so we'll
  633. //Save the current selections
  634. g_pAutoSyncPage->CommitIdleChanges();
  635. break;
  636. default:
  637. break;
  638. }
  639. }
  640. break;
  641. default:
  642. return FALSE;
  643. }
  644. return FALSE;
  645. }
  646. //+-------------------------------------------------------------------------------
  647. // FUNCTION: IdleAdvancedSettingsDlgProc(HWND, UINT, WPARAM, LPARAM)
  648. //
  649. // PURPOSE: Callback dialog procedure for the Advanced Idle Settings.
  650. //
  651. // PARAMETERS:
  652. // hDlg - Dialog box window handle
  653. // uMessage - current message
  654. // wParam - depends on message
  655. // lParam - depends on message
  656. //
  657. // RETURN VALUE:
  658. //
  659. // Depends on message. In general, return TRUE if we process it.
  660. //
  661. // COMMENTS:
  662. //
  663. //+-------------------------------------------------------------------------------
  664. INT_PTR CALLBACK IdleAdvancedSettingsDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  665. {
  666. switch(uMessage)
  667. {
  668. case WM_INITDIALOG:
  669. {
  670. CONNECTIONSETTINGS ConnectionSettings;
  671. Assert(g_pAutoSyncPage);
  672. if (NULL == g_pAutoSyncPage)
  673. return FALSE;
  674. UpDown_SetRange(GetDlgItem(hDlg,IDC_SPINIDLEWAITMINUTES), SPINDIALWAITMINUTES_MIN, SPINDIALWAITMINUTES_MAX);
  675. Edit_LimitText(GetDlgItem(hDlg,IDC_EDITIWAITMINUTES), 3);
  676. UpDown_SetRange(GetDlgItem(hDlg,IDC_SPINIDLEREPEATMINUTES), SPINDIALREPEATMINUTES_MIN, SPINDIALREPEATMINUTES_MAX);
  677. Edit_LimitText(GetDlgItem(hDlg,IDC_EDITIDLEREPEATMINUTES), 3);
  678. // initialize user specific preferences
  679. // if can't get shouldn't show dialog
  680. // EditText cannot accept DBCS characters on Win9x so disalbe IME for
  681. // Edit Boxes.
  682. ImmAssociateContext(GetDlgItem(hDlg,IDC_EDITIWAITMINUTES), NULL);
  683. ImmAssociateContext(GetDlgItem(hDlg,IDC_EDITIDLEREPEATMINUTES), NULL);
  684. if (NOERROR == g_pAutoSyncPage->GetAdvancedIdleSettings(&ConnectionSettings))
  685. {
  686. UpDown_SetPos(GetDlgItem(hDlg,IDC_SPINIDLEWAITMINUTES), ConnectionSettings.ulIdleWaitMinutes);
  687. UpDown_SetPos(GetDlgItem(hDlg,IDC_SPINIDLEREPEATMINUTES),ConnectionSettings.ulIdleRetryMinutes);
  688. Button_SetCheck(GetDlgItem(hDlg,IDC_CHECKREPEATESYNC),ConnectionSettings.dwRepeatSynchronization);
  689. Button_SetCheck(GetDlgItem(hDlg,IDC_CHECKRUNONBATTERIES),!(ConnectionSettings.dwRunOnBatteries));
  690. // if the repeat check state is selected then enable the edit box associated with it
  691. EnableWindow(GetDlgItem(hDlg,IDC_SPINIDLEREPEATMINUTES),ConnectionSettings.dwRepeatSynchronization);
  692. EnableWindow(GetDlgItem(hDlg,IDC_EDITIDLEREPEATMINUTES),ConnectionSettings.dwRepeatSynchronization);
  693. EnableWindow(GetDlgItem(hDlg,IDC_ADVANCEDIDLEMINUTESTEXT2),ConnectionSettings.dwRepeatSynchronization);
  694. }
  695. ShowWindow(hDlg,SW_SHOW);
  696. return TRUE;
  697. break;
  698. }
  699. case WM_HELP:
  700. {
  701. LPHELPINFO lphi = (LPHELPINFO)lParam;
  702. if (lphi->iContextType == HELPINFO_WINDOW)
  703. {
  704. WinHelp ( (HWND) lphi->hItemHandle,
  705. szSyncMgrHelp,
  706. HELP_WM_HELP,
  707. (ULONG_PTR) g_aContextHelpIds);
  708. }
  709. return TRUE;
  710. }
  711. case WM_CONTEXTMENU:
  712. {
  713. WinHelp ((HWND)wParam,
  714. szSyncMgrHelp,
  715. HELP_CONTEXTMENU,
  716. (ULONG_PTR)g_aContextHelpIds);
  717. return TRUE;
  718. }
  719. case WM_COMMAND:
  720. switch (LOWORD(wParam))
  721. {
  722. case IDCANCEL:
  723. EndDialog(hDlg,FALSE);
  724. break;
  725. case IDOK:
  726. if (g_pAutoSyncPage)
  727. {
  728. CONNECTIONSETTINGS ConnectionSettings;
  729. if (g_pAutoSyncPage)
  730. {
  731. ConnectionSettings.ulIdleWaitMinutes = GetDlgItemInt(hDlg, IDC_EDITIWAITMINUTES, NULL, FALSE);
  732. ConnectionSettings.ulIdleRetryMinutes = GetDlgItemInt(hDlg, IDC_EDITIDLEREPEATMINUTES, NULL, FALSE);
  733. ConnectionSettings.dwRepeatSynchronization = Button_GetCheck(GetDlgItem(hDlg,IDC_CHECKREPEATESYNC));
  734. ConnectionSettings.dwRunOnBatteries = (!Button_GetCheck(GetDlgItem(hDlg,IDC_CHECKRUNONBATTERIES)));
  735. g_pAutoSyncPage->SetAdvancedIdleSettings(&ConnectionSettings);
  736. }
  737. }
  738. EndDialog(hDlg,FALSE);
  739. break;
  740. case IDC_EDITIWAITMINUTES:
  741. {
  742. WORD wNotifyCode = HIWORD(wParam);
  743. INT iNewPos;
  744. //
  745. // If the user just pasted non-numeric text or an illegal numeric
  746. // value, overwrite it and complain.
  747. //
  748. if (EN_KILLFOCUS == wNotifyCode)
  749. {
  750. iNewPos = GetDlgItemInt(hDlg, IDC_EDITIWAITMINUTES, NULL, FALSE);
  751. if (iNewPos < SPINDIALWAITMINUTES_MIN || iNewPos > SPINDIALWAITMINUTES_MAX)
  752. {
  753. HWND hUD = GetDlgItem(hDlg,IDC_SPINIDLEWAITMINUTES);
  754. if (iNewPos < SPINDIALWAITMINUTES_MIN)
  755. {
  756. UpDown_SetPos(hUD, SPINDIALWAITMINUTES_MIN);
  757. }
  758. else
  759. {
  760. UpDown_SetPos(hUD,SPINDIALWAITMINUTES_MAX);
  761. }
  762. }
  763. }
  764. break;
  765. }
  766. case IDC_EDITIDLEREPEATMINUTES:
  767. {
  768. WORD wNotifyCode = HIWORD(wParam);
  769. INT iNewPos;
  770. //
  771. // If the user just pasted non-numeric text or an illegal numeric
  772. // value, overwrite it and complain.
  773. //
  774. // Review, redundant code with other spin control.
  775. if (EN_KILLFOCUS == wNotifyCode)
  776. {
  777. iNewPos = GetDlgItemInt(hDlg, IDC_EDITIDLEREPEATMINUTES, NULL, FALSE);
  778. if (iNewPos < SPINDIALREPEATMINUTES_MIN || iNewPos > SPINDIALREPEATMINUTES_MAX)
  779. {
  780. HWND hUD = GetDlgItem(hDlg,IDC_SPINIDLEREPEATMINUTES);
  781. if (iNewPos < SPINDIALREPEATMINUTES_MIN)
  782. {
  783. UpDown_SetPos(hUD, SPINDIALREPEATMINUTES_MIN);
  784. }
  785. else
  786. {
  787. UpDown_SetPos(hUD,SPINDIALREPEATMINUTES_MAX);
  788. }
  789. }
  790. }
  791. break;
  792. }
  793. case IDC_CHECKREPEATESYNC:
  794. {
  795. WORD wNotifyCode = HIWORD(wParam);
  796. // if use clicked the repeat check box set set state of the other
  797. // items associated with it.
  798. if (BN_CLICKED == wNotifyCode)
  799. {
  800. BOOL fEnableState = Button_GetCheck(GetDlgItem(hDlg,IDC_CHECKREPEATESYNC));
  801. // if the repeat check state is selected then enable the edit box associated with it
  802. EnableWindow(GetDlgItem(hDlg,IDC_SPINIDLEREPEATMINUTES),fEnableState);
  803. EnableWindow(GetDlgItem(hDlg,IDC_EDITIDLEREPEATMINUTES),fEnableState);
  804. EnableWindow(GetDlgItem(hDlg,IDC_ADVANCEDIDLEMINUTESTEXT2),fEnableState);
  805. }
  806. break;
  807. }
  808. default:
  809. break;
  810. }
  811. default:
  812. break;
  813. }
  814. return FALSE;
  815. }
  816. //+-------------------------------------------------------------------------------
  817. // FUNCTION: SchedSyncDlgProc(HWND, UINT, WPARAM, LPARAM)
  818. //
  819. // PURPOSE: Callback dialog procedure for the property page
  820. //
  821. // PARAMETERS:
  822. // hDlg - Dialog box window handle
  823. // uMessage - current message
  824. // wParam - depends on message
  825. // lParam - depends on message
  826. //
  827. // RETURN VALUE:
  828. //
  829. // Depends on message. In general, return TRUE if we process it.
  830. //
  831. // COMMENTS:
  832. //
  833. //--------------------------------------------------------------------------------
  834. INT_PTR CALLBACK SchedSyncDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
  835. {
  836. WORD wNotifyCode = HIWORD(wParam); // notification code
  837. BOOL bResult = FALSE;
  838. switch (uMessage)
  839. {
  840. case WM_INITDIALOG:
  841. {
  842. g_pSchedSyncPage = new CSchedSyncPage(g_hmodThisDll, hDlg);
  843. if (g_pSchedSyncPage)
  844. {
  845. bResult = g_pSchedSyncPage->Initialize();
  846. }
  847. }
  848. break;
  849. case WM_DESTROY:
  850. {
  851. g_pSchedSyncPage->FreeAllSchedules();
  852. }
  853. break;
  854. case WM_HELP:
  855. {
  856. LPHELPINFO lphi = (LPHELPINFO)lParam;
  857. if (lphi->iContextType == HELPINFO_WINDOW)
  858. {
  859. WinHelp ( (HWND) lphi->hItemHandle,
  860. szSyncMgrHelp,
  861. HELP_WM_HELP,
  862. (ULONG_PTR) g_aContextHelpIds);
  863. }
  864. bResult = TRUE;
  865. }
  866. break;
  867. case WM_CONTEXTMENU:
  868. {
  869. WinHelp ((HWND)wParam,
  870. szSyncMgrHelp,
  871. HELP_CONTEXTMENU,
  872. (ULONG_PTR)g_aContextHelpIds);
  873. bResult = TRUE;
  874. }
  875. break;
  876. case WM_NOTIFY:
  877. switch (((NMHDR FAR *)lParam)->code)
  878. {
  879. case PSN_SETACTIVE:
  880. break;
  881. case PSN_APPLY:
  882. //User has clicked the OK or Apply button so we'll
  883. //update the icon information in the .GAK file
  884. break;
  885. default:
  886. bResult = g_pSchedSyncPage->OnNotify(hDlg,(int)wParam,(LPNMHDR)lParam);
  887. break;
  888. }
  889. break;
  890. case WM_COMMAND:
  891. bResult = g_pSchedSyncPage->OnCommand(hDlg, HIWORD(wParam), LOWORD(wParam),
  892. (HWND)lParam);
  893. break;
  894. default:
  895. break;
  896. }
  897. return bResult;
  898. }
  899. //+-------------------------------------------------------------------------------
  900. //
  901. // FUNCTION: CALLBACK PropSheetProc( HWND hwndDlg, UINT uMsg, LPARAM lParam);
  902. //
  903. // PURPOSE: Callback dialog init procedure the settings property dialog
  904. //
  905. // PARAMETERS:
  906. // hwndDlg - Dialog box window handle
  907. // uMsg - current message
  908. // lParam - depends on message
  909. //
  910. //--------------------------------------------------------------------------------
  911. int CALLBACK PropSheetProc( HWND hwndDlg, UINT uMsg, LPARAM lParam)
  912. {
  913. switch(uMsg)
  914. {
  915. case PSCB_INITIALIZED:
  916. g_hwndPropSheet = hwndDlg;
  917. return TRUE;
  918. break;
  919. default:
  920. return TRUE;
  921. }
  922. return TRUE;
  923. }