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.

369 lines
8.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: dialogs.cxx
  7. //
  8. // Contents: Implementation of dialog classes
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "headers.hxx"
  12. //+---------------------------------------------------------------------------
  13. //
  14. // Function: ConfigDlgProc
  15. //
  16. // Synopsis: Handles the Config dialog
  17. //
  18. //----------------------------------------------------------------------------
  19. INT_PTR CALLBACK
  20. ConfigDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  21. {
  22. CConfig * pConfig;
  23. pConfig = (CConfig *)GetWindowLong(hwnd, DWL_USER);
  24. switch (msg)
  25. {
  26. case WM_INITDIALOG:
  27. pConfig = (CConfig*)lParam;
  28. SetWindowLong(hwnd, DWL_USER, lParam);
  29. pConfig->InitializeConfigDialog(hwnd);
  30. return TRUE;
  31. case WM_COMMAND:
  32. switch (LOWORD(wParam))
  33. {
  34. case IDOK:
  35. if (pConfig->CommitConfigChanges(hwnd))
  36. EndDialog(hwnd, 0);
  37. break;
  38. case IDCANCEL:
  39. EndDialog(hwnd, 1);
  40. break;
  41. }
  42. return TRUE;
  43. }
  44. return FALSE;
  45. }
  46. HRESULT
  47. CConfig::QueryInterface(REFIID iid, void **ppvObj)
  48. {
  49. VERIFY_THREAD();
  50. if (iid == IID_IUnknown)
  51. {
  52. *ppvObj = (IUnknown *)this;
  53. }
  54. else
  55. {
  56. *ppvObj = NULL;
  57. return E_NOINTERFACE;
  58. }
  59. ((IUnknown *)*ppvObj)->AddRef();
  60. return S_OK;
  61. }
  62. DWORD
  63. CConfig::ThreadMain()
  64. {
  65. AddRef();
  66. SetName("Config");
  67. ThreadStarted(S_OK); // Must be after the AddRef() call!
  68. int ret = DialogBoxParam(g_hInstance,
  69. MAKEINTRESOURCE(IDD_CONFIGPATHS),
  70. NULL,
  71. ConfigDlgProc,
  72. (LPARAM)this);
  73. if (ret == -1)
  74. {
  75. ErrorPopup(L"Could not bring up config dialog");
  76. }
  77. Release();
  78. return 0;
  79. }
  80. void
  81. CConfig::InitializeConfigDialog(HWND hwnd)
  82. {
  83. CStr cstr;
  84. CStr cstrInit;
  85. _hwnd = hwnd;
  86. _pMT->_options.GetScriptPath(&cstr);
  87. _pMT->_options.GetInitScript(&cstrInit);
  88. SetDlgItemText(hwnd, IDD_SCRIPTPATH, cstr);
  89. SetDlgItemText(hwnd, IDD_INITSCRIPT, cstrInit);
  90. }
  91. BOOL
  92. CConfig::CommitConfigChanges(HWND hwnd)
  93. {
  94. LOCK_LOCALS(_pMT);
  95. CStr cstr;
  96. TCHAR achBufPath[MAX_PATH];
  97. TCHAR achBufScript[MAX_PATH];
  98. // Read in the options from the dialog and store them. Need to have a
  99. // way to revert to defaults. Right now the user can revert to the
  100. // defaults by clearing the textbox(s) and clicking OK.
  101. GetDlgItemText(hwnd, IDD_SCRIPTPATH, achBufPath, sizeof(achBufPath));
  102. GetDlgItemText(hwnd, IDD_INITSCRIPT, achBufScript, sizeof(achBufScript));
  103. EnableWindow(_hwnd, FALSE);
  104. BOOL retval = _pMT->SetScriptPath(achBufPath, achBufScript);
  105. EnableWindow(_hwnd, TRUE);
  106. return retval;
  107. }
  108. //+---------------------------------------------------------------------------
  109. //
  110. // Function: MBTimeoutDlgProc
  111. //
  112. // Synopsis: Handles the MessageBoxTimeout dialog
  113. //
  114. //----------------------------------------------------------------------------
  115. INT_PTR CALLBACK
  116. MBTimeoutDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  117. {
  118. CMessageBoxTimeout * pDialog;
  119. pDialog = (CMessageBoxTimeout *)GetWindowLong(hwnd, DWL_USER);
  120. switch (msg)
  121. {
  122. case WM_INITDIALOG:
  123. pDialog = (CMessageBoxTimeout*)lParam;
  124. SetWindowLong(hwnd, DWL_USER, lParam);
  125. pDialog->InitializeDialog(hwnd);
  126. return TRUE;
  127. case WM_COMMAND:
  128. pDialog->OnCommand(LOWORD(wParam), HIWORD(wParam));
  129. return TRUE;
  130. case WM_TIMER:
  131. pDialog->OnTimer();
  132. return TRUE;
  133. case WM_CLOSE:
  134. return TRUE;
  135. case WM_DESTROY:
  136. pDialog->_hwnd = NULL;
  137. break;
  138. }
  139. return FALSE;
  140. }
  141. HRESULT
  142. CMessageBoxTimeout::QueryInterface(REFIID iid, void **ppvObj)
  143. {
  144. VERIFY_THREAD();
  145. if (iid == IID_IUnknown)
  146. {
  147. *ppvObj = (IUnknown *)this;
  148. }
  149. else
  150. {
  151. *ppvObj = NULL;
  152. return E_NOINTERFACE;
  153. }
  154. ((IUnknown *)*ppvObj)->AddRef();
  155. return S_OK;
  156. }
  157. DWORD
  158. CMessageBoxTimeout::ThreadMain()
  159. {
  160. AddRef();
  161. Assert(_pmbt != NULL);
  162. SetName("MsgBoxTO");
  163. ThreadStarted(S_OK); // Must be after the AddRef() call!
  164. int ret = DialogBoxParam(g_hInstance,
  165. MAKEINTRESOURCE(IDD_MESSAGEBOX),
  166. NULL,
  167. MBTimeoutDlgProc,
  168. (LPARAM)this);
  169. if (ret == -1)
  170. {
  171. _pmbt->mbts = MBTS_ERROR;
  172. }
  173. else
  174. {
  175. _pmbt->mbts = (MBT_SELECT)ret;
  176. }
  177. SetEvent(_pmbt->hEvent);
  178. Release();
  179. return 0;
  180. }
  181. void
  182. CMessageBoxTimeout::InitializeDialog(HWND hwnd)
  183. {
  184. CStr cstrButtons;
  185. TCHAR *pch = NULL;
  186. int i;
  187. _hwnd = hwnd;
  188. SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  189. cstrButtons.Set(_pmbt->bstrButtonText);
  190. SetDlgItemText(hwnd, IDD_MESSAGE, _pmbt->bstrMessage);
  191. for (i = 5; i > 0; i--)
  192. {
  193. pch = (i == 1) ? cstrButtons : _tcsrchr(cstrButtons, L',');
  194. if (pch && i != 1) // Skip the comma
  195. pch++;
  196. if (_pmbt->cButtons >= i && pch)
  197. {
  198. SetDlgItemText(hwnd, IDD_BUTTON1+i-1, pch);
  199. if (i > 1)
  200. *(pch-1) = L'\0';
  201. }
  202. else
  203. {
  204. ShowWindow(GetDlgItem(hwnd, IDD_BUTTON1+i-1), SW_HIDE);
  205. }
  206. }
  207. if (_pmbt->lTimeout == 0)
  208. {
  209. ShowWindow(GetDlgItem(hwnd, IDD_TIMEMSG), SW_HIDE);
  210. ShowWindow(GetDlgItem(hwnd, IDD_TIME), SW_HIDE);
  211. ShowWindow(GetDlgItem(hwnd, IDD_CANCELCOUNT), SW_HIDE);
  212. }
  213. else
  214. {
  215. TCHAR achBuf[30];
  216. if (!_pmbt->fCanCancel)
  217. EnableWindow(GetDlgItem(hwnd, IDD_CANCELCOUNT), FALSE);
  218. _lSecondsTilCancel = _pmbt->lTimeout * 60;
  219. _lSecondsTilNextEvent = _pmbt->lEventInterval * 60;
  220. wsprintf(achBuf, L"%01d:%02d", _lSecondsTilCancel / 60,
  221. _lSecondsTilCancel % 60);
  222. SetDlgItemText(hwnd, IDD_TIME, achBuf);
  223. // Setup a 1 second timer
  224. SetTimer(hwnd, 1, 1000, NULL);
  225. }
  226. }
  227. void
  228. CMessageBoxTimeout::OnCommand(USHORT id, USHORT wNotify)
  229. {
  230. switch (id)
  231. {
  232. case IDD_BUTTON1:
  233. case IDD_BUTTON2:
  234. case IDD_BUTTON3:
  235. case IDD_BUTTON4:
  236. case IDD_BUTTON5:
  237. if (_pmbt->fConfirm)
  238. {
  239. TCHAR achBuf[100];
  240. TCHAR achText[100];
  241. GetDlgItemText(_hwnd, id, achText, 100);
  242. wsprintf(achBuf,
  243. L"Click OK to confirm your choice of '%s'",
  244. achText);
  245. if (MessageBox(_hwnd,
  246. achBuf,
  247. L"Gauntlet",
  248. MB_OKCANCEL | MB_SETFOREGROUND) == IDCANCEL)
  249. {
  250. break;
  251. }
  252. }
  253. KillTimer(_hwnd, 1);
  254. EndDialog(_hwnd, id-IDD_BUTTON1+MBTS_BUTTON1);
  255. break;
  256. case IDD_CANCELCOUNT:
  257. KillTimer(_hwnd, 1);
  258. SetDlgItemText(_hwnd, IDD_TIME, L"");
  259. SetDlgItemText(_hwnd, IDD_TIMEMSG, L"The countdown has been canceled.");
  260. EnableWindow(GetDlgItem(_hwnd, IDD_CANCELCOUNT), FALSE);
  261. break;
  262. }
  263. }
  264. void
  265. CMessageBoxTimeout::OnTimer()
  266. {
  267. TCHAR achBuf[30];
  268. _lSecondsTilCancel--;
  269. _lSecondsTilNextEvent--;
  270. wsprintf(achBuf, L"%01d:%02d", _lSecondsTilCancel / 60,
  271. _lSecondsTilCancel % 60);
  272. SetDlgItemText(_hwnd, IDD_TIME, achBuf);
  273. if (_lSecondsTilCancel <= 0)
  274. {
  275. KillTimer(_hwnd, 1);
  276. EndDialog(_hwnd, MBTS_TIMEOUT);
  277. return;
  278. }
  279. if (_lSecondsTilNextEvent <= 0 && _pmbt->lEventInterval != 0)
  280. {
  281. _pmbt->mbts = MBTS_INTERVAL;
  282. SetEvent(_pmbt->hEvent);
  283. _lSecondsTilNextEvent = _pmbt->lEventInterval * 60;
  284. // If we're minimized, unminimize to remind that we're still there.
  285. ShowWindow(_hwnd, SW_SHOWNORMAL);
  286. }
  287. }