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.

382 lines
11 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001.
  5. //
  6. // File: Genpage.cpp
  7. //
  8. // Contents: Wireless Network Policy Management Snapin WIFI Policy General Properties
  9. //
  10. //
  11. // History: TaroonM
  12. // 10/30/01
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "stdafx.h"
  16. #include "sprpage.h"
  17. #include "GenPage.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CGenPage property page
  25. IMPLEMENT_DYNCREATE(CGenPage, CSnapinPropPage)
  26. //CGenPage::CGenPage() : CSnapinPropPage(CGenPage::IDD)
  27. CGenPage::CGenPage(UINT nIDTemplate) : CSnapinPropPage(nIDTemplate)
  28. {
  29. //{{AFX_DATA_INIT(CGenPage)
  30. // NOTE: the ClassWizard will add member initialization here
  31. //}}AFX_DATA_INIT
  32. m_dlgIDD = nIDTemplate;
  33. m_bNameChanged = FALSE;
  34. m_bPageInitialized = FALSE;
  35. m_dwEnableZeroConf = FALSE;
  36. m_dwConnectToNonPreferredNtwks = FALSE;
  37. m_dwPollingInterval = 90;
  38. m_MMCthreadID = ::GetCurrentThreadId();
  39. m_bReadOnly = FALSE;
  40. }
  41. CGenPage::~CGenPage()
  42. {
  43. }
  44. void CGenPage::DoDataExchange(CDataExchange* pDX)
  45. {
  46. CSnapinPropPage::DoDataExchange(pDX);
  47. //{{AFX_DATA_MAP(CGenPage)
  48. DDX_Control(pDX, IDC_EDNAME, m_edName);
  49. DDX_Control(pDX, IDC_EDDESCRIPTION, m_edDescription);
  50. DDX_Check(pDX,IDC_DISABLE_ZERO_CONF,m_dwEnableZeroConf);
  51. DDX_Check(pDX,IDC_AUTOMATICALLY_CONNECT_TO_NON_PREFERRED_NTWKS,m_dwConnectToNonPreferredNtwks);
  52. DDX_Control(pDX,IDC_COMBO_NETWORKS_TO_ACCESS, m_cbdwNetworksToAccess);
  53. DDX_Text(pDX, IDC_POLLING_INTERVAL, m_dwPollingInterval);
  54. // Limit polling interval to 30 days
  55. DDV_MinMaxDWord(pDX, m_dwPollingInterval, 0, 43200);
  56. //}}AFX_DATA_MAP
  57. }
  58. BEGIN_MESSAGE_MAP(CGenPage, CSnapinPropPage)
  59. //{{AFX_MSG_MAP(CGenPage)
  60. ON_WM_HELPINFO()
  61. ON_EN_CHANGE(IDC_EDNAME, OnChangedName)
  62. ON_EN_CHANGE(IDC_EDDESCRIPTION, OnChangedDescription)
  63. ON_EN_CHANGE(IDC_POLLING_INTERVAL, OnChangedOtherParams)
  64. ON_BN_CLICKED(IDC_AUTOMATICALLY_CONNECT_TO_NON_PREFERRED_NTWKS, OnChangedOtherParams)
  65. ON_BN_CLICKED(IDC_DISABLE_ZERO_CONF, OnChangedOtherParams)
  66. ON_CBN_SELENDOK(IDC_COMBO_NETWORKS_TO_ACCESS, OnChangedOtherParams)
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CGenPage message handlers
  71. BOOL CGenPage::OnInitDialog()
  72. {
  73. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  74. CString pszTemp;
  75. DWORD dwNetworksToAccessIndex = 0;
  76. DWORD dwPollingInterval = 0;
  77. // call base class init
  78. CSnapinPropPage::OnInitDialog();
  79. m_bPageInitialized = TRUE;
  80. // show the wait cursor in case there is a huge description being accessed
  81. CWaitCursor waitCursor;
  82. pWirelessPolicyData = GetResultObject()->GetWirelessPolicy();
  83. m_edName.SetLimitText(c_nMaxName);
  84. m_edDescription.SetLimitText(c_nMaxName);
  85. // initialize our edit controls
  86. ASSERT(pWirelessPolicyData);
  87. if (pWirelessPolicyData->pszWirelessName) {
  88. m_edName.SetWindowText (pWirelessPolicyData->pszWirelessName);
  89. m_strOldName = pWirelessPolicyData->pszWirelessName;
  90. }
  91. if (pWirelessPolicyData->pszDescription) {
  92. m_edDescription.SetWindowText (pWirelessPolicyData->pszDescription);
  93. }
  94. m_dwEnableZeroConf = pWirelessPolicyData->dwDisableZeroConf ? FALSE : TRUE;
  95. m_dwConnectToNonPreferredNtwks =
  96. pWirelessPolicyData->dwConnectToNonPreferredNtwks ? TRUE : FALSE;
  97. pszTemp.LoadString(IDS_WIRELESS_ACCESS_NETWORK_ANY);
  98. m_cbdwNetworksToAccess.AddString(pszTemp);
  99. pszTemp.LoadString(IDS_WIRELESS_ACCESS_NETWORK_AP);
  100. m_cbdwNetworksToAccess.AddString(pszTemp);
  101. pszTemp.LoadString(IDS_WIRELESS_ACCESS_NETWORK_ADHOC);
  102. m_cbdwNetworksToAccess.AddString(pszTemp);
  103. switch (pWirelessPolicyData->dwNetworkToAccess) {
  104. case WIRELESS_ACCESS_NETWORK_ANY:
  105. dwNetworksToAccessIndex = 0;
  106. break;
  107. case WIRELESS_ACCESS_NETWORK_AP:
  108. dwNetworksToAccessIndex = 1;
  109. break;
  110. case WIRELESS_ACCESS_NETWORK_ADHOC:
  111. dwNetworksToAccessIndex = 2;
  112. break;
  113. default:
  114. dwNetworksToAccessIndex = 0;
  115. break;
  116. }
  117. m_cbdwNetworksToAccess.SetCurSel(dwNetworksToAccessIndex);
  118. m_dwPollingInterval = pWirelessPolicyData->dwPollingInterval / 60;
  119. if (pWirelessPolicyData->dwFlags & WLSTORE_READONLY) {
  120. m_bReadOnly = TRUE;
  121. }
  122. if (m_bReadOnly) {
  123. DisableControls();
  124. }
  125. // add context help to the style bits
  126. if (GetParent())
  127. {
  128. GetParent()->ModifyStyleEx (0, WS_EX_CONTEXTHELP, 0);
  129. }
  130. UpdateData (FALSE);
  131. // OK, we can start paying attention to modifications made via dlg controls now.
  132. // This should be the last call before returning from OnInitDialog.
  133. OnFinishInitDialog();
  134. return TRUE; // return TRUE unless you set the focus to a control
  135. // EXCEPTION: OCX Property Pages should return FALSE
  136. }
  137. BOOL CGenPage::OnApply()
  138. {
  139. CString strName;
  140. CString strDescription;
  141. LPWSTR pszDescription = NULL;
  142. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  143. DWORD dwNetworksToAccesssIndex = 0;
  144. DWORD dwDisableZeroConf = 0;
  145. DWORD dwAutomaticallyConnectToNonPreferredNtwks = 0;
  146. DWORD dwNetworksToAccess = 0;
  147. pWirelessPolicyData = GetResultObject()->GetWirelessPolicy();
  148. // pull our data out of the controls and into the object
  149. if (!UpdateData (TRUE))
  150. // Data was not valid, return for user to correct it.
  151. return CancelApply();
  152. m_edName.GetWindowText (strName);
  153. m_edDescription.GetWindowText (strDescription);
  154. if (strName.IsEmpty()) {
  155. ReportError(IDS_OPERATION_FAILED_NULL_POLICY, 0);
  156. m_edName.SetWindowText (pWirelessPolicyData->pszWirelessName);
  157. return CancelApply();
  158. }
  159. ASSERT(pWirelessPolicyData);
  160. if (pWirelessPolicyData->pszOldWirelessName) {
  161. FreePolStr(pWirelessPolicyData->pszOldWirelessName);
  162. }
  163. pWirelessPolicyData->pszOldWirelessName = pWirelessPolicyData->pszWirelessName;
  164. pWirelessPolicyData->pszWirelessName = AllocPolStr(strName);
  165. FreeAndThenDupString(&pWirelessPolicyData->pszDescription, strDescription);
  166. pWirelessPolicyData->dwPollingInterval = (m_dwPollingInterval*60);
  167. dwNetworksToAccesssIndex = m_cbdwNetworksToAccess.GetCurSel();
  168. switch (dwNetworksToAccesssIndex) {
  169. case 0 :
  170. dwNetworksToAccess = WIRELESS_ACCESS_NETWORK_ANY;
  171. break;
  172. case 1 :
  173. dwNetworksToAccess = WIRELESS_ACCESS_NETWORK_AP;
  174. break;
  175. case 2 :
  176. dwNetworksToAccess = WIRELESS_ACCESS_NETWORK_ADHOC;
  177. break;
  178. }
  179. pWirelessPolicyData->dwNetworkToAccess = dwNetworksToAccess;
  180. dwDisableZeroConf = m_dwEnableZeroConf ? 0 : 1;
  181. pWirelessPolicyData->dwDisableZeroConf = dwDisableZeroConf;
  182. dwAutomaticallyConnectToNonPreferredNtwks =
  183. m_dwConnectToNonPreferredNtwks ? 1 : 0;
  184. pWirelessPolicyData->dwConnectToNonPreferredNtwks =
  185. dwAutomaticallyConnectToNonPreferredNtwks;
  186. return CSnapinPropPage::OnApply();
  187. }
  188. void CGenPage::OnCancel()
  189. {
  190. //This is a workaround to fix 343052. When there is sub dialog open and the user
  191. //click the corresponding result pane node, this function can get called when press
  192. //"ESC" or ALT_F4 although the policy property sheet is disabled.
  193. //We post a WM_CLOSE to the sub dialog to force them to close.
  194. //if there is any sub dialog active, force them to close
  195. //m_pDlgIKE may be set to NULL by the child thread during the mean time (although
  196. //the chance is very slim). Add a lock there to avoid potential AV
  197. //CSingleLock cLock(&m_csDlg);
  198. /* taroonm
  199. cLock.Lock();
  200. if (m_pDlgIKE)
  201. {
  202. HWND hwndDlg = m_pDlgIKE->GetSafeHwnd();
  203. if (hwndDlg)
  204. {
  205. ::PostMessage(hwndDlg, WM_CLOSE, 0, 0);
  206. }
  207. }
  208. cLock.Unlock();
  209. */
  210. CSnapinPropPage::OnCancel();
  211. }
  212. BOOL CGenPage::OnHelpInfo(HELPINFO* pHelpInfo)
  213. {
  214. if (pHelpInfo->iContextType == HELPINFO_WINDOW)
  215. {
  216. DWORD* pdwHelp = (DWORD*) &g_aHelpIDs_IDD_WIRELESSGENPROP[0];
  217. ::WinHelp ((HWND)pHelpInfo->hItemHandle,
  218. c_szWlsnpHelpFile,
  219. HELP_WM_HELP,
  220. (DWORD_PTR)(LPVOID)pdwHelp);
  221. }
  222. return CSnapinPropPage::OnHelpInfo(pHelpInfo);
  223. }
  224. void CGenPage::OnChangedName()
  225. {
  226. m_bNameChanged = TRUE;
  227. SetModified();
  228. }
  229. void CGenPage::OnChangedDescription()
  230. {
  231. SetModified();
  232. }
  233. void CGenPage::OnChangedOtherParams()
  234. {
  235. SetModified();
  236. }
  237. void CGenPage::SetNewSheetTitle()
  238. {
  239. //dont set new tile if page is not initialized or no result object associated
  240. if (NULL == GetResultObject() || !m_bPageInitialized)
  241. return;
  242. PWIRELESS_POLICY_DATA pWirelessPolicyData = GetResultObject()->GetWirelessPolicy();
  243. if (NULL == pWirelessPolicyData->pszWirelessName)
  244. return;
  245. if (0 == m_strOldName.Compare(pWirelessPolicyData->pszWirelessName))
  246. return;
  247. CPropertySheet *psht = (CPropertySheet*)GetParent();
  248. //sometimes the psh can be NULL, for example if the page is never initialized
  249. if (NULL == psht)
  250. {
  251. return;
  252. }
  253. CString strTitle;
  254. psht->GetWindowText( strTitle );
  255. CString strAppendage;
  256. int nIndex;
  257. // Get the name from the DS, this is the original policy name used to
  258. // generate the prop sheet's title.
  259. // Assume the sheet title is of the form "<policy name> Properties",
  260. // and that the DSObject name is the one used to create the title.
  261. // This would not be true if there has been >1 rename in the General
  262. // page during this invocation of the owning prop sheet.
  263. if (-1 != (nIndex = strTitle.Find( (LPCTSTR)m_strOldName )))
  264. {
  265. CString strNewTitle;
  266. strNewTitle = strTitle.Left(nIndex);
  267. strAppendage = strTitle.Right( strTitle.GetLength() - m_strOldName.GetLength() );
  268. strNewTitle += pWirelessPolicyData->pszWirelessName;
  269. strNewTitle += strAppendage;
  270. psht->SetTitle( (LPCTSTR)strNewTitle );
  271. m_strOldName = pWirelessPolicyData->pszWirelessName;
  272. }
  273. }
  274. void CGenPage::OnManagerApplied()
  275. {
  276. SetNewSheetTitle();
  277. }
  278. void CGenPage::DisableControls()
  279. {
  280. SAFE_ENABLEWINDOW (IDC_EDNAME, FALSE);
  281. SAFE_ENABLEWINDOW (IDC_EDDESCRIPTION, FALSE);
  282. SAFE_ENABLEWINDOW (IDC_POLLING_INTERVAL, FALSE);
  283. SAFE_ENABLEWINDOW(IDC_COMBO_NETWORKS_TO_ACCESS, FALSE);
  284. SAFE_ENABLEWINDOW(IDC_DISABLE_ZERO_CONF, FALSE);
  285. SAFE_ENABLEWINDOW(IDC_AUTOMATICALLY_CONNECT_TO_NON_PREFERRED_NTWKS, FALSE);
  286. return;
  287. }