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.

344 lines
9.0 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright (c) 1997-1999 Microsoft Corporation
  4. /**********************************************************************/
  5. #include "precomp.h"
  6. #include "AdvPage.h"
  7. #include "chstring1.h"
  8. #include "resource.h"
  9. #include "WMIHelp.h"
  10. #include "ShlWapi.h"
  11. const static DWORD advPageHelpIDs[] = { // Context Help IDs
  12. IDC_SCRIPT_LABEL, IDH_WMI_CTRL_ADVANCED_SCRIPTING_PATH,
  13. IDC_SCRIPT_NS, IDH_WMI_CTRL_ADVANCED_SCRIPTING_PATH,
  14. IDC_CHANGE_SCRIPT_NS, IDH_WMI_CTRL_ADVANCED_CHANGE_BUTTON,
  15. IDC_ASP, IDH_WMI_CTRL_ADVANCED_ASP_ACCESS,
  16. IDC_ASP_LABEL, IDH_WMI_CTRL_ADVANCED_ASP_ACCESS,
  17. IDC_9X_ANON_CONNECTION, IDH_WMI_CTRL_ADVANCED_ENABLE_CONNECT,
  18. IDC_9X_ONLY, IDH_WMI_CTRL_ADVANCED_RESTART_BOX,
  19. IDC_NORESTART, IDH_WMI_CTRL_ADVANCED_RESTART_BOX,
  20. IDC_ESSRESTART, IDH_WMI_CTRL_ADVANCED_RESTART_BOX,
  21. IDC_ALWAYSAUTORESTART, IDH_WMI_CTRL_ADVANCED_RESTART_BOX,
  22. IDC_ADV_PARA, -1,
  23. 0, 0};
  24. // WARNING: This class handles IDD_ADVANCED_NT and IDD_ADVANCED_9X so protect
  25. // yourself from controls that aren't on both templates.
  26. CAdvancedPage::CAdvancedPage(DataSource *ds, bool htmlSupport) :
  27. CUIHelpers(ds, &(ds->m_rootThread), htmlSupport),
  28. m_DS(ds)
  29. {
  30. }
  31. CAdvancedPage::~CAdvancedPage(void)
  32. {
  33. }
  34. //-------------------------------------------------------------------------
  35. void CAdvancedPage::InitDlg(HWND hDlg)
  36. {
  37. m_hDlg = hDlg;
  38. ATLTRACE(_T("ADV: init\n"));
  39. }
  40. //---------------------------------------------------------------------------
  41. void CAdvancedPage::Refresh(HWND hDlg)
  42. {
  43. if(m_DS && m_DS->IsNewConnection(&m_sessionID))
  44. {
  45. CHString1 temp;
  46. CHString1 szNotRemoteable, szUnavailable;
  47. HRESULT hr = S_OK;
  48. BOOL enable = TRUE;
  49. HWND hWnd;
  50. szNotRemoteable.LoadString(IDS_NOT_REMOTEABLE);
  51. szUnavailable.LoadString(IDS_UNAVAILABLE);
  52. PageChanged(PB_ADVANCED, false);
  53. //Make sure we don't display this stuff if there's no connection...
  54. if((m_DS->m_OSType == OSTYPE_WINNT) || (m_DS->m_rootThread.m_status != WbemServiceThread::ready))
  55. {
  56. ATLTRACE(_T("ADV: winnt\n"));
  57. ::ShowWindow(GetDlgItem(hDlg,IDC_NORESTART), SW_HIDE);
  58. ::ShowWindow(GetDlgItem(hDlg,IDC_ESSRESTART), SW_HIDE);
  59. ::ShowWindow(GetDlgItem(hDlg,IDC_ALWAYSAUTORESTART), SW_HIDE);
  60. ::ShowWindow(GetDlgItem(hDlg,IDC_9X_ANON_CONNECTION), SW_HIDE);
  61. ::ShowWindow(GetDlgItem(hDlg,IDC_9X_ONLY), SW_HIDE);
  62. CHString1 para;
  63. para.LoadString(IDS_ADV_PARA_NT);
  64. SetDlgItemText(hDlg, IDC_ADV_PARA, para);
  65. // - - - - - - - - - - - - - -
  66. // Enable for ASP:
  67. hWnd = GetDlgItem(hDlg,IDC_ASP);
  68. if(hWnd)
  69. {
  70. // only display it for NT 3.51 and NT4.0.
  71. CHString1 ver;
  72. m_DS->GetOSVersion(ver);
  73. if((_tcsncmp((LPCTSTR)ver, _T("3.51"), 4) == 0) ||
  74. ver[0] == _T('4'))
  75. {
  76. ATLTRACE(_T("ADV: winnt 4.0\n"));
  77. ::ShowWindow(hWnd, SW_SHOW);
  78. ::ShowWindow(GetDlgItem(hDlg, IDC_ASP_LABEL), SW_SHOW);
  79. hr = m_DS->GetScriptASPEnabled(m_enableASP);
  80. if(SUCCEEDED(hr))
  81. {
  82. Button_SetCheck(hWnd, (m_enableASP ? BST_CHECKED : BST_UNCHECKED));
  83. }
  84. }
  85. else // this must be w2k
  86. {
  87. ATLTRACE(_T("ADV: winnt 5.0\n"));
  88. ::ShowWindow(hWnd, SW_HIDE);
  89. ::ShowWindow(GetDlgItem(hDlg, IDC_ASP_LABEL), SW_HIDE);
  90. }
  91. }
  92. }
  93. else // 9x box
  94. {
  95. ATLTRACE(_T("ADV: 9x\n"));
  96. ::ShowWindow(GetDlgItem(hDlg,IDC_NORESTART), SW_SHOW);
  97. ::ShowWindow(GetDlgItem(hDlg,IDC_ESSRESTART), SW_SHOW);
  98. ::ShowWindow(GetDlgItem(hDlg,IDC_ALWAYSAUTORESTART), SW_SHOW);
  99. ::ShowWindow(GetDlgItem(hDlg,IDC_9X_ANON_CONNECTION), SW_SHOW);
  100. ::ShowWindow(GetDlgItem(hDlg,IDC_9X_ONLY), SW_SHOW);
  101. ShowWindow(GetDlgItem(hDlg,IDC_ASP), SW_HIDE);
  102. ShowWindow(GetDlgItem(hDlg,IDC_ASP_LABEL), SW_HIDE);
  103. CHString1 para;
  104. para.LoadString(IDS_ADV_PARA_9X);
  105. SetDlgItemText(hDlg, IDC_ADV_PARA, para);
  106. // - - - - - - - - - - - - - -
  107. // 9x restart.
  108. int ID;
  109. hr = m_DS->GetRestart(m_oldRestart);
  110. if(SUCCEEDED(hr))
  111. {
  112. switch(m_oldRestart)
  113. {
  114. case DataSource::Dont: ID = IDC_NORESTART; break;
  115. case DataSource::AsNeededByESS: ID = IDC_ESSRESTART; break;
  116. case DataSource::Always: ID = IDC_ALWAYSAUTORESTART; break;
  117. }
  118. CheckRadioButton(hDlg, IDC_NORESTART, IDC_ALWAYSAUTORESTART, ID);
  119. }
  120. // - - - - - - - - - - - - - -
  121. // 9x Anonymous connection:
  122. hWnd = GetDlgItem(hDlg, IDC_9X_ANON_CONNECTION);
  123. if(hWnd)
  124. {
  125. hr = m_DS->GetAnonConnections(m_anonConnection);
  126. if(SUCCEEDED(hr))
  127. {
  128. Button_SetCheck(hWnd, (m_anonConnection ? BST_CHECKED : BST_UNCHECKED));
  129. }
  130. }
  131. } //endif OSTtype
  132. // - - - - - - - - - - - - - -
  133. // ASP def namespace:
  134. hWnd = GetDlgItem(hDlg, IDC_SCRIPT_NS);
  135. if(hWnd)
  136. {
  137. hr = m_DS->GetScriptDefNS(m_DefNamespace);
  138. if(SUCCEEDED(hr))
  139. {
  140. enable = TRUE;
  141. TCHAR shortPath[50] = {0};
  142. PathCompactPathEx(shortPath, m_DefNamespace, 40,0);
  143. SetWindowText(hWnd, shortPath);
  144. }
  145. else //failed
  146. {
  147. enable = FALSE;
  148. SetWindowText(hWnd, szUnavailable);
  149. }
  150. ::EnableWindow(GetDlgItem(hDlg,IDC_CHANGE_SCRIPT_NS), enable);
  151. }
  152. }
  153. }
  154. //------------------------------------------------------------------------
  155. void CAdvancedPage::OnNSSelChange(HWND hDlg)
  156. {
  157. TCHAR path[MAX_PATH] = {0};
  158. if(DisplayNSBrowser(hDlg, path, MAX_PATH) == IDOK)
  159. {
  160. m_DefNamespace = path;
  161. HWND hWnd = GetDlgItem(hDlg, IDC_SCRIPT_NS);
  162. TCHAR shortPath[50] = {0};
  163. PathCompactPathEx(shortPath, m_DefNamespace, 40,0);
  164. ::SetWindowText(hWnd, shortPath);
  165. Edit_SetModify(hWnd, TRUE);
  166. PageChanged(PB_ADVANCED, true);
  167. }
  168. }
  169. //------------------------------------------------------------------------
  170. void CAdvancedPage::OnApply(HWND hDlg, bool bClose)
  171. {
  172. // enable ASP
  173. HWND hWnd = GetDlgItem(hDlg, IDC_ASP);
  174. bool needToPut = false;
  175. if(hWnd)
  176. {
  177. bool newEnable = (IsDlgButtonChecked(hDlg, IDC_ASP) & BST_CHECKED ?true:false);
  178. if(m_enableASP != newEnable)
  179. {
  180. m_DS->SetScriptASPEnabled(newEnable);
  181. m_enableASP = newEnable;
  182. needToPut = true;
  183. }
  184. }
  185. // default scripting namespace.
  186. TCHAR buf[_MAX_PATH] = {0};
  187. hWnd = GetDlgItem(hDlg, IDC_SCRIPT_NS);
  188. //if(Edit_GetModify(hWnd))
  189. {
  190. ::GetWindowText(hWnd, buf, ARRAYSIZE(buf));
  191. m_DS->SetScriptDefNS(m_DefNamespace);
  192. needToPut = true;
  193. }
  194. // Anon Connections
  195. hWnd = GetDlgItem(hDlg, IDC_9X_ANON_CONNECTION);
  196. if(hWnd)
  197. {
  198. bool anonConn = (IsDlgButtonChecked(hDlg, IDC_9X_ANON_CONNECTION) & BST_CHECKED ?true:false);
  199. if(m_anonConnection != anonConn)
  200. {
  201. m_DS->SetAnonConnections(anonConn);
  202. m_anonConnection = anonConn;
  203. needToPut = true;
  204. }
  205. }
  206. // 9x restart
  207. hWnd = GetDlgItem(hDlg, IDC_NORESTART);
  208. if(hWnd)
  209. {
  210. DataSource::RESTART restart = DataSource::Dont;
  211. if(IsDlgButtonChecked(hDlg, IDC_NORESTART) & BST_CHECKED)
  212. restart = DataSource::Dont;
  213. else if(IsDlgButtonChecked(hDlg, IDC_ESSRESTART) & BST_CHECKED)
  214. restart = DataSource::AsNeededByESS;
  215. else if(IsDlgButtonChecked(hDlg, IDC_ALWAYSAUTORESTART) & BST_CHECKED)
  216. restart = DataSource::Always;
  217. if(m_oldRestart != restart)
  218. {
  219. m_DS->SetRestart(restart);
  220. m_oldRestart = restart;
  221. needToPut = true;
  222. }
  223. }
  224. if(needToPut)
  225. {
  226. NeedToPut(PB_ADVANCED, !bClose);
  227. if(!bClose)
  228. Refresh(hDlg);
  229. }
  230. }
  231. //------------------------------------------------------------------------
  232. BOOL CAdvancedPage::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  233. {
  234. switch(uMsg)
  235. {
  236. case WM_INITDIALOG:
  237. InitDlg(hDlg);
  238. break;
  239. case WM_NOTIFY:
  240. switch(((LPNMHDR)lParam)->code)
  241. {
  242. case PSN_SETACTIVE:
  243. Refresh(hDlg);
  244. break;
  245. case PSN_HELP:
  246. HTMLHelper(hDlg);
  247. break;
  248. case PSN_APPLY:
  249. OnApply(hDlg, (((LPPSHNOTIFY)lParam)->lParam == 1));
  250. break;
  251. }
  252. break;
  253. case WM_COMMAND:
  254. switch(LOWORD(wParam))
  255. {
  256. case IDC_ASP:
  257. case IDC_9X_ANON_CONNECTION:
  258. case IDC_NORESTART:
  259. case IDC_ESSRESTART:
  260. case IDC_ALWAYSAUTORESTART:
  261. if(HIWORD(wParam) == BN_CLICKED)
  262. {
  263. PageChanged(PB_ADVANCED, true);
  264. return TRUE;
  265. }
  266. break;
  267. case IDC_CHANGE_SCRIPT_NS:
  268. if(HIWORD(wParam) == BN_CLICKED)
  269. {
  270. OnNSSelChange(hDlg);
  271. return TRUE;
  272. }
  273. break;
  274. } //endswitch(LOWORD(wParam))
  275. break;
  276. case WM_HELP:
  277. if (IsWindowEnabled(hDlg))
  278. {
  279. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  280. c_HelpFile,
  281. HELP_WM_HELP,
  282. (ULONG_PTR)advPageHelpIDs);
  283. }
  284. break;
  285. case WM_CONTEXTMENU:
  286. if (IsWindowEnabled(hDlg))
  287. {
  288. WinHelp(hDlg, c_HelpFile,
  289. HELP_CONTEXTMENU,
  290. (ULONG_PTR)advPageHelpIDs);
  291. }
  292. break;
  293. default:
  294. return FALSE;
  295. }
  296. return TRUE;
  297. }