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.

694 lines
25 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: options.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _INC_CSCUI_OPTIONS_H
  11. #define _INC_CSCUI_OPTIONS_H
  12. ///////////////////////////////////////////////////////////////////////////////
  13. /* File: options.h
  14. Description:
  15. Revision History:
  16. Date Description Programmer
  17. -------- --------------------------------------------------- ----------
  18. 04/15/98 Initial creation. BrianAu
  19. */
  20. ///////////////////////////////////////////////////////////////////////////////
  21. #ifndef _WINDOWS_
  22. # include <windows.h>
  23. #endif
  24. #ifndef _INC_CSCVIEW_CONFIG_H
  25. # include "config.h"
  26. #endif
  27. #ifndef _INC_CSCUI_UIHELP_H
  28. # include "uihelp.h"
  29. #endif
  30. #ifndef _INC_MATH
  31. # include <math.h>
  32. #endif
  33. #ifndef _INC_CSCUI_PURGE_H
  34. # include "purge.h"
  35. #endif
  36. #include "resource.h"
  37. //
  38. // The "Advanced" dialog invoked from the "Advanced" button on the
  39. // "Offline Files" prop page.
  40. //
  41. class CAdvOptDlg
  42. {
  43. public:
  44. enum
  45. {
  46. //
  47. // Listview subitem IDs.
  48. //
  49. iLVSUBITEM_SERVER = 0,
  50. iLVSUBITEM_ACTION = 1
  51. };
  52. CAdvOptDlg(HINSTANCE hInstance,
  53. HWND hwndParent)
  54. : m_hInstance(hInstance),
  55. m_hwndParent(hwndParent),
  56. m_hwndDlg(NULL),
  57. m_hwndLV(NULL),
  58. m_iLastColSorted(-1),
  59. m_bSortAscending(true),
  60. m_bNoConfigGoOfflineAction(false) { }
  61. int Run(void);
  62. protected:
  63. BOOL OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lInitParam);
  64. BOOL OnNotify(HWND hDlg, int idCtl, LPNMHDR pnmhdr);
  65. BOOL OnCommand(HWND hDlg, WORD wNotifyCode, WORD wID, HWND hwndCtl);
  66. BOOL OnDestroy(HWND hDlg);
  67. BOOL OnContextMenu(WPARAM wParam, LPARAM lParam);
  68. BOOL OnHelp(HWND hDlg, LPHELPINFO pHelpInfo);
  69. private:
  70. //
  71. // Structure to associate a radio button with an offline action code.
  72. //
  73. struct CtlActions
  74. {
  75. UINT idRbn;
  76. CConfig::OfflineAction action;
  77. };
  78. //
  79. // Class to describe the state of controls in the dialog. Used to
  80. // determine if user has changed anything.
  81. //
  82. class PgState
  83. {
  84. public:
  85. PgState(void)
  86. : m_DefaultGoOfflineAction(CConfig::eGoOfflineSilent),
  87. m_hdpaCustomGoOfflineActions(DPA_Create(4)) { }
  88. ~PgState(void);
  89. void SetDefGoOfflineAction(CConfig::OfflineAction action)
  90. { m_DefaultGoOfflineAction = action; }
  91. CConfig::OfflineAction GetDefGoOfflineAction(void) const
  92. { return m_DefaultGoOfflineAction; }
  93. void SetCustomGoOfflineActions(HWND hwndLV);
  94. HDPA GetCustomGoOfflineActions(void) const
  95. { return m_hdpaCustomGoOfflineActions; }
  96. bool operator == (const PgState& rhs) const;
  97. bool operator != (const PgState& rhs) const
  98. { return !(*this == rhs); }
  99. private:
  100. CConfig::OfflineAction m_DefaultGoOfflineAction;
  101. HDPA m_hdpaCustomGoOfflineActions;
  102. };
  103. HINSTANCE m_hInstance;
  104. HWND m_hwndParent;
  105. HWND m_hwndDlg;
  106. HWND m_hwndLV;
  107. int m_iLastColSorted;
  108. PgState m_state; // State on creation.
  109. bool m_bSortAscending;
  110. bool m_bNoConfigGoOfflineAction;
  111. static const CtlActions m_rgCtlActions[CConfig::eNumOfflineActions];
  112. static const DWORD m_rgHelpIDs[];
  113. static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  114. void ApplySettings(void);
  115. void EnableCtls(HWND hwnd);
  116. void CreateListColumns(HWND hwndList);
  117. void OnLVN_GetDispInfo(LV_DISPINFO *plvdi);
  118. void OnLVN_ColumnClick(NM_LISTVIEW *pnmlv);
  119. void OnLVN_ItemChanged(NM_LISTVIEW *pnmlv);
  120. void OnLVN_KeyDown(NMLVKEYDOWN *plvkd);
  121. void OnContextMenuItemSelected(int idMenuItem);
  122. static int CALLBACK CompareLVItems(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
  123. void GetPageState(PgState *pps);
  124. CConfig::OfflineAction GetCurrentGoOfflineAction(void) const;
  125. void AddCustomGoOfflineAction(LPCTSTR pszServer, CConfig::OfflineAction action);
  126. void ReplaceCustomGoOfflineAction(CConfig::CustomGOA *pGOA, int iItem, CConfig::OfflineAction action);
  127. void OnAddCustomGoOfflineAction(void);
  128. void OnEditCustomGoOfflineAction(void);
  129. void OnDeleteCustomGoOfflineAction(void);
  130. int CountSelectedListviewItems(int *pcSetByPolicy);
  131. void DeleteSelectedListviewItems(void);
  132. void SetSelectedListviewItemsAction(CConfig::OfflineAction action);
  133. void FocusOnSomethingInListview(void);
  134. int GetFirstSelectedLVItemRect(RECT *prc);
  135. bool IsCustomActionListviewEnabled(void) const
  136. { return boolify(IsWindowEnabled(GetDlgItem(m_hwndDlg, IDC_GRP_CUSTGOOFFLINE))); }
  137. static DWORD CheckNetServer(LPCTSTR pszServer);
  138. static int AddGOAToListView(HWND hwndLV, int iItem, const CConfig::CustomGOA& goa);
  139. static CConfig::CustomGOA *FindGOAInListView(HWND hwndLV, LPCTSTR pszServer, int *piItem);
  140. static CConfig::CustomGOA *GetListviewObject(HWND hwndLV, int iItem);
  141. //
  142. // PgState calls GetListviewObject.
  143. //
  144. friend void PgState::SetCustomGoOfflineActions(HWND);
  145. };
  146. //
  147. // The "Offline Files" property sheet page.
  148. //
  149. class COfflineFilesPage
  150. {
  151. public:
  152. COfflineFilesPage(HINSTANCE hInstance, LPUNKNOWN pUnkOuter)
  153. : m_hInstance(hInstance),
  154. m_hwndDlg(NULL),
  155. m_pUnkOuter(pUnkOuter),
  156. m_hwndSlider(NULL),
  157. m_hwndEncryptTooltip(NULL),
  158. m_pfnOldPropSheetWndProc(NULL),
  159. m_pfnOldEncryptionTooltipWndProc(NULL),
  160. m_bUserHasMachineAccess(false),
  161. m_bCscVolSupportsEncryption(false),
  162. m_bApplyingSettings(false),
  163. m_bFirstActivate(true),
  164. m_iSliderMax(0),
  165. m_llAvailableDiskSpace(0) { }
  166. UINT GetDlgTemplateID(void) const
  167. { return IDD_CSC_OPTIONS; }
  168. LPFNPSPCALLBACK GetCallbackFuncPtr(void) const
  169. { return PageCallback; }
  170. DLGPROC GetDlgProcPtr(void) const
  171. { return DlgProc; }
  172. //
  173. // This is called by the "Advanced" page to determine if controls can
  174. // be enabled or not.
  175. //
  176. bool IsCscEnabledChecked(void) const
  177. { return m_hwndDlg && BST_CHECKED == IsDlgButtonChecked(m_hwndDlg, IDC_CBX_ENABLE_CSC); }
  178. protected:
  179. BOOL OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lInitParam);
  180. BOOL OnNotify(HWND hDlg, int idCtl, LPNMHDR pnmhdr);
  181. BOOL OnCommand(HWND hDlg, WORD wNotifyCode, WORD wID, HWND hwndCtl);
  182. BOOL OnDestroy(HWND hDlg);
  183. BOOL OnContextMenu(HWND hwndItem, int xPos, int yPos);
  184. BOOL ApplySettings(HWND hDlg, bool bPropSheetClosing);
  185. BOOL OnHelp(HWND hDlg, LPHELPINFO pHelpInfo);
  186. BOOL OnSettingChange(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  187. private:
  188. class PgState
  189. {
  190. public:
  191. PgState(void)
  192. : m_bCscEnabled(false),
  193. m_bFullSyncAtLogoff(false),
  194. m_bFullSyncAtLogon(false),
  195. m_bLinkOnDesktop(false),
  196. m_bReminders(false),
  197. m_iEncrypted(BST_UNCHECKED),
  198. m_iReminderFreq(0),
  199. m_iSliderPos(0) { }
  200. void SetCscEnabled(bool bCscEnabled)
  201. { m_bCscEnabled = bCscEnabled; }
  202. bool GetCscEnabled(void) const
  203. { return m_bCscEnabled; }
  204. void SetFullSyncAtLogon(bool bFullSync)
  205. { m_bFullSyncAtLogon = bFullSync; }
  206. bool GetFullSyncAtLogon(void) const
  207. { return m_bFullSyncAtLogon; }
  208. void SetFullSyncAtLogoff(bool bFullSync)
  209. { m_bFullSyncAtLogoff = bFullSync; }
  210. bool GetFullSyncAtLogoff(void) const
  211. { return m_bFullSyncAtLogoff; }
  212. void SetEncrypted(int iEncrypted)
  213. { m_iEncrypted = iEncrypted; }
  214. int GetEncrypted(void) const
  215. { return m_iEncrypted; }
  216. void SetSliderPos(int iSliderPos)
  217. { m_iSliderPos = iSliderPos; }
  218. int GetSliderPos(void) const
  219. { return m_iSliderPos; }
  220. void SetRemindersEnabled(bool bEnabled)
  221. { m_bReminders = bEnabled; }
  222. bool GetRemindersEnabled(void) const
  223. { return m_bReminders; }
  224. void SetReminderFreq(int iMinutes)
  225. { m_iReminderFreq = iMinutes; }
  226. int GetReminderFreq(void) const
  227. { return m_iReminderFreq; }
  228. void SetLinkOnDesktop(bool bEnabled)
  229. { m_bLinkOnDesktop = bEnabled; }
  230. bool GetLinkOnDesktop(void) const
  231. { return m_bLinkOnDesktop; }
  232. bool operator == (const PgState& rhs) const
  233. { return (m_bCscEnabled == rhs.m_bCscEnabled &&
  234. m_bFullSyncAtLogoff == rhs.m_bFullSyncAtLogoff &&
  235. m_bFullSyncAtLogon == rhs.m_bFullSyncAtLogon &&
  236. m_bLinkOnDesktop == rhs.m_bLinkOnDesktop &&
  237. m_iEncrypted == rhs.m_iEncrypted &&
  238. m_iSliderPos == rhs.m_iSliderPos &&
  239. m_bReminders == rhs.m_bReminders &&
  240. m_iReminderFreq == rhs.m_iReminderFreq); }
  241. bool operator != (const PgState& rhs) const
  242. { return !(*this == rhs); }
  243. private:
  244. bool m_bCscEnabled;
  245. bool m_bFullSyncAtLogon;
  246. bool m_bFullSyncAtLogoff;
  247. bool m_bLinkOnDesktop;
  248. bool m_bReminders;
  249. int m_iEncrypted; // BST_CHECKED, BST_UNCHECKED, BST_INDETERMINATE
  250. int m_iSliderPos;
  251. int m_iReminderFreq;
  252. };
  253. class CConfigItems
  254. {
  255. public:
  256. CConfigItems(void) { ZeroMemory(m_rgItems, sizeof(m_rgItems)); }
  257. void Load(void);
  258. CConfig::SyncAction SyncAtLogoff(void) const
  259. { return CConfig::SyncAction(m_rgItems[iCFG_SYNCATLOGOFF].dwValue); }
  260. CConfig::SyncAction SyncAtLogon(void) const
  261. { return CConfig::SyncAction(m_rgItems[iCFG_SYNCATLOGON].dwValue); }
  262. bool NoConfigCache(void) const
  263. { return boolify(m_rgItems[iCFG_NOCONFIGCACHE].dwValue); }
  264. bool NoConfigSyncAtLogoff(void) const
  265. { return m_rgItems[iCFG_SYNCATLOGOFF].bSetByPolicy; }
  266. bool NoConfigSyncAtLogon(void) const
  267. { return m_rgItems[iCFG_SYNCATLOGON].bSetByPolicy; }
  268. bool NoReminders(void) const
  269. { return boolify(m_rgItems[iCFG_NOREMINDERS].dwValue); }
  270. bool NoConfigReminders(void) const
  271. { return m_rgItems[iCFG_NOREMINDERS].bSetByPolicy; }
  272. bool NoConfigCacheSize(void) const
  273. { return m_rgItems[iCFG_DEFCACHESIZE].bSetByPolicy; }
  274. bool NoCacheViewer(void) const
  275. { return boolify(m_rgItems[iCFG_NOCACHEVIEWER].dwValue); }
  276. bool NoConfigCscEnabled(void) const
  277. { return boolify(m_rgItems[iCFG_CSCENABLED].bSetByPolicy); }
  278. bool NoConfigReminderFreqMinutes(void) const
  279. { return boolify(m_rgItems[iCFG_REMINDERFREQMINUTES].bSetByPolicy); }
  280. int ReminderFreqMinutes(void) const
  281. { return int(m_rgItems[iCFG_REMINDERFREQMINUTES].dwValue); }
  282. bool EncryptCache(void) const
  283. { return boolify(m_rgItems[iCFG_ENCRYPTCACHE].dwValue); }
  284. bool NoConfigEncryptCache(void) const
  285. { return boolify(m_rgItems[iCFG_ENCRYPTCACHE].bSetByPolicy); }
  286. private:
  287. struct ConfigItem
  288. {
  289. DWORD dwValue;
  290. bool bSetByPolicy;
  291. };
  292. enum eConfigItems
  293. {
  294. iCFG_NOCONFIGCACHE,
  295. iCFG_SYNCATLOGOFF,
  296. iCFG_SYNCATLOGON,
  297. iCFG_NOREMINDERS,
  298. iCFG_DEFCACHESIZE,
  299. iCFG_NOCACHEVIEWER,
  300. iCFG_CSCENABLED,
  301. iCFG_REMINDERFREQMINUTES,
  302. iCFG_ENCRYPTCACHE,
  303. MAX_CONFIG_ITEMS
  304. };
  305. ConfigItem m_rgItems[MAX_CONFIG_ITEMS];
  306. };
  307. HINSTANCE m_hInstance;
  308. HWND m_hwndDlg;
  309. LPUNKNOWN m_pUnkOuter;
  310. HWND m_hwndSlider;
  311. HWND m_hwndEncryptTooltip;
  312. int m_iSliderMax;
  313. LONGLONG m_llAvailableDiskSpace;
  314. PgState m_state;
  315. CConfigItems m_config;
  316. TCHAR m_szEncryptTooltipBody[MAX_PATH];
  317. WNDPROC m_pfnOldPropSheetWndProc;
  318. WNDPROC m_pfnOldEncryptionTooltipWndProc;
  319. bool m_bUserHasMachineAccess;
  320. bool m_bCscVolSupportsEncryption;
  321. bool m_bApplyingSettings;
  322. bool m_bFirstActivate;
  323. static const DWORD m_rgHelpIDs[];
  324. static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  325. static UINT CALLBACK PageCallback(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp);
  326. static BOOL CALLBACK PurgeCacheCallback(CCachePurger *pPurger);
  327. static DWORD CALLBACK EncryptDecryptCallback(LPCWSTR lpszName, DWORD dwStatus, DWORD dwHintFlags,
  328. DWORD dwPinCount, WIN32_FIND_DATAW *pFind32, DWORD dwReason,
  329. DWORD dwParam1, DWORD dwParam2, DWORD_PTR dwContext);
  330. static LRESULT CALLBACK PropSheetSubclassWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  331. static LRESULT CALLBACK EncryptionTooltipSubclassWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  332. void OnDeleteCache(void);
  333. void OnFormatCache(void);
  334. void EnableCtls(HWND hwnd);
  335. void InitSlider(HWND hwndDlg, LONGLONG llMaxDiskSpace, LONGLONG llUsedDiskSpace);
  336. void OnHScroll(HWND hwndDlg, HWND hwndCtl, int iCode, int iPos);
  337. void SetCacheSizeDisplay(HWND hwndCtl, int iThumbPos);
  338. void EncryptOrDecryptCache(bool bEncrypt, bool bPropSheetClosing);
  339. void CreateEncryptionTooltip(void);
  340. void ShowEncryptionTooltip(bool bEncrypted);
  341. void HideEncryptionTooltip(void);
  342. void TrackEncryptionTooltip(void);
  343. void UpdateEncryptionCheckbox(void);
  344. void UpdateEncryptionTooltipBalloon(void);
  345. void UpdateEncryptionCheckboxOrBalloon(bool bCheckbox);
  346. void OnTTN_GetDispInfo(LPNMTTDISPINFO pttdi);
  347. double Fx(double x);
  348. double Fy(double y);
  349. double Rx(double x);
  350. LONGLONG DiskSpaceAtThumb(int t);
  351. int ThumbAtPctDiskSpace(double pct);
  352. void GetPageState(PgState *pps);
  353. void HandlePageStateChange(void);
  354. bool IsLinkOnDesktop(LPTSTR pszPathOut = NULL, UINT cchPathOut = 0);
  355. bool EnableOrDisableCsc(bool bEnable, bool *pbReboot, DWORD *pdwError);
  356. bool DisableForTerminalServer(void);
  357. HRESULT _ApplyEnabledSetting(RegKey& keyLM, RegKey& keyCU, const PgState& pgstNow, bool *pbUpdateSysTrayUI);
  358. HRESULT _ApplySyncAtLogoffSetting(RegKey& keyLM, RegKey& keyCU, const PgState& pgstNow);
  359. HRESULT _ApplySyncAtLogonSetting(RegKey& keyLM, RegKey& keyCU, const PgState& pgstNow);
  360. HRESULT _ApplyReminderSettings(RegKey& keyLM, RegKey& keyCU, const PgState& pgstNow);
  361. HRESULT _ApplyFolderLinkSetting(RegKey& keyLM, RegKey& keyCU, const PgState& pgstNow);
  362. HRESULT _ApplyCacheSizeSetting(RegKey& keyLM, RegKey& keyCU, const PgState& pgstNow);
  363. HRESULT _ApplyEncryptionSetting(RegKey& keyLM, RegKey& keyCU, const PgState& pgstNow, bool bPropSheetClosing, bool *pbPerformed);
  364. };
  365. class COfflineFilesSheet
  366. {
  367. public:
  368. static DWORD CreateAndRun(HINSTANCE hInstance,
  369. HWND hwndParent,
  370. LONG *pDllRefCount,
  371. BOOL bAsync=TRUE);
  372. private:
  373. //
  374. // Increase this if more pages are required.
  375. // Currently, we only need the "Offline Files" page.
  376. //
  377. enum { MAXPAGES = 1 };
  378. HINSTANCE m_hInstance;
  379. HWND m_hwndParent;
  380. LONG *m_pDllRefCount;
  381. //
  382. // Trivial class for passing parameters to share dialog thread proc.
  383. //
  384. class ThreadParams
  385. {
  386. public:
  387. ThreadParams(HWND hwndParent, LONG *pDllRefCount)
  388. : m_hwndParent(hwndParent),
  389. m_hInstance(NULL),
  390. m_pDllRefCount(pDllRefCount) { }
  391. HWND m_hwndParent;
  392. HINSTANCE m_hInstance;
  393. LONG *m_pDllRefCount;
  394. void SetModuleHandle(HINSTANCE hInstance)
  395. { m_hInstance = hInstance; }
  396. };
  397. COfflineFilesSheet(HINSTANCE hInstance,
  398. LONG *pDllRefCount,
  399. HWND hwndParent);
  400. ~COfflineFilesSheet(void);
  401. DWORD Run(void);
  402. static UINT WINAPI ThreadProc(LPVOID pvParam);
  403. static BOOL CALLBACK AddPropSheetPage(HPROPSHEETPAGE hpage, LPARAM lParam);
  404. };
  405. class CscOptPropSheetExt : public IShellExtInit, IShellPropSheetExt
  406. {
  407. public:
  408. CscOptPropSheetExt(HINSTANCE hInstance, LONG *pDllRefCnt);
  409. ~CscOptPropSheetExt(void);
  410. //
  411. // IUnknown
  412. //
  413. STDMETHODIMP QueryInterface(REFIID, void **);
  414. STDMETHODIMP_(ULONG) AddRef(void);
  415. STDMETHODIMP_(ULONG) Release(void);
  416. //
  417. // IShellExtInit method
  418. //
  419. STDMETHODIMP Initialize(LPCITEMIDLIST, LPDATAOBJECT, HKEY);
  420. //
  421. // IShellPropSheetExt
  422. //
  423. STDMETHODIMP AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam);
  424. STDMETHODIMP ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
  425. { return E_NOTIMPL; }
  426. //
  427. // Change this if you add or remove any prop pages from this prop sheet ext.
  428. //
  429. enum { NUMPAGES = 2 };
  430. private:
  431. LONG m_cRef;
  432. HINSTANCE m_hInstance;
  433. LONG *m_pDllRefCnt;
  434. COfflineFilesPage *m_pOfflineFoldersPg;
  435. HRESULT AddPage(LPFNADDPROPSHEETPAGE lpfnAddPage,
  436. LPARAM lParam,
  437. const COfflineFilesPage& pg,
  438. HPROPSHEETPAGE *phPage);
  439. };
  440. class CustomGOAAddDlg
  441. {
  442. public:
  443. CustomGOAAddDlg(HINSTANCE hInstance,
  444. HWND hwndParent,
  445. LPTSTR pszServer,
  446. UINT cchServer,
  447. CConfig::OfflineAction *pAction);
  448. int Run(void);
  449. private:
  450. //
  451. // Structure to associate a radio button with an offline action code.
  452. //
  453. struct CtlActions
  454. {
  455. UINT idRbn;
  456. CConfig::OfflineAction action;
  457. };
  458. HINSTANCE m_hInstance;
  459. HWND m_hwndParent;
  460. HWND m_hwndDlg;
  461. HWND m_hwndEdit;
  462. LPTSTR m_pszServer; // Output.
  463. UINT m_cchServer;
  464. CConfig::OfflineAction *m_pAction;
  465. static const CtlActions m_rgCtlActions[CConfig::eNumOfflineActions];
  466. static const DWORD m_rgHelpIDs[];
  467. static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  468. BOOL OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lInitParam);
  469. BOOL OnCommand(HWND hDlg, WORD wNotifyCode, WORD wID, HWND hwndCtl);
  470. BOOL OnDestroy(HWND hDlg);
  471. BOOL OnHelp(HWND hDlg, LPHELPINFO pHelpInfo);
  472. BOOL OnContextMenu(HWND hwndItem, int xPos, int yPos);
  473. void BrowseForServer(HWND hDlg, LPTSTR pszServer, UINT cchServer);
  474. void GetActionInfo(LPTSTR pszServer, UINT cchServer, CConfig::OfflineAction *pAction);
  475. bool CheckServerNameEntered(void);
  476. void GetEnteredServerName(LPTSTR pszServer, UINT cchServer, bool bTrimLeadingJunk);
  477. };
  478. class CustomGOAEditDlg
  479. {
  480. public:
  481. CustomGOAEditDlg(HINSTANCE hInstance,
  482. HWND hwndParent,
  483. LPCTSTR pszServer,
  484. CConfig::OfflineAction *pAction);
  485. int Run(void);
  486. private:
  487. //
  488. // Structure to associate a radio button with an offline action code.
  489. //
  490. struct CtlActions
  491. {
  492. UINT idRbn;
  493. CConfig::OfflineAction action;
  494. };
  495. HINSTANCE m_hInstance;
  496. HWND m_hwndParent;
  497. HWND m_hwndDlg;
  498. TCHAR m_szServer[MAX_PATH];
  499. CConfig::OfflineAction *m_pAction;
  500. static const CtlActions m_rgCtlActions[CConfig::eNumOfflineActions];
  501. static const DWORD m_rgHelpIDs[];
  502. static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  503. BOOL OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lInitParam);
  504. BOOL OnCommand(HWND hDlg, WORD wNotifyCode, WORD wID, HWND hwndCtl);
  505. BOOL OnDestroy(HWND hDlg);
  506. BOOL OnHelp(HWND hDlg, LPHELPINFO pHelpInfo);
  507. BOOL OnContextMenu(HWND hwndItem, int xPos, int yPos);
  508. void GetActionInfo(CConfig::OfflineAction *pAction);
  509. };
  510. //-----------------------------------------------------------------------------
  511. // Inline functions.
  512. //-----------------------------------------------------------------------------
  513. //
  514. // This is the "gain" function for the slider and resulting value.
  515. // Pass in a true position of the slider thumb and you get back
  516. // a scaled value for the thumb. To change the gain, change
  517. // this function. Remember to change Fy() also.
  518. //
  519. inline double
  520. COfflineFilesPage::Fx(
  521. double x
  522. )
  523. {
  524. return (x * x) / 2.0;
  525. }
  526. //
  527. // This is the "gain" function for the slider solved for 'y'.
  528. // Pass in a virtual position for the thumb and you get back
  529. // a true thumb position.
  530. //
  531. inline double
  532. COfflineFilesPage::Fy(
  533. double y
  534. )
  535. {
  536. return sqrt(2.0 * y);
  537. }
  538. //
  539. // Ratio used to calculate the disk space value for a given
  540. // true thumb position. Give it a true thumb position between
  541. // 0 and 100 and it will return a number between 0.0 and 1.0 that
  542. // can be used to find the disk space.
  543. //
  544. // DiskSpace = DiskSpaceMax * Rx(thumb)
  545. //
  546. inline double
  547. COfflineFilesPage::Rx(
  548. double x
  549. )
  550. {
  551. double denominator = Fx(m_iSliderMax);
  552. if (0.00001 < denominator)
  553. return Fx(x) / denominator;
  554. else
  555. return 1.0;
  556. }
  557. //
  558. // Calculates the disk space value at a particular position of the
  559. // slider thumb for values of 't' between 0 and 100.
  560. //
  561. inline LONGLONG
  562. COfflineFilesPage::DiskSpaceAtThumb(
  563. int t
  564. )
  565. {
  566. return LONGLONG(double(m_llAvailableDiskSpace) * Rx(t));
  567. }
  568. //
  569. // Calculates the true thumb position for a given disk space
  570. // percent value between 0.0 and 1.0.
  571. // The expression breaks down as follows:
  572. //
  573. // double MaxVirtualThumb = Fx(m_iSliderMax);
  574. // double VirtualThumb = MaxVirtualThumb * pct;
  575. // double TrueThumb = Fy(VirtualThumb);
  576. //
  577. // return round(TrueThumb); // "round" used for illustration only.
  578. //
  579. inline int
  580. COfflineFilesPage::ThumbAtPctDiskSpace(
  581. double pct
  582. )
  583. {
  584. double t = Fy(Fx(m_iSliderMax) * pct);
  585. double ft = floor(t);
  586. if (0.5 < t - ft)
  587. {
  588. //
  589. // Since the thumb position must be a whole number,
  590. // round up if necessary. Typecast from double to int
  591. // merely truncates at the decimal point.
  592. //
  593. ft += 1.0;
  594. }
  595. return int(ft);
  596. }
  597. #endif // _INC_CSCUI_OPTIONS_H