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.

306 lines
8.0 KiB

  1. //--------------------------------------------------------------------------;
  2. //
  3. // File: titleopt.cpp
  4. //
  5. // Copyright (c) 1998 Microsoft Corporation. All rights reserved
  6. //
  7. //--------------------------------------------------------------------------;
  8. #include "precomp.h"
  9. #include "cdopti.h"
  10. #include "cdoptimp.h"
  11. #include "helpids.h"
  12. //////////////
  13. // Help ID's
  14. //////////////
  15. #pragma data_seg(".text")
  16. const static DWORD aTitleOptsHelp[] =
  17. {
  18. IDC_CURPROVIDER_TEXT, IDH_SELECTCURRENTPROVIDER,
  19. IDC_PROVIDERPICKER, IDH_SELECTCURRENTPROVIDER,
  20. IDC_ALBUMBATCH_GROUP, IDH_ABOUTBATCHING,
  21. IDC_ALBUMINFO_TEXT, IDH_ABOUTALBUMS,
  22. IDC_DOWNLOADPROMPT, IDH_DOWNLOADPROMPT,
  23. IDC_BATCHENABLED, IDH_BATCHENABLED,
  24. IDC_TITLERESTORE, IDH_TITLEDEFAULTS,
  25. IDC_BATCHTEXT, IDH_NUMBATCHED,
  26. IDC_DOWNLOADENABLED, IDH_AUTODOWNLOADENABLED,
  27. IDC_DOWNLOADNOW, IDH_DOWNLOADNOW,
  28. IDC_DOWNLOAD_GROUP, IDH_DOWNLOADING,
  29. IDC_ALBUMBATCH_TEXT, IDH_ABOUTBATCHING,
  30. 0, 0
  31. };
  32. #pragma data_seg()
  33. ////////////
  34. // Functions
  35. ////////////
  36. STDMETHODIMP_(void) CCDOpt::ToggleInternetDownload(HWND hDlg)
  37. {
  38. if (m_pCDCopy)
  39. {
  40. LPCDOPTDATA pCDData = m_pCDCopy->pCDData;
  41. pCDData->fDownloadEnabled = Button_GetCheck(GetDlgItem(hDlg, IDC_DOWNLOADENABLED));
  42. EnableWindow(GetDlgItem(hDlg, IDC_PROVIDERPICKER), pCDData->fDownloadEnabled);
  43. EnableWindow(GetDlgItem(hDlg, IDC_CURPROVIDER_TEXT), pCDData->fDownloadEnabled);
  44. EnableWindow(GetDlgItem(hDlg, IDC_DOWNLOADPROMPT), pCDData->fDownloadEnabled);
  45. ToggleApplyButton(hDlg);
  46. }
  47. }
  48. STDMETHODIMP_(void) CCDOpt::UpdateBatched(HWND hDlg)
  49. {
  50. if (hDlg != NULL)
  51. {
  52. TCHAR szNum[MAX_PATH];
  53. TCHAR szBatch[MAX_PATH];
  54. if (m_pCDOpts->dwBatchedTitles == 0 || m_pCDOpts->pfnDownloadTitle == NULL)
  55. {
  56. EnableWindow(GetDlgItem(hDlg, IDC_DOWNLOADNOW), FALSE);
  57. }
  58. else
  59. {
  60. EnableWindow(GetDlgItem(hDlg, IDC_DOWNLOADNOW), TRUE);
  61. }
  62. LoadString( m_hInst, IDS_BATCHTEXT, szBatch, sizeof( szBatch )/sizeof(TCHAR) );
  63. wsprintf(szNum, TEXT("%s %d"), szBatch, m_pCDOpts->dwBatchedTitles);
  64. SetWindowText(GetDlgItem(hDlg, IDC_BATCHTEXT), szNum);
  65. }
  66. }
  67. STDMETHODIMP_(BOOL) CCDOpt::InitTitleOptions(HWND hDlg)
  68. {
  69. if (m_pCDCopy)
  70. {
  71. LPCDOPTDATA pCDData = m_pCDCopy->pCDData;
  72. LPCDPROVIDER pProvider;
  73. CheckDlgButton(hDlg, IDC_DOWNLOADENABLED, pCDData->fDownloadEnabled);
  74. CheckDlgButton(hDlg, IDC_DOWNLOADPROMPT, pCDData->fDownloadPrompt);
  75. CheckDlgButton(hDlg, IDC_BATCHENABLED, pCDData->fBatchEnabled);
  76. m_hTitleWnd = hDlg;
  77. UpdateBatched(m_hTitleWnd);
  78. SendDlgItemMessage(hDlg, IDC_PROVIDERPICKER, CB_RESETCONTENT,0,0);
  79. pProvider = m_pCDCopy->pProviderList;
  80. while (pProvider)
  81. {
  82. LRESULT dwIndex = SendDlgItemMessage(hDlg, IDC_PROVIDERPICKER, CB_INSERTSTRING, (WPARAM) -1, (LPARAM) pProvider->szProviderName);
  83. if (dwIndex != CB_ERR && dwIndex != CB_ERRSPACE)
  84. {
  85. SendDlgItemMessage(hDlg, IDC_PROVIDERPICKER, CB_SETITEMDATA, (WPARAM) dwIndex, (LPARAM) pProvider);
  86. if (pProvider == m_pCDCopy->pCurrentProvider)
  87. {
  88. SendDlgItemMessage(hDlg, IDC_PROVIDERPICKER, CB_SETCURSEL, (WPARAM) dwIndex, 0);
  89. }
  90. }
  91. pProvider = pProvider->pNext;
  92. }
  93. ToggleInternetDownload(hDlg);
  94. }
  95. return TRUE;
  96. }
  97. STDMETHODIMP_(void) CCDOpt::RestoreTitleDefaults(HWND hDlg)
  98. {
  99. if (m_pCDCopy)
  100. {
  101. LPCDOPTDATA pCDData = m_pCDCopy->pCDData;
  102. pCDData->fDownloadEnabled = CDDEFAULT_DOWNLOADENABLED;
  103. pCDData->fDownloadPrompt = CDDEFAULT_DOWNLOADPROMPT;
  104. pCDData->fBatchEnabled = CDDEFAULT_BATCHENABLED;
  105. m_pCDCopy->pCurrentProvider = m_pCDCopy->pDefaultProvider;
  106. InitTitleOptions(hDlg);
  107. ToggleApplyButton(hDlg);
  108. }
  109. }
  110. STDMETHODIMP_(void) CCDOpt::ChangeCDProvider(HWND hDlg)
  111. {
  112. if (m_pCDCopy)
  113. {
  114. LRESULT dwResult = SendDlgItemMessage(hDlg, IDC_PROVIDERPICKER, CB_GETCURSEL, 0, 0);
  115. if (dwResult != CB_ERR)
  116. {
  117. dwResult = SendDlgItemMessage(hDlg, IDC_PROVIDERPICKER, CB_GETITEMDATA, (WPARAM) dwResult, 0);
  118. if (dwResult != CB_ERR)
  119. {
  120. m_pCDCopy->pCurrentProvider = (LPCDPROVIDER) dwResult;
  121. }
  122. }
  123. ToggleApplyButton(hDlg);
  124. }
  125. }
  126. STDMETHODIMP_(void) CCDOpt::DownloadNow(HWND hDlg)
  127. {
  128. if (m_pCDOpts->dwBatchedTitles && m_pCDOpts->pfnDownloadTitle)
  129. {
  130. TCHAR szNum[MAX_PATH];
  131. TCHAR szBatch[MAX_PATH];
  132. m_pCDOpts->dwBatchedTitles = m_pCDOpts->pfnDownloadTitle(NULL, m_pCDOpts->lParam, hDlg);
  133. EnableWindow(GetDlgItem(hDlg, IDC_DOWNLOADNOW), m_pCDOpts->dwBatchedTitles != 0);
  134. LoadString( m_hInst, IDS_BATCHTEXT, szBatch, sizeof( szBatch )/sizeof(TCHAR) );
  135. wsprintf(szNum, TEXT("%s %d"), szBatch, m_pCDOpts->dwBatchedTitles);
  136. SetWindowText(GetDlgItem(hDlg, IDC_BATCHTEXT), szNum);
  137. }
  138. }
  139. STDMETHODIMP_(INT_PTR) CCDOpt::TitleOptions(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  140. {
  141. BOOL fResult = TRUE;
  142. switch (msg)
  143. {
  144. default:
  145. fResult = FALSE;
  146. break;
  147. case WM_DESTROY:
  148. {
  149. m_hTitleWnd = NULL;
  150. }
  151. break;
  152. case WM_CONTEXTMENU:
  153. {
  154. WinHelp((HWND)wParam, gszHelpFile, HELP_CONTEXTMENU, (ULONG_PTR)(LPSTR)aTitleOptsHelp);
  155. }
  156. break;
  157. case WM_HELP:
  158. {
  159. WinHelp((HWND) ((LPHELPINFO)lParam)->hItemHandle, gszHelpFile, HELP_WM_HELP, (ULONG_PTR)(LPSTR)aTitleOptsHelp);
  160. }
  161. break;
  162. case WM_INITDIALOG:
  163. {
  164. fResult = InitTitleOptions(hDlg);
  165. }
  166. break;
  167. case WM_COMMAND:
  168. {
  169. LPCDOPTDATA pCDData = m_pCDCopy->pCDData;
  170. switch (LOWORD(wParam))
  171. {
  172. case IDC_TITLERESTORE:
  173. RestoreTitleDefaults(hDlg);
  174. break;
  175. case IDC_DOWNLOADENABLED:
  176. ToggleInternetDownload(hDlg);
  177. break;
  178. case IDC_DOWNLOADPROMPT:
  179. pCDData->fDownloadPrompt = Button_GetCheck(GetDlgItem(hDlg, IDC_DOWNLOADPROMPT));
  180. ToggleApplyButton(hDlg);
  181. break;
  182. case IDC_BATCHENABLED:
  183. pCDData->fBatchEnabled = Button_GetCheck(GetDlgItem(hDlg, IDC_BATCHENABLED));
  184. ToggleApplyButton(hDlg);
  185. break;
  186. case IDC_DOWNLOADNOW:
  187. DownloadNow(hDlg);
  188. break;
  189. case IDC_PROVIDERPICKER:
  190. {
  191. if (HIWORD(wParam) == CBN_SELCHANGE)
  192. {
  193. ChangeCDProvider(hDlg);
  194. }
  195. }
  196. break;
  197. default:
  198. fResult = FALSE;
  199. break;
  200. }
  201. }
  202. break;
  203. case WM_NOTIFY:
  204. {
  205. LPNMHDR pnmh = (LPNMHDR) lParam;
  206. switch (pnmh->code)
  207. {
  208. case PSN_APPLY:
  209. {
  210. ApplyCurrentSettings();
  211. }
  212. }
  213. }
  214. break;
  215. }
  216. return fResult;
  217. }
  218. ///////////////////
  219. // Dialog handler
  220. //
  221. INT_PTR CALLBACK CCDOpt::TitleOptionsProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  222. {
  223. INT_PTR fResult = TRUE;
  224. CCDOpt *pCDOpt = (CCDOpt *) GetWindowLongPtr(hDlg, DWLP_USER);
  225. if (msg == WM_INITDIALOG)
  226. {
  227. pCDOpt = (CCDOpt *) ((LPPROPSHEETPAGE) lParam)->lParam;
  228. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR) pCDOpt);
  229. }
  230. if (pCDOpt)
  231. {
  232. fResult = pCDOpt->TitleOptions(hDlg, msg, wParam, lParam);
  233. }
  234. if (msg == WM_DESTROY)
  235. {
  236. pCDOpt = NULL;
  237. }
  238. return(fResult);
  239. }