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.

343 lines
8.0 KiB

  1. //Copyright (c) 1997-2000 Microsoft Corporation
  2. #include "pch.hxx"
  3. #pragma hdrstop
  4. #include "pgbase.h"
  5. #include "resource.h"
  6. #include "DlgFonts.h"
  7. /***************************************************************************
  8. * Use the following define if for some reason we have to go back to using
  9. * a message loop to let shell have time to update the UI
  10. *
  11. #define NEED_MSG_PUMP
  12. **************************************************************************/
  13. // Initialization of static members
  14. CWizardPageOrder WizardPage::sm_WizPageOrder;
  15. WizardPage::WizardPage(
  16. LPPROPSHEETPAGE ppsp,
  17. int nIdTitle,
  18. int nIdSubTitle
  19. ) : m_hwnd(NULL), m_dwPageId(0)
  20. {
  21. _ASSERTE(NULL != ppsp);
  22. // If we have a subtitle, we must have a title
  23. _ASSERTE(nIdSubTitle?nIdTitle:TRUE);
  24. //
  25. // Many of the members are 0 or NULL.
  26. //
  27. ZeroMemory(ppsp, sizeof(PROPSHEETPAGE));
  28. ppsp->dwSize = sizeof(PROPSHEETPAGE);
  29. ppsp->dwFlags = PSP_DEFAULT;
  30. ppsp->hInstance = g_hInstDll;
  31. // If we are using a title/subtitle, include the flags
  32. // Otherwise, hide the header
  33. if(nIdTitle)
  34. {
  35. ppsp->dwFlags |= PSP_USEHEADERTITLE | (nIdSubTitle?PSP_USEHEADERSUBTITLE:0);
  36. ppsp->pszHeaderTitle = MAKEINTRESOURCE(nIdTitle);
  37. ppsp->pszHeaderSubTitle = MAKEINTRESOURCE(nIdSubTitle);
  38. // ppsp->pszbmHeader = MAKEINTRESOURCE(IDB_ACCMARK);
  39. }
  40. else
  41. ppsp->dwFlags |= PSP_HIDEHEADER;
  42. //
  43. // Callback is a base class function. The derived page
  44. // classes need to implement OnPropSheetPageCreate() and
  45. // OnPropSheetPageRelease() if they want to handle this callback.
  46. // By WizardPage::OnPropSheetPageCreate() returns 1.
  47. //
  48. ppsp->pfnCallback = WizardPage::PropSheetPageCallback;
  49. ppsp->dwFlags |= (PSP_USECALLBACK /*| PSP_USEREFPARENT*/); // JMC: TODO: Do we want PSP_USEREFPARENT
  50. //
  51. // Store "this" in the page struct so we can call member functions
  52. // from the page's message proc.
  53. //
  54. _ASSERTE(NULL != this);
  55. ppsp->lParam = (LPARAM)this;
  56. //
  57. // All dialog messages first go through the base class' message proc.
  58. // Virtual functions are called for some messages. If not processed
  59. // using a message-specific virtual function, the message is passed
  60. // to the derived class instance through the virtual funcion HandleMsg.
  61. //
  62. ppsp->pfnDlgProc = WizardPage::DlgProc;
  63. }
  64. WizardPage::~WizardPage(
  65. VOID
  66. )
  67. {
  68. }
  69. UINT
  70. WizardPage::PropSheetPageCallback(
  71. HWND hwnd,
  72. UINT uMsg,
  73. LPPROPSHEETPAGE ppsp
  74. )
  75. {
  76. UINT uResult = 0;
  77. WizardPage *pThis = (WizardPage *)ppsp->lParam;
  78. _ASSERTE(NULL != pThis);
  79. switch(uMsg)
  80. {
  81. case PSPCB_CREATE:
  82. uResult = pThis->OnPropSheetPageCreate(hwnd, ppsp);
  83. break;
  84. case PSPCB_RELEASE:
  85. uResult = pThis->OnPropSheetPageRelease(hwnd, ppsp);
  86. //
  87. // IMPORTANT:
  88. // This is where we delete each property sheet page.
  89. // HERE and ONLY HERE.
  90. //
  91. // delete pThis; // We won't do this since we'll keep our own list
  92. // The reason it won't work is because if you never get to a page, you
  93. // will never get this message
  94. break;
  95. }
  96. return uResult;
  97. }
  98. //
  99. // This is a static method.
  100. //
  101. INT_PTR
  102. WizardPage::DlgProc(
  103. HWND hwnd,
  104. UINT uMsg,
  105. WPARAM wParam,
  106. LPARAM lParam
  107. )
  108. {
  109. INT_PTR bResult = FALSE;
  110. PROPSHEETPAGE *ppsp = NULL;
  111. if (WM_INITDIALOG == uMsg)
  112. ppsp = (PROPSHEETPAGE *)lParam;
  113. else
  114. ppsp = (PROPSHEETPAGE *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  115. if (NULL != ppsp)
  116. {
  117. WizardPage *pThis = (WizardPage *)ppsp->lParam;
  118. _ASSERTE(NULL != pThis);
  119. switch(uMsg)
  120. {
  121. case WM_INITDIALOG:
  122. {
  123. // The following will set fonts for 'known' controls,
  124. DialogFonts_InitWizardPage(hwnd);
  125. //
  126. // Store address of PROPSHEETPAGE struct for this page
  127. // in window's user data.
  128. //
  129. SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
  130. pThis->m_hwnd = hwnd;
  131. bResult = pThis->OnInitDialog(hwnd, wParam, lParam);
  132. }
  133. break;
  134. case WM_NOTIFY:
  135. bResult = pThis->OnNotify(hwnd, wParam, lParam);
  136. break;
  137. case PSM_QUERYSIBLINGS:
  138. bResult = pThis->OnPSM_QuerySiblings(hwnd, wParam, lParam);
  139. break;
  140. case WM_COMMAND:
  141. bResult = pThis->OnCommand(hwnd, wParam, lParam);
  142. break;
  143. case WM_TIMER:
  144. bResult = pThis->OnTimer(hwnd, wParam, lParam);
  145. break;
  146. case WM_DRAWITEM:
  147. bResult = pThis->OnDrawItem(hwnd, wParam, lParam);
  148. break;
  149. default:
  150. //
  151. // Let derived class instance handle any other messages
  152. // as needed.
  153. //
  154. bResult = pThis->HandleMsg(hwnd, uMsg, wParam, lParam);
  155. break;
  156. }
  157. }
  158. return bResult;
  159. }
  160. LRESULT
  161. WizardPage::OnNotify(
  162. HWND hwnd,
  163. WPARAM wParam,
  164. LPARAM lParam
  165. )
  166. {
  167. INT idCtl = (INT)wParam;
  168. LPNMHDR pnmh = (LPNMHDR)lParam;
  169. LRESULT lResult = 0;
  170. switch(pnmh->code)
  171. {
  172. case PSN_APPLY:
  173. lResult = OnPSN_Apply(hwnd, idCtl, (LPPSHNOTIFY)pnmh);
  174. break;
  175. case PSN_HELP:
  176. lResult = OnPSN_Help(hwnd, idCtl, (LPPSHNOTIFY)pnmh);
  177. break;
  178. case PSN_KILLACTIVE:
  179. lResult = OnPSN_KillActive(hwnd, idCtl, (LPPSHNOTIFY)pnmh);
  180. break;
  181. case PSN_QUERYCANCEL:
  182. lResult = OnPSN_QueryCancel(hwnd, idCtl, (LPPSHNOTIFY)pnmh);
  183. break;
  184. case PSN_RESET:
  185. lResult = OnPSN_Reset(hwnd, idCtl, (LPPSHNOTIFY)pnmh);
  186. break;
  187. case PSN_SETACTIVE:
  188. lResult = OnPSN_SetActive(hwnd, idCtl, (LPPSHNOTIFY)pnmh);
  189. break;
  190. case PSN_WIZBACK:
  191. lResult = OnPSN_WizBack(hwnd, idCtl, (LPPSHNOTIFY)pnmh);
  192. break;
  193. case PSN_WIZNEXT:
  194. lResult = OnPSN_WizNext(hwnd, idCtl, (LPPSHNOTIFY)pnmh);
  195. break;
  196. case PSN_WIZFINISH:
  197. lResult = OnPSN_WizFinish(hwnd, idCtl, (LPPSHNOTIFY)pnmh);
  198. break;
  199. case NM_CLICK:
  200. case NM_RETURN:
  201. OnMsgNotify(hwnd, idCtl, (LPNMHDR) pnmh);
  202. break;
  203. default:
  204. break;
  205. }
  206. return lResult;
  207. }
  208. LRESULT
  209. WizardPage::OnPSN_SetActive(
  210. HWND hwnd,
  211. INT idCtl,
  212. LPPSHNOTIFY pnmh
  213. )
  214. {
  215. // JMC: TODO: Maybe put this in the OnNotify Code so the overrided class does
  216. // not have to call this
  217. //
  218. // By default, each wizard page has a BACK and NEXT button.
  219. //
  220. DWORD dwFlags = 0;
  221. if(sm_WizPageOrder.GetPrevPage(m_dwPageId))
  222. dwFlags |= PSWIZB_BACK;
  223. if(sm_WizPageOrder.GetNextPage(m_dwPageId))
  224. dwFlags |= PSWIZB_NEXT;
  225. else
  226. dwFlags |= PSWIZB_FINISH;
  227. PropSheet_SetWizButtons(GetParent(hwnd), dwFlags);
  228. // Tell the wizard that it's ok to go to this page
  229. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 0);
  230. return TRUE;
  231. }
  232. LRESULT
  233. WizardPage::OnPSM_QuerySiblings(
  234. HWND hwnd,
  235. WPARAM wParam,
  236. LPARAM lParam
  237. )
  238. {
  239. return 0;
  240. }
  241. LRESULT
  242. WizardPage::OnPSN_QueryCancel(
  243. HWND hwnd,
  244. INT idCtl,
  245. LPPSHNOTIFY pnmh
  246. )
  247. {
  248. //If nothing has changed just exit...
  249. if ( memcmp( &g_Options.m_schemePreview, &g_Options.m_schemeOriginal, sizeof(WIZSCHEME)) == 0)
  250. {
  251. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 0);
  252. return TRUE;
  253. }
  254. // if (
  255. switch(StringTableMessageBox(hwnd, IDS_WIZSAVECHANGESMESSAGETEXT, IDS_WIZSAVECHANGESMESSAGETITLE, MB_YESNO))
  256. {
  257. case IDYES:
  258. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 0);
  259. break;
  260. case IDNO:
  261. {
  262. // Restore all settings to the original settings
  263. g_Options.ApplyOriginal();
  264. #if NEED_MSG_PUMP
  265. if (SetTimer(hwnd, 1, 4000, NULL))
  266. {
  267. // Wait for messages to be processed
  268. BOOL fKeepChecking = TRUE;
  269. while (fKeepChecking)
  270. {
  271. MSG msg;
  272. while (PeekMessage(&msg, hwnd, WM_TIMER, WM_TIMER, PM_REMOVE))
  273. {
  274. if (msg.message == WM_TIMER)
  275. {
  276. KillTimer(hwnd, 1);
  277. fKeepChecking = FALSE;
  278. break;
  279. }
  280. TranslateMessage(&msg);
  281. DispatchMessage(&msg);
  282. }
  283. }
  284. }
  285. #endif
  286. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 0);
  287. }
  288. break;
  289. case IDCANCEL:
  290. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 1);
  291. break;
  292. }
  293. return TRUE;
  294. }